Index: trunk/admin/admin.php
===================================================================
--- trunk/admin/admin.php	(revision 359)
+++ trunk/admin/admin.php	(revision 360)
@@ -139,5 +139,5 @@
 
 	try{
-	$dbi = new PDO("mysql:host=$dbhost;charset=latin1", $dbuname, $dbpass, array(PDO::ATTR_EMULATE_PREPARES => false, PDO::ATTR_ERRMODE=>PDO::ERRMODE_EXCEPTION)); 
+	$dbi = new PDO("mysql:host=$dbhost;charset=utf8", $dbuname, $dbpass, array(PDO::ATTR_EMULATE_PREPARES => false, PDO::ATTR_ERRMODE=>PDO::ERRMODE_EXCEPTION)); 
      	$sql = "use $dbname";
     	$dbi->exec($sql);
@@ -147,6 +147,18 @@
 	    echo $sql . "<br>" . $e->getMessage();
 	}                                                                                       	
-
-
+	$sth = $dbi->prepare("SET SESSION character_set_connection = 'utf8' ");
+	$sth->execute();
+	$sth = $dbi->prepare("SET SESSION character_set_client = 'utf8' ");
+	$sth->execute();
+	$sth = $dbi->prepare("SET SESSION character_set_database = 'utf8' ");
+	$sth->execute();
+	$sth = $dbi->prepare("SET CHARACTER SET utf8");
+	$sth->execute();
+
+	$sth = $dbi->prepare("SET NAMES 'utf8'");
+	$sth->execute();
+	$sth = $dbi->prepare("select * from ".$prefix."_config");
+	$sth->execute();
+	
 #		$dbi=mysql_connect($dbhost, $dbuname, $dbpass) or die("Connessione non riuscita: " . mysql_error());
 #		mysql_select_db($dbname)or die("Connessione non riuscita:" . mysql_error());
@@ -264,15 +276,23 @@
 $id_comune=$_SESSION['id_comune'];
 if($id_comune==0) $rifcomune='58047'; else $rifcomune=$id_comune;
-if (isset($_GET['id_cons_gen'])) $id_cons_gen=intval($_GET['id_cons_gen']);
+if (isset($_GET['id_cons_gen'])) {$id_cons_gen=intval($_GET['id_cons_gen']);}
 else {
-			$sql="SELECT t1.id_cons_gen FROM ".$prefix."_ele_cons_comune as t1, ".$prefix."_ele_comuni as t2 where t1.id_cons=t2.id_cons and  t2.id_comune='$id_comune'";
-			$sth = $dbi->prepare($sql);
-			$sth->execute();	
-			$row = $sth->fetch(PDO::FETCH_BOTH);
-			if($sth->rowCount())
-				$id_cons_gen=$row[0];
-			else
-			$id_cons_gen=0; #die("TEST IN CORSO : idconsgen: $id_cons_gen -- sql:select id_cons_gen  from ".$prefix."_ele_cons_comune where preferita='1' and (id_comune='$id_comune' or id_comune=0)");
-}
+	$oggi=date("Y-m-d",mktime(0,0,0,date("m"),date("d")-3,date("Y")));
+	$sql="select t1.id_cons_gen from ".$prefix."_ele_consultazione as t1, ".$prefix."_ele_cons_comune as t2 where t1.id_cons_gen=t2.id_cons_gen and t2.id_comune=$id_comune and t1.data_fine>'$oggi' and t2.id_cons in (select id_cons from ".$prefix."_ele_operatori where aid='$aid' and id_sez>0 and permessi>0) limit 0,1";
+	$rese = $dbi->prepare("$sql");
+	$rese->execute();
+	if($rese->rowCount()) 
+	{list($id_cons_gen)=$rese->fetch(PDO::FETCH_NUM); }
+	else {
+		$sql="SELECT t1.id_cons_gen FROM ".$prefix."_ele_cons_comune as t1, ".$prefix."_ele_comuni as t2 where t1.id_cons=t2.id_cons and  t2.id_comune='$id_comune'";
+		$sth = $dbi->prepare($sql);
+		$sth->execute();	
+		$row = $sth->fetch(PDO::FETCH_BOTH);
+		if($sth->rowCount())
+			$id_cons_gen=$row[0];
+		else
+		$id_cons_gen=0; #die("TEST IN CORSO : idconsgen: $id_cons_gen -- sql:$sql");
+	}
+} 
 $currentlang=$_SESSION['lang'];
 #$bgcolor1=$_SESSION['bgcolor1'];
@@ -281,6 +301,6 @@
 $session=$_SESSION['remote'];
 
-$perms=ChiSei($id_cons_gen);
-if($perms==0) logout();
+$perms=ChiSei($id_cons_gen); #die("qui".$_SESSION['aid']);
+if($perms==0) {logout();} 
 }
 
@@ -296,5 +316,4 @@
 $pwd=$_SESSION['pwd'];
 $id_comune=$_SESSION['id_comune'];
-
 
 $perms=0;
@@ -325,4 +344,5 @@
 		if($row[0]==0) $msglogout=1;
 	if ($sth->rowCount()==1) $perms=$row[0]; else {	$msglogout=1; $perms=0; }
+
 	return $perms;
 #} else return 0;
@@ -404,4 +424,5 @@
         Header("Location: admin.php?id_comune=$id_comune&language=$lang");
 */
+
 global $siteistat,$perms,$msglogout; 
 $language=$_SESSION['lang'];
@@ -432,14 +453,24 @@
 		$sth = $dbi->prepare("$sql");
 		$sth->execute();	
-		if ($sth->rowCount()) list($id_cons) = $sth->fetch(PDO::FETCH_NUM);
-		$_SESSION['id_cons']=$id_cons;
+		if ($sth->rowCount()) {
+			list($id_cons) = $sth->fetch(PDO::FETCH_NUM);
+			$_SESSION['id_cons']=$id_cons;
+		}
 	} 
 	if(isset($id_cons)) {
-		$sql="SELECT id_sez FROM ".$prefix."_ele_operatori where id_cons=$id_cons and aid='$aid' and id_comune=$id_comune";
+		$sql="SELECT id_sez FROM ".$prefix."_ele_operatori where id_sez>0 and aid='$aid' and id_comune=$id_comune";
 		$resmod = $dbi->prepare("$sql");
 		$resmod->execute();				
-		list($id_sez) = $resmod->fetch(PDO::FETCH_NUM);
-		if($id_sez) $tema='Futura2';#die( "TEST id_cons:$id_cons:");
-		$_SESSION['tema']=$tema;
+		list($id_sez) = $resmod->fetch(PDO::FETCH_NUM); #die("qui:$id_sez:$sql");
+		if($id_sez) { 
+			$oggi=date("Y-m-d",mktime(0,0,0,date("m"),date("d")-3,date("Y")));
+			$sql="select t1.id_cons_gen,t1.descrizione,t2.id_cons from ".$prefix."_ele_consultazione as t1, ".$prefix."_ele_cons_comune as t2 where t1.id_cons_gen=t2.id_cons_gen and t2.id_comune=$id_comune and t1.data_fine>'$oggi' and t2.id_cons in (select id_cons from ".$prefix."_ele_operatori where aid='$aid' and id_sez>0 and permessi>0)";
+			$resmod = $dbi->prepare("$sql");
+			$resmod->execute();
+			if ($resmod->rowCount()>0) {
+				$tema='Futura2'; #die( "TEST id_cons:$id_cons:".$_SESSION['aid']);
+				$_SESSION['tema']=$tema;
+			} else logout();
+		}
 	}
 }
@@ -449,5 +480,6 @@
 if (isset($param['op'])) $op=addslashes($param['op']); else $op='ele';
 //if (isset($param['op'])) $op=$param['op']; else $op='ele';
-#die( "OP: $op");
+#
+#die("TEST: qui $aid $id_cons $id_sez ".$_SESSION['aid']);
 if (isset($_SESSION['aid']) AND $_SESSION['remote']==$_SERVER['REMOTE_ADDR']) {
 	if($tema=='Futura2' and $op!='logout') 
Index: trunk/admin/aggiornadb.php
===================================================================
--- trunk/admin/aggiornadb.php	(revision 359)
+++ trunk/admin/aggiornadb.php	(revision 360)
@@ -80,5 +80,5 @@
 
 
-$num=0;
+
 
 function controllo($tabella,$campo,$num)
@@ -93,7 +93,5 @@
 }
 
-$sql="SELECT * FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = '$dbname' AND COLUMN_NAME = 'Versione'";	
-$res = $dbi->prepare("$sql");
-$res->execute();			
+$num=0;		
 
 if(!controllo($prefix.'_config','versione',++$num))
Index: trunk/admin/header.php
===================================================================
--- trunk/admin/header.php	(revision 359)
+++ trunk/admin/header.php	(revision 360)
@@ -62,4 +62,5 @@
     echo "<html>\n";
     echo "<head>\n";
+#	echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso8859-1\">\n";
 	echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\n";
 	echo "<meta http-equiv=\"Pragma\" content=\"no-cache\">\n";
Index: trunk/admin/modules/Elezioni/ele_candidato.php
===================================================================
--- trunk/admin/modules/Elezioni/ele_candidato.php	(revision 359)
+++ trunk/admin/modules/Elezioni/ele_candidato.php	(revision 360)
@@ -283,9 +283,10 @@
  	    		}else{
 				$pro= $sthcan->fetch(PDO::FETCH_BOTH);
+				$dati = htmlentities($_pro['cognome'], ENT_QUOTES, "UTF-8");
 				$sql="delete from ".$prefix."_ele_candidati where id_cand='$id_cand'";
 				$sth = $dbi->prepare("$sql");
 				$sth->execute();
 				$result=$sth->rowCount();
-				$sql="insert into ".$prefix."_ele_log values ('$id_cons','$id_sez','$username','$data','$tempo','DELETE:id_lista:$pro[id_lista],cognome:$pro[cognome],nome:$pro[nome]','','".$prefix."_ele_candidati')";
+				$sql="insert into ".$prefix."_ele_log values ('$id_cons','$id_sez','$username','$data','$tempo','DELETE:id_lista:$pro[id_lista],cognome:$dati,nome:$codifica:$pro[nome]','','".$prefix."_ele_candidati')";
 				$sth = $dbi->prepare("$sql");
 				$sth->execute();
Index: trunk/admin/modules/Elezioni/ele_controlli.php
===================================================================
--- trunk/admin/modules/Elezioni/ele_controlli.php	(revision 359)
+++ trunk/admin/modules/Elezioni/ele_controlli.php	(revision 360)
@@ -16,10 +16,17 @@
 	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+$voti_d>0) || $voti_u>$maschi || $voti_d>$femmine || $voti_t>$maschi+$femmine) ) {$err=1; break;}
-
+	$sql="select voti_uomini,voti_donne,voti_complessivi,id_gruppo from ".$prefix."_ele_voti_parziale where id_sez='$id_sez' order by id_gruppo,data,orario";
+	$res = $dbi->prepare("$sql");
+	$res->execute();
+	$votiu2=0;$votid2=0;$votit2=0;$idg2=-1;
+	while(list($voti_u,$voti_d,$voti_t,$idg)=$res->fetch(PDO::FETCH_NUM)) {
+		if($idg2!=$idg) {
+			$votiu2=0;$votid2=0;$votit2=0;
+			$idg2=$idg;
+		}
+		if((($voti_u+$voti_d!=$voti_t && $voti_u+$voti_d>0) || $voti_u>$maschi || $voti_d>$femmine || $voti_t>$maschi+$femmine ||$voti_u<$votiu2 ||$voti_d<$votid2 || $voti_t<$votit2) ) {
+			$err=1; break;}
+		$votiu2=$voti_u;$votid2=$voti_d;$votit2=$voti_t;
+	}
 	$tipo='affluenze';
 	$sql="select id from ".$prefix."_ele_controlli where tipo='$tipo' and id_sez='$id_sez' ";
