From 90e761e152c358adbf09d6bf9322f86ece70e9d2 Mon Sep 17 00:00:00 2001 From: Pierre-Lin Bonnemaison Date: Sun, 16 Aug 2015 03:25:41 +0200 Subject: [PATCH] =?UTF-8?q?Ajout=20du=20syst=C3=A8me=20de=20popup=20sur=20?= =?UTF-8?q?reception=20d'un=20SMS?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 20150816025505139706841.txt | 1 + controllers/internalIncs.php | 8 ++++++++ controllers/receiveds.php | 24 ++++++++++++++++++++++++ css/style.css | 11 +++++++++-- js/custom.js | 21 ++++++++++++++++++++- model/DataBase.php | 20 ++++++++++++++++++++ templates/internalIncs/head.php | 5 +++++ templates/internalIncs/phptojs.php | 3 +++ vi | 1 + 9 files changed, 91 insertions(+), 3 deletions(-) create mode 100644 20150816025505139706841.txt create mode 100644 templates/internalIncs/phptojs.php create mode 100644 vi diff --git a/20150816025505139706841.txt b/20150816025505139706841.txt new file mode 100644 index 0000000..14daed7 --- /dev/null +++ b/20150816025505139706841.txt @@ -0,0 +1 @@ +0612423997:salut diff --git a/controllers/internalIncs.php b/controllers/internalIncs.php index aa47c6f..ea1ecdf 100755 --- a/controllers/internalIncs.php +++ b/controllers/internalIncs.php @@ -51,4 +51,12 @@ { $this->render('internalIncs/footer'); } + + /** + * Cette fonction retourne une page js avec des constantes php sous forme js + */ + public function phptojs() + { + $this->render('internalIncs/phptojs'); + } } diff --git a/controllers/receiveds.php b/controllers/receiveds.php index 8a0b68b..517ba50 100755 --- a/controllers/receiveds.php +++ b/controllers/receiveds.php @@ -47,4 +47,28 @@ 'nbResults' => count($receiveds), )); } + + /** + * 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')); + + $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; + } } diff --git a/css/style.css b/css/style.css index dea9794..d8314a7 100755 --- a/css/style.css +++ b/css/style.css @@ -9,12 +9,19 @@ } /** POPUPS ALERT **/ -.popup-alert +.popup-alerts-container { position: fixed; left: 0; top: 0; - z-index: 9999; + z-index: 9998; + width: 100%; +} + +.popup-alert +{ + width: 50%; + position: relative; } /** FOOTER **/ diff --git a/js/custom.js b/js/custom.js index 45e9ebf..f404c51 100755 --- a/js/custom.js +++ b/js/custom.js @@ -17,5 +17,24 @@ function showMessage(message, type) } var alerthtml = ''; - jQuery('body').prepend(alerthtml); + jQuery('body .popup-alerts-container').prepend(alerthtml); } + +/** + * Cette fonction vérifie si un message a été reçu + */ +function verifReceived() +{ + jQuery('.popup-alert').fadeOut('slow'); + jQuery.getJSON(HTTP_PWD + "/receiveds/popup", function( data ) { + $.each(data, function(key, val) { + showMessage('SMS reçu du ' + val.send_by.replace(//g, ">") + ' : ' + val.content.replace(//g, ">"), 1); + }); + }); +} + + +jQuery(document).ready(function() +{ + var verifReceivedInterval = setInterval(verifReceived, 10000); +}); diff --git a/model/DataBase.php b/model/DataBase.php index adfd1ea..6ebb585 100755 --- a/model/DataBase.php +++ b/model/DataBase.php @@ -95,6 +95,26 @@ return $this->runQuery($query, $params); } + /** + * Récupère les SMS reçus depuis une date + * @param $date : La date depuis laquelle on veux les SMS (au format 2014-10-25 20:10:05) + * @return array : Tableau avec tous les SMS depuis la date + */ + public function getReceivedsSince($date) + { + $query = " + SELECT * + FROM receiveds + WHERE at > STR_TO_DATE(:date, '%Y-%m-%d %h:%i:%s') + "; + + $params = array( + 'date' => $date, + ); + + return $this->runQuery($query, $params); + } + /********************************/ /* PARTIE DES REQUETES CONTACTS */ /********************************/ diff --git a/templates/internalIncs/head.php b/templates/internalIncs/head.php index 3c130ef..b4d3a7a 100755 --- a/templates/internalIncs/head.php +++ b/templates/internalIncs/head.php @@ -15,6 +15,10 @@ + phptojs(); + ?> @@ -58,3 +62,4 @@ + diff --git a/templates/internalIncs/phptojs.php b/templates/internalIncs/phptojs.php new file mode 100644 index 0000000..0c49bc5 --- /dev/null +++ b/templates/internalIncs/phptojs.php @@ -0,0 +1,3 @@ + diff --git a/vi b/vi new file mode 100644 index 0000000..14daed7 --- /dev/null +++ b/vi @@ -0,0 +1 @@ +0612423997:salut