Index: trunk/admin/modules/Elezioni/ele_riepilogo.php
===================================================================
--- trunk/admin/modules/Elezioni/ele_riepilogo.php	(revision 254)
+++ trunk/admin/modules/Elezioni/ele_riepilogo.php	(revision 257)
@@ -14,7 +14,6 @@
     die ("You can't access this file directly...");
 }
-
+global $dbi;
 $aid=$_SESSION['aid'];
-$dbi=$_SESSION['dbi'];
 $prefix=$_SESSION['prefix'];
 $currentlang=$_SESSION['lang'];
@@ -26,8 +25,12 @@
 $perms=ChiSei($id_cons_gen);
 if ($perms<16 or !$id_cons_gen) die("$perms Non hai i permessi per inserire dati, o non hai scelto la consultazione!");
-$res = mysql_query("SELECT t1.tipo_cons,t2.id_cons,t2.solo_gruppo,t2.disgiunto FROM ".$prefix."_ele_consultazione as t1, ".$prefix."_ele_cons_comune as t2 where t1.id_cons_gen=t2.id_cons_gen and t2.id_cons_gen='$id_cons_gen' and t2.id_comune='$id_comune'" , $dbi);
-list($tipo_cons,$id_cons,$dettnulli,$disgiunto) = mysql_fetch_row($res);
-$res = mysql_query("SELECT genere,voto_g,voto_l FROM ".$prefix."_ele_tipo where tipo_cons='$tipo_cons' " , $dbi);
-	list($genere,$votog,$votol) = mysql_fetch_row($res);
+$sql="SELECT t1.tipo_cons,t2.id_cons,t2.solo_gruppo,t2.disgiunto FROM ".$prefix."_ele_consultazione as t1, ".$prefix."_ele_cons_comune as t2 where t1.id_cons_gen=t2.id_cons_gen and t2.id_cons_gen='$id_cons_gen' and t2.id_comune='$id_comune'";
+$res = $dbi->prepare("$sql");
+$res->execute();	
+list($tipo_cons,$id_cons,$dettnulli,$disgiunto) = $res->fetch(PDO::FETCH_NUM);
+$sql="SELECT genere,voto_g,voto_l FROM ".$prefix."_ele_tipo where tipo_cons='$tipo_cons' ";
+$res = $dbi->prepare("$sql");
+$res->execute();	
+list($genere,$votog,$votol) = $res->fetch(PDO::FETCH_NUM);
 
 include("modules/Elezioni/funzionidata.php");
@@ -43,57 +46,70 @@
 //**************************************************************************
  
