Index: trunk/client/temi/Futura2/function_theme.php
===================================================================
--- trunk/client/temi/Futura2/function_theme.php	(revision 418)
+++ trunk/client/temi/Futura2/function_theme.php	(revision 419)
@@ -261,5 +261,5 @@
         		left join ".$prefix."_$tab as t2 on (t1.id_lista=t2.id_lista)
 				where 	t1.id_cons='$id_cons' and t1.id_cons=t2.id_cons
-				group by t2.id_lista
+				group by t1.id_lista, t1.num_lista, t1.descrizione
 				order by somma desc";
 				$res = $dbi->prepare("$sql");
@@ -1094,84 +1094,83 @@
 global $dbi,$circo,$prefix,$id_cons,$genere,$id_circ,$id_comune,$id_cons_gen;
 
-if (isset($circo) and $circo) $circos="and t2.id_circ='$id_circ'";
-else $circos=''; 
-$circos='';
-// numero sezioni scrutinate
-
+	if (isset($circo) and $circo) $circos="and t2.id_circ='$id_circ'";
+	else $circos=''; 
+	$circos='';
+	// numero sezioni scrutinate
 	$sql="select t1.*  from ".$prefix."_ele_sezioni as t1 left join ".$prefix."_ele_sede as t2 on t1.id_sede=t2.id_sede where t1.id_cons='$id_cons'";
 	$res2 = $dbi->prepare("$sql");
 	$res2->execute();
 	$sezioni=$res2->rowCount();
