<?php
#Dettaglio inadempienze

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

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

$arr = array(
'P.S.C.' => 0,
'P.O.S.' => 0,
'P.S.S.' => 0,
'Doc. info/formaz.' => 0,
'Libretti/manuali' => 0,
'Reg. infortuni' => 0,
'D.u.v.r.' => 0,
'D.P.I. tipo 1' => 0,
'D.P.I. tipo 2' => 0,
'D.P.I. tipo 3' => 0,
'Ris. chimico' => 0,
'Ris. vibrazioni' => 0,
'Ris. rumore' => 0,
'Pimus' => 0,
'Orario lavoro' => 0,
'Servizi igienici' => 0,
'Spogliatoio/ricovero' => 0,
'Mensa' => 0,
'Cass. pronto socc.' => 0,
'Numeri utili' => 0
);

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

$result = mysql_query($query);
while($row = mysql_fetch_array($result)){
	$row['psc_ido'] == 2 ? $arr['P.S.C.']++ : NULL; 
	$row['pos_ido'] == 2 ? $arr['P.O.S.']++ : NULL; 
	$row['pss_ido'] == 2 ? $arr['P.S.S.']++ : NULL; 
	$row['docinfo_ido'] == 2 ? $arr['Doc info/formaz.']++ : NULL; 
	$row['libretti_ido'] == 2 ? $arr['Libretti/manuali']++ : NULL; 
	$row['reginf_ido'] == 2 ? $arr['Reg. infortuni']++ : NULL; 
	$row['duvri_ido'] == 2 ? $arr['D.u.v.r.']++ : NULL; 
	//$row['dpi1_dist'] == 2 ? $arr['D.P.I. tipo 1']++ : NULL; 
	$row['dpi1_form'] == 2 ? $arr['D.P.I. tipo 1']++ : NULL; 
	//$row['dpi2_dist'] == 2 ? $arr['D.P.I. tipo 3']++ : NULL; 
	$row['dpi2_form'] == 2 ? $arr['D.P.I. tipo 2']++ : NULL; 
	//$row['dpi3_dist'] == 2 ? $arr['Rischio vibrazioni']++ : NULL;  
	$row['dpi3_form'] == 2 ? $arr['D.P.I. tipo 3']++ : NULL; 
	$row['rchimico_ido'] == 2 ? $arr['Ris. chimico']++ : NULL;  
	$row['rvibraz_ido'] == 2 ? $arr['Ris. vibrazioni']++ : NULL; 
	$row['rrumore_ido'] == 2 ? $arr['Ris. rumore']++ : NULL; 
	$row['pimus_ido'] == 2 ? $arr['Pimus']++ : NULL; 
	$row['orario_ido'] == 2 ? $arr['Orario lavoro']++ : NULL; 
	$row['servizi_norma'] == 2 ? $arr['Servizi igienici']++ : NULL; 
	$row['spogliat_norma'] == 2 ? $arr['Spogliatoio/ricovero']++ : NULL; 
	$row['mensa_norma'] == 2 ? $arr['Mensa']++ : NULL; 
	$row['cassetta_norma'] == 2 ? $arr['Cass. pronto socc.']++ : NULL; 
	$row['numeri_norma'] == 2 ? $arr['Numeri utili']++ : NULL; 
}

if(is_array($arr)){
	unset($newarr[$k]);
	foreach($arr as $k=>$v)
		$newarr[$k] = $v;
	
	$arr = $newarr;
	ksort($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",8);
$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,55,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");  
}
// Write the title
$Test->setFontProperties("../classes/graph/Fonts/verdana.ttf",9);
$Test->drawTitle(15,25,"Dettaglio inadempienze ".$zona,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);
//die();
$Test->Render("grafici/04".$dir.str_replace("%","",$type).".png");
?>