-    global $prefix, $dbi,$fascia,$limite,$genere,$votog;
-	$res = mysql_query("SELECT sum(maschi),sum(femmine) FROM ".$prefix."_ele_sezioni where id_cons='$id_cons'", $dbi);
-	list($totm,$totf) = mysql_fetch_row($res);
-	$totel=$totm+$totf;
-	$res = mysql_query("SELECT data,orario FROM ".$prefix."_ele_rilaff where id_cons_gen=$id_cons_gen order by data desc, orario desc limit 0,1", $dbi);
-	list($giorno,$ora)=mysql_fetch_row($res);
-	$res = mysql_query("SELECT sum(voti_donne),sum(voti_uomini),sum(voti_complessivi) FROM ".$prefix."_ele_voti_parziale where id_cons='$id_cons' and data='$giorno' and orario='$ora'", $dbi);
-	list($votf,$votm,$votc) = mysql_fetch_row($res);
+global $prefix, $dbi,$fascia,$limite,$genere,$votog;
+$sql="SELECT sum(maschi),sum(femmine) FROM ".$prefix."_ele_sezioni where id_cons='$id_cons'";
+$res = $dbi->prepare("$sql");
+$res->execute();	
+list($totm,$totf) = $res->fetch(PDO::FETCH_NUM);
+$totel=$totm+$totf;
+$sql="SELECT data,orario FROM ".$prefix."_ele_rilaff where id_cons_gen=$id_cons_gen order by data desc, orario desc limit 0,1";
+$res = $dbi->prepare("$sql");
+$res->execute();	
+list($giorno,$ora)=$res->fetch(PDO::FETCH_NUM);
+$sql="SELECT sum(voti_donne),sum(voti_uomini),sum(voti_complessivi) FROM ".$prefix."_ele_voti_parziale where id_cons='$id_cons' and data='$giorno' and orario='$ora'";
+$res = $dbi->prepare("$sql");
+$res->execute();	
+list($votf,$votm,$votc) = $res->fetch(PDO::FETCH_NUM);
 if($genere!=0){	
-$res = mysql_query("SELECT sum(solo_gruppo),sum(validi),sum(nulli),sum(bianchi),sum(contestati), sum(voti_nulli),sum(validi_lista),sum(voti_nulli_lista),sum(contestati_lista),sum(solo_lista) FROM ".$prefix."_ele_sezioni where id_cons=$id_cons", $dbi);
-	list($sg,$validi,$nulli,$bianchi,$contestati,$votinulli,$validilista,$nullilista,$contestatilista,$sl)=mysql_fetch_row($res);
+	$sql="SELECT sum(solo_gruppo),sum(validi),sum(nulli),sum(bianchi),sum(contestati), sum(voti_nulli),sum(validi_lista),sum(voti_nulli_lista),sum(contestati_lista),sum(solo_lista) FROM ".$prefix."_ele_sezioni where id_cons=$id_cons";
+	$res = $dbi->prepare("$sql");
+	$res->execute();	
+	list($sg,$validi,$nulli,$bianchi,$contestati,$votinulli,$validilista,$nullilista,$contestatilista,$sl)=$res->fetch(PDO::FETCH_NUM);
 	echo "<center>";
 	echo "<fieldset><legend>"._VOTANTI."</legend>";
 	echo "<table border=\"1\" width=\"100%\"><tr><th>"._ISCRITTI."</TH><TH>"._UOMINI."</TH><TH>"._DONNE."</TH><TH>"._VOTIU."</TH><TH>"._VOTID."</TH><TH>"._VOTIE."</TH></TR>";
 	ECHO "<TR><TH>".number_format($totel,0,',','.')."</TH><TH>".number_format($totm,0,',','.')."</TH><TH>".number_format($totf,0,',','.')."</TH><TH>".number_format($votm,0,',','.')."</TH><TH>".number_format($votf,0,',','.')."</TH><TH>".number_format($votc,0,',','.')."</TH></TR></table><br/>";
-	ECHO "</fieldset><br/><br/><br/>";
-	
-	
+	ECHO "</fieldset><br/><br/><br/>";	
 	$totnulli=$nulli+$bianchi+$contestati+$votinulli;
 	if ($votog) echo "<fieldset><legend>"._VOTI_LISTA."</legend>";
-	else echo "<fieldset><legend>"._GRUPPO."</legend>";
-	
+	else echo "<fieldset><legend>"._GRUPPO."</legend>";	
 	echo "<table border=\"1\" width=\"100%\"><tr><th><b>"._VALIDI."</b></th><th>"._NULLI."</th><th>"._BIANCHI."</th><th>"._CONTESTATI."</th><th>"._VOTINULLI."</th><th>"._TOTNON."</th></TR>";
 	ECHO "<TR><TH>".number_format($validi,0,',','.')."</TH><TH>".number_format($nulli,0,',','.')."</TH><TH>".number_format($bianchi,0,',','.')."</TH><TH>".number_format($contestati,0,',','.')."</TH><TH>".number_format($votinulli,0,',','.')."</TH><TH>".number_format($totnulli,0,',','.')."</TH></TR></table><br/>";
+	ECHO "</fieldset><br/><br/><br/>";
+}else{
+	$sql="SELECT sum(si),sum(no),sum(validi),sum(nulli),sum(bianchi),sum(contestati),id_gruppo FROM ".$prefix."_ele_voti_ref where id_cons='$id_cons' group by id_gruppo";
+	$res = $dbi->prepare("$sql");
+	$res->execute();	
+	while (list($si,$no,$validi,$nulli,$bianchi,$contestati,$idg) = $res->fetch(PDO::FETCH_NUM)){	
+		$sql="SELECT num_gruppo,descrizione from ".$prefix."_ele_gruppo where id_gruppo='$idg'", $dbi);
+		$resref = $dbi->prepare("$sql");
+		$resref->execute();	
+		list($numgruppo,$descrizione) = mysql_fetch_row($resref);
+		echo "<fieldset><legend>"._GRUPPO."N. $numgruppo - $descrizione</legend>";
+		echo "<table border=\"1\" width=\"100%\"><tr><th><b> "._SI." </b></th><th><b>"._NO."</b></th><th><b>"._VALIDI."</b></th><th>"._NULLI."</th><th>"._BIANCHI."</th><th>"._CONTESTATI."</th><th>"._TOTNON."</th></TR>";
+		ECHO "<TR><TH>".number_format($si,0,',','.')."</TH><TH>".number_format($no,0,',','.')."</TH><TH>".number_format($validi,0,',','.')."</TH><TH>".number_format($nulli,0,',','.')."</TH><TH>".number_format($bianchi,0,',','.')."</TH><TH>".number_format($contestati,0,',','.')."</TH><TH>".number_format($nulli+$bianchi+$contestati,0,',','.')."</TH></TR></table><br/>";
+	# votanti-------------- <th><b>"._GRUPPO."</b></th><th><b>"._DESCR."</b></th> --- <TH>".$numgruppo."</TH><TH>".$descrizione."</TH>
+		$sql="SELECT sum(voti_donne),sum(voti_uomini),sum(voti_complessivi) FROM ".$prefix."_ele_voti_parziale where id_cons='$id_cons' and data='$giorno' and orario='$ora' and id_gruppo='$idg'";
+$resv = $dbi->prepare("$sql");
+$resv->execute();	
+		list($votf,$votm,$votc) = $resv->fetch(PDO::FETCH_NUM);
+
+		echo "<fieldset><legend>"._VOTANTI."</legend>";
+		echo "<table border=\"1\" width=\"100%\"><tr><th>"._ISCRITTI."</TH><TH>"._UOMINI."</TH><TH>"._DONNE."</TH><TH>"._VOTIU."</TH><TH>"._VOTID."</TH><TH>"._VOTIE."</TH></TR>";
+		ECHO "<TR><TH>".number_format($totel,0,',','.')."</TH><TH>".number_format($totm,0,',','.')."</TH><TH>".number_format($totf,0,',','.')."</TH><TH>".number_format($votm,0,',','.')."</TH><TH>".number_format($votf,0,',','.')."</TH><TH>".number_format($votc,0,',','.')."</TH></TR></table>";
+		ECHO "</fieldset><br/>";
 		ECHO "</fieldset><br/><br/><br/>";
-	}else{
-	$res = mysql_query("SELECT sum(si),sum(no),sum(validi),sum(nulli),sum(bianchi),sum(contestati),id_gruppo FROM ".$prefix."_ele_voti_ref where id_cons='$id_cons' group by id_gruppo", $dbi);
-		while (list($si,$no,$validi,$nulli,$bianchi,$contestati,$idg) = mysql_fetch_row($res)){	
-			$resref = mysql_query("SELECT num_gruppo,descrizione from ".$prefix."_ele_gruppo where id_gruppo='$idg'", $dbi);
-			list($numgruppo,$descrizione) = mysql_fetch_row($resref);
-			echo "<fieldset><legend>"._GRUPPO."N. $numgruppo - $descrizione</legend>";
-			echo "<table border=\"1\" width=\"100%\"><tr><th><b> "._SI." </b></th><th><b>"._NO."</b></th><th><b>"._VALIDI."</b></th><th>"._NULLI."</th><th>"._BIANCHI."</th><th>"._CONTESTATI."</th><th>"._TOTNON."</th></TR>";
-			ECHO "<TR><TH>".number_format($si,0,',','.')."</TH><TH>".number_format($no,0,',','.')."</TH><TH>".number_format($validi,0,',','.')."</TH><TH>".number_format($nulli,0,',','.')."</TH><TH>".number_format($bianchi,0,',','.')."</TH><TH>".number_format($contestati,0,',','.')."</TH><TH>".number_format($nulli+$bianchi+$contestati,0,',','.')."</TH></TR></table><br/>";
-		# votanti-------------- <th><b>"._GRUPPO."</b></th><th><b>"._DESCR."</b></th> --- <TH>".$numgruppo."</TH><TH>".$descrizione."</TH>
-			$resv = mysql_query("SELECT sum(voti_donne),sum(voti_uomini),sum(voti_complessivi) FROM ".$prefix."_ele_voti_parziale where id_cons='$id_cons' and data='$giorno' and orario='$ora' and id_gruppo='$idg'", $dbi);
-			list($votf,$votm,$votc) = mysql_fetch_row($resv);
 
-			echo "<fieldset><legend>"._VOTANTI."</legend>";
-			echo "<table border=\"1\" width=\"100%\"><tr><th>"._ISCRITTI."</TH><TH>"._UOMINI."</TH><TH>"._DONNE."</TH><TH>"._VOTIU."</TH><TH>"._VOTID."</TH><TH>"._VOTIE."</TH></TR>";
-			ECHO "<TR><TH>".number_format($totel,0,',','.')."</TH><TH>".number_format($totm,0,',','.')."</TH><TH>".number_format($totf,0,',','.')."</TH><TH>".number_format($votm,0,',','.')."</TH><TH>".number_format($votf,0,',','.')."</TH><TH>".number_format($votc,0,',','.')."</TH></TR></table>";
-			ECHO "</fieldset><br/>";
-			ECHO "</fieldset><br/><br/><br/>";
-
-		#-----------			
-		}
+	#-----------			
 	}
