diff --git a/controleurs/c_interventions.php b/controleurs/c_interventions.php index 92dc6ed..3a2470c 100644 --- a/controleurs/c_interventions.php +++ b/controleurs/c_interventions.php @@ -42,7 +42,11 @@ switch ($action) { include("vues/v_entete.php"); $lesCasernes = $pdo->getLesCasernes($_SESSION["adr1"]); $lesMotifs = $pdo->motifIntervention(); - $lesPompiers = $pdo->getPompiersDispo('2023-09-23', 2, 2924); + + $tranche = $pdo->getCurrentTranche(); + $date = date('Y-m-d'); + + $lesPompiers = $pdo->getPompiersDispo($date, $tranche, 2904); include("vues/v_nouvelleIntervention.php"); @@ -52,11 +56,33 @@ switch ($action) { require_once ("../include/class.pdo.php"); $pdo = PdoBD::getPdoBD(); + + $tranche = $pdo->getCurrentTranche(); + $date = date('Y-m-d'); - $lesPompiers = $pdo->getPompiersDispo('2023-09-23', 2, $_GET['cis']); + $lesPompiers = $pdo->getPompiersDispo($date, $tranche, $_GET['cis']); echo(json_encode($lesPompiers)); + break; + case 'nouvelleInter': + require_once ("../include/class.pdo.php"); + + $pdo = PdoBD::getPdoBD(); + //var_dump($_REQUEST); + + $listePompier = $_POST['listePompier']; + $data = $_POST['dataForm']; + + $pdo->newIntervention( + intval($data['motif']), + intval($data['caserne']), + $data['adresse'], + $data['commentaire'], + $listePompier + ); + //var_dump($listePompier); + break; //----------------------------------------- case 'majGarde': { diff --git a/include/class.pdo.php b/include/class.pdo.php index 0082c89..3e4de29 100644 --- a/include/class.pdo.php +++ b/include/class.pdo.php @@ -79,10 +79,10 @@ class PdoBD public function getInfosPompier($login, $mdp) { /* - $req = "SELECT pCis, pId as id, pNom as nom, pPrenom as prenom, pStatut, pMail, pLogin, pMdp, pGrade, pAdresse, pCp, pVille, pBip, pCommentaire, - 'la caserne' as cNom, 'adresse' as cAdresse, 'telephone' as cTel, 'le groupement' as cGroupement, 'le grade' as wGrade, 'le statut' as wStatut, 'le type' as wType - FROM pompier"; - */ + $req = "SELECT pCis, pId as id, pNom as nom, pPrenom as prenom, pStatut, pMail, pLogin, pMdp, pGrade, pAdresse, pCp, pVille, pBip, pCommentaire, + 'la caserne' as cNom, 'adresse' as cAdresse, 'telephone' as cTel, 'le groupement' as cGroupement, 'le grade' as wGrade, 'le statut' as wStatut, 'le type' as wType + FROM pompier"; + */ $req = "SELECT pCis, pId as id, @@ -358,8 +358,8 @@ class PdoBD $lesDispos[$pompier][$laDate][$couleur] = $uneLigne['dCouleur']; } /* echo "
";
-														print_r($lesDispos);
-														echo "
";*/ + print_r($lesDispos); + echo "";*/ return $lesDispos; } @@ -581,7 +581,7 @@ class PdoBD $cat = PdoBD::$monPdo->query($req); $cat = $cat->fetchAll(); - //Valeur : nbUtil + //Valeur : nbUtilisation //Plancher : Time //Plafond: nbPompier estimé $reqType = "SELECT pIndice, pLibelle, pValeur, pPlancher, pPlafond @@ -655,6 +655,109 @@ class PdoBD return $result->fetchAll(); } + public function getCurrentTranche() + { + $req = "SELECT pIndice + FROM parametre + WHERE pType = 'tranche' AND :heure >= pPlancher AND :heure < pPlafond;"; + + $result = PdoBD::$monPdo->prepare($req); + $hour = date("H"); + $result->bindParam(':heure', $hour); + $result->execute(); + $result = $result->fetch(); + + return $result['pIndice']; + } + + public function getLastIdIntervention(int $cis) + { + $req = "SELECT iId + FROM `intervention` + WHERE iCis = :cis;"; + + $result = PdoBD::$monPdo->prepare($req); + $result->bindParam(':cis', $cis); + $result->execute(); + $result = $result->fetch(); + $id = isset($result['iId']) ? $result['iId'] : 0; + return $id; + } + /** + * Crée une nouvelle intervention + */ + public function newIntervention( + int $motif, + int $caserne, + string $adresse, + string $description, + array $pompier + ) { + /** + * Nouvelle intervention + */ + $req = " INSERT INTO intervention + VALUES(:caserne, :id, :adresse, :description, + NOW(), :tranche, NOW(), NULL, :motif, :nbPompier);"; + + $result = PdoBD::$monPdo->prepare($req); + $result->bindParam(':caserne', $caserne); + $result->bindParam(':adresse', $adresse); + $result->bindParam(':description', $description); + $result->bindParam(':motif', $motif); + + $nbPompier = count($pompier); + $result->bindParam(':nbPompier', $nbPompier); + + $tranche = $this->getCurrentTranche(); + $result->bindParam(':tranche', $tranche); + + $idIntervention = $this->getLastIdIntervention($caserne) + 1; + $result->bindParam(':id', $idIntervention); + + $result->execute(); + + /** + * Nouvelle équipe + */ + foreach ($pompier as $value) { + var_dump($value); + foreach ($value as $key => $value) { + $req2 = "INSERT INTO equipe + VALUES (:caserne, :pompier, :intervention)"; + $result2 = PdoBD::$monPdo->prepare($req2); + $result2->bindParam('caserne', $caserne); + $result2->bindParam('intervention', $idIntervention); + + if ($value == 0) { + $result2->bindParam('pompier', $key); + + $result2->execute(); + } else { + $currentIntervention = "SELECT iId + FROM intervention + LEFT OUTER JOIN equipe on intervention.iId = equipe.eIntervention AND intervention.iCis = equipe.eCis + WHERE iHeureFin IS NULL AND equipe.ePompier = :pompier AND equipe.eCis = :caserne;"; + $curentId = PdoBD::$monPdo->prepare($currentIntervention); + $curentId->bindParam('pompier', $key); + $curentId->bindParam('caserne', $caserne); + $curentId->execute(); + $curentId = $curentId->fetch(); + + + $reqSuprInter = "DELETE FROM equipe + WHERE eCis = :caserne AND ePompier = :pompier AND eIntervention = :intervention"; + $suprInter = PdoBD::$monPdo->prepare($reqSuprInter); + $suprInter->bindParam('caserne', $caserne); + $suprInter->bindParam('pompier', $key); + $suprInter->bindParam('intervention', $currentId['iId']); + $suprInter->execute(); + + } + } + } + + } } /** diff --git a/include/gestionInterventions.js b/include/gestionInterventions.js index bd43f47..99ec441 100644 --- a/include/gestionInterventions.js +++ b/include/gestionInterventions.js @@ -3,22 +3,14 @@ date = Date.now() $(document).ready(function () { - // $.ajax({ - // url: "/controleurs/c_interventions.php?action=infoFormulaire", - // method: "POST", // Méthode HTTP (GET, POST, etc.) - // dataType: "json", // Type de données attendu - // error: function(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) { + $('#motifInter').change(function (e) { + let nbPompier = $(this).find(":selected").attr('data-effectif'); + $('#nbPompierCons').html("Nombre de pompiers conseillé: " + nbPompier); + }); - // } - // }); $('#caserneInter').change(function () { - console.log($(this).val()); - caserne = $(this).val() + caserne = $(this).val(); //cis $.ajax({ url: "./../controleurs/c_interventions.php?action=listePompier&cis=" + caserne, @@ -34,17 +26,17 @@ $(document).ready(function () { var ligne = '
' + element['pPrenom'] + ' ' + element['pNom'] + ' (' + element['statut'] + ')' + '
'; - $('#pompierDispo').append(ligne) + $('#pompierDispo').append(ligne) }); } }); - }); }); @@ -71,3 +63,51 @@ function dropHandler(ev) { } +/** + * PREPARATION DE L'ENVOIE DU FORMULAIRE + */ +$(document).on('submit', '#formulaireInter', function(e){ + e.preventDefault(); +}) + +$(document).on('click', '#sendInter', function(e){ + e.preventDefault(); + + //var data = $('#formulaireInter').serialize(); + var data = { + motif: $('#formulaireInter select[name=motif]').val(), + adresse: $('#formulaireInter input[name=adresse]').val(), + caserne: $('#formulaireInter select[name=caserne]').val(), + commentaire: $('#formulaireInter textarea[name=commentaire]').val() + }; + + let listePompier = []; + $('.pompierIntervenant div').each(function(index){ + num = $(this).attr('id'); + dispo = $(this).attr('data-intervention'); + + var obj = {}; + obj[num] = dispo + listePompier.push(obj) + }) + + var sendingData = { + "dataForm" : data, + "listePompier" : listePompier + }; + + $.ajax({ + url: "./../controleurs/c_interventions.php?action=nouvelleInter", + method: "POST", // Méthode HTTP (GET, POST, etc.) + data: sendingData, + dataType: "json", // Type de données attendu + error: function (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) { + //COMPLETE + } + }); + +}) \ No newline at end of file diff --git a/styles/styles.css b/styles/styles.css index ebdd0ec..a9a16ed 100644 --- a/styles/styles.css +++ b/styles/styles.css @@ -679,9 +679,6 @@ PARTIE DES INTERVENTIONS padding: 3px; margin: 5px; cursor: pointer; -} -.pompierDispo .1{ - } .pompierIntervenant{ background-color: red; diff --git a/vues/v_nouvelleIntervention.php b/vues/v_nouvelleIntervention.php index 84533d4..a4068b7 100644 --- a/vues/v_nouvelleIntervention.php +++ b/vues/v_nouvelleIntervention.php @@ -3,8 +3,8 @@

Nouvelle intervention

-
-
+
+