2019-10-29 14:57:13 +01:00
|
|
|
<?php
|
2019-10-30 00:30:39 +01:00
|
|
|
|
|
|
|
/*
|
2019-11-10 17:48:54 +01:00
|
|
|
* This file is part of RaspiSMS.
|
2019-10-30 00:30:39 +01:00
|
|
|
*
|
2019-11-10 17:48:54 +01:00
|
|
|
* (c) Pierre-Lin Bonnemaison <plebwebsas@gmail.com>
|
2019-10-30 00:30:39 +01:00
|
|
|
*
|
2019-11-10 17:48:54 +01:00
|
|
|
* This source file is subject to the GPL-3.0 license that is bundled
|
2019-10-30 00:30:39 +01:00
|
|
|
* with this source code in the file LICENSE.
|
|
|
|
*/
|
|
|
|
|
2019-10-29 14:57:13 +01:00
|
|
|
namespace controllers\publics;
|
2019-10-29 18:36:25 +01:00
|
|
|
|
|
|
|
/**
|
2019-10-30 00:30:39 +01:00
|
|
|
* Page des events.
|
2019-10-29 18:36:25 +01:00
|
|
|
*/
|
|
|
|
class Event extends \descartes\Controller
|
|
|
|
{
|
2019-10-30 00:17:10 +01:00
|
|
|
private $internal_event;
|
|
|
|
|
2019-10-29 18:36:25 +01:00
|
|
|
/**
|
|
|
|
* Cette fonction est appelée avant toute les autres :
|
2019-10-30 00:30:39 +01:00
|
|
|
* Elle vérifie que l'utilisateur est bien connecté.
|
|
|
|
*
|
2019-10-29 18:36:25 +01:00
|
|
|
* @return void;
|
|
|
|
*/
|
2019-10-30 00:17:10 +01:00
|
|
|
public function __construct()
|
2019-10-29 14:57:13 +01:00
|
|
|
{
|
2019-10-30 00:17:10 +01:00
|
|
|
$bdd = \descartes\Model::_connect(DATABASE_HOST, DATABASE_NAME, DATABASE_USER, DATABASE_PASSWORD);
|
2019-10-30 00:30:39 +01:00
|
|
|
|
2019-10-30 00:17:10 +01:00
|
|
|
$this->internal_event = new \controllers\internals\Event($bdd);
|
2019-10-29 14:57:13 +01:00
|
|
|
|
2019-10-30 00:17:10 +01:00
|
|
|
\controllers\internals\Tool::verifyconnect();
|
2019-10-29 14:57:13 +01:00
|
|
|
}
|
|
|
|
|
2019-10-29 18:36:25 +01:00
|
|
|
/**
|
2019-10-30 00:30:39 +01:00
|
|
|
* Cette fonction retourne tous les events, sous forme d'un tableau permettant l'administration de ces events.
|
|
|
|
*
|
|
|
|
* @param mixed $page
|
2019-10-29 18:36:25 +01:00
|
|
|
*/
|
2020-04-07 03:02:33 +02:00
|
|
|
public function list()
|
2019-10-29 14:57:13 +01:00
|
|
|
{
|
2020-09-23 03:02:13 +02:00
|
|
|
$this->render('event/list');
|
|
|
|
}
|
2021-07-21 16:42:25 +02:00
|
|
|
|
2020-09-23 03:02:13 +02:00
|
|
|
/**
|
2021-01-14 03:32:17 +01:00
|
|
|
* Return events as json.
|
2020-09-23 03:02:13 +02:00
|
|
|
*/
|
|
|
|
public function list_json()
|
|
|
|
{
|
2021-07-21 16:42:25 +02:00
|
|
|
$draw = (int) ($_GET['draw'] ?? false);
|
|
|
|
|
|
|
|
$columns = [
|
|
|
|
0 => 'type',
|
|
|
|
1 => 'at',
|
|
|
|
2 => 'text',
|
|
|
|
3 => 'updated_at',
|
|
|
|
];
|
|
|
|
|
|
|
|
$search = $_GET['search']['value'] ?? null;
|
|
|
|
$order_column = $columns[$_GET['order'][0]['column']] ?? null;
|
|
|
|
$order_desc = ($_GET['order'][0]['dir'] ?? 'asc') == 'desc' ? true : false;
|
|
|
|
$offset = (int) ($_GET['start'] ?? 0);
|
|
|
|
$limit = (int) ($_GET['length'] ?? 25);
|
|
|
|
|
|
|
|
$entities = $this->internal_event->datatable_list_for_user($_SESSION['user']['id'], $limit, $offset, $search, $columns, $order_column, $order_desc);
|
|
|
|
$count_entities = $this->internal_event->datatable_list_for_user($_SESSION['user']['id'], $limit, $offset, $search, $columns, $order_column, $order_desc, true);
|
2020-09-23 03:02:13 +02:00
|
|
|
foreach ($entities as &$entity)
|
|
|
|
{
|
|
|
|
$entity['icon'] = \controllers\internals\Tool::event_type_to_icon($entity['type']);
|
|
|
|
}
|
|
|
|
|
2021-07-21 16:42:25 +02:00
|
|
|
$records_total = $this->internal_event->count_for_user($_SESSION['user']['id']);
|
|
|
|
|
2020-09-23 03:02:13 +02:00
|
|
|
header('Content-Type: application/json');
|
2021-07-21 16:42:25 +02:00
|
|
|
echo json_encode([
|
|
|
|
'draw' => $draw,
|
|
|
|
'recordsTotal' => $records_total,
|
|
|
|
'recordsFiltered' => $count_entities,
|
|
|
|
'data' => $entities,
|
|
|
|
]);
|
2019-10-29 18:36:25 +01:00
|
|
|
}
|
2019-10-30 00:30:39 +01:00
|
|
|
|
2019-10-29 18:36:25 +01:00
|
|
|
/**
|
2019-10-30 00:30:39 +01:00
|
|
|
* Cette fonction va supprimer une liste de events.
|
|
|
|
*
|
2019-10-29 14:57:13 +01:00
|
|
|
* @param array int $_GET['ids'] : Les id des eventes à supprimer
|
2019-10-30 00:30:39 +01:00
|
|
|
* @param mixed $csrf
|
|
|
|
*
|
2019-10-29 14:57:13 +01:00
|
|
|
* @return boolean;
|
|
|
|
*/
|
2019-10-29 18:36:25 +01:00
|
|
|
public function delete($csrf)
|
2019-10-29 14:57:13 +01:00
|
|
|
{
|
2019-10-30 00:30:39 +01:00
|
|
|
if (!$this->verify_csrf($csrf))
|
|
|
|
{
|
2019-11-09 03:35:12 +01:00
|
|
|
\FlashMessage\FlashMessage::push('danger', 'Jeton CSRF invalid !');
|
2019-11-06 20:34:26 +01:00
|
|
|
|
2019-10-30 00:17:10 +01:00
|
|
|
return $this->redirect(\descartes\Router::url('Event', 'list'));
|
2019-10-29 14:57:13 +01:00
|
|
|
}
|
2021-01-14 03:32:17 +01:00
|
|
|
|
2020-09-23 03:02:13 +02:00
|
|
|
if (!\controllers\internals\Tool::is_admin())
|
|
|
|
{
|
|
|
|
\FlashMessage\FlashMessage::push('danger', 'Vous devez être administrateur pour supprimer un event !');
|
|
|
|
|
|
|
|
return $this->redirect(\descartes\Router::url('Event', 'list'));
|
|
|
|
}
|
2019-10-30 00:30:39 +01:00
|
|
|
|
2019-10-29 14:57:13 +01:00
|
|
|
$ids = $_GET['ids'] ?? [];
|
2019-10-30 00:30:39 +01:00
|
|
|
foreach ($ids as $id)
|
|
|
|
{
|
2019-11-14 22:33:00 +01:00
|
|
|
$this->internal_event->delete_for_user($_SESSION['user']['id'], $id);
|
2019-10-29 14:57:13 +01:00
|
|
|
}
|
|
|
|
|
2019-10-30 00:17:10 +01:00
|
|
|
return $this->redirect(\descartes\Router::url('Event', 'list'));
|
2019-10-29 14:57:13 +01:00
|
|
|
}
|
2019-10-29 18:36:25 +01:00
|
|
|
}
|