From cab85cbfbd470bfd60c164aebfcd87efc052af98 Mon Sep 17 00:00:00 2001 From: Daniel Maya Date: Wed, 30 Mar 2022 10:21:30 +0200 Subject: [PATCH] #8458 Fixed errors --- pandora_console/include/ajax/heatmap.ajax.php | 80 ++++++++++++------- .../include/class/Heatmap.class.php | 71 ++++++++++------ pandora_console/include/styles/heatmap.css | 16 ++++ pandora_console/operation/heatmap.php | 4 +- 4 files changed, 115 insertions(+), 56 deletions(-) diff --git a/pandora_console/include/ajax/heatmap.ajax.php b/pandora_console/include/ajax/heatmap.ajax.php index 3a4a1b1022..f2f6c81280 100644 --- a/pandora_console/include/ajax/heatmap.ajax.php +++ b/pandora_console/include/ajax/heatmap.ajax.php @@ -38,7 +38,7 @@ if (is_ajax() === true) { $type = get_parameter('type', 0); if ($getFilters === true) { - $refresh = get_parameter('refresh', 30); + $refresh = get_parameter('refresh', 180); $search = get_parameter('search', ''); $group = get_parameter('group', true); @@ -117,6 +117,7 @@ if (is_ajax() === true) { 'return' => true, 'required' => true, 'privilege' => 'AR', + 'multiple' => true, ] ); break; @@ -186,28 +187,20 @@ if (is_ajax() === true) { break; case 2: - $module_groups = modules_get_modulegroups(); - // $module_groups[0] = _('Not assigned'); - // hd(current($filter)); echo '

'.__('Module group').'

'; - echo html_print_select( - $module_groups, + echo html_print_select_from_sql( + 'SELECT id_mg, name FROM tmodule_group ORDER BY name', 'filter[]', $filter, '', - _('Not assigned'), - 0, + __('Not assigned'), + '0', + true, + true, true, false, - false, - '', - false, - 'width: 70%', - false, - false, - false, - '', - true + 'width: 200px', + '5' ); break; } @@ -216,20 +209,28 @@ if (is_ajax() === true) { } if ($getInfo === true) { + enterprise_include_once('include/functions_agents.php'); $id = get_parameter('id', 0); switch ($type) { case 2: $data = db_get_row('tagente_modulo', 'id_agente_modulo', $id); + // Nombre. + $link = sprintf( + 'index.php?sec=view&sec2=operation/agentes/status_monitor%s&ag_modulename=%s', + '&refr=0&ag_group=0&module_option=1&status=-1', + $data['nombre'] + ); echo '
'; echo '

'.__('Module name').'

'; - echo ''.$data['nombre'].''; + echo ''.$data['nombre'].''; echo '
'; // Descripcion. + $description = (empty($data['descripcion']) === true) ? '-' : $data['descripcion']; echo '
'; echo '

'.__('Description').'

'; - echo '

'.$data['descripcion'].'

'; + echo '

'.$description.'

'; echo '
'; // Agent. @@ -240,24 +241,35 @@ if (is_ajax() === true) { echo ''; // Group. + $group = (empty($data['id_module_group']) === true) + ? '-' + : modules_get_modulegroup_name($data['id_module_group']); + echo '
'; - echo '

'.__('Group').'

'; - echo '

'.modules_get_modulegroup_name($data['id_module_group']).'

'; + echo '

'.__('Module group').'

'; + echo '

'.$group.'

'; echo '
'; break; case 1: $data = db_get_row('tagente_modulo', 'id_agente_modulo', $id); + // Nombre. + $link = sprintf( + 'index.php?sec=view&sec2=operation/agentes/status_monitor%s&ag_modulename=%s', + '&refr=0&ag_group=0&module_option=1&status=-1', + $data['nombre'] + ); echo '
'; echo '

'.__('Module name').'

