Add support for mms
This commit is contained in:
parent
88b00e4e9f
commit
fb10b9cdfd
|
@ -28,6 +28,11 @@
|
|||
float: right;
|
||||
}
|
||||
|
||||
.inline-block
|
||||
{
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
/** POPUPS ALERT **/
|
||||
.popup-alerts-container
|
||||
{
|
||||
|
|
|
@ -0,0 +1,133 @@
|
|||
<?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\internals;
|
||||
|
||||
class Media extends StandardController
|
||||
{
|
||||
protected $model = null;
|
||||
|
||||
/**
|
||||
* Get the model for the Controller
|
||||
* @return \descartes\Model
|
||||
*/
|
||||
protected function get_model () : \descartes\Model
|
||||
{
|
||||
$this->model = $this->model ?? new \models\Media($this->bdd);
|
||||
return $this->model;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a media
|
||||
* @param int $id_user : Id of the user
|
||||
* @param int $id_scheduled : Id of the scheduled
|
||||
* @param array $media : $_FILES media array
|
||||
* @return bool : false on error, new media id else
|
||||
*/
|
||||
public function create (int $id_user, int $id_scheduled, array $media) : bool
|
||||
{
|
||||
$internal_scheduled = new Scheduled($this->bdd);
|
||||
$scheduled = $internal_scheduled->get_for_user($id_user, $id_scheduled);
|
||||
if (!$scheduled)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
$result_upload_media = \controllers\internals\Tool::upload_file($media);
|
||||
if ($result_upload_media['success'] == false)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
$datas = [
|
||||
'id_scheduled' => $id_scheduled,
|
||||
'path' => $result_upload_media['content'],
|
||||
];
|
||||
|
||||
return (bool) $this->get_model()->insert($datas);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Update a media for a user
|
||||
* @param int $id_user : user id
|
||||
* @param int $id_media : Media id
|
||||
* @param int $id_scheduled : Id of the scheduled
|
||||
* @param string $path : Path of the file
|
||||
* @return bool : false on error, true on success
|
||||
*/
|
||||
public function update_for_user (int $id_user, int $id_media, int $id_scheduled, string $path) : bool
|
||||
{
|
||||
$media = [
|
||||
'id_scheduled' => $id_scheduled,
|
||||
'path' => $path,
|
||||
];
|
||||
|
||||
$internal_scheduled = new Scheduled($this->bdd);
|
||||
$scheduled = $this->get_for_user($id_user, $id_scheduled);
|
||||
if (!$scheduled)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return (bool) $this->get_model()->update_for_user($id_user, $id_media, $media);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Delete a media for a user
|
||||
* @param int $id_user : User id
|
||||
* @param int $id : Entry id
|
||||
* @return int : Number of removed rows
|
||||
*/
|
||||
public function delete_for_user (int $id_user, int $id_media) : bool
|
||||
{
|
||||
$media = $this->get_model()->get_for_user($id_user, $id_media);
|
||||
if (!$media)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
unlink($media['path']);
|
||||
|
||||
return $this->get_model()->delete_for_user($id_user, $id);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Delete a media for a scheduled and a user
|
||||
* @param int $id_user : User id
|
||||
* @param int $id_scheduled : Scheduled id to delete medias for
|
||||
* @return int : Number of removed rows
|
||||
*/
|
||||
public function delete_for_scheduled_and_user (int $id_user, int $id_scheduled) : bool
|
||||
{
|
||||
$media = $this->get_model()->get_for_scheduled_and_user($id_user, $id_scheduled);
|
||||
if ($media)
|
||||
{
|
||||
unlink($media['path']);
|
||||
}
|
||||
|
||||
return $this->get_model()->delete_for_scheduled_and_user($id_user, $id_scheduled);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Find medias for a scheduled and a user
|
||||
* @param int $id_user : User id
|
||||
* @param int $id_scheduled : Scheduled id to delete medias for
|
||||
* @return mixed : Medias || false
|
||||
*/
|
||||
public function get_for_scheduled_and_user (int $id_user, int $id_scheduled)
|
||||
{
|
||||
return $this->get_model()->get_for_scheduled_and_user($id_user, $id_scheduled);
|
||||
}
|
||||
}
|
|
@ -288,4 +288,89 @@ namespace controllers\internals;
|
|||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Allow to upload file
|
||||
* @param array $file : The array extracted from $_FILES['file']
|
||||
* @return array : ['success' => bool, 'content' => file path | error message, 'error_code' => $file['error']]
|
||||
*/
|
||||
public static function upload_file(array $file)
|
||||
{
|
||||
$result = [
|
||||
'success' => false,
|
||||
'content' => 'Une erreur inconnue est survenue.',
|
||||
'error_code' => $file['error'] ?? 99,
|
||||
];
|
||||
|
||||
if ($file['error'] !== UPLOAD_ERR_OK)
|
||||
{
|
||||
switch ($file['error'])
|
||||
{
|
||||
case UPLOAD_ERR_INI_SIZE :
|
||||
$result['content'] = 'Impossible de télécharger le fichier car il dépasse les ' . ini_get('upload_max_filesize') / (1000 * 1000) . ' Mégaoctets.';
|
||||
break;
|
||||
|
||||
case UPLOAD_ERR_FORM_SIZE :
|
||||
$result['content'] = 'Le fichier dépasse la limite de taille.';
|
||||
break;
|
||||
|
||||
case UPLOAD_ERR_PARTIAL :
|
||||
$result['content'] = 'L\'envoi du fichier a été interrompu.';
|
||||
break;
|
||||
|
||||
case UPLOAD_ERR_NO_FILE :
|
||||
$result['content'] = 'Aucun fichier n\'a été envoyé.';
|
||||
break;
|
||||
|
||||
case UPLOAD_ERR_NO_TMP_DIR :
|
||||
$result['content'] = 'Le serveur ne dispose pas de fichier temporaire permettant l\'envoi de fichiers.';
|
||||
break;
|
||||
|
||||
case UPLOAD_ERR_CANT_WRITE :
|
||||
$result['content'] = 'Impossible d\'envoyer le fichier car il n\'y a plus de place sur le serveur.';
|
||||
break;
|
||||
|
||||
case UPLOAD_ERR_EXTENSION :
|
||||
$result['content'] = 'Le serveur a interrompu l\'envoi du fichier.';
|
||||
break;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
$tmp_filename = $file['tmp_name'] ?? false;
|
||||
if (!$tmp_filename || !is_readable($tmp_filename))
|
||||
{
|
||||
return $result;
|
||||
}
|
||||
|
||||
$md5_filename = md5_file($tmp_filename);
|
||||
if (!$md5_filename)
|
||||
{
|
||||
return $result;
|
||||
}
|
||||
|
||||
$new_file_path = PWD_DATAS . '/' . $md5_filename;
|
||||
|
||||
if (file_exists($new_file_path))
|
||||
{
|
||||
$result['success'] = true;
|
||||
$result['content'] = $new_file_path;
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
$success = move_uploaded_file($tmp_filename, $new_file_path);
|
||||
if (!$success)
|
||||
{
|
||||
$result['content'] = 'Impossible d\'écrire le fichier sur le serveur.';
|
||||
return $result;
|
||||
}
|
||||
|
||||
$result['success'] = true;
|
||||
$result['content'] = $new_file_path;
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,71 @@
|
|||
<?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\internals;
|
||||
|
||||
class Webhook extends StandardController
|
||||
{
|
||||
protected $model = null;
|
||||
|
||||
/**
|
||||
* Get the model for the Controller
|
||||
* @return \descartes\Model
|
||||
*/
|
||||
protected function get_model () : \descartes\Model
|
||||
{
|
||||
$this->model = $this->model ?? new \models\Webhook($this->bdd);
|
||||
return $this->model;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a new webhook
|
||||
* @param int $id_user : User id
|
||||
* @param string $url : Webhook url
|
||||
* @param string $type : Webhook type
|
||||
* @return mixed bool|int : False if cannot create webhook, id of the new webhook else
|
||||
*/
|
||||
public function create(int $id_user, string $url, string $type)
|
||||
{
|
||||
$webhook = [
|
||||
'id_user' => $id_user,
|
||||
'url' => $url,
|
||||
'type' => $type,
|
||||
];
|
||||
|
||||
$result = $this->get_model()->insert($webhook);
|
||||
if (!$result)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Update a webhook
|
||||
* @param int $id_user : User id
|
||||
* @param int $id : Webhook id
|
||||
* @param string $url : Webhook url
|
||||
* @param string $type : Webhook type
|
||||
* @return mixed bool|int : False if cannot create webhook, id of the new webhook else
|
||||
*/
|
||||
public function update_for_user(int $id_user, int $id, string $url, string $type)
|
||||
{
|
||||
$datas = [
|
||||
'url' => $url,
|
||||
'type' => $type,
|
||||
];
|
||||
|
||||
return $this->get_model()->update_for_user($id_user, $id, $datas);
|
||||
}
|
||||
}
|
|
@ -21,6 +21,7 @@ namespace controllers\publics;
|
|||
private $internal_contact;
|
||||
private $internal_group;
|
||||
private $internal_conditional_group;
|
||||
private $internal_media;
|
||||
|
||||
/**
|
||||
* Cette fonction est appelée avant toute les autres :
|
||||
|
@ -36,6 +37,7 @@ namespace controllers\publics;
|
|||
$this->internal_contact = new \controllers\internals\Contact($bdd);
|
||||
$this->internal_group = new \controllers\internals\Group($bdd);
|
||||
$this->internal_conditional_group = new \controllers\internals\ConditionalGroup($bdd);
|
||||
$this->internal_media = new \controllers\internals\Media($bdd);
|
||||
|
||||
\controllers\internals\Tool::verifyconnect();
|
||||
}
|
||||
|
@ -155,6 +157,8 @@ namespace controllers\publics;
|
|||
return $this->redirect(\descartes\Router::url('Scheduled', 'list'));
|
||||
}
|
||||
|
||||
$id_user = $_SESSION['user']['id'];
|
||||
|
||||
$all_contacts = $this->internal_contact->gets_for_user($_SESSION['user']['id']);
|
||||
$phones = $this->internal_phone->gets_for_user($_SESSION['user']['id']);
|
||||
$scheduleds = $this->internal_scheduled->gets_in_for_user($_SESSION['user']['id'], $ids);
|
||||
|
@ -190,6 +194,9 @@ namespace controllers\publics;
|
|||
$scheduleds[$key]['groups'][] = (int) $group['id'];
|
||||
}
|
||||
|
||||
$media = $this->internal_media->get_for_scheduled_and_user($id_user, $scheduled['id']);
|
||||
$scheduleds[$key]['media'] = $media;
|
||||
|
||||
$conditional_groups = $this->internal_scheduled->get_conditional_groups($scheduled['id']);
|
||||
foreach ($conditional_groups as $conditional_group)
|
||||
{
|
||||
|
@ -213,6 +220,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
|
||||
*/
|
||||
public function create($csrf)
|
||||
{
|
||||
|
@ -282,13 +290,28 @@ namespace controllers\publics;
|
|||
return $this->redirect(\descartes\Router::url('Scheduled', 'add'));
|
||||
}
|
||||
|
||||
\FlashMessage\FlashMessage::push('success', 'Le Sms a bien été créé pour le '.$at.'.');
|
||||
|
||||
//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'));
|
||||
}
|
||||
|
||||
$success = $this->internal_media->create($id_user, $scheduled_id, $media);
|
||||
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'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Cette fonction met à jour une schedulede.
|
||||
* Cette fonction met à jour un scheduled.
|
||||
*
|
||||
* @param $csrf : Le jeton CSRF
|
||||
* @param array $_POST['scheduleds'] : Un tableau des scheduledes avec leur nouvelle valeurs + les numbers, contacts et groups liées
|
||||
|
@ -306,8 +329,8 @@ namespace controllers\publics;
|
|||
|
||||
$scheduleds = $_POST['scheduleds'] ?? [];
|
||||
|
||||
$all_update_ok = true;
|
||||
|
||||
$nb_update = 0;
|
||||
foreach ($scheduleds as $id_scheduled => $scheduled)
|
||||
{
|
||||
$id_user = $_SESSION['user']['id'];
|
||||
|
@ -323,22 +346,17 @@ namespace controllers\publics;
|
|||
$scheduled = $this->internal_scheduled->get($id_scheduled);
|
||||
if (!$scheduled || $scheduled['id_user'] !== $id_user)
|
||||
{
|
||||
$all_update_ok = false;
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
if (empty($text))
|
||||
{
|
||||
$all_update_ok = false;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!\controllers\internals\Tool::validate_date($at, 'Y-m-d H:i:s') && !\controllers\internals\Tool::validate_date($at, 'Y-m-d H:i'))
|
||||
{
|
||||
$all_update_ok = false;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -357,30 +375,43 @@ namespace controllers\publics;
|
|||
|
||||
if (!$numbers && !$contacts && !$groups && !$conditional_groups)
|
||||
{
|
||||
$all_update_ok = false;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
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'));
|
||||
continue;
|
||||
}
|
||||
|
||||
$success = $this->internal_scheduled->update_for_user($id_user, $id_scheduled, $at, $text, $origin, $flash, $numbers, $contacts, $groups, $conditional_groups);
|
||||
if (!$success)
|
||||
{
|
||||
$all_update_ok = false;
|
||||
|
||||
//Check for media
|
||||
$current_media = $scheduled['current_media'] ?? false;
|
||||
if (!$current_media)
|
||||
{
|
||||
$this->internal_media->delete_for_scheduled_and_user($id_user, $id_scheduled);
|
||||
}
|
||||
|
||||
$media = $_FILES['media_' . $id_scheduled] ?? false;
|
||||
if (!$media)
|
||||
{
|
||||
$nb_update += (int) $success;
|
||||
continue;
|
||||
}
|
||||
|
||||
$success = $this->internal_media->create($id_user, $id_scheduled, $media);
|
||||
if (!$success)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$nb_update += 1;
|
||||
}
|
||||
|
||||
if (!$all_update_ok)
|
||||
if (!$nb_update != count($scheduleds))
|
||||
{
|
||||
\FlashMessage\FlashMessage::push('danger', 'Certains SMS n\'ont pas pu êtres mis à jour.');
|
||||
\FlashMessage\FlashMessage::push('danger', 'Certains SMS n\'ont pas été mis à jour.');
|
||||
return $this->redirect(\descartes\Router::url('Scheduled', 'list'));
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,178 @@
|
|||
<?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 webhooks.
|
||||
*/
|
||||
class Webhook extends \descartes\Controller
|
||||
{
|
||||
private $internal_webhook;
|
||||
private $internal_event;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$bdd = \descartes\Model::_connect(DATABASE_HOST, DATABASE_NAME, DATABASE_USER, DATABASE_PASSWORD);
|
||||
|
||||
$this->internal_webhook = new \controllers\internals\Webhook($bdd);
|
||||
$this->internal_event = new \controllers\internals\Event($bdd);
|
||||
|
||||
\controllers\internals\Tool::verifyconnect();
|
||||
}
|
||||
|
||||
/**
|
||||
* List all webhooks
|
||||
*
|
||||
* @param mixed $page
|
||||
*/
|
||||
public function list($page = 0)
|
||||
{
|
||||
$page = (int) $page;
|
||||
$webhooks = $this->internal_webhook->list_for_user($_SESSION['user']['id'], 25, $page);
|
||||
$this->render('webhook/list', ['webhooks' => $webhooks]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a list of webhooks
|
||||
*
|
||||
* @param array int $_GET['ids'] : Les id des webhooks à supprimer
|
||||
* @param mixed $csrf
|
||||
*
|
||||
* @return boolean;
|
||||
*/
|
||||
public function delete($csrf)
|
||||
{
|
||||
if (!$this->verify_csrf($csrf))
|
||||
{
|
||||
\FlashMessage\FlashMessage::push('danger', 'Jeton CSRF invalid !');
|
||||
$this->redirect(\descartes\Router::url('Webhook', 'list'));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
$ids = $_GET['ids'] ?? [];
|
||||
foreach ($ids as $id)
|
||||
{
|
||||
$this->internal_webhook->delete_for_user($_SESSION['user']['id'], $id);
|
||||
}
|
||||
|
||||
return $this->redirect(\descartes\Router::url('Webhook', 'list'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Cette fonction retourne la page d'ajout d'une webhook.
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
$this->render('webhook/add');
|
||||
}
|
||||
|
||||
/**
|
||||
* Edit a list of webhooks
|
||||
*
|
||||
* @param array int $_GET['ids'] : ids of webhooks to edit
|
||||
*/
|
||||
public function edit()
|
||||
{
|
||||
$ids = $_GET['ids'] ?? [];
|
||||
|
||||
$webhooks = $this->internal_webhook->gets_in_for_user($_SESSION['user']['id'], $ids);
|
||||
|
||||
$this->render('webhook/edit', [
|
||||
'webhooks' => $webhooks,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert a new webhook
|
||||
*
|
||||
* @param $csrf : Le jeton CSRF
|
||||
* @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;
|
||||
*/
|
||||
public function create($csrf)
|
||||
{
|
||||
if (!$this->verify_csrf($csrf))
|
||||
{
|
||||
\FlashMessage\FlashMessage::push('danger', 'Jeton CSRF invalid !');
|
||||
|
||||
return $this->redirect(\descartes\Router::url('Webhook', 'list'));
|
||||
}
|
||||
|
||||
$url = $_POST['url'] ?? false;
|
||||
$type = $_POST['type'] ?? false;
|
||||
|
||||
if (!$url || !$type)
|
||||
{
|
||||
\FlashMessage\FlashMessage::push('danger', 'Renseignez au moins une URL et un type de webhook.');
|
||||
|
||||
return $this->redirect(\descartes\Router::url('Webhook', 'list'));
|
||||
}
|
||||
|
||||
if (!$this->internal_webhook->create($_SESSION['user']['id'], $url, $type))
|
||||
{
|
||||
\FlashMessage\FlashMessage::push('danger', 'Impossible de créer ce webhook.');
|
||||
|
||||
return $this->redirect(\descartes\Router::url('webhooks', 'add'));
|
||||
}
|
||||
|
||||
\FlashMessage\FlashMessage::push('success', 'La webhook a bien été créé.');
|
||||
|
||||
return $this->redirect(\descartes\Router::url('Webhook', 'list'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Cette fonction met à jour une webhook.
|
||||
*
|
||||
* @param $csrf : Le jeton CSRF
|
||||
* @param array $_POST['webhooks'] : Un tableau des webhooks avec leur nouvelle valeurs
|
||||
*
|
||||
* @return boolean;
|
||||
*/
|
||||
public function update($csrf)
|
||||
{
|
||||
if (!$this->verify_csrf($csrf))
|
||||
{
|
||||
\FlashMessage\FlashMessage::push('danger', 'Jeton CSRF invalid !');
|
||||
|
||||
return $this->redirect(\descartes\Router::url('Webhook', 'list'));
|
||||
}
|
||||
|
||||
$nb_update = 0;
|
||||
foreach ($_POST['webhooks'] as $webhook)
|
||||
{
|
||||
$url = $webhook['url'] ?? false;
|
||||
$type = $webhook['type'] ?? false;
|
||||
|
||||
if (!$url || !$type)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$success = $this->internal_webhook->update_for_user($_SESSION['user']['id'], $webhook['id'], $url, $type);
|
||||
$nb_update += (int) $success;
|
||||
}
|
||||
|
||||
if ($nb_update !== \count($_POST['webhooks']))
|
||||
{
|
||||
\FlashMessage\FlashMessage::push('info', 'Certains webhooks n\'ont pas pu êtres mis à jour.');
|
||||
|
||||
return $this->redirect(\descartes\Router::url('Webhook', 'list'));
|
||||
}
|
||||
|
||||
\FlashMessage\FlashMessage::push('success', 'Tous les webhooks ont été modifiés avec succès.');
|
||||
|
||||
return $this->redirect(\descartes\Router::url('Webhook', 'list'));
|
||||
}
|
||||
}
|
|
@ -37,6 +37,16 @@ CREATE TABLE IF NOT EXISTS scheduled
|
|||
PRIMARY KEY (id)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS media
|
||||
(
|
||||
id INT NOT NULL AUTO_INCREMENT,
|
||||
id_scheduled INT NOT NULL,
|
||||
path VARCHAR(1000) NOT NULL,
|
||||
PRIMARY KEY (id),
|
||||
FOREIGN KEY (id_scheduled) REFERENCES scheduled (id) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
UNIQUE (id_scheduled)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS received
|
||||
(
|
||||
id INT NOT NULL AUTO_INCREMENT,
|
||||
|
@ -206,7 +216,7 @@ CREATE TABLE IF NOT EXISTS webhook
|
|||
id INT NOT NULL AUTO_INCREMENT,
|
||||
id_user INT NOT NULL,
|
||||
url VARCHAR(250) NOT NULL,
|
||||
type INT NOT NULL,
|
||||
type ENUM('send_sms', 'receive_sms') NOT NULL,
|
||||
FOREIGN KEY (id_user) REFERENCES user (id) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
PRIMARY KEY (id)
|
||||
);
|
||||
|
|
|
@ -0,0 +1,238 @@
|
|||
<?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 models;
|
||||
|
||||
/**
|
||||
* Cette classe gère les accès bdd pour les mediaes.
|
||||
*/
|
||||
class Media extends StandardModel
|
||||
{
|
||||
/**
|
||||
* Return table name
|
||||
* @return string
|
||||
*/
|
||||
protected function get_table_name() : string { return 'media'; }
|
||||
|
||||
|
||||
/**
|
||||
* Return an entry by his id for a user
|
||||
* @param int $id_user : user id
|
||||
* @param int $id : entry id
|
||||
* @return array
|
||||
*/
|
||||
public function get_for_user(int $id_user, int $id)
|
||||
{
|
||||
$query = '
|
||||
SELECT * FROM `' . $this->get_table_name() . '`
|
||||
WHERE id_scheduled IN (SELECT id FROM scheduled WHERE id_user = :id_user)
|
||||
AND id = :id
|
||||
';
|
||||
|
||||
$params = [
|
||||
'id' => $id,
|
||||
'id_user' => $id_user,
|
||||
];
|
||||
|
||||
$receiveds = $this->_run_query($query, $params);
|
||||
return $receiveds[0] ?? [];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return all entries for a user
|
||||
* @param int $id_user : user id
|
||||
* @return array
|
||||
*/
|
||||
public function gets_for_user(int $id_user)
|
||||
{
|
||||
$query = '
|
||||
SELECT * FROM `' . $this->get_table_name() . '`
|
||||
WHERE id_scheduled IN (SELECT id FROM scheduled WHERE id_user = :id_user)
|
||||
';
|
||||
|
||||
$params = [
|
||||
'id_user' => $id_user,
|
||||
];
|
||||
|
||||
$receiveds = $this->_run_query($query, $params);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return a media for a user and a scheduled
|
||||
* @param int $id_user : user id
|
||||
* @param int $id_scheduled : scheduled id
|
||||
* @return array
|
||||
*/
|
||||
public function get_for_scheduled_and_user(int $id_user, int $id_scheduled)
|
||||
{
|
||||
$query = '
|
||||
SELECT * FROM `' . $this->get_table_name() . '`
|
||||
WHERE id_scheduled IN (SELECT id FROM scheduled WHERE id_user = :id_user)
|
||||
AND id_scheduled = :id_scheduled
|
||||
';
|
||||
|
||||
$params = [
|
||||
'id_user' => $id_user,
|
||||
'id_scheduled' => $id_scheduled
|
||||
];
|
||||
|
||||
$receiveds = $this->_run_query($query, $params);
|
||||
if (!$receiveds)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return $receiveds[0];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return a list of media for a user
|
||||
* @param int $id_user : User id
|
||||
* @param int $limit : Max results to return
|
||||
* @param int $offset : Number of results to ignore
|
||||
*/
|
||||
public function list_for_user($id_user, $limit, $offset)
|
||||
{
|
||||
$limit = (int) $limit;
|
||||
$offset = (int) $offset;
|
||||
|
||||
$query = '
|
||||
SELECT * FROM media
|
||||
WHERE id_scheduled IN (SELECT id FROM scheduled WHERE id_user = :id_user)
|
||||
LIMIT ' . $limit . ' OFFSET ' . $offset;
|
||||
|
||||
$params = [
|
||||
'id_user' => $id_user,
|
||||
];
|
||||
|
||||
return $this->_run_query($query, $params);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return a list of medias in a group of ids and for a user
|
||||
* @param int $id_user : user id
|
||||
* @param array $ids : ids of medias to find
|
||||
* @return array
|
||||
*/
|
||||
public function gets_in_for_user(int $id_user, $ids)
|
||||
{
|
||||
$query = '
|
||||
SELECT * FROM media
|
||||
WHERE id_scheduled IN (SELECT id FROM scheduled WHERE id_user = :id_user)
|
||||
AND id ';
|
||||
|
||||
//On génère la clause IN et les paramètres adaptés depuis le tableau des id
|
||||
$generated_in = $this->_generate_in_from_array($ids);
|
||||
$query .= $generated_in['QUERY'];
|
||||
$params = $generated_in['PARAMS'];
|
||||
$params['id_user'] = $id_user;
|
||||
|
||||
return $this->_run_query($query, $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a entry by his id for a user
|
||||
* @param int $id_user : User id
|
||||
* @param int $id : Entry id
|
||||
* @return int : Number of removed rows
|
||||
*/
|
||||
public function delete_for_user(int $id_user, int $id)
|
||||
{
|
||||
$query = '
|
||||
DELETE FROM media
|
||||
WHERE id = :id
|
||||
AND id_scheduled IN (SELECT id FROM scheduled WHERE id_user = :id_user)
|
||||
';
|
||||
|
||||
$params = ['id_user' => $id_user, 'id' => $id];
|
||||
|
||||
return $this->_run_query($query, $params, self::ROWCOUNT);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Delete a entry by his id for a user
|
||||
* @param int $id_user : User id
|
||||
* @param int $id_scheduled : Scheduled id
|
||||
* @return int : Number of removed rows
|
||||
*/
|
||||
public function delete_for_scheduled_and_user(int $id_user, int $id_scheduled)
|
||||
{
|
||||
$query = '
|
||||
DELETE FROM media
|
||||
WHERE id_scheduled = :id_scheduled
|
||||
AND id_scheduled IN (SELECT id FROM scheduled WHERE id_user = :id_user)
|
||||
';
|
||||
|
||||
$params = ['id_user' => $id_user, 'id_scheduled' => $id_scheduled];
|
||||
|
||||
return $this->_run_query($query, $params, self::ROWCOUNT);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Update a media sms for a user
|
||||
* @param int $id_user : User id
|
||||
* @param int $id : Entry id
|
||||
* @param array $datas : datas to update
|
||||
*
|
||||
* @return int : number of modified rows
|
||||
*/
|
||||
public function update_for_user (int $id_user, int $id, array $datas)
|
||||
{
|
||||
$params = [];
|
||||
$sets = [];
|
||||
|
||||
foreach ($datas as $label => $value)
|
||||
{
|
||||
$label = preg_replace('#[^a-zA-Z0-9_]#', '', $label);
|
||||
$params['set_' . $label] = $value;
|
||||
$sets[] = '`' . $label . '` = :set_' . $label . ' ';
|
||||
}
|
||||
|
||||
$query = '
|
||||
UPDATE `media`
|
||||
SET ' . implode(', ', $sets) . '
|
||||
WHERE id = :id
|
||||
AND id_scheduled IN (SELECT id FROM scheduled WHERE id_user = :id_user)
|
||||
';
|
||||
|
||||
$params['id'] = $id;
|
||||
$params['id_user'] = $id_user;
|
||||
|
||||
return $this->_run_query($query, $params, self::ROWCOUNT);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Count number of media sms for user
|
||||
* @param int $id_user : user id
|
||||
* @return int : Number of media SMS for user
|
||||
*/
|
||||
public function count_for_user($id_user)
|
||||
{
|
||||
$query = '
|
||||
SELECT COUNT(id) as nb
|
||||
FROM media
|
||||
WHERE id_scheduled IN (SELECT id FROM scheduled WHERE id_user = :id_user)
|
||||
';
|
||||
|
||||
$params = [
|
||||
'id_user' => $id_user,
|
||||
];
|
||||
|
||||
return $this->_run_query($query, $params)[0]['nb'] ?? 0;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
<?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 models;
|
||||
|
||||
class Webhook extends StandardModel
|
||||
{
|
||||
/**
|
||||
* Return table name
|
||||
* @return string
|
||||
*/
|
||||
protected function get_table_name() : string { return 'webhook'; }
|
||||
}
|
12
routes.php
12
routes.php
|
@ -166,6 +166,18 @@
|
|||
'create' => '/phone/create/{csrf}/',
|
||||
'delete' => '/phone/delete/{csrf}/',
|
||||
],
|
||||
|
||||
'Webhook' => [
|
||||
'list' => [
|
||||
'/webhook/',
|
||||
'/webhook/p/{page}/',
|
||||
],
|
||||
'add' => '/webhook/add/',
|
||||
'create' => '/webhook/create/{csrf}/',
|
||||
'delete' => '/webhook/delete/{csrf}/',
|
||||
'edit' => '/webhook/edit/',
|
||||
'update' => '/webhook/update/{csrf}/',
|
||||
],
|
||||
);
|
||||
|
||||
define('ROUTES', $routes);
|
||||
|
|
|
@ -83,21 +83,5 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
jQuery(document).ready(function ()
|
||||
{
|
||||
jQuery('.action-dropdown a').on('click', function (e)
|
||||
{
|
||||
e.preventDefault();
|
||||
var destination = jQuery(this).parents('.action-dropdown').attr('destination');
|
||||
var url = jQuery(this).attr('href');
|
||||
jQuery(destination).find('input:checked').each(function ()
|
||||
{
|
||||
url += '/' + jQuery(this).val();
|
||||
});
|
||||
window.location = url;
|
||||
});
|
||||
});
|
||||
</script>
|
||||
<?php
|
||||
$this->render('incs/footer');
|
||||
|
|
|
@ -83,7 +83,10 @@
|
|||
hiddenInput: '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); ?>,
|
||||
nationalMode: true,
|
||||
nationalMode: true,
|
||||
<?php if ($_SESSION['user']['settings']['authorized_phone_country'] ?? false) { ?>
|
||||
onlyCountries: <?php $this->s(json_encode(explode(',', $_SESSION['user']['settings']['authorized_phone_country'])), false, false); ?>,
|
||||
<?php } ?>
|
||||
utilsScript: '<?php echo HTTP_PWD_JS; ?>/intlTelInput/utils.js'
|
||||
});
|
||||
|
||||
|
|
|
@ -107,6 +107,9 @@
|
|||
hiddenInput: hidden_input_name,
|
||||
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) { ?>
|
||||
onlyCountries: <?php $this->s(json_encode(explode(',', $_SESSION['user']['settings']['authorized_phone_country'])), false, false); ?>,
|
||||
<?php } ?>
|
||||
nationalMode: true,
|
||||
utilsScript: '<?php echo HTTP_PWD_JS; ?>/intlTelInput/utils.js'
|
||||
});
|
||||
|
|
|
@ -82,7 +82,12 @@
|
|||
</li>
|
||||
<li <?php echo $page == 'commands' ? 'class="active"' : ''; ?>>
|
||||
<a href="<?php echo \descartes\Router::url('Command', 'list'); ?>"><i class="fa fa-fw fa-terminal"></i> Commandes</a>
|
||||
</li>
|
||||
</li>
|
||||
<?php if ($_SESSION['user']['settings']['webhook'] ?? false) { ?>
|
||||
<li <?php echo $page == 'webhooks' ? 'class="active"' : ''; ?>>
|
||||
<a href="<?php echo \descartes\Router::url('Webhook', 'list'); ?>"><i class="fa fa-fw fa-plug"></i> Webhooks</a>
|
||||
</li>
|
||||
<?php } ?>
|
||||
<li <?php echo $page == 'phones' ? 'class="active"' : ''; ?>>
|
||||
<a href="<?php echo \descartes\Router::url('Phone', 'list'); ?>"><i class="fa fa-fw fa-phone"></i> Téléphones</a>
|
||||
</li>
|
||||
|
|
|
@ -37,7 +37,7 @@
|
|||
<h3 class="panel-title"><i class="fa fa-calendar fa-fw"></i> Ajout d'un SMS programmé</h3>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<form action="<?php echo \descartes\Router::url('Scheduled', 'create', ['csrf' => $_SESSION['csrf']]);?>" method="POST">
|
||||
<form action="<?php echo \descartes\Router::url('Scheduled', 'create', ['csrf' => $_SESSION['csrf']]);?>" method="POST" enctype="multipart/form-data">
|
||||
<div class="form-group">
|
||||
<label>Texte du SMS</label>
|
||||
<?php if ($_SESSION['user']['settings']['templating']) { ?>
|
||||
|
@ -59,6 +59,16 @@
|
|||
</div>
|
||||
<?php } ?>
|
||||
</div>
|
||||
|
||||
<?php if ($_SESSION['user']['settings']['mms'] ?? false) { ?>
|
||||
<div class="form-group">
|
||||
<label>Ajouter un média</label>
|
||||
<p class="italic small help description-scheduled-media">
|
||||
Le média sera utilisé uniquement si le téléphone utilisé supporte l'envoi de MMS. Pour plus d'information, consultez la documentation sur <a href="#">l'utilisation des MMS.</a>
|
||||
</p>
|
||||
<input class="" name="media" value="" type="file" />
|
||||
</div>
|
||||
<?php } ?>
|
||||
<div class="form-group">
|
||||
<label>Date d'envoi du SMS</label>
|
||||
<input name="at" class="form-control form-datetime" type="text" value="<?php $this->s($now); ?>" readonly>
|
||||
|
@ -195,6 +205,9 @@
|
|||
hiddenInput: 'numbers[]',
|
||||
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) { ?>
|
||||
onlyCountries: <?php $this->s(json_encode(explode(',', $_SESSION['user']['settings']['authorized_phone_country'])), false, false); ?>,
|
||||
<?php } ?>
|
||||
nationalMode: true,
|
||||
utilsScript: '<?php echo HTTP_PWD_JS; ?>/intlTelInput/utils.js'
|
||||
});
|
||||
|
@ -210,6 +223,9 @@
|
|||
hiddenInput: 'numbers[]',
|
||||
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) { ?>
|
||||
onlyCountries: <?php $this->s(json_encode(explode(',', $_SESSION['user']['settings']['authorized_phone_country'])), false, false); ?>,
|
||||
<?php } ?>
|
||||
nationalMode: true,
|
||||
utilsScript: '<?php echo HTTP_PWD_JS; ?>/intlTelInput/utils.js'
|
||||
});
|
||||
|
|
|
@ -37,7 +37,7 @@
|
|||
<h3 class="panel-title"><i class="fa fa-edit fa-fw"></i> Modification des SMS programmés</h3>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<form action="<?php echo \descartes\Router::url('Scheduled', 'update', ['csrf' => $_SESSION['csrf']]);?>" method="POST">
|
||||
<form action="<?php echo \descartes\Router::url('Scheduled', 'update', ['csrf' => $_SESSION['csrf']]);?>" method="POST" enctype="multipart/form-data">
|
||||
<?php foreach ($scheduleds as $scheduled) { ?>
|
||||
<div class="form-group">
|
||||
<label>Texte du SMS</label>
|
||||
|
@ -60,6 +60,24 @@
|
|||
</div>
|
||||
<?php } ?>
|
||||
</div>
|
||||
<?php if ($_SESSION['user']['settings']['mms'] ?? false) { ?>
|
||||
<div class="form-group">
|
||||
<label>Ajouter un média</label>
|
||||
<p class="italic small help description-scheduled-media">
|
||||
Le média sera utilisé uniquement si le téléphone utilisé supporte l'envoi de MMS. Pour plus d'information, consultez la documentation sur <a href="#">l'utilisation des MMS.</a>
|
||||
</p>
|
||||
<?php if ($scheduled['media']) { ?>
|
||||
<div class="current-media-container">
|
||||
<input type="hidden" name="scheduleds[<?php $this->s($scheduled['id']); ?>][current_media]" value="1">
|
||||
<p class="inline-block">Un média est déjà lié à ce message.</p>
|
||||
<a href="#" class="btn btn-warning btn-delete-media">Supprimer le média</a>
|
||||
</div>
|
||||
<input class="hidden" name="media_<?php $this->s($scheduled['id']); ?>" type="file" />
|
||||
<?php } else { ?>
|
||||
<input name="media_<?php $this->s($scheduled['id']); ?>" type="file" />
|
||||
<?php } ?>
|
||||
</div>
|
||||
<?php } ?>
|
||||
<div class="form-group">
|
||||
<label>Date d'envoi du SMS</label>
|
||||
<input name="scheduleds[<?php $this->s($scheduled['id']); ?>][at]" class="form-control form-datetime" type="text" value="<?php $this->s($scheduled['at']); ?>" readonly>
|
||||
|
@ -187,6 +205,9 @@
|
|||
hiddenInput: hidden_input_name,
|
||||
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) { ?>
|
||||
onlyCountries: <?php $this->s(json_encode(explode(',', $_SESSION['user']['settings']['authorized_phone_country'])), false, false); ?>,
|
||||
<?php } ?>
|
||||
nationalMode: true,
|
||||
utilsScript: '<?php echo HTTP_PWD_JS; ?>/intlTelInput/utils.js'
|
||||
});
|
||||
|
@ -210,11 +231,21 @@
|
|||
hiddenInput: hidden_input_name,
|
||||
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) { ?>
|
||||
onlyCountries: <?php $this->s(json_encode(explode(',', $_SESSION['user']['settings']['authorized_phone_country'])), false, false); ?>,
|
||||
<?php } ?>
|
||||
nationalMode: true,
|
||||
utilsScript: '<?php echo HTTP_PWD_JS; ?>/intlTelInput/utils.js'
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
jQuery('body').on('click', '.btn-delete-media', function (e)
|
||||
{
|
||||
e.preventDefault();
|
||||
jQuery(this).parents('.form-group').find('input').removeClass('hidden');
|
||||
jQuery(this).parents('.form-group').find('.current-media-container').remove();
|
||||
});
|
||||
|
||||
jQuery('body').on('click', '.preview-button', function (e)
|
||||
{
|
||||
|
|
|
@ -54,6 +54,25 @@
|
|||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">
|
||||
<h4 class="panel-title"><i class="fa fa-picture-o fa-fw"></i> Support des MMS</h4>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<form action="<?php echo \descartes\Router::url('Setting', 'update', ['setting_name' => 'mms', 'csrf' => $_SESSION['csrf']]); ?>" method="POST">
|
||||
<div class="form-group">
|
||||
<label>Activer les MMS : </label>
|
||||
<select name="setting_value" class="form-control">
|
||||
<option value="0">Non</option>
|
||||
<option value="1" <?php echo $_SESSION['user']['settings']['mms'] ? 'selected' : ''; ?>>Oui</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="text-center">
|
||||
<button class="btn btn-success">Mettre à jour les données</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">
|
||||
<h4 class="panel-title"><i class="fa fa-link fa-fw"></i> Détection des URL dans les discussions</h4>
|
||||
|
@ -89,6 +108,22 @@
|
|||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">
|
||||
<h4 class="panel-title"><i class="fa fa-flag fa-fw"></i> Pays autorisés pour l'envoi</h4>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<form action="<?php echo \descartes\Router::url('Setting', 'update', ['setting_name' => 'preferred_phone_country', 'csrf' => $_SESSION['csrf']]); ?>" method="POST">
|
||||
<div class="form-group">
|
||||
<label>Code des pays (norme ISO 3166-1 alpha-2) séparés par des virgules (laissez vide pour tout autoriser) : </label>
|
||||
<input name="setting_value" class="form-control" value="<?php $this->s($_SESSION['user']['settings']['authorized_phone_country']); ?>" />
|
||||
</div>
|
||||
<div class="text-center">
|
||||
<button class="btn btn-success">Mettre à jour les données</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">
|
||||
<h4 class="panel-title"><i class="fa fa-music fa-fw"></i> Son sur reception d'un SMS</h4>
|
||||
|
@ -148,6 +183,25 @@
|
|||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">
|
||||
<h4 class="panel-title"><i class="fa fa-plug fa-fw"></i> Activation de Webhooks</h4>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<form action="<?php echo \descartes\Router::url('Setting', 'update', ['setting_name' => 'webhook', 'csrf' => $_SESSION['csrf']]); ?>" method="POST">
|
||||
<div class="form-group">
|
||||
<label>Webhooks activé : </label>
|
||||
<select name="setting_value" class="form-control">
|
||||
<option value="0">Non</option>
|
||||
<option value="1" <?php echo $_SESSION['user']['settings']['webhook'] ? 'selected' : ''; ?>>Oui</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="text-center">
|
||||
<button class="btn btn-success">Mettre à jour les données</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">
|
||||
<h4 class="panel-title"><i class="fa fa-phone fa-fw"></i> Pays par défaut numéros internationaux</h4>
|
||||
|
|
|
@ -1,11 +1,9 @@
|
|||
<?php
|
||||
//Template dashboard
|
||||
$incs = new internalIncs();
|
||||
$incs->head('Webhook - Add');
|
||||
$this->render('incs/head', ['title' => 'Webhooks - Add'])
|
||||
?>
|
||||
<div id="wrapper">
|
||||
<?php
|
||||
$incs->nav('webhooks');
|
||||
$this->render('incs/nav', ['page' => 'webhooks'])
|
||||
?>
|
||||
<div id="page-wrapper">
|
||||
<div class="container-fluid">
|
||||
|
@ -20,7 +18,7 @@
|
|||
<i class="fa fa-dashboard"></i> <a href="<?php echo \descartes\Router::url('Dashboard', 'show'); ?>">Dashboard</a>
|
||||
</li>
|
||||
<li>
|
||||
<i class="fa fa-plug"></i> <a href="<?php echo \descartes\Router::url('webhooks'); ?>">Webhooks</a>
|
||||
<i class="fa fa-plug"></i> <a href="<?php echo \descartes\Router::url('Webhook', 'list'); ?>">Webhooks</a>
|
||||
</li>
|
||||
<li class="active">
|
||||
<i class="fa fa-plus"></i> Nouveau
|
||||
|
@ -37,7 +35,7 @@
|
|||
<h3 class="panel-title"><i class="fa fa-plug fa-fw"></i> Ajout d'un nouveau webhook</h3>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<form action="<?php echo \descartes\Router::url('webhooks', 'create', [$_SESSION['csrf']]);?>" method="POST">
|
||||
<form action="<?php echo \descartes\Router::url('Webhook', 'create', ['csrf' => $_SESSION['csrf']]);?>" method="POST">
|
||||
<div class="form-group">
|
||||
<label>URL cible</label>
|
||||
<div class="form-group">
|
||||
|
@ -47,12 +45,11 @@
|
|||
<div class="form-group">
|
||||
<label>Type de Webhook</label>
|
||||
<select name="type" class="form-control" required>
|
||||
<?php foreach (internalConstants::WEBHOOK_TYPE as $key => $value) { ?>
|
||||
<option value="<?php $this->s($value); ?>"><?php $this->s($key); ?></option>
|
||||
<?php } ?>
|
||||
<option value="receive_sms">Réception d'un SMS</option>
|
||||
<option value="send_sms">Envoi d'un SMS</option>
|
||||
</select>
|
||||
</div>
|
||||
<a class="btn btn-danger" href="<?php echo \descartes\Router::url('webhooks'); ?>">Annuler</a>
|
||||
<a class="btn btn-danger" href="<?php echo \descartes\Router::url('Webhook', 'list'); ?>">Annuler</a>
|
||||
<input type="submit" class="btn btn-success" value="Enregistrer le webhook" />
|
||||
</form>
|
||||
</div>
|
||||
|
@ -63,4 +60,4 @@
|
|||
</div>
|
||||
</div>
|
||||
<?php
|
||||
$incs->footer();
|
||||
$this->render('incs/footer');
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
<?php
|
||||
//Template dashboard
|
||||
$incs = new internalIncs();
|
||||
$incs->head('Webhook - Edit');
|
||||
$this->render('incs/head', ['title' => 'Webhooks - Edit'])
|
||||
?>
|
||||
<div id="wrapper">
|
||||
<?php
|
||||
$incs->nav('webhooks');
|
||||
$this->render('incs/nav', ['page' => 'webhooks'])
|
||||
?>
|
||||
<div id="page-wrapper">
|
||||
<div class="container-fluid">
|
||||
|
@ -20,7 +19,7 @@
|
|||
<i class="fa fa-dashboard"></i> <a href="<?php echo \descartes\Router::url('Dashboard', 'show'); ?>">Dashboard</a>
|
||||
</li>
|
||||
<li>
|
||||
<i class="fa fa-plug"></i> <a href="<?php echo \descartes\Router::url('webhooks'); ?>">Webhooks</a>
|
||||
<i class="fa fa-plug"></i> <a href="<?php echo \descartes\Router::url('Webhook', 'list'); ?>">Webhooks</a>
|
||||
</li>
|
||||
<li class="active">
|
||||
<i class="fa fa-edit"></i> Modifier
|
||||
|
@ -37,8 +36,9 @@
|
|||
<h3 class="panel-title"><i class="fa fa-edit fa-fw"></i>Modification de webhooks</h3>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<form action="<?php echo \descartes\Router::url('webhooks', 'update', [$_SESSION['csrf']]);?>" method="POST">
|
||||
<form action="<?php echo \descartes\Router::url('Webhook', 'update', ['csrf' => $_SESSION['csrf']]);?>" method="POST">
|
||||
<?php foreach ($webhooks as $webhook) { ?>
|
||||
<input type="hidden" value="<?php $this->s($webhook['id']); ?>" name="webhooks[<?php $this->s($webhook['id']); ?>][id]" />
|
||||
<div class="form-group">
|
||||
<label>URL cible</label>
|
||||
<div class="form-group">
|
||||
|
@ -48,14 +48,13 @@
|
|||
<div class="form-group">
|
||||
<label>Type de Webhook</label>
|
||||
<select name="webhooks[<?php $this->s($webhook['id']); ?>][type]" class="form-control" required>
|
||||
<?php foreach (internalConstants::WEBHOOK_TYPE as $key => $value) { ?>
|
||||
<option <?php echo ($webhook['type'] == $value ? 'selected' : ''); ?> value="<?php $this->s($value); ?>"><?php $this->s($key); ?></option>
|
||||
<?php } ?>
|
||||
<option <?php echo $webhook['type'] == 'receive_sms' ? 'selected="selected"' : '' ?> value="receive_sms">Réception d'un SMS</option>
|
||||
<option <?php echo $webhook['type'] == 'send_sms' ? 'selected="selected"' : '' ?> value="send_sms">Envoi d'un SMS</option>
|
||||
</select>
|
||||
</div>
|
||||
<hr/>
|
||||
<?php } ?>
|
||||
<a class="btn btn-danger" href="<?php echo \descartes\Router::url('webhooks'); ?>">Annuler</a>
|
||||
<a class="btn btn-danger" href="<?php echo \descartes\Router::url('Webhook', 'list'); ?>">Annuler</a>
|
||||
<input type="submit" class="btn btn-success" value="Enregistrer la webhook" />
|
||||
</form>
|
||||
</div>
|
||||
|
@ -66,4 +65,4 @@
|
|||
</div>
|
||||
</div>
|
||||
<?php
|
||||
$incs->footer();
|
||||
$this->render('incs/footer');
|
||||
|
|
|
@ -1,11 +1,9 @@
|
|||
<?php
|
||||
//Template dashboard
|
||||
$incs = new internalIncs();
|
||||
$incs->head('Webhooks - Show All');
|
||||
$this->render('incs/head', ['title' => 'Webhooks - Show All'])
|
||||
?>
|
||||
<div id="wrapper">
|
||||
<?php
|
||||
$incs->nav('webhooks');
|
||||
$this->render('incs/nav', ['page' => 'webhooks'])
|
||||
?>
|
||||
<div id="page-wrapper">
|
||||
<div class="container-fluid">
|
||||
|
@ -33,44 +31,47 @@
|
|||
<div class="panel-heading">
|
||||
<h3 class="panel-title"><i class="fa fa-plug fa-fw"></i> Liste des webhooks</h3>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<div class="table-responsive">
|
||||
<table class="table table-bordered table-hover table-striped" id="table-webhooks">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>#</th>
|
||||
<th>Url</th>
|
||||
<th>Type de Webhook</th>
|
||||
<th style="width:5%;">Sélectionner</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach ($webhooks as $webhook) { ?>
|
||||
<tr>
|
||||
<td><?php $this->s($webhook['id']); ?></td>
|
||||
<td><?php $this->s($webhook['url']); ?></td>
|
||||
<td><?php echo array_search($webhook['type'], internalConstants::WEBHOOK_TYPE); ?></td>
|
||||
<td><input type="checkbox" value="<?php $this->s($webhook['id']); ?>"></td>
|
||||
</tr>
|
||||
<div class="panel-body">
|
||||
<form method="GET">
|
||||
<?php if (!$webhooks) { ?>
|
||||
<p>Aucun webhook n'a été créé pour le moment.</p>
|
||||
<?php } else { ?>
|
||||
<div class="table-responsive">
|
||||
<table class="table table-bordered table-hover table-striped" id="table-webhooks">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>#</th>
|
||||
<th>Url</th>
|
||||
<th>Type de webhook</th>
|
||||
<th style="width:5%;">Sélectionner</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach ($webhooks as $webhook) { ?>
|
||||
<tr>
|
||||
<td><?php $this->s($webhook['id']); ?></td>
|
||||
<td><?php $this->s($webhook['url']); ?></td>
|
||||
<td><?php $this->s($webhook['type'] == 'send_sms' ? 'Envoi de SMS' : 'Reception de SMS'); ?></td>
|
||||
<td><input type="checkbox" name="ids[]" value="<?php $this->s($webhook['id']); ?>"></td>
|
||||
</tr>
|
||||
<?php } ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<?php } ?>
|
||||
<div>
|
||||
<div class="col-xs-6 no-padding">
|
||||
<a class="btn btn-success" href="<?php echo \descartes\Router::url('Webhook', 'add'); ?>"><span class="fa fa-plus"></span> Ajouter un webhook</a>
|
||||
</div>
|
||||
<?php if ($webhooks) { ?>
|
||||
<div class="text-right col-xs-6 no-padding">
|
||||
<strong>Action pour la séléction :</strong>
|
||||
<button class="btn btn-default" type="submit" formaction="<?php echo \descartes\Router::url('Webhook', 'edit'); ?>"><span class="fa fa-edit"></span> Modifier</button>
|
||||
<button class="btn btn-default btn-confirm" type="submit" formaction="<?php echo \descartes\Router::url('Webhook', 'delete', ['csrf' => $_SESSION['csrf']]); ?>"><span class="fa fa-trash-o"></span> Supprimer</button>
|
||||
</div>
|
||||
<?php } ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div>
|
||||
<div class="col-xs-6 no-padding">
|
||||
<a class="btn btn-success" href="<?php echo \descartes\Router::url('webhooks', 'add'); ?>"><span class="fa fa-plus"></span> Ajouter un webhook</a>
|
||||
</div>
|
||||
<div class="text-right col-xs-6 no-padding">
|
||||
<strong>Action pour la séléction :</strong>
|
||||
<div class="btn-groupe action-dropdown" destination="#table-webhooks">
|
||||
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">Action pour la sélection <span class="caret"></span></button>
|
||||
<ul class="dropdown-menu pull-right" role="menu">
|
||||
<li><a href="<?php echo \descartes\Router::url('webhooks', 'edit', [$_SESSION['csrf']]); ?>"><span class="fa fa-edit"></span> Modifier</a></li>
|
||||
<li><a href="<?php echo \descartes\Router::url('webhooks', 'delete', [$_SESSION['csrf']]); ?>"><span class="fa fa-trash-o"></span> Supprimer</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -78,21 +79,5 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
jQuery(document).ready(function ()
|
||||
{
|
||||
jQuery('.action-dropdown a').on('click', function (e)
|
||||
{
|
||||
e.preventDefault();
|
||||
var destination = jQuery(this).parents('.action-dropdown').attr('destination');
|
||||
var url = jQuery(this).attr('href');
|
||||
jQuery(destination).find('input:checked').each(function ()
|
||||
{
|
||||
url += '/' + jQuery(this).val();
|
||||
});
|
||||
window.location = url;
|
||||
});
|
||||
});
|
||||
</script>
|
||||
<?php
|
||||
$incs->footer();
|
||||
$this->render('incs/footer');
|
||||
|
|
Loading…
Reference in New Issue