@@ -28,8 +35,8 @@
 	$righe=$res->rowCount();
 	if($righe){
-		while(list($id)=$res->fetch(PDO::FETCH_NUM)){
-			if($id==$id_parz){
+		while(list($id)=$res->fetch(PDO::FETCH_NUM)){#die("$sql");
+#			if($id==$id_parz){
 				if(!$err){ 
-					$sql="delete from ".$prefix."_ele_controlli where tipo='$tipo' and id='$id_parz' ";
+					$sql="delete from ".$prefix."_ele_controlli where tipo='$tipo' and id_sez='$id_sez' ";
 					$res = $dbi->prepare("$sql");
 					$res->execute();
@@ -38,9 +45,9 @@
 				$err=0;
 				break;
-			}					
+#			}					
 		}
 	}
 	if($err){
-		$sql="insert into ".$prefix."_ele_controlli value('$id_cons','$id_sez','$tipo','$id_parz')";
+		$sql="insert into ".$prefix."_ele_controlli value('$id_cons','$id_sez','$tipo','$idg2')";#die("$sql");
 		$res = $dbi->prepare("$sql");
 		$res->execute();		
@@ -141,11 +148,11 @@
 		##############################
 	$err=0; $err2=0;
-	$sql="SELECT id_gruppo FROM ".$prefix."_ele_gruppo where id_cons='$id_cons'";
+	$sql="SELECT id_gruppo FROM ".$prefix."_ele_gruppo where id_cons='$id_cons'"; 
 	$resref = $dbi->prepare("$sql");
 	$resref->execute();	
-	$sql="SELECT sum(voti) FROM ".$prefix."_ele_voti_gruppo where id_sez='$id_sez'";
+	$sql="SELECT sum(voti),count(voti) FROM ".$prefix."_ele_voti_gruppo where id_sez='$id_sez'";
 	$resref = $dbi->prepare("$sql");
 	$resref->execute();
-	list($votig)=$resref->fetch(PDO::FETCH_NUM);
+	list($votig,$numrec)=$resref->fetch(PDO::FETCH_NUM);
 	$sql="SELECT max(voti_complessivi) FROM ".$prefix."_ele_voti_parziale where id_sez='$id_sez'";
 	$res3 = $dbi->prepare("$sql");
@@ -156,5 +163,5 @@
 	$res2->execute();
 	list($validi) = $res2->fetch(PDO::FETCH_NUM);
-	if($validi) {
+	if($validi and $numrec) {
 		$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'";
@@ -382,5 +389,5 @@
 
 		if(!$err){ 
-			$sql="delete from ".$prefix."_ele_controlli where tipo='lista' and id_sez='$id_sez' "; 
+			$sql="delete from ".$prefix."_ele_controlli where tipo='lista' and id_sez='$id_sez' and id='$id_lista'"; 
 			$res = $dbi->prepare("$sql");
 			$res->execute();
@@ -388,5 +395,5 @@
 
 	if($err){
-		$sql="select * from ".$prefix."_ele_controlli where tipo='lista' and id_sez='$id_sez' "; 
+		$sql="select * from ".$prefix."_ele_controlli where tipo='lista' and id_sez='$id_sez' and id='$id_lista'"; 
 		$res = $dbi->prepare("$sql");
 		$res->execute();
@@ -395,5 +402,5 @@
 			$sql="insert into ".$prefix."_ele_controlli value('$id_cons','$id_sez','$tipo','$id_lista')";
 			$res = $dbi->prepare("$sql");
-			$res->execute();	
+			$res->execute();	#die("TEST $sql");
 		}
 	}
Index: trunk/admin/modules/Elezioni/ele_lista.php
===================================================================
--- trunk/admin/modules/Elezioni/ele_lista.php	(revision 359)
+++ trunk/admin/modules/Elezioni/ele_lista.php	(revision 360)
@@ -26,8 +26,8 @@
 include("modules/Elezioni/funzionidata.php");
 include("modules/Elezioni/ele.php");
-if (isset($param['mex'])) $mex=addslashes($param['mex']); else $mex='';
-if (isset($param['do'])) $do=addslashes($param['do']); else $do='';
+if (isset($param['mex'])) $mex=htmlentities($param['mex'], ENT_QUOTES, "UTF-8"); else $mex='';
+if (isset($param['do'])) $do=htmlentities($param['do'], ENT_QUOTES, "UTF-8"); else $do='';
 if (isset($param['min'])) $min=intval($param['min']); else $min=0;
-if (isset($param['ok'])) $ok=addslashes($param['ok']); else $ok='';
+if (isset($param['ok'])) $ok=htmlentities($param['ok'], ENT_QUOTES, "UTF-8"); else $ok='';
 if (isset($param['id_lista'])) $id_lista=intval($param['id_lista']); else $id_lista=0;
 if (isset($param['id_circ'])) {$id_circ=intval($param['id_circ']); $_SESSION['id_circ']=$id_circ;} else
@@ -36,4 +36,5 @@
 if (isset($param['id_gruppo2'])) $id_gruppo2=intval($param['id_gruppo2']); else $id_gruppo2=0;
 if (isset($param['num_lista'])) $num_lista=intval($param['num_lista']); else $num_lista=0;
+#if (isset($param['descr_lista'])) $descr_lista=htmlentities($param['descr_lista']); else $descr_lista='';
 if (isset($param['descr_lista'])) $descr_lista=addslashes($param['descr_lista']); else $descr_lista='';
 if (isset($param['simbolo'])) $simbolo=addslashes($param['simbolo']); else $simbolo='';
@@ -268,9 +269,10 @@
 		$stemmacontents = fread ($fdstemma, filesize ("$filestemma"));
 		fclose ($fdstemma);
-		$stemmablob=addslashes($stemmacontents);
-		$stemmanome=addslashes($nomestemma);
+		$stemmablob=addslashes($stemmacontents); 
+		$stemmanome=($nomestemma);
 		$cond=", simbolo='$stemmanome', stemma='$stemmablob'";
 		} else {$cond='';}
 		$sql="update  ".$prefix."_ele_lista set  num_lista='$num_lista' , id_gruppo='$id_gruppo',descrizione='$descr_lista' $cond  where id_lista='$id_lista'";
+#die("TEST: $sql");		
 		$result = $dbi->prepare("$sql");
 		$result->execute();						
Index: trunk/admin/modules/Elezioni/ele_spoglio.php
===================================================================
--- trunk/admin/modules/Elezioni/ele_spoglio.php	(revision 360)
+++ trunk/admin/modules/Elezioni/ele_spoglio.php	(revision 360)
@@ -0,0 +1,1052 @@
+<?php
+/************************************************************************/
+/* Eleonline - Raccolta e diffusione dei dati elettorali                */
+/* by Luciano Apolito & Roberto Gigli                                   */
+/* http://www.eleonline.it                                              */
+/* info@eleonline.it  luciano@aniene.net rgigli@libero.it               */
+/************************************************************************/
+
+if (!defined('ADMIN_FILE')) {
+    die ("You can't access this file directly...");
+}
+
+########################################
+# Affluenze
+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,$id_comune,$ops;
+##################
+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>";
+
+
+##################
+$bgcolor1="#7777ff";
+$bgcolor2=$_SESSION['bgcolor2'];
+$sql="SELECT vismf from ".$prefix."_ele_cons_comune where id_cons='$id_cons'";
+$res = $dbi->prepare("$sql");
+$res->execute();
+if($res) list($vismf)= $res->fetch(PDO::FETCH_NUM); else $vismf=0;
+$sql="SELECT orario,data FROM ".$prefix."_ele_rilaff where id_cons_gen=$id_cons_gen order by data,orario ";
+$res = $dbi->prepare("$sql");
+$res->execute();
+$num = $res->rowCount();
+echo "<table><tr><td>";
+$sql="SELECT maschi,femmine FROM ".$prefix."_ele_sezioni where id_sez=$id_sez";#echo $sql;
+$ressez = $dbi->prepare("$sql");
+$ressez->execute();
+list($maschi,$femmine)=$ressez->fetch(PDO::FETCH_NUM);
+
+$afferr=0;
+$sql="select tipo from ".$prefix."_ele_controlli where id_sez='$id_sez' and tipo='affluenze'";
+$rese = $dbi->prepare("$sql");
+$rese->execute();
+if($rese->rowCount()) $afferr=1;
+
+$y=0;
+
+$riga=array();
+$rigat=array();
+while (list($ora,$giorno)= $res->fetch(PDO::FETCH_NUM)){
+	$y++;
+	$rigat[$y]='';
+	$riga[$y]='';
+	$rigat[$y]= "<div class=\"tr\">";
+	if ($genere==0){ //e' un referendum 
+		$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'  ";
+		$res2 = $dbi->prepare("$sql");
+		$res2->execute();
+		$max = $res2->rowCount();
+	}else{ $max=1;} 
+	$op="rec_add_votanti";
+	$rigat[$y].= "</div>";
+	$errvot1=0;
+	for ($i=1;$i<=$max;$i++){
+		$query="SELECT * FROM ".$prefix."_ele_voti_parziale as t1 left join ".$prefix."_ele_gruppo as t2 
+		on (t1.id_gruppo=t2.id_gruppo) where t1.id_sez='$id_sez' 
+		and t1.id_cons='$id_cons' and t1.orario='$ora' and t1.data='$giorno'";
+		if ($genere==0){
+			$query.=" and t2.num_gruppo=$i";
+		}
+		$sql=$query;
+		$result = $dbi->prepare("$sql");
+		$result->execute();
+		list($id_cons2,$id_sez2,$id_parz,$orario,$data, $voti_u, $voti_d, $voti_t,$id_gruppo) = $result->fetch(PDO::FETCH_NUM);
+	   	$sql="SELECT num_gruppo FROM ".$prefix."_ele_gruppo where id_gruppo='$id_gruppo' ";
+		$res2 = $dbi->prepare("$sql");
+		$res2->execute();
+		$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();
+        list($numril)=$resril->fetch(PDO::FETCH_NUM);
+		if ($res2)
+			list($gruppo)= $res2->fetch(PDO::FETCH_NUM);
+		else
+			$gruppo=0;
+		if (!$gruppo>0) {
+			$gruppo=$i;
+			$sql="SELECT id_gruppo FROM ".$prefix."_ele_gruppo where num_gruppo=$gruppo and id_cons=$id_cons";
+			$res3 = $dbi->prepare("$sql");
+			$res3->execute();
+			if ($res3)
+			list($id_gruppo)=$res3->fetch(PDO::FETCH_NUM);
+		}
+		if(!isset($precede[$id_gruppo])) $precede[$id_gruppo]=0; if(!isset($error)) $error=0;
+		if($precede[$id_gruppo]>($voti_t) and $voti_t!='') $error=1;
+		$precede[$id_gruppo]=$voti_t;
+		if (($voti_u+$voti_d and $voti_u+$voti_d!=$voti_t) or $error){
+			$riga[$y].= "<form class=\"tr\"  data-ajax=\"false\" style=\"background-color: rgb(255, 0, 0); text-align: center\" name=\"votanti\" action=\"modules/Elezioni/salva_aff.php\">";
+		}else{
+			$riga[$y].= "<form class=\"tr\" data-ajax=\"false\" action=\"modules/Elezioni/salva_aff.php\">";
+		}
+		if ($genere==0){ // e' un referendum
+			$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=\"genere\" value=\"$genere\"/>"
+		."<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\"/>"; 
+        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\">"; $errvot1=1;}
+		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\" onfocus=\"select();\"";
+		$riga[$y].= " size=\"5\"/></span>";
+		if ($voti_d > $femmine) {$riga[$y].= "<span class=\"td\" align=\"center\" bgcolor=\"red\">"; $errvot1=1;}
+		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\" onfocus=\"select();\"";
+		$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\" onfocus=\"select();\"/>"; $errvot1=1;}
+		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\" onfocus=\"select();\"/>";
+		$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 "</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");
+		$compl->execute();
+		list ($complessivi)= $compl->fetch(PDO::FETCH_NUM);
+	}
+#	echo "Errori:";
+	if($errvot1) echo "<table><tr><td align=\"center\" bgcolor=\"red\"> <h1 style=\"color:white;\">I votanti inseriti superano il numero di elettori</h1></td></tr></table></br>";
+	if($error) echo "<table><tr><td align=\"center\" bgcolor=\"red\"> <h1 style=\"color:white;\">Numero di votanti inferiore della rilevazione precedente</h1></td></tr></table></br>";
+	echo "<table border=\"1\"><tr><td><b>Iscritti nella sezione</b> Maschi: $maschi - Femmine: $femmine - Totale: ".($maschi+$femmine)."</td></tr></table></br>"; 
+	foreach($riga as $key=>$val){
+		echo $rigat[$key];
+		echo $riga[$key];
+	}
+	echo "</div></td></tr></table>";
+}
+
+
+//////////////////////////////////////////////////////////////////////
+// da qui va la sezione per le preferenze candidati consiglieri
+//////////////////////////////////////////////////////////////////////
+function preferenze($id_cons,$do,$id_circ,$id_sede,$id_sez,$ops){
+ 	global $aid, $prefix, $dbi, $id_lista,$genere,$id_cons_gen,$id_gruppo,$sezi,$circo,$votog,$votol,$votoc,$conscirc,$op;
+global $tipo_cons,$limite,$dettnulli,$disgiunto,$votoc;
+$bgcolor1="#7777ff";
+$bgcolor2=$_SESSION['bgcolor2'];
+echo "<SCRIPT type=\"text/javascript\">\n";
+echo "function vai_lista(idrif){\n";
+echo "var element=document.getElementById('pag')\n";
+echo "var elista=document.getElementById(idrif)\n";
+echo "var url=element.value+elista.value\n";
+echo "window.document.location.href=url \n";
+echo "}\n";
+echo "</script>\n"; 
+if ($genere==4){
+	$sql="SELECT voti_uomini,voti_donne, voti_complessivi FROM ".$prefix."_ele_voti_parziale where id_sez='$id_sez' and id_cons='$id_cons' order by data desc,orario desc limit 0,1";
+	$result = $dbi->prepare("$sql");
+	$result->execute();
+
+
+	list( $voti_u, $voti_d, $voti_t) = $result->fetch(PDO::FETCH_NUM);
+	echo "<table  class=\"table-menu\" style=\"width: 50%; color: black;\">"
+	."<tr><td></td><td align=\"center\"></td><td bgcolor=\"$bgcolor1\" align=\"center\">"._VOTIU."</td><td bgcolor=\"$bgcolor1\" align=\"center\">"._VOTID."</td><td bgcolor=\"$bgcolor1\" align=\"center\">"._VOTIT."</td></tr>"
+	."<tr><td></td><td bgcolor=\"$bgcolor1\" align=\"center\">"._TOT_ULT."</td><td bgcolor=\"$bgcolor2\" align=\"center\">$voti_u</td><td align=\"center\" bgcolor=\"$bgcolor2\">$voti_d</td><td bgcolor=\"$bgcolor2\" align=\"center\">$voti_t</td></tr>";
+	echo "</table>";
+}
+$sql="select validi,nulli,bianchi,contestati from ".$prefix."_ele_sezioni where id_sez='$id_sez' ";
+$result = $dbi->prepare("$sql");
+$result->execute();
+list($v1,$v2,$v3,$v4)=$result->fetch(PDO::FETCH_NUM);
+if($v1+$v2+$v3+$v4>0){
+    //controlla se sono stati inseriti i votanti
+$sql="SELECT preferenze, id_fascia, id_conf,solo_gruppo, disgiunto from ".$prefix."_ele_cons_comune where id_cons='$id_cons'";
+$result = $dbi->prepare("$sql");
+$result->execute();
+ 
+
+list($numprefs,$fascia,$id_conf,$flagsg,$disgiunto)=$result->fetch(PDO::FETCH_NUM);
+$dettnulli=$flagsg;
+####### 06-11-2014 - circoscrizionali - nello spostamento ad altra sezione resta sullo stesso numero di lista anche se sono sezioni di diverse circoscrizioni
+if ($circo and $id_lista){
+	$sql="SELECT num_lista from ".$prefix."_ele_lista where id_lista=$id_lista";
+	$res_lis = $dbi->prepare("$sql");
+	$res_lis->execute();
+	list($num_lista)=$res_lis->fetch(PDO::FETCH_NUM);
+}
+
+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");
+$result->execute();
+
+
+}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);
+		echo "<table class=\"table-menu\" style=\"width: 100%;\"><tr>";
+		$sql="SELECT id_lista, descrizione,num_lista from ".$prefix."_ele_lista where id_cons=$id_cons $circo order by num_lista";
+$res_lis = $dbi->prepare("$sql");
+$res_lis->execute();
+
+
+		$num_liste = $res_lis->rowCount();
+		$ele_lista='';
+		if (($genere==4 or $genere==5) and !$votoc) { //liste a piu' candidati
+			if(($genere==5 and $id_conf and $fascia<=$limite and !$disgiunto) and !$id_lista) { //esclude il voto di lista per le comunali nei comuni sotto fascia limite
+				$sql="SELECT id_lista from ".$prefix."_ele_lista where id_cons=$id_cons $circo order by num_lista limit 0,1";
+$result = $dbi->prepare("$sql");
+$result->execute();
+
+
+				list($id_lista)=$result->fetch(PDO::FETCH_NUM);
+			}
+			echo "<td colspan=\"2\">";
+			echo "<form name=\"liste\" data-ajax=\"false\" action=\"admin.php\">";  # data-ajax=\"false\" 
+			echo "<input type=\"hidden\" id=\"pag\" name=\"pag\" value=\"admin.php?id_cons_gen=$id_cons_gen&amp;op=$op&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 id=\"id_lista\" name=\"id_lista\" onChange=\"vai_lista('id_lista');\">";
+			if ($id_lista){
+				echo "<option value=\"0\">"._VOTI_LISTA;
+				$ele_lista=" and t1.id_lista='$id_lista' ";
+			}else{
+				echo "<option value=\"0\" selected>"._VOTI_LISTA;
+				$ele_lista=" group by t1.id_lista ";
+				if(!isset($votolista)) $votolista=0;
+			}
+			$preflis[]=array();
+			while(list($id_rif,$descrizione,$num_lis) = $res_lis->fetch(PDO::FETCH_NUM)) {
+				$segna='';
+				$sql="SELECT t1.voti from ".$prefix."_ele_voti_candidati as t1 left join ".$prefix."_ele_candidati as t2 on (t1.id_cand=t2.id_cand) where t1.id_sez=$id_sez and t2.id_lista=$id_rif limit 0,1";
+				$result = $dbi->prepare("$sql");
+				$result->execute();
+				if($result->rowCount()) $ctrvoticand=1; else $ctrvoticand=0;
+				$sql="SELECT sum(t1.voti),0,0 from ".$prefix."_ele_voti_candidati as t1 left join ".$prefix."_ele_candidati as t2 on (t1.id_cand=t2.id_cand) where t1.id_sez=$id_sez and t2.id_lista=$id_rif";
+				$result = $dbi->prepare("$sql");
+				$result->execute();
+				list($votisezcand)=$result->fetch(PDO::FETCH_NUM);
+				if((($fascia>$limite or $disgiunto) or !$id_conf) or $genere==4){
+					$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{
+					$sql="SELECT id_gruppo from ".$prefix."_ele_lista where id_lista='$id_rif'";
+					$result = $dbi->prepare("$sql");
+					$result->execute();
+					list($id_gruppo)=$result->fetch(PDO::FETCH_NUM);
+					$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);
+				$preflis[$id_rif]=$votisezlis;
+				if($votisezcand>($votisezlis*$numprefs))
+					{$segna="style=\"background-color: #dd0000;\""; }#$segna2=$segna;
+				elseif($ctrvoticand)
+					$segna="style=\"background-color: #99CC33;\"";
+				$sql="SELECT t1.voti,t2.num_cand FROM ".$prefix."_ele_voti_candidati as t1 left join ".$prefix."_ele_candidati as t2 on t1.id_cand=t2.id_cand where t1.id_cons='$id_cons' and  t1.id_sez='$id_sez' and t2.id_lista='$id_rif'";
+				$res4 = $dbi->prepare("$sql");
+				$res4->execute();
+				$errcand[$id_rif]=array();
+				while(list($testvotic,$numcand)=$res4->fetch(PDO::FETCH_NUM))
+					{if($votisezlis<$testvotic) { $segna="style=\"background-color: #dd0000;\"";$errcand[$id_rif][]=$numcand;}}
+				$sel = ($id_rif == $id_lista) ? "selected" : "";
+				echo "<option $segna value=\"$id_rif\" $sel>";
+				for ($j=strlen($num_lis);$j<2;$j++) { echo "&nbsp;&nbsp;";}
+				echo $num_lis.") ".$descrizione;
+#				echo $num_lis.") ".substr($descrizione,0,30);
+			}
+			echo "</select></form></td></tr><tr><td style=\"vertical-align: top;\">&nbsp;</td>\n";
+		}else {
+			$id_lista=0;
+		}
+		echo "<td style=\"vertical-align: top;\">";
+		if ((!$id_lista)){$tab="_ele_voti_lista";} else {$tab="_ele_voti_candidati";}
+		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,t2.contestati,0,0 from ".$prefix."_ele_sezioni as t2 left join ".$prefix.$tab." as t1 on (t1.id_sez=t2.id_sez) where t2.id_sez=$id_sez group by t1.id_sez";
+			$result = $dbi->prepare("$sql");
+			$result->execute();
+		}else{
+			$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,t1.id_sez 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,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";
+			$result = $dbi->prepare("$sql");
+			$result->execute();
+		}
+
+// aggiunte le variabili $sgpl e $vnulli2 per la gestione dei voti 1) al solo presidente per singola lista - 2) al solo presidente per singola lista perchÃ© nullo o contestato quello di lista		
+		$isscr= $result->rowCount();
+		list( $voti_sez, $validi2, $sg,$cont2,$vnulli2,$bia2,$nul2,$con2,$vnul2,$sgpl) = $result->fetch(PDO::FETCH_NUM);
+		if(($genere==5 and !$disgiunto and $voti_sez and $flagsg and ($tipo_cons==18 or $tipo_cons==19))){ 
+			$sql="SELECT sum(solo_gruppo) from ".$prefix."_ele_voti_gruppo where id_cons=$id_cons and id_sez=$id_sez";
+			$resg = $dbi->prepare("$sql");
+			$resg->execute();
+			list($sgpl)=$resg->fetch(PDO::FETCH_NUM);
+			if ($sg != $sgpl) echo "<table class=\"table-menu\" style=\"width: 50%;\"><tr><td style=\"background-color: rgb(255, 0, 0); color: black; text-align: center\"><img src=\"modules/Elezioni/images/alert.gif\" align=\"middle\" alt=\"\"><br><b> "._ATT_UNI." ".$sgpl." "._ATT_TOT_UNI." ".$sg."</b><br></td></table>";
+		}
+		$valista=$validi2;
+#######    controlli
+		$sql="select * from ".$prefix."_ele_controlli where id_cons='$id_cons' and id_sez='$id_sez' ";
+		$resc = $dbi->prepare("$sql");
+		$resc->execute();
+		if($resc->rowCount()){	
+			if(!$id_lista or $genere==3){	//controllo di congruenza
+				$sql="SELECT max(voti_complessivi) FROM ".$prefix."_ele_voti_parziale where id_cons='$id_cons' and id_sez='$id_sez'";
+				$res2 = $dbi->prepare("$sql");
+				$res2->execute();
+				list($tot) = $res2->fetch(PDO::FETCH_NUM);
+				if ($validi2+$vnulli2+$cont2+$sg+$bia2+$nul2+$con2+$vnul2!=$tot and $validi+$sg>0){
+					echo "<table class=\"table-menu\" style=\"width: 50%;\"><tr><td style=\"background-color: rgb(255, 0, 0); color: black; text-align: center\"><img src=\"modules/Elezioni/images/alert.gif\" align=\"middle\" alt=\"\"><br><b> "._ATT_VOTANTI." ".$tot." "._NO_TOT_VOTI." ".($validi2+$vnulli2+$cont2+$sg+$bia2+$nul2+$con2+$vnul2)."</b><br></td></table>";
+				}
+				if((($voti_sez)!=$validi2) and ($voti_sez>0)){
+					echo "<table class=\"table-menu\" style=\"width: 50%;\"><tr><td style=\"background-color: rgb(255, 0, 0); color: black; text-align: center\"><img src=\"modules/Elezioni/images/alert.gif\" align=\"middle\" alt=\"\"><br><b> "._ATT_VOTI." ".($voti_sez)." "._NO_VAL_VOTI." ".$validi2."</b><br></td></tr></table>";
+				}
+			}
+			if($genere==5 or $genere==4){
+				if($id_lista){
+				$sql="SELECT max(t1.voti),sum(t1.voti) from ".$prefix."_ele_voti_candidati as t1 left join ".$prefix."_ele_candidati as t2 on (t1.id_cand=t2.id_cand) where t1.id_sez=$id_sez and t2.id_lista='$id_lista'";
+				$result = $dbi->prepare("$sql");
+				$result->execute();
+				list($votimaxcand,$votisezcand)=$result->fetch(PDO::FETCH_NUM);
+				if(($fascia>$limite or $disgiunto) or !$id_conf){
+					$sql="SELECT sum(t2.voti) from ".$prefix."_ele_voti_lista as t2 where t2.id_sez='$id_sez' and t2.id_lista='$id_lista'"; 
+					$result = $dbi->prepare("$sql");
+					$result->execute();
+				}else{
+					$sql="SELECT id_gruppo from ".$prefix."_ele_lista where id_lista='$id_lista'";
+					$result = $dbi->prepare("$sql");
+					$result->execute();
+					list($id_gruppo)=$result->fetch(PDO::FETCH_NUM);
+					$sql="SELECT sum(voti) from ".$prefix."_ele_voti_gruppo where id_sez='$id_sez' and id_gruppo='$id_gruppo'";
+					$result = $dbi->prepare("$sql");
+					$result->execute();
+				}
+				list($votisezlis)=$result->fetch(PDO::FETCH_NUM);
+				$errpres=0; 
+				if($votisezcand>($votisezlis*$numprefs))
+				{
+					echo "<table class=\"table-menu\" style=\"width: 50%;\"><tr><td style=\"background-color: rgb(255, 0, 0); color: black; text-align: center\"><img src=\"modules/Elezioni/images/alert.gif\" align=\"middle\" alt=\"\"><br/><b> ATTENZIONE!<BR/>I voti di preferenza $votisezcand <br/>superano quelli ammessi ".$votisezlis*$numprefs."</b><br></td></tr></table>";
+					$segna2="style=\"background-color: #dd0000;\"";
+					$errpres=1;
+				}
+				if($votimaxcand>$votisezlis and !$errpres)
+				{
+					echo "<table class=\"table-menu\" style=\"width: 50%;\"><tr><td style=\"background-color: rgb(255, 0, 0); color: black; text-align: center\"><img src=\"modules/Elezioni/images/alert.gif\" align=\"middle\" alt=\"\"><br/><b> ATTENZIONE!<BR/>I voti di preferenza di un candidato $votimaxcand <br/>superano i voti di lista $votisezlis</b><br></td></tr></table>";
+					$segna2="style=\"background-color: #dd0000;\"";
+				}
+
+			}#else{
+					$sql="select solo_gruppo from ".$prefix."_ele_sezioni where id_sez='$id_sez' ";
+					$resgs = $dbi->prepare("$sql");
+					$resgs->execute();
+					list($sgs3)=$resgs->fetch(PDO::FETCH_NUM);
+					$sql="select sum(solo_gruppo) from ".$prefix."_ele_voti_gruppo where id_sez='$id_sez' ";
+					$resgs = $dbi->prepare("$sql");
+					$resgs->execute();
+					list($vsg3)=$resgs->fetch(PDO::FETCH_NUM);
+					if($sgs3!=$vsg3)
+						 echo "<table class=\"table-menu\" style=\"width: 50%;\"><tr><td style=\"background-color: rgb(255, 0, 0); color: black; text-align: center\"><img src=\"modules/Elezioni/images/alert.gif\" align=\"middle\" alt=\"\"><br/><b> ATTENZIONE!<BR/>I voti al solo gruppo: $sgs3 non corrispondono a quelli inseriti nella scheda dei gruppi $vsg3 </b><br></td></tr></table>";
+	
+		}
+#die("TEST: if($sgs3!=$vsg3)");
+#controllo voti a liste collegate <= voto di gruppo per voto non disgiunto
+	$errgrulis=array();
+	if($genere==5 and !$disgiunto  and ($tipo_cons==18 or $tipo_cons==19)){
+		$sql="SELECT id_gruppo FROM ".$prefix."_ele_gruppo where id_cons='$id_cons' $circo";
+$resref = $dbi->prepare("$sql");
+$resref->execute();
+
+
+		$sql="SELECT count(0) FROM ".$prefix."_ele_voti_lista where id_sez='$id_sez'";
+$res4 = $dbi->prepare("$sql");
+$res4->execute();
+
+
+		list($sezscrl)=$res4->fetch(PDO::FETCH_NUM); 
+		if ($sezscrl)
+				
+		while ( list($id_gruppo)=$resref->fetch(PDO::FETCH_NUM))
+                    {
+                    $sql="SELECT sum(voti),sum(solo_gruppo) FROM ".$prefix."_ele_voti_gruppo where id_sez='$id_sez' and id_gruppo='$id_gruppo'";
+					$res3 = $dbi->prepare("$sql");
+					$res3->execute();
+
+
+                    $sql="SELECT sum(voti+nulli_lista) FROM ".$prefix."_ele_voti_lista where id_sez='$id_sez' and  id_lista in (select id_lista from ".$prefix."_ele_lista where id_gruppo='$id_gruppo')";
+					$res4 = $dbi->prepare("$sql");
+					$res4->execute();
+                    list($vgruppo3,$vsl3)=$res3->fetch(PDO::FETCH_NUM);
+					$vgruppo=$vgruppo3-$vsl3;
+
+                    list($vliste)=$res4->fetch(PDO::FETCH_NUM);
+                    if($vliste>$vgruppo)
+                    	{
+                    	 $sql="SELECT descrizione FROM ".$prefix."_ele_gruppo where id_gruppo='$id_gruppo'";
+$result = $dbi->prepare("$sql");
+$result->execute();
+
+
+                    	 list($dgruppo)=$result->fetch(PDO::FETCH_NUM);
+                    	echo "<table class=\"table-menu\" style=\"width: 50%;\"><tr><td style=\"background-color: rgb(255, 0, 0); color: black; text-align: center\"><img src=\"modules/Elezioni/images/alert.gif\" align=\"middle\" alt=\"\"><br/><b> ATTENZIONE!<BR/>I voti delle liste collegate<br/> superano i voti assegnati al gruppo $dgruppo </b><br></td></tr></table>";
+                    	$errgrulis[$id_gruppo]=1;
+                    	}
+                    elseif($vliste<$vgruppo)
+                    	{
+                    	 $sql="SELECT descrizione FROM ".$prefix."_ele_gruppo where id_gruppo='$id_gruppo'";
+$result = $dbi->prepare("$sql");
+$result->execute();
+
+
+                    	 list($dgruppo)=$result->fetch(PDO::FETCH_NUM);
+                    	echo "<table class=\"table-menu\" style=\"width: 50%;\"><tr><td style=\"background-color: rgb(255, 0, 0); color: black; text-align: center\"><img src=\"modules/Elezioni/images/alert.gif\" align=\"middle\" alt=\"\"><br/><b> ATTENZIONE!<BR/>I voti assegnati al gruppo $dgruppo<br/> superano i voti delle liste collegate </b><br></td></tr></table>";
+                    	$errgrulis[$id_gruppo]=1;
+                    	}
+                    }
+		}
+}
+
+
+		echo "\n<form name=\"sezioni\" data-ajax=\"false\" 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=\"genere\" value=\"$genere\">"
+		."<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=\"tabella\" value=\"$tab\">"
+		."<input type=\"hidden\" name=\"id_lista\" value=\"$id_lista\">\n"
+		."<input type=\"hidden\" name=\"do\" id=\"do\" value=\"0\">\n";
+		echo "<table class=\"table-menu\" style=\"width: 90%; color: black\">";
+		echo "<tr><td bgcolor=\"$bgcolor1\" align=\"left\" width=\"32\">";
+		if ($genere<4){
+//			echo "<td bgcolor=\"$bgcolor1\" align=\"center\" width=\"32\"><b>"._LISTA."</b></td>";
+		}
+		echo "<b>"._NUM."</b></td>";
+		if($id_lista){
+			echo "<td bgcolor=\"$bgcolor1\" align=\"left\"><b>"._CANDIDATO."</b></td>"
+			."<td bgcolor=\"$bgcolor1\" align=\"center\"><b>"._VOTI."</b> (alla lista ".$preflis[$id_lista].")</td>";
+		}else{
+			echo "<td bgcolor=\"$bgcolor1\" align=\"left\"><b>"._DESCR."</b></td>"
+			."<td bgcolor=\"$bgcolor1\" align=\"center\"><b>"._VOTI."</b></td>";
+#funzione di inserimento del dettaglio di voti nulli sospesa, non ritenuta utile
+#			if($dettnulli && !$disgiunto  && $tipo_cons!=18 && $tipo_cons!=19)
+#			echo "<td bgcolor=\"$bgcolor1\" align=\"center\"><b>"._NULLI_LISTE."</b></td>";
+			if($disgiunto){
+			echo "<td bgcolor=\"$bgcolor1\" align=\"center\"><b>"._SOLOLIS."</b></td>";
+			}
+		}
+		echo "</tr>\n";
+
+
+if($id_lista)		$sql="select t1.* from ".$prefix."_ele_candidati as t1 left join ".$prefix."_ele_lista as t2 on (t1.id_lista=t2.id_lista) WHERE t1.id_cons=$id_cons and t1.id_cons=t2.id_cons $ele_lista $circo ORDER BY t2.num_lista,t1.num_cand";
+else $sql="select 0,'$id_cons',t1.id_lista,'','','','','',0 from ".$prefix."_ele_candidati as t1 left join ".$prefix."_ele_lista as t2 on (t1.id_lista=t2.id_lista) WHERE t1.id_cons=$id_cons and t1.id_cons=t2.id_cons $ele_lista $circo ORDER BY t2.num_lista";
+$result = $dbi->prepare("$sql");
+$result->execute();
+
+
+		$max = $result->rowCount();
+		$tot_pref=0;
+		$i=1;
+
+		if($id_lista) {
+			while(list($id_cand,$id_cons2,$id_lista2,$nl, $cognome, $nome, $note, $simbolo, $num_cand) = $result->fetch(PDO::FETCH_NUM)){
+				// dati lista
+				$sql="select id_lista, descrizione,simbolo,num_lista from ".$prefix."_ele_lista where id_lista='$id_lista2'";
+				$result1 = $dbi->prepare("$sql");
+				$result1->execute();
+				list($id_lista3,$descr_lista,$simb_lista,$num_lista)=$result1->fetch(PDO::FETCH_NUM);
+			// dati gruppo
+				$sql="select descrizione,simbolo from ".$prefix."_ele_gruppo where id_gruppo='$id_gruppo'";
+				$result2 = $dbi->prepare("$sql");
+				$result2->execute();
+				list($descr_gruppo,$simb_gruppo)=$result2->fetch(PDO::FETCH_NUM);
+								echo "<tr bgcolor=\"$bgcolor2\">";
+				if ($genere<4){
+					echo "<td align=\"left\"><b><img src=\"images/lista/$simb_lista \" width=\"32\" heigth=\"32\" align=\"center\" ALT=\"$descr_lista\" > </b></td>";
+				}
+				echo "<td align=\"center\"><b> $num_cand </b></td>"
+				."<td align=\"left\"><b>$cognome $nome</b></td>";
+				$cond_sele="and id_cand=$id_cand";
+				$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(!$voti) $voti2=''; else $voti2=$voti;
+				if(in_array($num_cand,$errcand[$id_lista2])) $errcolor="style=\"background-color: rgb(255, 0, 0);\""; else $errcolor='';
+				echo "<td align=\"right\" $errcolor><input name=\"voti$num_cand\" value=\"".$voti."\" size=\"7\"  style=\"text-align:right\" onfocus=\"select();\">";
+				echo "<input type=\"hidden\" name=\"id_cand$num_cand\" value=\"$id_cand\"></td></tr>\n";
+				$i++;
+				$tot_pref+=$voti;
+			} 
+		}else {
+			if($circo) $circot1=" and t1.id_circ=$id_circ"; else $circot1='';
+			$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' 
+			and t1.id_lista=t2.id_lista
+			and t2.id_sez=$id_sez
+			$circot1
+			order by t1.num_lista";
+
+			try {
+				$result1 = $dbi->prepare("$sql");
+				$result1->execute();
+			}
+			catch(PDOException $e)
+			{
+				echo $sql . "<br>" . $e->getMessage();
+			}                  
+			$scruliste=$result1->rowCount();
+			if (!$scruliste){
+				$sql="select null,id_lista, descrizione,simbolo,num_lista,'','',id_gruppo
+				from ".$prefix."_ele_lista where id_cons='$id_cons' $circo
+				order by num_lista";
+				$result1 = $dbi->prepare("$sql");
+				$result1->execute();
+			}
+			$tvnpl=0;
+			$tslpl=0;
+#			$segna2='';
+			$sezscru=0;
+			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){
+//				}
+				$sql="select max(t1.voti),sum(t1.voti), count(t1.voti) from ".$prefix."_ele_voti_candidati as t1, ".$prefix."_ele_candidati as t2 where t1.id_cand=t2.id_cand and t1.id_sez='$id_sez' and t2.id_lista='$id_lista3'";
+				$rese = $dbi->prepare("$sql");
+				$rese->execute();
+				list($maxvotic,$sumvotic,$numrec)=$rese->fetch(PDO::FETCH_NUM);#die("TEST: $numrec");
+				if($numrec>0 or ($votoc and $scruliste)) {$sezscru=1; $statuscol="#99CC33;";} else $statuscol='';
+				if($maxvotic>$voti or $sumvotic>$voti*$numprefs) $statuscol='#dd0000;'; #$segna="style=\"background-color: #dd0000;\"";
+				$sql="select * from ".$prefix."_ele_controlli where tipo='lista' and id_sez='$id_sez' and id='$id_lista3'";
+				$rese = $dbi->prepare("$sql");
+				$rese->execute();
+				if($rese->rowCount()) $statuscol='#dd0000;'; #$segna="style=\"background-color: #dd0000;\"";
+				list($sezcol)=$rese->fetch(PDO::FETCH_NUM);
+				$segna="style=\"background-color: $statuscol\"";
+ 				if ($statuscol) $errcolor=$segna; else $errcolor='';
+				if ($statuscol=='#dd0000;')
+					$bordcolor="border-color:red;"; 
+				else $bordcolor='';
+				if(isset($errgrulis[$rifgruppo])) {
+					$errcolor="style=\"background-color: rgb(255, 0, 0);\""; 
+					$bordcolor="border-color:red;";
+				}elseif(!$errcolor && $numrec) $errcolor="style=\"background-color: #99CC33;\""; 
+				echo "<td align=\"center\" $errcolor><b> $num_lista </b></td>"
+				."<td align=\"left\"  onClick=\"vai_lista('id_rif$i');\"><b>$descr_lista</b></td>";
+##				$cond_sele="and id_lista=$id_lista3";
+				echo "<td align=\"right\"><input  name=\"voti$i\" value=\"".$voti."\" size=\"7\" onfocus=\"select();\" style=\"text-align:right; $bordcolor;\"><input id=\"id_rif$i\" type=\"hidden\" name=\"id_lista$i\" value=\"$id_lista3\">";
+#funzione non ritenuta utile
+#				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\">"; $tvnpl+=$vnpl;}
+				if($disgiunto) {echo "</td><td align=\"right\"><input  name=\"slpl$i\" value=\"".$slpl."\" size=\"7\"  style=\"text-align:right\" onfocus=\"select();\">"; $tslpl+=intval($slpl);}
+				echo "</td>";
+//				echo "<td align=\"right\">$sgpl";
+				echo "</tr>\n";
+				$i++;
+				$tot_pref+=$voti;
+			}
+		}
+		if(!isset($segna2)) $segna2='';
+		if(!$id_lista) {
+			if ($tot_pref!=$validi2 and $sezscru) $segna2="style=\"background-color: #dd0000;\"";
+			echo "<tr bgcolor=\"$bgcolor1\"><td></td><td><font size=\"3\">"._TOT._VOTI_LISTA."</font></td><td align=\"center\" $segna2><font size=\"3\">$tot_pref</font></td>";
+#			if($dettnulli && !$disgiunto  && $tipo_cons!=18 && $tipo_cons!=19)
+#				echo "<td bgcolor=\"$bgcolor1\" align=\"center\"><font size=\"3\">".$tvnpl."</font></td>";
+			if($disgiunto)
+				echo "<td bgcolor=\"$bgcolor1\" align=\"center\"><font size=\"3\">".$tslpl."</font></td>";
+			echo "</tr>";
+		}
+		else echo "<tr bgcolor=\"$bgcolor1\"><td></td><td>"._TOTPREF."</td><td align=\"center\"  $segna2>$tot_pref</td></tr>";
+		// toglie ai candidati la visual... del solo_gruppo 
+		if(!$votog) {
+		   if (($genere==3 OR $genere==5) and (!$id_lista) and (($disgiunto or $fascia>$limite) or !$id_conf)) { //gruppo e liste
+			echo "<tr bgcolor=\"$bgcolor2\"><td></td><td><b>"._VALIDI_LISTA."</b></td><td align=\"center\"><input type=\"hidden\" name=\"id_sez\" value=\"$id_sez\"><input name=\"valista\" value=\"$valista\" size=\"5\" style=\"text-align:right;\" onfocus=\"select();\"></td></tr>";
+			echo "<tr bgcolor=\"$bgcolor2\"><td></td><td><b>"._SOLO_GRUPPO."</b></td><td align=\"center\"><input name=\"sg\" value=\"$sg\" size=\"5\" style=\"text-align:right;\" onfocus=\"select();\">";
+			if(defined('_NULLISTA'))
+				echo "<input type=\"hidden\" name=\"votinulli\" value=\"$votinulli\"><input  type=\"hidden\" name=\"contestati\" value=\"$contestati\"></td></tr>";
+			else
+				echo "</td></tr><tr bgcolor=\"$bgcolor2\"><td></td><td><b>"._NULLI_LISTE."</b></td><td align=\"center\"><input  name=\"votinulli\" value=\"$votinulli\" size=\"5\" style=\"text-align:right;\" onfocus=\"select();\">"
+	."</td></tr><tr bgcolor=\"$bgcolor2\"><td></td><td><b>"._CONTESTATI_LISTE."</b></td><td align=\"center\"><input  name=\"contestati\" value=\"$contestati\" size=\"5\" style=\"text-align:right;\" onfocus=\"select();\"></td></tr>";
+			
+		   }elseif (($genere==3 OR $genere==5) and !$votoc and (($disgiunto or $fascia>$limite) or !$id_conf)){ //}elseif ($tipo_cons!=10 and $tipo_cons!=11){
+			echo "<tr bgcolor=\"$bgcolor1\"><td></td><td><b>"._SOLO_GRUPPO."</b></td><td align=\"center\">$sg</td></tr>";
+		   }
+/* visualizzazione tolta perchÃ© inappropriata 04/03/2022
+######modifica del 16-04-2009 per visualizzare i voti al solo sindaco nei comuni con meno di 15000 abitanti
+elseif(($genere==3 OR $genere==5) and ($id_lista) and ($fascia<=$limite or !$id_conf) and $numprefs==1) {
+$sql="SELECT id_gruppo FROM ".$prefix."_ele_lista where id_lista='$id_lista'";
+$resvg = $dbi->prepare("$sql");
+$resvg->execute();
+
+
+list($id_gruppo) = $resvg->fetch(PDO::FETCH_NUM);
+$sql="SELECT sum(voti) FROM ".$prefix."_ele_voti_gruppo where id_gruppo='$id_gruppo' and id_sez='$id_sez'";
+$resvg = $dbi->prepare("$sql");
+$resvg->execute();
+
+
+        list($voti_sind) = $resvg->fetch(PDO::FETCH_NUM);
+
+echo "<tr bgcolor=\"$bgcolor1\"><td></td><td><b>"._SOLO_GRUPPO."</b></td><td align=\"center\">".($voti_sind - $tot_pref)."</td></tr>";
+} */
+###### fine modifica del 16-04-2009
+
+	}
+		echo "<tr>";
+		echo "<td></td><td></td>";
+		echo "<td align=\"center\"><input type=\"submit\" id=\"update\" name=\"update\" value=\""._OK."\"></td>";
+		echo "</tr></table>";
+		if(chisei($id_cons_gen)>=64){
+			echo "<td></td><td> <input type=\"checkbox\" id=\"pwd3\" name=\"pwd3\" value=\"1\">"._DELETE."</td>";
+		} # onclick=\"javascript:del_dati()\"
+		echo "</form></tr></table>";
+		
+
+
+}
+#if (!((!$votog) and ($genere==3 OR $genere==5) and ($fascia>$limite)))
+	finale($id_cons,$do,$id_circ,$id_sede,$id_sez,$ops);
+ }
+
+
+function finale($id_cons,$do,$id_circ,$id_sede,$id_sez,$ops){
+ global $aid, $prefix, $dbi,$id_cons_gen,$genere,$votog,$fascia,$limite;
+////////////////////////////////////////////
+// da qua va la sezione per i voti finali
+///////////////////////////////////////////
+$bgcolor1="#7777ff";
+$bgcolor2=$_SESSION['bgcolor2'];
+
+
+
+     	echo "<form name=\"spogliovoti\" data-ajax=\"false\" 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\">"
+     	."<input type=\"hidden\" name=\"id_sede\" value=\"$id_sede\">";
+
+	echo "<table border=\"0\" width=\"100%\" align=\"center\"><tr bgcolor=\"$bgcolor1\" align=\"center\">";
+/*	if($ops==3 and ($genere==3 or ($genere==5 and $fascia>$limite)) )
+		echo "<td width=\"32\"><b>"._VOTI_LISTA."</b></td>";
+	else */
+		echo "<td width=\"15%\"><b>"._VALIDI."</b></td>";
+	echo "<td width=\"82\"><b>"._NULLI."</b></td>"
+    ."<td><b>"._BIANCHI."</b></td>"
+	."<td width=\"82\"><b>"._VOTINULLI."</b></td>"
+	."<td><b>"._CONTESTATI."</b></td>"
+    ."<td><b>"._TOTNON."</b></td>"
+	."<td><b>"._TOTALEVOTI."</b></td>"
+	."<td bgcolor=\"#ffffff\"></td> </tr>";
+/*if($ops==3 and ($genere==3 or ($genere==5 and $fascia>$limite)) )
+    $result = mysql_query("select id_cons,id_sez,validi_lista,nulli,bianchi,contestati_lista,voti_nulli_lista,solo_gruppo,contestati,voti_nulli from ".$prefix."_ele_sezioni where id_cons='$id_cons' and id_sez='$id_sez' ";
+$res = $dbi->prepare("$sql");
+$res->execute();
+
+
+else */
+    $sql = "select id_cons,id_sez,validi,nulli,bianchi,contestati,voti_nulli,'0','0','0',solo_lista from ".$prefix."_ele_sezioni where id_cons='$id_cons' and id_sez='$id_sez' ";
+$result = $dbi->prepare("$sql");
+$result->execute();
+
+
+    list($id_cons2,$id_sez2,$validi, $nulli, $bianchi, $contestati,$votinulli,$sg,$conts,$nullis,$sololista) = $result->fetch(PDO::FETCH_NUM);
+    $tot_nulli=$nulli+$bianchi+$contestati+$votinulli;
+    $tot_voti=$validi+$tot_nulli+$conts+$nullis;
+//	."</td><td><input  name=\"sololista\" value=\"$sololista\" size=\"5\" style=\"text-align:right\">" ---     ."<td><b>"._SOLOLIS."</b></td>"
+
+
+	echo "<tr bgcolor=\"$bgcolor2\" align=\"center\"><td align=\"left\"><input  name=\"validi\" value=\"$validi\" size=\"7\" style=\"text-align:right;\" onfocus=\"select();\">";
+/*	if(($genere==3 or $genere==5) and !$votog and $ops==3){
+	echo "</td><td>$nulli"
+	."</td><td>$bianchi";
+	echo "<input type=\"hidden\" name=\"nulli\" value=\"$nulli\"><input type=\"hidden\" name=\"bianchi\" value=\"$bianchi\">";
+	}else{ */
+	echo "</td><td><input  name=\"nulli\" value=\"$nulli\" size=\"5\" style=\"text-align:right;\" onfocus=\"select();\">"
+	."</td><td><input  name=\"bianchi\" value=\"$bianchi\" size=\"5\" style=\"text-align:right;\" onfocus=\"select();\">";
+//	}
+	echo "</td><td><input  name=\"votinulli\" value=\"$votinulli\" style=\"text-align:right;\" onfocus=\"select();\">"
+	."</td><td><input  name=\"contestati\" value=\"$contestati\" size=\"5\" style=\"text-align:right\" onfocus=\"select();\">"
+	."</td><td>$tot_nulli"
+	."</td><td>$tot_voti</td><td>"
+    	."<input type=\"hidden\" name=\"genere\" value=\"$genere\">"
+    	."<input type=\"hidden\" name=\"ops\" value=\"$ops\">"
+       	."<input type=\"submit\" name=\"update\" value=\""._OK."\">"
+      	."</td></tr></table></form>"; //</td></tr>";
+
+
+//    echo "</table>";
+/*	echo "<SCRIPT type=\"text/javascript\">\n\n<!--\n";
+	if (!$validi) {
+		echo "document.spogliovoti.validi.focus()\n";
+		echo "document.spogliovoti.validi.select()\n";
+	}
+	echo "//-->\n"
+	."</script>\n"; */
+
+
+    }
+
+
+function preferenze_gruppi($id_cons,$do,$id_circ,$id_sede,$id_sez,$ops){
+ global $aid, $prefix, $dbi, $tipo_cons, $genere,$id_cons_gen,$sezi,$circo,$dettnulli;
+////////////////////////////////////////////
+// da qua va la sezione per le preferenze ai gruppi
+///////////////////////////////////////////
+// Controllo immmissioni
+
+$bgcolor1="#7777ff";
+$bgcolor2=$_SESSION['bgcolor2'];
+$sql="SELECT * FROM ".$prefix."_ele_gruppo where id_cons='$id_cons' $circo ";
+$res = $dbi->prepare("$sql");
+$res->execute();
+
+
+    $max = $res->rowCount();
+    $max = $max-1;
+/*	 echo "<SCRIPT type=\"text/javascript\">\n\n<!--\n";
+	if ($genere==0) {
+		echo "document.sezioni.si1.focus()\n";
+		echo "document.sezioni.si1.select()\n";
+	} else {
+		echo "document.sezioni.voti1.focus()\n"
+		."document.sezioni.voti1.select()\n";
+	}
+	echo "//-->\n"
+	."</script>\n"; */
+// tabella votanti
+	echo "<center>";
+    if ($genere!=0){
+	$sql="SELECT voti_uomini,voti_donne, voti_complessivi FROM ".$prefix."_ele_voti_parziale where id_sez='$id_sez' and id_cons='$id_cons' order by data desc,orario desc limit 0,1";
+$result = $dbi->prepare("$sql");
+$result->execute();
+
+
+    list( $voti_u, $voti_d, $voti_t) = $result->fetch(PDO::FETCH_NUM);
+   	echo "<table  class=\"table-menu\" style=\"width: 50%; color: black;\">"
+	."<tr><td></td><td align=\"center\"></td><td bgcolor=\"$bgcolor1\" align=\"center\">"._VOTIU."</td><td bgcolor=\"$bgcolor1\" align=\"center\">"._VOTID."</td><td bgcolor=\"$bgcolor1\" align=\"center\">"._VOTIT."</td></tr>"
+	."<tr><td></td><td bgcolor=\"$bgcolor1\" align=\"center\">"._TOT_ULT."</td><td bgcolor=\"$bgcolor2\" align=\"center\">$voti_u</td><td align=\"center\" bgcolor=\"$bgcolor2\">$voti_d</td><td bgcolor=\"$bgcolor2\" align=\"center\">$voti_t</td></tr>";
+   	echo "</table>";
+    }
+	echo "<table  class=\"table-menu\" style=\"width: 50%; color: black\">";
+    if ($genere==0){
+    	$sql="SELECT id_gruppo,si+no,validi,nulli,bianchi,contestati FROM ".$prefix."_ele_voti_ref where id_cons='$id_cons' and id_sez='$id_sez'  ";
+		$res = $dbi->prepare("$sql");
+		$res->execute();
+		while (list($id_gruppo,$voti_parz,$validi,$nulli,$bianchi,$contestati) = $res->fetch(PDO::FETCH_NUM)){
+			if ($voti_parz!=$validi){
+				$sql="SELECT num_gruppo FROM ".$prefix."_ele_gruppo where id_cons='$id_cons' and id_gruppo='$id_gruppo'  ";
+				$res2 = $dbi->prepare("$sql");
+				$res2->execute();
+				list($num_gruppo) = $res2->fetch(PDO::FETCH_NUM);
+				echo "<tr><td style=\"background-color: rgb(255, 0, 0); text-align:center\"><img src=\"modules/Elezioni/images/alert.gif\" align=\"middle\" alt=\"\"><br><b> "._ATT_VOTI_REF." $num_gruppo: ".$voti_parz." "._NO_VAL_VOTI.": ".$validi."</b><br></td></tr>";
+			}
+			$sql="SELECT max(voti_complessivi) FROM ".$prefix."_ele_voti_parziale where id_cons='$id_cons' and id_sez='$id_sez' and id_gruppo='$id_gruppo' ";
+			$res2 = $dbi->prepare("$sql");
+			$res2->execute();
+			list($tot) = $res2->fetch(PDO::FETCH_NUM);
+			if (($validi+$nulli+$bianchi+$contestati)!= $tot ){
+				$sql="SELECT num_gruppo FROM ".$prefix."_ele_gruppo where id_cons='$id_cons' and id_gruppo='$id_gruppo'";
+				$res2 = $dbi->prepare("$sql");
+				$res2->execute();
+				list($num_gruppo) = $res2->fetch(PDO::FETCH_NUM);
+				echo "<tr><td style=\"background-color: rgb(255, 0, 0); text-align:center\"><img src=\"modules/Elezioni/images/alert.gif\" align=\"middle\" alt=\"\"><br><b> "._ATT_VOTANTI_REF." $num_gruppo: ".$tot." "._NO_SOMMA." ".($validi+$nulli+$bianchi+$contestati)."</b><br></td></tr>";
+			}
+		}
+    }else{
+		$sql="select solo_gruppo,disgiunto from ".$prefix."_ele_cons_comune where id_cons='$id_cons' ";
+		$result = $dbi->prepare("$sql");
+		$result->execute();
+		list($flagsg,$disgiunto)=$result->fetch(PDO::FETCH_NUM);
+		$dettnulli=$flagsg;
+		$sql="SELECT sum(voti) FROM ".$prefix."_ele_voti_gruppo where id_cons='$id_cons' and id_sez='$id_sez'";
+		$res = $dbi->prepare("$sql");
+		$res->execute();
+		list($voti_parz) = $res->fetch(PDO::FETCH_NUM);
+		$sql="SELECT validi,nulli,bianchi,contestati,solo_lista,voti_nulli FROM ".$prefix."_ele_sezioni where id_cons='$id_cons' and id_sez='$id_sez'";
+		$res = $dbi->prepare("$sql");
+		$res->execute();
+		list($validi,$nulli,$bianchi,$contestati,$solo_lista,$votinulli) = $res->fetch(PDO::FETCH_NUM);
+		if ($voti_parz!=($validi-$solo_lista) and $voti_parz>0){
+			echo "<tr><td style=\"background-color: rgb(255, 0, 0); text-align:center\"><img src=\"modules/Elezioni/images/alert.gif\" align=\"middle\" alt=\"\"><br><b> "._ATT_VOTI." ".$voti_parz." "._NO_VAL_VOTI." ".($validi-$solo_lista)."</b><br></td><tr>";
+		}
+		$sql="SELECT max(voti_complessivi) FROM ".$prefix."_ele_voti_parziale where id_cons='$id_cons' and id_sez='$id_sez'";
+		$res2 = $dbi->prepare("$sql");
+		$res2->execute();
+		list($tot) = $res2->fetch(PDO::FETCH_NUM);
+		if ($validi+$nulli+$bianchi+$contestati+$votinulli!=$tot and $validi+$nulli+$bianchi+$contestati+$votinulli>0){
+			echo "<tr><td style=\"background-color: rgb(255, 0, 0); text-align:center\"><img src=\"modules/Elezioni/images/alert.gif\" align=\"middle\" alt=\"\"><br><b> "._ATT_VOTANTI." ".$tot." "._NO_TOT_VOTI." ".($validi+$nulli+$bianchi+$contestati+$votinulli)."</b><br></td></tr>";
+    	}
+		$sql="SELECT sum(voti) from ".$prefix."_ele_voti_lista where id_cons=$id_cons and id_sez=$id_sez";
+		$resg = $dbi->prepare("$sql");
+		$resg->execute();
+		list($voti_sez)=$resg->fetch(PDO::FETCH_NUM);
+		if(($genere==5 and !$disgiunto and $voti_sez and $flagsg and ($tipo_cons==18 or $tipo_cons==19))){
+			$sql="SELECT sum(solo_gruppo) from ".$prefix."_ele_voti_gruppo where id_cons=$id_cons and id_sez=$id_sez";
+			$resg = $dbi->prepare("$sql");
+			$resg->execute();
+			list($sgpl)=$resg->fetch(PDO::FETCH_NUM);
+			$sql="SELECT solo_gruppo from ".$prefix."_ele_sezioni where id_cons=$id_cons and id_sez=$id_sez";
+			$resg = $dbi->prepare("$sql");
+			$resg->execute();
+			list($sg)=$resg->fetch(PDO::FETCH_NUM);
+			if ($sg != $sgpl) echo "<tr><td style=\"background-color: rgb(255, 0, 0); color: black; text-align: center\"><img src=\"modules/Elezioni/images/alert.gif\" align=\"middle\" alt=\"\"><br><b> "._ATT_UNI." ".$sgpl." "._ATT_TOT_UNI." ".$sg."</b><br></td></tr>";
+		}
+#controllo voti a liste collegate <= voto di gruppo per voto non disgiunto
+		if($genere==5 and !$disgiunto and $flagsg  and ($tipo_cons==18 or $tipo_cons==19)){
+			$sql="SELECT id_gruppo FROM ".$prefix."_ele_gruppo where id_cons='$id_cons' $circo";
+			$resref = $dbi->prepare("$sql");
+			$resref->execute();
+			$errgrulis=array();
+			$sql="SELECT count(0) FROM ".$prefix."_ele_voti_lista where id_sez='$id_sez'";
+			$res4 = $dbi->prepare("$sql");
+			$res4->execute();
+			list($sezscrl)=$res4->fetch(PDO::FETCH_NUM); 
+			if ($sezscrl)
+                while ( list($id_gruppo)=$resref->fetch(PDO::FETCH_NUM))
+                {
+					if($disgiunto || $flagsg){	
+						$sql="SELECT sum(voti-solo_gruppo) FROM ".$prefix."_ele_voti_gruppo where id_sez='$id_sez' and id_gruppo='$id_gruppo'";
+						$res3 = $dbi->prepare("$sql");
+						$res3->execute();
+						if($flagsg){
+							$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();
+						}else{
+							$sql="SELECT sum(voti) 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();							
+						}
+					}else{
+						$sql="SELECT sum(voti) FROM ".$prefix."_ele_voti_gruppo where id_sez='$id_sez' and id_gruppo='$id_gruppo'";
+						$res3 = $dbi->prepare("$sql");
+						$res3->execute();
+						$sql="SELECT sum(voti) FROM ".$prefix."_ele_voti_lista where id_sez='$id_sez' and  id_lista in (select id_lista from ".$prefix."_ele_lista where id_gruppo='$id_gruppo')";						
+						$res4 = $dbi->prepare("$sql");
+						$res4->execute();
+					}
+                    list($vgruppo)=$res3->fetch(PDO::FETCH_NUM);
+                    list($vliste)=$res4->fetch(PDO::FETCH_NUM);
+                    if($vliste>$vgruppo and !$disgiunto )
+                    {
+                    	$sql="SELECT descrizione FROM ".$prefix."_ele_gruppo where id_gruppo='$id_gruppo'";
+ 						$result = $dbi->prepare("$sql");
+						$result->execute();
+						list($dgruppo)=$result->fetch(PDO::FETCH_NUM);
+                    	echo "<tr><td style=\"background-color: rgb(255, 0, 0); color: black; text-align: center\"><img src=\"modules/Elezioni/images/alert.gif\" align=\"middle\" alt=\"\"><br/><b> ATTENZIONE!<BR/>I voti delle liste collegate $vliste<br/> superano i voti assegnati al gruppo $dgruppo $vgruppo</b><br></td></tr>";
+                    	$errgrulis[$id_gruppo]=1;
+                   	}
+                    elseif($vliste<$vgruppo and !$disgiunto )
+                   	{
+                    	$sql="SELECT descrizione FROM ".$prefix."_ele_gruppo where id_gruppo='$id_gruppo'";
+ 						$result = $dbi->prepare("$sql");
+						$result->execute();
+                    	list($dgruppo)=$result->fetch(PDO::FETCH_NUM);
+                    	echo "<tr><td style=\"background-color: rgb(255, 0, 0); color: black; text-align: center\"><img src=\"modules/Elezioni/images/alert.gif\" align=\"middle\" alt=\"\"><br/><b> ATTENZIONE!<BR/>I voti assegnati al gruppo $dgruppo<br/> superano i voti delle liste collegate </b><br></td></tr>";
+                    	$errgrulis[$id_gruppo]=1;
+                    }
+                }
+		}
+	}
+    if(!isset($votinulli)) $votinulli=0;
+	echo "<tr><td></td></tr></table>";
+	if ($validi+$nulli+$bianchi+$contestati+$votinulli>0 or $genere==0) {
+		if($genere==0)   echo "<table class=\"table-menu\" style=\" width: 60%; color: black\"><tr><td colspan=\"3\"><form name=\"sezioni\" data-ajax=\"false\" action=\"modules/Elezioni/salva_ref.php\">";
+		else echo "<table class=\"table-menu\" style=\" width: 60%; color: black\"><tr><td colspan=\"3\"><form name=\"sezioni\" data-ajax=\"false\" 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\">";
+		if ($genere==0){
+			echo "<br><br> <table  class=\"table-menu\" style=\"width: 100%; color: black\"><tr align=\"center\" bgcolor=\"$bgcolor1\">"
+			."<td colspan=\"6\"><b>"._GRUPPO."</b></td></tr>";
+			$campitesta= "<tr align=\"center\" bgcolor=\"$bgcolor1\"><td><b>Votanti "._SI."</b></td>"
+			."<td><b>Votanti "._NO."</b></td>"
+			."<td><b>"._VALIDI."</b></td>"
+			."<td><b>"._BIANCHI."</b></td>"
+			."<td><b>"._CONTESTATI."</b></td>"
+			."<td><b>"._NULLI."</b></td></tr>";
+			
+			$campiriep="<tr  style=\"background-color: $bgcolor1; text-align:center\"><td colspan=\"2\"><b>"._TOTNON."</b></td>"
+			."<td colspan=\"2\"><b>"._TOTALEVOTI."</b></td>"
+			."<td colspan=\"2\"><b>"._VOTANTI."</b></td></tr>";
+		}else{
+			echo "<br><br> <table  class=\"table-menu\" style=\"width: 100%; color: black\"><tr align=\"center\" bgcolor=\"$bgcolor1\">"
+			."<td width=\"3%\"><b>"._NUM."</b></td>"
+			."<td width=\"50%\"><b>"._GRUPPO."</b></td>";
+			echo "<td width=\"5%\"><b>"._VOTI."</b></td>";
+			if($dettnulli)		echo "<td bgcolor=\"$bgcolor1\" align=\"center\"><b>"._SOLO_GRUPPO."</b></td>";
+			echo "</tr>";
+		}
+		$sql="SELECT * FROM ".$prefix."_ele_gruppo where id_cons='$id_cons' $circo ORDER BY num_gruppo ";
+		$res = $dbi->prepare("$sql");
+		$res->execute();
+		$max = $res->rowCount();
+		//echo "Massimo:$max - id=$id_cons - circo: $circo";
+		$sql="select * from ".$prefix."_ele_gruppo where id_cons='$id_cons' $circo ORDER BY num_gruppo  ";
+		$result = $dbi->prepare("$sql");
+		$result->execute();
+		$i=1;
+		$tot_pref=0;
+		$totsg=0;
+		while(list($id_cons2,$id_gruppo,$num_gruppo, $descr_gruppo, $simbolo) = $result->fetch(PDO::FETCH_NUM)){
+			echo "<SCRIPT type=\"text/javascript\">\n\n<!--\n"
+			."//-->\n";
+			echo "function controlloref$i() {\n";
+			echo "var a=Number(window.document.sezioni.si$i.value); var b=Number(window.document.sezioni.no$i.value); if(a=='NaN') {a=0} if(b=='NaN') {b=0} var c=a + b; window.document.sezioni.val$i.value=c\n";
+			echo "}\n";
+			echo "</script>\n";    
+			if ($num_gruppo != ''){
+				if ($genere==0){
+					$sql="SELECT max(voti_complessivi) FROM ".$prefix."_ele_voti_parziale where id_cons='$id_cons' and id_sez='$id_sez' and id_gruppo='$id_gruppo' ";
+					$res = $dbi->prepare("$sql");
+					$res->execute();
+					list($tot) = $res->fetch(PDO::FETCH_NUM);
+					$sql="SELECT * FROM ".$prefix."_ele_voti_ref where id_cons='$id_cons' and id_sez='$id_sez' and id_gruppo='$id_gruppo' ";
+					$res = $dbi->prepare("$sql");
+					$res->execute();
+					$pro= $res->fetch(PDO::FETCH_BOTH);
+					echo "<tr><td colspan=\"6\">&nbsp;</td></tr>";
+					if ($pro['si']+$pro['no']!=$pro['validi'] or ($pro['validi']+$pro['nulli']+$pro['bianchi']+$pro['contestati']!=$tot and $pro['validi']+$pro['nulli']+$pro['bianchi']+$pro['contestati']!=0)){
+						echo "<tr style=\"background-color: rgb(255, 0, 0); text-align:center\">";
+					}elseif($pro['validi']+$pro['nulli']+$pro['bianchi']+$pro['contestati']!=0)
+						echo "<tr style=\"background-color:#99CC33; text-align:center\">"; 
+					else 
+						echo "<tr style=\"background-color:$bgcolor2; text-align:center\">";
+					$descr = explode('.',$descr_gruppo, 100);
+					echo "<td colspan=\"6\" align=\"center\"><input type=\"hidden\" name=\"id_gruppo$i\" value=\"$id_gruppo\"><b>$num_gruppo) </b>"
+					."<b> $descr[0] </b></td></tr>";
+					$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']:'';
+					$tot_nulli=intval($pro['nulli'])+intval($pro['bianchi'])+intval($pro['contestati']);
+					$tot_voti=intval($pro['validi'])+$tot_nulli;
+					echo $campiriep; # style=\"text-align: center; border: 1px; border-color: black; border-collaps:collaps;\"
+					echo "<tr style=\"background-color: $bgcolor2; text-align:center\"><td colspan=\"2\" >$tot_nulli</td>";
+					echo "<td colspan=\"2\">$tot_voti</td>";
+					echo "<td colspan=\"2\">$tot</td></tr>";
+					echo $campitesta;	
+					echo "<tr><td align=\"right\" width=\"3%\"><input  name=\"si$i\" value=\"".$pro['si']."\" size=\"7\"  style=\"text-align:right\" onchange=controlloref$i() onfocus=\"select();\"></td>";
+					echo "</td><td align=\"right\" width=\"3%\"><input  name=\"no$i\" value=\"".$pro['no']."\" size=\"7\"  style=\"text-align:right\" onchange=controlloref$i() onfocus=\"select();\"></td>";
+					echo "</td><td align=\"right\" width=\"3%\"><input  name=\"val$i\" value=\"".$pro['validi']."\" size=\"7\" style=\"text-align:right;\" onfocus=\"select();\"></td>";
+					echo "</td><td align=\"right\"><input  name=\"bia$i\" value=\"".$pro['bianchi']."\" size=\"7\"  style=\"text-align:right;\" onfocus=\"select();\"></td>";
+					echo "</td><td align=\"right\"><input  name=\"con$i\" value=\"".$pro['contestati']."\" size=\"7\"  style=\"text-align:right;\" onfocus=\"select();\"></td>";
+					echo "</td><td align=\"right\"><input  name=\"nul$i\" value=\"".$pro['nulli']."\" size=\"7\"  style=\"text-align:right;\" onfocus=\"select();\"></td>";
+				}else{
+					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' ";
+					$res = $dbi->prepare("$sql");
+					$res->execute();
+					$pro= $res->fetch(PDO::FETCH_BOTH);
+					if(!$res->rowCount()) {$pro['voti']=''; $pro['solo_gruppo']='';}
+					$errcolor='';
+					if(isset($errgrulis[$id_gruppo])) {$errcolor="style=\"background-color: rgb(255, 0, 0);\"";}
+					echo "</td><td align=\"right\" $errcolor><input  name=\"voti$i\" value=\"".$pro['voti']."\" size=\"7\"  style=\"text-align:right;\" onfocus=\"select();\"></td>";
+					if($dettnulli) {echo "<td align=\"right\"><input name=\"solog$i\" value=\"".$pro['solo_gruppo']."\" size=\"7\"  style=\"text-align:right;\" onfocus=\"select();\"></td>"; $totsg+=intval($pro['solo_gruppo']);} 
+					$tot_pref += intval($pro['voti']);
+					echo "</tr>";
+				}
+				$i++;
+			}
+		}
+		if ($genere!=0) {
+			$sql="SELECT disgiunto FROM ".$prefix."_ele_cons_comune where id_cons='$id_cons' ";
+			$res = $dbi->prepare("$sql");
+			$res->execute();
+			list($disgiunto)=$res->fetch(PDO::FETCH_NUM);
+			$sql="SELECT solo_lista FROM ".$prefix."_ele_sezioni where id_sez='$id_sez' ";
+			$res = $dbi->prepare("$sql");
+			$res->execute();
+			if ($tot_pref!=$validi and ($tot_pref>0 and $validi>0)) $segna2="style=\"background-color: #dd0000;\""; else $segna2='';
+			list($sololis)=$res->fetch(PDO::FETCH_NUM);
+			echo "<tr style=\"background-color: $bgcolor1; text-align:center\"><td></td><td>"._TOTPREF."</td><td $segna2>$tot_pref</td>";
+			if($dettnulli) echo "<td>$totsg</td>";
+			echo "</tr>";
+			if($disgiunto)
+				echo "<tr style=\"background-color: $bgcolor1; text-align:center\"><td></td><td>"._SOLOLIS."</td><td><input  name=\"sololista\" value=\"".$sololis."\" size=\"7\"  style=\"text-align:right;\" onfocus=\"select();\"></td></tr>";
+		}
+		echo "<tr><td></td><td></td><td align=\"center\"><input type=\"submit\" name=\"update\" id=\"update\" value=\" "._OK. "\"></td>";
+		echo "</tr></table></form></td></tr>";
+		if(chisei($id_cons_gen)>=64){
+			echo "<tr><td><input type=\"checkbox\" id=\"pwd3\" name=\"pwd3\" value=\"\" onclick=\"javascript:del_dati()\">"._DELETE."";
+		}
+		echo "</td></tr></table></center>";
+	}
+	if ($genere!=0){
+		finale($id_cons,$do,$id_circ,$id_sede,$id_sez,$ops);
+	}
+}
+
+
+
+
+?>
Index: trunk/admin/modules/Elezioni/ele_voti.php
===================================================================
--- trunk/admin/modules/Elezioni/ele_voti.php	(revision 359)
+++ trunk/admin/modules/Elezioni/ele_voti.php	(revision 360)
@@ -43,4 +43,5 @@
 include("modules/Elezioni/funzionidata.php");
 include("modules/Elezioni/ele.php");
