diff --git a/pandora_console/godmode/agentes/planned_downtime.editor.php b/pandora_console/godmode/agentes/planned_downtime.editor.php
index 44312abe7f..c0ae46623a 100755
--- a/pandora_console/godmode/agentes/planned_downtime.editor.php
+++ b/pandora_console/godmode/agentes/planned_downtime.editor.php
@@ -29,6 +29,12 @@ $config["past_planned_downtimes"] = isset($config["past_planned_downtimes"]) ? $
require_once ('include/functions_users.php');
+// Buttons
+$buttons = array(
+ 'text' => ""
+ . html_print_image ("images/list.png", true, array ("title" =>__('List'))) . ""
+ );
+
// Header
ui_print_page_header(
__("Planned Downtime"),
@@ -36,56 +42,52 @@ ui_print_page_header(
false,
"planned_downtime",
true,
- "");
-
-
+ $buttons);
//Initialize data
-$id_agent = get_parameter ("id_agent");
-$id_group = (int) get_parameter ("id_group", 0);
-$name = (string) get_parameter ('name', '');
-$description = (string) get_parameter ('description', '');
-$once_date_from = (string) get_parameter ('once_date_from', date(DATE_FORMAT));
-$once_time_from = (string) get_parameter ('once_time_from', date(TIME_FORMAT));
-$once_date_to = (string) get_parameter ('once_date_to', date(DATE_FORMAT));
-$once_time_to = (string) get_parameter ('once_time_to', date(TIME_FORMAT));
-$periodically_day_from = (int) get_parameter ('periodically_day_from', 1);
-$periodically_day_to = (int) get_parameter ('periodically_day_to', 31);
+$id_group = (int) get_parameter ('id_group');
+$name = (string) get_parameter ('name');
+$description = (string) get_parameter ('description');
+
+$type_downtime = (string) get_parameter('type_downtime', 'quiet');
+$type_execution = (string) get_parameter('type_execution', 'once');
+$type_periodicity = (string) get_parameter('type_periodicity', 'weekly');
+
+$once_date_from = (string) get_parameter ('once_date_from', date(DATE_FORMAT));
+$once_time_from = (string) get_parameter ('once_time_from', date(TIME_FORMAT));
+$once_date_to = (string) get_parameter ('once_date_to', date(DATE_FORMAT));
+$once_time_to = (string) get_parameter ('once_time_to', date(TIME_FORMAT, time() + SECONDS_1HOUR));
+
+$periodically_day_from = (int) get_parameter ('periodically_day_from', 1);
+$periodically_day_to = (int) get_parameter ('periodically_day_to', 31);
$periodically_time_from = (string) get_parameter ('periodically_time_from', date(TIME_FORMAT));
-$periodically_time_to = (string) get_parameter ('periodically_time_to', date(TIME_FORMAT, time() + SECONDS_1HOUR));
+$periodically_time_to = (string) get_parameter ('periodically_time_to', date(TIME_FORMAT, time() + SECONDS_1HOUR));
-$first_create = (int) get_parameter ('first_create', 0);
+$monday = (bool) get_parameter ('monday');
+$tuesday = (bool) get_parameter ('tuesday');
+$wednesday = (bool) get_parameter ('wednesday');
+$thursday = (bool) get_parameter ('thursday');
+$friday = (bool) get_parameter ('friday');
+$saturday = (bool) get_parameter ('saturday');
+$sunday = (bool) get_parameter ('sunday');
-$create_downtime = (int) get_parameter ('create_downtime');
+$first_create = (int) get_parameter ('first_create');
+$create_downtime = (int) get_parameter ('create_downtime');
+$update_downtime = (int) get_parameter ('update_downtime');
+$edit_downtime = (int) get_parameter ('edit_downtime');
+$id_downtime = (int) get_parameter ('id_downtime');
-
-$edit_downtime = (int) get_parameter ('edit_downtime');
-$update_downtime = (int) get_parameter ('update_downtime');
-$id_downtime = (int) get_parameter ('id_downtime',0);
-
-$insert_downtime_agent = (int) get_parameter ("insert_downtime_agent", 0);
-$delete_downtime_agent = (int) get_parameter ("delete_downtime_agent", 0);
+$id_agent = (int) get_parameter ('id_agent');
+$insert_downtime_agent = (int) get_parameter ('insert_downtime_agent');
+$delete_downtime_agent = (int) get_parameter ('delete_downtime_agent');
$groups = users_get_groups ();
-$type_downtime = get_parameter('type_downtime', 'quiet');
-$type_execution = get_parameter('type_execution', 'once');
-$type_periodicity = get_parameter('type_periodicity', 'weekly');
-
-$monday = (bool) get_parameter ('monday');
-$tuesday = (bool) get_parameter ('tuesday');
-$wednesday = (bool) get_parameter ('wednesday');
-$thursday = (bool) get_parameter ('thursday');
-$friday = (bool) get_parameter ('friday');
-$saturday = (bool) get_parameter ('saturday');
-$sunday = (bool) get_parameter ('sunday');
-
-
-
// INSERT A NEW DOWNTIME_AGENT ASSOCIATION
-if ($insert_downtime_agent == 1) {
- $agents = (array)get_parameter("id_agents", array());
- $module_names = (array)get_parameter("module", array());
+if ($insert_downtime_agent === 1) {
+ $agents = (array) get_parameter ('id_agents');
+ $module_names = (array) get_parameter ('module');
+
$all_modules = false;
if (empty($module_names)) {
$all_modules = true;
@@ -96,30 +98,37 @@ if ($insert_downtime_agent == 1) {
$all_modules = true;
}
- for ($a=0; $a < count($agents); $a++) {
- $id_agente_dt = $agents[$a];
-
-
- $values = array(
- 'id_downtime' => $id_downtime,
- 'id_agent' => $id_agente_dt,
- 'all_modules' => $all_modules);
-
- $result = db_process_sql_insert('tplanned_downtime_agents', $values);
- if ($result && !$all_modules) {
- foreach ($module_names as $module_name) {
- $module =
- modules_get_agentmodule_id($module_name, $id_agente_dt);
- $values = array(
+ $executed = db_get_value ('executed', 'tplanned_downtime', 'id', $id_downtime);
+ if ($executed == 1) {
+ ui_print_error_message(__("This elements cannot be modified while the downtime is being executed"));
+ }
+ else {
+ $num_agents = count($agents);
+ for ($a = 0; $a < $num_agents; $a++) {
+ $id_agente_dt = $agents[$a];
+
+ $values = array(
'id_downtime' => $id_downtime,
'id_agent' => $id_agente_dt,
- 'id_agent_module' => $module["id_agente_modulo"]);
- $result = db_process_sql_insert('tplanned_downtime_modules', $values);
-
- if ($result) {
- $values = array('id_user' => $config['id_user']);
- $result = db_process_sql_update('tplanned_downtime',
- $values, array('id' => $id_downtime));
+ 'all_modules' => $all_modules
+ );
+
+ $result = db_process_sql_insert('tplanned_downtime_agents', $values);
+ if ($result && !$all_modules) {
+ foreach ($module_names as $module_name) {
+ $module = modules_get_agentmodule_id($module_name, $id_agente_dt);
+ $values = array(
+ 'id_downtime' => $id_downtime,
+ 'id_agent' => $id_agente_dt,
+ 'id_agent_module' => $module["id_agente_modulo"]
+ );
+ $result = db_process_sql_insert('tplanned_downtime_modules', $values);
+
+ if ($result) {
+ $values = array('id_user' => $config['id_user']);
+ $result = db_process_sql_update('tplanned_downtime',
+ $values, array('id' => $id_downtime));
+ }
}
}
}
@@ -127,21 +136,25 @@ if ($insert_downtime_agent == 1) {
}
// DELETE A DOWNTIME_AGENT ASSOCIATION
-if ($delete_downtime_agent == 1) {
+if ($delete_downtime_agent === 1) {
- $id_da = (int)get_parameter ("id_downtime_agent", 0);
- $id_agent_delete = (int)get_parameter('id_agent', 0);
+ $id_da = (int) get_parameter ('id_downtime_agent');
- $row_to_delete = db_get_row('tplanned_downtime_agents', 'id', $id_da);
-
- $result = db_process_sql_delete('tplanned_downtime_agents',
- array('id' => $id_da));
-
- if ($result) {
- //Delete modules in downtime
- db_process_sql_delete('tplanned_downtime_modules',
- array('id_downtime' => $row_to_delete['id_downtime'],
- 'id_agent' => $id_agent_delete));
+ $executed = db_get_value ('executed', 'tplanned_downtime', 'id', $id_downtime);
+ if ($executed == 1) {
+ ui_print_error_message(__("This elements cannot be modified while the downtime is being executed"));
+ }
+ else {
+ $row_to_delete = db_get_row('tplanned_downtime_agents', 'id', $id_da);
+
+ $result = db_process_sql_delete('tplanned_downtime_agents', array('id' => $id_da));
+
+ if ($result) {
+ //Delete modules in downtime
+ db_process_sql_delete('tplanned_downtime_modules',
+ array('id_downtime' => $row_to_delete['id_downtime'],
+ 'id_agent' => $id_agent));
+ }
}
}
@@ -159,6 +172,9 @@ if ($create_downtime || $update_downtime) {
else if ($type_execution == 'once' && $datetime_from >= $datetime_to) {
ui_print_error_message(__('Not created. Error inserting data') . ". " .__('The end date must be higher than the start date'));
}
+ else if ($type_execution == 'once' && $datetime_to <= $now) {
+ ui_print_error_message(__('Not created. Error inserting data') . ". " .__('The end date must be higher than the current time'));
+ }
else if ($type_execution == 'periodically'
&& (($type_periodicity == 'weekly' && $periodically_time_from >= $periodically_time_to)
|| ($type_periodicity == 'monthly' && $periodically_day_from == $periodically_day_to && $periodically_time_from >= $periodically_time_to))) {
@@ -173,31 +189,35 @@ if ($create_downtime || $update_downtime) {
if (trim(io_safe_output($name)) != '') {
if (!$check) {
$values = array(
- 'name' => $name,
- 'description' => $description,
- 'date_from' => $datetime_from,
- 'date_to' => $datetime_to,
- 'executed' => 0,
- 'id_group' => $id_group,
- 'only_alerts' => 0,
- 'monday' => $monday,
- 'tuesday' => $tuesday,
- 'wednesday' => $wednesday,
- 'thursday' => $thursday,
- 'friday' => $friday,
- 'saturday' => $saturday,
- 'sunday' => $sunday,
- 'periodically_time_from' => $periodically_time_from,
- 'periodically_time_to' => $periodically_time_to,
- 'periodically_day_from' => $periodically_day_from,
- 'periodically_day_to' => $periodically_day_to,
- 'type_downtime' => $type_downtime,
- 'type_execution' => $type_execution,
- 'type_periodicity' => $type_periodicity,
- 'id_user' => $config['id_user']
+ 'name' => $name,
+ 'description' => $description,
+ 'date_from' => $datetime_from,
+ 'date_to' => $datetime_to,
+ 'executed' => 0,
+ 'id_group' => $id_group,
+ 'only_alerts' => 0,
+ 'monday' => $monday,
+ 'tuesday' => $tuesday,
+ 'wednesday' => $wednesday,
+ 'thursday' => $thursday,
+ 'friday' => $friday,
+ 'saturday' => $saturday,
+ 'sunday' => $sunday,
+ 'periodically_time_from' => $periodically_time_from,
+ 'periodically_time_to' => $periodically_time_to,
+ 'periodically_day_from' => $periodically_day_from,
+ 'periodically_day_to' => $periodically_day_to,
+ 'type_downtime' => $type_downtime,
+ 'type_execution' => $type_execution,
+ 'type_periodicity' => $type_periodicity,
+ 'id_user' => $config['id_user']
);
- $result = db_process_sql_insert(
- 'tplanned_downtime', $values);
+ if ($config["dbtype"] == 'oracle') {
+ $values['periodically_time_from'] = '1970/01/01 ' . $values['periodically_time_from'];
+ $values['periodically_time_to'] = '1970/01/01 ' . $values['periodically_time_to'];
+ }
+
+ $result = db_process_sql_insert('tplanned_downtime', $values);
}
else {
ui_print_error_message(
@@ -210,13 +230,27 @@ if ($create_downtime || $update_downtime) {
}
}
else if ($update_downtime) {
- if (trim(io_safe_output($name)) != '') {
+ $has_been_executed = db_get_value ('executed', 'tplanned_downtime', 'name', $name);
+ $values = array();
+ if (trim(io_safe_output($name)) == '') {
+ ui_print_error_message(__('Planned downtime must have a name'));
+ }
+ else if ($has_been_executed == 1 && $type_execution == 'once') {
+ $values = array(
+ 'description' => $description,
+ 'date_to' => $datetime_to,
+ 'id_user' => $config['id_user']
+ );
+ }
+ else if ($has_been_executed == 1) {
+ ui_print_error_message(__('No updates. Planned Downtime has been executed'));
+ }
+ else {
$values = array(
'name' => $name,
'description' => $description,
'date_from' => $datetime_from,
'date_to' => $datetime_to,
- 'executed' => 0,
'id_group' => $id_group,
'only_alerts' => 0,
'monday' => $monday,
@@ -235,11 +269,13 @@ if ($create_downtime || $update_downtime) {
'type_periodicity' => $type_periodicity,
'id_user' => $config['id_user']
);
- $result = db_process_sql_update('tplanned_downtime', $values, array('id' => $id_downtime));
+ if ($config["dbtype"] == 'oracle') {
+ $values['periodically_time_from'] = '1970/01/01 ' . $values['periodically_time_from'];
+ $values['periodically_time_to'] = '1970/01/01 ' . $values['periodically_time_to'];
+ }
}
- else {
- ui_print_error_message(
- __('Planned downtime must have a name'));
+ if (!empty($values)) {
+ $result = db_process_sql_update('tplanned_downtime', $values, array('id' => $id_downtime));
}
}
@@ -265,75 +301,119 @@ if ($create_downtime || $update_downtime) {
// Have any data to show ?
if ($id_downtime > 0) {
+ // Columns of the table tplanned_downtime
+ $columns = array(
+ 'id',
+ 'name',
+ 'description',
+ 'date_from',
+ 'date_to',
+ 'executed',
+ 'id_group',
+ 'only_alerts',
+ 'monday',
+ 'tuesday',
+ 'wednesday',
+ 'thursday',
+ 'friday',
+ 'saturday',
+ 'sunday',
+ 'periodically_time_from',
+ 'periodically_time_to',
+ 'periodically_day_from',
+ 'periodically_day_to',
+ 'type_downtime',
+ 'type_execution',
+ 'type_periodicity',
+ 'id_user',
+ );
+
switch ($config["dbtype"]) {
case "mysql":
- $sql = sprintf ("SELECT *
- FROM `tplanned_downtime`
- WHERE `id` = %d",
- $id_downtime);
- break;
case "postgresql":
- $sql = sprintf ("SELECT *
- FROM \"tplanned_downtime\"
- WHERE \"id\" = %d",
- $id_downtime);
+ $columns_str = implode(',', $columns);
+ $sql = "SELECT $columns_str
+ FROM tplanned_downtime
+ WHERE id = $id_downtime";
break;
case "oracle":
- $sql = sprintf ("SELECT *
- FROM tplanned_downtime
- WHERE id = %d",
- $id_downtime);
+ // Oracle doesn't have TIME type, so we should transform the DATE value
+ $new_time_from = "TO_CHAR(periodically_time_from, 'HH24:MI:SS') AS periodically_time_from";
+ $new_time_to = "TO_CHAR(periodically_time_to, 'HH24:MI:SS') AS periodically_time_to";
+
+ $time_from_key = array_search('periodically_time_from', $columns);
+ $time_to_key = array_search('periodically_time_to', $columns);
+
+ if ($time_from_key !== false)
+ $columns[$time_from_key] = $new_time_from;
+ if ($time_to_key !== false)
+ $columns[$time_to_key] = $new_time_to;
+
+ $columns_str = implode(',', $columns);
+ $sql = "SELECT $columns_str
+ FROM tplanned_downtime
+ WHERE id = $id_downtime";
break;
}
$result = db_get_row_sql ($sql);
- $name = $result["name"];
- $description = $result["description"];
- $once_date_from = date(DATE_FORMAT, $result["date_from"]);
- $once_date_to = date(DATE_FORMAT, $result["date_to"]);
- $once_time_from = date(TIME_FORMAT, $result["date_from"]);
- $once_time_to = date(TIME_FORMAT, $result["date_to"]);
- $monday = $result['monday'];
- $tuesday = $result['tuesday'];
- $wednesday = $result['wednesday'];
- $thursday = $result['thursday'];
- $friday = $result['friday'];
- $saturday = $result['saturday'];
- $sunday = $result['sunday'];
- $periodically_time_from = $result['periodically_time_from'];
- $periodically_time_to = $result['periodically_time_to'];
- $periodically_day_from = $result['periodically_day_from'];
- $periodically_day_to = $result['periodically_day_to'];
- $type_downtime = $result['type_downtime'];
- $type_execution = $result['type_execution'];
- $type_periodicity = $result['type_periodicity'];
- if ($id_group == 0)
- $id_group = $result['id_group'];
+ $name = (string) $result["name"];
+ $id_group = (int) $result['id_group'];
+ $description = (string) $result["description"];
+
+ $type_downtime = (string) $result['type_downtime'];
+ $type_execution = (string) $result['type_execution'];
+ $type_periodicity = (string) $result['type_periodicity'];
+
+ $once_date_from = date(DATE_FORMAT, $result["date_from"]);
+ $once_date_to = date(DATE_FORMAT, $result["date_to"]);
+ $once_time_from = date(TIME_FORMAT, $result["date_from"]);
+ $once_time_to = date(TIME_FORMAT, $result["date_to"]);
+
+ $periodically_time_from = (string) $result['periodically_time_from'];
+ $periodically_time_to = (string) $result['periodically_time_to'];
+ $periodically_day_from = (int) $result['periodically_day_from'];
+ $periodically_day_to = (int) $result['periodically_day_to'];
+
+ $monday = (bool) $result['monday'];
+ $tuesday = (bool) $result['tuesday'];
+ $wednesday = (bool) $result['wednesday'];
+ $thursday = (bool) $result['thursday'];
+ $friday = (bool) $result['friday'];
+ $saturday = (bool) $result['saturday'];
+ $sunday = (bool) $result['sunday'];
+
+ $executed = (bool) $result['executed'];
}
-$table->class = 'databox_color';
-$table->width = '98%';
+// when the planned down time is in execution, only action to postpone on once type is enabled and the other are disabled.
+$disabled_in_execution = $executed ? 1 : 0;
+
+$table = new StdClass();
+$table->class = 'databox filters';
+$table->width = '100%';
$table->data = array ();
$table->data[0][0] = __('Name');
-$table->data[0][1] = html_print_input_text ('name', $name, '', 25, 40, true);
+$table->data[0][1] = html_print_input_text ('name', $name, '', 25, 40, true, $disabled_in_execution);
$table->data[1][0] = __('Group');
-$table->data[1][1] = html_print_select_groups(false, "AW", true, 'id_group', $id_group, '', '', 0, true);
+$table->data[1][1] = html_print_select_groups(false, "AW", true, 'id_group', $id_group, '', '', 0, true, false, true, '', $disabled_in_execution);
$table->data[2][0] = __('Description');
$table->data[2][1] = html_print_textarea ('description', 3, 35, $description, '', true);
$table->data[3][0] = __('Type').ui_print_help_tip(__("Quiet: Disable modules that we indicate below.").'
'.
-__("Disable Agents: Disables the selected agents.").'
'.
-__("Disable Alerts: Disable alerts for the selected agents."), true);
+ __("Disable Agents: Disables the selected agents.").'
'.
+ __("Disable Alerts: Disable alerts for the selected agents."), true);
$table->data[3][1] = html_print_select(array('quiet' => __('Quiet'),
'disable_agents' => __('Disabled Agents'),
'disable_agents_alerts' => __('Disabled only Alerts')),
'type_downtime', $type_downtime, 'change_type_downtime()', '', 0, true, false, true,
- '');
+ '', $disabled_in_execution);
$table->data[4][0] = __('Execution');
$table->data[4][1] = html_print_select(array('once' => __('Once'),
'periodically' => __('Periodically')),
- 'type_execution', $type_execution, 'change_type_execution();', '', 0, true);
+ 'type_execution', $type_execution, 'change_type_execution();', '', 0, true,
+ false, true, '', $disabled_in_execution);
$days = array_combine(range(1, 31), range(1, 31));
$table->data[5][0] = __('Configure the time') . " " . ui_print_help_icon ('planned_downtime_time', true);;
@@ -345,9 +425,9 @@ $table->data[5][1] = "
__('From:') .
"