2019-11-12 05:16:59 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This file is part of RaspiSMS.
|
|
|
|
*
|
|
|
|
* (c) Pierre-Lin Bonnemaison <plebwebsas@gmail.com>
|
|
|
|
*
|
|
|
|
* This source file is subject to the GPL-3.0 license that is bundled
|
|
|
|
* with this source code in the file LICENSE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace controllers\publics;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Page des phones.
|
|
|
|
*/
|
|
|
|
class Phone extends \descartes\Controller
|
|
|
|
{
|
|
|
|
private $internal_phone;
|
|
|
|
private $internal_adapter;
|
|
|
|
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
$bdd = \descartes\Model::_connect(DATABASE_HOST, DATABASE_NAME, DATABASE_USER, DATABASE_PASSWORD);
|
|
|
|
$this->internal_phone = new \controllers\internals\Phone($bdd);
|
2020-01-17 18:36:53 +01:00
|
|
|
$this->internal_adapter = new \controllers\internals\Adapter();
|
2019-11-12 05:16:59 +01:00
|
|
|
|
|
|
|
\controllers\internals\Tool::verifyconnect();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Cette fonction retourne tous les phones, sous forme d'un tableau permettant l'administration de ces phones.
|
|
|
|
*/
|
2020-04-07 03:02:33 +02:00
|
|
|
public function list()
|
2019-11-12 05:16:59 +01:00
|
|
|
{
|
2021-03-24 00:22:17 +01:00
|
|
|
$this->render('phone/list');
|
2019-11-12 05:16:59 +01:00
|
|
|
}
|
|
|
|
|
2020-09-23 03:02:13 +02:00
|
|
|
/**
|
2021-01-17 03:16:57 +01:00
|
|
|
* Return phones as json with additionnals data about callbacks.
|
2020-09-23 03:02:13 +02:00
|
|
|
*/
|
|
|
|
public function list_json()
|
|
|
|
{
|
|
|
|
$id_user = $_SESSION['user']['id'];
|
|
|
|
$api_key = $_SESSION['user']['api_key'];
|
|
|
|
$phones = $this->internal_phone->list_for_user($id_user);
|
|
|
|
|
|
|
|
$adapters = [];
|
|
|
|
$adapters = $this->internal_adapter->list_adapters();
|
|
|
|
foreach ($adapters as $key => $adapter)
|
|
|
|
{
|
|
|
|
unset($adapters[$key]);
|
|
|
|
$adapters[$adapter['meta_classname']] = $adapter;
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($phones as &$phone)
|
|
|
|
{
|
2023-02-04 01:45:59 +01:00
|
|
|
$limits = $this->internal_phone->get_limits($phone['id']);
|
|
|
|
$phone['limits'] = $limits;
|
|
|
|
|
2020-09-23 03:02:13 +02:00
|
|
|
$adapter = $adapters[$phone['adapter']] ?? false;
|
|
|
|
|
|
|
|
if (!$adapter)
|
|
|
|
{
|
|
|
|
$phone['adapter'] = 'Inconnu';
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
$phone['adapter'] = $adapter['meta_name'];
|
|
|
|
|
|
|
|
if ($adapter['meta_support_reception'])
|
|
|
|
{
|
|
|
|
$phone['callback_reception'] = \descartes\Router::url('Callback', 'reception', ['adapter_uid' => $adapter['meta_uid'], 'id_phone' => $phone['id']], ['api_key' => $api_key]);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($adapter['meta_support_status_change'])
|
|
|
|
{
|
|
|
|
$phone['callback_status'] = \descartes\Router::url('Callback', 'update_sended_status', ['adapter_uid' => $adapter['meta_uid']], ['api_key' => $api_key]);
|
|
|
|
}
|
2021-06-17 00:51:33 +02:00
|
|
|
|
2021-03-24 00:22:17 +01:00
|
|
|
if ($adapter['meta_support_inbound_call_callback'])
|
|
|
|
{
|
|
|
|
$phone['callback_inbound_call'] = \descartes\Router::url('Callback', 'inbound_call', ['id_phone' => $phone['id']], ['api_key' => $api_key]);
|
|
|
|
}
|
2021-06-17 00:51:33 +02:00
|
|
|
|
2021-03-24 00:22:17 +01:00
|
|
|
if ($adapter['meta_support_end_call_callback'])
|
|
|
|
{
|
|
|
|
$phone['callback_end_call'] = \descartes\Router::url('Callback', 'end_call', ['id_phone' => $phone['id']], ['api_key' => $api_key]);
|
|
|
|
}
|
2020-09-23 03:02:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
header('Content-Type: application/json');
|
|
|
|
echo json_encode(['data' => $phones]);
|
|
|
|
}
|
|
|
|
|
2019-11-12 05:16:59 +01:00
|
|
|
/**
|
|
|
|
* Cette fonction va supprimer une liste de phones.
|
|
|
|
*
|
|
|
|
* @param array int $_GET['ids'] : Les id des phonees à supprimer
|
|
|
|
* @param mixed $csrf
|
|
|
|
*
|
|
|
|
* @return boolean;
|
|
|
|
*/
|
|
|
|
public function delete($csrf)
|
|
|
|
{
|
|
|
|
if (!$this->verify_csrf($csrf))
|
|
|
|
{
|
|
|
|
\FlashMessage\FlashMessage::push('danger', 'Jeton CSRF invalid !');
|
|
|
|
|
|
|
|
return $this->redirect(\descartes\Router::url('Phone', 'list'));
|
|
|
|
}
|
|
|
|
|
|
|
|
$ids = $_GET['ids'] ?? [];
|
|
|
|
foreach ($ids as $id)
|
|
|
|
{
|
2019-11-14 22:33:00 +01:00
|
|
|
$this->internal_phone->delete_for_user($_SESSION['user']['id'], $id);
|
2019-11-12 05:16:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return $this->redirect(\descartes\Router::url('Phone', 'list'));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Cette fonction retourne la page d'ajout d'un phone.
|
|
|
|
*/
|
|
|
|
public function add()
|
|
|
|
{
|
|
|
|
$adapters = $this->internal_adapter->list_adapters();
|
2020-01-17 18:19:25 +01:00
|
|
|
|
2019-11-12 05:16:59 +01:00
|
|
|
return $this->render('phone/add', ['adapters' => $adapters]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-01-17 18:19:25 +01:00
|
|
|
* Create a new phone.
|
|
|
|
*
|
2019-11-12 05:16:59 +01:00
|
|
|
* @param $csrf : CSRF token
|
2023-02-02 01:12:30 +01:00
|
|
|
* @param string $_POST['name'] : Phone name
|
|
|
|
* @param string $_POST['adapter'] : Phone adapter
|
|
|
|
* @param ?array $_POST['adapter_data'] : Phone adapter data
|
2023-02-04 01:15:36 +01:00
|
|
|
* @param ?array $_POST['limits'] : Array of limits in number of SMS for a period to be applied to this phone.
|
2023-02-05 23:11:58 +01:00
|
|
|
* @param int $_POST['priority'] : Priority with which to use phone to send SMS. Default 0.
|
2019-11-12 05:16:59 +01:00
|
|
|
*/
|
|
|
|
public function create($csrf)
|
|
|
|
{
|
|
|
|
if (!$this->verify_csrf($csrf))
|
|
|
|
{
|
|
|
|
\FlashMessage\FlashMessage::push('danger', 'Jeton CSRF invalid !');
|
2020-01-17 18:19:25 +01:00
|
|
|
|
2019-11-12 05:16:59 +01:00
|
|
|
return $this->redirect(\descartes\Router::url('Phone', 'add'));
|
|
|
|
}
|
|
|
|
|
|
|
|
$id_user = $_SESSION['user']['id'];
|
2020-03-31 01:19:21 +02:00
|
|
|
$name = $_POST['name'] ?? false;
|
2023-02-05 23:11:58 +01:00
|
|
|
$priority = $_POST['priority'] ?? 0;
|
|
|
|
$priority = max(((int) $priority), 0);
|
2019-11-12 05:16:59 +01:00
|
|
|
$adapter = $_POST['adapter'] ?? false;
|
2021-01-17 03:16:57 +01:00
|
|
|
$adapter_data = !empty($_POST['adapter_data']) ? $_POST['adapter_data'] : [];
|
2023-02-02 01:12:30 +01:00
|
|
|
$limits = $_POST['limits'] ?? [];
|
|
|
|
$limits = is_array($limits) ? $limits : [$limits];
|
2019-11-12 05:16:59 +01:00
|
|
|
|
2020-03-31 01:19:21 +02:00
|
|
|
if (!$name || !$adapter)
|
2019-11-12 05:16:59 +01:00
|
|
|
{
|
|
|
|
\FlashMessage\FlashMessage::push('danger', 'Des champs obligatoires sont manquants.');
|
2020-01-17 18:19:25 +01:00
|
|
|
|
2019-11-12 05:16:59 +01:00
|
|
|
return $this->redirect(\descartes\Router::url('Phone', 'add'));
|
|
|
|
}
|
|
|
|
|
2023-02-02 01:12:30 +01:00
|
|
|
$name_exist = $this->internal_phone->get_by_name_and_user($id_user, $name);
|
2020-03-31 01:19:21 +02:00
|
|
|
if ($name_exist)
|
2019-11-12 05:16:59 +01:00
|
|
|
{
|
2020-03-31 01:19:21 +02:00
|
|
|
\FlashMessage\FlashMessage::push('danger', 'Ce nom est déjà utilisé pour un autre téléphone.');
|
2020-01-17 18:19:25 +01:00
|
|
|
|
2019-11-12 05:16:59 +01:00
|
|
|
return $this->redirect(\descartes\Router::url('Phone', 'add'));
|
|
|
|
}
|
|
|
|
|
2023-02-02 01:12:30 +01:00
|
|
|
if ($limits)
|
|
|
|
{
|
|
|
|
foreach ($limits as $key => $limit)
|
|
|
|
{
|
2023-02-04 01:15:36 +01:00
|
|
|
if (!is_array($limit))
|
|
|
|
{
|
|
|
|
unset($limits[$key]);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2023-02-02 01:12:30 +01:00
|
|
|
$startpoint = $limit['startpoint'] ?? false;
|
|
|
|
$volume = $limit['volume'] ?? false;
|
|
|
|
|
|
|
|
if (!$startpoint || !$volume)
|
|
|
|
{
|
|
|
|
unset($limits[$key]);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
$volume = (int) $volume;
|
|
|
|
$limits[$key]['volume'] = max($volume, 1);
|
|
|
|
|
|
|
|
if (!\controllers\internals\Tool::validate_relative_date($startpoint))
|
|
|
|
{
|
|
|
|
unset($limits[$key]);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-12 05:16:59 +01:00
|
|
|
$adapters = $this->internal_adapter->list_adapters();
|
2020-01-09 22:23:58 +01:00
|
|
|
$find_adapter = false;
|
2019-11-12 05:16:59 +01:00
|
|
|
foreach ($adapters as $metas)
|
|
|
|
{
|
|
|
|
if ($metas['meta_classname'] === $adapter)
|
|
|
|
{
|
2020-01-09 22:23:58 +01:00
|
|
|
$find_adapter = $metas;
|
2020-01-17 18:19:25 +01:00
|
|
|
|
2019-11-12 05:16:59 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-09 22:23:58 +01:00
|
|
|
if (!$find_adapter)
|
2019-11-12 05:16:59 +01:00
|
|
|
{
|
2021-02-04 16:44:13 +01:00
|
|
|
\FlashMessage\FlashMessage::push('danger', 'Ce type de téléphone n\'existe pas.');
|
2020-01-17 18:19:25 +01:00
|
|
|
|
2019-11-12 05:16:59 +01:00
|
|
|
return $this->redirect(\descartes\Router::url('Phone', 'add'));
|
|
|
|
}
|
|
|
|
|
2021-01-26 19:33:08 +01:00
|
|
|
if ($find_adapter['meta_hidden'])
|
|
|
|
{
|
|
|
|
\FlashMessage\FlashMessage::push('danger', 'Ce type de téléphone ne peux pas être créé via l\'interface graphique.');
|
|
|
|
|
|
|
|
return $this->redirect(\descartes\Router::url('Phone', 'add'));
|
|
|
|
}
|
|
|
|
|
2020-01-09 22:23:58 +01:00
|
|
|
//If missing required data fields, error
|
2021-01-17 03:16:57 +01:00
|
|
|
foreach ($find_adapter['meta_data_fields'] as $field)
|
2020-01-09 22:23:58 +01:00
|
|
|
{
|
2020-01-17 18:19:25 +01:00
|
|
|
if (false === $field['required'])
|
2020-01-09 22:23:58 +01:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2021-01-17 03:16:57 +01:00
|
|
|
if (!empty($adapter_data[$field['name']]))
|
2020-01-09 22:23:58 +01:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2021-02-04 16:44:13 +01:00
|
|
|
\FlashMessage\FlashMessage::push('danger', 'Vous n\'avez pas rempli certains champs obligatoires pour ce type de téléphone.');
|
2020-01-17 18:19:25 +01:00
|
|
|
|
2020-01-09 22:23:58 +01:00
|
|
|
return $this->redirect(\descartes\Router::url('Phone', 'add'));
|
|
|
|
}
|
|
|
|
|
2020-04-02 01:55:55 +02:00
|
|
|
//If field phone number is invalid
|
2021-01-17 03:16:57 +01:00
|
|
|
foreach ($find_adapter['meta_data_fields'] as $field)
|
2020-04-02 01:55:55 +02:00
|
|
|
{
|
2022-07-12 13:16:22 +02:00
|
|
|
if ('phone_number' !== ($field['type'] ?? false))
|
2020-04-02 01:55:55 +02:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2021-01-17 03:16:57 +01:00
|
|
|
if (!empty($adapter_data[$field['name']]))
|
2020-04-02 01:55:55 +02:00
|
|
|
{
|
2021-01-17 03:16:57 +01:00
|
|
|
$adapter_data[$field['name']] = \controllers\internals\Tool::parse_phone($adapter_data[$field['name']]);
|
2020-04-02 01:55:55 +02:00
|
|
|
|
2021-01-17 03:16:57 +01:00
|
|
|
if ($adapter_data[$field['name']])
|
2020-04-02 01:55:55 +02:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
\FlashMessage\FlashMessage::push('danger', 'Vous avez fourni un numéro de téléphone avec un format invalide.');
|
|
|
|
|
|
|
|
return $this->redirect(\descartes\Router::url('Phone', 'add'));
|
|
|
|
}
|
|
|
|
|
2021-01-17 03:16:57 +01:00
|
|
|
$adapter_data = json_encode($adapter_data);
|
2020-01-09 22:23:58 +01:00
|
|
|
|
2021-01-17 03:16:57 +01:00
|
|
|
//Check adapter is working correctly with thoses names and data
|
2020-01-09 22:23:58 +01:00
|
|
|
$adapter_classname = $find_adapter['meta_classname'];
|
2021-01-17 03:16:57 +01:00
|
|
|
$adapter_instance = new $adapter_classname($adapter_data);
|
2020-01-09 22:23:58 +01:00
|
|
|
$adapter_working = $adapter_instance->test();
|
2020-03-04 05:10:45 +01:00
|
|
|
|
2020-01-09 22:23:58 +01:00
|
|
|
if (!$adapter_working)
|
2019-11-12 05:16:59 +01:00
|
|
|
{
|
2021-02-04 16:44:13 +01:00
|
|
|
\FlashMessage\FlashMessage::push('danger', 'Impossible d\'utiliser ce type de téléphone avec les données fournies. Vérifiez les réglages.');
|
2020-01-17 18:19:25 +01:00
|
|
|
|
2019-11-12 05:16:59 +01:00
|
|
|
return $this->redirect(\descartes\Router::url('Phone', 'add'));
|
|
|
|
}
|
|
|
|
|
2023-02-05 23:11:58 +01:00
|
|
|
$success = $this->internal_phone->create($id_user, $name, $adapter, $adapter_data, $priority, $limits);
|
2019-11-12 05:16:59 +01:00
|
|
|
if (!$success)
|
|
|
|
{
|
|
|
|
\FlashMessage\FlashMessage::push('danger', 'Impossible de créer ce téléphone.');
|
2020-01-17 18:19:25 +01:00
|
|
|
|
2019-11-12 05:16:59 +01:00
|
|
|
return $this->redirect(\descartes\Router::url('Phone', 'add'));
|
|
|
|
}
|
2020-01-17 18:19:25 +01:00
|
|
|
|
2019-11-12 05:16:59 +01:00
|
|
|
\FlashMessage\FlashMessage::push('success', 'Le téléphone a bien été créé.');
|
2020-01-17 18:19:25 +01:00
|
|
|
|
2019-11-12 05:16:59 +01:00
|
|
|
return $this->redirect(\descartes\Router::url('Phone', 'list'));
|
|
|
|
}
|
2023-02-04 01:15:36 +01:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the edit page for phones
|
|
|
|
*
|
|
|
|
* @param int... $ids : Phones ids
|
|
|
|
*/
|
|
|
|
public function edit()
|
|
|
|
{
|
|
|
|
$ids = $_GET['ids'] ?? [];
|
|
|
|
$id_user = $_SESSION['user']['id'];
|
|
|
|
|
|
|
|
$phones = $this->internal_phone->gets_in_for_user($id_user, $ids);
|
|
|
|
|
|
|
|
if (!$phones)
|
|
|
|
{
|
|
|
|
return $this->redirect(\descartes\Router::url('Phone', 'list'));
|
|
|
|
}
|
|
|
|
|
2023-02-06 04:35:08 +01:00
|
|
|
$adapters = $this->internal_adapter->list_adapters();
|
|
|
|
|
2023-02-04 01:15:36 +01:00
|
|
|
foreach ($phones as &$phone)
|
|
|
|
{
|
|
|
|
$limits = $this->internal_phone->get_limits($phone['id']);
|
|
|
|
$phone['limits'] = $limits;
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->render('phone/edit', [
|
|
|
|
'phones' => $phones,
|
|
|
|
'adapters' => $adapters,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update multiple phones.
|
|
|
|
*
|
|
|
|
* @param $csrf : CSRF token
|
|
|
|
* @param string $_POST['phones']['id']['name'] : Phone name
|
|
|
|
* @param string $_POST['phones']['id']['adapter'] : Phone adapter
|
|
|
|
* @param ?array $_POST['phones']['id']['adapter_data'] : Phone adapter data
|
|
|
|
* @param ?array $_POST['phones']['id']['limits'] : Array of limits in number of SMS for a period to be applied to this phone.
|
2023-02-05 23:11:58 +01:00
|
|
|
* @param int $_POST['phones']['id']['priority'] : Priority with which to use phone to send SMS. Default 0.
|
2023-02-04 01:15:36 +01:00
|
|
|
*/
|
|
|
|
public function update($csrf)
|
|
|
|
{
|
|
|
|
if (!$this->verify_csrf($csrf))
|
|
|
|
{
|
|
|
|
\FlashMessage\FlashMessage::push('danger', 'Jeton CSRF invalid !');
|
|
|
|
|
|
|
|
return $this->redirect(\descartes\Router::url('Phone', 'add'));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$_POST['phones'])
|
|
|
|
{
|
|
|
|
return $this->redirect(\descartes\Router::url('Phone', 'list'));
|
|
|
|
}
|
|
|
|
|
|
|
|
$id_user = $_SESSION['user']['id'];
|
|
|
|
|
|
|
|
$nb_update = 0;
|
|
|
|
foreach ($_POST['phones'] as $id_phone => $phone)
|
|
|
|
{
|
|
|
|
$name = $phone['name'] ?? false;
|
2023-02-05 23:11:58 +01:00
|
|
|
$priority = $phone['priority'] ?? 0;
|
|
|
|
$priority = max(((int) $priority), 0);
|
2023-02-04 01:15:36 +01:00
|
|
|
$adapter = $phone['adapter'] ?? false;
|
|
|
|
$adapter_data = !empty($phone['adapter_data']) ? $phone['adapter_data'] : [];
|
|
|
|
$limits = $phone['limits'] ?? [];
|
|
|
|
$limits = is_array($limits) ? $limits : [$limits];
|
|
|
|
|
|
|
|
if (!$name || !$adapter)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
$phone_with_same_name = $this->internal_phone->get_by_name_and_user($id_user, $name);
|
|
|
|
if ($phone_with_same_name && $phone_with_same_name['id'] != $id_phone)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($limits)
|
|
|
|
{
|
|
|
|
foreach ($limits as $key => $limit)
|
|
|
|
{
|
|
|
|
if (!is_array($limit))
|
|
|
|
{
|
|
|
|
unset($limits[$key]);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
$startpoint = $limit['startpoint'] ?? false;
|
|
|
|
$volume = $limit['volume'] ?? false;
|
|
|
|
|
|
|
|
if (!$startpoint || !$volume)
|
|
|
|
{
|
|
|
|
unset($limits[$key]);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
$volume = (int) $volume;
|
|
|
|
$limits[$key]['volume'] = max($volume, 1);
|
|
|
|
|
|
|
|
if (!\controllers\internals\Tool::validate_relative_date($startpoint))
|
|
|
|
{
|
|
|
|
unset($limits[$key]);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$adapters = $this->internal_adapter->list_adapters();
|
|
|
|
$find_adapter = false;
|
|
|
|
foreach ($adapters as $metas)
|
|
|
|
{
|
|
|
|
if ($metas['meta_classname'] === $adapter)
|
|
|
|
{
|
|
|
|
$find_adapter = $metas;
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$find_adapter)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($find_adapter['meta_hidden'])
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
//If missing required data fields, error
|
|
|
|
foreach ($find_adapter['meta_data_fields'] as $field)
|
|
|
|
{
|
|
|
|
if (false === $field['required'])
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!empty($adapter_data[$field['name']]))
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
continue 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
//If field phone number is invalid
|
|
|
|
foreach ($find_adapter['meta_data_fields'] as $field)
|
|
|
|
{
|
|
|
|
if ('phone_number' !== ($field['type'] ?? false))
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!empty($adapter_data[$field['name']]))
|
|
|
|
{
|
|
|
|
$adapter_data[$field['name']] = \controllers\internals\Tool::parse_phone($adapter_data[$field['name']]);
|
|
|
|
|
|
|
|
if ($adapter_data[$field['name']])
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
continue 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
$adapter_data = json_encode($adapter_data);
|
|
|
|
|
|
|
|
//Check adapter is working correctly with thoses names and data
|
|
|
|
$adapter_classname = $find_adapter['meta_classname'];
|
|
|
|
$adapter_instance = new $adapter_classname($adapter_data);
|
|
|
|
$adapter_working = $adapter_instance->test();
|
|
|
|
|
|
|
|
if (!$adapter_working)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2023-02-05 23:11:58 +01:00
|
|
|
$success = $this->internal_phone->update_for_user($id_user, $id_phone, $name, $adapter, $adapter_data, $priority, $limits);
|
2023-02-04 01:15:36 +01:00
|
|
|
if (!$success)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
$nb_update ++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($nb_update !== \count($_POST['phones']))
|
|
|
|
{
|
|
|
|
\FlashMessage\FlashMessage::push('danger', 'Certains téléphones n\'ont pas pu êtres mis à jour.');
|
|
|
|
|
|
|
|
return $this->redirect(\descartes\Router::url('Phone', 'list'));
|
|
|
|
}
|
|
|
|
|
|
|
|
\FlashMessage\FlashMessage::push('success', 'Tous les téléphones ont été modifiés avec succès.');
|
|
|
|
|
|
|
|
return $this->redirect(\descartes\Router::url('Phone', 'list'));
|
|
|
|
}
|
2019-11-12 05:16:59 +01:00
|
|
|
}
|