From 645257f9dc3b919c48930668d834a1246da1811a Mon Sep 17 00:00:00 2001 From: Daniel Barbero Martin Date: Tue, 1 Feb 2022 11:29:25 +0100 Subject: [PATCH] alert template schedule pandora_enterprise#3943 --- pandora_console/godmode/alerts/alert_view.php | 108 ++---------------- .../alerts/configure_alert_template.php | 60 ++++++---- pandora_console/include/functions_alerts.php | 59 ++++++++++ pandora_console/include/styles/alert.css | 7 +- 4 files changed, 107 insertions(+), 127 deletions(-) diff --git a/pandora_console/godmode/alerts/alert_view.php b/pandora_console/godmode/alerts/alert_view.php index cc467b99f8..62d84167e6 100644 --- a/pandora_console/godmode/alerts/alert_view.php +++ b/pandora_console/godmode/alerts/alert_view.php @@ -206,105 +206,15 @@ $data[0] = $condition; $table_conditions->data[] = $data; -// DAYS -$table_days->class = 'databox alert_days'; -$table_days->width = '100%'; -$table_days->size = []; -$table_days->data = []; -$table_days->style = []; -$table_days->styleTable = 'padding: 1px; margin: 0px; text-align: center; height: 80px;'; -$table_days->head[0] = __('Mon'); -$table_days->head[1] = __('Tue'); -$table_days->head[2] = __('Wed'); -$table_days->head[3] = __('Thu'); -$table_days->head[4] = __('Fri'); -$table_days->head[5] = __('Sat'); -$table_days->head[6] = __('Sun'); -$table_days->data[0] = array_fill(0, 7, html_print_image('images/blade.png', true)); - -$days = []; -if ($template['monday']) { - $table_days->data[0][0] = html_print_image('images/tick.png', true, ['class' => 'invert_filter']); -} - -if ($template['tuesday']) { - $table_days->data[0][1] = html_print_image('images/tick.png', true, ['class' => 'invert_filter']); -} - -if ($template['wednesday']) { - $table_days->data[0][2] = html_print_image('images/tick.png', true, ['class' => 'invert_filter']); -} - -if ($template['thursday']) { - $table_days->data[0][3] = html_print_image('images/tick.png', true, ['class' => 'invert_filter']); -} - -if ($template['friday']) { - $table_days->data[0][4] = html_print_image('images/tick.png', true, ['class' => 'invert_filter']); -} - -if ($template['saturday']) { - $table_days->data[0][5] = html_print_image('images/tick.png', true, ['class' => 'invert_filter']); -} - -if ($template['sunday']) { - $table_days->data[0][6] = html_print_image('images/tick.png', true, ['class' => 'invert_filter']); -} - -$data[0] = html_print_table($table_days, true); -unset($table_days); - -// TIME -$table_time->class = 'databox alert_time'; -$table_time->width = '100%'; -$table_time->size = []; -$table_time->data = []; -$table_time->style = []; -$table_time->styleTable = 'padding: 1px; margin: 0px; text-align: center; height: 80px; width: 100%;'; - -// $data[0] = __('Time from') . ' / ' . __('Time to'); -if ($template['time_from'] == $template['time_to']) { - $table_time->head[0] = '00:00:00
-
23:59:59'; - $table_time->data[0][0] = html_print_image('images/tick.png', true, ['class' => 'invert_filter']); -} else { - $from_array = explode(':', $template['time_from']); - $from = ($from_array[0] * SECONDS_1HOUR + $from_array[1] * SECONDS_1MINUTE + $from_array[2]); - $to_array = explode(':', $template['time_to']); - $to = ($to_array[0] * SECONDS_1HOUR + $to_array[1] * SECONDS_1MINUTE + $to_array[2]); - if ($to > $from) { - if ($template['time_from'] != '00:00:00') { - $table_time->head[0] = '00:00:00
-
'.$template['time_from']; - $table_time->data[0][0] = html_print_image('images/blade.png', true); - } - - $table_time->head[1] = $template['time_from'].'
-
'.$template['time_to']; - $table_time->data[0][1] = html_print_image('images/tick.png', true, ['class' => 'invert_filter']); - - if ($template['time_to'] != '23:59:59') { - $table_time->head[2] = $template['time_to'].'
-
23:59:59'; - $table_time->data[0][2] = html_print_image('images/blade.png', true); - } - } else { - if ($template['time_to'] != '00:00:00') { - $table_time->head[0] = '00:00:00
-
'.$template['time_to']; - $table_time->data[0][0] = html_print_image('images/tick.png', true, ['class' => 'invert_filter']); - } - - $table_time->head[1] = $template['time_to'].'
-
'.$template['time_from']; - $table_time->data[0][1] = html_print_image('images/blade.png', true, ['class' => 'invert_filter']); - - if ($template['time_from'] != '23:59:59') { - $table_time->head[2] = $template['time_from'].'
-
23:59:59'; - $table_time->data[0][2] = html_print_image('images/tick.png', true, ['class' => 'invert_filter']); - } - } - - $data[1] = $template['time_from'].' / '.$template['time_to']; -} - -$data[1] = html_print_table($table_time, true); -unset($table_time); - +$table_conditions->colspan[1][0] = 2; +$schedule = json_decode( + io_safe_output( + $template['schedule'] + ), + true +); +$data[0] = drawInfoSchedule($schedule, 'databox alert_days'); +$data[1] = ''; $table_conditions->data[] = $data; $data[0] = __('Use special days list'); diff --git a/pandora_console/godmode/alerts/configure_alert_template.php b/pandora_console/godmode/alerts/configure_alert_template.php index 399b30ba86..c86952e5e6 100644 --- a/pandora_console/godmode/alerts/configure_alert_template.php +++ b/pandora_console/godmode/alerts/configure_alert_template.php @@ -1,16 +1,31 @@ '; - if (defined('METACONSOLE')) { + if (is_metaconsole() === true) { $sec = 'advanced'; } else { $sec = 'galertas'; @@ -256,7 +271,7 @@ function update_template($step) return false; } - if (defined('METACONSOLE')) { + if (is_metaconsole() === true) { $sec = 'advanced'; } else { $sec = 'galertas'; @@ -558,7 +573,7 @@ $table = new stdClass(); $table->id = 'template'; $table->width = '100%'; $table->class = 'databox filters'; -if (defined('METACONSOLE')) { +if (is_metaconsole() === true) { $table->head[0] = __('Create Template'); $table->head_colspan[0] = 4; $table->headstyle[0] = 'text-align: center'; @@ -623,7 +638,7 @@ if ($step == 2) { '', true ); - $table->data[1][1] .= '
'; + $table->data[1][1] .= '
'; $table->data[1][1] .= html_print_input_hidden('schedule', $schedule, true); $table->colspan['threshold'][1] = 3; @@ -716,8 +731,7 @@ if ($step == 2) { ); $sql_query = sprintf( - ' - SELECT id, name + 'SELECT id, name FROM talert_actions WHERE id_group IN (%s) ORDER BY name', @@ -1085,7 +1099,7 @@ if ($step == 2) { (!$is_management_allowed | $disabled) ); - if (defined('METACONSOLE')) { + if (is_metaconsole() === true) { $table->data[3][0] = __('Wizard level'); $wizard_levels = [ 'nowizard' => __('No wizard'), diff --git a/pandora_console/include/functions_alerts.php b/pandora_console/include/functions_alerts.php index 2b44308ebc..b9b4e33b52 100644 --- a/pandora_console/include/functions_alerts.php +++ b/pandora_console/include/functions_alerts.php @@ -3390,3 +3390,62 @@ function alerts_get_templates_name_array($array_ids) return $result; } + + +/** + * Draw schedule info + * + * @param array $schedule + * + * @return string + */ +function drawInfoSchedule($schedule, $class='info_table') +{ + $table_days = new stdClass(); + $table_days->width = '100%'; + $table_days->class = $class; + $table_days->data = []; + $table_days->styleTable = 'text-align: center;'; + $table_days->head['monday'] = __('Mon'); + $table_days->head['tuesday'] = __('Tue'); + $table_days->head['wednesday'] = __('Wed'); + $table_days->head['thursday'] = __('Thu'); + $table_days->head['friday'] = __('Fri'); + $table_days->head['saturday'] = __('Sat'); + $table_days->head['sunday'] = __('Sun'); + + $week = [ + 'monday', + 'tuesday', + 'wednesday', + 'thursday', + 'friday', + 'saturday', + 'sunday', + ]; + + foreach ($week as $day) { + $table_days->data[0][$day] = html_print_image( + 'images/blade.png', + true, + ['class' => 'invert_filter'] + ); + } + + foreach ($schedule as $day => $sch) { + if (isset($sch) === true && empty($sch) === false) { + $table_days->data[0][$day] = ''; + foreach ($sch as $value) { + $table_days->data[0][$day] .= '

'; + $table_days->data[0][$day] .= ''.__('From').': '; + $table_days->data[0][$day] .= ''.$value['start'].''; + + $table_days->data[0][$day] .= ' '.__('To').': '; + $table_days->data[0][$day] .= ''.$value['end'].''; + $table_days->data[0][$day] .= '

'; + } + } + } + + return \html_print_table($table_days, true); +} diff --git a/pandora_console/include/styles/alert.css b/pandora_console/include/styles/alert.css index a18d1eb9d6..15f8cb367e 100644 --- a/pandora_console/include/styles/alert.css +++ b/pandora_console/include/styles/alert.css @@ -248,14 +248,11 @@ div#rules.show { } .info-item { - width: 25%; -} - -.info-days { - width: 65%; + width: 100%; } .info-item table.info_table thead tr th { + min-width: 150px; text-align: center; }