<?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 Autorizzazione Comuni                                         */
/* Amministrazione                                                      */
/************************************************************************/
# e' l'unico file in cui è presente un controllo su tipo_cons, per ora va bene così. Per toglierlo va inserito un campo-flag in ele_tipo per indicare se per il tipo di consultazione si dovra' procedere al calcolo dell'assegnazione dei seggi
if (!defined('ADMIN_FILE')) {
    die ("You can't access this file directly...");
}

$aid=$_SESSION['aid'];
$dbi=$_SESSION['dbi'];
$prefix=$_SESSION['prefix'];
$id_comune=$_SESSION['id_comune'];
$id_cons_gen=intval($_GET['id_cons_gen']);
$perms=ChiSei(0);
if ($perms<128 or !$id_cons_gen) die("$perms Non hai i permessi per inserire dati, o non hai scelto la consultazione!");
$res = mysql_query("SELECT t1.tipo_cons,t1.descrizione,t2.id_cons,t2.id_conf 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' " , $dbi);
list($tipo_cons,$descr_cons,$id_cons,$id_conf) = mysql_fetch_row($res);

$res = mysql_query("SELECT genere FROM ".$prefix."_ele_tipo where tipo_cons='$tipo_cons' " , $dbi);
	list($genere) = mysql_fetch_row($res);

include("modules/Elezioni/funzionidata.php");
include("modules/Elezioni/ele.php");
if (isset($_GET['descr_comu'])) get_magic_quotes_gpc() ? $descr_comu=$param['descr_comu']:$descr_comu=addslashes($param['descr_comu']); else $descr_comu='';
if (isset($_GET['do'])) get_magic_quotes_gpc() ? $do=$param['do']:$do=addslashes($param['do']); else $do='';
if (isset($_GET['ok'])) $ok=intval($_GET['ok']); else $ok='';
if (isset($_GET['id_cons_comu'])) $id_cons_comu=intval($_GET['id_cons_comu']); else $id_cons_comu='';
if (isset($_GET['id_collegio'])) $id_collegio=intval($_GET['id_collegio']); else $id_collegio='';
if (isset($_GET['idcomune'])) $idcomune=intval($_GET['idcomune']); else $idcomune='';
if (isset($_GET['idcomunenew'])) $idcomunenew=intval($_GET['idcomunenew']); else $idcomunenew='';
if (isset($_GET['chiusa'])) $chiusa=intval($_GET['chiusa']); else $chiusa='';
if (isset($_GET['id_conf'])) $id_conf=intval($_GET['id_conf']);  else $id_conf=0;
if (isset($_GET['idfascia'])) $idfascia=intval($_GET['idfascia']);  else $idfascia=0;
if (isset($_GET['min'])) $min=intval($_GET['min']); else $min=0;
if (isset($_GET['help'])) $help=intval($_GET['help']);
if (isset($_GET['pwd4'])) $pwd4=intval($_GET['pwd4']);
if (isset($_GET['preferenze'])) $preferenze=intval($_GET['preferenze']); else $preferenze=1;
if (isset($_GET['vismf'])) $vismf=intval($_GET['vismf']); else $vismf=0;
if (isset($_GET['sg'])) $sg=intval($_GET['sg']); else $sg=0;
if (isset($_GET['disgiunto'])) $disgiunto=intval($_GET['disgiunto']); else $disgiunto=0;

