107 lines
2.7 KiB
PHP
107 lines
2.7 KiB
PHP
<?php
|
|
declare (strict_types = 1);
|
|
|
|
require_once __DIR__ . '/../includes/init_secretaire.php';
|
|
|
|
header('Content-Type: application/json; charset=utf-8');
|
|
|
|
$compteId = (int) ($_SESSION['compte_id'] ?? 0);
|
|
$userRole = strtolower((string) ($_SESSION['role'] ?? ''));
|
|
$praticien_id = (int) ($_POST['praticien_id'] ?? 0);
|
|
|
|
if (($_SERVER['REQUEST_METHOD'] ?? '') !== 'POST') {
|
|
echo json_encode([
|
|
'ok' => false,
|
|
'message' => 'Méthode non autorisée.',
|
|
], JSON_UNESCAPED_UNICODE);
|
|
exit;
|
|
}
|
|
|
|
require_post_csrf();
|
|
|
|
if ($praticien_id <= 0 || $userRole !== 'secretaire') {
|
|
echo json_encode([
|
|
'ok' => false,
|
|
'message' => 'Accès refusé.',
|
|
], JSON_UNESCAPED_UNICODE);
|
|
exit;
|
|
}
|
|
|
|
// Vérifier pivot + droit can_edit_slots
|
|
$st = $pdo->prepare("
|
|
SELECT can_edit_slots
|
|
FROM secretaire_praticien
|
|
WHERE secretaire_user_id = :u
|
|
AND praticien_id = :p
|
|
AND is_active = 1
|
|
LIMIT 1
|
|
");
|
|
$st->execute([
|
|
'u' => $compteId,
|
|
'p' => $praticien_id,
|
|
]);
|
|
$pivot = $st->fetch(PDO::FETCH_ASSOC);
|
|
|
|
if (! $pivot || (int) $pivot['can_edit_slots'] !== 1) {
|
|
echo json_encode([
|
|
'ok' => false,
|
|
'message' => 'Permission insuffisante.',
|
|
], JSON_UNESCAPED_UNICODE);
|
|
exit;
|
|
}
|
|
|
|
$id = (int) ($_POST['id'] ?? 0);
|
|
if ($id <= 0) {
|
|
echo json_encode([
|
|
'ok' => false,
|
|
'message' => 'ID invalide.',
|
|
], JSON_UNESCAPED_UNICODE);
|
|
exit;
|
|
}
|
|
|
|
try {
|
|
$check = $pdo->prepare("
|
|
SELECT id, praticien_id
|
|
FROM disponibilite_date
|
|
WHERE id = ?
|
|
LIMIT 1
|
|
");
|
|
$check->execute([$id]);
|
|
$slot = $check->fetch(PDO::FETCH_ASSOC);
|
|
|
|
if (! $slot) {
|
|
echo json_encode([
|
|
'ok' => false,
|
|
'message' => 'Créneau introuvable.',
|
|
], JSON_UNESCAPED_UNICODE);
|
|
exit;
|
|
}
|
|
|
|
if ((int) $slot['praticien_id'] !== $praticien_id) {
|
|
echo json_encode([
|
|
'ok' => false,
|
|
'message' => 'Ce créneau ne correspond pas au praticien sélectionné.',
|
|
], JSON_UNESCAPED_UNICODE);
|
|
exit;
|
|
}
|
|
|
|
$stmt = $pdo->prepare("DELETE FROM disponibilite_date WHERE id = ? AND praticien_id = ?");
|
|
$stmt->execute([$id, $praticien_id]);
|
|
|
|
echo json_encode([
|
|
'ok' => ($stmt->rowCount() > 0),
|
|
'message' => $stmt->rowCount() > 0
|
|
? 'Créneau supprimé.'
|
|
: 'Aucune ligne supprimée.',
|
|
], JSON_UNESCAPED_UNICODE);
|
|
exit;
|
|
|
|
} catch (Throwable $e) {
|
|
error_log('cabinet/supprimer_disponibilite_date.php: ' . $e->getMessage());
|
|
echo json_encode([
|
|
'ok' => false,
|
|
'message' => 'Erreur serveur.',
|
|
], JSON_UNESCAPED_UNICODE);
|
|
exit;
|
|
}
|