Index: trunk/admin/admin.php
===================================================================
--- trunk/admin/admin.php	(revision 257)
+++ trunk/admin/admin.php	(revision 258)
@@ -144,5 +144,4 @@
 	    echo $sql . "<br>" . $e->getMessage();
 	}                                                                                       	
-
 
 
@@ -163,5 +162,5 @@
 	$_SESSION['startdate']=$row['startdate'];
 	$_SESSION['adminmail']=$row['adminmail'];
-	if ($tema=='facebook')
+	if (isset($tema) and $tema=='facebook')
 		$_SESSION['tema']=$row['tema'];
 	else $_SESSION['tema']='default';
@@ -561,4 +560,5 @@
     break;
 }
+
 }else {
 
Index: trunk/admin/header.php
===================================================================
--- trunk/admin/header.php	(revision 257)
+++ trunk/admin/header.php	(revision 258)
@@ -30,5 +30,6 @@
 function head() {
 	global $csv,$tema;
-    echo "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n";
+ #   echo "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n";
+    echo "<!DOCTYPE HTML>\n";
     echo "<html>\n";
     echo "<head>\n";
Index: trunk/admin/modules/Elezioni/controllo_votanti.php
===================================================================
--- trunk/admin/modules/Elezioni/controllo_votanti.php	(revision 257)
+++ trunk/admin/modules/Elezioni/controllo_votanti.php	(revision 258)
@@ -16,5 +16,5 @@
 
 $aid=$_SESSION['aid'];
-$dbi=$_SESSION['dbi'];
+global $dbi;
 $prefix=$_SESSION['prefix'];
 $currentlang=$_SESSION['lang'];
@@ -79,5 +79,5 @@
 	}
 	$i=1;
-	$sql"SELECT num_sez,id_sez,t1.id_sede, t2.id_circ,maschi,femmine,(maschi+femmine) as elettori FROM ".$prefix."_ele_sezioni as t1, ".$prefix."_ele_sede as t2 where t1.id_cons='$id_cons' and t1.id_sede=t2.id_sede order by num_sez";
+	$sql="SELECT num_sez,id_sez,t1.id_sede, t2.id_circ,maschi,femmine,(maschi+femmine) as elettori FROM ".$prefix."_ele_sezioni as t1, ".$prefix."_ele_sede as t2 where t1.id_cons='$id_cons' and t1.id_sede=t2.id_sede order by num_sez";
 	$sth = $dbi->prepare("$sql");
 	$sth->execute();
Index: trunk/admin/modules/Elezioni/controllo_voti.php
===================================================================
--- trunk/admin/modules/Elezioni/controllo_voti.php	(revision 257)
+++ trunk/admin/modules/Elezioni/controllo_voti.php	(revision 258)
@@ -16,5 +16,5 @@
 
 $aid=$_SESSION['aid'];
-$dbi=$_SESSION['dbi'];
+global $dbi;
 $prefix=$_SESSION['prefix'];
 $currentlang=$_SESSION['lang'];
@@ -29,11 +29,10 @@
 	$sth = $dbi->prepare("$sql");
 	$sth->execute();	
-	$row = $sth->fetch(PDO::FETCH_BOTH);
-	list($tipo_cons,$id_cons,$dettnulli,$disgiunto) = explode($row);
+	list($tipo_cons,$id_cons,$dettnulli,$disgiunto) = $sth->fetch(PDO::FETCH_BOTH);
 	$sql="SELECT genere,voto_g,voto_l FROM ".$prefix."_ele_tipo where tipo_cons='$tipo_cons'";
 	$sth = $dbi->prepare("$sql");
 	$sth->execute();	
-	$row = $sth->fetch(PDO::FETCH_BOTH);
-	list($genere,$votog,$votol) = explode($row);
+	$row = 
+	list($genere,$votog,$votol) = $sth->fetch(PDO::FETCH_NUM);
 include("modules/Elezioni/funzionidata.php");
 include("modules/Elezioni/ele.php");
@@ -52,6 +51,6 @@
 	$sth = $dbi->prepare("$sql");
 	$sth->execute();	
-	$row = $sth->fetch(PDO::FETCH_BOTH);
-	list($totm,$totf) =  explode($row);
+#	$row = $sth->fetch(PDO::FETCH_BOTH);
+	list($totm,$totf) =  $sth->fetch(PDO::FETCH_NUM);
 	$totel=$totm+$totf;
 	if (!IsSet($pag)) {$pag=0;} //inizializza il numero di pagina 
@@ -61,6 +60,6 @@
 		$sth = $dbi->prepare("$sql");
 		$sth->execute();	
-		$row = $sth->fetch(PDO::FETCH_BOTH);
 		$num_refs= $sth->rowCount(); //quante pagine?
+#		$row = $sth->fetch(PDO::FETCH_BOTH);
 	}
 	if((($genere!=4) and $pag==0 and !$votog) or $genere==1 or $genere==2){ //diverso da liste a piu' candidati
@@ -73,12 +72,14 @@
 		$sth = $dbi->prepare("$sql");
 		$sth->execute();	
-		$row = $sth->fetch(PDO::FETCH_BOTH);
-		list($idg,$numg) = explode($row);
+#		$row = $sth->fetch(PDO::FETCH_BOTH);
+		list($idg,$numg) = $sth->fetch(PDO::FETCH_BOTH);
 		$sql="SELECT id_sez,num_sez,t1.id_sede as id_sede,t2.id_circ as id_circ FROM ".$prefix."_ele_sezioni as t1,".$prefix."_ele_sede as t2 where t1.id_cons='$id_cons' and t1.id_sede=t2.id_sede order by num_sez";
 		$sth = $dbi->prepare("$sql");
 		$sth->execute();
 		$num_sez = $sth->rowCount();  //quante sezioni?
+		$sezione=array();
 for ($i=1;$i<=$num_sez;$i++){
-		$sezione[$i]== $sth->fetch(PDO::FETCH_BOTH); //inizializza l'array delle sezioni
+		$sezione[$i]=array();
+		$sezione[$i]= $sth->fetch(PDO::FETCH_BOTH); //inizializza l'array delle sezioni
 		$ar[$i]=0;
 	}
@@ -127,7 +128,6 @@
 //	if ($genere>1 and $pag==1) $ops=3;
 	$tot_u=0;$tot_d=0;$tot_voti=0; $tot_si=0;$tot_no=0;$tot_validi=0;$tot_nulli=0;$tot_bianchi=0;$tot_contestati=0;$tgrup_pref=0;$tot_voti_nulli=0;$tot_val_lista=0;$tot_vot_nul_lis=0;$tot_cont_lis=0;$tot_solog=0;$tot_solol=0;$errors=0;
-	while (	$row = $sth->fetch(PDO::FETCH_BOTH)){
+	while (	list($id_gruppo,$id,$num,$si,$no,$validi,$nulli,$bianchi,$contestati,$id_circ,$id_sede,$gruppo,$voti_nulli,$val_lista,$vot_nul_lis,$cont_lis,$solog,$solol) = $sth->fetch(PDO::FETCH_NUM)){
 //controllare
-	list($id_gruppo,$id,$num,$si,$no,$validi,$nulli,$bianchi,$contestati,$id_circ,$id_sede,$gruppo,$voti_nulli,$val_lista,$vot_nul_lis,$cont_lis,$solog,$solol) = explode($row);
 	// inserimento numeri di sez non scrutinate
 		while ($scrutinate < $num) { 
@@ -141,6 +141,5 @@
 			$sth2 = $dbi->prepare("$sql");
 			$sth2->execute();	
-			$row2 = $sth2->fetch(PDO::FETCH_BOTH);
-			list ($gruppref) = explode($row2);
+			list ($gruppref) = $sth2->fetch(PDO::FETCH_NUM);
 			$tgrup_pref += $gruppref;
 		}
@@ -149,6 +148,5 @@
 			$sth2 = $dbi->prepare("$tab2");
 			$sth2->execute();	
-			$row2 = $sth2->fetch(PDO::FETCH_BOTH);
-			list($votid,$votiu,$voti) = explode($row2);
+			list($votid,$votiu,$voti) = $sth2->fetch(PDO::FETCH_NUM);
 //		$voti=$votiu+$votid;
 		
@@ -185,6 +183,5 @@
 			$sth2 = $dbi->prepare("select stato_lis from ".$prefix."_ele_controllosez where id_cons='$id_cons' and id_sez='$id'");
 			$sth2->execute();	
-			$row2 = $sth2->fetch(PDO::FETCH_BOTH);
-			list($crlis) = explode($row2);
+			list($crlis) = $sth2->fetch(PDO::FETCH_NUM);
 
 		if ($voti==$controllo1 and $validi==$controllo2 and !$g_err and $crlis!=-1){
Index: trunk/admin/modules/Elezioni/ele.php
===================================================================
--- trunk/admin/modules/Elezioni/ele.php	(revision 257)
+++ trunk/admin/modules/Elezioni/ele.php	(revision 258)
@@ -59,4 +59,5 @@
 	
 	include ("header.php");
+#	include("modules/Elezioni/testa.php");
         //immagine bullet
         $bullet="<img src=\"temi/$tema/images/bullet.gif\" alt =\" \" align=\"left\" border=\"0\">";
@@ -291,5 +292,5 @@
 		ele();
 		global $language;
-		include("language/$language/ele.html");
+		include("language/$currentlang/ele.html");
 		echo"</td></tr></table>";
 		include("footer.php");
Index: trunk/admin/modules/Elezioni/ele_associazioni.php
===================================================================
--- trunk/admin/modules/Elezioni/ele_associazioni.php	(revision 257)
+++ trunk/admin/modules/Elezioni/ele_associazioni.php	(revision 258)
@@ -252,5 +252,5 @@
 	echo "</td></tr></table></form>";
 	echo "<hr><br><table width=\"100%\" border=\"3\">";
-	echo "<tr align=\"center\"><td width=\"15%\" bgcolor=\"$bgcolor1\"><b>"._CONSULTA."TEST:$id_cons_comu</b></td>";
+	echo "<tr align=\"center\"><td width=\"15%\" bgcolor=\"$bgcolor1\"><b>"._CONSULTA."</b></td>";
 	echo "<td width=\"20%\" bgcolor=\"$bgcolor1\"><b>"._DEFCOMUNE."</b></td>";
 	echo "<td width=\"10%\" bgcolor=\"$bgcolor1\"><b>"._PREFERENZE."</b></td>";
@@ -325,5 +325,5 @@
 	$delcons=0;
 	if ($do !="" and $id_cons_gen>0 and $idcomunenew>0) {
-		$sql="SELECT id_cons from ".$prefix."_ele_cons_comune where id_cons_gen='$id_cons_gen' and id_comune='$idcomunenew'"; 
+		$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();	
@@ -351,8 +351,7 @@
 			if ($idcomunenew>0) $newid=", id_comune = $idcomunenew ";
 			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());
-			$result = $dbi->prepare("$sql");
-			$result->execute();	
-			if (!$result->rowCount()) return;
+			$sql="update ".$prefix."_ele_comu_collegi set id_collegio= '$id_collegio' $newid where id_comune='$id_comune' and id_cons_gen='$id_cons_gen'";
+			$result = $dbi->prepare("$sql");
+			$result->execute();	
 			$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");
Index: trunk/admin/modules/Elezioni/ele_candidato.php
===================================================================
--- trunk/admin/modules/Elezioni/ele_candidato.php	(revision 257)
+++ trunk/admin/modules/Elezioni/ele_candidato.php	(revision 258)
@@ -61,5 +61,5 @@
 
 function all() {
-	global $param, $bgcolor1, $bgcolor2, $prefix, $dbi, $offset, $min, $tipo_cons, $id_cons,$tipo_cons,$id_lista,$genere,$id_cons_gen,$id_comune,$id_cand,$id_circ,$id_gruppo;
+	global $do, $param, $bgcolor1, $bgcolor2, $prefix, $dbi, $offset, $min, $tipo_cons, $id_cons,$tipo_cons,$id_lista,$genere,$id_cons_gen,$id_comune,$id_cand,$id_circ,$id_gruppo;
 #patch per bloccare il submit se non e' stata scelta la lista. Proposta da margottid	
 echo "<script language=\"Javascript\">\n
@@ -157,5 +157,4 @@
 		$result = $dbi->prepare("$query");
 		$result->execute();
-#		list($id_lista)=$result->fetch(PDO::FETCH_NUM);
 	if($cons_circ)
 		$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 ";
@@ -164,5 +163,5 @@
 	$sth = $dbi->prepare("$sql");
 	$sth->execute();
-	list($max) = $sth->rowCount();
+	list($max) = $sth->fetch(PDO::FETCH_NUM);
 	if($id_lista){
 		$numero=$max+1;} else $numero='';
@@ -290,5 +289,4 @@
 				$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");
 			}
@@ -315,6 +313,5 @@
 				$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");
+				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");
 			} else {
 				ele();
@@ -341,6 +338,5 @@
 		$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");
+		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");
 	}
 
@@ -349,9 +345,8 @@
 
 
-echo "qui si if ($do and $do!='modify')";
-if ($do and $do!='modify'){ele();
+if ($do and $do!='modify'){
     candidato($ok, $do,$id_cand, $id_lista,$id_circ, $id_gruppo,$cognome, $nome, $note, $simbolo,$id_cand2,$num_cand);
 	} else { ele(); }
-//if (!$do)ele();
+
 all();
 echo"</td></tr></table>";
Index: trunk/admin/modules/Elezioni/ele_colora_sez.php
===================================================================
--- trunk/admin/modules/Elezioni/ele_colora_sez.php	(revision 258)
+++ trunk/admin/modules/Elezioni/ele_colora_sez.php	(revision 258)
@@ -0,0 +1,85 @@
+<?php
+if (!isset($_SESSION['aid'])) die ("You can't access this file directly..."); 
+global $id_cons,$id_circ,$id_sez,$dbi,$prefix;
+
+$sql="select status from ".$prefix."_ele_controllosez where id_cons='$id_cons' and id_sez='$id_sez'";
+$resc = $dbi->prepare("$sql");
+$resc->execute(); 
+list($stato)=$resc->fetch(PDO::FETCH_NUM);
+$sezstat=0;
+if($stato) {
+	$sezstat=1;
+	$sql="UPDATE ".$prefix."_ele_sezioni set colore='style=\" background: #FF3300;' where id_cons='$id_cons' and id_sez='$id_sez'"; #ROSSO
+	$res = $dbi->prepare("$sql");
+	$res->execute();	
+	}
+	
+elseif(!$sezstat){ #candidati
+	$sql="SELECT t2.id_lista 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' group by t2.id_lista";
+	$res = $dbi->prepare("$sql");
+	$res->execute();
+	$liste=$res->rowCount();
+	
+	$sql="SELECT count(id_lista) FROM ".$prefix."_ele_lista where id_cons='$id_cons'";
+	$res = $dbi->prepare("$sql");
+	$res->execute();
+	if($liste && $liste==$res->rowCount()){
+		$sezstat=2;
+		$sql="UPDATE ".$prefix."_ele_sezioni set colore='style=\" background: #99CC33;' where id_cons='$id_cons' and id_sez='$id_sez'"; #VERDE
+		$res = $dbi->prepare("$sql");
+		$res->execute();		
+	}
+	if(!$sezstat) { #liste
+		$sql="SELECT id_lista FROM ".$prefix."_ele_voti_lista where id_cons='$id_cons' and id_sez='$id_sez'";
+		$res = $dbi->prepare("$sql");
+		$res->execute();
+		if($res->rowCount()>0){
+			$sezstat=3;
+			$sql="UPDATE ".$prefix."_ele_sezioni set colore='style=\" background: #99CC33;' where id_cons='$id_cons' and id_sez='$id_sez'"; #VERDE
+			$res = $dbi->prepare("$sql");
+			$res->execute();
+		}elseif(!$sezstat){ #gruppi
+			$sql="SELECT id_gruppo FROM ".$prefix."_ele_voti_gruppo where id_cons='$id_cons' and id_sez='$id_sez'";
+			$res = $dbi->prepare("$sql");
+			$res->execute();
+			$righe=$res->rowCount();
+			if($righe){ 
+				$sezstat=4;
+				$sql="UPDATE ".$prefix."_ele_sezioni set colore='style=\" background: #F5F5F5;' where id_cons='$id_cons' and id_sez='$id_sez'"; #whitesmoke
+				$res = $dbi->prepare("$sql");
+				$res->execute();
+			}elseif(!$sezstat){ #voti
+				$sql="SELECT validi+nulli+bianchi+contestati as voti FROM ".$prefix."_ele_sezioni where id_cons='$id_cons' and id_sez='$id_sez'";
+				$res = $dbi->prepare("$sql");
+				$res->execute();
+				list($voti)=$res->fetch(PDO::FETCH_NUM);
+				if($voti) {
+					$sezstat=5;
+					$sql="UPDATE ".$prefix."_ele_sezioni set colore='style=\" background: #F5F5F5;' where id_cons='$id_cons' and id_sez'=$id_sez'"; #whitesmoke
+					$res = $dbi->prepare("$sql");
+					$res->execute(); 
+				}elseif(!$sezstat) {
+					$sql="SELECT count(0) FROM ".$prefix."_ele_voti_parziale where id_cons='$id_cons' and id_sez='$id_sez'";
+					$res = $dbi->prepare("$sql");
+					$res->execute();
+					list($righe)=$res->fetch(PDO::FETCH_NUM);
+					$num_ril=$righe % 4;
+					
+					if($num_ril==0) {$cursez="style=\" background: #7FFFD4;";}#aquamarine
+					elseif($num_ril==1) {$cursez="style=\" background: #ADD8E6;";}#lightblue
+					elseif($num_ril==2) {$cursez="style=\" background: #DCDCDC;";}#gainsboro 
+					elseif($num_ril==3) {$cursez="style=\" background: #E0FFFF;";}#lightcyan 
+					$sql="UPDATE ".$prefix."_ele_sezioni set colore='$cursez' where id_cons='$id_cons' and id_sez='$id_sez'";
+					$res = $dbi->prepare("$sql");
+					$res->execute(); 
+							
+						
+					
+				}
+			}
+		}
+	}
+}
+
+
+?>
Index: trunk/admin/modules/Elezioni/ele_cons_comuni.php
===================================================================
--- trunk/admin/modules/Elezioni/ele_cons_comuni.php	(revision 257)
+++ trunk/admin/modules/Elezioni/ele_cons_comuni.php	(revision 258)
@@ -161,7 +161,7 @@
 		if ($id_cons2) {
 			// copia circoscrizione
-			$res=mysql_query("select * from ".$prefix."_ele_circoscrizione where id_cons='$id_consulta'", $dbi);
+			$sql="select * from ".$prefix."_ele_circoscrizione where id_cons='$id_consulta'";
 			$res = $dbi->prepare("$sql");
-			$res->execute();	
+			$res->execute();				
 			while (list($id,$idcirc,$num,$des2)=$res->fetch(PDO::FETCH_NUM)){
 			$des=addslashes($des2);
@@ -188,5 +188,5 @@
 					$ind=addslashes($ind2);
 					$sql="select count(0) from ".$prefix."_ele_sede where id_cons='$id_cons2' and indirizzo='$ind'";
-					$resswdnew = $dbi->prepare("$sql");
+					$ressednew = $dbi->prepare("$sql");
 					$ressednew->execute();	
 					list($contr_sed)=$ressednew->fetch(PDO::FETCH_NUM);
Index: trunk/admin/modules/Elezioni/ele_lista.php
===================================================================
--- trunk/admin/modules/Elezioni/ele_lista.php	(revision 257)
+++ trunk/admin/modules/Elezioni/ele_lista.php	(revision 258)
@@ -231,5 +231,4 @@
 			$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");
 		}
@@ -252,5 +251,4 @@
 			$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 {
@@ -278,5 +276,4 @@
 		$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_riepilogo.php
===================================================================
--- trunk/admin/modules/Elezioni/ele_riepilogo.php	(revision 257)
+++ trunk/admin/modules/Elezioni/ele_riepilogo.php	(revision 258)
@@ -81,5 +81,5 @@
 	$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);
+		$sql="SELECT num_gruppo,descrizione from ".$prefix."_ele_gruppo where id_gruppo='$idg'";
 		$resref = $dbi->prepare("$sql");
 		$resref->execute();	
Index: trunk/admin/modules/Elezioni/ele_sede.php
===================================================================
--- trunk/admin/modules/Elezioni/ele_sede.php	(revision 257)
+++ trunk/admin/modules/Elezioni/ele_sede.php	(revision 258)
@@ -86,5 +86,5 @@
 		echo "<td align=\"right\"><select name=\"id_circ\">";
 		$sql= "SELECT id_circ,descrizione FROM ".$prefix."_ele_circoscrizione where id_cons='$id_cons' order by num_circ";
-		$res = $dbi->prepare("$sql");
+		$res = $dbi->prepare("$sql");echo $sql;
 		$res->execute();				
 		while(list($id,$descr) = $res->fetch(PDO::FETCH_NUM)) {
Index: trunk/admin/modules/Elezioni/ele_voti.php
===================================================================
--- trunk/admin/modules/Elezioni/ele_voti.php	(revision 257)
+++ trunk/admin/modules/Elezioni/ele_voti.php	(revision 258)
@@ -264,5 +264,5 @@
 
 		if($res3->rowCount() and !$votog){#$status=0;$ops=-4;
-			list($votigs,$votisolog) = m$res3->fetch(PDO::FETCH_NUM);
+			list($votigs,$votisolog) = $res3->fetch(PDO::FETCH_NUM);
 			if($votigs  and $genere!=2) {  
 				#	$status=0;
@@ -319,5 +319,5 @@
 
 
-								$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')";
+								$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();
@@ -449,5 +449,5 @@
 			}
 		}
-		$sql="SELECT num_sez, id_sez ,id_sede FROM ".$prefix."_ele_sezioni where id_cons='$id_cons' $solosede order by num_sez";
+		$sql="SELECT num_sez, id_sez ,id_sede,colore FROM ".$prefix."_ele_sezioni where id_cons='$id_cons' $solosede order by num_sez";
 $res = $dbi->prepare("$sql");
 $res->execute();
@@ -461,9 +461,9 @@
 
 		echo "<div id=\"navmenu\"> <ul>";
-		while(list($sez_num, $sez_id ,$sede_id) = $res->fetch(PDO::FETCH_NUM)) {
+		while(list($sez_num, $sez_id ,$sede_id,$cursez) = $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' ";
+			$sql="SELECT id_circ FROM ".$prefix."_ele_sede where id_cons='$id_cons' and id_sede='$sede_id' ";
 $result = $dbi->prepare("$sql");
 $result->execute();
@@ -471,4 +471,5 @@
 
 			list($circ_id) = $result->fetch(PDO::FETCH_NUM);
+			/*
 			//colora la sezione
 			$sezstat=0; #die($ops);
@@ -507,5 +508,5 @@
 							
 			if ($sezstat) $ops=abs($sezstat); else $ops=1;
-			
+			*/
 			if(!$ops) $ops=1;
 			$sql="SELECT num_sez FROM ".$prefix."_ele_sezioni where id_sez='$id_sez'";
@@ -515,5 +516,5 @@
 
 			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.="\"";
+			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";
 		}
@@ -650,5 +651,5 @@
      		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>";
+                echo "<hr><table><tr><td  width=\"200\"><font size =\"4\" color=\"black\" align=\"left\"><b>Sezione N. $num_sez</b></font></td><td><table><tr>";
                 echo "\n<td bgcolor=\"$bgcolor1\" align=\"center\"><p style=\"margin-left:10px;margin-right:10px;\"><b><a href=\"admin.php?op=voti&amp;id_cons_gen=$id_cons_gen&amp;id_sez=$id_sez&amp;id_circ=$id_circ&amp;id_sede=$id_sede&amp;do=spoglio&amp;ops=1\">"._AFFLUENZE."</a></b></p></td>\n";
                 if(!($genere==4) and !($votog)){ //if(!($genere==4) and !($tipo_cons==10 or $tipo_cons==11)){
@@ -768,5 +769,5 @@
 }
 #######    
-if(!$votog and ($genere==3 or $genere==5))
+if(!$votog and ($genere==3 or $genere==5)){
 	$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");
@@ -774,9 +775,9 @@
 
 
-else
+}else{
 	$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);
@@ -799,5 +800,5 @@
 			}
 			echo "<td>&nbsp;</td></tr><tr><td style=\"vertical-align: top;\">";
-			echo "<form name=\"liste\" action=\"admin.php\">";
+			echo "<form name=\"liste\" action=\"modules/Elezioni/salva_liste.php\">";
 			echo "<input type=\"hidden\" name=\"pag\" value=\"admin.php?op=voti&amp;id_cons_gen=$id_cons_gen&amp;id_sez=$id_sez&amp;id_circ=$id_circ&amp;id_sede=$id_sede&amp;do=spoglio&amp;ops=3&amp;id_lista=\">";
 			echo "<select name=\"id_lista\" size=\"".($num_liste+1)."\" onChange=\"vai_lista()\">";
@@ -825,23 +826,16 @@
 
 			list($votisezcand)=$result->fetch(PDO::FETCH_NUM);
-			if((($fascia>$limite or $disgiunto) or !$id_conf) or $genere==4)
+			if((($fascia>$limite or $disgiunto) or !$id_conf) or $genere==4){
                 $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{
-
+            }else{
 				$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)=$result->fetch(PDO::FETCH_NUM);
@@ -871,5 +865,5 @@
 
 		if ((!$id_lista)){$tab="_ele_voti_lista";} else {$tab="_ele_voti_candidati";}
-if(($genere==4 or ($genere==5 and $votog)) and !$id_lista)	
+if(($genere==4 or ($genere==5 and $votog)) and !$id_lista)	{
 		$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");
@@ -877,9 +871,9 @@
 
 
-else
+}else{
 		$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		
@@ -917,5 +911,5 @@
 
 			list($votisezcand)=$result->fetch(PDO::FETCH_NUM);
-			if(($fascia>$limite or $disgiunto) or !$id_conf)
+			if(($fascia>$limite or $disgiunto) or !$id_conf){
                  $sql="SELECT sum(voti) from ".$prefix."_ele_voti_lista where id_sez='$id_sez' and id_lista='$id_lista'";
 $result = $dbi->prepare("$sql");
@@ -923,5 +917,5 @@
 
 
-            else{
+            }else{
 
 				$sql="SELECT id_gruppo from ".$prefix."_ele_lista where id_lista='$id_lista'";
@@ -951,5 +945,5 @@
 
 
-		$res4= mysql_query("SELECT count(0) FROM ".$prefix."_ele_voti_lista where id_sez='$id_sez'";
+		$sql="SELECT count(0) FROM ".$prefix."_ele_voti_lista where id_sez='$id_sez'";
 $res4 = $dbi->prepare("$sql");
 $res4->execute();
@@ -1000,7 +994,8 @@
 
 
-		echo "\n<form name=\"sezioni\" action=\"admin.php\">"
+		echo "\n<form name=\"sezioni\" action=\"modules/Elezioni/salva_liste.php\">"
 		."<input type=\"hidden\" name=\"op\" value=\"rec_voti\">"
 		."<input type=\"hidden\" name=\"id_cons_gen\" value=\"$id_cons_gen\">"
+		."<input type=\"hidden\" name=\"id_cons\" value=\"$id_cons\">"
 		."<input type=\"hidden\" name=\"id_sez\" value=\"$id_sez\">"
 		."<input type=\"hidden\" name=\"id_circ\" value=\"$id_circ\">"
@@ -1066,18 +1061,18 @@
 				."<td align=\"left\"><b>$cognome $nome</b></td>";
 				$cond_sele="and id_cand=$id_cand";
-				$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);
+				$sql="SELECT voti FROM ".$prefix."$tab where id_cons='$id_cons' and id_sez='$id_sez' $cond_sele";
+$res = $dbi->prepare("$sql");
+$res->execute();
+
+
+				list($voti)= $res->fetch(PDO::FETCH_NUM);
 				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\">";
+				echo "<td align=\"right\" $errcolor><input  name=\"voti$i\" value=\"".$voti."\" size=\"7\"  style=\"text-align:right\">";
 				echo "<input type=\"hidden\" name=\"id_cand$i\" value=\"$id_cand\"></td></tr>\n";
 				$i++;
-				$tot_pref+=$pro['voti'];
+				$tot_pref+=$voti;
 			} 
 		}else {
-			$sql="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,t1.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' 
@@ -1085,11 +1080,18 @@
 			and t2.id_sez=$id_sez
 			order by t1.num_lista";
-$result1 = $dbi->prepare("$sql");
-$result1->execute();
-
+
+	try {
+		$result1 = $dbi->prepare("$sql");
+		$result1->execute();
+
+	}
+		catch(PDOException $e)
+		{
+			echo $sql . "<br>" . $e->getMessage();
+		}                  
 
 			$num_lista=$result1->rowCount();
 			if (!$num_lista){
-				$sql="select '',id_lista, descrizione,simbolo,num_lista,'','',id_gruppo
+				$sql="select '0',id_lista, descrizione,simbolo,num_lista,'','',id_gruppo
 				from ".$prefix."_ele_lista where id_cons='$id_cons' $circo
 				order by num_lista";
@@ -1099,5 +1101,5 @@
 
 			}
-			while (list($pro['voti'],$id_lista3,$descr_lista,$simb_lista,$num_lista,$vnpl,$slpl,$rifgruppo)=$result1->fetch(PDO::FETCH_NUM)){
+			while (list($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){
@@ -1108,5 +1110,5 @@
 				."<td align=\"left\"><b> $descr_lista</b></td>";
 				$cond_sele="and id_lista=$id_lista3";
-				echo "<td align=\"right\" $errcolor><input  name=\"voti$i\" value=\"".$pro['voti']."\" size=\"7\"  style=\"text-align:right\">";
+				echo "<td align=\"right\" $errcolor><input  name=\"voti$i\" value=\"".$voti."\" size=\"7\"  style=\"text-align:right\">";
 				if($dettnulli && !$disgiunto  && $tipo_cons!=18 && $tipo_cons!=19) echo "</td><td align=\"right\"><input  name=\"vnpl$i\" value=\"".$vnpl."\" size=\"7\"  style=\"text-align:right\">";
 				if($disgiunto) echo "</td><td align=\"right\"><input  name=\"slpl$i\" value=\"".$slpl."\" size=\"7\"  style=\"text-align:right\">";
@@ -1115,5 +1117,5 @@
 				echo "</tr>\n";
 				$i++;
-				$tot_pref+=$pro['voti'];
+				$tot_pref+=$voti;
 			}
 		}
@@ -1154,9 +1156,9 @@
 		echo "<td></td><td></td>";
 		echo "<td align=\"center\"><input type=\"submit\" id=\"update\" name=\"update\" value=\""._OK."\"></td>";
-		echo "</tr></table></form></tr>";
+		echo "</tr></table>";
 		if(chisei($id_cons_gen)>=64){
-			echo "<td></td><td> <input type=\"checkbox\" id=\"pwd3\" name=\"pwd3\" value=\"\" onclick=\"javascript:del_dati()\">"._DELETE."</td>";
-		}
-		echo "</table>";
+			echo "<td></td><td> <input type=\"checkbox\" id=\"pwd3\" name=\"pwd3\" value=\"1\">"._DELETE."</td>";
+		} # onclick=\"javascript:del_dati()\"
+		echo "</form></tr></table>";
 		echo "<SCRIPT type=\"text/javascript\">\n\n<!--\n"
 		."document.sezioni.voti1.focus()\n"
@@ -1179,6 +1181,5 @@
 	global $prefix, $dbi,$aid,$id_cons,$ops,$genere,$votog,$fileout,$id_comune,$limite,$update,$dettnulli,$disgiunto,$tipo_cons;
 	
-	$sqlcomu="select id_fascia,id_conf from ".$prefix."_ele_cons_comune where id_cons='$id_cons'";
-	$sql=$sqlcomu);
+	$sql="select id_fascia,id_conf from ".$prefix."_ele_cons_comune where id_cons='$id_cons'";
 	if($res)
 		list($fascia,$id_conf)=$res->fetch(PDO::FETCH_NUM);
@@ -1190,5 +1191,5 @@
 	$orario=($log_ora['hours'].":".$log_ora['minutes'].":".$log_ora['seconds']);
 	$arg2 = func_get_args();
-	$arg = split(",",$arg2[0]);
+	$arg = preg_split("/\,+/",$arg2[0]);
 	$id_cons_gen=intval($arg[1]);
 	$id_sez = intval($arg[2]);
@@ -1302,5 +1303,5 @@
 
 
-					if($valista) 
+					if($valista) {
 						$sql="update  ".$prefix."_ele_sezioni set validi_lista='$valista' where id_sez='$id_sez'";
 $res = $dbi->prepare("$sql");
@@ -1308,8 +1309,8 @@
 
 
-					else
+					}else{
 						$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();
+					$res->execute();}
 
 
@@ -1333,7 +1334,8 @@
 function votanti($id_cons,$do,$id_circ,$id_sede,$id_sez,$ops,$ov,$mv,$gv,$msv,$av){
 //function votanti($id_cons,$do,$id_circ,$id_sede,$id_sez,$ops,$ov,$mv,$gv,$msv,$av){
- global $aid, $prefix, $dbi,$tipo_cons,$genere,$id_cons_gen;
+ global $aid, $prefix, $dbi,$tipo_cons,$genere,$id_cons_gen,$id_comune;
 $bgcolor1=$_SESSION['bgcolor2'];
-OpenTable();
+
+#OpenTable();
 $sql="SELECT vismf from ".$prefix."_ele_cons_comune where id_cons='$id_cons'";
 $res = $dbi->prepare("$sql");
@@ -1346,27 +1348,75 @@
 $res->execute();
 
-
+echo "<table><tr><td>";
 $num = $res->rowCount();
 $sql="SELECT maschi,femmine FROM ".$prefix."_ele_sezioni where id_sez=$id_sez";
 $ressez = $dbi->prepare("$sql");
 $ressez->execute();
-
+##################
+echo "<style>";
+echo "DIV.table"; 
+echo "{
+    display:table;
+}
+FORM.tr
+{
+    display:table-row;
+	text-align: center;
+}
+DIV.tr
+{
+    display:table-row;
+	background-color: #D3D3D3;
+	text-align: center;
+}
+SPAN.tdm
+{
+    display:table-cell;
+	border: 1px solid black;
+	padding: 5px;
+}
+SPAN.td
+{
+    display:table-cell;
+}";
+echo "</style>";
+
+/*
+    echo "<form class=\"tr\"  name=\"votanti$y\" action=\"modules/Elezioni/salva_aff.php\">";
+        echo "<span class=\"td\"><input type=\"text\"/></span>";
+        <span class="td"><input type="text"/></span>
+    </form>
+    <div class="tr">
+        <span class="td">(cell data)</span>
+        <span class="td">(cell data)</span>
+    </div>
+    ...
+</div>
+*/
+##################
 
 list($maschi,$femmine)=$ressez->fetch(PDO::FETCH_NUM);
 $y=0;
-echo "<tr><td>&nbsp;</td></tr>";
+echo "<div class=\"table\">";
+#echo "<tr><td>&nbsp;</td></tr>";
+$riga=array();
+$rigat=array();
 while (list($ora,$giorno)= $res->fetch(PDO::FETCH_NUM)){
 	$y++;
-	echo "\n<tr><td>";
-	echo "<form name=\"votanti$y\" action=\"admin.php\">";
- 	echo "<table class=\"table-menu\" style=\"width: 100%; color: black;\"><tr>";
-	if ($genere==0){ //e' un referendum
-		echo "<td bgcolor=\"$bgcolor1\" align=\"center\" width=\"32\"><b>"._NUM."</b></td>";
-	}
-	echo "<td bgcolor=\"$bgcolor1\" align=\"center\" width=\"32\"><b>"._ORA."</b></td>"
-	."<td bgcolor=\"$bgcolor1\" align=\"center\"width=\"32\"><b>"._DATA."</b></td>";
-	echo "<td bgcolor=\"$bgcolor1\" align=\"center\"><b>"._VOTIU."</b></td>";
-	echo "<td bgcolor=\"$bgcolor1\" align=\"center\"><b>"._VOTID."</b></td>"
-	."<td bgcolor=\"$bgcolor1\" align=\"center\"><b>"._VOTIT."</b>"; 
+	$rigat[$y]='';
+	$riga[$y]='';
+#	echo "\n<tr><td>";
+#	echo "<form name=\"votanti$y\" action=\"modules/Elezioni/salva_aff.php\">";
+# 	echo "<table class=\"table-menu\" style=\"width: 100%; color: black;\"><tr>";
+$rigat[$y]= "<div class=\"tr\">";
+	if ($genere==0){ //e' un referendum 
+#		echo "<td bgcolor=\"$bgcolor1\" align=\"center\" width=\"32\"><b>"._NUM."</b></td>";
+		$rigat[$y].= "<span class=\"tdm\" bgcolor=\"$bgcolor1\" align=\"center\" width=\"32\"><b>"._NUM."</b></span>";
+	}
+	$rigat[$y].= "<span class=\"tdm\" bgcolor=\"$bgcolor1\" align=\"center\" width=\"32\"><b>"._ORA."</b></span>"
+	."<span class=\"tdm\" bgcolor=\"$bgcolor1\" align=\"center\" width=\"32\"><b>"._DATA."</b></span>";
+	$rigat[$y].= "<span class=\"tdm\" bgcolor=\"$bgcolor1\" align=\"center\"><b>"._VOTIU."</b></span>";
+	$rigat[$y].= "<span class=\"tdm\" bgcolor=\"$bgcolor1\" align=\"center\"><b>"._VOTID."</b></span>"
+	."<span class=\"tdm\" bgcolor=\"$bgcolor1\" align=\"center\"><b>"._VOTIT."</b></span>"; 
 	if ($genere==0){ 
 		$sql="SELECT * FROM ".$prefix."_ele_gruppo where id_cons='$id_cons'  ";
@@ -1375,12 +1425,8 @@
 
 
-		$max = $res2_>rowCount();
-	}else{ $max=1;}
-	echo "<input type=\"hidden\" name=\"op\" value=\"rec_add_votanti\">";
-	echo "<input type=\"hidden\" name=\"id_cons_gen\" value=\"$id_cons_gen\">"
-	."<input type=\"hidden\" name=\"id_sez\" value=\"$id_sez\">"
-	."<input type=\"hidden\" name=\"id_circ\" value=\"$id_circ\">"
-	."<input type=\"hidden\" name=\"id_sede\" value=\"$id_sede\">";
-	echo "</td>"; //la riga viene chiusa nel ciclo for    
+		$max = $res2->rowCount();
+	}else{ $max=1;} $op="rec_add_votanti";
+	$rigat[$y].= "</div>";
+
 	for ($i=1;$i<=$max;$i++){
 		$query="SELECT * FROM ".$prefix."_ele_voti_parziale as t1 left join ".$prefix."_ele_gruppo as t2 
@@ -1396,10 +1442,10 @@
 
 		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 ";
+	   	$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'";
+        $sql="select count(0) FROM ".$prefix."_ele_voti_parziale where id_sez='$id_sez' and id_gruppo='$id_gruppo'";
 $resril = $dbi->prepare("$sql");
 $resril->execute();
@@ -1425,39 +1471,49 @@
 		$precede[$id_gruppo]=$voti_t;
 		if (($voti_u+$voti_d and $voti_u+$voti_d!=$voti_t) or $error){
-			echo "</tr><tr style=\"background-color: rgb(255, 0, 0); text-align: center\">"; $error=0;
+#			echo "</tr><tr styl.e=\"background-color: rgb(255, 0, 0); text-align: center\">"; $error=0;
+			$riga[$y].= "<form class=\"tr\" style=\"background-color: rgb(255, 0, 0); text-align: center\" name=\"votanti\" action=\"modules/Elezioni/salva_aff.php\">";
 		}else{
-			echo "</tr><tr class=\"tr-dx\">";
+			$riga[$y].= "<form class=\"tr\" action=\"modules/Elezioni/salva_aff.php\">";
 		}
 		if ($genere==0){ // e' un referendum
-			echo "<td align=\"center\">$gruppo</td>";
-		}
-                
-                list ($anno,$mese,$di)=explode('-',$giorno);
-		echo "<td align=\"center\">$ora</td><td align=\"center\">$di-$mese-$anno</td>";
-		if ($voti_u > $maschi) echo "<td align=\"center\" bgcolor=\"red\">";
-		else echo "<td align=\"center\">";
-		if ($y<$num and $vismf==0 and $voti_u==0) { echo "<input type=\"hidden\"";}else echo "<input type=\"text\" style=\"text-align:right\"";
-		echo " name=\"voti_u$i\" value=\"$voti_u\" size=\"5\"></td>";
-		if ($voti_d > $femmine) echo "<td align=\"center\" bgcolor=\"red\">";
-		else echo "<td align=\"center\">";
-		if ($y<$num and $vismf==0 and $voti_d==0) { echo "<input type=\"hidden\"";}else echo "<input type=\"text\" style=\"text-align:right\"";
-		echo "  name=\"voti_d$i\" value=\"$voti_d\" size=\"5\"></td>";
-		if ($voti_t > ($maschi+$femmine)) echo "<td align=\"center\" bgcolor=\"red\"><input type=\"text\" name=\"voti_t$i\" value=\"$voti_t\" size=\"5\" style=\"text-align:right\">";
-		else echo "<td align=\"center\"><input name=\"voti_t$i\" value=\"$voti_t\" size=\"5\" style=\"text-align:right\">";
-		echo "<input type=\"hidden\" name=\"id_parz$i\" value=\"$id_parz\">"
-		."<input type=\"hidden\" name=\"data$i\" value=\"$giorno\">"
-		."<input type=\"hidden\" name=\"orario$i\" value=\"$ora\">"
-		."<input type=\"hidden\" name=\"gruppo$i\" value=\"$id_gruppo\">";
-		echo "</td>";
-	}
-	if (chisei($id_cons_gen)>=64 and $y==$numril)   echo "<td style=\"text-align: right;\" rowspan=\"1\" colspan=\"6\">"._DELETE." <input type=\"checkbox\" name=\"delete\" value=\"true\"></td>";
-	else echo "<td style=\"text-align: right;\" rowspan=\"1\" colspan=\"6\"><input type=\"hidden\" name=\"delete\" value=\"\"></td>";
-	echo "<td style=\"text-align: right;\" rowspan=\"1\" colspan=\"6\"><input type=\"submit\" name=\"update\" value=\""._OK."\"></td>";
-	echo "</tr>";
-
-
-
-#   echo "</table></form></td></tr>";
-   echo "</table></form>";
+			$riga[$y].= "<span class=\"td\" align=\"center\">$gruppo</span>";
+		}
+	
+
+	$riga[$y].= "<span class=\"td\"><input type=\"hidden\" name=\"op\" value=\"rec_add_votanti\"/>";
+	$riga[$y].= "<input type=\"hidden\" name=\"id_cons_gen\" value=\"$id_cons_gen\"/>"
+	."<input type=\"hidden\" name=\"id_sez\" value=\"$id_sez\"/>"
+	."<input type=\"hidden\" name=\"id_circ\" value=\"$id_circ\"/>"
+	."<input type=\"hidden\" name=\"id_sede\" value=\"$id_sede\"/>"; 
+#$riga[$y].= "</span>";                     
+        list ($anno,$mese,$di)=explode('-',$giorno);
+		$riga[$y].= "$ora</span><span class=\"td\" align=\"center\">$di-$mese-$anno</span>";
+		if ($voti_u > $maschi) $riga[$y].= "<span class=\"td\" align=\"center\" bgcolor=\"red\">";
+		else $riga[$y].= "<span class=\"td\" align=\"center\">";
+		if ($y<$num and $vismf==0 and $voti_u==0) { $riga[$y].= "<input type=\"hidden\" id=\"voti_u$y$i\" name=\"voti_u\" value=\"'$voti_u'\"";}else $riga[$y].= "<input type=\"text\" style=\"text-align:right\" id=\"voti_u$y$i\" name=\"voti_u\" value=\"$voti_u\"";
+		$riga[$y].= " size=\"5\"/></span>";
+		if ($voti_d > $femmine) $riga[$y].= "<span class=\"td\" align=\"center\" bgcolor=\"red\"/>";
+		else $riga[$y].= "<span class=\"td\" align=\"center\">";
+		if ($y<$num and $vismf==0 and $voti_d==0) { $riga[$y].= "<input type=\"hidden\" id=\"voti_d$y$i\" name=\"voti_d\" value=\"'$voti_d'\"";}else $riga[$y].= "<input type=\"text\" style=\"text-align:right\" id=\"voti_d$y$i\" name=\"voti_d\" value=\"$voti_d\"";
+		$riga[$y].= "  size=\"5\"/></span>";
+		if ($voti_t > ($maschi+$femmine)) $riga[$y].= "<span class=\"td\" align=\"center\" bgcolor=\"red\" ><input type=\"text\" id=\"voti_t$y$i\" name=\"voti_t\" value=\"$voti_t\" size=\"5\" style=\"text-align:right\"/>";
+		else $riga[$y].= "<span class=\"td\" align=\"center\"><input id=\"voti_t$y$i\" name=\"voti_t\" value=\"$voti_t\" size=\"5\" style=\"text-align:right\"/>";
+		$riga[$y].= "<input type=\"hidden\" name=\"id_parz\" value=\"$id_parz\"/>"
+		."<input type=\"hidden\" name=\"data\" value=\"$giorno\"/>"
+		."<input type=\"hidden\" name=\"orario\" value=\"$ora\"/>"
+		."<input type=\"hidden\" name=\"id_comune\" value=\"$id_comune\"/>"
+		."<input type=\"hidden\" name=\"id_gruppo\" value=\"$id_gruppo\"/>";
+		$riga[$y].= "</span>";
+
+		if (chisei($id_cons_gen)>=64 and $y==$numril)   $riga[$y].= "<span class=\"td\" style=\"text-align: right;\" rowspan=\"1\" colspan=\"6\">"._DELETE." <input type=\"checkbox\" name=\"delete\" value=\"true\"/></span>";
+		else $riga[$y].= "<span class=\"td\" style=\"text-align: right;\" rowspan=\"1\" colspan=\"6\"><input type=\"hidden\" name=\"delete\" value=\"\"/></span>";
+		$riga[$y].= "<span class=\"td\" style=\"text-align: right;\" rowspan=\"1\" colspan=\"6\"><input type=\"submit\" name=\"update\" value=\""._OK."\"/></span>";
+		$riga[$y].= "</form>";
+
+	}
+#	   echo "</table></form>";
+	   echo "</div>";
+
+
    	$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");
@@ -1469,10 +1525,11 @@
 	{
 		echo "<SCRIPT type=\"text/javascript\">\n\n<!--\n";
-		if ($y==$num) {
-			echo "document.votanti$y.voti_u1.focus()\n";
-			echo "document.votanti$y.voti_u1.select()\n";
+		$numy=$y.'1';
+		if ($y==$num) { 
+			echo "document.votanti$y.voti_u$numy.focus()\n";
+			echo "document.votanti$y.voti_u$numy.select()\n";
 		}else{
-			echo "document.votanti$y.voti_t1.focus()\n";
-			echo "document.votanti$y.voti_t1.select()\n";
+			echo "this.voti_t$numy.focus()\n";
+			echo "this.voti_t$numy.select()\n";
 		}
 		echo "//-->\n"
@@ -1480,98 +1537,12 @@
 		break;
 	}
-	echo "</td></tr>";
-	}
-CloseTable();
-}
-
-
-///////////////////////////
-// registra i votanti
-///////////////////////////
-
-function rec_add_votanti() {
-global $prefix, $dbi,$aid,$tipo_cons,$genere,$id_cons,$fileout;
-//ordine dei parametri: 0)op 1)voti_u 2) voti_d 3)voti_t 4)id_cons 5)id_sez 6)id_circ 7)id_sede
-// 8)id_parz 9)ops 10)data 11)orario 12)tipo 13)id_gruppo 14) update
-if ($fileout) while (!$fp = fopen($fileout,"a"));
-
-$username="$aid";
-$arg2 = func_get_args();
-$arg = split(",",$arg2[0]);
-$id_cons_gen=intval($arg[1]);
-$id_sez=intval($arg[2]);
-$id_circ=intval($arg[3]);
-$id_sede=intval($arg[4]);
-$op=$arg[count($arg)-2];
-for($i=5;$i< count($arg)-2;) {
-	$voti_u = intval($arg[$i++]);
-	$voti_d = intval($arg[$i++]);
-	$voti_t = intval($arg[$i++]);
-	if($voti_t==0) $voti_t=$voti_d+$voti_u;
-	$id_parz = intval($arg[$i++]);
-	$giorno = $arg[$i++];
-	$ora = $arg[$i++];
-	$id_gruppo = intval($arg[$i++]);
-    $data=date("Y/m/d");
-	$tempo=date("H:i:s");
-	$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";
-	}
-	$sql="$query";
-$res = $dbi->prepare("$sql");
-$res->execute();
-
-
-	$righe=$res->rowCount();
-    if (!$righe){
-        $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"){
-        $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 {
-  	$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){   	
-	$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");
-	}
-     }
-  }   
-if ($fileout)fclose($fp);
-Header("Location: admin.php?op=voti&id_cons_gen=$id_cons_gen&id_circ=$id_circ&id_sede=$id_sede&id_sez=$id_sez&ops=1&do=spoglio");
+#	echo "</td></tr>";
+	}
+#CloseTable();
+foreach($riga as $key=>$val){
+	echo $rigat[$key];
+	echo $riga[$key];
+}
+echo "</div></td></tr></table>";
 }
 
@@ -1588,7 +1559,8 @@
 
 
-     	echo "<form name=\"spogliovoti\" action=\"admin.php\">"
+     	echo "<form name=\"spogliovoti\" action=\"modules/Elezioni/salva_voti.php\">"
       	."<input type=\"hidden\" name=\"op\" value=\"rec_finale\">";
    	echo "<input type=\"hidden\" name=\"id_cons_gen\" value=\"$id_cons_gen\">"
+     	."<input type=\"hidden\" name=\"id_cons\" value=\"$id_cons\">"
      	."<input type=\"hidden\" name=\"id_sez\" value=\"$id_sez\">"
     	."<input type=\"hidden\" name=\"id_circ\" value=\"$id_circ\">"
@@ -1638,5 +1610,5 @@
 	."</td><td>$tot_nulli"
 	."</td><td>$tot_voti</td><td>"
-//    	."<input type=\"hidden\" name=\"id_cand\" value=\"$id_cand\">"
+    	."<input type=\"hidden\" name=\"genere\" value=\"$genere\">"
     	."<input type=\"hidden\" name=\"ops\" value=\"$ops\">"
        	."<input type=\"submit\" name=\"update\" value=\""._OK."\">"
@@ -1800,5 +1772,5 @@
 
 
-    	list( $voti_u, $voti_d, $voti_t) = $result->fetch(PDO::FETCH_NUM)
+    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>"
@@ -1950,10 +1922,14 @@
 	echo "<tr><td></td></tr></table>";
 	if ($validi+$nulli+$bianchi+$contestati+$votinulli>0 or $genere==0) {
-    echo "<table class=\"table-menu\" style=\" width: 60%; color: black\"><tr><td colspan=\"3\"><form name=\"sezioni\" action=\"admin.php\">";
-   	echo "<input type=\"hidden\" name=\"op\" value=\"rec_voti_gruppi\">"
+ if($genere==0)   echo "<table class=\"table-menu\" style=\" width: 60%; color: black\"><tr><td colspan=\"3\"><form name=\"sezioni\" action=\"modules/Elezioni/salva_ref.php\">";
+   else echo "<table class=\"table-menu\" style=\" width: 60%; color: black\"><tr><td colspan=\"3\"><form name=\"sezioni\" action=\"modules/Elezioni/salva_gruppi.php\">";
+   	echo "<input type=\"hidden\" name=\"op\" value=\"rec_voti_gruppiq\">"
     ."<input type=\"hidden\" name=\"id_cons_gen\" value=\"$id_cons_gen\">"
+    ."<input type=\"hidden\" name=\"id_cons\" value=\"$id_cons\">"
     ."<input type=\"hidden\" name=\"id_sez\" value=\"$id_sez\">"
     ."<input type=\"hidden\" name=\"id_circ\" value=\"$id_circ\">"
     ."<input type=\"hidden\" name=\"id_sede\" value=\"$id_sede\">"
+    ."<input type=\"hidden\" name=\"circo\" value=\"$circo\">"
+    ."<input type=\"hidden\" name=\"genere\" value=\"$genere\">"
     ."<input type=\"hidden\" name=\"do\" id=\"do\" value=\"0\">";
 	echo "<br><br> <table  class=\"table-menu\" style=\"width: 100%; color: black\"><tr align=\"center\" bgcolor=\"$bgcolor1\">"
@@ -2018,10 +1994,10 @@
 		echo "<td align=\"center\"><input type=\"hidden\" name=\"id_gruppo$i\" value=\"$id_gruppo\"><b>$num_gruppo</b>"
 		."</td><td align=\"left\" width=\"50%\"><b> $descr[0] </b>";
-        $pro['si']=(isset($pro['si']) and $pro['si']>=0) ? $pro['si']:'';
-        $pro['no']=(isset($pro['no']) and $pro['no']>=0) ? $pro['no']:'';
-        $pro['validi']=(isset($pro['validi']) and $pro['validi']>=0) ? $pro['validi']:'';
-        $pro['bianchi']=(isset($pro['bianchi']) and $pro['bianchi']>=0) ? $pro['bianchi']:'';
-        $pro['contestati']=(isset($pro['contestati']) and $pro['contestati']>=0) ? $pro['contestati']:'';
-        $pro['nulli']=(isset($pro['nulli']) and $pro['nulli']>=0) ? $pro['nulli']:'';
+        $pro['si']=(isset($pro['si']) and $pro['si']>=0) ? $pro['si']:'0';
+        $pro['no']=(isset($pro['no']) and $pro['no']>=0) ? $pro['no']:'0';
+        $pro['validi']=(isset($pro['validi']) and $pro['validi']>=0) ? $pro['validi']:'0';
+        $pro['bianchi']=(isset($pro['bianchi']) and $pro['bianchi']>=0) ? $pro['bianchi']:'0';
+        $pro['contestati']=(isset($pro['contestati']) and $pro['contestati']>=0) ? $pro['contestati']:'0';
+        $pro['nulli']=(isset($pro['nulli']) and $pro['nulli']>=0) ? $pro['nulli']:'0';
 		$tot_nulli=$pro['nulli']+$pro['bianchi']+$pro['contestati'];
 		$tot_voti=$pro['validi']+$tot_nulli;
@@ -2036,5 +2012,5 @@
 		echo "</td><td align=\"right\">$tot</td>";
 	}else{
-		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>"
+		echo "<tr style=\"background-color: $bgcolor2; text-align:center\"><td align=\"center\"><input type=\"hidden\" name=\"num_gruppo$i\" value=\"$num_gruppo\"><b>$num_gruppo</b>"
 		."</td><td align=\"left\"><b> $descr_gruppo </b>";
 		$sql="SELECT * FROM ".$prefix."_ele_voti_gruppo where id_cons='$id_cons' and id_sez='$id_sez' and id_gruppo='$id_gruppo' ";
@@ -2108,5 +2084,5 @@
 $log_ora=getdate(time());
 $arg2 = func_get_args();
-$arg = split(",",$arg2[0]);
+$arg = preg_split("/\,+/",$arg2[0]);
 $id_cons_gen=intval($arg[1]);
 $id_sez = intval($arg[2]);
@@ -2278,4 +2254,7 @@
     	voti($id_cons,$do,$id_circ,$id_sede,$ops,$ov,$mv,$gv,$msv,$av,$id_lista);
     	break;
+	case "rec_add_votanti":
+		rec_add_votanti($vari);
+		break;
 	default :
     	$op($vari); //chiamata a funzione variabile con parametri variabili (da cambiare!)
Index: trunk/admin/modules/Elezioni/salva_aff.php
===================================================================
--- trunk/admin/modules/Elezioni/salva_aff.php	(revision 258)
+++ trunk/admin/modules/Elezioni/salva_aff.php	(revision 258)
@@ -0,0 +1,181 @@
+<?php
+/************************************************************************/
+/* Eleonline - Raccolta e diffusione dei dati elettorali                */
+/************************************************************************/
+/* Modulo salva affluenze                                               */
+/* Amministrazione                                                      */
+/************************************************************************/
+session_name('sesadmin');
+  // gestione sessione
+$a = session_id();
+if(empty($a)) session_start();
+if(!$_SESSION['aid'])
+    die ("You can't access this file directly..."); 
+
+include("../../config.php");
+	try{
+	$dbi = new PDO("mysql:host=$dbhost;charset=latin1", $dbuname, $dbpass, array(PDO::ATTR_EMULATE_PREPARES => false, PDO::ATTR_ERRMODE=>PDO::ERRMODE_EXCEPTION)); 
+     	$sql = "use $dbname";
+    	$dbi->exec($sql);
+        }
+	catch(PDOException $e)
+	{
+	    echo $sql . "<br>" . $e->getMessage();
+	}             
+
+
+if (isset($_GET['id_cons_gen'])) $id_cons_gen=intval($_GET['id_cons_gen']); else $id_cons_gen='0';
+if (isset($_GET['op'])) $op=intval($_GET['op']); else $op='0';
+if (isset($_GET['id_circ'])) $id_circ=intval($_GET['id_circ']); else $id_circ='0';
+if (isset($_GET['id_sez'])) $id_sez=intval($_GET['id_sez']); else $id_sez='';
+if (isset($_GET['id_sede'])) $id_sede=intval($_GET['id_sede']); else $id_sede='0';
+if (isset($_GET['voti_u'])) $voti_u=intval($_GET['voti_u']); else $voti_u='0';
+if (isset($_GET['voti_d'])) $voti_d=intval($_GET['voti_d']); else $voti_d='0';
+if (isset($_GET['voti_t'])) $voti_t=intval($_GET['voti_t']); else $voti_t='0';
+if (isset($_GET['orario'])) get_magic_quotes_gpc() ? $orario=$_GET['orario']:$orario=addslashes($_GET['orario']); else $orario='';
+if (isset($_GET['data'])) get_magic_quotes_gpc() ? $data=$_GET['data']:$data=addslashes($_GET['data']); else $data='01-01-1900';
+if (isset($_GET['id_comune'])) $id_comune=intval($_GET['id_comune']); else $id_comune='0';
+if (isset($_GET['id_gruppo'])) $id_gruppo=intval($_GET['id_gruppo']); else $id_gruppo='0';
+if (isset($_GET['delete'])) get_magic_quotes_gpc() ? $delete=$_GET['delete']:$delete=addslashes($_GET['delete']); else $delete='';
+global $prefix,$id_parz,$tempo,$username,$aid,$dbi,$genere;
+/* ############
+$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();
+$y=0;
+	while(list($i,$a)=$result->fetch(PDO::FETCH_BOTH)) {
+		$y++;
+		$sql="SELECT * FROM ".$prefix."_ele_gruppo where id_cons='$id_cons'  ";
+		$res2 = $dbi->prepare("$sql");
+		$res2->execute();
+		for($i=1;$i<=$max;$i++){
+			$idg="id_gruppo$i";$vnp="vnpl$i";$slp="slpl$i";$idlist="id_lista$i";
+			if (isset($_GET[$vnp])) $vnpl[$i]=intval($_GET[$vnp]); else $vnpl[$i]='0';
+			if (isset($_GET[$vot])) $voti[$i]=intval($_GET[$vot]); else $voti[$i]='0';
+			if (isset($_GET[$slp])) $slpl[$i]=intval($_GET[$slp]); else $slpl[$i]='0';
+			if (isset($_GET[$idlist])) $idlista[$i]=intval($_GET[$idlist]); else $idlista[$i]='0';
+			$sololiste+=$slpl[$i];
+		}
+	}
+#############
+*/
+
+if (!isset($fileout)) $fileout='';
+if(($voti_u+$voti_d) and !$voti_t) $voti_t=$voti_u+$voti_d;
+
+$salvato=0;
+$query="select id_cons from ".$prefix."_ele_cons_comune where id_cons_gen='$id_cons_gen' and id_comune='$id_comune'";
+$res = $dbi->prepare("$query");
+$res->execute();
+$BASE=substr($_SERVER['PHP_SELF'], 0, strrpos($_SERVER['REQUEST_URI'], "/")-16);
+list($id_cons)=$res->fetch(PDO::FETCH_NUM); 
+$query="select id_parz from ".$prefix."_ele_voti_parziale where data='$data' and orario='$orario' and id_sez='$id_sez' and id_gruppo='$id_gruppo'";
+$res = $dbi->prepare("$query");
+$res->execute();         
+$righe=$res->rowCount();
+list($id_parz)=$res->fetch(PDO::FETCH_NUM);
+if($righe){ #la riga Ãš presente e viene aggiorata
+	$arr=$res->fetch(PDO::FETCH_BOTH);
+	$sql="update ".$prefix."_ele_voti_parziale set voti_uomini='$voti_u',voti_donne='$voti_d',voti_complessivi='$voti_t' where  id_parz='$id_parz'";
+	$compl = $dbi->prepare("$sql");
+	$compl->execute(); 
+	if($compl->rowCount()) $salvato=1;
+	if($delete=="true"){
+		$sql="delete from ".$prefix."_ele_voti_parziale where id_parz='$id_parz'";
+		$res = $dbi->prepare("$sql");
+		$res->execute();
+		if($res->rowCount()) $salvato=1;
+	}
+}else{ # Ãš un nuovo inserimento
+	$sql="insert into ".$prefix."_ele_voti_parziale values ('$id_cons', '$id_sez','','$orario','$data','$voti_u','$voti_d','$voti_t','$id_gruppo')";
+	$res = $dbi->prepare("$sql");
+	$res->execute();
+	if($res->rowCount()) $salvato=1;	
+}
+if ($fileout) {
+	while (!$fp = fopen($fileout,"a"));
+	fwrite($fp,"$sql;\n"); 
+	fclose($fp);
+}
+if($salvato){
+	$riga=addslashes($sql);
+	$sqlog="insert into ".$prefix."_ele_log values('$id_cons','$id_sez','$username','$data','$orario','','$riga','".$prefix."_ele_voti_parziale')";
+	$res = $dbi->prepare("$sqlog");
+	$res->execute();
+}
+controllo_aff($id_cons,$id_sez,$id_parz);  
+
+Header("Location: ".$BASE."admin.php?op=voti&id_cons_gen=$id_cons_gen&id_circ=$id_circ&id_sede=$id_sede&id_sez=$id_sez&ops=1&do=spoglio");
+
+
+function controllo_aff($id_cons,$id_sez,$id_parz){
+	global $prefix,$dbi,$id_sede,$id_con_gen;
+		##############################
+#	$sql="select * from ".$prefix."_ele_controllosez where id_cons='$id_cons' and id_sez='$id_sez'";
+#	$resc = $dbi->prepare("$sql");
+#	$resc->execute();
+#	$conta=$resc->rowCount();
+	$err=0;
+#	$err2=0;
+	$sql="select maschi,femmine from ".$prefix."_ele_sezioni where id_sez='$id_sez'";
+	$res = $dbi->prepare("$sql");
+	$res->execute();
+	list($maschi,$femmine)=$res->fetch(PDO::FETCH_NUM);
+
+	$sql="select voti_uomini,voti_donne,voti_complessivi from ".$prefix."_ele_voti_parziale where id_sez='$id_sez' and id_parz='$id_parz'";
+	$res = $dbi->prepare("$sql");
+	$res->execute();
+	while(list($voti_u,$voti_d,$voti_t)=$res->fetch(PDO::FETCH_NUM))
+		if(($voti_u+$voti_d!=$voti_t || $voti_u>$maschi || $voti_d>$femmine) and ($voti_u+$voti_d>0)) {$err=1; break;}
+/*	if($conta){
+		$aff=$resc->fetch(PDO::FETCH_BOTH);
+		if($aff['status']) 
+			if ($aff['stato_val'] || $aff['stato_lis'] || $aff['stato_gru'] || $aff['stato_can']) $err2=1;
+	}
+	if($conta && !$err2) {
+		$sql="update ".$prefix."_ele_controllosez set stato_aff='$err',status='$err' where id_cons='$id_cons' and id_sez='$id_sez'";
+		$res = $dbi->prepare("$sql");
+		$res->execute();
+	} elseif($conta && !$err){ 
+		$sql="update ".$prefix."_ele_controllosez set stato_aff='$err' where id_cons='$id_cons' and id_sez='$id_sez'";
+		$res = $dbi->prepare("$sql");
+		$res->execute();
+		return;
+	} else {
+			$sql="insert into ".$prefix."_ele_controllosez values ('$id_sez','$id_cons','$err','0','0','0','0','$err')";
+			$res = $dbi->prepare("$sql");
+			$res->execute();
+	}*/
+#######################
+	$tipo='affluenze';
+	$sql="select id from ".$prefix."_ele_controlli where tipo='$tipo' and id_sez='$id_sez' ";
+	$res = $dbi->prepare("$sql");
+	$res->execute();
+	$righe=$res->rowCount();
+	if($righe){
+		while(list($id)=$res->fetch(PDO::FETCH_NUM)){
+			if($id==$id_parz){
+				if(!$err){ 
+					$sql="delete from ".$prefix."_ele_controlli where tipo='$tipo' and id='$id_parz' ";
+					$res = $dbi->prepare("$sql");
+					$res->execute();
+					
+				}
+				$err=0;
+				break;
+			}					
+		}
+	}
+	if($err){
+		$sql="insert into ".$prefix."_ele_controlli value('$id_cons','$id_sez','$tipo','$id_parz')";
+		$res = $dbi->prepare("$sql");
+		$res->execute();		
+	}
+	
+	
+#######################
+	include("ele_colora_sez.php");
+}
+
+?>
Index: trunk/admin/modules/Elezioni/salva_gruppi.php
===================================================================
--- trunk/admin/modules/Elezioni/salva_gruppi.php	(revision 258)
+++ trunk/admin/modules/Elezioni/salva_gruppi.php	(revision 258)
@@ -0,0 +1,235 @@
+<?php
+/************************************************************************/
+/* Eleonline - Raccolta e diffusione dei dati elettorali                */
+/************************************************************************/
+/* Modulo salva affluenze                                               */
+/* Amministrazione                                                      */
+/************************************************************************/
+session_name('sesadmin');
+  // gestione sessione
+$a = session_id();
+if(empty($a)) session_start();
+if(!$_SESSION['aid'])
+    die ("You can't access this file directly..."); 
+$aid=$_SESSION['aid'];
+include("../../config.php");
+	try{
+	$dbi = new PDO("mysql:host=$dbhost;charset=latin1", $dbuname, $dbpass, array(PDO::ATTR_EMULATE_PREPARES => false, PDO::ATTR_ERRMODE=>PDO::ERRMODE_EXCEPTION)); 
+     	$sql = "use $dbname";
+    	$dbi->exec($sql);
+        }
+	catch(PDOException $e)
+	{
+	    echo $sql . "<br>" . $e->getMessage();
+	}             
+
+if (isset($_GET['genere'])) $genere=intval($_GET['genere']); else $genere='0';
+if (isset($_GET['id_cons_gen'])) $id_cons_gen=intval($_GET['id_cons_gen']); else $id_cons_gen='0';
+if (isset($_GET['id_cons'])) $id_cons=intval($_GET['id_cons']); else $id_cons='0';
+if (isset($_GET['op'])) $op=intval($_GET['op']); else $op='0';
+if (isset($_GET['id_circ'])) $id_circ=intval($_GET['id_circ']); else $id_circ='0';
+if (isset($_GET['id_sez'])) $id_sez=intval($_GET['id_sez']); else $id_sez='0';
+if (isset($_GET['id_sede'])) $id_sede=intval($_GET['id_sede']); else $id_sede='0';
+if (isset($_GET['do'])) $do=intval($_GET['do']); else $do='0';
+if (isset($_GET['validi'])) $validi=intval($_GET['validi']); else $validi='0';
+if (isset($_GET['nulli'])) $nulli=intval($_GET['nulli']); else $nulli='0';
+if (isset($_GET['bianchi'])) $bianchi=intval($_GET['bianchi']); else $bianchi='0';
+if (isset($_GET['contestati'])) $contestati=intval($_GET['contestati']); else $contestati='0';
+if (isset($_GET['votinulli'])) $votinulli=intval($_GET['votinulli']); else $votinulli='0';
+if (isset($_GET['id_comune'])) $id_comune=intval($_GET['id_comune']); else $id_comune='0';
+if (isset($_GET['ops'])) $ops=intval($_GET['ops']); else $ops='0';
+if (isset($_GET['delete'])) $delete=intval($_GET['delete']); else $delete='';
+if (isset($_GET['circo'])) get_magic_quotes_gpc() ? $circo=$_GET['circo']:$circo=addslashes($_GET['circo']); else $circo='';
+
+global $prefix,$id_parz,$fileout;
+$sql="select num_gruppo from ".$prefix."_ele_gruppo where id_cons='$id_cons' $circo ORDER BY num_gruppo  ";
+$result = $dbi->prepare("$sql");
+$result->execute();
+while(list($i)=$result->fetch(PDO::FETCH_BOTH)) {
+	$vot="voti$i";$solo="solog$i";$grupp="num_gruppo$i";
+	if (isset($_GET[$grupp])) $num_gruppo[$i]=intval($_GET[$grupp]); else $num_gruppo[$i]='0';
+	if (isset($_GET[$vot])) $voti[$i]=intval($_GET[$vot]); else $voti[$i]='0';
+	if (isset($_GET[$solo])) $solog[$i]=intval($_GET[$solo]); else $solog[$i]='0';
+
+}
+
+if (!isset($fileout)) $fileout='';
+#if(($voti_u+$voti_d) and !$voti_t) $voti_t=$voti_u+$voti_d;
+if ($fileout) while (!$fp = fopen($fileout,"a"));
+
+##################
+	if($do==1) {
+		$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="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{
+		$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){ 
+		}
+		$sql="select num_gruppo from ".$prefix."_ele_voti_gruppo where id_cons='$id_cons' and id_sez='$id_sez'";
+		$result = $dbi->prepare("$sql");
+		$result->execute();
+		if($result->rowCount()) {
+			while(list($i)=$result->fetch(PDO::FETCH_NUM)){
+				$sql="update  ".$prefix."_ele_voti_gruppo set voti='".$voti[$i]."',solo_gruppo='".$solog[$i]."' where id_cons='$id_cons' and id_sez='$id_sez' and num_gruppo='".$num_gruppo[$i]."'";
+				$res = $dbi->prepare("$sql");
+				$res->execute();
+			}
+		}else{
+			$sql="select num_gruppo,id_gruppo from ".$prefix."_ele_gruppo where id_cons='$id_cons'";
+			$result = $dbi->prepare("$sql");
+			$result->execute();
+			while(list($i,$id_gruppo)=$result->fetch(PDO::FETCH_NUM)){
+				$sql="insert into  ".$prefix."_ele_voti_gruppo values('$id_cons','$id_gruppo','$id_sez','$i','".$voti[$i]."','".$solog[$i]."')";
+				$res = $dbi->prepare("$sql");
+				$res->execute();
+			}
+			
+		}
+}
+
+
+
+controllo_votig($id_cons,$id_sez,$genere,$id_gruppo);
+
+if ($fileout) fclose($fp);
+$BASE=substr($_SERVER['PHP_SELF'], 0, strrpos($_SERVER['REQUEST_URI'], "/")-16);
+Header("Location: ".$BASE."admin.php?op=voti&id_cons_gen=$id_cons_gen&id_circ=$id_circ&id_sede=$id_sede&id_sez=$id_sez&do=spoglio&ops=$ops");
+#################################
+
+
+
+
+	
+function controllo_votig($id_cons,$id_sez,$genere){
+	global $prefix,$dbi,$id_sede,$id_cons_gen;
+		##############################
+	$sql="select * from ".$prefix."_ele_controllosez where id_cons='$id_cons' and id_sez='$id_sez'";
+	$resc = $dbi->prepare("$sql");
+	$resc->execute();
+	$conta=$resc->rowCount();
+	$err=0; $err2=0;
+	$sql="SELECT id_gruppo FROM ".$prefix."_ele_gruppo where id_cons='$id_cons'";
+	$resref = $dbi->prepare("$sql");
+	$resref->execute();	
+	if($genere==0){ 
+		$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(); 
+			$sql="SELECT max(voti_complessivi) FROM ".$prefix."_ele_voti_parziale where id_sez='$id_sez' and id_gruppo='$idrefgruppo'";
+			$res3 = $dbi->prepare("$sql");
+			$res3->execute();
+			list($voti)=$res3->fetch(PDO::FETCH_NUM);
+			$rifscru++;
+			list($si,$no,$validi,$nulli,$bianchi,$contestati)=$res2->fetch(PDO::FETCH_NUM);
+			if(($si+$no==$validi) and ($validi+$nulli+$bianchi+$contestati==$voti)) 
+				continue;
+			else {$err=1; break;}	
+		}
+	}else{
+		#per le altre consultazione
+		$sql="SELECT max(voti_complessivi) FROM ".$prefix."_ele_voti_parziale where id_sez='$id_sez'";
+		$res3 = $dbi->prepare("$sql");
+		$res3->execute();
+		list($voti)=$res3->fetch(PDO::FETCH_NUM);
+		$sql="SELECT validi FROM ".$prefix."_ele_sezioni where id_sez='$id_sez' and id_cons='$id_cons' ";
+		$res2 = $dbi->prepare("$sql");
+		$res2->execute();
+		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'";
+			$sql="$query";
+			$res4 = $dbi->prepare("$sql");
+			$res4->execute();
+			list($validi, $nulli, $bianchi,$contestati,$votinulli)=$res4->fetch(PDO::FETCH_NUM);
+			if (($validi+$nulli+$bianchi+$contestati+$votinulli)!=$voti)
+				{$err=1;}
+		} 
+	}
+
+#############
+	$tipo='gruppo';
+	$sql="select id from ".$prefix."_ele_controlli where tipo='$tipo' and id_sez='$id_sez' and id= ";
+	$res = $dbi->prepare("$sql");
+	$res->execute();
+	$righe=$res->rowCount();
+	if($righe){
+		if(!$err){ 
+			$sql="delete from ".$prefix."_ele_controlli where tipo='$tipo' and id='$id_sez' ";
+			$res = $dbi->prepare("$sql");
+			$res->execute();
+		}
+		$err=0;
+	}
+	if($err){
+		$sql="insert into ".$prefix."_ele_controlli value('$id_cons','$id_sez','$tipo','$id_sez')";
+		$res = $dbi->prepare("$sql");
+		$res->execute();		
+	}
+#############
+	$sql="select * from ".$prefix."_ele_controllosez where id_cons='$id_cons' and id_sez='$id_sez'";
+	$resc = $dbi->prepare("$sql");
+	$resc->execute();
+	$aff=$resc->fetch(PDO::FETCH_BOTH);
+	if($aff['status']) {
+		if ($aff['stato_aff'] ||$aff['stato_lis'] || $aff['stato_gru'] || $aff['stato_can']) {
+			$sql="update ".$prefix."_ele_controllosez set stato_val='$err' where id_cons='$id_cons' and id_sez='$id_sez'";
+			$res = $dbi->prepare("$sql");
+			$res->execute();
+		}else{
+			$sql="update ".$prefix."_ele_controllosez set stato_val='$err',status='$err' where id_cons='$id_cons' and id_sez='$id_sez'";
+			$res = $dbi->prepare("$sql");
+			$res->execute();
+		}
+		
+	}
+	if($err || $aff['status'])
+		$sql="UPDATE ".$prefix."_ele_sezioni set colore='style=\" background: #FF3300;' where id_cons='$id_cons' and id_sez='$id_sez'"; #ROSSO
+	else {
+		$col="#F0E68C;";
+		$sql="select id_cand from ".$prefix."_ele_voti_candidati where id_sez='$id_sez' group by id_cand";
+		$res = $dbi->prepare("$sql");
+		$res->execute();
+		$vv=$res->rowCount();
+		$sql="select id_cand from ".$prefix."_ele_candidati where id_cons='$id_cons'";
+		$res = $dbi->prepare("$sql");
+		$res->execute();
+		$vvt=$res->rowCount();
+		if($vvt=$vv) $col="#F0E68C;"; #colore se finito l'inserimento dei viti ai candidati
+		else{
+			$sql="select id_lista from ".$prefix."_ele_voti_lista where id_sez='$id_sez' group by id_lista";
+			$res = $dbi->prepare("$sql");
+			$res->execute();
+			$vv=$res->rowCount();
+			$sql="select id_lista from ".$prefix."_ele_lista where id_cons='id_cons'";
+			$res = $dbi->prepare("$sql");
+			$res->execute();
+			$vvt=$res->rowCount();
+			if($vvt=$vv) $col="#F0E68C;"; #colore se finito l'inserimento dei voti alle liste
+			
+		}
+		$sql="UPDATE ".$prefix."_ele_sezioni set colore='style=\" background: $col' where id_cons='$id_cons' and id_sez='$id_sez'"; #"#F0E68C" "KHAKY"
+		
+	}
+	$res = $dbi->prepare("$sql");
+	$res->execute();
+	
+}
+
+?>
Index: trunk/admin/modules/Elezioni/salva_liste.php
===================================================================
--- trunk/admin/modules/Elezioni/salva_liste.php	(revision 258)
+++ trunk/admin/modules/Elezioni/salva_liste.php	(revision 258)
@@ -0,0 +1,247 @@
+<?php
+/************************************************************************/
+/* Eleonline - Raccolta e diffusione dei dati elettorali                */
+/************************************************************************/
+/* Modulo salva affluenze                                               */
+/* Amministrazione                                                      */
+/************************************************************************/
+session_name('sesadmin');
+  // gestione sessione
+$a = session_id();
+if(empty($a)) session_start();
+if(!$_SESSION['aid'])
+    die ("You can't access this file directly..."); 
+$aid=$_SESSION['aid'];
+include("../../config.php");
+	try{
+	$dbi = new PDO("mysql:host=$dbhost;charset=latin1", $dbuname, $dbpass, array(PDO::ATTR_EMULATE_PREPARES => false, PDO::ATTR_ERRMODE=>PDO::ERRMODE_EXCEPTION)); 
+     	$sql = "use $dbname";
+    	$dbi->exec($sql);
+        }
+	catch(PDOException $e)
+	{
+	    echo $sql . "<br>" . $e->getMessage();
+	}             
+
+if (isset($_GET['genere'])) $genere=intval($_GET['genere']); else $genere='';
+if (isset($_GET['id_cons_gen'])) $id_cons_gen=intval($_GET['id_cons_gen']); else $id_cons_gen='';
+if (isset($_GET['id_cons'])) $id_cons=intval($_GET['id_cons']); else $id_cons='';
+if (isset($_GET['op'])) $op=intval($_GET['op']); else $op='';
+if (isset($_GET['id_circ'])) $id_circ=intval($_GET['id_circ']); else $id_circ='';
+if (isset($_GET['id_sez'])) $id_sez=intval($_GET['id_sez']); else $id_sez='';
+if (isset($_GET['id_sede'])) $id_sede=intval($_GET['id_sede']); else $id_sede='';
+if (isset($_GET['id_lista'])) $id_lista=intval($_GET['id_lista']); else $id_lista='';
+if (isset($_GET['valista'])) $valista=intval($_GET['valista']); else $valista='';
+if (isset($_GET['sg'])) $sg=intval($_GET['sg']); else $sg='';
+if (isset($_GET['votinulli'])) $votinulli=intval($_GET['votinulli']); else $votinulli='';
+if (isset($_GET['contestati'])) $contestati=intval($_GET['contestati']); else $contestati='';
+if (isset($_GET['update'])) $update=intval($_GET['update']); else $update='';
+if (isset($_GET['pwd3'])) $pwd3=intval($_GET['pwd3']); else $pwd3='';
+if (isset($_GET['do'])) $do=intval($_GET['do']); else $do='';
+if (isset($_GET['valista'])) $validi=intval($_GET['valista']); else $validi='0';
+if (isset($_GET['nulli'])) get_magic_quotes_gpc() ? $nulli=$_GET['nulli']:$nulli=intval($_GET['nulli']); else $nulli='';
+if (isset($_GET['bianchi'])) get_magic_quotes_gpc() ? $bianchi=$_GET['bianchi']:$bianchi=addslashes($_GET['bianchi']); else $bianchi='';
+if (isset($_GET['contestati'])) get_magic_quotes_gpc() ? $contestati=$_GET['contestati']:$contestati=addslashes($_GET['contestati']); else $contestati='';
+if (isset($_GET['votinulli'])) get_magic_quotes_gpc() ? $votinulli=$_GET['votinulli']:$votinulli=addslashes($_GET['votinulli']); else $votinulli='01-01-1900';
+if (isset($_GET['id_comune'])) $id_comune=intval($_GET['id_comune']); else $id_comune='';
+if (isset($_GET['ops'])) $ops=intval($_GET['ops']); else $ops='';
+if (isset($_GET['delete'])) $delete=intval($_GET['delete']); else $delete='';
+if (isset($_GET['circo'])) get_magic_quotes_gpc() ? $circo=$_GET['circo']:$circo=addslashes($_GET['circo']); else $circo='';
+
+global $prefix,$id_parz,$fileout;
+if($id_lista){
+	$sql="select num_cand from ".$prefix."_ele_candidati where id_cons='$id_cons' and id_lista='$id_lista' ORDER BY num_cand  ";
+	$result = $dbi->prepare("$sql");
+	$result->execute();
+	while(list($i)=$result->fetch(PDO::FETCH_BOTH)) {
+		$vot="voti$i";$cand="id_cand$i";
+		if (isset($_GET[$cand])) $idcand[$i]=intval($_GET[$cand]); else $idcand[$i]='0';
+		if (isset($_GET[$vot])) $voti[$i]=intval($_GET[$vot]); else $voti[$i]='0';
+	#	if (isset($_GET[$solo])) $solog[$i]=intval($_GET[$solo]); else $solog[$i]='0';
+
+	}
+}else{
+	$sql="select num_lista from ".$prefix."_ele_lista where id_cons='$id_cons' ORDER BY num_lista  ";
+	$result = $dbi->prepare("$sql");
+	$result->execute();
+	$sololiste=0;
+	while(list($i)=$result->fetch(PDO::FETCH_BOTH)) {
+		$vot="voti$i";$vnp="vnpl$i";$slp="slpl$i";$idlist="id_lista$i";
+		if (isset($_GET[$vnp])) $vnpl[$i]=intval($_GET[$vnp]); else $vnpl[$i]='0';
+		if (isset($_GET[$vot])) $voti[$i]=intval($_GET[$vot]); else $voti[$i]='0';
+		if (isset($_GET[$slp])) $slpl[$i]=intval($_GET[$slp]); else $slpl[$i]='0';
+		if (isset($_GET[$idlist])) $idlista[$i]=intval($_GET[$idlist]); else $idlista[$i]='0';
+		$sololiste+=$slpl[$i];
+	}	
+}
+if (!isset($fileout)) $fileout='';
+#if(($voti_u+$voti_d) and !$voti_t) $voti_t=$voti_u+$voti_d;
+if ($fileout) while (!$fp = fopen($fileout,"a"));
+
+##################
+# if($id_lista){
+	if($pwd3==1) {
+		$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="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();
+	}elseif($id_lista){
+		$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){ 
+		}
+		foreach($idcand as $idkey=>$idc){
+			
+			$sql="select num_cand from ".$prefix."_ele_voti_candidati where id_sez='$id_sez' and id_cand='$idc'";
+			$result = $dbi->prepare("$sql");
+			$result->execute();
+			if($result->rowCount()) 
+				$sql="update ".$prefix."_ele_voti_candidati set voti='".$voti[$idkey]."' where id_sez='$id_sez' and id_cand='$idc'";
+			else
+				$sql="insert into ".$prefix."_ele_voti_candidati values('$id_cons','$idc','$id_sez','$idkey','".$voti[$idkey]."')";
+			$result = $dbi->prepare("$sql");
+			$result->execute();
+		}
+	}else{
+			$sql="update  ".$prefix."_ele_sezioni set validi_lista='$validi',contestati_lista='$contestati',voti_nulli_lista='$votinulli',solo_gruppo='$sg',solo_lista='' where id_cons='$id_cons' and id_sez='$id_sez'";
+			$res = $dbi->prepare("$sql");
+			$res->execute();
+			$sql="select num_lista,id_lista from ".$prefix."_ele_voti_lista where id_cons='$id_cons' and id_sez='$id_sez'";
+			$result = $dbi->prepare("$sql");
+			$result->execute();
+			if($result->rowCount()){
+				$sql="select num_lista,id_lista from ".$prefix."_ele_lista where id_cons='$id_cons'";
+				$result = $dbi->prepare("$sql");
+				$result->execute();
+				while(list($i,$idl)=$result->fetch(PDO::FETCH_NUM)){
+					$sql="update ".$prefix."_ele_voti_lista set num_lista='$i',voti='".$voti[$i]."',nulli_lista='".$vnpl[$i]."',solo_lista='".$slpl[$i]."' where num_lista='$i' and id_sez='$id_sez'";
+					$res = $dbi->prepare("$sql");
+					$res->execute();
+				}
+				
+			}else{
+				
+				$sql="select num_lista,id_lista from ".$prefix."_ele_lista where id_cons='$id_cons'";
+				$result = $dbi->prepare("$sql");
+				$result->execute();
+				while(list($i,$idl)=$result->fetch(PDO::FETCH_NUM)){
+					$sql="insert into  ".$prefix."_ele_voti_lista values('$id_cons','$idl','$id_sez','$i','".$voti[$i]."','".$vnpl[$i]."','".$slpl[$i]."')";
+					$res = $dbi->prepare("$sql");
+					$res->execute();
+				}
+			}
+	}
+
+
+
+
+controllo_votil($id_cons,$id_sez,$id_lista);
+
+if ($fileout) fclose($fp);
+$BASE=substr($_SERVER['PHP_SELF'], 0, strrpos($_SERVER['REQUEST_URI'], "/")-16);
+Header("Location: ".$BASE."admin.php?op=voti&id_cons_gen=$id_cons_gen&id_circ=$id_circ&id_sede=$id_sede&id_sez=$id_sez&do=spoglio&ops=$ops");
+#################################
+
+
+
+
+	
+function controllo_votil($id_cons,$id_sez,$id_lista){
+	global $prefix,$dbi,$id_sede,$id_cons_gen;
+		##############################
+	$sql="select * from ".$prefix."_ele_controllosez where id_cons='$id_cons' and id_sez='$id_sez'";
+	$resc = $dbi->prepare("$sql");
+	$resc->execute();
+	$conta=$resc->rowCount();
+	$err=0; $err2=0;
+	if($id_lista){
+		$sql="SELECT preferenze FROM ".$prefix."_ele_cons_comune where id_cons='$id_cons'";
+		$res = $dbi->prepare("$sql");
+		$res->execute();
+		list($prefs)=$res->fetch(PDO::FETCH_NUM);
+		$sql="select voti from ".$prefix."_ele_voti_lista where id_lista='$id_lista' and id_sez='$id_sez'";
+		$res = $dbi->prepare("$sql");
+		$res->execute();
+		list($votil)=$res->fetch(PDO::FETCH_NUM);
+		$sql="SELECT sum(voti),max(voti) FROM ".$prefix."_ele_voti_candidati where id_sez='$id_sez' and id_cand in (select id_cand from ".$prefix."_ele_candidati where id_lista='$id_lista')";
+		$res = $dbi->prepare("$sql");
+		$res->execute();
+		list($votic,$mvc)=$res->fetch(PDO::FETCH_NUM);
+		if(($votic*$prefs)>$votil || $mvc>$votil) 
+			$err=1;
+	}else{
+		$sql="select id_gruppo from ".$prefix."_ele_lista where id_lista='$id_lista'";
+		$res = $dbi->prepare("$sql");
+		$res->execute();
+		list($idg)=$res->fetch(PDO::FETCH_NUM);
+		$sql="SELECT id_gruppo, voti, solo_gruppo FROM ".$prefix."_ele_voti_gruppo where id_sez='$id_sez'";
+		$resref = $dbi->prepare("$sql");
+		$resref->execute();
+		while (list($idg,$votig,$svg)=$resref->fetch(PDO::FETCH_NUM)) {
+			$sql="SELECT sum(voti), sum(solo_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='$idg')";
+			$res2 = $dbi->prepare("$sql");
+			$res2->execute();
+			if($res2->rowCount()){
+				list($votil,$svl)=$res2->fetch(PDO::FETCH_NUM); 
+				if(($votig+$svl)!=($votil+$svg)) 
+					$err=1;include("if(($votig+$svl)!=($votil+$svg))");
+			}
+		}	
+
+	}
+	$sql="select * from ".$prefix."_ele_controllosez where id_cons='$id_cons' and id_sez='$id_sez'";
+	$resc = $dbi->prepare("$sql");
+	$resc->execute();
+	$aff=$resc->fetch(PDO::FETCH_BOTH);
+	if($id_lista) {$cur=$aff['stato_lis']; $campo='stato_can';} else {$curr=$aff['stato_can']; $campo='stato_lis';}
+	if($aff['status']) {
+		if ($aff['stato_aff'] ||$curr || $aff['stato_gru'] || $aff['stato_val']) {
+			$sql="update ".$prefix."_ele_controllosez set $campo='$err' where id_cons='$id_cons' and id_sez='$id_sez'";
+			$res = $dbi->prepare("$sql");include("$sql");
+			$res->execute();
+		}else{
+			$sql="update ".$prefix."_ele_controllosez set $campo='$err',status='$err' where id_cons='$id_cons' and id_sez='$id_sez'";
+			$res = $dbi->prepare("$sql");
+			$res->execute();
+		}
+		
+	}
+	if($err || $aff['status'])
+		$sql="UPDATE ".$prefix."_ele_sezioni set colore='style=\" background: #FF3300;' where id_cons='$id_cons' and id_sez='$id_sez'"; #ROSSO
+	else {
+		$col="#F0E68C;";
+		$sql="select id_cand from ".$prefix."_ele_voti_candidati where id_sez='$id_sez' group by id_cand";
+		$res = $dbi->prepare("$sql");
+		$res->execute();
+		$vv=$res->rowCount();
+		$sql="select id_cand from ".$prefix."_ele_candidati where id_cons='$id_cons'";
+		$res = $dbi->prepare("$sql");
+		$res->execute();
+		$vvt=$res->rowCount();
+		if($vvt=$vv) $col="#32CD32;"; #"LIMEGREEN" colore se finito l'inserimento dei voti ai candidati 
+		else{
+			$sql="select id_lista from ".$prefix."_ele_voti_lista where id_sez='$id_sez' group by id_lista";
+			$res = $dbi->prepare("$sql");
+			$res->execute();
+			$vv=$res->rowCount();
+			$sql="select id_lista from ".$prefix."_ele_lista where id_cons='id_cons'";
+			$res = $dbi->prepare("$sql");
+			$res->execute();
+			$vvt=$res->rowCount();
+			if($vvt=$vv) $col="#F0E68C;"; #"KHAKY" colore se finito l'inserimento dei voti alle liste			
+		}
+		$sql="UPDATE ".$prefix."_ele_sezioni set colore='style=\" background: $col' where id_cons='$id_cons' and id_sez='$id_sez'"; 
+	}
+	$res = $dbi->prepare("$sql");
+	$res->execute();
+	
+}
+
+?>
Index: trunk/sql/README.txt
===================================================================
--- trunk/sql/README.txt	(revision 257)
+++ trunk/sql/README.txt	(revision 258)
@@ -66,2 +66,18 @@
 - widget.sql
 _________________________________
+
+...... saltiamo in avanti - descrizione del nuovo controllo di congruitÃ  in ele 3.0
+
+cambiato il controllo dello stato dei voti:
+1) nuova tabella in cui registrare lo stato di errore, l'inserimento corretto non viene registrato
+2) lo stato di errore viene registrato con l'id della sezione, il nome del tipo di inserimento (affluenze, votanti, referendum, gruppi, liste, candidati) e l'id del record (id_parz, id_sez, id_gruppo, id_gruppo, id_lista, id_cand)
+3) in fase di inserimento si fa il controllo se c'Ãš errore si inserisce un record
+4) in fase di update si fa il controllo e si verifica la presenza del record di errore:
+- se c'Ãš errore ed Ãš giÃ  presente record di errore non fa nulla
+- se c'Ãš errore e non Ãš presente record di errore lo inserisce
+- se non c'Ãš errore e c'Ãš record di errore lo cancella
+- se non c'Ãš errore e non c'Ãš record di errore non fa nulla
+5) in fase di delete cancella il record di errore se esiste
+
+I controlli per i colori cercano il record, se lo trovano assegnano il rosso altrimenti continuano normalmente
+Stop