-
     $sql="select orario,data  from ".$prefix."_ele_voti_parziale where id_cons='$id_cons' order  by data desc,orario desc limit 1";
 	$res = $dbi->prepare("$sql");
 	$res->execute();
     if($res){
-
-        while(list($orario,$data) = $res->fetch(PDO::FETCH_NUM)) {
-        	list ($ore,$minuti,$secondi)=explode(':',$orario);
-        	list ($anno,$mese,$giorno)=explode('-',$data);
-        	$tot_v_m=0;$tot_v_d=0;$tot_t=0;
-	
-
-  		$sql="select t3.id_sez from ".$prefix."_ele_voti_parziale as t3 left join ".$prefix."_ele_sezioni as t1 on t3.id_sez=t1.id_sez left join ".$prefix."_ele_sede as t2 on t1.id_sede=t2.id_sede where t3.id_cons='$id_cons' and t3.data='$data' and t3.orario='$orario' group by t3.id_sez ";
-		$res1 = $dbi->prepare("$sql");
-		$res1->execute();
-		$numero=$res1->rowCount();
-	
-		echo "<div style=\"text-align:center;\">Ultime Affluenze<br/>";
-               echo "<b>"._ORE." $ore,$minuti "._DEL."  $giorno/$mese/$anno</b></div>";
-                                                                                                                             
-
-    
-                                                                                                                                      
-$sql="select sum(t3.voti_complessivi), t4.num_gruppo , t4.id_gruppo   from ".$prefix."_ele_voti_parziale as t3 left join ".$prefix."_ele_sezioni as t1 on t3.id_sez=t1.id_sez left join ".$prefix."_ele_sede as t2 on t1.id_sede=t2.id_sede left join ".$prefix."_ele_gruppo as t4 on (t3.id_gruppo=t4.id_gruppo) where t3.id_cons='$id_cons' and t3.orario='$orario' and t3.data='$data' $circos  group by t4.num_gruppo, t4.id_gruppo order by t4.num_gruppo ";		
-	$res1 = $dbi->prepare("$sql");
-	$res1->execute();
-		
-		
-                                                                                                                             
-                while(list($voti_t, $num_gruppo,$id_gruppo) = $res1->fetch(PDO::FETCH_NUM)) {
-
-			$query="select sum(t3.voti_complessivi)  from ".$prefix."_ele_voti_parziale as t3 left join ".$prefix."_ele_sezioni as t1 on t3.id_sez=t1.id_sez left join ".$prefix."_ele_sede as t2 on t1.id_sede=t2.id_sede where t3.id_cons='$id_cons' and t3.data='$data' and t3.orario='$orario' $circos";		
-             if ($genere==0){$query.=" and t3.id_gruppo=$id_gruppo";}
-                	
-			$res_aff = $dbi->prepare("$query");
-			$res_aff->execute();
-			$voti_numero=$res_aff->rowCount();
-              	
-#			$query="select sum(t1.maschi+t1.femmine)  from ".$prefix."_ele_voti_parziale as t3 left join ".$prefix."_ele_sezioni as t1 on t3.id_sez=t1.id_sez left join ".$prefix."_ele_sede as t2 on t1.id_sede=t2.id_sede where t3.id_cons='$id_cons' and t3.data='$data' and t3.orario='$orario' ";	
-
-			$query="SELECT sum(maschi+femmine) FROM ".$prefix."_ele_sezioni as t1, ".$prefix."_ele_sede as t2 where t1.id_cons='$id_cons' and t1.id_sede=t2.id_sede ";
-			
-			//if ($genere==0){$query.=" and t3.id_gruppo=$id_gruppo";}
-			$tot='';
-			$res1234 = $dbi->prepare("$query");
-			$res1234->execute();
-            list($tot)=$res1234->fetch(PDO::FETCH_NUM);
-                	if (isset($tot)){$perc=number_format($voti_t*100/$tot,2);}
-			else{$tot=0;$perc="0.00";}
-			if($voti_t<=$tot){
-	  
-			$resto=100-$perc;
-			if ($genere==0){echo "<div style=\"text-align:center\"><b>Referendum n. $num_gruppo</b></div>";}
-
-			echo "<div style=\"margin:0 auto;width:300px;\"><img src=\"http://chart.apis.google.com/chart?
-			chs=300x200
-			&chd=t:$perc
-			&cht=gom
-			&chl=$perc%
-			&chco=ff0000,ffff00 \"
-			alt=\"Sample chart\" />
-			 
-			</div>";
-
-			}
-
-	}	
-
-        }
-}
-
+		while(list($orario,$data) = $res->fetch(PDO::FETCH_NUM)) {
+			list ($ore,$minuti,$secondi)=explode(':',$orario);
+			list ($anno,$mese,$giorno)=explode('-',$data);
+			$tot_v_m=0;$tot_v_d=0;$tot_t=0;
+			$sql="select t3.id_sez from ".$prefix."_ele_voti_parziale as t3 left join ".$prefix."_ele_sezioni as t1 on t3.id_sez=t1.id_sez left join ".$prefix."_ele_sede as t2 on t1.id_sede=t2.id_sede where t3.id_cons='$id_cons' and t3.data='$data' and t3.orario='$orario' group by t3.id_sez ";
+			$res1 = $dbi->prepare("$sql");
+			$res1->execute();
+			$numero=$res1->rowCount();		
+			echo "<div style=\"text-align:center;\"><br/>Ultime Affluenze<br/>";
+			echo "<b>"._ORE." $ore,$minuti "._DEL."  $giorno/$mese/$anno</b></div>";
+			$sql="select sum(t3.voti_complessivi), t4.num_gruppo , t4.id_gruppo   from ".$prefix."_ele_voti_parziale as t3 left join ".$prefix."_ele_sezioni as t1 on t3.id_sez=t1.id_sez left join ".$prefix."_ele_sede as t2 on t1.id_sede=t2.id_sede left join ".$prefix."_ele_gruppo as t4 on (t3.id_gruppo=t4.id_gruppo) where t3.id_cons='$id_cons' and t3.orario='$orario' and t3.data='$data' $circos  group by t4.num_gruppo, t4.id_gruppo order by t4.num_gruppo ";		
+			$res1 = $dbi->prepare("$sql");
+			$res1->execute();
+			while(list($voti_t, $num_gruppo,$id_gruppo) = $res1->fetch(PDO::FETCH_NUM)) {
+				$query="select sum(t3.voti_complessivi)  from ".$prefix."_ele_voti_parziale as t3 left join ".$prefix."_ele_sezioni as t1 on t3.id_sez=t1.id_sez left join ".$prefix."_ele_sede as t2 on t1.id_sede=t2.id_sede where t3.id_cons='$id_cons' and t3.data='$data' and t3.orario='$orario' $circos";		
+				if ($genere==0){$query.=" and t3.id_gruppo=$id_gruppo";}						
+				$res_aff = $dbi->prepare("$query");
+				$res_aff->execute();
+				$voti_numero=$res_aff->rowCount();					
+	#			$query="select sum(t1.maschi+t1.femmine)  from ".$prefix."_ele_voti_parziale as t3 left join ".$prefix."_ele_sezioni as t1 on t3.id_sez=t1.id_sez left join ".$prefix."_ele_sede as t2 on t1.id_sede=t2.id_sede where t3.id_cons='$id_cons' and t3.data='$data' and t3.orario='$orario' ";	
+				$query="SELECT sum(maschi+femmine) FROM ".$prefix."_ele_sezioni as t1, ".$prefix."_ele_sede as t2 where t1.id_cons='$id_cons' and t1.id_sede=t2.id_sede ";				
+				//if ($genere==0){$query.=" and t3.id_gruppo=$id_gruppo";}
+				$tot='';
+				$res1234 = $dbi->prepare("$query");
+				$res1234->execute();
+				list($tot)=$res1234->fetch(PDO::FETCH_NUM);
+				if (isset($tot)){$perc=number_format($voti_t*100/$tot,2);}
+				else{$tot=0;$perc="0.00";}
+				if($voti_t<=$tot){		  
+					$resto=100-$perc;
+					if ($genere==0){echo "<div style=\"text-align:center\"><b>Referendum n. $num_gruppo</b></div>";}
+					echo '<center>
+					<div id="piechart" style="width:100%; min-height:200px;"></div><br/>
+					</center>
+					<script>google.charts.load("current", {"packages":["corechart"]});
+					google.charts.setOnLoadCallback(drawChart);
+			  
+					function drawChart() {		  
+					  var data = google.visualization.arrayToDataTable([
+						["Task", "Affluenze"],
+						["",  '.$resto.'],
+						["'.$perc.'%", '.$perc.']
+					  ]);
+					  var options = {
+						title: "",
+						is3D:true,
+						 legend: "none",
+						 pieSliceText: "label",
+						 pieSliceTextStyle: {
+							color: "#000",
+							bold:true,
+							fontSize:12
+						  },
+						 slices: {
+							0: { color: "#ff0000", textStyle:{color:"#fff"}},
+							1: { color: "#ffff00" }
+						  }
+					  };
+					  var chart = new google.visualization.PieChart(document.getElementById("piechart"));
+
+					  chart.draw(data, options);
+					}
+					</script>';
+				}
+			}	
+		}
+	}
 }
 
