summaryrefslogtreecommitdiff
path: root/src/controller/ajax_calendar_admin.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/controller/ajax_calendar_admin.php')
-rw-r--r--src/controller/ajax_calendar_admin.php54
1 files changed, 0 insertions, 54 deletions
diff --git a/src/controller/ajax_calendar_admin.php b/src/controller/ajax_calendar_admin.php
deleted file mode 100644
index 0baf73e..0000000
--- a/src/controller/ajax_calendar_admin.php
+++ /dev/null
@@ -1,54 +0,0 @@
1<?php
2// src/controller/ajax_calendar_admin.php
3
4declare(strict_types=1);
5
6use App\Entity\Event;
7
8// actions sur le calendrier
9if(isset($_SESSION['admin']) && $_SESSION['admin'] === true
10 && $_SERVER['REQUEST_METHOD'] === 'POST' && $_SERVER['CONTENT_TYPE'] === 'application/json')
11{
12 $data = file_get_contents('php://input');
13 $json = json_decode($data, true);
14
15 if($_GET['action'] === 'new_event'){
16 try{
17 $event = new Event($json);
18 }
19 catch(InvalidArgumentException $e){
20 echo json_encode(['success' => false, 'error' => $e->getMessage()]);
21 http_response_code(400);
22 die;
23 }
24 $entityManager->persist($event);
25 $entityManager->flush();
26
27 echo json_encode(['success' => true, 'id' => $event->getId()]);
28 }
29 elseif($_GET['action'] === 'update_event'){
30 $event = $entityManager->find('App\Entity\Event', (int)$json['id']);
31 try{
32 $event->securedUpdateFromJSON($json);
33 }
34 catch(InvalidArgumentException $e){
35 echo json_encode(['success' => false, 'error' => $e->getMessage()]);
36 http_response_code(400);
37 die;
38 }
39 $entityManager->flush();
40
41 echo json_encode(['success' => true]);
42 }
43 elseif($_GET['action'] === 'remove_event'){
44 $event = $entityManager->find('App\Entity\Event', (int)$json['id']);
45 $entityManager->remove($event);
46 $entityManager->flush();
47
48 echo json_encode(['success' => true]);
49 }
50 else{
51 echo json_encode(['success' => false]);
52 }
53 die;
54} \ No newline at end of file