diff options
| author | polo <ordipolo@gmx.fr> | 2025-06-24 23:57:59 +0200 |
|---|---|---|
| committer | polo <ordipolo@gmx.fr> | 2025-06-24 23:57:59 +0200 |
| commit | 7a13d53e43c7db7fe39474208ffa54ba2906d308 (patch) | |
| tree | 5bb9af2935c0e7c753c5eace6d9e4538c739a383 /src/controller/ajax_calendar_admin.php | |
| parent | 41adf94ebf868232aa43fe9b8b80029896da9da7 (diff) | |
| download | cms-7a13d53e43c7db7fe39474208ffa54ba2906d308.tar.gz cms-7a13d53e43c7db7fe39474208ffa54ba2906d308.tar.bz2 cms-7a13d53e43c7db7fe39474208ffa54ba2906d308.zip | |
petites améliorations au système de mot de passe
Diffstat (limited to 'src/controller/ajax_calendar_admin.php')
| -rw-r--r-- | src/controller/ajax_calendar_admin.php | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/src/controller/ajax_calendar_admin.php b/src/controller/ajax_calendar_admin.php new file mode 100644 index 0000000..0baf73e --- /dev/null +++ b/src/controller/ajax_calendar_admin.php | |||
| @@ -0,0 +1,54 @@ | |||
| 1 | <?php | ||
| 2 | // src/controller/ajax_calendar_admin.php | ||
| 3 | |||
| 4 | declare(strict_types=1); | ||
| 5 | |||
| 6 | use App\Entity\Event; | ||
| 7 | |||
| 8 | // actions sur le calendrier | ||
| 9 | if(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 | ||
