ajout d'une intervention vFinal
This commit is contained in:
parent
062e417a9c
commit
6f165b76f2
@ -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");
|
||||
|
||||
@ -53,10 +57,32 @@ switch ($action) {
|
||||
|
||||
$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));
|
||||
|
||||
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': {
|
||||
|
@ -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 "<PRE>";
|
||||
print_r($lesDispos);
|
||||
echo "</PRE>";*/
|
||||
print_r($lesDispos);
|
||||
echo "</PRE>";*/
|
||||
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();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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 = '<div id='
|
||||
+ element['pId']
|
||||
+ ' class="' + element['pLibelle']
|
||||
+ '" data-intervention="' + element['enIntervention']
|
||||
+ '" style = "background-color: ' + element['pValeur'] + ';" draggable = "true" ondragstart = "dragstartHandler(event)" >'
|
||||
+ element['pPrenom'] + ' ' + element['pNom']
|
||||
+ ' (' + element['statut'] + ')'
|
||||
+ '</div> ';
|
||||
|
||||
$('#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
|
||||
}
|
||||
});
|
||||
|
||||
})
|
@ -679,9 +679,6 @@ PARTIE DES INTERVENTIONS
|
||||
padding: 3px;
|
||||
margin: 5px;
|
||||
cursor: pointer;
|
||||
}
|
||||
.pompierDispo .1{
|
||||
|
||||
}
|
||||
.pompierIntervenant{
|
||||
background-color: red;
|
||||
|
@ -3,8 +3,8 @@
|
||||
|
||||
<div class="nouvelleInter">
|
||||
<h1>Nouvelle intervention</h1>
|
||||
<div class="formulaire">
|
||||
<form action="">
|
||||
<div class="formulaire" >
|
||||
<form action="" id="formulaireInter">
|
||||
|
||||
<label for="motif">Motif de l'intervention : </label>
|
||||
<select name="motif" id="motifInter">
|
||||
@ -12,7 +12,10 @@
|
||||
foreach ($lesMotifs as $key => $type) {
|
||||
echo '<optgroup label="' . $key . '">';
|
||||
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'] ?>"
|
||||
style="background-color: <?= $pompier['pValeur'] ?>" draggable="true"
|
||||
ondragstart="dragstartHandler(event)">
|
||||
data-intervention="<?= $pompier['enIntervention'] ?>" ondragstart="dragstartHandler(event)">
|
||||
<?= $pompier['pPrenom'] ?>
|
||||
<?= $pompier['pNom'] ?>
|
||||
(<?= $pompier['statut'] ?>)
|
||||
(
|
||||
<?= $pompier['statut'] ?>)
|
||||
</div>
|
||||
<?php endforeach ?>
|
||||
|
||||
</div>
|
||||
<div id="target" ondrop="dropHandler(event)" ondragover="dragoverHandler(event)"
|
||||
ondragstart="dragstartHandler(event)" class="pompierIntervenant">
|
||||
<p>Nombre de pompiers conseillé: 4</p>
|
||||
<p id="nbPompierCons">Nombre de pompiers conseillé: 4</p>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
Loading…
x
Reference in New Issue
Block a user