ajout d'une intervention vFinal

This commit is contained in:
pierre renaudot 2023-11-30 12:14:44 +01:00
parent 062e417a9c
commit 6f165b76f2
5 changed files with 204 additions and 34 deletions

View File

@ -42,7 +42,11 @@ switch ($action) {
include("vues/v_entete.php"); include("vues/v_entete.php");
$lesCasernes = $pdo->getLesCasernes($_SESSION["adr1"]); $lesCasernes = $pdo->getLesCasernes($_SESSION["adr1"]);
$lesMotifs = $pdo->motifIntervention(); $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"); include("vues/v_nouvelleIntervention.php");
@ -53,10 +57,32 @@ switch ($action) {
$pdo = PdoBD::getPdoBD(); $pdo = PdoBD::getPdoBD();
$lesPompiers = $pdo->getPompiersDispo('2023-09-23', 2, $_GET['cis']); $tranche = $pdo->getCurrentTranche();
$date = date('Y-m-d');
$lesPompiers = $pdo->getPompiersDispo($date, $tranche, $_GET['cis']);
echo(json_encode($lesPompiers)); 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; break;
//----------------------------------------- //-----------------------------------------
case 'majGarde': { case 'majGarde': {

View File

@ -581,7 +581,7 @@ class PdoBD
$cat = PdoBD::$monPdo->query($req); $cat = PdoBD::$monPdo->query($req);
$cat = $cat->fetchAll(); $cat = $cat->fetchAll();
//Valeur : nbUtil //Valeur : nbUtilisation
//Plancher : Time //Plancher : Time
//Plafond: nbPompier estimé //Plafond: nbPompier estimé
$reqType = "SELECT pIndice, pLibelle, pValeur, pPlancher, pPlafond $reqType = "SELECT pIndice, pLibelle, pValeur, pPlancher, pPlafond
@ -655,6 +655,109 @@ class PdoBD
return $result->fetchAll(); 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();
}
}
}
}
} }
/** /**

View File

@ -3,22 +3,14 @@ date = Date.now()
$(document).ready(function () { $(document).ready(function () {
// $.ajax({ $('#motifInter').change(function (e) {
// url: "/controleurs/c_interventions.php?action=infoFormulaire", let nbPompier = $(this).find(":selected").attr('data-effectif');
// method: "POST", // Méthode HTTP (GET, POST, etc.) $('#nbPompierCons').html("Nombre de pompiers conseillé: " + nbPompier);
// 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 () { $('#caserneInter').change(function () {
console.log($(this).val()); caserne = $(this).val();
caserne = $(this).val()
//cis //cis
$.ajax({ $.ajax({
url: "./../controleurs/c_interventions.php?action=listePompier&cis=" + caserne, url: "./../controleurs/c_interventions.php?action=listePompier&cis=" + caserne,
@ -34,6 +26,7 @@ $(document).ready(function () {
var ligne = '<div id=' var ligne = '<div id='
+ element['pId'] + element['pId']
+ ' class="' + element['pLibelle'] + ' class="' + element['pLibelle']
+ '" data-intervention="' + element['enIntervention']
+ '" style = "background-color: ' + element['pValeur'] + ';" draggable = "true" ondragstart = "dragstartHandler(event)" >' + '" style = "background-color: ' + element['pValeur'] + ';" draggable = "true" ondragstart = "dragstartHandler(event)" >'
+ element['pPrenom'] + ' ' + element['pNom'] + element['pPrenom'] + ' ' + element['pNom']
+ ' (' + element['statut'] + ')' + ' (' + element['statut'] + ')'
@ -44,7 +37,6 @@ $(document).ready(function () {
}); });
} }
}); });
}); });
}); });
@ -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
}
});
})

View File

@ -679,9 +679,6 @@ PARTIE DES INTERVENTIONS
padding: 3px; padding: 3px;
margin: 5px; margin: 5px;
cursor: pointer; cursor: pointer;
}
.pompierDispo .1{
} }
.pompierIntervenant{ .pompierIntervenant{
background-color: red; background-color: red;

View File

@ -4,7 +4,7 @@
<div class="nouvelleInter"> <div class="nouvelleInter">
<h1>Nouvelle intervention</h1> <h1>Nouvelle intervention</h1>
<div class="formulaire" > <div class="formulaire" >
<form action=""> <form action="" id="formulaireInter">
<label for="motif">Motif de l'intervention : </label> <label for="motif">Motif de l'intervention : </label>
<select name="motif" id="motifInter"> <select name="motif" id="motifInter">
@ -12,7 +12,10 @@
foreach ($lesMotifs as $key => $type) { foreach ($lesMotifs as $key => $type) {
echo '<optgroup label="' . $key . '">'; echo '<optgroup label="' . $key . '">';
foreach ($type as $motif) { foreach ($type as $motif) {
echo ' <option value="' . $motif['pIndice'] . '">' . $motif['pLibelle'] . '</option>'; echo ' <option value="' . $motif['pIndice']
. '" data-time="' . $motif['pPlancher']
. '" data-effectif="' . $motif['pPlafond'] .'" >'
. $motif['pLibelle'] . '</option>';
} }
} }
?> ?>
@ -50,17 +53,18 @@
?> ?>
<div id="<?= $pompier['pId'] ?>" class="<?= $pompier['pLibelle'] ?>" <div id="<?= $pompier['pId'] ?>" class="<?= $pompier['pLibelle'] ?>"
style="background-color: <?= $pompier['pValeur'] ?>" draggable="true" style="background-color: <?= $pompier['pValeur'] ?>" draggable="true"
ondragstart="dragstartHandler(event)"> data-intervention="<?= $pompier['enIntervention'] ?>" ondragstart="dragstartHandler(event)">
<?= $pompier['pPrenom'] ?> <?= $pompier['pPrenom'] ?>
<?= $pompier['pNom'] ?> <?= $pompier['pNom'] ?>
(<?= $pompier['statut'] ?>) (
<?= $pompier['statut'] ?>)
</div> </div>
<?php endforeach ?> <?php endforeach ?>
</div> </div>
<div id="target" ondrop="dropHandler(event)" ondragover="dragoverHandler(event)" <div id="target" ondrop="dropHandler(event)" ondragover="dragoverHandler(event)"
ondragstart="dragstartHandler(event)" class="pompierIntervenant"> ondragstart="dragstartHandler(event)" class="pompierIntervenant">
<p>Nombre de pompiers conseillé: 4</p> <p id="nbPompierCons">Nombre de pompiers conseillé: 4</p>
</div> </div>
</div> </div>