Ajout d'une page de configuration globale de RaspiSMS, uniquement pour l'admin. Permet pour l'instant de gérer uniquement l'activation du transfer de SMS
This commit is contained in:
parent
e49141c747
commit
97e564ba73
|
@ -21,6 +21,13 @@
|
|||
#########
|
||||
//On va appeler un modèle, est l'initialiser
|
||||
$db = new DataBase($bdd);;
|
||||
|
||||
//On va ajouter les réglages globaux de RaspiSMS modifiables via l'interface
|
||||
$settings = $db->getFromTableWhere('settings');
|
||||
foreach ($settings as $setting)
|
||||
{
|
||||
define('RASPISMS_SETTINGS_' . mb_convert_case($setting['name'], MB_CASE_UPPER), $setting['value']);
|
||||
}
|
||||
|
||||
###########
|
||||
# ROUTAGE #
|
||||
|
|
|
@ -300,6 +300,12 @@
|
|||
*/
|
||||
public function sendTransfers ()
|
||||
{
|
||||
if (!RASPISMS_SETTINGS_TRANSFER)
|
||||
{
|
||||
echo "Le transfer de SMS est désactivé ! \n";
|
||||
return false;
|
||||
}
|
||||
|
||||
global $db;
|
||||
$transfers = $db->getFromTableWhere('transfers', ['progress' => false]);
|
||||
|
||||
|
|
|
@ -43,6 +43,7 @@
|
|||
$email = isset($_SESSION['email']) ? $_SESSION['email'] : 'Mon compte';
|
||||
$this->render('internalIncs/nav', array(
|
||||
'email' => $email,
|
||||
'admin' => $_SESSION['admin'],
|
||||
'page' => $page,
|
||||
));
|
||||
}
|
||||
|
|
|
@ -0,0 +1,69 @@
|
|||
<?php
|
||||
/**
|
||||
* Page des réglages de RaspiSMS
|
||||
*/
|
||||
class settings extends Controller
|
||||
{
|
||||
/**
|
||||
* Cette fonction est appelée avant toute les autres :
|
||||
* Elle vérifie que l'utilisateur est bien connecté && est admin
|
||||
* @return void;
|
||||
*/
|
||||
public function before()
|
||||
{
|
||||
internalTools::verifyConnect();
|
||||
|
||||
if (!$_SESSION['admin'])
|
||||
{
|
||||
die();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Cette fonction retourne la page d'accueil des réglages de RaspiSMS
|
||||
*/
|
||||
public function byDefault()
|
||||
{
|
||||
return $this->render('settings/default');
|
||||
}
|
||||
|
||||
/**
|
||||
* Cette fonction permet de mettre à jour l'activation ou la désactivation du transfer des SMS
|
||||
* @param $csrf : Le jeton CSRF
|
||||
* @param string $_POST['transfer'] : Le nouveau transfer de l'utilisateur
|
||||
* @return void;
|
||||
*/
|
||||
public function changeTransfer($csrf)
|
||||
{
|
||||
//On vérifie que le jeton csrf est bon
|
||||
if (!internalTools::verifyCSRF($csrf))
|
||||
{
|
||||
$_SESSION['errormessage'] = 'Jeton CSRF invalide !';
|
||||
header('Location: ' . $this->generateUrl('settings'));
|
||||
return false;
|
||||
}
|
||||
|
||||
//Creation de l'object de base de données
|
||||
global $db;
|
||||
|
||||
if (!isset($_POST['transfer']))
|
||||
{
|
||||
$_SESSION['errormessage'] = 'Vous devez renseigner un valeur';
|
||||
header('Location: ' . $this->generateUrl('settings'));
|
||||
return false;
|
||||
}
|
||||
|
||||
$transfer = (int)$_POST['transfer'];
|
||||
|
||||
if (!$db->updateTableWhere('settings', ['value' => $transfer], ['name' => 'transfer']))
|
||||
{
|
||||
$_SESSION['errormessage'] = 'Impossible de mettre les données à jour.';
|
||||
header('Location: ' . $this->generateUrl('settings'));
|
||||
return false;
|
||||
}
|
||||
|
||||
$_SESSION['successmessage'] = 'Les données ont été mises à jour.';
|
||||
header('Location: ' . $this->generateUrl('settings'));
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -3,6 +3,14 @@
|
|||
CREATE DATABASE IF NOT EXISTS raspisms;
|
||||
USE raspisms;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS settings
|
||||
(
|
||||
id INT NOT NULL AUTO_INCREMENT,
|
||||
name VARCHAR(20) NOT NULL,
|
||||
value VARCHAR(1000) NOT NULL,
|
||||
PRIMARY KEY (id)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS receiveds
|
||||
(
|
||||
id INT NOT NULL AUTO_INCREMENT,
|
||||
|
@ -126,3 +134,7 @@ CREATE TABLE IF NOT EXISTS transfers
|
|||
PRIMARY KEY (id),
|
||||
FOREIGN KEY (id_received) REFERENCES receiveds (id) ON DELETE CASCADE ON UPDATE CASCADE
|
||||
);
|
||||
|
||||
#On insert les données par défaut dans les settings
|
||||
INSERT INTO settings (name, value)
|
||||
VALUES ('transfer', '1');
|
||||
|
|
|
@ -18,6 +18,14 @@
|
|||
//On va appeler un modèle, est l'initialiser
|
||||
$db = new DataBase($bdd);;
|
||||
|
||||
//On va ajouter les réglages globaux de RaspiSMS modifiables via l'interface
|
||||
$settings = $db->getFromTableWhere('settings');
|
||||
foreach ($settings as $setting)
|
||||
{
|
||||
define('RASPISMS_SETTINGS_' . mb_convert_case($setting['name'], MB_CASE_UPPER), $setting['value']);
|
||||
}
|
||||
|
||||
|
||||
###########
|
||||
# ROUTAGE #
|
||||
###########
|
||||
|
|
|
@ -68,6 +68,11 @@
|
|||
<li <?php echo $page == 'users' ? 'class="active"' : ''; ?>>
|
||||
<a href="<?php echo $this->generateUrl('users'); ?>"><i class="fa fa-fw fa-user"></i> Utilisateurs</a>
|
||||
</li>
|
||||
<?php if ($admin) { ?>
|
||||
<li <?php echo $page == 'settings' ? 'class="active"' : ''; ?>>
|
||||
<a href="<?php echo $this->generateUrl('settings'); ?>"><i class="fa fa-fw fa-cogs"></i> Réglages</a>
|
||||
</li>
|
||||
<?php } ?>
|
||||
</ul>
|
||||
</div>
|
||||
<!-- /.navbar-collapse -->
|
||||
|
|
|
@ -0,0 +1,84 @@
|
|||
<?php
|
||||
//Template dashboard
|
||||
$incs = new internalIncs();
|
||||
$incs->head('Réglages');
|
||||
?>
|
||||
<div id="wrapper">
|
||||
<?php
|
||||
$incs->nav('settings');
|
||||
?>
|
||||
<div id="page-wrapper">
|
||||
<div class="container-fluid">
|
||||
<!-- Page Heading -->
|
||||
<div class="row">
|
||||
<div class="col-lg-12">
|
||||
<h1 class="page-header">
|
||||
Dashboard <small>Réglages</small>
|
||||
</h1>
|
||||
<ol class="breadcrumb">
|
||||
<li>
|
||||
<i class="fa fa-dashboard"></i> <a href="<?php echo $this->generateUrl('dashboard'); ?>">Dashboard</a>
|
||||
</li>
|
||||
<li class="active">
|
||||
<i class="fa fa-cogs"></i> Réglages
|
||||
</li>
|
||||
</ol>
|
||||
</div>
|
||||
</div>
|
||||
<!-- /.row -->
|
||||
|
||||
<div class="row">
|
||||
<div class="col-lg-12">
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">
|
||||
<h3 class="panel-title"><i class="fa fa-cogs fa-fw"></i> Les réglages de RaspiSMS</h3>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<div class="col-xs-12 col-md-6">
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">
|
||||
<h4 class="panel-title"><i class="fa fa-share fa-fw"></i> Transfert des SMS par e-mail</h4>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<form action="<?php echo $this->generateUrl('settings', 'changeTransfer', [$_SESSION['csrf']]); ?>" method="POST">
|
||||
<div class="form-group">
|
||||
<label>Transfert activé : </label>
|
||||
<select name="transfer" class="form-control">
|
||||
<option value="0">Non</option>
|
||||
<option value="1" <?php echo RASPISMS_SETTINGS_TRANSFER ? '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>
|
||||
<div class="col-xs-12 col-md-6">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
jQuery(document).ready(function ()
|
||||
{
|
||||
jQuery('.action-dropdown a').on('click', function (e)
|
||||
{
|
||||
e.preventDefault();
|
||||
var target = jQuery(this).parents('.action-dropdown').attr('target');
|
||||
var url = jQuery(this).attr('href');
|
||||
jQuery(target).find('input:checked').each(function ()
|
||||
{
|
||||
url += '/' + jQuery(this).val();
|
||||
});
|
||||
window.location = url;
|
||||
});
|
||||
});
|
||||
</script>
|
||||
<?php
|
||||
$incs->footer();
|
Loading…
Reference in New Issue