+include_once("modules/Elezioni/ele_spoglio.php");
 global $votolista, $limite, $dettnulli,$disgiunto;
 if(!isset($votolista)) $votolista=0;
@@ -302,4 +303,38 @@
 	$result->execute();
 	list($id_cons2,$id_sez2,$id_sede,$num_sez, $maschi, $femmine) = $result->fetch(PDO::FETCH_NUM);
+	$sql="select tipo from ".$prefix."_ele_controlli where id_sez='$id_sez' group by tipo";
+$rese = $dbi->prepare("$sql");
+$rese->execute();
+$id_comune=$_SESSION['id_comune'];
+$bordoa='';
+$bordog='';
+$bordol=''; 
+while (list($tipo)=$rese->fetch(PDO::FETCH_NUM)) {
+	if ($tipo=='affluenze') $bordoa="style=\"border: 6px solid; border-color: rgb(255, 0, 0);\"";
+	if ($tipo=='gruppo' or $tipo=='referendum') $bordog="style=\"border: 6px solid; border-color: rgb(255, 0, 0);\"";
+	if ($tipo=='lista') $bordol="style=\"border: 6px solid; border-color: rgb(255, 0, 0);\"";
+}
+echo "<SCRIPT type=\"text/javascript\">\n";
+echo "function vai_scelta(idrif){\n";
+echo "window.document.location.href=idrif\n";
+echo "}\n";
+echo "</script>\n"; 
+if($rese->rowCount()) $segna="style=\"background-color: #dd0000;\""; else $segna='';
+if($ops=="4" ) {$bgcolorg="yellow"; $tcolorg='blue';} else {$bgcolorg="grey"; $tcolorg='white';} #$active_gruppo=" class=\"ui-btn-active\""; else $active_gruppo='';
+if($ops=="3") {$bgcolorl="yellow"; $tcolorl='blue';} else {$bgcolorl="grey"; $tcolorl='white';} # $active_lista=" class=\"ui-btn-active\""; else $active_lista='';
+if($ops=="1") {$bgcolora="yellow"; $tcolora='blue';} else {$bgcolora="grey"; $tcolora='white';} # $active_aff=" class=\"ui-btn-active\""; else $active_aff='';
+echo "<div data-role=\"content\" data-theme=\"a\"><hr><table style=\"margin-left:auto; margin-right:auto;\"><tr>";
+#<a href=\"admin.php?id_comune=$id_comune&amp;id_cons_gen=$id_cons_gen&amp;ops=1\"></a>
+echo "\n<td bgcolor=\"$bgcolora\" align=\"center\" $bordoa onClick=\"vai_scelta('admin.php?op=voti&amp;id_comune=$id_comune&amp;id_sez=$id_sez&amp;id_cons_gen=$id_cons_gen&amp;do=spoglio&amp;ops=1');\"><p style=\"margin-left:10px;margin-right:10px;\"><font color=\"$tcolora\"><b>"._AFFLUENZE."</font></b></p></td>\n";
+if(!($genere==4) and !($votog)){ //if(!($genere==4) and !($tipo_cons==10 or $tipo_cons==11)){
+	echo "<td bgcolor=\"$bgcolorg\" align=\"center\" $bordog onClick=\"vai_scelta('admin.php?op=voti&amp;id_comune=$id_comune&amp;id_sez=$id_sez&amp;id_cons_gen=$id_cons_gen&amp;do=spoglio&amp;ops=4');\"><p style=\"margin-left:10px;margin-right:10px;\"><b><font color=\"$tcolorg\">"._GRUPPO."</font></b></p></td>\n";
+}
+if($genere==2 and $votog)
+	echo "<td bgcolor=\"$bgcolorg\" align=\"center\" $bordog onClick=\"vai_scelta('admin.php?op=voti&amp;id_comune=$id_comune&amp;id_sez=$id_sez&amp;id_cons_gen=$id_cons_gen&amp;do=spoglio&amp;ops=4');\"><p style=\"margin-left:10px;margin-right:10px;\"><b><font color=\"$tcolorg\">"._GRUPPO."</font></b></p></td>\n";
+elseif(($genere>2 or $votog)){ //if(($genere>2 or $tipo_cons==10 or $tipo_cons==11)){
+	echo "<td bgcolor=\"$bgcolorl\" align=\"center\"$bordol onClick=\"vai_scelta('admin.php?op=voti&amp;id_comune=$id_comune&amp;id_sez=$id_sez&amp;id_cons_gen=$id_cons_gen&amp;do=spoglio&amp;ops=3');\"><p style=\"margin-left:10px;margin-right:10px;\"><b><font color=\"$tcolorl\">"._LISTA."</font></b></p></td>\n";
+}
+echo "</tr></table><hr></div>\n";
+/*
 	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";
@@ -313,5 +348,5 @@
 	}
 	echo "</tr></table></td></tr></table><hr>\n";
-
+*/
 #############
 # posizionamento in mancanza di scelta
@@ -376,1121 +411,4 @@
 
 }
