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-02-17 16:17:38 +01:00
|
|
|
}
|