Index: trunk/admin/modules/Elezioni/ele_colora_sez.php
===================================================================
--- trunk/admin/modules/Elezioni/ele_colora_sez.php	(revision 393)
+++ trunk/admin/modules/Elezioni/ele_colora_sez.php	(revision 394)
@@ -20,16 +20,17 @@
 	$res->execute();	
 }else{ #candidati
-	$sql="SELECT t2.id_lista FROM ".$prefix."_ele_voti_candidati as t1 left join ".$prefix."_ele_candidati as t2 on t1.id_cand=t2.id_cand where t1.id_cons='$id_cons' and t1.id_sez='$id_sez' group by t2.id_lista";
+	$sql="SELECT t1.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' group by t2.id_lista";
 	$res = $dbi->prepare("$sql");
 	$res->execute();
 	$liste=$res->rowCount();
-	
+	list($listescru)=$res->fetch(PDO::FETCH_NUM);
+	if($res->rowCount() and $listescru==0) {$listescru=1;$liste=0;} 
 	$sql="SELECT count(id_lista) FROM ".$prefix."_ele_lista where id_cons='$id_cons' $iscirco";
 	$res = $dbi->prepare("$sql");
 	$res->execute();
 	list($ltot)=$res->fetch(PDO::FETCH_NUM);
-	if($liste && $liste==$ltot){
+	if(($liste && $liste==$ltot) or $listescru){
 		$sezstat=2;
-		$sql="UPDATE ".$prefix."_ele_sezioni set colore='#99CC33' where id_cons='$id_cons' and id_sez='$id_sez'"; #VERDE
+		$sql="UPDATE ".$prefix."_ele_sezioni set colore='#99CC33' where id_cons='$id_cons' and id_sez='$id_sez'"; ;#VERDE
 		$res = $dbi->prepare("$sql");
 		$res->execute();	
Index: trunk/admin/modules/Elezioni/ele_spoglio.php
===================================================================
--- trunk/admin/modules/Elezioni/ele_spoglio.php	(revision 393)
+++ trunk/admin/modules/Elezioni/ele_spoglio.php	(revision 394)
@@ -670,5 +670,5 @@
 
 function finale($id_cons,$do,$id_circ,$id_sede,$id_sez,$ops){
- global $aid, $prefix, $dbi,$id_cons_gen,$genere,$votog,$fascia,$limite;
+ global $aid, $prefix, $dbi,$id_cons_gen,$genere,$votog,$fascia,$limite,$scrtest;
 ////////////////////////////////////////////
 // da qua va la sezione per i voti finali
@@ -676,14 +676,24 @@
 $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 "<SCRIPT type=\"text/javascript\">\n\n<!--\n"
+."//-->\n";
+echo "function setsez() {\n";
+echo "document.getElementById('spogliovoti').submit(); }\n";
+echo "</script>\n";	
+
+$sql="select * from ".$prefix."_ele_voti_lista where id_cons=$id_cons and id_sez=$id_sez and id_lista=0";
+$res = $dbi->prepare("$sql");
+$res->execute(); 
+$stato=$res->rowCount();
+if($stato) $stato='checked'; else $stato='';
+echo "<form name=\"spogliovoti\" id=\"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\">";
+if($scrtest)
+	echo "<div style=\"text-align:right;\">Considerare la sezione come scrutinata? <input type=\"checkbox\" name=\"scrutinata\" id=\"scrutinata\" value=\"true\" $stato onclick=\"setsez()\";> <br></div>";
 
 	echo "<table border=\"0\" width=\"100%\" align=\"center\"><tr bgcolor=\"$bgcolor1\" align=\"center\">";
@@ -750,5 +760,5 @@
 
 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;
+ global $aid, $prefix, $dbi, $tipo_cons, $genere,$id_cons_gen,$sezi,$circo,$dettnulli,$scrtest;
 ////////////////////////////////////////////
 // da qua va la sezione per le preferenze ai gruppi
@@ -938,5 +948,5 @@
 			."<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\">"
+			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>";
@@ -956,7 +966,4 @@
 		$tot_pref=0;
 		$totsg=0;
-		$pro=array();
-		$pro['voti']='';
-		$pro['solo_gruppo']='';
 		while(list($id_cons2,$id_gruppo,$num_gruppo, $descr_gruppo, $simbolo) = $result->fetch(PDO::FETCH_NUM)){
 			echo "<SCRIPT type=\"text/javascript\">\n\n<!--\n"
@@ -1012,6 +1019,6 @@
 					$res = $dbi->prepare("$sql");
 					$res->execute();
-					if($res->rowCount())
-						$pro= $res->fetch(PDO::FETCH_BOTH);
+					$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);\"";}
@@ -1046,5 +1053,6 @@
 		}
 		echo "</td></tr></table></center>";
-	}
+		$scrtest=0;
+	}else{$scrtest=1;}
 	if ($genere!=0){
 		finale($id_cons,$do,$id_circ,$id_sede,$id_sez,$ops);
Index: trunk/admin/modules/Elezioni/salva_voti.php
===================================================================
--- trunk/admin/modules/Elezioni/salva_voti.php	(revision 393)
+++ trunk/admin/modules/Elezioni/salva_voti.php	(revision 394)
@@ -39,5 +39,7 @@
 if (isset($_GET['ops'])) $ops=intval($_GET['ops']); else $ops='';
 if (isset($_GET['delete'])) $delete=intval($_GET['delete']); else $delete='';
-
+if (isset($_GET['scrutinata'])) {$scrutinata=$_GET['scrutinata']==false ? false : true;}else $scrutinata=false;
+#$_SESSION['scrutinata']=$scrutinata;
+#if(isset($_SESSION['scrutinata'])) $scrutinata=$_SESSION['scrutinata']; #else $scrutinata=false;
 global $prefix,$id_parz,$genere,$fileout,$id_cons;
 if (!isset($fileout)) $fileout='';
@@ -69,4 +71,32 @@
 	$res->execute();
 	if ($fileout) fwrite($fp,"$sql;\n");
+######
+#include($sql."TEST: scru=$scrutinata");
+if(isset($scrutinata))
+{	
+	$sql="delete from ".$prefix."_ele_voti_gruppo where id_cons='$id_cons' and id_sez='$id_sez' and num_gruppo=0";
+	$res = $dbi->prepare("$sql");
+	$res->execute();
+	$sql="delete from ".$prefix."_ele_voti_lista where id_cons='$id_cons' and id_sez='$id_sez' and num_lista=0";
+	$res = $dbi->prepare("$sql");
+	$res->execute();
+	$sql="delete from ".$prefix."_ele_voti_candidati where id_cons='$id_cons' and id_sez='$id_sez' and num_cand=0";
+	$res = $dbi->prepare("$sql");
+	$res->execute();
+	if($scrutinata==true)
+	{
+		# provare insert dei soli id_cons e id_sez
+		$sql="insert into ".$prefix."_ele_voti_gruppo (id_cons,id_sez,num_gruppo) values('$id_cons','$id_sez',0)";
+		$res = $dbi->prepare("$sql");
+		$res->execute(); 
+		$sql="insert into ".$prefix."_ele_voti_lista (id_cons,id_sez) values('$id_cons','$id_sez')";
+		$res = $dbi->prepare("$sql");
+		$res->execute(); 
+		$sql="insert into ".$prefix."_ele_voti_candidati (id_cons,id_sez,num_cand) values('$id_cons','$id_sez',0)";
+		$res = $dbi->prepare("$sql");
+		$res->execute(); 
+#		
+	}		
+}	
 /*}else{
  	$sql="insert into ".$prefix."_ele_log values('$id_cons','$id_sez','$aid','','','validi:$ar[6] nulli:$ar[7] bianchi:$ar[8] contestati:$ar[9] voti_nulli:$ar[13]','validi=$validi, nulli=$nulli,bianchi=$bianchi,contestati=$contestati, voti_nulli=$votinulli','_ele_sezioni')";