-////////////////////////////////////////////////////////////////////////////////
-//   FUNZIONI DI IMMISSIONE
-//   - preferenze (candidati consiglieri)
-//   - preferenze_gruppi
-//   - votanti
-////////////////////////////////////////////////////////////////////////////////
-
-//////////////////////////////////////////////////////////////////////
-// da qui va la sezione per le preferenze candidati consiglieri
-//////////////////////////////////////////////////////////////////////
-function preferenze($id_cons,$do,$id_circ,$id_sede,$id_sez,$ops){
- 	global $aid, $prefix, $dbi, $id_lista,$genere,$id_cons_gen,$id_gruppo,$sezi,$circo,$votog,$votol,$votoc,$conscirc;
-global $tipo_cons,$limite,$dettnulli,$disgiunto;
-$bgcolor1="#7777ff";
-$bgcolor2=$_SESSION['bgcolor2'];
-
-if ($genere==4){
-	$sql="SELECT voti_uomini,voti_donne, voti_complessivi FROM ".$prefix."_ele_voti_parziale where id_sez='$id_sez' and id_cons='$id_cons' order by data desc,orario desc limit 0,1";
-	$result = $dbi->prepare("$sql");
-	$result->execute();
-
-
-	list( $voti_u, $voti_d, $voti_t) = $result->fetch(PDO::FETCH_NUM);
-	echo "<table  class=\"table-menu\" style=\"width: 50%; color: black;\">"
-	."<tr><td></td><td align=\"center\"></td><td bgcolor=\"$bgcolor1\" align=\"center\">"._VOTIU."</td><td bgcolor=\"$bgcolor1\" align=\"center\">"._VOTID."</td><td bgcolor=\"$bgcolor1\" align=\"center\">"._VOTIT."</td></tr>"
-	."<tr><td></td><td bgcolor=\"$bgcolor1\" align=\"center\">"._TOT_ULT."</td><td bgcolor=\"$bgcolor2\" align=\"center\">$voti_u</td><td align=\"center\" bgcolor=\"$bgcolor2\">$voti_d</td><td bgcolor=\"$bgcolor2\" align=\"center\">$voti_t</td></tr>";
-	echo "</table>";
-}
-$sql="select validi,nulli,bianchi,contestati from ".$prefix."_ele_sezioni where id_sez='$id_sez' ";
-$result = $dbi->prepare("$sql");
-$result->execute();
-list($v1,$v2,$v3,$v4)=$result->fetch(PDO::FETCH_NUM);
-if($v1+$v2+$v3+$v4>0){
-    //controlla se sono stati inseriti i votanti
-$sql="SELECT preferenze, id_fascia, id_conf,solo_gruppo, disgiunto from ".$prefix."_ele_cons_comune where id_cons='$id_cons'";
-$result = $dbi->prepare("$sql");
-$result->execute();
-
-
-list($numprefs,$fascia,$id_conf,$flagsg,$disgiunto)=$result->fetch(PDO::FETCH_NUM);
-
-####### 06-11-2014 - circoscrizionali - nello spostamento ad altra sezione resta sullo stesso numero di lista anche se sono sezioni di diverse circoscrizioni
-if ($circo and $id_lista){
-	$sql="SELECT num_lista from ".$prefix."_ele_lista where id_lista=$id_lista";
-	$res_lis = $dbi->prepare("$sql");
-	$res_lis->execute();
-	list($num_lista)=$res_lis->fetch(PDO::FETCH_NUM);
-}
-
-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");
-$result->execute();
-
-
-}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);
-		echo "<table class=\"table-menu\" style=\"width: 100%;\"><tr>";
-		$sql="SELECT id_lista, descrizione,num_lista from ".$prefix."_ele_lista where id_cons=$id_cons $circo order by num_lista";
-$res_lis = $dbi->prepare("$sql");
-$res_lis->execute();
-
-
-		$num_liste = $res_lis->rowCount();
-		$ele_lista='';
-		if (($genere==4 or $genere==5) and !$votoc) { //liste a piu' candidati
-			if(($genere==5 and $id_conf and $fascia<=$limite and !$disgiunto) and !$id_lista) { //esclude il voto di lista per le comunali nei comuni sotto fascia limite
-				$sql="SELECT id_lista from ".$prefix."_ele_lista where id_cons=$id_cons $circo limit 0,1";
-$result = $dbi->prepare("$sql");
-$result->execute();
-
-
-				list($id_lista)=$result->fetch(PDO::FETCH_NUM);
-			}
-			echo "<td>&nbsp;</td></tr><tr><td style=\"vertical-align: top;\">";
-			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()\">";
-			if ($id_lista){
-				echo "<option value=\"0\">"._VOTI_LISTA;
-				$ele_lista=" and t1.id_lista='$id_lista' ";
-			}else{
-				echo "<option value=\"0\" selected>"._VOTI_LISTA;
-				$ele_lista=" group by t1.id_lista ";
-if(!isset($votolista)) $votolista=0;
-
-			}
-			while(list($id_rif,$descrizione,$num_lis) = $res_lis->fetch(PDO::FETCH_NUM)) {
-			$segna='';
-			$sql="SELECT count(t1.voti) from ".$prefix."_ele_voti_candidati as t1 left join ".$prefix."_ele_candidati as t2 on (t1.id_cand=t2.id_cand) where t1.id_sez=$id_sez and t2.id_lista=$id_rif";
-$result = $dbi->prepare("$sql");
-$result->execute();
-
-
-			list($ctrvoticand)=$result->fetch(PDO::FETCH_NUM);
-			$sql="SELECT sum(t1.voti),0,0 from ".$prefix."_ele_voti_candidati as t1 left join ".$prefix."_ele_candidati as t2 on (t1.id_cand=t2.id_cand) where t1.id_sez=$id_sez and t2.id_lista=$id_rif";
-$result = $dbi->prepare("$sql");
-$result->execute();
-
-
-			list($votisezcand)=$result->fetch(PDO::FETCH_NUM);
-			if((($fascia>$limite or $disgiunto) or !$id_conf) or $genere==4){
-                $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{
-				$sql="SELECT id_gruppo from ".$prefix."_ele_lista where id_lista='$id_rif'";
-$result = $dbi->prepare("$sql");
-$result->execute();
-				list($id_gruppo)=$result->fetch(PDO::FETCH_NUM);
-				$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);
-			if($votisezcand>($votisezlis*$numprefs))
-				{$segna="style=\"background-color: #dd0000;\"";}
-			elseif($ctrvoticand)
-				$segna="style=\"background-color: #99CC33;\"";
-			$sql="SELECT t1.voti,t2.num_cand FROM ".$prefix."_ele_voti_candidati as t1 left join ".$prefix."_ele_candidati as t2 on t1.id_cand=t2.id_cand where t1.id_cons='$id_cons' and  t1.id_sez='$id_sez' and t2.id_lista='$id_rif'";
-$res4 = $dbi->prepare("$sql");
-$res4->execute();
-
-
-			$errcand[$id_rif]=array();
-			while(list($testvotic,$numcand)=$res4->fetch(PDO::FETCH_NUM))
-				if($votisezlis<$testvotic) { $segna="style=\"background-color: #dd0000;\"";$errcand[$id_rif][]=$numcand;}
-                        
-			$sel = ($id_rif == $id_lista) ? "selected" : "";
-				echo "<option $segna value=\"$id_rif\" $sel>";
-				for ($j=strlen($num_lis);$j<2;$j++) { echo "&nbsp;&nbsp;";}
-				echo $num_lis.") ".substr($descrizione,0,30);
-			}
-			echo "</select></form></td>\n";
-		}else {
-			$id_lista=0;
-		}
-		echo "<td style=\"vertical-align: top;\">";
-
-		if ((!$id_lista)){$tab="_ele_voti_lista";} else {$tab="_ele_voti_candidati";}
-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,t2.contestati,0,0 from ".$prefix."_ele_sezioni as t2 left join ".$prefix.$tab." as t1 on (t1.id_sez=t2.id_sez) where t2.id_sez=$id_sez group by t1.id_sez";
-$result = $dbi->prepare("$sql");
-$result->execute();
-
-
-}else{
-		$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,t1.id_sez 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,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";
-$result = $dbi->prepare("$sql");
-$result->execute();
-}
-
-// aggiunte le variabili $sgpl e $vnulli2 per la gestione dei voti 1) al solo presidente per singola lista - 2) al solo presidente per singola lista perchÃ© nullo o contestato quello di lista		
-		$isscr= $result->rowCount();
-		list( $voti_sez, $validi2, $sg,$cont2,$vnulli2,$bia2,$nul2,$con2,$vnul2,$sgpl) = $result->fetch(PDO::FETCH_NUM);
-		if(($genere==5 and !$disgiunto and $voti_sez and $flagsg and ($tipo_cons==18 or $tipo_cons==19))){ 
-			$sql="SELECT sum(solo_gruppo) from ".$prefix."_ele_voti_gruppo where id_cons=$id_cons and id_sez=$id_sez";
-$resg = $dbi->prepare("$sql");
-$resg->execute();
-
-
-			list($sgpl)=$resg->fetch(PDO::FETCH_NUM);
-			if ($sg != $sgpl) echo "<table class=\"table-menu\" style=\"width: 50%;\"><tr><td style=\"background-color: rgb(255, 0, 0); color: black; text-align: center\"><img src=\"modules/Elezioni/images/alert.gif\" align=\"middle\" alt=\"\"><br><b> "._ATT_UNI." ".$sgpl." "._ATT_TOT_UNI." ".$sg."</b><br></td></table>";
-		}
-		$valista=$validi2;
-		if(!$id_lista or $genere==3){	//controllo di congruenza
-			$sql="SELECT max(voti_complessivi) FROM ".$prefix."_ele_voti_parziale where id_cons='$id_cons' and id_sez='$id_sez'";
-$res2 = $dbi->prepare("$sql");
-$res2->execute();
-
-
-			list($tot) = $res2->fetch(PDO::FETCH_NUM);
-#######    controlli
-	$sql="select * from ".$prefix."_ele_controlli where id_cons='$id_cons' and id_sez='$id_sez' ";
-	$resc = $dbi->prepare("$sql");
-	$resc->execute();
-if($resc->rowCount()){			if ($validi2+$vnulli2+$cont2+$sg+$bia2+$nul2+$con2+$vnul2!=$tot and $validi+$sg>0){
-				echo "<table class=\"table-menu\" style=\"width: 50%;\"><tr><td style=\"background-color: rgb(255, 0, 0); color: black; text-align: center\"><img src=\"modules/Elezioni/images/alert.gif\" align=\"middle\" alt=\"\"><br><b> "._ATT_VOTANTI." ".$tot." "._NO_TOT_VOTI." ".($validi2+$vnulli2+$cont2+$sg+$bia2+$nul2+$con2+$vnul2)."</b><br></td></table>";
-			}
-
-			if((($voti_sez)!=$validi2) and ($voti_sez>0)){
-				echo "<table class=\"table-menu\" style=\"width: 50%;\"><tr><td style=\"background-color: rgb(255, 0, 0); color: black; text-align: center\"><img src=\"modules/Elezioni/images/alert.gif\" align=\"middle\" alt=\"\"><br><b> "._ATT_VOTI." ".($voti_sez)." "._NO_VAL_VOTI." ".$validi2."</b><br></td></tr></table>";
-			}
-		}elseif($genere==5){
-			$sql="SELECT sum(t1.voti) from ".$prefix."_ele_voti_candidati as t1 left join ".$prefix."_ele_candidati as t2 on (t1.id_cand=t2.id_cand) where t1.id_sez=$id_sez and t2.id_lista=$id_lista";
-$result = $dbi->prepare("$sql");
-$result->execute();
-
-
-			list($votisezcand)=$result->fetch(PDO::FETCH_NUM);
-			if(($fascia>$limite or $disgiunto) or !$id_conf){
-                 $sql="SELECT sum(voti) from ".$prefix."_ele_voti_lista where id_sez='$id_sez' and id_lista='$id_lista'";
-$result = $dbi->prepare("$sql");
-$result->execute();
-
-
-            }else{
-
-				$sql="SELECT id_gruppo from ".$prefix."_ele_lista where id_lista='$id_lista'";
-$result = $dbi->prepare("$sql");
-$result->execute();
-
-
-				list($id_gruppo)=$result->fetch(PDO::FETCH_NUM);
-				$sql="SELECT sum(voti) from ".$prefix."_ele_voti_gruppo where id_sez='$id_sez' and id_gruppo='$id_gruppo'";
-$result = $dbi->prepare("$sql");
-$result->execute();
-
-
-            }
-			list($votisezlis)=$result->fetch(PDO::FETCH_NUM);
-			if($votisezcand>($votisezlis*$numprefs))
-				{
-				echo "<table class=\"table-menu\" style=\"width: 50%;\"><tr><td style=\"background-color: rgb(255, 0, 0); color: black; text-align: center\"><img src=\"modules/Elezioni/images/alert.gif\" align=\"middle\" alt=\"\"><br/><b> ATTENZIONE!<BR/>I voti di preferenza $votisezcand <br/>superano i voti di lista $votisezlis</b><br></td></tr></table>";
-				}
-		}
-#controllo voti a liste collegate <= voto di gruppo per voto non disgiunto
-	$errgrulis=array();
-	if($genere==5 and !$disgiunto  and ($tipo_cons==18 or $tipo_cons==19)){
-		$sql="SELECT id_gruppo FROM ".$prefix."_ele_gruppo where id_cons='$id_cons' $circo";
-$resref = $dbi->prepare("$sql");
-$resref->execute();
-
-
-		$sql="SELECT count(0) FROM ".$prefix."_ele_voti_lista where id_sez='$id_sez'";
-$res4 = $dbi->prepare("$sql");
-$res4->execute();
-
-
-		list($sezscrl)=$res4->fetch(PDO::FETCH_NUM); 
-		if ($sezscrl)
-				
-		while ( list($id_gruppo)=$resref->fetch(PDO::FETCH_NUM))
-                    {
-                    $sql="SELECT sum(voti-solo_gruppo) FROM ".$prefix."_ele_voti_gruppo where id_sez='$id_sez' and id_gruppo='$id_gruppo'";
-$res3 = $dbi->prepare("$sql");
-$res3->execute();
-
-
-                    $sql="SELECT sum(voti+nulli_lista) FROM ".$prefix."_ele_voti_lista where id_sez='$id_sez' and  id_lista in (select id_lista from ".$prefix."_ele_lista where id_gruppo='$id_gruppo')";
-$res4 = $dbi->prepare("$sql");
-$res4->execute();
-
-
-                    list($vgruppo)=$res3->fetch(PDO::FETCH_NUM);
-                    list($vliste)=$res4->fetch(PDO::FETCH_NUM);
-                    if($vliste>$vgruppo)
-                    	{
-                    	 $sql="SELECT descrizione FROM ".$prefix."_ele_gruppo where id_gruppo='$id_gruppo'";
-$result = $dbi->prepare("$sql");
-$result->execute();
-
-
-                    	 list($dgruppo)=$result->fetch(PDO::FETCH_NUM);
-                    	echo "<table class=\"table-menu\" style=\"width: 50%;\"><tr><td style=\"background-color: rgb(255, 0, 0); color: black; text-align: center\"><img src=\"modules/Elezioni/images/alert.gif\" align=\"middle\" alt=\"\"><br/><b> ATTENZIONE!<BR/>I voti delle liste collegate<br/> superano i voti assegnati al gruppo $dgruppo </b><br></td></tr></table>";
-                    	$errgrulis[$id_gruppo]=1;
-                    	}
-                    elseif($vliste<$vgruppo)
-                    	{
-                    	 $sql="SELECT descrizione FROM ".$prefix."_ele_gruppo where id_gruppo='$id_gruppo'";
-$result = $dbi->prepare("$sql");
-$result->execute();
-
-
-                    	 list($dgruppo)=$result->fetch(PDO::FETCH_NUM);
-                    	echo "<table class=\"table-menu\" style=\"width: 50%;\"><tr><td style=\"background-color: rgb(255, 0, 0); color: black; text-align: center\"><img src=\"modules/Elezioni/images/alert.gif\" align=\"middle\" alt=\"\"><br/><b> ATTENZIONE!<BR/>I voti assegnati al gruppo $dgruppo<br/> superano i voti delle liste collegate </b><br></td></tr></table>";
-                    	$errgrulis[$id_gruppo]=1;
-                    	}
-                    }
-		}
-}
-
-
-		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=\"genere\" value=\"$genere\">"
-		."<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=\"tabella\" value=\"$tab\">"
-		."<input type=\"hidden\" name=\"id_lista\" value=\"$id_lista\">\n"
-		."<input type=\"hidden\" name=\"do\" id=\"do\" value=\"0\">\n";
-		echo "<table class=\"table-menu\" style=\"width: 90%; color: black\">";
-		echo "<tr><td bgcolor=\"$bgcolor1\" align=\"left\" width=\"32\">";
-		if ($genere<4){
-//			echo "<td bgcolor=\"$bgcolor1\" align=\"center\" width=\"32\"><b>"._LISTA."</b></td>";
-		}
-		echo "<b>"._NUM."</b></td>";
-		if($id_lista){
-			echo "<td bgcolor=\"$bgcolor1\" align=\"left\"><b>"._CANDIDATO."</b></td>"
-			."<td bgcolor=\"$bgcolor1\" align=\"center\"><b>"._VOTI."</b></td>";
-		}else{
-			echo "<td bgcolor=\"$bgcolor1\" align=\"left\"><b>"._DESCR."</b></td>"
-			."<td bgcolor=\"$bgcolor1\" align=\"center\"><b>"._VOTI."</b></td>";
-#			if($dettnulli && !$disgiunto  && $tipo_cons!=18 && $tipo_cons!=19)
-#			echo "<td bgcolor=\"$bgcolor1\" align=\"center\"><b>"._NULLI_LISTE."</b></td>";
-			if($disgiunto){
-			echo "<td bgcolor=\"$bgcolor1\" align=\"center\"><b>"._SOLOLIS."</b></td>";
-			}
-		}
-		echo "</tr>\n";
-
-
-
-
-
-if($id_lista)		$sql="select t1.* from ".$prefix."_ele_candidati as t1 left join ".$prefix."_ele_lista as t2 on (t1.id_lista=t2.id_lista) WHERE t1.id_cons=$id_cons and t1.id_cons=t2.id_cons $ele_lista $circo ORDER BY t2.num_lista,t1.num_cand";
-else $sql="select 0,'$id_cons',t1.id_lista,'','','','','',0 from ".$prefix."_ele_candidati as t1 left join ".$prefix."_ele_lista as t2 on (t1.id_lista=t2.id_lista) WHERE t1.id_cons=$id_cons and t1.id_cons=t2.id_cons $ele_lista $circo ORDER BY t2.num_lista";
-$result = $dbi->prepare("$sql");
-$result->execute();
-
-
-		$max = $result->rowCount();
-		$tot_pref=0;
-		$i=1;
-
-		if($id_lista) {
-			while(list($id_cand,$id_cons2,$id_lista2,$nl, $cognome, $nome, $note, $simbolo, $num_cand) = $result->fetch(PDO::FETCH_NUM)){
-				// dati lista
-				$sql="select id_lista, descrizione,simbolo,num_lista from ".$prefix."_ele_lista where id_lista='$id_lista2'";
-$result1 = $dbi->prepare("$sql");
-$result1->execute();
-
-
-				list($id_lista3,$descr_lista,$simb_lista,$num_lista)=$result1->fetch(PDO::FETCH_NUM);
-			// dati gruppo
-				$sql="select descrizione,simbolo from ".$prefix."_ele_gruppo where id_gruppo='$id_gruppo'";
-$result2 = $dbi->prepare("$sql");
-$result2->execute();
-
-
-				list($descr_gruppo,$simb_gruppo)=$result2->fetch(PDO::FETCH_NUM);
-				
-				echo "<tr bgcolor=\"$bgcolor2\">";
-				if ($genere<4){
-					echo "<td align=\"left\"><b><img src=\"images/lista/$simb_lista \" width=\"32\" heigth=\"32\" align=\"center\" ALT=\"$descr_lista\" > </b></td>";
-				}
-				echo "<td align=\"center\"><b> $num_cand </b></td>"
-				."<td align=\"left\"><b>$cognome $nome</b></td>";
-				$cond_sele="and id_cand=$id_cand";
-				$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$num_cand\" value=\"".$voti."\" size=\"7\"  style=\"text-align:right\">";
-				echo "<input type=\"hidden\" name=\"id_cand$num_cand\" value=\"$id_cand\"></td></tr>\n";
-				$i++;
-				$tot_pref+=$voti;
-			} 
-		}else {
-			if($circo) $circot1=" and t1.id_circ=$id_circ"; else $circot1='';
-			$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' 
-			and t1.id_lista=t2.id_lista
-			and t2.id_sez=$id_sez
-			$circot1
-			order by t1.num_lista";
-
-	try {
-		$result1 = $dbi->prepare("$sql");
-		$result1->execute();
-
-	}
-		catch(PDOException $e)
-		{
-			echo $sql . "<br>" . $e->getMessage();
-		}                  
-
-			$num_lista=$result1->rowCount();
-			if (!$num_lista){
-				$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";
-				$result1 = $dbi->prepare("$sql");
-				$result1->execute();
-			}
-			$tvnpl=0;
-			$tslpl=0;
-			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){
-//				}
-				$errcolor='';
-				if(isset($errgrulis[$rifgruppo])) $errcolor="style=\"background-color: rgb(255, 0, 0);\"";
-				echo "<td align=\"center\"><b> $num_lista </b></td>"
-				."<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=\"".$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\">"; $tvnpl+=$vnpl;}
-				if($disgiunto) {echo "</td><td align=\"right\"><input  name=\"slpl$i\" value=\"".$slpl."\" size=\"7\"  style=\"text-align:right\">"; $tslpl+=$slpl;}
-				echo "<input type=\"hidden\" name=\"id_lista$i\" value=\"$id_lista3\"></td>";
-//				echo "<td align=\"right\">$sgpl";
-				echo "</tr>\n";
-				$i++;
-				$tot_pref+=$voti;
-			}
-		}
-		if(!$id_lista) {
-			echo "<tr bgcolor=\"$bgcolor1\"><td></td><td><font size=\"3\">"._TOT._VOTI_LISTA."</font></td><td align=\"center\"><font size=\"3\">$tot_pref</font></td>";
-#			if($dettnulli && !$disgiunto  && $tipo_cons!=18 && $tipo_cons!=19)
-#				echo "<td bgcolor=\"$bgcolor1\" align=\"center\"><font size=\"3\">".$tvnpl."</font></td>";
-			if($disgiunto)
-				echo "<td bgcolor=\"$bgcolor1\" align=\"center\"><font size=\"3\">".$tslpl."</font></td>";
-			echo "</tr>";
-		}
-		else echo "<tr bgcolor=\"$bgcolor1\"><td></td><td>"._TOTPREF."</td><td align=\"center\">$tot_pref</td></tr>";
-		// toglie ai candidati la visual... del solo_gruppo 
-		if(!$votog) {
-		   if (($genere==3 OR $genere==5) and (!$id_lista) and (($disgiunto or $fascia>$limite) or !$id_conf)) { //gruppo e liste
-			echo "<tr bgcolor=\"$bgcolor2\"><td></td><td><b>"._VALIDI_LISTA."</b></td><td align=\"center\"><input type=\"hidden\" name=\"id_sez\" value=\"$id_sez\"><input name=\"valista\" value=\"$valista\" size=\"5\" style=\"text-align:right\"></td></tr>";
-			echo "<tr bgcolor=\"$bgcolor2\"><td></td><td><b>"._SOLO_GRUPPO."</b></td><td align=\"center\"><input name=\"sg\" value=\"$sg\" size=\"5\" style=\"text-align:right\">";
-			if(defined('_NULLISTA'))
-				echo "<input type=\"hidden\" name=\"votinulli\" value=\"$votinulli\"><input  type=\"hidden\" name=\"contestati\" value=\"$contestati\"></td></tr>";
-			else
-				echo "</td></tr><tr bgcolor=\"$bgcolor2\"><td></td><td><b>"._NULLI_LISTE."</b></td><td align=\"center\"><input  name=\"votinulli\" value=\"$votinulli\" size=\"5\" style=\"text-align:right\">"
-	."</td></tr><tr bgcolor=\"$bgcolor2\"><td></td><td><b>"._CONTESTATI_LISTE."</b></td><td align=\"center\"><input  name=\"contestati\" value=\"$contestati\" size=\"5\" style=\"text-align:right\"></td></tr>";
-			
-		   }elseif (($genere==3 OR $genere==5) and !$votoc and (($disgiunto or $fascia>$limite) or !$id_conf)){ //}elseif ($tipo_cons!=10 and $tipo_cons!=11){
-			echo "<tr bgcolor=\"$bgcolor1\"><td></td><td><b>"._SOLO_GRUPPO."</b></td><td align=\"center\">$sg</td></tr>";
-		   }
-######modifica del 16-04-2009 per visualizzare i voti al solo sindaco nei comuni con meno di 15000 abitanti
-elseif(($genere==3 OR $genere==5) and ($id_lista) and ($fascia<=$limite or !$id_conf) and $numprefs==1) {
-$sql="SELECT id_gruppo FROM ".$prefix."_ele_lista where id_lista='$id_lista'";
-$resvg = $dbi->prepare("$sql");
-$resvg->execute();
-
-
-list($id_gruppo) = $resvg->fetch(PDO::FETCH_NUM);
-$sql="SELECT sum(voti) FROM ".$prefix."_ele_voti_gruppo where id_gruppo='$id_gruppo' and id_sez='$id_sez'";
-$resvg = $dbi->prepare("$sql");
-$resvg->execute();
-
-
-        list($voti_sind) = $resvg->fetch(PDO::FETCH_NUM);
-
-echo "<tr bgcolor=\"$bgcolor1\"><td></td><td><b>"._SOLO_GRUPPO."</b></td><td align=\"center\">".($voti_sind - $tot_pref)."</td></tr>";
-}
-###### fine modifica del 16-04-2009
-
-	}
-		echo "<tr>";
-		echo "<td></td><td></td>";
-		echo "<td align=\"center\"><input type=\"submit\" id=\"update\" name=\"update\" value=\""._OK."\"></td>";
-		echo "</tr></table>";
-		if(chisei($id_cons_gen)>=64){
-			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"
-		."document.sezioni.voti1.select()\n"
-		."//-->\n";
-		echo "function vai_lista() {\n";
-		echo "window.document.location.href=document.liste.pag.value+document.liste.id_lista.value\n";
-		echo "}\n";
-		echo "</script>\n";
-}
-#if (!((!$votog) and ($genere==3 OR $genere==5) and ($fascia>$limite)))
-	finale($id_cons,$do,$id_circ,$id_sede,$id_sez,$ops);
- }
-
-
-////////////////////////////////////////////
-// da qua va la sezione per i votanti
-///////////////////////////////////////////
-
-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,$id_comune;
-$bgcolor1=$_SESSION['bgcolor2'];
-
-#OpenTable();
-$sql="SELECT vismf from ".$prefix."_ele_cons_comune where id_cons='$id_cons'";
-$res = $dbi->prepare("$sql");
-$res->execute();
-
-
-if($res) list($vismf)= $res->fetch(PDO::FETCH_NUM); else $vismf=0;
-$sql="SELECT orario,data FROM ".$prefix."_ele_rilaff where id_cons_gen=$id_cons_gen order by data,orario ";
-$res = $dbi->prepare("$sql");
-$res->execute();
-
-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 "<div class=\"table\">";
-#echo "<tr><td>&nbsp;</td></tr>";
-$riga=array();
-$rigat=array();
-while (list($ora,$giorno)= $res->fetch(PDO::FETCH_NUM)){
-	$y++;
-	$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'  ";
-$res2 = $dbi->prepare("$sql");
-$res2->execute();
-
-
-		$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 
-		on (t1.id_gruppo=t2.id_gruppo) where t1.id_sez='$id_sez' 
-		and t1.id_cons='$id_cons' and t1.orario='$ora' and t1.data='$giorno'";
-		if ($genere==0){
-			$query.=" and t2.num_gruppo=$i";
-		}
-		$sql=$query;
-$result = $dbi->prepare("$sql");
-$result->execute();
-
-
-		list($id_cons2,$id_sez2,$id_parz,$orario,$data, $voti_u, $voti_d, $voti_t,$id_gruppo) = $result->fetch(PDO::FETCH_NUM);
-	   	$sql="SELECT num_gruppo FROM ".$prefix."_ele_gruppo where id_gruppo='$id_gruppo' ";
-$res2 = $dbi->prepare("$sql");
-$res2->execute();
-
-
-        $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();
-
-
-        list($numril)=$resril->fetch(PDO::FETCH_NUM);
-		if ($res2)
-			list($gruppo)= $res2->fetch(PDO::FETCH_NUM);
-		else
-			$gruppo=0;
-		if (!$gruppo>0) {
-			$gruppo=$i;
-			$sql="SELECT id_gruppo FROM ".$prefix."_ele_gruppo where num_gruppo=$gruppo and id_cons=$id_cons";
-$res3 = $dbi->prepare("$sql");
-$res3->execute();
-
-
-			if ($res3)
-			list($id_gruppo)=$res3->fetch(PDO::FETCH_NUM);
-		}
-		if(!isset($precede[$id_gruppo])) $precede[$id_gruppo]=0; if(!isset($error)) $error=0;
-		if($precede[$id_gruppo]>($voti_t) and $voti_t!='') $error=1;
-		$precede[$id_gruppo]=$voti_t;
-		if (($voti_u+$voti_d and $voti_u+$voti_d!=$voti_t) or $error){
-#			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{
-			$riga[$y].= "<form class=\"tr\" action=\"modules/Elezioni/salva_aff.php\">";
-		}
-		if ($genere==0){ // e' un referendum
-			$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=\"genere\" value=\"$genere\"/>"
-	."<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");
-$compl->execute();
-
-
-   	list ($complessivi)= $compl->fetch(PDO::FETCH_NUM);
-	if (!$complessivi) 
-	{
-		echo "<SCRIPT type=\"text/javascript\">\n\n<!--\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 "this.voti_t$numy.focus()\n";
-			echo "this.voti_t$numy.select()\n";
-		}
-		echo "//-->\n"
-		."</script>\n";
-		break;
-	}
-#	echo "</td></tr>";
-	}
-#CloseTable();
-foreach($riga as $key=>$val){
-	echo $rigat[$key];
-	echo $riga[$key];
-}
-echo "</div></td></tr></table>";
-}
-
-
-
-function finale($id_cons,$do,$id_circ,$id_sede,$id_sez,$ops){
- global $aid, $prefix, $dbi,$id_cons_gen,$genere,$votog,$fascia,$limite;
-////////////////////////////////////////////
-// da qua va la sezione per i voti finali
-///////////////////////////////////////////
-$bgcolor1="#7777ff";
-$bgcolor2=$_SESSION['bgcolor2'];
-
-
-
-     	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\">"
-     	."<input type=\"hidden\" name=\"id_sede\" value=\"$id_sede\">";
-
-	echo "<table border=\"0\" width=\"90%\" align=\"center\"><tr bgcolor=\"$bgcolor1\" align=\"center\">";
-/*	if($ops==3 and ($genere==3 or ($genere==5 and $fascia>$limite)) )
-		echo "<td width=\"32\"><b>"._VOTI_LISTA."</b></td>";
-	else */
-		echo "<td width=\"32\"><b>"._VALIDI."</b></td>";
-	echo "<td width=\"82\"><b>"._NULLI."</b></td>"
-    ."<td><b>"._BIANCHI."</b></td>"
-	."<td width=\"32\"><b>"._VOTINULLI."</b></td>"
-	."<td><b>"._CONTESTATI."</b></td>"
-    ."<td><b>"._TOTNON."</b></td>"
-	."<td><b>"._TOTALEVOTI."</b></td>"
-	."<td bgcolor=\"#ffffff\"></td> </tr>";
-/*if($ops==3 and ($genere==3 or ($genere==5 and $fascia>$limite)) )
-    $result = mysql_query("select id_cons,id_sez,validi_lista,nulli,bianchi,contestati_lista,voti_nulli_lista,solo_gruppo,contestati,voti_nulli from ".$prefix."_ele_sezioni where id_cons='$id_cons' and id_sez='$id_sez' ";
-$res = $dbi->prepare("$sql");
-$res->execute();
-
-
-else */
-    $sql = "select id_cons,id_sez,validi,nulli,bianchi,contestati,voti_nulli,'0','0','0',solo_lista from ".$prefix."_ele_sezioni where id_cons='$id_cons' and id_sez='$id_sez' ";
-$result = $dbi->prepare("$sql");
-$result->execute();
-
-
-    list($id_cons2,$id_sez2,$validi, $nulli, $bianchi, $contestati,$votinulli,$sg,$conts,$nullis,$sololista) = $result->fetch(PDO::FETCH_NUM);
-    $tot_nulli=$nulli+$bianchi+$contestati+$votinulli;
-    $tot_voti=$validi+$tot_nulli+$conts+$nullis;
-//	."</td><td><input  name=\"sololista\" value=\"$sololista\" size=\"5\" style=\"text-align:right\">" ---     ."<td><b>"._SOLOLIS."</b></td>"
-
-
-	echo "<tr bgcolor=\"$bgcolor2\" align=\"center\"><td align=\"left\"><input  name=\"validi\" value=\"$validi\" size=\"5\" style=\"text-align:right\">";
-/*	if(($genere==3 or $genere==5) and !$votog and $ops==3){
-	echo "</td><td>$nulli"
-	."</td><td>$bianchi";
-	echo "<input type=\"hidden\" name=\"nulli\" value=\"$nulli\"><input type=\"hidden\" name=\"bianchi\" value=\"$bianchi\">";
-	}else{ */
-	echo "</td><td><input  name=\"nulli\" value=\"$nulli\" size=\"5\" style=\"text-align:right\">"
-	."</td><td><input  name=\"bianchi\" value=\"$bianchi\" size=\"5\" style=\"text-align:right\">";
-//	}
-	echo "</td><td><input  name=\"votinulli\" value=\"$votinulli\" size=\"5\" style=\"text-align:right\">"
-	."</td><td><input  name=\"contestati\" value=\"$contestati\" size=\"5\" style=\"text-align:right\">"
-	."</td><td>$tot_nulli"
-	."</td><td>$tot_voti</td><td>"
-    	."<input type=\"hidden\" name=\"genere\" value=\"$genere\">"
-    	."<input type=\"hidden\" name=\"ops\" value=\"$ops\">"
-       	."<input type=\"submit\" name=\"update\" value=\""._OK."\">"
-      	."</td></tr></table></form>"; //</td></tr>";
-
-
-//    echo "</table>";
-	echo "<SCRIPT type=\"text/javascript\">\n\n<!--\n";
-	if (!$validi) {
-		echo "document.spogliovoti.validi.focus()\n";
-		echo "document.spogliovoti.validi.select()\n";
-	}
-	echo "//-->\n"
-	."</script>\n";
-
-
-    }
-
-
-function preferenze_gruppi($id_cons,$do,$id_circ,$id_sede,$id_sez,$ops){
- global $aid, $prefix, $dbi, $tipo_cons, $genere,$id_cons_gen,$sezi,$circo,$dettnulli;
-////////////////////////////////////////////
-// da qua va la sezione per le preferenze ai gruppi
-///////////////////////////////////////////
-// Controllo immmissioni
-
-$bgcolor1="#7777ff";
-$bgcolor2=$_SESSION['bgcolor2'];
-$sql="SELECT * FROM ".$prefix."_ele_gruppo where id_cons='$id_cons' $circo ";
-$res = $dbi->prepare("$sql");
-$res->execute();
-
-
-    $max = $res->rowCount();
-    $max = $max-1;
-	 echo "<SCRIPT type=\"text/javascript\">\n\n<!--\n";
-	if ($genere==0) {
-		echo "document.sezioni.si1.focus()\n";
-		echo "document.sezioni.si1.select()\n";
-	} else {
-		echo "document.sezioni.voti1.focus()\n"
-		."document.sezioni.voti1.select()\n";
-	}
-	echo "//-->\n"
-	."</script>\n";
-// tabella votanti
-	echo "<center>";
-    if ($genere!=0){
-	$sql="SELECT voti_uomini,voti_donne, voti_complessivi FROM ".$prefix."_ele_voti_parziale where id_sez='$id_sez' and id_cons='$id_cons' order by data desc,orario desc limit 0,1";
-$result = $dbi->prepare("$sql");
-$result->execute();
-
-
-    list( $voti_u, $voti_d, $voti_t) = $result->fetch(PDO::FETCH_NUM);
-   	echo "<table  class=\"table-menu\" style=\"width: 50%; color: black;\">"
-	."<tr><td></td><td align=\"center\"></td><td bgcolor=\"$bgcolor1\" align=\"center\">"._VOTIU."</td><td bgcolor=\"$bgcolor1\" align=\"center\">"._VOTID."</td><td bgcolor=\"$bgcolor1\" align=\"center\">"._VOTIT."</td></tr>"
-	."<tr><td></td><td bgcolor=\"$bgcolor1\" align=\"center\">"._TOT_ULT."</td><td bgcolor=\"$bgcolor2\" align=\"center\">$voti_u</td><td align=\"center\" bgcolor=\"$bgcolor2\">$voti_d</td><td bgcolor=\"$bgcolor2\" align=\"center\">$voti_t</td></tr>";
-   	echo "</table>";
-    }
-	echo "<table  class=\"table-menu\" style=\"width: 50%; color: black\">";
-    if ($genere==0){
-    	$sql="SELECT id_gruppo,si+no,validi,nulli,bianchi,contestati FROM ".$prefix."_ele_voti_ref where id_cons='$id_cons' and id_sez='$id_sez'  ";
-$res = $dbi->prepare("$sql");
-$res->execute();
-
-
-		while (list($id_gruppo,$voti_parz,$validi,$nulli,$bianchi,$contestati) = $res->fetch(PDO::FETCH_NUM)){
-			if ($voti_parz!=$validi){
-				$sql="SELECT num_gruppo FROM ".$prefix."_ele_gruppo where id_cons='$id_cons' and id_gruppo='$id_gruppo'  ";
-$res2 = $dbi->prepare("$sql");
-$res2->execute();
-
-
-				list($num_gruppo) = $res2->fetch(PDO::FETCH_NUM);
-				echo "<tr><td style=\"background-color: rgb(255, 0, 0); text-align:center\"><img src=\"modules/Elezioni/images/alert.gif\" align=\"middle\" alt=\"\"><br><b> "._ATT_VOTI_REF." $num_gruppo: ".$voti_parz." "._NO_VAL_VOTI.": ".$validi."</b><br></td></tr>";
-			}
-			$sql="SELECT max(voti_complessivi) FROM ".$prefix."_ele_voti_parziale where id_cons='$id_cons' and id_sez='$id_sez' and id_gruppo='$id_gruppo' ";
-$res2 = $dbi->prepare("$sql");
-$res2->execute();
-
-
-			list($tot) = $res2->fetch(PDO::FETCH_NUM);
-			if (($validi+$nulli+$bianchi+$contestati)!= $tot ){
-				$sql="SELECT num_gruppo FROM ".$prefix."_ele_gruppo where id_cons='$id_cons' and id_gruppo='$id_gruppo'";
-$res2 = $dbi->prepare("$sql");
-$res2->execute();
-
-
-				list($num_gruppo) = $res2->fetch(PDO::FETCH_NUM);
-				echo "<tr><td style=\"background-color: rgb(255, 0, 0); text-align:center\"><img src=\"modules/Elezioni/images/alert.gif\" align=\"middle\" alt=\"\"><br><b> "._ATT_VOTANTI_REF." $num_gruppo: ".$tot." "._NO_SOMMA." ".($validi+$nulli+$bianchi+$contestati)."</b><br></td></tr>";
-			}
-		}
-    }else{
-	$sql="select solo_gruppo,disgiunto from ".$prefix."_ele_cons_comune where id_cons='$id_cons' ";
-$result = $dbi->prepare("$sql");
-$result->execute();
-
-
-	list($flagsg,$disgiunto)=$result->fetch(PDO::FETCH_NUM);
-    	$sql="SELECT sum(voti) FROM ".$prefix."_ele_voti_gruppo where id_cons='$id_cons' and id_sez='$id_sez'";
-$res = $dbi->prepare("$sql");
-$res->execute();
-
-
-       	list($voti_parz) = $res->fetch(PDO::FETCH_NUM);
-        $sql="SELECT validi,nulli,bianchi,contestati,solo_lista,voti_nulli FROM ".$prefix."_ele_sezioni where id_cons='$id_cons' and id_sez='$id_sez'";
-$res = $dbi->prepare("$sql");
-$res->execute();
-
-
-    	list($validi,$nulli,$bianchi,$contestati,$solo_lista,$votinulli) = $res->fetch(PDO::FETCH_NUM);
-		if ($voti_parz!=($validi-$solo_lista) and $voti_parz>0){
-			echo "<tr><td style=\"background-color: rgb(255, 0, 0); text-align:center\"><img src=\"modules/Elezioni/images/alert.gif\" align=\"middle\" alt=\"\"><br><b> "._ATT_VOTI." ".$voti_parz." "._NO_VAL_VOTI." ".($validi-$solo_lista)."</b><br></td><tr>";
-    	}
-		$sql="SELECT max(voti_complessivi) FROM ".$prefix."_ele_voti_parziale where id_cons='$id_cons' and id_sez='$id_sez'";
-$res2 = $dbi->prepare("$sql");
-$res2->execute();
-
-
-		list($tot) = $res2->fetch(PDO::FETCH_NUM);
-		if ($validi+$nulli+$bianchi+$contestati+$votinulli!=$tot and $validi+$nulli+$bianchi+$contestati+$votinulli>0){
-			echo "<tr><td style=\"background-color: rgb(255, 0, 0); text-align:center\"><img src=\"modules/Elezioni/images/alert.gif\" align=\"middle\" alt=\"\"><br><b> "._ATT_VOTANTI." ".$tot." "._NO_TOT_VOTI." ".($validi+$nulli+$bianchi+$contestati+$votinulli)."</b><br></td></tr>";
-    	}
-		$sql="SELECT sum(voti) from ".$prefix."_ele_voti_lista where id_cons=$id_cons and id_sez=$id_sez";
-		$resg = $dbi->prepare("$sql");
-		$resg->execute();
-
-
-		list($voti_sez)=$resg->fetch(PDO::FETCH_NUM);
-		if(($genere==5 and !$disgiunto and $voti_sez and $flagsg and ($tipo_cons==18 or $tipo_cons==19))){
-
-			$sql="SELECT sum(solo_gruppo) from ".$prefix."_ele_voti_gruppo where id_cons=$id_cons and id_sez=$id_sez";
-			$resg = $dbi->prepare("$sql");
-			$resg->execute();
-
-
-			list($sgpl)=$resg->fetch(PDO::FETCH_NUM);
-			$sql="SELECT solo_gruppo from ".$prefix."_ele_sezioni where id_cons=$id_cons and id_sez=$id_sez";
-			$resg = $dbi->prepare("$sql");
-			$resg->execute();
-
-
-			list($sg)=$resg->fetch(PDO::FETCH_NUM);
-			if ($sg != $sgpl) echo "<tr><td style=\"background-color: rgb(255, 0, 0); color: black; text-align: center\"><img src=\"modules/Elezioni/images/alert.gif\" align=\"middle\" alt=\"\"><br><b> "._ATT_UNI." ".$sgpl." "._ATT_TOT_UNI." ".$sg."</b><br></td></tr>";
-		}
-#controllo voti a liste collegate <= voto di gruppo per voto non disgiunto
-if($genere==5 and !$disgiunto and $flagsg  and ($tipo_cons==18 or $tipo_cons==19)){
-$sql="SELECT id_gruppo FROM ".$prefix."_ele_gruppo where id_cons='$id_cons' $circo";
-$resref = $dbi->prepare("$sql");
-$resref->execute();
-
-
-		$errgrulis=array();
-		$sql="SELECT count(0) FROM ".$prefix."_ele_voti_lista where id_sez='$id_sez'";
-		$res4 = $dbi->prepare("$sql");
-		$res4->execute();
-
-
-		list($sezscrl)=$res4->fetch(PDO::FETCH_NUM); 
-		if ($sezscrl)
-                while ( list($id_gruppo)=$resref->fetch(PDO::FETCH_NUM))
-                {
-					if($disgiunto || $flagsg){	
-						$sql="SELECT sum(voti-solo_gruppo) FROM ".$prefix."_ele_voti_gruppo where id_sez='$id_sez' and id_gruppo='$id_gruppo'";
-						$res3 = $dbi->prepare("$sql");
-						$res3->execute();
-						if($flagsg){
-							$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();
-						}else{
-							$sql="SELECT sum(voti) 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();							
-						}
-					}else{
-						$sql="SELECT sum(voti) FROM ".$prefix."_ele_voti_gruppo where id_sez='$id_sez' and id_gruppo='$id_gruppo'";
-						$res3 = $dbi->prepare("$sql");
-						$res3->execute();
-						$sql="SELECT sum(voti) FROM ".$prefix."_ele_voti_lista where id_sez='$id_sez' and  id_lista in (select id_lista from ".$prefix."_ele_lista where id_gruppo='$id_gruppo')";						
-						$res4 = $dbi->prepare("$sql");
-						$res4->execute();
-					}
-                    list($vgruppo)=$res3->fetch(PDO::FETCH_NUM);
-                    list($vliste)=$res4->fetch(PDO::FETCH_NUM);
-                    if($vliste>$vgruppo and !$disgiunto )
-                    	{
-                    	$sql="SELECT descrizione FROM ".$prefix."_ele_gruppo where id_gruppo='$id_gruppo'";
- 						$result = $dbi->prepare("$sql");
-						$result->execute();
-						list($dgruppo)=$result->fetch(PDO::FETCH_NUM);
-                    	echo "<table class=\"table-menu\" style=\"width: 50%;\"><tr><td style=\"background-color: rgb(255, 0, 0); color: black; text-align: center\"><img src=\"modules/Elezioni/images/alert.gif\" align=\"middle\" alt=\"\"><br/><b> ATTENZIONE!<BR/>I voti delle liste collegate $vliste<br/> superano i voti assegnati al gruppo $dgruppo $vgruppo</b><br></td></tr></table>";
-                    	$errgrulis[$id_gruppo]=1;
-                    	}
-                    elseif($vliste<$vgruppo and $disgiunto )
-                    	{
-                    	$sql="SELECT descrizione FROM ".$prefix."_ele_gruppo where id_gruppo='$id_gruppo'";
- 						$result = $dbi->prepare("$sql");
-						$result->execute();
-                    	list($dgruppo)=$result->fetch(PDO::FETCH_NUM);
-                    	echo "<table class=\"table-menu\" style=\"width: 50%;\"><tr><td style=\"background-color: rgb(255, 0, 0); color: black; text-align: center\"><img src=\"modules/Elezioni/images/alert.gif\" align=\"middle\" alt=\"\"><br/><b> ATTENZIONE!<BR/>I voti assegnati al gruppo $dgruppo<br/> superano i voti delle liste collegate </b><br></td></tr></table>";
-                    	$errgrulis[$id_gruppo]=1;
-                    	}
-                }
-		}
-
-    }
-    if(!isset($votinulli)) $votinulli=0;
-	echo "<tr><td></td></tr></table>";
-	if ($validi+$nulli+$bianchi+$contestati+$votinulli>0 or $genere==0) {
- 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\">"
-	."<td width=\"3%\"><b>"._NUM."</b></td>"
-    ."<td width=\"50%\"><b>"._GRUPPO."</b></td>";
-	if ($genere==0){
-		echo "<td><b>"._SI."</b></td>"
-		."<td><b>"._NO."</b></td>"
-		."<td><b>"._VALIDI."</b></td>"
-		."<td><b>"._BIANCHI."</b></td>"
-		."<td><b>"._CONTESTATI."</b></td>"
-		."<td><b>"._NULLI."</b></td>"
-		."<td><b>"._TOTNON."</b></td>"
-		."<td><b>"._TOTALEVOTI."</b></td>"
-		."<td><b>"._VOTANTI."</b></td>";
-	}else{
-		echo "<td width=\"5%\"><b>"._VOTI."</b></td>";
-		if($dettnulli)		echo "<td bgcolor=\"$bgcolor1\" align=\"center\"><b>"._SOLO_GRUPPO."</b></td>";
-	}
-    echo "</tr>";
-    $sql="SELECT * FROM ".$prefix."_ele_gruppo where id_cons='$id_cons' $circo ORDER BY num_gruppo ";
-$res = $dbi->prepare("$sql");
-$res->execute();
-
-
-    $max = $res->rowCount();
-    //echo "Massimo:$max - id=$id_cons - circo: $circo";
-    $sql="select * from ".$prefix."_ele_gruppo where id_cons='$id_cons' $circo ORDER BY num_gruppo  ";
-$result = $dbi->prepare("$sql");
-$result->execute();
-
-
-    $i=1;
-	$tot_pref=0;
-       $totsg=0;
-    while(list($id_cons2,$id_gruppo,$num_gruppo, $descr_gruppo, $simbolo) = $result->fetch(PDO::FETCH_NUM)){
-  
-      //echo "test: $id_cons2,$id_gruppo,$num_gruppo, $descr_gruppo, $simbolo";
-  		echo "<SCRIPT type=\"text/javascript\">\n\n<!--\n"
-		
-		."//-->\n";
-		echo "function controlloref$i() {\n";
-		echo "var a=Number(window.document.sezioni.si$i.value); var b=Number(window.document.sezioni.no$i.value); if(a=='NaN') {a=0} if(b=='NaN') {b=0} var c=a + b; window.document.sezioni.val$i.value=c\n";
-		echo "}\n";
-		echo "</script>\n";    
-
-     if ($num_gruppo != ''){
-	if ($genere==0){
-		$sql="SELECT max(voti_complessivi) FROM ".$prefix."_ele_voti_parziale where id_cons='$id_cons' and id_sez='$id_sez' and id_gruppo='$id_gruppo' ";
-$res = $dbi->prepare("$sql");
-$res->execute();
-
-
-		list($tot) = $res->fetch(PDO::FETCH_NUM);
-		$sql="SELECT * FROM ".$prefix."_ele_voti_ref where id_cons='$id_cons' and id_sez='$id_sez' and id_gruppo='$id_gruppo' ";
-$res = $dbi->prepare("$sql");
-$res->execute();
-
-
-		$pro= $res->fetch(PDO::FETCH_BOTH);
-	
-		if ($pro['si']+$pro['no']!=$pro['validi'] or ($pro['validi']+$pro['nulli']+$pro['bianchi']+$pro['contestati']!=$tot and $pro['validi']+$pro['nulli']+$pro['bianchi']+$pro['contestati']!=0)){
-			echo "<tr style=\"background-color: rgb(255, 0, 0); text-align:center\">";
-		}else{
-			echo "<tr style=\"background-color: $bgcolor2; text-align:center\">";
-		}
-		$descr = explode('.',$descr_gruppo, 100);
-		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']:'';
-		$tot_nulli=intval($pro['nulli'])+intval($pro['bianchi'])+intval($pro['contestati']);
-		$tot_voti=intval($pro['validi'])+$tot_nulli;
-		echo "</td><td align=\"right\" width=\"3%\"><input  name=\"si$i\" value=\"".$pro['si']."\" size=\"7\"  style=\"text-align:right\" onchange=controlloref$i()></td>";
-		echo "</td><td align=\"right\" width=\"3%\"><input  name=\"no$i\" value=\"".$pro['no']."\" size=\"7\"  style=\"text-align:right\" onchange=controlloref$i()></td>";
-		echo "</td><td align=\"right\" width=\"3%\"><input  name=\"val$i\" value=\"".$pro['validi']."\" size=\"7\" style=\"text-align:right\" ></td>";
-		echo "</td><td align=\"right\"><input  name=\"bia$i\" value=\"".$pro['bianchi']."\" size=\"7\"  style=\"text-align:right\"></td>";
-		echo "</td><td align=\"right\"><input  name=\"con$i\" value=\"".$pro['contestati']."\" size=\"7\"  style=\"text-align:right\"></td>";
-		echo "</td><td align=\"right\"><input  name=\"nul$i\" value=\"".$pro['nulli']."\" size=\"7\"  style=\"text-align:right\"></td>";
-		echo "</td><td align=\"right\">$tot_nulli</td>";
-		echo "</td><td align=\"right\">$tot_voti</td>";
-		echo "</td><td align=\"right\">$tot</td>";
-	}else{
-		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' ";
-		$res = $dbi->prepare("$sql");
-		$res->execute();
-
-		$pro= $res->fetch(PDO::FETCH_BOTH);
-		if(!$res->rowCount()) {$pro['voti']=''; $pro['solo_gruppo']='';}
-		$errcolor='';
-		if(isset($errgrulis[$id_gruppo])) $errcolor="style=\"background-color: rgb(255, 0, 0);\"";
-		echo "</td><td align=\"right\" $errcolor><input  name=\"voti$i\" value=\"".$pro['voti']."\" size=\"7\"  style=\"text-align:right\"></td>";
-
-		if($dettnulli) {echo "<td align=\"right\"><input name=\"solog$i\" value=\"".$pro['solo_gruppo']."\" size=\"7\"  style=\"text-align:right\"></td>"; $totsg+=intval($pro['solo_gruppo']);} 
-		$tot_pref += intval($pro['voti']);
-		echo "</tr>";
-	}
-	
-	$i++;
-    }
-
-   }
-	if ($genere!=0) {
-		$sql="SELECT disgiunto FROM ".$prefix."_ele_cons_comune where id_cons='$id_cons' ";
-$res = $dbi->prepare("$sql");
-$res->execute();
-
-
-		list($disgiunto)=$res->fetch(PDO::FETCH_NUM);
-		$sql="SELECT solo_lista FROM ".$prefix."_ele_sezioni where id_sez='$id_sez' ";
-$res = $dbi->prepare("$sql");
-$res->execute();
-
-
-		list($sololis)=$res->fetch(PDO::FETCH_NUM);
-		echo "<tr style=\"background-color: $bgcolor1; text-align:center\"><td></td><td>"._TOTPREF."</td><td>$tot_pref</td>";
-		if($dettnulli) echo "<td>$totsg</td>";
-		echo "</tr>";
-		if($disgiunto)
-			echo "<tr style=\"background-color: $bgcolor1; text-align:center\"><td></td><td>"._SOLOLIS."</td><td><input  name=\"sololista\" value=\"".$sololis."\" size=\"7\"  style=\"text-align:right\"></td></tr>";
-	}
-
-   echo "<tr><td></td><td></td><td align=\"center\"><input type=\"submit\" name=\"update\" id=\"update\" value=\" "._OK. "\"></td>";
-
-    echo "</tr></table></form></td></tr>";
-		if(chisei($id_cons_gen)>=64){
-			echo "<tr><td><input type=\"checkbox\" id=\"pwd3\" name=\"pwd3\" value=\"\" onclick=\"javascript:del_dati()\">"._DELETE."";
-		}
-
-	echo "</td></tr></table></center>";
-	}
-    if ($genere!=0){
-    	finale($id_cons,$do,$id_circ,$id_sede,$id_sez,$ops);
-    }
-}
 
 
Index: trunk/admin/modules/Elezioni/ele_widget.php
===================================================================
--- trunk/admin/modules/Elezioni/ele_widget.php	(revision 359)
+++ trunk/admin/modules/Elezioni/ele_widget.php	(revision 360)
@@ -20,5 +20,5 @@
 $currentlang=$_SESSION['lang'];
 $param=strtolower($_SERVER['REQUEST_METHOD']) == 'get' ? $_GET : $_POST;
