From 443c0225aebb8561d6ed89e47fb0ad10efa1ff0b Mon Sep 17 00:00:00 2001 From: pierre renaudot Date: Thu, 19 Oct 2023 11:53:17 +0200 Subject: [PATCH] ajout pompier --- controleurs/c_pompiers.php | 20 ++++++++++++++----- include/class.pdo.php | 41 +++++++++++++++++++++++++++++++++----- include/proceduresJava.js | 30 ++++++++++++++++++++++++---- vues/v_entete.php | 1 + vues/v_unPompier.php | 24 ++++++++++++---------- 5 files changed, 91 insertions(+), 25 deletions(-) diff --git a/controleurs/c_pompiers.php b/controleurs/c_pompiers.php index 74ea240..3f30d73 100644 --- a/controleurs/c_pompiers.php +++ b/controleurs/c_pompiers.php @@ -65,14 +65,14 @@ switch ($action) { break; case 'validerAjouter': case 'validerModifier': { - var_dump($_REQUEST); + //var_dump($_REQUEST); if (!isset($pdo)) { require_once ("../include/class.pdo.php"); $pdo = PdoBD::getPdoBD(); } - $pId = $_REQUEST['pId']; + $pId = isset($_REQUEST['pId']) ? $_REQUEST['pId'] : $pdo->getLastId($_REQUEST['zCis']); $nom = addslashes($_REQUEST['ztNom']); $prenom = addslashes($_REQUEST['ztPrenom']); $type = $_REQUEST['lstType']; @@ -80,7 +80,8 @@ switch ($action) { $statut = $_REQUEST['lstStatut']; $cis = $_REQUEST['zCis']; $mail = $_REQUEST['ztMail']; - $login = strtolower($_REQUEST['ztPrenom'][0]) . strtoupper($_REQUEST['ztNom']); + // $login = strtolower($_REQUEST['ztPrenom'][0]) . strtoupper($_REQUEST['ztNom']); + $login = $_REQUEST['ztLogin']; $mdp = md5($login); //$mdp = md5($_REQUEST['ztMdp']); // if ($_REQUEST['brMdp'] == 0 and $action === "validerModifier") { @@ -104,10 +105,19 @@ switch ($action) { } $commentaire = addslashes($_REQUEST['ztObservation']); - if ($action === "validerAjouter") { - $pdo->ajoutPompier($cis, $pId, $nom, $prenom, $statut, $mail, $login, $mdp, $grade, $type, $adresse, $cp, $ville, $tel, $commentaire); + if ( + $action === "validerAjouter" + && $pdo->verifDataAjoutPompier($nom, $prenom, $tel, $mail, $login) === true + ) { + //$pdo->ajoutPompier($cis, $pId, $nom, $prenom, $statut, $mail, $login, $mdp, $grade, $type, $adresse, $cp, $ville, $tel, $commentaire); + echo(json_encode(array("success"=> "Ajout effectuée"))); + } elseif ($action === "validerModifier") { $pdo->majPompier($cis, $pId, $nom, $prenom, $statut, $mail, $login, $mdp, $grade, $type, $adresse, $cp, $ville, $tel, $commentaire); + echo(json_encode(array("success"=> "Modification effectuée"))); + + } else { + echo(json_encode(array("error"=> "Merci de remplir tous les champs"))); } //header('location: index.php?choixTraitement=pompiers&action=voir&lstPompiers=' . $valeur); break; diff --git a/include/class.pdo.php b/include/class.pdo.php index d7ad829..539389c 100644 --- a/include/class.pdo.php +++ b/include/class.pdo.php @@ -195,8 +195,6 @@ class PdoBD pCommentaire ='$commentaire', pDateModif ='$dateUpdate' WHERE pCis='$cis' AND pId = '$pId' ;"; - var_dump($req); - die; $rs = PdoBD::$monPdo->exec($req); if ($rs === false) { afficherErreurSQL("Probleme lors de la mise à jour du pompier dans la base de données.", $req, PdoBD::$monPdo->errorInfo()); @@ -220,12 +218,19 @@ class PdoBD /** * ajoute une ligne dans la table pompier */ - public function ajoutPompier($cis, $valeur, $nom, $prenom, $statut, $mail, $login, $mdp, $grade, $type, $adresse, $cp, $ville, $tel, $commentaire) + public function ajoutPompier($cis, $id, $nom, $prenom, $statut, $mail, $login, $mdp, $grade, $type, $adresse, $cp, $ville, $tel, $commentaire) { $req = "INSERT INTO pompier - (pCis,pId,pNom,pPrenom,pStatut,pMail,pLogin,pMdp,pGrade,pType, pAdresse,pCp,pVille,pBip,pCommentaire,pDateEnreg,pDateModif) + (pCis,pId,pNom,pPrenom,pStatut,pMail,pLogin,pMdp,pGrade,pType, pAdresse,pCp,pVille,pBip,pCommentaire, pNbGardes, pDateEnreg, pDateModif) VALUES - ( + (" . $cis . ", " . $id . ", + '" . $nom . "', '" . $prenom . "', + " . $statut . ", '" . $mail . "', + '" . $login . "', '" . $mdp . "', + " . $grade . ", " . $type . ", + '" . $adresse . "', " . $cp . ", + '" . $ville . "', '" . $tel . "', + '" . $commentaire . "',0 ,CURRENT_DATE, CURRENT_DATE );"; $rs = PdoBD::$monPdo->exec($req); if ($rs === false) { @@ -540,6 +545,32 @@ class PdoBD return $lesLignes; } + public function getLastId($pCis) : int + { + $req = "SELECT MAX(pId) + 1 as id FROM pompier WHERE pCis =" . $pCis . ";"; + $rs = PdoBD::$monPdo->query($req); + if ($rs === false) { + afficherErreurSQL("Erreur de lma requete pour l'id ajouter", $req, PdoBD::$monPdo->errorInfo()); + } + $id = $rs->fetch(); + return $id["id"]; + } + + public function verifDataAjoutPompier( + string $nom, + string $prenom, + string $tel, + string $mail, + string $login + ) : bool { + + if (empty($nom) || empty($prenom) || empty($tel) || empty($mail) || empty($login)) { + return false; + } else { + return true; + } + } + } ?> \ No newline at end of file diff --git a/include/proceduresJava.js b/include/proceduresJava.js index c048f04..0b3bbfa 100644 --- a/include/proceduresJava.js +++ b/include/proceduresJava.js @@ -397,12 +397,13 @@ $(document).on('click', '.btn-valid-modif', function (e) { /** * Ajout d'un pompier */ -$(document).on('click', '.validerAjout', function (e) { +$(document).on('submit', '.dataPompierAjout', function (e) { e.preventDefault(); - - console.log('toto'); + $('#inputDisabled').attr('disabled', false); data = $('.dataPompierAjout').serialize() + $('#inputDisabled').attr('disabled', true); + $.ajax({ url: "/controleurs/c_pompiers.php?action=validerAjouter", method: "POST", // Méthode HTTP (GET, POST, etc.) @@ -411,6 +412,27 @@ $(document).on('click', '.validerAjout', function (e) { error: function(xhr, status, error) { // Gérer les erreurs de la requête AJAX console.error("Erreur lors de la requête AJAX :", status, error); - } + }, + success: function(result) { + $('.dataPompierAjout').trigger("reset"); ; + $('.notif-ajout').html(result['success']) + } }); }); +$(document).on('click', '.btAnnulerAjout', function (e) { + e.preventDefault(); + + window.location.href = "http://sdis29-1/index.php?choixTraitement=pompiers&action=voir&type=a"; +}) +$(document).ready(function(){ + $('#newName, #newUsername').change(function() { + newUserName = $('#newUsername').val()[0].toLowerCase(); + if (newUserName == undefined) { + newUserName = ''; + } + newName = $('#newName').val().toUpperCase(); + + $('#newLogin').val(newUserName+newName) + }); +}); + diff --git a/vues/v_entete.php b/vues/v_entete.php index 12547ba..5156e4e 100644 --- a/vues/v_entete.php +++ b/vues/v_entete.php @@ -4,6 +4,7 @@ SDIS29 + diff --git a/vues/v_unPompier.php b/vues/v_unPompier.php index aabaa0b..36282a8 100644 --- a/vues/v_unPompier.php +++ b/vues/v_unPompier.php @@ -64,18 +64,18 @@ "); } if ($_REQUEST['action'] == "ajouter") { + // echo (" - Nom - Prénom - Adresse - Code postal + Nom* + Prénom* + Adresse + Code postal Ville - Téléphone - Adresse électronique - Nom de compte - - Code + Téléphone* + Adresse électronique* + Nom de compte* + Code Nom " . $lesInfosPompier['cNom'] . " Adresse " . $lesInfosPompier['cAdresse'] . " Téléphone " . $lesInfosPompier['cTel'] . " @@ -121,8 +121,9 @@
- +

+
@@ -135,7 +136,8 @@ "> + value=""> +