Index: trunk/admin/admin.php
===================================================================
--- trunk/admin/admin.php	(revision 256)
+++ trunk/admin/admin.php	(revision 257)
@@ -269,5 +269,4 @@
 
 $aid=$_SESSION['aid'];
-#$dbi=$_SESSION['dbi'];
 $prefix=$_SESSION['prefix'];
 $pwd=$_SESSION['pwd'];
@@ -276,7 +275,8 @@
 
 $perms=0;
-			$sth = $dbi->prepare("select adminsuper, admincomune, adminop  from ".$prefix."_authors where aid='$aid' and pwd='$pwd' and (id_comune='$id_comune' or id_comune=0)");
-			$sth->execute();	
-			$row = $sth->fetch(PDO::FETCH_BOTH);	
+$sql="select adminsuper, admincomune, adminop  from ".$prefix."_authors where aid='$aid' and pwd='$pwd' and (id_comune='$id_comune' or id_comune=0)";
+$sth = $dbi->prepare("$sql");
+$sth->execute();	
+$row = $sth->fetch(PDO::FETCH_BOTH);	
 
 $adminsuper=$row[0];
Index: trunk/admin/modules/Elezioni/ele.php
===================================================================
--- trunk/admin/modules/Elezioni/ele.php	(revision 256)
+++ trunk/admin/modules/Elezioni/ele.php	(revision 257)
@@ -66,5 +66,5 @@
 
 	$row=daticonscom();
-	if ($row['fascia']) $fascia=$row['fascia'];
+	if (isset($row['fascia'])) $fascia=$row['fascia'];
 	else
 	$fascia=0;
Index: trunk/admin/modules/Elezioni/ele_associazioni.php
===================================================================
--- trunk/admin/modules/Elezioni/ele_associazioni.php	(revision 256)
+++ trunk/admin/modules/Elezioni/ele_associazioni.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'];
 $id_comune=$_SESSION['id_comune'];
