diff --git a/controleurs/c_interventions.php b/controleurs/c_interventions.php index e09bdb3..92dc6ed 100644 --- a/controleurs/c_interventions.php +++ b/controleurs/c_interventions.php @@ -9,44 +9,67 @@ // Auteur : pascal-blain@wanadoo.fr ' //*****************************************' $action = $_REQUEST['action']; -switch($action) -{ -case 'voir': - { - include("vues/v_entete.php"); - if(!isset($_REQUEST['zSemaine'])){$_REQUEST['zSemaine'] = date('W');} - $semaine = $_REQUEST['zSemaine']; - if(!isset($_REQUEST['zAnnee'])){$_REQUEST['zAnnee'] = date('Y');} - $annee = $_REQUEST['zAnnee']; - $premierJour = strtotime("+$semaine weeks",mktime(0,0,0,1,1,$annee)); - if (date('w',$premierJour) != 1){$premierJour = strtotime("last monday",$premierJour);} - $lesTranches = $pdo->getParametre("tranche"); - $lesTypesDispos = $pdo->getParametre("dispo"); - $titre="CIS"; //Centre d'incendie et de secours :"; - $lesCasernes = $pdo->getLesCasernes($_SESSION["adr1"]); - include("vues/v_choixCaserne.php"); - $lesPompiers = $pdo->getLesPompiers($choix); - $lesInterventions=$pdo->getLesInterventions($choix); - $intervention=1; - $lesParticipants= $pdo->getLesParticipants($choix, $intervention); - include("vues/v_Intervention.php"); - break; - } +switch ($action) { + case 'voir': { + include("vues/v_entete.php"); -//----------------------------------------- -case 'majGarde': - { - $pdo->majGarde($_REQUEST["ztLaDate"], $_REQUEST["ztLaTranche"], $_REQUEST["ztExGarde"], $_REQUEST["ztPompier"]); - header ('location: index.php?choixTraitement=gardes&action=voir&zSemaine='.$_REQUEST["zSemaine"].'&zAnnee='.$_REQUEST["zAnnee"]); - break; - } + if (!isset($_REQUEST['zSemaine'])) { + $_REQUEST['zSemaine'] = date('W'); + } + $semaine = $_REQUEST['zSemaine']; + + if (!isset($_REQUEST['zAnnee'])) { + $_REQUEST['zAnnee'] = date('Y'); + } + $annee = $_REQUEST['zAnnee']; + $premierJour = strtotime("+$semaine weeks", mktime(0, 0, 0, 1, 1, $annee)); + + if (date('w', $premierJour) != 1) { + $premierJour = strtotime("last monday", $premierJour); + } + $lesTranches = $pdo->getParametre("tranche"); + $lesTypesDispos = $pdo->getParametre("dispo"); + $titre = "CIS"; //Centre d'incendie et de secours :"; + //include("vues/v_choixCaserne.php"); + //$lesPompiers = $pdo->getLesPompiers($choix); + //$lesInterventions = $pdo->getLesInterventions($choix); + //$intervention = 1; + //$lesParticipants = $pdo->getLesParticipants($choix, $intervention); + include("vues/v_Intervention.php"); + break; + } + case 'nouvelle': { + include("vues/v_entete.php"); + $lesCasernes = $pdo->getLesCasernes($_SESSION["adr1"]); + $lesMotifs = $pdo->motifIntervention(); + $lesPompiers = $pdo->getPompiersDispo('2023-09-23', 2, 2924); + + include("vues/v_nouvelleIntervention.php"); + + break; + } + case 'listePompier': + require_once ("../include/class.pdo.php"); + + $pdo = PdoBD::getPdoBD(); + + $lesPompiers = $pdo->getPompiersDispo('2023-09-23', 2, $_GET['cis']); + + echo(json_encode($lesPompiers)); -//----------------------------------------- -default : - { - echo 'erreur d\'aiguillage !'.$action; break; - } + //----------------------------------------- + case 'majGarde': { + $pdo->majGarde($_REQUEST["ztLaDate"], $_REQUEST["ztLaTranche"], $_REQUEST["ztExGarde"], $_REQUEST["ztPompier"]); + header('location: index.php?choixTraitement=gardes&action=voir&zSemaine=' . $_REQUEST["zSemaine"] . '&zAnnee=' . $_REQUEST["zAnnee"]); + break; + } + + //----------------------------------------- + default: { + echo 'erreur d\'aiguillage !' . $action; + break; + } } /* table equipe: @@ -64,4 +87,4 @@ iTranche tinyint(3) iHeureDebut datetime iHeureFin datetime */ -?> +?> \ No newline at end of file diff --git a/include/class.pdo.php b/include/class.pdo.php index 42fd4e5..0082c89 100644 --- a/include/class.pdo.php +++ b/include/class.pdo.php @@ -63,7 +63,7 @@ class PdoBD { $req = "SELECT pCis, pId, pNom, pPrenom, pStatut FROM pompier - WHERE pCis=" . $cis . " + WHERE pCis = " . $cis . " ORDER BY pNom;"; $rs = PdoBD::$monPdo->query($req); if ($rs === false) { @@ -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; } @@ -543,7 +543,7 @@ class PdoBD return $lesLignes; } - public function getLastId($pCis) : int + public function getLastId($pCis): int { $req = "SELECT MAX(pId) + 1 as id FROM pompier WHERE pCis =" . $pCis . ";"; $rs = PdoBD::$monPdo->query($req); @@ -556,11 +556,11 @@ class PdoBD public function verifDataAjoutPompier( string $nom, - string $prenom, - string $tel, - string $mail, + string $prenom, + string $tel, + string $mail, string $login - ) : bool { + ): bool { if (empty($nom) || empty($prenom) || empty($tel) || empty($mail) || empty($login)) { return false; @@ -569,6 +569,111 @@ class PdoBD } } + /** + * PARTIE INTERVENTION + */ + public function motifIntervention() + { + $req = "SELECT pIndice, pLibelle + FROM `parametre` + WHERE pType = 'cateInt' + ORDER BY pLibelle;"; + $cat = PdoBD::$monPdo->query($req); + $cat = $cat->fetchAll(); + + //Valeur : nbUtil + //Plancher : Time + //Plafond: nbPompier estimé + $reqType = "SELECT pIndice, pLibelle, pValeur, pPlancher, pPlafond + FROM parametre + WHERE pType = 'typeInt' + ORDER BY pLibelle;"; + $type = PdoBD::$monPdo->query($reqType); + $type = $type->fetchAll(); + + $response = []; + + foreach ($cat as $uneCat) { + $table = []; + foreach ($type as $row) { + if (substr($row['pIndice'], -3, 1) === $uneCat['pIndice']) { + array_push($table, $row); + } + } + $response[$uneCat['pLibelle']] = $table; + } + + return $response; + } + + public function getPompiersDispo(string $date, int $tranche, int $caserne) + { + $req = "SELECT pompier.pId, pompier.pNom, pompier.pPrenom, g.pLibelle AS statut, 0 AS enIntervention, p.pLibelle, p.pValeur + FROM `pompier` + INNER JOIN activite ON pompier.pId = activite.aPompier + AND activite.aCis = pompier.pCis + INNER JOIN parametre p ON p.pType = 'dispo' AND p.pIndice = activite.aDisponibilite + INNER JOIN parametre g ON g.pType = 'grade' AND g.pIndice = pompier.pGrade + WHERE activite.aGarde = 1 + AND pCis = :caserne + AND activite.aDateGarde = :date + AND activite.aTranche = :tranche + AND pompier.pId NOT IN(SELECT ePompier + FROM equipe + INNER JOIN intervention on intervention.iId = equipe.eIntervention AND intervention.iCis = equipe.eCis + WHERE intervention.iHeureFin is null + AND intervention.iDate = :date + AND intervention.iTranche = :tranche + AND intervention.iCis = :caserne + ) + + UNION + + SELECT pompier.pId, pompier.pNom, pompier.pPrenom, g.pLibelle AS statut, 1 AS enIntervention, p.pLibelle, 'grey' + FROM equipe + INNER JOIN pompier on equipe.ePompier = pompier.pId + AND equipe.eCis = pompier.pCis + INNER JOIN intervention on intervention.iId = equipe.eIntervention + AND intervention.iCis = equipe.eCis + INNER JOIN activite on pompier.pId = activite.aPompier + AND activite.aCis = pompier.pCis + AND activite.aDateGarde = intervention.iDate + AND activite.aTranche = intervention.iTranche + INNER JOIN parametre p ON p.pType = 'dispo' AND p.pIndice = activite.aDisponibilite + INNER JOIN parametre g ON g.pType = 'grade' AND g.pIndice = pompier.pGrade + WHERE intervention.iHeureFin is null + AND intervention.iTranche = :tranche + AND intervention.iDate = :date + AND equipe.eCis = :caserne;"; + + $result = PdoBD::$monPdo->prepare($req); + $result->bindParam(':date', $date); // 2023-09-23 + $result->bindParam(':tranche', $tranche); //2 + $result->bindParam(':caserne', $caserne); //2924 + + $result->execute(); + return $result->fetchAll(); + } + } +/** +SELECT pompier.*, 0 AS enIntervention, activite.aDisponibilite +FROM `pompier` +INNER JOIN activite ON pompier.pId = activite.aPompier AND activite.aCis = pompier.pCis +WHERE pCis = 2924 AND activite.aDateGarde = '2023-09-23' AND activite.aTranche = 2 AND activite.aGarde = 1 +AND pompier.pId NOT IN(SELECT ePompier +FROM equipe +INNER JOIN intervention on intervention.iId = equipe.eIntervention AND intervention.iCis = equipe.eCis +WHERE intervention.iDate = '2023-09-23' AND intervention.iTranche = 2 AND intervention.iHeureFin is null) + +UNION + +SELECT pompier.*, 1 AS enIntervention, activite.aDisponibilite +FROM equipe +INNER JOIN pompier on equipe.ePompier = pompier.pId AND equipe.eCis = pompier.pCis +INNER JOIN activite on pompier.pId = activite.aPompier AND activite.aCis = pompier.pCis +INNER JOIN intervention on intervention.iId = equipe.eIntervention AND intervention.iCis = equipe.eCis +WHERE intervention.iDate = '2023-09-23' AND intervention.iTranche = 2 AND intervention.iHeureFin is null; + */ ?> \ No newline at end of file diff --git a/include/gestionInterventions.js b/include/gestionInterventions.js new file mode 100644 index 0000000..bd43f47 --- /dev/null +++ b/include/gestionInterventions.js @@ -0,0 +1,73 @@ +formulaire = $('.formulaire') +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) { + + // } + // }); + + $('#caserneInter').change(function () { + console.log($(this).val()); + caserne = $(this).val() + //cis + $.ajax({ + url: "./../controleurs/c_interventions.php?action=listePompier&cis=" + caserne, + 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) { + $('#pompierDispo').html(' '); + result.forEach(element => { + var ligne = '
Nombre de pompiers conseillé: 4
+ +
-
- 2023 Pierre Renaudot";?>
+
+ 2023 Pierre Renaudot"; ?>
+