mirror of
https://github.com/pandorafms/pandorafms.git
synced 2025-07-28 08:14:38 +02:00
Added notification global configuration (only enable and disable)
Former-commit-id: 850d4dd1d8e30fc66623308b8ab148eaeadb5015
This commit is contained in:
parent
b589826c86
commit
01bc0775bc
@ -271,7 +271,10 @@ if (check_acl ($config['id_user'], 0, "PM")) {
|
|||||||
|
|
||||||
$sub2["godmode/setup/setup&section=ehorus"]["text"] = __('eHorus');
|
$sub2["godmode/setup/setup&section=ehorus"]["text"] = __('eHorus');
|
||||||
$sub2["godmode/setup/setup&section=ehorus"]["refr"] = 0;
|
$sub2["godmode/setup/setup&section=ehorus"]["refr"] = 0;
|
||||||
|
|
||||||
|
$sub2["godmode/setup/setup&section=notifications"]["text"] = __('Notifications');
|
||||||
|
$sub2["godmode/setup/setup&section=notifications"]["refr"] = 0;
|
||||||
|
|
||||||
if ($config['activate_gis']) {
|
if ($config['activate_gis']) {
|
||||||
$sub2["godmode/setup/gis"]["text"] = __('Map conections GIS');
|
$sub2["godmode/setup/gis"]["text"] = __('Map conections GIS');
|
||||||
}
|
}
|
||||||
|
@ -101,6 +101,11 @@ $buttons['ehorus'] = array('active' => false,
|
|||||||
'text' => '<a href="index.php?sec=gsetup&sec2=godmode/setup/setup§ion=ehorus">' .
|
'text' => '<a href="index.php?sec=gsetup&sec2=godmode/setup/setup§ion=ehorus">' .
|
||||||
html_print_image("images/ehorus/ehorus.png", true, array ("title" => __('eHorus'))) . '</a>');
|
html_print_image("images/ehorus/ehorus.png", true, array ("title" => __('eHorus'))) . '</a>');
|
||||||
|
|
||||||
|
// FIXME: Not definitive icon
|
||||||
|
$buttons['notifications'] = array('active' => false,
|
||||||
|
'text' => '<a href="index.php?sec=gsetup&sec2=godmode/setup/setup§ion=notifications">' .
|
||||||
|
html_print_image("images/alerts_template.png", true, array ("title" => __('Notifications'))) . '</a>');
|
||||||
|
|
||||||
$help_header = '';
|
$help_header = '';
|
||||||
if (enterprise_installed()) {
|
if (enterprise_installed()) {
|
||||||
$subpage = setup_enterprise_add_subsection_main($section, $buttons, $help_header);
|
$subpage = setup_enterprise_add_subsection_main($section, $buttons, $help_header);
|
||||||
@ -132,6 +137,10 @@ switch ($section) {
|
|||||||
$buttons['ehorus']['active'] = true;
|
$buttons['ehorus']['active'] = true;
|
||||||
$subpage = ' » ' . __('eHorus');
|
$subpage = ' » ' . __('eHorus');
|
||||||
break;
|
break;
|
||||||
|
case 'notifications':
|
||||||
|
$buttons['notifications']['active'] = true;
|
||||||
|
$subpage = ' » ' . __('Notifications');
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Header
|
// Header
|
||||||
@ -167,6 +176,9 @@ switch ($section) {
|
|||||||
case "ehorus":
|
case "ehorus":
|
||||||
require_once($config['homedir'] . "/godmode/setup/setup_ehorus.php");
|
require_once($config['homedir'] . "/godmode/setup/setup_ehorus.php");
|
||||||
break;
|
break;
|
||||||
|
case "notifications":
|
||||||
|
require_once($config['homedir'] . "/godmode/setup/setup_notifications.php");
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
enterprise_hook('setup_enterprise_select_tab', array($section));
|
enterprise_hook('setup_enterprise_select_tab', array($section));
|
||||||
break;
|
break;
|
||||||
|
66
pandora_console/godmode/setup/setup_notifications.php
Normal file
66
pandora_console/godmode/setup/setup_notifications.php
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
// Pandora FMS - http://pandorafms.com
|
||||||
|
// ==================================================
|
||||||
|
// Copyright (c) 2005-2019 Artica Soluciones Tecnologicas
|
||||||
|
// Please see http://pandorafms.org for full contribution list
|
||||||
|
|
||||||
|
// This program is free software; you can redistribute it and/or
|
||||||
|
// modify it under the terms of the GNU General Public License
|
||||||
|
// as published by the Free Software Foundation for version 2.
|
||||||
|
// This program is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
|
||||||
|
// Warning: This file may be required into the metaconsole's setup
|
||||||
|
|
||||||
|
// Load global vars
|
||||||
|
global $config;
|
||||||
|
|
||||||
|
check_login ();
|
||||||
|
|
||||||
|
if (! check_acl($config['id_user'], 0, 'PM') && ! is_user_admin($config['id_user'])) {
|
||||||
|
db_pandora_audit('ACL Violation', 'Trying to access Setup Management');
|
||||||
|
require ('general/noaccess.php');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Actions
|
||||||
|
if (get_parameter('update_config', 0)) {
|
||||||
|
$res_global = array_reduce(notifications_get_all_sources(), function($carry, $source){
|
||||||
|
$id = notifications_desc_to_id($source['description']);
|
||||||
|
if (empty($id)) return false;
|
||||||
|
$enable_value = switch_to_int(get_parameter("enable-$id"));
|
||||||
|
$res = mysql_db_process_sql_update(
|
||||||
|
'tnotification_source',
|
||||||
|
array(
|
||||||
|
'enabled' => $enable_value),
|
||||||
|
array('id' => $source['id'])
|
||||||
|
);
|
||||||
|
return $res && $carry;
|
||||||
|
}, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Notification table. It is just a wrapper.
|
||||||
|
$table_content = new StdClass();
|
||||||
|
$table_content->data = array();
|
||||||
|
$table_content->width = '100%';
|
||||||
|
$table_content->id = 'notifications-wrapper';
|
||||||
|
$table_content->class = 'databox filters';
|
||||||
|
$table_content->size['name'] = '30%';
|
||||||
|
$table_remote->style['name'] = 'font-weight: bold';
|
||||||
|
|
||||||
|
// Print each source configuration
|
||||||
|
$table_content->data = array_map(function ($source) {
|
||||||
|
return notifications_print_global_source_configuration($source);
|
||||||
|
}, notifications_get_all_sources());
|
||||||
|
$table_content->data[] = html_print_submit_button(
|
||||||
|
__('Update'), 'update_button', false, 'class="sub upd" style="display: flex; "', true
|
||||||
|
);
|
||||||
|
|
||||||
|
echo '<form id="form_enable" method="post">';
|
||||||
|
html_print_input_hidden('update_config', 1);
|
||||||
|
html_print_table($table_content);
|
||||||
|
echo '</form>';
|
||||||
|
|
@ -42,15 +42,24 @@ function get_notification_source_id(string $source)
|
|||||||
}
|
}
|
||||||
|
|
||||||
return db_get_value_sql(
|
return db_get_value_sql(
|
||||||
sprintf(
|
"SELECT id
|
||||||
'SELECT id
|
FROM `tnotification_source`
|
||||||
FROM `tnotification_source`
|
WHERE `description` LIKE '{$source}%'"
|
||||||
WHERE lower(`description`) = lower("%s")',
|
|
||||||
$source
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts description into a handable identifier
|
||||||
|
*
|
||||||
|
* @param string $desc Full description
|
||||||
|
*
|
||||||
|
* @return string First word in lowercase. Empty string if no word detected.
|
||||||
|
*/
|
||||||
|
function notifications_desc_to_id(string $desc) {
|
||||||
|
preg_match('/^[a-zA-Z]*/', $desc, $matches);
|
||||||
|
$match = $matches[0];
|
||||||
|
return isset($match) ? $match : '';
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve all targets for given message.
|
* Retrieve all targets for given message.
|
||||||
@ -148,6 +157,15 @@ function check_notification_readable(int $id_message)
|
|||||||
return (bool) db_get_value_sql($sql);
|
return (bool) db_get_value_sql($sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return all info from tnotification_source
|
||||||
|
*
|
||||||
|
* @return array with sources info
|
||||||
|
*/
|
||||||
|
function notifications_get_all_sources() {
|
||||||
|
return mysql_db_get_all_rows_in_table('tnotification_source');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Print the notification ball to see unread messages
|
* Print the notification ball to see unread messages
|
||||||
*
|
*
|
||||||
@ -163,3 +181,27 @@ function notifications_print_ball() {
|
|||||||
$num_notifications
|
$num_notifications
|
||||||
</div>";
|
</div>";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Print notification configuration global
|
||||||
|
*
|
||||||
|
* @param array notification source data
|
||||||
|
*
|
||||||
|
* @return string with HTML of source configuration
|
||||||
|
*/
|
||||||
|
function notifications_print_global_source_configuration($source) {
|
||||||
|
|
||||||
|
// Get some values to generate the title
|
||||||
|
$switch_values = array (
|
||||||
|
'name' => "enable-" . notifications_desc_to_id($source['description']),
|
||||||
|
'value' => $source['enabled']
|
||||||
|
);
|
||||||
|
// Generate the title
|
||||||
|
$html_title = "<div class='global-config-notification-title'>";
|
||||||
|
$html_title .= html_print_switch($switch_values);
|
||||||
|
$html_title .= "<h2>{$source['description']}</h2>";
|
||||||
|
$html_title .= "</div>";
|
||||||
|
|
||||||
|
// Return all html
|
||||||
|
return $html_title;
|
||||||
|
}
|
||||||
|
@ -4929,6 +4929,16 @@ div#dialog_messages table th:last-child {
|
|||||||
background-color: #fc4444;
|
background-color: #fc4444;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.global-config-notification-title {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.global-config-notification-title h2 {
|
||||||
|
margin-left: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
/* --- JQUERY-UI --- */
|
/* --- JQUERY-UI --- */
|
||||||
.ui-button-text-only .ui-button-text {
|
.ui-button-text-only .ui-button-text {
|
||||||
font-family: "nunito", sans-serif;
|
font-family: "nunito", sans-serif;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user