-$id_cons_gen=$param['id_cons_gen'];	
+$id_cons_gen=intval($param['id_cons_gen']);	
 $perms=ChiSei($id_cons_gen);
 if ($perms<32) die("Non hai i permessi per inserire dati, o non hai scelto la consultazione!");
@@ -41,5 +41,5 @@
 if (isset($param['attivo'])) $attivo=intval($param['attivo']); else $attivo='';
 
-
+/*
 ############# controllo dei widget
         make_db_widget(); // crea tabella se non esiste
@@ -103,5 +103,5 @@
 		}
 
-
+*/
 
 /******************************************************/
Index: trunk/admin/modules/Elezioni/importa.php
===================================================================
--- trunk/admin/modules/Elezioni/importa.php	(revision 359)
+++ trunk/admin/modules/Elezioni/importa.php	(revision 360)
@@ -35,5 +35,7 @@
 		elseif ($key==1) {$valori.= "null"; $oldidg=$campo;}
 		elseif ($key==6) $valori.= ",0";
-		else $valori.= ",'$campo'";
+		elseif($key==4 || $key==8) $valori.=",'".utf8_encode($campo)."'";
+		elseif($key==9) $valori.=",''";
+		else $valori.= ",'".$campo."'";
 		if ($key==2) $numgruppo= $campo;
 		if ($key==8) $isnew=1;
@@ -43,6 +45,12 @@
 
 		$sql="insert into ".$prefix."_ele_gruppo values($valori)";
+	try {
 		$res_gruppo = $dbi->prepare("$sql");
 		$res_gruppo->execute();	
+	}
+	catch(PDOException $e)
+	{
+		echo $sql . "<br>" . $e->getMessage();
+	}                  
 		$sql="select id_gruppo from ".$prefix."_ele_gruppo where num_gruppo='$numgruppo' and id_cons='$idcns'";
 		$resnew = $dbi->prepare("$sql");
@@ -60,25 +68,45 @@
 {
 global $prefix, $dbi;
-global $ar_lista,$ar_candi,$idcns;
-
-	foreach ($ar_lista as $rigalista){
+global $ar_lista,$idcns;
+
+	foreach ($ar_lista as $rigalista){ 
 		if(!isset($rigalista[3])) continue;
 		$oldidl=0;
 		$okl=0; 
 		$oldidg=$rigalista[3];
-		$newidg=$_SESSION['gruppi']['idg_'.$oldidg];
+		if(isset($_SESSION['gruppi'])) $newidg=$_SESSION['gruppi']['idg_'.$oldidg]; else $newidg=0;
 		foreach($rigalista as $key=>$campo){
-			if ($key==0) $valori="'$idcns',";
-			elseif ($key==1) {$valori.= "null";$oldidl=$campo;}
-			elseif ($key==3) {$valori.= ",'$newidg'"; if ($campo!=$oldidg) $okl=1;}
-			elseif ($key==4) $valori.= ",0"; 
-			else $valori.= ",'$campo'";
-			if ($key==2) $numlista= $campo;
+			if ($key==0) $valori=$idcns.",";
+/*			elseif ($key==1) {$oldidl=$campo;} 
+			elseif ($key==2) {$num_lista=$campo;$numlista=$campo;}
+			elseif ($key==3) {$id_gruppo=$newidg; if ($campo!=$oldidg) $okl=1;}
+			elseif ($key==5) $id_circ=$campo;			
+			elseif ($key==7) $descr_lista=$campo;			
+			elseif ($key==8) $stemmanome=$campo;			
+			elseif ($key==9) $stemmablob=$campo;			
+*/			
+			elseif ($key==1) {$valori.= "null,";$oldidl=$campo;}
+			elseif ($key==2) {$valori.="'$campo',";$numlista= $campo;}
+			elseif ($key==3) {$valori.= "'$newidg',"; if ($campo!=$oldidg) $okl=1;}
+			elseif ($key==4) $valori.= "0,"; 
+			elseif ($key==9 ) $valori.= "'$campo'"; 
+#			else $valori.= "'$campo',"; # htmlentities(stripslashes(utf8_decode($_POST['parola'])));
+			else $valori.="'".utf8_encode($campo)."',";
+#			else $valori.= "'".htmlentities($campo, ENT_QUOTES, "UTF-8")."',";  htmlspecialchars($str, ENT_QUOTES)
 		}
-		if(isset($valori)){
+		if($key==9){
 		if ($okl) {$okl=0;continue;}
+#		$valori2=htmlentities($valori);
+#			$sql="insert into ".$prefix."_ele_lista (id_cons,num_lista,id_gruppo,id_circ,descrizione,simbolo,stemma) values ('$id_cons','$num_lista','$id_gruppo','$id_circ','$descr_lista','$stemmanome','$stemmablob')";
 		$sql="insert into ".$prefix."_ele_lista values($valori)";
+	try {
 		$res_lista = $dbi->prepare("$sql");
-		$res_lista->execute();	
+		$res_lista->execute();
+	}
+	catch(PDOException $e)
+	{
+		echo $sql . "<br>" . $e->getMessage();
+	}                  
+			
 		$sql="select id_lista from ".$prefix."_ele_lista where num_lista='$numlista' and id_cons='$idcns'";
 		$reslnew = $dbi->prepare("$sql");
@@ -86,10 +114,11 @@
 		list ($newidl) = $reslnew->fetch(PDO::FETCH_NUM);
 		unset($valori);
-		if($oldidl)
+		if($oldidl){
 			$_SESSION['liste']['idl_'.$oldidl]=$newidl; 
-
+echo "id_lista:$oldidl:$newidl<br>";
+		}
 #		inscandi($oldidl,$newidl);
 		}
-}
+	}
 }
 
@@ -109,11 +138,20 @@
 				elseif ($key==1) $valori.="'$idcns',";
 				elseif ($key==2) {$valori.= "'$newidl'"; if ($campo!=$oldidl) $okc=1;}
-				else $valori.= ",'$campo'";
+				else $valori.= ",'".utf8_encode($campo)."'";
 			}
-			if(isset($valori)){
+			if(isset($valori) and $valori!=''){
 				if ($okc) {$okc=0;continue;}
+#				$valori2=addslashes($valori);
 				$sql="insert into ".$prefix."_ele_candidati values($valori)";
-				$res_lista = $dbi->prepare("$sql");
-				$res_lista->execute();	
+#				$res_lista = $dbi->prepare("$sql");
+#				$res_lista->execute();	
+				try {
+					$res_lista = $dbi->prepare("$sql");
+					$res_lista->execute();
+				}
+				catch(PDOException $e)
+				{
+					echo "<br>key:$key sql:".$sql . "<br>" . $e->getMessage();
+				}                  
 			}
 		}
@@ -268,5 +306,5 @@
 	}
 elseif ($numlista) {
-	inslista(0,0);
+#	inslista();
 	Header("Location: admin.php?op=lista&id_cons_gen=$id_cons_gen");
 	}
Index: trunk/admin/modules/Elezioni/salva_liste.php
===================================================================
--- trunk/admin/modules/Elezioni/salva_liste.php	(revision 359)
+++ trunk/admin/modules/Elezioni/salva_liste.php	(revision 360)
@@ -41,7 +41,7 @@
 if (isset($_GET['valista'])) $validi=intval($_GET['valista']); else $validi='0';
 if (isset($_GET['nulli'])) $nulli=intval($_GET['nulli']); else $nulli='0';
-if (isset($_GET['bianchi'])) $bianchi=addslashes($_GET['bianchi']); else $bianchi='0';
-if (isset($_GET['contestati'])) $contestati=addslashes($_GET['contestati']); else $contestati='0';
-if (isset($_GET['votinulli'])) $votinulli=addslashes($_GET['votinulli']); else $votinulli='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='3';
Index: trunk/admin/modules/Elezioni/scarica.php
===================================================================
--- trunk/admin/modules/Elezioni/scarica.php	(revision 359)
+++ trunk/admin/modules/Elezioni/scarica.php	(revision 360)
@@ -29,7 +29,7 @@
 if (isset($param['fase'])) $fase=intval($param['fase']); else $fase=0;
 if (isset($param['id_cons_gen2'])) $id_cons_gen2=intval($param['id_cons_gen2']); else $id_cons_gen2='0';
-if (isset($param['indirizzoweb'])) $indirizzoweb=addslashes($param['indirizzoweb']); else $indirizzoweb='http://www.eleonline.it/client/';
+if (isset($param['indirizzoweb'])) $indirizzoweb=addslashes($param['indirizzoweb']); else $indirizzoweb='https://www.eleonline.it/client/';
 if (isset($param['id_comune2'])) $id_comune2=intval($param['id_comune2']); else $id_comune2='0';
-
+# htmlentities($param['indirizzoweb'], ENT_COMPAT, 'UTF-8')
 /******************************************************/
 /*Funzione di visualizzazione globale                 */
@@ -39,58 +39,46 @@
 	if (isset($help)) include("language/$language/ele_scarica.html");
 
-$bgcolor1=$_SESSION['bgcolor1'];
-$bgcolor2=$_SESSION['bgcolor2'];
-
-if ($fase=='0'){
-
-	echo "<form name=\"import\" action=\"admin.php\">";
-	echo "<table border=\"0\" width=\"100%\"><tr bgcolor=\"$bgcolor2\">";
-	echo "<td><b>"._INDIRIZZOWEB1."</b></td>";
-	echo "<td><input type=\"hidden\" name=\"id_cons_gen\" value=\"$id_cons_gen\"><input type=\"hidden\" name=\"op\" value=\"scarica\"><input type=\"hidden\" name=\"fase\" value=\"1\"><input type=\"text\" name=\"indirizzoweb\" size=\"50\" value=\"".$indirizzoweb."\"></td></tr>";
-	echo "<td><input type=\"submit\" name=\"add\" value=\""._OK."\"></td>";
-echo "</tr></table><br>";
-	echo "</form>";
-}elseif ($fase=='1'){
-$rem_cons="<script type=\"text/javascript\" src=\"$indirizzoweb/file.php?fase=1\"></script>";
-
-	echo "<form name=\"import\" action=\"admin.php\">";
-	echo "<table border=\"0\" width=\"100%\"><tr bgcolor=\"$bgcolor2\">";
-	echo "<td><b>"._INDIRIZZOWEB1."</b></td>";
-	echo "<td><input type=\"hidden\" name=\"id_cons_gen\" value=\"$id_cons_gen\"><input type=\"hidden\" name=\"op\" value=\"scarica\"><input type=\"hidden\" name=\"fase\" value=\"2\"><input type=\"hidden\" name=\"indirizzoweb\" value=\"$indirizzoweb\">$indirizzoweb</td></tr>";
-	echo "<tr><td><b>"._SCARICACONS."</b></td>";
-
-	echo "<td>$rem_cons</td></tr>";
-
+	$bgcolor1=$_SESSION['bgcolor1'];
+	$bgcolor2=$_SESSION['bgcolor2'];
+	if ($fase=='0'){
+		echo "<form name=\"import\" action=\"admin.php\">";
+		echo "<table border=\"0\" width=\"100%\"><tr bgcolor=\"$bgcolor2\">";
+		echo "<td><b>"._INDIRIZZOWEB1."</b></td>";
+		echo "<td><input type=\"hidden\" name=\"id_cons_gen\" value=\"$id_cons_gen\"><input type=\"hidden\" name=\"op\" value=\"scarica\"><input type=\"hidden\" name=\"fase\" value=\"1\"><input type=\"text\" name=\"indirizzoweb\" size=\"50\" value=\"".$indirizzoweb."\"></td></tr>";
+		echo "<td><input type=\"submit\" name=\"add\" value=\""._OK."\"></td>";
+		echo "</tr></table><br>";
+		echo "</form>";
+	}elseif ($fase=='1'){
+		$urlrem="$indirizzoweb/file.php?fase=1";
+		$rem_cons="<script type=\"text/javascript\" src=\"$urlrem\" crossorigin=\"anonymous\"></script>";
+		echo "<form name=\"import\" action=\"admin.php\">";
+		echo "<table border=\"0\" width=\"100%\"><tr bgcolor=\"$bgcolor2\">";
+		echo "<td><b>"._INDIRIZZOWEB1."</b></td>";
+		echo "<td><input type=\"hidden\" name=\"id_cons_gen\" value=\"$id_cons_gen\"><input type=\"hidden\" name=\"op\" value=\"scarica\"><input type=\"hidden\" name=\"fase\" value=\"2\"><input type=\"hidden\" name=\"indirizzoweb\" value=\"$indirizzoweb\">$indirizzoweb</td></tr>";
+		echo "<tr><td><b>"._SCARICACONS."</b></td>";
+		echo "<td>".$rem_cons."</td></tr>";
 		echo "<tr><td><input type=\"submit\" name=\"add\" value=\""._OK."\"></td>";
-
-echo "</tr></table><br>";
-	echo "</form>";
+		echo "</tr></table><br>";
+		echo "</form>";
 	}elseif($fase=='2'){
-
-$sql="SELECT descrizione from ".$prefix."_ele_consultazione WHERE id_cons_gen=$id_cons_gen2";
-$res = $dbi->prepare("$sql");
-$res->execute();
-list($descrcons) = $res->fetch(PDO::FETCH_NUM);
-$rem_cons="<script type=\"text/javascript\" src=\"$indirizzoweb/file.php?fase=2&id_cons_gen2=$id_cons_gen2\"></script>";
-
-	echo "<form name=\"import\" action=\"admin.php\">";
-	echo "<table border=\"0\" width=\"100%\"><tr bgcolor=\"$bgcolor2\">";
-	echo "<td><b>"._INDIRIZZOWEB1."</b></td>";
-	echo "<td><input type=\"hidden\" name=\"id_cons_gen\" value=\"$id_cons_gen\"><input type=\"hidden\" name=\"op\" value=\"scarica\"><input type=\"hidden\" name=\"fase\" value=\"3\"><input type=\"hidden\" name=\"indirizzoweb\" value=\"$indirizzoweb\">$indirizzoweb</td></td></tr>";
-$cons_rem=addslashes($_GET[($id_cons_gen2)]);
-echo "<tr><td><b>"._CONSULTA.":</b></td><td>$cons_rem</td></tr>";
-	echo "<tr><td><b>"._SCELTACOMUNE."</b></td><td>$rem_cons</td></tr>";
-
+		$sql="SELECT descrizione from ".$prefix."_ele_consultazione WHERE id_cons_gen=$id_cons_gen2";
+		$res = $dbi->prepare("$sql");
+		$res->execute();
+		list($descrcons) = $res->fetch(PDO::FETCH_NUM);
+		$rem_cons="<script type=\"text/javascript\" src=\"$indirizzoweb/file.php?fase=2&id_cons_gen2=$id_cons_gen2\"></script>";
+		echo "<form name=\"import\" action=\"admin.php\">";
+		echo "<table border=\"0\" width=\"100%\"><tr bgcolor=\"$bgcolor2\">";
+		echo "<td><b>"._INDIRIZZOWEB1."</b></td>";
+		echo "<td><input type=\"hidden\" name=\"id_cons_gen\" value=\"$id_cons_gen\"><input type=\"hidden\" name=\"op\" value=\"scarica\"><input type=\"hidden\" name=\"fase\" value=\"3\"><input type=\"hidden\" name=\"indirizzoweb\" value=\"$indirizzoweb\">$indirizzoweb</td></td></tr>";
+		$cons_rem=addslashes($_GET[($id_cons_gen2)]);
+		echo "<tr><td><b>"._CONSULTA.":</b></td><td>$cons_rem</td></tr>";
+		echo "<tr><td><b>"._SCELTACOMUNE."</b></td><td>$rem_cons</td></tr>";
 		echo "<tr><td><input type=\"submit\" name=\"add\" value=\""._OK."\"></td>";
-
-echo "</tr></table><br>";
-	echo "</form>";
-
+		echo "</tr></table><br>";
+		echo "</form>";
 	}elseif ($fase=='3'){
-
-$id_cons_gen2=$_GET['id_cons_gen2'];
-$id_comune2=$_GET['id_comune2'];
-Header("Location: $indirizzoweb/modules.php?op=backup&id_cons_gen=$id_cons_gen2&id_comune=$id_comune2");
-
+		$id_cons_gen2=$_GET['id_cons_gen2'];
+		$id_comune2=$_GET['id_comune2'];
+		Header("Location: $indirizzoweb/modules.php?op=backup&id_cons_gen=$id_cons_gen2&id_comune=$id_comune2");
 	} 
 }
Index: trunk/admin/temi/Futura2/index.php
===================================================================
--- trunk/admin/temi/Futura2/index.php	(revision 359)
+++ trunk/admin/temi/Futura2/index.php	(revision 360)
@@ -16,13 +16,21 @@
 }
 
-include("header.php");
+
+
+include_once("header.php");
 $nometema=$tema;
+#require_once("class/db/db.php"); //classe db
+global $tema,$id_comune,$descr_cons,$multicomune,$dbi,$prefix,$currentlang,$ops,$id_sez,$id_cons,$id_cons_gen;
+include_once("modules/Elezioni/query.sql");
+#if(($tema='Futura2' and !$id_sez) or $_SESSION['id_cons']!=$id_cons) {Header("Location: admin.php?id_comune=$id_comune&op=logout&is=$id_sez"); die();}
+#die( "OP: $op - aid:".$_SESSION['aid']." - tema:$tema");
+include_once("modules/Elezioni/ele_spoglio.php");
+$row=setconsultazione(); 
+$sql="select id_sez from ".$prefix."_ele_operatori where aid='$aid' and id_cons=$id_cons";
+$res = $dbi->prepare("$sql");
+$res->execute();
 
-#require_once("class/db/db.php"); //classe db
-global $tema,$id_comune,$descr_cons,$multicomune,$dbi,$prefix,$currentlang,$ops,$id_sez;
-include_once("modules/Elezioni/query.sql");
-if(($tema='Futura2' and !$id_sez) or $_SESSION['id_cons']!=$id_cons) {Header("Location: admin.php?id_comune=$id_comune&op=logout&is=$id_sez"); die();}
+list($id_sez) = $res->fetch(PDO::FETCH_NUM);#include("TEST:$id_sez:$sql:");
 
-$row=setconsultazione(); 
 if(isset($row[0])) {
 	$tipo_cons=$row[0]; $descr_cons=$row[1]; $id_cons_gen=$row[2];
@@ -37,7 +45,4 @@
 }
 
-# colore tema mobile
-
-
 include("temi/$tema/config.php");
 
@@ -50,5 +55,5 @@
 
 list($descr_com) = $res->fetch(PDO::FETCH_NUM);
-include_once("header.php");
+#include_once("header.php");
 testata();
 
@@ -59,265 +64,93 @@
 global $op,$tema,$dbi,$nometema,$file,$bgcolor,$sitename,$prefix,$blocco,$lang,$siteistat,$id_cons_gen,$descr_cons,$minsez,$offsetsez,$multicomune,$id_comune,$multicomune,$rss,$colortheme,$descr_com;
 global $id_cons,$do,$id_circ,$id_sede,$id_sez,$ops,$ov,$mv,$gv,$msv,$av,$votog,$genere,$aid,$bgcolor1,$language;
+
 include("temi/$tema/function_theme.php");
-#$op='informazioni';
-#$logo= "<img src=\"admin.php?name=Elezioni&amp;file=foto&amp;id_comune=".$id_comune."\" alt=\"logo\" width=\"70\" align=\"left\"/>";
 $logo='';
-#echo"togliere combo consultazioni e impostare su consultazione predefinita e sezione fissata su autorizza operatori (nuovo tipo: per unica sezione - spostare voci di menu, affluenze, gruppi. liste al posto della combo e togliere menu verticale)";
+
+echo "<SCRIPT type=\"text/javascript\">\n";
+echo "function vai_cong(idrif){\n";
+echo "document.getElementById('frm').submit()\n";
+echo "}\n";
+echo "function vai_scelta(idrif){\n";
+echo "window.document.location.href=idrif\n";
+echo "}\n";
+echo "</script>\n"; 
+
+#
+if(!$ops) $ops=1;
 $sql="SELECT descrizione FROM ".$prefix."_ele_comuni where id_comune='$id_comune' ";
-	$res = $dbi->prepare("$sql");
-	$res->execute();
-
-	list($descr_com) = $res->fetch(PDO::FETCH_NUM);
-        $descr_com =stripslashes($descr_com); 
+$res = $dbi->prepare("$sql");
+$res->execute();
+list($descr_com) = $res->fetch(PDO::FETCH_NUM);
+$descr_com =stripslashes($descr_com); 
 
 echo '
 <div data-role="page" data-theme="a">
-	<div data-role="header" data-position="inline">';
-	
-	/*
-	if($op!="gruppo") 
-		echo '<a href="#" onClick="javascript:history.back()" data-role="button" data-icon="arrow-left">indietro</a>';
-	else 	echo '<a href="modules.php?tema=facebook" target="_blank" data-icon="off" data-role="button">Vers Web</a>';
-	*/
-	//
-	# se aperta o sezioni scrutinate 
-	# se non Ãš il menu di config o about sceglie elezione
-
-	   echo '<h2>Elezioni on line</h2>'; 
-
-#	   echo '<a href="admin.php?name=Elezioni&op=about&id_comune='.$id_comune.'&id_cons_gen='.$id_cons_gen.'" data-theme="c" data-icon="user">About</a>';
-	
-
-####### menu in alto
-# definizione attivo
-#echo "TEST: ".$_SESSION['BASE'];
-#echo "TEST: ".$_SERVER['REQUEST_URI'];
-#echo "TEST: ".$_SERVER['PHP_SELF']; 
-			$sql="select tipo from ".$prefix."_ele_controlli where id_sez='$id_sez' group by tipo";
-			$rese = $dbi->prepare("$sql");
-			$rese->execute();
-			$bordoa='';
-			$bordog='';
-			$bordol='';
-			while (list($tipo)=$rese->fetch(PDO::FETCH_NUM)) {
-				if ($tipo=='affluenze') $bordoa="style=\"border: 6px solid; border-color: rgb(255, 0, 0);\"";
-				if ($tipo=='gruppo') $bordog="style=\"border: 6px solid; border-color: rgb(255, 0, 0);\"";
-				if ($tipo=='lista') $bordol="style=\"border: 6px solid; border-color: rgb(255, 0, 0);\"";
-			}
-			if($rese->rowCount()) $segna="style=\"background-color: #dd0000;\""; else $segna='';
+<div data-role="header" data-position="inline">';
+echo '<h2 style="color: white;">Elezioni on line</h2>'; 
+$oggi=date("Y-m-d",mktime(0,0,0,date("m"),date("d")-3,date("Y")));
+$sql="select t1.id_cons_gen,t1.descrizione from ".$prefix."_ele_consultazione as t1, ".$prefix."_ele_cons_comune as t2 where t1.id_cons_gen=t2.id_cons_gen and t2.id_comune=$id_comune and t1.data_fine>'$oggi' and t2.id_cons in (select id_cons from ".$prefix."_ele_operatori where aid='$aid' and id_sez>0 and permessi>0)";
+$rese = $dbi->prepare("$sql");
+$rese->execute();
+if ($rese->rowCount()>1){
+	echo "<form id=\"frm\" name=\"sceltacons\" data-ajax=\"false\" action=\"admin.php\">";  
+	echo "<input type=\"hidden\" name=\"id_comune=\" value=\"$id_comune\">";
+	echo "<input type=\"hidden\" name=\"ops=\" value=\"$ops\">";
+	echo "<select id=\"id_cong\" name=\"id_cons_gen\" onChange=\"vai_cong('id_cong');\">";
+	while (list($id_cons_gen2,$desc2)=$rese->fetch(PDO::FETCH_NUM)) {
+		$sel = ($id_cons_gen == $id_cons_gen2) ? "selected" : "";
+		echo "<option value=\"$id_cons_gen2\" $sel>";
+		echo $desc2;
+		echo "</option>"; 
+	}
+	echo "</select></form>";
+}
+$sql="select tipo from ".$prefix."_ele_controlli where id_sez='$id_sez' group by tipo";
+$rese = $dbi->prepare("$sql");
+$rese->execute();
+$bordoa='';
+$bordog='';
+$bordol=''; 
+while (list($tipo)=$rese->fetch(PDO::FETCH_NUM)) {
+	if ($tipo=='affluenze') $bordoa="style=\"border: 6px solid; border-color: rgb(255, 0, 0);\"";
+	if ($tipo=='gruppo' or $tipo=='referendum') $bordog="style=\"border: 6px solid; border-color: rgb(255, 0, 0);\"";
+	if ($tipo=='lista') $bordol="style=\"border: 6px solid; border-color: rgb(255, 0, 0);\"";
+}
+if($rese->rowCount()) $segna="style=\"background-color: #dd0000;\""; else $segna='';
 if($ops=="4" ) {$bgcolorg="yellow"; $tcolorg='blue';} else {$bgcolorg="grey"; $tcolorg='white';} #$active_gruppo=" class=\"ui-btn-active\""; else $active_gruppo='';
 if($ops=="3") {$bgcolorl="yellow"; $tcolorl='blue';} else {$bgcolorl="grey"; $tcolorl='white';} # $active_lista=" class=\"ui-btn-active\""; else $active_lista='';
 if($ops=="1") {$bgcolora="yellow"; $tcolora='blue';} else {$bgcolora="grey"; $tcolora='white';} # $active_aff=" class=\"ui-btn-active\""; else $active_aff='';
-/*if($op=="risultati" || $op=="affluenze_all" || $op=="gruppo_mob" || $op=="candidato_mob" || $op=="liste_mob" || $op=="votanti_mob") $active_ris=" class=\"ui-btn-active\""; else $active_ris='';
-if($op=="conf_mob" ) $active_conf=" class=\"ui-btn-active\""; else $active_conf='';
-if($op=="grafica_mob" ) $active_graf=" class=\"ui-btn-active\""; else $active_graf='';
-
-*/
 echo "</div>";
-
-
-# se non Ãš il menu di config o about sceglie elezione
-#if($op!="conf_mob" and $op!="about"){
-	echo'<div data-role="fieldcontain" style="text-align:center;">
-	<span style="text-align:center;width:100%;height:110px;background-color:#fff;color:#000;">'.$logo.' Comune di '.$descr_com.' <br>Consultazione: '.$descr_cons.'</span></div>';
-
-
+echo'<div data-role="fieldcontain" style="text-align:center;">
+<span style="text-align:center;width:100%;height:110px;background-color:#fff;color:#000;">'.$logo.' Comune di '.$descr_com.' <br><h2>Consultazione: '.$descr_cons.'</h2></span></div>';
 ###############
 	//************************************
 	// Menu spoglio
 	//************************************
-#echo "TEST : select id_sez from ".$prefix."_ele_operatori where id_cons='$id_cons' and aid='$aid' and id_comune='$id_comune'";
-	$sql="select id_sez from ".$prefix."_ele_operatori where id_cons='$id_cons' and aid='$aid' and id_comune='$id_comune'";
-	$sth = $dbi->prepare("$sql"); #echo $sql;
-	$sth->execute();	
-	list($id_sez)=$sth->fetch(PDO::FETCH_NUM);    
-	$sql="select id_cons,id_sez,id_sede,num_sez, maschi, femmine, colore  from ".$prefix."_ele_sezioni where id_cons='$id_cons' and id_sez='$id_sez'";
-	$result = $dbi->prepare("$sql");#echo $sql;
-	$result->execute();
-	list($id_cons2,$id_sez2,$id_sede,$num_sez, $maschi, $femmine, $colore) = $result->fetch(PDO::FETCH_NUM);
-	echo "<div data-role=\"content\" data-theme=\"a\"><hr><table><tr><td align=\"center\" width=\"100\"  bgcolor=\"$colore\"><font size =\"4\" color=\"black\" align=\"left\"><b>Sezione<br>N. $num_sez</b></font></td><td><table><tr>";
-	echo "\n<td bgcolor=\"$bgcolora\" align=\"center\" $bordoa><p style=\"margin-left:10px;margin-right:10px;\"><b><a href=\"admin.php?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\"><font color=\"$tcolora\">"._AFFLUENZE."</font></a></b></p></td>\n";
-	if(!($genere==4) and !($votog)){ //if(!($genere==4) and !($tipo_cons==10 or $tipo_cons==11)){
-			echo "<td bgcolor=\"$bgcolorg\" align=\"center\" $bordog><p style=\"margin-left:10px;margin-right:10px;\"><b><a href=\"admin.php?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=4\"><font color=\"$tcolorg\">"._GRUPPO."</font></a></b></p></td>\n";
-	}
-	if($genere==2 and $votog)
-		echo "<td bgcolor=\"$bgcolorg\" align=\"center\" $bordog><p style=\"margin-left:10px;margin-right:10px;\"><b><a href=\"admin.php?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=4\"><font color=\"$tcolorg\">"._GRUPPO."</font></a></b></p></td>\n";
-	elseif(($genere>2 or $votog)){ //if(($genere>2 or $tipo_cons==10 or $tipo_cons==11)){
-		echo "<td bgcolor=\"$bgcolorl\" align=\"center\"$bordol><p style=\"margin-left:10px;margin-right:10px;\"><b><a href=\"admin.php?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\"><font color=\"$tcolorl\">"._LISTA."</font></a></b></p></td>\n";
-	}
-	echo "</tr></table></td></tr></table><hr></div>\n";
-
-
+$sql="select id_sez from ".$prefix."_ele_operatori where id_cons='$id_cons' and aid='$aid' and id_comune='$id_comune'";
+$sth = $dbi->prepare("$sql"); #echo $sql;
+$sth->execute();	
+list($id_sez)=$sth->fetch(PDO::FETCH_NUM);    
+$sql="select id_cons,id_sez,id_sede,num_sez, maschi, femmine, colore  from ".$prefix."_ele_sezioni where id_cons='$id_cons' and id_sez='$id_sez'";
+$result = $dbi->prepare("$sql");#echo $sql;
+$result->execute();
+list($id_cons2,$id_sez2,$id_sede,$num_sez, $maschi, $femmine, $colore) = $result->fetch(PDO::FETCH_NUM);
+echo "<div data-role=\"content\" data-theme=\"a\"><hr><table><tr><td align=\"center\" width=\"100\"  bgcolor=\"$colore\"><font size =\"4\" color=\"black\" align=\"left\"><b>Sezione<br>N. $num_sez</b></font></td><td><table><tr>";
+#<a href=\"admin.php?id_comune=$id_comune&amp;id_cons_gen=$id_cons_gen&amp;ops=1\"></a>
+echo "\n<td bgcolor=\"$bgcolora\" align=\"center\" $bordoa onClick=\"vai_scelta('admin.php?id_comune=$id_comune&amp;id_cons_gen=$id_cons_gen&amp;ops=1');\"><p style=\"margin-left:10px;margin-right:10px;\"><font color=\"$tcolora\"><b>"._AFFLUENZE."</font></b></p></td>\n";
+if(!($genere==4) and !($votog)){ //if(!($genere==4) and !($tipo_cons==10 or $tipo_cons==11)){
+	echo "<td bgcolor=\"$bgcolorg\" align=\"center\" $bordog onClick=\"vai_scelta('admin.php?id_comune=$id_comune&amp;id_cons_gen=$id_cons_gen&amp;ops=4');\"><p style=\"margin-left:10px;margin-right:10px;\"><b><font color=\"$tcolorg\">"._GRUPPO."</font></b></p></td>\n";
+}
+if($genere==2 and $votog)
+	echo "<td bgcolor=\"$bgcolorg\" align=\"center\" $bordog onClick=\"vai_scelta('admin.php?id_comune=$id_comune&amp;id_cons_gen=$id_cons_gen&amp;ops=4');\"><p style=\"margin-left:10px;margin-right:10px;\"><b><font color=\"$tcolorg\">"._GRUPPO."</font></b></p></td>\n";
+elseif(($genere>2 or $votog)){ //if(($genere>2 or $tipo_cons==10 or $tipo_cons==11)){
+	echo "<td bgcolor=\"$bgcolorl\" align=\"center\"$bordol onClick=\"vai_scelta('admin.php?id_comune=$id_comune&amp;id_cons_gen=$id_cons_gen&amp;ops=3');\"><p style=\"margin-left:10px;margin-right:10px;\"><b><font color=\"$tcolorl\">"._LISTA."</font></b></p></td>\n";
+}
+echo "</tr></table></td></tr></table><hr></div>\n";
 if($ops=="1")votanti($id_cons,$do,$id_circ,$id_sede,$id_sez,$ops,$ov,$mv,$gv,$msv,$av);
 elseif($ops=="3")preferenze($id_cons,$do,$id_circ,$id_sede,$id_sez,$ops);
 elseif($ops=="4")preferenze_gruppi($id_cons,$do,$id_circ,$id_sede,$id_sez,$ops);
