mirror of
https://github.com/RaspbianFrance/raspisms.git
synced 2025-06-07 07:06:26 +02:00
Fix php style
This commit is contained in:
parent
461bd9c98d
commit
b8bd067dc7
59 changed files with 2307 additions and 1868 deletions
|
@ -70,7 +70,6 @@ namespace controllers\publics;
|
|||
return $this->redirect(\descartes\Router::url('Account', 'show'));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Update user email.
|
||||
*
|
||||
|
@ -117,8 +116,7 @@ namespace controllers\publics;
|
|||
|
||||
return $this->redirect(\descartes\Router::url('Account', 'show'));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Update user api key.
|
||||
*
|
||||
|
@ -148,7 +146,6 @@ namespace controllers\publics;
|
|||
return $this->redirect(\descartes\Router::url('Account', 'show'));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Delete a user.
|
||||
*
|
||||
|
|
|
@ -12,11 +12,11 @@
|
|||
namespace controllers\publics;
|
||||
|
||||
/**
|
||||
* Api to interact with raspisms
|
||||
* Api to interact with raspisms.
|
||||
*/
|
||||
class Api extends \descartes\ApiController
|
||||
{
|
||||
CONST DEFAULT_RETURN = [
|
||||
const DEFAULT_RETURN = [
|
||||
'error' => 0, //Error code
|
||||
'message' => null, //Any message to describe a potential error
|
||||
'response' => null, //The content of the response
|
||||
|
@ -24,7 +24,7 @@ namespace controllers\publics;
|
|||
'prev' => null, //Link to the previous results
|
||||
];
|
||||
|
||||
CONST ERROR_CODES = [
|
||||
const ERROR_CODES = [
|
||||
'NONE' => 0,
|
||||
'INVALID_CREDENTIALS' => 1,
|
||||
'INVALID_PARAMETER' => 2,
|
||||
|
@ -32,13 +32,12 @@ namespace controllers\publics;
|
|||
'CANNOT_CREATE' => 8,
|
||||
];
|
||||
|
||||
CONST ERROR_MESSAGES = [
|
||||
const ERROR_MESSAGES = [
|
||||
'INVALID_CREDENTIALS' => 'Invalid API Key. Please provide a valid API as GET parameter "api_key".',
|
||||
'INVALID_PARAMETER' => 'You have specified an invalid parameter : ',
|
||||
'MISSING_PARAMETER' => 'One require parameter is missing : ',
|
||||
'CANNOT_CREATE' => 'Cannot create a new entry.',
|
||||
];
|
||||
|
||||
|
||||
private $internal_user;
|
||||
private $internal_phone;
|
||||
|
@ -49,13 +48,14 @@ namespace controllers\publics;
|
|||
private $user;
|
||||
|
||||
/**
|
||||
* Construct the object and quit if failed authentication
|
||||
* Construct the object and quit if failed authentication.
|
||||
*
|
||||
* @return void;
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
|
||||
$bdd = \descartes\Model::_connect(DATABASE_HOST, DATABASE_NAME, DATABASE_USER, DATABASE_PASSWORD);
|
||||
$this->internal_user = new \controllers\internals\User($bdd);
|
||||
$this->internal_phone = new \controllers\internals\Phone($bdd);
|
||||
|
@ -71,7 +71,7 @@ namespace controllers\publics;
|
|||
$api_key = $_GET['api_key'] ?? false;
|
||||
if ($api_key)
|
||||
{
|
||||
$this->user = $this->internal_user->get_by_api_key($api_key);
|
||||
$this->user = $this->internal_user->get_by_api_key($api_key);
|
||||
}
|
||||
|
||||
if (!$this->user)
|
||||
|
@ -86,37 +86,38 @@ namespace controllers\publics;
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* List all entries of a certain type for the current user, sorted by id.
|
||||
*
|
||||
* @param string $entry_type : Type of entries we want to list ['sended', 'received', 'scheduled', 'contact', 'group', 'conditional_group', 'phone']
|
||||
* @param int $page : Pagination number, Default = 0. Group of 25 results.
|
||||
* @param int $page : Pagination number, Default = 0. Group of 25 results.
|
||||
*
|
||||
* @return List of entries
|
||||
*/
|
||||
public function get_entries (string $entry_type, int $page = 0)
|
||||
public function get_entries(string $entry_type, int $page = 0)
|
||||
{
|
||||
$entry_types = ['sended', 'received', 'scheduled', 'contact', 'group', 'conditional_group', 'phone'];
|
||||
|
||||
if (!in_array($entry_type, $entry_types))
|
||||
if (!\in_array($entry_type, $entry_types, true))
|
||||
{
|
||||
$return = self::DEFAULT_RETURN;
|
||||
$return['error'] = self::ERROR_CODES['INVALID_PARAMETER'];
|
||||
$return['message'] = self::ERROR_MESSAGES['INVALID_PARAMETER'] . 'entry_type must be one of : ' . join(', ', $entry_types) . '.';
|
||||
$return['message'] = self::ERROR_MESSAGES['INVALID_PARAMETER'].'entry_type must be one of : '.implode(', ', $entry_types).'.';
|
||||
$this->auto_http_code(false);
|
||||
$this->json($return);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
$controller_str = 'internal_' . $entry_type;
|
||||
$controller = $this->$controller_str;
|
||||
$controller_str = 'internal_'.$entry_type;
|
||||
$controller = $this->{$controller_str};
|
||||
|
||||
$page = (int) $page;
|
||||
$limit = 25;
|
||||
$entries = $controller->list_for_user($this->user['id'], $limit, $page);
|
||||
|
||||
//Special case for scheduled, we must add numbers because its a join
|
||||
if ($entry_type === 'scheduled')
|
||||
if ('scheduled' === $entry_type)
|
||||
{
|
||||
foreach ($entries as $key => $entry)
|
||||
{
|
||||
|
@ -127,7 +128,7 @@ namespace controllers\publics;
|
|||
}
|
||||
}
|
||||
//Special case for group we must add contact because its a join
|
||||
elseif ($entry_type === 'group')
|
||||
elseif ('group' === $entry_type)
|
||||
{
|
||||
foreach ($entries as $key => $entry)
|
||||
{
|
||||
|
@ -135,11 +136,10 @@ namespace controllers\publics;
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
$return = self::DEFAULT_RETURN;
|
||||
$return['response'] = $entries;
|
||||
|
||||
if (count($entries) == $limit)
|
||||
if (\count($entries) === $limit)
|
||||
{
|
||||
$return['next'] = \descartes\Router::url('Api', __FUNCTION__, ['entry_type' => $entry_type, 'page' => $page + 1], ['api_key' => $this->user['api_key']]);
|
||||
}
|
||||
|
@ -153,35 +153,36 @@ namespace controllers\publics;
|
|||
$this->json($return);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Schedule a message to be send
|
||||
* @param string $_POST['at'] : Date to send message at format Y-m-d H:i:s
|
||||
* @param string $_POST['text'] : Text of the message to send
|
||||
* @param string $_POST['origin'] : Default null. Number to send the message from. If null use a random phone
|
||||
* @param string $_POST['flash'] : Default false. Is the sms a flash sms.
|
||||
* @param string $_POST['numbers'] : Array of numbers to send message to
|
||||
* @param string $_POST['contacts'] : Array of ids of contacts to send message to
|
||||
* @param string $_POST['groups'] : Array of ids of groups to send message to
|
||||
* Schedule a message to be send.
|
||||
*
|
||||
* @param string $_POST['at'] : Date to send message at format Y-m-d H:i:s
|
||||
* @param string $_POST['text'] : Text of the message to send
|
||||
* @param string $_POST['origin'] : Default null. Number to send the message from. If null use a random phone
|
||||
* @param string $_POST['flash'] : Default false. Is the sms a flash sms.
|
||||
* @param string $_POST['numbers'] : Array of numbers to send message to
|
||||
* @param string $_POST['contacts'] : Array of ids of contacts to send message to
|
||||
* @param string $_POST['groups'] : Array of ids of groups to send message to
|
||||
* @param string $_POST['conditional_groups'] : Array of ids of conditional groups to send message to
|
||||
*
|
||||
* @return Id of scheduled created
|
||||
*/
|
||||
public function post_scheduled ()
|
||||
public function post_scheduled()
|
||||
{
|
||||
$at = $_POST['at'] ?? false;
|
||||
$text = $_POST['text'] ?? false;
|
||||
$origin = empty($_POST['origin']) ? null : $_POST['origin'];
|
||||
$flash = (bool) ($_POST['flash'] ?? false);
|
||||
$numbers = $_POST['numbers'] ?? [];
|
||||
$contacts = $_POST['contacts'] ?? [];
|
||||
$groups = $_POST['groups'] ?? [];
|
||||
$numbers = $_POST['numbers'] ?? [];
|
||||
$contacts = $_POST['contacts'] ?? [];
|
||||
$groups = $_POST['groups'] ?? [];
|
||||
$conditional_groups = $_POST['conditional_groups'] ?? [];
|
||||
|
||||
if (!$at || !$text)
|
||||
{
|
||||
$return = self::DEFAULT_RETURN;
|
||||
$return['error'] = self::ERROR_CODES['MISSING_PARAMETER'];
|
||||
$return['message'] = self::ERROR_MESSAGES['MISSING_PARAMETER'] . ($at ? '' : 'at ') . ($text ? '' : 'text');
|
||||
$return['message'] = self::ERROR_MESSAGES['MISSING_PARAMETER'].($at ? '' : 'at ').($text ? '' : 'text');
|
||||
$this->auto_http_code(false);
|
||||
$this->json($return);
|
||||
|
||||
|
@ -192,7 +193,7 @@ namespace controllers\publics;
|
|||
{
|
||||
$return = self::DEFAULT_RETURN;
|
||||
$return['error'] = self::ERROR_CODES['INVALID_PARAMETER'];
|
||||
$return['message'] = self::ERROR_MESSAGES['INVALID_PARAMETER'] . 'at must be a date of format "Y-m-d H:i:s".';
|
||||
$return['message'] = self::ERROR_MESSAGES['INVALID_PARAMETER'].'at must be a date of format "Y-m-d H:i:s".';
|
||||
$this->auto_http_code(false);
|
||||
$this->json($return);
|
||||
|
||||
|
@ -206,6 +207,7 @@ namespace controllers\publics;
|
|||
if (!$number)
|
||||
{
|
||||
unset($numbers[$key]);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -216,7 +218,7 @@ namespace controllers\publics;
|
|||
{
|
||||
$return = self::DEFAULT_RETURN;
|
||||
$return['error'] = self::ERROR_CODES['MISSING_PARAMETER'];
|
||||
$return['message'] = self::ERROR_MESSAGES['MISSING_PARAMETER'] . 'You must specify at least one valid number, contact, group or conditional_group.';
|
||||
$return['message'] = self::ERROR_MESSAGES['MISSING_PARAMETER'].'You must specify at least one valid number, contact, group or conditional_group.';
|
||||
$this->auto_http_code(false);
|
||||
$this->json($return);
|
||||
|
||||
|
@ -227,7 +229,7 @@ namespace controllers\publics;
|
|||
{
|
||||
$return = self::DEFAULT_RETURN;
|
||||
$return['error'] = self::ERROR_CODES['INVALID_PARAMETER'];
|
||||
$return['message'] = self::ERROR_MESSAGES['INVALID_PARAMETER'] . 'origin : You must specify an origin number among thoses of user phones.';
|
||||
$return['message'] = self::ERROR_MESSAGES['INVALID_PARAMETER'].'origin : You must specify an origin number among thoses of user phones.';
|
||||
$this->auto_http_code(false);
|
||||
$this->json($return);
|
||||
|
||||
|
@ -252,23 +254,22 @@ namespace controllers\publics;
|
|||
$this->json($return);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Delete a scheduled message
|
||||
* Delete a scheduled message.
|
||||
*
|
||||
* @param int $id : Id of scheduled message to delete
|
||||
* @return void on success, error else
|
||||
*/
|
||||
public function delete_scheduled (int $id)
|
||||
public function delete_scheduled(int $id)
|
||||
{
|
||||
$success = $this->internal_scheduled->delete_for_user($this->user['id'], $id);
|
||||
|
||||
if (!$success)
|
||||
{
|
||||
$this->auto_http_code(false);
|
||||
return false;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->auto_http_code(true);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
namespace controllers\publics;
|
||||
|
||||
/**
|
||||
* Controller of callback pages, like sms status update notification
|
||||
* Controller of callback pages, like sms status update notification.
|
||||
*/
|
||||
class Callback extends \descartes\Controller
|
||||
{
|
||||
|
@ -30,16 +30,17 @@ namespace controllers\publics;
|
|||
}
|
||||
|
||||
/**
|
||||
* Function call on a sended sms status change notification reception
|
||||
* Function call on a sended sms status change notification reception.
|
||||
*
|
||||
* @param string $adapter_name : Name of the adapter to use
|
||||
*
|
||||
* @return false : We must always return false, and we respect a random usleep before returning anything
|
||||
* in order to prevent bruteforce api key guessing and time guessing
|
||||
* in order to prevent bruteforce api key guessing and time guessing
|
||||
*/
|
||||
public function update_sended_status (string $adapter_name)
|
||||
public function update_sended_status(string $adapter_name)
|
||||
{
|
||||
//Wait between 0.5 and 1.03s in order to counter time guessing bruteforce attack against api key
|
||||
usleep(mt_rand(5,10) / 10 * 1000000 + mt_rand(0, 30000));
|
||||
|
||||
usleep(mt_rand(5, 10) / 10 * 1000000 + mt_rand(0, 30000));
|
||||
|
||||
//Search for an adapter
|
||||
$find_adapter = false;
|
||||
|
|
|
@ -40,7 +40,7 @@ namespace controllers\publics;
|
|||
}
|
||||
|
||||
/**
|
||||
* Return all conditionnals groups for administration
|
||||
* Return all conditionnals groups for administration.
|
||||
*
|
||||
* @param mixed $page
|
||||
*/
|
||||
|
@ -48,7 +48,6 @@ namespace controllers\publics;
|
|||
{
|
||||
$page = (int) $page;
|
||||
|
||||
|
||||
$groups = $this->internal_conditional_group->list_for_user($_SESSION['user']['id'], 25, $page);
|
||||
$this->render('conditional_group/list', ['groups' => $groups]);
|
||||
}
|
||||
|
@ -107,7 +106,7 @@ namespace controllers\publics;
|
|||
* Cette fonction insert un nouveau group.
|
||||
*
|
||||
* @param $csrf : Le jeton CSRF
|
||||
* @param string $_POST['name'] : Le nom du group
|
||||
* @param string $_POST['name'] : Le nom du group
|
||||
* @param array $_POST['condition'] : The condition to used
|
||||
*/
|
||||
public function create($csrf)
|
||||
|
@ -178,14 +177,15 @@ namespace controllers\publics;
|
|||
|
||||
return $this->redirect(\descartes\Router::url('ConditionalGroup', 'list'));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Try to get the preview of contacts for a conditionnal group
|
||||
* Try to get the preview of contacts for a conditionnal group.
|
||||
*
|
||||
* @param string $_POST['condition'] : Condition to apply
|
||||
*
|
||||
* @return json string
|
||||
*/
|
||||
public function contacts_preview ()
|
||||
public function contacts_preview()
|
||||
{
|
||||
$return = [
|
||||
'success' => false,
|
||||
|
@ -193,21 +193,22 @@ namespace controllers\publics;
|
|||
];
|
||||
|
||||
$condition = $_POST['condition'] ?? false;
|
||||
|
||||
|
||||
if (!$condition)
|
||||
{
|
||||
$return['result'] = 'Vous devez renseigner une condition.';
|
||||
echo json_encode($return);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
$internal_ruler = new \controllers\internals\Ruler();
|
||||
$valid_condition = $internal_ruler->validate_condition($condition, ['contact' => (object) ['datas' => (object) null]]);
|
||||
if (!$valid_condition)
|
||||
{
|
||||
$return['result'] = 'Syntaxe de la condition invalide.';
|
||||
echo json_encode($return);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -216,6 +217,7 @@ namespace controllers\publics;
|
|||
{
|
||||
$return['result'] = 'Aucun contact dans le groupe.';
|
||||
echo json_encode($return);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -225,16 +227,15 @@ namespace controllers\publics;
|
|||
$contacts_name[] = $contact['name'];
|
||||
}
|
||||
|
||||
$return['result'] = "Contacts du groupe : " . implode(', ', $contacts_name);
|
||||
$return['result'] = 'Contacts du groupe : '.implode(', ', $contacts_name);
|
||||
$return['success'] = true;
|
||||
echo json_encode($return);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Return the list of groups as JSON
|
||||
* Return the list of groups as JSON.
|
||||
*/
|
||||
public function json_list()
|
||||
{
|
||||
|
|
|
@ -151,7 +151,7 @@ namespace controllers\publics;
|
|||
$clean_datas = [];
|
||||
foreach ($datas as $key => $value)
|
||||
{
|
||||
if ($value === "")
|
||||
if ('' === $value)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
@ -159,7 +159,7 @@ namespace controllers\publics;
|
|||
$key = mb_ereg_replace('[\W]', '', $key);
|
||||
$clean_datas[$key] = (string) $value;
|
||||
}
|
||||
|
||||
|
||||
$clean_datas = json_encode($clean_datas);
|
||||
|
||||
if (!$this->internal_contact->create($id_user, $number, $name, $clean_datas))
|
||||
|
@ -191,7 +191,7 @@ namespace controllers\publics;
|
|||
return $this->redirect(\descartes\Router::url('Contact', 'list'));
|
||||
}
|
||||
|
||||
if (!array($_POST['contacts']))
|
||||
if (![$_POST['contacts']])
|
||||
{
|
||||
return $this->redirect(\descartes\Router::url('Contact', 'list'));
|
||||
}
|
||||
|
@ -203,22 +203,22 @@ namespace controllers\publics;
|
|||
$number = $contact['number'] ?? false;
|
||||
$id_user = $_SESSION['user']['id'];
|
||||
$datas = $contact['datas'] ?? [];
|
||||
|
||||
|
||||
if (!$name || !$number)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
$number = \controllers\internals\Tool::parse_phone($number);
|
||||
if (!$number)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
$clean_datas = [];
|
||||
foreach ($datas as $key => $value)
|
||||
{
|
||||
if ($value === "")
|
||||
if ('' === $value)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
@ -227,7 +227,7 @@ namespace controllers\publics;
|
|||
$clean_datas[$key] = (string) $value;
|
||||
}
|
||||
$clean_datas = json_encode($clean_datas);
|
||||
|
||||
|
||||
$nb_contacts_update += (int) $this->internal_contact->update_for_user($id_user, $id_contact, $number, $name, $clean_datas);
|
||||
}
|
||||
|
||||
|
@ -243,17 +243,18 @@ namespace controllers\publics;
|
|||
return $this->redirect(\descartes\Router::url('Contact', 'list'));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Allow to import a contacts list
|
||||
* Allow to import a contacts list.
|
||||
*
|
||||
* @param string $csrf : Csrf token
|
||||
* @param $_FILES['contacts_list_file'] : A csv file of the contacts to import
|
||||
*/
|
||||
public function import (string $csrf)
|
||||
public function import(string $csrf)
|
||||
{
|
||||
if (!$this->verify_csrf($csrf))
|
||||
{
|
||||
\FlashMessage\FlashMessage::push('danger', 'Jeton CSRF invalid !');
|
||||
|
||||
return $this->redirect(\descartes\Router::url('Contact', 'list'));
|
||||
}
|
||||
|
||||
|
@ -263,6 +264,7 @@ namespace controllers\publics;
|
|||
if (!$upload_array)
|
||||
{
|
||||
\FlashMessage\FlashMessage::push('danger', 'Vous devez fournir un fichier de contacts à importer.');
|
||||
|
||||
return $this->redirect(\descartes\Router::url('Contact', 'list'));
|
||||
}
|
||||
|
||||
|
@ -270,6 +272,7 @@ namespace controllers\publics;
|
|||
if (!$read_file['success'])
|
||||
{
|
||||
\FlashMessage\FlashMessage::push('danger', $read_file['content']);
|
||||
|
||||
return $this->redirect(\descartes\Router::url('Contact', 'list'));
|
||||
}
|
||||
|
||||
|
@ -277,46 +280,49 @@ namespace controllers\publics;
|
|||
$invalid_type = false;
|
||||
switch ($read_file['mime_type'])
|
||||
{
|
||||
case 'text/csv' :
|
||||
case 'text/csv':
|
||||
$result = $this->internal_contact->import_csv($id_user, $read_file['content']);
|
||||
|
||||
break;
|
||||
|
||||
case 'application/json' :
|
||||
case 'application/json':
|
||||
$result = $this->internal_contact->import_json($id_user, $read_file['content']);
|
||||
|
||||
break;
|
||||
|
||||
default :
|
||||
default:
|
||||
$invalid_type = true;
|
||||
}
|
||||
|
||||
if ($invalid_type)
|
||||
{
|
||||
\FlashMessage\FlashMessage::push('danger', 'Le type de fichier n\'est pas valide.');
|
||||
|
||||
return $this->redirect(\descartes\Router::url('Contact', 'list'));
|
||||
}
|
||||
|
||||
if ($result === false)
|
||||
if (false === $result)
|
||||
{
|
||||
\FlashMessage\FlashMessage::push('danger', 'Le fichier contient des erreurs. Impossible d\'importer les contacts.');
|
||||
|
||||
return $this->redirect(\descartes\Router::url('Contact', 'list'));
|
||||
}
|
||||
|
||||
$msg = $result . ' nouveau contact a été inséré.';
|
||||
$msg = $result.' nouveau contact a été inséré.';
|
||||
if ($result > 1)
|
||||
{
|
||||
$msg = $result . ' nouveaux contacts ont été insérés.';
|
||||
$msg = $result.' nouveaux contacts ont été insérés.';
|
||||
}
|
||||
|
||||
\FlashMessage\FlashMessage::push('success', $msg);
|
||||
|
||||
return $this->redirect(\descartes\Router::url('Contact', 'list'));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Allow to export a contacts list
|
||||
* Allow to export a contacts list.
|
||||
*
|
||||
* @param $format : Format to export contacts to
|
||||
*/
|
||||
public function export (string $format)
|
||||
public function export(string $format)
|
||||
{
|
||||
$id_user = $_SESSION['user']['id'];
|
||||
|
||||
|
@ -324,27 +330,29 @@ namespace controllers\publics;
|
|||
$invalid_type = false;
|
||||
switch ($format)
|
||||
{
|
||||
case 'csv' :
|
||||
case 'csv':
|
||||
$result = $this->internal_contact->export_csv($id_user);
|
||||
|
||||
break;
|
||||
|
||||
case 'json' :
|
||||
case 'json':
|
||||
$result = $this->internal_contact->export_json($id_user);
|
||||
|
||||
break;
|
||||
|
||||
default :
|
||||
default:
|
||||
$invalid_type = true;
|
||||
}
|
||||
|
||||
if ($invalid_type)
|
||||
{
|
||||
\FlashMessage\FlashMessage::push('danger', 'Le format demandé n\'est pas supporté.');
|
||||
|
||||
return $this->redirect(\descartes\Router::url('Contact', 'list'));
|
||||
}
|
||||
|
||||
if ($result === false)
|
||||
if (false === $result)
|
||||
{
|
||||
\FlashMessage\FlashMessage::push('danger', 'Nous ne sommes par parveu à exporté les contacts.');
|
||||
|
||||
return $this->redirect(\descartes\Router::url('Contact', 'list'));
|
||||
}
|
||||
|
||||
|
|
|
@ -71,7 +71,6 @@ namespace controllers\publics;
|
|||
$receiveds = $this->internal_received->get_lasts_by_date_for_user($id_user, 10);
|
||||
$events = $this->internal_event->get_lasts_by_date_for_user($id_user, 10);
|
||||
|
||||
|
||||
//Récupération du nombre de Sms envoyés et reçus depuis les 7 derniers jours
|
||||
$nb_sendeds_by_day = $this->internal_sended->count_by_day_since_for_user($id_user, $formated_date);
|
||||
$nb_receiveds_by_day = $this->internal_received->count_by_day_since_for_user($id_user, $formated_date);
|
||||
|
|
|
@ -113,7 +113,7 @@ namespace controllers\publics;
|
|||
|
||||
foreach ($receiveds as $received)
|
||||
{
|
||||
if ($received['status'] != 'read')
|
||||
if ('read' !== $received['status'])
|
||||
{
|
||||
$this->internal_received->mark_as_read_for_user($id_user, $received['id']);
|
||||
}
|
||||
|
@ -152,10 +152,10 @@ namespace controllers\publics;
|
|||
/**
|
||||
* Cette fonction permet d'envoyer facilement un sms à un numéro donné.
|
||||
*
|
||||
* @param string $csrf : Le jeton csrf
|
||||
* @param string $_POST['text'] : Le contenu du Sms
|
||||
* @param string $csrf : Le jeton csrf
|
||||
* @param string $_POST['text'] : Le contenu du Sms
|
||||
* @param string $_POST['destination'] : Number to send sms to
|
||||
* @param string $_POST['origin'] : Number to send sms with
|
||||
* @param string $_POST['origin'] : Number to send sms with
|
||||
*
|
||||
* @return string : json string Le statut de l'envoi
|
||||
*/
|
||||
|
|
|
@ -93,21 +93,24 @@ class Phone extends \descartes\Controller
|
|||
public function add()
|
||||
{
|
||||
$adapters = $this->internal_adapter->list_adapters();
|
||||
|
||||
return $this->render('phone/add', ['adapters' => $adapters]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new phone
|
||||
* Create a new phone.
|
||||
*
|
||||
* @param $csrf : CSRF token
|
||||
* @param string $_POST['number'] : Phone number
|
||||
* @param string $_POST['adapter'] : Phone adapter
|
||||
* @param array $_POST['adapter_datas'] : Phone adapter datas
|
||||
* @param string $_POST['number'] : Phone number
|
||||
* @param string $_POST['adapter'] : Phone adapter
|
||||
* @param array $_POST['adapter_datas'] : Phone adapter datas
|
||||
*/
|
||||
public function create($csrf)
|
||||
{
|
||||
if (!$this->verify_csrf($csrf))
|
||||
{
|
||||
\FlashMessage\FlashMessage::push('danger', 'Jeton CSRF invalid !');
|
||||
|
||||
return $this->redirect(\descartes\Router::url('Phone', 'add'));
|
||||
}
|
||||
|
||||
|
@ -119,14 +122,15 @@ class Phone extends \descartes\Controller
|
|||
if (!$number || !$adapter)
|
||||
{
|
||||
\FlashMessage\FlashMessage::push('danger', 'Des champs obligatoires sont manquants.');
|
||||
|
||||
return $this->redirect(\descartes\Router::url('Phone', 'add'));
|
||||
}
|
||||
|
||||
|
||||
$number = \controllers\internals\Tool::parse_phone($number);
|
||||
if (!$number)
|
||||
{
|
||||
\FlashMessage\FlashMessage::push('danger', 'Numéro de téléphone incorrect.');
|
||||
|
||||
return $this->redirect(\descartes\Router::url('Phone', 'add'));
|
||||
}
|
||||
|
||||
|
@ -134,10 +138,10 @@ class Phone extends \descartes\Controller
|
|||
if ($number_exist)
|
||||
{
|
||||
\FlashMessage\FlashMessage::push('danger', 'Ce numéro de téléphone est déjà utilisé.');
|
||||
|
||||
return $this->redirect(\descartes\Router::url('Phone', 'add'));
|
||||
}
|
||||
|
||||
|
||||
$adapters = $this->internal_adapter->list_adapters();
|
||||
$find_adapter = false;
|
||||
foreach ($adapters as $metas)
|
||||
|
@ -145,6 +149,7 @@ class Phone extends \descartes\Controller
|
|||
if ($metas['meta_classname'] === $adapter)
|
||||
{
|
||||
$find_adapter = $metas;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -152,13 +157,14 @@ class Phone extends \descartes\Controller
|
|||
if (!$find_adapter)
|
||||
{
|
||||
\FlashMessage\FlashMessage::push('danger', 'Cet adaptateur n\'existe pas.');
|
||||
|
||||
return $this->redirect(\descartes\Router::url('Phone', 'add'));
|
||||
}
|
||||
|
||||
//If missing required data fields, error
|
||||
foreach ($find_adapter['meta_datas_fields'] as $field)
|
||||
{
|
||||
if ($field['required'] === false)
|
||||
if (false === $field['required'])
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
@ -169,6 +175,7 @@ class Phone extends \descartes\Controller
|
|||
}
|
||||
|
||||
\FlashMessage\FlashMessage::push('danger', 'Vous n\'avez pas rempli certains champs obligatoires pour l\'adaptateur choisis.');
|
||||
|
||||
return $this->redirect(\descartes\Router::url('Phone', 'add'));
|
||||
}
|
||||
|
||||
|
@ -182,18 +189,20 @@ class Phone extends \descartes\Controller
|
|||
if (!$adapter_working)
|
||||
{
|
||||
\FlashMessage\FlashMessage::push('danger', 'Impossible d\'utiliser l\'adaptateur choisis avec les données fournies. Vérifiez le numéro de téléphone et les réglages.');
|
||||
|
||||
return $this->redirect(\descartes\Router::url('Phone', 'add'));
|
||||
}
|
||||
|
||||
|
||||
$success = $this->internal_phone->create($id_user, $number, $adapter, $adapter_datas);
|
||||
if (!$success)
|
||||
{
|
||||
\FlashMessage\FlashMessage::push('danger', 'Impossible de créer ce téléphone.');
|
||||
|
||||
return $this->redirect(\descartes\Router::url('Phone', 'add'));
|
||||
}
|
||||
|
||||
|
||||
\FlashMessage\FlashMessage::push('success', 'Le téléphone a bien été créé.');
|
||||
|
||||
return $this->redirect(\descartes\Router::url('Phone', 'list'));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -49,7 +49,7 @@ namespace controllers\publics;
|
|||
|
||||
foreach ($receiveds as $key => $received)
|
||||
{
|
||||
if ($received['status'] != 'read')
|
||||
if ('read' !== $received['status'])
|
||||
{
|
||||
$this->internal_received->mark_as_read_for_user($_SESSION['user']['id'], $received['id']);
|
||||
}
|
||||
|
@ -64,10 +64,10 @@ namespace controllers\publics;
|
|||
|
||||
$this->render('received/list', ['receiveds' => $receiveds, 'page' => $page, 'limit' => $limit, 'nb_results' => \count($receiveds)]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Return all unread receiveds messages
|
||||
* Return all unread receiveds messages.
|
||||
*
|
||||
* @param mixed $page
|
||||
*/
|
||||
public function list_unread($page = 0)
|
||||
|
@ -92,7 +92,8 @@ namespace controllers\publics;
|
|||
}
|
||||
|
||||
/**
|
||||
* Delete Receiveds
|
||||
* Delete Receiveds.
|
||||
*
|
||||
* @param array int $_GET['ids'] : Ids of receiveds to delete
|
||||
* @param mixed $csrf
|
||||
*
|
||||
|
@ -103,6 +104,7 @@ namespace controllers\publics;
|
|||
if (!$this->verify_csrf($csrf))
|
||||
{
|
||||
\FlashMessage\FlashMessage::push('danger', 'Jeton CSRF invalid !');
|
||||
|
||||
return $this->redirect(\descartes\Router::url('Received', 'list'));
|
||||
}
|
||||
|
||||
|
@ -132,7 +134,7 @@ namespace controllers\publics;
|
|||
continue;
|
||||
}
|
||||
|
||||
$receiveds[$key]['origin'] = $this->s($contact['name'], false, true, false) . ' (' . \controllers\internals\Tool::phone_link($received['origin']) . ')';
|
||||
$receiveds[$key]['origin'] = $this->s($contact['name'], false, true, false).' ('.\controllers\internals\Tool::phone_link($received['origin']).')';
|
||||
}
|
||||
|
||||
$nb_received = \count($receiveds);
|
||||
|
|
|
@ -88,6 +88,7 @@ namespace controllers\publics;
|
|||
|
||||
/**
|
||||
* Cette fonction retourne la page d'ajout d'un scheduled.
|
||||
*
|
||||
* @param $prefilled : If we have prefilled some fields (possible values : 'contacts', 'groups', 'conditional_groups', false)
|
||||
*/
|
||||
public function add($prefilled = false)
|
||||
|
@ -100,7 +101,7 @@ namespace controllers\publics;
|
|||
|
||||
$contacts = $this->internal_contact->gets_for_user($id_user);
|
||||
$phones = $this->internal_phone->gets_for_user($id_user);
|
||||
|
||||
|
||||
$prefilled_contacts = [];
|
||||
$prefilled_groups = [];
|
||||
$prefilled_conditional_groups = [];
|
||||
|
@ -110,21 +111,21 @@ namespace controllers\publics;
|
|||
$ids = $_GET['ids'] ?? [];
|
||||
}
|
||||
|
||||
if ($prefilled === 'contacts')
|
||||
if ('contacts' === $prefilled)
|
||||
{
|
||||
foreach ($this->internal_contact->gets_in_for_user($id_user, $ids) as $contact)
|
||||
{
|
||||
$prefilled_contacts[] = $contact['id'];
|
||||
}
|
||||
}
|
||||
elseif ($prefilled === 'groups')
|
||||
elseif ('groups' === $prefilled)
|
||||
{
|
||||
foreach ($this->internal_group->gets_in_for_user($id_user, $ids) as $group)
|
||||
{
|
||||
$prefilled_groups[] = $group['id'];
|
||||
}
|
||||
}
|
||||
elseif ($prefilled === 'conditional_groups')
|
||||
elseif ('conditional_groups' === $prefilled)
|
||||
{
|
||||
foreach ($this->internal_conditional_group->gets_in_for_user($id_user, $ids) as $conditional_group)
|
||||
{
|
||||
|
@ -154,6 +155,7 @@ namespace controllers\publics;
|
|||
if (!$ids)
|
||||
{
|
||||
\FlashMessage\FlashMessage::push('danger', 'Vous devez choisir des messages à mettre à jour !');
|
||||
|
||||
return $this->redirect(\descartes\Router::url('Scheduled', 'list'));
|
||||
}
|
||||
|
||||
|
@ -195,7 +197,7 @@ namespace controllers\publics;
|
|||
}
|
||||
|
||||
$media = $this->internal_media->get_for_scheduled_and_user($id_user, $scheduled['id']);
|
||||
$scheduleds[$key]['media'] = $media;
|
||||
$scheduleds[$key]['media'] = $media;
|
||||
|
||||
$conditional_groups = $this->internal_scheduled->get_conditional_groups($scheduled['id']);
|
||||
foreach ($conditional_groups as $conditional_group)
|
||||
|
@ -220,7 +222,7 @@ namespace controllers\publics;
|
|||
* @param string $_POST['numbers'] : Les numeros de téléphone du scheduled
|
||||
* @param string $_POST['contacts'] : Les contacts du scheduled
|
||||
* @param string $_POST['groups'] : Les groups du scheduled
|
||||
* @param array $_FILES['media'] : The media to link to a scheduled
|
||||
* @param array $_FILES['media'] : The media to link to a scheduled
|
||||
*/
|
||||
public function create($csrf)
|
||||
{
|
||||
|
@ -272,30 +274,31 @@ namespace controllers\publics;
|
|||
if (!$numbers && !$contacts && !$groups && !$conditional_groups)
|
||||
{
|
||||
\FlashMessage\FlashMessage::push('danger', 'Vous devez renseigner au moins un destinataire pour le Sms.');
|
||||
|
||||
return $this->redirect(\descartes\Router::url('Scheduled', 'add'));
|
||||
}
|
||||
|
||||
|
||||
if ($origin && !$this->internal_phone->get_by_number_and_user($id_user, $origin))
|
||||
{
|
||||
\FlashMessage\FlashMessage::push('danger', 'Ce numéro n\'existe pas ou vous n\'en êtes pas propriétaire.');
|
||||
|
||||
return $this->redirect(\descartes\Router::url('Scheduled', 'add'));
|
||||
}
|
||||
|
||||
|
||||
$scheduled_id = $this->internal_scheduled->create($id_user, $at, $text, $origin, $flash, $numbers, $contacts, $groups, $conditional_groups);
|
||||
if (!$scheduled_id)
|
||||
{
|
||||
\FlashMessage\FlashMessage::push('danger', 'Impossible de créer le Sms.');
|
||||
|
||||
return $this->redirect(\descartes\Router::url('Scheduled', 'add'));
|
||||
}
|
||||
|
||||
|
||||
//If mms is enabled, try to process a media to link to the scheduled
|
||||
$media = $_FILES['media'] ?? false;
|
||||
if (!($_SESSION['user']['settings']['mms'] ?? false) || !$media)
|
||||
{
|
||||
\FlashMessage\FlashMessage::push('success', 'Le Sms a bien été créé pour le '.$at.'.');
|
||||
|
||||
return $this->redirect(\descartes\Router::url('Scheduled', 'list'));
|
||||
}
|
||||
|
||||
|
@ -303,10 +306,12 @@ namespace controllers\publics;
|
|||
if (!$success)
|
||||
{
|
||||
\FlashMessage\FlashMessage::push('success', 'Le SMS a bien été créé mais le média n\'as pas pu être enregistré.');
|
||||
|
||||
return $this->redirect(\descartes\Router::url('Scheduled', 'list'));
|
||||
}
|
||||
|
||||
\FlashMessage\FlashMessage::push('success', 'Le Sms a bien été créé pour le '.$at.'.');
|
||||
|
||||
return $this->redirect(\descartes\Router::url('Scheduled', 'list'));
|
||||
}
|
||||
|
||||
|
@ -329,7 +334,6 @@ namespace controllers\publics;
|
|||
|
||||
$scheduleds = $_POST['scheduleds'] ?? [];
|
||||
|
||||
|
||||
$nb_update = 0;
|
||||
foreach ($scheduleds as $id_scheduled => $scheduled)
|
||||
{
|
||||
|
@ -348,8 +352,7 @@ namespace controllers\publics;
|
|||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (empty($text))
|
||||
{
|
||||
continue;
|
||||
|
@ -377,8 +380,7 @@ namespace controllers\publics;
|
|||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
|
||||
if ($origin && !$this->internal_phone->get_by_number_and_user($id_user, $origin))
|
||||
{
|
||||
continue;
|
||||
|
@ -408,17 +410,18 @@ namespace controllers\publics;
|
|||
}
|
||||
*/
|
||||
|
||||
$nb_update += 1;
|
||||
++$nb_update;
|
||||
}
|
||||
|
||||
if ($nb_update != count($scheduleds))
|
||||
if ($nb_update !== \count($scheduleds))
|
||||
{
|
||||
\FlashMessage\FlashMessage::push('danger', 'Certains SMS n\'ont pas été mis à jour.');
|
||||
|
||||
return $this->redirect(\descartes\Router::url('Scheduled', 'list'));
|
||||
}
|
||||
|
||||
\FlashMessage\FlashMessage::push('success', 'Tous les SMS ont été mis à jour.');
|
||||
|
||||
return $this->redirect(\descartes\Router::url('Scheduled', 'list'));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -51,12 +51,13 @@ namespace controllers\publics;
|
|||
|
||||
return $this->redirect(\descartes\Router::url('Setting', 'show'));
|
||||
}
|
||||
|
||||
|
||||
$setting_value = $_POST['setting_value'] ?? false;
|
||||
|
||||
if (false === $setting_value)
|
||||
{
|
||||
\FlashMessage\FlashMessage::push('danger', 'Vous devez renseigner une valeure pour le réglage.');
|
||||
|
||||
return $this->redirect(\descartes\Router::url('Setting', 'show'));
|
||||
}
|
||||
|
||||
|
@ -72,6 +73,7 @@ namespace controllers\publics;
|
|||
$_SESSION['user']['settings'] = $settings;
|
||||
|
||||
\FlashMessage\FlashMessage::push('success', 'Le réglage a bien été mis à jour.');
|
||||
|
||||
return $this->redirect(\descartes\Router::url('Setting', 'show'));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,12 +32,14 @@ namespace controllers\publics;
|
|||
}
|
||||
|
||||
/**
|
||||
* Try to render a template as a message for preview
|
||||
* @param string $_POST['template'] : Template string
|
||||
* @param int $_POST['id_contact'] : Id of the contact to render the template for
|
||||
* Try to render a template as a message for preview.
|
||||
*
|
||||
* @param string $_POST['template'] : Template string
|
||||
* @param int $_POST['id_contact'] : Id of the contact to render the template for
|
||||
*
|
||||
* @return json string
|
||||
*/
|
||||
public function render_preview ()
|
||||
public function render_preview()
|
||||
{
|
||||
$return = [
|
||||
'success' => false,
|
||||
|
@ -46,19 +48,21 @@ namespace controllers\publics;
|
|||
|
||||
$template = $_POST['template'] ?? false;
|
||||
$id_contact = $_POST['id_contact'] ?? false;
|
||||
|
||||
|
||||
if (!$template || !$id_contact)
|
||||
{
|
||||
$return['result'] = 'Veuillez remplir un message.';
|
||||
echo json_encode($return);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
$contact = $this->internal_contact->get_for_user($_SESSION['user']['id'], $id_contact);
|
||||
if (!$contact)
|
||||
{
|
||||
$return['result'] = 'Ce contact n\'existe pas.';
|
||||
echo json_encode($return);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -76,6 +80,7 @@ namespace controllers\publics;
|
|||
}
|
||||
|
||||
echo json_encode($return);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ namespace controllers\publics;
|
|||
}
|
||||
|
||||
/**
|
||||
* List all webhooks
|
||||
* List all webhooks.
|
||||
*
|
||||
* @param mixed $page
|
||||
*/
|
||||
|
@ -42,7 +42,7 @@ namespace controllers\publics;
|
|||
}
|
||||
|
||||
/**
|
||||
* Delete a list of webhooks
|
||||
* Delete a list of webhooks.
|
||||
*
|
||||
* @param array int $_GET['ids'] : Les id des webhooks à supprimer
|
||||
* @param mixed $csrf
|
||||
|
@ -77,7 +77,7 @@ namespace controllers\publics;
|
|||
}
|
||||
|
||||
/**
|
||||
* Edit a list of webhooks
|
||||
* Edit a list of webhooks.
|
||||
*
|
||||
* @param array int $_GET['ids'] : ids of webhooks to edit
|
||||
*/
|
||||
|
@ -93,10 +93,10 @@ namespace controllers\publics;
|
|||
}
|
||||
|
||||
/**
|
||||
* Insert a new webhook
|
||||
* Insert a new webhook.
|
||||
*
|
||||
* @param $csrf : Le jeton CSRF
|
||||
* @param string $_POST['url'] : URL to call on webhook release
|
||||
* @param string $_POST['url'] : URL to call on webhook release
|
||||
* @param string $_POST['type'] : Type of webhook, either 'send_sms' or 'receive_sms'
|
||||
*
|
||||
* @return boolean;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue