$id_user));
}
echo json_encode($result);
return;
}
// Update if shortcut is visible or hidden
if ($update_shortcut_state) {
$value = (int) get_parameter('value');
$result = db_process_sql_update('tusuario', array('shortcut' => $value), array('id_user' => $config['id_user']));
echo json_encode($result);
return;
}
// Get critical events (realtime update)
if ($get_alerts_fired) {
echo sc_get_alerts_fired();
return;
}
// Get critical events (realtime update)
if ($get_critical_events) {
echo sc_get_critical_events();
return;
}
// Select only opened incidents
if ($get_opened_incidents) {
echo sc_get_opened_incidents();
return;
}
return;
}
function sc_get_alerts_fired () {
global $config;
$data_reporting = reporting_get_group_stats();
return $data_reporting['monitor_alerts_fired'];
}
function sc_get_critical_events () {
global $config;
$own_info = get_user_info ($config['id_user']);
if ($own_info['is_admin'] || check_acl ($config['id_user'], 0, "PM"))
$own_groups = array_keys(users_get_groups($config['id_user'], "IR"));
else
$own_groups = array_keys(users_get_groups($config['id_user'], "IR", false));
// Get events in the last 8 hours
$shortcut_events_update = events_get_group_events($own_groups, 28800, time());
if ($shortcut_events_update == false)
$shortcut_events_update = array();
$critical_events_update = 0;
foreach ($shortcut_events_update as $event_update) {
if ($event_update['criticity'] == 4 and $event_update['estado'] == 0) {
$critical_events_update++;
}
}
return $critical_events_update;
}
function sc_get_opened_incidents () {
global $config;
$own_info = get_user_info ($config['id_user']);
if ($own_info['is_admin'] || check_acl ($config['id_user'], 0, "PM")) {
$sql = "SELECT count(*) total_incidents
FROM tincidencia
WHERE estado = 0
ORDER BY actualizacion";
$result_incidents_update = db_get_all_rows_sql ($sql);
}
else {
$own_groups = array_keys(users_get_groups($config['id_user'], "IR", false));
$sql = "SELECT count(*) total_incidents
FROM tincidencia
WHERE id_grupo IN (".implode (",",array_keys ($own_groups)).")
AND estado = 0
ORDER BY actualizacion";
if (!empty($own_groups)) {
$result_incidents_update = db_get_all_rows_sql($sql);
}
else {
$result_incidents_update = false;
}
}
if ($result_incidents_update === false)
$shortcut_incidents = 0;
else
$shortcut_incidents = $result_incidents_update[0]['total_incidents'];
return $shortcut_incidents;
}
$shortcut_state = db_get_value_filter('shortcut', 'tusuario', array('id_user' => $config['id_user']));
// If shortcut bar is disabled return to index.php
if ($shortcut_state == 0)
return;
$own_info = get_user_info ($config['id_user']);
$shortcut_html = "
";
$shortcut_html .= "
";
$shortcut_html .= html_print_image("images/control_play.png", true, array("title" => __("Press here to activate shortcut bar")));
$shortcut_html .= "
";
$shortcut_html .= "
";
$num_shortcut_items = 0;
// Alerts item
if ($own_info['is_admin'] || check_acl ($config['id_user'], 0, "PM") || check_acl ($config['id_user'], 0, "AR")) {
$alerts_fired = sc_get_alerts_fired();
$shortcut_html .= "
";
$shortcut_html .= html_print_image("images/op_alerts.png", true, array("title" => __("Alerts fired"), "style" => "margin-bottom: 0px;"));
$shortcut_html .= " ";
$shortcut_html .= "" . $alerts_fired . "";
$shortcut_html .= "";
$num_shortcut_items++;
}
// Events item
if ($own_info['is_admin'] || check_acl ($config['id_user'], 0, "PM") || check_acl ($config['id_user'], 0, "IR")) {
$critical_events = sc_get_critical_events();
$shortcut_html .= "
";
$shortcut_html .= html_print_image("images/op_events.png", true, array("title" => __("Critical events"), "style" => "margin-bottom: 0px;"));
$shortcut_html .= " ";
$shortcut_html .= "" . $critical_events . "";
$shortcut_html .= "";
$num_shortcut_items++;
}
// Calculate opened incidents (id integria incidents are not enabled)
if ($config['integria_enabled'] == 0) {
$shortcut_incidents = sc_get_opened_incidents();
$shortcut_html .= "
";
$shortcut_html .= html_print_image("images/incidents.png", true, array("title" => __("Incidents opened"), "style" => "margin-bottom: 0px;"));
$shortcut_html .= " ";
$shortcut_html .= "" . $shortcut_incidents . "";
$shortcut_html .= "";
$num_shortcut_items++;
}
if ($num_shortcut_items > 0) {
$shortcut_html .= "
";
$shortcut_html .= "|";
$shortcut_html .= "";
}
$shortcut_html .= "
";
$shortcut_html .= html_print_image("images/op_reporting.png", true, array("title" => __("View reports"), "style" => "margin-bottom: 0px;"));
$shortcut_html .= "";
$num_shortcut_items++;
$shortcut_html .= "
";
$shortcut_html .= html_print_image("images/email_mc.png", true, array("title" => __("Create new message"), "style" => "margin-bottom: 0px;"));
$shortcut_html .= "";
$num_shortcut_items++;
//Quick access
// $shortcut_data = db_get_value('shortcut_data', 'tusuario', 'id_user', $config['id_user']);
// if (!empty($shortcut_data)) {
// $serialize = $shortcut_data;
// $unserialize = json_decode($serialize, true);
// $items = $unserialize['item_shorcut'];
// }
// else {
// $items = array();
// }
// $shortcut_html .= "
" .
// __("Shortcut: ");
// $shortcut_html .= "
";
// foreach ($items as $item) {
// $shortcut_html .= "- " . io_safe_output($item) . "
";
// }
// $shortcut_html .= "
";
$shortcut_html .= "
";
$shortcut_html .= "
";
echo $shortcut_html;
// Login in Console and shortcut bar is disabled
// This will show and hide the shortcut value in Javascript code
if (isset($_POST['nick']) and $shortcut_state != 2) {
html_print_input_hidden("login_console", 1);
}
else {
html_print_input_hidden("login_console", 0);
}
html_print_input_hidden("shortcut_id_user", $config['id_user']);
?>