|
voci le code ... un peu long mais ...
<?php Session_start(); $login=$_SESSION['MyLogin']; if ($login == ''){ header("Location:../../index.php"); }
$mbureau=$_SESSION['mbureau']; $admin=$_SESSION['madmin'];
include('../../Include/BDconnect.php'); include('../../Include/tools.php'); include('MajArrDep_inc.php');
$error = false; $id = ''; // ID du record à traiter (suppression ou édition) $mode; // mode de la page : recherche, édition, création
// variables pour mémoriser les champs de saisie (p_ : variables POSTée) $p_id = ''; $p_mouvDate = ''; $p_mouvSens = ''; $p_mouvHameau = ''; $p_mouvVilla = ''; $p_mouvNom = '';
$error = false ;
//******** $array_typhabitant=$_POST['typhabitant'];
if (isset($_POST["mode"])) $mode = $_POST["mode"]; elseif (isset($_GET["mode"])) $mode = $_GET["mode"]; else { // mode initial par défaut $mode = 'init'; }
if (isset($_GET["id"])) $id = $_GET["id"];
/* Gestion de la type de liste if ($mode=='init') { $chxliste ='Actu'; $array_typhabitant[0] ='Actu'; $_SESSION['typhabitant']= 'Actu'; } else { $_SESSION['typhabitant'] = $array_typhabitant[0]; } */ if ($mode != 'save' && $mode != 'insert' && $mode != 'retour') { if (isset($_POST['ID'])) $_SESSION["ID"] = $_POST['ID']; if (isset($_POST['mouvDate'])) $_SESSION["mouvDate"] = $_POST['mouvDate']; if (isset($_POST['mouvSens'])) $_SESSION["mouvSens"] = $_POST['mouvSens']; if (isset($_POST['mouvHameau'])) $_SESSION["mouvHameau"] = $_POST['mouvHameau']; if (isset($_POST['mouvVilla'])) $_SESSION["mouvVilla"] = $_POST['mouvVilla']; if (isset($_POST['mouvNom'])) $_SESSION["mouvNom"] = $_POST['mouvNom']; if (isset($_POST['notaire'])) $_SESSION["notaire"] = $_POST['notaire']; if (isset($_SESSION["ID"])) $p_id = $_SESSION["ID"]; if (isset($_SESSION["mouvDate"])) $p_mouvDate = $_SESSION["mouvDate"]; if (isset($_SESSION["mouvSens"])) $p_mouvSens = $_SESSION["mouvSens"]; if (isset($_SESSION["mouvHameau"])) $p_mouvHameau = $_SESSION["mouvHameau"]; if (isset($_SESSION["mouvVilla"])) $p_mouvVilla = $_SESSION["mouvVilla"]; if (isset($_SESSION["mouvNom"])) $p_mouvNom = $_SESSION["mouvNom"]; if (isset($_SESSION["notaire"])) $p_notaire = $_SESSION["notaire"]; }
//000000000000000000000000000000000000000000000000000000000000000000 //CE QUE je fais pour pallier au problème mais cela ne me semble pas normal
if ($mode == 'retour') { // effacer les variables locales (obligatoire pour Axinet) unset($mouvDate); unset($mouvSens); unset($mouvHameau ); unset($mouvVilla); unset($mouvNom ); unset($notaire ); $mode = "search"; } //000000000000000000000000000000000000000000000000000000000000000000
/* *********************************************** Suppression : $mode=="delete" *************************************************/
if ($mode=="delete") { $stmt = mysqli_prepare($link, "DELETE FROM t_mouvements WHERE id = ".$id); if (!$stmt) die('Requête DELETE invalide : '.mysqli_error($link));
mysqli_stmt_execute($stmt); $mode = "search"; }
/* ************************************************* // Enregistrement : $mode=="save" ****************************************************/ if ($mode=="save") { if ($_POST['ID']!='') { //UPDATE tests si modification : $update = false; if ($_SESSION['record'][1] !=$_POST['mouvDate']) {$update=true; $_SESSION['record'][1] =$_POST['mouvDate'] ;} if ($_SESSION['record'][2] !=$_POST['mouvSens']) {$update=true; $_SESSION['record'][2] =$_POST['mouvSens'] ;} if ($_SESSION['record'][3] !=$_POST['mouvHameau']) {$update=true; $_SESSION['record'][3] =$_POST['mouvHameau'] ;} if ($_SESSION['record'][4] !=$_POST['mouvVilla']) {$update=true; $_SESSION['record'][4] =$_POST['mouvVilla'] ;} if ($_SESSION['record'][5] !=$_POST['mouvNom']) {$update=true; $_SESSION['record'][5] =$_POST['mouvNom'] ;} if ($_SESSION['record'][6] !=$_POST['notaire']) {$update=true; $_SESSION['record'][6] =$_POST['notaire'] ;} if ($update == true) { $sql="UPDATE t_mouvements SET mouvDate=?,mouvSens=?,mouvHameau=?,mouvVilla=?,mouvNom=?,notaire=? WHERE id=".$id; $stmt = mysqli_prepare($link,$sql); if (!$stmt) die('Requête UPDATE t_mouvements invalide : '.mysqli_error($link)); mysqli_stmt_bind_param($stmt, 'ssssss', $mouvDate,$mouvSens,$mouvHameau,$mouvVilla,$mouvNom,$notaire); $mouvDate = stringToDate($_POST['mouvDate']); $mouvSens = $_POST['mouvSens']; $mouvHameau = $_POST['mouvHameau']; $mouvVilla = $_POST['mouvVilla']; $mouvNom = $_POST['mouvNom']; $notaire = $_POST['notaire']; if ($mouvDate==-1) { $error = true; ligneErreur('$update=true La date doit être au format \'jj.mm.(aa)aa\' ou \'jjmm(aa)aa\'.'); } //On vérifie également qu'on ne supprime pas de données if ($mouvSens == '') {$error = true; ligneErreur('Le sens est obligatoire.');} if ($error) reloadSession(); if (!$error) { mysqli_stmt_execute($stmt); mysqli_stmt_close($stmt); // On recharge le résultat : $mode='update'; } } else { // Pas de changement, on affiche les valeurs en session reloadSession(); } } else { /*************************************************** //INSERT : ****************************************************/ // Vérifications $valide = true; $p_mouvDate = stringToDate($_POST['mouvDate']); $p_mouvSens = $_POST['mouvSens']; $p_mouvHameau = $_POST['mouvHameau']; $p_mouvVilla = $_POST['mouvVilla']; $p_mouvNom = $_POST['mouvNom']; $p_notaire = $_POST['notaire']; if ($p_mouvSens == '') {$valide = false; ligneErreur('Le sens est obligatoire.');} if ($p_mouvDate==-1) { $valide = false; ligneErreur('$valide=true La date doit être au format \'jj.mm.(aa)aa\' ou \'jjmm(aa)aa\'.'); } // Enregistrement if ($valide==true) { $stmt = mysqli_prepare($link, "INSERT INTO t_mouvements (mouvDate,mouvSens,mouvHameau,mouvVilla,mouvNom,notaire) VALUES (?,?,?,?,?,?)"); if (!$stmt) die('Requête INSERT INTO invalide : '.mysqli_error($link)); mysqli_stmt_bind_param($stmt, 'ssssss', $p_mouvDate,$p_mouvSens,$p_mouvHameau,$p_mouvVilla,$p_mouvNom,$p_notaire); mysqli_stmt_execute($stmt); mysqli_stmt_close($stmt); // Il faut avoir l'ID : $id = mysqli_insert_id($link); // On recharge le résultat : header('location:MajArrDep.php?mode=update&id='.$id); } } }
/*************************************************** Edition (chargement de l'enregistrement à modifier) ****************************************************/ if ($mode=="update") { $sql="SELECT ID, mouvDate, mouvSens, mouvHameau, mouvVilla, mouvNom, notaire FROM t_mouvements WHERE id=".$id; $stmt = mysqli_prepare($link, $sql); if (!$stmt) die('Requête SELECT ID invalide : '.mysqli_error($link)); mysqli_stmt_execute($stmt); mysqli_stmt_bind_result($stmt,$p_id,$p_mouvDate,$p_mouvSens,$p_mouvHameau,$p_mouvVilla,$p_mouvNom,$p_notaire); // compter les résultats mysqli_stmt_store_result($stmt); $row=mysqli_stmt_num_rows($stmt); // fetch if (mysqli_stmt_num_rows($stmt) == 1) { mysqli_stmt_fetch($stmt); // Formattage des dates $p_mouvDate = ISOdateToString($p_mouvDate); // il faut stocker l'enregistrement en session (pour vérifier s'il y a eu modification ou non) : $record = array($p_id,$p_mouvDate,$p_mouvSens,$p_mouvHameau,$p_mouvVilla,$p_mouvNom,$p_notaire); $_SESSION['record'] = $record; } else { $mode = "search"; ligneErreur('ERREUR lors du chargement de l\'élément'); } }
//--------------------------------------------------------------------------
?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>Maj Habitants</title> <meta http-equiv=Content-Type content="text/html; charset=windows-1252"> <link rel='stylesheet' type='text/css' href='../../Style/Aful.css'/> <link rel='stylesheet' type='text/css' href='../../Style/Qmenu.css'/> <script type="text/javascript">QBPATH='../../javascript'; VISUAL=0; SECURE=1;</script> <script type='text/javascript' src='../../Javascript/Qmenu.js'></script> <SCRIPT type="text/javascript" SRC="../../Javascript/CCNcalendrier.js"></SCRIPT> <script language="JavaScript"> function cancelEdit() { location.replace("MajArrDep.php?mode=retour"); } function newClient() { location.replace("MajArrDep.php?mode=insert"); } </script> </head> <body leftMargin="0" topMargin="0" marginwidth="0" marginheight="0" text="#000000"> <?php if ($mbureau == "Oui"):?> <table Align="center" cellSpacing="0" cellPadding="0" width="980" height="500" border="0"> <TR> <TD Valign="Top"> <!--------------- BANNIERER SITE ---------------> <table cellSpacing="0" cellPadding="0" width="100%" height="91" border="0"> <tr> <td width="20" background="../../images/head_fond_G.gif"> </td> <td width="135" Valign="middle" background="../../images/head_fond.gif"> <center><img border="0" src="../../images/ImgBanniere.jpg" width="125" height="80"> </td> <td Class='Banniere' background="../../images/head_fond.gif"> AFUL . LES HAMEAUX DE LA RAPE </td> <td width="135" Valign="middle" background="../../images/head_fond.gif"> <center><img border="0" src="../../images/ImgBanniere.jpg" width="125" height="80"> </td> <td width="20" background="../../images/head_fond_D.gif"> </td> </tr> </table> <!--------------- MENUS ---------------> <table cellSpacing="0" cellPadding="0" width="100%" border="0" height="39" valign="top" background="../../images/Qmenu.jpg"> <tr><td align="left"> <ul id="qm0" class="qmmc"> <li><a href="../../Include/KillSession.php?param1=<? echo $login ?>"><img border="0" src="../../images/logout.gif" alt="Déconnection"></a> <a class="qmparent" href=""></a></li> <li><span class="qmdivider qmdividery" ></span></li> <li><a class="qmparent" href="../../indexaful.php">ACCUEIL</a> <ul> <li><span class="qmtitle" ></span></li> </ul> <li><span class="qmdivider qmdividery" ></span></li> <li class="qmclear"> </li></ul> <!-- Create Menu Settings: (Menu ID, Is Vertical, Show Timer, Hide Timer, On Click (options: 'all' * 'all-always-open' * 'main' * 'lev2'), Right to Left, Horizontal Subs, Flush Left, Flush Top) --> <script type="text/javascript">qm_create(0,false,0,500,false,false,false,false,false);</script> </td> <td class="SousBanniere" align="right"> <?php if ($mode=='init' || $mode=='search') echo '<span style="color:#009E00;">Recherche Mouvements</span>'; elseif ($mode=='insert') echo '<span style="color:#ff6600;">Création Mouvements</span>'; else echo '<span style="color:#ff0000;">Modification Mouvements</span>'; ?> </td> <td width="20"> </td> </tr> </table> <br /> <fieldset><form method="post"> <table style="text-align:center; width: 900; font-family: Helvetica,Arial,sans-serif;" border="0" align="center" cellpadding="0" cellspacing="0"> <tbody> <tr> <!-- ***************************** LIGNE 1 ******* Libelle ************************** --> <td style="width:30px;">Id</td> <td style="width:125px;">Date Mouvement <br />(<Font size="1">Format jj.mm.aaaa</font>)</td> <td style="width:110px;">Sens du Mouvement</td> <td style="width:60px;" valign="bottom">N° Villa</td> <td style="width:60px;" valign="bottom" >Hameau</td> <td style="width:10px;" valign="bottom" > </td> <td style="width:200px;text-align:left;" valign="bottom">Nom des habitants</td> <td style="width:10px;" valign="bottom" > </td> <td style="width:170px;text-align:left;" valign="bottom">Notaire</td>
</tr> <!-- ***************************** LIGNE 2 ******* Champs ************************** --> <tr> <!-- ID --> <td style="width: 30px;"><center> <?php if($mode=='save' || $mode=='update' || $mode=='insert'):?> <input readonly name="ID" size="4" value="<?=$p_id?>"> <?php else:?> <input name="ID" size="4" value="<?=$p_id?>"> <?php endif;?> </center> </td> <!-- date Mouvement --> <td style="width:115px;"><input name="mouvDate" size="13" value="<?=$p_mouvDate?>"></td> <!-- sens du mouvement --> <td > <select name="mouvSens"> <option></option> <option <?= testSens('Arrivée')?>>Arrivée</option> <option <?= testSens('Départ')?>>Départ</option> </select> <!--<input name="mouvSens" value="<?=$p_mouvSens?>">--> </td> <!-- villa --> <td style="width: 60px;"><input name="mouvVilla" size="3" value="<?=$p_mouvVilla?>"></td> <!-- hameau --> <td style="width: 60px;"> <select name="mouvHameau"> <option></option> <option <?= testHameau('A')?>>A</option> <option <?= testHameau('B')?>>B</option> <option <?= testHameau('C')?>>C</option> <option <?= testHameau('D')?>>D</option> <option <?= testHameau('E')?>>E</option> <option <?= testHameau('F')?>>F</option> <option <?= testHameau('G')?>>G</option> <option <?= testHameau('H')?>>H</option> </select> <!--<input name="mouvHameau" value="<?=$p_mouvHameau?>">--> </td> <!-- Nom --> <td> </td> <td style="width: 180px;"><input name="mouvNom" size="50" value="<?=$p_mouvNom?>"></td> <!-- Notaire --> <td> </td> <td style="width: 120px;"><input name="notaire" size="50" value="<?=$p_notaire?>"></td> </tr> <!-- bouton submit --> <tr> <td colspan="9" height="40" align="center"> <?php if ($mode=='search' || $mode=='init'): ?> <input name="mode" value="search" type="hidden"> <input value="Chercher" type="submit" style="width:80px"> <input value="Nouveau" onclick="newClient();" type="button" style="width:80px"> <?php else:?> <input name="mode" value="save" type="hidden" > <input value="Enregistrer" type="submit" style="width:80px"> <input value="Retour" onclick="cancelEdit();" type="button" style="width:80px"> <?php endif;?> </td> </tr> <!---------------> </tbody> </table> </fieldset> </form> <!-- Affichage résultat recherche du client sélectionné --> <fieldset style="font-family: Helvetica,Arial,sans-serif;"> <?php if ($mode=='search') { $page = 1; if (isset($_GET['page'])) $page = $_GET['page']; searchMajArrDep($page); } ?> </fieldset> <?php endif; ?> </body></html>
MERCI de votre aide |