gaim/www

people are dense
WITH_GTK12_ANSWERS
2004-01-19, Luke Schierer
522b8ea7e1b3
people are dense
<?php
require "base.inc.php";
require "smilies.inc.php";
require "Table.inc.php";
$bug_data_file = $bug_data_dir . "/bugs.dat";
$bug_lock_file = $bug_data_dir . "/bugs.lock";
function build_bug_tracker_nav()
{
global $action, $session;
if ($action == "")
$buffer = "<b>List Bugs</b>";
else
{
$buffer = "<a href=\"" . $session->localUrl($PHP_SELF) . "\">" .
"List Bugs</a>";
}
$buffer .= " &nbsp;";
$buffer .= "<b>&middot;</b> &nbsp;";
if ($action == "addbug")
$buffer .= "<b>Add Bug</b>";
else
{
$buffer .= "<a href=\"" . $session->localUrl($PHP_SELF) .
"?action=addbug\">Add Bug</a>";
}
$buffer .= " &nbsp;";
$buffer .= "<b>&middot;</b> &nbsp;";
$buffer .= "<a href=\"" . $session->localUrl("logout.php") .
"\">Log Out</a>";
return $buffer;
}
function lock_bug_file()
{
global $bug_lock_file;
while (file_exists($bug_lock_file))
{
clearstatcache();
usleep(rand(5, 70));
}
$fp = fopen($bug_lock_file, "w");
return $fp;
}
function unlock_bug_file($fp)
{
global $bug_lock_file;
fclose($fp);
unlink($bug_lock_file);
}
function add_bug($bugnum, $desc)
{
global $bug_data_file;
/* Just In Case (TM) */
chop($bugnum);
chop($desc);
$lock = lock_bug_file();
if (!$fp = fopen($bug_data_file, "a"))
{
print "There was an error opening $bug_data_file!";
unlock_bug_file($lock);
exit;
}
fwrite($fp, $bugnum . "\t" . $desc . "\n");
fclose($fp);
unlock_bug_file($lock);
header("Location: bugtracker.php");
exit;
}
function display_add_bug()
{
global $bugnum;
global $desc;
setup_site("Add Bug");
start_section("Add Bug", build_bug_tracker_nav(), false);
?>
<form method="get" action="bugtracker.php">
<input type="hidden" name="action" value="addbug" />
<?php
start_table(array("width" => "100%", "cellspacing" => 2,
"cellpadding" => 0, "border" => 0));
form_item("Bug Number", "bugnum", $bugnum, true, 10);
form_item("Description", "desc", $desc, true, 50);
start_tr();
start_td(array("colspan" => 2, "align" => "center"));
br();
?>
<input type="submit" value="Submit" />&nbsp;&nbsp;
<input type="reset" />
<?php
end_td();
end_tr();
end_table();
end_tag("form");
end_section();
}
function remove_bugs($bugs)
{
global $bug_data_file;
if (count($bugs) == 0)
{
print "No bugs were entered.\n";
exit;
}
/* I know this algorithm sucks. It's slow. Deal with it :) */
/* Build a little hashtable for the bugs */
$bug_table = array();
for ($i = 0; $i < count($bugs); $i++)
{
$bug_table[$bugs[$i]] = 1;
}
/* Write it out. */
$lock = lock_bug_file();
$lines = file($bug_data_file);
if (!$fp = fopen($bug_data_file, "w"))
{
print "There was an error opening $bug_data_file!";
unlock_bug_file($lock);
exit;
}
for ($i = 0; $i < count($lines); $i++)
{
list($bugnum, $desc) = split("\t", $lines[$i], 2);
if (!array_key_exists($bugnum, $bug_table))
fwrite($fp, $bugnum . "\t" . $desc);
}
fclose($fp);
unlock_bug_file($lock);
}
function display_remove_bugs()
{
global $bugs;
setup_site("Remove Bugs");
start_section("Remove Bugs", build_bug_tracker_nav(), false);
print "<p>\n";
print " Are you sure you want to remove the following bugs: ";
$bug_count = count($bugs);
for ($i = 0; $i < $bug_count; $i++)
{
print "<b>" . $bugs[$i] . "</b>";
if ($i < $bug_count - 1)
print ", ";
}
print "</p>\n";
br();
?>
<div align="center">
<form method="post" action="bugtracker.php">
<input type="hidden" name="action" value="removebug" />
<?php
for ($i = 0; $i < $bug_count; $i++)
{
print " <input type=\"hidden\" name=\"bugs[]\" value=\"";
print $bugs[$i] . "\" />\n";
}
?>
<input type="submit" name="confirm" value="Yes" />&nbsp;&nbsp;
<input type="submit" name="confirm" value="No" />
</form>
</div>
<?php
end_section();
}
function display_bugs()
{
global $bug_data_file;
setup_site("Bugs");
start_section("Bugs", build_bug_tracker_nav(), false);
if (!file_exists($bug_data_file))
{
print "<i>None. We're a bug-free Gaim!</i>";
}
else
{
$lines = file($bug_data_file);
$line_count = count($lines);
if ($line_count == 0)
{
print "<i>None. We're a bug-free Gaim!</i>";
}
else
{
?>
<form method="get" action="bugtracker.php">
<input type="hidden" name="action" value="removebug" />
<?php
$table = new Table(array("", "Bug Number", "Description"),
true, true);
$table->set_valignment(0, "top");
$table->set_valignment(1, "top");
$table->set_widths(array("20", "100", "100%"));
for ($i = 0; $i < $line_count; $i++)
{
list($bugnum, $desc) = split("\t", $lines[$i], 2);
$table->add_row(array(
"<input type=\"checkbox\" name=\"bugs[]\" value=\"" .
$bugnum . "\" />",
"<a href=\"http://sourceforge.net/tracker/index.php?" .
"func=detail&aid=" . $bugnum . "&group_id=235&" .
"atid=100235" .
"\">" . $bugnum . "</a>",
$desc
), array(
0,
array("valign" => "top"),
array("valign" => "top")
));
}
$table->output_html();
br();
?>
<div align="right">
<input type="reset" value="Clear Checks" />
<input type="submit" value="Remove Bugs" />&nbsp;&nbsp;
</div>
<?php
}
}
end_section();
}
/* Beginning of the main code */
setup_site(-1);
if (!$users->logged_in() || !$users->is_active_user_admin())
{
header("Location: login.php");
exit;
}
if ($action == "addbug")
{
if (isset($bugnum) && isset($desc))
add_bug($bugnum, $desc);
else
display_add_bug();
}
else if ($action == "removebug")
{
if (isset($confirm))
{
if ($confirm == "Yes")
remove_bugs($bugs);
header("Location: bugtracker.php");
exit;
}
else
display_remove_bugs();
}
else
{
display_bugs();
}
site_shutdown();
?>