-
-
 footer_mon();
-
 die();
-}
-########################################
-
-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,$id_comune,$ops;
-
-$bgcolor1="#7777ff";
-$bgcolor2=$_SESSION['bgcolor2'];
-#OpenTable();
-$sql="SELECT vismf from ".$prefix."_ele_cons_comune where id_cons='$id_cons'";
-$res = $dbi->prepare("$sql");
-$res->execute();
-
-if($res) list($vismf)= $res->fetch(PDO::FETCH_NUM); else $vismf=0;
-$sql="SELECT orario,data FROM ".$prefix."_ele_rilaff where id_cons_gen=$id_cons_gen order by data,orario ";
-$res = $dbi->prepare("$sql");
-$res->execute();
-
-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>";
-
-##################
-
-list($maschi,$femmine)=$ressez->fetch(PDO::FETCH_NUM);
-$y=0;
-echo "<div class=\"table\">";
-$riga=array();
-$rigat=array();
-while (list($ora,$giorno)= $res->fetch(PDO::FETCH_NUM)){
-	$y++;
-	$rigat[$y]='';
-	$riga[$y]='';
-	$rigat[$y]= "<div class=\"tr\">";
-	if ($genere==0){ //e' un referendum 
-		$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'  ";
-		$res2 = $dbi->prepare("$sql");
-		$res2->execute();
-		$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 
-		on (t1.id_gruppo=t2.id_gruppo) where t1.id_sez='$id_sez' 
-		and t1.id_cons='$id_cons' and t1.orario='$ora' and t1.data='$giorno'";
-		if ($genere==0){
-			$query.=" and t2.num_gruppo=$i";
-		}
-		$sql=$query;
-		$result = $dbi->prepare("$sql");
-		$result->execute();
-		list($id_cons2,$id_sez2,$id_parz,$orario,$data, $voti_u, $voti_d, $voti_t,$id_gruppo) = $result->fetch(PDO::FETCH_NUM);
-	   	$sql="SELECT num_gruppo FROM ".$prefix."_ele_gruppo where id_gruppo='$id_gruppo' ";
-		$res2 = $dbi->prepare("$sql");
-		$res2->execute();
-		$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();
-        list($numril)=$resril->fetch(PDO::FETCH_NUM);
-		if ($res2)
-			list($gruppo)= $res2->fetch(PDO::FETCH_NUM);
-		else
-			$gruppo=0;
-		if (!$gruppo>0) {
-			$gruppo=$i;
-			$sql="SELECT id_gruppo FROM ".$prefix."_ele_gruppo where num_gruppo=$gruppo and id_cons=$id_cons";
-			$res3 = $dbi->prepare("$sql");
-			$res3->execute();
-			if ($res3)
-			list($id_gruppo)=$res3->fetch(PDO::FETCH_NUM);
-		}
-		if(!isset($precede[$id_gruppo])) $precede[$id_gruppo]=0; if(!isset($error)) $error=0;
-		if($precede[$id_gruppo]>($voti_t) and $voti_t!='') $error=1;
-		$precede[$id_gruppo]=$voti_t;
-		if (($voti_u+$voti_d and $voti_u+$voti_d!=$voti_t) or $error){
-			$riga[$y].= "<form class=\"tr\"  data-ajax=\"false\" style=\"background-color: rgb(255, 0, 0); text-align: center\" name=\"votanti\" action=\"modules/Elezioni/salva_aff.php\">";
-		}else{
-			$riga[$y].= "<form class=\"tr\" data-ajax=\"false\" action=\"modules/Elezioni/salva_aff.php\">";
-		}
-		if ($genere==0){ // e' un referendum
-			$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=\"genere\" value=\"$genere\"/>"
-		."<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\"/>"; 
-        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 "</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");
-		$compl->execute();
-		list ($complessivi)= $compl->fetch(PDO::FETCH_NUM);
-	}
-	foreach($riga as $key=>$val){
-		echo $rigat[$key];
-		echo $riga[$key];
-	}
-	echo "</div></td></tr></table>";
 }
 
@@ -341,906 +174,3 @@
 
 
-//////////////////////////////////////////////////////////////////////
-// da qui va la sezione per le preferenze candidati consiglieri
-//////////////////////////////////////////////////////////////////////
-function preferenze($id_cons,$do,$id_circ,$id_sede,$id_sez,$ops){
- 	global $aid, $prefix, $dbi, $id_lista,$genere,$id_cons_gen,$id_gruppo,$sezi,$circo,$votog,$votol,$votoc,$conscirc;
-global $tipo_cons,$limite,$dettnulli,$disgiunto;
-$bgcolor1="#7777ff";
-$bgcolor2=$_SESSION['bgcolor2'];
-		echo "<SCRIPT type=\"text/javascript\">\n";
-		echo "function vai_lista(){\n";
-		echo "var element=document.getElementById('pag')\n";
-		echo "var elista=document.getElementById('id_lista')\n";
-		echo "var url=element.value+elista.value\n";
-		echo "window.document.location.href=url \n";
-		echo "}\n";
-		echo "</script>\n"; 
-if ($genere==4){
-	$sql="SELECT voti_uomini,voti_donne, voti_complessivi FROM ".$prefix."_ele_voti_parziale where id_sez='$id_sez' and id_cons='$id_cons' order by data desc,orario desc limit 0,1";
-	$result = $dbi->prepare("$sql");
-	$result->execute();
-
-
-	list( $voti_u, $voti_d, $voti_t) = $result->fetch(PDO::FETCH_NUM);
-	echo "<table  class=\"table-menu\" style=\"width: 50%; color: black;\">"
-	."<tr><td></td><td align=\"center\"></td><td bgcolor=\"$bgcolor1\" align=\"center\">"._VOTIU."</td><td bgcolor=\"$bgcolor1\" align=\"center\">"._VOTID."</td><td bgcolor=\"$bgcolor1\" align=\"center\">"._VOTIT."</td></tr>"
-	."<tr><td></td><td bgcolor=\"$bgcolor1\" align=\"center\">"._TOT_ULT."</td><td bgcolor=\"$bgcolor2\" align=\"center\">$voti_u</td><td align=\"center\" bgcolor=\"$bgcolor2\">$voti_d</td><td bgcolor=\"$bgcolor2\" align=\"center\">$voti_t</td></tr>";
-	echo "</table>";
-}
-$sql="select validi,nulli,bianchi,contestati from ".$prefix."_ele_sezioni where id_sez='$id_sez' ";
-$result = $dbi->prepare("$sql");
-$result->execute();
-list($v1,$v2,$v3,$v4)=$result->fetch(PDO::FETCH_NUM);
-if($v1+$v2+$v3+$v4>0){
-    //controlla se sono stati inseriti i votanti
-$sql="SELECT preferenze, id_fascia, id_conf,solo_gruppo, disgiunto from ".$prefix."_ele_cons_comune where id_cons='$id_cons'";
-$result = $dbi->prepare("$sql");
-$result->execute();
- 
-
-list($numprefs,$fascia,$id_conf,$flagsg,$disgiunto)=$result->fetch(PDO::FETCH_NUM);
-$dettnulli=$flagsg;
-####### 06-11-2014 - circoscrizionali - nello spostamento ad altra sezione resta sullo stesso numero di lista anche se sono sezioni di diverse circoscrizioni
-if ($circo and $id_lista){
-	$sql="SELECT num_lista from ".$prefix."_ele_lista where id_lista=$id_lista";
-	$res_lis = $dbi->prepare("$sql");
-	$res_lis->execute();
-	list($num_lista)=$res_lis->fetch(PDO::FETCH_NUM);
-}
-
-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");
-$result->execute();
-
-
-}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);
-		echo "<table class=\"table-menu\" style=\"width: 100%;\"><tr>";
-		$sql="SELECT id_lista, descrizione,num_lista from ".$prefix."_ele_lista where id_cons=$id_cons $circo order by num_lista";
-$res_lis = $dbi->prepare("$sql");
-$res_lis->execute();
-
-
-		$num_liste = $res_lis->rowCount();
-		$ele_lista='';
-		if (($genere==4 or $genere==5) and !$votoc) { //liste a piu' candidati
-			if(($genere==5 and $id_conf and $fascia<=$limite and !$disgiunto) and !$id_lista) { //esclude il voto di lista per le comunali nei comuni sotto fascia limite
-				$sql="SELECT id_lista from ".$prefix."_ele_lista where id_cons=$id_cons $circo limit 0,1";
-$result = $dbi->prepare("$sql");
-$result->execute();
-
-
-				list($id_lista)=$result->fetch(PDO::FETCH_NUM);
-			}
-			echo "<td colspan=\"2\">";
-			echo "<form name=\"liste\" data-ajax=\"false\" action=\"admin.php\">";  # data-ajax=\"false\" 
-			echo "<input type=\"hidden\" id=\"pag\" name=\"pag\" value=\"admin.php?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 id=\"id_lista\" name=\"id_lista\" onChange=\"vai_lista();\">";
-			if ($id_lista){
-				echo "<option value=\"0\">"._VOTI_LISTA;
-				$ele_lista=" and t1.id_lista='$id_lista' ";
-			}else{
-				echo "<option value=\"0\" selected>"._VOTI_LISTA;
-				$ele_lista=" group by t1.id_lista ";
-if(!isset($votolista)) $votolista=0;
-
-			}
-			while(list($id_rif,$descrizione,$num_lis) = $res_lis->fetch(PDO::FETCH_NUM)) {
-			$segna='';
-			$sql="SELECT count(t1.voti) from ".$prefix."_ele_voti_candidati as t1 left join ".$prefix."_ele_candidati as t2 on (t1.id_cand=t2.id_cand) where t1.id_sez=$id_sez and t2.id_lista=$id_rif";
-$result = $dbi->prepare("$sql");
-$result->execute();
-
-
-			list($ctrvoticand)=$result->fetch(PDO::FETCH_NUM);
-			$sql="SELECT sum(t1.voti),0,0 from ".$prefix."_ele_voti_candidati as t1 left join ".$prefix."_ele_candidati as t2 on (t1.id_cand=t2.id_cand) where t1.id_sez=$id_sez and t2.id_lista=$id_rif";
-$result = $dbi->prepare("$sql");
-$result->execute();
-
-
-			list($votisezcand)=$result->fetch(PDO::FETCH_NUM);
-			if((($fascia>$limite or $disgiunto) or !$id_conf) or $genere==4){
-                $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{
-				$sql="SELECT id_gruppo from ".$prefix."_ele_lista where id_lista='$id_rif'";
-$result = $dbi->prepare("$sql");
-$result->execute();
-				list($id_gruppo)=$result->fetch(PDO::FETCH_NUM);
-				$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);
-			if($votisezcand>($votisezlis*$numprefs))
-				{$segna="style=\"background-color: #dd0000;\"";}
-			elseif($ctrvoticand)
-				$segna="style=\"background-color: #99CC33;\"";
-			$sql="SELECT t1.voti,t2.num_cand FROM ".$prefix."_ele_voti_candidati as t1 left join ".$prefix."_ele_candidati as t2 on t1.id_cand=t2.id_cand where t1.id_cons='$id_cons' and  t1.id_sez='$id_sez' and t2.id_lista='$id_rif'";
-$res4 = $dbi->prepare("$sql");
-$res4->execute();
-
-
-			$errcand[$id_rif]=array();
-			while(list($testvotic,$numcand)=$res4->fetch(PDO::FETCH_NUM))
-				if($votisezlis<$testvotic) { $segna="style=\"background-color: #dd0000;\"";$errcand[$id_rif][]=$numcand;}
-                        
-			$sel = ($id_rif == $id_lista) ? "selected" : "";
-				echo "<option $segna value=\"$id_rif\" $sel>";
-				for ($j=strlen($num_lis);$j<2;$j++) { echo "&nbsp;&nbsp;";}
-				echo $num_lis.") ".substr($descrizione,0,30);
-			}
-			echo "</select></form></td></tr><tr><td style=\"vertical-align: top;\">&nbsp;</td>\n";
-		}else {
-			$id_lista=0;
-		}
-		echo "<td style=\"vertical-align: top;\">";
-
-		if ((!$id_lista)){$tab="_ele_voti_lista";} else {$tab="_ele_voti_candidati";}
-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,t2.contestati,0,0 from ".$prefix."_ele_sezioni as t2 left join ".$prefix.$tab." as t1 on (t1.id_sez=t2.id_sez) where t2.id_sez=$id_sez group by t1.id_sez";
-$result = $dbi->prepare("$sql");
-$result->execute();
-
-
-}else{
-		$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,t1.id_sez 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,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";
-$result = $dbi->prepare("$sql");
-$result->execute();
-}
-
-// aggiunte le variabili $sgpl e $vnulli2 per la gestione dei voti 1) al solo presidente per singola lista - 2) al solo presidente per singola lista perchÃ© nullo o contestato quello di lista		
-		$isscr= $result->rowCount();
-		list( $voti_sez, $validi2, $sg,$cont2,$vnulli2,$bia2,$nul2,$con2,$vnul2,$sgpl) = $result->fetch(PDO::FETCH_NUM);
-		if(($genere==5 and !$disgiunto and $voti_sez and $flagsg and ($tipo_cons==18 or $tipo_cons==19))){ 
-			$sql="SELECT sum(solo_gruppo) from ".$prefix."_ele_voti_gruppo where id_cons=$id_cons and id_sez=$id_sez";
-$resg = $dbi->prepare("$sql");
-$resg->execute();
-
-
-			list($sgpl)=$resg->fetch(PDO::FETCH_NUM);
-			if ($sg != $sgpl) echo "<table class=\"table-menu\" style=\"width: 50%;\"><tr><td style=\"background-color: rgb(255, 0, 0); color: black; text-align: center\"><img src=\"modules/Elezioni/images/alert.gif\" align=\"middle\" alt=\"\"><br><b> "._ATT_UNI." ".$sgpl." "._ATT_TOT_UNI." ".$sg."</b><br></td></table>";
-		}
-		$valista=$validi2;
-		if(!$id_lista or $genere==3){	//controllo di congruenza
-			$sql="SELECT max(voti_complessivi) FROM ".$prefix."_ele_voti_parziale where id_cons='$id_cons' and id_sez='$id_sez'";
-$res2 = $dbi->prepare("$sql");
-$res2->execute();
-
-
-			list($tot) = $res2->fetch(PDO::FETCH_NUM);
-#######    controlli
-	$sql="select * from ".$prefix."_ele_controlli where id_cons='$id_cons' and id_sez='$id_sez' ";
-	$resc = $dbi->prepare("$sql");
-	$resc->execute();
-if($resc->rowCount()){			if ($validi2+$vnulli2+$cont2+$sg+$bia2+$nul2+$con2+$vnul2!=$tot and $validi+$sg>0){
-				echo "<table class=\"table-menu\" style=\"width: 50%;\"><tr><td style=\"background-color: rgb(255, 0, 0); color: black; text-align: center\"><img src=\"modules/Elezioni/images/alert.gif\" align=\"middle\" alt=\"\"><br><b> "._ATT_VOTANTI." ".$tot." "._NO_TOT_VOTI." ".($validi2+$vnulli2+$cont2+$sg+$bia2+$nul2+$con2+$vnul2)."</b><br></td></table>";
-			}
-
-			if((($voti_sez)!=$validi2) and ($voti_sez>0)){
-				echo "<table class=\"table-menu\" style=\"width: 50%;\"><tr><td style=\"background-color: rgb(255, 0, 0); color: black; text-align: center\"><img src=\"modules/Elezioni/images/alert.gif\" align=\"middle\" alt=\"\"><br><b> "._ATT_VOTI." ".($voti_sez)." "._NO_VAL_VOTI." ".$validi2."</b><br></td></tr></table>";
-			}
-		}elseif($genere==5){
-			$sql="SELECT sum(t1.voti) from ".$prefix."_ele_voti_candidati as t1 left join ".$prefix."_ele_candidati as t2 on (t1.id_cand=t2.id_cand) where t1.id_sez=$id_sez and t2.id_lista='$id_lista'";
-$result = $dbi->prepare("$sql");
-$result->execute();
-
-
-			list($votisezcand)=$result->fetch(PDO::FETCH_NUM);
-			if(($fascia>$limite or $disgiunto) or !$id_conf){
-                 $sql="SELECT sum(voti) from ".$prefix."_ele_voti_lista where id_sez='$id_sez' and id_lista='$id_lista'"; 
-$result = $dbi->prepare("$sql");
-$result->execute();
-
-
-            }else{
-
-				$sql="SELECT id_gruppo from ".$prefix."_ele_lista where id_lista='$id_lista'";
-$result = $dbi->prepare("$sql");
-$result->execute();
-
-
-				list($id_gruppo)=$result->fetch(PDO::FETCH_NUM);
-				$sql="SELECT sum(voti) from ".$prefix."_ele_voti_gruppo where id_sez='$id_sez' and id_gruppo='$id_gruppo'";
-$result = $dbi->prepare("$sql");
-$result->execute();
-
-
-            }
-			list($votisezlis)=$result->fetch(PDO::FETCH_NUM);
-			if($votisezcand>($votisezlis*$numprefs))
-				{
-				echo "<table class=\"table-menu\" style=\"width: 50%;\"><tr><td style=\"background-color: rgb(255, 0, 0); color: black; text-align: center\"><img src=\"modules/Elezioni/images/alert.gif\" align=\"middle\" alt=\"\"><br/><b> ATTENZIONE!<BR/>I voti di preferenza $votisezcand <br/>superano i voti di lista $votisezlis</b><br></td></tr></table>";
-				}
-		}
-#controllo voti a liste collegate <= voto di gruppo per voto non disgiunto
-	$errgrulis=array();
-	if($genere==5 and !$disgiunto  and ($tipo_cons==18 or $tipo_cons==19)){
-		$sql="SELECT id_gruppo FROM ".$prefix."_ele_gruppo where id_cons='$id_cons' $circo";
-$resref = $dbi->prepare("$sql");
-$resref->execute();
-
-
-		$sql="SELECT count(0) FROM ".$prefix."_ele_voti_lista where id_sez='$id_sez'";
-$res4 = $dbi->prepare("$sql");
-$res4->execute();
-
-
-		list($sezscrl)=$res4->fetch(PDO::FETCH_NUM); 
-		if ($sezscrl)
-				
-		while ( list($id_gruppo)=$resref->fetch(PDO::FETCH_NUM))
-                    {
-                    $sql="SELECT sum(voti-solo_gruppo) FROM ".$prefix."_ele_voti_gruppo where id_sez='$id_sez' and id_gruppo='$id_gruppo'";
-$res3 = $dbi->prepare("$sql");
-$res3->execute();
-
-
-                    $sql="SELECT sum(voti+nulli_lista) FROM ".$prefix."_ele_voti_lista where id_sez='$id_sez' and  id_lista in (select id_lista from ".$prefix."_ele_lista where id_gruppo='$id_gruppo')";
-$res4 = $dbi->prepare("$sql");
-$res4->execute();
-
-
-                    list($vgruppo)=$res3->fetch(PDO::FETCH_NUM);
-                    list($vliste)=$res4->fetch(PDO::FETCH_NUM);
-                    if($vliste>$vgruppo)
-                    	{
-                    	 $sql="SELECT descrizione FROM ".$prefix."_ele_gruppo where id_gruppo='$id_gruppo'";
-$result = $dbi->prepare("$sql");
-$result->execute();
-
-
-                    	 list($dgruppo)=$result->fetch(PDO::FETCH_NUM);
-                    	echo "<table class=\"table-menu\" style=\"width: 50%;\"><tr><td style=\"background-color: rgb(255, 0, 0); color: black; text-align: center\"><img src=\"modules/Elezioni/images/alert.gif\" align=\"middle\" alt=\"\"><br/><b> ATTENZIONE!<BR/>I voti delle liste collegate<br/> superano i voti assegnati al gruppo $dgruppo </b><br></td></tr></table>";
-                    	$errgrulis[$id_gruppo]=1;
-                    	}
-                    elseif($vliste<$vgruppo)
-                    	{
-                    	 $sql="SELECT descrizione FROM ".$prefix."_ele_gruppo where id_gruppo='$id_gruppo'";
-$result = $dbi->prepare("$sql");
-$result->execute();
-
-
-                    	 list($dgruppo)=$result->fetch(PDO::FETCH_NUM);
-                    	echo "<table class=\"table-menu\" style=\"width: 50%;\"><tr><td style=\"background-color: rgb(255, 0, 0); color: black; text-align: center\"><img src=\"modules/Elezioni/images/alert.gif\" align=\"middle\" alt=\"\"><br/><b> ATTENZIONE!<BR/>I voti assegnati al gruppo $dgruppo<br/> superano i voti delle liste collegate </b><br></td></tr></table>";
-                    	$errgrulis[$id_gruppo]=1;
-                    	}
-                    }
-		}
-}
-
-
-		echo "\n<form name=\"sezioni\" data-ajax=\"false\" 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=\"genere\" value=\"$genere\">"
-		."<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=\"tabella\" value=\"$tab\">"
-		."<input type=\"hidden\" name=\"id_lista\" value=\"$id_lista\">\n"
-		."<input type=\"hidden\" name=\"do\" id=\"do\" value=\"0\">\n";
-		echo "<table class=\"table-menu\" style=\"width: 90%; color: black\">";
-		echo "<tr><td bgcolor=\"$bgcolor1\" align=\"left\" width=\"32\">";
-		if ($genere<4){
-//			echo "<td bgcolor=\"$bgcolor1\" align=\"center\" width=\"32\"><b>"._LISTA."</b></td>";
-		}
-		echo "<b>"._NUM."</b></td>";
-		if($id_lista){
-			echo "<td bgcolor=\"$bgcolor1\" align=\"left\"><b>"._CANDIDATO."</b></td>"
-			."<td bgcolor=\"$bgcolor1\" align=\"center\"><b>"._VOTI."</b></td>";
-		}else{
-			echo "<td bgcolor=\"$bgcolor1\" align=\"left\"><b>"._DESCR."</b></td>"
-			."<td bgcolor=\"$bgcolor1\" align=\"center\"><b>"._VOTI."</b></td>";
-#funzione di inserimento del dettaglio di voti nulli sospesa, non ritenuta utile
-#			if($dettnulli && !$disgiunto  && $tipo_cons!=18 && $tipo_cons!=19)
-#			echo "<td bgcolor=\"$bgcolor1\" align=\"center\"><b>"._NULLI_LISTE."</b></td>";
-			if($disgiunto){
-			echo "<td bgcolor=\"$bgcolor1\" align=\"center\"><b>"._SOLOLIS."</b></td>";
-			}
-		}
-		echo "</tr>\n";
-
-
-if($id_lista)		$sql="select t1.* from ".$prefix."_ele_candidati as t1 left join ".$prefix."_ele_lista as t2 on (t1.id_lista=t2.id_lista) WHERE t1.id_cons=$id_cons and t1.id_cons=t2.id_cons $ele_lista $circo ORDER BY t2.num_lista,t1.num_cand";
-else $sql="select 0,'$id_cons',t1.id_lista,'','','','','',0 from ".$prefix."_ele_candidati as t1 left join ".$prefix."_ele_lista as t2 on (t1.id_lista=t2.id_lista) WHERE t1.id_cons=$id_cons and t1.id_cons=t2.id_cons $ele_lista $circo ORDER BY t2.num_lista";
-$result = $dbi->prepare("$sql");
-$result->execute();
-
-
-		$max = $result->rowCount();
-		$tot_pref=0;
-		$i=1;
-
-		if($id_lista) {
-			while(list($id_cand,$id_cons2,$id_lista2,$nl, $cognome, $nome, $note, $simbolo, $num_cand) = $result->fetch(PDO::FETCH_NUM)){
-				// dati lista
-				$sql="select id_lista, descrizione,simbolo,num_lista from ".$prefix."_ele_lista where id_lista='$id_lista2'";
-$result1 = $dbi->prepare("$sql");
-$result1->execute();
-
-
-				list($id_lista3,$descr_lista,$simb_lista,$num_lista)=$result1->fetch(PDO::FETCH_NUM);
-			// dati gruppo
-				$sql="select descrizione,simbolo from ".$prefix."_ele_gruppo where id_gruppo='$id_gruppo'";
-$result2 = $dbi->prepare("$sql");
-$result2->execute();
-
-
-				list($descr_gruppo,$simb_gruppo)=$result2->fetch(PDO::FETCH_NUM);
-				
-				echo "<tr bgcolor=\"$bgcolor2\">";
-				if ($genere<4){
-					echo "<td align=\"left\"><b><img src=\"images/lista/$simb_lista \" width=\"32\" heigth=\"32\" align=\"center\" ALT=\"$descr_lista\" > </b></td>";
-				}
-				echo "<td align=\"center\"><b> $num_cand </b></td>"
-				."<td align=\"left\"><b>$cognome $nome</b></td>";
-				$cond_sele="and id_cand=$id_cand";
-				$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$num_cand\" value=\"".$voti."\" size=\"7\"  style=\"text-align:right\">";
-				echo "<input type=\"hidden\" name=\"id_cand$num_cand\" value=\"$id_cand\"></td></tr>\n";
-				$i++;
-				$tot_pref+=$voti;
-			} 
-		}else {
-			if($circo) $circot1=" and t1.id_circ=$id_circ"; else $circot1='';
-			$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' 
-			and t1.id_lista=t2.id_lista
-			and t2.id_sez=$id_sez
-			$circot1
-			order by t1.num_lista";
-
-	try {
-		$result1 = $dbi->prepare("$sql");
-		$result1->execute();
-
-	}
-		catch(PDOException $e)
-		{
-			echo $sql . "<br>" . $e->getMessage();
-		}                  
-
-			$num_lista=$result1->rowCount();
-			if (!$num_lista){
-				$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";
-				$result1 = $dbi->prepare("$sql");
-				$result1->execute();
-			}
-			$tvnpl=0;
-			$tslpl=0;
-			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){
-//				}
-				$sql="select t1.* from ".$prefix."_ele_voti_candidati as t1, ".$prefix."_ele_candidati as t2 where t1.id_cand=t2.id_cand and t1.id_sez='$id_sez' and t2.id_lista='$id_lista3' limit 0,1";
-				$rese = $dbi->prepare("$sql");
-				$rese->execute();
-				if($rese->rowCount()) $segna="style=\"background-color: #99CC33;\""; else $segna='';
-				$sql="select * from ".$prefix."_ele_controlli where tipo='lista' and id_sez='$id_sez' and id='$id_lista3'";
-				$rese = $dbi->prepare("$sql");
-				$rese->execute();
-				if($rese->rowCount()) $segna="style=\"background-color: #dd0000;\"";
-				list($sezcol)=$rese->fetch(PDO::FETCH_NUM);
-				$errcolor='';
-				if(isset($errgrulis[$rifgruppo])) $errcolor="style=\"background-color: rgb(255, 0, 0);\"";
-				echo "<td align=\"center\" $segna><b> $num_lista </b></td>"
-				."<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=\"".$voti."\" size=\"7\"  style=\"text-align:right\">";
-#funzione non ritenuta utile
-#				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\">"; $tvnpl+=$vnpl;}
-				if($disgiunto) {echo "</td><td align=\"right\"><input  name=\"slpl$i\" value=\"".$slpl."\" size=\"7\"  style=\"text-align:right\">"; $tslpl+=intval($slpl);}
-				echo "<input type=\"hidden\" name=\"id_lista$i\" value=\"$id_lista3\"></td>";
-//				echo "<td align=\"right\">$sgpl";
-				echo "</tr>\n";
-				$i++;
-				$tot_pref+=$voti;
-			}
-		}
-		if(!$id_lista) {
-			echo "<tr bgcolor=\"$bgcolor1\"><td></td><td><font size=\"3\">"._TOT._VOTI_LISTA."</font></td><td align=\"center\"><font size=\"3\">$tot_pref</font></td>";
-#			if($dettnulli && !$disgiunto  && $tipo_cons!=18 && $tipo_cons!=19)
-#				echo "<td bgcolor=\"$bgcolor1\" align=\"center\"><font size=\"3\">".$tvnpl."</font></td>";
-			if($disgiunto)
-				echo "<td bgcolor=\"$bgcolor1\" align=\"center\"><font size=\"3\">".$tslpl."</font></td>";
-			echo "</tr>";
-		}
-		else echo "<tr bgcolor=\"$bgcolor1\"><td></td><td>"._TOTPREF."</td><td align=\"center\">$tot_pref</td></tr>";
-		// toglie ai candidati la visual... del solo_gruppo 
-		if(!$votog) {
-		   if (($genere==3 OR $genere==5) and (!$id_lista) and (($disgiunto or $fascia>$limite) or !$id_conf)) { //gruppo e liste
-			echo "<tr bgcolor=\"$bgcolor2\"><td></td><td><b>"._VALIDI_LISTA."</b></td><td align=\"center\"><input type=\"hidden\" name=\"id_sez\" value=\"$id_sez\"><input name=\"valista\" value=\"$valista\" size=\"5\" style=\"text-align:right\"></td></tr>";
-			echo "<tr bgcolor=\"$bgcolor2\"><td></td><td><b>"._SOLO_GRUPPO."</b></td><td align=\"center\"><input name=\"sg\" value=\"$sg\" size=\"5\" style=\"text-align:right\">";
-			if(defined('_NULLISTA'))
-				echo "<input type=\"hidden\" name=\"votinulli\" value=\"$votinulli\"><input  type=\"hidden\" name=\"contestati\" value=\"$contestati\"></td></tr>";
-			else
-				echo "</td></tr><tr bgcolor=\"$bgcolor2\"><td></td><td><b>"._NULLI_LISTE."</b></td><td align=\"center\"><input  name=\"votinulli\" value=\"$votinulli\" size=\"5\" style=\"text-align:right\">"
-	."</td></tr><tr bgcolor=\"$bgcolor2\"><td></td><td><b>"._CONTESTATI_LISTE."</b></td><td align=\"center\"><input  name=\"contestati\" value=\"$contestati\" size=\"5\" style=\"text-align:right\"></td></tr>";
-			
-		   }elseif (($genere==3 OR $genere==5) and !$votoc and (($disgiunto or $fascia>$limite) or !$id_conf)){ //}elseif ($tipo_cons!=10 and $tipo_cons!=11){
-			echo "<tr bgcolor=\"$bgcolor1\"><td></td><td><b>"._SOLO_GRUPPO."</b></td><td align=\"center\">$sg</td></tr>";
-		   }
-######modifica del 16-04-2009 per visualizzare i voti al solo sindaco nei comuni con meno di 15000 abitanti
-elseif(($genere==3 OR $genere==5) and ($id_lista) and ($fascia<=$limite or !$id_conf) and $numprefs==1) {
-$sql="SELECT id_gruppo FROM ".$prefix."_ele_lista where id_lista='$id_lista'";
-$resvg = $dbi->prepare("$sql");
-$resvg->execute();
-
-
-list($id_gruppo) = $resvg->fetch(PDO::FETCH_NUM);
-$sql="SELECT sum(voti) FROM ".$prefix."_ele_voti_gruppo where id_gruppo='$id_gruppo' and id_sez='$id_sez'";
-$resvg = $dbi->prepare("$sql");
-$resvg->execute();
-
-
-        list($voti_sind) = $resvg->fetch(PDO::FETCH_NUM);
-
-echo "<tr bgcolor=\"$bgcolor1\"><td></td><td><b>"._SOLO_GRUPPO."</b></td><td align=\"center\">".($voti_sind - $tot_pref)."</td></tr>";
-}
-###### fine modifica del 16-04-2009
-
-	}
-		echo "<tr>";
-		echo "<td></td><td></td>";
-		echo "<td align=\"center\"><input type=\"submit\" id=\"update\" name=\"update\" value=\""._OK."\"></td>";
-		echo "</tr></table>";
-		if(chisei($id_cons_gen)>=64){
-			echo "<td></td><td> <input type=\"checkbox\" id=\"pwd3\" name=\"pwd3\" value=\"1\">"._DELETE."</td>";
-		} # onclick=\"javascript:del_dati()\"
-		echo "</form></tr></table>";
-		
-
-
-}
-#if (!((!$votog) and ($genere==3 OR $genere==5) and ($fascia>$limite)))
-	finale($id_cons,$do,$id_circ,$id_sede,$id_sez,$ops);
- }
-
-
-function finale($id_cons,$do,$id_circ,$id_sede,$id_sez,$ops){
- global $aid, $prefix, $dbi,$id_cons_gen,$genere,$votog,$fascia,$limite;
-////////////////////////////////////////////
-// da qua va la sezione per i voti finali
-///////////////////////////////////////////
-$bgcolor1="#7777ff";
-$bgcolor2=$_SESSION['bgcolor2'];
-
-
-
-     	echo "<form name=\"spogliovoti\" data-ajax=\"false\" 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\">"
-     	."<input type=\"hidden\" name=\"id_sede\" value=\"$id_sede\">";
-
-	echo "<table border=\"0\" width=\"100%\" align=\"center\"><tr bgcolor=\"$bgcolor1\" align=\"center\">";
-/*	if($ops==3 and ($genere==3 or ($genere==5 and $fascia>$limite)) )
-		echo "<td width=\"32\"><b>"._VOTI_LISTA."</b></td>";
-	else */
-		echo "<td width=\"15%\"><b>"._VALIDI."</b></td>";
-	echo "<td width=\"82\"><b>"._NULLI."</b></td>"
-    ."<td><b>"._BIANCHI."</b></td>"
-	."<td width=\"82\"><b>"._VOTINULLI."</b></td>"
-	."<td><b>"._CONTESTATI."</b></td>"
-    ."<td><b>"._TOTNON."</b></td>"
-	."<td><b>"._TOTALEVOTI."</b></td>"
-	."<td bgcolor=\"#ffffff\"></td> </tr>";
-/*if($ops==3 and ($genere==3 or ($genere==5 and $fascia>$limite)) )
-    $result = mysql_query("select id_cons,id_sez,validi_lista,nulli,bianchi,contestati_lista,voti_nulli_lista,solo_gruppo,contestati,voti_nulli from ".$prefix."_ele_sezioni where id_cons='$id_cons' and id_sez='$id_sez' ";
-$res = $dbi->prepare("$sql");
-$res->execute();
-
-
-else */
-    $sql = "select id_cons,id_sez,validi,nulli,bianchi,contestati,voti_nulli,'0','0','0',solo_lista from ".$prefix."_ele_sezioni where id_cons='$id_cons' and id_sez='$id_sez' ";
-$result = $dbi->prepare("$sql");
-$result->execute();
-
-
-    list($id_cons2,$id_sez2,$validi, $nulli, $bianchi, $contestati,$votinulli,$sg,$conts,$nullis,$sololista) = $result->fetch(PDO::FETCH_NUM);
-    $tot_nulli=$nulli+$bianchi+$contestati+$votinulli;
-    $tot_voti=$validi+$tot_nulli+$conts+$nullis;
-//	."</td><td><input  name=\"sololista\" value=\"$sololista\" size=\"5\" style=\"text-align:right\">" ---     ."<td><b>"._SOLOLIS."</b></td>"
-
-
-	echo "<tr bgcolor=\"$bgcolor2\" align=\"center\"><td align=\"left\"><input  name=\"validi\" value=\"$validi\" size=\"7\" style=\"text-align:right\">";
-/*	if(($genere==3 or $genere==5) and !$votog and $ops==3){
-	echo "</td><td>$nulli"
-	."</td><td>$bianchi";
-	echo "<input type=\"hidden\" name=\"nulli\" value=\"$nulli\"><input type=\"hidden\" name=\"bianchi\" value=\"$bianchi\">";
-	}else{ */
-	echo "</td><td><input  name=\"nulli\" value=\"$nulli\" size=\"5\" style=\"text-align:right\">"
-	."</td><td><input  name=\"bianchi\" value=\"$bianchi\" size=\"5\" style=\"text-align:right\">";
-//	}
-	echo "</td><td><input  name=\"votinulli\" value=\"$votinulli\" style=\"text-align:right;\">"
-	."</td><td><input  name=\"contestati\" value=\"$contestati\" size=\"5\" style=\"text-align:right\">"
-	."</td><td>$tot_nulli"
-	."</td><td>$tot_voti</td><td>"
-    	."<input type=\"hidden\" name=\"genere\" value=\"$genere\">"
-    	."<input type=\"hidden\" name=\"ops\" value=\"$ops\">"
-       	."<input type=\"submit\" name=\"update\" value=\""._OK."\">"
-      	."</td></tr></table></form>"; //</td></tr>";
-
-
-//    echo "</table>";
-/*	echo "<SCRIPT type=\"text/javascript\">\n\n<!--\n";
-	if (!$validi) {
-		echo "document.spogliovoti.validi.focus()\n";
-		echo "document.spogliovoti.validi.select()\n";
-	}
-	echo "//-->\n"
-	."</script>\n"; */
-
-
-    }
-
-
-function preferenze_gruppi($id_cons,$do,$id_circ,$id_sede,$id_sez,$ops){
- global $aid, $prefix, $dbi, $tipo_cons, $genere,$id_cons_gen,$sezi,$circo,$dettnulli;
-////////////////////////////////////////////
-// da qua va la sezione per le preferenze ai gruppi
-///////////////////////////////////////////
-// Controllo immmissioni
-
-$bgcolor1="#7777ff";
-$bgcolor2=$_SESSION['bgcolor2'];
-$sql="SELECT * FROM ".$prefix."_ele_gruppo where id_cons='$id_cons' $circo ";
-$res = $dbi->prepare("$sql");
-$res->execute();
-
-
-    $max = $res->rowCount();
-    $max = $max-1;
-/*	 echo "<SCRIPT type=\"text/javascript\">\n\n<!--\n";
-	if ($genere==0) {
-		echo "document.sezioni.si1.focus()\n";
-		echo "document.sezioni.si1.select()\n";
-	} else {
-		echo "document.sezioni.voti1.focus()\n"
-		."document.sezioni.voti1.select()\n";
-	}
-	echo "//-->\n"
-	."</script>\n"; */
-// tabella votanti
-	echo "<center>";
-    if ($genere!=0){
-	$sql="SELECT voti_uomini,voti_donne, voti_complessivi FROM ".$prefix."_ele_voti_parziale where id_sez='$id_sez' and id_cons='$id_cons' order by data desc,orario desc limit 0,1";
-$result = $dbi->prepare("$sql");
-$result->execute();
-
-
-    list( $voti_u, $voti_d, $voti_t) = $result->fetch(PDO::FETCH_NUM);
-   	echo "<table  class=\"table-menu\" style=\"width: 50%; color: black;\">"
-	."<tr><td></td><td align=\"center\"></td><td bgcolor=\"$bgcolor1\" align=\"center\">"._VOTIU."</td><td bgcolor=\"$bgcolor1\" align=\"center\">"._VOTID."</td><td bgcolor=\"$bgcolor1\" align=\"center\">"._VOTIT."</td></tr>"
-	."<tr><td></td><td bgcolor=\"$bgcolor1\" align=\"center\">"._TOT_ULT."</td><td bgcolor=\"$bgcolor2\" align=\"center\">$voti_u</td><td align=\"center\" bgcolor=\"$bgcolor2\">$voti_d</td><td bgcolor=\"$bgcolor2\" align=\"center\">$voti_t</td></tr>";
-   	echo "</table>";
-    }
-	echo "<table  class=\"table-menu\" style=\"width: 50%; color: black\">";
-    if ($genere==0){
-    	$sql="SELECT id_gruppo,si+no,validi,nulli,bianchi,contestati FROM ".$prefix."_ele_voti_ref where id_cons='$id_cons' and id_sez='$id_sez'  ";
-$res = $dbi->prepare("$sql");
-$res->execute();
-
-
-		while (list($id_gruppo,$voti_parz,$validi,$nulli,$bianchi,$contestati) = $res->fetch(PDO::FETCH_NUM)){
-			if ($voti_parz!=$validi){
-				$sql="SELECT num_gruppo FROM ".$prefix."_ele_gruppo where id_cons='$id_cons' and id_gruppo='$id_gruppo'  ";
-$res2 = $dbi->prepare("$sql");
-$res2->execute();
-
-
-				list($num_gruppo) = $res2->fetch(PDO::FETCH_NUM);
-				echo "<tr><td style=\"background-color: rgb(255, 0, 0); text-align:center\"><img src=\"modules/Elezioni/images/alert.gif\" align=\"middle\" alt=\"\"><br><b> "._ATT_VOTI_REF." $num_gruppo: ".$voti_parz." "._NO_VAL_VOTI.": ".$validi."</b><br></td></tr>";
-			}
-			$sql="SELECT max(voti_complessivi) FROM ".$prefix."_ele_voti_parziale where id_cons='$id_cons' and id_sez='$id_sez' and id_gruppo='$id_gruppo' ";
-$res2 = $dbi->prepare("$sql");
-$res2->execute();
-
-
-			list($tot) = $res2->fetch(PDO::FETCH_NUM);
-			if (($validi+$nulli+$bianchi+$contestati)!= $tot ){
-				$sql="SELECT num_gruppo FROM ".$prefix."_ele_gruppo where id_cons='$id_cons' and id_gruppo='$id_gruppo'";
-$res2 = $dbi->prepare("$sql");
-$res2->execute();
-
-
-				list($num_gruppo) = $res2->fetch(PDO::FETCH_NUM);
-				echo "<tr><td style=\"background-color: rgb(255, 0, 0); text-align:center\"><img src=\"modules/Elezioni/images/alert.gif\" align=\"middle\" alt=\"\"><br><b> "._ATT_VOTANTI_REF." $num_gruppo: ".$tot." "._NO_SOMMA." ".($validi+$nulli+$bianchi+$contestati)."</b><br></td></tr>";
-			}
-		}
-    }else{
-	$sql="select solo_gruppo,disgiunto from ".$prefix."_ele_cons_comune where id_cons='$id_cons' ";
-	$result = $dbi->prepare("$sql");
-	$result->execute();
-	list($flagsg,$disgiunto)=$result->fetch(PDO::FETCH_NUM);
-	$dettnulli=$flagsg;
-    $sql="SELECT sum(voti) FROM ".$prefix."_ele_voti_gruppo where id_cons='$id_cons' and id_sez='$id_sez'";
-	$res = $dbi->prepare("$sql");
-	$res->execute();
-	list($voti_parz) = $res->fetch(PDO::FETCH_NUM);
-    $sql="SELECT validi,nulli,bianchi,contestati,solo_lista,voti_nulli FROM ".$prefix."_ele_sezioni where id_cons='$id_cons' and id_sez='$id_sez'";
-	$res = $dbi->prepare("$sql");
-	$res->execute();
-	list($validi,$nulli,$bianchi,$contestati,$solo_lista,$votinulli) = $res->fetch(PDO::FETCH_NUM);
-		if ($voti_parz!=($validi-$solo_lista) and $voti_parz>0){
-			echo "<tr><td style=\"background-color: rgb(255, 0, 0); text-align:center\"><img src=\"modules/Elezioni/images/alert.gif\" align=\"middle\" alt=\"\"><br><b> "._ATT_VOTI." ".$voti_parz." "._NO_VAL_VOTI." ".($validi-$solo_lista)."</b><br></td><tr>";
-    	}
-		$sql="SELECT max(voti_complessivi) FROM ".$prefix."_ele_voti_parziale where id_cons='$id_cons' and id_sez='$id_sez'";
-	$res2 = $dbi->prepare("$sql");
-	$res2->execute();
-
-
-		list($tot) = $res2->fetch(PDO::FETCH_NUM);
-		if ($validi+$nulli+$bianchi+$contestati+$votinulli!=$tot and $validi+$nulli+$bianchi+$contestati+$votinulli>0){
-			echo "<tr><td style=\"background-color: rgb(255, 0, 0); text-align:center\"><img src=\"modules/Elezioni/images/alert.gif\" align=\"middle\" alt=\"\"><br><b> "._ATT_VOTANTI." ".$tot." "._NO_TOT_VOTI." ".($validi+$nulli+$bianchi+$contestati+$votinulli)."</b><br></td></tr>";
-    	}
-		$sql="SELECT sum(voti) from ".$prefix."_ele_voti_lista where id_cons=$id_cons and id_sez=$id_sez";
-		$resg = $dbi->prepare("$sql");
-		$resg->execute();
-
-
-		list($voti_sez)=$resg->fetch(PDO::FETCH_NUM);
-		if(($genere==5 and !$disgiunto and $voti_sez and $flagsg and ($tipo_cons==18 or $tipo_cons==19))){
-
-			$sql="SELECT sum(solo_gruppo) from ".$prefix."_ele_voti_gruppo where id_cons=$id_cons and id_sez=$id_sez";
-			$resg = $dbi->prepare("$sql");
-			$resg->execute();
-
-
-			list($sgpl)=$resg->fetch(PDO::FETCH_NUM);
-			$sql="SELECT solo_gruppo from ".$prefix."_ele_sezioni where id_cons=$id_cons and id_sez=$id_sez";
-			$resg = $dbi->prepare("$sql");
-			$resg->execute();
-
-
-			list($sg)=$resg->fetch(PDO::FETCH_NUM);
-			if ($sg != $sgpl) echo "<tr><td style=\"background-color: rgb(255, 0, 0); color: black; text-align: center\"><img src=\"modules/Elezioni/images/alert.gif\" align=\"middle\" alt=\"\"><br><b> "._ATT_UNI." ".$sgpl." "._ATT_TOT_UNI." ".$sg."</b><br></td></tr>";
-		}
-#controllo voti a liste collegate <= voto di gruppo per voto non disgiunto
-if($genere==5 and !$disgiunto and $flagsg  and ($tipo_cons==18 or $tipo_cons==19)){
-$sql="SELECT id_gruppo FROM ".$prefix."_ele_gruppo where id_cons='$id_cons' $circo";
-$resref = $dbi->prepare("$sql");
-$resref->execute();
-
-
-		$errgrulis=array();
-		$sql="SELECT count(0) FROM ".$prefix."_ele_voti_lista where id_sez='$id_sez'";
-		$res4 = $dbi->prepare("$sql");
-		$res4->execute();
-
-
-		list($sezscrl)=$res4->fetch(PDO::FETCH_NUM); 
-		if ($sezscrl)
-                while ( list($id_gruppo)=$resref->fetch(PDO::FETCH_NUM))
-                {
-					if($disgiunto || $flagsg){	
-						$sql="SELECT sum(voti-solo_gruppo) FROM ".$prefix."_ele_voti_gruppo where id_sez='$id_sez' and id_gruppo='$id_gruppo'";
-						$res3 = $dbi->prepare("$sql");
-						$res3->execute();
-						if($flagsg){
-							$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();
-						}else{
-							$sql="SELECT sum(voti) 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();							
-						}
-					}else{
-						$sql="SELECT sum(voti) FROM ".$prefix."_ele_voti_gruppo where id_sez='$id_sez' and id_gruppo='$id_gruppo'";
-						$res3 = $dbi->prepare("$sql");
-						$res3->execute();
-						$sql="SELECT sum(voti) FROM ".$prefix."_ele_voti_lista where id_sez='$id_sez' and  id_lista in (select id_lista from ".$prefix."_ele_lista where id_gruppo='$id_gruppo')";						
-						$res4 = $dbi->prepare("$sql");
-						$res4->execute();
-					}
-                    list($vgruppo)=$res3->fetch(PDO::FETCH_NUM);
-                    list($vliste)=$res4->fetch(PDO::FETCH_NUM);
-                    if($vliste>$vgruppo and !$disgiunto )
-                    	{
-                    	$sql="SELECT descrizione FROM ".$prefix."_ele_gruppo where id_gruppo='$id_gruppo'";
- 						$result = $dbi->prepare("$sql");
-						$result->execute();
-						list($dgruppo)=$result->fetch(PDO::FETCH_NUM);
-                    	echo "<table class=\"table-menu\" style=\"width: 50%;\"><tr><td style=\"background-color: rgb(255, 0, 0); color: black; text-align: center\"><img src=\"modules/Elezioni/images/alert.gif\" align=\"middle\" alt=\"\"><br/><b> ATTENZIONE!<BR/>I voti delle liste collegate $vliste<br/> superano i voti assegnati al gruppo $dgruppo $vgruppo</b><br></td></tr></table>";
-                    	$errgrulis[$id_gruppo]=1;
-                    	}
-                    elseif($vliste<$vgruppo and $disgiunto )
-                    	{
-                    	$sql="SELECT descrizione FROM ".$prefix."_ele_gruppo where id_gruppo='$id_gruppo'";
- 						$result = $dbi->prepare("$sql");
-						$result->execute();
-                    	list($dgruppo)=$result->fetch(PDO::FETCH_NUM);
-                    	echo "<table class=\"table-menu\" style=\"width: 50%;\"><tr><td style=\"background-color: rgb(255, 0, 0); color: black; text-align: center\"><img src=\"modules/Elezioni/images/alert.gif\" align=\"middle\" alt=\"\"><br/><b> ATTENZIONE!<BR/>I voti assegnati al gruppo $dgruppo<br/> superano i voti delle liste collegate </b><br></td></tr></table>";
-                    	$errgrulis[$id_gruppo]=1;
-                    	}
-                }
-		}
-
-    }
-    if(!isset($votinulli)) $votinulli=0;
-	echo "<tr><td></td></tr></table>";
-	if ($validi+$nulli+$bianchi+$contestati+$votinulli>0 or $genere==0) {
- if($genere==0)   echo "<table class=\"table-menu\" style=\" width: 60%; color: black\"><tr><td colspan=\"3\"><form name=\"sezioni\" data-ajax=\"false\" action=\"modules/Elezioni/salva_ref.php\">";
-   else echo "<table class=\"table-menu\" style=\" width: 60%; color: black\"><tr><td colspan=\"3\"><form name=\"sezioni\" data-ajax=\"false\" 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\">";
-
-	if ($genere==0){
-	echo "<br><br> <table  class=\"table-menu\" style=\"width: 100%; color: black\"><tr align=\"center\" bgcolor=\"$bgcolor1\">"
-    ."<td colspan=\"6\"><b>"._GRUPPO."</b></td></tr>";
-		$campitesta= "<tr align=\"center\" bgcolor=\"$bgcolor1\"><td><b>Votanti "._SI."</b></td>"
-		."<td><b>Votanti "._NO."</b></td>"
-		."<td><b>"._VALIDI."</b></td>"
-		."<td><b>"._BIANCHI."</b></td>"
-		."<td><b>"._CONTESTATI."</b></td>"
-		."<td><b>"._NULLI."</b></td></tr>";
-		
-		$campiriep="<tr  style=\"background-color: $bgcolor1; text-align:center\"><td colspan=\"2\"><b>"._TOTNON."</b></td>"
-		."<td colspan=\"2\"><b>"._TOTALEVOTI."</b></td>"
-		."<td colspan=\"2\"><b>"._VOTANTI."</b></td></tr>";
-	}else{
-		echo "<br><br> <table  class=\"table-menu\" style=\"width: 100%; color: black\"><tr align=\"center\" bgcolor=\"$bgcolor1\">"
-	."<td width=\"3%\"><b>"._NUM."</b></td>"
-    ."<td width=\"50%\"><b>"._GRUPPO."</b></td>";
-		echo "<td width=\"5%\"><b>"._VOTI."</b></td>";
-		if($dettnulli)		echo "<td bgcolor=\"$bgcolor1\" align=\"center\"><b>"._SOLO_GRUPPO."</b></td>";
-		echo "</tr>";
-	}
-    $sql="SELECT * FROM ".$prefix."_ele_gruppo where id_cons='$id_cons' $circo ORDER BY num_gruppo ";
-$res = $dbi->prepare("$sql");
-$res->execute();
-
-
-    $max = $res->rowCount();
-    //echo "Massimo:$max - id=$id_cons - circo: $circo";
-    $sql="select * from ".$prefix."_ele_gruppo where id_cons='$id_cons' $circo ORDER BY num_gruppo  ";
-$result = $dbi->prepare("$sql");
-$result->execute();
-
-
-    $i=1;
-	$tot_pref=0;
-       $totsg=0;
-    while(list($id_cons2,$id_gruppo,$num_gruppo, $descr_gruppo, $simbolo) = $result->fetch(PDO::FETCH_NUM)){
-  
-      //echo "test: $id_cons2,$id_gruppo,$num_gruppo, $descr_gruppo, $simbolo";
-  		echo "<SCRIPT type=\"text/javascript\">\n\n<!--\n"
-		
-		."//-->\n";
-		echo "function controlloref$i() {\n";
-		echo "var a=Number(window.document.sezioni.si$i.value); var b=Number(window.document.sezioni.no$i.value); if(a=='NaN') {a=0} if(b=='NaN') {b=0} var c=a + b; window.document.sezioni.val$i.value=c\n";
-		echo "}\n";
-		echo "</script>\n";    
-
-     if ($num_gruppo != ''){
-	if ($genere==0){
-		$sql="SELECT max(voti_complessivi) FROM ".$prefix."_ele_voti_parziale where id_cons='$id_cons' and id_sez='$id_sez' and id_gruppo='$id_gruppo' ";
-$res = $dbi->prepare("$sql");
-$res->execute();
-
-
-		list($tot) = $res->fetch(PDO::FETCH_NUM);
-		$sql="SELECT * FROM ".$prefix."_ele_voti_ref where id_cons='$id_cons' and id_sez='$id_sez' and id_gruppo='$id_gruppo' ";
-$res = $dbi->prepare("$sql");
-$res->execute();
-
-
-		$pro= $res->fetch(PDO::FETCH_BOTH);
-		if ($pro['si']+$pro['no']!=$pro['validi'] or ($pro['validi']+$pro['nulli']+$pro['bianchi']+$pro['contestati']!=$tot and $pro['validi']+$pro['nulli']+$pro['bianchi']+$pro['contestati']!=0)){
-			echo "<tr style=\"background-color: rgb(255, 0, 0); text-align:center\">";
-		}else{
-			echo "<tr style=\"background-color: $bgcolor2; text-align:center\">";
-		}
-		$descr = explode('.',$descr_gruppo, 100);
-		echo "<td colspan=\"6\" align=\"center\"><input type=\"hidden\" name=\"id_gruppo$i\" value=\"$id_gruppo\"><b>$num_gruppo) </b>"
-		."<b> $descr[0] </b></td></tr>";
-        $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']:'';
-		$tot_nulli=intval($pro['nulli'])+intval($pro['bianchi'])+intval($pro['contestati']);
-		$tot_voti=intval($pro['validi'])+$tot_nulli;
-		echo $campiriep; # style=\"text-align: center; border: 1px; border-color: black; border-collaps:collaps;\"
-		echo "<tr style=\"background-color: $bgcolor2; text-align:center\"><td colspan=\"2\" >$tot_nulli</td>";
-		echo "<td colspan=\"2\">$tot_voti</td>";
-		echo "<td colspan=\"2\">$tot</td></tr>";
-		echo $campitesta;	
-		echo "<tr><td align=\"right\" width=\"3%\"><input  name=\"si$i\" value=\"".$pro['si']."\" size=\"7\"  style=\"text-align:right\" onchange=controlloref$i()></td>";
-		echo "</td><td align=\"right\" width=\"3%\"><input  name=\"no$i\" value=\"".$pro['no']."\" size=\"7\"  style=\"text-align:right\" onchange=controlloref$i()></td>";
-		echo "</td><td align=\"right\" width=\"3%\"><input  name=\"val$i\" value=\"".$pro['validi']."\" size=\"7\" style=\"text-align:right\" ></td>";
-		echo "</td><td align=\"right\"><input  name=\"bia$i\" value=\"".$pro['bianchi']."\" size=\"7\"  style=\"text-align:right\"></td>";
-		echo "</td><td align=\"right\"><input  name=\"con$i\" value=\"".$pro['contestati']."\" size=\"7\"  style=\"text-align:right\"></td>";
-		echo "</td><td align=\"right\"><input  name=\"nul$i\" value=\"".$pro['nulli']."\" size=\"7\"  style=\"text-align:right\"></td>";
-
-
-	}else{
-		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' ";
-		$res = $dbi->prepare("$sql");
-		$res->execute();
-
-		$pro= $res->fetch(PDO::FETCH_BOTH);
-		if(!$res->rowCount()) {$pro['voti']=''; $pro['solo_gruppo']='';}
-		$errcolor='';
-		if(isset($errgrulis[$id_gruppo])) $errcolor="style=\"background-color: rgb(255, 0, 0);\"";
-		echo "</td><td align=\"right\" $errcolor><input  name=\"voti$i\" value=\"".$pro['voti']."\" size=\"7\"  style=\"text-align:right\"></td>";
-
-		if($dettnulli) {echo "<td align=\"right\"><input name=\"solog$i\" value=\"".$pro['solo_gruppo']."\" size=\"7\"  style=\"text-align:right\"></td>"; $totsg+=intval($pro['solo_gruppo']);} 
-		$tot_pref += intval($pro['voti']);
-		echo "</tr>";
-	}
-	
-	$i++;
-    }
-
-   }
-	if ($genere!=0) {
-		$sql="SELECT disgiunto FROM ".$prefix."_ele_cons_comune where id_cons='$id_cons' ";
-$res = $dbi->prepare("$sql");
-$res->execute();
-
-
-		list($disgiunto)=$res->fetch(PDO::FETCH_NUM);
-		$sql="SELECT solo_lista FROM ".$prefix."_ele_sezioni where id_sez='$id_sez' ";
-$res = $dbi->prepare("$sql");
-$res->execute();
-
-
-		list($sololis)=$res->fetch(PDO::FETCH_NUM);
-		echo "<tr style=\"background-color: $bgcolor1; text-align:center\"><td></td><td>"._TOTPREF."</td><td>$tot_pref</td>";
-		if($dettnulli) echo "<td>$totsg</td>";
-		echo "</tr>";
-		if($disgiunto)
-			echo "<tr style=\"background-color: $bgcolor1; text-align:center\"><td></td><td>"._SOLOLIS."</td><td><input  name=\"sololista\" value=\"".$sololis."\" size=\"7\"  style=\"text-align:right\"></td></tr>";
-	}
-
-   echo "<tr><td></td><td></td><td align=\"center\"><input type=\"submit\" name=\"update\" id=\"update\" value=\" "._OK. "\"></td>";
-
-    echo "</tr></table></form></td></tr>";
-		if(chisei($id_cons_gen)>=64){
-			echo "<tr><td><input type=\"checkbox\" id=\"pwd3\" name=\"pwd3\" value=\"\" onclick=\"javascript:del_dati()\">"._DELETE."";
-		}
-
-	echo "</td></tr></table></center>";
-	}
-    if ($genere!=0){
-    	finale($id_cons,$do,$id_circ,$id_sede,$id_sez,$ops);
-    }
-}
-
-
-
-
 ?>