@@ -1184,15 +1183,11 @@
 global $op, $prefix, $offset, $min,$descr_cons,$genere,$votog,$votol,$votoc,$circo, $id_cons,$tipo_cons,$id_comune,$id_cons_gen,$id_circ,$csv,$w,$l,$siteistat,$flash,$tour,$dbi;
 
-
-
-
-if (isset($circo) and $circo) $circos="and t2.id_circ='$id_circ'";
-else $circos=''; 
-$circos='';
-//if ($genere==0) $tab="ref";elseif($genere=='4' || $votog) $tab="lista";
-if($genere=='4' || $votog) $tab="lista";
-		 else $tab="gruppo";
-if ($genere==0) $tab="ref";
-
+	if (isset($circo) and $circo) $circos="and t2.id_circ='$id_circ'";
+	else $circos=''; 
+	$circos='';
+	//if ($genere==0) $tab="ref";elseif($genere=='4' || $votog) $tab="lista";
+	if($genere=='4' || $votog) $tab="lista";
+	else $tab="gruppo";
+	if ($genere==0) $tab="ref";
   	$sql="select t3.id_sez from ".$prefix."_ele_voti_".$tab." as t3 left join ".$prefix."_ele_sezioni as t1 on t3.id_sez=t1.id_sez left join ".$prefix."_ele_sede as t2 on t1.id_sede=t2.id_sede where t3.id_cons='$id_cons' $circos  group by t3.id_sez ";
 	$res = $dbi->prepare("$sql");
