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 sendeds.
|
2019-10-29 18:36:25 +01:00
|
|
|
*/
|
2019-11-07 16:17:18 +01:00
|
|
|
class Sended extends \descartes\Controller
|
2019-10-29 18:36:25 +01:00
|
|
|
{
|
2019-10-30 00:17:10 +01:00
|
|
|
private $internal_sended;
|
2019-11-12 17:58:07 +01:00
|
|
|
private $internal_phone;
|
2019-10-30 00:17:10 +01:00
|
|
|
|
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-11-07 16:17:18 +01:00
|
|
|
$this->internal_sended = new \controllers\internals\Sended($bdd);
|
2019-11-12 17:58:07 +01:00
|
|
|
$this->internal_phone = new \controllers\internals\Phone($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 sendeds, sous forme d'un tableau permettant l'administration de ces sendeds.
|
|
|
|
*
|
|
|
|
* @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-12 17:58:07 +01:00
|
|
|
$sendeds = $this->internal_sended->list($_SESSION['user']['id'], $limit, $page);
|
2019-10-30 00:30:39 +01:00
|
|
|
$this->render('sended/list', ['sendeds' => $sendeds, 'page' => $page, 'limit' => $limit, 'nb_results' => \count($sendeds)]);
|
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 sendeds.
|
|
|
|
*
|
2019-10-29 14:57:13 +01:00
|
|
|
* @param array int $_GET['ids'] : Les id des sendedes à supprimer
|
2019-10-30 00:30:39 +01:00
|
|
|
* @param mixed $csrf
|
|
|
|
*
|
2019-10-29 14:57:13 +01:00
|
|
|
* @return boolean;
|
|
|
|
*/
|
|
|
|
public function delete($csrf)
|
|
|
|
{
|
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-11-07 16:17:18 +01:00
|
|
|
return $this->redirect(\descartes\Router::url('Sended', '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-11-12 17:58:07 +01:00
|
|
|
$sended = $this->internal_sended->get($id);
|
|
|
|
if (!$sended)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
$is_owner = (bool) $this->internal_phone->get_by_number_and_user($sended['origin'], $_SESSION['user']['id']);
|
|
|
|
if (!$is_owner)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2019-10-30 00:17:10 +01:00
|
|
|
$this->internal_sended->delete($id);
|
2019-10-29 14:57:13 +01:00
|
|
|
}
|
|
|
|
|
2019-11-07 16:17:18 +01:00
|
|
|
return $this->redirect(\descartes\Router::url('Sended', 'list'));
|
2019-10-29 14:57:13 +01:00
|
|
|
}
|
2019-10-29 18:36:25 +01:00
|
|
|
}
|