Index: trunk/admin/modules/Elezioni/controllo_votanti.php
===================================================================
--- trunk/admin/modules/Elezioni/controllo_votanti.php	(revision 331)
+++ trunk/admin/modules/Elezioni/controllo_votanti.php	(revision 331)
@@ -0,0 +1,238 @@
+<?php
+
+/************************************************************************/
+/* Eleonline - Raccolta e diffusione dei dati elettorali                */
+/* by Roberto Gigli & Luciano Apolito                                   */
+/* http://www.eleonline.it                                              */
+/* info@eleonline.it  luciano@aniene.net rgigli@libero.it               */
+/************************************************************************/
+/* Modulo Controllo dei votanti                                         */
+/* Amministrazione                                                      */
+/************************************************************************/
+
+if (!defined('ADMIN_FILE')) {
+    die ("You can't access this file directly...");
+}
+
+$aid=$_SESSION['aid'];
+global $dbi;
+$prefix=$_SESSION['prefix'];
+$currentlang=$_SESSION['lang'];
+$id_comune=$_SESSION['id_comune'];
+$id_cons_gen=$_GET['id_cons_gen'];
+$bgcolor0=$_SESSION['bgcolor1'];
+$perms=ChiSei($id_cons_gen);
+if ($perms<16 or !$id_cons_gen) die("$perms ".$_SESSION['id_comune'].$_SESSION['aid'].";Non hai i permessi per inserire dati, o non hai scelto la consultazione!");
+
+	$sql="SELECT t1.descrizione,t1.tipo_cons,t2.id_cons FROM ".$prefix."_ele_consultazione as t1, ".$prefix."_ele_cons_comune as t2 where t1.id_cons_gen=t2.id_cons_gen and t2.id_cons_gen='$id_cons_gen' and t2.id_comune='$id_comune'";
+	$sth = $dbi->prepare("$sql");
+	$sth->execute();	
+	$row = $sth->fetch(PDO::FETCH_BOTH);
+$descr_consultazione=$row[0];
+$tipo_cons=$row[1];
+$id_cons=$row[2];
+	$sql="SELECT genere FROM ".$prefix."_ele_tipo where tipo_cons='$tipo_cons' ";
+	$sth = $dbi->prepare("$sql");
+	$sth->execute();	
+	$row = $sth->fetch(PDO::FETCH_BOTH);	
+	$genere = $row[0];
+if (isset($param['ops'])) get_magic_quotes_gpc() ? $ops=$param['ops']:$ops=addslashes($param['ops']); else $ops='';
+if (isset($param['pag'])) $pag=intval($param['pag']); else $pag=0;
+if (isset($param['num_ref'])) $num_ref=intval($param['num_ref']);
+if (isset($param['num_refs'])) $num_refs=intval($param['num_refs']);
+
+include("modules/Elezioni/funzionidata.php");
+include("modules/Elezioni/ele.php");
+//	echo "<SCRIPT type=\"text/javascript\">\n\n<!--\n"
+//	."//-->\n";
+//	echo "function com_pref(testo) {\n";
+//	echo "window2=open(testo,\"test di apertura\")\n";
+//	echo "}\n";
+//	echo "</script>\n";
+
+ele();
+//**************************************************************************
+//        ELE
+//**************************************************************************
+ 
+    global $admin, $bgcolor1, $bgcolor2, $prefix, $dbi, $genere, $id_gruppo;
+	
+	$cond='';
+	if ($genere==0) {
+		if (!IsSet($pag)) {$pag=0;} //inizializza il numero di pagina 
+		if (!IsSet($num_ref)) { 
+			$num_ref=1;
+			$sql="SELECT id_gruppo from ".$prefix."_ele_gruppo where id_cons=$id_cons";
+			$sth = $dbi->prepare("$sql");
+			$sth->execute();
+			$num_refs= $sth->rowCount(); //quante pagine?
+		}
+			$sql="SELECT id_gruppo,num_gruppo from ".$prefix."_ele_gruppo where id_cons=$id_cons and num_gruppo=$num_ref";
+			$sth = $dbi->prepare("$sql");
+			$sth->execute();
+			$row = $sth->fetch(PDO::FETCH_BOTH);	
+			$idg=$row[0];
+			$numg=$row[1];
+		$id_gruppo=$idg;
+		$cond= "and id_gruppo=$id_gruppo";
+		echo "\n<table border=\"0\" width=\"100%\" bgcolor=\"$bgcolor1\" ><tr><td align=\"center\">"._CONSULTAZIONE." N. ".$numg."</td></tr></table>\n<hr>";
+	}
+	$i=1;
+	$sql="SELECT num_sez,id_sez,t1.id_sede, t2.id_circ,maschi,femmine,(maschi+femmine) as elettori FROM ".$prefix."_ele_sezioni as t1, ".$prefix."_ele_sede as t2 where t1.id_cons='$id_cons' and t1.id_sede=t2.id_sede order by num_sez";
+	$sth = $dbi->prepare("$sql");
+	$sth->execute();
+	while ($linka[$i++] = $sth->fetch(PDO::FETCH_BOTH));
+	$num_sez = $sth->rowCount(); //numero totale delle sezioni
+	$tot_compl=0;$tot_u=0;$tot_d=0;
+//	$ar['riga1'][0]="<hr>";
+	$ar[0][0]="<b>"._TOTS."</b>";
+	$ar['perc'][0]=_PERC;
+//	$ar['riga2'][0]="<hr>";
+	for ($i=1;$i<=$num_sez;$i++)
+	{	
+		$ar[$i]['numsez']=$i;
+		$ar[$i]['elettori']=number_format($linka[$i]['elettori'],0,',','.');
+		$tot_compl+=$linka[$i]['elettori'];
+		$tot_u+=$linka[$i]['maschi'];
+		$tot_d+=$linka[$i]['femmine'];
+		
+	}
+	$ar[0][1]="<b>".number_format($tot_compl,0,',','.')."</b>";
+//	$ar['riga1'][1]="<hr>";
+	$ar['perc'][1]=" ";
+//	$ar['riga2'][1]="<hr>";
+	$sql="SELECT orario,data FROM ".$prefix."_ele_rilaff where id_cons_gen=$id_cons_gen order by data desc,orario desc limit 0,1";
+	$sth = $dbi->prepare("$sql");
+	$sth->execute();
+	$row = $sth->fetch(PDO::FETCH_BOTH);	
+	$ultora=$row[0];
+	$ultdata=$row[1];
+
+	$sql = "SELECT data,orario FROM ".$prefix."_ele_rilaff where id_cons_gen='$id_cons_gen' order by data,orario";
+	$resril = $dbi->prepare("$sql");
+	$resril->execute();	
+	$num_ril = $resril->rowCount();  //numero delle rilevazioni previste
+	echo "\n<table border=\"0\" width=\"100%\"  align=\"center\">";
+	echo "<tr bgcolor=\"$bgcolor1\" align=\"center\"><td width=\"5%\"><b>"._SEZIONI."</b></td><td><b>"._ISCRITTI."<br>"._INSEZ."</b></td>";
+	$sql="SELECT  data,orario,sum(voti_complessivi),sum(voti_uomini),sum(voti_donne) from ".$prefix."_ele_voti_parziale where id_cons=$id_cons $cond group by data,orario";
+	$sth = $dbi->prepare("$sql");
+	$sth->execute();
+	while ($row = $sth->fetch(PDO::FETCH_BOTH)) {
+		$data=$row[0];
+		$ora=$row[1];
+		$somma=$row[2];
+		$votiu=$row[3];
+		$votid=$row[4];
+		$perc_u='';$perc_d='';$perc_c='';
+#		if($votiu or $votid)
+		if(($data==$ultdata) and ($ora==$ultora))
+		{
+			$tot[$data.$ora]="\n<table width=\"100%\"><tr align=\"center\"><td width=\"30%\"><b>".number_format($votiu,0,',','.')."</b></td><td width=\"30%\"><b>".number_format($votid,0,',','.')."</b></td><td><b>".number_format($somma,0,',','.')."</b></td></tr></table>\n";
+			if($tot_u) $perc_u=number_format($votiu*100/$tot_u,2);
+			if($tot_d) $perc_d=number_format($votid*100/$tot_d,2);
+			$perc_c=number_format($somma*100/$tot_compl,2);
+		}
+		else
+			$tot[$data.$ora]=$somma;
+	}
+	$ud=0;$ora_rif="";
+	while ($row2 = $resril->fetch(PDO::FETCH_BOTH)) 
+	{
+		$data1=$row2[0];
+		$ora1=$row2[1];
+		$ud++;	
+		list($hour, $minute, $second) = explode(":", $ora1);
+		$ora_ril=$hour.":".$minute;
+		echo "<td";
+		if ($ud==$num_ril) {$ora_rif="$data1.$ora1";}
+		echo ">".form_data($data1)."<br>"._ORE." ".$ora_ril;
+		$sql="SELECT count(data) FROM ".$prefix."_ele_voti_parziale where id_cons='$id_cons' and data='$data1' and orario='$ora_ril' $cond";
+		$resaff = $dbi->prepare("$sql");
+		$resaff->execute();
+		list($num_scr)=$resaff->fetch(PDO::FETCH_NUM); //numero delle sezioni inserite
+		echo "<br>"._SEZIONI." $num_scr "._SU." $num_sez";
+		if ($ud==$num_ril) echo "<br>\n<table width=\"100%\"><tr align=\"center\"><td width=\"30%\">"._UOMINI."</td><td width=\"30%\">"._DONNE."</td><td>"._COMPLESSIVI."</td></tr></table>\n";
+		
+		echo "</td>";
+//	$ar['riga1'][$data1.$ora1]="<hr>";
+	if (isset($tot[$data1.$ora1])){
+		if ($ora_rif=="$data1.$ora1")
+		{
+			$ar['perc'][$data1.$ora1]="\n<table width=\"100%\"><tr align=\"center\"><td width=\"30%\"><i>$perc_u%</i></td><td width=\"30%\"><i>$perc_d%</i></td><td><i>$perc_c%</i></td></tr></table>\n";
+			$ar[0][$data1.$ora1]=$tot[$data1.$ora1];
+		}
+		else
+		{
+			$ar['perc'][$data1.$ora1]="<i>".number_format($tot[$data1.$ora1]*100/$tot_compl,2)."%</i>";
+			$ar[0][$data1.$ora1]="<b>".(number_format($tot[$data1.$ora1],0,',','.'))."</b>";
+		}
+//	$ar['riga2'][$data1.$ora1]="<hr>";
+		if (intval(preg_match("/[1-9]/",$tot[$data1.$ora1]))>0) {
+			for ($i=1;$i<=$num_sez;$i++)
+			{
+				$ar[$i][$data1.$ora1]="<a href=\"admin.php?op=voti&amp;id_cons_gen=$id_cons_gen&amp;id_sez=".$linka[$i]['id_sez']."&amp;id_circ=".$linka[$i]['id_circ']."&amp;id_sede=".$linka[$i]['id_sede']."&amp;do=spoglio&amp;ops=1\"><span style=\"color: rgb(255, 0, 0);\">non rilevata</span>";
+			}
+		}
+	}
+	}
+	$sql="SELECT  data,orario,t2.num_sez,voti_uomini, voti_donne, voti_complessivi from ".$prefix."_ele_voti_parziale as t1, ".$prefix."_ele_sezioni as t2 where t1.id_cons=$id_cons and t1.id_sez=t2.id_sez $cond order by data,orario,t2.num_sez";
+	$sth = $dbi->prepare("$sql");
+	$sth->execute();
+	$ud=0;
+	while ($row = $sth->fetch(PDO::FETCH_BOTH)) {
+		$data=$row[0];
+		$ora=$row[1];
+		$numsez=$row[2];
+		$uomini=$row[3];
+		$donne=$row[4];
+		$complessivi=$row[5];
+		if ($ora_rif=="$data.$ora")
+			$ar[$numsez][$data.$ora]="\n<table width=\"100%\"><tr align=\"center\"><td width=\"30%\">$uomini</td><td width=\"30%\">$donne</td><td>$complessivi</td></tr></table>\n";
+		else
+			$ar[$numsez][$data.$ora]=$complessivi;
+		if ($uomini+$donne>0) {
+			if ($uomini+$donne!=$complessivi) {
+				$ar[$numsez]['controllo']= "<a href=\"admin.php?op=voti&amp;id_cons_gen=$id_cons_gen&amp;id_sez=".$linka[$numsez]['id_sez']."&amp;id_circ=".$linka[$numsez]['id_circ']."&amp;id_sede=".$linka[$numsez]['id_sede']."&amp;do=spoglio&amp;ops=1\"><span style=\"color: rgb(255, 0, 0);\">ERRORE</span></a>";
+			} else {
+				$ar[$numsez]['controllo']= "OK";
+			}
+		}
+	}
+    echo "<td><b>"._STATO."</b></td></tr>\n";
+
+	foreach ($ar as $i => $arr) {
+		echo "<tr bgcolor=\"$bgcolor2\" align=\"center\">";
+		foreach ($arr as $valore)
+		{
+		
+			echo "<td >$valore</td>";
+		}
+		echo "</tr>\n";
+	}
+
+	
+	
+
+     if($genere==0){ //se e' referendum
+        #'Pagina precedente' e 'Pagina Successiva'
+      echo "\n<table width=\"100%\"><tr align=middle>";
+	    $cur=$num_ref;
+        if ($cur>1) {
+              $num_ref--;
+			  echo "<td colspan=\"5\" align=\"center\" bgcolor=\"$bgcolor1\"><a href=\"admin.php?op=controllo_votanti&amp;id_cons_gen=$id_cons_gen&amp;num_ref=$num_ref&amp;num_refs=$num_refs\">";
+              echo "<b>"._PREV_MATCH."</b></a></td>";
+        }
+        if ($cur<$num_refs) {
+	        $cur++;        
+			echo "<td colspan=\"5\" align=\"center\" bgcolor=\"$bgcolor1\"><a href=\"admin.php?op=controllo_votanti&amp;id_cons_gen=$id_cons_gen&amp;num_ref=$cur&amp;num_refs=$num_refs\">";
+            echo "<b>"._NEXT_MATCH."</b></a></td>";
+        }
+        echo "</tr></table>\n";
+	}
+
+	echo "</table>\n<br>\n";
+
+  echo "</table>\n";
+  include ("footer.php");
+
+?>
Index: trunk/admin/modules/Elezioni/controllo_voti.php
===================================================================
--- trunk/admin/modules/Elezioni/controllo_voti.php	(revision 331)
+++ trunk/admin/modules/Elezioni/controllo_voti.php	(revision 331)
@@ -0,0 +1,269 @@
+<?php
+
+/************************************************************************/
+/* Eleonline - Raccolta e diffusione dei dati elettorali                */
+/* by Roberto Gigli & Luciano Apolito                                   */
+/* http://www.eleonline.it                                              */
+/* info@eleonline.it  luciano@aniene.net rgigli@libero.it               */
+/************************************************************************/
+/* Modulo Controllo dei voti                                            */
+/* Amministrazione                                                      */
+/************************************************************************/
+
+if (!defined('ADMIN_FILE')) {
+    die ("You can't access this file directly...");
+}
+
+$aid=$_SESSION['aid'];
+global $dbi;
+$prefix=$_SESSION['prefix'];
+$currentlang=$_SESSION['lang'];
+$id_comune=$_SESSION['id_comune'];
+$id_cons_gen=$_GET['id_cons_gen'];
+$bgcolor1=$_SESSION['bgcolor1'];
+$bgcolor2=$_SESSION['bgcolor2'];
+
+$perms=ChiSei($id_cons_gen);
+if ($perms<16 or !$id_cons_gen) die("$perms Non hai i permessi per inserire dati, o non hai scelto la consultazione!");
+	$sql="SELECT t1.tipo_cons,t2.id_cons,t2.solo_gruppo,t2.disgiunto FROM ".$prefix."_ele_consultazione as t1, ".$prefix."_ele_cons_comune as t2 where t1.id_cons_gen=t2.id_cons_gen and t2.id_cons_gen='$id_cons_gen' and t2.id_comune='$id_comune'";
+	$sth = $dbi->prepare("$sql");
+	$sth->execute();	
+	list($tipo_cons,$id_cons,$dettnulli,$disgiunto) = $sth->fetch(PDO::FETCH_BOTH);
+	$sql="SELECT genere,voto_g,voto_l FROM ".$prefix."_ele_tipo where tipo_cons='$tipo_cons'";
+	$sth = $dbi->prepare("$sql");
+	$sth->execute();	
+	$row = 
+	list($genere,$votog,$votol) = $sth->fetch(PDO::FETCH_NUM);
+include("modules/Elezioni/funzionidata.php");
+include("modules/Elezioni/ele.php");
+if (! get_magic_quotes_gpc()) $magic='addslashes'; else $magic='';
+if (isset($param['ops'])) get_magic_quotes_gpc() ? $ops=$param['ops']:$ops=addslashes($param['ops']); else $ops='';
+if (isset($param['pag'])) $pag=intval($param['pag']); else $pag=0;
+if (isset($param['num_ref'])) $num_ref=intval($param['num_ref']);
+if (isset($param['num_refs'])) $num_refs=intval($param['num_refs']);
+ele();
+//**************************************************************************
+//        ELE
+//**************************************************************************
+ 
+    global $prefix, $dbi,$fascia,$limite;
+	$sql="SELECT sum(maschi),sum(femmine) FROM ".$prefix."_ele_sezioni where id_cons='$id_cons'";
+	$sth = $dbi->prepare("$sql");
+	$sth->execute();	
+#	$row = $sth->fetch(PDO::FETCH_BOTH);
+	list($totm,$totf) =  $sth->fetch(PDO::FETCH_NUM);
+	$totel=$totm+$totf;
+	if (!IsSet($pag)) {$pag=0;} //inizializza il numero di pagina 
+	if (!IsSet($num_ref)) { 
+		$num_ref=1;
+		$sql="SELECT id_gruppo from ".$prefix."_ele_gruppo where id_cons=$id_cons";
+		$sth = $dbi->prepare("$sql");
+		$sth->execute();	
+		$num_refs= $sth->rowCount(); //quante pagine?
+#		$row = $sth->fetch(PDO::FETCH_BOTH);
+	}
+	if((($genere!=4) and $pag==0 and !$votog) or $genere==1 or $genere==2){ //diverso da liste a piu' candidati
+		$ops=4;	//gestione gruppi (anche liste uninominali)
+	}else{
+		$ops=3; //gestione liste
+	}
+	OpenTable();
+		$sql="SELECT id_gruppo,num_gruppo from ".$prefix."_ele_gruppo where id_cons=$id_cons and num_gruppo=$num_ref";
+		$sth = $dbi->prepare("$sql");
+		$sth->execute();	
+#		$row = $sth->fetch(PDO::FETCH_BOTH);
+		list($idg,$numg) = $sth->fetch(PDO::FETCH_BOTH);
+		$sql="SELECT id_sez,num_sez,t1.id_sede as id_sede,t2.id_circ as id_circ FROM ".$prefix."_ele_sezioni as t1,".$prefix."_ele_sede as t2 where t1.id_cons='$id_cons' and t1.id_sede=t2.id_sede order by num_sez";
+		$sth = $dbi->prepare("$sql");
+		$sth->execute();
+		$num_sez = $sth->rowCount();  //quante sezioni?
+		$sezione=array();
+for ($i=1;$i<=$num_sez;$i++){
+		$sezione[$i]=array();
+		$sezione[$i]= $sth->fetch(PDO::FETCH_BOTH); //inizializza l'array delle sezioni
+		$ar[$i]=0;
+	}
+	$tab3="_ele_voti_lista";
+//	if ($genere==3) {$tab3="_ele_voti_candidati";} else {$tab3="_ele_voti_lista";} //i voti di lista per le uninominali sono memorizzati in ele_voti_candidati altrimenti in ele_voti_lista.
+if ($genere==1 or $genere==2) $tab3="_ele_voti_gruppo";
+	if ($genere>0) {  //se non e' un referendum
+		if (!($genere==4) and $pag==0){  //se non e' una lista uninominale ed e' la prima pagina
+			$tab="SELECT 0,t2.id_sez,t2.num_sez,t2.validi,'0',t2.validi,t2.nulli,t2.bianchi,t2.contestati, t4.id_circ,t2.id_sede,'0',t2.voti_nulli,t2.validi_lista,t2.voti_nulli_lista,t2.contestati_lista,t2.solo_gruppo,t2.solo_lista FROM ".$prefix."_ele_sezioni as t2 left join ".$prefix."_ele_sede as t4 on (t2.id_sede=t4.id_sede) where t2.id_cons='$id_cons' and t2.validi+t2.nulli+t2.bianchi+t2.contestati>0 group by t2.id_sez order by t2.num_sez";
+
+		}else{ // e' una lista uninominale o la seconda pagina
+			$tab="SELECT '0',t1.id_sez,t1.num_sez,sum(t2.voti),t1.solo_gruppo,t1.validi,t1.nulli,t1.bianchi,t1.contestati, t4.id_circ,t1.id_sede,'0',t1.voti_nulli,t1.validi_lista,t1.voti_nulli_lista,t1.contestati_lista,t1.solo_gruppo,t1.solo_lista
+			FROM ".$prefix."_ele_sezioni as t1 left join ".$prefix.$tab3." as t2 on (t1.id_sez=t2.id_sez)
+			left join ".$prefix."_ele_sede as t4 on (t1.id_sede=t4.id_sede)
+			where t1.id_cons='$id_cons' and t1.id_cons=t2.id_cons group by t2.id_sez order by t1.num_sez";
+		}
+		$riga1="<tr><td>\n<table border=\"0\" width=\"100%\" bgcolor=\"$bgcolor1\" ><tr><td align=\"center\">"._SEZSCR." "._CONSULTAZIONE."</td></tr></table></td></tr>\n";
+	}else{ // e' un referendum
+		$tab="SELECT t1.id_gruppo,t1.id_sez,t2.num_sez,t1.si,t1.no,t1.validi,t1.nulli,t1.bianchi,t1.contestati, t4.id_circ,t2.id_sede,t3.num_gruppo,'0','0','0','0','0','0'
+		FROM ".$prefix."_ele_voti_ref as t1 left join ".$prefix."_ele_sezioni as t2 on (t1.id_sez=t2.id_sez)
+		left join  ".$prefix."_ele_gruppo as t3 on (t1.id_gruppo=t3.id_gruppo) left join ".$prefix."_ele_sede as t4 on (t2.id_sede=t4.id_sede)
+		where t1.id_cons='$id_cons' and t1.id_gruppo='$idg' order by t2.num_sez";
+		$riga1= "<tr><td>\n<table border=\"0\" width=\"100%\" bgcolor=\"$bgcolor1\" ><tr><td align=\"center\">"._SEZSCR." "._CONSULTAZIONE." N. ".$numg."</td></tr></table></td></tr>\n";
+	}
+	$sth = $dbi->prepare("$tab ");
+			$sth->execute();
+	$num_scr = $sth->rowCount(); 
+	$riga2= "<tr><td>\n<table border=\"0\" width=\"100%\" bgcolor=\"$bgcolor1\" ><tr><td align=\"center\">"._SEZIONI." $num_scr "._SU." $num_sez</td></tr></table></td></tr>\n";//sezioni scrutinate
+	$riga2 .= "<tr><td>\n<table border=\"0\" width=\"100%\"  align=\"center\">";
+	$riga3 = "<tr bgcolor=\"$bgcolor2\" align=\"center\"><td width=\"5%\"><b>"._SEZIONI."</b></td>"
+    ."<td><b>"._VOTIU."</b></td>"."<td><b>"._VOTID."</b></td>"."<td><b>"._VOTIE."</b></td>"; //testata con nomi dei campi
+	if ($genere==0) {  //se e' un referendum
+		$riga3 .= "<td><b>"._SI."</b></td><td><b>"._NO."</b></td>";
+	} elseif ((($genere==5) or ($genere==3)) and $pag==1){
+		$riga3 .= "<td><b>"._ASOLA_LISTA."</b></td>";
+		if (!$votog) $riga3 .= "<td><b>"._ASOLO_GRUPPO."</b></td>";
+	}
+	$riga3 .= "<td><b>"._VALIDI."</b></td><td><b>"._NULLI."</b></td><td><b>"._BIANCHI."</b></td><td><b>"._CONTESTATI."</b></td>";
+//	if (($genere==2 or $genere==3 or $genere==5) and !$votog)
+//		$riga3 .= "<td><b>"._PREFGRU."</b></td>";
+//	if ($genere>1 and !$votol)
+//		$riga3 .= "<td><b>"._PREFLIS."</b></td>";
+    	$riga3 .= "<td><b>"._STATO."</b></td></tr>\n";
+	$righe= "";
+	$scrutinate=1;
+//	if ($genere>1 and $pag==1) $ops=3;
+	$tot_u=0;$tot_d=0;$tot_voti=0; $tot_si=0;$tot_no=0;$tot_validi=0;$tot_nulli=0;$tot_bianchi=0;$tot_contestati=0;$tgrup_pref=0;$tot_voti_nulli=0;$tot_val_lista=0;$tot_vot_nul_lis=0;$tot_cont_lis=0;$tot_solog=0;$tot_solol=0;$errors=0;
+	while (	list($id_gruppo,$id,$num,$si,$no,$validi,$nulli,$bianchi,$contestati,$id_circ,$id_sede,$gruppo,$voti_nulli,$val_lista,$vot_nul_lis,$cont_lis,$solog,$solol) = $sth->fetch(PDO::FETCH_NUM)){
+//controllare
+	// inserimento numeri di sez non scrutinate
+		while ($scrutinate < $num) { 
+			$righe.= "<tr align=\"center\"><td><a href=\"admin.php?op=voti&amp;id_cons_gen=$id_cons_gen&amp;id_sez=".$sezione[$scrutinate]['id_sez']."&amp;id_circ=".$sezione[$scrutinate]['id_circ']."&amp;id_sede=".$sezione[$scrutinate]['id_sede']."&amp;do=spoglio&amp;ops=$ops\"><span style=\"color: rgb(255, 0, 0);\">$scrutinate</span></a></td></tr>\n";
+			$scrutinate++;
+		}
+		$scrutinate++; 
+	// fine inserimento	
+		if (($genere==2 or $genere==3 or $genere==5) and !$votog and !$dettnulli) {
+			$sql="select sum(voti) from ".$prefix."_ele_voti_gruppo where id_sez='$id'";
+			$sth2 = $dbi->prepare("$sql");
+			$sth2->execute();	
+			list ($gruppref) = $sth2->fetch(PDO::FETCH_NUM);
+			$tgrup_pref += $gruppref;
+		}
+		$tab2="SELECT max(voti_donne),max(voti_uomini),max(voti_complessivi) FROM ".$prefix."_ele_voti_parziale where id_cons='$id_cons' and id_sez='$id'";
+		if ($genere==0) $tab2 .= " and id_gruppo=$id_gruppo";
+			$sth2 = $dbi->prepare("$tab2");
+			$sth2->execute();	
+			list($votid,$votiu,$voti) = $sth2->fetch(PDO::FETCH_NUM);
+//		$voti=$votiu+$votid;
+		
+		$tot_u+=$votiu;
+		$tot_d+=$votid;
+		$tot_voti+=$voti;
+		$tot_si+=$si;
+		$tot_no+=$no;
+		$tot_validi+=$validi;
+		$tot_nulli+=$nulli;
+		$tot_bianchi+=$bianchi;
+		$tot_contestati+=$contestati;
+		$tot_voti_nulli+=$voti_nulli;
+		$tot_val_lista+=$val_lista;
+		$tot_vot_nul_lis+=$vot_nul_lis;
+		$tot_cont_lis+=$cont_lis;
+		$tot_solog+=$solog;
+		$tot_solol+=$solol;
+		$righe .= "<tr bgcolor=\"$bgcolor2\" align=\"center\"><td>$num</td><td>".number_format($votiu,0,',','.')."</td><td>".number_format($votid,0,',','.')."</td><td>".number_format($voti,0,',','.')."</td>";
+		if ($genere==0 or ((($genere==5) or ($genere==3)) and $pag==1)){$righe .= "<td>".number_format($si,0,',','.')."</td>";}
+		if ($genere==0 or ((($genere==5) or ($genere==3)) and $pag==1 and !$votog)){$righe .= "<td>".number_format($no,0,',','.')."</td>";}
+		$righe .= "<td>".number_format($validi,0,',','.')."</td><td>$nulli</td><td>$bianchi</td><td>$contestati</td>";
+		$g_err=0;
+		if (($genere==2 or $genere==3 or $genere==5) and $pag==1 and !$votog and !$dettnulli) {
+			if ($gruppref!=$validi) {
+				$g_err=1;
+				$ops=4;
+			}
+		}
+		$controllo1=$validi+$nulli+$bianchi+$contestati+$voti_nulli; #prova
+		if($pag==0) $controllo2=$si+$no; else $controllo2=$si+$no+$vot_nul_lis+$cont_lis;
+		if($genere==5 and !$votog) #$validi+$nulli+$bianchi+$vcont+$vn 
+			if($pag==0 and !$votog or $fascia<=$limite) {$controllo1=$validi+$nulli+$bianchi+$contestati+$voti_nulli;} else { $controllo1=$val_lista+$nulli+$bianchi+$contestati+$voti_nulli+$cont_lis+$vot_nul_lis+$solog;$controllo2=$si+$no-$solol+$cont_lis+$vot_nul_lis;}
+			$sth2 = $dbi->prepare("select count(0) from ".$prefix."_ele_controlli where id_cons='$id_cons' and id_sez='$id'");
+			$sth2->execute();	
+			list($crlis) = $sth2->fetch(PDO::FETCH_NUM);
+
+		if ($voti==$controllo1 and $validi==$controllo2 and !$g_err and !$crlis){
+			$righe .= "<td>"._OK."</td></tr>\n";
+		}else{
+			$righe .= "<td><a href=\"admin.php?op=voti&amp;id_cons_gen=$id_cons_gen&amp;id_sez=$id&amp;id_circ=$id_circ&amp;id_sede=$id_sede&amp;do=spoglio&amp;ops=$ops\"><span style=\"color: rgb(255, 0, 0);\">"._ERRORE."</span></a></td></tr>\n";$errors=1;
+			if ($ops==4) $ops=3;
+		}
+	}
+	if ($num<$num_sez) {
+		for (;$scrutinate<=$num_sez;$scrutinate++) {
+			$righe .= "<tr align=\"center\"><td><a href=\"admin.php?op=voti&amp;id_cons_gen=$id_cons_gen&amp;id_sez=".$sezione[$scrutinate]['id_sez']."&amp;id_circ=".$sezione[$scrutinate]['id_circ']."&amp;id_sede=".$sezione[$scrutinate]['id_sede']."&amp;do=spoglio&amp;ops=$ops\"><span style=\"color: rgb(255, 0, 0);\">$scrutinate</span></td></tr>\n";
+		}
+	}
+	if($num_scr){
+	$righet = "<tr align=\"center\"><td><b>"._TOT."</b></td><td><b>".number_format($tot_u,0,',','.')."</b><br><i>(".number_format($tot_u*100/$totm,2)." %)</i></td><td><b>".number_format($tot_d,0,',','.')."</b><br><i>(".number_format($tot_d*100/$totf,2)." %)</i></td><td><b>".number_format($tot_voti,0,',','.')."</b><br><i>(".number_format($tot_voti*100/$totel,2)." %)</i></td>";
+	// se e' un referendum o una consultazione con raggruppamenti
+	if($tot_validi){
+	if ($genere==0 or ((($genere==5) or ($genere==3)) and $pag==1)){$righet .= "<td><b>".number_format($tot_si,0,',','.')."</b><br><i>(".number_format($tot_si*100/$tot_validi,2)." %)</i></td>";}
+	if ($genere==0 or ((($genere==5) or ($genere==3)) and $pag==1 and !$votog)){$righet .= "<td><b>".number_format($tot_no,0,',','.')."</b><br><i>(".number_format($tot_no*100/$tot_validi,2)." %)</i></td>";}
+	$righet .= "<td><b>".number_format($tot_validi,0,',','.')."</b><br><i>(".number_format($tot_validi*100/$tot_voti,2)." %)</i></td><td><b>"
+	.number_format($tot_nulli,0,',','.')."</b><br><i>(".number_format($tot_nulli*100/$tot_voti,2)." %)</i></td><td><b>".number_format($tot_bianchi,0,',','.')."</b><br><i>(".number_format($tot_bianchi*100/$tot_voti,2)." %)</i></td><td><b>".number_format($tot_contestati,0,',','.')."</b><br><i>(".number_format($tot_contestati*100/$tot_voti,2)." %)</i></td>";
+	}else{
+	if ($genere==0 or ((($genere==5) or ($genere==3)) and $pag==1)){$righet .= "<td><b>".number_format($tot_si,0,',','.')."</b><br><i>(0.00 %)</i></td>";}
+	if ($genere==0 or ((($genere==5) or ($genere==3)) and $pag==1 and !$votog)){$righet .= "<td><b>".number_format($tot_no,0,',','.')."</b><br><i>(0.00 %)</i></td>";}
+	$righet .= "<td><b>".number_format($tot_validi,0,',','.')."</b><br><i>(0.00 %)</i></td><td><b>"
+	.number_format($tot_nulli,0,',','.')."</b><br><i>(".number_format($tot_nulli*100/$tot_voti,2)." %)</i></td><td><b>".number_format($tot_bianchi,0,',','.')."</b><br><i>(".number_format($tot_bianchi*100/$tot_voti,2)." %)</i></td><td><b>".number_format($tot_contestati,0,',','.')."</b><br><i>(".number_format($tot_contestati*100/$tot_voti,2)." %)</i></td>";
+	}
+	$g_err=0;
+	if (($genere==2 or $genere==3 or $genere==5) and $pag==1 and !$votog) {
+		if ($tgrup_pref!=$tot_validi) {
+			$g_err=1;
+		}
+	}
+#	if ($tot_voti==$tot_validi+$tot_nulli+$tot_bianchi+$tot_contestati and
+#		$tot_validi==$tot_si+$tot_no and !$g_err) {
+	if (! $errors) {
+		$righet .= "<td>"._OK."</td></tr>\n";
+	}else{
+		$righet .= "<td><span style=\"color: rgb(255, 0, 0);\">"._ERRORE."</span></td></tr>\n";
+	}
+	}else $righet='';
+	//$righe .= "</table></td></tr>\n";
+
+	echo "$riga1";
+	echo $riga2;
+	echo $righet;
+	echo $riga3;
+	echo $righe;
+	CloseTable();
+
+    echo"<table align=\"center\" width=\"100%\" bgcolor=\"$bgcolor1\"><tr>\n";
+    if($genere==0){ //se e' referendum
+        #'Pagina precedente' e 'Pagina Successiva'
+	    $cur=$num_ref;
+        if ($cur>1) {
+              $num_ref--;
+			  echo "<td colspan=\"5\" align=\"center\" bgcolor=\"$bgcolor1\"><a href=\"admin.php?op=controllo_voti&amp;id_cons_gen=$id_cons_gen&amp;num_ref=$num_ref&amp;num_refs=$num_refs\">";
+              echo "<b>"._PREV_MATCH."</b></a></td>";
+        }
+        if ($cur<$num_refs) {
+	        $cur++;        
+			echo "<td colspan=\"5\" align=\"center\" bgcolor=\"$bgcolor1\"><a href=\"admin.php?op=controllo_voti&amp;id_cons_gen=$id_cons_gen&amp;num_ref=$cur&amp;num_refs=$num_refs\">";
+            echo "<b>"._NEXT_MATCH."</b></a></td>";
+        }
+    }elseif(($genere==5 and ($fascia>=$limite or $dettnulli)) or ($genere==3) or ($genere==2) or $genere==1){ //se vi sono raggruppamenti
+		$pag=($pag==0 ? 1:0);
+		echo "<td colspan=\"5\" align=\"center\" bgcolor=\"$bgcolor1\"><a href=\"admin.php?op=controllo_voti&amp;id_cons_gen=$id_cons_gen&amp;pag=$pag\"><b>";
+        if($pag) echo _CONTR_PREF;
+		else echo _CONTR_ESPR;
+		echo "</b></a></td>";
+
+	}/* elseif ($genere==1){
+		$pag=($pag==0 ? 1:0);
+		echo "<td colspan=\"5\" align=\"center\" bgcolor=\"$bgcolor1\"><a href=\"admin.php?op=controllo_voti&amp;id_cons_gen=$id_cons_gen&amp;pag=$pag\"><b>";
+        if($pag) echo _CONTR_GRUP;
+		else echo _CONTR_ESPR;
+		echo "</b></a></td>";
+	}*/
+	echo "</tr></table><br>\n";
+echo "</table>\n</td></tr></table>\n";
+
+   include ("footer.php");
+
+?>
