From f007bac3b9172711dc0fcca1306270ab99dbd8a4 Mon Sep 17 00:00:00 2001 From: polo Date: Tue, 24 Jun 2025 01:04:35 +0200 Subject: =?UTF-8?q?am=C3=A9lioration=20affichage,=20contr=C3=B4le=20des=20?= =?UTF-8?q?entr=C3=A9es?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controller/calendar.php | 133 ++++++++++++++++++++++++++------------------ 1 file changed, 80 insertions(+), 53 deletions(-) (limited to 'src/controller/calendar.php') diff --git a/src/controller/calendar.php b/src/controller/calendar.php index ab2832e..c15141a 100644 --- a/src/controller/calendar.php +++ b/src/controller/calendar.php @@ -1,12 +1,31 @@ 1, - 'title' => 'Évènement1', - 'start' => '2025-06-03T05:00:00Z', // Z indique que l'heure est en UTC - 'end' => '2025-06-03T09:00:00Z', - 'allDay' => false, - 'color' => '#ffa500', // couleur hexa, éviter les couleurs CSS qui ne fonctionnent pas dans value="" en HTML - //'url' => 'https://dev.nageurs-bigoudens.fr', // comportement: https://fullcalendar.io/docs/eventClick - 'description' => 'blablabla', + 'id' => 1, + 'title' => 'Évènement1', + 'description' => 'blablabla', + 'start' => '2025-06-03T05:00:00Z', // Z indique que l'heure est en UTC + 'end' => '2025-06-03T09:00:00Z', + 'allDay' => false, + 'color' => '#ffa500', // couleur hexa, éviter les couleurs CSS qui ne fonctionnent pas dans value="" en HTML + //'url' => 'https://dev.nageurs-bigoudens.fr', // comportement: https://fullcalendar.io/docs/eventClick ], [ - 'id' => 2, - 'title' => 'Évènement2', - 'start' => '2025-06-06T08:00:00Z', - 'end' => '2025-06-07T08:00:00Z', - 'allDay' => false, - 'color' => '#e01b24', - 'description' => 'truc machin', + 'id' => 2, + 'title' => 'Évènement2', + 'description' => 'truc machin', + 'start' => '2025-06-06T08:00:00Z', + 'end' => '2025-06-07T08:00:00Z', + 'allDay' => false, + 'color' => '#e01b24', ], [ - 'id' => 3, - 'title' => 'Évènement3', - 'start' => '2025-06-08', - 'end' => '2025-06-09', - 'allDay' => true, // pas d'heure - 'color' => '#008000', - 'description' => 'ça va chier', + 'id' => 3, + 'title' => 'Évènement3', + 'description' => 'ça va chier', + 'start' => '2025-06-08', + 'end' => '2025-06-09', + 'allDay' => true, // pas d'heure + 'color' => '#008000', ], - // provoque une erreur, si allDay la fin ne peut être égale au début - /*[ - 'id' => 4, - 'title' => 'Évènement4', - 'start' => '2025-06-09', - 'end' => '2025-06-09', - 'allDay' => true, - 'color' => '#1a5fb4', - ],*/ ]; header('Content-Type: application/json'); @@ -71,29 +81,46 @@ if($_SERVER['REQUEST_METHOD'] === 'GET' && isset($_GET['action']) && $_GET['acti // actions sur le calendrier elseif(isset($_SESSION['admin']) && $_SESSION['admin'] === true - && $_SERVER['REQUEST_METHOD'] === 'POST' && $_SERVER['CONTENT_TYPE'] === 'application/json') + && $_SERVER['REQUEST_METHOD'] === 'POST' && $_SERVER['CONTENT_TYPE'] === 'application/json') { - $data = file_get_contents('php://input'); - $json = json_decode($data, true); - - if($_GET['action'] === 'new_event'){ - // BDD - //print_r($json);die; - $id = 7; // généré par la BDD - echo json_encode(['success' => true, 'id' => $id]); + $data = file_get_contents('php://input'); + $json = json_decode($data, true); + + if($_GET['action'] === 'new_event'){ + try{ + $json = cleanInput($json); } - elseif($_GET['action'] === 'update_event'){ - // BDD - //print_r($json);die; - echo json_encode(['success' => true]); + catch(InvalidArgumentException $e){ + echo json_encode(['success' => false, 'error' => $e->getMessage()]); + http_response_code(400); + die; } - elseif($_GET['action'] === 'remove_event'){ - // BDD - //echo $json['id']; die; - echo json_encode(['success' => true]); + //print_r($json);die; + + $id = 7; // généré par la BDD + echo json_encode(['success' => true, 'id' => $id]); + } + elseif($_GET['action'] === 'update_event'){ + try{ + $json = cleanInput($json); } - else{ - echo json_encode(['success' => false]); + catch(InvalidArgumentException $e){ + echo json_encode(['success' => false, 'error' => $e->getMessage()]); + http_response_code(400); + die; } - die; -} \ No newline at end of file + //print_r($json);die; + + echo json_encode(['success' => true]); + } + elseif($_GET['action'] === 'remove_event'){ + $json['id'] = (int)$json['id']; + //echo $json['id']; die; + + echo json_encode(['success' => true]); + } + else{ + echo json_encode(['success' => false]); + } + die; +} -- cgit v1.2.3