Add support for numbers with data on scheduled + add support for sending sms to a csv file
This commit is contained in:
parent
7fc7a8f245
commit
81fb987740
|
@ -13,7 +13,6 @@ namespace adapters;
|
|||
|
||||
use controllers\internals\Quota;
|
||||
use controllers\internals\Tool;
|
||||
use descartes\Router;
|
||||
|
||||
/**
|
||||
* Kannel adapter.
|
||||
|
@ -31,7 +30,7 @@ class KannelAdapter implements AdapterInterface
|
|||
const KANNEL_CODING_UCS_2 = 2;
|
||||
|
||||
/**
|
||||
* DLR mask to transmit to kannel
|
||||
* DLR mask to transmit to kannel.
|
||||
*
|
||||
* 1 -> Delivered to phone
|
||||
* 2 -> not delivered
|
||||
|
@ -47,7 +46,7 @@ class KannelAdapter implements AdapterInterface
|
|||
private $data;
|
||||
|
||||
/**
|
||||
* Kannel send-sms service url
|
||||
* Kannel send-sms service url.
|
||||
*/
|
||||
private $kannel_sendsms_url;
|
||||
|
||||
|
@ -62,17 +61,17 @@ class KannelAdapter implements AdapterInterface
|
|||
private $password;
|
||||
|
||||
/**
|
||||
* Phone number of the sender, this number may or may not actually be overrided by the SMSC
|
||||
* Phone number of the sender, this number may or may not actually be overrided by the SMSC.
|
||||
*/
|
||||
private $from;
|
||||
|
||||
/**
|
||||
* SMSC's id to use for sending the message
|
||||
* SMSC's id to use for sending the message.
|
||||
*/
|
||||
private $smsc;
|
||||
|
||||
/**
|
||||
* SMS Delivery Report Url
|
||||
* SMS Delivery Report Url.
|
||||
*/
|
||||
private $dlr_url;
|
||||
|
||||
|
@ -265,7 +264,6 @@ class KannelAdapter implements AdapterInterface
|
|||
//in order to retrieve it in raspisms and update the status
|
||||
$sms_uid = Tool::random_uuid();
|
||||
|
||||
|
||||
//Forge dlr Url by adding new query parts to url provided within phone settings
|
||||
$dlr_url_parts = parse_url($this->dlr_url);
|
||||
|
||||
|
@ -279,7 +277,6 @@ class KannelAdapter implements AdapterInterface
|
|||
|
||||
$forged_dlr_url = Tool::unparse_url($dlr_url_parts);
|
||||
|
||||
|
||||
$data = [
|
||||
'username' => $this->username,
|
||||
'password' => $this->password,
|
||||
|
@ -389,11 +386,11 @@ class KannelAdapter implements AdapterInterface
|
|||
|
||||
switch (true)
|
||||
{
|
||||
case 403 == $http_code : //Bad credentials
|
||||
case 404 == $http_code : //Cannot find url
|
||||
case 403 == $http_code: //Bad credentials
|
||||
case 404 == $http_code: //Cannot find url
|
||||
return false;
|
||||
|
||||
case $http_code >= 500 : //Server error
|
||||
case $http_code >= 500: //Server error
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -373,6 +373,46 @@ footer img
|
|||
text-align: right;
|
||||
}
|
||||
|
||||
.scheduleds-number-groupe
|
||||
{
|
||||
padding-top: 15px;
|
||||
padding-bottom: 15px;
|
||||
background-color: #eee;
|
||||
border-radius: 4px;
|
||||
margin-bottom: 15px;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.scheduleds-number-groupe-remove
|
||||
{
|
||||
position: absolute;
|
||||
top: 15px;
|
||||
right: 15px;
|
||||
color: #888;
|
||||
}
|
||||
|
||||
.scheduleds-number-groupe-remove:hover
|
||||
{
|
||||
color: #555;
|
||||
}
|
||||
|
||||
.scheduleds-number-data-container .form-group:last-of-type
|
||||
{
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
.scheduled-number-data-name
|
||||
{
|
||||
width: 30%;
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.scheduled-number-data-value
|
||||
{
|
||||
width: 65%;
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
/* AUDIO RECEPTION MESSAGE */
|
||||
#reception-sound
|
||||
{
|
||||
|
@ -414,11 +454,18 @@ footer img
|
|||
width: 50%;
|
||||
}
|
||||
|
||||
.contact-data-container .contact-data-remove
|
||||
.contact-data-container .contact-data-remove,
|
||||
.scheduled-number-data-remove
|
||||
{
|
||||
color: #c9302c;
|
||||
}
|
||||
|
||||
.contact-data-container .contact-data-remove:hover,
|
||||
.scheduled-number-data-remove:hover
|
||||
{
|
||||
color: #9b2420;
|
||||
}
|
||||
|
||||
|
||||
/* PHONE */
|
||||
#adapter-data-container
|
||||
|
|
|
@ -108,7 +108,7 @@ class Quota extends StandardController
|
|||
}
|
||||
|
||||
/**
|
||||
* Check if a message can be encoded as gsm0338 or if it must be UTF8
|
||||
* Check if a message can be encoded as gsm0338 or if it must be UTF8.
|
||||
*
|
||||
* @param string $text : Message to send
|
||||
*
|
||||
|
|
|
@ -48,8 +48,8 @@ use Symfony\Component\ExpressionLanguage\ExpressionLanguage;
|
|||
|
||||
return true;
|
||||
}
|
||||
catch (\Throwable $t) //Catch both, exceptions and php error
|
||||
{
|
||||
catch (\Throwable $t)
|
||||
{ //Catch both, exceptions and php error
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -71,8 +71,8 @@ use Symfony\Component\ExpressionLanguage\ExpressionLanguage;
|
|||
|
||||
return (bool) $result;
|
||||
}
|
||||
catch (\Throwable $t) //Catch both, exceptions and php error
|
||||
{
|
||||
catch (\Throwable $t)
|
||||
{ //Catch both, exceptions and php error
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ namespace controllers\internals;
|
|||
* @param ?int $id_phone : Id of the phone to send message with, null by default
|
||||
* @param bool $flash : Is the sms a flash sms, by default false
|
||||
* @param bool $mms : Is the sms a mms, by default false
|
||||
* @param array $numbers : Numbers to send message to
|
||||
* @param array $numbers : Array of numbers to send message to, a number is an array ['number' => '+33XXX', 'data' => '{"key":"value", ...}']
|
||||
* @param array $contacts_ids : Contact ids to send message to
|
||||
* @param array $groups_ids : Group ids to send message to
|
||||
* @param array $conditional_group_ids : Conditional Groups ids to send message to
|
||||
|
@ -84,7 +84,7 @@ namespace controllers\internals;
|
|||
|
||||
foreach ($numbers as $number)
|
||||
{
|
||||
$this->get_model()->insert_scheduled_number($id_scheduled, $number);
|
||||
$this->get_model()->insert_scheduled_number($id_scheduled, $number['number'], $number['data']);
|
||||
}
|
||||
|
||||
$internal_contact = new Contact($this->bdd);
|
||||
|
@ -146,7 +146,7 @@ namespace controllers\internals;
|
|||
* @param ?int $id_phone : Id of the phone to send message with, null by default
|
||||
* @param bool $flash : Is the sms a flash sms, by default false
|
||||
* @param bool $mms : Is the sms a mms, by default false
|
||||
* @param array $numbers : Numbers to send message to
|
||||
* @param array $numbers : Array of numbers to send message to, a number is an array ['number' => '+33XXX', 'data' => '{"key":"value", ...}']
|
||||
* @param array $contacts_ids : Contact ids to send message to
|
||||
* @param array $groups_ids : Group ids to send message to
|
||||
* @param array $conditional_group_ids : Conditional Groups ids to send message to
|
||||
|
@ -201,7 +201,7 @@ namespace controllers\internals;
|
|||
|
||||
foreach ($numbers as $number)
|
||||
{
|
||||
$this->get_model()->insert_scheduled_number($id_scheduled, $number);
|
||||
$this->get_model()->insert_scheduled_number($id_scheduled, $number['number'], $number['data']);
|
||||
}
|
||||
|
||||
$internal_contact = new Contact($this->bdd);
|
||||
|
@ -496,6 +496,72 @@ namespace controllers\internals;
|
|||
return $smss_to_send_per_scheduled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a CSV file of numbers, potentially associated with datas.
|
||||
*
|
||||
* @param resource $file_handler : File handler pointing to the file
|
||||
*
|
||||
* @throws Exception : raise exception if file is not valid
|
||||
*
|
||||
* @return mixed : array of numbers ['number' => '+XXXX...', 'data' => ['key' => 'value', ...]]
|
||||
*/
|
||||
public function parse_csv_numbers_file($file_handler)
|
||||
{
|
||||
$numbers = [];
|
||||
|
||||
$head = null;
|
||||
$line_nb = 0;
|
||||
while ($line = fgetcsv($file_handler))
|
||||
{
|
||||
++$line_nb;
|
||||
if (null === $head)
|
||||
{
|
||||
$head = $line;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
//Padding line with '' entries to make sure its same length as head
|
||||
//this allow to mix users with data with users without data
|
||||
$line = array_pad($line, \count($head), '');
|
||||
|
||||
$line = array_combine($head, $line);
|
||||
if (false === $line)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$phone_number = \controllers\internals\Tool::parse_phone($line[array_keys($line)[0]] ?? '');
|
||||
if (!$phone_number)
|
||||
{
|
||||
throw new \Exception('Erreur à la ligne ' . $line_nb . ' colonne 1, numéro de téléphone invalide.');
|
||||
}
|
||||
|
||||
$data = [];
|
||||
$i = 0;
|
||||
foreach ($line as $key => $value)
|
||||
{
|
||||
++$i;
|
||||
if ($i < 2)
|
||||
{ // Ignore first column
|
||||
continue;
|
||||
}
|
||||
|
||||
if ('' === $value)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$key = mb_ereg_replace('[\W]', '', $key);
|
||||
$data[$key] = $value;
|
||||
}
|
||||
|
||||
$numbers[] = ['number' => $phone_number, 'data' => $data];
|
||||
}
|
||||
|
||||
return $numbers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return numbers for a scheduled message.
|
||||
*
|
||||
|
|
|
@ -225,6 +225,7 @@ namespace controllers\internals;
|
|||
* @param bool $mms : Is the sms a MMS. By default false.
|
||||
* @param array $medias : Array of medias to link to the MMS
|
||||
* @param string $status : Status of a the sms. By default \models\Sended::STATUS_UNKNOWN
|
||||
* @param null|mixed $originating_scheduled
|
||||
*
|
||||
* @return array : [
|
||||
* bool 'error' => false if success, true else
|
||||
|
|
|
@ -374,9 +374,10 @@ namespace controllers\internals;
|
|||
}
|
||||
|
||||
/**
|
||||
* Forge back an url parsed with PHP parse_url function
|
||||
* Forge back an url parsed with PHP parse_url function.
|
||||
*
|
||||
* @param array $parsed_url : Parsed url returned by parse_url function
|
||||
*
|
||||
* @return string : The url as a string
|
||||
*/
|
||||
public static function unparse_url(array $parsed_url)
|
||||
|
@ -386,10 +387,11 @@ namespace controllers\internals;
|
|||
$port = isset($parsed_url['port']) ? ':' . $parsed_url['port'] : '';
|
||||
$user = isset($parsed_url['user']) ? $parsed_url['user'] : '';
|
||||
$pass = isset($parsed_url['pass']) ? ':' . $parsed_url['pass'] : '';
|
||||
$pass = ($user || $pass) ? "$pass@" : '';
|
||||
$pass = ($user || $pass) ? "{$pass}@" : '';
|
||||
$path = isset($parsed_url['path']) ? $parsed_url['path'] : '';
|
||||
$query = isset($parsed_url['query']) ? '?' . $parsed_url['query'] : '';
|
||||
$fragment = isset($parsed_url['fragment']) ? '#' . $parsed_url['fragment'] : '';
|
||||
return "$scheme$user$pass$host$port$path$query$fragment";
|
||||
|
||||
return "{$scheme}{$user}{$pass}{$host}{$port}{$path}{$query}{$fragment}";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -222,6 +222,7 @@ namespace controllers\publics;
|
|||
$groups = $_POST['groups'] ?? [];
|
||||
$conditional_groups = $_POST['conditional_groups'] ?? [];
|
||||
$files = $_FILES['medias'] ?? false;
|
||||
$csv_file = $_FILES['numbers_csv'] ?? false;
|
||||
|
||||
$numbers = \is_array($numbers) ? $numbers : [$numbers];
|
||||
$contacts = \is_array($contacts) ? $contacts : [$contacts];
|
||||
|
@ -315,22 +316,66 @@ namespace controllers\publics;
|
|||
return $this->json($return);
|
||||
}
|
||||
|
||||
if ($csv_file)
|
||||
{
|
||||
$uploaded_file = \controllers\internals\Tool::read_uploaded_file($csv_file);
|
||||
if (!$uploaded_file['success'])
|
||||
{
|
||||
$return = self::DEFAULT_RETURN;
|
||||
$return['error'] = self::ERROR_CODES['INVALID_PARAMETER'];
|
||||
$return['message'] = self::ERROR_MESSAGES['INVALID_PARAMETER'] . 'csv : ' . $uploaded_file['content'];
|
||||
$this->auto_http_code(false);
|
||||
|
||||
return $this->json($return);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
$csv_numbers = $this->internal_scheduled->parse_csv_numbers_file($uploaded_file['content'], true);
|
||||
if (!$csv_numbers)
|
||||
{
|
||||
throw new \Exception('no valid number in csv file.');
|
||||
}
|
||||
|
||||
foreach ($csv_numbers as $csv_number)
|
||||
{
|
||||
$csv_number['data'] = json_encode($csv_number['data']);
|
||||
$numbers[] = $csv_number;
|
||||
}
|
||||
}
|
||||
catch (\Exception $e)
|
||||
{
|
||||
$return = self::DEFAULT_RETURN;
|
||||
$return['error'] = self::ERROR_CODES['INVALID_PARAMETER'];
|
||||
$return['message'] = self::ERROR_MESSAGES['INVALID_PARAMETER'] . 'csv : ' . $e->getMessage();
|
||||
$this->auto_http_code(false);
|
||||
|
||||
return $this->json($return);
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($numbers as $key => $number)
|
||||
{
|
||||
if (!is_string($number))
|
||||
// If number is not an array turn it into an array
|
||||
$number = is_array($number) ? $number : ['number' => $number, 'data' => '[]'];
|
||||
$number['data'] = $number['data'] ?? '[]';
|
||||
$number['number'] = \controllers\internals\Tool::parse_phone($number['number'] ?? '');
|
||||
|
||||
if (!$number['number'])
|
||||
{
|
||||
unset($numbers[$key]);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$number = \controllers\internals\Tool::parse_phone($number);
|
||||
|
||||
if (!$number)
|
||||
if (null === json_decode($number['data']))
|
||||
{
|
||||
unset($numbers[$key]);
|
||||
$return = self::DEFAULT_RETURN;
|
||||
$return['error'] = self::ERROR_CODES['INVALID_PARAMETER'];
|
||||
$return['message'] = self::ERROR_MESSAGES['INVALID_PARAMETER'] . 'number data must be a valid json or leave not set.';
|
||||
$this->auto_http_code(false);
|
||||
|
||||
continue;
|
||||
return $this->json($return);
|
||||
}
|
||||
|
||||
$numbers[$key] = $number;
|
||||
|
@ -368,7 +413,7 @@ namespace controllers\publics;
|
|||
{
|
||||
try
|
||||
{
|
||||
$new_media_id = $this->internal_media->upload_and_create_for_user($this->user['id'], $file);
|
||||
$new_media_id = $this->internal_media->create_from_uploaded_file_for_user($this->user['id'], $file);
|
||||
}
|
||||
catch (\Exception $e)
|
||||
{
|
||||
|
|
|
@ -45,7 +45,6 @@ namespace controllers\publics;
|
|||
return $this->render('contact/list');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return contacts as json.
|
||||
*/
|
||||
|
|
|
@ -313,7 +313,7 @@ namespace controllers\publics;
|
|||
$mms = (bool) count($media_ids);
|
||||
|
||||
//Destinations must be an array of number
|
||||
$destinations = [$destination];
|
||||
$destinations = [['number' => $destination]];
|
||||
|
||||
if (!$this->internal_scheduled->create($id_user, $at, $text, $id_phone, false, $mms, $destinations, [], [], [], $media_ids))
|
||||
{
|
||||
|
|
|
@ -197,7 +197,8 @@ namespace controllers\publics;
|
|||
$numbers = $this->internal_scheduled->get_numbers($scheduled['id']);
|
||||
foreach ($numbers as $number)
|
||||
{
|
||||
$scheduleds[$key]['numbers'][] = $number['number'];
|
||||
$number['data'] = json_decode($number['data'] ?? '[]');
|
||||
$scheduleds[$key]['numbers'][] = $number;
|
||||
}
|
||||
|
||||
$contacts = $this->internal_scheduled->get_contacts($scheduled['id']);
|
||||
|
@ -259,10 +260,12 @@ namespace controllers\publics;
|
|||
$flash = (bool) ($_POST['flash'] ?? false);
|
||||
$id_phone = empty($_POST['id_phone']) ? null : $_POST['id_phone'];
|
||||
$numbers = $_POST['numbers'] ?? [];
|
||||
$numbers = is_array($numbers) ? $numbers : [$numbers];
|
||||
$contacts = $_POST['contacts'] ?? [];
|
||||
$groups = $_POST['groups'] ?? [];
|
||||
$conditional_groups = $_POST['conditional_groups'] ?? [];
|
||||
$files = $_FILES['medias'] ?? false;
|
||||
$csv_file = $_FILES['csv'] ?? false;
|
||||
|
||||
//Iterate over files to re-create individual $_FILES array
|
||||
$files_arrays = [];
|
||||
|
@ -326,17 +329,64 @@ namespace controllers\publics;
|
|||
return $this->redirect(\descartes\Router::url('Scheduled', 'add'));
|
||||
}
|
||||
|
||||
if ($csv_file)
|
||||
{
|
||||
$uploaded_file = \controllers\internals\Tool::read_uploaded_file($csv_file);
|
||||
if (!$uploaded_file['success'])
|
||||
{
|
||||
\FlashMessage\FlashMessage::push('danger', 'Impossible de traiter ce fichier CSV : ' . $uploaded_file['content']);
|
||||
|
||||
return $this->redirect(\descartes\Router::url('Scheduled', 'add'));
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
$csv_numbers = $this->internal_scheduled->parse_csv_numbers_file($uploaded_file['content']);
|
||||
if (!$csv_numbers)
|
||||
{
|
||||
\FlashMessage\FlashMessage::push('danger', 'Aucun destinataire valide dans le fichier CSV, assurez-vous de fournir un fichier CSV valide.');
|
||||
|
||||
return $this->redirect(\descartes\Router::url('Scheduled', 'add'));
|
||||
}
|
||||
|
||||
$numbers = array_merge($csv_numbers, $numbers);
|
||||
}
|
||||
catch (\Exception $e)
|
||||
{
|
||||
\FlashMessage\FlashMessage::push('danger', 'Impossible de traiter ce fichier CSV : ' . $e->getMessage());
|
||||
|
||||
return $this->redirect(\descartes\Router::url('Scheduled', 'add'));
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($numbers as $key => $number)
|
||||
{
|
||||
$number = \controllers\internals\Tool::parse_phone($number);
|
||||
// If number is not an array turn it into an array
|
||||
$number = is_array($number) ? $number : ['number' => $number, 'data' => []];
|
||||
$number['data'] = $number['data'] ?? [];
|
||||
$number['number'] = \controllers\internals\Tool::parse_phone($number['number'] ?? '');
|
||||
|
||||
if (!$number)
|
||||
if (!$number['number'])
|
||||
{
|
||||
unset($numbers[$key]);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$clean_data = [];
|
||||
foreach ($number['data'] as $data_key => $value)
|
||||
{
|
||||
if ('' === $value)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$data_key = mb_ereg_replace('[\W]', '', $data_key);
|
||||
$clean_data[$data_key] = (string) $value;
|
||||
}
|
||||
$clean_data = json_encode($clean_data);
|
||||
$number['data'] = $clean_data;
|
||||
|
||||
$numbers[$key] = $number;
|
||||
}
|
||||
|
||||
|
@ -415,6 +465,7 @@ namespace controllers\publics;
|
|||
$groups = $scheduled['groups'] ?? [];
|
||||
$conditional_groups = $scheduled['conditional_groups'] ?? [];
|
||||
$files = $_FILES['scheduleds_' . $id_scheduled . '_medias'] ?? false;
|
||||
$csv_file = $_FILES['scheduleds_' . $id_scheduled . '_csv'] ?? false;
|
||||
$media_ids = $scheduled['media_ids'] ?? [];
|
||||
|
||||
//Check scheduled exists and belong to user
|
||||
|
@ -482,16 +533,59 @@ namespace controllers\publics;
|
|||
continue;
|
||||
}
|
||||
|
||||
if ($csv_file)
|
||||
{
|
||||
$uploaded_file = \controllers\internals\Tool::read_uploaded_file($csv_file);
|
||||
if (!$uploaded_file['success'])
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
$csv_numbers = $this->internal_scheduled->parse_csv_numbers_file($uploaded_file['content']);
|
||||
if (!$csv_numbers)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$numbers = array_merge($csv_numbers, $numbers);
|
||||
}
|
||||
catch (\Exception $e)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
$numbers = is_array($numbers) ? $numbers : [$numbers];
|
||||
foreach ($numbers as $key => $number)
|
||||
{
|
||||
$number = \controllers\internals\Tool::parse_phone($number);
|
||||
if (!$number)
|
||||
// If number is not an array turn it into an array
|
||||
$number = is_array($number) ? $number : ['number' => $number, 'data' => []];
|
||||
$number['data'] = $number['data'] ?? [];
|
||||
$number['number'] = \controllers\internals\Tool::parse_phone($number['number'] ?? '');
|
||||
|
||||
if (!$number['number'])
|
||||
{
|
||||
unset($numbers[$key]);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$clean_data = [];
|
||||
foreach ($number['data'] as $data_key => $value)
|
||||
{
|
||||
if ('' === $value)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$data_key = mb_ereg_replace('[\W]', '', $data_key);
|
||||
$clean_data[$data_key] = (string) $value;
|
||||
}
|
||||
$clean_data = json_encode($clean_data);
|
||||
$number['data'] = $clean_data;
|
||||
|
||||
$numbers[$key] = $number;
|
||||
}
|
||||
|
||||
|
|
|
@ -58,7 +58,7 @@ class Phone extends AbstractDaemon
|
|||
{
|
||||
usleep(0.5 * 1000000); //Micro sleep for perfs
|
||||
|
||||
$this->read_tick += 1;
|
||||
++$this->read_tick;
|
||||
|
||||
$this->bdd = \descartes\Model::_connect(DATABASE_HOST, DATABASE_NAME, DATABASE_USER, DATABASE_PASSWORD);
|
||||
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
|
||||
use Phinx\Migration\AbstractMigration;
|
||||
|
||||
class AddDataToScheduledNumber extends AbstractMigration
|
||||
{
|
||||
/**
|
||||
* Change Method.
|
||||
*
|
||||
* Write your reversible migrations using this method.
|
||||
*
|
||||
* More information on writing migrations is available here:
|
||||
* https://book.cakephp.org/phinx/0/en/migrations.html
|
||||
*
|
||||
* The following commands can be used in this method and Phinx will
|
||||
* automatically reverse them when rolling back:
|
||||
*
|
||||
* createTable
|
||||
* renameTable
|
||||
* addColumn
|
||||
* addCustomColumn
|
||||
* renameColumn
|
||||
* addIndex
|
||||
* addForeignKey
|
||||
*
|
||||
* Any other destructive changes will result in an error when trying to
|
||||
* rollback the migration.
|
||||
*
|
||||
* Remember to call "create()" or "update()" and NOT "save()" when working
|
||||
* with the Table class.
|
||||
*/
|
||||
public function change()
|
||||
{
|
||||
$table = $this->table('scheduled_number');
|
||||
$table->addColumn('data', 'text', ['default' => null, 'null' => true, 'after' => 'number'])
|
||||
->update();
|
||||
}
|
||||
}
|
|
@ -75,12 +75,13 @@ namespace models;
|
|||
*
|
||||
* @param int $id_scheduled : Scheduled id
|
||||
* @param string $number : Number
|
||||
* @param string $data : Data to link to number
|
||||
*
|
||||
* @return mixed (bool|int) : False on error, new row id else
|
||||
*/
|
||||
public function insert_scheduled_number(int $id_scheduled, string $number)
|
||||
public function insert_scheduled_number(int $id_scheduled, string $number, string $data)
|
||||
{
|
||||
$success = $this->_insert('scheduled_number', ['id_scheduled' => $id_scheduled, 'number' => $number]);
|
||||
$success = $this->_insert('scheduled_number', ['id_scheduled' => $id_scheduled, 'number' => $number, 'data' => $data]);
|
||||
|
||||
return $success ? $this->_last_id() : false;
|
||||
}
|
||||
|
|
|
@ -80,12 +80,23 @@
|
|||
</div>
|
||||
<div class="form-group">
|
||||
<label>Numéros cibles</label>
|
||||
<div class="form-group scheduleds-number-groupe-container">
|
||||
<div class="form-group scheduleds-number-groupe">
|
||||
<input name="" class="form-control phone-international-input" type="tel" >
|
||||
<span class="remove-scheduleds-number fa fa-times"></span>
|
||||
<div class="form-group scheduleds-number-groupe-container container-fluid">
|
||||
<div class="row scheduleds-number-groupe">
|
||||
<?php $random_id = uniqid(); ?>
|
||||
<div class="col-xs-4">
|
||||
<label>Numéro cible : </label><br/>
|
||||
<input name="" data-uid="<?= $random_id ?>" class="form-control phone-international-input" type="tel" >
|
||||
</div>
|
||||
<div class="add-number-button fa fa-plus-circle"></div>
|
||||
<div class="scheduleds-number-data-container col-xs-8">
|
||||
<label>Données associées : </label>
|
||||
<div class="form-group" data-uid="<?= $random_id ?>">
|
||||
<input name="" class="form-control scheduled-number-data-name" type="text" placeholder="Nom de la donnée" pattern="[a-zA-Z0-9_]*">
|
||||
:
|
||||
<input name="" class="form-control scheduled-number-data-value" type="text" placeholder="Valeur de la donnée">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="text-center"><div class="add-number-button fa fa-plus-circle"></div></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
|
@ -102,6 +113,15 @@
|
|||
<input class="add-conditional-groups form-control" name="conditional_groups[]" value="<?php $this->s(json_encode($_SESSION['previous_http_post']['conditional_groups'] ?? $prefilled_conditional_groups)) ?>" />
|
||||
</div>
|
||||
<?php } ?>
|
||||
<div class="form-group scheduled-media-group">
|
||||
<label>Ajouter un fichier CSV de destinataires</label>
|
||||
<p class="italic small help description-scheduled-csv">
|
||||
Le SMS sera envoyé à tous les numéros inclus dans le fichier CSV. Assurez-vous que le fichier CSV respecte le format indiqué dans la documentation sur <a href="https://documentation.raspisms.fr/users/sms/csv.html" target="_blank">l'envoi de SMS à un fichier CSV.</a>
|
||||
</p>
|
||||
<div class="form-group">
|
||||
<input class="" name="csv" value="" type="file" multiple />
|
||||
</div>
|
||||
</div>
|
||||
<?php if ($_SESSION['user']['settings']['sms_flash']) { ?>
|
||||
<div class="form-group">
|
||||
<label>Envoyer comme un SMS Flash : </label>
|
||||
|
@ -156,6 +176,7 @@
|
|||
jQuery(document).ready(function()
|
||||
{
|
||||
var number_inputs = [];
|
||||
toto = number_inputs;
|
||||
|
||||
jQuery('.add-contacts').each(function()
|
||||
{
|
||||
|
@ -206,16 +227,27 @@
|
|||
{
|
||||
var random_id = Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15);
|
||||
var newScheduledsNumberGroupe = '' +
|
||||
'<div class="form-group scheduleds-number-groupe">' +
|
||||
'<input name="" class="form-control phone-international-input" type="tel" id="' + random_id + '">' +
|
||||
' <span class="remove-scheduleds-number fa fa-times"></span>' +
|
||||
'<div class="row scheduleds-number-groupe">' +
|
||||
'<div class="col-xs-4">' +
|
||||
'<label>Numéro cible : </label><br/>' +
|
||||
'<input id="' + random_id + '" name="" class="form-control phone-international-input" type="tel" >' +
|
||||
'</div>' +
|
||||
'<div class="scheduleds-number-data-container col-xs-8">' +
|
||||
'<label>Données associées : </label>' +
|
||||
'<div class="form-group" data-uid="' + random_id + '">' +
|
||||
'<input name="" class="form-control scheduled-number-data-name" type="text" placeholder="Nom de la donnée" pattern="[a-zA-Z0-9_]*">' +
|
||||
' : ' +
|
||||
'<input name="" class="form-control scheduled-number-data-value" type="text" placeholder="Valeur de la donnée">' +
|
||||
'</div>' +
|
||||
'</div>' +
|
||||
'<a href="#" class="scheduleds-number-groupe-remove"><span class="fa fa-times"></span></a>' +
|
||||
'</div>';
|
||||
|
||||
jQuery(this).before(newScheduledsNumberGroupe);
|
||||
jQuery(this).parent('div').before(newScheduledsNumberGroupe);
|
||||
|
||||
var number_input = jQuery('#' + random_id)[0];
|
||||
var iti_number_input = window.intlTelInput(number_input, {
|
||||
hiddenInput: 'numbers[]',
|
||||
hiddenInput: 'numbers[' + random_id + '][number]',
|
||||
defaultCountry: '<?php $this->s($_SESSION['user']['settings']['default_phone_country']); ?>',
|
||||
preferredCountries: <?php $this->s(json_encode(explode(',', $_SESSION['user']['settings']['preferred_phone_country'])), false, false); ?>,
|
||||
<?php if ($_SESSION['user']['settings']['authorized_phone_country'] ?? false) { ?>
|
||||
|
@ -231,9 +263,16 @@
|
|||
});
|
||||
});
|
||||
|
||||
jQuery('body').on('click', '.scheduleds-number-groupe-remove', function (e)
|
||||
{
|
||||
e.preventDefault();
|
||||
jQuery(this).parent('.scheduleds-number-groupe').remove();
|
||||
return false;
|
||||
});
|
||||
|
||||
var number_input = jQuery('.phone-international-input')[0];
|
||||
var iti_number_input = window.intlTelInput(number_input, {
|
||||
hiddenInput: 'numbers[]',
|
||||
hiddenInput: 'numbers[' + jQuery(number_input).attr('data-uid') + '][number]',
|
||||
defaultCountry: '<?php $this->s($_SESSION['user']['settings']['default_phone_country']); ?>',
|
||||
preferredCountries: <?php $this->s(json_encode(explode(',', $_SESSION['user']['settings']['preferred_phone_country'])), false, false); ?>,
|
||||
<?php if ($_SESSION['user']['settings']['authorized_phone_country'] ?? false) { ?>
|
||||
|
@ -277,6 +316,75 @@
|
|||
dataType: 'json'
|
||||
});
|
||||
});
|
||||
|
||||
jQuery('.scheduleds-number-groupe-container').on('input', '.scheduled-number-data-value, .scheduled-number-data-name', function (e)
|
||||
{
|
||||
var scheduled_number = jQuery(this).parents('.scheduleds-number-groupe');
|
||||
var focus_group = jQuery(this).parent('.form-group');
|
||||
var focus_input = this;
|
||||
var input_name = focus_group.find('.scheduled-number-data-name');
|
||||
var input_value = focus_group.find('.scheduled-number-data-value');
|
||||
var uid = focus_group.attr('data-uid')
|
||||
|
||||
scheduled_number.find('.form-group').each(function (e)
|
||||
{
|
||||
var current_input_name = jQuery(this).find('.scheduled-number-data-name');
|
||||
var current_input_value = jQuery(this).find('.scheduled-number-data-value');
|
||||
|
||||
if (current_input_value.is(focus_input) || current_input_name.is(focus_input))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (jQuery(current_input_name).val() === '' && jQuery(current_input_value).val() === '')
|
||||
{
|
||||
jQuery(this).remove();
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
if (input_name.val() === '' || input_value.val() === '')
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
var template = '' +
|
||||
'<div class="form-group" data-uid="' + uid + '">' +
|
||||
'<input name="" class="form-control scheduled-number-data-name" type="text" placeholder="Nom de la donnée" pattern="[a-zA-Z0-9_]*">' +
|
||||
' : ' +
|
||||
'<input name="" class="form-control scheduled-number-data-value" type="text" placeholder="Valeur de la donnée">' +
|
||||
' <a href="#" class="scheduled-number-data-remove"><span class="fa fa-times"></span></a>' +
|
||||
'</div>';
|
||||
scheduled_number.find('.scheduleds-number-data-container').append(template);
|
||||
});
|
||||
|
||||
jQuery('.scheduleds-number-groupe-container').on('click', '.scheduled-number-data-remove', function (e)
|
||||
{
|
||||
e.preventDefault();
|
||||
if (jQuery('.scheduleds-number-data-container .form-group').length > 1)
|
||||
{
|
||||
jQuery(this).parent('.form-group').remove();
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
|
||||
jQuery('form').on('submit', function (e)
|
||||
{
|
||||
jQuery('.scheduleds-number-data-container .form-group').each(function ()
|
||||
{
|
||||
var name = jQuery(this).find('.scheduled-number-data-name').val();
|
||||
name = name.replace(/\W/g, '');
|
||||
var uid = jQuery(this).attr('data-uid');
|
||||
name = 'numbers[' + uid + '][data][' + name + ']';
|
||||
jQuery(this).find('.scheduled-number-data-value').attr('name', name);
|
||||
});
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
});
|
||||
</script>
|
||||
<?php
|
||||
|
|
|
@ -88,14 +88,36 @@
|
|||
</div>
|
||||
<div class="form-group">
|
||||
<label>Numéros cibles</label>
|
||||
<div class="form-group scheduleds-number-groupe-container" scheduled-id="<?php $this->s($scheduled['id']); ?>" >
|
||||
<?php foreach ($scheduled['numbers'] as $number) { ?>
|
||||
<div class="form-group scheduleds-number-groupe">
|
||||
<input name="" class="form-control phone-international-input" type="tel" value="<?php $this->s($number); ?>" scheduled-id="<?php $this->s($scheduled['id']); ?>">
|
||||
<span class="remove-scheduleds-number fa fa-times"></span>
|
||||
<div class="form-group scheduleds-number-groupe-container container-fluid" data-scheduled-id="<?php $this->s($scheduled['id']); ?>">
|
||||
<?php foreach ($scheduled['numbers'] as $number_key => $number) { ?>
|
||||
<div class="row scheduleds-number-groupe">
|
||||
<div class="col-xs-4">
|
||||
<label>Numéro cible : </label><br/>
|
||||
<input name="" data-uid="<?= $number_key ?>" class="form-control phone-international-input" type="tel" value="<?php $this->s($number['number']); ?>" >
|
||||
</div>
|
||||
<div class="scheduleds-number-data-container col-xs-8">
|
||||
<label>Données associées : </label>
|
||||
<?php foreach ($number['data'] as $data_key => $data_value) { ?>
|
||||
<div class="form-group" data-uid="<?= $number_key ?>">
|
||||
<input value="<?php $this->s($data_key); ?>" name="" class="form-control scheduled-number-data-name" type="text" placeholder="Nom de la donnée" pattern="[a-zA-Z0-9_]*">
|
||||
:
|
||||
<input value="<?php $this->s($data_value); ?>" name="" class="form-control scheduled-number-data-value" type="text" placeholder="Valeur de la donnée">
|
||||
<a href="#" class="scheduled-number-data-remove"><span class="fa fa-times"></span></a>
|
||||
</div>
|
||||
<?php } ?>
|
||||
<div class="add-number-button fa fa-plus-circle"></div>
|
||||
<div class="form-group" data-uid="<?= $number_key ?>">
|
||||
<input name="" class="form-control scheduled-number-data-name" type="text" placeholder="Nom de la donnée" pattern="[a-zA-Z0-9_]*">
|
||||
:
|
||||
<input name="" class="form-control scheduled-number-data-value" type="text" placeholder="Valeur de la donnée">
|
||||
</div>
|
||||
</div>
|
||||
<?php if (!($first ?? true)) { ?>
|
||||
<a href="#" class="scheduleds-number-groupe-remove"><span class="fa fa-times"></span></a>
|
||||
<?php } ?>
|
||||
<?php $first = false; ?>
|
||||
</div>
|
||||
<?php } ?>
|
||||
<div class="text-center"><div class="add-number-button fa fa-plus-circle"></div></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
|
@ -112,6 +134,15 @@
|
|||
<input class="add-conditional-groups form-control" name="scheduleds[<?php $this->s($scheduled['id']); ?>][conditional_groups][]" value="<?php $this->s(json_encode($scheduled['conditional_groups'])); ?>" />
|
||||
</div>
|
||||
<?php } ?>
|
||||
<div class="form-group scheduled-media-group">
|
||||
<label>Ajouter un fichier CSV de destinataires</label>
|
||||
<p class="italic small help description-scheduled-csv">
|
||||
Le SMS sera envoyé à tous les numéros inclus dans le fichier CSV. Assurez-vous que le fichier CSV respecte le format indiqué dans la documentation sur <a href="https://documentation.raspisms.fr/users/sms/csv.html" target="_blank">l'envoi de SMS à un fichier CSV.</a>
|
||||
</p>
|
||||
<div class="form-group">
|
||||
<input class="" name="scheduleds_<?php $this->s($scheduled['id']); ?>_csv" value="" type="file" multiple />
|
||||
</div>
|
||||
</div>
|
||||
<?php if ($_SESSION['user']['settings']['sms_flash']) { ?>
|
||||
<div class="form-group">
|
||||
<label>Envoyer comme un SMS Flash : </label>
|
||||
|
@ -210,7 +241,9 @@
|
|||
|
||||
jQuery('.phone-international-input').each(function ()
|
||||
{
|
||||
var hidden_input_name = 'scheduleds[' + jQuery(this).attr('scheduled-id') + '][numbers][]';
|
||||
var scheduledId = jQuery(this).parents('.scheduleds-number-groupe-container').attr('data-scheduled-id');
|
||||
var uid = jQuery(this).attr('data-uid');
|
||||
var hidden_input_name = 'scheduleds[' + scheduledId + '][numbers][' + uid + '][number]';
|
||||
window.intlTelInput(this, {
|
||||
hiddenInput: hidden_input_name,
|
||||
defaultCountry: '<?php $this->s($_SESSION['user']['settings']['default_phone_country']); ?>',
|
||||
|
@ -226,19 +259,29 @@
|
|||
jQuery('body').on('click', '.add-number-button', function(e)
|
||||
{
|
||||
var random_id = Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15);
|
||||
var scheduledId = jQuery(this).parents('.scheduleds-number-groupe-container').attr('scheduled-id');
|
||||
var scheduledId = jQuery(this).parents('.scheduleds-number-groupe-container').attr('data-scheduled-id');
|
||||
var newScheduledsNumberGroupe = '' +
|
||||
'<div class="form-group scheduleds-number-groupe">' +
|
||||
'<input name="" class="form-control phone-international-input" type="tel" scheduled-id="' + scheduledId + '" id="' + random_id + '">' +
|
||||
' <span class="remove-scheduleds-number fa fa-times"></span>' +
|
||||
'<div class="row scheduleds-number-groupe" data-scheduled-id="' + scheduledId + '">' +
|
||||
'<div class="col-xs-4">' +
|
||||
'<label>Numéro cible : </label><br/>' +
|
||||
'<input id="' + random_id + '" name="" class="form-control phone-international-input" type="tel" >' +
|
||||
'</div>' +
|
||||
'<div class="scheduleds-number-data-container col-xs-8">' +
|
||||
'<label>Données associées : </label>' +
|
||||
'<div class="form-group" data-uid="' + random_id + '">' +
|
||||
'<input name="" class="form-control scheduled-number-data-name" type="text" placeholder="Nom de la donnée" pattern="[a-zA-Z0-9_]*">' +
|
||||
' : ' +
|
||||
'<input name="" class="form-control scheduled-number-data-value" type="text" placeholder="Valeur de la donnée">' +
|
||||
'</div>' +
|
||||
'</div>' +
|
||||
'<a href="#" class="scheduleds-number-groupe-remove"><span class="fa fa-times"></span></a>' +
|
||||
'</div>';
|
||||
|
||||
jQuery(this).before(newScheduledsNumberGroupe);
|
||||
jQuery(this).parent('div').before(newScheduledsNumberGroupe);
|
||||
|
||||
var hidden_input_name = 'scheduleds[' + scheduledId + '][numbers][]';
|
||||
var phone_input = jQuery('#' + random_id)[0];
|
||||
window.intlTelInput(phone_input, {
|
||||
hiddenInput: hidden_input_name,
|
||||
var number_input = jQuery('#' + random_id)[0];
|
||||
var iti_number_input = window.intlTelInput(number_input, {
|
||||
hiddenInput: 'scheduleds[' + scheduledId + '][numbers][' + random_id + '][number]',
|
||||
defaultCountry: '<?php $this->s($_SESSION['user']['settings']['default_phone_country']); ?>',
|
||||
preferredCountries: <?php $this->s(json_encode(explode(',', $_SESSION['user']['settings']['preferred_phone_country'])), false, false); ?>,
|
||||
<?php if ($_SESSION['user']['settings']['authorized_phone_country'] ?? false) { ?>
|
||||
|
@ -248,6 +291,17 @@
|
|||
utilsScript: '<?php echo HTTP_PWD_JS; ?>/intlTelInput/utils.js'
|
||||
});
|
||||
|
||||
number_inputs.push({
|
||||
'number_input': number_input,
|
||||
'iti_number_input': iti_number_input,
|
||||
});
|
||||
});
|
||||
|
||||
jQuery('body').on('click', '.scheduleds-number-groupe-remove', function (e)
|
||||
{
|
||||
e.preventDefault();
|
||||
jQuery(this).parent('.scheduleds-number-groupe').remove();
|
||||
return false;
|
||||
});
|
||||
|
||||
jQuery('body').on('click', '.btn-delete-media', function (e)
|
||||
|
@ -285,6 +339,75 @@
|
|||
dataType: 'json'
|
||||
});
|
||||
});
|
||||
|
||||
jQuery('.scheduleds-number-groupe-container').on('input', '.scheduled-number-data-value, .scheduled-number-data-name', function (e)
|
||||
{
|
||||
var scheduled_number = jQuery(this).parents('.scheduleds-number-groupe');
|
||||
var focus_group = jQuery(this).parent('.form-group');
|
||||
var focus_input = this;
|
||||
var input_name = focus_group.find('.scheduled-number-data-name');
|
||||
var input_value = focus_group.find('.scheduled-number-data-value');
|
||||
var uid = focus_group.attr('data-uid')
|
||||
|
||||
scheduled_number.find('.form-group').each(function (e)
|
||||
{
|
||||
var current_input_name = jQuery(this).find('.scheduled-number-data-name');
|
||||
var current_input_value = jQuery(this).find('.scheduled-number-data-value');
|
||||
|
||||
if (current_input_value.is(focus_input) || current_input_name.is(focus_input))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (jQuery(current_input_name).val() === '' && jQuery(current_input_value).val() === '')
|
||||
{
|
||||
jQuery(this).remove();
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
if (input_name.val() === '' || input_value.val() === '')
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
var template = '' +
|
||||
'<div class="form-group" data-uid="' + uid + '">' +
|
||||
'<input name="" class="form-control scheduled-number-data-name" type="text" placeholder="Nom de la donnée" pattern="[a-zA-Z0-9_]*">' +
|
||||
' : ' +
|
||||
'<input name="" class="form-control scheduled-number-data-value" type="text" placeholder="Valeur de la donnée">' +
|
||||
' <a href="#" class="scheduled-number-data-remove"><span class="fa fa-times"></span></a>' +
|
||||
'</div>';
|
||||
scheduled_number.find('.scheduleds-number-data-container').append(template);
|
||||
});
|
||||
|
||||
jQuery('.scheduleds-number-groupe-container').on('click', '.scheduled-number-data-remove', function (e)
|
||||
{
|
||||
e.preventDefault();
|
||||
if (jQuery('.scheduleds-number-data-container .form-group').length > 1)
|
||||
{
|
||||
jQuery(this).parent('.form-group').remove();
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
|
||||
jQuery('form').on('submit', function (e)
|
||||
{
|
||||
jQuery('.scheduleds-number-data-container .form-group').each(function ()
|
||||
{
|
||||
var name = jQuery(this).find('.scheduled-number-data-name').val();
|
||||
name = name.replace(/\W/g, '');
|
||||
var scheduled_id = jQuery(this).parents('.scheduleds-number-groupe-container').attr('data-scheduled-id')
|
||||
var uid = jQuery(this).attr('data-uid');
|
||||
name = 'scheduleds[' + scheduled_id + '][numbers][' + uid + '][data][' + name + ']';
|
||||
jQuery(this).find('.scheduled-number-data-value').attr('name', name);
|
||||
});
|
||||
|
||||
return true;
|
||||
});
|
||||
});
|
||||
</script>
|
||||
<?php
|
||||
|
|
Loading…
Reference in New Issue