<?php
#Visite positive / negative

include("../sessionreserved.php");
include("../../db.php");

#notifiche 
if($type){
	$zona = "(".$type.")";
	$user = $type;
}else{
	$user = '%';
	$zona = "";
}

$arr = array('Negative' => 0,'Positive' => 0);

$query = "SELECT * FROM visite
LEFT JOIN users ON visite.userid = users.userid
WHERE users.zona LIKE '".$user."'
AND users.dir = '".$_SESSION['dir']."'
AND datavisita >= '".$dal."' AND datavisita <= '".$al."'";

$result = mysql_query($query);
while($row = mysql_fetch_array($result)){
$no = false;

$row['psc_ido'] == 2 ? $no=true : NULL; 
$row['pos_ido'] == 2 ? $no=true : NULL; 
$row['pss_ido'] == 2 ? $no=true : NULL; 
$row['docinfo_ido'] == 2 ? $no=true : NULL; 
$row['libretti_ido'] == 2 ? $no=true : NULL; 
$row['reginf_ido'] == 2 ? $no=true : NULL; 
$row['duvri_ido'] == 2 ? $no=true : NULL; 
$row['dpi1_form'] == 2 ? $no=true : NULL; 
$row['dpi2_form'] == 2 ? $no=true : NULL; 
$row['dpi3_form'] == 2 ? $no=true : NULL; 
$row['rchimico_ido'] == 2 ? $no=true : NULL;  
$row['rvibraz_ido'] == 2 ? $no=true : NULL; 
$row['rrumore_ido'] == 2 ? $no=true : NULL; 
$row['pimus_ido'] == 2 ?$no=true : NULL; 
$row['orario_ido'] == 2 ? $no=true : NULL; 
$row['servizi_norma'] == 2 ? $no=true : NULL; 
$row['spogliat_norma'] == 2 ? $no=true : NULL; 
$row['mensa_norma'] == 2 ? $no=true : NULL; 
$row['cassetta_norma'] == 2 ? $no=true : NULL; 
$row['numeri_norma'] == 2 ? $no=true : NULL; 

$no ?  $arr['Negative'] ++ : $arr['Positive'] ++;
}

$tot_visite = array_sum($arr);

arsort($arr);



// Dataset definition 
$DataSet = new pData;
if(is_array($arr)){
	
	
	
	$DataSet->AddPoint($arr,"Serie1");
	$DataSet->AddPoint(array_keys($arr),"Serie2");
	$DataSet->AddAllSeries();
	$DataSet->SetAbsciseLabelSerie("Serie2");
	$DataSet->RemoveSerie("Serie2");
	
}

// Initialise the graph
$width = 500;
$height = 300;

 $Test = new pChart($width,$height);
$Test->setColorPalette(0,22,89,160);  

$Test->setFontProperties("../classes/graph/Fonts/tahoma.ttf",9);
$Test->setGraphArea(50,60,450,200);
$Test->drawFilledRoundedRectangle(7,7,$width-7,$height-7,5,240,240,240);
$Test->drawRoundedRectangle(5,5,$width-5,$height-5,5,230,230,230);
$Test->drawGraphArea(255,255,255,TRUE);
if(is_array($arr)){
	$Test->drawScale($DataSet->GetData(),$DataSet->GetDataDescription(),SCALE_ADDALLSTART0,10,10,10,TRUE,0,0,TRUE);
	$Test->drawGrid(4,TRUE,230,230,230,50);

	// Draw the bar graph
	$Test->drawOverlayBarGraph($DataSet->GetData(),$DataSet->GetDataDescription());
	$Test->writeValues($DataSet->GetData(),$DataSet->GetDataDescription(),"Serie1");  
}



/*
// Dataset definition 
$DataSet = new pData;

$DataSet->AddPoint($arr,"Serie1");
$DataSet->AddPoint(array_keys($arr),"Serie2");
$DataSet->AddAllSeries();
$DataSet->SetAbsciseLabelSerie("Serie2");

$width = 500;
$height = 300;

 // Initialise the graph
 $Test = new pChart($width,$height);
$Test->setColorPalette(0,22,89,160);  

$Test->setFontProperties("../classes/graph/Fonts/verdana.ttf",8);
$Test->drawFilledRoundedRectangle(7,7,$width-7,$height-7,5,240,240,240);
$Test->drawRoundedRectangle(5,5,$width-5,$height-5,5,230,230,230);

// Draw the pie chart
$Test->AntialiasQuality = 0;
$Test->setShadowProperties(2,2,200,200,200);
$Test->drawFlatPieGraphWithShadow($DataSet->GetData(),$DataSet->GetDataDescription(),190,155,80,PIE_PERCENTAGE_LABEL,8);
$Test->clearShadow();

$Test->drawPieLegend($width-130,15,$DataSet->GetData(),$DataSet->GetDataDescription(),250,250,250);
*/
// Write the title
$Test->setFontProperties("../classes/graph/Fonts/verdana.ttf",9);
$Test->drawTitle(15,25,"Visite positive / negative",0,0,0,true);

$Test->setFontProperties("../classes/graph/Fonts/verdana.ttf",8);
//sottotitolo
//$Test->drawTextBox(14,30,150,45,"Territorio: ".$committente."      Notifiche totali: ".$totale ,0,160,160,160,ALIGN_LEFT,FALSE);
$Test->Render("grafici/03".str_replace("%","",$type).".png");
?>