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!)
