Ended development

This commit is contained in:
Jose Gonzalez 2020-11-10 16:48:09 +01:00
parent 665deaa5c8
commit 702b5025e9
2 changed files with 34 additions and 254 deletions

View File

@ -41,6 +41,7 @@ extensions_add_operation_menu_option(
'view' 'view'
); );
// If sec2 parameter come with this page info.
if ($sec2 === 'extensions/agents_alerts') { if ($sec2 === 'extensions/agents_alerts') {
extensions_add_main_function('mainAgentsAlerts'); extensions_add_main_function('mainAgentsAlerts');
} }
@ -53,8 +54,10 @@ if ($sec2 === 'extensions/agents_alerts') {
*/ */
function mainAgentsAlerts() function mainAgentsAlerts()
{ {
global $ajaxPage;
// This page. // This page.
$thisOwnPage = 'index.php?sec=view&sec2=extensions/agents_alerts'; $thisOwnPage = 'index.php?sec=view&sec2=extensions/agents_alerts';
// Ajax variables.
$ajaxPage = 'extensions/agents_alerts'; $ajaxPage = 'extensions/agents_alerts';
$pageName = '[AgentsAlerts]'; $pageName = '[AgentsAlerts]';
// Control call flow. // Control call flow.

View File

@ -138,7 +138,7 @@ class AgentsAlerts extends HTML
// Show Modules without alerts table. // Show Modules without alerts table.
$this->showWithoutAlertModules = isset($_POST['show-modules-without-alerts']); $this->showWithoutAlertModules = isset($_POST['show-modules-without-alerts']);
// Selected group. // Selected group.
$this->groupId = (int) get_parameter('filter-groups', 0); $this->groupId = (int) get_parameter('group-id', 0);
// Create alert token. // Create alert token.
$this->createAlert = (int) get_parameter('create_alert', 0); $this->createAlert = (int) get_parameter('create_alert', 0);
// View token (for full screen view). // View token (for full screen view).
@ -210,10 +210,8 @@ class AgentsAlerts extends HTML
$table = new stdClass(); $table = new stdClass();
$group_id = $this->groupId; if ($this->groupId > 0) {
$grupo = ' AND tagente.id_grupo = '.$this->groupId;
if ($group_id > 0) {
$grupo = ' AND tagente.id_grupo = '.$group_id;
} else { } else {
$grupo = ''; $grupo = '';
} }
@ -554,11 +552,14 @@ class AgentsAlerts extends HTML
); );
$templates_raw = db_get_all_rows_sql($sql); $templates_raw = db_get_all_rows_sql($sql);
if (empty($templates_raw)) {
$templates_raw = [];
}
} }
if (empty($templates_raw)) { // Is needed sort templates for show in the row.
$templates_raw = []; sort($templates);
}
$alerts = []; $alerts = [];
$ntemplates = 0; $ntemplates = 0;
@ -569,10 +570,11 @@ class AgentsAlerts extends HTML
html_print_anchor( html_print_anchor(
[ [
'href' => sprintf( 'href' => sprintf(
'index.php?sec=extensions&sec2=extensions/agents_alerts&hor_offset=%s&offset=%s&group_id=%s', 'index.php?sec=extensions&sec2=extensions/agents_alerts&hor_offset=%s&offset=%s&group-id=%s&pure=%s',
$new_hor_offset, $new_hor_offset,
$this->offset, $this->offset,
$this->groupId $this->groupId,
$this->selectedFullScreen
), ),
'content' => html_print_image( 'content' => html_print_image(
'images/arrow_left_green.png', 'images/arrow_left_green.png',
@ -619,10 +621,11 @@ class AgentsAlerts extends HTML
html_print_anchor( html_print_anchor(
[ [
'href' => sprintf( 'href' => sprintf(
'index.php?sec=extensions&sec2=extensions/agents_alerts&hor_offset=%s&offset=%s&group_id=%s', 'index.php?sec=extensions&sec2=extensions/agents_alerts&hor_offset=%s&offset=%s&group-id=%s&pure=%s',
$new_hor_offset, $new_hor_offset,
$this->offset, $this->offset,
$this->groupId $this->groupId,
$this->selectedFullScreen
), ),
'content' => html_print_image( 'content' => html_print_image(
'images/arrow_right_green.png', 'images/arrow_right_green.png',
@ -640,23 +643,26 @@ class AgentsAlerts extends HTML
echo '</tr>'; echo '</tr>';
foreach ($agents as $agent) { foreach ($agents as $agent) {
// Flag for fired alerts.
$anyfired = false;
// Get aliases.
$alias = db_get_row('tagente', 'id_agente', $agent['id_agente']); $alias = db_get_row('tagente', 'id_agente', $agent['id_agente']);
echo '<tr>'; echo '<tr>';
// Name of the agent. // Name of the agent.
echo '<td style="font-weight:bold;text-align: right;">'.$alias['alias'].'</td>'; echo '<td style="font-weight:bold;text-align: right;">'.$alias['alias'].'</td>';
// Alerts of the agent. // Alerts of the agent.
$anyfired = false;
foreach ($templates as $tid => $tname) { foreach ($templates as $tid => $tname) {
$anyfired = 0;
if ($tname == '') { if ($tname == '') {
continue; continue;
} }
echo '<td style="text-align: center;">'; echo '<td style="text-align: center;">';
if (isset($agent_alerts[$agent['nombre']][$tid])) { if (isset($agent_alerts[$alias['alias']][$tid])) {
foreach ($agent_alerts[$agent['nombre']][$tid] as $alert) { foreach ($agent_alerts[$alias['alias']][$tid] as $alert) {
if ($alert['times_fired'] > 0) { if ((int) $alert['times_fired'] > 0) {
$anyfired = true; $anyfired = true;
} }
} }
@ -677,14 +683,14 @@ class AgentsAlerts extends HTML
'id' => 'line_header_'.$temp['id'], 'id' => 'line_header_'.$temp['id'],
'class' => 'status_rounded_rectangles text_inside', 'class' => 'status_rounded_rectangles text_inside',
'style' => $cellstyle, 'style' => $cellstyle,
'content' => count($agent_alerts[$agent['nombre']][$tid]), 'content' => count($agent_alerts[$alias['alias']][$tid]),
], ],
true true
), ),
] ]
); );
$this->printAlertsSummaryModalWindow($uniqid, $agent_alerts[$agent['nombre']][$tid]); $this->printAlertsSummaryModalWindow($uniqid, $agent_alerts[$alias['alias']][$tid]);
} }
echo '</td>'; echo '</td>';
@ -769,9 +775,9 @@ class AgentsAlerts extends HTML
$headerInputs[] = [ $headerInputs[] = [
'label' => __('Group'), 'label' => __('Group'),
'id' => 'select-filter-groups', 'id' => 'select-group-id',
'arguments' => [ 'arguments' => [
'name' => 'filter-groups', 'name' => 'group-id',
'type' => 'select_groups', 'type' => 'select_groups',
'input_class' => 'flex-row', 'input_class' => 'flex-row',
'class' => '', 'class' => '',
@ -1002,7 +1008,9 @@ class AgentsAlerts extends HTML
($('#refresh-rate').val() * 1000)); ($('#refresh-rate').val() * 1000));
<?php } ?> <?php } ?>
$('#checkbox-show-modules-without-alerts').click(function(){
$('#form-header-filters').submit();
});
//Get max width of name of modules //Get max width of name of modules
max_width = 0; max_width = 0;
@ -1022,211 +1030,8 @@ class AgentsAlerts extends HTML
$("#div_module_r_" + id).css('margin-top', (max_width - 20) + 'px'); $("#div_module_r_" + id).css('margin-top', (max_width - 20) + 'px');
$("#div_module_r_" + id).show(); $("#div_module_r_" + id).show();
}); });
var refr = '<?php echo get_parameter('refresh', 0); ?>';
var pure = '<?php echo get_parameter('pure', 0); ?>';
var href =' <?php echo ui_get_url_refresh($ignored_params); ?>';
if (pure) {
var startCountDown = function (duration, cb) {
$('div.vc-countdown').countdown('destroy');
if (!duration) return;
var t = new Date();
t.setTime(t.getTime() + duration * 1000);
$('div.vc-countdown').countdown({
until: t,
format: 'MS',
layout: '(%M%nn%M:%S%nn%S <?php echo __('Until next'); ?>) ',
alwaysExpire: true,
onExpiry: function () {
$('div.vc-countdown').countdown('destroy');
url = js_html_entity_decode( href ) + duration;
$(document).attr ("location", url);
}
});
}
if(refr>0){
startCountDown(refr, false);
}
var controls = document.getElementById('vc-controls');
autoHideElement(controls, 1000);
$('select#refresh').change(function (event) {
refr = Number.parseInt(event.target.value, 10);
startCountDown(refr, false);
});
}
else {
var agentes_id = $("#id_agents2").val();
var id_agentes = getQueryParam("full_agents_id");
if (agentes_id === null && id_agentes !== null) {
id_agentes = id_agentes.split(";")
id_agentes.forEach(function(element) {
$("#id_agents2 option[value="+ element +"]").attr("selected",true);
});
selection_agent_module();
}
$('#refresh').change(function () {
$('#hidden-vc_refr').val($('#refresh option:selected').val());
});
}
/*
$("#group_id").change (function () {
jQuery.post ("ajax.php",
{"page" : "operation/agentes/ver_agente",
"get_agents_group_json" : 1,
"id_group" : this.value,
"privilege" : "AW",
"keys_prefix" : "_",
"recursion" : $('#checkbox-recursion').is(':checked')
},
function (data, status) {
$("#id_agents2").html('');
$("#module").html('');
jQuery.each (data, function (id, value) {
// Remove keys_prefix from the index
id = id.substring(1);
option = $("<option></option>")
.attr ("value", value["id_agente"])
.html (value["alias"]);
$("#id_agents").append (option);
$("#id_agents2").append (option);
});
},
"json"
);
});
$("#checkbox-recursion").change (function () {
jQuery.post ("ajax.php",
{"page" : "operation/agentes/ver_agente",
"get_agents_group_json" : 1,
"id_group" : $("#group_id").val(),
"privilege" : "AW",
"keys_prefix" : "_",
"recursion" : $('#checkbox-recursion').is(':checked')
},
function (data, status) {
$("#id_agents2").html('');
$("#module").html('');
jQuery.each (data, function (id, value) {
// Remove keys_prefix from the index
id = id.substring(1);
option = $("<option></option>")
.attr ("value", value["id_agente"])
.html (value["alias"]);
$("#id_agents").append (option);
$("#id_agents2").append (option);
});
},
"json"
);
});
$("#modulegroup").change (function () {
jQuery.post ("ajax.php",
{"page" : "operation/agentes/ver_agente",
"get_modules_group_json" : 1,
"id_module_group" : this.value,
"id_agents" : $("#id_agents2").val(),
"selection" : $("#selection_agent_module").val()
},
function (data, status) {
$("#module").html('');
if(data){
jQuery.each (data, function (id, value) {
option = $("<option></option>")
.attr ("value", value["id_agente_modulo"])
.html (value["nombre"]);
$("#module").append (option);
});
}
},
"json"
);
});
$("#id_agents2").click (function(){
selection_agent_module();
});
*/
$("#selection_agent_module").change(function() {
jQuery.post ("ajax.php",
{"page" : "operation/agentes/ver_agente",
"get_modules_group_json" : 1,
"id_module_group" : $("#modulegroup").val(),
"id_agents" : $("#id_agents2").val(),
"selection" : $("#selection_agent_module").val()
},
function (data, status) {
$("#module").html('');
if(data){
jQuery.each (data, function (id, value) {
option = $("<option></option>")
.attr ("value", value["id_agente_modulo"])
.html (value["nombre"]);
$("#module").append (option);
});
}
},
"json"
);
});
}); });
function selection_agent_module() {
jQuery.post ("ajax.php",
{"page" : "operation/agentes/ver_agente",
"get_modules_group_json" : 1,
"id_module_group" : $("#modulegroup").val(),
"id_agents" : $("#id_agents2").val(),
"selection" : $("#selection_agent_module").val()
},
function (data, status) {
$("#module").html('');
if(data){
jQuery.each (data, function (id, value) {
option = $("<option></option>")
.attr ("value", value["id_agente_modulo"])
.html (value["nombre"]);
$("#module").append (option);
});
var id_modules = getQueryParam("full_modules_selected");
if(id_modules !== null) {
id_modules = id_modules.split(";");
id_modules.forEach(function(element) {
$("#module option[value="+ element +"]").attr("selected",true);
});
}
}
},
"json"
);
}
function getQueryParam (key) {
var pattern = "[?&]" + key + "=([^&#]*)";
var regex = new RegExp(pattern);
var url = unescape(window.location.href);
var results = regex.exec(url);
if (results === null) {
return null;
} else {
return results[1];
}
}
function show_alerts_details(id) { function show_alerts_details(id) {
$("#alerts_details_"+id).dialog({ $("#alerts_details_"+id).dialog({
resizable: true, resizable: true,
@ -1253,35 +1058,7 @@ class AgentsAlerts extends HTML
background: "black" background: "black"
} }
}); });
} }
// checkbox-slides_ids
$(document).ready(function () {
$('#checkbox-show-modules-without-alerts').click(function(){
$('#form-header-filters').submit();
});
$('#checkbox-slides_ids').click(function(){
if ($('#checkbox-slides_ids').prop('checked')){
var url = location.href.replace("&show_modules=true", "");
location.href = url+"&show_modules=true";
} else {
var url = location.href.replace("&show_modules=true", "");
var re = /&offset=\d*/g;
location.href = url.replace(re, "");
}
});
$('#group_id').change(function(){
if(location.href.indexOf("extensions/agents_modules") == -1){
var regx = /&group_id=\d*/g;
var url = location.href.replace(regx, "");
location.href = url+"&group_id="+$("#group_id").val();
}
});
});
</script> </script>
<?php <?php