diff options
| author | polo <ordipolo@gmx.fr> | 2025-06-21 01:44:16 +0200 |
|---|---|---|
| committer | polo <ordipolo@gmx.fr> | 2025-06-21 01:44:16 +0200 |
| commit | 8ee3440f204dfc6532a49a05719ba37a8c4df359 (patch) | |
| tree | 03dec8764e55d1a4e1983fcceea8ccd99686989a /src | |
| parent | f0e0b449f2bd6c4417e467b2903b29ad03a9626d (diff) | |
| download | fullcalendar-8ee3440f204dfc6532a49a05719ba37a8c4df359.tar.gz fullcalendar-8ee3440f204dfc6532a49a05719ba37a8c4df359.tar.bz2 fullcalendar-8ee3440f204dfc6532a49a05719ba37a8c4df359.zip | |
échanges client/serveur
Diffstat (limited to 'src')
| -rw-r--r-- | src/controller/calendar.php (renamed from src/load-events.php) | 44 | ||||
| -rw-r--r-- | src/post-ajax.php | 14 |
2 files changed, 38 insertions, 20 deletions
diff --git a/src/load-events.php b/src/controller/calendar.php index 5c71137..ab2832e 100644 --- a/src/load-events.php +++ b/src/controller/calendar.php | |||
| @@ -1,8 +1,12 @@ | |||
| 1 | <?php | 1 | <?php |
| 2 | // réception de deux paramètres GET: 'start' et 'end' | 2 | // src/controller/calendar.php |
| 3 | 3 | ||
| 4 | if(isset($_GET['start']) && isset($_GET['end']) && empty($_POST)){ | 4 | // chargement des évènements à la création du calendrier |
| 5 | // bornes début et fin du calendrier affiché à l'heure locale | 5 | // et au changement de dates affichées (boutons flèches mais pas changement de vue) |
| 6 | if($_SERVER['REQUEST_METHOD'] === 'GET' && isset($_GET['action']) && $_GET['action'] === 'get_events' | ||
| 7 | && isset($_GET['start']) && isset($_GET['end']) && empty($_POST)) | ||
| 8 | { | ||
| 9 | // bornes début et fin du calendrier affiché à l'heure locale | ||
| 6 | // noter que la vue "planning" est similaire à la vue "semaine" | 10 | // noter que la vue "planning" est similaire à la vue "semaine" |
| 7 | $start = new DateTime($_GET['start']); | 11 | $start = new DateTime($_GET['start']); |
| 8 | $end = new DateTime($_GET['end']); | 12 | $end = new DateTime($_GET['end']); |
| @@ -17,8 +21,8 @@ if(isset($_GET['start']) && isset($_GET['end']) && empty($_POST)){ | |||
| 17 | // affichage format ISO à l'heure UTC | 21 | // affichage format ISO à l'heure UTC |
| 18 | //$date->format('Y-m-d\TH:i:s\Z'); | 22 | //$date->format('Y-m-d\TH:i:s\Z'); |
| 19 | 23 | ||
| 20 | // chatgpt suggère l'utilisation d'un DTO | 24 | // chatgpt suggère l'utilisation d'un DTO => une classe de données simple et tout "public" |
| 21 | // => une classe de données simple et tout "public" pour des évènements obtenables autant depuis la BDD que de fichiers .ics par exemple | 25 | // => pour des évènements obtenables autant depuis la BDD que de fichiers .ics par exemple |
| 22 | 26 | ||
| 23 | $events = [ | 27 | $events = [ |
| 24 | [ | 28 | [ |
| @@ -62,6 +66,34 @@ if(isset($_GET['start']) && isset($_GET['end']) && empty($_POST)){ | |||
| 62 | 66 | ||
| 63 | header('Content-Type: application/json'); | 67 | header('Content-Type: application/json'); |
| 64 | echo json_encode($events); | 68 | echo json_encode($events); |
| 69 | die; | ||
| 65 | } | 70 | } |
| 66 | 71 | ||
| 67 | 72 | // actions sur le calendrier | |
| 73 | elseif(isset($_SESSION['admin']) && $_SESSION['admin'] === true | ||
| 74 | && $_SERVER['REQUEST_METHOD'] === 'POST' && $_SERVER['CONTENT_TYPE'] === 'application/json') | ||
| 75 | { | ||
| 76 | $data = file_get_contents('php://input'); | ||
| 77 | $json = json_decode($data, true); | ||
| 78 | |||
| 79 | if($_GET['action'] === 'new_event'){ | ||
| 80 | // BDD | ||
| 81 | //print_r($json);die; | ||
| 82 | $id = 7; // généré par la BDD | ||
| 83 | echo json_encode(['success' => true, 'id' => $id]); | ||
| 84 | } | ||
| 85 | elseif($_GET['action'] === 'update_event'){ | ||
| 86 | // BDD | ||
| 87 | //print_r($json);die; | ||
| 88 | echo json_encode(['success' => true]); | ||
| 89 | } | ||
| 90 | elseif($_GET['action'] === 'remove_event'){ | ||
| 91 | // BDD | ||
| 92 | //echo $json['id']; die; | ||
| 93 | echo json_encode(['success' => true]); | ||
| 94 | } | ||
| 95 | else{ | ||
| 96 | echo json_encode(['success' => false]); | ||
| 97 | } | ||
| 98 | die; | ||
| 99 | } \ No newline at end of file | ||
diff --git a/src/post-ajax.php b/src/post-ajax.php deleted file mode 100644 index bedfed5..0000000 --- a/src/post-ajax.php +++ /dev/null | |||
| @@ -1,14 +0,0 @@ | |||
| 1 | <?php | ||
| 2 | session_start(); | ||
| 3 | |||
| 4 | if(isset($_SESSION['admin']) && $_SESSION['admin'] === true && $_SERVER['REQUEST_METHOD'] === 'POST'){ // && $_SESSION['admin'] === true | ||
| 5 | if($_SERVER['CONTENT_TYPE'] === 'application/json'){ | ||
| 6 | $data = file_get_contents('php://input'); | ||
| 7 | $json = json_decode($data, true); | ||
| 8 | //var_dump($json); | ||
| 9 | |||
| 10 | $id = isset($json['id']) ? $json['id'] : 7; // = id_event en BDD si nouvel évènement | ||
| 11 | echo json_encode(['success' => true, 'id' => $id]); | ||
| 12 | die; | ||
| 13 | } | ||
| 14 | } \ No newline at end of file | ||
