2015-02-17 16:17:38 +01:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Page des SMS reçus
|
|
|
|
*/
|
|
|
|
class receiveds extends Controller
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Cette fonction est appelée avant toute les autres :
|
|
|
|
* Elle vérifie que l'utilisateur est bien connecté
|
|
|
|
* @return void;
|
|
|
|
*/
|
|
|
|
public function before()
|
|
|
|
{
|
|
|
|
internalTools::verifyConnect();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Cette fonction est alias de showAll()
|
|
|
|
*/
|
|
|
|
public function byDefault()
|
|
|
|
{
|
|
|
|
$this->showAll();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Cette fonction retourne tous les SMS envoyés, sous forme d'un tableau
|
2015-08-08 13:23:47 +02:00
|
|
|
* @param int $page : La page à consulter. Par défaut 0
|
2015-02-17 16:17:38 +01:00
|
|
|
* @return void;
|
|
|
|
*/
|
2015-08-08 13:23:47 +02:00
|
|
|
public function showAll($page = 0)
|
2015-02-17 16:17:38 +01:00
|
|
|
{
|
|
|
|
//Creation de l'object de base de données
|
|
|
|
global $db;
|
|
|
|
|
2015-08-08 13:23:47 +02:00
|
|
|
$page = (int)($page < 0 ? $page = 0 : $page);
|
2015-02-17 16:17:38 +01:00
|
|
|
$limit = 25;
|
|
|
|
$offset = $limit * $page;
|
|
|
|
|
|
|
|
|
|
|
|
//Récupération des SMS envoyés triés par date, du plus récent au plus ancien, par paquets de $limit, en ignorant les $offset premiers
|
2015-08-08 13:23:47 +02:00
|
|
|
$receiveds = $db->getFromTableWhere('receiveds', [], 'at', true, $limit, $offset);
|
2015-02-17 16:17:38 +01:00
|
|
|
|
2015-09-21 22:02:50 +02:00
|
|
|
foreach ($receiveds as $key => $received)
|
|
|
|
{
|
|
|
|
if (!$contacts = $db->getFromTableWhere('contacts', ['number' => $received['send_by']]))
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
$receiveds[$key]['send_by'] = $contacts[0]['name'] . ' (' . $received['send_by'] . ')';
|
|
|
|
}
|
|
|
|
|
2015-08-16 00:06:31 +02:00
|
|
|
return $this->render('receiveds/showAll', array(
|
2015-02-17 16:17:38 +01:00
|
|
|
'receiveds' => $receiveds,
|
|
|
|
'page' => $page,
|
|
|
|
'limit' => $limit,
|
|
|
|
'nbResults' => count($receiveds),
|
|
|
|
));
|
|
|
|
}
|
2015-08-16 03:25:41 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Cette fonction retourne tous les SMS reçus aujourd'hui pour la popup
|
|
|
|
* @return json : Un tableau des sms
|
|
|
|
*/
|
|
|
|
public function popup ()
|
|
|
|
{
|
|
|
|
global $db;
|
|
|
|
$now = new DateTime();
|
|
|
|
$receiveds = $db->getReceivedsSince($now->format('Y-m-d'));
|
2015-09-21 22:08:54 +02:00
|
|
|
|
|
|
|
foreach ($receiveds as $key => $received)
|
|
|
|
{
|
|
|
|
if (!$contacts = $db->getFromTableWhere('contacts', ['number' => $received['send_by']]))
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
$receiveds[$key]['send_by'] = $contacts[0]['name'] . ' (' . $received['send_by'] . ')';
|
|
|
|
}
|
2015-08-16 03:25:41 +02:00
|
|
|
|
|
|
|
$nbReceiveds = count($receiveds);
|
|
|
|
|
|
|
|
if (!isset($_SESSION['popup_nb_receiveds']) || ($_SESSION['popup_nb_receiveds'] > $nbReceiveds))
|
|
|
|
{
|
|
|
|
$_SESSION['popup_nb_receiveds'] = $nbReceiveds;
|
|
|
|
}
|
|
|
|
|
|
|
|
$newlyReceiveds = array_slice($receiveds, $_SESSION['popup_nb_receiveds']);
|
|
|
|
|
|
|
|
echo json_encode($newlyReceiveds);
|
|
|
|
$_SESSION['popup_nb_receiveds'] = $nbReceiveds;
|
|
|
|
return true;
|
|
|
|
}
|
2015-10-13 19:24:20 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Cette fonction supprimer une liste de sms reçus
|
|
|
|
* @param $csrf : Le jeton CSRF
|
|
|
|
* @param int... $ids : Les id des sms à supprimer
|
|
|
|
* @return boolean;
|
|
|
|
*/
|
|
|
|
public function delete($csrf)
|
|
|
|
{
|
|
|
|
//On vérifie que le jeton csrf est bon
|
|
|
|
if (!internalTools::verifyCSRF($csrf))
|
|
|
|
{
|
|
|
|
$_SESSION['errormessage'] = 'Jeton CSRF invalide !';
|
|
|
|
header('Location: ' . $this->generateUrl('receiveds'));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//On récupère les ids comme étant tous les arguments de la fonction et on supprime le premier (csrf)
|
|
|
|
$ids = func_get_args();
|
|
|
|
unset($ids[0]);
|
|
|
|
|
|
|
|
//Create de l'object de base de données
|
|
|
|
global $db;
|
|
|
|
|
|
|
|
//Si on est pas admin
|
|
|
|
if (!$_SESSION['admin'])
|
|
|
|
{
|
|
|
|
$_SESSION['errormessage'] = 'Vous devez être administrateur pour effectuer cette action.';
|
|
|
|
header('Location: ' . $this->generateUrl('receiveds'));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$db->deleteReceivedsIn($ids);
|
|
|
|
header('Location: ' . $this->generateUrl('receiveds'));
|
|
|
|
return true;
|
|
|
|
}
|
2015-02-17 16:17:38 +01:00
|
|
|
}
|