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 = '<div class="col-xs-10 col-xs-offset-1 col-md-6 col-md-offset-3 popup-alert alert ' + type + '"><button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>' + message + '</div>'; - 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, "<").replace(/>/g, ">") + ' : ' + val.content.replace(/</g, "<").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 @@ <link href="<?php echo HTTP_PWD; ?>font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css"> <!-- Custom CSS site --> <link href="<?php echo HTTP_PWD; ?>css/style.css" rel="stylesheet"> + <?php + $incs = new internalIncs(); + $incs->phptojs(); + ?> <script src="<?php echo HTTP_PWD; ?>js/jquery.js"></script> <script src="<?php echo HTTP_PWD; ?>js/bootstrap.min.js"></script> <script src="<?php echo HTTP_PWD; ?>js/plugins/morris/raphael.min.js"></script> @@ -58,3 +62,4 @@ </script> </head> <body> + <div class="popup-alerts-container"></div> 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 @@ +<script> + var HTTP_PWD = '<?php echo addslashes(HTTP_PWD); ?>'; +</script> diff --git a/vi b/vi new file mode 100644 index 0000000..14daed7 --- /dev/null +++ b/vi @@ -0,0 +1 @@ +0612423997:salut