add setting to hide menus for users

This commit is contained in:
osaajani 2021-06-14 21:33:06 +02:00
parent ca9b7c7c6e
commit 17d91873d4
4 changed files with 90 additions and 24 deletions

View File

@ -40,6 +40,7 @@ namespace controllers\publics;
* @param string $setting_name : Name of the setting to modify
* @param $csrf : CSRF token
* @param string $_POST['setting_value'] : Setting's new value
* @param bool $_POST['allow_no_value'] : Default false, if true then allow $_POST['setting_value'] to dont exists, and treat it as empty string
*
* @return boolean;
*/
@ -53,6 +54,13 @@ namespace controllers\publics;
}
$setting_value = $_POST['setting_value'] ?? false;
$allow_no_value = $_POST['allow_no_value'] ?? false;
//if no value allowed and no value fund, default to ''
if ($allow_no_value && ($setting_value === false))
{
$setting_value = '';
}
if (false === $setting_value)
{
@ -61,6 +69,12 @@ namespace controllers\publics;
return $this->redirect(\descartes\Router::url('Setting', 'show'));
}
//If setting is an array, join with comas
if (is_array($setting_value))
{
$setting_value = json_encode($setting_value);
}
$update_setting_result = $this->internal_setting->update_for_user($_SESSION['user']['id'], $setting_name, $setting_value);
if (false === $update_setting_result)
{

View File

@ -82,6 +82,7 @@
'mms' => 1,
'alert_quota_limit_reached' => 1,
'alert_quota_limit_close' => 0.9,
'hide_menus' => '',
],
];

View File

@ -68,37 +68,51 @@
</li>
<?php } ?>
</ul>
</li>
<li>
<a href="javascript:;" data-toggle="collapse" data-target="#logs"><i class="fa fa-fw fa-file-text"></i> Logs <i class="fa fa-fw fa-caret-down"></i></a>
<ul id="logs" class="collapse <?php echo in_array($page, array('events', 'smsstop', 'calls')) ? 'in' : ''; ?>">
<li <?php echo $page == 'smsstop' ? 'class="active"' : ''; ?>>
<a href="<?php echo \descartes\Router::url('SmsStop', 'list'); ?>"><i class="fa fa-fw fa-ban"></i> SMS STOP</a>
</li>
<li <?php echo $page == 'calls' ? 'class="active"' : ''; ?>>
<a href="<?php echo \descartes\Router::url('Call', 'list'); ?>"><i class="fa fa-fw fa-file-audio-o"></i> Appels</a>
</li>
<li <?php echo $page == 'events' ? 'class="active"' : ''; ?>>
<a href="<?php echo \descartes\Router::url('Event', 'list'); ?>"><i class="fa fa-fw fa-clock-o"></i> Évènements</a>
</li>
</ul>
</li>
<?php if (ENABLE_COMMAND) { ?>
<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>
<?php if (!in_array('log', json_decode($_SESSION['user']['settings']['hide_menus'], true) ?? [])) { ?>
<li>
<a href="javascript:;" data-toggle="collapse" data-target="#logs"><i class="fa fa-fw fa-file-text"></i> Logs <i class="fa fa-fw fa-caret-down"></i></a>
<ul id="logs" class="collapse <?php echo in_array($page, array('events', 'smsstop', 'calls')) ? 'in' : ''; ?>">
<?php if (!in_array('smsstop', json_decode($_SESSION['user']['settings']['hide_menus'], true) ?? [])) { ?>
<li <?php echo $page == 'smsstop' ? 'class="active"' : ''; ?>>
<a href="<?php echo \descartes\Router::url('SmsStop', 'list'); ?>"><i class="fa fa-fw fa-ban"></i> SMS STOP</a>
</li>
<?php } ?>
<?php if (!in_array('calls', json_decode($_SESSION['user']['settings']['hide_menus'], true) ?? [])) { ?>
<li <?php echo $page == 'calls' ? 'class="active"' : ''; ?>>
<a href="<?php echo \descartes\Router::url('Call', 'list'); ?>"><i class="fa fa-fw fa-file-audio-o"></i> Appels</a>
</li>
<?php } ?>
<?php if (!in_array('events', json_decode($_SESSION['user']['settings']['hide_menus'], true) ?? [])) { ?>
<li <?php echo $page == 'events' ? 'class="active"' : ''; ?>>
<a href="<?php echo \descartes\Router::url('Event', 'list'); ?>"><i class="fa fa-fw fa-clock-o"></i> Évènements</a>
</li>
<?php } ?>
</ul>
</li>
<?php } ?>
<?php if (ENABLE_COMMAND) { ?>
<?php if (!in_array('commands', json_decode($_SESSION['user']['settings']['hide_menus'], true) ?? [])) { ?>
<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>
<?php } ?>
<?php } ?>
<?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>
<li <?php echo $page == 'settings' ? 'class="active"' : ''; ?>>
<a href="<?php echo \descartes\Router::url('Setting', 'show'); ?>"><i class="fa fa-fw fa-cogs"></i> Réglages</a>
</li>
<?php if (!in_array('phones', json_decode($_SESSION['user']['settings']['hide_menus'], true) ?? [])) { ?>
<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>
<?php } ?>
<?php if (!in_array('settings', json_decode($_SESSION['user']['settings']['hide_menus'], true) ?? [])) { ?>
<li <?php echo $page == 'settings' ? 'class="active"' : ''; ?>>
<a href="<?php echo \descartes\Router::url('Setting', 'show'); ?>"><i class="fa fa-fw fa-cogs"></i> Réglages</a>
</li>
<?php } ?>
<?php if (\controllers\internals\Tool::is_admin()) { ?>
<li <?php echo $page == 'users' ? 'class="active"' : ''; ?>>
<a href="<?php echo \descartes\Router::url('User', 'list'); ?>"><i class="fa fa-fw fa-user"></i> Utilisateurs</a>

View File

@ -318,6 +318,23 @@
</form>
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title"><i class="fa fa-eye-slash fa-fw"></i> Cacher des menus</h4>
</div>
<div class="panel-body">
<form action="<?php echo \descartes\Router::url('Setting', 'update', ['setting_name' => 'hide_menus', 'csrf' => $_SESSION['csrf']]); ?>" method="POST">
<input type="hidden" name="allow_no_value" value="1" />
<div class="form-group">
<label>Cacher certains menus à l'utilisateur (ces menus restent accessibles par l'URL) : </label>
<input name="setting_value[]" class="add-hide-menus form-control" type="text" placeholder="Menus à cacher" autofocus value="<?php $this->s($_SESSION['user']['settings']['hide_menus']); ?>">
</div>
<div class="text-center">
<button class="btn btn-success">Mettre à jour les données</button>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
@ -339,7 +356,27 @@
url += '/' + jQuery(this).val();
});
window.location = url;
});
});
jQuery('.add-hide-menus').each(function()
{
jQuery(this).magicSuggest({
data: [
{'id': 'logs', 'name': 'Logs'},
{"id": "smsstop", "name": "SMS Stop"},
{"id": "calls", "name": "Appels"},
{"id": "events", "name": "Évènements"},
{"id": "commands", "name": "Commandes"},
{"id": "phones", "name": "Téléphones"},
{"id": "settings", "name": "Réglages"},
],
valueField: 'id',
displayField: 'name',
name: 'hide_menus[]',
maxSelection: null,
});
});
});
</script>
<?php