$offset=15;
$hiddenInfo = "<input type=\"hidden\" name=\"min\" value=\"$min\">";


	/******************************************************/
	/*Funzione di visualizzazione globale                 */
	/*****************************************************/
	//
	function all() {
	global $user, $admin, $bgcolor1, $bgcolor2, $prefix,$descr_cons, $dbi,$id_cons,$desc,$indirizzo,$centralino,$fax,$id_cons_gen,$id_collegio,$idcomune,$chiusa,$id_conf,$tipo_cons,$language,$help,$preferenze,$idfascia,$vismf,$sg,$disgiunto,$id_cons_comu;
$aid=$_SESSION['aid'];
$dbi=$_SESSION['dbi'];
$prefix=$_SESSION['prefix'];
############# Controllo flag per cancellazione consultazione
	echo "<SCRIPT type=\"text/javascript\">\n\n<!--\n" 
     ."//-->\n"; 
     echo "function del_cons() {\n"; 
     echo "if (document.getElementById('pwd3').checked==false) {\n"; 
     echo "if (document.getElementById('chiusa').selectedIndex==3) document.getElementById('chiusa').options[0].selected=true \n"; 
     echo "document.getElementById('pwd4').checked=false \n"; 
     echo "document.getElementById('trspunta').style.visibility='hidden' \n"; 
     echo "} \n"; 
     echo "else document.getElementById('trspunta').style.visibility='visible' \n"; 
     echo "if (document.getElementById('chiusa').selectedIndex!=3) { \n"; 
     echo "document.getElementById('add').value=\""._MODIFY."\" \n"; 
     echo "document.getElementById('do').value=\"update\" \n"; 
     echo "}else{\n"; 
     echo "if (document.getElementById('pwd4').checked==false) \n"; 
     echo "document.getElementById('add').value=\""._DELETE." "._DATI."\" \n"; 
     echo "else document.getElementById('add').value=\""._DELETE." "._CONSULTA."\" \n"; 
     echo "document.getElementById('do').value=\"delete\" \n"; 
     echo "} \n";     
     echo "} \n"; 
     echo "</script>\n"; 
  
echo "<script type=\"text/javascript\" language=\"JavaScript\" >\n\n<!--\n" 
     ."//-->\n"; 
echo "function showdate(str,posiz,tempo)\n";
echo "{\n";
echo "if (str==\"\")\n";
echo "  {\n";
echo "  document.getElementById(posiz).innerHTML=\"\";\n";
echo "  return;\n";
echo "  }\n";
echo "if (window.XMLHttpRequest)\n";
echo "  {// code for IE7+, Firefox, Chrome, Opera, Safari\n";
echo "  xmlhttp=new XMLHttpRequest();\n";
echo "  }\n";
echo "else\n";
echo "  {// code for IE6, IE5\n";
echo "  xmlhttp=new ActiveXObject(\"Microsoft.XMLHTTP\");\n";
echo "  }\n";
echo "xmlhttp.onreadystatechange=function()\n";
echo "  {\n";
echo "  if (xmlhttp.readyState==4 && xmlhttp.status==200 && posiz!=null)\n";
echo "    {\n";
echo "    document.getElementById(posiz).innerHTML=xmlhttp.responseText;\n";
echo "    }\n";
echo "  }\n";
echo "xmlhttp.open(\"GET\",str,true);\n";
echo "xmlhttp.send();\n";

echo "}\n";
echo "</script>\n";

#########################
	if (isset($help)) include("language/$language/ele_associazioni.html");
	OpenTable();
	echo "<tr><td><hr><br>";	
	$res = mysql_query("SELECT descrizione FROM ".$prefix."_ele_consultazione where id_cons_gen='$id_cons_gen'" , $dbi);
	list ($descr_cons) = mysql_fetch_row($res);
//inserire avviso su mancanza dei permessi
	echo "<form name=\"model\" action=\"admin.php\">";
	echo "<table width=\"100%\" border=\"3\">";
	echo "<tr align=\"center\"><td bgcolor=\"$bgcolor1\"><b>"._CONSULTA."</b></td>";
	echo "<td bgcolor=\"$bgcolor1\"><b>"._DEFCOMUNE."</b></td>";
	echo "<td width=\"10%\" bgcolor=\"$bgcolor1\"><b>"._PREFERENZE."</b></td>";
	echo "<td bgcolor=\"$bgcolor1\"><b>"._STATO."</b></td>";
	if($tipo_cons==3){
		echo "<td bgcolor=\"$bgcolor1\"><b>"._CONF."</b></td>";
		echo "<td bgcolor=\"$bgcolor1\" align=\"center\"><b>"._FASCIA."</b></td>";
		}
	echo "<td bgcolor=\"$bgcolor1\" align=\"center\"><b>"._VISAFFMF."</b></td>";
	echo "<td bgcolor=\"$bgcolor1\" align=\"center\"><b>"._ASOLO_GRUPPO."</b></td>";
	echo "<td bgcolor=\"$bgcolor1\" align=\"center\"><b>"._DISGIUNTO."</b></td>";
	echo "</tr>";
	echo "<tr align=\"center\"><td>";
	echo "<input type=\"hidden\" name=\"op\" value=\"associazioni\">";
	echo "<input type=\"hidden\" name=\"id_cons_gen\" value=\"$id_cons_gen\">$descr_cons</td>";
	$rescomu = mysql_query("SELECT id_comune, descrizione from ".$prefix."_ele_comuni order by descrizione asc", $dbi);
	echo "<td>";
	if($idcomune) {
		while ($listele=mysql_fetch_array($rescomu))
			if($listele['id_comune']==$idcomune) {
				echo $listele['descrizione'];
				echo "<input type=\"hidden\" name=\"idcomunenew\" value=\"$idcomune\">";
			}
		
	}else{
	echo "<select name=\"idcomunenew\">";
	echo "<option value=\"0\"> ";
	while(list($id,$descr_comu)=mysql_fetch_row($rescomu)){
		$sel= ($id == $idcomune) ? "selected":"";
		echo "<option value=\"$id\" $sel>$descr_comu";
	}
	echo "</select>";
	}
	echo "</td>";
	echo "<td><input type=\"text\" name=\"preferenze\" value=\"$preferenze\" size=\"2\"></td>";
	$selez['0']='';
	$selez['1']='';
	$selez['2']='';
	$selez['3']='';
	$selez[$chiusa]="selected";
	echo "<td><select name=\"chiusa\" id=\"chiusa\" onChange=\"javascript:del_cons()\">";
		echo "<option value=\"0\" ".$selez[0].">"._ATTIVA;
		echo "<option value=\"1\" ".$selez[1].">"._CHIUSA;
		echo "<option value=\"2\" ".$selez[2].">"._NULLA;

		if($idcomune) echo "<option value=\"3\" ".$selez[3].">"._ELIMINA;
	echo "</select></td>";
	if($tipo_cons==3){
		if($idcomune) {
			$rescomu = mysql_query("SELECT id_fascia from ".$prefix."_ele_cons_comune where id_cons_gen='$id_cons_gen' and id_comune='$idcomune'", $dbi);
			if($rescomu)
				list($fasciacom)=mysql_fetch_row($rescomu);
		} else $fasciacom=0;
		$rescomu = mysql_query("SELECT id_conf, descrizione from ".$prefix."_ele_conf order by id_conf desc", $dbi);
		echo "<td><select name=\"id_conf\" id=\"id_conf\" onchange=\"javascript:showdate('modules/Elezioni/ele_desc_fasce.php?fascia=$fasciacom&id_conf=' + model.id_conf.options[model.id_conf.selectedIndex].value,'fasceconf');\">";
		echo "<option value=\"0\"> ";
		while(list($id,$descr_conf)=mysql_fetch_row($rescomu)){
			$sel='';
			if ($idcomune and $id == $id_conf) $sel="selected"; 
			echo "<option value=\"$id\" $sel>$descr_conf";
		}
		echo "</select></td>";
		if(!$id_conf) $id_conf=1;
		$rescomu = mysql_query("SELECT id_fascia,abitanti from ".$prefix."_ele_fasce where id_conf='$id_conf'", $dbi);
		
		echo "<td id=\"fasceconf\"><select name=\"idfascia\">";
		echo "<option value=\"0\"> ";
		$inffascia=0;
		while(list($id,$abitanti)=mysql_fetch_row($rescomu)){
			$sel='';
			if ($idcomune and $id == $fasciacom) $sel="selected"; elseif ($id==1) $sel="selected";
			echo "<option value=\"$id\" $sel>$inffascia - $abitanti";
			$inffascia=$abitanti;
		}
		echo "</select></td>";
		
		
	}
	unset($sel);
	$rescomu = mysql_query("SELECT vismf,solo_gruppo,disgiunto from ".$prefix."_ele_cons_comune where id_cons='$id_cons_comu'", $dbi);
	list($vismf,$sg,$disgiunto)=mysql_fetch_row($rescomu);
	echo "<td><select name=\"vismf\">";
	if ($vismf==0) $sel="selected"; else $sel="";
	echo "<option value=\"0\" $sel>No";
	if ($vismf==1) $sel="selected"; else $sel="";
	echo "<option value=\"1\" $sel>Si";
	echo "</select></td>";
	echo "<td><select name=\"sg\">";
	if ($sg==0) $sel="selected"; else $sel="";
	echo "<option value=\"0\" $sel>No";
	if ($sg==1) $sel="selected"; else $sel="";
	echo "<option value=\"1\" $sel>Si";
	echo "</select></td>";
	echo "<td><select name=\"disgiunto\">";
	if ($disgiunto==0) $sel="selected"; else $sel="";
	echo "<option value=\"0\" $sel>No";
	if ($disgiunto==1) $sel="selected"; else $sel="";
	echo "<option value=\"1\" $sel>Si";
	echo "</select></td>";
	
	echo "<td><input type=\"hidden\" name=\"ok\" value=0>";
	echo "<input type=\"hidden\" name=\"id_cons_gen\" value=\"$id_cons_gen\">";
	if ($idcomune) {
		echo "<input type=\"hidden\" id=\"do\" name=\"do\" value=\"update\">";
		echo "<input type=\"hidden\" name=\"idcomune\" value=\"$idcomune\">";
		echo "<input type=\"submit\" id=\"add\" name=\"add\" value=\""._MODIFY."\" ></td></tr>";
		echo "<tr><td colspan=\"5\"><fieldset><legend>"._SPUNTALABEL1."</legend><label id=\"prov1\">"._SPUNTAELIMINA." <input type=\"checkbox\" id=\"pwd3\" name=\"pwd3\" value=\"\" onclick=\"javascript:del_cons()\"></label></fieldset></td></tr>";
		echo "<tr id=\"trspunta\" style=\"visibility:hidden\"><td colspan=\"4\"><fieldset><legend>"._SPUNTALABEL2."</legend><label id=\"prov\">"._VIASPUNTAELIMINA." <input type=\"checkbox\" id=\"pwd4\" name=\"pwd4\" value=\"1\" onclick=\"javascript:del_cons()\"></label></fieldset>";
	}else{
		echo "<input type=\"hidden\" name=\"do\" value=\"add\">";
		echo "<input type=\"submit\" name=\"add\" value=\""._ADD."\">";
	}
	$i=0;
	echo "</td></tr></table></form>";
	echo "<hr><br><table width=\"100%\" border=\"3\">";
	echo "<tr align=\"center\"><td width=\"15%\" bgcolor=\"$bgcolor1\"><b>"._CONSULTA."TEST:$id_cons_comu</b></td>";
	echo "<td width=\"20%\" bgcolor=\"$bgcolor1\"><b>"._DEFCOMUNE."</b></td>";
	echo "<td width=\"10%\" bgcolor=\"$bgcolor1\"><b>"._PREFERENZE."</b></td>";
	echo "<td width=\"10%\" bgcolor=\"$bgcolor1\"><b>"._STATO."</b></td>";
	if($tipo_cons==3){
		echo "<td width=\"20%\" bgcolor=\"$bgcolor1\"><b>"._CONF."</b></td>";
		echo "<td width=\"20%\" bgcolor=\"$bgcolor1\" align=\"center\"><b>"._FASCIA."</b></td>";
		}
	echo "<td width=\"10%\" bgcolor=\"$bgcolor1\" align=\"center\"><b>"._VISAFFMF."</b></td>";
	echo "<td width=\"10%\" bgcolor=\"$bgcolor1\" align=\"center\"><b>"._ASOLO_GRUPPO."</b></td>";
	echo "<td width=\"10%\" bgcolor=\"$bgcolor1\" align=\"center\"><b>"._DISGIUNTO."</b></td>";
	echo "<td width=\"10\" bgcolor=\"$bgcolor1\"><b>&nbsp;"._FUNZIONI."</b></td></tr>";

	$resmod = mysql_query("SELECT '',t1.id_comune,'',t1.id_cons, t2.descrizione, t1.chiusa, t1.id_conf, preferenze,t1.id_fascia,t1.vismf,t1.solo_gruppo,t1.disgiunto FROM ".$prefix."_ele_cons_comune as t1, ".$prefix."_ele_comuni as t2 where t1.id_cons_gen='$id_cons_gen' and t1.id_comune=t2.id_comune order by t2.descrizione", $dbi);
	while (list($id_collegio,$id_comune2,$descr_coll,$id_cons_comu,$descr_comu, $chiusa,$id_conf,$preferenze2,$fasciacom,$vismf2,$sg2,$disgiunto2) = mysql_fetch_row($resmod)){ //elenco dei modelli inseriti
		$resconf = mysql_query("SELECT descrizione FROM ".$prefix."_ele_conf where id_conf='$id_conf'", $dbi);
		list($descr_conf) = mysql_fetch_row($resconf);
		$i++;
		$bgcolor1=($bgcolor1==$_SESSION['bgcolor1'])?$_SESSION['bgcolor2']:$_SESSION['bgcolor1'];
		echo "<tr align=\"center\" bgcolor=\"$bgcolor1\">";
		echo "<td><b>$descr_cons</b></td>";
		echo "<td><b>$descr_comu</b></td>";
		echo "<td><b>$preferenze2</b></td>";
		$stato['0']=_ATTIVA;
		$stato['1']=_CHIUSA;
		$stato['2']=_NULLA;
		echo "<td><b>".$stato[$chiusa]."</b></td>";
		if($tipo_cons==3){
			echo "<td><b>".$descr_conf."</b></td>";
			$rescomu = mysql_query("SELECT id_fascia,abitanti from ".$prefix."_ele_fasce where id_conf='$id_conf'", $dbi);
			$inffascia=0;
			if (mysql_num_rows($rescomu)==0) echo "<td></td>";
			while(list($id,$abitanti)=mysql_fetch_row($rescomu)){
				$sel='';
				if ($id == $fasciacom) 
					echo "<td>$inffascia - $abitanti</td>";
				$inffascia=$abitanti;
			}

		}
		if ($vismf2==0) $sel=_NO; else $sel=_SI;
		echo "<td>$sel</td>";
		if ($sg2==0) $sel=_NO; else $sel=_SI;
		echo "<td>$sel</td>";
		if ($disgiunto2==0) $sel=_NO; else $sel=_SI;
		echo "<td>$sel</td>";
		echo "<td>";
		echo "<form name=\"modello$i\" action=\"admin.php\">"
		."<input type=\"hidden\" name=\"op\" value=\"associazioni\">";
		echo "<input type=\"hidden\" name=\"id_conf\" value=\"$id_conf\">";
		echo "<input type=\"hidden\" name=\"idcomune\" value=\"$id_comune2\">";
		echo "<input type=\"hidden\" name=\"id_cons_comu\" value=\"$id_cons_comu\">";
		echo "<input type=\"hidden\" name=\"id_cons_gen\" value=\"$id_cons_gen\">";
		echo "<input type=\"hidden\" name=\"desc\" value=\"$descr_cons\">";
		echo "<input type=\"hidden\" name=\"preferenze\" value=\"$preferenze2\">";
		echo "<input type=\"hidden\" name=\"chiusa\" value=\"$chiusa\">";
		echo "<input type=\"hidden\" name=\"ok\" value=0><input type=\"submit\" name=\"edit$i\" value=\""._EDIT."\">"
			."</form></td></tr>\n";
	}
		echo "</table></td></tr></table>";
	CloseTable();
	}

