<?php
session_start();
$user = $_SESSION['utente'];
if ($user) {
$ntessera = $_POST['ntessera'];
$nnome = $_POST['nome'];
$ncognome = $_POST['cognome'];
$nindirizzo = $_POST['indirizzo'];
$cap = $_POST['comuni'];
$ncitta = $_POST['regioni'];
$nprovincia = $_POST['provincie'];
$ntel = $_POST['tel'];
$ntel2 = $_POST['tel2'];
$ndatangg = $_POST['datangg'];
$ndatanmm = $_POST['datanmm'];
$ndatanaaaa = $_POST['datanaaaa'];
$materia = $_POST['materia'];
$nnomerif = $_POST['nomerif']; //Codice fiscale
$email = $_POST['email'];
$nnote = $_POST['note'];
$ndatan = ($ndatangg."-".$ndatanmm."-".$ndatanaaaa);
//escape html
$nome = htmlspecialchars($nnome, ENT_NOQUOTES, "UTF-8");
$tessera = htmlspecialchars($ntessera, ENT_NOQUOTES, "UTF-8");
$cognome = htmlspecialchars($ncognome, ENT_NOQUOTES, "UTF-8");
$indirizzo = htmlspecialchars($nindirizzo, ENT_NOQUOTES, "UTF-8");
$citta = htmlspecialchars($ncitta, ENT_NOQUOTES, "UTF-8");
$provincia = htmlspecialchars($nprovincia, ENT_NOQUOTES, "UTF-8");
$tel = htmlspecialchars($ntel, ENT_NOQUOTES, "UTF-8");
$tel2 = htmlspecialchars($ntel2, ENT_NOQUOTES, "UTF-8");
$datan = htmlspecialchars($ndatan, ENT_NOQUOTES, "UTF-8");
$nomerif = htmlspecialchars($nnomerif, ENT_NOQUOTES, "UTF-8");
$note = htmlspecialchars($nnote, ENT_NOQUOTES, "UTF-8");
//Se L'associato è attivo
$checkbox = isset($_POST["check"]);
if ($checkbox) {
$associato = "si";
} else { $associato = "no";}
//Funzione per il redirect
function redirect($url,$tempo = FALSE ){
if(!headers_sent() && $tempo == FALSE ){
header('Location:' . $url);
}elseif(!headers_sent() && $tempo != FALSE ){
header('Refresh:' . $tempo . ';' . $url);
}else{
if($tempo == FALSE ){
$tempo = 0;
}
echo "<meta http-equiv=\"refresh\" content=\"" . $tempo . ";" . $url . "\">";
}
}
//Controllo campi compilati
if ($nome == "")
{
echo "<center><b>Il campo nome è obbligatorio</b></center>";
redirect('./InsAnagrIns.php' ,2);
// break;
die ("");
}
if ($materia == "")
{
echo "<center><b>Il campo Tipo associato è obbligatorio</b></center>";
redirect('./InsAnagrIns.php' ,2);
// break;
die ("");
}
// *** GESTIONE DELL'IMMAGINE ***
$upload_dir = "./Immagini/Utenti";
if(@is_uploaded_file($_FILES["immagine"]["tmp_name"])) {
$file_name = $_FILES["immagine"]["name"];
@move_uploaded_file($_FILES["immagine"]["tmp_name"], "$upload_dir/$file_name")
or die("Impossibile spostare il file, controlla l'esistenza o i permessi della directory dove fare l'upload.");
} else {
$file_name = "personal.gif";
@move_uploaded_file($_FILES["immagine"]["tmp_name"], "$upload_dir/$file_name");
}
// *** FINE MODULO GESTIONE IMMAGINE ***
include ('./dati_db.inc');
$connect = mysqli_connect("$host", "$username", "$password", "$db_name", $port ) or die("cannot connect DB");
$tb_anagrafe = ('tb_anagrafe(ntessera, nome, cognome, indirizzo, cap, citta, provincia, tel, tel2, datan, classe, nomerif, materia, mansione, email, tipologia, note, immagine, associato)');
if ($nome){
$sql="insert into $tb_anagrafe values('$tessera','$nome', '$cognome', '$indirizzo', '$cap', '$citta', '$provincia', '$tel', '$tel2', '$datan', '', '$nomerif', '$materia', '', '$email', 'Ins', '$note', '$file_name', '$associato')"; //inserisco i valori nel database
$result=mysqli_query($connect, $sql);
header('location: ./conferma.php?rif=InsAnagrStud'); //Vado alla pagina di conferma
}else{
header('location: ./errore.php?rif=InsAnagrStud'); //Vado alla pagina di errore
}
mysqli_close($connect);
} else {
header("Location: ./index.php");
} ?>