@@ -1202,101 +1197,71 @@
 	$res = $dbi->prepare("$sql");
 	$res->execute();
-	$sezioni=$res->rowCount();
-	
+	$sezioni=$res->rowCount();	
 	if ($numero!=0){
-
-	echo "<li data-role=\"list-divider\" data-icon=\"arrow-up\" >";
-	echo "<center><b>"._DETTAGLIO." "._VOTIE."</b></center></li>";
-	echo "<div style=\"text-align:center;\"><i> "._SEZSCRU." $numero "._SU." $sezioni </i></div>";
-	
-
-
-
-	if ($genere!=0) {
-
-	$sql="select sum(t1.maschi+t1.femmine)   from ".$prefix."_ele_sezioni as t1 left join ".$prefix."_ele_sede as t2 on t1.id_sede=t2.id_sede where t1.id_cons='$id_cons' and validi>0 $circos";
-	$res = $dbi->prepare("$sql");
-	$res->execute();
-	list($tot_aventi) = $res->fetch(PDO::FETCH_NUM);
-
-	$sql="select sum(t1.validi+t1.nulli+t1.bianchi+t1.contestati) as tot,
-		sum(t1.validi),sum(t1.nulli),sum(t1.bianchi),sum(t1.contestati), '0', '0', '0'
- 		from ".$prefix."_ele_sezioni as t1 left join ".$prefix."_ele_sede as t2 on t1.id_sede=t2.id_sede where t1.id_cons='$id_cons' and validi>0 $circos";
-	$res = $dbi->prepare("$sql");
-	$res->execute();
-
-	}else{
-	$sql="SELECT sum(maschi+femmine) FROM ".$prefix."_ele_sezioni where id_cons='$id_cons'";
-	$res = $dbi->prepare("$sql");
-	$res->execute();
-	list($tot_aventi) = $res->fetch(PDO::FETCH_NUM);
-	$sql="SELECT  sum(validi+nulli+bianchi+contestati) as tot,
-		sum(validi),sum(nulli),sum(bianchi),sum(contestati), id_gruppo, sum(si), sum(no)
-		from ".$prefix."_ele_voti_ref  where id_cons=$id_cons group by id_gruppo having tot>'0'";
-	$res = $dbi->prepare("$sql");
-	$res->execute();
+		echo "<li data-role=\"list-divider\" data-icon=\"arrow-up\" >";
+		echo "<center><b>"._DETTAGLIO." "._VOTIE."</b></center></li>";
+		echo "<div style=\"text-align:center;\"><i> "._SEZSCRU." $numero "._SU." $sezioni </i></div>";
+		if ($genere!=0) {
+			$sql="select sum(t1.maschi+t1.femmine)   from ".$prefix."_ele_sezioni as t1 left join ".$prefix."_ele_sede as t2 on t1.id_sede=t2.id_sede where t1.id_cons='$id_cons' and validi>0 $circos";
+			$res = $dbi->prepare("$sql");
+			$res->execute();
+			list($tot_aventi) = $res->fetch(PDO::FETCH_NUM);
+			$sql="select sum(t1.validi+t1.nulli+t1.bianchi+t1.contestati) as tot,
+				sum(t1.validi),sum(t1.nulli),sum(t1.bianchi),sum(t1.contestati), '0', '0', '0'
+				from ".$prefix."_ele_sezioni as t1 left join ".$prefix."_ele_sede as t2 on t1.id_sede=t2.id_sede where t1.id_cons='$id_cons' and validi>0 $circos";
+			$res = $dbi->prepare("$sql");
+			$res->execute();
+		}else{
+			$sql="SELECT sum(maschi+femmine) FROM ".$prefix."_ele_sezioni where id_cons='$id_cons'";
+			$res = $dbi->prepare("$sql");
+			$res->execute();
+			list($tot_aventi) = $res->fetch(PDO::FETCH_NUM);
+			$sql="SELECT  sum(validi+nulli+bianchi+contestati) as tot,
+				sum(validi),sum(nulli),sum(bianchi),sum(contestati), id_gruppo, sum(si), sum(no)
+				from ".$prefix."_ele_voti_ref  where id_cons=$id_cons group by id_gruppo having tot>'0'";
+			$res = $dbi->prepare("$sql");
+			$res->execute();
+		}
+		while (list($tot_votanti,$validi,$nulli,$bianchi,$contestati,$id,$si,$no) = $res->fetch(PDO::FETCH_NUM)){
+			$tot_votanti=$validi+$bianchi+$nulli+$contestati;
+			$arvoti=array($validi,$nulli,$bianchi,$contestati);
+			$arperc=arrayperc($arvoti,$tot_votanti);
+			if($tot_votanti){
+				if($genere==0 and $validi) {$perc_si=number_format($si*100/$validi,2);$perc_no=number_format(100 - $si*100/$validi,2);}
+				else {$perc_si="0.00"; $perc_no="0.00";}
+				$perc_validi=number_format($arperc[0],2);#number_format($validi*100/$tot_votanti,2);
+				$perc_nulli=number_format($arperc[1],2);
+				$perc_bianchi=number_format($arperc[2],2);
+				$perc_conte=number_format($arperc[3],2);
+			}else{$perc_validi="0.00";$perc_nulli="0.00";$perc_bianchi="0.00";$perc_conte="0.00";}
+			if($tot_aventi) $perc_votanti=number_format($tot_votanti*100/$tot_aventi,2);
+			else $perc_votanti="0.00";
+			$non_votanti=($tot_aventi - $tot_votanti);
+			$perc_non=100-$perc_votanti;
+			if ($genere==0) {
+				$sql="SELECT num_gruppo,descrizione from ".$prefix."_ele_gruppo where id_gruppo=$id";
+				$resg = $dbi->prepare("$sql");
+				$resg->execute();
+				list($num_gruppo,$descr_gruppo)  = $resg->fetch(PDO::FETCH_NUM);
+			}
+			echo "<li><table bgcolor=\"gray\" width=\"100%\" cellspacing=\"1\">";
+			if ($genere==0) {echo "<br/>Referendum n. <b>[$num_gruppo]</b><br/>";}
+			echo "
+			<tr bgcolor=\"#ffffff\"><td ><b>"._AVENTI."</b></td><td align=\"right\">$tot_aventi</td><td align=\"right\"><span class=\"red\">100.00%</span></td></tr>
+
+			<tr bgcolor=\"#ffffff\"><td><b>"._VOTANTI."</b></td><td align=\"right\">$tot_votanti</td><td align=\"right\"><span class=\"red\">$perc_votanti%</span></td></tr>";
+			if ($genere==0){		
+				echo "<tr bgcolor=\"#ffffff\"><td>"._SI."</td><td align=\"right\">$si</td><td align=\"right\"><span class=\"red\">$perc_si%</span></td></tr>
+				<tr bgcolor=\"#ffffff\"><td>"._NO."</td><td align=\"right\">$no</td><td align=\"right\"><span class=\"red\">$perc_no%</span></td></tr>";
+			}
+			echo "<tr bgcolor=\"#ffffff\"><td>"._VALIDI."</td><td align=\"right\">$validi</td><td align=\"right\"><span class=\"red\">$perc_validi%</span></td></tr>
+			<tr bgcolor=\"#ffffff\"><td>"._NULLI."</td><td align=\"right\">$nulli</td><td align=\"right\"><span class=\"red\">$perc_nulli%</span></td></tr>
+			<tr bgcolor=\"#ffffff\"><td>"._BIANCHI."</td><td align=\"right\">$bianchi</td><td align=\"right\"><span class=\"red\">$perc_bianchi%</span></td></tr>
+			<tr bgcolor=\"#ffffff\"><td>"._CONTESTATI."</td><td align=\"right\">$contestati</td><td align=\"right\"><span class=\"red\">$perc_conte%</span></td></tr>
+			</table></li>";
+		}
 	}
-
-	while (list($tot_votanti,$validi,$nulli,$bianchi,$contestati,$id,$si,$no) = $res->fetch(PDO::FETCH_NUM)){
-		$tot_votanti=$validi+$bianchi+$nulli+$contestati;
-		$arvoti=array($validi,$nulli,$bianchi,$contestati);
-		$arperc=arrayperc($arvoti,$tot_votanti);
-		if($tot_votanti){
-			if($genere==0 and $validi) {$perc_si=number_format($si*100/$validi,2);$perc_no=number_format(100 - $si*100/$validi,2);}
-			else {$perc_si="0.00"; $perc_no="0.00";}
-		$perc_validi=number_format($arperc[0],2);#number_format($validi*100/$tot_votanti,2);
-		$perc_nulli=number_format($arperc[1],2);
-		$perc_bianchi=number_format($arperc[2],2);
-		$perc_conte=number_format($arperc[3],2);
-		}else {$perc_validi="0.00";$perc_nulli="0.00";$perc_bianchi="0.00";$perc_conte="0.00";}
-		if($tot_aventi)
-			$perc_votanti=number_format($tot_votanti*100/$tot_aventi,2);
-		else $perc_votanti="0.00";
-		$non_votanti=($tot_aventi - $tot_votanti);
-		$perc_non=100-$perc_votanti;
-
-		if ($genere==0) {
-			$sql="SELECT num_gruppo,descrizione from ".$prefix."_ele_gruppo where id_gruppo=$id";
-	$resg = $dbi->prepare("$sql");
-	$resg->execute();
-			list($num_gruppo,$descr_gruppo)  = $resg->fetch(PDO::FETCH_NUM);
-		}
-		  
-
-		    
-		
-		echo "<li><table bgcolor=\"gray\" width=\"100%\" cellspacing=\"1\">";
-		if ($genere==0) {echo "<br/>Referendum n. <b>[$num_gruppo]</b><br/>";}
-		echo "
-		<tr bgcolor=\"#ffffff\"><td ><b>"._AVENTI."</b></td><td align=\"right\">$tot_aventi</td><td align=\"right\"><span class=\"red\">100.00%</span></td></tr>
-
-		<tr bgcolor=\"#ffffff\"><td><b>"._VOTANTI."</b></td><td align=\"right\">$tot_votanti</td><td align=\"right\"><span class=\"red\">$perc_votanti%</span></td></tr>";
-	if ($genere==0){		
-		echo "<tr bgcolor=\"#ffffff\"><td>"._SI."</td><td align=\"right\">$si</td><td align=\"right\"><span class=\"red\">$perc_si%</span></td></tr>
-		
-		<tr bgcolor=\"#ffffff\"><td>"._NO."</td><td align=\"right\">$no</td><td align=\"right\"><span class=\"red\">$perc_no%</span></td></tr>";
-		}
-		echo "<tr bgcolor=\"#ffffff\"><td>"._VALIDI."</td><td align=\"right\">$validi</td><td align=\"right\"><span class=\"red\">$perc_validi%</span></td></tr>
-		
-		<tr bgcolor=\"#ffffff\"><td>"._NULLI."</td><td align=\"right\">$nulli</td><td align=\"right\"><span class=\"red\">$perc_nulli%</span></td></tr>
-		
-		<tr bgcolor=\"#ffffff\"><td>"._BIANCHI."</td><td align=\"right\">$bianchi</td><td align=\"right\"><span class=\"red\">$perc_bianchi%</span></td></tr>
-		
-		<tr bgcolor=\"#ffffff\"><td>"._CONTESTATI."</td><td align=\"right\">$contestati</td><td align=\"right\"><span class=\"red\">$perc_conte%</span></td></tr>
-
-		</table></li>";
-
-    }
-}
-}
-
-
-
+}
 ######## fine
-
-
-
-
-
 
 ####################################
@@ -1330,6 +1295,6 @@
 		# numero sezioni
 		$sql="select t1.id_sez,t1.num_sez  from ".$prefix."_ele_sezioni as t1 left join ".$prefix."_ele_sede as t2 on t1.id_sede=t2.id_sede where t1.id_cons='$id_cons' $circos order by t1.num_sez";
-	$res = $dbi->prepare("$sql");
-	$res->execute();
+		$res = $dbi->prepare("$sql");
+		$res->execute();
 		$max = $res->rowCount();
 		if(!isset($html)) $html='';
