Matériel

Réservations

Consultez les disponibilités et faites votre demande

Praticable gonfable

Nouvelle demande

SERVER['SCRIPT_NAME']), '/\\') . '/' ; $swal_script = ''; $materiels = []; $reservations = []; $blockedRanges = []; try { require_once __DIR__ . '/../../../modules/setting/database.php'; } catch (Throwable $e) {} if (isset($_GET['success'])) { $swal_script = "Swal.fire({title:'Demande envoyée !',text:'Votre demande a bien été transmise.',icon:'success',confirmButtonColor:'#E23650',timer:2500,timerProgressBar:true});"; } /* ── SOUMISSION ────────────────────────────────────────────────────── */ if ($_SERVER['REQUEST_METHOD'] === 'POST' && ($_POST['action'] ?? '') === 'demande_reservation' && isset($pdo)) { $materielId = (int)($_POST['materiel_id'] ?? 0); $dateDebut = trim($_POST['date_debut'] ?? ''); $dateFin = trim($_POST['date_fin'] ?? ''); $quantite = max(1, (int)($_POST['quantite'] ?? 1)); $commentaire = trim($_POST['commentaire'] ?? ''); $nomDem = trim($_POST['demandeur_nom'] ?? ''); $emailDem = trim($_POST['demandeur_email'] ?? ''); try { if ($materielId <= 0 || $dateDebut === '' || $dateFin === '' || $nomDem === '') { throw new RuntimeException("Champs obligatoires manquants."); } if ($dateFin < $dateDebut) { throw new RuntimeException("La date de fin doit être après la date de début."); } $chk = $pdo->prepare("SELECT COUNT(*) FROM reservation_demande WHERE materiel_id = :mid AND statut = 'acceptee' AND NOT (date_fin < :dd OR date_debut > :df)"); $chk->execute([':mid' => $materielId, ':dd' => $dateDebut, ':df' => $dateFin]); if ((int)$chk->fetchColumn() > 0) { throw new RuntimeException("Ce matériel est déjà réservé sur cette période. Choisissez d'autres dates."); } $pdo->prepare("INSERT INTO reservation_demande (materiel_id, user_id, demandeur_nom, demandeur_email, date_debut, date_fin, quantite, commentaire, statut, created_at) VALUES (:mid, NULL, :nom, :email, :dd, :df, :qt, :com, 'a_traiter', NOW())") ->execute([':mid' => $materielId, ':nom' => $nomDem, ':email' => $emailDem, ':dd' => $dateDebut, ':df' => $dateFin, ':qt' => $quantite, ':com' => $commentaire ?: null]); $base = rtrim(dirname($_SERVER['SCRIPT_NAME']), '/\\') . '/'; header('Location: ' . $base . 'index.php?page=reservations&success=1'); exit; } catch (Throwable $e) { $swal_script = "Swal.fire('Impossible de réserver','" . addslashes($e->getMessage()) . "','error');"; } } /* ── DONNÉES ────────────────────────────────────────────────────────── */ if (isset($pdo)) { try { $stmtM = $pdo->query("SELECT id, nom, prix_jour, caution FROM reservation_materiel WHERE actif = 1 ORDER BY nom ASC"); $materiels = $stmtM ? $stmtM->fetchAll(PDO::FETCH_ASSOC) : []; $stmtR = $pdo->query("SELECT d.id, d.materiel_id, d.date_debut, d.date_fin, d.quantite, m.nom AS materiel_nom FROM reservation_demande d JOIN reservation_materiel m ON m.id = d.materiel_id WHERE d.statut = 'acceptee' ORDER BY d.date_debut ASC"); $reservations = $stmtR ? $stmtR->fetchAll(PDO::FETCH_ASSOC) : []; } catch (Throwable $e) {} } $colors = ['#E23650','#923f95','#3d76c4','#10b981','#f59e0b','#8b5cf6','#ef4444','#06b6d4']; $matColors = []; foreach ($materiels as $i => $m) $matColors[$m['id']] = $colors[$i % count($colors)]; $blockedRanges = array_map(fn($r) => [ 'debut' => $r['date_debut'], 'fin' => $r['date_fin'], 'materiel_id' => (int)$r['materiel_id'], ], $reservations); ?> Réservations — GymPulse

Matériel

Réservations

Consultez les disponibilités et faites votre demande

Praticable gonfable

Nouvelle demande