@@ -22,9 +21,14 @@
 $perms=ChiSei(0);
 if ($perms<128 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,t1.descrizione,t2.id_cons,t2.id_conf FROM ".$prefix."_ele_consultazione as t1, ".$prefix."_ele_cons_comune as t2 where t1.id_cons_gen=t2.id_cons_gen and t2.id_comune='$id_comune' " , $dbi);
-list($tipo_cons,$descr_cons,$id_cons,$id_conf) = mysql_fetch_row($res);
-
-$res = mysql_query("SELECT genere FROM ".$prefix."_ele_tipo where tipo_cons='$tipo_cons' " , $dbi);
-	list($genere) = mysql_fetch_row($res);
+$sql="SELECT t1.tipo_cons,t1.descrizione,t2.id_cons,t2.id_conf FROM ".$prefix."_ele_consultazione as t1, ".$prefix."_ele_cons_comune as t2 where t1.id_cons_gen=t2.id_cons_gen and t2.id_comune='$id_comune' ";
+$res = $dbi->prepare("$sql");
+$res->execute();	
+#	$gru = $sth->fetch(PDO::FETCH_BOTH);	
+list($tipo_cons,$descr_cons,$id_cons,$id_conf) = $res->fetch(PDO::FETCH_NUM);
+
+$sql="SELECT genere FROM ".$prefix."_ele_tipo where tipo_cons='$tipo_cons' ";
+$res = $dbi->prepare("$sql");
+$res->execute();	
+list($genere) = $res->fetch(PDO::FETCH_NUM);
 
 include("modules/Elezioni/funzionidata.php");
@@ -59,5 +63,4 @@
 	global $user, $admin, $bgcolor1, $bgcolor2, $prefix,$descr_cons, $dbi,$id_cons,$desc,$indirizzo,$centralino,$fax,$id_cons_gen,$id_collegio,$idcomune,$chiusa,$id_conf,$tipo_cons,$language,$help,$preferenze,$idfascia,$vismf,$sg,$disgiunto,$id_cons_comu;
 $aid=$_SESSION['aid'];
-$dbi=$_SESSION['dbi'];
 $prefix=$_SESSION['prefix'];
 ############# Controllo flag per cancellazione consultazione
@@ -117,6 +120,8 @@
 	OpenTable();
 	echo "<tr><td><hr><br>";	
-	$res = mysql_query("SELECT descrizione FROM ".$prefix."_ele_consultazione where id_cons_gen='$id_cons_gen'" , $dbi);
-	list ($descr_cons) = mysql_fetch_row($res);
+	$sql="SELECT descrizione FROM ".$prefix."_ele_consultazione where id_cons_gen='$id_cons_gen'";
+	$res = $dbi->prepare("$sql");
+	$res->execute();	
+	list ($descr_cons) =  $res->fetch(PDO::FETCH_NUM);
 //inserire avviso su mancanza dei permessi
 	echo "<form name=\"model\" action=\"admin.php\">";
@@ -137,8 +142,10 @@
 	echo "<input type=\"hidden\" name=\"op\" value=\"associazioni\">";
 	echo "<input type=\"hidden\" name=\"id_cons_gen\" value=\"$id_cons_gen\">$descr_cons</td>";
-	$rescomu = mysql_query("SELECT id_comune, descrizione from ".$prefix."_ele_comuni order by descrizione asc", $dbi);
+	$sql = "SELECT id_comune, descrizione from ".$prefix."_ele_comuni order by descrizione asc";
+	$rescomu = $dbi->prepare("$sql");
+	$rescomu->execute();	
 	echo "<td>";
 	if($idcomune) {
-		while ($listele=mysql_fetch_array($rescomu))
+		while ($listele=$rescomu->fetch(PDO::FETCH_BOTH))
 			if($listele['id_comune']==$idcomune) {
 				echo $listele['descrizione'];
@@ -149,5 +156,5 @@
 	echo "<select name=\"idcomunenew\">";
 	echo "<option value=\"0\"> ";
-	while(list($id,$descr_comu)=mysql_fetch_row($rescomu)){
+	while(list($id,$descr_comu)=$rescomu->fetch(PDO::FETCH_NUM)){
 		$sel= ($id == $idcomune) ? "selected":"";
 		echo "<option value=\"$id\" $sel>$descr_comu";
@@ -171,12 +178,16 @@
 	if($tipo_cons==3){
 		if($idcomune) {
-			$rescomu = mysql_query("SELECT id_fascia from ".$prefix."_ele_cons_comune where id_cons_gen='$id_cons_gen' and id_comune='$idcomune'", $dbi);
-			if($rescomu)
-				list($fasciacom)=mysql_fetch_row($rescomu);
+			$sql="SELECT id_fascia from ".$prefix."_ele_cons_comune where id_cons_gen='$id_cons_gen' and id_comune='$idcomune'";
+			$rescomu = $dbi->prepare("$sql");
+			$rescomu->execute();	
+			if($rescomu->rowCount())
+				list($fasciacom)=$rescomu->fetch(PDO::FETCH_NUM);
 		} else $fasciacom=0;
-		$rescomu = mysql_query("SELECT id_conf, descrizione from ".$prefix."_ele_conf order by id_conf desc", $dbi);
+		$sql="SELECT id_conf, descrizione from ".$prefix."_ele_conf order by id_conf desc";
+		$rescomu = $dbi->prepare("$sql");
+		$rescomu->execute();	
 		echo "<td><select name=\"id_conf\" id=\"id_conf\" onchange=\"javascript:showdate('modules/Elezioni/ele_desc_fasce.php?fascia=$fasciacom&id_conf=' + model.id_conf.options[model.id_conf.selectedIndex].value,'fasceconf');\">";
 		echo "<option value=\"0\"> ";
-		while(list($id,$descr_conf)=mysql_fetch_row($rescomu)){
+		while(list($id,$descr_conf)=$rescomu->fetch(PDO::FETCH_NUM)){
 			$sel='';
 			if ($idcomune and $id == $id_conf) $sel="selected"; 
@@ -185,10 +196,12 @@
 		echo "</select></td>";
 		if(!$id_conf) $id_conf=1;
-		$rescomu = mysql_query("SELECT id_fascia,abitanti from ".$prefix."_ele_fasce where id_conf='$id_conf'", $dbi);
+		$sql="SELECT id_fascia,abitanti from ".$prefix."_ele_fasce where id_conf='$id_conf'";
+		$rescomu = $dbi->prepare("$sql");
+		$rescomu->execute();	
 		
 		echo "<td id=\"fasceconf\"><select name=\"idfascia\">";
 		echo "<option value=\"0\"> ";
 		$inffascia=0;
-		while(list($id,$abitanti)=mysql_fetch_row($rescomu)){
+		while(list($id,$abitanti)=$rescomu->fetch(PDO::FETCH_NUM)){
 			$sel='';
 			if ($idcomune and $id == $fasciacom) $sel="selected"; elseif ($id==1) $sel="selected";
@@ -201,6 +214,8 @@
 	}
 	unset($sel);
-	$rescomu = mysql_query("SELECT vismf,solo_gruppo,disgiunto from ".$prefix."_ele_cons_comune where id_cons='$id_cons_comu'", $dbi);
-	list($vismf,$sg,$disgiunto)=mysql_fetch_row($rescomu);
+	$sql = "SELECT vismf,vismf,solo_gruppo,disgiunto from ".$prefix."_ele_cons_comune where id_cons='$id_cons_comu'";
+	$rescomu = $dbi->prepare("$sql");
+	$rescomu->execute();	
+	list($vismf,$sg,$disgiunto)=$rescomu->fetch(PDO::FETCH_NUM);
 	echo "<td><select name=\"vismf\">";
 	if ($vismf==0) $sel="selected"; else $sel="";
@@ -250,8 +265,12 @@
 	echo "<td width=\"10\" bgcolor=\"$bgcolor1\"><b>&nbsp;"._FUNZIONI."</b></td></tr>";
 
-	$resmod = mysql_query("SELECT '',t1.id_comune,'',t1.id_cons, t2.descrizione, t1.chiusa, t1.id_conf, preferenze,t1.id_fascia,t1.vismf,t1.solo_gruppo,t1.disgiunto FROM ".$prefix."_ele_cons_comune as t1, ".$prefix."_ele_comuni as t2 where t1.id_cons_gen='$id_cons_gen' and t1.id_comune=t2.id_comune order by t2.descrizione", $dbi);
-	while (list($id_collegio,$id_comune2,$descr_coll,$id_cons_comu,$descr_comu, $chiusa,$id_conf,$preferenze2,$fasciacom,$vismf2,$sg2,$disgiunto2) = mysql_fetch_row($resmod)){ //elenco dei modelli inseriti
-		$resconf = mysql_query("SELECT descrizione FROM ".$prefix."_ele_conf where id_conf='$id_conf'", $dbi);
-		list($descr_conf) = mysql_fetch_row($resconf);
+	$sql="SELECT '',t1.id_comune,'',t1.id_cons, t2.descrizione, t1.chiusa, t1.id_conf, preferenze,t1.id_fascia,t1.vismf,t1.solo_gruppo,t1.disgiunto FROM ".$prefix."_ele_cons_comune as t1, ".$prefix."_ele_comuni as t2 where t1.id_cons_gen='$id_cons_gen' and t1.id_comune=t2.id_comune order by t2.descrizione";
+	$resmod = $dbi->prepare("$sql");
+	$resmod->execute();	
+	while (list($id_collegio,$id_comune2,$descr_coll,$id_cons_comu,$descr_comu, $chiusa,$id_conf,$preferenze2,$fasciacom,$vismf2,$sg2,$disgiunto2) = $resmod->fetch(PDO::FETCH_NUM)){ //elenco dei modelli inseriti
+		$sql="SELECT descrizione FROM ".$prefix."_ele_conf where id_conf='$id_conf'";
+		$resconf = $dbi->prepare("$sql");
+		$resconf->execute();	
+		list($descr_conf) = $resconf->fetch(PDO::FETCH_NUM);
 		$i++;
 		$bgcolor1=($bgcolor1==$_SESSION['bgcolor1'])?$_SESSION['bgcolor2']:$_SESSION['bgcolor1'];
@@ -266,8 +285,10 @@
 		if($tipo_cons==3){
 			echo "<td><b>".$descr_conf."</b></td>";
-			$rescomu = mysql_query("SELECT id_fascia,abitanti from ".$prefix."_ele_fasce where id_conf='$id_conf'", $dbi);
+			$sql="SELECT id_fascia,abitanti from ".$prefix."_ele_fasce where id_conf='$id_conf'";
+			$rescomu = $dbi->prepare("$sql");
+			$rescomu->execute();	
 			$inffascia=0;
-			if (mysql_num_rows($rescomu)==0) echo "<td></td>";
-			while(list($id,$abitanti)=mysql_fetch_row($rescomu)){
+			if ($rescomu->rowCount()==0) echo "<td></td>";
+			while(list($id,$abitanti)=$rescomu->fetch(PDO::FETCH_NUM)){
 				$sel='';
 				if ($id == $fasciacom) 
@@ -304,16 +325,26 @@
 	$delcons=0;
 	if ($do !="" and $id_cons_gen>0 and $idcomunenew>0) {
-		$rescomu = mysql_query("SELECT id_cons from ".$prefix."_ele_cons_comune where id_cons_gen='$id_cons_gen' and id_comune='$idcomunenew'", $dbi); 
-		$max = mysql_num_rows($rescomu); //esiste autorizzazione?
-			list($delcons)=mysql_fetch_row($rescomu);
-			if (!$max){			//se no la inserisce
-			$result = mysql_query("insert into ".$prefix."_ele_cons_comune (chiusa,id_comune,id_cons_gen,id_conf,preferenze,id_fascia,vismf,solo_gruppo,disgiunto) values ('0','$idcomunenew','$id_cons_gen','$id_conf','$preferenze','$idfascia','$vismf','$sg','$disgiunto')", $dbi) || die("<br><br>Errore di inserimento: ".mysql_error());
-			$rescomu = mysql_query("SELECT id_cons from ".$prefix."_ele_cons_comune where id_cons_gen='$id_cons_gen' and id_comune='$idcomunenew'", $dbi);
-		list($id_cons_comu)=mysql_fetch_row($rescomu);
-			$res = mysql_query("SELECT id_cons FROM ".$prefix."_ele_comuni where id_comune='$idcomunenew' ", $dbi);
-        		list($id_cons_pred)=mysql_fetch_row($res);
-			if (!$id_cons_pred) 
-				$res = mysql_query("update ".$prefix."_ele_comuni set id_cons='$id_cons_comu' where id_comune='$idcomunenew' ", $dbi);
-
+		$sql="SELECT id_cons from ".$prefix."_ele_cons_comune where id_cons_gen='$id_cons_gen' and id_comune='$idcomunenew'"; 
+		$rescomu = $dbi->prepare("$sql");
+		$rescomu->execute();	
+		$max = $rescomu->rowCount(); //esiste autorizzazione?
+		list($delcons)=$rescomu->fetch(PDO::FETCH_NUM);
+		if (!$max){			//se no la inserisce
+			$sql="insert into ".$prefix."_ele_cons_comune (chiusa,id_comune,id_cons_gen,id_conf,preferenze,id_fascia,vismf,solo_gruppo,disgiunto) values ('0','$idcomunenew','$id_cons_gen','$id_conf','$preferenze','$idfascia','$vismf','$sg','$disgiunto')";
+			$result = $dbi->prepare("$sql");
+			$result->execute();	
+			$sql="SELECT id_cons from ".$prefix."_ele_cons_comune where id_cons_gen='$id_cons_gen' and id_comune='$idcomunenew'";
+			$rescomu = $dbi->prepare("$sql");
+			$rescomu->execute();	
+			list($id_cons_comu)=$rescomu->fetch(PDO::FETCH_NUM);
+			$sql="SELECT id_cons FROM ".$prefix."_ele_comuni where id_comune='$idcomunenew' ";
+			$res = $dbi->prepare("$sql");
+			$res->execute();	
+			list($id_cons_pred)=$res->fetch(PDO::FETCH_NUM);
+			if (!$id_cons_pred) {
+				$sql="update ".$prefix."_ele_comuni set id_cons='$id_cons_comu' where id_comune='$idcomunenew' ";
+				$res = $dbi->prepare("$sql");
+				$res->execute();	
+				}
 		}
 		if ($do == "update") {
@@ -321,36 +352,71 @@
 			else $newid='';
 			$result = mysql_query("update ".$prefix."_ele_comu_collegi set id_collegio= '$id_collegio' $newid where id_comune='$id_comune' and id_cons_gen='$id_cons_gen'", $dbi) || die(mysql_error());
-			if (!$result) return;
-			$result = mysql_query("update ".$prefix."_ele_cons_comune set id_conf='$id_conf', chiusa= '$chiusa', preferenze='$preferenze',id_fascia='$idfascia',vismf='$vismf',solo_gruppo='$sg',disgiunto='$disgiunto' where id_comune='$id_comune' and id_cons_gen='$id_cons_gen'", $dbi)|| die(mysql_error());
+			$result = $dbi->prepare("$sql");
+			$result->execute();	
+			if (!$result->rowCount()) return;
+			$sql="update ".$prefix."_ele_cons_comune set id_conf='$id_conf', chiusa= '$chiusa', preferenze='$preferenze',id_fascia='$idfascia',vismf='$vismf',solo_gruppo='$sg',disgiunto='$disgiunto' where id_comune='$id_comune' and id_cons_gen='$id_cons_gen'";
+			$result = $dbi->prepare("$sql");
+			$result->execute();	
 			Header("Location: admin.php?op=associazioni&id_cons_gen=$id_cons_gen");
 		}elseif ($do == "add") {
 			if ($id_collegio){
-				$result = mysql_query("insert into ".$prefix."_ele_comu_collegi (id_collegio,id_cons,id_comune,id_cons_gen) values ('$id_collegio','$id_cons_comu','$idcomunenew','$id_cons_gen')", $dbi) || die("<br><br>Errore di inserimento: ".mysql_error());
+				$sql="insert into ".$prefix."_ele_comu_collegi (id_collegio,id_cons,id_comune,id_cons_gen) values ('$id_collegio','$id_cons_comu','$idcomunenew','$id_cons_gen')";
+				$result = $dbi->prepare("$sql");
+				$result->execute();	
 				}
 			Header("Location: admin.php?op=associazioni&id_cons_gen=$id_cons_gen");
 		}elseif ($do == "delete" and $delcons>0) {
 			$idcns=$delcons; 
-			$res_del = mysql_query("delete from ".$prefix."_ele_voti_ref where id_cons=$idcns" ,$dbi);
-			$res_del = mysql_query("delete from ".$prefix."_ele_voti_candidati where id_cons=$idcns" ,$dbi);
-			$res_del = mysql_query("delete from ".$prefix."_ele_voti_lista where id_cons=$idcns" ,$dbi);
-			$res_del = mysql_query("delete from ".$prefix."_ele_voti_gruppo where id_cons=$idcns" ,$dbi);
-			$res_del = mysql_query("delete from ".$prefix."_ele_voti_parziale where id_cons=$idcns" ,$dbi);
-			$res_del = mysql_query("delete from ".$prefix."_ele_controllosez where id_cons=$idcns" ,$dbi);
+			$sql="delete from ".$prefix."_ele_voti_ref where id_cons=$idcns";
+			$result = $dbi->prepare("$sql");
+			$result->execute();	
+			$sql="delete from ".$prefix."_ele_voti_candidati where id_cons=$idcns";
+			$result = $dbi->prepare("$sql");
+			$result->execute();	
+			$sql="delete from ".$prefix."_ele_voti_lista where id_cons=$idcns";
+			$result = $dbi->prepare("$sql");
+			$result->execute();	
+			$sql="delete from ".$prefix."_ele_voti_gruppo where id_cons=$idcns";
+			$result = $dbi->prepare("$sql");
+			$result->execute();	
+			$sql="delete from ".$prefix."_ele_voti_parziale where id_cons=$idcns";
+			$result = $dbi->prepare("$sql");
+			$result->execute();	
+			$sql="delete from ".$prefix."_ele_controllosez where id_cons=$idcns";
+			$result = $dbi->prepare("$sql");
+			$result->execute();	
 			if ($pwd4==1){
-			$res_del = mysql_query("delete from ".$prefix."_ele_candidati where id_cons=$idcns" ,$dbi);
-			$res_del = mysql_query("delete from ".$prefix."_ele_lista where id_cons=$idcns" ,$dbi);
-			$res_del = mysql_query("delete from ".$prefix."_ele_gruppo where id_cons=$idcns" ,$dbi);
-			$res_del = mysql_query("delete from ".$prefix."_ele_sezioni where id_cons=$idcns" ,$dbi);
-			$res_del = mysql_query("delete from ".$prefix."_ele_cons_comune where id_cons=$idcns" ,$dbi);
-			$res = mysql_query("SELECT id_cons FROM ".$prefix."_ele_comuni where id_comune='$id_comune' ", $dbi);
-        		list($id_cons_pred)=mysql_fetch_row($res);
+				$sql="delete from ".$prefix."_ele_candidati where id_cons=$idcns";
+				$result = $dbi->prepare("$sql");
+				$result->execute();	
+				$sql="delete from ".$prefix."_ele_lista where id_cons=$idcns";
+				$result = $dbi->prepare("$sql");
+				$result->execute();	
+				$sql="delete from ".$prefix."_ele_gruppo where id_cons=$idcns";
+				$result = $dbi->prepare("$sql");
+				$result->execute();	
+				$sql="delete from ".$prefix."_ele_sezioni where id_cons=$idcns";
+				$result = $dbi->prepare("$sql");
+				$result->execute();	
+				$sql="delete from ".$prefix."_ele_cons_comune where id_cons=$idcns";
+				$result = $dbi->prepare("$sql");
+				$result->execute();	
+				$sql="SELECT id_cons FROM ".$prefix."_ele_comuni where id_comune='$id_comune' ";
+				$res = $dbi->prepare("$sql");
+				$res->execute();	
+				list($id_cons_pred)=$res->fetch(PDO::FETCH_NUM);
 				if ($idcns==$id_cons_pred) {
-				$res = mysql_query("select id_cons from ".$prefix."_ele_cons_comune where id_comune=$id_comune order by id_cons desc limit 0,1" ,$dbi);
-        			list($id_cons_pred)=mysql_fetch_row($res); 
-				$res = mysql_query("update ".$prefix."_ele_comuni set id_cons='$id_cons_pred' where id_comune='$id_comune' ", $dbi);
+					$sql="select id_cons from ".$prefix."_ele_cons_comune where id_comune=$id_comune order by id_cons desc limit 0,1";
+					$res = $dbi->prepare("$sql");
+					$res->execute();	
+					list($id_cons_pred)=$res->fetch(PDO::FETCH_NUM);
+					$sql="update ".$prefix."_ele_comuni set id_cons='$id_cons_pred' where id_comune='$id_comune' ";
+					$res = $dbi->prepare("$sql");
+					$res->execute();	
 				}
 			}else{
-			$res_del = mysql_query("update ".$prefix."_ele_sezioni set validi='0', nulli='0', bianchi='0', contestati='0', solo_gruppo='0', autorizzati_m='0', autorizzati_f='0', voti_nulli='0', validi_lista='0', contestati_lista='0', voti_nulli_lista='0' where id_cons=$idcns" ,$dbi);
-			
+				$sql="update ".$prefix."_ele_sezioni set validi='0', nulli='0', bianchi='0', contestati='0', solo_gruppo='0', autorizzati_m='0', autorizzati_f='0', voti_nulli='0', validi_lista='0', contestati_lista='0', voti_nulli_lista='0' where id_cons=$idcns";
+				$result = $dbi->prepare("$sql");
+				$result->execute();	
 			}
 			Header("Location: admin.php?op=associazioni&id_cons_gen=$id_cons_gen");
Index: trunk/admin/modules/Elezioni/ele_candidato.php
===================================================================
--- trunk/admin/modules/Elezioni/ele_candidato.php	(revision 256)
+++ trunk/admin/modules/Elezioni/ele_candidato.php	(revision 257)
@@ -13,7 +13,6 @@
     die ("You can't access this file directly...");
 }
-
+global $dbi;
 $aid=$_SESSION['aid'];
-$dbi=$_SESSION['dbi'];
 $prefix=$_SESSION['prefix'];
 $currentlang=$_SESSION['lang'];
@@ -23,8 +22,13 @@
 $perms=ChiSei($id_cons_gen);
 if ($perms<32 or !$id_cons_gen) die("$id_cons_gen -Non hai i permessi per inserire dati, o non hai scelto la consultazione!");
-$res = mysql_query("SELECT t1.tipo_cons,t2.id_cons 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) = mysql_fetch_row($res);
-$res = mysql_query("SELECT genere FROM ".$prefix."_ele_tipo where tipo_cons='$tipo_cons' " , $dbi);
-	list($genere) = mysql_fetch_row($res);
+$sql = "SELECT t1.tipo_cons,t2.id_cons 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' ";
+$sth = $dbi->prepare("$sql");
+$sth->execute();	
+
+list($tipo_cons,$id_cons) = $sth->fetch(PDO::FETCH_NUM);
+$sql = "SELECT genere FROM ".$prefix."_ele_tipo where tipo_cons='$tipo_cons' ";
+$sth = $dbi->prepare("$sql");
+$sth->execute();
+list($genere) = $sth->fetch(PDO::FETCH_NUM);
 include("modules/Elezioni/funzionidata.php");
 include("modules/Elezioni/ele.php");
@@ -78,15 +82,19 @@
 	$circo='';$circo2='';
 	$currentlang=$_SESSION['lang'];	
-	$res = mysql_query("SELECT circo FROM ".$prefix."_ele_tipo where tipo_cons='$tipo_cons' and lingua='$currentlang'", $dbi);
-	list($cons_circ)= mysql_fetch_row($res);
+	$sql = "SELECT circo FROM ".$prefix."_ele_tipo where tipo_cons='$tipo_cons' and lingua='$currentlang'";
+	$sth = $dbi->prepare("$sql");
+	$sth->execute();
+	list($cons_circ)= $sth->fetch(PDO::FETCH_NUM);
 	if($cons_circ) //elezioni circoscrizionali
 	{
 		echo "<form name=\"circo\" action=\"admin.php\" method=\"post\">";
 		echo "<br><br><table border=\"1\" width=\"50%\" ><tr bgcolor=\"$bgcolor1\"><td>"._SCEGLI_CIRCO.": </td>";
-		$res = mysql_query("SELECT * FROM ".$prefix."_ele_circoscrizione where id_cons='$id_cons'", $dbi);
 		echo "<input type=\"hidden\" name=\"pag\" value=\"admin.php?op=candidato&amp;id_cons_gen=$id_cons_gen&amp;id_circ=\">";
 		echo "<td><select name=\"id_circ\" onChange=\"top.location.href=this.form.pag.value+this.form.id_circ.options[this.form.id_circ.selectedIndex].value;return false\">";
 		echo "<option value=\"\">";
-		while($arr=mysql_fetch_array($res,3)){
+		$sql = "SELECT * FROM ".$prefix."_ele_circoscrizione where id_cons='$id_cons'";
+		$sth = $dbi->prepare("$sql");
+		$sth->execute();
+		while($arr=$sth->fetch(PDO::FETCH_BOTH)){
 			if (!$id_circ) $id_circ=$arr['id_circ'];
 			$sel= ($arr['id_circ'] == $id_circ) ? "selected":"";
@@ -99,12 +107,16 @@
 	if($id_cand)
 	{
-		$res = mysql_query("SELECT * FROM ".$prefix."_ele_candidati where id_cand='$id_cand'", $dbi);
-		$pro= mysql_fetch_array($res, 3);
+		$sql = "SELECT * FROM ".$prefix."_ele_candidati where id_cand='$id_cand'";
+		$sth = $dbi->prepare("$sql");
+		$sth->execute();
+		$pro= $sth->fetch(PDO::FETCH_BOTH);
 	}else{
 	$pro['cognome']='';$pro['num_cand']='';$pro['nome']='';
 	}
 	if (!isset($id_lista)) {
-		$res_lista=mysql_query("SELECT id_lista from ".$prefix."_ele_lista where id_cons=$id_cons $circo and num_lista=1", $dbi);
-		list($id_lista)=mysql_fetch_row($res_lista);
+		$sql="SELECT id_lista from ".$prefix."_ele_lista where id_cons=$id_cons $circo and num_lista=1";
+		$sth = $dbi->prepare("$sql");
+		$sth->execute();
+		list($id_lista)=$sth->fetch(PDO::FETCH_NUM);
 	}
 	$cond=($id_lista>0) ? "and t1.id_lista=".$id_lista :'';
@@ -143,10 +155,14 @@
 	}
 	echo "<td bgcolor=\"$bgcolor1\" align=\"center\"><b>"._FUNZIONI."</b></td></tr>";
-	$result = mysql_query($query, $dbi);
+		$result = $dbi->prepare("$query");
+		$result->execute();
+#		list($id_lista)=$result->fetch(PDO::FETCH_NUM);
 	if($cons_circ)
-		$res = mysql_query("SELECT count(0) FROM ".$prefix."_ele_candidati as t1,".$prefix."_ele_lista as t2 where t1.id_cons='$id_cons' and t1.id_cons=t2.id_cons and t2.id_circ=$id_circ and t1.id_lista=t2.id_lista $cond ", $dbi);
+		$sql = "SELECT count(0) FROM ".$prefix."_ele_candidati as t1,".$prefix."_ele_lista as t2 where t1.id_cons='$id_cons' and t1.id_cons=t2.id_cons and t2.id_circ=$id_circ and t1.id_lista=t2.id_lista $cond ";
 	else
-		$res = mysql_query("SELECT count(0) FROM ".$prefix."_ele_candidati as t1 where t1.id_cons='$id_cons' $cond ", $dbi);
-	list($max) = mysql_fetch_row($res);
+		$sql = "SELECT count(0) FROM ".$prefix."_ele_candidati as t1 where t1.id_cons='$id_cons' $cond ";
+	$sth = $dbi->prepare("$sql");
+	$sth->execute();
+	list($max) = $sth->rowCount();
 	if($id_lista){
 		$numero=$max+1;} else $numero='';
@@ -166,7 +182,10 @@
 	echo "<input type=\"hidden\" name=\"pag\" value=\"admin.php?op=candidato&amp;id_cons=$id_cons&amp;id_cons_gen=$id_cons_gen&amp;id_comune=$id_comune&amp;id_circ=$id_circ&amp;id_lista=\">";
 	echo "<td width=\"10%\"><select width=\"10\" name=\"id_lista\" onChange=\"aggiorna()\">";
-	$res= mysql_query("SELECT id_lista,num_lista,descrizione FROM ".$prefix."_ele_lista where id_cons='$id_cons' $circo order by num_lista", $dbi);
+	$sql= "SELECT id_lista,num_lista,descrizione FROM ".$prefix."_ele_lista where id_cons='$id_cons' $circo order by num_lista";
+	$lis = $dbi->prepare("$sql");
+	$lis->execute();
 	echo "<option value=\"\">";
-	while(list($id,$numlist,$descr) = mysql_fetch_row($res)) {
+	
+	while(list($id,$numlist,$descr) = $lis->fetch(PDO::FETCH_NUM)) {
 		if (!isset($id_lista)){$id_lista=$id;}
 		$sel= ($id == $id_lista) ? "selected":"";
@@ -198,5 +217,5 @@
 	if ($result)
 	while(list($id_cand,$id_lista2,$num_cand,$cognome, $nome,$simbolo,$simb_lista,
-	$descr_lista,$simb_gruppo,$descr_gruppo) = mysql_fetch_row($result)) {
+	$descr_lista,$simb_gruppo,$descr_gruppo) = $result->fetch(PDO::FETCH_NUM)) {
 		$bgcolor1=($bgcolor1==$_SESSION['bgcolor1'])?$_SESSION['bgcolor2']:$_SESSION['bgcolor1'];
 		echo "<tr bgcolor=\"$bgcolor1\"><td align=\"center\"><b>$num_cand</b>"
@@ -245,9 +264,12 @@
 if ($perms >16) {
 		if($id_cand) {
-			$res = mysql_query("SELECT * FROM ".$prefix."_ele_candidati where id_cand='$id_cand'", $dbi);
+			$sql = "SELECT * FROM ".$prefix."_ele_candidati where id_cand='$id_cand'";
 		}else{
-			$res = mysql_query("SELECT * FROM ".$prefix."_ele_candidati where id_lista='$id_lista'
-			and id_cons=$id_cons and cognome=$cognome and nome=$nome", $dbi);
+			$sql="SELECT * FROM ".$prefix."_ele_candidati where id_lista='$id_lista'
+			and id_cons='$id_cons' and cognome='$cognome' and nome='$nome'";
 		}
+		$sthcan = $dbi->prepare("$sql");
+		$sthcan->execute();
+
 		$username=$aid;
 		$data=date("Y/m/d");
@@ -260,8 +282,13 @@
 				echo "[ <a href=\"admin.php?op=candidato&amp;id_cons_gen=$id_cons_gen\">"._NO."</a> ] - [<a href=\"admin.php?op=candidato&amp;do=delete&amp;id_cand=$id_cand&amp;id_gruppo=$id_gruppo&amp;id_cons=$id_cons&amp;id_circ=$id_circ&amp;ok=1&amp;id_cons_gen=$id_cons_gen&amp;id_lista=$id_lista&amp;id_comune=$id_comune&amp;min=$min\">"._YES."</a> ]";
  	    		}else{
-				$pro= mysql_fetch_array($res, MYSQL_ASSOC);
-				$result = mysql_query("delete from ".$prefix."_ele_candidati where id_cand='$id_cand'", $dbi);
-				mysql_query("insert into ".$prefix."_ele_log values ('$id_cons','$id_sez','$username','$data','$tempo','DELETE:id_lista:$pro[id_lista],cognome:$pro[cognome],nome:$pro[nome]','','".$prefix."_ele_candidati')", $dbi);
-				if (!$result)return;
+				$pro= $sthcan->fetch(PDO::FETCH_BOTH);
+				$sql="delete from ".$prefix."_ele_candidati where id_cand='$id_cand'";
+				$sth = $dbi->prepare("$sql");
+				$sth->execute();
+				$result=$sth->rowCount();
+				$sql="insert into ".$prefix."_ele_log values ('$id_cons','$id_sez','$username','$data','$tempo','DELETE:id_lista:$pro[id_lista],cognome:$pro[cognome],nome:$pro[nome]','','".$prefix."_ele_candidati')";
+				$sth = $dbi->prepare("$sql");
+				$sth->execute();
+				if (!$result->rowCount())return;
 				Header("Location: admin.php?op=candidato&id_cons=$id_cons&id_cons_gen=$id_cons_gen&id_comune=$id_comune&id_circ=$id_circ&id_lista=$id_lista&min=$min");
 			}
@@ -270,13 +297,22 @@
 		// dati gruppo
 				if (!$num_cand){
-					$result = mysql_query("select max(num_cand) from ".$prefix."_ele_candidati where id_lista='$id_lista'", $dbi);
-					if ($result) list($num_cand)=mysql_fetch_row($result);
+					$sql="select max(num_cand) from ".$prefix."_ele_candidati where id_lista='$id_lista'";
+				$result = $dbi->prepare("$sql");
+				$result->execute();
+					if ($result->rowCount()) list($num_cand)=$result->fetch(PDO::FETCH_NUM);
 					else $num_cand=0;
 					$num_cand++;
 				}
-				$result = mysql_query("select id_gruppo from ".$prefix."_ele_lista where id_lista='$id_lista'", $dbi);
-				list($id_gruppo)=mysql_fetch_row($result);
-				$result = mysql_query("insert into ".$prefix."_ele_candidati(id_cons,id_lista,cognome,nome,note,simbolo,num_cand) values ('$id_cons','$id_lista','$cognome','$nome','$note','$simbolo','$num_cand')", $dbi);
-				mysql_query("insert into ".$prefix."_ele_log values ('$id_cons','$id_sez','$username','$data','$tempo','','ADD:id_lista:$id_lista,cognome:$cognome,nome:$nome','".$prefix."_ele_candidati')", $dbi);
+				$sql="select id_gruppo from ".$prefix."_ele_lista where id_lista='$id_lista'";
+				$sth = $dbi->prepare("$sql");
+				$sth->execute();
+				list($id_gruppo)=$sth->fetch(PDO::FETCH_NUM);
+				$sql="insert into ".$prefix."_ele_candidati(id_cons,id_lista,cognome,nome,note,simbolo,num_cand) values ('$id_cons','$id_lista','$cognome','$nome','$note','$simbolo','$num_cand')";
+				$sth = $dbi->prepare("$sql");
+				$sth->execute();
+				$result=$sth->rowCount();
+				$sql="insert into ".$prefix."_ele_log values ('$id_cons','$id_sez','$username','$data','$tempo','','ADD:id_lista:$id_lista,cognome:$cognome,nome:$nome','".$prefix."_ele_candidati')";
+				$sth = $dbi->prepare("$sql");
+				$sth->execute();
 					if (!$result) return;
 					Header("Location: admin.php?op=candidato&id_cons=$id_cons&id_lista=$id_lista&id_cons_gen=$id_cons_gen&id_comune=$id_comune&id_circ=$id_circ&min=$min");
@@ -289,15 +325,22 @@
 			}
 		}elseif ($do == "update") {
+		$pro= $sthcan->fetch(PDO::FETCH_BOTH);
 		
-		$pro= mysql_fetch_array($res, MYSQL_ASSOC);
-		$result = mysql_query("select id_gruppo from ".$prefix."_ele_lista where id_lista='$id_lista'", $dbi);
-		list($id_gruppo)=mysql_fetch_row($result);
+		$sql="select id_gruppo from ".$prefix."_ele_lista where id_lista='$id_lista'";
+		$sth = $dbi->prepare("$sql");
+		$sth->execute();
+		list($id_gruppo)=$sth->fetch(PDO::FETCH_NUM);
 		$cond='';
 		if (isset($note)) {$cond=", note='$note'";}
 		if (isset($simbolo)) {$cond.=", simbolo='$simbolo'";}
-		$result = mysql_query("update  ".$prefix."_ele_candidati set id_lista='$id_lista', cognome='$cognome', nome='$nome', num_cand='$num_cand' $cond where id_cand='$id_cand' ", $dbi);
-		mysql_query("insert into ".$prefix."_ele_log values ('$id_cons','$id_sez','$username','$data','$tempo','UPDATE:id_lista:$pro[id_lista],cognome:$pro[cognome],nome:$pro[nome],num_cand:$pro[num_cand]','id_lista:$id_lista,cognome:$cognome,nome:$nome,num_cand:$num_cand','".$prefix."_ele_candidati')", $dbi);
-		if (!$result) return;
-		Header("Location: admin.php?op=candidato&id_cons=$id_cons&id_lista=$id_lista&id_cons_gen=$id_cons_gen&id_comune=$id_comune&id_circ=$id_circ&min=$min");
+		$sql="update  ".$prefix."_ele_candidati set id_lista='$id_lista', cognome='$cognome', nome='$nome', num_cand='$num_cand' $cond where id_cand='$id_cand' ";
+		$sth = $dbi->prepare("$sql");
+		$sth->execute();
+		$result=$sth->rowCount();
+		$sql="insert into ".$prefix."_ele_log values ('$id_cons','$id_sez','$username','$data','$tempo','UPDATE:id_lista:$pro[id_lista],cognome:$pro[cognome],nome:$pro[nome],num_cand:$pro[num_cand]','id_lista:$id_lista,cognome:$cognome,nome:$nome,num_cand:$num_cand','".$prefix."_ele_candidati')";
+		$sth = $dbi->prepare("$sql");
+		$sth->execute();
+		if (!$result) {return;}
+#		Header("Location: admin.php?op=candidato&id_cons=$id_cons&id_lista=$id_lista&id_cons_gen=$id_cons_gen&id_comune=$id_comune&id_circ=$id_circ&min=$min");
 	}
 
@@ -306,8 +349,8 @@
 
 
-
-if ($do and $do!='modify')
+echo "qui si if ($do and $do!='modify')";
+if ($do and $do!='modify'){ele();
     candidato($ok, $do,$id_cand, $id_lista,$id_circ, $id_gruppo,$cognome, $nome, $note, $simbolo,$id_cand2,$num_cand);
-    else ele();
+	} else { ele(); }
 //if (!$do)ele();
 all();
Index: trunk/admin/modules/Elezioni/ele_circo.php
===================================================================
--- trunk/admin/modules/Elezioni/ele_circo.php	(revision 256)
+++ trunk/admin/modules/Elezioni/ele_circo.php	(revision 257)
@@ -13,7 +13,6 @@
     die ("You can't access this file directly...");
 }
-
+global $dbi;
 $aid=$_SESSION['aid'];
-$dbi=$_SESSION['dbi'];
 $prefix=$_SESSION['prefix'];
 $currentlang=$_SESSION['lang'];
@@ -24,6 +23,8 @@
 if ($perms<16 or !$id_cons_gen) die("Non hai i permessi per inserire dati, o non hai scelto la consultazione!");
 
-$res = mysql_query("SELECT t1.tipo_cons,t1.descrizione,t2.id_cons 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,$descr_cons,$id_cons) = mysql_fetch_row($res);
+$sql="SELECT t1.tipo_cons,t1.descrizione,t2.id_cons 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,$descr_cons,$id_cons) = $res->fetch(PDO::FETCH_NUM);
 include("modules/Elezioni/funzionidata.php");
 include("modules/Elezioni/ele.php");
@@ -55,6 +56,8 @@
 
 	if ($do == "modify"){
-		$res = mysql_query("SELECT * FROM ".$prefix."_ele_circoscrizione where id_circ='$id_circ'", $dbi);
-		$pro= mysql_fetch_array($res, 3);
+		$sql = "SELECT * FROM ".$prefix."_ele_circoscrizione where id_circ='$id_circ'";
+		$res = $dbi->prepare("$sql");
+		$res->execute();	
+		$pro= $res->fetch(PDO::FETCH_BOTH);
 		echo "<input type=\"hidden\" name=\"id_circ\" value=\"$id_circ\">"
 		."<input type=\"hidden\" name=\"do\" value=\"update\">";
@@ -63,6 +66,8 @@
 		."<td align=\"center\"><input type=\"submit\" name=\"update\" value=\""._MODIFY."\"></td></tr>";
 	} else {
-		$result = mysql_query("select * from ".$prefix."_ele_circoscrizione where id_cons='$id_cons'",$dbi);
-		$numc=mysql_num_rows($result);
+		$sql = "select max(num_circ) from ".$prefix."_ele_circoscrizione where id_cons='$id_cons'";
+		$result = $dbi->prepare("$sql");
+		$result->execute();	
+		list($numc)=$result->fetch(PDO::FETCH_NUM);
 		$numc++;
 		echo "<tr><td align=\"right\"><input type=\"hidden\" name=\"do\" value=\"add\"><input type=\"text\" name=\"num_circ\"  maxlength=\"3\" size=\"3\" value=\"$numc\"></td>"
@@ -70,10 +75,16 @@
 		echo "<td align=\"center\"><input type=\"submit\" name=\"add\" value=\""._ADD."\"></td></tr>";
 	}	
-	$res = mysql_query("SELECT * FROM ".$prefix."_ele_circoscrizione where id_cons='$id_cons'  ", $dbi);
-	$max = mysql_num_rows($res);
-	$result = mysql_query("select * from ".$prefix."_ele_circoscrizione where id_cons='$id_cons'  ORDER BY num_circ  LIMIT $min,$offset", $dbi);
-	while(list($id_cons2, $id_circ, $num_sez, $descr_circ) = mysql_fetch_row($result)) {
-		$restemp = mysql_query("select count(0) from ".$prefix."_ele_sede where id_circ='$id_circ'", $dbi);
-		list($numtemp)=mysql_fetch_row($restemp);
+	$sql = "SELECT * FROM ".$prefix."_ele_circoscrizione where id_cons='$id_cons'  ";
+	$res = $dbi->prepare("$sql");
+	$res->execute();	
+	$max = $res->rowCount();
+	$sql="select * from ".$prefix."_ele_circoscrizione where id_cons='$id_cons'  ORDER BY num_circ  LIMIT $min,$offset";
+	$result = $dbi->prepare("$sql");
+	$result->execute();	
+	while(list($id_cons2, $id_circ, $num_sez, $descr_circ) = $result->fetch(PDO::FETCH_NUM)) {
+		$sql="select count(0) from ".$prefix."_ele_sede where id_circ='$id_circ'";
+		$restemp = $dbi->prepare("$sql");
+		$restemp->execute();	
+		list($numtemp)=$restemp->fetch(PDO::FETCH_NUM);
 		$bgcolor1=($bgcolor1==$_SESSION['bgcolor1'])?$_SESSION['bgcolor2']:$_SESSION['bgcolor1'];
 		echo "<tr bgcolor=\"$bgcolor1\"><td align=\"right\"width=\"5%\"><b>$num_sez</b>"
@@ -132,26 +143,34 @@
 			die();
 		}else{
-			$rescirc= mysql_query("select num_circ from ".$prefix."_ele_circoscrizione where id_circ=$id_circ",$dbi);
-			if (mysql_num_rows($rescirc)!=1) die("(1001) Grave errore nel database! contattare l'amministratore");
-			list($num_circ)=mysql_fetch_row($rescirc);
-#			$rif_numcirc=($num_circ>1)?($num_circ-1):($num_circ+1);
-#			$rescirc= mysql_query("select id_circ from ".$prefix."_ele_circoscrizione where num_circ=$rif_numcirc and id_cons=$id_cons",$dbi);
-#			if (mysql_num_rows($rescirc)!=1) die("(1002) Grave errore nel database! contattare l'amministratore -- select id_circ from ".$prefix."_ele_circoscrizione where num_circ=$rif_numcirc  -- $num_circ and id_cons=$id_cons");
-#			list($rif_idcirc)=mysql_fetch_row($rescirc);
-#			mysql_query("update ".$prefix."_ele_sede set id_circ=$rif_idcirc where id_circ=$id_circ",$dbi);
-			$result = mysql_query("delete from ".$prefix."_ele_circoscrizione where id_circ='$id_circ'", $dbi)|| die("(1003) Grave errore nel database! contattare l'amministratore".mysql_error());
-			$rescirc= mysql_query("select id_circ,num_circ from ".$prefix."_ele_circoscrizione where num_circ>$num_circ and id_cons=$id_cons",$dbi);
-			while (list($tmp_id,$tmp_num)=mysql_fetch_row($rescirc))
-				mysql_query("update ".$prefix."_ele_circoscrizione set num_circ=".($tmp_num-1)." where id_circ=$tmp_id",$dbi);
+			$sql="select num_circ from ".$prefix."_ele_circoscrizione where id_circ=$id_circ";
+			$rescirc = $dbi->prepare("$sql");
+			$rescirc->execute();	
+			if ($rescirc->rowCount()!=1) die("(1001) Grave errore nel database! contattare l'amministratore");
+			list($num_circ)=$rescirc->fetch(PDO::FETCH_NUM);
+			$sql="delete from ".$prefix."_ele_circoscrizione where id_circ='$id_circ'";
+			$result = $dbi->prepare("$sql");
+			$result->execute();	
+			$sql="select id_circ,num_circ from ".$prefix."_ele_circoscrizione where num_circ>$num_circ and id_cons=$id_cons";
+			$rescirc = $dbi->prepare("$sql");
+			$rescirc->execute();	
+			while (list($tmp_id,$tmp_num)=$rescirc->fetch(PDO::FETCH_NUM)){
+				$sql="update ".$prefix."_ele_circoscrizione set num_circ=".($tmp_num-1)." where id_circ=$tmp_id";
+				$result = $dbi->prepare("$sql");
+				$result->execute();	
+			}
 			Header("Location: admin.php?op=circo&id_cons_gen=$id_cons_gen");
 		}
 	}elseif ($do == "add") {
 		if ($descr_circ) {
-			$result = mysql_query("insert into ".$prefix."_ele_circoscrizione (id_cons,num_circ,descrizione) values ('$id_cons','$num_circ','$descr_circ')", $dbi)|| die("(1004) Non e' stato possibile inserire i dati nel database! contattare l'amministratore".mysql_error());
+			$sql="insert into ".$prefix."_ele_circoscrizione (id_cons,num_circ,descrizione) values ('$id_cons','$num_circ','$descr_circ')";
+			$result = $dbi->prepare("$sql");
+			$result->execute();	
 			Header("Location: admin.php?op=circo&id_cons_gen=$id_cons_gen");
 		}
 	}elseif ($do == "update") {
 		
-		$result = mysql_query("update  ".$prefix."_ele_circoscrizione set num_circ='$num_circ' , descrizione='$descr_circ' WHERE id_circ='$id_circ'", $dbi)|| die("(1005) Non e' stato possibile aggiornare i dati! contattare l'amministratore".mysql_error());
+		$sql="update  ".$prefix."_ele_circoscrizione set num_circ='$num_circ' , descrizione='$descr_circ' WHERE id_circ='$id_circ'";
+		$result = $dbi->prepare("$sql");
+		$result->execute();	
 		Header("Location: admin.php?op=circo&id_cons_gen=$id_cons_gen");
 	}
Index: trunk/admin/modules/Elezioni/ele_collegi.php
===================================================================
--- trunk/admin/modules/Elezioni/ele_collegi.php	(revision 256)
+++ trunk/admin/modules/Elezioni/ele_collegi.php	(revision 257)
@@ -41,5 +41,7 @@
 
 	OpenTable();	
-	$resmod = mysql_query("SELECT t1.id_collegio, t1.descrizione, t2.descrizione FROM ".$prefix."_ele_collegi as t1, ".$prefix."_ele_consultazione as t2 where t1.id_cons_gen=t2.id_cons_gen and t2.id_cons_gen=$id_cons_gen order by t1.descrizione asc", $dbi);
+	$sql = "SELECT t1.id_collegio, t1.descrizione, t2.descrizione FROM ".$prefix."_ele_collegi as t1, ".$prefix."_ele_consultazione as t2 where t1.id_cons_gen=t2.id_cons_gen and t2.id_cons_gen=$id_cons_gen order by t1.descrizione asc";
+	$resmod = $dbi->prepare("$sql");
+	$resmod->execute();	
 	echo "<table><tr ALIGN=\"CENTER\">";
 	echo "<td bgcolor=\"$bgcolor1\"><b>"._CONSULTA."</b></td>";
@@ -50,6 +52,8 @@
 	echo "<input type=\"hidden\" name=\"id_collegio\" value=\"$id_collegio\">";
 	echo "<tr align=\"center\">";
-	$ressede = mysql_query("SELECT descrizione from ".$prefix."_ele_consultazione where id_cons_gen='$id_cons_gen'", $dbi);
-	list($descr_cons)=mysql_fetch_row($ressede);
+	$sql = "SELECT descrizione from ".$prefix."_ele_consultazione where id_cons_gen='$id_cons_gen'";
+	$ressede = $dbi->prepare("$sql");
+	$ressede->execute();	
+	list($descr_cons)=$ressede->fetch(PDO::FETCH_NUM);
 	echo "<td>$descr_cons</td>";
 	echo "<td  align=\"center\" width=\"32\"><input name=\"desc\" value=\"$desc\"></td>";
@@ -64,5 +68,5 @@
 	}
 	$i=0;
-	while (list($id_collegio2,$desc,$descr_cons) = mysql_fetch_row($resmod)){ //elenco dei modelli inseriti
+	while (list($id_collegio2,$desc,$descr_cons) = $resmod->fetch(PDO::FETCH_NUM)){ //elenco dei modelli inseriti
 		$i++;
 		$bgcolor1=($bgcolor1==$_SESSION['bgcolor1'])?$_SESSION['bgcolor2']:$_SESSION['bgcolor1'];
@@ -97,17 +101,22 @@
 				die();
   	   		}else{
-			  	$result = mysql_query("delete from ".$prefix."_ele_collegi where id_collegio='$id_collegio'", $dbi);
-    		      		if (!$result) return;
+			  	$sql = "delete from ".$prefix."_ele_collegi where id_collegio='$id_collegio'";
+				$result = $dbi->prepare("$sql");
+				$result->execute();	
+    		    if (!$result->rowCount()) return;
 			  	Header("Location: admin.php?op=inscollegi&id_cons_gen=$id_cons_gen");
 			}
      	 	}
    	  	if ($do == "add") {
-   	   		$result = mysql_query("insert into ".$prefix."_ele_collegi(id_cons_gen,descrizione) values ('$id_cons_gen','$desc')", $dbi) || die("Impossibile inserire il collegio! ".mysql_error());
+   	   		$sql = "insert into ".$prefix."_ele_collegi(id_cons_gen,descrizione) values ('$id_cons_gen','$desc')";
+			$result = $dbi->prepare("$sql");
+			$result->execute();	
    		}
     	 	if ($do == "update") {
-    		    	$result = mysql_query("update  ".$prefix."_ele_collegi set descrizione='$desc' , id_cons_gen='$id_cons_gen' where id_collegio='$id_collegio'", $dbi);
-    	       	if (!$result) return;
-#			echo "update  ".$prefix."_ele_collegi set descrizione='$desc' , id_cons_gen='$id_cons_gen' where id_collegio='$id_collegio'";
-   	        	Header("Location: admin.php?op=inscollegi&id_cons_gen=$id_cons_gen&id_collegio=$id_collegio");
+    		$sql= "update  ".$prefix."_ele_collegi set descrizione='$desc' , id_cons_gen='$id_cons_gen' where id_collegio='$id_collegio'";
+ 			$result = $dbi->prepare("$sql");
+			$result->execute();	
+   	       	if (!$result->rowCount()) return;
+			Header("Location: admin.php?op=inscollegi&id_cons_gen=$id_cons_gen&id_collegio=$id_collegio");
    		}
 	} 
Index: trunk/admin/modules/Elezioni/ele_come.php
===================================================================
--- trunk/admin/modules/Elezioni/ele_come.php	(revision 256)
+++ trunk/admin/modules/Elezioni/ele_come.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'];
@@ -38,6 +37,7 @@
 /*********************************************************/
 $sql="SELECT t1.descrizione,t1.tipo_cons,t2.id_cons 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 = mysql_query("$sql", $dbi);
-list($descr_cons,$tipo_cons,$id_cons) = mysql_fetch_row($res);
+$res = $dbi->prepare("$sql");
+$res->execute();	
+list($descr_cons,$tipo_cons,$id_cons) = $res->fetch(PDO::FETCH_NUM);
 
 include("modules/Elezioni/ele.php");
@@ -64,6 +64,8 @@
 
 
-    $result = mysql_query("select  mid, title,preamble, content,  editimage from ".$prefix.$tab."  where id_cons='$id_cons'", $dbi);
-    while(list($mid2, $title, $preamble, $content,  $editimage) = mysql_fetch_row($result)) {
+    $sql="select  mid, title,preamble, content,  editimage from ".$prefix.$tab."  where id_cons='$id_cons'";
+	$result = $dbi->prepare("$sql");
+	$result->execute();	
+    while(list($mid2, $title, $preamble, $content,  $editimage) = $result->fetch(PDO::FETCH_NUM)) {
 
 	echo "<tr>"
@@ -80,11 +82,14 @@
     echo "<br>";
     if($vai=='editedit'){
-    $result = mysql_query("select title, preamble,content, editimage from ".$prefix.$tab." WHERE mid='$mid' AND id_cons='$id_cons'", $dbi);
-    list($add_title,$add_preamble, $add_content, $editimage) = mysql_fetch_row($result);
+    $sql="select title, preamble,content, editimage from ".$prefix.$tab." WHERE mid='$mid' AND id_cons='$id_cons'";
+	$result = $dbi->prepare("$sql");
+	$result->execute();	
+    list($add_title,$add_preamble, $add_content, $editimage) = $result->fetch(PDO::FETCH_NUM);
     }
 //25.05.2009
     $sql="SELECT editor,ed_user FROM ".$prefix."_config";
-$res = mysql_query("$sql", $dbi);
-list($editor,$ed_user) = mysql_fetch_row($res);
+	$res = $dbi->prepare("$sql");
+	$res->execute();	
+	list($editor,$ed_user) = $res->fetch(PDO::FETCH_NUM);
 //
 
@@ -157,5 +162,7 @@
 $temp=$title.$preamble.$content;
 	if (preg_match("/script/i",$temp)) die("La parola script e' proibita, devi toglierla dal testo.");
-    $result = mysql_query("update ".$prefix.$tab." set title='$title', preamble='$preamble', content='$content' WHERE mid='$mid' AND id_cons='$id_cons'", $dbi);
+    $sql="update ".$prefix.$tab." set title='$title', preamble='$preamble', content='$content' WHERE mid='$mid' AND id_cons='$id_cons'";
+	$res = $dbi->prepare("$sql");
+	$res->execute();	
     Header("Location: admin.php?op=$op&vai=come&id_cons_gen=$id_cons_gen");
 }
@@ -164,6 +171,8 @@
     global $prefix, $dbi,$id_cons, $id_cons_gen,$tab,$op;
 
-    $result = mysql_query("insert into ".$prefix.$tab." (id_cons,title,preamble,content) values ('$id_cons', '$add_title', '$add_preamble','$add_content')", $dbi);
-    if (!$result) {
+    $sql="insert into ".$prefix.$tab." (id_cons,title,preamble,content) values ('$id_cons', '$add_title', '$add_preamble','$add_content')";
+	$res = $dbi->prepare("$sql");
+	$res->execute();	
+    if (!$res->rowCount()) {
 	exit();
     }
@@ -175,6 +184,8 @@
     global $prefix, $dbi, $id_cons,$id_cons_gen,$tab,$op;
     if($ok) {
-	$result = mysql_query("delete from ".$prefix.$tab." where mid=$mid and id_cons='$id_cons'", $dbi);
-    	if (!$result) {
+	$sql="delete from ".$prefix.$tab." where mid=$mid and id_cons='$id_cons'";
+ 	$res = $dbi->prepare("$sql");
+	$res->execute();	
+   	if (!$res->rowCount()) {
 	    return;
     	}
Index: trunk/admin/modules/Elezioni/ele_comuni.php
===================================================================
--- trunk/admin/modules/Elezioni/ele_comuni.php	(revision 256)
+++ trunk/admin/modules/Elezioni/ele_comuni.php	(revision 257)
@@ -12,7 +12,8 @@
     die ("You can't access this file directly...");
 }
-#foreach($_FILES as $key=>$val) echo $key;die();
+#foreach($_SESSION as $key=>$val) echo "$key : $val<br>";die();
+global $dbi;
 $aid=$_SESSION['aid'];
-$dbi=$_SESSION['dbi'];
+#$dbi=$_SESSION['dbi'];
 $prefix=$_SESSION['prefix'];
 $id_comune=$_SESSION['id_comune'];
@@ -36,8 +37,12 @@
 if (isset($param['cap'])) get_magic_quotes_gpc() ? $cap=$param['cap']:$cap=addslashes($param['cap']); else $cap='';
 
-	$res = mysql_query("SELECT t1.tipo_cons FROM ".$prefix."_ele_consultazione as t1, ".$prefix."_ele_cons_comune as t2 where t1.id_cons_gen=t2.id_cons_gen and t2.id_comune='$id_comune' " , $dbi);
-	list($tipo_cons) = mysql_fetch_row($res);
-	$res = mysql_query("SELECT genere FROM ".$prefix."_ele_tipo where tipo_cons='$tipo_cons' " , $dbi);
-	list($genere) = mysql_fetch_row($res);
+	$sql="SELECT t1.tipo_cons FROM ".$prefix."_ele_consultazione as t1, ".$prefix."_ele_cons_comune as t2 where t1.id_cons_gen=t2.id_cons_gen and t2.id_comune='$id_comune' ";
+	$res = $dbi->prepare("$sql");
+	$res->execute();	
+	list($tipo_cons) = $res->fetch(PDO::FETCH_NUM);
+	$sql="SELECT genere FROM ".$prefix."_ele_tipo where tipo_cons='$tipo_cons' ";
+	$res = $dbi->prepare("$sql");
+	$res->execute();	
+	list($genere) = $res->fetch(PDO::FETCH_NUM);
 	include("modules/Elezioni/funzionidata.php");
 	include("modules/Elezioni/ele.php");
@@ -70,5 +75,8 @@
 
  
-	$resmod = mysql_query("SELECT id_comune,descrizione,indirizzo,centralino,fax,email,fascia,capoluogo,simbolo,cap FROM ".$prefix."_ele_comuni where descrizione like '$cerca%' order by descrizione", $dbi);
+	$sql="SELECT id_comune,descrizione,indirizzo,centralino,fax,email,fascia,capoluogo,simbolo,cap FROM ".$prefix."_ele_comuni where descrizione like '$cerca%' order by descrizione";
+	$resmod = $dbi->prepare("$sql");
+	$resmod->execute();	
+#	list($tipo_cons) = $resmod->fetch(PDO::FETCH_NUM);
 	echo "<table width=\"100%\"><tr><td bgcolor=\"$bgcolor2\"> <form name=\"cerca\" action=\"admin.php\">"
 	."<input type=\"hidden\" name=\"op\" value=\"inscomuni\">";
@@ -97,6 +105,8 @@
 	echo "<tr><td bgcolor=\"$bgcolor1\"><b>"._FASCIA."</b></td><td><select name=\"fascia\">";
 	$descr2="<";
-			$resopt1 = mysql_query("select id_fascia, abitanti from ".$prefix."_ele_fasce where id_conf=1 order by id_fascia", $dbi);
-		while(list($id,$descr)=mysql_fetch_row($resopt1)){
+	$sql="select id_fascia, abitanti from ".$prefix."_ele_fasce where id_conf=1 order by id_fascia";
+	$resopt1 = $dbi->prepare("$sql");
+	$resopt1->execute();	
+		while(list($id,$descr)=$resopt1->fetch(PDO::FETCH_NUM)){
 			$selid= ($id == $fasciatmp) ? "selected":"";
 			
@@ -134,5 +144,5 @@
 
 ####
-	while (list($id_comune2,$desc,$indirizzo,$centralino,$fax,$email,$fasciatmp,$prov,$simbolo,$cap) = mysql_fetch_row($resmod)){ //elenco dei modelli inseriti
+	while (list($id_comune2,$desc,$indirizzo,$centralino,$fax,$email,$fasciatmp,$prov,$simbolo,$cap) = $resmod->fetch(PDO::FETCH_NUM)){ //elenco dei modelli inseriti
 		$bgcolor1=($bgcolor1==$_SESSION['bgcolor1'])?$_SESSION['bgcolor2']:$_SESSION['bgcolor1'];
 		if (!$simbolo) $simbolo="nulla.jpg";
@@ -154,12 +164,16 @@
 		echo "<td><b>".substr($email,0,15)."...</b></td>";
 		echo "<td><b>$cap</b></td>";
-		$resopt1 = mysql_query("select abitanti from ".$prefix."_ele_fasce where id_fascia=$fasciatmp and id_conf=$id_conf", $dbi);
-		list($tmpfascia)=mysql_fetch_row($resopt1);
+		$sql="select abitanti from ".$prefix."_ele_fasce where id_fascia=$fasciatmp and id_conf=$id_conf";
+		$resopt1 = $dbi->prepare("$sql");
+		$resopt1->execute();	
+		list($tmpfascia)=$resopt1->fetch(PDO::FETCH_NUM);
 		$fasciaref=$fasciatmp-1;
-		$resopt1 = mysql_query("select abitanti from ".$prefix."_ele_fasce where id_fascia=$fasciaref and id_conf=$id_conf", $dbi);
-		if(mysql_num_rows($resopt1)==0) $valfascia="< $tmpfascia";
+		$sql="select abitanti from ".$prefix."_ele_fasce where id_fascia=$fasciaref and id_conf=$id_conf";
+		$resopt1 = $dbi->prepare("$sql");
+		$resopt1->execute();	
+		if($resopt1->rowCount()==0) $valfascia="< $tmpfascia";
 		else
 		{
-		    list($tmp2fascia)=mysql_fetch_row($resopt1);
+		    list($tmp2fascia)=$resopt1->fetch(PDO::FETCH_NUM);
 			$valfascia="$tmp2fascia - $tmpfascia";
 		}
@@ -219,6 +233,8 @@
 					$stemmanome=addslashes($nomestemma);
 				}
-      			$result = mysql_query("insert into ".$prefix."_ele_comuni (id_comune,descrizione,indirizzo,centralino,fax,email,fascia,capoluogo,simbolo,stemma,cap) values ('$id_comune','$desc','$indirizzo','$centralino','$fax','$email','$fasciatmp','$prov','$stemmanome','$stemmablob','$cap')", $dbi) || die("<br><br>Errore di inserimento: ".mysql_error());
-           		Header("Location: admin.php?op=inscomuni&id_cons_gen=$id_cons_gen");
+      			$sql = "insert into ".$prefix."_ele_comuni (id_comune,descrizione,indirizzo,centralino,fax,email,fascia,capoluogo,simbolo,stemma,cap) values ('$id_comune','$desc','$indirizzo','$centralino','$fax','$email','$fasciatmp','$prov','$stemmanome','$stemmablob','$cap')";
+				$result = $dbi->prepare("$sql");
+				$result->execute();	
+          		Header("Location: admin.php?op=inscomuni&id_cons_gen=$id_cons_gen");
      		} else {
         		OpenTable();
@@ -242,5 +258,7 @@
 				$cond=", simbolo='$stemmanome', stemma='$stemmablob'";
 			} else {$cond='';$stemmanome=''; $stemmablob='';}
-        	$result = mysql_query("update  ".$prefix."_ele_comuni set descrizione='$desc' , indirizzo='$indirizzo', centralino='$centralino', fax='$fax' , cap='$cap' , email='$email', fascia='$fasciatmp',capoluogo='$prov' $cond where id_comune='$id_comune'", $dbi) || die("<br><br>Errore di inserimento: ".mysql_error());
+        	$sql = "update  ".$prefix."_ele_comuni set descrizione='$desc' , indirizzo='$indirizzo', centralino='$centralino', fax='$fax' , cap='$cap' , email='$email', fascia='$fasciatmp',capoluogo='$prov' $cond where id_comune='$id_comune'";
+			$result = $dbi->prepare("$sql");
+			$result->execute();	
            	Header("Location: admin.php?op=inscomuni&id_cons_gen=$id_cons_gen");
    	}
Index: trunk/admin/modules/Elezioni/ele_confcons.php
===================================================================
--- trunk/admin/modules/Elezioni/ele_confcons.php	(revision 256)
+++ trunk/admin/modules/Elezioni/ele_confcons.php	(revision 257)
@@ -15,7 +15,6 @@
 // Offset - visualizza il numero di elementi per pagina
 $offset=5;
-
+global $db1;
 $aid=$_SESSION['aid'];
-$dbi=$_SESSION['dbi'];
 $prefix=$_SESSION['prefix'];
 $currentlang=$_SESSION['lang'];
@@ -26,6 +25,8 @@
 
 $id_comune=$_SESSION['id_comune'];
-$res = mysql_query("SELECT t1.tipo_cons,t2.id_cons 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) = mysql_fetch_row($res);
+$sql = "SELECT t1.tipo_cons,t2.id_cons 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) = $res->fetch(PDO::FETCH_NUM);
 
 include("modules/Elezioni/funzionidata.php");
@@ -66,12 +67,16 @@
 
 	//-----------------------visualizza blocco inserimento -
-	$res = mysql_query("SELECT * FROM ".$prefix."_ele_conf", $dbi); //da modificare
-	$max = mysql_num_rows($res);
+	$sql="SELECT * FROM ".$prefix."_ele_conf"; //da modificare
+	$res = $dbi->prepare("$sql");
+	$res->execute();	
+	$max = $res->rowCount();
 	$nuovo_gruppo=$max+1;
 	echo "<form name=\"gruppo2\" enctype=\"multipart/form-data\" action=\"admin.php\" method=\"post\">"
 	."<input type=\"hidden\" name=\"op\" value=\"confconsiglio\">";
 	if ($do=='modify') {
-	$resl = mysql_query("SELECT * FROM ".$prefix."_ele_conf where id_conf='$id_conf'", $dbi);
-	$gru=mysql_fetch_array($resl);
+	$sql="SELECT * FROM ".$prefix."_ele_conf where id_conf='$id_conf'";
+	$res1 = $dbi->prepare("$sql");
+	$res1->execute();	
+	$gru=$resl->fetch(PDO::FETCH_BOTH);
 	$nuovo_gruppo=$gru['id_conf'];
 	echo "<input type=\"hidden\" name=\"do\" value=\"update\">";
@@ -85,10 +90,12 @@
 	."<tr><td align=\"center\"><b>"._LIMITE."</b></td><td><select name=\"limite\"><option value=\"0\">"._NOFASCIA;
 		
-		$result1 = mysql_query("select id_fascia, abitanti from ".$prefix."_ele_fasce where id_conf='".$gru['id_conf']."' order by id_fascia", $dbi);
-		while(list($id,$descr)=mysql_fetch_row($result1)){
-			$sel= ($id == $gru['limite']) ? "selected":"";
-			echo "<option value=\"$id\" $sel>$descr";
-		}
-		echo "</select></td>";
+	$sql="select id_fascia, abitanti from ".$prefix."_ele_fasce where id_conf='".$gru['id_conf']."' order by id_fascia";
+	$result1 = $dbi->prepare("$sql");
+	$result1->execute();	
+	while(list($id,$descr)=$result1->fetch(PDO::FETCH_NUM)){
+		$sel= ($id == $gru['limite']) ? "selected":"";
+		echo "<option value=\"$id\" $sel>$descr";
+	}
+	echo "</select></td>";
 	$sel= ($gru['consin']==1) ? "selected":"";
 	echo "<td align=\"center\"><b>"._CONSIN."</b></td><td><select name=\"consin\"><option value=\"0\">No<option value=\"1\" $sel>Si</select></td></tr>"
@@ -116,8 +123,12 @@
 		
 		
-	$res = mysql_query("SELECT * FROM ".$prefix."_ele_conf", $dbi);
-	$max = mysql_num_rows($res);
-	$result = mysql_query("select * from ".$prefix."_ele_conf ORDER BY id_conf  LIMIT $min,$offset", $dbi);
-	while(list($id_conf,$descrizione,$limite, $consin,$infpremio, $supsbarramento, $suppremio, $listinfsbar, $listinfconta, $listsupconta) = mysql_fetch_row($result)) {
+	$sql="SELECT * FROM ".$prefix."_ele_conf";
+	$res = $dbi->prepare("$sql");
+	$res->execute();	
+	$max = $res->rowCount();
+	$sql="select * from ".$prefix."_ele_conf ORDER BY id_conf  LIMIT $min,$offset";
+	$result = $dbi->prepare("$sql");
+	$result->execute();	
+	while(list($id_conf,$descrizione,$limite, $consin,$infpremio, $supsbarramento, $suppremio, $listinfsbar, $listinfconta, $listsupconta) = $result->fetch(PDO::FETCH_NUM)) {
 		$bgcolor1=($bgcolor1==$_SESSION['bgcolor1'])?$_SESSION['bgcolor2']:$_SESSION['bgcolor1'];
 		echo "<tr bgcolor=\"$bgcolor1\"><td align=\"center\"><b>$id_conf</b></td>"
@@ -179,6 +190,8 @@
 				echo "[ <a href=\"admin.php?op=confconsiglio&amp;id_cons_gen=$id_cons_gen&amp;id_conf=$id_conf\">"._NO."</a> ] - [<a href=\"admin.php?op=confconsiglio&amp;do=delete&amp;id_conf=$id_conf&amp;id_cons_gen=$id_cons_gen&amp;id_comune=$id_comune&amp;ok=1\">"._YES."</a> ]";exit;
      			}else{
-				$result = mysql_query("delete from ".$prefix."_ele_conf where id_conf='$id_conf'", $dbi);
-          			if (!$result) return;
+				$sql="delete from ".$prefix."_ele_conf where id_conf='$id_conf'";
+				$result = $dbi->prepare("$sql");
+				$result->execute();	
+          		if (!$result->rowCount()) return;
 				Header("Location: admin.php?op=confconsiglio&id_cons_gen=$id_cons_gen&id_conf=$id_conf&min=$min");
 			}
@@ -186,6 +199,8 @@
       			if ($descrizione) {
 				$sqlset='';
-      				$result = mysql_query("insert into ".$prefix."_ele_conf(id_conf,descrizione, limite,consin,infpremio,supsbarramento,suppremio,listinfsbar,listinfconta,listsupconta,infminpremio,supminpremio) values ('$id_conf','$descrizione','$limite','$consin','$infpremio','$supsbarramento','$suppremio','$listinfsbar','$listinfconta','$listsupconta','$infminpremio','$supminpremio')", $dbi) || die("Errore di aggiornamento dei dati!".mysql_error());
-           			if (!$result) return;
+      			$sql="insert into ".$prefix."_ele_conf(id_conf,descrizione, limite,consin,infpremio,supsbarramento,suppremio,listinfsbar,listinfconta,listsupconta,infminpremio,supminpremio) values ('$id_conf','$descrizione','$limite','$consin','$infpremio','$supsbarramento','$suppremio','$listinfsbar','$listinfconta','$listsupconta','$infminpremio','$supminpremio')";
+				$result = $dbi->prepare("$sql");
+				$result->execute();	
+           			if (!$result->rowCount()) return;
            			Header("Location: admin.php?op=confconsiglio&id_cons_gen=$id_cons_gen&min=$min");
      			} else {
@@ -197,5 +212,7 @@
      			}
    		} elseif ($do == "update") {
-			$result = mysql_query("update  ".$prefix."_ele_conf set descrizione='$descrizione', limite='$limite', consin='$consin', infpremio='$infpremio', supsbarramento='$supsbarramento', suppremio='$suppremio', listinfsbar='$listinfsbar', listinfconta='$listinfconta', listsupconta='$listsupconta', infminpremio='$infminpremio', supminpremio='$supminpremio' where id_conf='$id_conf' ", $dbi) || die("Errore di aggiornamento dei dati!".mysql_error());
+			$sql="update  ".$prefix."_ele_conf set descrizione='$descrizione', limite='$limite', consin='$consin', infpremio='$infpremio', supsbarramento='$supsbarramento', suppremio='$suppremio', listinfsbar='$listinfsbar', listinfconta='$listinfconta', listsupconta='$listsupconta', infminpremio='$infminpremio', supminpremio='$supminpremio' where id_conf='$id_conf' ";
+			$result = $dbi->prepare("$sql");
+			$result->execute();	
 			Header("Location: admin.php?op=confconsiglio&id_cons_gen=$id_cons_gen&min=$min");
    		}
Index: trunk/admin/modules/Elezioni/ele_configurazione.php
===================================================================
--- trunk/admin/modules/Elezioni/ele_configurazione.php	(revision 256)
+++ trunk/admin/modules/Elezioni/ele_configurazione.php	(revision 257)
@@ -257,6 +257,6 @@
 		$sth = $dbi->prepare("$sql");
 		$sth->execute();
-		$sql2 = $sth->fetch(PDO::FETCH_BOTH);
-		foreach($sql2 as $row){
+		while( $row = $sth->fetch(PDO::FETCH_BOTH)) {
+	#	foreach($sql2 as $row){
 			$esi=0;
 			for ($i=0; $i < sizeof($tlist); $i++) {
Index: trunk/admin/modules/Elezioni/ele_cons_comuni.php
===================================================================
--- trunk/admin/modules/Elezioni/ele_cons_comuni.php	(revision 256)
+++ trunk/admin/modules/Elezioni/ele_cons_comuni.php	(revision 257)
@@ -13,6 +13,6 @@
 }
 
+$aid=$_SESSION['aid'];
 global $dbi;
-$aid=$_SESSION['aid'];
 $prefix=$_SESSION['prefix'];
 if($param)
@@ -23,9 +23,10 @@
 $perms=ChiSei(0);
 if ($perms<64 or !$id_cons_gen) die("Non hai i permessi per inserire dati, o non hai scelto la consultazione!");
+$sql="SELECT tipo_cons,descrizione FROM ".$prefix."_ele_consultazione where id_cons_gen='$id_cons_gen' ";
+$res = $dbi->prepare("$sql");
+$res->execute();	
+list($tipo_cons,$descr_cons) = $res->fetch(PDO::FETCH_NUM);
 include("modules/Elezioni/funzionidata.php");
 include("modules/Elezioni/ele.php");
-$row=descr_cons();
-$tipo_cons=$row[0];$descr_cons=$row[2];
-
 if (isset($param['do'])) get_magic_quotes_gpc() ? $do=$param['do']:$do=addslashes($param['do']); else $do='';
 if (isset($param['ok'])) get_magic_quotes_gpc() ? $ok=$param['ok']:$ok=addslashes($param['ok']); else $ok='';
@@ -49,11 +50,13 @@
 
 	if (isset($help)) include("language/$language/ele_cons_comuni.html");
-	$row=descr_comune();
-	$res = mysql_query("SELECT id_cons FROM ".$prefix."_ele_comuni where id_comune=$id_comune", $dbi);
-	if (count($row)) $idpred = $row[2]; else $idpred='';
-#	$res = mysql_query("SELECT t1.id_cons, t2.descrizione FROM ".$prefix."_ele_cons_comune as t1 left join ".$prefix."_ele_consultazione as t2 on t1.id_cons_gen=t2.id_cons_gen where t1.id_comune='$id_comune' " , $dbi);
-	$row=elenco_cons_comune();
-	
-	$max = count($row);
+
+	$sql="SELECT id_cons FROM ".$prefix."_ele_comuni where id_comune=$id_comune";
+	$res = $dbi->prepare("$sql");
+	$res->execute();	
+	if ($res->rowCount()) list($idpred) = $res->fetch(PDO::FETCH_NUM); else $idpred='';
+	$sql="SELECT t1.id_cons, t2.descrizione FROM ".$prefix."_ele_cons_comune as t1 left join ".$prefix."_ele_consultazione as t2 on t1.id_cons_gen=t2.id_cons_gen where t1.id_comune='$id_comune' ";
+	$res = $dbi->prepare("$sql");
+	$res->execute();	
+	$max = $res->rowCount();
 	echo "<table border=\"0\" width=\"100%\" align=\"left\"><tr><td>";
 	echo "<form name=\"imppred\" action=\"admin.php\">";
@@ -61,5 +64,5 @@
    	."&nbsp;<b>"._CONSPRED."</b>&nbsp;</td><td><select name=\"predefinita\">";
 	echo "<option value=\"\">";
-	foreach($row as $arr){
+	while($arr=$res->fetch(PDO::FETCH_BOTH)){
 		$sel='';
 		if (($idpred))
@@ -80,17 +83,14 @@
 	."<td bgcolor=\"$bgcolor1\" align=\"center\"><b>"._COPIA." "._NUM." "._ELETTORI."</b></td>"
 	."<td bgcolor=\"$bgcolor1\" align=\"center\"><b>"._FUNZIONI."</b></td></tr>";
-	$sql = "select t2.chiusa,t2.id_cons,t1.* from ".$prefix."_ele_consultazione as t1, ".$prefix."_ele_cons_comune as t2, ".$prefix."_ele_tipo as t3 where t1.tipo_cons=t3.tipo_cons and t2.id_comune='$id_comune' and t1.id_cons_gen=t2.id_cons_gen and t2.id_cons!=$id_cons ORDER BY data_fine desc LIMIT $min,$offset";
-	$sth = $dbi->prepare("$sql");
-	$sth->execute();	
-	$row = $sth->fetchAll();
+	$sql="select t2.chiusa,t2.id_cons,t1.* from ".$prefix."_ele_consultazione as t1, ".$prefix."_ele_cons_comune as t2, ".$prefix."_ele_tipo as t3 where t1.tipo_cons=t3.tipo_cons and t2.id_comune='$id_comune' and t1.id_cons_gen=t2.id_cons_gen and t2.id_cons!=$id_cons ORDER BY data_fine desc LIMIT $min,$offset";
+	$res = $dbi->prepare("$sql");
+	$res->execute();	
 	$i=0;
-	foreach($row as $arr) {
-		$chiusa=$arr[0];$id_cons2=$arr[1];$idconsgen2=$arr[2]; $descr_cons=$arr[3]; $data_inizio=$arr[4]; $data_fine=$arr[5];$tipo=$arr[6];
+	while(list($chiusa,$id_cons2,$idconsgen2, $descr_cons, $data_inizio, $data_fine,$tipo) = $res->fetch(PDO::FETCH_NUM)) {
 		$bgcolor1=($bgcolor1==$_SESSION['bgcolor1'])?$_SESSION['bgcolor2']:$_SESSION['bgcolor1'];
-		$sql = "select count(id_cons) from ".$prefix."_ele_sezioni where id_cons='$id_cons2'";
-		$sth = $dbi->prepare("$sql");
-		$sth->execute();	
-		$row = $sth->fetch(PDO::FETCH_BOTH);
-		$somma=$row[0];
+		$sql="select count(id_cons) from ".$prefix."_ele_sezioni where id_cons='$id_cons2'";
+		$ressez = $dbi->prepare("$sql");
+		$ressez->execute();	
+		list($somma)=$ressez->fetch(PDO::FETCH_NUM);
 		$data_inizio=form_data($data_inizio);$data_fine=form_data($data_fine);
 		echo "<tr bgcolor=\"$bgcolor1\" align=\"center\" ><td align=\"left\" ><a href=\"admin.php?op=cons_comuni&amp;id_cons_gen=$idconsgen2\"><b>$descr_cons</b></a></td>"
@@ -151,80 +151,63 @@
 if ($perms>32) {
 	$sql="select id_cons from ".$prefix."_ele_cons_comune where id_cons_gen='$id_cons_gen' and id_comune=$id_comune";
-	$sth = $dbi->prepare("$sql");
-	$sth->execute();	
-	$row = $sth->fetch(PDO::FETCH_BOTH);
-	$id_consulta=$row[0];
+	$res = $dbi->prepare("$sql");
+	$res->execute();	
+	list($id_consulta)=$res->fetch(PDO::FETCH_NUM);
 	$sql="select t1.descrizione from ".$prefix."_ele_consultazione as t1, ".$prefix."_ele_cons_comune as t2 where t2.id_cons='$id_cons2' and t1.id_cons_gen=t2.id_cons_gen";
-	$sth = $dbi->prepare("$sql");
-	$sth->execute();	
-	$row = $sth->fetch(PDO::FETCH_BOTH);
-		
-	$descr_cons2=$row[0];
+	$res = $dbi->prepare("$sql");
+	$res->execute();	
+	list($descr_cons2)=$res->fetch(PDO::FETCH_NUM);
 	if ($do == "add") {
 		if ($id_cons2) {
 			// copia circoscrizione
-			$sql="select * from ".$prefix."_ele_circoscrizione where id_cons='$id_consulta'";
-			$sth = $dbi->prepare("$sql");
-			$sth->execute();	
-			$row = $sth->fetchAll();
-			foreach($row as $arr){
-				$id=$arr[0];$idcirc=$arr[1];$num=$arr[2];$des2=$arr[3];
-				$des=addslashes($des2);
-				$sql="select count(0) from ".$prefix."_ele_circoscrizione where id_cons='$id_cons2' and num_circ='$num'";
-				$sth = $dbi->prepare("$sql");
-				$sth->execute();	
-				$row = $sth->fetch(PDO::FETCH_BOTH);
-				$contr_circ=$row[0];
-				if (! $contr_circ){
-					sql="insert into ".$prefix."_ele_circoscrizione (id_cons,num_circ,descrizione) values ('$id_cons2',$num,'$des')";
-					$sth = $dbi->prepare("$sql");
-					$sth->execute();	
-
-				}
+			$res=mysql_query("select * from ".$prefix."_ele_circoscrizione where id_cons='$id_consulta'", $dbi);
+			$res = $dbi->prepare("$sql");
+			$res->execute();	
+			while (list($id,$idcirc,$num,$des2)=$res->fetch(PDO::FETCH_NUM)){
+			$des=addslashes($des2);
+			$sql="select count(0) from ".$prefix."_ele_circoscrizione where id_cons='$id_cons2' and num_circ='$num'";
+			$resconnew = $dbi->prepare("$sql");
+			$resconnew->execute();	
+			list($contr_circ)=$resconnew->fetch(PDO::FETCH_NUM);
+			if (! $contr_circ){
+				$sql="insert into ".$prefix."_ele_circoscrizione (id_cons,num_circ,descrizione) values ('$id_cons2',$num,'$des')";
+				$res = $dbi->prepare("$sql");
+				$res->execute();	
+}
 				$sql="select id_circ from ".$prefix."_ele_circoscrizione where id_cons=$id_cons2 and num_circ=$num";
-				$sth = $dbi->prepare("$sql");
-				$sth->execute();	
-				$row = $sth->fetch(PDO::FETCH_BOTH);
-				$id_circ=$row[0];
+				$res0 = $dbi->prepare("$sql");
+				$res0->execute();	
+				list($id_circ)=$res0->fetch(PDO::FETCH_NUM);
 				// copia sede
 				$sql="select * from ".$prefix."_ele_sede where id_cons='$id_consulta' and id_circ='$idcirc'";
-				$sth = $dbi->prepare("$sql");
-				$sth->execute();	
-				$row = $sth->fetchAll();
-				foreach($row as $row2) {
-					$id1=$row2[0];$idsede1=$row2[1];$idcirc1=$row2[2];$ind2=$row2[3];$tel=$row2[4];$tel2=$row2[5];$fax=$row2[6];$resp=$row2[7];$mappa2=$row2[8];$filemappa2=$row2[9];
+				$res1 = $dbi->prepare("$sql");
+				$res1->execute();	
+				while(list($id1,$idsede1,$idcirc1,$ind2,$tel,$tel2,$fax,$resp,$mappa2,$filemappa2)=$res1->fetch(PDO::FETCH_NUM)){
 					$filemappa=addslashes($filemappa2);
 					$mappa=addslashes($mappa2);
 					$ind=addslashes($ind2);
 					$sql="select count(0) from ".$prefix."_ele_sede where id_cons='$id_cons2' and indirizzo='$ind'";
-					$sth = $dbi->prepare("$sql");
-					$sth->execute();	
-					$row = $sth->fetch(PDO::FETCH_BOTH);
-					$contr_sed=$row[0];
+					$resswdnew = $dbi->prepare("$sql");
+					$ressednew->execute();	
+					list($contr_sed)=$ressednew->fetch(PDO::FETCH_NUM);
 					if (! $contr_sed){
-						$sql="insert into ".$prefix."_ele_sede (id_cons,id_circ,indirizzo,telefono1,telefono2,fax,responsabile,mappa,filemappa) values ('$id_cons2','$id_circ','$ind','$tel','$tel2','$fax','$resp','$mappa','$filemappa')";
-						$sth = $dbi->prepare("$sql");
-						$sth->execute();	
-					}
-					$sql"select id_sede from ".$prefix."_ele_sede where id_cons=$id_cons2 and id_circ=$id_circ and indirizzo='$ind'";
-					list($id_sede)=mysql_fetch_row($res2);
-					$sth = $dbi->prepare("$sql");
-					$sth->execute();	
-					$row = $sth->fetch(PDO::FETCH_BOTH);
-					$id_sede=$row[0];
+					$sql="insert into ".$prefix."_ele_sede (id_cons,id_circ,indirizzo,telefono1,telefono2,fax,responsabile,mappa,filemappa) values ('$id_cons2','$id_circ','$ind','$tel','$tel2','$fax','$resp','$mappa','$filemappa')";
+					$res0 = $dbi->prepare("$sql");
+					$res0->execute();	
+}
+					$sql="select id_sede from ".$prefix."_ele_sede where id_cons=$id_cons2 and id_circ=$id_circ and indirizzo='$ind'";
+					$res2 = $dbi->prepare("$sql");
+					$res2->execute();	
+					list($id_sede)=$res2->fetch(PDO::FETCH_NUM);
 					//copia sezione
 					$sql="select * from ".$prefix."_ele_sezioni where id_cons=$id_consulta and id_sede=$idsede1";
-					$sth = $dbi->prepare("$sql");
-					$sth->execute();	
-					$row = $sth->fetchAll();
-					foreach($row as $arr2)
-					{
-						$id3=$arr2[0];$idsez3=$arr2[1];$idsede3=$arr2[2];$numero=$arr2[3];$maschi3=$arr2[4];$femmine3=$arr2[5];$validi3=$arr2[6];$nulli3=$arr2[7];
-						$bianchi3=$arr2[8];$contest3=$arr2[9];$sg3,$aut_m=$arr2[10];$aut_f=$arr2[11];
+					$res3 = $dbi->prepare("$sql");
+					$res3->execute();	
+					while (list($id3,$idsez3,$idsede3,$numero,$maschi3,$femmine3,$validi3,$nulli3,
+						$bianchi3,$contest3,$sg3,$aut_m,$aut_f)=$res3->fetch(PDO::FETCH_NUM)){
 						if ($elettori=='true') $sql="insert into ".$prefix."_ele_sezioni (id_cons,id_sede,num_sez,maschi,femmine) values ('$id_cons2','$id_sede','$numero','$maschi3','$femmine3')";
 						else $sql="insert into ".$prefix."_ele_sezioni (id_cons,id_sede,num_sez) values ('$id_cons2','$id_sede','$numero')";
-						$sth = $dbi->prepare("$sql");
-						$sth->execute();	
-
+						$res3 = $dbi->prepare("$sql");
+						$res3->execute();	
 					}
 				}
@@ -240,23 +223,21 @@
 		}else{
 		$sql="update ".$prefix."_ele_sezioni as t1, ".$prefix."_ele_sezioni as t2 set t1.maschi=t2.maschi, t1.femmine=t2.femmine WHERE t1.id_cons=$id_cons2 and t2.id_cons=$id_consulta and t1.num_sez=t2.num_sez";
-		$sth = $dbi->prepare("$sql");
-		$result=$sth->execute();	
-
-		if (!$result) return;
+		$result = $dbi->prepare("$sql");
+		$result->execute();	
+		if (!$result->rowCount()) return;
 		Header("Location: admin.php?op=cons_comuni&id_cons_gen=$id_cons_gen");
 		}
    	} 
 	if ($do == "update") {
-		if ($predefinita) 
-		{
+		if ($predefinita) {
 			$sql="update  ".$prefix."_ele_comuni set  id_cons='$predefinita' WHERE id_comune='$id_comune'";
-			$sth = $dbi->prepare("$sql");
-			$result=$sth->execute();	
+			$result = $dbi->prepare("$sql");
+			$result->execute();	
 		}else{
-			$sql"update  ".$prefix."_ele_cons_comune set  chiusa='$chiusa' WHERE id_cons2='$id_cons2'";
-			$sth = $dbi->prepare("$sql");
-			$result=$sth->execute();	
-		}
-			if (!$result) return;
+			$sql="update  ".$prefix."_ele_cons_comune set  chiusa='$chiusa' WHERE id_cons2='$id_cons2'";
+			$result = $dbi->prepare("$sql");
+			$result->execute();	
+		}
+		if (!$result->rowCount()) return;
 		Header("Location: admin.php?op=cons_comuni&id_cons_gen=$id_cons_gen");
    	} 
Index: trunk/admin/modules/Elezioni/ele_consultazioni.php
===================================================================
--- trunk/admin/modules/Elezioni/ele_consultazioni.php	(revision 256)
+++ trunk/admin/modules/Elezioni/ele_consultazioni.php	(revision 257)
@@ -12,5 +12,5 @@
     die ("You can't access this file directly...");
 }
-global $dbi;
+global $dbi,$tipo_cons;
 $aid=$_SESSION['aid'];
 $prefix=$_SESSION['prefix'];
@@ -266,5 +266,5 @@
 			$sth = $dbi->prepare("$sql");
 			$sth->execute();	
-			if (!$result) return;
+			if (!$sth->rowCount()) return;
 			Header("Location: admin.php?op=consultazione&id_cons_gen=$id_cons_gen");
    		}
Index: trunk/admin/modules/Elezioni/ele_consultazionitipi.php
===================================================================
--- trunk/admin/modules/Elezioni/ele_consultazionitipi.php	(revision 256)
+++ trunk/admin/modules/Elezioni/ele_consultazionitipi.php	(revision 257)
@@ -12,7 +12,6 @@
     die ("You can't access this file directly...");
 }
-
+global $dbi;
 $aid=$_SESSION['aid'];
-$dbi=$_SESSION['dbi'];
 $prefix=$_SESSION['prefix'];
 $param=strtolower($_SERVER['REQUEST_METHOD']) == 'get' ? $_GET : $_POST;
@@ -21,6 +20,8 @@
 //if ($perms<128 or !$id_cons_gen) die("Non hai i permessi per inserire dati, o non hai scelto la consultazione!");
 if ($perms!=256) die("Non hai i permessi per inserire dati, o non hai scelto la consultazione!");
-$res = mysql_query("SELECT tipo_cons FROM ".$prefix."_ele_consultazione where id_cons_gen=$id_cons_gen " , $dbi);
-list($tipo_cons) = mysql_fetch_row($res);
+$sql="SELECT tipo_cons FROM ".$prefix."_ele_consultazione where id_cons_gen=$id_cons_gen ";
+$res = $dbi->prepare("$sql");
+$res->execute();	
+list($tipo_cons) = $res->fetch(PDO::FETCH_NUM);
 
 if (isset($param['min'])) $min=intval($param['min']); else $min=0;
@@ -91,6 +92,8 @@
 	echo "</script>\n";
 	if ($do == "modify") {
-		$rest = mysql_query("SELECT * FROM ".$prefix."_ele_tipo where tipo_cons='$tipocons' and lingua='$language'", $dbi);
-		$pro_t=mysql_fetch_array($rest, 3);
+		$sql="SELECT * FROM ".$prefix."_ele_tipo where tipo_cons='$tipocons' and lingua='$language'";
+		$rest = $dbi->prepare("$sql");
+		$rest->execute();
+		$pro_t=$rest->fetch(PDO::FETCH_BOTH);
 
 		echo "<form name=\"consultazione\" method=\"post\" action=\"admin.php\" >"
@@ -150,10 +153,8 @@
 	."<td bgcolor=\"$bgcolor1\" align=\"center\"><b>"._FUNZIONI."</b></td></tr>";
 
-		$result = mysql_query("SELECT tipo_cons,descrizione FROM ".$prefix."_ele_tipo where lingua='$language' LIMIT $min,$offset", $dbi);
-		
-
-
-
-	while(list($tipocons, $descr_cons) = mysql_fetch_row($result)) {
+	$sql="SELECT tipo_cons,descrizione FROM ".$prefix."_ele_tipo where lingua='$language' LIMIT $min,$offset";
+	$result = $dbi->prepare("$sql");
+	$result->execute();
+	while(list($tipocons, $descr_cons) = $result->fetch(PDO::FETCH_NUM)) {
 		
 		$bgcolor1=($bgcolor1==$_SESSION['bgcolor1'])?$_SESSION['bgcolor2']:$_SESSION['bgcolor1'];
@@ -173,6 +174,8 @@
 	}
 	$next=$min+$offset;
-	$res = mysql_query("SELECT * FROM ".$prefix."_ele_tipo where lingua='$language' " , $dbi);
-	$max = mysql_num_rows($res);
+	$sql="SELECT * FROM ".$prefix."_ele_tipo where lingua='$language' ";
+	$res = $dbi->prepare("$sql");
+	$res->execute();	
+	$max = $res->rowCount();
 	if ($next>=($offset-1)) {
 		if($next>=$max) $next = $max;
@@ -208,15 +211,21 @@
 				$voticandi=$voticandi=='true'? 1:0;
 				$circo=$circo=='true'? 1:0;
-				$result = mysql_query("select max(tipo_cons) from ".$prefix."_ele_tipo where lingua='$language'", $dbi);
-				list($max)=mysql_fetch_row($result);
+				$sql="select max(tipo_cons) from ".$prefix."_ele_tipo where lingua='$language'";
+				$result = $dbi->prepare("$sql");
+				$result->execute();				
+				list($max)=$result->fetch(PDO::FETCH_NUM);
 				$max++;
 
-				$result = mysql_query("insert into ".$prefix."_ele_tipo (tipo_cons,descrizione,lingua,genere,voto_g,voto_l,voto_c,circo) values ('$max','$descr_cons2','$language','$genere','$votigruppo','$votilista','$voticandi','$circo')", $dbi) || die("Errore di inserimento: ".mysql_error());
+				$sql="insert into ".$prefix."_ele_tipo (tipo_cons,descrizione,lingua,genere,voto_g,voto_l,voto_c,circo) values ('$max','$descr_cons2','$language','$genere','$votigruppo','$votilista','$voticandi','$circo')";
+				$result = $dbi->prepare("$sql");
+				$result->execute();				
 
 
 			}
 		}else if ($do == "update") {
-			$result = mysql_query("update  ".$prefix."_ele_tipo set descrizione='$descr_cons2' WHERE tipo_cons='$tipocons' and lingua='$language'", $dbi);
-			if (!$result) return;
+			$sql="update  ".$prefix."_ele_tipo set descrizione='$descr_cons2' WHERE tipo_cons='$tipocons' and lingua='$language'";
+			$result = $dbi->prepare("$sql");
+			$result->execute();				
+			if (!$result->rowCount()) return;
 			Header("Location: admin.php?op=constipi&id_cons_gen=$id_cons_gen");
    		}
Index: trunk/admin/modules/Elezioni/ele_gruppo.php
===================================================================
--- trunk/admin/modules/Elezioni/ele_gruppo.php	(revision 256)
+++ trunk/admin/modules/Elezioni/ele_gruppo.php	(revision 257)
@@ -15,7 +15,6 @@
 // Offset - visualizza il numero di elementi per pagina
 $offset=5;
-
+global $dbi;
 $aid=$_SESSION['aid'];
-$dbi=$_SESSION['dbi'];
 $prefix=$_SESSION['prefix'];
 $currentlang=$_SESSION['lang'];
@@ -25,6 +24,8 @@
 if ($perms<32 or !$id_cons_gen) die("Non hai i permessi per inserire dati, o non hai scelto la consultazione!");
 $id_comune=$_SESSION['id_comune'];
-$res = mysql_query("SELECT t1.tipo_cons,t2.id_cons 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) = mysql_fetch_row($res);
+$sql="SELECT t1.tipo_cons,t2.id_cons 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) = $res->fetch(PDO::FETCH_NUM);
 
 include("modules/Elezioni/funzionidata.php");
@@ -48,15 +49,19 @@
 	function all() {
    		global $delsimb,$delprog,$tipo_cons,$param,$currentlang, $bgcolor1, $bgcolor2, $prefix, $dbi, $offset, $min, $id_cons,$id_cons_gen,$id_comune,$id_circ,$do,$id_gruppo;
-	$res = mysql_query("SELECT circo FROM ".$prefix."_ele_tipo where tipo_cons='$tipo_cons' and lingua='$currentlang'", $dbi);
-	list($cons_circ)= mysql_fetch_row($res);
+	$sql="SELECT circo FROM ".$prefix."_ele_tipo where tipo_cons='$tipo_cons' and lingua='$currentlang'";
+	$res = $dbi->prepare("$sql");
+	$res->execute();				
+	list($cons_circ)= $res->fetch(PDO::FETCH_NUM);
 	if($cons_circ)
 	{
 		echo "<form name=\"circo\" action=\"admin.php\" method=\"post\">";
 		echo "<br><table border=\"1\" width=\"50%\" ><tr bgcolor=\"$bgcolor1\"><td>"._SCEGLI_CIRCO.": </td>";
-		$res = mysql_query("SELECT * FROM ".$prefix."_ele_circoscrizione where id_cons='$id_cons'", $dbi);
+		$sql="SELECT * FROM ".$prefix."_ele_circoscrizione where id_cons='$id_cons'";
+		$res = $dbi->prepare("$sql");
+		$res->execute();						
 		echo "<input type=\"hidden\" name=\"pag\" value=\"admin.php?op=gruppo&amp;id_cons_gen=$id_cons_gen&amp;id_circ=\">";
 		echo "<td><select name=\"id_circ\" onChange=\"top.location.href=this.form.pag.value+this.form.id_circ.options[this.form.id_circ.selectedIndex].value;return false\">";
 		echo "<option value=\"\">";
-		while($arr=mysql_fetch_array($res,3)){
+		while($arr=$res->fetch(PDO::FETCH_BOTH)){
 			if (!$id_circ) $id_circ=$arr['id_circ'];
 			$sel= ($arr['id_circ'] == $id_circ) ? "selected":"";
@@ -87,11 +92,15 @@
 	//-----------------------visualizza riga superiore per inserimento -
 	$circo= $cons_circ==1 ? "and id_circ='$id_circ'":"";	
-	$res = mysql_query("SELECT * FROM ".$prefix."_ele_gruppo where id_cons='$id_cons' $circo ", $dbi);
-	$max = mysql_num_rows($res);
+	$sql="SELECT * FROM ".$prefix."_ele_gruppo where id_cons='$id_cons' $circo ";
+	$res = $dbi->prepare("$sql");
+	$res->execute();						
+	$max = $res->rowCount();
 	$nuovo_gruppo=$max+1;
 	echo "<tr><td>";
 	if ($do=='modify') {
-	$resl = mysql_query("SELECT * FROM ".$prefix."_ele_gruppo where id_gruppo='$id_gruppo'", $dbi);
-	$gru=mysql_fetch_array($resl);
+	$sql="SELECT * FROM ".$prefix."_ele_gruppo where id_gruppo='$id_gruppo'";
+	$resl = $dbi->prepare("$sql");
+	$resl->execute();						
+	$gru=$resl->fetch(PDO::FETCH_BOTH);
 	$nuovo_gruppo=$gru['num_gruppo'];
 	echo "<input type=\"hidden\" name=\"do\" value=\"update\">";
@@ -126,10 +135,16 @@
 		
 		
-	$res = mysql_query("SELECT * FROM ".$prefix."_ele_gruppo where id_cons='$id_cons' $circo ", $dbi);
-	$max = mysql_num_rows($res);
-	$result = mysql_query("select * from ".$prefix."_ele_gruppo where id_cons='$id_cons' $circo ORDER BY num_gruppo  LIMIT $min,$offset", $dbi);
-	while(list($id_cons2,$id_gruppo,$num_gruppo, $descr_gruppo, $simbolo,,, $prognome) = mysql_fetch_row($result)) {
-		$restemp = mysql_query("select count(0) from ".$prefix."_ele_lista where id_gruppo='$id_gruppo'", $dbi);
-		list($numtemp)=mysql_fetch_row($restemp);
+	$sql="SELECT * FROM ".$prefix."_ele_gruppo where id_cons='$id_cons' $circo ";
+	$res = $dbi->prepare("$sql");
+	$res->execute();						
+	$max = $res->rowCount();
+	$sql="select * from ".$prefix."_ele_gruppo where id_cons='$id_cons' $circo ORDER BY num_gruppo  LIMIT $min,$offset";
+	$result = $dbi->prepare("$sql");
+	$result->execute();						
+	while(list($id_cons2,$id_gruppo,$num_gruppo, $descr_gruppo, $simbolo,,, $prognome) = $result->fetch(PDO::FETCH_NUM)) {
+		$sql="select count(0) from ".$prefix."_ele_lista where id_gruppo='$id_gruppo'";
+		$restemp = $dbi->prepare("$sql");
+		$restemp->execute();						
+		list($numtemp)=$restemp->fetch(PDO::FETCH_NUM);
 		$bgcolor1=($bgcolor1==$_SESSION['bgcolor1'])?$_SESSION['bgcolor2']:$_SESSION['bgcolor1'];
 		if (!$simbolo) $simbolo="nulla.jpg";
@@ -183,22 +198,38 @@
 	if ($perms >16) {
        	if ($do == "delete") {  
-     			if ($ok !="1") {
+     		if ($ok !="1") {
 				ele();
 				echo "<center><br><br>"._DOMCANCELLA." "._GRUPPO." $descr_gruppo ?<br>";
 				echo "[ <a href=\"admin.php?op=gruppo&amp;id_cons_gen=$id_cons_gen&amp;id_circ=$id_circ\">"._NO."</a> ] - [<a href=\"admin.php?op=gruppo&amp;do=delete&amp;id_gruppo=$id_gruppo&amp;id_cons_gen=$id_cons_gen&amp;id_comune=$id_comune&amp;min=$min&amp;ok=1\">"._YES."</a> ]";exit;
-     			}else{
-				$reslis = mysql_query("select id_lista from ".$prefix."_ele_lista where id_gruppo='$id_gruppo'", $dbi);
-				while (list($idlst)=mysql_fetch_row($reslis)){
-				$rescan = mysql_query("select id_cand from ".$prefix."_ele_candidato where id_lista='$idlst'", $dbi);
-				while (list($idcnd)=mysql_fetch_row($rescan)){
-					mysql_query("delete from  ".$prefix."_ele_voti_candidati where id_cand='$idcnd'");
-					mysql_query("delete from  ".$prefix."_ele_candidati where id_cand='$idcnd'");
+     		}else{
+				$sql="select id_lista from ".$prefix."_ele_lista where id_gruppo='$id_gruppo'";
+				$reslis = $dbi->prepare("$sql");
+				$reslis->execute();						
+				while (list($idlst)=$reslis->fetch(PDO::FETCH_NUM)){
+					$sql="select id_cand from ".$prefix."_ele_candidato where id_lista='$idlst'";
+					$rescan = $dbi->prepare("$sql");
+					$rescan->execute();						
+					while (list($idcnd)=$rescan->fetch(PDO::FETCH_NUM)){
+						$sql="delete from  ".$prefix."_ele_voti_candidati where id_cand='$idcnd'";
+						$res = $dbi->prepare("$sql");
+						$res->execute();						
+						$sql="delete from  ".$prefix."_ele_candidati where id_cand='$idcnd'";
+						$res = $dbi->prepare("$sql");
+						$res->execute();						
+					}
+					$sql="delete from  ".$prefix."_ele_voti_lista where id_lista='$idlst'";
+					$res = $dbi->prepare("$sql");
+					$res->execute();						
+					$sql="delete from  ".$prefix."_ele_lista where id_lista='$idlst'";
+					$res = $dbi->prepare("$sql");
+					$res->execute();						
 				}
-				mysql_query("delete from  ".$prefix."_ele_voti_lista where id_lista='$idlst'");
-				mysql_query("delete from  ".$prefix."_ele_lista where id_lista='$idlst'");
-				}
-				$result = mysql_query("delete from ".$prefix."_ele_voti_gruppo where id_gruppo='$id_gruppo'", $dbi);
-				$result = mysql_query("delete from ".$prefix."_ele_gruppo where id_gruppo='$id_gruppo'", $dbi);
-          			if (!$result) return;
+				$sql="delete from ".$prefix."_ele_voti_gruppo where id_gruppo='$id_gruppo'";
+				$res = $dbi->prepare("$sql");
+				$res->execute();						
+				$sql="delete from ".$prefix."_ele_gruppo where id_gruppo='$id_gruppo'";
+				$res = $dbi->prepare("$sql");
+				$res->execute();						
+         		if (!$result) return;
 				Header("Location: admin.php?op=gruppo&id_cons_gen=$id_cons_gen&id_circ=$id_circ&min=$min");
 			}
@@ -230,6 +261,8 @@
 					$prognome=addslashes($nomeprog );
 				}
-      				$result = mysql_query("insert into ".$prefix."_ele_gruppo (id_cons,id_gruppo,num_gruppo,descrizione,simbolo,stemma,id_circ,prognome,programma) values ('$id_cons','$id_gruppo','$num_gruppo','$descr_gruppo','$stemmanome','$stemmablob','$id_circ','$prognome','$progblob')", $dbi);
-           			if (!$result) return;
+      			$sql="insert into ".$prefix."_ele_gruppo (id_cons,id_gruppo,num_gruppo,descrizione,simbolo,stemma,id_circ,prognome,programma) values ('$id_cons','$id_gruppo','$num_gruppo','$descr_gruppo','$stemmanome','$stemmablob','$id_circ','$prognome','$progblob')";
+ 				$result = $dbi->prepare("$sql");
+				$result->execute();						
+          			if (!$result->rowCount()) return;
            			Header("Location: admin.php?op=gruppo&id_cons_gen=$id_cons_gen&id_circ=$id_circ&min=$min");
      			} else {
@@ -276,5 +309,7 @@
 					else $cond2='';
 			}
-         		$result = mysql_query("update  ".$prefix."_ele_gruppo set num_gruppo='$num_gruppo' , descrizione='$descr_gruppo' $cond $cond2 where id_gruppo='$id_gruppo' ", $dbi) || die("Errore di aggiornamento dei dati!".mysql_error());
+         		$sql="update  ".$prefix."_ele_gruppo set num_gruppo='$num_gruppo' , descrizione='$descr_gruppo' $cond $cond2 where id_gruppo='$id_gruppo' ";
+ 				$result = $dbi->prepare("$sql");
+				$result->execute();						
 			Header("Location: admin.php?op=gruppo&id_cons_gen=$id_cons_gen&id_circ=$id_circ&min=$min");
    		}
Index: trunk/admin/modules/Elezioni/ele_lista.php
===================================================================
--- trunk/admin/modules/Elezioni/ele_lista.php	(revision 256)
+++ trunk/admin/modules/Elezioni/ele_lista.php	(revision 257)
@@ -19,6 +19,8 @@
 $perms=ChiSei($id_cons_gen);
 if ($perms<32 or !$id_cons_gen) die("$id_cons_gen -Non hai i permessi per inserire dati, o non hai scelto la consultazione!");
-$res = mysql_query("SELECT t1.tipo_cons,t2.id_cons 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) = mysql_fetch_row($res);
+$sql="SELECT t1.tipo_cons,t2.id_cons 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) = $res->fetch(PDO::FETCH_NUM);
 
 include("modules/Elezioni/funzionidata.php");
@@ -54,16 +56,20 @@
 	
 	$circo='';
-	$res = mysql_query("SELECT circo FROM ".$prefix."_ele_tipo where tipo_cons='$tipo_cons'", $dbi);
+	$sql="SELECT circo FROM ".$prefix."_ele_tipo where tipo_cons='$tipo_cons'";
 #	$res = mysql_query("SELECT circo FROM ".$prefix."_ele_tipo where tipo_cons='$tipo_cons' and lingua='$currentlang'", $dbi);
-	list($cons_circ)= mysql_fetch_row($res);
+	$res = $dbi->prepare("$sql");
+	$res->execute();						
+	list($cons_circ)= $res->fetch(PDO::FETCH_NUM);
 	if($cons_circ)
 	{
 		echo "<form name=\"circo\" action=\"admin.php\" method=\"post\">";
 		echo "<br><br><table border=\"1\" width=\"50%\" ><tr bgcolor=\"$bgcolor1\"><td>"._SCEGLI_CIRCO.": </td>";
-		$res = mysql_query("SELECT * FROM ".$prefix."_ele_circoscrizione where id_cons='$id_cons'", $dbi);
+		$sql="SELECT * FROM ".$prefix."_ele_circoscrizione where id_cons='$id_cons'";
+		$res = $dbi->prepare("$sql");
+		$res->execute();						
 		echo "<input type=\"hidden\" name=\"pag\" value=\"admin.php?op=lista&amp;id_cons_gen=$id_cons_gen&amp;id_circ=\">";
 		echo "<td><select name=\"id_circ\" onChange=\"top.location.href=this.form.pag.value+this.form.id_circ.options[this.form.id_circ.selectedIndex].value;return false\">";
 		echo "<option value=\"\">";
-		while($arr=mysql_fetch_array($res,3)){
+		while($arr=$res->fetch(PDO::FETCH_BOTH)){
 			if (!$id_circ) $id_circ=$arr['id_circ'];
 			$sel= ($arr['id_circ'] == $id_circ) ? "selected":"";
@@ -83,6 +89,8 @@
 	}
 	echo "<td bgcolor=\"$bgcolor1\" align=\"center\"><b>"._FUNZIONI."</b></td></tr>";
-	$res = mysql_query("SELECT * FROM ".$prefix."_ele_lista where id_cons='$id_cons' $circo ", $dbi);
-	$max = mysql_num_rows($res);
+	$sql="SELECT * FROM ".$prefix."_ele_lista where id_cons='$id_cons' $circo ";
+	$res = $dbi->prepare("$sql");
+	$res->execute();						
+	$max = $res->rowCount();
 	$nuova_lista=$max+1;
 	//-----------------------visualizza riga superiore per inserimento -
@@ -90,6 +98,8 @@
 	."<input type=\"hidden\" name=\"op\" value=\"lista\">";
 	if ($do=='modify') {
-	$resl = mysql_query("SELECT * FROM ".$prefix."_ele_lista where id_lista='$id_lista'", $dbi);
-	$lis=mysql_fetch_array($resl);
+	$sql="SELECT * FROM ".$prefix."_ele_lista where id_lista='$id_lista'";
+	$resl = $dbi->prepare("$sql");
+	$resl->execute();						
+	$lis=$resl->fetch(PDO::FETCH_BOTH);
 	$nuova_lista=$lis['num_lista'];
 	echo "<input type=\"hidden\" name=\"do\" value=\"update\">";
@@ -116,8 +126,10 @@
 		<option value=\"\">";
 		
-		$result1 = mysql_query("select id_gruppo, descrizione from ".$prefix."_ele_gruppo where id_cons=$id_cons $circo", $dbi);
+		$sql="select id_gruppo, descrizione from ".$prefix."_ele_gruppo where id_cons=$id_cons $circo";
+		$result1 = $dbi->prepare("$sql");
+		$result1->execute();						
 		$id_gruppo2= ($id_gruppo2)?$id_gruppo2:$id_gruppo;
 		if ($result1)
-		while(list($id,$descr)=mysql_fetch_row($result1)){
+		while(list($id,$descr)=$result1->fetch(PDO::FETCH_NUM)){
 			$sel= ($id == $id_gruppo2) ? "selected":"";
 			echo "<option value=\"$id\" $sel>$descr";
@@ -144,16 +156,24 @@
 	echo "</script>\n";
 	$grup= $id_gruppo ? "and id_gruppo='$id_gruppo'":"";
-	$result = mysql_query("select count(id_lista) from ".$prefix."_ele_lista where id_cons='$id_cons' $circo", $dbi);
-	list($numero) = mysql_fetch_row($result);
-	$result = mysql_query("select * from ".$prefix."_ele_lista where id_cons='$id_cons' $grup $circo ORDER BY num_lista  LIMIT $min,$offset", $dbi);
-	while(list($id_cons2,$id_lista,$num_lista, $id_gruppo,$id_circ, $descr_lista, $simbolo) = mysql_fetch_row($result)) {
+	$sql="select count(id_lista) from ".$prefix."_ele_lista where id_cons='$id_cons' $circo";
+	$result = $dbi->prepare("$sql");
+	$result->execute();						
+	list($numero) = $result->fetch(PDO::FETCH_NUM);
+	$sql="select * from ".$prefix."_ele_lista where id_cons='$id_cons' $grup $circo ORDER BY num_lista  LIMIT $min,$offset";
+	$result = $dbi->prepare("$sql");
+	$result->execute();						
+	while(list($id_cons2,$id_lista,$num_lista, $id_gruppo,$num_gruppo,$id_circ,$num_circ, $descr_lista, $simbolo) = $result->fetch(PDO::FETCH_NUM)) {
 		$bgcolor1=($bgcolor1==$_SESSION['bgcolor1'])?$_SESSION['bgcolor2']:$_SESSION['bgcolor1'];
         	// dati gruppo
 		if ($genere==1 or $genere==3 or $genere==5){ ###prova	
-		$result1 = mysql_query("select descrizione,simbolo from ".$prefix."_ele_gruppo where id_cons='$id_cons' and id_gruppo='$id_gruppo'", $dbi);
-        		list($descr_gruppo,$simb_gruppo)=mysql_fetch_row($result1);
-		}
-		$restemp = mysql_query("select count(0) from ".$prefix."_ele_candidati where id_lista='$id_lista'", $dbi);
-		list($numtemp)=mysql_fetch_row($restemp);
+			$sql="select descrizione,simbolo from ".$prefix."_ele_gruppo where id_cons='$id_cons' and id_gruppo='$id_gruppo'";
+			$result1 = $dbi->prepare("$sql");
+			$result1->execute();						
+        	list($descr_gruppo,$simb_gruppo)=$result1->fetch(PDO::FETCH_NUM);
+		}
+		$sql="select count(0) from ".$prefix."_ele_candidati where id_lista='$id_lista'";
+			$restemp = $dbi->prepare("$sql");
+			$restemp->execute();						
+		list($numtemp)=$restemp->fetch(PDO::FETCH_NUM);
 
 		echo "<tr bgcolor=\"$bgcolor1\"><td align=\"right\"><b>$num_lista</b>"
@@ -208,6 +228,8 @@
 			echo "[ <a href=\"admin.php?op=lista&amp;id_cons_gen=$id_cons_gen&amp;min=$min&amp;id_circ=$id_circ\">"._NO."</a> ] - [<a href=\"admin.php?op=lista&amp;do=delete&amp;id_lista=$id_lista&amp;id_gruppo=$id_gruppo&amp;id_circ=$id_circ&amp;ok=1&amp;min=$min&amp;id_cons_gen=$id_cons_gen\">"._YES."</a> ]";exit;
 		}else{
-			$result = mysql_query("delete from ".$prefix."_ele_lista where id_lista='$id_lista'", $dbi);
-			if (!$result)return;
+			$sql="delete from ".$prefix."_ele_lista where id_lista='$id_lista'";
+			$result = $dbi->prepare("$sql");
+			$result->execute();						
+			if (!$result->rowCount())return;
 			Header("Location: admin.php?op=lista&id_circ=$id_circ&id_cons_gen=$id_cons_gen&min=$min");
 		}
@@ -227,6 +249,8 @@
 				$stemmanome=addslashes($nomestemma);
 			}
-			$result = mysql_query("insert into ".$prefix."_ele_lista (id_cons,num_lista,id_gruppo,id_circ,descrizione,simbolo,stemma) values ('$id_cons','$num_lista','$id_gruppo','$id_circ','$descr_lista','$stemmanome','$stemmablob')", $dbi);
-			if (!$result) return;
+			$sql="insert into ".$prefix."_ele_lista (id_cons,num_lista,id_gruppo,id_circ,descrizione,simbolo,stemma) values ('$id_cons','$num_lista','$id_gruppo','$id_circ','$descr_lista','$stemmanome','$stemmablob')";
+			$result = $dbi->prepare("$sql");
+			$result->execute();						
+			if (!$result->rowCount()) return;
 			Header("Location: admin.php?op=lista&id_circ=$id_circ&min=$min&id_cons_gen=$id_cons_gen");
 		} else {
@@ -251,6 +275,8 @@
 		$cond=", simbolo='$stemmanome', stemma='$stemmablob'";
 		} else {$cond='';}
-		$result = mysql_query("update  ".$prefix."_ele_lista set  num_lista='$num_lista' , id_gruppo='$id_gruppo',descrizione='$descr_lista' $cond  where id_lista='$id_lista'", $dbi);
-		if (!$result) return;
+		$sql="update  ".$prefix."_ele_lista set  num_lista='$num_lista' , id_gruppo='$id_gruppo',descrizione='$descr_lista' $cond  where id_lista='$id_lista'";
+		$result = $dbi->prepare("$sql");
+		$result->execute();						
+		if (!$result->rowCount()) return;
 		Header("Location: admin.php?op=lista&id_circ=$id_circ&min=$min&id_cons_gen=$id_cons_gen");
 	}
Index: trunk/admin/modules/Elezioni/ele_operatori.php
===================================================================
--- trunk/admin/modules/Elezioni/ele_operatori.php	(revision 256)
+++ trunk/admin/modules/Elezioni/ele_operatori.php	(revision 257)
@@ -15,6 +15,8 @@
 $perms=ChiSei($id_cons_gen);
 if (($perms<64 or !$id_cons_gen) and $perms!=256) die("(($perms<64 or !$id_cons_gen) and $perms!=256)Non hai i permessi per inserire dati, o non hai scelto la consultazione!");
-$res = mysql_query("SELECT t1.tipo_cons,t2.id_cons 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) = mysql_fetch_row($res);
+$sql="SELECT t1.tipo_cons,t2.id_cons 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) = $res->fetch(PDO::FETCH_NUM);
 if (isset($_GET['aid2'])) get_magic_quotes_gpc() ? $aid2=$param['aid2']:$aid2=addslashes($param['aid2']); else {if ($perms==256) $aid2='admin'; else $aid2='';}
 if (isset($_GET['id_sede'])) $id_sede=intval($_GET['id_sede']); else $id_sede='';
@@ -38,8 +40,12 @@
 	$id_comune=$_SESSION['id_comune'];
 	$user=$aid;
-	$rescom = mysql_query("select descrizione from ".$prefix."_ele_comuni where id_comune=$id_comune",$dbi);
-	list($descr_com) = mysql_fetch_row($rescom);
-	$resmod = mysql_query("SELECT aid,name,email FROM ".$prefix."_authors where aid='$aid2' and id_comune='$id_comune'", $dbi);
-	list ($aid2,$name,$email) = mysql_fetch_row($resmod);
+	$sql="select descrizione from ".$prefix."_ele_comuni where id_comune=$id_comune";
+	$rescom = $dbi->prepare("$sql");
+	$rescom->execute();	
+	list($descr_com) = $rescom->fetch(PDO::FETCH_NUM);
+	$sql="SELECT aid,name,email FROM ".$prefix."_authors where aid='$aid2' and id_comune='$id_comune'";
+	$resmod = $dbi->prepare("$sql");
+	$resmod->execute();	
+	list ($aid2,$name,$email) = $resmod->fetch(PDO::FETCH_NUM);
 	if (isset($_GET['mex'])){
 		echo "<table align=\"center\"><tr><td style=\"background-color: rgb(255, 0, 0)\">";
@@ -54,10 +60,12 @@
 	echo "<table style=\"color: #000000;\"><tr align=\"center\" bgcolor=\"$bgcolor1\">";
 	echo "<td><b>"._UTENTE."</b></td>";
-	$resins = mysql_query("select aid from ".$prefix."_authors where id_comune='$id_comune' order by aid",$dbi); 
+	$sql="select aid from ".$prefix."_authors where id_comune='$id_comune' order by aid"; 
+	$resins = $dbi->prepare("$sql");
+	$resins->execute();	
 	echo "</tr><tr align=\"center\">";
 	echo "<td><input type=\"hidden\" name=\"pag_op\" value=\"admin.php?op=operatori&amp;id_cons_gen=$id_cons_gen&amp;aid2=\">";
 	echo "<select name=\"aid2\" onChange=\"top.location.href=this.form.pag_op.value+this.form.aid2.options[this.form.aid2.selectedIndex].value;return false\">";
 	echo "<option value=\"\">";
-	while(list($utente)=mysql_fetch_row($resins)){
+	while(list($utente)=$resins->fetch(PDO::FETCH_NUM)){
 		$sel= ($utente == $aid2) ? "selected":"";
 		echo "<option value=\"$utente\" $sel>$utente";
@@ -66,5 +74,7 @@
 	echo "</select></td>";
 	echo "</tr></table></form><br><hr>";
-	$resmod = mysql_query("SELECT * FROM ".$prefix."_authors where id_cons='$id_cons' and id_comune='$id_comune'", $dbi);
+#	$sql="SELECT * FROM ".$prefix."_authors where id_cons='$id_cons' and id_comune='$id_comune'";
+#	$resmod = $dbi->prepare("$sql");
+#	$resmod->execute();	
 	echo "<form name=\"modello\" action=\"admin.php\">";
 	echo "<table style=\"color: #000000;\">";
@@ -111,12 +121,16 @@
 		if ($do == "add") {
 			$sql="select * from ".$prefix."_authors where aid='$aid2' and id_comune=$id_comune";
-			$res=mysql_query($sql,$dbi);
-			$max=mysql_num_rows($res);
+			$res = $dbi->prepare("$sql");
+			$res->execute();	
+			$max=$res->rowCount();
 			if ($passwd==$passwd2 and $max==0){
 				if ($aid2=='admin') $super='1,0,0,'; else $super = '0,1,0,';
 				$sql="insert into ".$prefix."_authors (aid,name,id_comune,email,pwd,counter,adminop,admincomune,adminsuper,admlanguage) values ('$aid2','$name','$id_comune' , '$email','".md5($passwd)."',0,$super'$currentlang')";
-				$result = mysql_query($sql, $dbi)||die("Errore 1301: Non e' stato possibile inserire l'utente!<br>$sql<br>".mysql_error());
+				$res = $dbi->prepare("$sql");
+				$res->execute();	
 				if ($perms==256 and $aid2=='admin'){
-					$result = mysql_query("insert into ".$prefix."_ele_operatori (id_cons,id_sede,id_comune,permessi,aid) values ('0','0','$id_comune','64','$aid2')", $dbi) || die("<br><br>Errore di inserimento: ".mysql_error());
+					$sql="insert into ".$prefix."_ele_operatori (id_cons,id_sede,id_comune,permessi,aid) values ('0','0','$id_comune','64','$aid2')";
+					$res = $dbi->prepare("$sql");
+					$res->execute();	
 				}
 			Header("Location: admin.php?op=operatori&id_cons_gen=$id_cons_gen");
@@ -128,5 +142,7 @@
 			}
 		} elseif ($do == "update") {
-			$result = mysql_query("update  ".$prefix."_authors set name='$name',pwd='".md5($passwd)."', email='$email' where id_comune='$id_comune' and aid='$aid2' ", $dbi);
+			$sql="update  ".$prefix."_authors set name='$name',pwd='".md5($passwd)."', email='$email' where id_comune='$id_comune' and aid='$aid2' ";
+			$res = $dbi->prepare("$sql");
+			$res->execute();	
 			if (!$result) return;
 			if ($aid2==$aid) $_SESSION['pwd']=md5($passwd);
Index: trunk/admin/modules/Elezioni/ele_operatori_admin.php
===================================================================
--- trunk/admin/modules/Elezioni/ele_operatori_admin.php	(revision 256)
+++ trunk/admin/modules/Elezioni/ele_operatori_admin.php	(revision 257)
@@ -16,7 +16,6 @@
 $offset=15;
 if (!isset($min)) $min=0;
-
+global $dbi;
 $aid=$_SESSION['aid'];
-$dbi=$_SESSION['dbi'];
 $prefix=$_SESSION['prefix'];
 if (isset($_GET['do'])) $do=$_GET['do']; else $do='';
@@ -31,6 +30,8 @@
 
 
-$res = mysql_query("SELECT t1.tipo_cons FROM ".$prefix."_ele_consultazione as t1, ".$prefix."_ele_cons_comune as t2 where t1.id_cons_gen=t2.id_cons_gen and t1.id_cons_gen='$id_cons_gen' " , $dbi);
-list($tipo_cons) = mysql_fetch_row($res);
+$sql="SELECT t1.tipo_cons FROM ".$prefix."_ele_consultazione as t1, ".$prefix."_ele_cons_comune as t2 where t1.id_cons_gen=t2.id_cons_gen and t1.id_cons_gen='$id_cons_gen' ";
+$res = $dbi->prepare("$sql");
+$res->execute();				
+list($tipo_cons) = $res->fetch(PDO::FETCH_NUM);
 
 $hiddenInfo = "<input type=\"hidden\" name=\"min\" value=\"$min\">";
@@ -49,6 +50,8 @@
 	OpenTable();	
 	
-	$resmod = mysql_query("SELECT id_comune,permessi FROM ".$prefix."_ele_operatori where id_cons='0' and aid='$aid' and id_comune='0'", $dbi);
-	list ($id_comu,$permessi) = mysql_fetch_row($resmod);
+	$sql="SELECT id_comune,permessi FROM ".$prefix."_ele_operatori where id_cons='0' and aid='$aid' and id_comune='0'";
+	$resmod = $dbi->prepare("$sql");
+	$resmod->execute();				
+	list ($id_comu,$permessi) = $resmod->fetch(PDO::FETCH_NUM);
 	if ($perms!=256) 
 	{
@@ -56,5 +59,7 @@
 	return;
 	}
-	$resmod = mysql_query("SELECT * FROM ".$prefix."_ele_operatori where id_cons=0 and id_comune>0", $dbi);
+	$sql="SELECT * FROM ".$prefix."_ele_operatori where id_cons=0 and id_comune>0";
+	$resmod = $dbi->prepare("$sql");
+	$resmod->execute();				
 	echo "<table><tr></tr><hr><tr align=\"center\">";
 	echo "<td bgcolor=\"$bgcolor1\"><b>"._UTENTE."</b></td>"
@@ -70,8 +75,10 @@
 		echo "<td  align=\"center\" width=\"32\"><input name=\"aid2\"></td>";
 	}
-	$ressede = mysql_query("SELECT id_comune, descrizione from ".$prefix."_ele_comuni", $dbi);
+	$sql="SELECT id_comune, descrizione from ".$prefix."_ele_comuni";
+	$ressede = $dbi->prepare("$sql");
+	$ressede->execute();				
 	echo "<td><select name=\"id_comune2\">";
 	echo "<option value=\"\">";
-	while(list($id,$descr)=mysql_fetch_row($ressede)){
+	while(list($id,$descr)=$ressede->fetch(PDO::FETCH_NUM)){
 		$sel= ($id == $id_comune2) ? "selected":"";
 		$arr[$id]="$descr";
@@ -95,5 +102,5 @@
 	}
 	$i=1;
-	while (list($id_cons2,$id_sede2,$id_comune2,$perm,$utente) = mysql_fetch_row($resmod)){ //elenco dei modelli inseriti
+	while (list($id_cons2,$id_sede2,$id_comune2,$perm,$utente) = $resmod->fetch(PDO::FETCH_NUM)){ //elenco dei modelli inseriti
 		$bgcolor1=($bgcolor1==$_SESSION['bgcolor1'])?$_SESSION['bgcolor2']:$_SESSION['bgcolor1'];
 		echo "<form name=\"modello$i\" action=\"admin.php\">"
@@ -131,6 +138,8 @@
 		if ($do == "add") {
 			if ($aid2) {
-				$result = mysql_query("select * from ".$prefix."_ele_operatori where aid='$aid2'", $dbi);
-				$result = mysql_query("insert into ".$prefix."_ele_operatori (id_cons,id_sede,id_comune,permessi,aid) values ('0','0','$id_comune2','$permessi','$aid2')", $dbi) || die("<br><br>Errore di inserimento: ".mysql_error());
+#				$result = mysql_query("select * from ".$prefix."_ele_operatori where aid='$aid2'", $dbi);
+				$sql="insert into ".$prefix."_ele_operatori (id_cons,id_sede,id_comune,permessi,aid) values ('0','0','$id_comune2','$permessi','$aid2')";
+				$res = $dbi->prepare("$sql");
+				$res->execute();				
 				Header("Location: admin.php?op=oper_admin&id_cons_gen=$id_cons_gen");
 			} else {
@@ -141,5 +150,7 @@
 			}
 		}else if ($do == "update") {
-			$result = mysql_query("update  ".$prefix."_ele_operatori set permessi='$permessi' where id_cons='0' and aid='$aid2' ", $dbi) || die("<br><br>Errore di inserimento: ".mysql_error());
+			$sql="update  ".$prefix."_ele_operatori set permessi='$permessi' where id_cons='0' and aid='$aid2' ";
+			$res = $dbi->prepare("$sql");
+			$res->execute();				
 			Header("Location: admin.php?op=oper_admin&id_cons_gen=$id_cons_gen");
 		} 
Index: trunk/admin/modules/Elezioni/ele_permessi.php
===================================================================
--- trunk/admin/modules/Elezioni/ele_permessi.php	(revision 256)
+++ trunk/admin/modules/Elezioni/ele_permessi.php	(revision 257)
@@ -19,6 +19,8 @@
 $perms=ChiSei($id_cons_gen);
 if ($perms<64 or !$id_cons_gen) die("Non hai i permessi per inserire dati ($perms)($id_cons_gen), o non hai scelto la consultazione!");
-$res = mysql_query("SELECT t1.tipo_cons,t2.id_cons 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) = mysql_fetch_row($res);
+$sql="SELECT t1.tipo_cons,t2.id_cons 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) = $res->fetch(PDO::FETCH_NUM);
 if (isset($param['aid2'])) get_magic_quotes_gpc() ? $aid2=$param['aid2']:$aid2=addslashes($param['aid2']); else $aid2='';
 if (isset($param['id_sede'])) $id_sede=intval($param['id_sede']); else $id_sede='';
@@ -45,5 +47,7 @@
 	}	
 	OpenTable();
-	$resmod = mysql_query("SELECT * FROM ".$prefix."_ele_operatori where id_cons=$id_cons and permessi<64 order by aid", $dbi);
+	$sql="SELECT * FROM ".$prefix."_ele_operatori where id_cons=$id_cons and permessi<64 order by aid";
+	$resmod = $dbi->prepare("$sql");
+	$resmod->execute();				
 
 	echo "<br><table><tr align=\"center\" bgcolor=\"$bgcolor1\">";
@@ -55,8 +59,10 @@
 	
 		
-	$restmp = mysql_query("SELECT aid FROM ".$prefix."_ele_operatori where id_cons=$id_cons and permessi<64 order by aid", $dbi);
+	$sql="SELECT aid FROM ".$prefix."_ele_operatori where id_cons=$id_cons and permessi<64 order by aid";
+	$restmp = $dbi->prepare("$sql");
+	$restmp->execute();				
 	if($restmp) {
 	$listmp='';$virg='';
-	while (list($artmp) = mysql_fetch_row($restmp)){ //elenco degli operatori gia' autorizzati
+	while (list($artmp) = $restmp->fetch(PDO::FETCH_NUM)){ //elenco degli operatori gia' autorizzati
 		$listmp .= $virg."'".$artmp."'";
 		$virg=',';
@@ -65,5 +71,7 @@
         
 	if (!$listmp) $listmp="''";
-	$resins = mysql_query("select aid from ".$prefix."_authors where id_comune=$id_comune and (admincomune=1 and aid not in ($listmp)) order by aid",$dbi); // operatori registrati ma non ancora autorizzati
+	$sql="select aid from ".$prefix."_authors where id_comune=$id_comune and (admincomune=1 and aid not in ($listmp)) order by aid"; // operatori registrati ma non ancora autorizzati
+	$resins = $dbi->prepare("$sql");
+	$resins->execute();				
 	
          
@@ -73,15 +81,17 @@
 	echo "<td><select name=\"aid2\">";
 	echo "<option value=\"\">";
-	if($resins) {
-		while(list($utente)=mysql_fetch_row($resins)){
+	if($resins->rowCount()) {
+		while(list($utente)=$resins->fetch(PDO::FETCH_NUM)){
 			echo "<option value=\"$utente\">$utente";
 		}
 	}
 	echo "</select></td>";
-	$ressede = mysql_query("SELECT id_sede, indirizzo from ".$prefix."_ele_sede where id_cons=$id_cons", $dbi);
+	$ressede = mysql_query("SELECT id_sede, indirizzo from ".$prefix."_ele_sede where id_cons=$id_cons";
+	$ressede = $dbi->prepare("$sql");
+	$ressede->execute();				
 	echo "<td><select name=\"id_sede\">";
 	echo "<option value=\"0\"> "._TUTTESEDI;
-	if($ressede)
-	while(list($id,$descr)=mysql_fetch_row($ressede)){
+	if($ressede->rowCount())
+	while(list($id,$descr)=$ressede->fetch(PDO::FETCH_NUM)){
 		$sel= ($id == $id_sede) ? "selected":"";
 		$arr[$id]=$descr;
@@ -103,7 +113,7 @@
 	echo "<td><input type=\"submit\" name=\"add\" value=\""._AGGIUNGI."\"></td></tr></form></table>";
 	echo "<br><hr><br><table>";
-	if($resmod){
+	if($resmod->rowCount()){
 		$i=1;
-		while (list($id_cons2,$id_sede2,$id_comunetemp,$perm,$utente) = mysql_fetch_row($resmod)){ 
+		while (list($id_cons2,$id_sede2,$id_comunetemp,$perm,$utente) = $resmod->fetch(PDO::FETCH_NUM)){ 
 			$bgcolor1=($bgcolor1==$_SESSION['bgcolor1'])?$_SESSION['bgcolor2']:$_SESSION['bgcolor1'];
 			echo "<form name=\"modello$i\" action=\"admin.php\">"
@@ -115,8 +125,10 @@
 			echo "<tr align=\"center\" bgcolor=\"$bgcolor1\">";
 			echo "<td  align=\"center\" width=\"32\"><b>$utente</b></td>";
-			$ressede = mysql_query("SELECT id_sede, indirizzo from ".$prefix."_ele_sede where id_cons=$id_cons", $dbi);
+			$sql="SELECT id_sede, indirizzo from ".$prefix."_ele_sede where id_cons=$id_cons";
+			$ressede = $dbi->prepare("$sql");
+			$ressede->execute();				
 			echo "<td><select name=\"id_sede\">";
 			echo "<option value=\"0\"> "._TUTTESEDI;
-			while(list($id,$descr)=mysql_fetch_row($ressede)){
+			while(list($id,$descr)=$ressede->fetch(PDO::FETCH_NUM)){
 				$sel= ($id == $id_sede2) ? "selected":"";
 				$arr[$id]=$descr;
@@ -147,8 +159,12 @@
 	if ($perms>32 and $permessi<$perms and $aid2) {
 		if ($do == "autorizza") {
-			$result = mysql_query("insert into ".$prefix."_ele_operatori (id_cons,id_sede,id_comune,permessi,aid) values ('$id_cons','$id_sede','$id_comune','$permessi','$aid2')", $dbi)||die("Errore 1301: Non e' stato possibile inserire l'utente!".mysql_error());
+			$sql="insert into ".$prefix."_ele_operatori (id_cons,id_sede,id_comune,permessi,aid) values ('$id_cons','$id_sede','$id_comune','$permessi','$aid2')";
+			$res = $dbi->prepare("$sql");
+			$res->execute();				
 			Header("Location: admin.php?op=permessi&id_cons_gen=$id_cons_gen");
 		} elseif ($do == "update") {
-			$result = mysql_query("update  ".$prefix."_ele_operatori set id_sede='$id_sede' , permessi='$permessi' where id_cons='$id_cons' and aid='$aid2' ", $dbi);
+			$sql="update  ".$prefix."_ele_operatori set id_sede='$id_sede' , permessi='$permessi' where id_cons='$id_cons' and aid='$aid2' ";
+			$res = $dbi->prepare("$sql");
+			$res->execute();				
 			if (!$result) return;
 			Header("Location: admin.php?op=permessi&id_cons_gen=$id_cons_gen");
Index: trunk/admin/modules/Elezioni/ele_pwd.php
===================================================================
--- trunk/admin/modules/Elezioni/ele_pwd.php	(revision 256)
+++ trunk/admin/modules/Elezioni/ele_pwd.php	(revision 257)
@@ -15,6 +15,6 @@
     die ("You can't access this file directly...");
 }
+global $dbi;
 $aid=$_SESSION['aid'];
-$dbi=$_SESSION['dbi'];
 $prefix=$_SESSION['prefix'];
 $currentlang=$_SESSION['lang'];
@@ -64,5 +64,7 @@
     $aid=$_SESSION['aid'];
     if ($pwd1==$pwd2 and md5($oldpwd)==$_SESSION['pwd']) {
-        $result = mysql_query("update ".$prefix."_authors set pwd='".md5($pwd1)."' WHERE aid='$aid' and pwd='".md5($oldpwd)."'", $dbi) || die("Errore di accesso ai dati!".mysql_error());
+        $sql="update ".$prefix."_authors set pwd='".md5($pwd1)."' WHERE aid='$aid' and pwd='".md5($oldpwd)."'";
+		$sth = $dbi->prepare("$sql");
+		$sth->execute();	
         $_SESSION['pwd']=md5($pwd1);
     }else{
Index: trunk/admin/modules/Elezioni/ele_riepilogo.php
===================================================================
--- trunk/admin/modules/Elezioni/ele_riepilogo.php	(revision 256)
+++ 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");
 
 ?>
Index: trunk/admin/modules/Elezioni/ele_riepilogovoti.php
===================================================================
--- trunk/admin/modules/Elezioni/ele_riepilogovoti.php	(revision 256)
+++ trunk/admin/modules/Elezioni/ele_riepilogovoti.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");
@@ -47,28 +50,32 @@
 
 if($genere!=0){	
-	$res = mysql_query("SELECT t1.id_gruppo,sum(t1.voti),sum(t1.solo_gruppo) FROM ".$prefix."_ele_voti_gruppo as t1 left join ".$prefix."_ele_gruppo as t2 on t1.id_gruppo=t2.id_gruppo where t1.id_cons='$id_cons' group by t1.id_gruppo order by t2.num_gruppo", $dbi);
+	$sql="SELECT t1.id_gruppo,sum(t1.voti),sum(t1.solo_gruppo) FROM ".$prefix."_ele_voti_gruppo as t1 left join ".$prefix."_ele_gruppo as t2 on t1.id_gruppo=t2.id_gruppo where t1.id_cons='$id_cons' group by t1.id_gruppo order by t2.num_gruppo";
+	$res = $dbi->prepare("$sql");
+	$res->execute();	
 	####################### inserimento scrutinio in percentuale -- per i gruppi
-	$NicolaSez = mysql_query("SELECT COUNT( id_sez ) FROM ".$prefix."_ele_sezioni WHERE validi <>0 AND id_cons ='$id_cons'",$dbi);
-	$NicolaSezScrut = mysql_fetch_row($NicolaSez);
-	$NicolaSez = mysql_query("SELECT COUNT( id_sez ) FROM ".$prefix."_ele_sezioni WHERE id_cons ='$id_cons'",$dbi);
-	$NicolaSezTot = mysql_fetch_row($NicolaSez);
 	
-		$resperc=mysql_query("select sum(validi),sum(nulli+bianchi+contestati+voti_nulli) from ".$prefix."_ele_sezioni where id_cons='$id_cons'",$dbi);
-		list($scruvalidi,$scrunulli)=mysql_fetch_row($resperc);
-		$resperc = mysql_query("select sum(voti_complessivi) from ".$prefix."_ele_voti_parziale where id_cons='$id_cons' group by data,orario order by data desc, orario desc limit 0,1 ",$dbi);
-		list($totschede)=mysql_fetch_row($resperc);
-		if($totschede)
+	$sql="select sum(validi),sum(nulli+bianchi+contestati+voti_nulli) from ".$prefix."_ele_sezioni where id_cons='$id_cons'";
+	$resperc = $dbi->prepare("$sql");
+	$resperc->execute();	
+	list($scruvalidi,$scrunulli)=$resperc->fetch(PDO::FETCH_NUM);
+	$sql="select sum(voti_complessivi) from ".$prefix."_ele_voti_parziale where id_cons='$id_cons' group by data,orario order by data desc, orario desc limit 0,1 ";
+	$resperc = $dbi->prepare("$sql");
+	$resperc->execute();	
+	list($totschede)=$resperc->fetch(PDO::FETCH_NUM);
+	if($totschede)
 		$grpercscru=number_format(($scruvalidi+$scrunulli)*100/$totschede,2);
-		else $grpercscru=0;
+	else $grpercscru=0;
 
 ################# calcolo voti di lista espressi
-         $resperc=mysql_query("select sum(validi_lista),sum(nulli+bianchi+voti_nulli+contestati+contestati_lista+solo_gruppo+voti_nulli_lista) from ".$prefix."_ele_sezioni where id_cons='$id_cons'",$dbi);
-		list($scruvalidi,$scrunulli)=mysql_fetch_row($resperc);
+	$sql="select sum(validi_lista),sum(nulli+bianchi+voti_nulli+contestati+contestati_lista+solo_gruppo+voti_nulli_lista) from ".$prefix."_ele_sezioni where id_cons='$id_cons'";
+	$resperc = $dbi->prepare("$sql");
+	$resperc->execute();	
+	list($scruvalidi,$scrunulli)=$resperc->fetch(PDO::FETCH_NUM);
 
-		if($totschede)
+	if($totschede)
 		$listpercscru=number_format(($scruvalidi+$scrunulli)*100/$totschede,2);
-		else $listpercscru=0;
-		$listtotschede=$totschede;
-		$listtotvoti=($scruvalidi+$scrunulli);
+	else $listpercscru=0;
+	$listtotschede=$totschede;
+	$listtotvoti=($scruvalidi+$scrunulli);
 
 #################
@@ -77,18 +84,24 @@
 	echo "<tr align=\"middle\"><td><b>Candidato Uninominale</b></td><td><b>Voti</b></td><td><b>Al solo</br>Candidato Uninominale</b></td><td><b>Lista</br>Collegata</b></td><td><b>Voti alla lista</b></td></tr>";
 	$totl=0;$totg=0;$totsg=0;
-	while(list($id_gruppo,$votigruppo,$sologruppo)=mysql_fetch_row($res))
+	while(list($id_gruppo,$votigruppo,$sologruppo)=$res->fetch(PDO::FETCH_NUM))
 	{
 		$totg+=$votigruppo; $totsg+=$sologruppo;
-		$resl = mysql_query("SELECT id_lista,num_lista,descrizione FROM ".$prefix."_ele_lista where id_cons='$id_cons' and id_gruppo='$id_gruppo' group by id_lista order by num_lista", $dbi);
-		$numliste=mysql_num_rows($resl);
-		$resg2 = mysql_query("SELECT num_gruppo,descrizione FROM ".$prefix."_ele_gruppo where id_gruppo='$id_gruppo'", $dbi);
-		list($num_gruppo,$descrg)=mysql_fetch_row($resg2);
+		$sql="SELECT id_lista,num_lista,descrizione FROM ".$prefix."_ele_lista where id_cons='$id_cons' and id_gruppo='$id_gruppo' group by id_lista order by num_lista";
+		$res1 = $dbi->prepare("$sql");
+		$res1->execute();	
+		$numliste=$resl->fetch(PDO::FETCH_NUM);
+		$sql="SELECT num_gruppo,descrizione FROM ".$prefix."_ele_gruppo where id_gruppo='$id_gruppo'";
+		$res2 = $dbi->prepare("$sql");
+		$res2->execute();	
+		list($num_gruppo,$descrg)=$resg2->fetch(PDO::FETCH_NUM);
 
 		echo "<tr><td rowspan=\"$numliste\">$descrg</td><td rowspan=\"$numliste\" align=\"right\"><h2>".number_format($votigruppo,0,',','.')."</h2></td><td rowspan=\"$numliste\" align=\"right\"><h2>".number_format($sologruppo,0,',','.')."</h2></td>";
 		$currlst=0;
-		while (list($id_lista,$num_lista,$descrl)=mysql_fetch_row($resl))
+		while (list($id_lista,$num_lista,$descrl)=$resl->fetch(PDO::FETCH_NUM))
 		{
-			$resl2 = mysql_query("SELECT sum(voti) FROM ".$prefix."_ele_voti_lista where id_lista='$id_lista'", $dbi);
-			list($votilista)=mysql_fetch_row($resl2);
+			$sql="SELECT sum(voti) FROM ".$prefix."_ele_voti_lista where id_lista='$id_lista'";
+			$resl2 = $dbi->prepare("$sql");
+			$resl2->execute();	
+			list($votilista)=$resl2->fetch(PDO::FETCH_NUM);
 			if($currlst) echo "<tr>"; else $currlst++;
 			$totl+=$votilista;
Index: trunk/admin/modules/Elezioni/ele_sede.php
===================================================================
--- trunk/admin/modules/Elezioni/ele_sede.php	(revision 256)
+++ trunk/admin/modules/Elezioni/ele_sede.php	(revision 257)
@@ -23,6 +23,8 @@
 if ($perms>16) {
 
-$res = mysql_query("SELECT t1.tipo_cons,t2.id_cons 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) = mysql_fetch_row($res);
+$sql = "SELECT t1.tipo_cons,t2.id_cons 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) = $res->fetch(PDO::FETCH_NUM);
 
 include("modules/Elezioni/funzionidata.php");
@@ -73,6 +75,8 @@
 	
 	if ($id_sede){
-		$res = mysql_query("SELECT * FROM ".$prefix."_ele_sede where id_sede='$id_sede'", $dbi);
-		$pro= mysql_fetch_array($res, 3);
+		$sql = "SELECT * FROM ".$prefix."_ele_sede where id_sede='$id_sede'";
+		$res = $dbi->prepare("$sql");
+		$res->execute();				
+		$pro= $res->fetch(PDO::FETCH_BOTH);
 	}else{
 		$pro['indirizzo']='';$pro['filemappa']='';$pro['telefono1']='';$pro['fax']='';
@@ -81,6 +85,8 @@
 		echo "<tr>";
 		echo "<td align=\"right\"><select name=\"id_circ\">";
-		$res= mysql_query("SELECT id_circ,descrizione FROM ".$prefix."_ele_circoscrizione where id_cons='$id_cons' order by num_circ", $dbi);
-		while(list($id,$descr) = mysql_fetch_row($res)) {
+		$sql= "SELECT id_circ,descrizione FROM ".$prefix."_ele_circoscrizione where id_cons='$id_cons' order by num_circ";
+		$res = $dbi->prepare("$sql");
+		$res->execute();				
+		while(list($id,$descr) = $res->fetch(PDO::FETCH_NUM)) {
 			if ($id == $pro['id_circ']) {
 				$sel = "selected";
@@ -110,21 +116,29 @@
 	
 	
-    $res = mysql_query("SELECT * FROM ".$prefix."_ele_sede where id_cons='$id_cons'  ", $dbi);
-    $max = mysql_num_rows($res);
-    $result = mysql_query("select * from ".$prefix."_ele_sede where id_cons='$id_cons'  ORDER BY id_circ  LIMIT $min,$offset", $dbi);
-    while(list($id_cons2,$id_sede,$id_circ,$indir, $tel1, $tel2,  $fax, $resp,$mappabin, $filemappa) = mysql_fetch_row($result)) {
+    $sql = "SELECT * FROM ".$prefix."_ele_sede where id_cons='$id_cons'  ";
+	$res = $dbi->prepare("$sql");
+	$res->execute();				
+    $max = $res->rowCount();
+    $sql = "select * from ".$prefix."_ele_sede where id_cons='$id_cons'  ORDER BY id_circ  LIMIT $min,$offset";
+ 	$result = $dbi->prepare("$sql");
+	$result->execute();				
+   while(list($id_cons2,$id_sede,$id_circ,$indir, $tel1, $tel2,  $fax, $resp,$mappabin, $filemappa) = $result->fetch(PDO::FETCH_NUM)) {
         // dati circoscrizione
-		$restemp = mysql_query("select count(0) from ".$prefix."_ele_sezioni where id_sede='$id_sede'", $dbi);
-		list($numtemp)=mysql_fetch_row($restemp);
-	$bgcolor1=($bgcolor1==$_SESSION['bgcolor1'])?$_SESSION['bgcolor2']:$_SESSION['bgcolor1'];
-	$result1 = mysql_query("select descrizione from ".$prefix."_ele_circoscrizione where id_circ='$id_circ'", $dbi);
-        list($descr_circ)=mysql_fetch_row($result1);
-	echo "<tr bgcolor=\"$bgcolor1\"><td align=\"left\"><b>$descr_circ</b>"
-	."</td><td align=\"left\"><b>$indir</b>"
-	."</td><td align=\"right\"><b>$filemappa</b>"
-	."</td><td align=\"right\"><b>$tel1</b>"
-	."</td><td align=\"right\"><b>$fax</b>"
-	."</td><td align=\"left\"><b>$resp</b>"
-	."</td><td align=\"center\" nowrap>[<a
+		$sql = "select count(0) from ".$prefix."_ele_sezioni where id_sede='$id_sede'";
+		$restemp = $dbi->prepare("$sql");
+		$restemp->execute();				
+		list($numtemp)=$restemp->fetch(PDO::FETCH_NUM);
+		$bgcolor1=($bgcolor1==$_SESSION['bgcolor1'])?$_SESSION['bgcolor2']:$_SESSION['bgcolor1'];
+		$sql="select descrizione from ".$prefix."_ele_circoscrizione where id_circ='$id_circ'";
+		$result1 = $dbi->prepare("$sql");
+		$result1->execute();				
+        list($descr_circ)=$result1->fetch(PDO::FETCH_NUM);
+		echo "<tr bgcolor=\"$bgcolor1\"><td align=\"left\"><b>$descr_circ</b>"
+		."</td><td align=\"left\"><b>$indir</b>"
+		."</td><td align=\"right\"><b>$filemappa</b>"
+		."</td><td align=\"right\"><b>$tel1</b>"
+		."</td><td align=\"right\"><b>$fax</b>"
+		."</td><td align=\"left\"><b>$resp</b>"
+		."</td><td align=\"center\" nowrap>[<a
 		href=\"admin.php?op=sede&amp;do=modify&amp;id_sede=$id_sede&amp;id_circ=$id_circ&amp;id_cons_gen=$id_cons_gen\"><img src=\"modules/Elezioni/images/edit.gif\"
                 border=\"0\" align=\"middle\" alt=\"edit\"> "._EDIT."</a>]";
@@ -182,6 +196,8 @@
 			die();
 		}else{
-			$result = mysql_query("delete from ".$prefix."_ele_sede where id_sede='$id_sede'", $dbi);
-			if (!$result)return;
+			$sql="delete from ".$prefix."_ele_sede where id_sede='$id_sede'";
+			$res = $dbi->prepare("$sql");
+			$res->execute();
+			if (!$res->rowCount())return;
 			Header("Location: admin.php?op=sede&id_cons_gen=$id_cons_gen");
 		}
@@ -211,6 +227,8 @@
 		
 		
-			$result = mysql_query("insert into ".$prefix."_ele_sede (id_cons,id_circ,indirizzo,telefono1,telefono2,fax,responsabile,mappa,filemappa) values ('$id_cons', '$id_circ','$indir','$tel1','$tel2', '$fax','$resp','$mappablob','$mappanome')", $dbi)|| die(mysql_error());
-			if (!$result) return;
+			$sql="insert into ".$prefix."_ele_sede (id_cons,id_circ,indirizzo,telefono1,telefono2,fax,responsabile,mappa,filemappa) values ('$id_cons', '$id_circ','$indir','$tel1','$tel2', '$fax','$resp','$mappablob','$mappanome')";
+			$res = $dbi->prepare("$sql");
+			$res->execute();
+			if (!$res->rowCount()) return;
 			Header("Location: admin.php?op=sede&id_cons_gen=$id_cons_gen");
 		} else {
@@ -237,7 +255,9 @@
 			} else {$cond='';}
         	
-		$result = mysql_query("update  ".$prefix."_ele_sede set    id_circ='$id_circ',indirizzo='$indir' , telefono1='$tel1', telefono2='$tel2',fax='$fax',responsabile='$resp' $cond where id_sede='$id_sede2' ", $dbi)|| die(mysql_error());
-          	 if (!$result) return;
-          	 Header("Location: admin.php?op=sede&id_cons_gen=$id_cons_gen&id_comune=$id_comune");
+			$sql="update  ".$prefix."_ele_sede set    id_circ='$id_circ',indirizzo='$indir' , telefono1='$tel1', telefono2='$tel2',fax='$fax',responsabile='$resp' $cond where id_sede='$id_sede2' ";
+			$res = $dbi->prepare("$sql");
+			$res->execute();
+			if (!$res->rowCount()) return;
+          	Header("Location: admin.php?op=sede&id_cons_gen=$id_cons_gen&id_comune=$id_comune");
    	}
 }
Index: trunk/admin/modules/Elezioni/ele_sezione.php
===================================================================
--- trunk/admin/modules/Elezioni/ele_sezione.php	(revision 256)
+++ trunk/admin/modules/Elezioni/ele_sezione.php	(revision 257)
@@ -18,6 +18,8 @@
 
 
-$res = mysql_query("SELECT t1.tipo_cons,t2.id_cons 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) = mysql_fetch_row($res);
+$sql="SELECT t1.tipo_cons,t2.id_cons 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) = $res->fetch(PDO::FETCH_NUM);
 if (isset($param['do'])) get_magic_quotes_gpc() ? $do=$param['do']:$do=addslashes($param['do']); else $do='';
 if (isset($param['id_sede'])) $id_sede=intval($param['id_sede']); else $id_sede='';
@@ -54,6 +56,8 @@
 	."<td bgcolor=\"$bgcolor1\" align=\"center\" ><b>"._TOTS." "._ISCRITTI."</b></td>"
 	."<td bgcolor=\"$bgcolor1\" align=\"center\"><b>"._FUNZIONI."</b></td></tr>";
-    $res = mysql_query("SELECT * FROM ".$prefix."_ele_sezioni where id_cons='$id_cons'  ", $dbi);
-    $max = mysql_num_rows($res);
+    $sql="SELECT * FROM ".$prefix."_ele_sezioni where id_cons='$id_cons'  ";
+	$res = $dbi->prepare("$sql");
+	$res->execute(); 
+    $max = $res->rowCount();
 	echo "<tr align=\"center\"><form name=\"sezi\" action=\"admin.php\">"
 	."<input type=\"hidden\" name=\"op\" value=\"sezione\">"
@@ -61,12 +65,16 @@
     
 	$nuova= $max+1;
-	$res = mysql_query("SELECT id_sede FROM ".$prefix."_ele_sezioni where id_cons='$id_cons' and num_sez='$max'  ", $dbi);
-	list($id_sede_old) = mysql_fetch_row($res);
+	$sql="SELECT id_sede FROM ".$prefix."_ele_sezioni where id_cons='$id_cons' and num_sez='$max'  ";
+	$res = $dbi->prepare("$sql");
+	$res->execute(); 
+	list($id_sede_old) = $res->fetch(PDO::FETCH_NUM);
 
 	echo "<td><input type=\"text\" name=\"num_sez\" value=\"$nuova\" size=\"5\"></td>";
 
 	echo "<td><select name=\"id_sede\">";
-	$res= mysql_query("SELECT id_sede,indirizzo FROM ".$prefix."_ele_sede where id_cons='$id_cons' order by indirizzo", $dbi);
-	while(list($id,$indir) = mysql_fetch_row($res)) {
+	$sql="SELECT id_sede,indirizzo FROM ".$prefix."_ele_sede where id_cons='$id_cons' order by indirizzo";
+	$res = $dbi->prepare("$sql");
+	$res->execute(); 
+	while(list($id,$indir) = $res->fetch(PDO::FETCH_NUM)) {
 		if ($id == $id_sede_old) {
 			$sel = "selected";
@@ -93,10 +101,14 @@
     
     
-    $result = mysql_query("select id_cons, id_sez, id_sede, num_sez, maschi, femmine, autorizzati_m, autorizzati_f from ".$prefix."_ele_sezioni where id_cons='$id_cons'  ORDER BY num_sez  LIMIT $min,$offset", $dbi);
-    while(list($id_cons2,$id_sez,$id_sede,$num_sez, $maschi, $femmine,$aut_m,$aut_f) = mysql_fetch_row($result)) {
+    $sql="select id_cons, id_sez, id_sede, num_sez, maschi, femmine, autorizzati_m, autorizzati_f from ".$prefix."_ele_sezioni where id_cons='$id_cons'  ORDER BY num_sez  LIMIT $min,$offset";
+ 	$result = $dbi->prepare("$sql");
+	$result->execute(); 
+   while(list($id_cons2,$id_sez,$id_sede,$num_sez, $maschi, $femmine,$aut_m,$aut_f) = $result->fetch(PDO::FETCH_NUM)) {
 	$bgcolor1=($bgcolor1==$_SESSION['bgcolor1'])?$_SESSION['bgcolor2']:$_SESSION['bgcolor1'];
         // dati circoscrizione
-	$result1 = mysql_query("select indirizzo from ".$prefix."_ele_sede where id_sede='$id_sede'", $dbi);
-        list($indir)=mysql_fetch_row($result1);
+	$sql="select indirizzo from ".$prefix."_ele_sede where id_sede='$id_sede'";
+	$result1 = $dbi->prepare("$sql");
+	$result1->execute(); 
+        list($indir)=$result1->fetch(PDO::FETCH_NUM);
         $totali=$maschi+$femmine+$aut_m+$aut_f;
 	$y++;
@@ -111,6 +123,8 @@
 	echo "<tr bgcolor=\"$bgcolor1\"><td align=\"right\" size=\"90\"><b>$num_sez</b></td>";
 	echo "<td align=\"right\" size=\"120\"><select name=\"id_sede\">";
-	$res= mysql_query("SELECT id_sede,indirizzo FROM ".$prefix."_ele_sede where id_cons='$id_cons' order by indirizzo", $dbi);
-	while(list($id,$indir) = mysql_fetch_row($res)) {
+	$sql="SELECT id_sede,indirizzo FROM ".$prefix."_ele_sede where id_cons='$id_cons' order by indirizzo";
+	$res = $dbi->prepare("$sql");
+	$res->execute(); 
+	while(list($id,$indir) = $res->fetch(PDO::FETCH_NUM)) {
 		if ($id == $id_sede) {
 			$sel = "selected";
@@ -179,15 +193,29 @@
 			die();
 		}else{
-			$result = mysql_query("delete from ".$prefix."_ele_voti_candidati where id_sez='$id_sez'", $dbi)|| die("(1104) Non e' stato possibile eliminare i dati dal database! contattare l'amministratore".mysql_error());
- 			$result = mysql_query("delete from ".$prefix."_ele_voti_lista where id_sez='$id_sez'", $dbi)|| die("(1104) Non e' stato possibile eliminare i dati dal database! contattare l'amministratore".mysql_error());
-			$result = mysql_query("delete from ".$prefix."_ele_voti_gruppo where id_sez='$id_sez'",$dbi)|| die("(1104) Non e' stato possibile eliminare i dati dal database! contattare l'amministratore".mysql_error());
-			$result = mysql_query("delete from ".$prefix."_ele_voti_ref where id_sez='$id_sez'", $dbi)|| die("(1104) Non e' stato possibile eliminare i dati dal database! contattare l'amministratore".mysql_error());
-			$result = mysql_query("delete from ".$prefix."_ele_voti_parziale where id_sez='$id_sez'", $dbi)|| die("(1104) Non e' stato possibile eliminare i dati dal database! contattare l'amministratore".mysql_error());
-			$result = mysql_query("delete from ".$prefix."_ele_sezioni where id_sez='$id_sez'", $dbi)|| die("(1104) Non e' stato possibile eliminare i dati dal database! contattare l'amministratore".mysql_error());
+			$sql="delete from ".$prefix."_ele_voti_candidati where id_sez='$id_sez'";
+			$res = $dbi->prepare("$sql");
+			$res->execute(); 
+ 			$sql="delete from ".$prefix."_ele_voti_lista where id_sez='$id_sez'";
+			$res = $dbi->prepare("$sql");
+			$res->execute(); 
+			$sql="delete from ".$prefix."_ele_voti_gruppo where id_sez='$id_sez'";
+			$res = $dbi->prepare("$sql");
+			$res->execute(); 
+			$sql="delete from ".$prefix."_ele_voti_ref where id_sez='$id_sez'";
+			$res = $dbi->prepare("$sql");
+			$res->execute(); 
+			$sql="delete from ".$prefix."_ele_voti_parziale where id_sez='$id_sez'";
+			$res = $dbi->prepare("$sql");
+			$res->execute(); 
+			$sql="delete from ".$prefix."_ele_sezioni where id_sez='$id_sez'";
+			$res = $dbi->prepare("$sql");
+			$res->execute(); 
 			Header("Location: admin.php?op=sezione&id_cons_gen=$id_cons_gen&min=$min");
 		}
 	}elseif ($do == "add") {
 		if ($num_sez) {
-			$result = mysql_query("insert into ".$prefix."_ele_sezioni (id_cons,id_sede,num_sez,maschi,femmine, autorizzati_m,autorizzati_f) values ('$id_cons', '$id_sede', '$num_sez','$maschi','$femmine','$aut_m', '$aut_f')", $dbi)|| die("(1104) Non e' stato possibile inserire i dati nel database! contattare l'amministratore".mysql_error());
+			$sql="insert into ".$prefix."_ele_sezioni (id_cons,id_sede,num_sez,maschi,femmine, autorizzati_m,autorizzati_f) values ('$id_cons', '$id_sede', '$num_sez','$maschi','$femmine','$aut_m', '$aut_f')";
+			$res = $dbi->prepare("$sql");
+			$res->execute(); 
 			Header("Location: admin.php?op=sezione&id_cons_gen=$id_cons_gen&min=$min");
 		} else {
@@ -199,5 +227,7 @@
 		}
 	}elseif ($do == "update") {
-		$result = mysql_query("update  ".$prefix."_ele_sezioni set id_sede='$id_sede', maschi='$maschi', femmine='$femmine', autorizzati_m='$aut_m', autorizzati_f='$aut_f' where id_sez='$id_sez2' ", $dbi)|| die("(1104) Non e' stato possibile aggiornare i dati nel database! contattare l'amministratore".mysql_error());
+		$sql="update  ".$prefix."_ele_sezioni set id_sede='$id_sede', maschi='$maschi', femmine='$femmine', autorizzati_m='$aut_m', autorizzati_f='$aut_f' where id_sez='$id_sez2' ";
+		$res = $dbi->prepare("$sql");
+		$res->execute(); 
 		$num_sez--;
 		Header("Location: admin.php?op=sezione&id_cons_gen=$id_cons_gen&min=$num_sez");
Index: trunk/admin/modules/Elezioni/ele_voti.php
===================================================================
--- trunk/admin/modules/Elezioni/ele_voti.php	(revision 256)
+++ trunk/admin/modules/Elezioni/ele_voti.php	(revision 257)
@@ -13,6 +13,6 @@
     die ("You can't access this file directly...");
 }
+global $dbi;
 $aid=$_SESSION['aid'];
-$dbi=$_SESSION['dbi'];
 $prefix=$_SESSION['prefix'];
 $currentlang=$_SESSION['lang'];
@@ -45,30 +45,62 @@
 global $votolista, $limite, $dettnulli,$disgiunto;
 if(!isset($votolista)) $votolista=0;
-$res = mysql_query("SELECT tipo_cons FROM ".$prefix."_ele_consultazione where id_cons_gen='$id_cons_gen'" , $dbi);
-list($tipo_cons) = mysql_fetch_row($res);
+$sql="SELECT tipo_cons FROM ".$prefix."_ele_consultazione where id_cons_gen='$id_cons_gen'" ;
+$res = $dbi->prepare("$sql");
+$res->execute();
+
+
+list($tipo_cons) = $res->fetch(PDO::FETCH_NUM);
 if ($tipo_cons!=3 or $votolista==1) $limite=0; #die ("limite: $limite");}
-$res = mysql_query("SELECT count(id_circ) FROM ".$prefix."_ele_circoscrizione where id_cons='$id_cons' ", $dbi);
-list($num_circ)=mysql_fetch_row($res);
-$res = mysql_query("SELECT solo_gruppo,disgiunto FROM ".$prefix."_ele_cons_comune where id_cons='$id_cons' ", $dbi);
-list($dettnulli,$disgiunto)=mysql_fetch_row($res);
+$sql="SELECT count(id_circ) FROM ".$prefix."_ele_circoscrizione where id_cons='$id_cons' ";
+$res = $dbi->prepare("$sql");
+$res->execute();
+
+
+list($num_circ)=$res->fetch(PDO::FETCH_NUM);
+$sql="SELECT solo_gruppo,disgiunto FROM ".$prefix."_ele_cons_comune where id_cons='$id_cons' ";
+$res = $dbi->prepare("$sql");
+$res->execute();
+
+
+list($dettnulli,$disgiunto)=$res->fetch(PDO::FETCH_NUM);
 if ($conscirc){  // or $num_circ==1
 	if (!$id_circ){
 		if (!$id_sez){
-			$res = mysql_query("SELECT id_sez FROM ".$prefix."_ele_sezioni where id_cons='$id_cons' and num_sez='1'", $dbi);
-			list($id_sez)=mysql_fetch_row($res);
-		}
-		$res = mysql_query("SELECT t1.id_circ FROM ".$prefix."_ele_sede as t1 left join ".$prefix."_ele_sezioni as t2 on t1.id_sede=t2.id_sede where t1.id_cons='$id_cons' and t2.id_sez='$id_sez'", $dbi);
-		#$res = mysql_query("SELECT id_circ FROM ".$prefix."_ele_circoscrizione where id_cons='$id_cons' order by num_circ limit 0,1", $dbi);
-		if (!$res) die("Errore, non trovo circoscrizioni inserite! Consultare l'amministratore");
-		list($id_circ)=mysql_fetch_row($res);
+			$sql="SELECT id_sez FROM ".$prefix."_ele_sezioni where id_cons='$id_cons' and num_sez='1'";
+$res = $dbi->prepare("$sql");
+$res->execute();
+
+
+			list($id_sez)=$res->fetch(PDO::FETCH_NUM);
+		}
+		$sql="SELECT t1.id_circ FROM ".$prefix."_ele_sede as t1 left join ".$prefix."_ele_sezioni as t2 on t1.id_sede=t2.id_sede where t1.id_cons='$id_cons' and t2.id_sez='$id_sez'";
+$res = $dbi->prepare("$sql");
+$res->execute();
+
+
+		#$sql="SELECT id_circ FROM ".$prefix."_ele_circoscrizione where id_cons='$id_cons' order by num_circ limit 0,1";
+$res = $dbi->prepare("$sql");
+$res->execute();
+
+
+		if (!$res->rowCount()) die("Errore, non trovo circoscrizioni inserite! Consultare l'amministratore");
+		list($id_circ)=$res->fetch(PDO::FETCH_NUM);
 		$_SESSION['id_circ']=$id_circ;
 	}
-	$result = mysql_query("select id_sede from ".$prefix."_ele_sede where id_circ='$id_circ'", $dbi);
+	$sql="select id_sede from ".$prefix."_ele_sede where id_circ='$id_circ'";
+$result = $dbi->prepare("$sql");
+$result->execute();
+
+
 	$i=0;
-	while(list($tmp) = mysql_fetch_row($result)) $idsedi[$i++]=$tmp;$tmp=implode (",",$idsedi);
+	while(list($tmp) = $result->fetch(PDO::FETCH_NUM)) $idsedi[$i++]=$tmp;$tmp=implode (",",$idsedi);
 	unset($idsedi);$i=0;$idsezi=array();unset($result);
-	$result = mysql_query("SELECT id_sez FROM ".$prefix."_ele_sezioni where id_sede in ($tmp)", $dbi);
+	$sql="SELECT id_sez FROM ".$prefix."_ele_sezioni where id_sede in ($tmp)";
+$result = $dbi->prepare("$sql");
+$result->execute();
+
+
 	unset($tmp);
-	while(list($tmp) = mysql_fetch_row($result)) $idsezi[$i++]=$tmp;
+	while(list($tmp) = $result->fetch(PDO::FETCH_NUM)) $idsezi[$i++]=$tmp;
 	$tmp=implode (",",$idsezi);
 	$sezi = "and id_sez in ($tmp)";
@@ -88,10 +120,18 @@
 $stret=0; $contains=0;
 ###########
-$res = mysql_query("SELECT data,orario FROM ".$prefix."_ele_rilaff where id_cons_gen=$id_cons_gen order by data asc,orario asc", $dbi);
-$num_ril=mysql_num_rows($res);
-$res3 = mysql_query("SELECT stato_aff, stato_val,stato_gru,stato_lis,stato_can,status FROM ".$prefix."_ele_controllosez where id_sez='$id_sez' and id_cons='$id_cons'", $dbi);
+$sql="SELECT data,orario FROM ".$prefix."_ele_rilaff where id_cons_gen=$id_cons_gen order by data asc,orario asc";
+$res = $dbi->prepare("$sql");
+$res->execute();
+
+
+$num_ril=$res->rowCount();
+$sql="SELECT stato_aff, stato_val,stato_gru,stato_lis,stato_can,status FROM ".$prefix."_ele_controllosez where id_sez='$id_sez' and id_cons='$id_cons'";
+$res3 = $dbi->prepare("$sql");
+$res3->execute();
+
+
 						
-if(mysql_num_rows($res3)){
-	list($aff,$val,$gru,$lis,$can,$status)=mysql_fetch_row($res3); 
+if($res3->rowCount()){
+	list($aff,$val,$gru,$lis,$can,$status)=$res3->fetch(PDO::FETCH_NUM); 
 	if ($can) {$ops=-5;}
 	elseif ($lis) {$ops=-3;}
@@ -105,28 +145,48 @@
 	if($ops==0){
 #controllo congruenza affluenze
-		$res3= mysql_query("SELECT count(num_sez) FROM ".$prefix."_ele_sezioni where id_cons='$id_cons'", $dbi);
-		list($numtot) = mysql_fetch_row($res3);
+		$sql="SELECT count(num_sez) FROM ".$prefix."_ele_sezioni where id_cons='$id_cons'";
+$res3 = $dbi->prepare("$sql");
+$res3->execute();
+
+
+		list($numtot) = $res3->fetch(PDO::FETCH_NUM);
 		$test_ril=0;$pre_rilc=0;$pre_rilm=0;$pre_rilf=0;
-		if($res)
-		while (list($giorno,$ora) = mysql_fetch_row($res)){
+		if($res->rowCount())
+		while (list($giorno,$ora) = $res->fetch(PDO::FETCH_NUM)){
 			$test_ril++;
 			$query="SELECT voti_complessivi FROM ".$prefix."_ele_voti_parziale where id_sez='$id_sez' $perref and orario='$ora' and data='$giorno'";
-			$res2 = mysql_query("$query", $dbi);
-			$numscru=mysql_num_rows($res2);
+			$sql="$query";
+$res2 = $dbi->prepare("$sql");
+$res2->execute();
+
+
+			$numscru=$res2->rowCount();
 			$query="SELECT sum(voti_complessivi) FROM ".$prefix."_ele_voti_parziale where id_sez='$id_sez' $perref and orario='$ora' and data='$giorno'";
-			$res2 = mysql_query("$query", $dbi);
-			list($voti)=mysql_fetch_row($res2);
+			$sql="$query";
+$res2 = $dbi->prepare("$sql");
+$res2->execute();
+
+
+			list($voti)=$res2->fetch(PDO::FETCH_NUM);
 			if($numscru) {
 				if(isset($ora)){
 					$query="SELECT count(voti_complessivi) FROM ".$prefix."_ele_voti_parziale where id_cons='$id_cons' $perref and orario='$ora' and data='$giorno'";
-#					$res3 = mysql_query("$query", $dbi);
+#					$res3 = mysql_query("$query";
 #					list($numscru)=mysql_fetch_row($res3);
-					$res3= mysql_query("SELECT maschi+autorizzati_m,femmine+autorizzati_f FROM ".$prefix."_ele_sezioni where id_sez='$id_sez'", $dbi);
-					list($iscrittim,$iscrittif) = mysql_fetch_row($res3);
+					$sql="SELECT maschi+autorizzati_m,femmine+autorizzati_f FROM ".$prefix."_ele_sezioni where id_sez='$id_sez'";
+$res3 = $dbi->prepare("$sql");
+$res3->execute();
+
+
+					list($iscrittim,$iscrittif) = $res3->fetch(PDO::FETCH_NUM);
 					$iscritti=$iscrittim+$iscrittif;
 					
 					$query="SELECT voti_complessivi, voti_uomini, voti_donne FROM ".$prefix."_ele_voti_parziale where id_sez='$id_sez' $perref and orario='$ora' and data='$giorno'";
-					$res3 = mysql_query("$query", $dbi);
-					list($voti, $uomini, $donne)=mysql_fetch_row($res3);
+					$sql="$query";
+$res3 = $dbi->prepare("$sql");
+$res3->execute();
+
+
+					list($voti, $uomini, $donne)=$res3->fetch(PDO::FETCH_NUM);
 						if (((($uomini+$donne)==0 and ($voti<=$iscritti) and $voti>=$pre_rilc) or ((($uomini+$donne)==$voti) and ($uomini<=$iscrittim) and ($donne<=$iscrittif) )) and $uomini>=$pre_rilm and $donne>=$pre_rilf and $voti>=$pre_rilc)
 						{
@@ -142,17 +202,29 @@
 		#controllo congruenza voti espressi
 			#per referendum
-		$resref = mysql_query("SELECT id_gruppo FROM ".$prefix."_ele_gruppo where id_cons='$id_cons'", $dbi);
+		$sql="SELECT id_gruppo FROM ".$prefix."_ele_gruppo where id_cons='$id_cons'";
+$resref = $dbi->prepare("$sql");
+$resref->execute();
+
+
 		if($genere==0){ 
-			$numscru=mysql_num_rows($resref); $rifscru=0;
-			while(list($idrefgruppo)=mysql_fetch_row($resref)) {
-			$res2= mysql_query("SELECT si,no,validi,nulli,bianchi,contestati FROM ".$prefix."_ele_voti_ref where id_sez='$id_sez' and id_gruppo='$idrefgruppo'", $dbi);
-			$refscru=mysql_num_rows($res2); 
+			$numscru=$resref->rowCount(); $rifscru=0;
+			while(list($idrefgruppo)=$resref->fetch(PDO::FETCH_NUM)) {
+			$sql="SELECT si,no,validi,nulli,bianchi,contestati FROM ".$prefix."_ele_voti_ref where id_sez='$id_sez' and id_gruppo='$idrefgruppo'";
+$res2 = $dbi->prepare("$sql");
+$res2->execute();
+
+
+			$refscru=$res2->rowCount(); 
 				if($refscru){
 					$query="SELECT voti_complessivi FROM ".$prefix."_ele_voti_parziale where id_sez='$id_sez' and id_gruppo='$idrefgruppo' order by data desc, orario desc";
-					$res3 = mysql_query("$query", $dbi);
-					list($voti)=mysql_fetch_row($res3);
+					$sql="$query";
+$res3 = $dbi->prepare("$sql");
+$res3->execute();
+
+
+					list($voti)=$res3->fetch(PDO::FETCH_NUM);
 				
 					$rifscru++;
-					list($si,$no,$validi,$nulli,$bianchi,$contestati)=mysql_fetch_row($res2);
+					list($si,$no,$validi,$nulli,$bianchi,$contestati)=$res2->fetch(PDO::FETCH_NUM);
 					if(($si+$no==$validi) and ($validi+$nulli+$bianchi+$contestati==$voti)) { if($rifscru==$numscru) $status=5; else $status=4; $ops=-4;$val=1;} #{$status=1;return (-4);}
 					else {$val=-1;$stret=4;break;} #return (4);
@@ -161,12 +233,20 @@
 		}else{
 			#per le altre consultazione
-		$res2= mysql_query("SELECT validi FROM ".$prefix."_ele_sezioni where id_sez='$id_sez' and id_cons='$id_cons' ", $dbi);
+		$sql="SELECT validi FROM ".$prefix."_ele_sezioni where id_sez='$id_sez' and id_cons='$id_cons' ";
+$res2 = $dbi->prepare("$sql");
+$res2->execute();
+
+
 		if($res2){
-		list($validi) = mysql_fetch_row($res2);
+		list($validi) = $res2->fetch(PDO::FETCH_NUM);
 			if($validi) {
 					$status=0;
 					$query="SELECT validi,nulli,bianchi,contestati,voti_nulli,solo_gruppo,validi_lista,contestati_lista,voti_nulli_lista,solo_lista FROM ".$prefix."_ele_sezioni as t1 where t1.id_sez='$id_sez'";
-					$res4 = mysql_query("$query", $dbi);
-					list($validi, $nulli, $bianchi,$contestati,$votinulli,$sologruppo,$validilista,$contestatilista,$votinullilista,$sololista)=mysql_fetch_row($res4);
+					$sql="$query";
+$res4 = $dbi->prepare("$sql");
+$res4->execute();
+
+
+					list($validi, $nulli, $bianchi,$contestati,$votinulli,$sologruppo,$validilista,$contestatilista,$votinullilista,$sololista)=$res4->fetch(PDO::FETCH_NUM);
 					if($validi>0) {
 						if (($validi+$nulli+$bianchi+$contestati+$votinulli)==$voti)
@@ -178,11 +258,15 @@
 		#controllo congruenza voti di gruppo
 		if($genere!=4){
-		$res3= mysql_query("SELECT sum(voti),sum(solo_gruppo) FROM ".$prefix."_ele_voti_gruppo where id_sez='$id_sez' and id_cons='$id_cons'", $dbi);
-		if($res3 and !$votog){#$status=0;$ops=-4;
-			list($votigs,$votisolog) = mysql_fetch_row($res3);
+		$sql="SELECT sum(voti),sum(solo_gruppo) FROM ".$prefix."_ele_voti_gruppo where id_sez='$id_sez' and id_cons='$id_cons'";
+$res3 = $dbi->prepare("$sql");
+$res3->execute();
+
+
+		if($res3->rowCount() and !$votog){#$status=0;$ops=-4;
+			list($votigs,$votisolog) = m$res3->fetch(PDO::FETCH_NUM);
 			if($votigs  and $genere!=2) {  
 				#	$status=0;
 #					$query="SELECT sum(voti) FROM ".$prefix."_ele_voti_gruppo where id_sez='$id_sez'";
-#					$res4 = mysql_query("$query", $dbi);
+#					$res4 = mysql_query("$query";
 #					list($votigs)=mysql_fetch_row($res4);
 					if($votigs>0||$sololista==$validi) {
@@ -195,17 +279,29 @@
 		}#else {$gru=1;echo "--$votigs -- $votog";}
 		if(($genere>1 and !$votol)){#$status=0;
-		$res4= mysql_query("SELECT t1.preferenze,t1.id_fascia,t2.limite,t1.disgiunto 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($res4) list($testpref,$fascia,$limite,$disgiunto)=mysql_fetch_row($res4); else {$testpref=0;$fascia=0;$limite=0;}
+		$sql="SELECT t1.preferenze,t1.id_fascia,t2.limite,t1.disgiunto 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'";
+$res4 = $dbi->prepare("$sql");
+$res4->execute();
+
+
+		if($res4) list($testpref,$fascia,$limite,$disgiunto)=$res4->fetch(PDO::FETCH_NUM); else {$testpref=0;$fascia=0;$limite=0;}
 
 		#controllo congruenza voti di lista
-#		$res3= mysql_query("SELECT sum(voti) FROM ".$prefix."_ele_voti_lista where id_cons='$id_cons'", $dbi);
+#		$res3= mysql_query("SELECT sum(voti) FROM ".$prefix."_ele_voti_lista where id_cons='$id_cons'";
 #			list($votil) = mysql_fetch_row($res3);
 					$tablg=($fascia<=$limite && !$disgiunto) ? "gruppo":"lista";
 					$query="SELECT sum(voti),sum(solo_".$tablg.") FROM ".$prefix."_ele_voti_$tablg where id_sez='$id_sez' and  id_cons='$id_cons'";	
-					$res4 = mysql_query($query, $dbi);
-					list($votils,$votisolols)=mysql_fetch_row($res4);
+					$sql=$query;
+$res4 = $dbi->prepare("$sql");
+$res4->execute();
+
+
+					list($votils,$votisolols)=$res4->fetch(PDO::FETCH_NUM);
 					$query="SELECT voti FROM ".$prefix."_ele_voti_$tablg where id_sez='$id_sez' and  id_cons='$id_cons'";	
-					$res4 = mysql_query($query, $dbi);
-					$sezscru=mysql_num_rows($res4);
+					$sql=$query;
+$res4 = $dbi->prepare("$sql");
+$res4->execute();
+
+
+					$sezscru=$res4->rowCount();
 			if($sezscru) {
 					if($genere==4 or $votog) {$contrlis= ($votisolols==$sololista || $votisolols==0) ? 1:0; }
@@ -216,10 +312,18 @@
 						$contrlis=($votisolols==$sololista  || $votisolols==0) ? 1:0;
 						if($contrlis  and $tipo_cons==18 or $tipo_cons==19)
-							while ( list($id_gruppo)=mysql_fetch_row($resref))
+							while ( list($id_gruppo)=$resref->fetch(PDO::FETCH_NUM))
 								{
-								$res3= mysql_query("SELECT sum(voti-solo_gruppo) FROM ".$prefix."_ele_voti_gruppo where id_sez='$id_sez' and id_gruppo='$id_gruppo'", $dbi);
-								$res4= mysql_query("SELECT sum(voti+nulli_lista) FROM ".$prefix."_ele_voti_lista where id_sez='$id_sez' and  id_lista in (select id_lista from ".$prefix."_ele_lista where id_gruppo='$id_gruppo')", $dbi);
-								list($vgruppo)=mysql_fetch_row($res3);
-								list($vliste)=mysql_fetch_row($res4);
+								$sql="SELECT sum(voti-solo_gruppo) FROM ".$prefix."_ele_voti_gruppo where id_sez='$id_sez' and id_gruppo='$id_gruppo'";
+$res3 = $dbi->prepare("$sql");
+$res3->execute();
+
+
+								$res4= mysql_query("SELECT sum(voti+nulli_lista) FROM ".$prefix."_ele_voti_lista where id_sez='$id_sez' and  id_lista in (select id_lista from ".$prefix."_ele_lista where id_gruppo='$id_gruppo')";
+$res4 = $dbi->prepare("$sql");
+$res4->execute();
+
+
+								list($vgruppo)=$res3->fetch(PDO::FETCH_NUM);
+								list($vliste)=$res4->fetch(PDO::FETCH_NUM);
 								if($vliste>$vgruppo) {$contrlis=0 ;} 
 								if($vliste<$vgruppo) {$contrlis=0 ;} 
@@ -232,31 +336,59 @@
 					
 #					if($votils>0) {
-					if(mysql_num_rows($res4)>0) {
-#						$res4= mysql_query("SELECT count(0) FROM ".$prefix."_ele_voti_candidati where id_cons='$id_cons' and  id_sez='$id_sez' ", $dbi);
+					if($res4->rowCount()>0) {
+#						$res4= mysql_query("SELECT count(0) FROM ".$prefix."_ele_voti_candidati where id_cons='$id_cons' and  id_sez='$id_sez' ";
 #						list($contains)=mysql_fetch_row($res4);
 #						if($contains==0) $tutte=1; else $tutte=0;
 							
 							$query="SELECT id_lista FROM ".$prefix."_ele_lista where id_cons='$id_cons' $circo";
-							$res3 = mysql_query("$query", $dbi); 
-							$contaliste=mysql_num_rows($res3);
-							$res4= mysql_query("SELECT preferenze FROM ".$prefix."_ele_cons_comune where id_cons='$id_cons'", $dbi);
-							if($res4) list($testpref)=mysql_fetch_row($res4); else $testpref=0;
-							while(list($testlista)=mysql_fetch_row($res3)){
+							$sql="$query";
+$res3 = $dbi->prepare("$sql");
+$res3->execute();
+
+ 
+							$contaliste=$res3->rowCount();
+							$sql="SELECT preferenze FROM ".$prefix."_ele_cons_comune where id_cons='$id_cons'";
+$res4 = $dbi->prepare("$sql");
+$res4->execute();
+
+
+							if($res4->rowCount()) list($testpref)=$res4->fetch(PDO::FETCH_NUM); else $testpref=0;
+							while(list($testlista)=$res3->fetch(PDO::FETCH_NUM)){
 								if($fascia<=$limite and !$disgiunto and !$dettnulli)
 								{
-									$res4= mysql_query("SELECT id_gruppo FROM ".$prefix."_ele_lista where id_cons='$id_cons' and id_lista='$testlista'", $dbi);
-									list($idgruppo)=mysql_fetch_row($res4);
-									$res4= mysql_query("SELECT sum(voti) FROM ".$prefix."_ele_voti_gruppo where id_cons='$id_cons' and id_sez='$id_sez' and id_gruppo='$idgruppo'", $dbi);
+									$sql="SELECT id_gruppo FROM ".$prefix."_ele_lista where id_cons='$id_cons' and id_lista='$testlista'";
+$res4 = $dbi->prepare("$sql");
+$res4->execute();
+
+
+									list($idgruppo)=$res4->fetch(PDO::FETCH_NUM);
+									$sql="SELECT sum(voti) FROM ".$prefix."_ele_voti_gruppo where id_cons='$id_cons' and id_sez='$id_sez' and id_gruppo='$idgruppo'";
+$res4 = $dbi->prepare("$sql");
+$res4->execute();
+
+
 
 								}else{
-									$res4= mysql_query("SELECT sum(voti) FROM ".$prefix."_ele_voti_lista where id_cons='$id_cons' and id_sez='$id_sez' and id_lista='$testlista'", $dbi);
+									$sql="SELECT sum(voti) FROM ".$prefix."_ele_voti_lista where id_cons='$id_cons' and id_sez='$id_sez' and id_lista='$testlista'";
+$res4 = $dbi->prepare("$sql");
+$res4->execute();
+
+
 								}
-								if($res4) list($testvotil)=mysql_fetch_row($res4); else $testvotil=0;
-								$res4= mysql_query("SELECT sum(t1.voti) FROM ".$prefix."_ele_voti_candidati as t1 left join ".$prefix."_ele_candidati as t2 on t1.id_cand=t2.id_cand where t1.id_cons='$id_cons' and  t1.id_sez='$id_sez' and t2.id_lista='$testlista'", $dbi);
-								if($res4) list($testvotic)=mysql_fetch_row($res4); else $testvotic=0;
-								$res4= mysql_query("SELECT t1.voti FROM ".$prefix."_ele_voti_candidati as t1 left join ".$prefix."_ele_candidati as t2 on t1.id_cand=t2.id_cand where t1.id_cons='$id_cons' and  t1.id_sez='$id_sez' and t2.id_lista='$testlista'", $dbi);
-								if(mysql_num_rows($res4)) $contains++;
+								if($res4) list($testvotil)=$res4->fetch(PDO::FETCH_NUM); else $testvotil=0;
+								$sql="SELECT sum(t1.voti) FROM ".$prefix."_ele_voti_candidati as t1 left join ".$prefix."_ele_candidati as t2 on t1.id_cand=t2.id_cand where t1.id_cons='$id_cons' and  t1.id_sez='$id_sez' and t2.id_lista='$testlista'";
+$res4 = $dbi->prepare("$sql");
+$res4->execute();
+
+
+								if($res4) list($testvotic)=$res4->fetch(PDO::FETCH_NUM); else $testvotic=0;
+								$sql="SELECT t1.voti FROM ".$prefix."_ele_voti_candidati as t1 left join ".$prefix."_ele_candidati as t2 on t1.id_cand=t2.id_cand where t1.id_cons='$id_cons' and  t1.id_sez='$id_sez' and t2.id_lista='$testlista'";
+$res4 = $dbi->prepare("$sql");
+$res4->execute();
+
+
+								if($res4->rowCount()) $contains++;
 								$totvotic=0;
-								while(list($testvotic)=mysql_fetch_row($res4))
+								while(list($testvotic)=$res4->fetch(PDO::FETCH_NUM))
 								{
 									$totvotic+=$testvotic;
@@ -272,5 +404,9 @@
 		}
 					if(isset($can)){ 
-						$res4=mysql_query("insert into ".$prefix."_ele_controllosez values('$id_sez','$id_cons','$aff','$val','$gru','$lis','$can','$status')",$dbi);
+						$sql="insert into ".$prefix."_ele_controllosez values('$id_sez','$id_cons','$aff','$val','$gru','$lis','$can','$status')";
+$res4 = $dbi->prepare("$sql");
+$res4->execute();
+
+
 					}
 }
@@ -303,12 +439,20 @@
 	$solosede='';
 	if ($perms<32) {
-		$res = mysql_query("SELECT id_sede FROM ".$prefix."_ele_operatori where aid='$aid' and id_cons=$id_cons", $dbi);
+		$sql="SELECT id_sede FROM ".$prefix."_ele_operatori where aid='$aid' and id_cons=$id_cons";
+$res = $dbi->prepare("$sql");
+$res->execute();
+
+
 		if ($res) {
-			list($solouna)=mysql_fetch_row($res);
+			list($solouna)=$res->fetch(PDO::FETCH_NUM);
 			if ($solouna>0) $solosede="and id_sede='$solouna'";
 			}
 		}
-		$res = mysql_query("SELECT num_sez, id_sez ,id_sede FROM ".$prefix."_ele_sezioni where id_cons='$id_cons' $solosede order by num_sez", $dbi);
-		$max = mysql_num_rows($res);
+		$sql="SELECT num_sez, id_sez ,id_sede FROM ".$prefix."_ele_sezioni where id_cons='$id_cons' $solosede order by num_sez";
+$res = $dbi->prepare("$sql");
+$res->execute();
+
+
+		$max = $res->rowCount();
 		//if ($max>=64){
 		$i=0;
@@ -317,10 +461,14 @@
 
 		echo "<div id=\"navmenu\"> <ul>";
-		while(list($sez_num, $sez_id ,$sede_id) = mysql_fetch_row($res)) {
+		while(list($sez_num, $sez_id ,$sede_id) = $res->fetch(PDO::FETCH_NUM)) {
 			$ops='';
 			if(!$id_sez) {$id_sez=$sez_id; $id_sede=$sede_id;}
 			$i++;
-			$result = mysql_query("SELECT id_circ FROM ".$prefix."_ele_sede where id_cons='$id_cons' and id_sede='$sede_id' ", $dbi);
-			list($circ_id) = mysql_fetch_row($result);
+			$result = mysql_query("SELECT id_circ FROM ".$prefix."_ele_sede where id_cons='$id_cons' and id_sede='$sede_id' ";
+$result = $dbi->prepare("$sql");
+$result->execute();
+
+
+			list($circ_id) = $result->fetch(PDO::FETCH_NUM);
 			//colora la sezione
 			$sezstat=0; #die($ops);
@@ -361,6 +509,10 @@
 			
 			if(!$ops) $ops=1;
-			$res2= mysql_query("SELECT num_sez FROM ".$prefix."_ele_sezioni where id_sez='$id_sez'", $dbi);
-			list($numero_sez) = mysql_fetch_row($res2);
+			$sql="SELECT num_sez FROM ".$prefix."_ele_sezioni where id_sez='$id_sez'";
+$res2 = $dbi->prepare("$sql");
+$res2->execute();
+
+
+			list($numero_sez) = $res2->fetch(PDO::FETCH_NUM);
 			if ($sez_num==$numero_sez) {$cursez.= " border: solid; border-color: YELLOW; border-width: 4px; border-left: solid gray 4px; border-top: solid gray 4px;\"";} else $cursez.="\"";
 			echo "\n<li $cursez><b><a href=\"admin.php?op=voti&amp;id_cons_gen=$id_cons_gen&amp;id_circ=$circ_id&amp;id_sede=$sede_id&amp;id_sez=$sez_id&amp;ops=$ops&amp;do=spoglio&amp;id_lista=$id_lista\">$sez_num</a></b></li>\n";
@@ -386,14 +538,22 @@
 	///////////////////////
 
-	$resoper=mysql_query("SELECT t1.id_sede,t2.id_circ FROM ".$prefix."_ele_operatori as t1,
+	$sql="SELECT t1.id_sede,t2.id_circ FROM ".$prefix."_ele_operatori as t1,
 			 ".$prefix."_ele_sede as t2 
-			 where t1.id_cons='$id_cons' AND t1.id_sede=t2.id_sede and t1.aid='$aid'", $dbi);
-	list($id_sede2,$id_circ2) = mysql_fetch_row($resoper);
+			 where t1.id_cons='$id_cons' AND t1.id_sede=t2.id_sede and t1.aid='$aid'";
+$resoper = $dbi->prepare("$sql");
+$resoper->execute();
+
+
+	list($id_sede2,$id_circ2) = $resoper->fetch(PDO::FETCH_NUM);
 	if ($id_sede2 and !($id_sede==$id_sede2)) {
 		$id_sede=$id_sede2;
 		$id_circ=$id_circ2;
 		$do="spoglio";
-		$res= mysql_query("SELECT id_sez FROM ".$prefix."_ele_sezioni where id_cons='$id_cons' and id_sede=$id_sede order by num_sez limit 0,1", $dbi);
-		list($id_sez) = mysql_fetch_row($res);
+		$sql="SELECT id_sez FROM ".$prefix."_ele_sezioni where id_cons='$id_cons' and id_sede=$id_sede order by num_sez limit 0,1";
+$res = $dbi->prepare("$sql");
+$res->execute();
+
+
+		list($id_sez) = $res->fetch(PDO::FETCH_NUM);
 	}
 	if  ($do == "circo") {
@@ -406,6 +566,10 @@
 		.""._CIRCO.": "
 		."<select name=\"id_circ\">";
-		$res= mysql_query("SELECT id_circ,descrizione FROM ".$prefix."_ele_circoscrizione where id_cons='$id_cons' order by num_circ", $dbi);
-        	while(list($id,$descr) = mysql_fetch_row($res)) {
+		$sql="SELECT id_circ,descrizione FROM ".$prefix."_ele_circoscrizione where id_cons='$id_cons' order by num_circ";
+$res = $dbi->prepare("$sql");
+$res->execute();
+
+
+        	while(list($id,$descr) = $res->fetch(PDO::FETCH_NUM)) {
         		if ($descr!="Tutte"){
         			if ($id == $id_circ) {
@@ -433,6 +597,10 @@
 		OpenTable();
  		echo "\n<tr><td><form name=\"sede\" action=\"admin.php\">";
-		$res= mysql_query("SELECT  descrizione FROM ".$prefix."_ele_circoscrizione where id_cons='$id_cons' AND id_circ='$id_circ' order by num_circ", $dbi);
-        	list( $descr_circ) = mysql_fetch_row($res);
+		$sql="SELECT  descrizione FROM ".$prefix."_ele_circoscrizione where id_cons='$id_cons' AND id_circ='$id_circ' order by num_circ";
+$res = $dbi->prepare("$sql");
+$res->execute();
+
+
+        	list( $descr_circ) = $res->fetch(PDO::FETCH_NUM);
 		echo "<a href=\"admin.php?op=voti&amp;id_cons_gen=$id_cons_gen&amp;do=circo\">"._CIRCO."</a> $descr_circ ->";
       		echo "<input type=\"hidden\" name=\"op\" value=\"voti\">"
@@ -443,7 +611,11 @@
 		.""._INDIRIZZO.": "
 		."<select name=\"id_sede\">";
-		$res= mysql_query("SELECT id_sede,indirizzo FROM ".$prefix."_ele_sede where id_cons='$id_cons' and id_circ='$id_circ' order by indirizzo", $dbi);
+		$sql="SELECT id_sede,indirizzo FROM ".$prefix."_ele_sede where id_cons='$id_cons' and id_circ='$id_circ' order by indirizzo";
+$res = $dbi->prepare("$sql");
+$res->execute();
+
+
 //        	echo "$id_circ - $id_cons";
-		while(list($id,$indir) = mysql_fetch_row($res)) {
+		while(list($id,$indir) = $res->fetch(PDO::FETCH_NUM)) {
         		if ($id == $id_sede) {
 		     		$sel = "selected";
@@ -471,6 +643,10 @@
 	// Menu spoglio
 	//************************************
-     		$result = mysql_query("select id_cons,id_sez,id_sede,num_sez, maschi, femmine  from ".$prefix."_ele_sezioni where id_cons='$id_cons' and id_sez='$id_sez'", $dbi);
-     		list($id_cons2,$id_sez2,$id_sede,$num_sez, $maschi, $femmine) = mysql_fetch_row($result);
+     		$sql="select id_cons,id_sez,id_sede,num_sez, maschi, femmine  from ".$prefix."_ele_sezioni where id_cons='$id_cons' and id_sez='$id_sez'";
+$result = $dbi->prepare("$sql");
+$result->execute();
+
+
+     		list($id_cons2,$id_sez2,$id_sede,$num_sez, $maschi, $femmine) = $result->fetch(PDO::FETCH_NUM);
 
                 echo "<hr><table><tr><td  width=\"200\"><font size =\"4\" color=\"black\" align=\"left\"><b>Sezione N. $num_sez</b></font size></td><td><table><tr>";
@@ -490,13 +666,25 @@
 	if (!$id_sez) { echo"";#import( pagina di help );
 	} else{
-		$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($data,$orario)=mysql_fetch_row($res);
-		$res= mysql_query("SELECT voti_complessivi from ".$prefix."_ele_voti_parziale where id_sez='$id_sez' and orario='$orario' and data='$data'", $dbi);
-        list($voti) = mysql_fetch_row($res);
+		$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($data,$orario)=$res->fetch(PDO::FETCH_NUM);
+		$sql="SELECT voti_complessivi from ".$prefix."_ele_voti_parziale where id_sez='$id_sez' and orario='$orario' and data='$data'";
+$res = $dbi->prepare("$sql");
+$res->execute();
+
+
+        list($voti) = $res->fetch(PDO::FETCH_NUM);
 		if (!$voti) $ops=1;
 		else {
 			if($genere<4){
-				$res= mysql_query("SELECT sum(voti) from ".$prefix."_ele_voti_gruppo where id_sez='$id_sez'", $dbi);
-        		list($voti) = mysql_fetch_row($res);
+				$sql="SELECT sum(voti) from ".$prefix."_ele_voti_gruppo where id_sez='$id_sez'";
+$res = $dbi->prepare("$sql");
+$res->execute();
+
+
+        		list($voti) = $res->fetch(PDO::FETCH_NUM);
 				if ($voti==0 or $genere<3) $ops=4;
 				}
@@ -557,28 +745,56 @@
 $bgcolor2=$_SESSION['bgcolor2'];
     //controlla se sono stati inseriti i votanti
-$result = mysql_query("SELECT preferenze, id_fascia, id_conf,solo_gruppo, disgiunto from ".$prefix."_ele_cons_comune where id_cons='$id_cons'",$dbi);
-list($numprefs,$fascia,$id_conf,$flagsg,$disgiunto)=mysql_fetch_row($result);
+$sql="SELECT preferenze, id_fascia, id_conf,solo_gruppo, disgiunto from ".$prefix."_ele_cons_comune where id_cons='$id_cons'";
+$result = $dbi->prepare("$sql");
+$result->execute();
+
+
+list($numprefs,$fascia,$id_conf,$flagsg,$disgiunto)=$result->fetch(PDO::FETCH_NUM);
 
 ####### 06-11-2014 - circoscrizionali - nello spostamento ad altra sezione resta sullo stesso numero di lista anche se sono sezioni di diverse circoscrizioni
 if ($circo and $id_lista){
-	$res_lis = mysql_query("SELECT num_lista from ".$prefix."_ele_lista where id_lista=$id_lista",$dbi);
-	list($num_lista)=mysql_fetch_row($res_lis);
-	$res_lis = mysql_query("SELECT id_lista from ".$prefix."_ele_lista where num_lista=$num_lista and id_cons='$id_cons' $circo",$dbi);
-	list($id_lista)=mysql_fetch_row($res_lis);
+	$sql="SELECT num_lista from ".$prefix."_ele_lista where id_lista=$id_lista";
+$res_lis = $dbi->prepare("$sql");
+$res_lis->execute();
+
+
+	list($num_lista)=$res_lis->fetch(PDO::FETCH_NUM);
+	$sql="SELECT id_lista from ".$prefix."_ele_lista where num_lista=$num_lista and id_cons='$id_cons' $circo";
+$res_lis = $dbi->prepare("$sql");
+$res_lis->execute();
+
+
+	list($id_lista)=$res_lis->fetch(PDO::FETCH_NUM);
 }
 #######    
 if(!$votog and ($genere==3 or $genere==5))
-	$result = mysql_query("select validi_lista,nulli,bianchi,contestati_lista,voti_nulli_lista from ".$prefix."_ele_sezioni where id_cons='$id_cons' and id_sez='$id_sez' ", $dbi);
+	$sql="select validi_lista,nulli,bianchi,contestati_lista,voti_nulli_lista from ".$prefix."_ele_sezioni where id_cons='$id_cons' and id_sez='$id_sez' ";
+$result = $dbi->prepare("$sql");
+$result->execute();
+
+
 else
-	$result = mysql_query("select validi,nulli,bianchi,contestati,voti_nulli from ".$prefix."_ele_sezioni where id_cons='$id_cons' and id_sez='$id_sez' ", $dbi);
-    list($validi,$nulli,$bianchi,$contestati,$votinulli) = mysql_fetch_row($result);
+	$sql="select validi,nulli,bianchi,contestati,voti_nulli from ".$prefix."_ele_sezioni where id_cons='$id_cons' and id_sez='$id_sez' ";
+$result = $dbi->prepare("$sql");
+$result->execute();
+
+
+    list($validi,$nulli,$bianchi,$contestati,$votinulli) = $result->fetch(PDO::FETCH_NUM);
 		echo "<table class=\"table-menu\" style=\"width: 100%;\"><tr>";
-		$res_lis = mysql_query("SELECT id_lista, descrizione,num_lista from ".$prefix."_ele_lista where id_cons=$id_cons $circo order by num_lista",$dbi);
-		$num_liste = mysql_num_rows($res_lis);
+		$sql="SELECT id_lista, descrizione,num_lista from ".$prefix."_ele_lista where id_cons=$id_cons $circo order by num_lista";
+$res_lis = $dbi->prepare("$sql");
+$res_lis->execute();
+
+
+		$num_liste = $res_lis->rowCount();
 		$ele_lista='';
 		if (($genere==4 or $genere==5) and !$votoc) { //liste a piu' candidati
 			if(($genere==5 and $id_conf and $fascia<=$limite and !$disgiunto) and !$id_lista) { //esclude il voto di lista per le comunali nei comuni sotto fascia limite
-				$result = mysql_query("SELECT id_lista from ".$prefix."_ele_lista where id_cons=$id_cons limit 0,1",$dbi);
-				list($id_lista)=mysql_fetch_row($result);
+				$sql="SELECT id_lista from ".$prefix."_ele_lista where id_cons=$id_cons limit 0,1";
+$result = $dbi->prepare("$sql");
+$result->execute();
+
+
+				list($id_lista)=$result->fetch(PDO::FETCH_NUM);
 			}
 			echo "<td>&nbsp;</td></tr><tr><td style=\"vertical-align: top;\">";
@@ -595,26 +811,50 @@
 
 			}
-			while(list($id_rif,$descrizione,$num_lis) = mysql_fetch_row($res_lis)) {
+			while(list($id_rif,$descrizione,$num_lis) = $res_lis->fetch(PDO::FETCH_NUM)) {
 			$segna='';
-			$result = mysql_query("SELECT count(t1.voti) from ".$prefix."_ele_voti_candidati as t1 left join ".$prefix."_ele_candidati as t2 on (t1.id_cand=t2.id_cand) where t1.id_sez=$id_sez and t2.id_lista=$id_rif",$dbi);
-			list($ctrvoticand)=mysql_fetch_row($result);
-			$result = mysql_query("SELECT sum(t1.voti),0,0 from ".$prefix."_ele_voti_candidati as t1 left join ".$prefix."_ele_candidati as t2 on (t1.id_cand=t2.id_cand) where t1.id_sez=$id_sez and t2.id_lista=$id_rif",$dbi);
-			list($votisezcand)=mysql_fetch_row($result);
+			$sql="SELECT count(t1.voti) from ".$prefix."_ele_voti_candidati as t1 left join ".$prefix."_ele_candidati as t2 on (t1.id_cand=t2.id_cand) where t1.id_sez=$id_sez and t2.id_lista=$id_rif";
+$result = $dbi->prepare("$sql");
+$result->execute();
+
+
+			list($ctrvoticand)=$result->fetch(PDO::FETCH_NUM);
+			$sql="SELECT sum(t1.voti),0,0 from ".$prefix."_ele_voti_candidati as t1 left join ".$prefix."_ele_candidati as t2 on (t1.id_cand=t2.id_cand) where t1.id_sez=$id_sez and t2.id_lista=$id_rif";
+$result = $dbi->prepare("$sql");
+$result->execute();
+
+
+			list($votisezcand)=$result->fetch(PDO::FETCH_NUM);
 			if((($fascia>$limite or $disgiunto) or !$id_conf) or $genere==4)
-                $result = mysql_query("SELECT voti,solo_lista from ".$prefix."_ele_voti_lista where id_sez='$id_sez' and id_lista='$id_rif'", $dbi);
+                $sql="SELECT voti,solo_lista from ".$prefix."_ele_voti_lista where id_sez='$id_sez' and id_lista='$id_rif'";
+$result = $dbi->prepare("$sql");
+$result->execute();
+
+
             else{
 
-				$result = mysql_query("SELECT id_gruppo from ".$prefix."_ele_lista where id_lista='$id_rif'", $dbi);
-				list($id_gruppo)=mysql_fetch_row($result);
-				$result = mysql_query("SELECT sum(voti),0 from ".$prefix."_ele_voti_gruppo where id_sez='$id_sez' and id_gruppo='$id_gruppo'", $dbi);
+				$sql="SELECT id_gruppo from ".$prefix."_ele_lista where id_lista='$id_rif'";
+$result = $dbi->prepare("$sql");
+$result->execute();
+
+
+				list($id_gruppo)=$result;
+				$sql="SELECT sum(voti),0 from ".$prefix."_ele_voti_gruppo where id_sez='$id_sez' and id_gruppo='$id_gruppo'";
+$result = $dbi->prepare("$sql");
+$result->execute();
+
+
             }
-			list($votisezlis,$sgpl)=mysql_fetch_row($result);
+			list($votisezlis,$sgpl)=$result->fetch(PDO::FETCH_NUM);
 			if($votisezcand>($votisezlis*$numprefs))
 				{$segna="style=\"background-color: #dd0000;\"";}
 			elseif($ctrvoticand)
 				$segna="style=\"background-color: #99CC33;\"";
-			$res4= mysql_query("SELECT t1.voti,t2.num_cand FROM ".$prefix."_ele_voti_candidati as t1 left join ".$prefix."_ele_candidati as t2 on t1.id_cand=t2.id_cand where t1.id_cons='$id_cons' and  t1.id_sez='$id_sez' and t2.id_lista='$id_rif'", $dbi);
+			$sql="SELECT t1.voti,t2.num_cand FROM ".$prefix."_ele_voti_candidati as t1 left join ".$prefix."_ele_candidati as t2 on t1.id_cand=t2.id_cand where t1.id_cons='$id_cons' and  t1.id_sez='$id_sez' and t2.id_lista='$id_rif'";
+$res4 = $dbi->prepare("$sql");
+$res4->execute();
+
+
 			$errcand[$id_rif]=array();
-			while(list($testvotic,$numcand)=mysql_fetch_row($res4))
+			while(list($testvotic,$numcand)=$res4->fetch(PDO::FETCH_NUM))
 				if($votisezlis<$testvotic) { $segna="style=\"background-color: #dd0000;\"";$errcand[$id_rif][]=$numcand;}
                         
@@ -632,19 +872,35 @@
 		if ((!$id_lista)){$tab="_ele_voti_lista";} else {$tab="_ele_voti_candidati";}
 if(($genere==4 or ($genere==5 and $votog)) and !$id_lista)	
-		$result = mysql_query("SELECT sum(t1.voti),t2.validi, t2.solo_gruppo,t2.contestati_lista,t2.voti_nulli,t2.bianchi,t2.nulli,0,0,0 from ".$prefix."_ele_sezioni as t2 left join ".$prefix.$tab." as t1 on (t1.id_sez=t2.id_sez) where t2.id_sez=$id_sez group by t1.id_sez",$dbi);
+		$sql="SELECT sum(t1.voti),t2.validi, t2.solo_gruppo,t2.contestati_lista,t2.voti_nulli,t2.bianchi,t2.nulli,0,0,0 from ".$prefix."_ele_sezioni as t2 left join ".$prefix.$tab." as t1 on (t1.id_sez=t2.id_sez) where t2.id_sez=$id_sez group by t1.id_sez";
+$result = $dbi->prepare("$sql");
+$result->execute();
+
+
 else
-		$result = mysql_query("SELECT sum(t1.voti),t2.validi_lista, t2.solo_gruppo,t2.contestati_lista,t2.voti_nulli_lista,t2.bianchi,t2.nulli,t2.contestati,t2.voti_nulli,t2.solo_gruppo from ".$prefix."_ele_sezioni as t2 left join ".$prefix.$tab." as t1 on (t1.id_sez=t2.id_sez) where t2.id_sez='$id_sez' group by t1.id_sez",$dbi);
+		$sql="SELECT sum(t1.voti),t2.validi_lista, t2.solo_gruppo,t2.contestati_lista,t2.voti_nulli_lista,t2.bianchi,t2.nulli,t2.contestati,t2.voti_nulli,t2.solo_gruppo from ".$prefix."_ele_sezioni as t2 left join ".$prefix.$tab." as t1 on (t1.id_sez=t2.id_sez) where t2.id_sez='$id_sez' group by t1.id_sez";
+$result = $dbi->prepare("$sql");
+$result->execute();
+
+
 // aggiunte le variabili $sgpl e $vnulli2 per la gestione dei voti 1) al solo presidente per singola lista - 2) al solo presidente per singola lista perchÃ© nullo o contestato quello di lista		
-		$isscr= mysql_num_rows($result);
-		list( $voti_sez, $validi2, $sg,$cont2,$vnulli2,$bia2,$nul2,$con2,$vnul2,$sgpl) = mysql_fetch_row($result);
+		$isscr= $result->rowCount();
+		list( $voti_sez, $validi2, $sg,$cont2,$vnulli2,$bia2,$nul2,$con2,$vnul2,$sgpl) = $result->fetch(PDO::FETCH_NUM);
 		if(($genere==5 and !$disgiunto and $voti_sez and $flagsg and ($tipo_cons==18 or $tipo_cons==19))){ 
-			$resg = mysql_query("SELECT sum(solo_gruppo) from ".$prefix."_ele_voti_gruppo where id_cons=$id_cons and id_sez=$id_sez",$dbi);
-			list($sgpl)=mysql_fetch_row($resg);
+			$sql="SELECT sum(solo_gruppo) from ".$prefix."_ele_voti_gruppo where id_cons=$id_cons and id_sez=$id_sez";
+$resg = $dbi->prepare("$sql");
+$resg->execute();
+
+
+			list($sgpl)=$resg->fetch(PDO::FETCH_NUM);
 			if ($sg != $sgpl) echo "<table class=\"table-menu\" style=\"width: 50%;\"><tr><td style=\"background-color: rgb(255, 0, 0); color: black; text-align: center\"><img src=\"modules/Elezioni/images/alert.gif\" align=\"middle\" alt=\"\"><br><b> "._ATT_UNI." ".$sgpl." "._ATT_TOT_UNI." ".$sg."</b><br></td></table>";
 		}
 		$valista=$validi2;
 		if(!$id_lista or $genere==3){	//controllo di congruenza
-			$res2 = mysql_query("SELECT max(voti_complessivi) FROM ".$prefix."_ele_voti_parziale where id_cons='$id_cons' and id_sez='$id_sez'", $dbi);
-			list($tot) = mysql_fetch_row($res2);
+			$sql="SELECT max(voti_complessivi) FROM ".$prefix."_ele_voti_parziale where id_cons='$id_cons' and id_sez='$id_sez'";
+$res2 = $dbi->prepare("$sql");
+$res2->execute();
+
+
+			list($tot) = $res2->fetch(PDO::FETCH_NUM);
 			if ($validi2+$vnulli2+$cont2+$sg+$bia2+$nul2+$con2+$vnul2!=$tot and $validi+$sg>0){
 				echo "<table class=\"table-menu\" style=\"width: 50%;\"><tr><td style=\"background-color: rgb(255, 0, 0); color: black; text-align: center\"><img src=\"modules/Elezioni/images/alert.gif\" align=\"middle\" alt=\"\"><br><b> "._ATT_VOTANTI." ".$tot." "._NO_TOT_VOTI." ".($validi2+$vnulli2+$cont2+$sg+$bia2+$nul2+$con2+$vnul2)."</b><br></td></table>";
@@ -655,15 +911,31 @@
 			}
 		}elseif($genere==5){
-			$result = mysql_query("SELECT sum(t1.voti) from ".$prefix."_ele_voti_candidati as t1 left join ".$prefix."_ele_candidati as t2 on (t1.id_cand=t2.id_cand) where t1.id_sez=$id_sez and t2.id_lista=$id_lista",$dbi);
-			list($votisezcand)=mysql_fetch_row($result);
+			$sql="SELECT sum(t1.voti) from ".$prefix."_ele_voti_candidati as t1 left join ".$prefix."_ele_candidati as t2 on (t1.id_cand=t2.id_cand) where t1.id_sez=$id_sez and t2.id_lista=$id_lista";
+$result = $dbi->prepare("$sql");
+$result->execute();
+
+
+			list($votisezcand)=$result->fetch(PDO::FETCH_NUM);
 			if(($fascia>$limite or $disgiunto) or !$id_conf)
-                 $result = mysql_query("SELECT sum(voti) from ".$prefix."_ele_voti_lista where id_sez='$id_sez' and id_lista='$id_lista'", $dbi);
+                 $sql="SELECT sum(voti) from ".$prefix."_ele_voti_lista where id_sez='$id_sez' and id_lista='$id_lista'";
+$result = $dbi->prepare("$sql");
+$result->execute();
+
+
             else{
 
-				$result = mysql_query("SELECT id_gruppo from ".$prefix."_ele_lista where id_lista='$id_lista'", $dbi);
-				list($id_gruppo)=mysql_fetch_row($result);
-				$result = mysql_query("SELECT sum(voti) from ".$prefix."_ele_voti_gruppo where id_sez='$id_sez' and id_gruppo='$id_gruppo'", $dbi);
+				$sql="SELECT id_gruppo from ".$prefix."_ele_lista where id_lista='$id_lista'";
+$result = $dbi->prepare("$sql");
+$result->execute();
+
+
+				list($id_gruppo)=$result->fetch(PDO::FETCH_NUM);
+				$sql="SELECT sum(voti) from ".$prefix."_ele_voti_gruppo where id_sez='$id_sez' and id_gruppo='$id_gruppo'";
+$result = $dbi->prepare("$sql");
+$result->execute();
+
+
             }
-			list($votisezlis)=mysql_fetch_row($result);
+			list($votisezlis)=$result->fetch(PDO::FETCH_NUM);
 			if($votisezcand>($votisezlis*$numprefs))
 				{
@@ -674,19 +946,39 @@
 	$errgrulis=array();
 	if($genere==5 and !$disgiunto  and ($tipo_cons==18 or $tipo_cons==19)){
-		$resref = mysql_query("SELECT id_gruppo FROM ".$prefix."_ele_gruppo where id_cons='$id_cons'", $dbi);
-		$res4= mysql_query("SELECT count(0) FROM ".$prefix."_ele_voti_lista where id_sez='$id_sez'", $dbi);
-		list($sezscrl)=mysql_fetch_row($res4); 
+		$sql="SELECT id_gruppo FROM ".$prefix."_ele_gruppo where id_cons='$id_cons'";
+$resref = $dbi->prepare("$sql");
+$resref->execute();
+
+
+		$res4= mysql_query("SELECT count(0) FROM ".$prefix."_ele_voti_lista where id_sez='$id_sez'";
+$res4 = $dbi->prepare("$sql");
+$res4->execute();
+
+
+		list($sezscrl)=$res4->fetch(PDO::FETCH_NUM); 
 		if ($sezscrl)
 				
-		while ( list($id_gruppo)=mysql_fetch_row($resref))
+		while ( list($id_gruppo)=$resref->fetch(PDO::FETCH_NUM))
                     {
-                    $res3= mysql_query("SELECT sum(voti-solo_gruppo) FROM ".$prefix."_ele_voti_gruppo where id_sez='$id_sez' and id_gruppo='$id_gruppo'", $dbi);
-                    $res4= mysql_query("SELECT sum(voti+nulli_lista) FROM ".$prefix."_ele_voti_lista where id_sez='$id_sez' and  id_lista in (select id_lista from ".$prefix."_ele_lista where id_gruppo='$id_gruppo')", $dbi);
-                    list($vgruppo)=mysql_fetch_row($res3);
-                    list($vliste)=mysql_fetch_row($res4);
+                    $sql="SELECT sum(voti-solo_gruppo) FROM ".$prefix."_ele_voti_gruppo where id_sez='$id_sez' and id_gruppo='$id_gruppo'";
+$res3 = $dbi->prepare("$sql");
+$res3->execute();
+
+
+                    $sql="SELECT sum(voti+nulli_lista) FROM ".$prefix."_ele_voti_lista where id_sez='$id_sez' and  id_lista in (select id_lista from ".$prefix."_ele_lista where id_gruppo='$id_gruppo')";
+$res4 = $dbi->prepare("$sql");
+$res4->execute();
+
+
+                    list($vgruppo)=$res3->fetch(PDO::FETCH_NUM);
+                    list($vliste)=$res4->fetch(PDO::FETCH_NUM);
                     if($vliste>$vgruppo)
                     	{
-                    	 $result = mysql_query("SELECT descrizione FROM ".$prefix."_ele_gruppo where id_gruppo='$id_gruppo'", $dbi);
-                    	 list($dgruppo)=mysql_fetch_row($result);
+                    	 $sql="SELECT descrizione FROM ".$prefix."_ele_gruppo where id_gruppo='$id_gruppo'";
+$result = $dbi->prepare("$sql");
+$result->execute();
+
+
+                    	 list($dgruppo)=$result->fetch(PDO::FETCH_NUM);
                     	echo "<table class=\"table-menu\" style=\"width: 50%;\"><tr><td style=\"background-color: rgb(255, 0, 0); color: black; text-align: center\"><img src=\"modules/Elezioni/images/alert.gif\" align=\"middle\" alt=\"\"><br/><b> ATTENZIONE!<BR/>I voti delle liste collegate<br/> superano i voti assegnati al gruppo $dgruppo </b><br></td></tr></table>";
                     	$errgrulis[$id_gruppo]=1;
@@ -694,6 +986,10 @@
                     elseif($vliste<$vgruppo)
                     	{
-                    	 $result = mysql_query("SELECT descrizione FROM ".$prefix."_ele_gruppo where id_gruppo='$id_gruppo'", $dbi);
-                    	 list($dgruppo)=mysql_fetch_row($result);
+                    	 $sql="SELECT descrizione FROM ".$prefix."_ele_gruppo where id_gruppo='$id_gruppo'";
+$result = $dbi->prepare("$sql");
+$result->execute();
+
+
+                    	 list($dgruppo)=$result->fetch(PDO::FETCH_NUM);
                     	echo "<table class=\"table-menu\" style=\"width: 50%;\"><tr><td style=\"background-color: rgb(255, 0, 0); color: black; text-align: center\"><img src=\"modules/Elezioni/images/alert.gif\" align=\"middle\" alt=\"\"><br/><b> ATTENZIONE!<BR/>I voti assegnati al gruppo $dgruppo<br/> superano i voti delle liste collegate </b><br></td></tr></table>";
                     	$errgrulis[$id_gruppo]=1;
@@ -737,17 +1033,29 @@
 
 
-		$result = mysql_query("select t1.* from ".$prefix."_ele_candidati as t1 left join ".$prefix."_ele_lista as t2 on (t1.id_lista=t2.id_lista) WHERE t1.id_cons=$id_cons and t1.id_cons=t2.id_cons $ele_lista $circo ORDER BY t2.num_lista,t1.num_cand", $dbi);
-		$max = mysql_num_rows($result);
+		$sql="select t1.* from ".$prefix."_ele_candidati as t1 left join ".$prefix."_ele_lista as t2 on (t1.id_lista=t2.id_lista) WHERE t1.id_cons=$id_cons and t1.id_cons=t2.id_cons $ele_lista $circo ORDER BY t2.num_lista,t1.num_cand";
+$result = $dbi->prepare("$sql");
+$result->execute();
+
+
+		$max = $result->rowCount();
 		$tot_pref=0;
 		$i=1;
 
 		if($id_lista) {
-			while(list($id_cand,$id_cons2,$id_lista2, $cognome, $nome, $note, $simbolo, $num_cand) = mysql_fetch_row($result)){
+			while(list($id_cand,$id_cons2,$id_lista2, $cognome, $nome, $note, $simbolo, $num_cand) = $result->fetch(PDO::FETCH_NUM)){
 				// dati lista
-				$result1 = mysql_query("select id_lista, descrizione,simbolo,num_lista from ".$prefix."_ele_lista where id_lista='$id_lista2'", $dbi);
-				list($id_lista3,$descr_lista,$simb_lista,$num_lista)=mysql_fetch_row($result1);
+				$sql="select id_lista, descrizione,simbolo,num_lista from ".$prefix."_ele_lista where id_lista='$id_lista2'";
+$result1 = $dbi->prepare("$sql");
+$result1->execute();
+
+
+				list($id_lista3,$descr_lista,$simb_lista,$num_lista)=$result1->fetch(PDO::FETCH_NUM);
 			// dati gruppo
-				$result2 = mysql_query("select descrizione,simbolo from ".$prefix."_ele_gruppo where id_gruppo='$id_gruppo'", $dbi);
-				list($descr_gruppo,$simb_gruppo)=mysql_fetch_row($result2);
+				$sql="select descrizione,simbolo from ".$prefix."_ele_gruppo where id_gruppo='$id_gruppo'";
+$result2 = $dbi->prepare("$sql");
+$result2->execute();
+
+
+				list($descr_gruppo,$simb_gruppo)=$result2->fetch(PDO::FETCH_NUM);
 				
 				echo "<tr bgcolor=\"$bgcolor2\">";
@@ -758,6 +1066,10 @@
 				."<td align=\"left\"><b>$cognome $nome</b></td>";
 				$cond_sele="and id_cand=$id_cand";
-				$res = mysql_query("SELECT * FROM ".$prefix."$tab where id_cons='$id_cons' and id_sez='$id_sez' $cond_sele", $dbi);
-				$pro= mysql_fetch_array($res, 3);
+				$sql="SELECT * FROM ".$prefix."$tab where id_cons='$id_cons' and id_sez='$id_sez' $cond_sele";
+$res = $dbi->prepare("$sql");
+$res->execute();
+
+
+				$pro= $res->fetch(PDO::FETCH_BOTH);
 				if(in_array($num_cand,$errcand[$id_lista])) $errcolor="style=\"background-color: rgb(255, 0, 0);\""; else $errcolor='';
 				echo "<td align=\"right\" $errcolor><input  name=\"voti$i\" value=\"".$pro['voti']."\" size=\"7\"  style=\"text-align:right\">";
@@ -767,17 +1079,25 @@
 			} 
 		}else {
-			$result1 = mysql_query("select t2.voti,t1.id_lista, descrizione,simbolo,num_lista,t2.nulli_lista,t2.solo_lista,t1.id_gruppo 
+			$sql="select t2.voti,t1.id_lista, descrizione,simbolo,num_lista,t2.nulli_lista,t2.solo_lista,t1.id_gruppo 
 			from ".$prefix."_ele_lista as t1, ".$prefix."_ele_voti_lista as t2
 			where t1.id_cons='$id_cons' 
 			and t1.id_lista=t2.id_lista
 			and t2.id_sez=$id_sez
-			order by t1.num_lista", $dbi);
-			$num_lista=mysql_num_rows($result1);
+			order by t1.num_lista";
+$result1 = $dbi->prepare("$sql");
+$result1->execute();
+
+
+			$num_lista=$result1->rowCount();
 			if (!$num_lista){
-				$result1 = mysql_query("select '',id_lista, descrizione,simbolo,num_lista,'','',id_gruppo
+				$sql="select '',id_lista, descrizione,simbolo,num_lista,'','',id_gruppo
 				from ".$prefix."_ele_lista where id_cons='$id_cons' $circo
-				order by num_lista", $dbi);
+				order by num_lista";
+$result1 = $dbi->prepare("$sql");
+$result1->execute();
+
+
 			}
-			while (list($pro['voti'],$id_lista3,$descr_lista,$simb_lista,$num_lista,$vnpl,$slpl,$rifgruppo)=mysql_fetch_row($result1)){
+			while (list($pro['voti'],$id_lista3,$descr_lista,$simb_lista,$num_lista,$vnpl,$slpl,$rifgruppo)=$result1->fetch(PDO::FETCH_NUM)){
 				echo "<tr bgcolor=\"$bgcolor2\">";
 //				if ($genere<4 or $votoc){
@@ -813,8 +1133,16 @@
 ######modifica del 16-04-2009 per visualizzare i voti al solo sindaco nei comuni con meno di 15000 abitanti
 elseif(($genere==3 OR $genere==5) and ($id_lista) and ($fascia<=$limite or !$id_conf) and $numprefs==1) {
-$resvg = mysql_query("SELECT id_gruppo FROM ".$prefix."_ele_lista where id_lista='$id_lista'", $dbi);
-list($id_gruppo) = mysql_fetch_row($resvg);
-$resvg = mysql_query("SELECT sum(voti) FROM ".$prefix."_ele_voti_gruppo where id_gruppo='$id_gruppo' and id_sez='$id_sez'", $dbi);
-        list($voti_sind) = mysql_fetch_row($resvg);
+$sql="SELECT id_gruppo FROM ".$prefix."_ele_lista where id_lista='$id_lista'";
+$resvg = $dbi->prepare("$sql");
+$resvg->execute();
+
+
+list($id_gruppo) = $resvg->fetch(PDO::FETCH_NUM);
+$sql="SELECT sum(voti) FROM ".$prefix."_ele_voti_gruppo where id_gruppo='$id_gruppo' and id_sez='$id_sez'";
+$resvg = $dbi->prepare("$sql");
+$resvg->execute();
+
+
+        list($voti_sind) = $resvg;
 
 echo "<tr bgcolor=\"$bgcolor1\"><td></td><td><b>"._SOLO_GRUPPO."</b></td><td align=\"center\">".($voti_sind - $tot_pref)."</td></tr>";
@@ -852,7 +1180,7 @@
 	
 	$sqlcomu="select id_fascia,id_conf from ".$prefix."_ele_cons_comune where id_cons='$id_cons'";
-	$res = mysql_query($sqlcomu);
+	$sql=$sqlcomu);
 	if($res)
-		list($fascia,$id_conf)=mysql_fetch_row($res);
+		list($fascia,$id_conf)=$res->fetch(PDO::FETCH_NUM);
 	else {$fascia=0; $id_conf=0;}
 	if ($fileout) while (!$fp = fopen($fileout,"a"));
@@ -877,10 +1205,26 @@
 	if ((($genere==3) OR ($genere==5)) and !$id_lista and !$votog and (($disgiunto or $fascia>$limite) or !$id_conf)) $y = (count($arg)-4);
 	else $y=count($arg);#die ("delete from ".$prefix."_ele_controllosez where id_cons='$id_cons' and id_sez='$id_sez'");
-	mysql_query("delete from ".$prefix."_ele_controllosez where id_cons='$id_cons' and id_sez='$id_sez'", $dbi);
+	$sql="delete from ".$prefix."_ele_controllosez where id_cons='$id_cons' and id_sez='$id_sez'";
+$res = $dbi->prepare("$sql");
+$res->execute();
+
+
 	if($do==1) {
-			mysql_query("delete from ".$prefix."_ele_voti_lista where id_cons='$id_cons' and id_sez='$id_sez'", $dbi);
-			mysql_query("delete from ".$prefix."_ele_voti_candidati where id_cons='$id_cons' and id_sez='$id_sez'", $dbi);
+			$sql="delete from ".$prefix."_ele_voti_lista where id_cons='$id_cons' and id_sez='$id_sez'";
+$res = $dbi->prepare("$sql");
+$res->execute();
+
+
+			$sql="delete from ".$prefix."_ele_voti_candidati where id_cons='$id_cons' and id_sez='$id_sez'";
+$res = $dbi->prepare("$sql");
+$res->execute();
+
+
 			if($genere!=4)
-				mysql_query("update  ".$prefix."_ele_sezioni set validi_lista='0',contestati_lista='0',voti_nulli_lista='0',solo_gruppo='0' where id_cons='$id_cons' and id_sez='$id_sez'", $dbi);
+				$sql="update  ".$prefix."_ele_sezioni set validi_lista='0',contestati_lista='0',voti_nulli_lista='0',solo_gruppo='0' where id_cons='$id_cons' and id_sez='$id_sez'";
+$res = $dbi->prepare("$sql");
+$res->execute();
+
+
 	
 	}else{
@@ -892,18 +1236,38 @@
 		if($disgiunto and $condizione!="id_cand") {$slpl = intval($arg[$i++]); $vnriga.=",solo_lista='$slpl'"; $vnrigains.=",'".$slpl."'";} else {$vnriga.=''; if ($condizione=="id_lista") $vnrigains.=",'0'"; else $vnrigains="";}
 		$id_cand = intval($arg[$i]); 
-		$result = mysql_query("select * from ".$prefix."$tab where id_cons='$id_cons' and id_sez='$id_sez' and $condizione='$id_cand'", $dbi);
-        	$ar=mysql_fetch_array($result);		
+		$sql="select * from ".$prefix."$tab where id_cons='$id_cons' and id_sez='$id_sez' and $condizione='$id_cand'";
+$result = $dbi->prepare("$sql");
+$result->execute();
+
+
+        	$ar=$result->fetch(PDO::FETCH_BOTH);		
 
 		if ($ar){
 #die("T1:$dettnulli -- T2:$disgiunto -- update  ".$prefix."$tab set voti='$voti'$vnriga where id_cons='$id_cons' and id_sez='$id_sez' and $condizione='$id_cand'");
 			if ($ar['voti']!=$voti or (isset($vnpl) and $ar['nulli_lista']!=$vnpl) or (isset($slpl) and $ar['solo_lista']!=$slpl)) {
-				mysql_query("update  ".$prefix."$tab set voti='$voti'$vnriga where id_cons='$id_cons' and id_sez='$id_sez' and $condizione='$id_cand'", $dbi);
+				$sql="update  ".$prefix."$tab set voti='$voti'$vnriga where id_cons='$id_cons' and id_sez='$id_sez' and $condizione='$id_cand'";
+$res = $dbi->prepare("$sql");
+$res->execute();
+
+
 				if ($fileout) fwrite($fp,"update  ".$prefix."$tab set voti='$voti' where id_cons='$id_cons' and id_sez='$id_sez' and $condizione='$id_cand';\n");
-	        	mysql_query("insert into ".$prefix."_ele_log values('$id_cons','$id_sez','$username','$log_data','$orario','voti=".$ar['voti']."','$condizione:$id_cand voti: $voti','$tab')", $dbi);
+	        	$sql="insert into ".$prefix."_ele_log values('$id_cons','$id_sez','$username','$log_data','$orario','voti=".$ar['voti']."','$condizione:$id_cand voti: $voti','$tab')";
+$res = $dbi->prepare("$sql");
+$res->execute();
+
+
 			}
 		} else {//die ("insert into ".$prefix."$tab values ('$id_cons', '$id_cand','$id_sez','$voti'$vnrigains)");
 			if ($voti)
-	    		mysql_query("insert into ".$prefix."_ele_log values('$id_cons','$id_sez','$username','$log_data','$orario',' ','$condizione:$id_cand voti: $voti','$tab')", $dbi);
-			mysql_query("insert into ".$prefix."$tab values ('$id_cons', '$id_cand','$id_sez','$voti'$vnrigains)", $dbi);
+	    		$sql="insert into ".$prefix."_ele_log values('$id_cons','$id_sez','$username','$log_data','$orario',' ','$condizione:$id_cand voti: $voti','$tab')";
+$res = $dbi->prepare("$sql");
+$res->execute();
+
+
+			$sql="insert into ".$prefix."$tab values ('$id_cons', '$id_cand','$id_sez','$voti'$vnrigains)";
+$res = $dbi->prepare("$sql");
+$res->execute();
+
+
 			if ($fileout) fwrite($fp,"insert into ".$prefix."$tab values ('$id_cons', '$id_cand','$id_sez','$voti');\n");
 		}
@@ -915,21 +1279,39 @@
 	   if ((($genere==3) OR ($genere==5)) and !$id_lista and (($disgiunto or $fascia>$limite) or !$id_conf)) {
 			$valista=$arg[$i++]; 
-			$result = mysql_query("update ".$prefix."_ele_sezioni set solo_gruppo='".$arg[$i]."' where id_sez='$id_sez'",$dbi);
+			$sql="update ".$prefix."_ele_sezioni set solo_gruppo='".$arg[$i]."' where id_sez='$id_sez'";
+$res = $dbi->prepare("$sql");
+$res->execute();
+
+
 			if ($fileout) fwrite($fp,"update ".$prefix."_ele_sezioni set solo_gruppo='".$arg[$i]."' where id_sez='$id_sez';\n");
 			if ($condizione=="id_lista"){
-				$result = mysql_query("select * from ".$prefix."_ele_sezioni where id_sez='$id_sez'", $dbi);
-        		$ar=mysql_fetch_array($result);
+				$sql="select * from ".$prefix."_ele_sezioni where id_sez='$id_sez'";
+$result = $dbi->prepare("$sql");
+$result->execute();
+
+
+        		$ar=$result->fetch(PDO::FETCH_BOTH);
 				++$i;
-				mysql_query("update  ".$prefix."_ele_sezioni set voti_nulli_lista='".$arg[$i++]."', contestati_lista='".$arg[$i++]."' where id_sez='$id_sez'", $dbi);
+				$sql="update  ".$prefix."_ele_sezioni set voti_nulli_lista='".$arg[$i++]."', contestati_lista='".$arg[$i++]."' where id_sez='$id_sez'";
+$res = $dbi->prepare("$sql");
+$res->execute();
+
+
 				if ($fileout) fwrite($fp,"update  ".$prefix."_ele_sezioni set voti_nulli_lista='".$arg[$i++]."', contestati_lista='".$arg[$i++]."' where id_sez='$id_sez';\n");
-#				if ($ar['validi'] and !$ar['validi_lista']){
 				if ($ar['validi']){
-#					$result = mysql_query("select sum(voti) from ".$prefix."_ele_voti_lista where id_sez='$id_sez'", $dbi);
-#					list($val)=mysql_fetch_row($result);
-#					mysql_query("update  ".$prefix."_ele_sezioni set validi_lista='$val' where id_sez='$id_sez'", $dbi);
+
+
 					if($valista) 
-						mysql_query("update  ".$prefix."_ele_sezioni set validi_lista='$valista' where id_sez='$id_sez'", $dbi);
+						$sql="update  ".$prefix."_ele_sezioni set validi_lista='$valista' where id_sez='$id_sez'";
+$res = $dbi->prepare("$sql");
+$res->execute();
+
+
 					else
-						mysql_query("update  ".$prefix."_ele_sezioni set validi_lista=(`validi`-`solo_gruppo`-`voti_nulli_lista`-`contestati_lista`) where id_sez='$id_sez'", $dbi);
+						$sql="update  ".$prefix."_ele_sezioni set validi_lista=(`validi`-`solo_gruppo`-`voti_nulli_lista`-`contestati_lista`) where id_sez='$id_sez'";
+$res = $dbi->prepare("$sql");
+$res->execute();
+
+
 					if ($fileout) fwrite($fp,"update  ".$prefix."_ele_sezioni set validi_lista=(`validi`+`contestati`+`voti_nulli`-`solo_gruppo`-`voti_nulli_lista`-`contestati_lista`) where id_sez='$id_sez';\n");
 				}
@@ -954,13 +1336,25 @@
 $bgcolor1=$_SESSION['bgcolor2'];
 OpenTable();
-$res = mysql_query("SELECT vismf from ".$prefix."_ele_cons_comune where id_cons='$id_cons'", $dbi);
-if($res) list($vismf)= mysql_fetch_row($res); else $vismf=0;
-$res = mysql_query("SELECT orario,data FROM ".$prefix."_ele_rilaff where id_cons_gen=$id_cons_gen order by data,orario ", $dbi);
-$num = mysql_num_rows($res);
-$ressez = mysql_query("SELECT maschi,femmine FROM ".$prefix."_ele_sezioni where id_sez=$id_sez", $dbi);
-list($maschi,$femmine)=mysql_fetch_row($ressez);
+$sql="SELECT vismf from ".$prefix."_ele_cons_comune where id_cons='$id_cons'";
+$res = $dbi->prepare("$sql");
+$res->execute();
+
+
+if($res) list($vismf)= $res->fetch(PDO::FETCH_NUM); else $vismf=0;
+$sql="SELECT orario,data FROM ".$prefix."_ele_rilaff where id_cons_gen=$id_cons_gen order by data,orario ";
+$res = $dbi->prepare("$sql");
+$res->execute();
+
+
+$num = $res->rowCount();
+$sql="SELECT maschi,femmine FROM ".$prefix."_ele_sezioni where id_sez=$id_sez";
+$ressez = $dbi->prepare("$sql");
+$ressez->execute();
+
+
+list($maschi,$femmine)=$ressez->fetch(PDO::FETCH_NUM);
 $y=0;
 echo "<tr><td>&nbsp;</td></tr>";
-while (list($ora,$giorno)= mysql_fetch_row($res)){
+while (list($ora,$giorno)= $res->fetch(PDO::FETCH_NUM)){
 	$y++;
 	echo "\n<tr><td>";
@@ -976,6 +1370,10 @@
 	."<td bgcolor=\"$bgcolor1\" align=\"center\"><b>"._VOTIT."</b>"; 
 	if ($genere==0){ 
-		$res2 = mysql_query("SELECT * FROM ".$prefix."_ele_gruppo where id_cons='$id_cons'  ", $dbi);
-		$max = mysql_num_rows($res2);
+		$sql="SELECT * FROM ".$prefix."_ele_gruppo where id_cons='$id_cons'  ";
+$res2 = $dbi->prepare("$sql");
+$res2->execute();
+
+
+		$max = $res2_>rowCount();
 	}else{ $max=1;}
 	echo "<input type=\"hidden\" name=\"op\" value=\"rec_add_votanti\">";
@@ -992,18 +1390,34 @@
 			$query.=" and t2.num_gruppo=$i";
 		}
-		$result = mysql_query($query, $dbi);
-		list($id_cons2,$id_sez2,$id_parz,$orario,$data, $voti_u, $voti_d, $voti_t,$id_gruppo) = mysql_fetch_row($result);
-	   	$res2 = mysql_query("SELECT num_gruppo FROM ".$prefix."_ele_gruppo where id_gruppo=$id_gruppo ", $dbi);
-        $resril = mysql_query("select count(0) FROM ".$prefix."_ele_voti_parziale where id_sez='$id_sez' and id_gruppo='$id_gruppo'", $dbi);
-        list($numril)=mysql_fetch_row($resril);
+		$sql=$query;
+$result = $dbi->prepare("$sql");
+$result->execute();
+
+
+		list($id_cons2,$id_sez2,$id_parz,$orario,$data, $voti_u, $voti_d, $voti_t,$id_gruppo) = $result->fetch(PDO::FETCH_NUM);
+	   	$sql="SELECT num_gruppo FROM ".$prefix."_ele_gruppo where id_gruppo=$id_gruppo ";
+$res2 = $dbi->prepare("$sql");
+$res2->execute();
+
+
+        $resril = mysql_query("select count(0) FROM ".$prefix."_ele_voti_parziale where id_sez='$id_sez' and id_gruppo='$id_gruppo'";
+$resril = $dbi->prepare("$sql");
+$resril->execute();
+
+
+        list($numril)=$resril->fetch(PDO::FETCH_NUM);
 		if ($res2)
-			list($gruppo)= mysql_fetch_row($res2);
+			list($gruppo)= $res2->fetch(PDO::FETCH_NUM);
 		else
 			$gruppo=0;
 		if (!$gruppo>0) {
 			$gruppo=$i;
-			$res3 = mysql_query("SELECT id_gruppo FROM ".$prefix."_ele_gruppo where num_gruppo=$gruppo and id_cons=$id_cons", $dbi);
+			$sql="SELECT id_gruppo FROM ".$prefix."_ele_gruppo where num_gruppo=$gruppo and id_cons=$id_cons";
+$res3 = $dbi->prepare("$sql");
+$res3->execute();
+
+
 			if ($res3)
-			list($id_gruppo)=mysql_fetch_row($res3);
+			list($id_gruppo)=$res3->fetch(PDO::FETCH_NUM);
 		}
 		if(!isset($precede[$id_gruppo])) $precede[$id_gruppo]=0; if(!isset($error)) $error=0;
@@ -1046,6 +1460,10 @@
 #   echo "</table></form></td></tr>";
    echo "</table></form>";
-   	$compl= mysql_query("select count(voti_complessivi) from ".$prefix."_ele_voti_parziale where data='$giorno' and orario='$ora' and id_sez=$id_sez", $dbi);
-   	list ($complessivi)= mysql_fetch_row($compl);
+   	$sql="select count(voti_complessivi) from ".$prefix."_ele_voti_parziale where data='$giorno' and orario='$ora' and id_sez=$id_sez";
+$compl = $dbi->prepare("$sql");
+$compl->execute();
+
+
+   	list ($complessivi)= $compl->fetch(PDO::FETCH_NUM);
 	if (!$complessivi) 
 	{
@@ -1097,25 +1515,57 @@
     $data=date("Y/m/d");
 	$tempo=date("H:i:s");
-	mysql_query("delete from ".$prefix."_ele_controllosez where id_cons='$id_cons' and id_sez='$id_sez'", $dbi);
+	$sql="delete from ".$prefix."_ele_controllosez where id_cons='$id_cons' and id_sez='$id_sez'";
+$res = $dbi->prepare("$sql");
+$res->execute();
+
+
 	$query="select * from ".$prefix."_ele_voti_parziale where data='$giorno' and orario='$ora' and id_sez='$id_sez'";
 	if ($genere==0){
 		$query.=" and id_gruppo=$id_gruppo";
 	}
-	$res=mysql_query("$query",$dbi);
-	$righe=mysql_num_rows($res);
+	$sql="$query";
+$res = $dbi->prepare("$sql");
+$res->execute();
+
+
+	$righe=$res->rowCount();
     if (!$righe){
-        mysql_query("insert into ".$prefix."_ele_log values('$id_cons','$id_sez','$username','$data','$tempo','','id_parz:$id_parz ora: $ora data:$giorno voti uomini:$voti_u donne:$voti_d totali:$voti_t id_gruppo:$id_gruppo','".$prefix."_ele_voti_parziale')", $dbi);
-	mysql_query("insert into ".$prefix."_ele_voti_parziale values ('$id_cons', '$id_sez','$id_parz','$ora','$giorno','$voti_u','$voti_d','$voti_t','$id_gruppo')", $dbi);
+        $sql="insert into ".$prefix."_ele_log values('$id_cons','$id_sez','$username','$data','$tempo','','id_parz:$id_parz ora: $ora data:$giorno voti uomini:$voti_u donne:$voti_d totali:$voti_t id_gruppo:$id_gruppo','".$prefix."_ele_voti_parziale')";
+$res = $dbi->prepare("$sql");
+$res->execute();
+
+
+	$sql="insert into ".$prefix."_ele_voti_parziale values ('$id_cons', '$id_sez','$id_parz','$ora','$giorno','$voti_u','$voti_d','$voti_t','$id_gruppo')";
+$res = $dbi->prepare("$sql");
+$res->execute();
+
+
 	if ($fileout) fwrite($fp,"insert into ".$prefix."_ele_voti_parziale values ('$id_cons', '$id_sez','$id_parz','$ora','$giorno','$voti_u','$voti_d','$voti_t','$id_gruppo');\n");
      } elseif($op=="true"){
-        $result = mysql_query("delete from ".$prefix."_ele_voti_parziale where id_parz='$id_parz'", $dbi);
+        $sql="delete from ".$prefix."_ele_voti_parziale where id_parz='$id_parz'";
+$res = $dbi->prepare("$sql");
+$res->execute();
+
+
         if ($fileout) fwrite($fp,"delete from ".$prefix."_ele_voti_parziale where id_parz='$id_parz';\n");
 	 } else {
-  	$res=mysql_query("select * from ".$prefix."_ele_voti_parziale where id_parz=$id_parz",$dbi);
-	$ar=mysql_fetch_array($res);
+  	$sql="select * from ".$prefix."_ele_voti_parziale where id_parz=$id_parz";
+$res = $dbi->prepare("$sql");
+$res->execute();
+
+
+	$ar=$res->fetch(PDO::FETCH_BOTH);
 	
 	if ($ar['voti_uomini']!=$voti_u or $ar['voti_donne']!=$voti_d or $ar['voti_complessivi']!=$voti_t){   	
-	mysql_query("insert into ".$prefix."_ele_log values('$id_cons','$id_sez','$username','$data','$tempo','ora:$ar[3] data:$ar[4] voti uomini:$ar[5] donne:$ar[6] totali:$ar[7] gruppo:$ar[8]','id_parz:$id_parz ora: $ora data:$giorno voti uomini:$voti_u donne:$voti_d totali:$voti_t id_gruppo:$id_gruppo','".$prefix."_ele_voti_parziale')", $dbi);	
-	$result = mysql_query("update  ".$prefix."_ele_voti_parziale set voti_uomini='$voti_u', voti_donne='$voti_d', voti_complessivi='$voti_t' where id_parz='$id_parz'", $dbi);
+	$sql="insert into ".$prefix."_ele_log values('$id_cons','$id_sez','$username','$data','$tempo','ora:$ar[3] data:$ar[4] voti uomini:$ar[5] donne:$ar[6] totali:$ar[7] gruppo:$ar[8]','id_parz:$id_parz ora: $ora data:$giorno voti uomini:$voti_u donne:$voti_d totali:$voti_t id_gruppo:$id_gruppo','".$prefix."_ele_voti_parziale')";
+$res = $dbi->prepare("$sql");
+$res->execute();
+
+	
+	$sql="update  ".$prefix."_ele_voti_parziale set voti_uomini='$voti_u', voti_donne='$voti_d', voti_complessivi='$voti_t' where id_parz='$id_parz'";
+$res = $dbi->prepare("$sql");
+$res->execute();
+
+
 	if ($fileout) fwrite($fp,"update  ".$prefix."_ele_voti_parziale set voti_uomini='$voti_u', voti_donne='$voti_d', voti_complessivi='$voti_t' where id_parz='$id_parz';\n");
 	}
@@ -1158,8 +1608,16 @@
 	."<td bgcolor=\"#ffffff\"></td> </tr>";
 /*if($ops==3 and ($genere==3 or ($genere==5 and $fascia>$limite)) )
-    $result = mysql_query("select id_cons,id_sez,validi_lista,nulli,bianchi,contestati_lista,voti_nulli_lista,solo_gruppo,contestati,voti_nulli from ".$prefix."_ele_sezioni where id_cons='$id_cons' and id_sez='$id_sez' ", $dbi);
+    $result = mysql_query("select id_cons,id_sez,validi_lista,nulli,bianchi,contestati_lista,voti_nulli_lista,solo_gruppo,contestati,voti_nulli from ".$prefix."_ele_sezioni where id_cons='$id_cons' and id_sez='$id_sez' ";
+$res = $dbi->prepare("$sql");
+$res->execute();
+
+
 else */
-    $result = mysql_query("select id_cons,id_sez,validi,nulli,bianchi,contestati,voti_nulli,'0','0','0',solo_lista from ".$prefix."_ele_sezioni where id_cons='$id_cons' and id_sez='$id_sez' ", $dbi);
-    list($id_cons2,$id_sez2,$validi, $nulli, $bianchi, $contestati,$votinulli,$sg,$conts,$nullis,$sololista) = mysql_fetch_row($result);
+    $sql = "select id_cons,id_sez,validi,nulli,bianchi,contestati,voti_nulli,'0','0','0',solo_lista from ".$prefix."_ele_sezioni where id_cons='$id_cons' and id_sez='$id_sez' ";
+$result = $dbi->prepare("$sql");
+$result->execute();
+
+
+    list($id_cons2,$id_sez2,$validi, $nulli, $bianchi, $contestati,$votinulli,$sg,$conts,$nullis,$sololista) = $result->fetch(PDO::FETCH_NUM);
     $tot_nulli=$nulli+$bianchi+$contestati+$votinulli;
     $tot_voti=$validi+$tot_nulli+$conts+$nullis;
@@ -1228,26 +1686,58 @@
 $log_ora=getdate(time());	
 $orario=($log_ora['hours'].":".$log_ora['minutes'].":".$log_ora['seconds']);
-mysql_query("delete from ".$prefix."_ele_controllosez where id_cons='$id_cons' and id_sez='$id_sez'", $dbi);
-
-$result= mysql_query("select voti_complessivi from ".$prefix."_ele_voti_parziale where id_cons='$id_cons' and id_sez='$id_sez' order by id_parz desc", $dbi);
-list($voti_t) = mysql_fetch_row($result);
+$sql="delete from ".$prefix."_ele_controllosez where id_cons='$id_cons' and id_sez='$id_sez'";
+$res = $dbi->prepare("$sql");
+$res->execute();
+
+
+
+$sql="select voti_complessivi from ".$prefix."_ele_voti_parziale where id_cons='$id_cons' and id_sez='$id_sez' order by id_parz desc";
+$result = $dbi->prepare("$sql");
+$result->execute();
+
+
+list($voti_t) = $result->fetch(PDO::FETCH_NUM);
    $tot_voti=$validi+$nulli+$bianchi+$contestati+$votinulli;
 $sololista=$voti_t-$tot_voti;
-	$result= mysql_query("select solo_gruppo,disgiunto from ".$prefix."_ele_cons_comune where id_cons='$id_cons' ", $dbi);
-	list($flagsg,$disgiunto)=mysql_fetch_row($result);
-	$result= mysql_query("select * from ".$prefix."_ele_sezioni where id_cons='$id_cons' and id_sez='$id_sez' ", $dbi);
-	$ar=mysql_fetch_array($result);
+	$sql="select solo_gruppo,disgiunto from ".$prefix."_ele_cons_comune where id_cons='$id_cons' ";
+$result = $dbi->prepare("$sql");
+$result->execute();
+
+
+	list($flagsg,$disgiunto)=$result->fetch(PDO::FETCH_NUM);
+	$sql="select * from ".$prefix."_ele_sezioni where id_cons='$id_cons' and id_sez='$id_sez' ";
+$result = $dbi->prepare("$sql");
+$result->execute();
+
+
+	$ar=$result->fetch(PDO::FETCH_NUM);
 	$validilista=$validi-$ar['solo_gruppo'];
 	if ($ar['solo_lista'] or !$disgiunto) $rigasl=''; else $rigasl=", solo_lista='$sololista'";
 #die("qui: if($ops==3 and ($genere==3 or $genere==4 or $genere==5) and $votog){");
 	if($ops==3 and ($genere==3 or $genere==4 or $genere==5) and ($votog or $genere==4)){
-	mysql_query("insert into ".$prefix."_ele_log values('$id_cons','$id_sez','$username','$log_data','$orario','validi_lista:$ar[14] nulli:$ar[7] bianchi:$ar[8] contestati_lista:$ar[15]  voti_nulli_lista:$ar[16]','validi_lista=$validilista, nulli=$nulli,bianchi=$bianchi,contestati_lista=$contestati,voti_nulli_lista=$votinulli','_ele_sezioni')", $dbi);	
-
-/*		$result = mysql_query("update  ".$prefix."_ele_sezioni set validi='$validi', contestati='$contestati', validi_lista='$validi', nulli='$nulli',bianchi='$bianchi',contestati_lista='$contestati', voti_nulli_lista='$votinulli' where id_cons='$id_cons' and id_sez='$id_sez' ", $dbi);
+	$sql="insert into ".$prefix."_ele_log values('$id_cons','$id_sez','$username','$log_data','$orario','validi_lista:$ar[14] nulli:$ar[7] bianchi:$ar[8] contestati_lista:$ar[15]  voti_nulli_lista:$ar[16]','validi_lista=$validilista, nulli=$nulli,bianchi=$bianchi,contestati_lista=$contestati,voti_nulli_lista=$votinulli','_ele_sezioni')";
+$res = $dbi->prepare("$sql");
+$res->execute();
+
+	
+
+/*		$result = mysql_query("update  ".$prefix."_ele_sezioni set validi='$validi', contestati='$contestati', validi_lista='$validi', nulli='$nulli',bianchi='$bianchi',contestati_lista='$contestati', voti_nulli_lista='$votinulli' where id_cons='$id_cons' and id_sez='$id_sez' ";
+$res = $dbi->prepare("$sql");
+$res->execute();
+
+
 		if ($fileout) fwrite($fp,"update  ".$prefix."_ele_sezioni set validi='$validi', contestati='$contestati', validi_lista='$validi', nulli='$nulli',bianchi='$bianchi',contestati_lista='$contestati', voti_nulli_lista='$votinulli' where id_cons='$id_cons' and id_sez='$id_sez';\n"); */
-		$result = mysql_query("update  ".$prefix."_ele_sezioni set validi='$validi', contestati='$contestati', validi_lista='$validi', nulli='$nulli',bianchi='$bianchi',contestati_lista='$contestati', voti_nulli='$votinulli' $rigasl where id_cons='$id_cons' and id_sez='$id_sez' ", $dbi);
+		$sql="update  ".$prefix."_ele_sezioni set validi='$validi', contestati='$contestati', validi_lista='$validi', nulli='$nulli',bianchi='$bianchi',contestati_lista='$contestati', voti_nulli='$votinulli' $rigasl where id_cons='$id_cons' and id_sez='$id_sez' ";
+$res = $dbi->prepare("$sql");
+$res->execute();
+
+
 		if ($fileout) fwrite($fp,"update  ".$prefix."_ele_sezioni set validi='$validi', contestati='$contestati', validi_lista='$validilista', nulli='$nulli',bianchi='$bianchi',contestati_lista='$contestati', voti_nulli='$votinulli' $rigasl where id_cons='$id_cons' and id_sez='$id_sez';\n");
 	}else{
- 	mysql_query("insert into ".$prefix."_ele_log values('$id_cons','$id_sez','$username','$log_data','$orario','validi:$ar[6] nulli:$ar[7] bianchi:$ar[8] contestati:$ar[9] voti_nulli:$ar[13]','validi=$validi, nulli=$nulli,bianchi=$bianchi,contestati=$contestati, voti_nulli=$votinulli','_ele_sezioni')", $dbi);	
+ 	$sql="insert into ".$prefix."_ele_log values('$id_cons','$id_sez','$username','$log_data','$orario','validi:$ar[6] nulli:$ar[7] bianchi:$ar[8] contestati:$ar[9] voti_nulli:$ar[13]','validi=$validi, nulli=$nulli,bianchi=$bianchi,contestati=$contestati, voti_nulli=$votinulli','_ele_sezioni')";
+$res = $dbi->prepare("$sql");
+$res->execute();
+
+	
 	$valista="";
 	if ($ar['validi_lista']){ 
@@ -1256,5 +1746,9 @@
 	}
 
-		$result = mysql_query("update  ".$prefix."_ele_sezioni set validi='$validi', nulli='$nulli',bianchi='$bianchi',contestati='$contestati',voti_nulli='$votinulli' $rigasl $valista where id_cons='$id_cons' and id_sez='$id_sez' ", $dbi);
+		$sql="update  ".$prefix."_ele_sezioni set validi='$validi', nulli='$nulli',bianchi='$bianchi',contestati='$contestati',voti_nulli='$votinulli' $rigasl $valista where id_cons='$id_cons' and id_sez='$id_sez' ";
+$res = $dbi->prepare("$sql");
+$res->execute();
+
+
 		if ($fileout) fwrite($fp,"update  ".$prefix."_ele_sezioni set validi='$validi', nulli='$nulli',bianchi='$bianchi',contestati='$contestati',voti_nulli='$votinulli' $rigasl $valista where id_cons='$id_cons' and id_sez='$id_sez';\n");
 	}
@@ -1281,6 +1775,10 @@
 $bgcolor1="#7777ff";
 $bgcolor2=$_SESSION['bgcolor2'];
-    $res = mysql_query("SELECT * FROM ".$prefix."_ele_gruppo where id_cons='$id_cons'  ", $dbi);
-    $max = mysql_num_rows($res);
+    $sql="SELECT * FROM ".$prefix."_ele_gruppo where id_cons='$id_cons'  ";
+$res = $dbi->prepare("$sql");
+$res->execute();
+
+
+    $max = $res->rowCount();
     $max = $max-1;
 	 echo "<SCRIPT type=\"text/javascript\">\n\n<!--\n";
@@ -1297,6 +1795,10 @@
 	echo "<center>";
     if ($genere!=0){
-	$result = mysql_query("SELECT voti_uomini,voti_donne, voti_complessivi FROM ".$prefix."_ele_voti_parziale where id_sez='$id_sez' and id_cons='$id_cons' order by data desc,orario desc limit 0,1", $dbi);
-    	list( $voti_u, $voti_d, $voti_t) = mysql_fetch_row($result);
+	$sql="SELECT voti_uomini,voti_donne, voti_complessivi FROM ".$prefix."_ele_voti_parziale where id_sez='$id_sez' and id_cons='$id_cons' order by data desc,orario desc limit 0,1";
+$result = $dbi->prepare("$sql");
+$result->execute();
+
+
+    	list( $voti_u, $voti_d, $voti_t) = $result->fetch(PDO::FETCH_NUM)
    	echo "<table  class=\"table-menu\" style=\"width: 50%; color: black;\">"
 	."<tr><td></td><td align=\"center\"></td><td bgcolor=\"$bgcolor1\" align=\"center\">"._VOTIU."</td><td bgcolor=\"$bgcolor1\" align=\"center\">"._VOTID."</td><td bgcolor=\"$bgcolor1\" align=\"center\">"._VOTIT."</td></tr>"
@@ -1306,62 +1808,126 @@
 	echo "<table  class=\"table-menu\" style=\"width: 50%; color: black\">";
     if ($genere==0){
-    	$res = mysql_query("SELECT id_gruppo,si+no,validi,nulli,bianchi,contestati FROM ".$prefix."_ele_voti_ref where id_cons='$id_cons' and id_sez='$id_sez'  ", $dbi);
-		while (list($id_gruppo,$voti_parz,$validi,$nulli,$bianchi,$contestati) = mysql_fetch_row($res)){
+    	$sql="SELECT id_gruppo,si+no,validi,nulli,bianchi,contestati FROM ".$prefix."_ele_voti_ref where id_cons='$id_cons' and id_sez='$id_sez'  ";
+$res = $dbi->prepare("$sql");
+$res->execute();
+
+
+		while (list($id_gruppo,$voti_parz,$validi,$nulli,$bianchi,$contestati) = $res->fetch(PDO::FETCH_NUM)){
 			if ($voti_parz!=$validi){
-				$res2 = mysql_query("SELECT num_gruppo FROM ".$prefix."_ele_gruppo where id_cons='$id_cons' and id_gruppo='$id_gruppo'  ", $dbi);
-				list($num_gruppo) = mysql_fetch_row($res2);
+				$sql="SELECT num_gruppo FROM ".$prefix."_ele_gruppo where id_cons='$id_cons' and id_gruppo='$id_gruppo'  ";
+$res2 = $dbi->prepare("$sql");
+$res2->execute();
+
+
+				list($num_gruppo) = $res2->fetch(PDO::FETCH_NUM);
 				echo "<tr><td style=\"background-color: rgb(255, 0, 0); text-align:center\"><img src=\"modules/Elezioni/images/alert.gif\" align=\"middle\" alt=\"\"><br><b> "._ATT_VOTI_REF." $num_gruppo: ".$voti_parz." "._NO_VAL_VOTI.": ".$validi."</b><br></td></tr>";
 			}
-			$res2 = mysql_query("SELECT max(voti_complessivi) FROM ".$prefix."_ele_voti_parziale where id_cons='$id_cons' and id_sez='$id_sez' and id_gruppo='$id_gruppo' ", $dbi);
-			list($tot) = mysql_fetch_row($res2);
+			$sql="SELECT max(voti_complessivi) FROM ".$prefix."_ele_voti_parziale where id_cons='$id_cons' and id_sez='$id_sez' and id_gruppo='$id_gruppo' ";
+$res2 = $dbi->prepare("$sql");
+$res2->execute();
+
+
+			list($tot) = $res2->fetch(PDO::FETCH_NUM);
 			if (($validi+$nulli+$bianchi+$contestati)!= $tot ){
-				$res2 = mysql_query("SELECT num_gruppo FROM ".$prefix."_ele_gruppo where id_cons='$id_cons' and id_gruppo='$id_gruppo'", $dbi);
-				list($num_gruppo) = mysql_fetch_row($res2);
+				$sql="SELECT num_gruppo FROM ".$prefix."_ele_gruppo where id_cons='$id_cons' and id_gruppo='$id_gruppo'";
+$res2 = $dbi->prepare("$sql");
+$res2->execute();
+
+
+				list($num_gruppo) = $res2->fetch(PDO::FETCH_NUM);
 				echo "<tr><td style=\"background-color: rgb(255, 0, 0); text-align:center\"><img src=\"modules/Elezioni/images/alert.gif\" align=\"middle\" alt=\"\"><br><b> "._ATT_VOTANTI_REF." $num_gruppo: ".$tot." "._NO_SOMMA." ".($validi+$nulli+$bianchi+$contestati)."</b><br></td></tr>";
 			}
 		}
     }else{
-	$result= mysql_query("select solo_gruppo,disgiunto from ".$prefix."_ele_cons_comune where id_cons='$id_cons' ", $dbi);
-	list($flagsg,$disgiunto)=mysql_fetch_row($result);
-    	$res = mysql_query("SELECT sum(voti) FROM ".$prefix."_ele_voti_gruppo where id_cons='$id_cons' and id_sez='$id_sez'", $dbi);
-       	list($voti_parz) = mysql_fetch_row($res);
-        $res = mysql_query("SELECT validi,nulli,bianchi,contestati,solo_lista,voti_nulli FROM ".$prefix."_ele_sezioni where id_cons='$id_cons' and id_sez='$id_sez'", $dbi);
-    	list($validi,$nulli,$bianchi,$contestati,$solo_lista,$votinulli) = mysql_fetch_row($res);
+	$sql="select solo_gruppo,disgiunto from ".$prefix."_ele_cons_comune where id_cons='$id_cons' ";
+$result = $dbi->prepare("$sql");
+$result->execute();
+
+
+	list($flagsg,$disgiunto)=$result->fetch(PDO::FETCH_NUM);
+    	$sql="SELECT sum(voti) FROM ".$prefix."_ele_voti_gruppo where id_cons='$id_cons' and id_sez='$id_sez'";
+$res = $dbi->prepare("$sql");
+$res->execute();
+
+
+       	list($voti_parz) = $res->fetch(PDO::FETCH_NUM);
+        $sql="SELECT validi,nulli,bianchi,contestati,solo_lista,voti_nulli FROM ".$prefix."_ele_sezioni where id_cons='$id_cons' and id_sez='$id_sez'";
+$res = $dbi->prepare("$sql");
+$res->execute();
+
+
+    	list($validi,$nulli,$bianchi,$contestati,$solo_lista,$votinulli) = $res->fetch(PDO::FETCH_NUM);
 		if ($voti_parz!=($validi-$solo_lista) and $voti_parz>0){
 			echo "<tr><td style=\"background-color: rgb(255, 0, 0); text-align:center\"><img src=\"modules/Elezioni/images/alert.gif\" align=\"middle\" alt=\"\"><br><b> "._ATT_VOTI." ".$voti_parz." "._NO_VAL_VOTI." ".($validi-$solo_lista)."</b><br></td><tr>";
     	}
-		$res2 = mysql_query("SELECT max(voti_complessivi) FROM ".$prefix."_ele_voti_parziale where id_cons='$id_cons' and id_sez='$id_sez'", $dbi);
-		list($tot) = mysql_fetch_row($res2);
+		$sql="SELECT max(voti_complessivi) FROM ".$prefix."_ele_voti_parziale where id_cons='$id_cons' and id_sez='$id_sez'";
+$res2 = $dbi->prepare("$sql");
+$res2->execute();
+
+
+		list($tot) = $res2->fetch(PDO::FETCH_NUM);
 		if ($validi+$nulli+$bianchi+$contestati+$votinulli!=$tot and $validi+$nulli+$bianchi+$contestati+$votinulli>0){
 			echo "<tr><td style=\"background-color: rgb(255, 0, 0); text-align:center\"><img src=\"modules/Elezioni/images/alert.gif\" align=\"middle\" alt=\"\"><br><b> "._ATT_VOTANTI." ".$tot." "._NO_TOT_VOTI." ".($validi+$nulli+$bianchi+$contestati+$votinulli)."</b><br></td></tr>";
     	}
-		$resg=mysql_query("SELECT sum(voti) from ".$prefix."_ele_voti_lista where id_cons=$id_cons and id_sez=$id_sez",$dbi);
-		list($voti_sez)=mysql_fetch_row($resg);
+		$sql="SELECT sum(voti) from ".$prefix."_ele_voti_lista where id_cons=$id_cons and id_sez=$id_sez";
+$resg = $dbi->prepare("$sql");
+$resg->execute();
+
+
+		list($voti_sez)=$resg->fetch(PDO::FETCH_NUM);
 		if(($genere==5 and !$disgiunto and $voti_sez and $flagsg and ($tipo_cons==18 or $tipo_cons==19))){
 
-			$resg = mysql_query("SELECT sum(solo_gruppo) from ".$prefix."_ele_voti_gruppo where id_cons=$id_cons and id_sez=$id_sez",$dbi);
-			list($sgpl)=mysql_fetch_row($resg);
-			$resg = mysql_query("SELECT solo_gruppo from ".$prefix."_ele_sezioni where id_cons=$id_cons and id_sez=$id_sez",$dbi);
-			list($sg)=mysql_fetch_row($resg);
+			$sql="SELECT sum(solo_gruppo) from ".$prefix."_ele_voti_gruppo where id_cons=$id_cons and id_sez=$id_sez";
+$resg = $dbi->prepare("$sql");
+$resg->execute();
+
+
+			list($sgpl)=$resg->fetch(PDO::FETCH_NUM);
+			$sql="SELECT solo_gruppo from ".$prefix."_ele_sezioni where id_cons=$id_cons and id_sez=$id_sez";
+$resg = $dbi->prepare("$sql");
+$resg->execute();
+
+
+			list($sg)=$resg->fetch(PDO::FETCH_NUM);
 			if ($sg != $sgpl) echo "<tr><td style=\"background-color: rgb(255, 0, 0); color: black; text-align: center\"><img src=\"modules/Elezioni/images/alert.gif\" align=\"middle\" alt=\"\"><br><b> "._ATT_UNI." ".$sgpl." "._ATT_TOT_UNI." ".$sg."</b><br></td></tr>";
 		}
 #controllo voti a liste collegate <= voto di gruppo per voto non disgiunto
 if($genere==5 and !$disgiunto and $flagsg  and ($tipo_cons==18 or $tipo_cons==19)){
-                $resref = mysql_query("SELECT id_gruppo FROM ".$prefix."_ele_gruppo where id_cons='$id_cons'", $dbi);
+                $sql="SELECT id_gruppo FROM ".$prefix."_ele_gruppo where id_cons='$id_cons'";
+$resref = $dbi->prepare("$sql");
+$resref->execute();
+
+
 		  $errgrulis=array();
-		$res4= mysql_query("SELECT count(0) FROM ".$prefix."_ele_voti_lista where id_sez='$id_sez'", $dbi);
-		list($sezscrl)=mysql_fetch_row($res4); 
+		$sql="SELECT count(0) FROM ".$prefix."_ele_voti_lista where id_sez='$id_sez'";
+$res4 = $dbi->prepare("$sql");
+$res4->execute();
+
+
+		list($sezscrl)=$res4->fetch(PDO::FETCH_NUM); 
 		if ($sezscrl)
-                while ( list($id_gruppo)=mysql_fetch_row($resref))
+                while ( list($id_gruppo)=$resref->fetch(PDO::FETCH_NUM))
                     {
-                    $res3= mysql_query("SELECT sum(voti-solo_gruppo) FROM ".$prefix."_ele_voti_gruppo where id_sez='$id_sez' and id_gruppo='$id_gruppo'", $dbi);
-                    $res4= mysql_query("SELECT sum(voti+nulli_lista) FROM ".$prefix."_ele_voti_lista where id_sez='$id_sez' and  id_lista in (select id_lista from ".$prefix."_ele_lista where id_gruppo='$id_gruppo')", $dbi);
-                    list($vgruppo)=mysql_fetch_row($res3);
-                    list($vliste)=mysql_fetch_row($res4); 
+                    $sql="SELECT sum(voti-solo_gruppo) FROM ".$prefix."_ele_voti_gruppo where id_sez='$id_sez' and id_gruppo='$id_gruppo'";
+$res3 = $dbi->prepare("$sql");
+$res3->execute();
+
+
+                    $sql="SELECT sum(voti+nulli_lista) FROM ".$prefix."_ele_voti_lista where id_sez='$id_sez' and  id_lista in (select id_lista from ".$prefix."_ele_lista where id_gruppo='$id_gruppo')";
+$res4 = $dbi->prepare("$sql");
+$res4->execute();
+
+
+                    list($vgruppo)=$res3->fetch(PDO::FETCH_NUM);
+                    list($vliste)=$res4->fetch(PDO::FETCH_NUM); 
                     if($vliste>$vgruppo  and ($tipo_cons=18 or $tipo_cons=19))
                         {
 			    $errgrulis[$id_gruppo]=1;
-                         $result = mysql_query("SELECT descrizione FROM ".$prefix."_ele_gruppo where id_gruppo='$id_gruppo'", $dbi);
-                         list($dgruppo)=mysql_fetch_row($result);
+                         $sql="SELECT descrizione FROM ".$prefix."_ele_gruppo where id_gruppo='$id_gruppo'";
+$result = $dbi->prepare("$sql");
+$result->execute();
+
+
+                         list($dgruppo)=$result->fetch(PDO::FETCH_NUM);
                         echo "<tr><td style=\"background-color: rgb(255, 0, 0); color: black; text-align: center\"><img src=\"modules/Elezioni/images/alert.gif\" align=\"middle\" alt=\"\"><br/><b> ATTENZIONE!<BR/>I voti delle liste collegate<br/> superano i voti assegnati al gruppo $dgruppo </b><br></td></tr>";
                         }
@@ -1369,6 +1935,10 @@
                         {
 			    $errgrulis[$id_gruppo]=1;
-                         $result = mysql_query("SELECT descrizione FROM ".$prefix."_ele_gruppo where id_gruppo='$id_gruppo'", $dbi);
-                         list($dgruppo)=mysql_fetch_row($result);
+                         $sql="SELECT descrizione FROM ".$prefix."_ele_gruppo where id_gruppo='$id_gruppo'";
+$result = $dbi->prepare("$sql");
+$result->execute();
+
+
+                         list($dgruppo)=$result->fetch(PDO::FETCH_NUM);
                         echo "<tr><td style=\"background-color: rgb(255, 0, 0); color: black; text-align: center\"><img src=\"modules/Elezioni/images/alert.gif\" align=\"middle\" alt=\"\"><br/><b> ATTENZIONE!<BR/>I voti assegnati al gruppo $dgruppo <br/> superano i voti delle liste collegate</b><br></td></tr>";
                         }
@@ -1405,12 +1975,20 @@
 	}
     echo "</tr>";
-    $res = mysql_query("SELECT * FROM ".$prefix."_ele_gruppo where id_cons='$id_cons' $circo ", $dbi);
-    $max = mysql_num_rows($res);
+    $sql="SELECT * FROM ".$prefix."_ele_gruppo where id_cons='$id_cons' $circo ";
+$res = $dbi->prepare("$sql");
+$res->execute();
+
+
+    $max = $res->rowCount();
     //echo "Massimo:$max - id=$id_cons - circo: $circo";
-    $result = mysql_query("select * from ".$prefix."_ele_gruppo where id_cons='$id_cons' $circo ORDER BY num_gruppo  ", $dbi);
+    $sql="select * from ".$prefix."_ele_gruppo where id_cons='$id_cons' $circo ORDER BY num_gruppo  ";
+$result = $dbi->prepare("$sql");
+$result->execute();
+
+
     $i=1;
 	$tot_pref=0;
        $totsg=0;
-    while(list($id_cons2,$id_gruppo,$num_gruppo, $descr_gruppo, $simbolo) = mysql_fetch_row($result)){
+    while(list($id_cons2,$id_gruppo,$num_gruppo, $descr_gruppo, $simbolo) = $result->fetch(PDO::FETCH_NUM)){
   
       //echo "test: $id_cons2,$id_gruppo,$num_gruppo, $descr_gruppo, $simbolo";
@@ -1419,8 +1997,16 @@
      if ($num_gruppo != ''){
 	if ($genere==0){
-		$res = mysql_query("SELECT max(voti_complessivi) FROM ".$prefix."_ele_voti_parziale where id_cons='$id_cons' and id_sez='$id_sez' and id_gruppo='$id_gruppo' ", $dbi);
-		list($tot) = mysql_fetch_row($res);
-		$res = mysql_query("SELECT * FROM ".$prefix."_ele_voti_ref where id_cons='$id_cons' and id_sez='$id_sez' and id_gruppo='$id_gruppo' ", $dbi);
-		$pro= mysql_fetch_array($res, 3);
+		$sql="SELECT max(voti_complessivi) FROM ".$prefix."_ele_voti_parziale where id_cons='$id_cons' and id_sez='$id_sez' and id_gruppo='$id_gruppo' ";
+$res = $dbi->prepare("$sql");
+$res->execute();
+
+
+		list($tot) = $res->fetch(PDO::FETCH_NUM);
+		$sql="SELECT * FROM ".$prefix."_ele_voti_ref where id_cons='$id_cons' and id_sez='$id_sez' and id_gruppo='$id_gruppo' ";
+$res = $dbi->prepare("$sql");
+$res->execute();
+
+
+		$pro= $res->fetch(PDO::FETCH_BOTH);
 	
 		if ($pro['si']+$pro['no']!=$pro['validi'] or ($pro['validi']+$pro['nulli']+$pro['bianchi']+$pro['contestati']!=$tot and $pro['validi']+$pro['nulli']+$pro['bianchi']+$pro['contestati']!=0)){
@@ -1452,12 +2038,14 @@
 		echo "<tr style=\"background-color: $bgcolor2; text-align:center\"><td align=\"center\"><input type=\"hidden\" name=\"id_gruppo$i\" value=\"$id_gruppo\"><b>$num_gruppo</b>"
 		."</td><td align=\"left\"><b> $descr_gruppo </b>";
-		$res = mysql_query("SELECT * FROM ".$prefix."_ele_voti_gruppo where id_cons='$id_cons' and id_sez='$id_sez' and id_gruppo='$id_gruppo' ", $dbi);
-		$pro= mysql_fetch_array($res, 3);
+		$sql="SELECT * FROM ".$prefix."_ele_voti_gruppo where id_cons='$id_cons' and id_sez='$id_sez' and id_gruppo='$id_gruppo' ";
+$res = $dbi->prepare("$sql");
+$res->execute();
+
+
+		$pro= $res->fetch(PDO::FETCH_BOTH);
 		$errcolor='';
 		if(isset($errgrulis[$id_gruppo])) $errcolor="style=\"background-color: rgb(255, 0, 0);\"";
 		echo "</td><td align=\"right\" $errcolor><input  name=\"voti$i\" value=\"".$pro['voti']."\" size=\"7\"  style=\"text-align:right\"></td>";
-#		$lisgrures = mysql_query("SELECT count(id_lista) FROM ".$prefix."_ele_lista where id_cons='$id_cons' and id_gruppo='$id_gruppo'", $dbi);
-#		list($totlis) = mysql_fetch_row($lisgrures);
-#		if($totlis>1) $insinp=""; else $insinp= "type =\"hidden\" ";		
+
 		if($dettnulli) {echo "<td align=\"right\"><input name=\"solog$i\" value=\"".$pro['solo_gruppo']."\" size=\"7\"  style=\"text-align:right\"></td>"; $totsg+=$pro['solo_gruppo'];} 
 		$tot_pref += $pro['voti'];
@@ -1470,8 +2058,16 @@
    }
 	if ($genere!=0) {
-		$res = mysql_query("SELECT disgiunto FROM ".$prefix."_ele_cons_comune where id_cons='$id_cons' ", $dbi);
-		list($disgiunto)=mysql_fetch_row($res);
-		$res = mysql_query("SELECT solo_lista FROM ".$prefix."_ele_sezioni where id_sez='$id_sez' ", $dbi);
-		list($sololis)=mysql_fetch_row($res);
+		$sql="SELECT disgiunto FROM ".$prefix."_ele_cons_comune where id_cons='$id_cons' ";
+$res = $dbi->prepare("$sql");
+$res->execute();
+
+
+		list($disgiunto)=$res->fetch(PDO::FETCH_NUM);
+		$sql="SELECT solo_lista FROM ".$prefix."_ele_sezioni where id_sez='$id_sez' ";
+$res = $dbi->prepare("$sql");
+$res->execute();
+
+
+		list($sololis)=$res->fetch(PDO::FETCH_NUM);
 		echo "<tr style=\"background-color: $bgcolor1; text-align:center\"><td></td><td>"._TOTPREF."</td><td>$tot_pref</td>";
 		if($dettnulli) echo "<td>$totsg</td>";
@@ -1519,11 +2115,35 @@
 $do = intval($arg[5]);
 $y=count($arg)-1; 
-	mysql_query("delete from ".$prefix."_ele_controllosez where id_cons='$id_cons' and id_sez='$id_sez'", $dbi);
+	$sql="delete from ".$prefix."_ele_controllosez where id_cons='$id_cons' and id_sez='$id_sez'";
+$res = $dbi->prepare("$sql");
+$res->execute();
+
+
 	if($do==1) {
-			mysql_query("delete from ".$prefix."_ele_voti_gruppo where id_cons='$id_cons' and id_sez='$id_sez'", $dbi);
-			mysql_query("delete from ".$prefix."_ele_voti_lista where id_cons='$id_cons' and id_sez='$id_sez'", $dbi);
-			mysql_query("delete from ".$prefix."_ele_voti_candidati where id_cons='$id_cons' and id_sez='$id_sez'", $dbi);
-			mysql_query("delete from ".$prefix."_ele_voti_ref where id_cons='$id_cons' and id_sez='$id_sez'", $dbi);
-			mysql_query("update  ".$prefix."_ele_sezioni set validi_lista='',contestati_lista='',voti_nulli_lista='',solo_gruppo='',solo_lista='' where id_cons='$id_cons' and id_sez='$id_sez'", $dbi);
+			$sql="delete from ".$prefix."_ele_voti_gruppo where id_cons='$id_cons' and id_sez='$id_sez'";
+$res = $dbi->prepare("$sql");
+$res->execute();
+
+
+			$sql="delete from ".$prefix."_ele_voti_lista where id_cons='$id_cons' and id_sez='$id_sez'";
+$res = $dbi->prepare("$sql");
+$res->execute();
+
+
+			$sql="delete from ".$prefix."_ele_voti_candidati where id_cons='$id_cons' and id_sez='$id_sez'";
+$res = $dbi->prepare("$sql");
+$res->execute();
+
+
+			$sql="delete from ".$prefix."_ele_voti_ref where id_cons='$id_cons' and id_sez='$id_sez'";
+$res = $dbi->prepare("$sql");
+$res->execute();
+
+
+			$sql="update  ".$prefix."_ele_sezioni set validi_lista='',contestati_lista='',voti_nulli_lista='',solo_gruppo='',solo_lista='' where id_cons='$id_cons' and id_sez='$id_sez'";
+$res = $dbi->prepare("$sql");
+$res->execute();
+
+
 	
 	}else{
@@ -1534,8 +2154,16 @@
 	$tab="_ele_voti_gruppo";
 	$y--;
-	$res = mysql_query("SELECT disgiunto FROM ".$prefix."_ele_cons_comune where id_cons='$id_cons' ", $dbi);
-	list($disgiunto)=mysql_fetch_row($res);
+	$sql="SELECT disgiunto FROM ".$prefix."_ele_cons_comune where id_cons='$id_cons' ";
+$res = $dbi->prepare("$sql");
+$res->execute();
+
+
+	list($disgiunto)=$res->fetch(PDO::FETCH_NUM);
 	if($disgiunto)
-		$res=mysql_query("update  ".$prefix."_ele_sezioni set solo_lista='".$arg[$y--]."' where id_sez='$id_sez'", $dbi);
+		$sql="update  ".$prefix."_ele_sezioni set solo_lista='".$arg[$y--]."' where id_sez='$id_sez'";
+$res = $dbi->prepare("$sql");
+$res->execute();
+
+
 
 }
@@ -1571,8 +2199,16 @@
 	}
 	if($testval) continue;
-	$result = mysql_query("select * from ".$prefix."$tab where id_cons='$id_cons' and id_sez='$id_sez' and id_gruppo='$id_gruppo'", $dbi);
-	$ar=mysql_fetch_array($result);
-	$res = mysql_query("select num_gruppo from ".$prefix."_ele_gruppo where id_cons='$id_cons' and id_gruppo='$id_gruppo'", $dbi);
-	list($num_gruppo)=mysql_fetch_array($res);
+	$sql="select * from ".$prefix."$tab where id_cons='$id_cons' and id_sez='$id_sez' and id_gruppo='$id_gruppo'";
+$result = $dbi->prepare("$sql");
+$result->execute();
+
+
+	$ar=$result->fetch(PDO::FETCH_BOTH);
+	$sql="select num_gruppo from ".$prefix."_ele_gruppo where id_cons='$id_cons' and id_gruppo='$id_gruppo'";
+$res = $dbi->prepare("$sql");
+$res->execute();
+
+
+	list($num_gruppo)=$res->fetch(PDO::FETCH_NUM);
 	$oldval='';
 	if ($ar){
@@ -1593,11 +2229,27 @@
 		} 
 		if ($oldval) { 
-			mysql_query("update  ".$prefix."$tab set $riga where id_cons='$id_cons' and id_sez='$id_sez' and id_gruppo='$id_gruppo'", $dbi);
+			$sql="update  ".$prefix."$tab set $riga where id_cons='$id_cons' and id_sez='$id_sez' and id_gruppo='$id_gruppo'";
+$res = $dbi->prepare("$sql");
+$res->execute();
+
+
 			if ($fileout) fwrite($fp,"update  ".$prefix."$tab set $riga where id_cons='$id_cons' and id_sez='$id_sez' and id_gruppo='$id_gruppo';\n");
-			mysql_query("insert into ".$prefix."_ele_log values('$id_cons','$id_sez','$username','$log_data','".$log_ora['hours'].":".$log_ora['minutes'].":".$log_ora['seconds']."','$oldval','num_gruppo:$num_gruppo $riga','$tab')", $dbi);
+			$sql="insert into ".$prefix."_ele_log values('$id_cons','$id_sez','$username','$log_data','".$log_ora['hours'].":".$log_ora['minutes'].":".$log_ora['seconds']."','$oldval','num_gruppo:$num_gruppo $riga','$tab')";
+$res = $dbi->prepare("$sql");
+$res->execute();
+
+
 		}
 	} else { #die ("test in corso: insert into ".$prefix."$tab values ('$id_cons', '$id_gruppo','$id_sez',$voti)");
-		mysql_query("insert into ".$prefix."_ele_log values('$id_cons','$id_sez','$username','$log_data','".$log_ora['hours'].":".$log_ora['minutes'].":".$log_ora['seconds']."','','num_gruppo:$num_gruppo $riga','$tab')", $dbi);
-		mysql_query("insert into ".$prefix."$tab values ('$id_cons', '$id_gruppo','$id_sez',$voti $sgriga)", $dbi);
+		$sql="insert into ".$prefix."_ele_log values('$id_cons','$id_sez','$username','$log_data','".$log_ora['hours'].":".$log_ora['minutes'].":".$log_ora['seconds']."','','num_gruppo:$num_gruppo $riga','$tab')";
+$res = $dbi->prepare("$sql");
+$res->execute();
+
+
+		$sql="insert into ".$prefix."$tab values ('$id_cons', '$id_gruppo','$id_sez',$voti $sgriga)";
+$res = $dbi->prepare("$sql");
+$res->execute();
+
+
 		if ($fileout) fwrite($fp,"insert into ".$prefix."$tab values ('$id_cons', '$id_gruppo','$id_sez',$voti $sgriga);\n");
 	//
Index: trunk/admin/modules/Elezioni/foto.php
===================================================================
--- trunk/admin/modules/Elezioni/foto.php	(revision 256)
+++ trunk/admin/modules/Elezioni/foto.php	(revision 257)
@@ -29,18 +29,22 @@
 if ($id_lista){
 	$sql = "select stemma from ".$prefix."_ele_lista where id_lista=".$id_lista;
-	$res = mysql_query($sql,$dbi);
-	list($stemma) = mysql_fetch_row($res);
+	$res = $dbi->prepare("$sql");
+	$res->execute(); 
+	list($stemma) = $res->fetch(PDO::FETCH_NUM);
 }elseif ($id_gruppo){
 	$sql = "select stemma from ".$prefix."_ele_gruppo where id_gruppo=".$id_gruppo;
-	$res = mysql_query($sql,$dbi);
-	list($stemma) = mysql_fetch_row($res);
+	$res = $dbi->prepare("$sql");
+	$res->execute(); 
+	list($stemma) = $res->fetch(PDO::FETCH_NUM);
 }elseif ($id_sede){
 	$sql = "select mappa from ".$prefix."_ele_sede where id_sede=".$id_sede;
-	$res = mysql_query($sql,$dbi);
-	list($stemma) = mysql_fetch_row($res);
+	$res = $dbi->prepare("$sql");
+	$res->execute(); 
+	list($stemma) = $res->fetch(PDO::FETCH_NUM);
 }elseif ($id_comune2){
 	$sql = "select stemma from ".$prefix."_ele_comuni where id_comune=".$id_comune2;
-	$res = mysql_query($sql,$dbi);
-	list($stemma) = mysql_fetch_row($res);
+	$res = $dbi->prepare("$sql");
+	$res->execute(); 
+	list($stemma) = $res->fetch(PDO::FETCH_NUM);
 }else{
 return;
@@ -51,9 +55,10 @@
 if ($stemma==""){ 
 
-$sql = "select stemma from ".$prefix."_ele_conf where id_com='0'";
-$res = mysql_query($sql,$dbi);
-if($res)
+$sql = "select stemma from ".$prefix."_ele_comuni where id_comune='0'";
+$res = $dbi->prepare("$sql");
+$res->execute(); 
+if($res->rowCount())
 	{
-	$dati = mysql_fetch_array($res);
+	$dati = $res->fetch(PDO::FETCH_BOTH);
 	$stemma = $dati['stemma'];
 	}
Index: trunk/admin/modules/Elezioni/funzionidata.php
===================================================================
--- trunk/admin/modules/Elezioni/funzionidata.php	(revision 256)
+++ trunk/admin/modules/Elezioni/funzionidata.php	(revision 257)
@@ -95,11 +95,14 @@
 global $prefix,$dbi,$id_cons,$limite,$id_comune,$ops;
 $sqlcomu="select fascia from ".$prefix."_ele_comuni where id_comune='$id_comune'";
-$res = mysql_query($sqlcomu);
-list($fascia)=mysql_fetch_row($res);
+$res = $dbi->prepare("$sqlcomu");
+$res->execute();	
+list($fascia)=$res->fetch(PDO::FETCH_NUM);
 	#voti di lista e di gruppo completamente disgiunti 
-	$result = mysql_query("select infdisgiunto, supdisgiunto from ".$prefix."_ele_conf as t2 left join ".$prefix."_ele_cons_comune as t1 on t1.id_conf=t2.id_conf where id_cons = '$id_cons' ", $dbi);
+	$sql="select infdisgiunto, supdisgiunto from ".$prefix."_ele_conf as t2 left join ".$prefix."_ele_cons_comune as t1 on t1.id_conf=t2.id_conf where id_cons = '$id_cons' ";
+	$result = $dbi->prepare("$sql");
+	$result->execute();	
 	$glsep='';
-	if ($result) {
-		list($infdis,$supdis)=mysql_fetch_row($result);
+	if ($result->rowCount()) {
+		list($infdis,$supdis)=$result->fetch(PDO::FETCH_NUM);
 		if((($fascia>$limite and $supdis) or ($fascia<=$limite and $infdis)))
 			$glsep='_lista';
Index: trunk/admin/modules/Elezioni/importa.php
===================================================================
--- trunk/admin/modules/Elezioni/importa.php	(revision 256)
+++ trunk/admin/modules/Elezioni/importa.php	(revision 257)
@@ -42,7 +42,11 @@
 	if(isset($valori)){
 
-		$res_gruppo = mysql_query("insert into ".$prefix."_ele_gruppo values($valori)" ,$dbi)||die("(1104) Non e' stato possibile inserire i gruppi nel database! contattare l'amministratore".mysql_error());
-		$resnew = mysql_query("select id_gruppo from ".$prefix."_ele_gruppo where num_gruppo='$numgruppo' and id_cons='$idcns'" ,$dbi);
-		list ($newidg) = mysql_fetch_row($resnew);
+		$sql="insert into ".$prefix."_ele_gruppo values($valori)";
+		$res_gruppo = $dbi->prepare("$sql");
+		$res_gruppo->execute();	
+		$sql="select id_gruppo from ".$prefix."_ele_gruppo where num_gruppo='$numgruppo' and id_cons='$idcns'";
+		$resnew = $dbi->prepare("$sql");
+		$resnew->execute();	
+		list ($newidg) = $resnew->fetch(PDO::FETCH_NUM);
 		unset($valori);
 		if($oldidg)
@@ -74,7 +78,11 @@
 		if(isset($valori)){
 		if ($okl) {$okl=0;continue;}
-		$res_lista = mysql_query("insert into ".$prefix."_ele_lista values($valori)" ,$dbi)||die("(1104) Non e' stato possibile inserire le liste nel database! contattare l'amministratore".mysql_error());
-		$reslnew = mysql_query("select id_lista from ".$prefix."_ele_lista where num_lista='$numlista' and id_cons='$idcns'" ,$dbi);
-		list ($newidl) = mysql_fetch_row($reslnew);
+		$sql="insert into ".$prefix."_ele_lista values($valori)";
+		$res_lista = $dbi->prepare("$sql");
+		$res_lista->execute();	
+		$sql="select id_lista from ".$prefix."_ele_lista where num_lista='$numlista' and id_cons='$idcns'";
+		$reslnew = $dbi->prepare("$sql");
+		$reslnew->execute();	
+		list ($newidl) = $reslnew->fetch(PDO::FETCH_NUM);
 		unset($valori);
 		if($oldidl)
@@ -105,5 +113,7 @@
 			if(isset($valori)){
 				if ($okc) {$okc=0;continue;}
-				$res_lista = mysql_query("insert into ".$prefix."_ele_candidati values($valori)" ,$dbi)||die("(1104) Non e' stato possibile inserire i candidati nel database! contattare l'amministratore".mysql_error());
+				$sql="insert into ".$prefix."_ele_candidati values($valori)";
+				$res_lista = $dbi->prepare("$sql");
+				$res_lista->execute();	
 			}
 		}
@@ -115,6 +125,8 @@
 
 
-$res = mysql_query("SELECT t1.id_cons, t2.descrizione FROM ".$prefix."_ele_cons_comune as t1 left join ".$prefix."_ele_consultazione as t2 on t1.id_cons_gen=t2.id_cons_gen where t1.id_comune='$id_comune' and t2.id_cons_gen='$id_cons_gen'" , $dbi);
-list($id_cons,$descrizione) = mysql_fetch_row($res);
+$sql="SELECT t1.id_cons, t2.descrizione FROM ".$prefix."_ele_cons_comune as t1 left join ".$prefix."_ele_consultazione as t2 on t1.id_cons_gen=t2.id_cons_gen where t1.id_comune='$id_comune' and t2.id_cons_gen='$id_cons_gen'";
+$res = $dbi->prepare("$sql");
+$res->execute();	
+list($id_cons,$descrizione) = $res->fetch(PDO::FETCH_NUM);
  if (!isset($_FILES['datafile']['tmp_name']) or !is_uploaded_file($_FILES['datafile']['tmp_name'])) 
 	{
@@ -132,13 +144,31 @@
 }else{
 $idcns=$id_cons; 
-$res_del = mysql_query("delete from ".$prefix."_ele_voti_ref where id_cons=$idcns" ,$dbi);
-$res_del = mysql_query("delete from ".$prefix."_ele_voti_candidati where id_cons=$idcns" ,$dbi);
-$res_del = mysql_query("delete from ".$prefix."_ele_voti_lista where id_cons=$idcns" ,$dbi);
-$res_del = mysql_query("delete from ".$prefix."_ele_voti_gruppo where id_cons=$idcns" ,$dbi);
-$res_del = mysql_query("update ".$prefix."_ele_sezioni set validi='0', contestati='0', validi_lista='0', nulli='0',bianchi='0',contestati_lista='0', voti_nulli_lista='0'  where id_cons=$idcns" ,$dbi);
-$res_del = mysql_query("delete from ".$prefix."_ele_voti_parziale where id_cons=$idcns" ,$dbi);
-$res_del = mysql_query("delete from ".$prefix."_ele_candidati where id_cons=$idcns" ,$dbi);
-$res_del = mysql_query("delete from ".$prefix."_ele_lista where id_cons=$idcns" ,$dbi);
-$res_del = mysql_query("delete from ".$prefix."_ele_gruppo where id_cons=$idcns" ,$dbi);
+$sql="delete from ".$prefix."_ele_voti_ref where id_cons=$idcns";
+$res_del = $dbi->prepare("$sql");
+$res_del->execute();	
+$sql="delete from ".$prefix."_ele_voti_candidati where id_cons=$idcns";
+$res_del = $dbi->prepare("$sql");
+$res_del->execute();	
+$sql="delete from ".$prefix."_ele_voti_lista where id_cons=$idcns";
+$res_del = $dbi->prepare("$sql");
+$res_del->execute();	
+$sql="delete from ".$prefix."_ele_voti_gruppo where id_cons=$idcns";
+$res_del = $dbi->prepare("$sql");
+$res_del->execute();	
+$sql="update ".$prefix."_ele_sezioni set validi='0', contestati='0', validi_lista='0', nulli='0',bianchi='0',contestati_lista='0', voti_nulli_lista='0'  where id_cons=$idcns";
+$res_del = $dbi->prepare("$sql");
+$res_del->execute();	
+$sql="delete from ".$prefix."_ele_voti_parziale where id_cons=$idcns";
+$res_del = $dbi->prepare("$sql");
+$res_del->execute();	
+$sql="delete from ".$prefix."_ele_candidati where id_cons=$idcns";
+$res_del = $dbi->prepare("$sql");
+$res_del->execute();	
+$sql="delete from ".$prefix."_ele_lista where id_cons=$idcns";
+$res_del = $dbi->prepare("$sql");
+$res_del->execute();	
+$sql="delete from ".$prefix."_ele_gruppo where id_cons=$idcns";
+$res_del = $dbi->prepare("$sql");
+$res_del->execute();	
 $datafile=$_FILES['datafile']['tmp_name'];
 $arrFile = file($datafile);
Index: trunk/admin/modules/Elezioni/query.sql
===================================================================
--- trunk/admin/modules/Elezioni/query.sql	(revision 256)
+++ trunk/admin/modules/Elezioni/query.sql	(revision 257)
@@ -45,5 +45,5 @@
 	$sth = $dbi->prepare("$sql");
 	$sth->execute();	
-	$row = $sth->fetchAll();
+	$row = $sth->fetch(PDO::FETCH_BOTH);
 	return ($row);
 
@@ -78,6 +78,5 @@
 	$sth = $dbi->prepare("$sql");
 	$sth->execute();	
-	$row2 = $sth->fetchAll();
-    if ($row2) $id_cons = $row2['id_cons']; 
+    if ($sth->rowCount()) list($id_cons) = $sth->fetch(PDO::FETCH_NUM); 
 	else	$espandi=1;
 	if(!isset($tipo_cons))$tipo_cons=0;
@@ -87,6 +86,8 @@
 	$sth = $dbi->prepare("$sql");
 	$sth->execute();	
-	$row2 = $sth->fetchAll();
-	$limite=$row2[0];
+	if ($sth->rowCount()){
+		$row2 = $sth->fetchAll();
+		$limite=$row2[0];
+	}
 	return($row);
 }
@@ -187,5 +188,5 @@
 	$sth = $dbi->prepare("$sql");
 	$sth->execute();	
-	$row = $sth->fetchAll();
+	$row = $sth->fetch(PDO::FETCH_BOTH);
 	return($row);
 }
Index: trunk/admin/modules/Elezioni/restore.php
===================================================================
--- trunk/admin/modules/Elezioni/restore.php	(revision 256)
+++ trunk/admin/modules/Elezioni/restore.php	(revision 257)
@@ -95,10 +95,14 @@
 						if ($y==0) {$idcns=$valori;$y++;
 						foreach($tabs as $tbs){
-							$res_del = mysql_query("delete from $tbs where id_cons=$idcns" ,$dbi);
+							$sql="delete from $tbs where id_cons=$idcns";
+							$res_del = $dbi->prepare("$sql");
+							$res_del->execute();	
 							} 
 						}
-						if(!$res_del) die ("delete $tbs where id_cons=$idcns--- errore di cancellazione").mysql_error();
+						if(!$res_del->rowCount()) die ("delete $tbs where id_cons=$idcns--- errore di cancellazione");
 					}else $valori.= ",'".addslashes(base64_decode($val))."'";
-				$res_comune = mysql_query("insert into $tab values($valori)" ,$dbi);	
+				$sql="insert into $tab values($valori)";	
+				$res_comune = $dbi->prepare("$sql");
+				$res_comune->execute();	
 				$currentLine++;
 			}
Index: trunk/admin/modules/Elezioni/scarica.php
===================================================================
--- trunk/admin/modules/Elezioni/scarica.php	(revision 256)
+++ trunk/admin/modules/Elezioni/scarica.php	(revision 257)
@@ -13,7 +13,6 @@
 }
 
-
+global $dbi;
 $aid=$_SESSION['aid'];
-$dbi=$_SESSION['dbi'];
 $prefix=$_SESSION['prefix'];
 $currentlang=$_SESSION['lang'];
@@ -71,6 +70,8 @@
 	}elseif($fase=='2'){
 
-$res = mysql_query("SELECT descrizione from ".$prefix."_ele_consultazione WHERE id_cons_gen=$id_cons_gen2",$dbi);
-list($descrcons) = mysql_fetch_row($res);
+$sql="SELECT descrizione from ".$prefix."_ele_consultazione WHERE id_cons_gen=$id_cons_gen2";
+$res = $dbi->prepare("$sql");
+$res->execute();
+list($descrcons) = $res->fetch(PDO::FETCH_NUM);
 $rem_cons="<script type=\"text/javascript\" src=\"$indirizzoweb/file.php?fase=2&id_cons_gen2=$id_cons_gen2\"></script>";
 
@@ -79,5 +80,5 @@
 	echo "<td><b>"._INDIRIZZOWEB1."</b></td>";
 	echo "<td><input type=\"hidden\" name=\"id_cons_gen\" value=\"$id_cons_gen\"><input type=\"hidden\" name=\"op\" value=\"scarica\"><input type=\"hidden\" name=\"fase\" value=\"3\"><input type=\"hidden\" name=\"indirizzoweb\" value=\"$indirizzoweb\">$indirizzoweb</td></td></tr>";
-$cons_rem=$_GET[($id_cons_gen2)];
+$cons_rem=intval($_GET[($id_cons_gen2)]);
 echo "<tr><td><b>"._CONSULTA.":</b></td><td>$cons_rem</td></tr>";
 	echo "<tr><td><b>"._SCELTACOMUNE."</b></td><td>$rem_cons</td></tr>";
Index: trunk/admin/temi/altro/index.php
===================================================================
--- trunk/admin/temi/altro/index.php	(revision 256)
+++ trunk/admin/temi/altro/index.php	(revision 257)
@@ -13,8 +13,12 @@
 global $nometema,$id_comune,$id_cons_gen,$aid,$dbi,$prefix;
 $nometema=$tema;
-$res_com = mysql_query("SELECT descrizione FROM ".$prefix."_ele_comuni where id_comune='$id_comune'",$dbi);
-$res_cons = mysql_query("SELECT descrizione FROM ".$prefix."_ele_consultazione where id_cons_gen='$id_cons_gen'",$dbi);
-list($descr_comune) = mysql_fetch_row($res_com);
-list($descr_consultazione) = mysql_fetch_row($res_cons);
+$res_com = "SELECT descrizione FROM ".$prefix."_ele_comuni where id_comune='$id_comune'";
+$sth = $dbi->prepare("$sql");
+$sth->execute();	
+list($descr_comune) = $sth->fetch(PDO::FETCH_NUM);
+$sql="SELECT descrizione FROM ".$prefix."_ele_consultazione where id_cons_gen='$id_cons_gen'";
+$sth = $dbi->prepare("$sql");
+$sth->execute();	
+list($descr_consultazione) = $sth->fetch(PDO::FETCH_NUM);
 
 echo "<div class=\"container\"><table width=\"95%\"  border=\"0\" cellpadding=\"0\" cellspacing=\"0\" class=\"table-main\">
Index: trunk/admin/temi/facebook/index.php
===================================================================
--- trunk/admin/temi/facebook/index.php	(revision 256)
+++ trunk/admin/temi/facebook/index.php	(revision 257)
@@ -95,6 +95,9 @@
 // Blocco link
 
-$result = mysql_query("select mid, title, preamble, content,editimage from ".$prefix."_ele_link where id_cons='$id_cons' order by mid ", $dbi);
-    if (mysql_num_rows($result) == 0) {
+	$sql="select mid, title, preamble, content,editimage from ".$prefix."_ele_link where id_cons='$id_cons' order by mid";
+	$sth = $dbi->prepare("$sql");
+	$sth->execute();	
+	$row = $sth->fetchAll();
+    if ($sth->rowCount() == 0) {
 	echo "</td></tr></table>";
         echo "</div></td><td>";
@@ -103,5 +106,6 @@
     } else {
 	echo "<h5>"._LINK."</h5><p>";
-	while (list($mid, $title, $preamble,$content,  $editimage) = mysql_fetch_row($result)) {
+	foreach($row as $row2) {
+		list($mid, $title,$preamble,$content,$editimage) = explode($row2)) {
   		if ($title != "" && $content != "") {
 			$content = stripslashes($content);
Index: trunk/admin/temi/facebook/menu.php
===================================================================
--- trunk/admin/temi/facebook/menu.php	(revision 256)
+++ trunk/admin/temi/facebook/menu.php	(revision 257)
@@ -19,7 +19,9 @@
 	$button="<br /><object><noscript><div><input name=\"vai\" type=\"image\" src=\"modules/Elezioni/images/ok2.jpg\" alt=\"ok\" title=\"ok\" /></div></noscript></object>";
 	
-	$sqlcomu="select descrizione,fascia from ".$prefix."_ele_comuni where id_comune=$id_comune";
-	$rescomu= mysql_query("$sqlcomu",$dbi);
-	list($descr_com,$fascia)=mysql_fetch_row($rescomu);
+	$sql="select descrizione,fascia from ".$prefix."_ele_comuni where id_comune=$id_comune";
+	$sth = $dbi->prepare("$sql");
+	$sth->execute();	
+	$row = $sth->fetch(PDO::FETCH_BOTH);
+	list($descr_com,$fascia)=explode($row);
         echo '<style type="text/css">
 		html,body{margin:0;padding:0}
@@ -52,7 +54,9 @@
 	if ($multicomune=='1')
 	{
-	      $sqlcomu="select t1.id_comune,t1.descrizione,count(0) from ".$prefix."_ele_comuni as t1, ".$prefix."_ele_cons_comune as t2 where t1.id_comune=t2.id_comune group by t1.id_comune,t1.descrizione order by t1.descrizione asc";
-	      $rescomu= mysql_query("$sqlcomu",$dbi);
-	      $esiste_multi=mysql_num_rows($rescomu);
+	      $sql="select t1.id_comune,t1.descrizione,count(0) from ".$prefix."_ele_comuni as t1, ".$prefix."_ele_cons_comune as t2 where t1.id_comune=t2.id_comune group by t1.id_comune,t1.descrizione order by t1.descrizione asc";
+	$sth = $dbi->prepare("$sql");
+	$sth->execute();	
+	$row = $sth->fetch(PDO::FETCH_BOTH);	      
+	$esiste_multi=mysql_num_rows($rescomu);
 	      if ($esiste_multi>=1) {
 		    echo " <li>
@@ -61,5 +65,5 @@
 			  <ul>";
 			
-		      while (list($id,$descrizione,)=mysql_fetch_row($rescomu)){
+		      while (list($id,$descrizione,)=$sth->fetch(PDO::FETCH_NUM)){
 			    echo "<li><a href=\"modules.php?op=gruppo&amp;name=Elezioni&amp;id_comune=$id&amp;file=index\">$descrizione</a></li>";
 			}
@@ -75,6 +79,8 @@
 	***********************************/
        
-	$res = mysql_query("SELECT t1.id_cons_gen,t1.descrizione FROM ".$prefix."_ele_consultazione as t1, ".$prefix."_ele_cons_comune as t2 where t1.id_cons_gen=t2.id_cons_gen and t2.id_comune='$id_comune' and t2.chiusa!='2' order by t1.data_fine desc" , $dbi); 
-	$esiste=mysql_num_rows($res);
+	$sql = "SELECT t1.id_cons_gen,t1.descrizione FROM ".$prefix."_ele_consultazione as t1, ".$prefix."_ele_cons_comune as t2 where t1.id_cons_gen=t2.id_cons_gen and t2.id_comune='$id_comune' and t2.chiusa!='2' order by t1.data_fine desc"; 
+	$sth = $dbi->prepare("$sql");
+	$sth->execute();	
+	$esiste=$sth->rowCount();
 	//se esiste consultazione fa vedere i dati
 	if ($esiste>=1) {
@@ -83,5 +89,5 @@
 	    <ul>";
 	 
-	    while(list($id,$descrizione) = mysql_fetch_row($res)) {
+	    while(list($id,$descrizione) = $sth->fetch(PDO::FETCH_NUM)) {
 		echo "<li><a href=\"modules.php?op=gruppo&amp;name=Elezioni&amp;id_comune=$id_comune&amp;file=index&amp;id_cons_gen=$id\">
 	      ".substr($descrizione,0,31)."</a></li>";
@@ -124,5 +130,8 @@
 
  	$res = mysql_query("SELECT count(0) FROM ".$prefix."_ele_circoscrizione where id_cons='$id_cons' ", $dbi);
-	list($num_circ) = mysql_fetch_row($res);
+	$sql = "SELECT count(0) FROM ".$prefix."_ele_circoscrizione where id_cons='$id_cons'"; 
+	$sth = $dbi->prepare("$sql");
+	$sth->execute();	
+	list($num_circ) = $sth->fetch(PDO::FETCH_NUM);
        	 echo " <li><a href=\"#\"><strong>"._RISULTATI."</strong></a>
 	    <ul>";