Index: trunk/admin/versione.php
===================================================================
--- trunk/admin/versione.php	(revision 359)
+++ trunk/admin/versione.php	(revision 360)
@@ -1,7 +1,7 @@
 <?php
 
-$versione = "3.0 rev 359";
+$versione = "3.0 rev 360";
 $version_number = $versione;
-$datarel = "24 febbraio 2022";
+$datarel = "14 marzo 2022";
 $version = "Eleonline $version_number (<i>Data Release: $datarel</i>)";
 
Index: trunk/client/file.php
===================================================================
--- trunk/client/file.php	(revision 359)
+++ trunk/client/file.php	(revision 360)
@@ -3,5 +3,5 @@
 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)); 
+	$dbi = new PDO("mysql:host=$dbhost;charset=utf8", $dbuname, $dbpass, array(PDO::ATTR_EMULATE_PREPARES => false, PDO::ATTR_ERRMODE=>PDO::ERRMODE_EXCEPTION)); 
      	$sql = "use $dbname";
     	$dbi->exec($sql);
@@ -11,4 +11,8 @@
 	    echo $sql . "<br>" . $e->getMessage();
 	}             
+	$sth = $dbi->prepare("SET NAMES 'utf8'");
+	$sth->execute();
+
+
 $fase=intval($_GET['fase']);
 
@@ -19,9 +23,9 @@
 	$res->execute();
 
-Header("content-type: application/x-javascript");
+Header("content-type: application/x-javascript; charset=utf-8");
 echo "document.write(\"<b><select name=\'id_cons_gen2\'>";
 
 while(list($id_cons_gen2,$descr) = $res->fetch(PDO::FETCH_NUM)) {
-			echo "<option value=\'$id_cons_gen2\'>$descr";
+			echo "<option value=\'$id_cons_gen2\'>$descr</option>";
 		}
 		echo "</select>";
@@ -44,9 +48,9 @@
 	$res->execute();
 
-Header("content-type: application/x-javascript");
+Header("content-type: application/x-javascript; charset=utf-8");
 echo "document.write(\"<b><input type=\'hidden\' name=\'id_cons_gen2\' value=\'$id_cons_gen2\'><select name=\'id_comune2\'>";
 
 while(list($id_comune2,$descr) = $res->fetch(PDO::FETCH_NUM)) {
-			echo "<option value=\'$id_comune2\'>$descr";
+			echo "<option value=\'$id_comune2\'>$descr</option>";
 		}
 		echo "</select>";
Index: trunk/client/modules/Elezioni/backup.php
===================================================================
--- trunk/client/modules/Elezioni/backup.php	(revision 359)
+++ trunk/client/modules/Elezioni/backup.php	(revision 360)
@@ -12,5 +12,5 @@
 list($nomeFile) = $result->fetch(PDO::FETCH_NUM);
 #$nomeFile="backup";
-header( 'Content-Type: application/octet-stream' );
+header( 'Content-Type: application/octet-stream; charset=utf-8' );
 header( 'Content-Disposition: attachment; filename="'.$nomeFile.'"' );
 #header( 'Content-Length:'.strlen( $content ) );
Index: trunk/client/versione.php
===================================================================
--- trunk/client/versione.php	(revision 359)
+++ trunk/client/versione.php	(revision 360)
@@ -1,7 +1,7 @@
 <?php
 
-$versione = "3.0 rev 359";
+$versione = "3.0 rev 360";
 $version_number = $versione;
-$datarel = "24 febbraio 2022";
+$datarel = "14 marzo 2022";
 $version = "Eleonline $version_number (<i>Data Release: $datarel</i>)";
 
Index: trunk/install/sql/eleonline.sql
===================================================================
--- trunk/install/sql/eleonline.sql	(revision 359)
+++ trunk/install/sql/eleonline.sql	(revision 360)
@@ -1,13 +1,12 @@
 -- phpMyAdmin SQL Dump
--- version 4.7.7
+-- version 5.1.0
 -- https://www.phpmyadmin.net/
 --
--- Host: 127.0.0.1
--- Creato il: Apr 16, 2019 alle 21:10
--- Versione del server: 10.1.30-MariaDB
--- Versione PHP: 7.2.2
+-- Host: localhost
+-- Creato il: Mar 11, 2022 alle 17:08
+-- Versione del server: 10.3.27-MariaDB-0+deb10u1
+-- Versione PHP: 7.3.31-1~deb10u1
 
 SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
-SET AUTOCOMMIT = 0;
 START TRANSACTION;
 SET time_zone = "+00:00";
@@ -20,5 +19,5 @@
 
 --
--- Database: `ele3`
+-- Database: `eleonline3`
 --
 
@@ -32,5 +31,5 @@
   `access_id` int(10) NOT NULL,
   `access_title` varchar(20) DEFAULT NULL
-) ENGINE=MyISAM DEFAULT CHARSET=latin1;
+) ENGINE=MyISAM DEFAULT CHARSET=utf8;
 
 --
@@ -54,13 +53,13 @@
   `aid` varchar(25) NOT NULL DEFAULT '',
   `name` varchar(50) DEFAULT NULL,
-  `id_comune` int(11) NOT NULL DEFAULT '0',
+  `id_comune` int(11) NOT NULL DEFAULT 0,
   `email` varchar(255) DEFAULT NULL,
   `pwd` varchar(40) DEFAULT NULL,
-  `counter` int(11) NOT NULL DEFAULT '0',
-  `adminop` tinyint(2) NOT NULL DEFAULT '0',
-  `admincomune` tinyint(2) NOT NULL DEFAULT '0',
-  `adminsuper` tinyint(2) NOT NULL DEFAULT '0',
+  `counter` int(11) NOT NULL DEFAULT 0,
+  `adminop` tinyint(2) NOT NULL DEFAULT 0,
+  `admincomune` tinyint(2) NOT NULL DEFAULT 0,
+  `adminsuper` tinyint(2) NOT NULL DEFAULT 0,
   `admlanguage` varchar(30) NOT NULL DEFAULT ''
-) ENGINE=MyISAM DEFAULT CHARSET=latin1;
+) ENGINE=MyISAM DEFAULT CHARSET=utf8;
 
 --
@@ -84,24 +83,25 @@
   `startdate` varchar(50) NOT NULL DEFAULT '',
   `adminmail` varchar(255) NOT NULL DEFAULT '',
-  `tema` varchar(25) NOT NULL,
-  `foot` text NOT NULL,
-  `language` varchar(3) NOT NULL,
-  `blocco` enum('0','1') NOT NULL,
-  `testata` blob,
-  `nome_testata` varchar(50) NOT NULL,
-  `fileout` varchar(255) NOT NULL,
-  `copyright` text NOT NULL,
-  `versione` int(3) NOT NULL,
-  `patch` int(3) NOT NULL,
-  `siteistat` int(11) NOT NULL,
-  `multicomune` enum('0','1') NOT NULL,
-  `flash` enum('0','1') NOT NULL,
-  `displayerrors` enum('0','1') NOT NULL,
-  `gkey` varchar(100) NOT NULL,
-  `googlemaps` enum('0','1') NOT NULL,
+  `tema` varchar(25) NOT NULL DEFAULT '',
+  `foot` mediumtext NOT NULL,
+  `language` char(3) NOT NULL DEFAULT '',
+  `blocco` enum('0','1') NOT NULL DEFAULT '0',
+  `testata` blob DEFAULT NULL,
+  `nome_testata` varchar(50) NOT NULL DEFAULT '',
+  `fileout` varchar(255) NOT NULL DEFAULT '',
+  `copyright` mediumtext NOT NULL,
+  `versione` int(3) DEFAULT NULL,
+  `patch` int(3) NOT NULL DEFAULT 0,
+  `siteistat` int(11) NOT NULL DEFAULT 0,
+  `multicomune` enum('0','1') NOT NULL DEFAULT '0',
+  `flash` enum('0','1') NOT NULL DEFAULT '0',
+  `displayerrors` enum('0','1') NOT NULL DEFAULT '0',
+  `gkey` varchar(100) NOT NULL DEFAULT '',
+  `googlemaps` enum('0','1') NOT NULL DEFAULT '0',
   `editor` enum('0','1') NOT NULL DEFAULT '1',
   `tema_on` enum('0','1') NOT NULL DEFAULT '1',
-  `ed_user` varchar(25) NOT NULL
-) ENGINE=MyISAM DEFAULT CHARSET=latin1;
+  `ed_user` varchar(25) NOT NULL DEFAULT '',
+  `secret` varchar(30) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=utf8;
 
 --