function associazioni($ok, $do,$descr_comu,$id_cons_comu,$id_collegio,$id_comune,$chiusa,$id_conf,$preferenze) {
	global $admin, $bgcolor1, $bgcolor2, $prefix, $dbi, $descr_cons,$genere,$id_cons_gen,$idcomunenew,$pwd4,$idfascia,$vismf,$sg,$disgiunto;
	$delcons=0;
	if ($do !="" and $id_cons_gen>0 and $idcomunenew>0) {
		$rescomu = mysql_query("SELECT id_cons from ".$prefix."_ele_cons_comune where id_cons_gen='$id_cons_gen' and id_comune='$idcomunenew'", $dbi); 
		$max = mysql_num_rows($rescomu); //esiste autorizzazione?
			list($delcons)=mysql_fetch_row($rescomu);
			if (!$max){			//se no la inserisce
			$result = mysql_query("insert into ".$prefix."_ele_cons_comune (chiusa,id_comune,id_cons_gen,id_conf,preferenze,id_fascia,vismf,solo_gruppo,disgiunto) values ('0','$idcomunenew','$id_cons_gen','$id_conf','$preferenze','$idfascia','$vismf','$sg','$disgiunto')", $dbi) || die("<br><br>Errore di inserimento: ".mysql_error());
			$rescomu = mysql_query("SELECT id_cons from ".$prefix."_ele_cons_comune where id_cons_gen='$id_cons_gen' and id_comune='$idcomunenew'", $dbi);
		list($id_cons_comu)=mysql_fetch_row($rescomu);
			$res = mysql_query("SELECT id_cons FROM ".$prefix."_ele_comuni where id_comune='$idcomunenew' ", $dbi);
        		list($id_cons_pred)=mysql_fetch_row($res);
			if (!$id_cons_pred) 
				$res = mysql_query("update ".$prefix."_ele_comuni set id_cons='$id_cons_comu' where id_comune='$idcomunenew' ", $dbi);

		}
		if ($do == "update") {
			if ($idcomunenew>0) $newid=", id_comune = $idcomunenew ";
			else $newid='';
			$result = mysql_query("update ".$prefix."_ele_comu_collegi set id_collegio= '$id_collegio' $newid where id_comune='$id_comune' and id_cons_gen='$id_cons_gen'", $dbi) || die(mysql_error());
			if (!$result) return;
			$result = mysql_query("update ".$prefix."_ele_cons_comune set id_conf='$id_conf', chiusa= '$chiusa', preferenze='$preferenze',id_fascia='$idfascia',vismf='$vismf',solo_gruppo='$sg',disgiunto='$disgiunto' where id_comune='$id_comune' and id_cons_gen='$id_cons_gen'", $dbi)|| die(mysql_error());
			Header("Location: admin.php?op=associazioni&id_cons_gen=$id_cons_gen");
		}elseif ($do == "add") {
			if ($id_collegio){
				$result = mysql_query("insert into ".$prefix."_ele_comu_collegi (id_collegio,id_cons,id_comune,id_cons_gen) values ('$id_collegio','$id_cons_comu','$idcomunenew','$id_cons_gen')", $dbi) || die("<br><br>Errore di inserimento: ".mysql_error());
				}
			Header("Location: admin.php?op=associazioni&id_cons_gen=$id_cons_gen");
		}elseif ($do == "delete" and $delcons>0) {
			$idcns=$delcons; 
			$res_del = mysql_query("delete from ".$prefix."_ele_voti_ref where id_cons=$idcns" ,$dbi);
			$res_del = mysql_query("delete from ".$prefix."_ele_voti_candidati where id_cons=$idcns" ,$dbi);
			$res_del = mysql_query("delete from ".$prefix."_ele_voti_lista where id_cons=$idcns" ,$dbi);
			$res_del = mysql_query("delete from ".$prefix."_ele_voti_gruppo where id_cons=$idcns" ,$dbi);
			$res_del = mysql_query("delete from ".$prefix."_ele_voti_parziale where id_cons=$idcns" ,$dbi);
			$res_del = mysql_query("delete from ".$prefix."_ele_controllosez where id_cons=$idcns" ,$dbi);
			if ($pwd4==1){
			$res_del = mysql_query("delete from ".$prefix."_ele_candidati where id_cons=$idcns" ,$dbi);
			$res_del = mysql_query("delete from ".$prefix."_ele_lista where id_cons=$idcns" ,$dbi);
			$res_del = mysql_query("delete from ".$prefix."_ele_gruppo where id_cons=$idcns" ,$dbi);
			$res_del = mysql_query("delete from ".$prefix."_ele_sezioni where id_cons=$idcns" ,$dbi);
			$res_del = mysql_query("delete from ".$prefix."_ele_cons_comune where id_cons=$idcns" ,$dbi);
			$res = mysql_query("SELECT id_cons FROM ".$prefix."_ele_comuni where id_comune='$id_comune' ", $dbi);
        		list($id_cons_pred)=mysql_fetch_row($res);
				if ($idcns==$id_cons_pred) {
				$res = mysql_query("select id_cons from ".$prefix."_ele_cons_comune where id_comune=$id_comune order by id_cons desc limit 0,1" ,$dbi);
        			list($id_cons_pred)=mysql_fetch_row($res); 
				$res = mysql_query("update ".$prefix."_ele_comuni set id_cons='$id_cons_pred' where id_comune='$id_comune' ", $dbi);
				}
			}else{
			$res_del = mysql_query("update ".$prefix."_ele_sezioni set validi='0', nulli='0', bianchi='0', contestati='0', solo_gruppo='0', autorizzati_m='0', autorizzati_f='0', voti_nulli='0', validi_lista='0', contestati_lista='0', voti_nulli_lista='0' where id_cons=$idcns" ,$dbi);
			
			}
			Header("Location: admin.php?op=associazioni&id_cons_gen=$id_cons_gen");
		}
	} 
}




	
//****************************
// switch
//****************************
	if ($op=="associazioni"){
    		associazioni($ok, $do,$descr_comu,$id_cons_comu,$id_collegio,$idcomune,$chiusa,$id_conf,$preferenze);
	}
	ele();
	if (isset($_GET['id_cons_gen'])) $id_cons_gen=intval($_GET['id_cons_gen']); else $id_cons_gen='0';
	all();
	include("footer.php");

?>


