782 lines
24 KiB
PHP
782 lines
24 KiB
PHP
<?php
|
|
/**
|
|
* @author : Pascal BLAIN, lycee le Castel à Dijon
|
|
* @version : 2023-09-18 à 16h43
|
|
* Classe d'acces aux donnees. Utilise les services de la classe PDO pour l'application
|
|
* Les attributs sont tous statiques, les 4 premiers pour la connexion
|
|
* $monPdo est de type PDO - $monPdoBD contient l'unique instance de la classe
|
|
* @link http://www.php.net/manual/fr/book.pdo.php
|
|
*/
|
|
|
|
class PdoBD
|
|
{
|
|
private static $serveur = 'mysql:host=localhost';
|
|
private static $bdd = 'dbname=sdis29';
|
|
private static $user = 'root';
|
|
private static $mdp = 'root';
|
|
private static $monPdo;
|
|
private static $monPdoBD = null;
|
|
|
|
private function __construct()
|
|
{
|
|
PdoBD::$monPdo = new PDO(PdoBD::$serveur . ';' . PdoBD::$bdd, PdoBD::$user, PdoBD::$mdp);
|
|
PdoBD::$monPdo->query("SET CHARACTER SET utf8");
|
|
}
|
|
public function _destruct()
|
|
{
|
|
PdoBD::$monPdo = null;
|
|
}
|
|
|
|
/**
|
|
* Fonction statique qui cree l'unique instance de la classe PdoBD
|
|
* Appel : $instancePdoBD = PdoBD::getPdoBD();
|
|
*/
|
|
public static function getPdoBD()
|
|
{
|
|
if (PdoBD::$monPdoBD == null) {
|
|
PdoBD::$monPdoBD = new PdoBD();
|
|
}
|
|
return PdoBD::$monPdoBD;
|
|
}
|
|
|
|
/**
|
|
* Retourne les informations d'un centre de coordination
|
|
*/
|
|
public function getLesCasernes($leCentre)
|
|
{
|
|
$req = "SELECT cId, cNom, cAdresse, cTel, cGroupement
|
|
FROM caserne
|
|
WHERE cGroupement='" . $leCentre . "'
|
|
ORDER BY cNom;";
|
|
$rs = PdoBD::$monPdo->query($req);
|
|
if ($rs === false) {
|
|
afficherErreurSQL("Probleme lors de la lecture des casernes ..", $req, PdoBD::$monPdo->errorInfo());
|
|
}
|
|
$lesLignes = $rs->fetchAll();
|
|
return $lesLignes;
|
|
}
|
|
|
|
/**
|
|
* Retourne les informations des pompiers
|
|
*/
|
|
public function getLesPompiers($cis)
|
|
{
|
|
$req = "SELECT pCis, pId, pNom, pPrenom, pStatut
|
|
FROM pompier
|
|
WHERE pCis = " . $cis . "
|
|
ORDER BY pNom;";
|
|
$rs = PdoBD::$monPdo->query($req);
|
|
if ($rs === false) {
|
|
afficherErreurSQL("Probleme lors de la lecture des pompiers ..", $req, PdoBD::$monPdo->errorInfo());
|
|
}
|
|
$lesLignes = $rs->fetchAll();
|
|
return $lesLignes;
|
|
}
|
|
|
|
/**
|
|
* Retourne les informations d'un pompier sous la forme d'un tableau associatif
|
|
*/
|
|
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,
|
|
pAdresse,
|
|
pCp, pVille,
|
|
pBip, pCommentaire,
|
|
a.pLibelle AS wType,
|
|
b.pLibelle AS wGrade,
|
|
c.pLibelle AS wStatut,
|
|
cNom, cAdresse,
|
|
cTel, cGroupement
|
|
FROM pompier
|
|
INNER JOIN caserne ON pompier.pCis = caserne.cId
|
|
INNER JOIN parametre AS a ON a.pType = 'typePer' AND pompier.pType = a.pIndice
|
|
INNER JOIN parametre AS b ON b.pType = 'grade' AND pompier.pGrade = b.pIndice
|
|
INNER JOIN parametre AS c ON c.pType = 'statAgt' AND pompier.pStatut = c.pIndice";
|
|
if ($login === "*") {
|
|
$req .= " WHERE pCis=" . $_SESSION['cis'] . " AND pId = $mdp";
|
|
} else {
|
|
$req .= " WHERE pLogin='$login'
|
|
AND pMdp='$mdp'";
|
|
}
|
|
$rs = PdoBD::$monPdo->query($req);
|
|
if ($rs === false) {
|
|
afficherErreurSQL("Probleme lors de la lecture des informations d'un pompier...", $req, PdoBD::$monPdo->errorInfo());
|
|
}
|
|
$ligne = $rs->fetch();
|
|
return $ligne;
|
|
}
|
|
|
|
/**
|
|
* Met à jour les disp d'un pompier sur une tranche
|
|
*/
|
|
public function majActivite($cis, $idUser, $jour, $tranche, $newDispo)
|
|
{
|
|
$existedTranche = 'SELECT aDisponibilite FROM activite
|
|
WHERE aCis = ' . $cis . ' AND aDateGarde = "' . $jour . '" AND aTranche = ' . $tranche . ' AND aPompier = ' . $idUser . ';';
|
|
$rs = PdoBD::$monPdo->query($existedTranche);
|
|
|
|
if ($rs === false) {
|
|
afficherErreurSQL("Probleme lors de la mise à jour de l'activité dans la base de données.", $existedTranche, PdoBD::$monPdo->errorInfo());
|
|
} else {
|
|
|
|
if ($rs->fetch() === false) {
|
|
$req = 'INSERT INTO activite (aCis, aPompier, aDateGarde, aTranche, aDisponibilite, aGarde)
|
|
VALUES (' . $cis . ',
|
|
' . $idUser . ',
|
|
"' . $jour . '",
|
|
' . $tranche . ',
|
|
' . $newDispo . ', 0);';
|
|
} else {
|
|
$req = 'UPDATE activite
|
|
SET aDisponibilite = ' . $newDispo . '
|
|
WHERE aCis = ' . $cis . '
|
|
AND aPompier = ' . $idUser . '
|
|
AND aDateGarde = "' . $jour . '"
|
|
AND aTranche = ' . $tranche . ';';
|
|
}
|
|
$rs = PdoBD::$monPdo->exec($req);
|
|
|
|
if ($rs === false) {
|
|
afficherErreurSQL("Probleme lors de la mise à jour de l'activité dans la base de données.", $existedTranche, PdoBD::$monPdo->errorInfo());
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Met à jour la garde d'un pompier sur une tranche
|
|
*/
|
|
public function majGarde($cis, $idUser, $jour, $tranche, $newGarde)
|
|
{
|
|
$req = 'UPDATE activite
|
|
SET aGarde = ' . $newGarde . '
|
|
WHERE aCis = ' . $cis . '
|
|
AND aPompier = ' . $idUser . '
|
|
AND aDateGarde = "' . $jour . '"
|
|
AND aTranche = ' . $tranche . ';';
|
|
$rs = PdoBD::$monPdo->exec($req);
|
|
if ($rs === false) {
|
|
afficherErreurSQL("Probleme lors de la mise à jour de la garde dans la base de données.", $req, PdoBD::$monPdo->errorInfo());
|
|
}
|
|
}
|
|
/**
|
|
* Met à jour une ligne de la table pompier
|
|
*/
|
|
public function majPompier($cis, $pId, $nom, $prenom, $statut, $mail, $login, $mdp, $grade, $type, $adresse, $cp, $ville, $tel, $commentaire)
|
|
{
|
|
$grade = 7;
|
|
$type = 2;
|
|
$statut = 2;
|
|
date_default_timezone_set('Europe/Paris');
|
|
$dateUpdate = date('y-m-d h:i:s');
|
|
|
|
|
|
$req = "
|
|
UPDATE pompier
|
|
SET pCis ='$cis', pId ='$pId',
|
|
pNom ='$nom', pPrenom ='$prenom',
|
|
pStatut ='$statut', pType ='$type',
|
|
pMail ='$mail', pLogin ='$login',
|
|
pMdp ='$mdp', pAdresse ='$adresse',
|
|
pCp ='$cp', pVille ='$ville',
|
|
pBip ='$tel', pGrade ='$grade',
|
|
pCommentaire ='$commentaire', pDateModif ='$dateUpdate'
|
|
WHERE pCis='$cis' AND pId = '$pId'
|
|
;";
|
|
$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());
|
|
}
|
|
}
|
|
|
|
/**
|
|
* supprime une ligne de la table pompier
|
|
*/
|
|
public function supprimePompier($cis, $valeur)
|
|
{
|
|
$req = "
|
|
|
|
;";
|
|
$rs = PdoBD::$monPdo->exec($req);
|
|
if ($rs === false) {
|
|
afficherErreurSQL("Probleme lors de la suppression du pompier dans la base de données.", $req, PdoBD::$monPdo->errorInfo());
|
|
}
|
|
}
|
|
|
|
/**
|
|
* ajoute une ligne dans la table pompier
|
|
*/
|
|
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, 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) {
|
|
afficherErreurSQL("Probleme lors de l'insertion du pompier dans la base de données.", $req, PdoBD::$monPdo->errorInfo());
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Retourne les informations des gardes d'un pompier (ou des pompiers) sous la forme d'un tableau associatif
|
|
*/
|
|
public function getInfosGardes($pompier)
|
|
{
|
|
$req = "SELECT aPompier, DATE_FORMAT(aDateGarde,'%d/%m/%Y') as wDate, aTranche, pLibelle as tLibelle
|
|
FROM activite INNER JOIN parametre ON pType = 'tranche' AND aTranche = pIndice
|
|
WHERE aCis=" . $_SESSION['cis'];
|
|
if ($pompier <> "*") {
|
|
$req .= " AND aPompier=" . $pompier;
|
|
}
|
|
$req .= " AND aGarde=True
|
|
ORDER BY aPompier, aDateGarde DESC, aTranche ASC;";
|
|
|
|
$rs = PdoBD::$monPdo->query($req);
|
|
if ($rs === false) {
|
|
afficherErreurSQL("Probleme lors de la lecture des gardes d'un pompier...", $req, PdoBD::$monPdo->errorInfo());
|
|
}
|
|
$lesLignes = $rs->fetchAll();
|
|
return $lesLignes;
|
|
}
|
|
|
|
/**
|
|
* Retourne les informations des disponibilites hebdomadaires d'un pompier sous la forme d'un tableau associatif
|
|
*/
|
|
public function getDisposHebdo($pompier, $semaine, $annee)
|
|
{
|
|
$premierJour = strtotime("+$semaine weeks", mktime(0, 0, 0, 1, 1, $annee)); //renvoie la date du lundi
|
|
|
|
if (date('w', $premierJour) != 1) {
|
|
$premierJour = strtotime("last monday", $premierJour);
|
|
}
|
|
$debut = date('Y/m/d', $premierJour);
|
|
$fin = date('Y/m/d', strtotime("6 days", $premierJour));
|
|
|
|
$req = "SELECT pId, pNom, pPrenom, DATE_FORMAT(aDateGarde,'%d/%m/%Y') as wDate, aTranche, aDisponibilite, aGarde, d.pValeur as dCouleur
|
|
FROM (activite
|
|
INNER JOIN parametre t ON t.pType='tranche'AND aTranche = t.pIndice
|
|
INNER JOIN parametre d ON d.pType='dispo' AND aDisponibilite = d.pIndice
|
|
)
|
|
RIGHT OUTER JOIN pompier ON aCis = pCis AND aPompier=pId
|
|
WHERE aCis=" . $_SESSION['cis'];
|
|
|
|
if ($pompier <> "*") {
|
|
$req .= " AND aPompier=" . $pompier;
|
|
}
|
|
$req .= " AND aDateGarde BETWEEN '" . $debut . "' AND '" . $fin . "'
|
|
AND aDisponibilite>0
|
|
ORDER BY aPompier, aDateGarde ASC, aTranche ASC;";
|
|
$rs = PdoBD::$monPdo->query($req);
|
|
|
|
if ($rs === false) {
|
|
afficherErreurSQL("Probleme lors de la lecture des gardes d'un pompier...", $req, PdoBD::$monPdo->errorInfo());
|
|
}
|
|
$lesLignes = $rs->fetchAll();
|
|
$lesDispos = array();
|
|
|
|
if ($pompier <> "*") {
|
|
for ($jour = 0; $jour <= 6; $jour++) {
|
|
$laDate = date('d/m/Y', strtotime('+' . $jour . ' day', $premierJour));
|
|
$lesDispos[$pompier][$laDate] = array(
|
|
'dPompier' => $pompier,
|
|
'dDate' => $laDate,
|
|
'd1' => 0,
|
|
'd2' => 0,
|
|
'd3' => 0,
|
|
'd4' => 0,
|
|
'g1' => 0,
|
|
'g2' => 0,
|
|
'g3' => 0,
|
|
'g4' => 0,
|
|
'c1' => 'red',
|
|
'c2' => 'red',
|
|
'c3' => 'red',
|
|
'c4' => 'red'
|
|
);
|
|
}
|
|
} else {
|
|
$req = "SELECT pCis, pId, pNom, pPrenom, pStatut
|
|
FROM pompier
|
|
WHERE pCis=" . $_SESSION['cis'] . "
|
|
ORDER BY pNom, pPrenom;";
|
|
$rs = PdoBD::$monPdo->query($req);
|
|
if ($rs === false) {
|
|
afficherErreurSQL("Probleme lors de la lecture des pompiers ..", $req, PdoBD::$monPdo->errorInfo());
|
|
}
|
|
$lesPompiers = $rs->fetchAll();
|
|
|
|
foreach ($lesPompiers as $unPompier) {
|
|
$pompier = $unPompier['pId'];
|
|
for ($jour = 0; $jour <= 6; $jour++) {
|
|
$laDate = date('d/m/Y', strtotime('+' . $jour . ' day', $premierJour));
|
|
$lesDispos[$pompier][$laDate] = array(
|
|
'dPompier' => $pompier,
|
|
'dDate' => $laDate,
|
|
'd1' => 0,
|
|
'd2' => 0,
|
|
'd3' => 0,
|
|
'd4' => 0,
|
|
'g1' => 0,
|
|
'g2' => 0,
|
|
'g3' => 0,
|
|
'g4' => 0,
|
|
'c1' => 'red',
|
|
'c2' => 'red',
|
|
'c3' => 'red',
|
|
'c4' => 'red'
|
|
);
|
|
}
|
|
}
|
|
}
|
|
foreach ($lesLignes as $uneLigne) {
|
|
$pompier = $uneLigne['pId'];
|
|
$laDate = $uneLigne['wDate'];
|
|
$dispo = "d" . $uneLigne['aTranche'];
|
|
$garde = "g" . $uneLigne['aTranche'];
|
|
$couleur = "c" . $uneLigne['aTranche'];
|
|
$lesDispos[$pompier][$laDate][$dispo] = $uneLigne['aDisponibilite'];
|
|
$lesDispos[$pompier][$laDate][$garde] = $uneLigne['aGarde'];
|
|
$lesDispos[$pompier][$laDate][$couleur] = $uneLigne['dCouleur'];
|
|
}
|
|
/* echo "<PRE>";
|
|
print_r($lesDispos);
|
|
echo "</PRE>";*/
|
|
return $lesDispos;
|
|
}
|
|
|
|
/**
|
|
* Retourne dans un tableau associatif les informations de la table tranche
|
|
*/
|
|
public function getLesTranches()
|
|
{
|
|
$req = "SELECT pIndice as tId, pLibelle as tLibelle
|
|
FROM parametre WHERE pType='tranche'
|
|
ORDER by 1;";
|
|
$rs = PdoBD::$monPdo->query($req);
|
|
if ($rs === false) {
|
|
afficherErreurSQL("Probleme lors de la recherche des tranches dans la base de données.", $req, PdoBD::$monPdo->errorInfo());
|
|
}
|
|
$lesLignes = $rs->fetchAll();
|
|
return $lesLignes;
|
|
}
|
|
|
|
/**
|
|
* Retourne les informations de la table typeParametre
|
|
*/
|
|
public function getLesParametres()
|
|
{
|
|
$req = "SELECT tpId, tpLibelle, tpBooleen, tpChoixMultiple
|
|
FROM typeParametre
|
|
ORDER BY tpLibelle;";
|
|
$rs = PdoBD::$monPdo->query($req);
|
|
$lesLignes = $rs->fetchAll();
|
|
return $lesLignes;
|
|
}
|
|
|
|
/**
|
|
* Retourne dans un tableau associatif les informations de la table PARAMETRE (pour un type particulier)
|
|
*/
|
|
public function getParametre($type)
|
|
{
|
|
$req = "SELECT pIndice, pLibelle, pValeur, pPlancher, pPlafond ";
|
|
if ($type == "typePer") {
|
|
$req .= ",(SELECT count(*) FROM parametre p INNER JOIN pompier on p.pIndice=pompier.pType WHERE p.pType='$type' AND p.pIndice=parametre.pIndice) as nb";
|
|
} elseif ($type == "statAgt") {
|
|
$req .= ",(SELECT count(*) FROM parametre p INNER JOIN pompier on p.pIndice=pompier.pStatut WHERE p.pType='$type' AND p.pIndice=parametre.pIndice) as nb";
|
|
} elseif ($type == "grade") {
|
|
$req .= ",(SELECT count(*) FROM parametre p INNER JOIN pompier on p.pIndice=pompier.pgrade WHERE p.pType='$type' AND p.pIndice=parametre.pIndice) as nb";
|
|
} else {
|
|
$req .= ", 0 as nb";
|
|
}
|
|
$req .= " FROM parametre
|
|
WHERE pType='$type'
|
|
ORDER by pIndice;";
|
|
$rs = PdoBD::$monPdo->query($req);
|
|
if ($rs === false) {
|
|
afficherErreurSQL("Probleme lors de la recherche des parametres " . $type . " dans la base de données.", $req, PdoBD::$monPdo->errorInfo());
|
|
}
|
|
$lesLignes = $rs->fetchAll();
|
|
return $lesLignes;
|
|
}
|
|
|
|
/**
|
|
* Retourne dans un tableau associatifles informations de la table PARAMETRE (pour un type particulier)
|
|
*/
|
|
public function getInfosParam($type, $valeur)
|
|
{
|
|
if ($valeur == "NULL") {
|
|
$req = "SELECT pType, max(pIndice)+1 AS pIndice, ' ' AS pLibelle, tpLibelle
|
|
FROM parametre INNER JOIN typeParametre ON typeParametre.tpId=parametre.pType
|
|
WHERE pType='$type';";
|
|
} else {
|
|
$req = "SELECT pType, pIndice, pLibelle, tpLibelle, pPlancher, pPlafond
|
|
FROM parametre INNER JOIN typeParametre ON typeParametre.tpId=parametre.pType
|
|
WHERE pType='$type'
|
|
AND pIndice='$valeur';";
|
|
}
|
|
$rs = PdoBD::$monPdo->query($req);
|
|
$ligne = $rs->fetch();
|
|
return $ligne;
|
|
}
|
|
|
|
/**
|
|
* Met a jour une ligne de la table PARAMETRE
|
|
*/
|
|
public function majParametre($type, $valeur, $libelle, $plancher, $plafond)
|
|
{
|
|
$req = "UPDATE parametre SET pLibelle='$libelle', pPlancher='$plancher', pPlafond='$plafond'
|
|
WHERE pType='$type'
|
|
AND pIndice=$valeur;";
|
|
$rs = PdoBD::$monPdo->exec($req);
|
|
if ($rs === false) {
|
|
afficherErreurSQL("Probleme lors de la modification d'un parametre dans la base de données.", $req, PdoBD::$monPdo->errorInfo());
|
|
}
|
|
}
|
|
|
|
/**
|
|
* supprime une ligne de la table PARAMETRE
|
|
*/
|
|
public function supprimeParametre($type, $valeur)
|
|
{
|
|
$req = "DELETE
|
|
FROM parametre
|
|
WHERE pType='$type'
|
|
AND pIndice=$valeur;";
|
|
$rs = PdoBD::$monPdo->exec($req);
|
|
if ($rs === false) {
|
|
afficherErreurSQL("Probleme lors de la suppression d'un parametre dans la base de données.", $req, PdoBD::$monPdo->errorInfo());
|
|
}
|
|
}
|
|
|
|
/**
|
|
* ajoute une ligne dans la table PARAMETRE
|
|
*/
|
|
public function ajoutParametre($type, $valeur, $libelle, $plancher, $plafond)
|
|
{
|
|
$req = "INSERT INTO parametre
|
|
(pType, pIndice, pLibelle, pPlancher, pPlafond)
|
|
VALUES ('$type', $valeur, '$libelle', $plancher, $plafond);";
|
|
$rs = PdoBD::$monPdo->exec($req);
|
|
if ($rs === false) {
|
|
afficherErreurSQL("Probleme lors de l'insertion d'un parametre dans la base de données.", $req, PdoBD::$monPdo->errorInfo());
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
* envoyer un message electronique
|
|
*/
|
|
public function envoyerMail($mail, $sujet, $msg, $entete)
|
|
{
|
|
if (mail($mail, $sujet, $msg, null) == false) {
|
|
echo 'Suite à un problème technique, votre message n a pas été envoyé a ' . $mail . ' sujet' . $sujet . 'message ' . $msg . ' entete ' . $entete;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Retourne les informations d'une intervention
|
|
*/
|
|
public function getInfosIntervention($intervention)
|
|
{
|
|
$req = "SELECT iCis, iId, iLieu, iDescription, iDate , iTranche, iHeureDebut, iHeureFin
|
|
FROM intervention
|
|
WHERE iId=" . $intervention . ";";
|
|
$rs = PdoBD::$monPdo->query($req);
|
|
if ($rs === false) {
|
|
afficherErreurSQL("Probleme lors de la lecture de l'intervention ...", $req, PdoBD::$monPdo->errorInfo());
|
|
}
|
|
$lesLignes = $rs->fetchAll();
|
|
return $lesLignes;
|
|
}
|
|
|
|
/**
|
|
* Retourne les informations de toutes les interventions d'une caserne
|
|
*/
|
|
public function getLesInterventions($cis)
|
|
{
|
|
$req = "SELECT iCis, iId, iLieu, iDescription, iDate , iTranche, iHeureDebut, iHeureFin
|
|
FROM intervention
|
|
WHERE iCis=" . $cis . "
|
|
ORDER BY iId;";
|
|
$rs = PdoBD::$monPdo->query($req);
|
|
if ($rs === false) {
|
|
afficherErreurSQL("Probleme lors de la lecture des interventions de la caserne ...", $req, PdoBD::$monPdo->errorInfo());
|
|
}
|
|
$lesLignes = $rs->fetchAll();
|
|
return $lesLignes;
|
|
}
|
|
|
|
/**
|
|
* Retourne les participants à une intervention
|
|
*/
|
|
public function getLesParticipants($cis, $intervention)
|
|
{
|
|
$req = "SELECT pId, pNom, pPrenom
|
|
FROM pompier INNER JOIN equipe ON pompier.pId=equipe.ePompier AND pompier.pCis=equipe.eCis
|
|
WHERE eIntervention=" . $intervention . "
|
|
AND eCis=" . $cis . "
|
|
ORDER BY pNom, pPrenom;";
|
|
$rs = PdoBD::$monPdo->query($req);
|
|
if ($rs === false) {
|
|
afficherErreurSQL("Probleme lors de la lecture des participants ..", $req, PdoBD::$monPdo->errorInfo());
|
|
}
|
|
$lesLignes = $rs->fetchAll();
|
|
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;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 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 : nbUtilisation
|
|
//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();
|
|
}
|
|
|
|
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();
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
/**
|
|
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;
|
|
*/
|
|
?>
|