diff options
-rw-r--r-- | public/index.php | 1 | ||||
-rw-r--r-- | public/js/calendar.js | 6 | ||||
-rw-r--r-- | public/js/calendar_admin.js | 13 | ||||
-rw-r--r-- | src/controller/calendar.php (renamed from src/load-events.php) | 44 | ||||
-rw-r--r-- | src/post-ajax.php | 14 |
5 files changed, 52 insertions, 26 deletions
diff --git a/public/index.php b/public/index.php index abcef90..99220e8 100644 --- a/public/index.php +++ b/public/index.php | |||
@@ -1,6 +1,7 @@ | |||
1 | <?php | 1 | <?php |
2 | session_start(); | 2 | session_start(); |
3 | $_SESSION['admin'] = false; | 3 | $_SESSION['admin'] = false; |
4 | require '../src/controller/calendar.php'; | ||
4 | ?> | 5 | ?> |
5 | <!DOCTYPE html> | 6 | <!DOCTYPE html> |
6 | <html lang="fr"> | 7 | <html lang="fr"> |
diff --git a/public/js/calendar.js b/public/js/calendar.js index f1c55c4..2193272 100644 --- a/public/js/calendar.js +++ b/public/js/calendar.js | |||
@@ -1,3 +1,5 @@ | |||
1 | // js/calendar.js | ||
2 | |||
1 | document.addEventListener('DOMContentLoaded', function(){ | 3 | document.addEventListener('DOMContentLoaded', function(){ |
2 | const calendarEl = document.getElementById('calendar'); | 4 | const calendarEl = document.getElementById('calendar'); |
3 | let selected_start_string = null; | 5 | let selected_start_string = null; |
@@ -34,10 +36,12 @@ document.addEventListener('DOMContentLoaded', function(){ | |||
34 | allDayContent: 'Journée', // texte dans la case "toute la journée" | 36 | allDayContent: 'Journée', // texte dans la case "toute la journée" |
35 | nowIndicator: true, // barre rouge pour maintenant | 37 | nowIndicator: true, // barre rouge pour maintenant |
36 | 38 | ||
37 | events: '../src/load-events.php', // fichier PHP qui retourne les événements | 39 | // params en plus: https://fullcalendar.io/docs/events-json-feed |
40 | events: 'index.php?action=get_events', // fichier PHP qui retourne les événements | ||
38 | 41 | ||
39 | select: function(info){ | 42 | select: function(info){ |
40 | selected_start_string = info.startStr; // variable "globale" | 43 | selected_start_string = info.startStr; // variable "globale" |
44 | hideModal(); | ||
41 | }, | 45 | }, |
42 | //unselect: function(event, view){}, | 46 | //unselect: function(event, view){}, |
43 | 47 | ||
diff --git a/public/js/calendar_admin.js b/public/js/calendar_admin.js index 8fe91a3..a99b069 100644 --- a/public/js/calendar_admin.js +++ b/public/js/calendar_admin.js | |||
@@ -1,3 +1,5 @@ | |||
1 | // js/calendar_admin.js | ||
2 | |||
1 | document.addEventListener('DOMContentLoaded', function(){ | 3 | document.addEventListener('DOMContentLoaded', function(){ |
2 | const calendarEl = document.getElementById('calendar'); | 4 | const calendarEl = document.getElementById('calendar'); |
3 | let selected_start_string = null; | 5 | let selected_start_string = null; |
@@ -35,7 +37,8 @@ document.addEventListener('DOMContentLoaded', function(){ | |||
35 | allDayContent: 'Journée', // texte dans la case "toute la journée" | 37 | allDayContent: 'Journée', // texte dans la case "toute la journée" |
36 | nowIndicator: true, // barre rouge pour maintenant | 38 | nowIndicator: true, // barre rouge pour maintenant |
37 | 39 | ||
38 | events: '../src/load-events.php', // fichier PHP qui retourne les événements | 40 | // params en plus: https://fullcalendar.io/docs/events-json-feed |
41 | events: 'index.php?action=get_events', // fichier PHP qui retourne les événements | ||
39 | 42 | ||
40 | select: function(info){ | 43 | select: function(info){ |
41 | selected_start_string = info.startStr; // variable "globale" | 44 | selected_start_string = info.startStr; // variable "globale" |
@@ -220,7 +223,7 @@ document.addEventListener('DOMContentLoaded', function(){ | |||
220 | color: event_color | 223 | color: event_color |
221 | }; | 224 | }; |
222 | 225 | ||
223 | fetch('../src/post-ajax.php', { | 226 | fetch('index.php?action=new_event', { |
224 | method: 'POST', | 227 | method: 'POST', |
225 | headers: { | 228 | headers: { |
226 | 'Content-Type': 'application/json', | 229 | 'Content-Type': 'application/json', |
@@ -255,7 +258,7 @@ document.addEventListener('DOMContentLoaded', function(){ | |||
255 | color: event_color | 258 | color: event_color |
256 | }; | 259 | }; |
257 | 260 | ||
258 | fetch('../src/post-ajax.php', { | 261 | fetch('index.php?action=update_event', { |
259 | method: 'POST', | 262 | method: 'POST', |
260 | headers: { | 263 | headers: { |
261 | 'Content-Type': 'application/json', | 264 | 'Content-Type': 'application/json', |
@@ -318,12 +321,12 @@ document.addEventListener('DOMContentLoaded', function(){ | |||
318 | const event_id = document.getElementById('event_id').value; | 321 | const event_id = document.getElementById('event_id').value; |
319 | const event = calendar.getEventById(event_id); | 322 | const event = calendar.getEventById(event_id); |
320 | 323 | ||
321 | fetch('../src/post-ajax.php', { | 324 | fetch('index.php?action=remove_event', { |
322 | method: 'POST', | 325 | method: 'POST', |
323 | headers: { | 326 | headers: { |
324 | 'Content-Type': 'application/json', | 327 | 'Content-Type': 'application/json', |
325 | }, | 328 | }, |
326 | body: JSON.stringify(event_id), | 329 | body: JSON.stringify({'id': event_id}), |
327 | }) | 330 | }) |
328 | .then(response => response.json()) | 331 | .then(response => response.json()) |
329 | .then(data => { | 332 | .then(data => { |
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 | ||