Index: trunk/admin/modules/Elezioni/ele_operatori.php
===================================================================
--- trunk/admin/modules/Elezioni/ele_operatori.php	(revision 344)
+++ trunk/admin/modules/Elezioni/ele_operatori.php	(revision 358)
@@ -26,4 +26,5 @@
 if (isset($_GET['passwd'])) $passwd=addslashes($param['passwd']); else $passwd='';
 if (isset($_GET['passwd2'])) $passwd2=addslashes($param['passwd2']); else $passwd2='';
+if (isset($_GET['stato']) && $aid2!='admin') $stato=intval($param['stato']); else $stato=0;
 
 include("modules/Elezioni/funzionidata.php");
@@ -37,4 +38,5 @@
 	global $aid, $offset, $prefix, $dbi,$id_cons,$aid2,$id_sede,$id_cons_gen,$mex,$perms;
         //echo $perms;die();
+
 	$bgcolor1=$_SESSION['bgcolor1'];
 	$id_comune=$_SESSION['id_comune'];
@@ -44,8 +46,8 @@
 	$rescom->execute();	
 	list($descr_com) = $rescom->fetch(PDO::FETCH_NUM);
-	$sql="SELECT aid,name,email FROM ".$prefix."_authors where aid='$aid2' and id_comune='$id_comune'";
+	$sql="SELECT aid,name,email,adminop FROM ".$prefix."_authors where aid='$aid2' and id_comune='$id_comune'";
 	$resmod = $dbi->prepare("$sql");
 	$resmod->execute();	