'; - echo ''.$data['nombre'].''; + echo ''.$data['nombre'].''; echo '
'; // Descripcion. + $description = (empty($data['descripcion']) === true) ? '-' : $data['descripcion']; echo '
'; - echo '

'.__('Description').'

'; - echo '

'.$data['descripcion'].'

'; + echo '

'.__('Description').'

'; + echo '

'.$description.'

'; echo '
'; // Agent. @@ -268,9 +280,13 @@ if (is_ajax() === true) { echo ''; // Group. + $group = (empty($data['id_module_group']) === true) + ? '-' + : modules_get_modulegroup_name($data['id_module_group']); + echo '
'; - echo '

'.__('Group').'

'; - echo '

'.modules_get_modulegroup_name($data['id_module_group']).'

'; + echo '

'.__('Module group').'

'; + echo '

'.$group.'

'; echo '
'; // Tag. @@ -317,17 +333,25 @@ if (is_ajax() === true) { echo ''; // Group. + $secondary_groups = ''; + $secondary = agents_get_secondary_groups($data['id_agente']); + if (isset($secondary['for_select']) === true && empty($secondary['for_select']) === false) { + $secondary_groups = implode(', ', $secondary['for_select']); + $secondary_groups = ', '.$secondary_groups; + } + echo '
'; echo '

'.__('Group').'

'; - echo '

'.groups_get_name($data['id_grupo']).'

'; + echo '

'.groups_get_name($data['id_grupo']).$secondary_groups.'

