SetScale("lin");
//$graph->SetScale("textlin");
$graph->SetScale("loglin");
// Create the linear plot
$lineplot=new BarPlot($arr, $xarr);
$lineplot->SetColor("blue");
// Add the plot to the graph
$graph->Add($lineplot);
// Display the graph
$graph->Stroke();
}
function show_text($xarr, $yarr) {
$n = sizeof($xarr);
for ($i=0; $i<$n; $i++) {
echo "
$xarr[$i] $yarr[$i]\n";
}
}
function show_graph() {
require_once("../inc/db.inc");
db_init();
$xaxis = $_GET['xaxis'];
$yaxis = $_GET['yaxis'];
$granularity = $_GET['granularity'];
$active = $_GET['active'];
$inactive = $_GET['inactive'];
$show_text = $_GET['show_text'];
if (!$active && !$inactive) {
echo "You must select at least one of (active, inactive)";
exit();
}
$fields = 'host.id, user.create_time';
if ($xaxis == 'active' || !$active || !$inactive) {
$query = "select $fields, max(rpc_time) as max_rpc_time from host, user where host.userid=user.id group by userid";
} else {
$query = 'select $fields from user';
}
$result = mysql_query($query);
$yarr = array();
$now = time();
$maxind = 0;
$active_thresh = time() - 30*86400;
while ($user = mysql_fetch_object($result)) {
$val = $now - $user->max_rpc_time;
if (!$active) {
if ($user->max_rpc_time > $active_thresh) continue;
}
if (!$inactive) {
if ($user->max_rpc_time < $active_thresh) continue;
}
$life = $user->max_rpc_time - $user->create_time;
$ind = $life/$granularity;
$ind = (int)$ind;
$yarr[$ind]++;
if ($ind > $maxind) $maxind = $ind;
}
$xarr = array();
for ($i=0; $i<=$maxind; $i++) {
$xarr[$i] = $i;
if (is_null($yarr[$i])) $yarr[$i]=0;
}
if ($show_text) {
show_text($xarr, $yarr);
} else {
draw_graph($xarr, $yarr);
}
}
function show_form() {
echo "