= \"$start\"";
}
if(isset($HTTP_GET_VARS['normalize'])){
if(strcmp($HTTP_GET_VARS['normalize'],"true")==0){
$NORMALIZE=1;
}
else{
$NORMALIZE=0;
}
}
else{
$NORMALIZE=0;
}
if(isset($HTTP_GET_VARS['showdata'])){
if(strcmp($HTTP_GET_VARS['showdata'],"true")==0){
$SHOWDATA=1;
}
else{
$SHOWDATA=0;
}
}
else{
$SHOWDATA=0;
}
if(isset($HTTP_GET_VARS['showpoints'])){
if(strcmp($HTTP_GET_VARS['showpoints'],"true")==0){
$SHOWPOINTS=1;
}
else{
$SHOWPOINTS=0;
}
}
else{
$SHOWPOINTS=0;
}
/********************************
*
* printing error image if necessary
*
********************************/
if($URL_ERROR==1){
printErrorMsg("URL Error: $error_msg. Could not draw graph.", $DEBUG);
}
/********************************
*
* creating the graph
*
********************************/
// Callback formatting function for the X-scale to convert timestamps
// to hour and minutes.
function TimeCallback( $aVal) {
return Date ('m-d-y', $aVal);
}
$graph = new Graph($xsize,$ysize);
$graph->SetScale("datelin");
$graph->tabtitle->Set(" $name ");
$graph->xaxis->SetLabelAngle(90);
$graph->SetMargin(50,10,30,110+sizeof($program)*18);
$graph->xaxis->title->Set("");
$graph->xaxis->title->SetMargin(80);
$graph->yaxis->title->Set("");
$graph->yaxis->title->SetMargin(30);
$graph->SetFrame(false);
$graph->SetMarginColor("White");
$graph->legend->SetShadow('gray@0.4',5);
$graph->legend->SetAbsPos($xsize*.2,$ysize-(40+(sizeof($program)*18)),'top','left');
$graph->legend->hide(false);
$graph->ygrid->SetFill(true,'#EFEFEF@0.5','#BBCCFF@0.5');
$graph->xgrid->Show();
$graph->xaxis->scale->SetTimeAlign(MONTHADJ_1);
$graph->xaxis-> SetLabelFormatCallback( 'TimeCallback');
/********************************
*
* executing the query by...
* 1.) finding all the nights associated with the provided machine
* 2.) getting all the correct programs for that night
*
********************************/
$night_table_statement = "SELECT * FROM night WHERE machine=$machine_id ";
if(strcmp($start_query,"")!=0){
$night_table_statement.=" $start_query";
}
if(strcmp($end,"")!=0){
$night_table_statement.=" $end_query";
}
$night_table_statement.=" ORDER BY added DESC";
if($DEBUG){
print "night_table_statement: $night_table_statement
\n";
}
$night_table_query = mysql_query($night_table_statement) or die(mysql_error());
$night_arr=array();
while($row = mysql_fetch_array($night_table_query)){
array_push($night_arr, $row['id']);
}
mysql_free_result($night_table_query);
$data_arr=array();
$line_arr=array();
$color_arr = array("red","blue","green","orange","black", "brown","gray");
$RELEVANT_DATA=0;
$index=0;
foreach ($program as $prog){
$prog=str_replace(" ", "+", $prog);
$program_table_statement="SELECT * FROM program WHERE program=\"$prog\" and (";
$night_id_arr= array();
foreach ($night_arr as $night){
$program_table_statement.=" night=$night or";
if($DEBUG){
print "adding night $night
\n";
}
}
$program_table_statement.=" night=0 ) order by night asc";
if($DEBUG){
print "$program_table_statement
\n";
}
$night_table_query=mysql_query($program_table_statement) or die(mysql_error());
$xdata=array();
$values=array();
$data_max=-1;
$regexp = "/$preg_measure:\s*([0-9\.]+|\?)/";
while($row=mysql_fetch_array($night_table_query)){
$night_id = $row['night'];
$query = mysql_query("select added from night where id=$night_id") or die(mysql_error());
$added = mysql_fetch_array($query);
mysql_free_result($query);
preg_match("/(\d\d\d\d)\-(\d\d)\-(\d\d)\s(\d\d)\:(\d\d)\:(\d\d)/", $added['added'], $pjs);
$seconds = mktime($pjs[4], $pjs[5], $pjs[6], $pjs[2], $pjs[3],$pjs[1]);
if($DEBUG){
print "searching for $regexp
\n";
}
$row['result']=str_replace("
", " ", "{$row['result']}");
preg_match($regexp, "{$row['result']}", $ans);
if(isset($ans[1])){
array_push($values, "$ans[1]");
if(!isset($data_arr["$added"])){
$data_arr["$added"]=array();
}
$RELEVANT_DATA++;
if($DEBUG){
print "{$added['added']}: $ans[1]
\n";
}
if($ans[1]>$data_max){
$data_max=$ans[1];
}
}
else{
array_push($values, "-");
if($DEBUG){
print "{$added['added']}: -
\n";
}
}
array_push($xdata, $seconds);
} #end while
mysql_free_result($night_table_query);
if($NORMALIZE){
for($i=0; $iSetLegend("$prog");
if($SHOWDATA==1){
$line_arr[$index]->value->Show();
}
if($SHOWPOINTS==1){
$line_arr[$index]->mark->SetType(MARK_UTRIANGLE);
}
$color_index=$index % sizeof($color_arr);
$line_arr[$index]->SetColor($color_arr[$color_index]);
$graph->Add($line_arr[$index]);
$index++;
}#end foreach
if($RELEVANT_DATA==0){
printErrorMsg("Error: Graph of $measure contains no data", $DEBUG);
}
if($DEBUG){
print "Finished!
$RELEVANT_DATA
\n";
}
else{
$graph->Stroke();
}
?>