+}
 	
-	if ($genere==5 and !$votog) {
-	$totnullil=$nullilista+$contestatilista;
-	$id_conf=0;
-	$res = mysql_query("SELECT t1.id_conf,t1.id_fascia, t2.limite, t1.solo_gruppo from ".$prefix."_ele_cons_comune as t1 left join ".$prefix."_ele_conf as t2 on t1.id_conf=t2.id_conf where t1.id_cons='$id_cons'", $dbi);
-	if($res) list($id_conf,$fascia,$limite,$dettnulli) = mysql_fetch_row($res);
-	if ($id_conf and $fascia<=$limite) {
+if ($genere==5 and !$votog) {
+$totnullil=$nullilista+$contestatilista;
+$id_conf=0;
+$sql="SELECT t1.id_conf,t1.id_fascia, t2.limite, t1.solo_gruppo from ".$prefix."_ele_cons_comune as t1 left join ".$prefix."_ele_conf as t2 on t1.id_conf=t2.id_conf where t1.id_cons='$id_cons'";
+$res = $dbi->prepare("$sql");
+$res->execute();	
+if($res->rowCount()) list($id_conf,$fascia,$limite,$dettnulli) = $res->fetch(PDO::FETCH_NUM);
+if ($id_conf and $fascia<=$limite) {
 	echo "<fieldset><legend>"._VOTI_LISTA."</legend>";
 	echo "<table border=\"1\" width=\"100%\"><tr><th><b>"._VALIDI."</b></th><th>"._NULLI."</th><th>"._BIANCHI."</th><th>"._CONTESTATI."</th><th>"._VOTINULLI."</th><th>"._TOTNON."</th></TR>";
@@ -101,36 +117,39 @@
 	ECHO "</fieldset><br/><br/><br/>";
 	
-	}else{
+}else{
 	if ($dettnulli or $disgiunto){ 
-			$res = mysql_query("SELECT id_gruppo,num_gruppo,descrizione from ".$prefix."_ele_gruppo where id_cons='$id_cons' order by num_gruppo", $dbi);
-
-	echo "<fieldset><legend>"._GRUPPO."</legend>";
-	echo "<table border=\"1\" width=\"100%\"><tr><th colspan=\"2\" rowspan=\"2\" ALIGN=\"CENTER\"><b>Candidato</b></th><th rowspan=\"2\" ALIGN=\"CENTER\">"._VALIDI."</th><th colspan=\"2\" ALIGN=\"CENTER\">"._SOLO_GRUPPO."</th></tr><tr><th ALIGN=\"CENTER\">Senza indicazione di lista</th>";
-	if ($disgiunto) echo "<th>"._SOLOLIS."</th>"; else echo "<th>"._VOTINULLI." di Lista</th>";
-	echo "</TR>";
-	$t_voti=0;$t_solo_gruppo=0;$t_nulli_lista=0;
-	while(list($id_gruppo,$num_gruppo,$desc) = mysql_fetch_row($res)){
-		$resv = mysql_query("SELECT sum(voti),sum(solo_gruppo) from ".$prefix."_ele_voti_gruppo where id_gruppo='$id_gruppo'", $dbi);
-		list($voti,$solo_gruppo)=mysql_fetch_row($resv);
-		if($disgiunto){
-			$resv = mysql_query("SELECT sum(t1.solo_lista) from ".$prefix."_ele_voti_lista as t1 left join ".$prefix."_ele_lista as t2 on t1.id_lista=t2.id_lista where t2.id_gruppo='$id_gruppo'", $dbi);		
-		}else{
-			$resv = mysql_query("SELECT sum(t1.nulli_lista) from ".$prefix."_ele_voti_lista as t1 left join ".$prefix."_ele_lista as t2 on t1.id_lista=t2.id_lista where t2.id_gruppo='$id_gruppo'", $dbi);
+		$sql="SELECT id_gruppo,num_gruppo,descrizione from ".$prefix."_ele_gruppo where id_cons='$id_cons' order by num_gruppo";
+		$res = $dbi->prepare("$sql");
+		$res->execute();	
+		echo "<fieldset><legend>"._GRUPPO."</legend>";
+		echo "<table border=\"1\" width=\"100%\"><tr><th colspan=\"2\" rowspan=\"2\" ALIGN=\"CENTER\"><b>Candidato</b></th><th rowspan=\"2\" ALIGN=\"CENTER\">"._VALIDI."</th><th colspan=\"2\" ALIGN=\"CENTER\">"._SOLO_GRUPPO."</th></tr><tr><th ALIGN=\"CENTER\">Senza indicazione di lista</th>";
+		if ($disgiunto) echo "<th>"._SOLOLIS."</th>"; else echo "<th>"._VOTINULLI." di Lista</th>";
+		echo "</TR>";
+		$t_voti=0;$t_solo_gruppo=0;$t_nulli_lista=0;
+		while(list($id_gruppo,$num_gruppo,$desc) = $res->fetch(PDO::FETCH_NUM)){
+			$sql="SELECT sum(voti),sum(solo_gruppo) from ".$prefix."_ele_voti_gruppo where id_gruppo='$id_gruppo'";
+			$resv = $dbi->prepare("$sql");
+			$resv->execute();	
+			list($voti,$solo_gruppo)=$resv->fetch(PDO::FETCH_NUM);
+			if($disgiunto){
+				$sql="SELECT sum(t1.solo_lista) from ".$prefix."_ele_voti_lista as t1 left join ".$prefix."_ele_lista as t2 on t1.id_lista=t2.id_lista where t2.id_gruppo='$id_gruppo'";				
+			}else{
+				$sql="SELECT sum(t1.nulli_lista) from ".$prefix."_ele_voti_lista as t1 left join ".$prefix."_ele_lista as t2 on t1.id_lista=t2.id_lista where t2.id_gruppo='$id_gruppo'";
+			}
+			$resv = $dbi->prepare("$sql");
+			$resv->execute();	
+			list($perlista)=$resv->fetch(PDO::FETCH_NUM);
+			$t_voti+=$voti;$t_solo_gruppo+=$solo_gruppo;$t_perlista+=$perlista;	
+			ECHO "<TR><TD>".$num_gruppo."</TD><TD>".$desc."</TD><TD ALIGN=\"RIGHT\">".number_format($voti,0,',','.')."</TD><TD ALIGN=\"RIGHT\">".number_format($solo_gruppo,0,',','.')."</TD><TD ALIGN=\"RIGHT\">".number_format($perlista,0,',','.')."</TD></TD></TR>";
 		}
-		list($perlista)=mysql_fetch_row($resv);
-		$t_voti+=$voti;$t_solo_gruppo+=$solo_gruppo;$t_perlista+=$perlista;	
-		ECHO "<TR><TD>".$num_gruppo."</TD><TD>".$desc."</TD><TD ALIGN=\"RIGHT\">".number_format($voti,0,',','.')."</TD><TD ALIGN=\"RIGHT\">".number_format($solo_gruppo,0,',','.')."</TD><TD ALIGN=\"RIGHT\">".number_format($perlista,0,',','.')."</TD></TD></TR>";
-	}
-	echo "<tr><th colspan=\"2\" rowspan=\"2\" ALIGN=\"CENTER\"><b>Totale</b></th><th rowspan=\"2\"  ALIGN=\"RIGHT\">$t_voti</th><th ALIGN=\"RIGHT\">$t_solo_gruppo</th><th ALIGN=\"RIGHT\">$t_perlista</th></tr>";
-	ECHO "</table><br/></fieldset><br/><br/><br/>";
-
+		echo "<tr><th colspan=\"2\" rowspan=\"2\" ALIGN=\"CENTER\"><b>Totale</b></th><th rowspan=\"2\"  ALIGN=\"RIGHT\">$t_voti</th><th ALIGN=\"RIGHT\">$t_solo_gruppo</th><th ALIGN=\"RIGHT\">$t_perlista</th></tr>";
+		ECHO "</table><br/></fieldset><br/><br/><br/>";
 	}
 	echo "<fieldset><legend>"._VOTI_LISTA."</legend>";
 	echo "<table border=\"1\" width=\"100%\"><tr><th>"._VALIDI."</th><th>"._VOTINULLI."</th><th>"._CONTESTATI."</th>";
 	// if ($genere==5 and !$votog)
-		echo "<th>"._SOLO_GRUPPO."</th>";
+	echo "<th>"._SOLO_GRUPPO."</th>";
 	echo "<th>"._TOTNON."</th></TR>";
-
-		ECHO "<TR><TH>".number_format($validilista,0,',','.')."</TH><TH>".number_format($nullilista,0,',','.')."</TH><TH>".number_format($contestatilista,0,',','.')."</TH>";
+	ECHO "<TR><TH>".number_format($validilista,0,',','.')."</TH><TH>".number_format($nullilista,0,',','.')."</TH><TH>".number_format($contestatilista,0,',','.')."</TH>";
 	if($genere==5 and !$votog)
 		echo "<TH>".number_format($sg,0,',','.')."</TH>";
@@ -138,12 +157,8 @@
 	ECHO "</fieldset>";
 	}
-	}
-	echo "</center>";
-	
-	
-	
+}
+echo "</center>";
 echo "</table>\n</td></tr></table>\n";
-
-   include ("footer.php");
+include ("footer.php");
 
 ?>