-	list ($aid2,$name,$email) = $resmod->fetch(PDO::FETCH_NUM);
+	list ($aid2,$name,$email,$attivo) = $resmod->fetch(PDO::FETCH_NUM);
 	if (isset($_GET['mex'])){
 		echo "<table align=\"center\"><tr><td style=\"background-color: rgb(255, 0, 0)\">";
@@ -65,6 +67,6 @@
 	echo "</tr><tr align=\"center\">";
 	echo "<td><input type=\"hidden\" name=\"pag_op\" value=\"admin.php?op=operatori&amp;id_cons_gen=$id_cons_gen&amp;aid2=\">";
-	echo "<select name=\"aid2\" onChange=\"top.location.href=this.form.pag_op.value+this.form.aid2.options[this.form.aid2.selectedIndex].value;return false\">";
-	echo "<option value=\"\">";
+	echo "<select id=\"aid2\" name=\"aid2\" onChange=\"top.location.href=this.form.pag_op.value+this.form.aid2.options[this.form.aid2.selectedIndex].value;return false\">";
+	echo "<option value=\"\">Nuovo Utente";
 	while(list($utente)=$resins->fetch(PDO::FETCH_NUM)){
 		$sel= ($utente == $aid2) ? "selected":"";
@@ -86,4 +88,7 @@
 	echo "<td bgcolor=\"$bgcolor1\"><b>"._NOME."</b></td>"
 	."<td bgcolor=\"$bgcolor1\"><b>"._EMAIL."</b></td>";
+	echo "<td bgcolor=\"$bgcolor1\"><b>"._STATO."</b></td>";
+	
+
 	echo "<td bgcolor=\"$bgcolor1\"><b>"._FUNZIONI."</b></td></tr>";
 	echo "<tr align=\"center\"><td>";
@@ -98,5 +103,7 @@
 	echo "<td  align=\"center\"><input type=password name=\"passwd2\" size=\"12\"></td>";
 	echo "<td><input name=\"name\" value=\"$name\"></td>";
-	echo "<td><input name=\"email\" value=\"$email\">";
+	echo "<td><input name=\"email\" value=\"$email\"></td>";
+	if($attivo==0) {$sel2="selected"; $sel3='';} else {$sel2=''; $sel3="selected";}
+	echo "<td><select name=\"stato\"><option value=\"0\" $sel2>Attivo<option value=\"1\" $sel3>Disattivo<option value=\"2\" >Elimina</select>";
 	echo "<input type=\"hidden\" name=\"id_cons_gen\" value=\"$id_cons_gen\">";
 	echo "<input type=\"hidden\" name=\"ok\" value=0></td>";
@@ -113,7 +120,11 @@
 }
 
-function operatori($do,$aid2,$name,$email,$passwd,$passwd2,$id_comune) {
+function operatori($do,$aid2,$name,$email,$passwd,$passwd2,$id_comune,$stato) {
 	global $aid, $prefix, $dbi, $id_cons,$id_cons_gen,$currentlang;
 	$perms=ChiSei($id_cons_gen);
+	if($passwd!=$passwd2) {
+		$mex="- Le password non coincidono! -<br>";
+		header("location:admin.php?op=operatori&id_cons_gen=$id_cons_gen&aid2=$aid2&name=$name&email=$email&mex=$mex&stato=$stato");
+	}
        
 	if ($perms!=256) $id_comune=$_SESSION['id_comune'];
@@ -124,7 +135,7 @@
 			$res->execute();	
 			$max=$res->rowCount();
-			if ($passwd==$passwd2 and $max==0){
-				if ($aid2=='admin') $super='1,0,0,'; else $super = '0,1,0,';
-				$sql="insert into ".$prefix."_authors (aid,name,id_comune,email,pwd,counter,adminop,admincomune,adminsuper,admlanguage) values ('$aid2','$name','$id_comune' , '$email','".md5($passwd)."',0,$super'$currentlang')";
+			if ($max==0){
+				if ($aid2=='admin') $super='0,1,0,'; else $super = '0,0,0,';
+				$sql="insert into ".$prefix."_authors (aid,name,id_comune,email,pwd,counter,adminop,admincomune,adminsuper,admlanguage) values ('$aid2','$name','$id_comune' , '$email','".md5($passwd)."','0',$super'$currentlang')";
 				$res = $dbi->prepare("$sql");
 				$res->execute();	
@@ -133,17 +144,27 @@
 					$res = $dbi->prepare("$sql");
 					$res->execute();	
-				}
-			Header("Location: admin.php?op=operatori&id_cons_gen=$id_cons_gen");
+			}
+			Header("Location: admin.php?op=operatori&id_cons_gen=$id_cons_gen&aid2=$aid2");
 			}else{
 				$mex='';
-				if($passwd!=$passwd2) $mex="- Le password non coincidono! -<br>";
 				if($max>0) $mex.=" - Utente <b>$aid2</b> presente in archivio! - ";
-				header("location:admin.php?op=operatori&id_cons_gen=$id_cons_gen&aid2=$aid2&name=$name&email=$email&mex=$mex");
 			}
 		} elseif ($do == "update") {
-			$sql="update  ".$prefix."_authors set name='$name',pwd='".md5($passwd)."', email='$email' where id_comune='$id_comune' and aid='$aid2' ";
-			$res = $dbi->prepare("$sql");
-			$res->execute();
+			if($passwd!='') $mexpwd="pwd='".md5($passwd)."',"; else $mexpwd='';
+			if($stato==2){
+				$sql="delete from ".$prefix."_authors where aid='$aid2' and id_comune=$id_comune";
+				$res = $dbi->prepare("$sql");
+				$res->execute();					
+			}else{
+				$sql="update  ".$prefix."_authors set name='$name', $mexpwd email='$email', adminop='$stato' where id_comune='$id_comune' and aid='$aid2' ";
+				$res = $dbi->prepare("$sql");
+				$res->execute();
+			}
 			$result=$res->rowCount();
+			if($stato!=0){
+				$sql="delete from ".$prefix."_ele_operatori where id_comune='$id_comune' and aid='$aid2' ";
+				$res = $dbi->prepare("$sql");
+				$res->execute();
+			}
 			if (!$result) return;
 			if ($aid2==$aid) $_SESSION['pwd']=md5($passwd);
@@ -157,5 +178,5 @@
 // switch
 //****************************
-	if ($do) operatori($do,$aid2,$name,$email,$passwd,$passwd2,$id_comune);
+	if ($do) operatori($do,$aid2,$name,$email,$passwd,$passwd2,$id_comune,$stato);
 	ele();
 	all();
