few coderules changes

This commit is contained in:
osaajani 2019-10-29 18:36:25 +01:00
parent 80b6a3ed86
commit 117c18ddca
28 changed files with 1485 additions and 1666 deletions

View File

@ -1,9 +1,10 @@
<?php <?php
namespace controllers\internals; namespace controllers\internals;
/** /**
* Classe des commandes * Classe des commandes
*/ */
class Command extends \InternalController class Command extends \descartes\InternalController
{ {
private $model_command; private $model_command;
@ -76,8 +77,7 @@ namespace controllers\internals;
$modelCommand = new \models\Command($this->bdd); $modelCommand = new \models\Command($this->bdd);
$result = $modelCommand->insert($command); $result = $modelCommand->insert($command);
if (!$result) if (!$result) {
{
return false; return false;
} }

View File

@ -1,6 +1,7 @@
<?php <?php
namespace controllers\internals; namespace controllers\internals;
class Console extends \InternalController
class Console extends \descartes\InternalController
{ {
/** /**
@ -32,35 +33,26 @@ class Console extends \InternalController
$message .= "Voici la liste des commandes disponibles : \n"; $message .= "Voici la liste des commandes disponibles : \n";
//On écrit les texte pour la liste des commandes dispos //On écrit les texte pour la liste des commandes dispos
foreach ($commands as $name => $value) foreach ($commands as $name => $value) {
{
$requireds = isset($value['requireds']) ? $value['requireds'] : array(); $requireds = isset($value['requireds']) ? $value['requireds'] : array();
$optionals = isset($value['optionals']) ? $value['optionals'] : array(); $optionals = isset($value['optionals']) ? $value['optionals'] : array();
$message .= ' ' . $name . ' : ' . $value['description'] . "\n"; $message .= ' ' . $name . ' : ' . $value['description'] . "\n";
$message .= " Arguments obligatoires : \n"; $message .= " Arguments obligatoires : \n";
if (!count($requireds)) if (!count($requireds)) {
{
$message .= " Pas d'argument\n"; $message .= " Pas d'argument\n";
} } else {
else foreach ($requireds as $argument => $desc) {
{
foreach ($requireds as $argument => $desc)
{
$message .= ' - ' . $argument . ' : ' . $desc . "\n"; $message .= ' - ' . $argument . ' : ' . $desc . "\n";
} }
} }
$message .= " Arguments optionnels : \n"; $message .= " Arguments optionnels : \n";
if (!count($optionals)) if (!count($optionals)) {
{
$message .= " Pas d'argument\n"; $message .= " Pas d'argument\n";
} } else {
else foreach ($optionals as $argument => $desc) {
{
foreach ($optionals as $argument => $desc)
{
$message .= ' - ' . $argument . ' : ' . $desc . "\n"; $message .= ' - ' . $argument . ' : ' . $desc . "\n";
} }
} }
@ -77,8 +69,7 @@ class Console extends \InternalController
//On créé l'objet de base de données //On créé l'objet de base de données
global $db; global $db;
for ($i = 0; $i < 30; $i++) for ($i = 0; $i < 30; $i++) {
{
$now = new \DateTime(); $now = new \DateTime();
$now = $now->format('Y-m-d H:i:s'); $now = $now->format('Y-m-d H:i:s');
@ -89,8 +80,7 @@ class Console extends \InternalController
$ids_scheduleds = array(); $ids_scheduleds = array();
//On passe en cours de progression tous les SMS //On passe en cours de progression tous les SMS
foreach ($scheduleds as $scheduled) foreach ($scheduleds as $scheduled) {
{
$ids_scheduleds[] = $scheduled['id']; $ids_scheduleds[] = $scheduled['id'];
} }
@ -99,8 +89,7 @@ class Console extends \InternalController
$db->updateProgressScheduledIn($ids_scheduleds, true); $db->updateProgressScheduledIn($ids_scheduleds, true);
//Pour chaque SMS à envoyer //Pour chaque SMS à envoyer
foreach ($scheduleds as $scheduled) foreach ($scheduleds as $scheduled) {
{
$id_scheduled = $scheduled['id']; $id_scheduled = $scheduled['id'];
$text_sms = escapeshellarg($scheduled['content']); $text_sms = escapeshellarg($scheduled['content']);
$flash = $scheduled['flash']; $flash = $scheduled['flash'];
@ -110,41 +99,33 @@ class Console extends \InternalController
//On récupère les numéros pour le SMS et on les ajoute //On récupère les numéros pour le SMS et on les ajoute
$target_numbers = $db->getNumbersForScheduled($id_scheduled); $target_numbers = $db->getNumbersForScheduled($id_scheduled);
foreach ($target_numbers as $target_number) foreach ($target_numbers as $target_number) {
{
$numbers[] = $target_number['number']; $numbers[] = $target_number['number'];
} }
//On récupère les contacts, et on ajoute les numéros //On récupère les contacts, et on ajoute les numéros
$contacts = $db->getContactForScheduled($id_scheduled); $contacts = $db->getContactForScheduled($id_scheduled);
foreach ($contacts as $contact) foreach ($contacts as $contact) {
{
$numbers[] = $contact['number']; $numbers[] = $contact['number'];
} }
//On récupère les groupes //On récupère les groupes
$groupes = $db->getGroupeForScheduled($id_scheduled); $groupes = $db->getGroupeForScheduled($id_scheduled);
foreach ($groupes as $groupe) foreach ($groupes as $groupe) {
{
//On récupère les contacts du groupe et on les ajoute aux numéros //On récupère les contacts du groupe et on les ajoute aux numéros
$contacts = $db->getContactForGroupe($groupe['id']); $contacts = $db->getContactForGroupe($groupe['id']);
foreach ($contacts as $contact) foreach ($contacts as $contact) {
{
$numbers[] = $contact['number']; $numbers[] = $contact['number'];
} }
} }
$smsStops = $db->getFromTableWhere('smsstop'); $smsStops = $db->getFromTableWhere('smsstop');
foreach ($numbers as $number) foreach ($numbers as $number) {
{
//Si les SMS STOP sont activés, on passe au numéro suivant si le numéro actuelle fait parti des SMS STOP //Si les SMS STOP sont activés, on passe au numéro suivant si le numéro actuelle fait parti des SMS STOP
if (RASPISMS_SETTINGS_SMSSTOPS) if (RASPISMS_SETTINGS_SMSSTOPS) {
{ foreach ($smsStops as $smsStop) {
foreach ($smsStops as $smsStop) if (!($number == $smsStop['number'])) {
{
if (!($number == $smsStop['number']))
{
continue; continue;
} }
@ -160,8 +141,7 @@ class Console extends \InternalController
$now = $now->format('Y-m-d H:i:s'); $now = $now->format('Y-m-d H:i:s');
//On peut maintenant ajouter le SMS //On peut maintenant ajouter le SMS
if (!$db->insertIntoTable('sendeds', ['at' => $now, 'target' => $number, 'content' => $scheduled['content'], 'before_delivered' => ceil(mb_strlen($scheduled['content'])/160)])) if (!$db->insertIntoTable('sendeds', ['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"; echo 'Impossible d\'inserer le sms pour le numero ' . $number . "\n";
} }
@ -170,8 +150,7 @@ class Console extends \InternalController
//Commande qui envoie le SMS //Commande qui envoie le SMS
$commande_send_sms = 'gammu-smsd-inject TEXT ' . escapeshellarg($number) . ' -report -len ' . mb_strlen($text_sms) . ' -text ' . $text_sms; $commande_send_sms = 'gammu-smsd-inject TEXT ' . escapeshellarg($number) . ' -report -len ' . mb_strlen($text_sms) . ' -text ' . $text_sms;
if (RASPISMS_SETTINGS_SMS_FLASH && $flash) if (RASPISMS_SETTINGS_SMS_FLASH && $flash) {
{
$commande_send_sms .= ' -flash'; $commande_send_sms .= ' -flash';
} }
@ -200,13 +179,10 @@ class Console extends \InternalController
//On créer l'objet de base de données //On créer l'objet de base de données
global $db; global $db;
for ($i = 0; $i < 30; $i++) for ($i = 0; $i < 30; $i++) {
{ foreach (scandir(PWD_RECEIVEDS) as $dir) {
foreach (scandir(PWD_RECEIVEDS) as $dir)
{
//Si le fichier est un fichier système, on passe à l'itération suivante //Si le fichier est un fichier système, on passe à l'itération suivante
if ($dir == '.' || $dir == '..' || $dir == '.tokeep') if ($dir == '.' || $dir == '..' || $dir == '.tokeep') {
{
continue; continue;
} }
@ -220,15 +196,13 @@ class Console extends \InternalController
$content_file = file_get_contents(PWD_RECEIVEDS . $dir); $content_file = file_get_contents(PWD_RECEIVEDS . $dir);
//Si on peux pas ouvrir le fichier, on quitte en logant une erreur //Si on peux pas ouvrir le fichier, on quitte en logant une erreur
if ($content_file == false) if ($content_file == false) {
{
$this->wlog('Unable to read file "' . $dir); $this->wlog('Unable to read file "' . $dir);
die(4); die(4);
} }
//On supprime le fichier. Si on n'y arrive pas, alors on log //On supprime le fichier. Si on n'y arrive pas, alors on log
if (!unlink(PWD_RECEIVEDS . $dir)) if (!unlink(PWD_RECEIVEDS . $dir)) {
{
$this->wlog('Unable to delete file "' . $dir); $this->wlog('Unable to delete file "' . $dir);
die(8); die(8);
} }
@ -236,8 +210,7 @@ class Console extends \InternalController
$content_file = explode(':', $content_file, 2); $content_file = explode(':', $content_file, 2);
//Si on a pas passé de numéro ou de message, alors on lève une erreur //Si on a pas passé de numéro ou de message, alors on lève une erreur
if (!isset($content_file[0], $content_file[1])) if (!isset($content_file[0], $content_file[1])) {
{
$this->wlog('Missing params in file "' . $dir); $this->wlog('Missing params in file "' . $dir);
die(5); die(5);
} }
@ -247,8 +220,7 @@ class Console extends \InternalController
$text = $content_file[1]; $text = $content_file[1];
//On gère les SMS STOP //On gère les SMS STOP
if (trim($text) == 'STOP') if (trim($text) == 'STOP') {
{
echo 'STOP SMS detected ' . $number . "\n"; echo 'STOP SMS detected ' . $number . "\n";
$this->wlog('STOP SMS detected ' . $number); $this->wlog('STOP SMS detected ' . $number);
$db->insertIntoTable('smsstop', ['number' => $number]); $db->insertIntoTable('smsstop', ['number' => $number]);
@ -256,8 +228,7 @@ class Console extends \InternalController
} }
//On gère les accusés de reception //On gère les accusés de reception
if (trim($text) == 'Delivered' || trim($text) == 'Failed') if (trim($text) == 'Delivered' || trim($text) == 'Failed') {
{
echo 'Delivered or Failed SMS for ' . $number . "\n"; echo 'Delivered or Failed SMS for ' . $number . "\n";
$this->wlog('Delivered or Failed SMS for ' . $number); $this->wlog('Delivered or Failed SMS for ' . $number);
@ -266,24 +237,21 @@ class Console extends \InternalController
$interval = new \DateInterval('PT12H'); $interval = new \DateInterval('PT12H');
$sinceDate = $now->sub($interval)->format('Y-m-d H:i:s'); $sinceDate = $now->sub($interval)->format('Y-m-d H:i:s');
if (!$sendeds = $db->getFromTableWhere('sendeds', ['target' => $number, 'delivered' => false, 'failed' => false, '>at' => $sinceDate], 'at', false, 1)) if (!$sendeds = $db->getFromTableWhere('sendeds', ['target' => $number, 'delivered' => false, 'failed' => false, '>at' => $sinceDate], 'at', false, 1)) {
{
continue; continue;
} }
$sended = $sendeds[0]; $sended = $sendeds[0];
//On gère les echecs //On gère les echecs
if (trim($text) == 'Failed') if (trim($text) == 'Failed') {
{
$db->updateTableWhere('sendeds', ['before_delivered' => 0, 'failed' => true], ['id' => $sended['id']]); $db->updateTableWhere('sendeds', ['before_delivered' => 0, 'failed' => true], ['id' => $sended['id']]);
echo "Sended SMS id " . $sended['id'] . " pass to failed status\n"; echo "Sended SMS id " . $sended['id'] . " pass to failed status\n";
continue; continue;
} }
//On gère le cas des messages de plus de 160 caractères, lesquels impliquent plusieurs accusés //On gère le cas des messages de plus de 160 caractères, lesquels impliquent plusieurs accusés
if ($sended['before_delivered'] > 1) if ($sended['before_delivered'] > 1) {
{
$db->updateTableWhere('sendeds', ['before_delivered' => $sended['before_delivered'] - 1], ['id' => $sended['id']]); $db->updateTableWhere('sendeds', ['before_delivered' => $sended['before_delivered'] - 1], ['id' => $sended['id']]);
echo "Sended SMS id " . $sended['id'] . " before_delivered decrement\n"; echo "Sended SMS id " . $sended['id'] . " before_delivered decrement\n";
continue; continue;
@ -295,8 +263,7 @@ class Console extends \InternalController
continue; continue;
} }
if (!$number) if (!$number) {
{
$this->wlog('Invalid phone number in file "' . $dir); $this->wlog('Invalid phone number in file "' . $dir);
die(6); die(6);
} }
@ -309,28 +276,23 @@ class Console extends \InternalController
$found_commands = array(); $found_commands = array();
//Si on reçu des identifiants //Si on reçu des identifiants
if (array_key_exists('LOGIN', $flags) && array_key_exists('PASSWORD', $flags)) if (array_key_exists('LOGIN', $flags) && array_key_exists('PASSWORD', $flags)) {
{
//Si on a bien un utilisateur avec les identifiants reçus //Si on a bien un utilisateur avec les identifiants reçus
$user = $db->getUserFromEmail($flags['LOGIN']); $user = $db->getUserFromEmail($flags['LOGIN']);
$this->wlog('We found ' . count($user) . ' users'); $this->wlog('We found ' . count($user) . ' users');
if ($user && $user['password'] == sha1($flags['PASSWORD'])) if ($user && $user['password'] == sha1($flags['PASSWORD'])) {
{
$this->wlog('Password is valid'); $this->wlog('Password is valid');
//On va passer en revue toutes les commandes, pour voir si on en trouve dans ce message //On va passer en revue toutes les commandes, pour voir si on en trouve dans ce message
$commands = $db->getFromTableWhere('commands'); $commands = $db->getFromTableWhere('commands');
$this->wlog('We found ' . count($commands) . ' commands'); $this->wlog('We found ' . count($commands) . ' commands');
foreach ($commands as $command) foreach ($commands as $command) {
{
$command_name = mb_strtoupper($command['name']); $command_name = mb_strtoupper($command['name']);
if (array_key_exists($command_name, $flags)) if (array_key_exists($command_name, $flags)) {
{
$this->wlog('We found command ' . $command_name); $this->wlog('We found command ' . $command_name);
//Si la commande ne nécessite pas d'être admin, ou si on est admin //Si la commande ne nécessite pas d'être admin, ou si on est admin
if (!$command['admin'] || $user['admin']) if (!$command['admin'] || $user['admin']) {
{
$this->wlog('And the count is ok'); $this->wlog('And the count is ok');
$found_commands[$command_name] = PWD_SCRIPTS . $command['script'] . escapeshellcmd($flags[$command_name]); $found_commands[$command_name] = PWD_SCRIPTS . $command['script'] . escapeshellcmd($flags[$command_name]);
} }
@ -340,8 +302,7 @@ class Console extends \InternalController
} }
//On va supprimer le mot de passe du SMS pour pouvoir l'enregistrer sans danger //On va supprimer le mot de passe du SMS pour pouvoir l'enregistrer sans danger
if (isset($flags['PASSWORD'])) if (isset($flags['PASSWORD'])) {
{
$text = str_replace($flags['PASSWORD'], '*****', $text); $text = str_replace($flags['PASSWORD'], '*****', $text);
} }
@ -349,8 +310,7 @@ class Console extends \InternalController
$send_by = $number; $send_by = $number;
$content = $text; $content = $text;
$is_command = count($found_commands); $is_command = count($found_commands);
if (!$db->insertIntoTable('receiveds', ['at' => $date, 'send_by' => $send_by, 'content' => $content, 'is_command' => $is_command])) if (!$db->insertIntoTable('receiveds', ['at' => $date, 'send_by' => $send_by, 'content' => $content, 'is_command' => $is_command])) {
{
echo "Erreur lors de l'enregistrement du SMS\n"; echo "Erreur lors de l'enregistrement du SMS\n";
$this->wlog('Unable to process the SMS in file "' . $dir); $this->wlog('Unable to process the SMS in file "' . $dir);
die(7); die(7);
@ -360,8 +320,7 @@ class Console extends \InternalController
$db->insertIntoTable('transfers', ['id_received' => $db->lastId(), 'progress' => false]); $db->insertIntoTable('transfers', ['id_received' => $db->lastId(), 'progress' => false]);
//Chaque commande sera executée. //Chaque commande sera executée.
foreach ($found_commands as $command_name => $command) foreach ($found_commands as $command_name => $command) {
{
echo 'Execution de la commande : ' . $command_name . ' :: ' . $command . "\n"; echo 'Execution de la commande : ' . $command_name . ' :: ' . $command . "\n";
exec($command); exec($command);
} }
@ -377,8 +336,7 @@ class Console extends \InternalController
*/ */
public function sendTransfers() public function sendTransfers()
{ {
if (!RASPISMS_SETTINGS_TRANSFER) if (!RASPISMS_SETTINGS_TRANSFER) {
{
echo "Le transfer de SMS est désactivé ! \n"; echo "Le transfer de SMS est désactivé ! \n";
return false; return false;
} }
@ -388,8 +346,7 @@ class Console extends \InternalController
$ids_transfers = []; $ids_transfers = [];
$ids_receiveds = []; $ids_receiveds = [];
foreach ($transfers as $transfer) foreach ($transfers as $transfer) {
{
$ids_transfers[] = $transfer['id']; $ids_transfers[] = $transfer['id'];
$ids_receiveds[] = $transfer['id_received']; $ids_receiveds[] = $transfer['id_received'];
} }
@ -400,10 +357,8 @@ class Console extends \InternalController
$users = $db->getFromTableWhere('users', ['transfer' => true]); $users = $db->getFromTableWhere('users', ['transfer' => true]);
foreach ($users as $user) foreach ($users as $user) {
{ foreach ($receiveds as $received) {
foreach ($receiveds as $received)
{
echo "Transfer d'un SMS du " . $received['send_by'] . " à l'email " . $user['email']; echo "Transfer d'un SMS du " . $received['send_by'] . " à l'email " . $user['email'];
$to = $user['email']; $to = $user['email'];
$subject = '[RaspiSMS] - Transfert d\'un SMS du ' . $received['send_by']; $subject = '[RaspiSMS] - Transfert d\'un SMS du ' . $received['send_by'];

View File

@ -1,9 +1,10 @@
<?php <?php
namespace controllers\internals; namespace controllers\internals;
/** /**
* Classe des contactes * Classe des contactes
*/ */
class Contact extends \InternalController class Contact extends \descartes\InternalController
{ {
/** /**
@ -92,8 +93,7 @@ namespace controllers\internals;
$modelContact = new \models\Contact($this->bdd); $modelContact = new \models\Contact($this->bdd);
$result = $modelContact->insert($contact); $result = $modelContact->insert($contact);
if (!$result) if (!$result) {
{
return $result; return $result;
} }

View File

@ -4,7 +4,7 @@
/** /**
* Classe des Event * Classe des Event
*/ */
class Event extends \InternalController class Event extends \descartes\InternalController
{ {
/** /**
@ -59,5 +59,4 @@
return $modelEvent->insert($event); return $modelEvent->insert($event);
} }
} }

View File

@ -1,9 +1,10 @@
<?php <?php
namespace controllers\internals; namespace controllers\internals;
/** /**
* Classe des groupes * Classe des groupes
*/ */
class Groupe extends \InternalController class Groupe extends \descartes\InternalController
{ {
/** /**
@ -79,13 +80,11 @@ namespace controllers\internals;
]; ];
$id_groupe = $modelGroupe->insert($groupe); $id_groupe = $modelGroupe->insert($groupe);
if (!$id_groupe) if (!$id_groupe) {
{
return false; return false;
} }
foreach ($contacts_ids as $contact_id) foreach ($contacts_ids as $contact_id) {
{
$modelGroupe->insert_groupe_contact($id_groupe, $contact_id); $modelGroupe->insert_groupe_contact($id_groupe, $contact_id);
} }
@ -115,16 +114,13 @@ namespace controllers\internals;
$modelGroupe->delete_groupe_contact($id); $modelGroupe->delete_groupe_contact($id);
$nb_contact_insert = 0; $nb_contact_insert = 0;
foreach ($contacts_ids as $contact_id) foreach ($contacts_ids as $contact_id) {
{ if ($modelGroupe->insert_groupe_contact($id, $contact_id)) {
if ($modelGroupe->insert_groupe_contact($id, $contact_id))
{
$nb_contact_insert ++; $nb_contact_insert ++;
} }
} }
if (!$result && $nb_contact_insert != count($contacts_ids)) if (!$result && $nb_contact_insert != count($contacts_ids)) {
{
return false; return false;
} }
@ -142,5 +138,4 @@ namespace controllers\internals;
$modelGroupe = new \models\Groupe($this->bdd); $modelGroupe = new \models\Groupe($this->bdd);
return $modelGroupe->get_contact($id); return $modelGroupe->get_contact($id);
} }
} }

View File

@ -1,9 +1,10 @@
<?php <?php
namespace controllers\internals; namespace controllers\internals;
/** /**
* Classe des receivedes * Classe des receivedes
*/ */
class Received extends \InternalController class Received extends \descartes\InternalController
{ {
/** /**
@ -145,8 +146,7 @@ class Received extends \InternalController
$counts_by_day = $modelReceived->count_by_day_since($date); $counts_by_day = $modelReceived->count_by_day_since($date);
$return = []; $return = [];
foreach ($counts_by_day as $count_by_day) foreach ($counts_by_day as $count_by_day) {
{
$return[$count_by_day['at_ymd']] = $count_by_day['nb']; $return[$count_by_day['at_ymd']] = $count_by_day['nb'];
} }

View File

@ -1,9 +1,10 @@
<?php <?php
namespace controllers\internals; namespace controllers\internals;
/** /**
* Classe des smsstopes * Classe des smsstopes
*/ */
class SMSStop extends \InternalController class SMSStop extends \descartes\InternalController
{ {
/** /**
* Cette fonction retourne une liste des smsstopes sous forme d'un tableau * Cette fonction retourne une liste des smsstopes sous forme d'un tableau
@ -84,12 +85,10 @@ namespace controllers\internals;
$modelSMSStop = new \models\SMSStop($this->bdd); $modelSMSStop = new \models\SMSStop($this->bdd);
$nb_update = 0; $nb_update = 0;
foreach ($smsstops as $smsstop) foreach ($smsstops as $smsstop) {
{
$result = $modelSMSStop->update($smsstop['id'], $smsstop); $result = $modelSMSStop->update($smsstop['id'], $smsstop);
if ($result) if ($result) {
{
$nb_update ++; $nb_update ++;
} }
} }

View File

@ -1,9 +1,10 @@
<?php <?php
namespace controllers\internals; namespace controllers\internals;
/** /**
* Classe des scheduledes * Classe des scheduledes
*/ */
class Scheduled extends \InternalController class Scheduled extends \descartes\InternalController
{ {
/** /**
@ -76,26 +77,22 @@ namespace controllers\internals;
{ {
$modelScheduled = new \models\Scheduled($this->bdd); $modelScheduled = new \models\Scheduled($this->bdd);
if (!$id_scheduled = $modelScheduled->insert($scheduled)) if (!$id_scheduled = $modelScheduled->insert($scheduled)) {
{
$internalEvent = new \controllers\internals\Event($this->bdd); $internalEvent = new \controllers\internals\Event($this->bdd);
$internalEvent->create('SCHEDULED_ADD', 'Ajout d\'un SMS pour le ' . $date . '.'); $internalEvent->create('SCHEDULED_ADD', 'Ajout d\'un SMS pour le ' . $date . '.');
return false; return false;
} }
foreach ($numbers as $number) foreach ($numbers as $number) {
{
$modelScheduled->insert_scheduled_number($id_scheduled, $number); $modelScheduled->insert_scheduled_number($id_scheduled, $number);
} }
foreach ($contacts_ids as $contact_id) foreach ($contacts_ids as $contact_id) {
{
$modelScheduled->insert_scheduled_contact($id_scheduled, $contact_id); $modelScheduled->insert_scheduled_contact($id_scheduled, $contact_id);
} }
foreach ($groupes_ids as $groupe_id) foreach ($groupes_ids as $groupe_id) {
{
$modelScheduled->insert_scheduled_groupe($id_scheduled, $groupe_id); $modelScheduled->insert_scheduled_groupe($id_scheduled, $groupe_id);
} }
@ -115,26 +112,22 @@ namespace controllers\internals;
$modelScheduled = new \models\Scheduled($this->bdd); $modelScheduled = new \models\Scheduled($this->bdd);
$nb_update = 0; $nb_update = 0;
foreach ($scheduleds as $scheduled) foreach ($scheduleds as $scheduled) {
{
$result = $modelScheduled->update($scheduled['scheduled']['id'], $scheduled['scheduled']); $result = $modelScheduled->update($scheduled['scheduled']['id'], $scheduled['scheduled']);
$modelScheduled->delete_scheduled_number($scheduled['scheduled']['id']); $modelScheduled->delete_scheduled_number($scheduled['scheduled']['id']);
$modelScheduled->delete_scheduled_contact($scheduled['scheduled']['id']); $modelScheduled->delete_scheduled_contact($scheduled['scheduled']['id']);
$modelScheduled->delete_scheduled_groupe($scheduled['scheduled']['id']); $modelScheduled->delete_scheduled_groupe($scheduled['scheduled']['id']);
foreach ($scheduled['number'] as $number) foreach ($scheduled['number'] as $number) {
{
$modelScheduled->insert_scheduled_number($scheduled['scheduled']['id'], $number); $modelScheduled->insert_scheduled_number($scheduled['scheduled']['id'], $number);
} }
foreach ($scheduled['contact_ids'] as $contact_id) foreach ($scheduled['contact_ids'] as $contact_id) {
{
$modelScheduled->insert_scheduled_contact($scheduled['scheduled']['id'], $contact_id); $modelScheduled->insert_scheduled_contact($scheduled['scheduled']['id'], $contact_id);
} }
foreach ($scheduled['groupe_ids'] as $groupe_id) foreach ($scheduled['groupe_ids'] as $groupe_id) {
{
$modelScheduled->insert_scheduled_groupe($scheduled['scheduled']['id'], $groupe_id); $modelScheduled->insert_scheduled_groupe($scheduled['scheduled']['id'], $groupe_id);
} }

View File

@ -1,9 +1,10 @@
<?php <?php
namespace controllers\internals; namespace controllers\internals;
/** /**
* Classe des sendedes * Classe des sendedes
*/ */
class Sended extends \InternalController class Sended extends \descartes\InternalController
{ {
/** /**
@ -86,12 +87,10 @@ namespace controllers\internals;
$modelSended = new \models\Sended($this->bdd); $modelSended = new \models\Sended($this->bdd);
$nb_update = 0; $nb_update = 0;
foreach ($sendeds as $sended) foreach ($sendeds as $sended) {
{
$result = $modelSended->update($sended['id'], $sended); $result = $modelSended->update($sended['id'], $sended);
if ($result) if ($result) {
{
$nb_update ++; $nb_update ++;
} }
} }
@ -120,8 +119,7 @@ namespace controllers\internals;
$counts_by_day = $modelSended->count_by_day_since($date); $counts_by_day = $modelSended->count_by_day_since($date);
$return = []; $return = [];
foreach ($counts_by_day as $count_by_day) foreach ($counts_by_day as $count_by_day) {
{
$return[$count_by_day['at_ymd']] = $count_by_day['nb']; $return[$count_by_day['at_ymd']] = $count_by_day['nb'];
} }

View File

@ -1,7 +1,7 @@
<?php <?php
namespace controllers\internals; namespace controllers\internals;
class Setting extends \InternalController class Setting extends \descartes\InternalController
{ {
private $model_setting; private $model_setting;

View File

@ -1,6 +1,7 @@
<?php <?php
namespace controllers\internals; namespace controllers\internals;
class Tool extends \InternalController
class Tool extends \descartes\InternalController
{ {
/** /**
* Cette fonction parse un numéro pour le retourner sans espaces, etc. * Cette fonction parse un numéro pour le retourner sans espaces, etc.
@ -10,8 +11,7 @@
public static function parse_phone($number) public static function parse_phone($number)
{ {
$number = preg_replace('#[^-0-9+]#', '', $number); $number = preg_replace('#[^-0-9+]#', '', $number);
if (preg_match('#^(0|\+[1-9]{1,3}|\+1\-[0-9]{3})[1-9][0-9]{8,10}$#', $number)) if (preg_match('#^(0|\+[1-9]{1,3}|\+1\-[0-9]{3})[1-9][0-9]{8,10}$#', $number)) {
{
return $number; return $number;
} }
@ -35,8 +35,7 @@
*/ */
public static function event_type_to_icon($type) public static function event_type_to_icon($type)
{ {
switch ($type) switch ($type) {
{
case 'USER_ADD': case 'USER_ADD':
$logo = 'fa-user'; $logo = 'fa-user';
break; break;
@ -80,8 +79,7 @@
{ {
$returns = array(); $returns = array();
$results = array(); $results = array();
while(preg_match('#\[(.*)(?<!\\\):(.*)(?<!\\\)\]#Uui', $texte, $results)) //Tant qu'on recuèpre un flag while (preg_match('#\[(.*)(?<!\\\):(.*)(?<!\\\)\]#Uui', $texte, $results)) { //Tant qu'on recuèpre un flag
{
$returns[mb_strtoupper($results[1])] = $results[2]; $returns[mb_strtoupper($results[1])] = $results[2];
$texte = str_replace($results[0], '', $texte); $texte = str_replace($results[0], '', $texte);
} }
@ -100,8 +98,7 @@
$password = ''; $password = '';
$chars_length = mb_strlen($chars) - 1; $chars_length = mb_strlen($chars) - 1;
$i = 0; $i = 0;
while ($i < $length) while ($i < $length) {
{
$i ++; $i ++;
$password .= $chars[rand(0, $chars_length)]; $password .= $chars[rand(0, $chars_length)];
} }
@ -114,8 +111,7 @@
*/ */
public static function verify_connect() public static function verify_connect()
{ {
if (!isset($_SESSION['connect']) || !$_SESSION['connect']) if (!isset($_SESSION['connect']) || !$_SESSION['connect']) {
{
header('Location: /'); header('Location: /');
die(); die();
} }
@ -127,8 +123,7 @@
*/ */
public static function is_admin() public static function is_admin()
{ {
if (!isset($_SESSION['user']) || !$_SESSION['connect']['admin']) if (!isset($_SESSION['user']) || !$_SESSION['connect']['admin']) {
{
return false; return false;
} }

View File

@ -1,7 +1,7 @@
<?php <?php
namespace controllers\internals; namespace controllers\internals;
class User extends \InternalController class User extends \descartes\InternalController
{ {
private $model_user; private $model_user;
@ -41,13 +41,11 @@
public function check_credentials($email, $password) public function check_credentials($email, $password)
{ {
$user = $this->model_user->get_by_email($email); $user = $this->model_user->get_by_email($email);
if (!$user) if (!$user) {
{
return false; return false;
} }
if (!password_verify($password, $user['password'])) if (!password_verify($password, $user['password'])) {
{
return false; return false;
} }
@ -130,8 +128,7 @@
$result = $model_user->insert($user); $result = $model_user->insert($user);
if (!$result) if (!$result) {
{
return false; return false;
} }

View File

@ -3,7 +3,7 @@ namespace controllers\internals;
/** /**
* Classe des commandes * Classe des commandes
*/ */
class Command extends \InternalController class Command extends \descartes\InternalController
{ {
public function populate_database ($nb_entry = false, $page = false) public function populate_database ($nb_entry = false, $page = false)
@ -19,7 +19,7 @@ namespace controllers\internals;
$contact = [ $contact = [
'name' => 'Contact N°' . $i, 'name' => 'Contact N°' . $i,
'number' => '06' . rand(10,99) . rand(10,99) . rand(10,99) . rand(10,99), 'number' => '06' . rand(10,99) . rand(10,99) . rand(10,99) . rand(10,99),
] ];
if (!$id_contact = $internalContact->create($contact)) if (!$id_contact = $internalContact->create($contact))
{ {

View File

@ -1,7 +1,7 @@
<?php <?php
namespace controllers\publics; namespace controllers\publics;
class Account extends \Controller class Account extends \descartes\Controller
{ {
public $internal_user; public $internal_user;
@ -31,28 +31,25 @@
{ {
$password = $_POST['password'] ?? false; $password = $_POST['password'] ?? false;
if (!$this->verifyCSRF($csrf)) if (!$this->verifyCSRF($csrf)) {
{
\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Jeton CSRF invalid !'); \DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Jeton CSRF invalid !');
return header('Location: ' . \Router::url('Account', 'show')); return header('Location: ' . \descartes\Router::url('Account', 'show'));
} }
if (!$password) if (!$password) {
{
\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Vous devez renseigner un mot de passe.'); \DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Vous devez renseigner un mot de passe.');
return header('Location: ' . \Router::url('Account', 'show')); return header('Location: ' . \descartes\Router::url('Account', 'show'));
} }
$update_password_result = $this->internal_user->update_password($_SESSION['user']['id'], $password); $update_password_result = $this->internal_user->update_password($_SESSION['user']['id'], $password);
if (!$update_password_result) if (!$update_password_result) {
{
\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Impossible de mettre à jour le mot de passe.'); \DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Impossible de mettre à jour le mot de passe.');
return header('Location: ' . \Router::url('Account', 'show')); return header('Location: ' . \descartes\Router::url('Account', 'show'));
} }
\DescartesSessionMessages\internals\DescartesSessionMessages::push('success', 'Le mot de passe a bien été mis à jour.'); \DescartesSessionMessages\internals\DescartesSessionMessages::push('success', 'Le mot de passe a bien été mis à jour.');
return header('Location: ' . \Router::url('Account', 'show')); return header('Location: ' . \descartes\Router::url('Account', 'show'));
} }
/** /**
@ -64,29 +61,26 @@
{ {
$transfer = $_POST['transfer'] ?? false; $transfer = $_POST['transfer'] ?? false;
if (!$this->verifyCSRF($csrf)) if (!$this->verifyCSRF($csrf)) {
{
\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Jeton CSRF invalid !'); \DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Jeton CSRF invalid !');
return header('Location: ' . \Router::url('Account', 'show')); return header('Location: ' . \descartes\Router::url('Account', 'show'));
} }
if ($transfer === false) if ($transfer === false) {
{
\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Vous devez choisir une option parmis celles de la liste déroulante.'); \DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Vous devez choisir une option parmis celles de la liste déroulante.');
return header('Location: ' . \Router::url('Account', 'show')); return header('Location: ' . \descartes\Router::url('Account', 'show'));
} }
$transfer_update_result = $this->internal_user->update_transfer($_SESSION['user']['id'], $transfer); $transfer_update_result = $this->internal_user->update_transfer($_SESSION['user']['id'], $transfer);
if (!$transfer_update_result) if (!$transfer_update_result) {
{
\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Impossible de mettre à jour.'); \DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Impossible de mettre à jour.');
return header('Location: ' . \Router::url('Account', 'show')); return header('Location: ' . \descartes\Router::url('Account', 'show'));
} }
$_SESSION['user']['transfer'] = $transfer; $_SESSION['user']['transfer'] = $transfer;
\DescartesSessionMessages\internals\DescartesSessionMessages::push('success', 'Le transfert a bien été ' . ($transfer ? 'activé' : 'désactivé') . '.'); \DescartesSessionMessages\internals\DescartesSessionMessages::push('success', 'Le transfert a bien été ' . ($transfer ? 'activé' : 'désactivé') . '.');
return header('Location: ' . \Router::url('Account', 'show')); return header('Location: ' . \descartes\Router::url('Account', 'show'));
} }
/** /**
@ -97,37 +91,33 @@
*/ */
public function update_email($csrf) public function update_email($csrf)
{ {
if (!$this->verifyCSRF($csrf)) if (!$this->verifyCSRF($csrf)) {
{
\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Jeton CSRF invalid !'); \DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Jeton CSRF invalid !');
return header('Location: ' . \Router::url('Account', 'show')); return header('Location: ' . \descartes\Router::url('Account', 'show'));
} }
$email = $_POST['email'] ?? false; $email = $_POST['email'] ?? false;
if (!$email) if (!$email) {
{
\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Vous devez fournir une adresse e-mail !'); \DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Vous devez fournir une adresse e-mail !');
return header('Location: ' . \Router::url('Account', 'show')); return header('Location: ' . \descartes\Router::url('Account', 'show'));
} }
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
{
\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'L\'adresse e-mail n\'est pas une adresse valide.'); \DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'L\'adresse e-mail n\'est pas une adresse valide.');
return header('Location: ' . \Router::url('Account', 'show')); return header('Location: ' . \descartes\Router::url('Account', 'show'));
} }
$update_email_result = $this->internal_user->update_email($_SESSION['user']['id'], $email); $update_email_result = $this->internal_user->update_email($_SESSION['user']['id'], $email);
if (!$update_email_result) if (!$update_email_result) {
{
\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Impossible de mettre à jour.'); \DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Impossible de mettre à jour.');
return header('Location: ' . \Router::url('Account', 'show')); return header('Location: ' . \descartes\Router::url('Account', 'show'));
} }
$_SESSION['user']['email'] = $email; $_SESSION['user']['email'] = $email;
\DescartesSessionMessages\internals\DescartesSessionMessages::push('success', 'L\'email a bien été mis à jour.'); \DescartesSessionMessages\internals\DescartesSessionMessages::push('success', 'L\'email a bien été mis à jour.');
return header('Location: ' . \Router::url('Account', 'show')); return header('Location: ' . \descartes\Router::url('Account', 'show'));
} }
/** /**
@ -137,25 +127,22 @@
*/ */
public function delete($csrf) public function delete($csrf)
{ {
if (!$this->verifyCSRF($csrf)) if (!$this->verifyCSRF($csrf)) {
{
\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Jeton CSRF invalid !'); \DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Jeton CSRF invalid !');
return header('Location: ' . \Router::url('Account', 'show')); return header('Location: ' . \descartes\Router::url('Account', 'show'));
} }
$delete_account = $_POST['delete_account'] ?? false; $delete_account = $_POST['delete_account'] ?? false;
if (!$delete_account) if (!$delete_account) {
{
\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Pour supprimer le compte, vous devez cocher la case correspondante.'); \DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Pour supprimer le compte, vous devez cocher la case correspondante.');
return header('Location: ' . \Router::url('Account', 'show')); return header('Location: ' . \descartes\Router::url('Account', 'show'));
} }
$delete_account_result = $this->internal_user->delete($_SESSION['user']['id']); $delete_account_result = $this->internal_user->delete($_SESSION['user']['id']);
if (!$delete_account_result) if (!$delete_account_result) {
{
\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Impossible de supprimer le compte.'); \DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Impossible de supprimer le compte.');
return header('Location: ' . \Router::url('Account', 'show')); return header('Location: ' . \descartes\Router::url('Account', 'show'));
} }
return $this->logout(); return $this->logout();
@ -169,6 +156,6 @@
{ {
session_unset(); session_unset();
session_destroy(); session_destroy();
return header('Location: ' . \Router::url('Connect', 'login')); return header('Location: ' . \descartes\Router::url('Connect', 'login'));
} }
} }

View File

@ -1,9 +1,10 @@
<?php <?php
namespace controllers\publics; namespace controllers\publics;
/** /**
* Page des commandes * Page des commandes
*/ */
class Command extends \Controller class Command extends \descartes\Controller
{ {
public $bdd; public $bdd;
@ -35,20 +36,18 @@ namespace controllers\publics;
*/ */
public function delete($csrf) public function delete($csrf)
{ {
if (!$this->verifyCSRF($csrf)) if (!$this->verifyCSRF($csrf)) {
{
\modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Jeton CSRF invalid !'); \modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Jeton CSRF invalid !');
header('Location: ' . \Router::url('Command', 'list')); header('Location: ' . \descartes\Router::url('Command', 'list'));
return false; return false;
} }
$ids = $_GET['ids'] ?? []; $ids = $_GET['ids'] ?? [];
foreach ($ids as $id) foreach ($ids as $id) {
{
$this->internalCommand->delete($id); $this->internalCommand->delete($id);
} }
header('Location: ' . \Router::url('Command', 'list')); header('Location: ' . \descartes\Router::url('Command', 'list'));
return true; return true;
} }
@ -86,10 +85,9 @@ namespace controllers\publics;
*/ */
public function create($csrf) public function create($csrf)
{ {
if (!$this->verifyCSRF($csrf)) if (!$this->verifyCSRF($csrf)) {
{
\modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Jeton CSRF invalid !'); \modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Jeton CSRF invalid !');
header('Location: ' . \Router::url('Command', 'list')); header('Location: ' . \descartes\Router::url('Command', 'list'));
return false; return false;
} }
@ -97,21 +95,19 @@ namespace controllers\publics;
$script = $_POST['script'] ?? false; $script = $_POST['script'] ?? false;
$admin = (isset($_POST['admin']) ? $_POST['admin'] : false); $admin = (isset($_POST['admin']) ? $_POST['admin'] : false);
if (!$name || !$script) if (!$name || !$script) {
{
\modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Renseignez au moins un nom et un script.'); \modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Renseignez au moins un nom et un script.');
return header('Location: ' . \Router::url('Command', 'list')); return header('Location: ' . \descartes\Router::url('Command', 'list'));
} }
if (!$this->internalCommand->create($name, $script, $admin)) if (!$this->internalCommand->create($name, $script, $admin)) {
{
\modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Impossible créer cette commande.'); \modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Impossible créer cette commande.');
return header('Location: ' . \Router::url('commands', 'add')); return header('Location: ' . \descartes\Router::url('commands', 'add'));
} }
\modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('success', 'La commande a bien été crée.'); \modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('success', 'La commande a bien été crée.');
return header('Location: ' . \Router::url('Command', 'list')); return header('Location: ' . \descartes\Router::url('Command', 'list'));
} }
/** /**
@ -122,29 +118,26 @@ namespace controllers\publics;
*/ */
public function update($csrf) public function update($csrf)
{ {
if (!$this->verifyCSRF($csrf)) if (!$this->verifyCSRF($csrf)) {
{
\modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Jeton CSRF invalid !'); \modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Jeton CSRF invalid !');
header('Location: ' . \Router::url('Command', 'list')); header('Location: ' . \descartes\Router::url('Command', 'list'));
return false; return false;
} }
$nb_commands_update = 0; $nb_commands_update = 0;
foreach ($_POST['commands'] as $command) foreach ($_POST['commands'] as $command) {
{
$update_command = $this->internalCommand->update($command['id'], $command['name'], $command['script'], $command['admin']); $update_command = $this->internalCommand->update($command['id'], $command['name'], $command['script'], $command['admin']);
$nb_commands_update += (int) $update_command; $nb_commands_update += (int) $update_command;
} }
if ($nb_commands_update != count($_POST['commands'])) if ($nb_commands_update != count($_POST['commands'])) {
{
\modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Certaines commandes n\'ont pas pu êtres mises à jour.'); \modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Certaines commandes n\'ont pas pu êtres mises à jour.');
header('Location: ' . \Router::url('Command', 'list')); header('Location: ' . \descartes\Router::url('Command', 'list'));
return false; return false;
} }
\modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('success', 'Toutes les commandes ont été modifiées avec succès.'); \modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('success', 'Toutes les commandes ont été modifiées avec succès.');
header('Location: ' . \Router::url('Command', 'list')); header('Location: ' . \descartes\Router::url('Command', 'list'));
return true; return true;
} }
} }

View File

@ -4,7 +4,7 @@
/** /**
* Page de connexion * Page de connexion
*/ */
class Connect extends \Controller class Connect extends \descartes\Controller
{ {
/** /**
* Cette fonction est appelée avant toute les autres : * Cette fonction est appelée avant toute les autres :
@ -40,17 +40,16 @@
$password = $_POST['password'] ?? false; $password = $_POST['password'] ?? false;
$user = $this->internal_user->check_credentials($email, $password); $user = $this->internal_user->check_credentials($email, $password);
if (!$user) if (!$user) {
{
\modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Email ou mot de passe invalide.'); \modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Email ou mot de passe invalide.');
return header('Location: ' . \Router::url('Connect', 'login')); return header('Location: ' . \descartes\Router::url('Connect', 'login'));
} }
$_SESSION['connect'] = true; $_SESSION['connect'] = true;
$_SESSION['user'] = $user; $_SESSION['user'] = $user;
$_SESSION['csrf'] = str_shuffle(uniqid().uniqid()); $_SESSION['csrf'] = str_shuffle(uniqid().uniqid());
return header('Location: ' . \Router::url('Dashboard', 'show')); return header('Location: ' . \descartes\Router::url('Dashboard', 'show'));
} }
@ -70,27 +69,25 @@
*/ */
public function send_reset_password($csrf) public function send_reset_password($csrf)
{ {
if (!$this->verifyCSRF($csrf)) if (!$this->verifyCSRF($csrf)) {
{
\modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Jeton CSRF invalid !'); \modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Jeton CSRF invalid !');
header('Location: ' . \Router::url('Connect', 'forget_password')); header('Location: ' . \descartes\Router::url('Connect', 'forget_password'));
return false; return false;
} }
$email = $_POST['email'] ?? false; $email = $_POST['email'] ?? false;
$user = $this->internal_user->get_by_email($email); $user = $this->internal_user->get_by_email($email);
if (!$email || !$user) if (!$email || !$user) {
{
\modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Aucun utilisateur n\'existe pour cette adresse mail.'); \modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Aucun utilisateur n\'existe pour cette adresse mail.');
header('Location: ' . \Router::url('Connect', 'forget_password')); header('Location: ' . \descartes\Router::url('Connect', 'forget_password'));
return false; return false;
} }
$Tokenista = new \Ingenerator\Tokenista(APP_SECRET); $Tokenista = new \Ingenerator\Tokenista(APP_SECRET);
$token = $Tokenista->generate(3600, ['user_id' => $user['id']]); $token = $Tokenista->generate(3600, ['user_id' => $user['id']]);
$reset_link = \Router::url('Connect', 'reset_password', ['user_id' => $user['id'], 'token' => $token]); $reset_link = \descartes\Router::url('Connect', 'reset_password', ['user_id' => $user['id'], 'token' => $token]);
\controllers\internals\Tool::send_email($email, EMAIL_RESET_PASSWORD, ['reset_link' => $reset_link]); \controllers\internals\Tool::send_email($email, EMAIL_RESET_PASSWORD, ['reset_link' => $reset_link]);
@ -109,13 +106,11 @@
$Tokenista = new \Ingenerator\Tokenista(APP_SECRET); $Tokenista = new \Ingenerator\Tokenista(APP_SECRET);
if (!$Tokenista->isValid($token, ['user_id' => $user_id])) if (!$Tokenista->isValid($token, ['user_id' => $user_id])) {
{
return $this->render('connect/reset-password-invalid'); return $this->render('connect/reset-password-invalid');
} }
if (!$password) if (!$password) {
{
return $this->render('connect/reset-password'); return $this->render('connect/reset-password');
} }
@ -131,6 +126,6 @@
{ {
session_unset(); session_unset();
session_destroy(); session_destroy();
header('Location: ' . \Router::url('Connect', 'login')); header('Location: ' . \descartes\Router::url('Connect', 'login'));
} }
} }

View File

@ -1,9 +1,10 @@
<?php <?php
namespace controllers\publics; namespace controllers\publics;
/** /**
* Page des contacts * Page des contacts
*/ */
class Contact extends \Controller class Contact extends \descartes\Controller
{ {
/** /**
* Cette fonction est appelée avant toute les autres : * Cette fonction est appelée avant toute les autres :
@ -38,19 +39,17 @@ namespace controllers\publics;
*/ */
public function delete($csrf) public function delete($csrf)
{ {
if (!$this->verifyCSRF($csrf)) if (!$this->verifyCSRF($csrf)) {
{
\modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Jeton CSRF invalid !'); \modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Jeton CSRF invalid !');
return header('Location: ' . \Router::url('Contact', 'list')); return header('Location: ' . \descartes\Router::url('Contact', 'list'));
} }
$ids = $_GET['ids'] ?? []; $ids = $_GET['ids'] ?? [];
foreach ($ids as $id) foreach ($ids as $id) {
{
$this->internalContact->delete($id); $this->internalContact->delete($id);
} }
header('Location: ' . \Router::url('Contact', 'list')); header('Location: ' . \descartes\Router::url('Contact', 'list'));
return true; return true;
} }
@ -86,36 +85,32 @@ namespace controllers\publics;
*/ */
public function create($csrf) public function create($csrf)
{ {
if (!$this->verifyCSRF($csrf)) if (!$this->verifyCSRF($csrf)) {
{
\modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Jeton CSRF invalid !'); \modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Jeton CSRF invalid !');
return header('Location: ' . \Router::url('Contact', 'add')); return header('Location: ' . \descartes\Router::url('Contact', 'add'));
} }
$name = $_POST['name'] ?? false; $name = $_POST['name'] ?? false;
$number = $_POST['number'] ?? false; $number = $_POST['number'] ?? false;
if (!$name || !$number) if (!$name || !$number) {
{
\modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Des champs sont manquants !'); \modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Des champs sont manquants !');
return header('Location: ' . \Router::url('Contact', 'add')); return header('Location: ' . \descartes\Router::url('Contact', 'add'));
} }
$number = \controllers\internals\Tool::parse_phone($number); $number = \controllers\internals\Tool::parse_phone($number);
if (!$number) if (!$number) {
{
\modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Numéro de téléphone incorrect.'); \modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Numéro de téléphone incorrect.');
return header('Location: ' . \Router::url('Contact', 'add')); return header('Location: ' . \descartes\Router::url('Contact', 'add'));
} }
if (!$this->internalContact->create($number, $name)) if (!$this->internalContact->create($number, $name)) {
{
\modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Impossible de créer ce contact.'); \modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Impossible de créer ce contact.');
return header('Location: ' . \Router::url('Contact', 'add')); return header('Location: ' . \descartes\Router::url('Contact', 'add'));
} }
\modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('success', 'Le contact a bien été créé.'); \modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('success', 'Le contact a bien été créé.');
return header('Location: ' . \Router::url('Contact', 'list')); return header('Location: ' . \descartes\Router::url('Contact', 'list'));
} }
/** /**
@ -126,27 +121,24 @@ namespace controllers\publics;
*/ */
public function update($csrf) public function update($csrf)
{ {
if (!$this->verifyCSRF($csrf)) if (!$this->verifyCSRF($csrf)) {
{
\modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Jeton CSRF invalid !'); \modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Jeton CSRF invalid !');
return header('Location: ' . \Router::url('Contact', 'list')); return header('Location: ' . \descartes\Router::url('Contact', 'list'));
} }
$nb_contacts_update = 0; $nb_contacts_update = 0;
foreach ($_POST['contacts'] as $contact) foreach ($_POST['contacts'] as $contact) {
{
$nb_contacts_update += $this->internalContact->update($contact['id'], $contact['number'], $contact['name']); $nb_contacts_update += $this->internalContact->update($contact['id'], $contact['number'], $contact['name']);
} }
if ($nb_contacts_update != count($_POST['contacts'])) if ($nb_contacts_update != count($_POST['contacts'])) {
{
\modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Certais contacts n\'ont pas pu êtres mis à jour.'); \modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Certais contacts n\'ont pas pu êtres mis à jour.');
return header('Location: ' . \Router::url('Contact', 'list')); return header('Location: ' . \descartes\Router::url('Contact', 'list'));
} }
\modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('success', 'Tous les contacts ont été modifiés avec succès.'); \modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('success', 'Tous les contacts ont été modifiés avec succès.');
return header('Location: ' . \Router::url('Contact', 'list')); return header('Location: ' . \descartes\Router::url('Contact', 'list'));
} }
/** /**

View File

@ -1,9 +1,10 @@
<?php <?php
namespace controllers\publics; namespace controllers\publics;
/** /**
* Page d'index, qui gère l'affichage par défaut temporairement * Page d'index, qui gère l'affichage par défaut temporairement
*/ */
class Dashboard extends \Controller class Dashboard extends \descartes\Controller
{ {
/** /**
* Cette fonction est appelée avant toute les autres : * Cette fonction est appelée avant toute les autres :
@ -67,8 +68,7 @@ namespace controllers\publics;
$i = 0; $i = 0;
//On va construire un tableau avec la date en clef, et les données pour chaque date //On va construire un tableau avec la date en clef, et les données pour chaque date
while ($i < 7) while ($i < 7) {
{
$today_less_7_day->add($increment_day); $today_less_7_day->add($increment_day);
$i ++; $i ++;
$date_f = $today_less_7_day->format('Y-m-d'); $date_f = $today_less_7_day->format('Y-m-d');
@ -83,14 +83,12 @@ namespace controllers\publics;
$total_receiveds = 0; $total_receiveds = 0;
//0n remplie le tableau avec les données adaptées //0n remplie le tableau avec les données adaptées
foreach ($nb_sendeds_by_day as $date => $nb_sended) foreach ($nb_sendeds_by_day as $date => $nb_sended) {
{
$array_area_chart[$date]['sendeds'] = $nb_sended; $array_area_chart[$date]['sendeds'] = $nb_sended;
$total_sendeds += $nb_sended; $total_sendeds += $nb_sended;
} }
foreach ($nb_receiveds_by_day as $date => $nb_received) foreach ($nb_receiveds_by_day as $date => $nb_received) {
{
$array_area_chart[$date]['receiveds'] = $nb_received; $array_area_chart[$date]['receiveds'] = $nb_received;
$total_receiveds += $nb_received; $total_receiveds += $nb_received;
} }
@ -115,6 +113,5 @@ namespace controllers\publics;
'events' => $events, 'events' => $events,
'datas_area_chart' => json_encode($array_area_chart), 'datas_area_chart' => json_encode($array_area_chart),
)); ));
} }
} }

View File

@ -1,9 +1,10 @@
<?php <?php
namespace controllers\publics; namespace controllers\publics;
/** /**
* Page des discussions * Page des discussions
*/ */
class Discussion extends \Controller class Discussion extends \descartes\Controller
{ {
/** /**
* Cette fonction est appelée avant toute les autres : * Cette fonction est appelée avant toute les autres :
@ -32,10 +33,8 @@ namespace controllers\publics;
{ {
$discussions = $this->internalReceived->get_discussions(); $discussions = $this->internalReceived->get_discussions();
foreach ($discussions as $key => $discussion) foreach ($discussions as $key => $discussion) {
{ if (!$contact = $this->internalContact->get_by_number($discussion['number'])) {
if (!$contact = $this->internalContact->get_by_number($discussion['number']))
{
continue; continue;
} }
@ -67,7 +66,7 @@ namespace controllers\publics;
* @param string $number : Le numéro cible * @param string $number : Le numéro cible
* @param string $transaction_id : Le numéro unique de la transaction ajax (sert à vérifier si la requete doit être prise en compte) * @param string $transaction_id : Le numéro unique de la transaction ajax (sert à vérifier si la requete doit être prise en compte)
*/ */
function get_messages($number, $transaction_id) public function get_messages($number, $transaction_id)
{ {
$now = new \DateTime(); $now = new \DateTime();
$now = $now->format('Y-m-d H:i:s'); $now = $now->format('Y-m-d H:i:s');
@ -78,8 +77,7 @@ namespace controllers\publics;
$messages = []; $messages = [];
foreach ($sendeds as $sended) foreach ($sendeds as $sended) {
{
$messages[] = array( $messages[] = array(
'date' => htmlspecialchars($sended['at']), 'date' => htmlspecialchars($sended['at']),
'text' => htmlspecialchars($sended['content']), 'text' => htmlspecialchars($sended['content']),
@ -88,8 +86,7 @@ namespace controllers\publics;
); );
} }
foreach ($receiveds as $received) foreach ($receiveds as $received) {
{
$messages[] = array( $messages[] = array(
'date' => htmlspecialchars($received['at']), 'date' => htmlspecialchars($received['at']),
'text' => htmlspecialchars($received['content']), 'text' => htmlspecialchars($received['content']),
@ -98,8 +95,7 @@ namespace controllers\publics;
); );
} }
foreach ($scheduleds as $scheduled) foreach ($scheduleds as $scheduled) {
{
$messages[] = array( $messages[] = array(
'date' => htmlspecialchars($scheduled['at']), 'date' => htmlspecialchars($scheduled['at']),
'text' => htmlspecialchars($scheduled['content']), 'text' => htmlspecialchars($scheduled['content']),
@ -126,13 +122,12 @@ namespace controllers\publics;
* @param string $_POST['numbers'] : Un tableau avec le numero des gens auxquel envoyer le sms * @param string $_POST['numbers'] : Un tableau avec le numero des gens auxquel envoyer le sms
* @return json : Le statut de l'envoi * @return json : Le statut de l'envoi
*/ */
function send ($csrf) public function send($csrf)
{ {
$return = ['success' => true, 'message' => '']; $return = ['success' => true, 'message' => ''];
//On vérifie que le jeton csrf est bon //On vérifie que le jeton csrf est bon
if (!$this->verifyCSRF($csrf)) if (!$this->verifyCSRF($csrf)) {
{
$return['success'] = false; $return['success'] = false;
$return['message'] = 'Jeton CSRF invalide'; $return['message'] = 'Jeton CSRF invalide';
echo json_encode($return); echo json_encode($return);
@ -147,16 +142,14 @@ namespace controllers\publics;
$scheduled['content'] = $_POST['content'] ?? ''; $scheduled['content'] = $_POST['content'] ?? '';
$numbers = $_POST['numbers'] ?? false; $numbers = $_POST['numbers'] ?? false;
if (!$numbers) if (!$numbers) {
{
$return['success'] = false; $return['success'] = false;
$return['message'] = 'Vous devez renseigner un numéro valide'; $return['message'] = 'Vous devez renseigner un numéro valide';
echo json_encode($return); echo json_encode($return);
return false; return false;
} }
if (!$this->internalScheduled->create($scheduled, $numbers)) if (!$this->internalScheduled->create($scheduled, $numbers)) {
{
$return['success'] = false; $return['success'] = false;
$return['message'] = 'Impossible de créer le SMS'; $return['message'] = 'Impossible de créer le SMS';
echo json_encode($return); echo json_encode($return);
@ -171,7 +164,7 @@ namespace controllers\publics;
* Cette fonction retourne les id des sms qui sont envoyés * Cette fonction retourne les id des sms qui sont envoyés
* @return json : Tableau des ids des sms qui sont envoyés * @return json : Tableau des ids des sms qui sont envoyés
*/ */
function checksendeds () public function checksendeds()
{ {
$_SESSION['discussion_wait_progress'] = isset($_SESSION['discussion_wait_progress']) ? $_SESSION['discussion_wait_progress'] : []; $_SESSION['discussion_wait_progress'] = isset($_SESSION['discussion_wait_progress']) ? $_SESSION['discussion_wait_progress'] : [];
@ -179,19 +172,15 @@ namespace controllers\publics;
//On va chercher à chaque fois si on a trouvé le sms. Si ce n'est pas le cas c'est qu'il a été envoyé //On va chercher à chaque fois si on a trouvé le sms. Si ce n'est pas le cas c'est qu'il a été envoyé
$sendeds = []; $sendeds = [];
foreach ($_SESSION['discussion_wait_progress'] as $key => $id_scheduled) foreach ($_SESSION['discussion_wait_progress'] as $key => $id_scheduled) {
{
$found = false; $found = false;
foreach ($scheduleds as $scheduled) foreach ($scheduleds as $scheduled) {
{ if ($id == $scheduled['id']) {
if ($id == $scheduled['id'])
{
$found = true; $found = true;
} }
} }
if (!$found) if (!$found) {
{
unset($_SESSION['discussion_wait_progress'][$key]); unset($_SESSION['discussion_wait_progress'][$key]);
$sendeds[] = $id; $sendeds[] = $id;
} }
@ -206,7 +195,7 @@ namespace controllers\publics;
* @param string $number : Le numéro de téléphone pour lequel on veux les messages * @param string $number : Le numéro de téléphone pour lequel on veux les messages
* @return json : Un tableau avec les messages * @return json : Un tableau avec les messages
*/ */
function checkreceiveds ($number) public function checkreceiveds($number)
{ {
$now = new \DateTime(); $now = new \DateTime();
$now = $now->format('Y-m-d H:i'); $now = $now->format('Y-m-d H:i');
@ -218,11 +207,9 @@ namespace controllers\publics;
//On va gérer le cas des messages en double en stockant ceux déjà reçus et en eliminant les autres //On va gérer le cas des messages en double en stockant ceux déjà reçus et en eliminant les autres
$_SESSION['discussion_already_receiveds'] = isset($_SESSION['discussion_already_receiveds']) ? $_SESSION['discussion_already_receiveds'] : []; $_SESSION['discussion_already_receiveds'] = isset($_SESSION['discussion_already_receiveds']) ? $_SESSION['discussion_already_receiveds'] : [];
foreach ($receiveds as $key => $received) foreach ($receiveds as $key => $received) {
{
//Sms jamais recu //Sms jamais recu
if (array_search($received['id'], $_SESSION['discussion_already_receiveds']) === false) if (array_search($received['id'], $_SESSION['discussion_already_receiveds']) === false) {
{
$_SESSION['discussion_already_receiveds'][] = $received['id']; $_SESSION['discussion_already_receiveds'][] = $received['id'];
continue; continue;
} }

View File

@ -1,9 +1,10 @@
<?php <?php
namespace controllers\publics; namespace controllers\publics;
/** /**
* Page des events * Page des events
*/ */
class Event extends \Controller class Event extends \descartes\Controller
{ {
/** /**
* Cette fonction est appelée avant toute les autres : * Cette fonction est appelée avant toute les autres :
@ -38,24 +39,21 @@ namespace controllers\publics;
*/ */
public function delete($csrf) public function delete($csrf)
{ {
if (!$this->verifyCSRF($csrf)) if (!$this->verifyCSRF($csrf)) {
{
\modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Jeton CSRF invalid !'); \modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Jeton CSRF invalid !');
return header('Location: ' . \Router::url('Event', 'list')); return header('Location: ' . \descartes\Router::url('Event', 'list'));
} }
if (!\controllers\internals\Tool::is_admin()) if (!\controllers\internals\Tool::is_admin()) {
{
\modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Vous devez être admin pour pouvoir supprimer des events.'); \modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Vous devez être admin pour pouvoir supprimer des events.');
return header('Location: ' . \Router::url('Event', 'list')); return header('Location: ' . \descartes\Router::url('Event', 'list'));
} }
$ids = $_GET['ids'] ?? []; $ids = $_GET['ids'] ?? [];
foreach ($ids as $id) foreach ($ids as $id) {
{
$this->internalEvent->delete($id); $this->internalEvent->delete($id);
} }
return header('Location: ' . \Router::url('Event', 'list')); return header('Location: ' . \descartes\Router::url('Event', 'list'));
} }
} }

View File

@ -1,9 +1,10 @@
<?php <?php
namespace controllers\publics; namespace controllers\publics;
/** /**
* Page des groupes * Page des groupes
*/ */
class Groupe extends \Controller class Groupe extends \descartes\Controller
{ {
/** /**
* Cette fonction est appelée avant toute les autres : * Cette fonction est appelée avant toute les autres :
@ -30,8 +31,7 @@ namespace controllers\publics;
$page = (int) $page; $page = (int) $page;
$groupes = $this->internalGroupe->get_list(25, $page); $groupes = $this->internalGroupe->get_list(25, $page);
foreach ($groupes as $key => $groupe) foreach ($groupes as $key => $groupe) {
{
$contacts = $this->internalGroupe->get_contact($groupe['id']); $contacts = $this->internalGroupe->get_contact($groupe['id']);
$groupes[$key]['nb_contacts'] = count($contacts); $groupes[$key]['nb_contacts'] = count($contacts);
} }
@ -46,17 +46,16 @@ namespace controllers\publics;
*/ */
public function delete($csrf) public function delete($csrf)
{ {
if (!$this->verifyCSRF($csrf)) if (!$this->verifyCSRF($csrf)) {
{
\modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Jeton CSRF invalid !'); \modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Jeton CSRF invalid !');
header('Location: ' . \Router::url('Groupe', 'list')); header('Location: ' . \descartes\Router::url('Groupe', 'list'));
return false; return false;
} }
$ids = $_GET['ids'] ?? []; $ids = $_GET['ids'] ?? [];
$this->internalGroupe->delete($ids); $this->internalGroupe->delete($ids);
header('Location: ' . \Router::url('Groupe', 'list')); header('Location: ' . \descartes\Router::url('Groupe', 'list'));
return true; return true;
} }
@ -76,11 +75,9 @@ namespace controllers\publics;
{ {
$ids = $_GET['ids'] ?? []; $ids = $_GET['ids'] ?? [];
$groupes = $this->internalGroupe->get_by_ids $groupes = $this->internalGroupe->get_by_ids($ids);
($ids);
foreach ($groupes as $key => $groupe) foreach ($groupes as $key => $groupe) {
{
$groupes[$key]['contacts'] = $this->internalGroupe->get_contact($groupe['id']); $groupes[$key]['contacts'] = $this->internalGroupe->get_contact($groupe['id']);
} }
@ -97,30 +94,27 @@ namespace controllers\publics;
*/ */
public function create($csrf) public function create($csrf)
{ {
if (!$this->verifyCSRF($csrf)) if (!$this->verifyCSRF($csrf)) {
{
\modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Jeton CSRF invalid !'); \modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Jeton CSRF invalid !');
return header('Location: ' . \Router::url('Groupe', 'add')); return header('Location: ' . \descartes\Router::url('Groupe', 'add'));
} }
$name = $_POST['name'] ?? false; $name = $_POST['name'] ?? false;
$contacts_ids = $_POST['contacts'] ?? false; $contacts_ids = $_POST['contacts'] ?? false;
if (!$name || !$contacts_ids) if (!$name || !$contacts_ids) {
{
\modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Des champs sont manquants !'); \modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Des champs sont manquants !');
return header('Location: ' . \Router::url('Groupe', 'add')); return header('Location: ' . \descartes\Router::url('Groupe', 'add'));
} }
$id_groupe = $this->internalGroupe->create($name, $contacts_ids); $id_groupe = $this->internalGroupe->create($name, $contacts_ids);
if (!$id_groupe) if (!$id_groupe) {
{
\modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Impossible de créer ce groupe.'); \modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Impossible de créer ce groupe.');
return header('Location: ' . \Router::url('Groupe', 'add')); return header('Location: ' . \descartes\Router::url('Groupe', 'add'));
} }
\modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('success', 'Le groupe a bien été créé.'); \modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('success', 'Le groupe a bien été créé.');
return header('Location: ' . \Router::url('Groupe', 'list')); return header('Location: ' . \descartes\Router::url('Groupe', 'list'));
} }
/** /**
@ -131,29 +125,26 @@ namespace controllers\publics;
*/ */
public function update($csrf) public function update($csrf)
{ {
if (!$this->verifyCSRF($csrf)) if (!$this->verifyCSRF($csrf)) {
{
\modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Jeton CSRF invalid !'); \modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Jeton CSRF invalid !');
header('Location: ' . \Router::url('Groupe', 'list')); header('Location: ' . \descartes\Router::url('Groupe', 'list'));
return false; return false;
} }
$groupes = $_POST['groupes'] ?? []; $groupes = $_POST['groupes'] ?? [];
$nb_groupes_update = 0; $nb_groupes_update = 0;
foreach ($groupes as $id => $groupe) foreach ($groupes as $id => $groupe) {
{
$nb_groupes_update += (int) $this->internalGroupe->update($id, $groupe['name'], $groupe['contacts_ids']); $nb_groupes_update += (int) $this->internalGroupe->update($id, $groupe['name'], $groupe['contacts_ids']);
} }
if ($nb_groupes_update != count($groupes)) if ($nb_groupes_update != count($groupes)) {
{
\modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Certains groupes n\'ont pas pu êtres mis à jour.'); \modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Certains groupes n\'ont pas pu êtres mis à jour.');
return header('Location: ' . \Router::url('Groupe', 'list')); return header('Location: ' . \descartes\Router::url('Groupe', 'list'));
} }
\modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('success', 'Tous les groupes ont été modifiés avec succès.'); \modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('success', 'Tous les groupes ont été modifiés avec succès.');
return header('Location: ' . \Router::url('Groupe', 'list')); return header('Location: ' . \descartes\Router::url('Groupe', 'list'));
} }
/** /**

View File

@ -1,9 +1,10 @@
<?php <?php
namespace controllers\publics; namespace controllers\publics;
/** /**
* Page des receiveds * Page des receiveds
*/ */
class Received extends \Controller class Received extends \descartes\Controller
{ {
/** /**
* Cette fonction est appelée avant toute les autres : * Cette fonction est appelée avant toute les autres :
@ -30,10 +31,8 @@ namespace controllers\publics;
$limit = 25; $limit = 25;
$receiveds = $this->internalReceived->get_list($limit, $page); $receiveds = $this->internalReceived->get_list($limit, $page);
foreach ($receiveds as $key => $received) foreach ($receiveds as $key => $received) {
{ if (!$contact = $this->internalContact->get_by_number($received['origin'])) {
if (!$contact = $this->internalContact->get_by_number($received['origin']))
{
continue; continue;
} }
@ -52,10 +51,8 @@ namespace controllers\publics;
$now = new \DateTime(); $now = new \DateTime();
$receiveds = $this->internalReceived->get_since_by_date($now->format('Y-m-d')); $receiveds = $this->internalReceived->get_since_by_date($now->format('Y-m-d'));
foreach ($receiveds as $key => $received) foreach ($receiveds as $key => $received) {
{ if (!$contact = $this->internalContact->get_by_number($received['origin'])) {
if (!$contact = $this->internalContact->get_by_number($received['origin']))
{
continue; continue;
} }
@ -64,8 +61,7 @@ namespace controllers\publics;
$nb_received = count($receiveds); $nb_received = count($receiveds);
if (!isset($_SESSION['popup_nb_receiveds']) || $_SESSION['popup_nb_receiveds'] > $nb_receiveds) if (!isset($_SESSION['popup_nb_receiveds']) || $_SESSION['popup_nb_receiveds'] > $nb_receiveds) {
{
$_SESSION['popup_nb_receiveds'] = $nb_received; $_SESSION['popup_nb_receiveds'] = $nb_received;
} }
@ -84,24 +80,21 @@ namespace controllers\publics;
*/ */
public function delete($csrf) public function delete($csrf)
{ {
if (!$this->verifyCSRF($csrf)) if (!$this->verifyCSRF($csrf)) {
{
\modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Jeton CSRF invalid !'); \modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Jeton CSRF invalid !');
return header('Location: ' . \Router::url('Received', 'list')); return header('Location: ' . \descartes\Router::url('Received', 'list'));
} }
if (!\controllers\internals\Tool::is_admin()) if (!\controllers\internals\Tool::is_admin()) {
{
\modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Vous devez être administrateur pour effectuer cette action.'); \modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Vous devez être administrateur pour effectuer cette action.');
return header('Location: ' . \Router::url('Received', 'list')); return header('Location: ' . \descartes\Router::url('Received', 'list'));
} }
$ids = $_GET['ids'] ?? []; $ids = $_GET['ids'] ?? [];
foreach ($ids as $id) foreach ($ids as $id) {
{
$this->internalReceived->delete($id); $this->internalReceived->delete($id);
} }
return header('Location: ' . \Router::url('Received', 'list')); return header('Location: ' . \descartes\Router::url('Received', 'list'));
} }
} }

View File

@ -1,9 +1,10 @@
<?php <?php
namespace controllers\publics; namespace controllers\publics;
/** /**
* Page des smsapis * Page des smsapis
*/ */
class SMSAPI extends \Controller class SMSAPI extends \descartes\Controller
{ {
//On défini les constantes qui servent pour les retours d'API //On défini les constantes qui servent pour les retours d'API
const API_ERROR_NO = 0; const API_ERROR_NO = 0;
@ -41,16 +42,15 @@ namespace controllers\publics;
public function api() public function api()
{ {
//On récupère l'email et le password //On récupère l'email et le password
$email = isset($_GET['email']) ? $_GET['email'] : NULL; $email = isset($_GET['email']) ? $_GET['email'] : null;
$email = isset($_POST['email']) ? $_POST['email'] : $email; $email = isset($_POST['email']) ? $_POST['email'] : $email;
$password = isset($_GET['password']) ? $_GET['password'] : NULL; $password = isset($_GET['password']) ? $_GET['password'] : null;
$password = isset($_POST['password']) ? $_POST['password'] : $password; $password = isset($_POST['password']) ? $_POST['password'] : $password;
//Si les identifiants sont incorrect on retourne une erreur //Si les identifiants sont incorrect on retourne une erreur
$user = $internal_user->check_credentials($email, $password); $user = $internal_user->check_credentials($email, $password);
if (!$user) if (!$user) {
{
echo json_encode(array( echo json_encode(array(
'error' => self::API_ERROR_BAD_ID, 'error' => self::API_ERROR_BAD_ID,
)); ));
@ -68,9 +68,9 @@ namespace controllers\publics;
$post_groupes = isset($_POST['groupes']) ? $_POST['groupes'] : array(); $post_groupes = isset($_POST['groupes']) ? $_POST['groupes'] : array();
//On map le texte et la date à part car c'est les seuls arguments qui ne sera jamais un tableau //On map le texte et la date à part car c'est les seuls arguments qui ne sera jamais un tableau
$text = isset($_GET['text']) ? $_GET['text'] : NULL; $text = isset($_GET['text']) ? $_GET['text'] : null;
$text = isset($_POST['text']) ? $_POST['text'] : $text; $text = isset($_POST['text']) ? $_POST['text'] : $text;
$date = isset($_GET['date']) ? $_GET['date'] : NULL; $date = isset($_GET['date']) ? $_GET['date'] : null;
$date = isset($_POST['date']) ? $_POST['date'] : $date; $date = isset($_POST['date']) ? $_POST['date'] : $date;
//On passe tous les paramètres GET en tableau //On passe tous les paramètres GET en tableau
@ -89,10 +89,8 @@ namespace controllers\publics;
$groupes = array_merge($get_groupes, $post_groupes); $groupes = array_merge($get_groupes, $post_groupes);
//Pour chaque contact, on récupère l'id du contact //Pour chaque contact, on récupère l'id du contact
foreach ($contacts as $key => $contact) foreach ($contacts as $key => $contact) {
{ if (!$contact = $internalContact->get_by_name($contact)) {
if (!$contact = $internalContact->get_by_name($contact))
{
unset($contacts[$key]); unset($contacts[$key]);
continue; continue;
} }
@ -101,10 +99,8 @@ namespace controllers\publics;
} }
//Pour chaque groupe, on récupère l'id du groupe //Pour chaque groupe, on récupère l'id du groupe
foreach ($groupes as $key => $name) foreach ($groupes as $key => $name) {
{ if (!$groupe = $internalContact->get_by_name($groupe)) {
if (!$groupe = $internalContact->get_by_name($groupe))
{
unset($groupes[$key]); unset($groupes[$key]);
continue; continue;
} }
@ -113,15 +109,13 @@ namespace controllers\publics;
} }
//Si la date n'est pas définie, on la met à la date du jour //Si la date n'est pas définie, on la met à la date du jour
if (!$date) if (!$date) {
{
$now = new \DateTime(); $now = new \DateTime();
$date = $now->format('Y-m-d H:i'); $date = $now->format('Y-m-d H:i');
} }
//Si il manque des champs essentiels, on leve une erreur //Si il manque des champs essentiels, on leve une erreur
if (!$text || (!$numbers && !$contacts && !$groupes)) if (!$text || (!$numbers && !$contacts && !$groupes)) {
{
echo json_encode(array( echo json_encode(array(
'error' => self::API_ERROR_MISSING_FIELD, 'error' => self::API_ERROR_MISSING_FIELD,
)); ));
@ -129,8 +123,7 @@ namespace controllers\publics;
} }
//On assigne les variable POST (après avoir vidé $_POST) en prévision de la création du SMS //On assigne les variable POST (après avoir vidé $_POST) en prévision de la création du SMS
if (!$this->internalScheduled->create(['at' => $date, 'content' => $text], $numbers, $contacts, $groupes)) if (!$this->internalScheduled->create(['at' => $date, 'content' => $text], $numbers, $contacts, $groupes)) {
{
echo json_encode(array( echo json_encode(array(
'error' => self::API_ERROR_CREATION_FAILED, 'error' => self::API_ERROR_CREATION_FAILED,
)); ));
@ -142,5 +135,4 @@ namespace controllers\publics;
)); ));
return true; return true;
} }
} }

View File

@ -1,9 +1,10 @@
<?php <?php
namespace controllers\publics; namespace controllers\publics;
/** /**
* Page des smsstops * Page des smsstops
*/ */
class SMSStop extends \Controller class SMSStop extends \descartes\Controller
{ {
/** /**
* Cette fonction est appelée avant toute les autres : * Cette fonction est appelée avant toute les autres :
@ -38,25 +39,21 @@ namespace controllers\publics;
*/ */
public function delete($csrf) public function delete($csrf)
{ {
if (!$this->verifyCSRF($csrf)) if (!$this->verifyCSRF($csrf)) {
{
\modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Jeton CSRF invalid !'); \modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Jeton CSRF invalid !');
return header('Location: ' . \Router::url('SMSStop', 'list')); return header('Location: ' . \descartes\Router::url('SMSStop', 'list'));
} }
if (!\controllers\internals\Tool::is_admin()) if (!\controllers\internals\Tool::is_admin()) {
{
\modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Vous devez être administrateur pour pouvoir supprimer un "STOP SMS" !'); \modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Vous devez être administrateur pour pouvoir supprimer un "STOP SMS" !');
return header('Location: ' . \Router::url('SMSStop', 'list')); return header('Location: ' . \descartes\Router::url('SMSStop', 'list'));
} }
$ids = $_GET['ids'] ?? []; $ids = $_GET['ids'] ?? [];
foreach ($ids as $id) foreach ($ids as $id) {
{
$this->internalSMSStop->delete($id); $this->internalSMSStop->delete($id);
} }
return header('Location: ' . \Router::url('SMSStop', 'list')); return header('Location: ' . \descartes\Router::url('SMSStop', 'list'));
} }
} }

View File

@ -1,9 +1,10 @@
<?php <?php
namespace controllers\publics; namespace controllers\publics;
/** /**
* Page des scheduleds * Page des scheduleds
*/ */
class Scheduled extends \Controller class Scheduled extends \descartes\Controller
{ {
/** /**
* Cette fonction est appelée avant toute les autres : * Cette fonction est appelée avant toute les autres :
@ -38,19 +39,17 @@ namespace controllers\publics;
*/ */
public function delete($csrf) public function delete($csrf)
{ {
if (!$this->verifyCSRF($csrf)) if (!$this->verifyCSRF($csrf)) {
{
\modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Jeton CSRF invalid !'); \modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Jeton CSRF invalid !');
return header('Location: ' . \Router::url('Scheduled', 'list')); return header('Location: ' . \descartes\Router::url('Scheduled', 'list'));
} }
$ids = $_GET['ids'] ?? []; $ids = $_GET['ids'] ?? [];
foreach ($ids as $id) foreach ($ids as $id) {
{
$this->internalScheduled->delete($id); $this->internalScheduled->delete($id);
} }
return header('Location: ' . \Router::url('Scheduled', 'list')); return header('Location: ' . \descartes\Router::url('Scheduled', 'list'));
} }
/** /**
@ -78,28 +77,24 @@ namespace controllers\publics;
$scheduleds = $this->internalScheduled->get_by_ids($ids); $scheduleds = $this->internalScheduled->get_by_ids($ids);
//Pour chaque message on ajoute les numéros, les contacts & les groupes //Pour chaque message on ajoute les numéros, les contacts & les groupes
foreach ($scheduleds as $key => $scheduled) foreach ($scheduleds as $key => $scheduled) {
{
$scheduleds[$key]['numbers'] = []; $scheduleds[$key]['numbers'] = [];
$scheduleds[$key]['contacts'] = []; $scheduleds[$key]['contacts'] = [];
$scheduleds[$key]['groupes'] = []; $scheduleds[$key]['groupes'] = [];
$numbers = $this->internalScheduled->get_numbers($scheduled['id']); $numbers = $this->internalScheduled->get_numbers($scheduled['id']);
foreach ($numbers as $number) foreach ($numbers as $number) {
{
$scheduleds[$key]['numbers'][] = $number['number']; $scheduleds[$key]['numbers'][] = $number['number'];
} }
$contacts = $this->internalScheduled->get_contacts($scheduled['id']); $contacts = $this->internalScheduled->get_contacts($scheduled['id']);
foreach ($contacts as $contact) foreach ($contacts as $contact) {
{
$scheduleds[$key]['contacts'][] = (int) $contact['id']; $scheduleds[$key]['contacts'][] = (int) $contact['id'];
} }
$groupes = $this->internalScheduled->get_groupes($scheduled['id']); $groupes = $this->internalScheduled->get_groupes($scheduled['id']);
foreach ($groupes as $groupe) foreach ($groupes as $groupe) {
{
$scheduleds[$key]['groupes'][] = (int) $groupe['id']; $scheduleds[$key]['groupes'][] = (int) $groupe['id'];
} }
} }
@ -121,10 +116,9 @@ namespace controllers\publics;
*/ */
public function create($csrf) public function create($csrf)
{ {
if (!$this->verifyCSRF($csrf)) if (!$this->verifyCSRF($csrf)) {
{
\modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Jeton CSRF invalid !'); \modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Jeton CSRF invalid !');
return header('Location: ' . \Router::url('Scheduled', 'add')); return header('Location: ' . \descartes\Router::url('Scheduled', 'add'));
} }
$date = $_POST['date'] ?? false; $date = $_POST['date'] ?? false;
@ -133,24 +127,20 @@ namespace controllers\publics;
$contacts = $_POST['contacts'] ?? []; $contacts = $_POST['contacts'] ?? [];
$groupes = $_POST['groupes'] ?? []; $groupes = $_POST['groupes'] ?? [];
if (!$content) if (!$content) {
{
\modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Vous ne pouvez pas créer un SMS sans message.'); \modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Vous ne pouvez pas créer un SMS sans message.');
return header('Location: ' . \Router::url('Scheduled', 'add')); return header('Location: ' . \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')) 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.'); \modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Vous devez fournir une date valide.');
return header('Location: ' . \Router::url('Scheduled', 'add')); return header('Location: ' . \descartes\Router::url('Scheduled', 'add'));
} }
foreach ($numbers as $key => $number) foreach ($numbers as $key => $number) {
{
$number = \controllers\internals\Tool::parse_phone($number); $number = \controllers\internals\Tool::parse_phone($number);
if (!$number) if (!$number) {
{
unset($numbers[$key]); unset($numbers[$key]);
continue; continue;
} }
@ -158,10 +148,9 @@ namespace controllers\publics;
$numbers[$key] = $number; $numbers[$key] = $number;
} }
if (!$numbers && !$contacts && !$groupes) if (!$numbers && !$contacts && !$groupes) {
{
\modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Vous devez renseigner au moins un destinataire pour le SMS.'); \modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Vous devez renseigner au moins un destinataire pour le SMS.');
return header('Location: ' . \Router::url('Scheduled', 'add')); return header('Location: ' . \descartes\Router::url('Scheduled', 'add'));
} }
$scheduled = [ $scheduled = [
@ -171,14 +160,13 @@ namespace controllers\publics;
'progress' => false, 'progress' => false,
]; ];
if (!$scheduled_id = $this->internalScheduled->create($scheduled, $numbers, $contacts, $groupes)) if (!$scheduled_id = $this->internalScheduled->create($scheduled, $numbers, $contacts, $groupes)) {
{
\modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Impossible de créer le SMS.'); \modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Impossible de créer le SMS.');
return header('Location: ' . \Router::url('Scheduled', 'add')); return header('Location: ' . \descartes\Router::url('Scheduled', 'add'));
} }
\modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('success', 'Le SMS a bien été créé pour le ' . $date . '.'); \modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('success', 'Le SMS a bien été créé pour le ' . $date . '.');
return header('Location: ' . \Router::url('Scheduled', 'list')); return header('Location: ' . \descartes\Router::url('Scheduled', 'list'));
} }
/** /**
@ -189,43 +177,36 @@ namespace controllers\publics;
*/ */
public function update($csrf) public function update($csrf)
{ {
if (!$this->verifyCSRF($csrf)) if (!$this->verifyCSRF($csrf)) {
{
\modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Jeton CSRF invalid !'); \modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Jeton CSRF invalid !');
return header('Location: ' . \Router::url('Scheduled', 'list')); return header('Location: ' . \descartes\Router::url('Scheduled', 'list'));
} }
$scheduleds = $_POST['scheduleds'] ?? []; $scheduleds = $_POST['scheduleds'] ?? [];
$all_update_ok = true; $all_update_ok = true;
foreach ($scheduleds as $id_scheduled => $scheduled) foreach ($scheduleds as $id_scheduled => $scheduled) {
{
$date = $scheduled['date'] ?? false; $date = $scheduled['date'] ?? false;
$content = $scheduled['content'] ?? false; $content = $scheduled['content'] ?? false;
$numbers = $scheduled['numbers'] ?? []; $numbers = $scheduled['numbers'] ?? [];
$contacts = $scheduled['contacts'] ?? []; $contacts = $scheduled['contacts'] ?? [];
$groupes = $scheduled['groupes'] ?? []; $groupes = $scheduled['groupes'] ?? [];
if (!$content) if (!$content) {
{
$all_update_ok = false; $all_update_ok = false;
continue; 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')) 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; $all_update_ok = false;
continue; continue;
} }
foreach ($numbers as $key => $number) foreach ($numbers as $key => $number) {
{
$number = \controllers\internals\Tool::parse_phone($number); $number = \controllers\internals\Tool::parse_phone($number);
if (!$number) if (!$number) {
{
unset($numbers[$key]); unset($numbers[$key]);
continue; continue;
} }
@ -233,8 +214,7 @@ namespace controllers\publics;
$numbers[$key] = $number; $numbers[$key] = $number;
} }
if (!$numbers && !$contacts && !$groupes) if (!$numbers && !$contacts && !$groupes) {
{
$all_update_ok = false; $all_update_ok = false;
continue; continue;
} }
@ -252,20 +232,18 @@ namespace controllers\publics;
'groupes_ids' => $groupes, 'groupes_ids' => $groupes,
]; ];
if (!$this->internalScheduled->update([$scheduled])) if (!$this->internalScheduled->update([$scheduled])) {
{
$all_update_ok = false; $all_update_ok = false;
continue; continue;
} }
} }
if (!$all_update_ok) if (!$all_update_ok) {
{
\modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Certains SMS n\'ont pas pu êtres mis à jour.'); \modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Certains SMS n\'ont pas pu êtres mis à jour.');
return header('Location: ' . \Router::url('Scheduled', 'list')); return header('Location: ' . \descartes\Router::url('Scheduled', 'list'));
} }
\modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('success', 'Tous les SMS ont été mis à jour.'); \modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('success', 'Tous les SMS ont été mis à jour.');
return header('Location: ' . \Router::url('Scheduled', 'list')); return header('Location: ' . \descartes\Router::url('Scheduled', 'list'));
} }
} }

View File

@ -1,9 +1,10 @@
<?php <?php
namespace controllers\publics; namespace controllers\publics;
/** /**
* Page des sendeds * Page des sendeds
*/ */
class Sended extends \Controller class Sended extends \descartes\Controller
{ {
/** /**
* Cette fonction est appelée avant toute les autres : * Cette fonction est appelée avant toute les autres :
@ -38,18 +39,16 @@ namespace controllers\publics;
*/ */
public function delete($csrf) public function delete($csrf)
{ {
if (!$this->verifyCSRF($csrf)) if (!$this->verifyCSRF($csrf)) {
{
\modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Jeton CSRF invalid !'); \modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Jeton CSRF invalid !');
return header('Location: ' . \Router::url('Sended', 'list')); return header('Location: ' . \descartes\Router::url('Sended', 'list'));
} }
$ids = $_GET['ids'] ?? []; $ids = $_GET['ids'] ?? [];
foreach ($ids as $id) foreach ($ids as $id) {
{
$this->internalSended->delete($id); $this->internalSended->delete($id);
} }
return header('Location: ' . \Router::url('Sended', 'list')); return header('Location: ' . \descartes\Router::url('Sended', 'list'));
} }
} }

View File

@ -1,9 +1,10 @@
<?php <?php
namespace controllers\publics; namespace controllers\publics;
/** /**
* Page des settings * Page des settings
*/ */
class Setting extends \Controller class Setting extends \descartes\Controller
{ {
private $internal_setting; private $internal_setting;
@ -33,35 +34,30 @@ namespace controllers\publics;
*/ */
public function update(string $setting_name, string $csrf) public function update(string $setting_name, string $csrf)
{ {
if (!$this->verifyCSRF($csrf)) if (!$this->verifyCSRF($csrf)) {
{
\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Jeton CSRF invalid !'); \DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Jeton CSRF invalid !');
return header('Location: ' . \Router::url('Setting', 'show')); return header('Location: ' . \descartes\Router::url('Setting', 'show'));
} }
if (!\controllers\internals\Tool::is_admin()) if (!\controllers\internals\Tool::is_admin()) {
{
\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Vous devez être administrateur pour pouvoir modifier un réglage.'); \DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Vous devez être administrateur pour pouvoir modifier un réglage.');
return header('Location: ' . \Router::url('Setting', 'show')); return header('Location: ' . \descartes\Router::url('Setting', 'show'));
} }
$setting_value = $_POST['setting_value'] ?? false; $setting_value = $_POST['setting_value'] ?? false;
if ($setting_value === false) if ($setting_value === false) {
{
\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Vous devez renseigner une valeure pour le réglage.'); \DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Vous devez renseigner une valeure pour le réglage.');
return header('Location: ' . \Router::url('Setting', 'show')); return header('Location: ' . \descartes\Router::url('Setting', 'show'));
} }
$update_setting_result = $this->internal_setting->update($setting_name, $setting_value); $update_setting_result = $this->internal_setting->update($setting_name, $setting_value);
if ($update_setting_result === false) if ($update_setting_result === false) {
{
\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Impossible de mettre à jour ce réglage.'); \DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Impossible de mettre à jour ce réglage.');
return header('Location: ' . \Router::url('Setting', 'show')); return header('Location: ' . \descartes\Router::url('Setting', 'show'));
} }
\DescartesSessionMessages\internals\DescartesSessionMessages::push('success', 'Le réglage a bien été mis à jour.'); \DescartesSessionMessages\internals\DescartesSessionMessages::push('success', 'Le réglage a bien été mis à jour.');
return header('Location: ' . \Router::url('Setting', 'show')); return header('Location: ' . \descartes\Router::url('Setting', 'show'));
} }
} }

View File

@ -1,9 +1,10 @@
<?php <?php
namespace controllers\publics; namespace controllers\publics;
/** /**
* Page des users * Page des users
*/ */
class User extends \Controller class User extends \descartes\Controller
{ {
/** /**
* Cette fonction est appelée avant toute les autres : * Cette fonction est appelée avant toute les autres :
@ -35,25 +36,22 @@ namespace controllers\publics;
*/ */
public function delete($csrf) public function delete($csrf)
{ {
if (!$this->verifyCSRF($csrf)) if (!$this->verifyCSRF($csrf)) {
{
\modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Jeton CSRF invalid !'); \modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Jeton CSRF invalid !');
return header('Location: ' . \Router::url('User', 'list')); return header('Location: ' . \descartes\Router::url('User', 'list'));
} }
if (!\controllers\internals\Tool::is_admin()) if (!\controllers\internals\Tool::is_admin()) {
{
\modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Vous devez être administrateur pour supprimer un utilisateur !'); \modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Vous devez être administrateur pour supprimer un utilisateur !');
return header('Location: ' . \Router::url('User', 'list')); return header('Location: ' . \descartes\Router::url('User', 'list'));
} }
$ids = $_GET['ids'] ?? []; $ids = $_GET['ids'] ?? [];
foreach ($ids as $id) foreach ($ids as $id) {
{
$this->internal_user->delete($id); $this->internal_user->delete($id);
} }
return header('Location: ' . \Router::url('User', 'list')); return header('Location: ' . \descartes\Router::url('User', 'list'));
} }
/** /**
@ -75,43 +73,38 @@ namespace controllers\publics;
*/ */
public function create($csrf) public function create($csrf)
{ {
if (!$this->verifyCSRF($csrf)) if (!$this->verifyCSRF($csrf)) {
{
\modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Jeton CSRF invalid !'); \modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Jeton CSRF invalid !');
return header('Location: ' . \Router::url('User', 'add')); return header('Location: ' . \descartes\Router::url('User', 'add'));
} }
$email = $_POST['email'] ?? false; $email = $_POST['email'] ?? false;
$password = $_POST['password'] ?? \controllers\internals\Tool::generate_password(rand(6, 12)); $password = $_POST['password'] ?? \controllers\internals\Tool::generate_password(rand(6, 12));
$admin = $_POST['admin'] ?? false; $admin = $_POST['admin'] ?? false;
if (!$email) if (!$email) {
{
\modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Vous devez au moins fournir une adresse e-mail pour l\'utilisateur.'); \modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Vous devez au moins fournir une adresse e-mail pour l\'utilisateur.');
return header('Location: ' . \Router::url('User', 'add')); return header('Location: ' . \descartes\Router::url('User', 'add'));
} }
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
{
\modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'L\'adresse e-mail n\'est pas valide.'); \modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'L\'adresse e-mail n\'est pas valide.');
return header('Location: ' . \Router::url('User', 'add')); return header('Location: ' . \descartes\Router::url('User', 'add'));
} }
$email_send = \controllers\internals\Tool::send_email($email, EMAIL_CREATE_USER, ['email' => $email, 'password' => $password]); $email_send = \controllers\internals\Tool::send_email($email, EMAIL_CREATE_USER, ['email' => $email, 'password' => $password]);
if (!$email_send) if (!$email_send) {
{
\modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Impossible d\'envoyer l\'e-mail à l\'utilisateur, le compte n\'a donc pas été créé.'); \modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Impossible d\'envoyer l\'e-mail à l\'utilisateur, le compte n\'a donc pas été créé.');
return header('Location: ' . \Router::url('User', 'add')); return header('Location: ' . \descartes\Router::url('User', 'add'));
} }
$user_id = $this->internal_user->create($email, $password, $admin); $user_id = $this->internal_user->create($email, $password, $admin);
if (!$user_id) if (!$user_id) {
{
\modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Impossible de créer ce user.'); \modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('danger', 'Impossible de créer ce user.');
return header('Location: ' . \Router::url('User', 'add')); return header('Location: ' . \descartes\Router::url('User', 'add'));
} }
\modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('success', 'L\'utilisateur a bien été créé.'); \modules\DescartesSessionMessages\internals\DescartesSessionMessages::push('success', 'L\'utilisateur a bien été créé.');
return header('Location: ' . \Router::url('User', 'list')); return header('Location: ' . \descartes\Router::url('User', 'list'));
} }
} }