a parte che io pulirei un po' il codice...
comunque non recuperi i POST delle aree
Codice PHP:
<?php
$cognome = ucwords(strtolower($_POST['cognome']));
$nome = ucwords(strtolower($_POST['nome']));
$username = ucwords(strtolower($_POST['username']));
$password = $_POST['password'];
//controllo se l'utente è già stato inserito
$sql = mysql_query("select * from utenti where username = '$username'");
//prelevo dal database tutti gli utenti che hanno il codice inserito nella form
$row = mysql_fetch_array($sql);
$cerca = mysql_num_rows($sql);
if($cerca > 0) { //se l'utente è presente
?>
[img]img/attenzione.png[/img]
<?php print" [b]ATTENZIONE[/b]"."
"."la login"."
"." [b] $utente [/b]" ."
". "è già stata assegnata all'utente". "
". "[b]$row[cognome]" . " $row[nome][/b] " ?>
<form name="form1" method="post" action="utenti_ins.php">
<input type="hidden" name="cognome" value="<?php print "$cognome"; ?>">
<input type="hidden" name="nome" value="<?php print "$nome"; ?>">
<input type="hidden" name="username" value="<?php print "$username"; ?>">
<input type="hidden" name="password" value="<?php print "$password"; ?>">
<input type="submit" name="Submit" value="Torna Indietro">
</form>
<?php
exit;
}
//fine controllo
if ($_POST['tipo'] == "admin") {
$query = mysql_query("INSERT INTO utenti (cognome,nome,username,password,tipo) VALUES ('$cognome','$nome','$username','$password','$tipo')");
//header("Location: utenti_lista.php");
exit;
} else {
include("top_foot.inc.php");
if (checkpermessi("inserimento","utenti",$_SESSION['login_staff_utente'])) { ?>
<form action="utenti_ins3.php" method="post" name="form">
Inserimento Nuovo Utente 2/2 User:
<input name="username" type="hidden" id="username" value="<?php print "$username"; ?>">
<?php print stripslashes("$username"); ?>[/b]</td>
Cognome:
<input name="cognome" type="hidden" id="cognome" value="<?php print "$cognome"; ?>">
<?php print "$cognome"; ?> Nome:
<input name="nome" type="hidden" id="nome" value="<?php print "$nome"; ?>">
<?php print "$nome"; ?> Tipo
<input name="tipo" type="hidden" id="tipo" value="<?php print $_POST['tipo']; ?>">// attento che l'utente non modifichi questo valore!!
<?php print $_POST['tipo']; ?>
<input name="password" type="hidden" id="password" value="<?php print "$password"; ?>">
<?php if ($_POST['tipo'] != "admin") { ?>
Inserimento Permessi Utente
<?php $aree = array("news","articoli","convegni","incontri_ed_eventi"); ?>
Aree di gestione[/B]
<?php foreach ($aree as $area) { ?>
<td width="150" align="left" bgcolor="D3D8E2">[b]<?php print strtr(ucfirst($area),"_"," "); ?>[/b]</td>
<td width="70" align="center" bgcolor="D3D8E2"><?php print "<input name=".$area."_inserisci " . " type=checkbox id=".$area."_inserisci " . "value='ok'>"; ?></td>
<td width="70" align="center" bgcolor="D3D8E2"><?php print "<input name=".$area."_modifica " . " type=checkbox id=".$area."_modifica " . "value=ok>"; ?></td>
<td width="70" align="center" bgcolor="D3D8E2"><?php print "<input name=".$area."_elimina " . " type=checkbox id=".$area."_elimina " . "value=ok>"; ?></td>
<td width="70" align="center" bgcolor="D3D8E2"><?php print "<input name=".$area."_allega " . " type=checkbox id=".$area."_allega " . "value=ok>"; ?></td>
<td width="70" align="center" bgcolor="D3D8E2"><?php print "<input name=".$area."_eliminaall " . " type=checkbox id=".$area."_eliminaall " . "value=ok>"; ?></td>
<td width="70" align="center" bgcolor="D3D8E2"><?php print "<input name=".$area."_visualizza " . " type=checkbox checked=checked id=".$area."_visualizza " . "value=ok>"; ?>
<?php } ?>
<?php } ?>
<input name="submit" type=submit value="continua">
</form>
<?php } else {
header("Location: index.php");
exit;
}
/* footer */
foot();
}
}
?>
Codice PHP:
<?php
$cognome = $_POST['cognome'];
$nome = $_POST['nome'];
$username = $_POST['username'];
$password = $_POST['password'];
////
$query = mysql_query("INSERT INTO utenti (cognome,nome,username,password,tipo) VALUES ('$cognome','$nome','$username','$password','$tipo')");
////
$query = mysql_query("SELECT idutente FROM utenti WHERE username = '".$username."'");
$row = mysql_fetch_array($query);
$id = $row['idutente'];
// inserisci permessi
$aree = $aree = array("news","articoli","convegni","incontri_ed_eventi");
foreach ($aree as $area) {
$ck_ins = "$area"."_inserisci";
$ck_mod = "$area"."_modifica";
$ck_can = "$area"."_elimina";
$ck_all = "$area"."_allega";
$ck_eliall = "$area"."_eliminaall";
$ck_vis = "$area"."_visualizza";
if ($_POST[$ck_all] == "ok") { mysql_query("INSERT INTO permessi (idutente,sezione,azione) VALUES (".$id.",'".$area."','ins_allegati')"); }
if ($_POST[$ck_eliall] == "ok") { mysql_query("INSERT INTO permessi (idutente,sezione,azione) VALUES (".$id.",'".$area."','canc_allegati')"); }
if ($_POST[$ck_ins] == "ok") {mysql_query("INSERT INTO permessi (idutente,sezione,azione) VALUES (". $id . ",'".$area."','inserimento')");}
if ($_POST[$ck_mod] == "ok") { mysql_query("INSERT INTO permessi (idutente,sezione,azione) VALUES (".$id.",'".$area."','modifica')"); }
if ($_POST[$ck_can] == "ok") { mysql_query("INSERT INTO permessi (idutente,sezione,azione) VALUES (".$id.",'".$area."','elimina')"); }
if ($_POST[$ck_vis] == "ok") { mysql_query("INSERT INTO permessi (idutente,sezione,azione) VALUES (".$id.",'".$area."','visualizza')"); }
}
header("Location: utenti_lista.php");
exit;
}
?>