diff --git a/pandora_console/godmode/agentes/planned_downtime.editor.php b/pandora_console/godmode/agentes/planned_downtime.editor.php index 87c2f75060..f540de54b0 100755 --- a/pandora_console/godmode/agentes/planned_downtime.editor.php +++ b/pandora_console/godmode/agentes/planned_downtime.editor.php @@ -152,10 +152,10 @@ if ($create_downtime || $update_downtime) { $datetime_to = strtotime ($once_date_to . ' ' . $once_time_to); $now = strtotime(date(DATE_FORMAT). ' ' . date(TIME_FORMAT)); - if ($datetime_from < $now) { + if ($type_execution == 'once' && $datetime_from < $now) { ui_print_error_message(__('Not created. Error inserting data. Start time must be higher than the current time' )); } - else if ($datetime_from >= $datetime_to) { + else if ($type_execution == 'once' && $datetime_from >= $datetime_to) { ui_print_error_message(__('Not created. Error inserting data' ). ': START >= END'); } diff --git a/pandora_console/godmode/agentes/planned_downtime.export_csv.php b/pandora_console/godmode/agentes/planned_downtime.export_csv.php new file mode 100644 index 0000000000..da4fd6564b --- /dev/null +++ b/pandora_console/godmode/agentes/planned_downtime.export_csv.php @@ -0,0 +1,215 @@ += '".strtotime("$date_from 00:00:00")."'))"; +} + +if (!empty($date_to)) { + $periodically_monthly_w = "type_periodicity = 'monthly' AND (periodically_day_from <= '".date('d', strtotime($date_from))."' AND periodically_time_to >= '".date('d', strtotime($date_to))."')"; + + $periodically_weekly_days = array(); + $date_from_aux = strtotime($date_from); + $date_end = strtotime($date_to); + $days_number = 0; + + while ($date_from_aux <= $date_end && $days_number < 7) { + $weekday_actual = strtolower(date('l', $date_from_aux)); + + $periodically_weekly_days[] = "$weekday_actual = 1"; + + $date_from_aux = $date_from_aux + SECONDS_1DAY; + $days_number++; + } + + $periodically_weekly_w = "type_periodicity = 'weekly' AND (".implode(" OR ", $periodically_weekly_days).")"; + + $periodically_w = "type_execution = 'periodically' AND (($periodically_monthly_w) OR ($periodically_weekly_w))"; + + $once_w = "type_execution = 'once' AND date_to <= '".strtotime("$date_to 23:59:59")."'"; + + $where_values .= " AND (($periodically_w) OR ($once_w))"; +} + +if (!$show_archived) { + $where_values .= " AND (type_execution = 'periodically' OR (type_execution = 'once' AND date_to >= '".time()."'))"; +} + +if (!empty($agent_id)) { + $where_values .= " AND id IN (SELECT id_downtime FROM tplanned_downtime_agents WHERE id_agent = $agent_id)"; +} + +if (!empty($module_id)) { + $where_values .= " AND (id IN (SELECT id_downtime + FROM tplanned_downtime_modules + WHERE id_agent_module = $module_id) + OR id IN (SELECT id_downtime + FROM tplanned_downtime_agents tpda, tagente_modulo tam + WHERE tpda.id_agent = tam.id_agente + AND tam.id_agente_modulo = $module_id + AND tpda.all_modules = 1))"; +} + +$sql = "SELECT * + FROM tplanned_downtime + WHERE $where_values + ORDER BY type_execution DESC, date_from DESC"; +$downtimes = @db_get_all_rows_sql($sql); +html_debug_print($sql); +html_debug_print($downtimes); +if (!empty($downtimes)) { + ob_clean(); + // Show contentype header + Header("Content-type: text/csv"); + header('Content-Disposition: attachment; filename="pandora_planned_downtime_'.date("Y/m/d H:i:s").'.csv"'); + + $titles = array(); + $titles[] = "id"; + $titles[] = "name"; + $titles[] = "description"; + $titles[] = "group"; + $titles[] = "type"; + $titles[] = "execution_type"; + $titles[] = "execution_date"; + + echo implode($separator, $titles); + echo chr(13); + + foreach ($downtimes as $downtime) { + $id = $downtime['id']; + $name = io_safe_output($downtime['name']); + $description = io_safe_output($downtime['description']); + $group = ucfirst(io_safe_output(groups_get_name($downtime['id_group']))); + $type = ucfirst(io_safe_output($downtime['type_downtime'])); + $execution_type = ucfirst(io_safe_output($downtime['type_execution'])); + + switch ($downtime['type_execution']) { + case 'once': + $execution_date = date ("Y-m-d H:i", $downtime['date_from']) . + " " . __('to') . " ". + date ("Y-m-d H:i", $downtime['date_to']); + break; + case 'periodically': + switch ($downtime['type_periodicity']) { + case 'weekly': + $execution_date = __('Weekly:'); + $execution_date .= " "; + if ($downtime['monday']) { + $execution_date .= __('Mon'); + $execution_date .= " "; + } + if ($downtime['tuesday']) { + $execution_date .= __('Tue'); + $execution_date .= " "; + } + if ($downtime['wednesday']) { + $execution_date .= __('Wed'); + $execution_date .= " "; + } + if ($downtime['thursday']) { + $execution_date .= __('Thu'); + $execution_date .= " "; + } + if ($downtime['friday']) { + $execution_date .= __('Fri'); + $execution_date .= " "; + } + if ($downtime['saturday']) { + $execution_date .= __('Sat'); + $execution_date .= " "; + } + if ($downtime['sunday']) { + $execution_date .= __('Sun'); + $execution_date .= " "; + } + $execution_date .= " (" . $downtime['periodically_time_from']; + $execution_date .= "-" . $downtime['periodically_time_to'] . ")"; + break; + case 'monthly': + $execution_date = __('Monthly:'); + $execution_date .= __('From day') . " " . $downtime['periodically_day_from']; + $execution_date .= "/" . __('To day') . " "; + $execution_date .= $downtime['periodically_day_to']; + $execution_date .= " (" . $downtime['periodically_time_from']; + $execution_date .= "-" . $downtime['periodically_time_to'] . ")"; + break; + } + break; + } + $execution_date = io_safe_output($execution_date); + + $values = array(); + $values[] = $id; + $values[] = $name; + $values[] = $description; + $values[] = $group; + $values[] = $type; + $values[] = $execution_type; + $values[] = $execution_date; + + echo implode($separator, $values); + echo chr(13); + } +} +else { + echo '
'.__('No planned downtime').'
'; +} +?> \ No newline at end of file diff --git a/pandora_console/godmode/agentes/planned_downtime.list.php b/pandora_console/godmode/agentes/planned_downtime.list.php index e14ee776b0..c9dc4eb5cc 100755 --- a/pandora_console/godmode/agentes/planned_downtime.list.php +++ b/pandora_console/godmode/agentes/planned_downtime.list.php @@ -180,9 +180,95 @@ if ($delete_downtime) { } } -$groups = users_get_groups (); +// Filter parameters +$offset = (int) get_parameter('offset'); +$search_text = (string) get_parameter('search_text'); +$date_from = (string) get_parameter('date_from'); +$date_to = (string) get_parameter('date_to'); +$execution_type = (string) get_parameter('execution_type'); +$show_archived = (bool) get_parameter('archived'); +$agent_id = (int) get_parameter('agent_id'); +$agent_name = !empty($agent_id) ? (string) get_parameter('agent_name') : ""; +$module_id = (int) get_parameter('module_name_hidden'); +$module_name = !empty($module_id) ? (string) get_parameter('module_name') : ""; + +$filter_params = array(); +$filter_params['search_text'] = $search_text; +$filter_params['date_from'] = $date_from; +$filter_params['date_to'] = $date_to; +$filter_params['execution_type'] = $execution_type; +$filter_params['archived'] = $show_archived; +$filter_params['agent_id'] = $agent_id; +$filter_params['agent_name'] = $agent_name; +$filter_params['module_id'] = $module_id; +$filter_params['module_name'] = $module_name; + +$filter_params_aux = array(); +foreach ($filter_params as $name => $value) { + $filter_params_aux[] = is_bool($value) ? $name."=".(int)$value : "$name=$value"; +} +$filter_params_str = !empty($filter_params_aux) ? implode("&", $filter_params_aux) : ""; + +// Table filter +$table = new StdClass(); +$table->class = 'databox'; +$table->width = '99%'; +$table->rowstyle = array(); +$table->rowstyle[0] = "background-color: #f9faf9;"; +$table->rowstyle[1] = "background-color: #f9faf9;"; +$table->rowstyle[2] = "background-color: #f9faf9;"; +$table->data = array(); + +$row = array(); + +// Search text +$row[] = __('Search') . ' ' . html_print_input_text("search_text", $search_text, '', 50, 250, true); +// Dates +$date_inputs = __('From') . ' ' . html_print_input_text('date_from', $date_from, '', 10, 10, true); +$date_inputs .= "  "; +$date_inputs .= __('To') . ' ' . html_print_input_text('date_to', $date_to, '', 10, 10, true); +$row[] = $date_inputs; + +$table->data[] = $row; + +$row = array(); + +// Execution type +$execution_type_fields = array('once' => __('Once'), 'periodically' => __('Periodically')); +$row[] = __('Execution type') . ' ' . html_print_select($execution_type_fields, 'execution_type', $execution_type, '', __('Any'), '', true, false, false); +// Show past downtimes +$row[] = __('Show past downtimes') . ' ' . html_print_checkbox ("archived", 1, $show_archived, true); + +$table->data[] = $row; + +$row = array(); + +// Agent +$params = array(); +$params['show_helptip'] = true; +$params['input_name'] = 'agent_name'; +$params['value'] = $agent_name; +$params['return'] = true; +$params['print_hidden_input_idagent'] = true; +$params['hidden_input_idagent_name'] = 'agent_id'; +$params['hidden_input_idagent_value'] = $agent_id; +$agent_input = __('Agent') . ' ' . ui_print_agent_autocomplete_input($params); +$row[] = $agent_input; + +// Module +$module_input = __('Module') . ' ' . html_print_autocomplete_modules('module_name', $module_name, false, true, '', array(), true); +$row[] = $module_input; + +$row[] = html_print_submit_button('Search', 'search', false, 'class="sub search"', true); + +$table->data[] = $row; + +echo "
"; +html_print_table($table); +echo "
"; // View available downtimes present in database (if any of them) +$table = new StdClass(); $table->class = 'databox'; //Start Overview of existing planned downtime $table->width = '98%'; @@ -194,10 +280,10 @@ $table->head[2] = __('Group'); $table->head[3] = __('Type'); $table->head[4] = __('Execution'); $table->head[5] = __('Configuration'); -$table->head[6] = __('Delete'); -$table->head[7] = __('Update'); -$table->head[8] = __('Running'); -$table->head[9] = __('Stop downtime'); +$table->head[6] = __('Running'); +$table->head[7] = __('Stop downtime'); +$table->head[8] = __('Edit'); +$table->head[9] = __('Delete'); $table->align[2] = "center"; //$table->align[5] = "center"; $table->align[6] = "center"; @@ -205,11 +291,82 @@ $table->align[7] = "center"; $table->align[8] = "center"; $table->align[9] = "center"; +$groups = users_get_groups (); if(!empty($groups)) { + $where_values = "1=1"; + + $groups_string = implode (",", array_keys ($groups)); + $where_values .= " AND id_group IN ($groups_string)"; + + if (!empty($search_text)) { + $where_values .= " AND (name LIKE '%$search_text%' OR description LIKE '%$search_text%')"; + } + + if (!empty($execution_type)) { + $where_values .= " AND type_execution = '$execution_type'"; + } + + if (!empty($date_from)) { + $where_values .= " AND (type_execution = 'periodically' OR (type_execution = 'once' AND date_from >= '".strtotime("$date_from 00:00:00")."'))"; + } + + if (!empty($date_to)) { + $periodically_monthly_w = "type_periodicity = 'monthly' AND (periodically_day_from <= '".date('d', strtotime($date_from))."' AND periodically_time_to >= '".date('d', strtotime($date_to))."')"; + + $periodically_weekly_days = array(); + $date_from_aux = strtotime($date_from); + $date_end = strtotime($date_to); + $days_number = 0; + + while ($date_from_aux <= $date_end && $days_number < 7) { + $weekday_actual = strtolower(date('l', $date_from_aux)); + + $periodically_weekly_days[] = "$weekday_actual = 1"; + + $date_from_aux = $date_from_aux + SECONDS_1DAY; + $days_number++; + } + + $periodically_weekly_w = "type_periodicity = 'weekly' AND (".implode(" OR ", $periodically_weekly_days).")"; + + $periodically_w = "type_execution = 'periodically' AND (($periodically_monthly_w) OR ($periodically_weekly_w))"; + + $once_w = "type_execution = 'once' AND date_to <= '".strtotime("$date_to 23:59:59")."'"; + + $where_values .= " AND (($periodically_w) OR ($once_w))"; + } + + if (!$show_archived) { + $where_values .= " AND (type_execution = 'periodically' OR (type_execution = 'once' AND date_to >= '".time()."'))"; + } + + if (!empty($agent_id)) { + $where_values .= " AND id IN (SELECT id_downtime FROM tplanned_downtime_agents WHERE id_agent = $agent_id)"; + } + + if (!empty($module_id)) { + $where_values .= " AND (id IN (SELECT id_downtime + FROM tplanned_downtime_modules + WHERE id_agent_module = $module_id) + OR id IN (SELECT id_downtime + FROM tplanned_downtime_agents tpda, tagente_modulo tam + WHERE tpda.id_agent = tam.id_agente + AND tam.id_agente_modulo = $module_id + AND tpda.all_modules = 1))"; + } + $sql = "SELECT * - FROM tplanned_downtime - WHERE id_group IN (" . implode (",", array_keys ($groups)) . ")"; + FROM tplanned_downtime + WHERE $where_values + ORDER BY type_execution DESC, date_from DESC + LIMIT ".$config["block_size"]." + OFFSET $offset"; + $sql_count = "SELECT COUNT(id) AS num + FROM tplanned_downtime + WHERE $where_values"; $downtimes = db_get_all_rows_sql ($sql); + $downtimes_number_res = db_get_all_rows_sql($sql_count); + $downtimes_number = $downtimes_number_res != false ? $downtimes_number_res[0]['num'] : 0; } else { $downtimes = array(); @@ -219,6 +376,8 @@ if (!$downtimes) { echo '
'.__('No planned downtime').'
'; } else { + ui_pagination($downtimes_number, "index.php?sec=estado&sec2=godmode/agentes/planned_downtime.list&$filter_params_str", $offset); + foreach ($downtimes as $downtime) { $data = array(); $total = db_get_sql ("SELECT COUNT(id_agent) @@ -295,44 +454,71 @@ else { } if ($downtime["executed"] == 0) { - $data[6] = '' . - html_print_image("images/cross.png", true, array("border" => '0', "alt" => __('Delete'))); - $data[7] = '' . - html_print_image("images/config.png", true, array("border" => '0', "alt" => __('Update'))) . ''; - } - else { - $data[6]= "N/A"; - $data[7]= "N/A"; - - } - if ($downtime["executed"] == 0) { - $data[8] = html_print_image ("images/pixel_red.png", true, + $data[6] = html_print_image ("images/pixel_red.png", true, array ('width' => 20, 'height' => 20, 'alt' => __('Executed'))); } else { - $data[8] = html_print_image ("images/pixel_green.png", true, + $data[6] = html_print_image ("images/pixel_green.png", true, array ('width' => 20, 'height' => 20, 'alt' => __('Not executed'))); } - - if (($downtime['type_execution'] == 'once') - && ($downtime["executed"] == 1)) { + if ($downtime['type_execution'] == 'once' && $downtime["executed"] == 1) { - $data[9] = '' . html_print_image("images/cancel.png", true, array("border" => '0', "alt" => __('Stop downtime'))); } + else { + $data[7] = ""; + } + if ($downtime["executed"] == 0) { + $data[8] = '' . + html_print_image("images/config.png", true, array("border" => '0', "alt" => __('Update'))) . ''; + $data[9] = '' . + html_print_image("images/cross.png", true, array("border" => '0', "alt" => __('Delete'))); + } + else { + $data[8]= "N/A"; + $data[9]= "N/A"; + + } array_push ($table->data, $data); } html_print_table ($table); } echo '
'; -echo '
'; +echo '
'; +echo '
'; +html_print_button(__('Export to CSV'), 'csv_export', false, "location.href='godmode/agentes/planned_downtime.export_csv.php?$filter_params_str'", 'class="sub next"'); +echo '
'; +echo ' '; +echo ''; html_print_submit_button (__('Create'), 'create', false, 'class="sub next"'); echo '
'; echo '
'; + + +ui_require_jquery_file("ui.datepicker-" . get_user_language(), "include/javascript/i18n/"); + +?> + \ No newline at end of file