ajout pompier
This commit is contained in:
parent
aa0701334e
commit
443c0225ae
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
@ -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)
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -4,6 +4,7 @@
|
||||
<head>
|
||||
<title>SDIS29</title>
|
||||
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
|
||||
|
||||
<link href="./styles/styles.css" rel="stylesheet" type="text/css" />
|
||||
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
|
||||
<link rel="shortcut icon" type="image/x-icon" href="./images/favicon.ico" />
|
||||
|
@ -64,18 +64,18 @@
|
||||
");
|
||||
}
|
||||
if ($_REQUEST['action'] == "ajouter") {
|
||||
// <input name='pId' class='infoPompier' value='" . $lesInfosPompier['id'] . "' >
|
||||
|
||||
echo ("
|
||||
<tr><th style='width:130px;'>Nom</th> <td style='width:130px;'><input name='ztNom' type='text' class='infoPompier' ></td> </tr>
|
||||
<tr><th>Prénom</th> <td> <input name='ztPrenom' type='text' class='infoPompier infoPompier-chef' ></td> </tr>
|
||||
<tr><th>Adresse</th> <td> <input name='ztAdresse' type='text' class='infoPompier infoPompier-chef' ></td> </tr>
|
||||
<tr><th>Code postal</th> <td> <input name='ztCodePostal' type='text' class='infoPompier infoPompier-chef' ></td> </tr>
|
||||
<tr><th style='width:130px;'>Nom*</th> <td style='width:130px;'><input name='ztNom' id='newName' type='text' class='infoPompier' required></td> </tr>
|
||||
<tr><th>Prénom*</th> <td> <input name='ztPrenom' id='newUsername' type='text' class='infoPompier infoPompier-chef' required></td> </tr>
|
||||
<tr><th>Adresse</th> <td> <input name='ztAdresse' type='text' class='infoPompier infoPompier-chef' ></td> </tr>
|
||||
<tr><th>Code postal</th> <td> <input name='ztCodePostal' type='text' class='infoPompier infoPompier-chef' ></td> </tr>
|
||||
<tr><th>Ville</th> <td> <input name='ztVille' type='text' class='infoPompier infoPompier-chef' ></td> </tr>
|
||||
<tr><th>Téléphone</th> <td> <input name='ztTel' type='text' class='infoPompier-chef' ></td> </tr>
|
||||
<tr><th>Adresse électronique</th> <td> <input name='ztMail' type='text' class='infoPompier infoPompier-chef' ></td> </tr>
|
||||
<tr><th>Nom de compte</th> <td><input name='ztMail' type='text' class='infoPompier infoPompier-chef' ></td></tr>
|
||||
<input name='pId' type='hidden' class='infoPompier' value='" . $lesInfosPompier['id'] . "' >
|
||||
<tr><th style='width:130px;'>Code</th> <td><input name='zCis' type='text' class='infoPompier-chef' value='" . $lesInfosPompier['pCis'] . "' ></td> </tr>
|
||||
<tr><th>Téléphone*</th> <td> <input name='ztTel' type='text' class='infoPompier-chef' required></td> </tr>
|
||||
<tr><th>Adresse électronique*</th> <td> <input name='ztMail' type='text' class='infoPompier infoPompier-chef' required></td> </tr>
|
||||
<tr><th>Nom de compte*</th> <td><input name='ztLogin' id='newLogin' type='text' class='infoPompier infoPompier-chef' required></td></tr>
|
||||
<tr><th style='width:130px;'>Code</th> <td><input name='zCis' id='inputDisabled' type='text' class='infoPompier-chef' value='" . $lesInfosPompier['pCis'] . "' disabled></td> </tr>
|
||||
<tr><th>Nom</th> <td>" . $lesInfosPompier['cNom'] . "</td> </tr>
|
||||
<tr><th>Adresse</th> <td>" . $lesInfosPompier['cAdresse'] . "</td> </tr>
|
||||
<tr><th>Téléphone</th> <td>" . $lesInfosPompier['cTel'] . "</td> </tr>
|
||||
@ -121,8 +121,9 @@
|
||||
</table>
|
||||
</fieldset>
|
||||
<div style='text-align:center; '>
|
||||
<input type= 'image' class='validerAjout' alt='Valider' src= 'images/Valider.jpg'>
|
||||
<p class='notif-ajout' style:'margin: 10px'></p>
|
||||
<input type= 'image' class='btAnnulerAjout' alt='Annuler' src= 'images/Annuler.jpg'>
|
||||
<input type= 'image' class='validerAjout' alt='Valider' src= 'images/Valider.jpg'>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
@ -135,7 +136,8 @@
|
||||
<tr>
|
||||
<td style='border: 0px solid white; witdh:130px; text-align:right;'>
|
||||
<input type="hidden" name="zTypeAdm"
|
||||
value="<? php // if ($type=="adm") {echo ("true");} else {echo ("false");} ?>">
|
||||
value="">
|
||||
<? // if ($type=="adm") {echo ("true");} else {echo ("false");} ?>
|
||||
<input type="hidden" name="zOk" value="OK">
|
||||
|
||||
</td>
|
||||
|
Loading…
x
Reference in New Issue
Block a user