'; echo '
'; + // Events. echo '
'; echo graph_graphic_agentevents( $id, 100, - 80, + 40, SECONDS_1DAY, '', true, diff --git a/pandora_console/include/class/Heatmap.class.php b/pandora_console/include/class/Heatmap.class.php index 2f448df4a4..3f70d29a27 100644 --- a/pandora_console/include/class/Heatmap.class.php +++ b/pandora_console/include/class/Heatmap.class.php @@ -112,7 +112,7 @@ class Heatmap int $type=0, array $filter=[], string $randomId=null, - int $refresh=300, + int $refresh=180, int $width=0, int $height=0, string $search=null, @@ -230,6 +230,8 @@ class Heatmap }, (refresh * 1000) ); + } else { + location.reload(); } } }); @@ -307,8 +309,7 @@ class Heatmap $id_grupo = ''; if (empty($this->filter) === false && current($this->filter) != 0) { - $filter['id_grupo'] = current($this->filter); - $id_grupo = ' AND id_grupo = '.current($this->filter); + $id_grupo = ' AND id_grupo IN ('.implode(',', $this->filter).')'; } // All agents. @@ -380,7 +381,7 @@ class Heatmap { $filter_group = ''; if (empty($this->filter) === false && current($this->filter) != -1) { - $filter_group = 'AND am.id_module_group ='.current($this->filter); + $filter_group = 'AND am.id_module_group IN ('.implode(',', $this->filter).')'; } $filter_name = ''; @@ -477,9 +478,8 @@ class Heatmap { $filter_tag = ''; if (empty($this->filter) === false && $this->filter[0] !== '0') { - foreach ($this->filter as $key => $value) { - $filter_tag .= ' AND tm.id_tag ='.$value; - } + $tags = implode(',', $this->filter); + $filter_tag .= ' AND tm.id_tag IN ('.$tags.')'; } $filter_name = ''; @@ -680,11 +680,22 @@ class Heatmap { $result = $this->getData(); - $scale = ($this->width / $this->height); + if (empty($result) === true) { + echo '
'.__('No data found').'
'; + return; + } - $Yaxis = $this->getYAxis(count($result), $scale); - $Xaxis = (int) ceil($Yaxis * $scale); - $Yaxis = ceil($Yaxis); + $count_result = count($result); + + $scale = ($this->width / $this->height); + $Yaxis = $this->getYAxis($count_result, $scale); + if ($count_result <= 3) { + $Xaxis = $count_result; + $Yaxis = 1; + } else { + $Xaxis = (int) ceil($Yaxis * $scale); + $Yaxis = ceil($Yaxis); + } $viewBox = sprintf( '0 0 %d %d', @@ -728,7 +739,7 @@ class Heatmap modal: true, closeOnEscape: true, height: 400, - width: 430, + width: 530, title: '', open: function() { $.ajax({ @@ -755,7 +766,15 @@ class Heatmap $x_back = 0; $y_back = 0; - echo ''; + if ($count_result <= 100) { + $fontSize = 'small-size'; + $stroke = 'small-stroke'; + } else { + $fontSize = 'big-size'; + $stroke = 'big-stroke'; + } + + echo ''; foreach ($groups as $key => $group) { $name = ''; switch ($this->type) { @@ -786,7 +805,7 @@ class Heatmap ($y_back + 1) ); - echo ''; + echo ''; } $points = sprintf( @@ -799,11 +818,11 @@ class Heatmap $y_back ); - echo ''; + echo ''; // Name. echo ''.$name.''; + class="'.$fontSize.'">'.$name.''; $x_back = $x_position; if ($x_position === $Xaxis) { @@ -815,7 +834,7 @@ class Heatmap ($y_back + 1) ); - echo ''; + echo ''; $y_back++; $x_back = 0; @@ -838,7 +857,7 @@ class Heatmap ($y_position) ); - echo ''; + echo ''; } // Bottom of last line. @@ -850,11 +869,11 @@ class Heatmap ($y_position + 1) ); - echo ''; + echo ''; // Name. echo ''.$name.''; + class="'.$fontSize.'">'.$name.''; // Bottom-right of last line. $points = sprintf( @@ -865,7 +884,7 @@ class Heatmap ($y_position + 1) ); - echo ''; + echo ''; if ($x_position > $x_back) { // Bottom-top of last line. @@ -877,7 +896,7 @@ class Heatmap ($y_position) ); - echo ''; + echo ''; } } else { // Two or more lines. @@ -896,7 +915,7 @@ class Heatmap ($y_position + 1) ); - echo ''; + echo ''; // Bottom-right of last line. $points = sprintf( @@ -907,11 +926,11 @@ class Heatmap ($y_position + 1) ); - echo ''; + echo ''; // Name. echo ''.$name.''; + class="'.$fontSize.'">'.$name.''; // Bottom-top of last line. $points = sprintf( @@ -922,7 +941,7 @@ class Heatmap ($y_position) ); - echo ''; + echo ''; } if ($x_position === $Xaxis) { diff --git a/pandora_console/include/styles/heatmap.css b/pandora_console/include/styles/heatmap.css index 2e9533c339..bac09b561e 100644 --- a/pandora_console/include/styles/heatmap.css +++ b/pandora_console/include/styles/heatmap.css @@ -253,3 +253,19 @@ div#heatmap-controls div.heatmap-refr > div { stroke: black; stroke-width: 0.05; } + +.small-stroke { + stroke-width: 0.03; +} + +.big-stroke { + stroke-width: 0.05; +} + +.small-size { + font-size: 0.2px; +} + +.big-size { + font-size: 0.4px; +} diff --git a/pandora_console/operation/heatmap.php b/pandora_console/operation/heatmap.php index 9f7d4cee4d..59f97048a9 100644 --- a/pandora_console/operation/heatmap.php +++ b/pandora_console/operation/heatmap.php @@ -45,7 +45,7 @@ require_once $config['homedir'].'/include/class/Heatmap.class.php'; $pure = (bool) get_parameter('pure', false); $type = get_parameter('type', 0); $randomId = get_parameter('randomId', null); -$refresh = get_parameter('refresh', 30); +$refresh = get_parameter('refresh', 180); $height = get_parameter('height', 0); $width = get_parameter('width', 0); $search = get_parameter('search', ''); @@ -274,7 +274,7 @@ if ($is_ajax === true) { draggable: false, modal: true, closeOnEscape: true, - height: 370, + height: 410, width: 330, title: '', position: {