diff --git a/controllers/internals/Console.php b/controllers/internals/Console.php index fa0cb29..ce6a29c 100755 --- a/controllers/internals/Console.php +++ b/controllers/internals/Console.php @@ -16,28 +16,29 @@ class Console extends \descartes\InternalController { private $model_command; private $model_database; - private $model_sended; + private $model_sent; private $model_smsstop; private $model_received; + private $model_scheduled; private $model_user; + private $internal_scheduled; private $internal_event; public function __construct() { - $bdd = descartes\Model::connect(DATABASE_HOST, DATABASE_NAME, DATABASE_USER, DATABASE_PASSWORD); + $bdd = \descartes\Model::_connect(DATABASE_HOST, DATABASE_NAME, DATABASE_USER, DATABASE_PASSWORD); $this->model_command = new \models\Command($bdd); $this->model_database = new \models\DataBase($bdd); - $this->model_sended = new \models\Sent($bdd); + $this->model_sent = new \models\Sent($bdd); $this->model_smsstop = new \models\SmsStop($bdd); $this->model_received = new \models\Received($bdd); $this->model_user = new \models\User($bdd); $this->internal_event = new \controllers\internals\Event($bdd); } - - + /** * Cette fonction envoie tous les Sms programmés qui doivent l'être. */ @@ -131,7 +132,7 @@ class Console extends \descartes\InternalController $now = $now->format('Y-m-d H:i:s'); //On peut maintenant ajouter le Sms - if (!$id_sended = $this->model_sended->insert(['at' => $now, 'target' => $number, 'content' => $scheduled['content'], 'before_delivered' => ceil(mb_strlen($scheduled['content']) / 160)])) + if (!$id_sended = $this->model_sent->insert(['at' => $now, 'target' => $number, 'content' => $scheduled['content'], 'before_delivered' => ceil(mb_strlen($scheduled['content']) / 160)])) { echo 'Impossible d\'inserer le sms pour le numero '.$number."\n"; } @@ -237,7 +238,7 @@ class Console extends \descartes\InternalController $interval = new \DateInterval('PT12H'); $sinceDate = $now->sub($interval)->format('Y-m-d H:i:s'); - if (!$sendeds = $this->model_sended->_select('sendeds', ['target' => $number, 'delivered' => false, 'failed' => false, '>at' => $sinceDate], 'at', false, 1)) + if (!$sendeds = $this->model_sent->_select('sendeds', ['target' => $number, 'delivered' => false, 'failed' => false, '>at' => $sinceDate], 'at', false, 1)) { continue; } @@ -247,8 +248,8 @@ class Console extends \descartes\InternalController //On gère les echecs if ('Failed' === trim($text)) { - $this->model_sended->update($sended['id'], ['before_delivered' => 0, 'failed' => true]); - echo 'Sent Sms id ' . $sended['id'] . " pass to failed status\n"; + $this->model_sent->update($sended['id'], ['before_delivered' => 0, 'failed' => true]); + echo 'Sent Sms id '.$sended['id']." pass to failed status\n"; continue; } @@ -257,14 +258,14 @@ class Console extends \descartes\InternalController if ($sended['before_delivered'] > 1) { $this->model_database->update($sended['id'], ['before_delivered' => $sended['before_delivered'] - 1]); - echo 'Sent Sms id ' . $sended['id'] . " before_delivered decrement\n"; + echo 'Sent Sms id '.$sended['id']." before_delivered decrement\n"; continue; } //Si tout est bon, que nous avons assez d'accusés, nous validons ! $this->model_database->update($sended['id'], ['before_delivered' => 0, 'delivered' => true]); - echo 'Sent Sms id ' . $sended['id'] . " to delivered status\n"; + echo 'Sent Sms id '.$sended['id']." to delivered status\n"; continue; } @@ -358,7 +359,6 @@ class Console extends \descartes\InternalController return false; } - global $this->model_database; $transfers = $this->model_database->_select('transfers', ['progress' => false]); $ids_transfers = []; diff --git a/controllers/internals/Received.php b/controllers/internals/Received.php index b969a88..96a56d7 100755 --- a/controllers/internals/Received.php +++ b/controllers/internals/Received.php @@ -1,5 +1,15 @@ + * Dariusz Rumiński + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + namespace controllers\internals; /** diff --git a/controllers/internals/Scheduled.php b/controllers/internals/Scheduled.php index b479afd..c19528a 100755 --- a/controllers/internals/Scheduled.php +++ b/controllers/internals/Scheduled.php @@ -133,13 +133,19 @@ namespace controllers\internals; * @param array $numbers : Les numéros auxquels envoyer le scheduled * @param array $contacts_ids : Les ids des contact auquels envoyer le scheduled * @param array $groups_ids : Les ids des group auxquels envoyer le scheduled + * @param mixed $id + * @param mixed $content + * @param mixed $at + * @param mixed $contact_ids + * @param mixed $flash + * @param mixed $progress * * @return int : le nombre de ligne modifiées */ public function update($id, $content, $at, $numbers = [], $contact_ids = [], $groups_ids = [], $flash = false, $progress = false) { $scheduled = [ - 'at' => $date, + 'at' => $at, 'content' => $content, 'flash' => $flash, 'progress' => $progress, @@ -209,11 +215,14 @@ namespace controllers\internals; } /** - * This function update progress status of a scheduled sms - * @param bool $progress : Progress status + * This function update progress status of a scheduled sms. + * + * @param bool $progress : Progress status + * @param mixed $id_scheduled + * * @return int : Number of update */ - public function update_progress ($id_scheduled, $progress) + public function update_progress($id_scheduled, $progress) { return $this->model_scheduled->update($id_scheduled, ['progress' => $progress]); } diff --git a/controllers/internals/Sent.php b/controllers/internals/Sent.php index 74b0d0b..7f470c2 100755 --- a/controllers/internals/Sent.php +++ b/controllers/internals/Sent.php @@ -17,11 +17,11 @@ namespace controllers\internals; */ class Sent extends \descartes\InternalController { - private $model_sended; + private $model_sent; public function __construct(\PDO $bdd) { - $this->model_sended = new \models\Sent($bdd); + $this->model_sent = new \models\Sent($bdd); } /** @@ -35,7 +35,7 @@ namespace controllers\internals; public function list($nb_entry = false, $page = false) { //Recupération des sendedes - return $this->model_sended->list($nb_entry, $nb_entry * $page); + return $this->model_sent->list($nb_entry, $nb_entry * $page); } /** @@ -48,7 +48,7 @@ namespace controllers\internals; public function gets($ids) { //Recupération des sendedes - return $this->model_sended->gets($ids); + return $this->model_sent->gets($ids); } /** @@ -60,7 +60,7 @@ namespace controllers\internals; */ public function get_lasts_by_date($nb_entry = false) { - return $this->model_sended->get_lasts_by_date($nb_entry); + return $this->model_sent->get_lasts_by_date($nb_entry); } /** @@ -73,7 +73,7 @@ namespace controllers\internals; public function get_by_target($target) { //Recupération des sendeds - return $this->model_sended->get_by_target($target); + return $this->model_sent->get_by_target($target); } /** @@ -86,7 +86,7 @@ namespace controllers\internals; */ public function delete($id) { - return $this->model_sended->delete($id); + return $this->model_sent->delete($id); } /** @@ -98,7 +98,7 @@ namespace controllers\internals; */ public function create($sended) { - return $this->model_sended->create($sended); + return $this->model_sent->create($sended); } /** @@ -108,7 +108,7 @@ namespace controllers\internals; */ public function count() { - return $this->model_sended->count(); + return $this->model_sent->count(); } /** @@ -120,7 +120,7 @@ namespace controllers\internals; */ public function count_by_day_since($date) { - $counts_by_day = $this->model_sended->count_by_day_since($date); + $counts_by_day = $this->model_sent->count_by_day_since($date); $return = []; foreach ($counts_by_day as $count_by_day) diff --git a/controllers/publics/Command.php b/controllers/publics/Command.php index de78121..3894a87 100755 --- a/controllers/publics/Command.php +++ b/controllers/publics/Command.php @@ -108,6 +108,7 @@ namespace controllers\publics; if (!$this->verify_csrf($csrf)) { \modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Jeton CSRF invalid !'); + return $this->redirect(\descartes\Router::url('Command', 'list')); } @@ -118,16 +119,19 @@ namespace controllers\publics; if (!$name || !$script) { \modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Renseignez au moins un nom et un script.'); + return $this->redirect(\descartes\Router::url('Command', 'list')); } if (!$this->internal_command->create($name, $script, $admin)) { \modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Impossible créer cette commande.'); + return $this->redirect(\descartes\Router::url('commands', 'add')); } \modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('success', 'La commande a bien été crée.'); + return $this->redirect(\descartes\Router::url('Command', 'list')); } @@ -144,6 +148,7 @@ namespace controllers\publics; if (!$this->verify_csrf($csrf)) { \modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Jeton CSRF invalid !'); + return $this->redirect(\descartes\Router::url('Command', 'list')); } @@ -157,10 +162,12 @@ namespace controllers\publics; if ($nb_commands_update !== \count($_POST['commands'])) { \modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Certaines commandes n\'ont pas pu êtres mises à jour.'); + return $this->redirect(\descartes\Router::url('Command', 'list')); } \modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('success', 'Toutes les commandes ont été modifiées avec succès.'); + return $this->redirect(\descartes\Router::url('Command', 'list')); } } diff --git a/controllers/publics/Connect.php b/controllers/publics/Connect.php index 82cfa64..286db26 100755 --- a/controllers/publics/Connect.php +++ b/controllers/publics/Connect.php @@ -87,6 +87,7 @@ namespace controllers\publics; if (!$this->verify_csrf($csrf)) { \modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Jeton CSRF invalid !'); + return $this->redirect(\descartes\Router::url('Connect', 'forget_password')); } @@ -96,6 +97,7 @@ namespace controllers\publics; if (!$email || !$user) { \modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Aucun utilisateur n\'existe pour cette adresse mail.'); + return $this->redirect(\descartes\Router::url('Connect', 'forget_password')); } @@ -144,6 +146,7 @@ namespace controllers\publics; { session_unset(); session_destroy(); + return $this->redirect(\descartes\Router::url('Connect', 'login')); } } diff --git a/controllers/publics/Contact.php b/controllers/publics/Contact.php index c63cf2a..f3df32e 100755 --- a/controllers/publics/Contact.php +++ b/controllers/publics/Contact.php @@ -45,6 +45,7 @@ namespace controllers\publics; { $page = (int) $page; $contacts = $this->internal_contact->list(25, $page); + return $this->render('contact/list', ['contacts' => $contacts]); } @@ -61,6 +62,7 @@ namespace controllers\publics; if (!$this->verify_csrf($csrf)) { \modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Jeton CSRF invalid !'); + return $this->redirect(\descartes\Router::url('Contact', 'list')); } diff --git a/controllers/publics/Event.php b/controllers/publics/Event.php index 9cc00cb..e8bc2a5 100755 --- a/controllers/publics/Event.php +++ b/controllers/publics/Event.php @@ -60,12 +60,14 @@ namespace controllers\publics; if (!$this->verify_csrf($csrf)) { \modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Jeton CSRF invalid !'); + return $this->redirect(\descartes\Router::url('Event', 'list')); } if (!\controllers\internals\Tool::is_admin()) { \modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Vous devez être admin pour pouvoir supprimer des events.'); + return $this->redirect(\descartes\Router::url('Event', 'list')); } diff --git a/controllers/publics/Group.php b/controllers/publics/Group.php index 1388456..6e09637 100755 --- a/controllers/publics/Group.php +++ b/controllers/publics/Group.php @@ -70,6 +70,7 @@ namespace controllers\publics; if (!$this->verify_csrf($csrf)) { \modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Jeton CSRF invalid !'); + return $this->redirect(\descartes\Router::url('Group', 'list')); } @@ -120,6 +121,7 @@ namespace controllers\publics; if (!$this->verify_csrf($csrf)) { \modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Jeton CSRF invalid !'); + return $this->redirect(\descartes\Router::url('Group', 'add')); } @@ -129,6 +131,7 @@ namespace controllers\publics; if (!$name || !$contacts_ids) { \modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Des champs sont manquants !'); + return $this->redirect(\descartes\Router::url('Group', 'add')); } @@ -136,10 +139,12 @@ namespace controllers\publics; if (!$id_group) { \modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Impossible de créer ce groupe.'); + return $this->redirect(\descartes\Router::url('Group', 'add')); } \modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('success', 'Le groupe a bien été créé.'); + return $this->redirect(\descartes\Router::url('Group', 'list')); } @@ -156,6 +161,7 @@ namespace controllers\publics; if (!$this->verify_csrf($csrf)) { \modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Jeton CSRF invalid !'); + return $this->redirect(\descartes\Router::url('Group', 'list')); } @@ -170,10 +176,12 @@ namespace controllers\publics; if ($nb_groups_update !== \count($groups)) { \modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Certains groupes n\'ont pas pu êtres mis à jour.'); + return $this->redirect(\descartes\Router::url('Group', 'list')); } \modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('success', 'Tous les groupes ont été modifiés avec succès.'); + return $this->redirect(\descartes\Router::url('Group', 'list')); } diff --git a/controllers/publics/Received.php b/controllers/publics/Received.php index 97a5025..d019c48 100755 --- a/controllers/publics/Received.php +++ b/controllers/publics/Received.php @@ -108,12 +108,14 @@ namespace controllers\publics; if (!$this->verify_csrf($csrf)) { \modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Jeton CSRF invalid !'); + return $this->redirect(\descartes\Router::url('Received', 'list')); } if (!\controllers\internals\Tool::is_admin()) { \modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Vous devez être administrateur pour effectuer cette action.'); + return $this->redirect(\descartes\Router::url('Received', 'list')); } diff --git a/controllers/publics/Scheduled.php b/controllers/publics/Scheduled.php index 00dbfd5..baff208 100755 --- a/controllers/publics/Scheduled.php +++ b/controllers/publics/Scheduled.php @@ -58,6 +58,7 @@ namespace controllers\publics; if (!$this->verify_csrf($csrf)) { \modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Jeton CSRF invalid !'); + return $this->redirect(\descartes\Router::url('Scheduled', 'list')); } @@ -141,6 +142,7 @@ namespace controllers\publics; if (!$this->verify_csrf($csrf)) { \modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Jeton CSRF invalid !'); + return $this->redirect(\descartes\Router::url('Scheduled', 'add')); } @@ -153,12 +155,14 @@ namespace controllers\publics; if (!$content) { \modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Vous ne pouvez pas créer un Sms sans message.'); + return $this->redirect(\descartes\Router::url('Scheduled', 'add')); } if (!\controllers\internals\Tool::validate_date($date, 'Y-m-d H:i:s') && !\controllers\internals\Tool::validate_date($date, 'Y-m-d H:i')) { \modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Vous devez fournir une date valide.'); + return $this->redirect(\descartes\Router::url('Scheduled', 'add')); } @@ -179,6 +183,7 @@ namespace controllers\publics; if (!$numbers && !$contacts && !$groups) { \modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Vous devez renseigner au moins un destinataire pour le Sms.'); + return $this->redirect(\descartes\Router::url('Scheduled', 'add')); } @@ -192,10 +197,12 @@ namespace controllers\publics; if (!$scheduled_id = $this->internal_scheduled->create($scheduled, $numbers, $contacts, $groups)) { \modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Impossible de créer le Sms.'); + return $this->redirect(\descartes\Router::url('Scheduled', 'add')); } \modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('success', 'Le Sms a bien été créé pour le '.$date.'.'); + return $this->redirect(\descartes\Router::url('Scheduled', 'list')); } @@ -212,6 +219,7 @@ namespace controllers\publics; if (!$this->verify_csrf($csrf)) { \modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Jeton CSRF invalid !'); + return $this->redirect(\descartes\Router::url('Scheduled', 'list')); } @@ -230,12 +238,14 @@ namespace controllers\publics; if (!$content) { $all_update_ok = false; + continue; } if (!\controllers\internals\Tool::validate_date($date, 'Y-m-d H:i:s') && !\controllers\internals\Tool::validate_date($date, 'Y-m-d H:i')) { $all_update_ok = false; + continue; } @@ -246,6 +256,7 @@ namespace controllers\publics; if (!$number) { unset($numbers[$key]); + continue; } @@ -255,13 +266,15 @@ namespace controllers\publics; if (!$numbers && !$contacts && !$groups) { $all_update_ok = false; + continue; } - $success = $this->internal_scheduled->update($id_scheduled, $content, $at, $numbers, $contacts, $groups); + $success = $this->internal_scheduled->update($id_scheduled, $content, $date, $numbers, $contacts, $groups); if (!$success) { $all_update_ok = false; + continue; } } @@ -269,10 +282,12 @@ namespace controllers\publics; if (!$all_update_ok) { \modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Certains SMS n\'ont pas pu êtres mis à jour.'); + return $this->redirect(\descartes\Router::url('Scheduled', 'list')); } \modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('success', 'Tous les SMS ont été mis à jour.'); + return $this->redirect(\descartes\Router::url('Scheduled', 'list')); } } diff --git a/controllers/publics/Sent.php b/controllers/publics/Sent.php index 2f3a2ba..1a08f8b 100755 --- a/controllers/publics/Sent.php +++ b/controllers/publics/Sent.php @@ -59,6 +59,7 @@ namespace controllers\publics; if (!$this->verify_csrf($csrf)) { \modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Jeton CSRF invalid !'); + return $this->redirect(\descartes\Router::url('Sent', 'list')); } diff --git a/controllers/publics/SmsStop.php b/controllers/publics/SmsStop.php index 859000a..0beb6f9 100755 --- a/controllers/publics/SmsStop.php +++ b/controllers/publics/SmsStop.php @@ -59,12 +59,14 @@ namespace controllers\publics; if (!$this->verify_csrf($csrf)) { \modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Jeton CSRF invalid !'); + return $this->redirect(\descartes\Router::url('SmsStop', 'list')); } if (!\controllers\internals\Tool::is_admin()) { \modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Vous devez être administrateur pour pouvoir supprimer un "STOP Sms" !'); + return $this->redirect(\descartes\Router::url('SmsStop', 'list')); } diff --git a/models/Contact.php b/models/Contact.php index 48b1efe..c198deb 100755 --- a/models/Contact.php +++ b/models/Contact.php @@ -58,18 +58,17 @@ namespace models; return isset($contacts[0]) ? $contacts[0] : false; } - - + /** - * Get contacts of a particular group + * Get contacts of a particular group. * * @param int $id_group : Id of the group we want contacts for + * * @return array */ public function get_by_group($id_group) { - $contacts = $this->_select('contact', ['id_group' => $id_group]); - return $contacts; + return $this->_select('contact', ['id_group' => $id_group]); } /** diff --git a/models/DataBase.php b/models/DataBase.php index eda47c2..24c9edc 100755 --- a/models/DataBase.php +++ b/models/DataBase.php @@ -14,7 +14,6 @@ namespace models; class DataBase extends \descartes\Model { - // // PARTIE DES REQUETES SCHEDULEDS_NUMBERS // diff --git a/models/Received.php b/models/Received.php index ffd7561..c853cdb 100755 --- a/models/Received.php +++ b/models/Received.php @@ -1,5 +1,14 @@ + * Dariusz Rumiński + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ namespace models; diff --git a/models/Scheduled.php b/models/Scheduled.php index 9507e11..4b1c00c 100755 --- a/models/Scheduled.php +++ b/models/Scheduled.php @@ -64,16 +64,17 @@ namespace models; } /** - * Get scheduleds message not in progress and before a date + * Get scheduleds message not in progress and before a date. + * * @param string $date : Limit date + * * @return array */ - public function get_scheduleds_not_in_progress_before ($date) + public function get_scheduleds_not_in_progress_before($date) { return $this->_select('scheduleds', ['<=at' => $date, 'progress' => false]); } - /** * Cette fonction retourne les messages programmés avant une date et pour un numéro. * diff --git a/models/Sended.php b/models/Sent.php similarity index 99% rename from models/Sended.php rename to models/Sent.php index 56e9148..c759467 100755 --- a/models/Sended.php +++ b/models/Sent.php @@ -15,7 +15,7 @@ namespace models; /** * Cette classe gère les accès bdd pour les sendedes. */ - class Sended extends \descartes\Model + class Sent extends \descartes\Model { /** * Retourne une entrée par son id.