diff options
Diffstat (limited to 'src/controller')
-rw-r--r-- | src/controller/ajax_calendar_admin.php (renamed from src/controller/ajax_calendar.php) | 37 | ||||
-rw-r--r-- | src/controller/ajax_calendar_visitor.php | 39 | ||||
-rw-r--r-- | src/controller/password.php | 16 | ||||
-rw-r--r-- | src/controller/post.php | 13 |
4 files changed, 58 insertions, 47 deletions
diff --git a/src/controller/ajax_calendar.php b/src/controller/ajax_calendar_admin.php index 79268f6..0baf73e 100644 --- a/src/controller/ajax_calendar.php +++ b/src/controller/ajax_calendar_admin.php | |||
@@ -1,45 +1,12 @@ | |||
1 | <?php | 1 | <?php |
2 | // src/controller/calendar.php | 2 | // src/controller/ajax_calendar_admin.php |
3 | 3 | ||
4 | declare(strict_types=1); | 4 | declare(strict_types=1); |
5 | 5 | ||
6 | use App\Entity\Event; | 6 | use App\Entity\Event; |
7 | 7 | ||
8 | // chargement des évènements à la création du calendrier | ||
9 | // et au changement de dates affichées (boutons flèches mais pas changement de vue) | ||
10 | if($_SERVER['REQUEST_METHOD'] === 'GET' && isset($_GET['action']) && $_GET['action'] === 'get_events' | ||
11 | && isset($_GET['start']) && isset($_GET['end']) && empty($_POST)) | ||
12 | { | ||
13 | // bornes début et fin du calendrier affiché à l'heure locale | ||
14 | // noter que la vue "planning" est similaire à la vue "semaine" | ||
15 | $start = new DateTime($_GET['start']); | ||
16 | $end = new DateTime($_GET['end']); | ||
17 | $start->setTimezone(new DateTimeZone('UTC')); | ||
18 | $end->setTimezone(new DateTimeZone('UTC')); | ||
19 | |||
20 | // affichage format ISO à l'heure UTC | ||
21 | //$date->format('Y-m-d\TH:i:s\Z'); | ||
22 | |||
23 | // on prend les évènements se finissant après le début ou commençant avant la fin de la fourchette | ||
24 | $dql = 'SELECT e FROM App\Entity\Event e WHERE e.end >= :start AND e.start <= :end'; | ||
25 | $bulk_data = $entityManager->createQuery($dql) | ||
26 | ->setParameter('start', $start) | ||
27 | ->setParameter('end', $end) | ||
28 | ->getResult(); | ||
29 | |||
30 | $events = []; | ||
31 | foreach($bulk_data as $one_entry){ | ||
32 | $event = new EventDTO($one_entry); | ||
33 | $events[] = $event->toArray(); | ||
34 | } | ||
35 | |||
36 | header('Content-Type: application/json'); | ||
37 | echo json_encode($events); | ||
38 | die; | ||
39 | } | ||
40 | |||
41 | // actions sur le calendrier | 8 | // actions sur le calendrier |
42 | elseif(isset($_SESSION['admin']) && $_SESSION['admin'] === true | 9 | if(isset($_SESSION['admin']) && $_SESSION['admin'] === true |
43 | && $_SERVER['REQUEST_METHOD'] === 'POST' && $_SERVER['CONTENT_TYPE'] === 'application/json') | 10 | && $_SERVER['REQUEST_METHOD'] === 'POST' && $_SERVER['CONTENT_TYPE'] === 'application/json') |
44 | { | 11 | { |
45 | $data = file_get_contents('php://input'); | 12 | $data = file_get_contents('php://input'); |
diff --git a/src/controller/ajax_calendar_visitor.php b/src/controller/ajax_calendar_visitor.php new file mode 100644 index 0000000..dcdbebd --- /dev/null +++ b/src/controller/ajax_calendar_visitor.php | |||
@@ -0,0 +1,39 @@ | |||
1 | <?php | ||
2 | // src/controller/ajax_calendar_visitor.php | ||
3 | |||
4 | declare(strict_types=1); | ||
5 | |||
6 | use App\Entity\Event; | ||
7 | |||
8 | // chargement des évènements à la création du calendrier | ||
9 | // et au changement de dates affichées (boutons flèches mais pas changement de vue) | ||
10 | if($_SERVER['REQUEST_METHOD'] === 'GET' && isset($_GET['action']) && $_GET['action'] === 'get_events' | ||
11 | && isset($_GET['start']) && isset($_GET['end']) && empty($_POST)) | ||
12 | { | ||
13 | // bornes début et fin du calendrier affiché à l'heure locale | ||
14 | // noter que la vue "planning" est similaire à la vue "semaine" | ||
15 | $start = new DateTime($_GET['start']); | ||
16 | $end = new DateTime($_GET['end']); | ||
17 | $start->setTimezone(new DateTimeZone('UTC')); | ||
18 | $end->setTimezone(new DateTimeZone('UTC')); | ||
19 | |||
20 | // affichage format ISO à l'heure UTC | ||
21 | //$date->format('Y-m-d\TH:i:s\Z'); | ||
22 | |||
23 | // on prend les évènements se finissant après le début ou commençant avant la fin de la fourchette | ||
24 | $dql = 'SELECT e FROM App\Entity\Event e WHERE e.end >= :start AND e.start <= :end'; | ||
25 | $bulk_data = $entityManager->createQuery($dql) | ||
26 | ->setParameter('start', $start) | ||
27 | ->setParameter('end', $end) | ||
28 | ->getResult(); | ||
29 | |||
30 | $events = []; | ||
31 | foreach($bulk_data as $one_entry){ | ||
32 | $event = new EventDTO($one_entry); | ||
33 | $events[] = $event->toArray(); | ||
34 | } | ||
35 | |||
36 | header('Content-Type: application/json'); | ||
37 | echo json_encode($events); | ||
38 | die; | ||
39 | } \ No newline at end of file | ||
diff --git a/src/controller/password.php b/src/controller/password.php index 5573a33..62b1542 100644 --- a/src/controller/password.php +++ b/src/controller/password.php | |||
@@ -86,7 +86,7 @@ function createPassword(EntityManager $entityManager) | |||
86 | } | 86 | } |
87 | else | 87 | else |
88 | { | 88 | { |
89 | $error = 'bad_password'; | 89 | $error = 'bad_login_or_password'; |
90 | 90 | ||
91 | // compteur dans la session et blocage de compte | 91 | // compteur dans la session et blocage de compte |
92 | } | 92 | } |
@@ -217,15 +217,6 @@ function changePassword(EntityManager $entityManager) | |||
217 | { | 217 | { |
218 | // fonction exécutée à priori deux fois d'affilée: affichage puis traitement de la saisie | 218 | // fonction exécutée à priori deux fois d'affilée: affichage puis traitement de la saisie |
219 | 219 | ||
220 | // OUT !! | ||
221 | if(empty($_SESSION['user']) || !$_SESSION['admin']) | ||
222 | { | ||
223 | $_SESSION['user'] = ''; | ||
224 | $_SESSION['admin'] = false; | ||
225 | header('Location: index.php'); | ||
226 | die; | ||
227 | } | ||
228 | |||
229 | // II - traitement | 220 | // II - traitement |
230 | $error = ''; | 221 | $error = ''; |
231 | $success = false; | 222 | $success = false; |
@@ -254,6 +245,9 @@ function changePassword(EntityManager $entityManager) | |||
254 | { | 245 | { |
255 | $error = 'forbidden_characters'; | 246 | $error = 'forbidden_characters'; |
256 | } | 247 | } |
248 | elseif($login !== $_SESSION['user']){ | ||
249 | $error = 'bad_login_or_password'; | ||
250 | } | ||
257 | else | 251 | else |
258 | { | 252 | { |
259 | $user = getUser($login, $entityManager); | 253 | $user = getUser($login, $entityManager); |
@@ -268,7 +262,7 @@ function changePassword(EntityManager $entityManager) | |||
268 | } | 262 | } |
269 | else | 263 | else |
270 | { | 264 | { |
271 | $error = 'bad_password'; | 265 | $error = 'bad_login_or_password'; |
272 | } | 266 | } |
273 | } | 267 | } |
274 | } | 268 | } |
diff --git a/src/controller/post.php b/src/controller/post.php index b0bc6a0..3ba0656 100644 --- a/src/controller/post.php +++ b/src/controller/post.php | |||
@@ -220,6 +220,14 @@ if($_SERVER['REQUEST_METHOD'] === 'POST' && $_SESSION['admin'] === true) | |||
220 | header("Location: " . new URL(['page' => $_GET['from']])); | 220 | header("Location: " . new URL(['page' => $_GET['from']])); |
221 | die; | 221 | die; |
222 | } | 222 | } |
223 | elseif(isset($_GET['action']) && $_GET['action'] === 'modif_mdp' | ||
224 | && isset($_POST['login']) && isset($_POST['old_password']) && isset($_POST['new_password']) | ||
225 | && isset($_POST['modify_password_hidden']) && empty($_POST['modify_password_hidden'])) | ||
226 | { | ||
227 | changePassword($entityManager); | ||
228 | header("Location: " . new URL(['page' => $_GET['from']])); | ||
229 | die; | ||
230 | } | ||
223 | else{ | 231 | else{ |
224 | header("Location: " . new URL(['error' => 'paramètres inconnus'])); | 232 | header("Location: " . new URL(['error' => 'paramètres inconnus'])); |
225 | die; | 233 | die; |
@@ -230,5 +238,8 @@ if($_SERVER['REQUEST_METHOD'] === 'POST' && $_SESSION['admin'] === true) | |||
230 | else{ | 238 | else{ |
231 | require '../src/controller/ajax.php'; | 239 | require '../src/controller/ajax.php'; |
232 | } | 240 | } |
241 | |||
242 | require '../src/controller/ajax_calendar_admin.php'; | ||
233 | } | 243 | } |
234 | require '../src/controller/ajax_calendar.php'; \ No newline at end of file | 244 | |
245 | require '../src/controller/ajax_calendar_visitor.php'; | ||