. * --------------------------------------------------------------------- */ if (!defined('GLPI_ROOT')) { die("Sorry. You can't access this file directly"); } /** * Notifications settings configuration class */ class NotificationSettingConfig extends CommonDBTM { public $table = 'glpi_configs'; protected $displaylist = false; static $rightname = 'config'; public function update(array $input, $history = 1, $options = []) { if (isset($input['use_notifications'])) { $config = new Config(); $tmp = [ 'id' => 1, 'use_notifications' => $input['use_notifications'] ]; $config->update($tmp); //disable all notifications types if notifications has been disabled if ($tmp['use_notifications'] == 0) { $modes = Notification_NotificationTemplate::getModes(); foreach (array_keys($modes) as $mode) { $input['notifications_' . $mode] = 0; } } } $config = new Config(); foreach ($input as $k => $v) { if (substr($k, 0, strlen('notifications_')) === 'notifications_') { $tmp = [ 'id' => 1, $k => $v ]; $config->update($tmp); } } } /** * Show configuration form * * @return string|void */ public function showForm($options = []) { global $CFG_GLPI; if (!isset($options['display'])) { $options['display'] = true; } $modes = Notification_NotificationTemplate::getModes(); $out = ''; $modes_settings = []; if (Session::haveRight("config", UPDATE)) { $out .= "
"; $out .= "
"; $out .= ""; $out .= ""; if ($CFG_GLPI['use_notifications'] && !Notification_NotificationTemplate::hasActiveMode()) { $out .= ""; } $out .= ""; $out .= ""; $out .= ""; $out .= ""; foreach (array_keys($modes) as $mode) { $settings_class = Notification_NotificationTemplate::getModeClass($mode, 'setting'); $settings = new $settings_class(); $modes_settings[$mode] = $settings; $out .= ""; $out .= ""; $out .= ""; $out .= ""; } $out .= ""; $out .= "
" . __('Notifications configuration') . "
".__('You must enable at least one notification mode.')."
" . __('Enable followup') . ""; $out .= Dropdown::showYesNo('use_notifications', $CFG_GLPI['use_notifications'], -1, ['display' => false]); $out .= "
" . $settings->getEnableLabel() . ""; $out .= Dropdown::showYesNo("notifications_$mode", $CFG_GLPI["notifications_$mode"], -1, ['display' => false, 'disabled' => !$CFG_GLPI['use_notifications']]); $out .= "
"; $out .= Html::closeForm(false); $js = "$(function(){ $('[name=use_notifications]').on('change', function() { var _val = $(this).find('option:selected').val(); if (_val == '1') { $('select[name!=use_notifications]').prop('disabled', false); } else { $('select[name!=use_notifications]').select2('enable', false); } }); })"; $out .= Html::scriptBlock($js); } $notifs_on = false; if ($CFG_GLPI['use_notifications']) { foreach (array_keys($modes) as $mode) { if ($CFG_GLPI['notifications_' . $mode]) { $notifs_on = true; break; } } } if ($notifs_on) { $out .= ""; $out .= ""; /* Glocal parameters */ if (Session::haveRight("config", READ)) { $out .= ""; } if (Session::haveRight("notification", READ) && $notifs_on) { $out .= ""; } else { $out .= ""; } /* Per notification parameters */ foreach (array_keys($modes) as $mode) { if (Session::haveRight("config", UPDATE) && $CFG_GLPI['notifications_' . $mode]) { $settings = $modes_settings[$mode]; $out .= ""; } } $out .= "
" . _n('Notification', 'Notifications', Session::getPluralNumber())."
" . _n('Notification template', 'Notification templates', Session::getPluralNumber()) ."
". "". _n('Notification', 'Notifications', Session::getPluralNumber())."
" . __('Unable to configure notifications: please configure at least one followup type using the above configuration.') . "
". "". $settings->getTypeName() . "
"; $out .= "
"; } if ($options['display']) { echo $out; } else { return $out; } } }