creation du crud et du controllers pour opérations.php et ajout dans le index

This commit is contained in:
kylian prebost 2026-06-08 14:14:58 +02:00
commit dee50a7335
5 changed files with 94 additions and 61 deletions

View file

@ -0,0 +1,45 @@
<?php
require 'model.php';
$couleurs = [
'Sauveteur disponible' => '#2ecc71',
'Sauveteur en approche de la cavité' => '#9b59b6',
'Sauveteur sous terre' => '#8B4513',
'Sauveteur équipe de gestion' => '#f1c40f',
"Sauveteur en mission à l'extérieur" => '#e67e22',
'Sauveteur en repos' => '#3498db',
'Sauveteur en brancardage civière' => '#e74c3c',
];
$creneaux = [];
for ($min = 8 * 60; $min < 20 * 60; $min += 30) {
$creneaux[] = sprintf('%02d:%02d', intdiv($min, 60), $min % 60);
}
// Indexer les sauveteurs par ID pour accès rapide à la spécialité
$sauveteursById = [];
foreach ($sauveteurs as $s) {
$sauveteursById[$s['ID_Sauveteur']] = $s;
$grille[$s['ID_Sauveteur']]= array_fill_keys($creneaux, false);
}
foreach ($missions as $m) {
$id = $m['ID_Sauveteur'];
if (!isset($grille[$id])) continue;
$specialite = $sauveteursById[$id]['Specialite'] ?? '';
$couleur = $couleurs[$specialite] ?? '#cccccc';
$debut = new DateTime($m['DtaHeureDebut']);
$fin = new DateTime($m['DtaHeureFin']);
foreach ($creneaux as $c) {
$debutCreneau = new DateTime($date . ' ' . $c . ':00');
$finCreneau = (clone $debutCreneau)->modify('+30 minutes');
if ($debut < $finCreneau && $fin > $debutCreneau) {
$grille[$id][$c] = $couleur;
}
}
}
require 'view.php';

View file

@ -70,10 +70,21 @@
operations_form_ctrl();
break;
<<<<<<< HEAD
case 'add_operation':
require('controllers/operation_ctrl.php');
add_operation_write_ctrl();
break;
=======
case 'lecture':
require('views/lecture_page.php');
break;
case 'lecture_ctrl':
require('controllers/lecture_page_ctrl.php');
break;
>>>>>>> c98d36d6ee22b1cc45aaf2d55c29677ea8c56d65
default:
require('views/404_view.php');
break;

1
lecture_page_model Normal file
View file

@ -0,0 +1 @@

View file

@ -0,0 +1,12 @@
<?php
$pdo = new PDO('mysql:host=localhost;dbname=projet3_tp1;charset=utf8mb4', 'root', '');
$date = $_GET['date'] ?? date('Y-m-d');
$sauveteurs = $pdo->query('SELECT ID_Sauveteur, Nom, Prenom, Specialite FROM Sauveteur ORDER BY Nom, Prenom')->fetchAll(PDO::FETCH_ASSOC);
$stmt = $pdo->prepare('SELECT ID_Mission, DtaHeureDebut, DtaHeureFin, ID_Sauveteur FROM Mission WHERE DATE(DtaHeureDebut) = ? OR DATE(DtaHeureFin) = ?');
$stmt->execute([$date, $date]);
$missions = $stmt->fetchAll(PDO::FETCH_ASSOC);

View file

@ -1,63 +1,27 @@
<?php
require('views/header.php');
<!DOCTYPE html>
<html lang="fr">
<head><meta charset="UTF-8"><title>Planning</title></head>
<body>
<h2>Planning du <?= $date ?></h2>
<table border="1">
<tr>
<th>Nom / Prénom</th>
<?php foreach ($creneaux as $c): ?>
<th><?= $c ?></th>
<?php endforeach; ?>
</tr>
<?php foreach ($sauveteurs as $s): ?>
<tr>
<td><?= $s['Nom'] ?> <?= $s['Prenom'] ?></td>
<?php foreach ($creneaux as $c):
$couleur = $grille[$s['ID_Sauveteur']][$c];
?>
<form action="index.php?route=lecture" method="post">
<table border="1" cellpadding="8" cellspacing="0">
<thead>
<tr>
<th>Personnes</th>
<th> - </th>
<th> - </th>
<th> - </th>
<th> - </th>
<th> - </th>
<th> - </th>
<td <?= $couleur ? 'bgcolor="' . $couleur . '"' : '' ?>></td>
<?php endforeach; ?>
</tr>
</thead>
<tbody>
<tr>
<td><input type="text" size="15" maxlength="100"/></td>
<td><input type="text" size="15" maxlength="100"/></td>
<td><input type="text" size="15" maxlength="100"/></td>
<td><input type="text" size="15" maxlength="100"/></td>
<td><input type="text" size="15" maxlength="100"/></td>
<td><input type="text" size="15" maxlength="100"/></td>
<td><input type="text" size="15" maxlength="100"/></td>
</tr>
<tr>
<td><input type="text" size="15" maxlength="100"/></td>
<td><input type="text" size="15" maxlength="100"/></td>
<td><input type="text" size="15" maxlength="100"/></td>
<td><input type="text" size="15" maxlength="100"/></td>
<td><input type="text" size="15" maxlength="100"/></td>
<td><input type="text" size="15" maxlength="100"/></td>
<td><input type="text" size="15" maxlength="100"/></td>
</tr>
<tr>
<td><input type="text" size="15" maxlength="100"/></td>
<td><input type="text" size="15" maxlength="100"/></td>
<td><input type="text" size="15" maxlength="100"/></td>
<td><input type="text" size="15" maxlength="100"/></td>
<td><input type="text" size="15" maxlength="100"/></td>
<td><input type="text" size="15" maxlength="100"/></td>
<td><input type="text" size="15" maxlength="100"/></td>
</tr>
<tr>
<td><input type="text" size="15" maxlength="100"/></td>
<td><input type="text" size="15" maxlength="100"/></td>
<td><input type="text" size="15" maxlength="100"/></td>
<td><input type="text" size="15" maxlength="100"/></td>
<td><input type="text" size="15" maxlength="100"/></td>
<td><input type="text" size="15" maxlength="100"/></td>
<td><input type="text" size="15" maxlength="100"/></td>
</tr>
</tbody>
<?php endforeach; ?>
</table>
</form>
<?php
require('views/footer.php');
?>
</body>
</html>