@@ -110,5 +110,5 @@
 
 INSERT INTO `soraldo_config` (`sitename`, `siteurl`, `site_logo`, `slogan`, `startdate`, `adminmail`, `tema`, `foot`, `language`, `blocco`, `testata`, `nome_testata`, `fileout`, `copyright`, `Versione`, `patch`, `siteistat`, `multicomune`, `flash`, `displayerrors`, `gkey`, `googlemaps`, `editor`, `tema_on`, `ed_user`) VALUES
-('', 'http://www.fonte-nuova.it', '', 'Sito istituzionale', 'Maggio 2009', 'admin@localhost', 'facebook', '<b>Comune di Menfi</b><br>\r\nvia  - 84023 Menfi (Ag)\r\nTel:  Fax: \r\n<hr>', 'it', '1', '', '', '', 'Gpl v3', 2, 0, 84023, '1', '1', '0', '', '0', '1', '1', 'Admin');
+('', 'https://www.eleonline.it', '', 'Sito istituzionale', 'Maggio 2022', 'admin@localhost', 'facebook', '<b>Comune di Test</b><br>\r\nvia  - \r\nTel:  Fax: \r\n<hr>', 'it', '1', '', '', '', 'Gpl v3', 2, 0, 84023, '1', '1', '0', '', '0', '1', '1', 'Admin');
 
 -- --------------------------------------------------------
@@ -119,8 +119,8 @@
 
 CREATE TABLE `soraldo_doc_cons` (
-  `id_cons` int(11) NOT NULL,
-  `id_doc` int(11) NOT NULL,
-  `tabella` varchar(25) NOT NULL
-) ENGINE=MyISAM DEFAULT CHARSET=latin1;
+  `id_cons` int(11) NOT NULL DEFAULT 0,
+  `id_doc` int(11) NOT NULL DEFAULT 0,
+  `tabella` varchar(25) NOT NULL DEFAULT ''
+) ENGINE=MyISAM DEFAULT CHARSET=utf8;
 
 -- --------------------------------------------------------
@@ -132,13 +132,13 @@
 CREATE TABLE `soraldo_ele_candidati` (
   `id_cand` int(11) NOT NULL,
-  `id_cons` int(11) NOT NULL DEFAULT '0',
-  `id_lista` int(11) NOT NULL DEFAULT '0',
-  `num_lista` int(2) UNSIGNED NOT NULL DEFAULT '0',
+  `id_cons` int(11) NOT NULL DEFAULT 0,
+  `id_lista` int(11) NOT NULL DEFAULT 0,
+  `num_lista` int(2) UNSIGNED NOT NULL,
   `cognome` varchar(50) DEFAULT NULL,
   `nome` varchar(50) DEFAULT NULL,
-  `note` tinytext NOT NULL,
+  `note` text NOT NULL,
   `simbolo` varchar(30) NOT NULL DEFAULT '',
-  `num_cand` int(7) NOT NULL DEFAULT '0'
-) ENGINE=MyISAM DEFAULT CHARSET=latin1;
+  `num_cand` int(7) NOT NULL DEFAULT 0
+) ENGINE=MyISAM DEFAULT CHARSET=utf8;
 
 -- --------------------------------------------------------
@@ -149,9 +149,9 @@
 
 CREATE TABLE `soraldo_ele_circoscrizione` (
-  `id_cons` int(11) NOT NULL DEFAULT '0',
+  `id_cons` int(11) NOT NULL DEFAULT 0,
   `id_circ` int(11) NOT NULL,
-  `num_circ` int(7) NOT NULL DEFAULT '0',
-  `descrizione` text
-) ENGINE=MyISAM DEFAULT CHARSET=latin1;
+  `num_circ` int(7) NOT NULL DEFAULT 0,
+  `descrizione` mediumtext DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=utf8;
 
 -- --------------------------------------------------------
@@ -163,7 +163,7 @@
 CREATE TABLE `soraldo_ele_collegi` (
   `id_collegio` int(11) NOT NULL,
-  `id_cons_gen` int(11) NOT NULL DEFAULT '0',
-  `descrizione` text
-) ENGINE=MyISAM DEFAULT CHARSET=latin1;
+  `id_cons_gen` int(11) NOT NULL DEFAULT 0,
+  `descrizione` mediumtext DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=utf8;
 
 -- --------------------------------------------------------
@@ -174,11 +174,11 @@
 
 CREATE TABLE `soraldo_ele_come` (
-  `id_cons` int(11) NOT NULL DEFAULT '0',
+  `id_cons` int(11) NOT NULL DEFAULT 0,
   `mid` int(7) NOT NULL,
   `title` varchar(150) NOT NULL DEFAULT '',
-  `preamble` text NOT NULL,
-  `content` text NOT NULL,
+  `preamble` mediumtext NOT NULL,
+  `content` mediumtext NOT NULL,
   `editimage` varchar(100) NOT NULL DEFAULT ''
-) ENGINE=MyISAM DEFAULT CHARSET=latin1;
+) ENGINE=MyISAM DEFAULT CHARSET=utf8;
 
 -- --------------------------------------------------------
@@ -189,5 +189,5 @@
 
 CREATE TABLE `soraldo_ele_comuni` (
-  `id_comune` int(11) NOT NULL DEFAULT '0',
+  `id_comune` int(11) NOT NULL DEFAULT 0,
   `descrizione` varchar(50) DEFAULT NULL,
   `indirizzo` varchar(50) DEFAULT NULL,
@@ -195,11 +195,11 @@
   `fax` varchar(15) DEFAULT NULL,
   `email` varchar(50) DEFAULT NULL,
-  `fascia` tinyint(4) NOT NULL DEFAULT '0',
+  `fascia` tinyint(4) NOT NULL DEFAULT 0,
   `capoluogo` enum('0','1') NOT NULL DEFAULT '0',
-  `simbolo` text,
-  `stemma` blob,
-  `id_cons` int(11) DEFAULT '0',
-  `cap` text
-) ENGINE=MyISAM DEFAULT CHARSET=latin1;
+  `simbolo` mediumtext DEFAULT NULL,
+  `stemma` blob DEFAULT NULL,
+  `id_cons` int(11) DEFAULT 0,
+  `cap` mediumtext DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=utf8;
 
 -- --------------------------------------------------------
@@ -210,9 +210,9 @@
 
 CREATE TABLE `soraldo_ele_comu_collegi` (
-  `id_collegio` int(11) NOT NULL DEFAULT '0',
-  `id_cons` int(11) NOT NULL DEFAULT '0',
-  `id_comune` int(11) NOT NULL DEFAULT '0',
-  `id_cons_gen` int(11) NOT NULL DEFAULT '0'
-) ENGINE=MyISAM DEFAULT CHARSET=latin1;
+  `id_collegio` int(11) NOT NULL DEFAULT 0,
+  `id_cons` int(11) NOT NULL DEFAULT 0,
+  `id_comune` int(11) NOT NULL DEFAULT 0,
+  `id_cons_gen` int(11) NOT NULL DEFAULT 0
+) ENGINE=MyISAM DEFAULT CHARSET=utf8;
 
 -- --------------------------------------------------------
@@ -230,5 +230,5 @@
   `supsbarramento` int(3) NOT NULL,
   `suppremio` int(3) NOT NULL,
-  `listinfsbar` int(3) NOT NULL DEFAULT '1',
+  `listinfsbar` int(3) NOT NULL DEFAULT 1,
   `listinfconta` enum('0','1') NOT NULL DEFAULT '1',
   `listsupconta` enum('0','1') NOT NULL DEFAULT '1',
@@ -240,6 +240,6 @@
   `inffisso` enum('0','1') NOT NULL DEFAULT '0',
   `supfisso` enum('0','1') NOT NULL DEFAULT '0',
-  `fascia_capoluogo` int(2) NOT NULL DEFAULT '0'
-) ENGINE=MyISAM DEFAULT CHARSET=latin1;
+  `fascia_capoluogo` int(2) NOT NULL DEFAULT 0
+) ENGINE=MyISAM DEFAULT CHARSET=utf8;
 
 --
@@ -264,9 +264,9 @@
 CREATE TABLE `soraldo_ele_consultazione` (
   `id_cons_gen` int(11) NOT NULL,
-  `descrizione` text,
+  `descrizione` mediumtext DEFAULT NULL,
   `data_inizio` date DEFAULT NULL,
   `data_fine` date DEFAULT NULL,
-  `tipo_cons` int(7) NOT NULL DEFAULT '0'
-) ENGINE=MyISAM DEFAULT CHARSET=latin1;
+  `tipo_cons` int(7) NOT NULL DEFAULT 0
+) ENGINE=MyISAM DEFAULT CHARSET=utf8;
 
 -- --------------------------------------------------------
@@ -279,14 +279,14 @@
   `id_cons` int(11) NOT NULL,
   `chiusa` set('0','1','2') NOT NULL DEFAULT '0',
-  `id_comune` int(11) NOT NULL DEFAULT '0',
-  `id_cons_gen` int(11) NOT NULL DEFAULT '0',
-  `id_conf` int(11) NOT NULL DEFAULT '0',
+  `id_comune` int(11) NOT NULL DEFAULT 0,
+  `id_cons_gen` int(11) NOT NULL DEFAULT 0,
+  `id_conf` int(11) NOT NULL DEFAULT 0,
   `preferita` enum('0','1') NOT NULL DEFAULT '0',
-  `preferenze` tinyint(1) NOT NULL DEFAULT '1',
-  `id_fascia` int(2) NOT NULL DEFAULT '1',
+  `preferenze` tinyint(1) NOT NULL DEFAULT 1,
+  `id_fascia` int(2) NOT NULL DEFAULT 1,
   `vismf` enum('0','1') NOT NULL DEFAULT '0',
-  `solo_gruppo` enum('0','1') NOT NULL DEFAULT '0',
+  `solo_gruppo` enum('0','1') DEFAULT '0',
   `disgiunto` enum('0','1') NOT NULL DEFAULT '0'
-) ENGINE=MyISAM DEFAULT CHARSET=latin1;
+) ENGINE=MyISAM DEFAULT CHARSET=utf8;
 
 -- --------------------------------------------------------
@@ -301,5 +301,5 @@
   `tipo` varchar(10) NOT NULL,
   `id` int(11) NOT NULL
-) ENGINE=MyISAM DEFAULT CHARSET=latin1;
+) ENGINE=MyISAM DEFAULT CHARSET=utf8;
 
 -- --------------------------------------------------------
@@ -311,8 +311,8 @@
 CREATE TABLE `soraldo_ele_documenti` (
   `id_doc` int(11) NOT NULL,
-  `descrizione` varchar(50) NOT NULL,
-  `nomedoc` varchar(25) NOT NULL,
+  `descrizione` varchar(50) NOT NULL DEFAULT '',
+  `nomedoc` varchar(25) NOT NULL DEFAULT '',
   `filedoc` blob NOT NULL
-) ENGINE=MyISAM DEFAULT CHARSET=latin1;
+) ENGINE=MyISAM DEFAULT CHARSET=utf8;
 
 -- --------------------------------------------------------
@@ -326,6 +326,6 @@
   `abitanti` int(11) NOT NULL,
   `seggi` int(4) NOT NULL,
-  `id_conf` int(11) DEFAULT '1'
-) ENGINE=MyISAM DEFAULT CHARSET=latin1;
+  `id_conf` int(11) DEFAULT 1
+) ENGINE=MyISAM DEFAULT CHARSET=utf8;
 
 --
@@ -409,15 +409,15 @@
 
 CREATE TABLE `soraldo_ele_gruppo` (
-  `id_cons` int(11) NOT NULL DEFAULT '0',
+  `id_cons` int(11) NOT NULL DEFAULT 0,
   `id_gruppo` int(11) NOT NULL,
-  `num_gruppo` int(7) NOT NULL DEFAULT '0',
-  `descrizione` text,
-  `simbolo` text,
-  `stemma` blob,
-  `id_circ` int(11) NOT NULL DEFAULT '0',
-  `num_circ` int(2) UNSIGNED NOT NULL DEFAULT '1',
-  `prognome` text,
-  `programma` mediumblob
-) ENGINE=MyISAM DEFAULT CHARSET=latin1;
+  `num_gruppo` int(7) NOT NULL DEFAULT 0,
+  `descrizione` mediumtext DEFAULT NULL,
+  `simbolo` mediumtext DEFAULT NULL,
+  `stemma` blob DEFAULT NULL,
+  `id_circ` int(11) NOT NULL DEFAULT 0,
+  `num_circ` int(2) UNSIGNED NOT NULL DEFAULT 1,
+  `prognome` mediumtext DEFAULT NULL,
+  `programma` mediumblob DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=utf8;
 
 -- --------------------------------------------------------
@@ -428,11 +428,11 @@
 
 CREATE TABLE `soraldo_ele_link` (
-  `id_cons` int(11) NOT NULL DEFAULT '0',
+  `id_cons` int(11) NOT NULL DEFAULT 0,
   `mid` int(7) NOT NULL,
   `title` varchar(150) NOT NULL DEFAULT '',
-  `preamble` text NOT NULL,
-  `content` text NOT NULL,
+  `preamble` mediumtext NOT NULL,
+  `content` mediumtext NOT NULL,
   `editimage` varchar(100) NOT NULL DEFAULT ''
-) ENGINE=MyISAM DEFAULT CHARSET=latin1;
+) ENGINE=MyISAM DEFAULT CHARSET=utf8;
 
 -- --------------------------------------------------------
@@ -443,15 +443,15 @@
 
 CREATE TABLE `soraldo_ele_lista` (
-  `id_cons` int(11) NOT NULL DEFAULT '0',
+  `id_cons` int(11) NOT NULL DEFAULT 0,
   `id_lista` int(11) NOT NULL,
-  `num_lista` int(7) NOT NULL DEFAULT '0',
-  `id_gruppo` int(11) NOT NULL DEFAULT '0',
-  `num_gruppo` int(2) UNSIGNED NOT NULL DEFAULT '0',
-  `id_circ` int(11) NOT NULL DEFAULT '0',
-  `num_circ` int(2) UNSIGNED NOT NULL DEFAULT '1',
-  `descrizione` text,
-  `simbolo` text,
-  `stemma` blob
-) ENGINE=MyISAM DEFAULT CHARSET=latin1;
+  `num_lista` int(7) NOT NULL DEFAULT 0,
+  `id_gruppo` int(11) NOT NULL DEFAULT 0,
+  `num_gruppo` int(2) UNSIGNED NOT NULL DEFAULT 0,
+  `id_circ` int(11) NOT NULL DEFAULT 0,
+  `num_circ` int(2) UNSIGNED NOT NULL DEFAULT 1,
+  `descrizione` text DEFAULT NULL,
+  `simbolo` mediumtext DEFAULT NULL,
+  `stemma` blob DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=utf8;
 
 -- --------------------------------------------------------
@@ -467,8 +467,8 @@
   `data` date DEFAULT NULL,
   `ora` time DEFAULT NULL,
-  `log_da` text,
-  `log_a` text,
+  `log_da` mediumtext DEFAULT NULL,
+  `log_a` mediumtext DEFAULT NULL,
   `tabella` varchar(30) DEFAULT NULL
-) ENGINE=MyISAM DEFAULT CHARSET=latin1;
+) ENGINE=MyISAM DEFAULT CHARSET=utf8;
 
 -- --------------------------------------------------------
@@ -479,8 +479,8 @@
 
 CREATE TABLE `soraldo_ele_modelli` (
-  `id_cons` int(11) NOT NULL DEFAULT '0',
+  `id_cons` int(11) NOT NULL DEFAULT 0,
   `categoria` varchar(20) NOT NULL DEFAULT '',
   `modello` blob NOT NULL
-) ENGINE=MyISAM DEFAULT CHARSET=latin1;
+) ENGINE=MyISAM DEFAULT CHARSET=utf8;
 
 -- --------------------------------------------------------
@@ -491,11 +491,11 @@
 
 CREATE TABLE `soraldo_ele_numeri` (
-  `id_cons` int(11) NOT NULL DEFAULT '0',
+  `id_cons` int(11) NOT NULL DEFAULT 0,
   `mid` int(7) NOT NULL,
   `title` varchar(150) NOT NULL DEFAULT '',
-  `preamble` text NOT NULL,
-  `content` text NOT NULL,
+  `preamble` mediumtext NOT NULL,
+  `content` mediumtext NOT NULL,
   `editimage` varchar(100) NOT NULL DEFAULT ''
-) ENGINE=MyISAM DEFAULT CHARSET=latin1;
+) ENGINE=MyISAM DEFAULT CHARSET=utf8;
 
 -- --------------------------------------------------------
@@ -506,10 +506,12 @@
 
 CREATE TABLE `soraldo_ele_operatori` (
-  `id_cons` int(11) NOT NULL DEFAULT '0',
-  `id_sede` int(11) NOT NULL DEFAULT '0',
-  `id_comune` int(11) NOT NULL DEFAULT '0',
+  `id_cons` int(11) NOT NULL DEFAULT 0,
+  `id_sede` int(11) NOT NULL DEFAULT 0,
+  `id_comune` int(11) NOT NULL DEFAULT 0,
   `permessi` int(3) DEFAULT NULL,
-  `aid` varchar(25) NOT NULL DEFAULT ''
-) ENGINE=MyISAM DEFAULT CHARSET=latin1;
+  `aid` varchar(25) NOT NULL DEFAULT '',
+  `id_circ` int(11) NOT NULL DEFAULT 0,
+  `id_sez` int(11) NOT NULL DEFAULT 0
+) ENGINE=MyISAM DEFAULT CHARSET=utf8;
 
 -- --------------------------------------------------------
@@ -520,7 +522,7 @@
 
 CREATE TABLE `soraldo_ele_province` (
-  `id` tinyint(11) NOT NULL,
-  `descrizione` varchar(30) NOT NULL
-) ENGINE=MyISAM DEFAULT CHARSET=latin1;
+  `id` tinyint(11) NOT NULL DEFAULT 0,
+  `descrizione` varchar(30) NOT NULL DEFAULT ''
+) ENGINE=MyISAM DEFAULT CHARSET=utf8;
 
 -- --------------------------------------------------------
@@ -531,7 +533,7 @@
 
 CREATE TABLE `soraldo_ele_regioni` (
-  `id` int(11) NOT NULL,
-  `descrizione` varchar(25) NOT NULL
-) ENGINE=MyISAM DEFAULT CHARSET=latin1;
+  `id` int(11) NOT NULL DEFAULT 0,
+  `descrizione` varchar(25) NOT NULL DEFAULT ''
+) ENGINE=MyISAM DEFAULT CHARSET=utf8;
 
 -- --------------------------------------------------------
@@ -542,8 +544,8 @@
 
 CREATE TABLE `soraldo_ele_rilaff` (
-  `id_cons_gen` int(11) NOT NULL DEFAULT '0',
+  `id_cons_gen` int(11) NOT NULL DEFAULT 0,
   `orario` time NOT NULL DEFAULT '00:00:00',
-  `data` date NOT NULL DEFAULT '1970-01-01'
-) ENGINE=MyISAM DEFAULT CHARSET=latin1;
+  `data` date NOT NULL DEFAULT '0000-00-00'
+) ENGINE=MyISAM DEFAULT CHARSET=utf8;
 
 -- --------------------------------------------------------
@@ -554,7 +556,7 @@
 
 CREATE TABLE `soraldo_ele_sede` (
-  `id_cons` int(11) NOT NULL DEFAULT '0',
+  `id_cons` int(11) NOT NULL DEFAULT 0,
   `id_sede` int(11) NOT NULL,
-  `id_circ` int(11) NOT NULL DEFAULT '0',
+  `id_circ` int(11) NOT NULL DEFAULT 0,
   `indirizzo` varchar(60) DEFAULT NULL,
   `telefono1` varchar(12) DEFAULT NULL,
@@ -564,5 +566,5 @@
   `mappa` mediumblob NOT NULL,
   `filemappa` varchar(100) NOT NULL DEFAULT ''
-) ENGINE=MyISAM DEFAULT CHARSET=latin1;
+) ENGINE=MyISAM DEFAULT CHARSET=utf8;
 
 -- --------------------------------------------------------
@@ -573,11 +575,11 @@
 
 CREATE TABLE `soraldo_ele_servizi` (
-  `id_cons` int(11) NOT NULL DEFAULT '0',
+  `id_cons` int(11) NOT NULL DEFAULT 0,
   `mid` int(7) NOT NULL,
   `title` varchar(150) NOT NULL DEFAULT '',
-  `preamble` text NOT NULL,
-  `content` text NOT NULL,
+  `preamble` mediumtext NOT NULL,
+  `content` mediumtext NOT NULL,
   `editimage` varchar(100) NOT NULL DEFAULT ''
-) ENGINE=MyISAM DEFAULT CHARSET=latin1;
+) ENGINE=MyISAM DEFAULT CHARSET=utf8;
 
 -- --------------------------------------------------------
@@ -588,24 +590,24 @@
 
 CREATE TABLE `soraldo_ele_sezioni` (
-  `id_cons` int(11) NOT NULL DEFAULT '0',
+  `id_cons` int(11) NOT NULL DEFAULT 0,
   `id_sez` int(11) NOT NULL,
-  `id_sede` int(11) NOT NULL DEFAULT '0',
-  `num_sez` int(7) NOT NULL DEFAULT '0',
+  `id_sede` int(11) NOT NULL DEFAULT 0,
+  `num_sez` int(7) NOT NULL DEFAULT 0,
   `maschi` int(4) DEFAULT NULL,
   `femmine` int(4) DEFAULT NULL,
-  `validi` int(7) NOT NULL DEFAULT '0',
-  `nulli` int(7) NOT NULL DEFAULT '0',
-  `bianchi` int(7) NOT NULL DEFAULT '0',
-  `contestati` int(7) NOT NULL DEFAULT '0',
-  `solo_gruppo` int(7) NOT NULL DEFAULT '0',
-  `autorizzati_m` int(4) NOT NULL DEFAULT '0',
-  `autorizzati_f` int(4) NOT NULL DEFAULT '0',
-  `voti_nulli` int(7) NOT NULL DEFAULT '0',
-  `validi_lista` int(7) NOT NULL DEFAULT '0',
-  `contestati_lista` int(7) NOT NULL DEFAULT '0',
-  `voti_nulli_lista` int(7) NOT NULL DEFAULT '0',
-  `solo_lista` int(7) NOT NULL DEFAULT '0',
+  `validi` int(7) NOT NULL DEFAULT 0,
+  `nulli` int(7) NOT NULL DEFAULT 0,
+  `bianchi` int(7) NOT NULL DEFAULT 0,
+  `contestati` int(7) NOT NULL DEFAULT 0,
+  `solo_gruppo` int(7) NOT NULL DEFAULT 0,
+  `autorizzati_m` int(4) NOT NULL DEFAULT 0,
+  `autorizzati_f` int(4) NOT NULL DEFAULT 0,
+  `voti_nulli` int(7) NOT NULL DEFAULT 0,
+  `validi_lista` int(7) NOT NULL DEFAULT 0,
+  `contestati_lista` int(7) NOT NULL DEFAULT 0,
+  `voti_nulli_lista` int(7) NOT NULL DEFAULT 0,
+  `solo_lista` int(7) NOT NULL DEFAULT 0,
   `colore` varchar(50) DEFAULT NULL
-) ENGINE=MyISAM DEFAULT CHARSET=latin1;
+) ENGINE=MyISAM DEFAULT CHARSET=utf8;
 
 -- --------------------------------------------------------
@@ -618,5 +620,5 @@
   `id` int(11) NOT NULL,
   `tema` varchar(20) NOT NULL DEFAULT ''
-) ENGINE=MyISAM DEFAULT CHARSET=latin1;
+) ENGINE=MyISAM DEFAULT CHARSET=utf8;
 
 -- --------------------------------------------------------
@@ -627,13 +629,13 @@
 
 CREATE TABLE `soraldo_ele_tipo` (
-  `tipo_cons` int(11) NOT NULL DEFAULT '0',
+  `tipo_cons` int(11) NOT NULL DEFAULT 0,
   `descrizione` varchar(30) DEFAULT NULL,
   `lingua` varchar(2) NOT NULL DEFAULT '0',
-  `genere` tinyint(4) NOT NULL DEFAULT '0',
+  `genere` tinyint(4) NOT NULL DEFAULT 0,
   `voto_g` enum('0','1') NOT NULL DEFAULT '0',
   `voto_l` enum('0','1') NOT NULL DEFAULT '0',
   `voto_c` enum('0','1') NOT NULL DEFAULT '0',
   `circo` enum('0','1') NOT NULL DEFAULT '0'
-) ENGINE=MyISAM DEFAULT CHARSET=latin1;
+) ENGINE=MyISAM DEFAULT CHARSET=utf8;
 
 --
@@ -669,10 +671,10 @@
 
 CREATE TABLE `soraldo_ele_voti_candidati` (
-  `id_cons` int(11) NOT NULL DEFAULT '0',
-  `id_cand` int(11) NOT NULL DEFAULT '0',
-  `id_sez` int(11) NOT NULL DEFAULT '0',
+  `id_cons` int(11) NOT NULL DEFAULT 0,
+  `id_cand` int(11) NOT NULL DEFAULT 0,
+  `id_sez` int(11) NOT NULL DEFAULT 0,
   `num_cand` int(2) UNSIGNED NOT NULL,
-  `voti` int(7) NOT NULL DEFAULT '0'
-) ENGINE=MyISAM DEFAULT CHARSET=latin1;
+  `voti` int(7) NOT NULL DEFAULT 0
+) ENGINE=MyISAM DEFAULT CHARSET=utf8;
 
 -- --------------------------------------------------------
@@ -683,11 +685,11 @@
 
 CREATE TABLE `soraldo_ele_voti_gruppo` (
-  `id_cons` int(11) NOT NULL DEFAULT '0',
-  `id_gruppo` int(11) NOT NULL DEFAULT '0',
-  `id_sez` int(11) NOT NULL DEFAULT '0',
+  `id_cons` int(11) NOT NULL DEFAULT 0,
+  `id_gruppo` int(11) NOT NULL DEFAULT 0,
+  `id_sez` int(11) NOT NULL DEFAULT 0,
   `num_gruppo` int(2) UNSIGNED NOT NULL,
-  `voti` int(7) NOT NULL DEFAULT '0',
-  `solo_gruppo` int(7) NOT NULL DEFAULT '0'
-) ENGINE=MyISAM DEFAULT CHARSET=latin1;
+  `voti` int(7) NOT NULL DEFAULT 0,
+  `solo_gruppo` int(7) NOT NULL DEFAULT 0
+) ENGINE=MyISAM DEFAULT CHARSET=utf8;
 
 -- --------------------------------------------------------
@@ -698,12 +700,12 @@
 
 CREATE TABLE `soraldo_ele_voti_lista` (
-  `id_cons` int(11) NOT NULL DEFAULT '0',
-  `id_lista` int(11) NOT NULL DEFAULT '0',
-  `id_sez` int(11) NOT NULL DEFAULT '0',
-  `num_lista` int(2) UNSIGNED NOT NULL,
-  `voti` int(7) NOT NULL DEFAULT '0',
-  `nulli_lista` int(7) NOT NULL DEFAULT '0',
-  `solo_lista` int(7) NOT NULL DEFAULT '0'
-) ENGINE=MyISAM DEFAULT CHARSET=latin1;
+  `id_cons` int(11) NOT NULL DEFAULT 0,
+  `id_lista` int(11) NOT NULL DEFAULT 0,
+  `id_sez` int(11) NOT NULL DEFAULT 0,
+  `num_lista` int(2) UNSIGNED DEFAULT 0,
+  `voti` int(7) NOT NULL DEFAULT 0,
+  `nulli_lista` int(7) NOT NULL DEFAULT 0,
+  `solo_lista` int(7) DEFAULT 0
+) ENGINE=MyISAM DEFAULT CHARSET=utf8;
 
 -- --------------------------------------------------------
@@ -714,14 +716,14 @@
 
 CREATE TABLE `soraldo_ele_voti_parziale` (
-  `id_cons` int(11) NOT NULL DEFAULT '0',
-  `id_sez` int(11) NOT NULL DEFAULT '0',
+  `id_cons` int(11) NOT NULL DEFAULT 0,
+  `id_sez` int(11) NOT NULL DEFAULT 0,
   `id_parz` int(11) NOT NULL,
   `orario` time NOT NULL DEFAULT '00:00:00',
-  `data` date NOT NULL DEFAULT '1970-01-01',
-  `voti_uomini` int(7) NOT NULL DEFAULT '0',
-  `voti_donne` int(7) NOT NULL DEFAULT '0',
-  `voti_complessivi` int(7) NOT NULL DEFAULT '0',
-  `id_gruppo` int(11) NOT NULL DEFAULT '0'
-) ENGINE=MyISAM DEFAULT CHARSET=latin1;
+  `data` date NOT NULL DEFAULT '0000-00-00',
+  `voti_uomini` int(7) NOT NULL DEFAULT 0,
+  `voti_donne` int(7) NOT NULL DEFAULT 0,
+  `voti_complessivi` int(7) NOT NULL DEFAULT 0,
+  `id_gruppo` int(11) NOT NULL DEFAULT 0
+) ENGINE=MyISAM DEFAULT CHARSET=utf8;
 
 -- --------------------------------------------------------
@@ -732,15 +734,15 @@
 
 CREATE TABLE `soraldo_ele_voti_ref` (
-  `id_cons` int(11) NOT NULL DEFAULT '0',
-  `id_gruppo` int(11) NOT NULL DEFAULT '0',
-  `id_sez` int(11) NOT NULL DEFAULT '0',
+  `id_cons` int(11) NOT NULL DEFAULT 0,
+  `id_gruppo` int(11) NOT NULL DEFAULT 0,
+  `id_sez` int(11) NOT NULL DEFAULT 0,
   `num_gruppo` int(2) UNSIGNED NOT NULL,
-  `si` int(7) DEFAULT '0',
-  `no` int(7) DEFAULT '0',
-  `validi` int(7) DEFAULT '0',
-  `nulli` int(7) DEFAULT '0',
-  `bianchi` int(7) DEFAULT '0',
-  `contestati` int(7) DEFAULT '0'
-) ENGINE=MyISAM DEFAULT CHARSET=latin1;
+  `si` int(7) DEFAULT 0,
+  `no` int(7) DEFAULT 0,
+  `validi` int(7) DEFAULT 0,
+  `nulli` int(7) DEFAULT 0,
+  `bianchi` int(7) DEFAULT 0,
+  `contestati` int(7) DEFAULT 0
+) ENGINE=MyISAM DEFAULT CHARSET=utf8;
 
 -- --------------------------------------------------------
@@ -754,8 +756,8 @@
   `nome_file` varchar(255) NOT NULL DEFAULT '',
   `titolo` varchar(255) NOT NULL DEFAULT '',
-  `pos_or` int(1) NOT NULL DEFAULT '1',
-  `pos_ver` int(3) NOT NULL DEFAULT '0',
-  `attivo` int(1) NOT NULL DEFAULT '0'
-) ENGINE=MyISAM DEFAULT CHARSET=latin1;
+  `pos_or` int(1) NOT NULL DEFAULT 1,
+  `pos_ver` int(3) NOT NULL DEFAULT 0,
+  `attivo` int(1) NOT NULL DEFAULT 0
+) ENGINE=MyISAM DEFAULT CHARSET=utf8;
 
 --
@@ -804,7 +806,7 @@
 --
 ALTER TABLE `soraldo_ele_candidati`
-  ADD UNIQUE KEY `id_cand` (`id_cand`),
+  ADD PRIMARY KEY (`id_cand`) USING BTREE,
   ADD KEY `id_lista` (`id_lista`),
-  ADD KEY `id_cons` (`id_cons`,`num_lista`) USING BTREE;
+  ADD KEY `id_cons` (`id_cons`,`id_lista`) USING BTREE;
 
 --
@@ -853,5 +855,6 @@
 --
 ALTER TABLE `soraldo_ele_consultazione`
-  ADD PRIMARY KEY (`id_cons_gen`);
+  ADD PRIMARY KEY (`id_cons_gen`),
+  ADD UNIQUE KEY `descrizione` (`descrizione`(100));
 
 --
@@ -885,6 +888,6 @@
 --
 ALTER TABLE `soraldo_ele_gruppo`
-  ADD UNIQUE KEY `id_gruppo` (`id_gruppo`),
-  ADD UNIQUE KEY `id_cons` (`id_cons`,`num_gruppo`,`num_circ`) USING BTREE;
+  ADD PRIMARY KEY (`id_gruppo`) USING BTREE,
+  ADD KEY `id_cons` (`id_cons`,`id_circ`) USING BTREE;
 
 --
@@ -898,13 +901,7 @@
 --
 ALTER TABLE `soraldo_ele_lista`
-  ADD PRIMARY KEY (`id_cons`,`num_lista`,`num_circ`) USING BTREE,
-  ADD UNIQUE KEY `id_lista` (`id_lista`),
-  ADD KEY `id_gruppo` (`id_gruppo`);
-
---
--- Indici per le tabelle `soraldo_ele_log`
---
-ALTER TABLE `soraldo_ele_log`
-  ADD KEY `id_cons` (`id_cons`);
+  ADD PRIMARY KEY (`id_lista`) USING BTREE,
+  ADD KEY `id_gruppo` (`id_gruppo`),
+  ADD KEY `id_cons` (`id_cons`,`id_gruppo`) USING BTREE;
 
 --
@@ -983,5 +980,5 @@
   ADD KEY `id_sez` (`id_sez`),
   ADD KEY `id_cand` (`id_cand`),
-  ADD KEY `id_cons` (`id_cons`,`num_cand`) USING BTREE;
+  ADD KEY `id_cons` (`id_cons`,`id_sez`,`id_cand`) USING BTREE;
 
 --
@@ -991,5 +988,5 @@
   ADD KEY `id_gruppo` (`id_gruppo`),
   ADD KEY `id_sez` (`id_sez`),
-  ADD KEY `id_cons` (`id_cons`,`num_gruppo`) USING BTREE;
+  ADD KEY `id_cons` (`id_cons`,`id_sez`,`id_gruppo`) USING BTREE;
 
 --
@@ -999,5 +996,5 @@
   ADD KEY `id_lista` (`id_lista`),
   ADD KEY `id_sez` (`id_sez`),
-  ADD KEY `cons` (`id_cons`,`num_lista`) USING BTREE;
+  ADD KEY `id_cons` (`id_cons`,`id_sez`,`id_lista`) USING BTREE;
 
 --
@@ -1016,5 +1013,5 @@
   ADD KEY `id_gruppo` (`id_gruppo`),
   ADD KEY `id_sez` (`id_sez`),
-  ADD KEY `id_cons` (`id_cons`,`num_gruppo`) USING BTREE;
+  ADD KEY `id_cons` (`id_cons`,`id_gruppo`) USING BTREE;
 
 --
@@ -1140,3 +1137,2 @@
 /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
 /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
-
