2019-10-29 14:57:13 +01:00
|
|
|
<?php
|
2019-10-30 00:30:39 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* This file is part of PHP CS Fixer.
|
|
|
|
*
|
|
|
|
* (c) Fabien Potencier <fabien@symfony.com>
|
|
|
|
* Dariusz Rumiński <dariusz.ruminski@gmail.com>
|
|
|
|
*
|
|
|
|
* This source file is subject to the MIT license that is bundled
|
|
|
|
* 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 receiveds.
|
2019-10-29 18:36:25 +01:00
|
|
|
*/
|
|
|
|
class Received extends \descartes\Controller
|
|
|
|
{
|
2019-10-30 00:17:10 +01:00
|
|
|
private $internal_received;
|
|
|
|
private $internal_contact;
|
|
|
|
|
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);
|
|
|
|
$this->internal_received = new \controllers\internals\Received($bdd);
|
|
|
|
$this->internal_contact = new \controllers\internals\Contact($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 receiveds, sous forme d'un tableau permettant l'administration de ces receiveds.
|
|
|
|
*
|
|
|
|
* @param mixed $page
|
2019-10-29 18:36:25 +01:00
|
|
|
*/
|
|
|
|
public function list($page = 0)
|
2019-10-29 14:57:13 +01:00
|
|
|
{
|
|
|
|
$page = (int) $page;
|
|
|
|
$limit = 25;
|
2019-11-04 17:12:52 +01:00
|
|
|
$receiveds = $this->internal_received->list($limit, $page);
|
2019-10-29 14:57:13 +01:00
|
|
|
|
2019-10-30 00:30:39 +01:00
|
|
|
foreach ($receiveds as $key => $received)
|
|
|
|
{
|
|
|
|
if (!$contact = $this->internal_contact->get_by_number($received['origin']))
|
|
|
|
{
|
2019-10-29 14:57:13 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2019-10-30 00:30:39 +01:00
|
|
|
$receiveds[$key]['send_by'] = $contact['name'].' ('.$received['origin'].')';
|
2019-10-29 14:57:13 +01:00
|
|
|
}
|
|
|
|
|
2019-10-30 00:30:39 +01:00
|
|
|
$this->render('received/list', ['receiveds' => $receiveds, 'page' => $page, 'limit' => $limit, 'nb_results' => \count($receiveds)]);
|
2019-10-29 18:36:25 +01:00
|
|
|
}
|
2019-10-29 14:57:13 +01:00
|
|
|
|
|
|
|
/**
|
2019-10-30 00:30:39 +01:00
|
|
|
* Cette fonction retourne tous les Sms reçus aujourd'hui pour la popup.
|
|
|
|
*
|
2019-10-30 00:17:10 +01:00
|
|
|
* @return string : A JSON Un tableau des Sms reçus
|
2019-10-29 14:57:13 +01:00
|
|
|
*/
|
2019-10-29 18:36:25 +01:00
|
|
|
public function popup()
|
2019-10-29 14:57:13 +01:00
|
|
|
{
|
|
|
|
$now = new \DateTime();
|
2019-10-30 00:17:10 +01:00
|
|
|
$receiveds = $this->internal_received->get_since_by_date($now->format('Y-m-d'));
|
2019-10-30 00:30:39 +01:00
|
|
|
|
|
|
|
foreach ($receiveds as $key => $received)
|
|
|
|
{
|
|
|
|
if (!$contact = $this->internal_contact->get_by_number($received['origin']))
|
|
|
|
{
|
2019-10-29 14:57:13 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2019-10-30 00:30:39 +01:00
|
|
|
$receiveds[$key]['origin'] = $contact['name'].' ('.$received['origin'].')';
|
2019-10-29 14:57:13 +01:00
|
|
|
}
|
|
|
|
|
2019-10-30 00:30:39 +01:00
|
|
|
$nb_received = \count($receiveds);
|
|
|
|
|
|
|
|
if (!isset($_SESSION['popup_nb_receiveds']) || $_SESSION['popup_nb_receiveds'] > $nb_received)
|
|
|
|
{
|
2019-10-29 14:57:13 +01:00
|
|
|
$_SESSION['popup_nb_receiveds'] = $nb_received;
|
|
|
|
}
|
|
|
|
|
2019-10-30 00:30:39 +01:00
|
|
|
$newly_receiveds = \array_slice($receiveds, $_SESSION['popup_nb_receiveds']);
|
|
|
|
|
2019-10-30 00:17:10 +01:00
|
|
|
$_SESSION['popup_nb_receiveds'] = $nb_received;
|
2019-10-29 14:57:13 +01:00
|
|
|
|
|
|
|
echo json_encode($newly_receiveds);
|
2019-10-30 00:30:39 +01:00
|
|
|
|
2019-10-29 14:57:13 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-10-29 18:36:25 +01:00
|
|
|
/**
|
2019-10-30 00:30:39 +01:00
|
|
|
* Cette fonction va supprimer une liste de receiveds.
|
|
|
|
*
|
2019-10-29 14:57:13 +01:00
|
|
|
* @param array int $_GET['ids'] : Les id des receivedes à 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-10-29 14:57:13 +01:00
|
|
|
\modules\DescartesSessionMessages\internals\DescartesSessionMessages::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('Received', 'list'));
|
2019-10-29 14:57:13 +01:00
|
|
|
}
|
|
|
|
|
2019-10-30 00:30:39 +01:00
|
|
|
if (!\controllers\internals\Tool::is_admin())
|
|
|
|
{
|
2019-10-29 14:57:13 +01:00
|
|
|
\modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Vous devez être administrateur pour effectuer cette action.');
|
2019-11-06 20:34:26 +01:00
|
|
|
|
2019-10-30 00:17:10 +01:00
|
|
|
return $this->redirect(\descartes\Router::url('Received', 'list'));
|
2019-10-29 14:57:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$ids = $_GET['ids'] ?? [];
|
2019-10-30 00:30:39 +01:00
|
|
|
foreach ($ids as $id)
|
|
|
|
{
|
2019-10-30 00:17:10 +01:00
|
|
|
$this->internal_received->delete($id);
|
2019-10-29 14:57:13 +01:00
|
|
|
}
|
|
|
|
|
2019-10-30 00:17:10 +01:00
|
|
|
return $this->redirect(\descartes\Router::url('Received', 'list'));
|
2019-10-29 14:57:13 +01:00
|
|
|
}
|
2019-10-29 18:36:25 +01:00
|
|
|
}
|