Planned downtime list and edit changed. Ticket #2404

(cherry picked from commit 12334a3cd1)

Conflicts resolved:
	pandora_console/godmode/agentes/planned_downtime.editor.php
This commit is contained in:
Arturo Gonzalez Diaz 2015-07-14 16:15:04 +02:00 committed by Alejandro Gallardo Escobar
parent f654d6567b
commit 49ad7477c3
2 changed files with 317 additions and 209 deletions

View File

@ -29,6 +29,12 @@ $config["past_planned_downtimes"] = isset($config["past_planned_downtimes"]) ? $
require_once ('include/functions_users.php'); require_once ('include/functions_users.php');
// Buttons
$buttons = array(
'text' => "<a href='index.php?sec=extensions&sec2=godmode/agentes/planned_downtime.list'>"
. html_print_image ("images/list.png", true, array ("title" =>__('List'))) . "</a>"
);
// Header // Header
ui_print_page_header( ui_print_page_header(
__("Planned Downtime"), __("Planned Downtime"),
@ -36,56 +42,52 @@ ui_print_page_header(
false, false,
"planned_downtime", "planned_downtime",
true, true,
""); $buttons);
//Initialize data //Initialize data
$id_agent = get_parameter ("id_agent"); $id_group = (int) get_parameter ('id_group');
$id_group = (int) get_parameter ("id_group", 0); $name = (string) get_parameter ('name');
$name = (string) get_parameter ('name', ''); $description = (string) get_parameter ('description');
$description = (string) get_parameter ('description', '');
$once_date_from = (string) get_parameter ('once_date_from', date(DATE_FORMAT)); $type_downtime = (string) get_parameter('type_downtime', 'quiet');
$once_time_from = (string) get_parameter ('once_time_from', date(TIME_FORMAT)); $type_execution = (string) get_parameter('type_execution', 'once');
$once_date_to = (string) get_parameter ('once_date_to', date(DATE_FORMAT)); $type_periodicity = (string) get_parameter('type_periodicity', 'weekly');
$once_time_to = (string) get_parameter ('once_time_to', date(TIME_FORMAT));
$periodically_day_from = (int) get_parameter ('periodically_day_from', 1); $once_date_from = (string) get_parameter ('once_date_from', date(DATE_FORMAT));
$periodically_day_to = (int) get_parameter ('periodically_day_to', 31); $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_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');
$id_agent = (int) get_parameter ('id_agent');
$edit_downtime = (int) get_parameter ('edit_downtime'); $insert_downtime_agent = (int) get_parameter ('insert_downtime_agent');
$update_downtime = (int) get_parameter ('update_downtime'); $delete_downtime_agent = (int) get_parameter ('delete_downtime_agent');
$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);
$groups = users_get_groups (); $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 // INSERT A NEW DOWNTIME_AGENT ASSOCIATION
if ($insert_downtime_agent == 1) { if ($insert_downtime_agent === 1) {
$agents = (array)get_parameter("id_agents", array()); $agents = (array) get_parameter ('id_agents');
$module_names = (array)get_parameter("module", array()); $module_names = (array) get_parameter ('module');
$all_modules = false; $all_modules = false;
if (empty($module_names)) { if (empty($module_names)) {
$all_modules = true; $all_modules = true;
@ -96,30 +98,37 @@ if ($insert_downtime_agent == 1) {
$all_modules = true; $all_modules = true;
} }
for ($a=0; $a < count($agents); $a++) { $executed = db_get_value ('executed', 'tplanned_downtime', 'id', $id_downtime);
$id_agente_dt = $agents[$a]; if ($executed == 1) {
ui_print_error_message(__("This elements cannot be modified while the downtime is being executed"));
}
$values = array( else {
'id_downtime' => $id_downtime, $num_agents = count($agents);
'id_agent' => $id_agente_dt, for ($a = 0; $a < $num_agents; $a++) {
'all_modules' => $all_modules); $id_agente_dt = $agents[$a];
$result = db_process_sql_insert('tplanned_downtime_agents', $values); $values = array(
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_downtime' => $id_downtime,
'id_agent' => $id_agente_dt, 'id_agent' => $id_agente_dt,
'id_agent_module' => $module["id_agente_modulo"]); 'all_modules' => $all_modules
$result = db_process_sql_insert('tplanned_downtime_modules', $values); );
if ($result) { $result = db_process_sql_insert('tplanned_downtime_agents', $values);
$values = array('id_user' => $config['id_user']); if ($result && !$all_modules) {
$result = db_process_sql_update('tplanned_downtime', foreach ($module_names as $module_name) {
$values, array('id' => $id_downtime)); $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 // 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_da = (int) get_parameter ('id_downtime_agent');
$id_agent_delete = (int)get_parameter('id_agent', 0);
$row_to_delete = db_get_row('tplanned_downtime_agents', 'id', $id_da); $executed = db_get_value ('executed', 'tplanned_downtime', 'id', $id_downtime);
if ($executed == 1) {
$result = db_process_sql_delete('tplanned_downtime_agents', ui_print_error_message(__("This elements cannot be modified while the downtime is being executed"));
array('id' => $id_da)); }
else {
if ($result) { $row_to_delete = db_get_row('tplanned_downtime_agents', 'id', $id_da);
//Delete modules in downtime
db_process_sql_delete('tplanned_downtime_modules', $result = db_process_sql_delete('tplanned_downtime_agents', array('id' => $id_da));
array('id_downtime' => $row_to_delete['id_downtime'],
'id_agent' => $id_agent_delete)); 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) { 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')); 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' else if ($type_execution == 'periodically'
&& (($type_periodicity == 'weekly' && $periodically_time_from >= $periodically_time_to) && (($type_periodicity == 'weekly' && $periodically_time_from >= $periodically_time_to)
|| ($type_periodicity == 'monthly' && $periodically_day_from == $periodically_day_to && $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 (trim(io_safe_output($name)) != '') {
if (!$check) { if (!$check) {
$values = array( $values = array(
'name' => $name, 'name' => $name,
'description' => $description, 'description' => $description,
'date_from' => $datetime_from, 'date_from' => $datetime_from,
'date_to' => $datetime_to, 'date_to' => $datetime_to,
'executed' => 0, 'executed' => 0,
'id_group' => $id_group, 'id_group' => $id_group,
'only_alerts' => 0, 'only_alerts' => 0,
'monday' => $monday, 'monday' => $monday,
'tuesday' => $tuesday, 'tuesday' => $tuesday,
'wednesday' => $wednesday, 'wednesday' => $wednesday,
'thursday' => $thursday, 'thursday' => $thursday,
'friday' => $friday, 'friday' => $friday,
'saturday' => $saturday, 'saturday' => $saturday,
'sunday' => $sunday, 'sunday' => $sunday,
'periodically_time_from' => $periodically_time_from, 'periodically_time_from' => $periodically_time_from,
'periodically_time_to' => $periodically_time_to, 'periodically_time_to' => $periodically_time_to,
'periodically_day_from' => $periodically_day_from, 'periodically_day_from' => $periodically_day_from,
'periodically_day_to' => $periodically_day_to, 'periodically_day_to' => $periodically_day_to,
'type_downtime' => $type_downtime, 'type_downtime' => $type_downtime,
'type_execution' => $type_execution, 'type_execution' => $type_execution,
'type_periodicity' => $type_periodicity, 'type_periodicity' => $type_periodicity,
'id_user' => $config['id_user'] 'id_user' => $config['id_user']
); );
$result = db_process_sql_insert( if ($config["dbtype"] == 'oracle') {
'tplanned_downtime', $values); $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 { else {
ui_print_error_message( ui_print_error_message(
@ -210,13 +230,27 @@ if ($create_downtime || $update_downtime) {
} }
} }
else if ($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( $values = array(
'name' => $name, 'name' => $name,
'description' => $description, 'description' => $description,
'date_from' => $datetime_from, 'date_from' => $datetime_from,
'date_to' => $datetime_to, 'date_to' => $datetime_to,
'executed' => 0,
'id_group' => $id_group, 'id_group' => $id_group,
'only_alerts' => 0, 'only_alerts' => 0,
'monday' => $monday, 'monday' => $monday,
@ -235,11 +269,13 @@ if ($create_downtime || $update_downtime) {
'type_periodicity' => $type_periodicity, 'type_periodicity' => $type_periodicity,
'id_user' => $config['id_user'] '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 { if (!empty($values)) {
ui_print_error_message( $result = db_process_sql_update('tplanned_downtime', $values, array('id' => $id_downtime));
__('Planned downtime must have a name'));
} }
} }
@ -265,75 +301,119 @@ if ($create_downtime || $update_downtime) {
// Have any data to show ? // Have any data to show ?
if ($id_downtime > 0) { 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"]) { switch ($config["dbtype"]) {
case "mysql": case "mysql":
$sql = sprintf ("SELECT *
FROM `tplanned_downtime`
WHERE `id` = %d",
$id_downtime);
break;
case "postgresql": case "postgresql":
$sql = sprintf ("SELECT * $columns_str = implode(',', $columns);
FROM \"tplanned_downtime\" $sql = "SELECT $columns_str
WHERE \"id\" = %d", FROM tplanned_downtime
$id_downtime); WHERE id = $id_downtime";
break; break;
case "oracle": case "oracle":
$sql = sprintf ("SELECT * // Oracle doesn't have TIME type, so we should transform the DATE value
FROM tplanned_downtime $new_time_from = "TO_CHAR(periodically_time_from, 'HH24:MI:SS') AS periodically_time_from";
WHERE id = %d", $new_time_to = "TO_CHAR(periodically_time_to, 'HH24:MI:SS') AS periodically_time_to";
$id_downtime);
$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; break;
} }
$result = db_get_row_sql ($sql); $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) $name = (string) $result["name"];
$id_group = $result['id_group']; $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'; // when the planned down time is in execution, only action to postpone on once type is enabled and the other are disabled.
$table->width = '98%'; $disabled_in_execution = $executed ? 1 : 0;
$table = new StdClass();
$table->class = 'databox filters';
$table->width = '100%';
$table->data = array (); $table->data = array ();
$table->data[0][0] = __('Name'); $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][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][0] = __('Description');
$table->data[2][1] = html_print_textarea ('description', 3, 35, $description, '', true); $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.").'<br>'. $table->data[3][0] = __('Type').ui_print_help_tip(__("Quiet: Disable modules that we indicate below.").'<br>'.
__("Disable Agents: Disables the selected agents.").'<br>'. __("Disable Agents: Disables the selected agents.").'<br>'.
__("Disable Alerts: Disable alerts for the selected agents."), true); __("Disable Alerts: Disable alerts for the selected agents."), true);
$table->data[3][1] = html_print_select(array('quiet' => __('Quiet'), $table->data[3][1] = html_print_select(array('quiet' => __('Quiet'),
'disable_agents' => __('Disabled Agents'), 'disable_agents' => __('Disabled Agents'),
'disable_agents_alerts' => __('Disabled only Alerts')), 'disable_agents_alerts' => __('Disabled only Alerts')),
'type_downtime', $type_downtime, 'change_type_downtime()', '', 0, true, false, true, 'type_downtime', $type_downtime, 'change_type_downtime()', '', 0, true, false, true,
''); '', $disabled_in_execution);
$table->data[4][0] = __('Execution'); $table->data[4][0] = __('Execution');
$table->data[4][1] = html_print_select(array('once' => __('Once'), $table->data[4][1] = html_print_select(array('once' => __('Once'),
'periodically' => __('Periodically')), '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)); $days = array_combine(range(1, 31), range(1, 31));
$table->data[5][0] = __('Configure the time') . "&nbsp;" . ui_print_help_icon ('planned_downtime_time', true);; $table->data[5][0] = __('Configure the time') . "&nbsp;" . ui_print_help_icon ('planned_downtime_time', true);;
@ -345,9 +425,9 @@ $table->data[5][1] = "
__('From:') . __('From:') .
"</td> "</td>
<td>". <td>".
html_print_input_text ('once_date_from', $once_date_from, '', 10, 10, true) . html_print_input_text ('once_date_from', $once_date_from, '', 10, 10, true, $disabled_in_execution) .
ui_print_help_tip(__('Date format in Pandora is year/month/day'), true) . ui_print_help_tip(__('Date format in Pandora is year/month/day'), true) .
html_print_input_text ('once_time_from', $once_time_from, '', 9, 9, true) . html_print_input_text ('once_time_from', $once_time_from, '', 9, 9, true, $disabled_in_execution) .
ui_print_help_tip(__('Time format in Pandora is hours(24h):minutes:seconds'), true) . ui_print_help_tip(__('Time format in Pandora is hours(24h):minutes:seconds'), true) .
"</td> "</td>
</tr> </tr>
@ -372,7 +452,8 @@ $table->data[5][1] = "
'weekly' => __('Weekly'), 'weekly' => __('Weekly'),
'monthly' => __('Monthly')), 'monthly' => __('Monthly')),
'type_periodicity', $type_periodicity, 'type_periodicity', $type_periodicity,
'change_type_periodicity();', '', 0, true) . 'change_type_periodicity();', '', 0, true,
false, true, '', $disabled_in_execution) .
"</td> "</td>
</tr> </tr>
<tr> <tr>
@ -380,25 +461,25 @@ $table->data[5][1] = "
<table id='weekly_item' style='display: none;'> <table id='weekly_item' style='display: none;'>
<tr> <tr>
<td>" . __('Mon') . <td>" . __('Mon') .
html_print_checkbox ('monday', 1, $monday, true) . html_print_checkbox ('monday', 1, $monday, true, $disabled_in_execution) .
"</td> "</td>
<td>" . __('Tue') . <td>" . __('Tue') .
html_print_checkbox ('tuesday', 1, $tuesday, true) . html_print_checkbox ('tuesday', 1, $tuesday, true, $disabled_in_execution) .
"</td> "</td>
<td>" . __('Wed') . <td>" . __('Wed') .
html_print_checkbox ('wednesday', 1, $wednesday, true) . html_print_checkbox ('wednesday', 1, $wednesday, true, $disabled_in_execution) .
"</td> "</td>
<td>" . __('Thu') . <td>" . __('Thu') .
html_print_checkbox ('thursday', 1, $thursday, true) . html_print_checkbox ('thursday', 1, $thursday, true, $disabled_in_execution) .
"</td> "</td>
<td>" . __('Fri') . <td>" . __('Fri') .
html_print_checkbox ('friday', 1, $friday, true) . html_print_checkbox ('friday', 1, $friday, true, $disabled_in_execution) .
"</td> "</td>
<td>" . __('Sat') . <td>" . __('Sat') .
html_print_checkbox ('saturday', 1, $saturday, true) . html_print_checkbox ('saturday', 1, $saturday, true, $disabled_in_execution) .
"</td> "</td>
<td>" . __('Sun') . <td>" . __('Sun') .
html_print_checkbox ('sunday', 1, $sunday, true) . html_print_checkbox ('sunday', 1, $sunday, true, $disabled_in_execution) .
"</td> "</td>
</tr> </tr>
</table> </table>
@ -407,12 +488,14 @@ $table->data[5][1] = "
<td>" . __('From day:') . "</td> <td>" . __('From day:') . "</td>
<td>". <td>".
html_print_select($days, html_print_select($days,
'periodically_day_from', $periodically_day_from, '', '', 0, true) . 'periodically_day_from', $periodically_day_from, '', '', 0, true,
false, true, '', $disabled_in_execution) .
"</td> "</td>
<td>" . __('To day:') . "</td> <td>" . __('To day:') . "</td>
<td>". <td>".
html_print_select($days, html_print_select($days,
'periodically_day_to', $periodically_day_to, '', '', 0, true) . 'periodically_day_to', $periodically_day_to, '', '', 0, true,
false, true, '', $disabled_in_execution) .
"</td> "</td>
<td>" . ui_print_help_tip(__('The end day must be higher than the start day'), true) . "</td> <td>" . ui_print_help_tip(__('The end day must be higher than the start day'), true) . "</td>
</tr> </tr>
@ -423,7 +506,7 @@ $table->data[5][1] = "
<td>". <td>".
html_print_input_text ( html_print_input_text (
'periodically_time_from', 'periodically_time_from',
$periodically_time_from, '', 7, 7, true) . $periodically_time_from, '', 7, 7, true, $disabled_in_execution) .
ui_print_help_tip(__('Time format in Pandora is hours(24h):minutes:seconds'). ui_print_help_tip(__('Time format in Pandora is hours(24h):minutes:seconds').
".<br>".__('The end time must be higher than the start time'), true) . ".<br>".__('The end time must be higher than the start time'), true) .
"</td> "</td>
@ -431,7 +514,7 @@ $table->data[5][1] = "
<td>". <td>".
html_print_input_text ( html_print_input_text (
'periodically_time_to', 'periodically_time_to',
$periodically_time_to, '', 7, 7, true) . $periodically_time_to, '', 7, 7, true, $disabled_in_execution) .
ui_print_help_tip(__('Time format in Pandora is hours(24h):minutes:seconds'). ui_print_help_tip(__('Time format in Pandora is hours(24h):minutes:seconds').
".<br>".__('The end time must be higher than the start time'), true) . ".<br>".__('The end time must be higher than the start time'), true) .
"</td> "</td>
@ -453,8 +536,8 @@ if ($id_downtime > 0) {
html_print_table ($table); html_print_table ($table);
html_print_input_hidden ('id_agent', $id_agent); html_print_input_hidden ('id_agent', $id_agent);
echo '<div class="action-buttons" style="width: 90%">'; echo '<div class="action-buttons" style="width: 100%">';
if ($id_downtime) { if ($id_downtime > 0) {
html_print_input_hidden ('update_downtime', 1); html_print_input_hidden ('update_downtime', 1);
html_print_input_hidden ('id_downtime', $id_downtime); html_print_input_hidden ('id_downtime', $id_downtime);
html_print_submit_button (__('Update'), 'updbutton', false, 'class="sub upd"'); html_print_submit_button (__('Update'), 'updbutton', false, 'class="sub upd"');
@ -474,19 +557,28 @@ if ($id_downtime > 0) {
$filter_group = get_parameter("filter_group", 0); $filter_group = get_parameter("filter_group", 0);
$groupsAW = users_get_groups($config['id_user'], 'AW', true, false, null, 'id_grupo');
$groupsAW = array_keys($groupsAW);
$id_groups_list = implode(",", $groupsAW);
if (empty($id_groups_list)){
$id_groups_list = -1;
}
$filter_cond = ''; $filter_cond = '';
if($filter_group > 0) if ($filter_group > 0)
$filter_cond = " AND id_grupo = $filter_group "; $filter_cond = " AND id_grupo = $filter_group ";
$sql = sprintf ("SELECT tagente.id_agente, tagente.nombre, $sql = sprintf ("SELECT tagente.id_agente, tagente.nombre,
tagente.id_grupo tagente.id_grupo
FROM tagente FROM tagente
WHERE tagente.id_agente NOT IN ( WHERE tagente.id_agente NOT IN (
SELECT tagente.id_agente SELECT tagente.id_agente
FROM tagente, tplanned_downtime_agents FROM tagente, tplanned_downtime_agents
WHERE tplanned_downtime_agents.id_agent = tagente.id_agente WHERE tplanned_downtime_agents.id_agent = tagente.id_agente
AND tplanned_downtime_agents.id_downtime = %d AND tplanned_downtime_agents.id_downtime = %d
) AND disabled = 0 $filter_cond ) AND disabled = 0 $filter_cond
ORDER by tagente.nombre", $id_downtime); AND tagente.id_grupo IN (%s)
ORDER by tagente.nombre", $id_downtime, $id_groups_list);
$downtimes = db_get_all_rows_sql ($sql); $downtimes = db_get_all_rows_sql ($sql);
$data = array (); $data = array ();
if ($downtimes) { if ($downtimes) {
@ -498,7 +590,7 @@ if ($id_downtime > 0) {
} }
$disabled_add_button = false; $disabled_add_button = false;
if (empty($data)) { if (empty($data) || $disabled_in_execution) {
$disabled_add_button = true; $disabled_add_button = true;
} }
@ -531,11 +623,11 @@ if ($id_downtime > 0) {
echo '<h4>'.__('Agents planned for this downtime').':</h4>'; echo '<h4>'.__('Agents planned for this downtime').':</h4>';
$sql = sprintf ("SELECT tagente.nombre, tplanned_downtime_agents.id, $sql = sprintf ("SELECT tagente.nombre, tplanned_downtime_agents.id,
tagente.id_os, tagente.id_agente, tagente.id_grupo, tagente.id_os, tagente.id_agente, tagente.id_grupo,
tagente.ultimo_contacto, tplanned_downtime_agents.all_modules tagente.ultimo_contacto, tplanned_downtime_agents.all_modules
FROM tagente, tplanned_downtime_agents FROM tagente, tplanned_downtime_agents
WHERE tplanned_downtime_agents.id_agent = tagente.id_agente WHERE tplanned_downtime_agents.id_agent = tagente.id_agente
AND tplanned_downtime_agents.id_downtime = %d ", $id_downtime); AND tplanned_downtime_agents.id_downtime = %d ", $id_downtime);
$downtimes = db_get_all_rows_sql ($sql); $downtimes = db_get_all_rows_sql ($sql);
if ($downtimes === false) { if ($downtimes === false) {
@ -543,9 +635,10 @@ if ($id_downtime > 0) {
__('There are no scheduled downtimes') . '</div>'; __('There are no scheduled downtimes') . '</div>';
} }
else { else {
$table = new stdClass();
$table->id = 'list'; $table->id = 'list';
$table->class = 'databox'; $table->class = 'databox data';
$table->width = '98%'; $table->width = '100%';
$table->data = array (); $table->data = array ();
$table->head = array (); $table->head = array ();
$table->head[0] = __('Name'); $table->head[0] = __('Name');
@ -553,9 +646,12 @@ if ($id_downtime > 0) {
$table->head[2] = __('OS'); $table->head[2] = __('OS');
$table->head[3] = __('Last contact'); $table->head[3] = __('Last contact');
$table->head['count_modules'] = __('Modules'); $table->head['count_modules'] = __('Modules');
$table->head[5] = __('Actions');
$table->align[5] = "center"; if (!$executed) {
$table->size[5] = "5%"; $table->head[5] = __('Actions');
$table->align[5] = "center";
$table->size[5] = "5%";
}
foreach ($downtimes as $downtime) { foreach ($downtimes as $downtime) {
$data = array (); $data = array ();
@ -563,8 +659,8 @@ if ($id_downtime > 0) {
$data[0] = $downtime['nombre']; $data[0] = $downtime['nombre'];
$data[1] = db_get_sql ("SELECT nombre $data[1] = db_get_sql ("SELECT nombre
FROM tgrupo FROM tgrupo
WHERE id_grupo = " . $downtime["id_grupo"]); WHERE id_grupo = " . $downtime["id_grupo"]);
$data[2] = ui_print_os_icon($downtime["id_os"], true, true); $data[2] = ui_print_os_icon($downtime["id_os"], true, true);
@ -585,21 +681,17 @@ if ($id_downtime > 0) {
} }
} }
$data[5] = ''; if (!$executed) {
if (($type_downtime != 'disable_agents_alerts') $data[5] = '';
&& ($type_downtime != 'disable_agents')) { if ($type_downtime != 'disable_agents_alerts' && $type_downtime != 'disable_agents') {
$data[5] = '<a href="javascript:show_editor_module(' . $downtime["id_agente"] . ');">' .
$data[5] = '<a href="javascript:show_editor_module(' . $downtime["id_agente"] . ');">' . html_print_image("images/config.png", true, array("border" => '0', "alt" => __('Delete'))) . "</a>";
html_print_image("images/config.png", true, array("border" => '0', "alt" => __('Delete'))) . "</a>"; }
$data[5] .= '<a href="index.php?sec=estado&amp;sec2=godmode/agentes/planned_downtime.editor&id_agent=' . $downtime["id_agente"] .
'&delete_downtime_agent=1&id_downtime_agent=' . $downtime["id"] . '&id_downtime=' . $id_downtime . '">' .
html_print_image("images/cross.png", true, array("border" => '0', "alt" => __('Delete'))) . "</a>";
} }
$data[5] .= '<a href="index.php?sec=estado&amp;sec2=godmode/agentes/planned_downtime.editor'.
'&amp;id_agent=' . $downtime["id_agente"] .
'&amp;delete_downtime_agent=1' .
'&amp;id_downtime_agent=' . $downtime["id"] .
'&amp;id_downtime=' . $id_downtime . '">' .
html_print_image("images/cross.png", true,
array("border" => '0', "alt" => __('Delete'))) . "</a>";
$table->data['agent_' . $downtime["id_agente"]] = $data; $table->data['agent_' . $downtime["id_agente"]] = $data;
} }
@ -607,8 +699,9 @@ if ($id_downtime > 0) {
} }
} }
$table = null; $table = new stdClass();
$table->id = 'loading'; $table->id = 'loading';
$table->width = '100%';
$table->colspan['loading'][0] = '6'; $table->colspan['loading'][0] = '6';
$table->style[0] = 'text-align: center;'; $table->style[0] = 'text-align: center;';
$table->data = array(); $table->data = array();
@ -618,8 +711,9 @@ echo "<div style='display: none;'>";
html_print_table ($table); html_print_table ($table);
echo "</div>"; echo "</div>";
$table = null; $table = new stdClass();
$table->id = 'editor'; $table->id = 'editor';
$table->width = '100%';
$table->colspan['module'][1] = '5'; $table->colspan['module'][1] = '5';
$table->data = array(); $table->data = array();
$table->data['module'] = array(); $table->data['module'] = array();
@ -628,7 +722,7 @@ $table->data['module'][1] = "<h4>" . __('Modules') . "</h4>";
//List of modules, empty, it is populated by javascript. //List of modules, empty, it is populated by javascript.
$table->data['module'][1] = " $table->data['module'][1] = "
<table cellspacing='4' cellpadding='4' border='0' width='98%' <table cellspacing='4' cellpadding='4' border='0' width='100%'
id='modules_in_agent' class='databox_color'> id='modules_in_agent' class='databox_color'>
<thead> <thead>
<tr> <tr>
@ -639,7 +733,7 @@ $table->data['module'][1] = "
<tbody> <tbody>
<tr class='datos' id='template' style='display: none;'> <tr class='datos' id='template' style='display: none;'>
<td class='name_module' style=''></td> <td class='name_module' style=''></td>
<td class='cell_delete_button' style='text-align: center; width:10%;' id=''>" <td class='cell_delete_button' style='text-align: right; width:10%;' id=''>"
. '<a class="link_delete" . '<a class="link_delete"
onclick="if(!confirm(\'' . __('Are you sure?') . '\')) return false;" onclick="if(!confirm(\'' . __('Are you sure?') . '\')) return false;"
href="">' href="">'
@ -653,7 +747,7 @@ $table->data['module'][1] = "
. html_print_select(array(), . html_print_select(array(),
'modules', '', '', '', 0, true) 'modules', '', '', '', 0, true)
. "</td> . "</td>
<td class='datos2 button_cell' style='text-align: center; width:10%;' id=''>" <td class='datos2 button_cell' style='text-align: right; width:10%;' id=''>"
. '<div id="add_button_div">' . '<div id="add_button_div">'
. '<a class="add_button" href="">' . '<a class="add_button" href="">'
. html_print_image("images/add.png", true, . html_print_image("images/add.png", true,
@ -734,6 +828,10 @@ ui_require_jquery_file("ui.datepicker-" . get_user_language(), "include/javascri
} }
} }
function show_executing_alert () {
alert('<?php echo __("This elements cannot be modified while the downtime is being executed"); ?>');
}
function show_editor_module(id_agent) { function show_editor_module(id_agent) {
//Avoid freak states. //Avoid freak states.
if (action_in_progress) if (action_in_progress)
@ -893,6 +991,9 @@ ui_require_jquery_file("ui.datepicker-" . get_user_language(), "include/javascri
$("#spinner_add", $('#module_editor_' + id_agent)) $("#spinner_add", $('#module_editor_' + id_agent))
.toggle(); .toggle();
} }
else if (data['executed']) {
show_executing_alert();
}
action_in_progress = false; action_in_progress = false;
}, },
@ -931,6 +1032,9 @@ ui_require_jquery_file("ui.datepicker-" . get_user_language(), "include/javascri
$("#all_modules_text").html()); $("#all_modules_text").html());
} }
} }
else if (data['executed']) {
show_executing_alert();
}
else { else {
$(".cell_delete_button", "#row_module_in_downtime_" + id_module) $(".cell_delete_button", "#row_module_in_downtime_" + id_module)
.html($(old_cell_content)); .html($(old_cell_content));
@ -964,8 +1068,7 @@ ui_require_jquery_file("ui.datepicker-" . get_user_language(), "include/javascri
$.datepicker.setDefaults($.datepicker.regional[ "<?php echo get_user_language(); ?>"]); $.datepicker.setDefaults($.datepicker.regional[ "<?php echo get_user_language(); ?>"]);
$("#filter_group").click ( $("#filter_group").click (function () {
function () {
$(this).css ("width", "auto"); $(this).css ("width", "auto");
}); });
@ -973,8 +1076,7 @@ ui_require_jquery_file("ui.datepicker-" . get_user_language(), "include/javascri
$(this).css ("width", "180px"); $(this).css ("width", "180px");
}); });
$("#id_agent").click ( $("#id_agent").click (function () {
function () {
$(this).css ("width", "auto"); $(this).css ("width", "auto");
}); });
@ -994,5 +1096,7 @@ ui_require_jquery_file("ui.datepicker-" . get_user_language(), "include/javascri
} }
}); });
} }
// Disable datepickers when it has readonly attribute
$('input.hasDatepicker[readonly]').disable();
}); });
</script> </script>

View File

@ -447,6 +447,10 @@ else {
$groupsAW = users_get_groups($config['id_user'], 'AW', true, false, null, 'id_grupo'); $groupsAW = users_get_groups($config['id_user'], 'AW', true, false, null, 'id_grupo');
$groupsAW = array_keys($groupsAW); $groupsAW = array_keys($groupsAW);
if (empty($groupsAW)){
$groupsAW = -1;
}
foreach ($downtimes as $downtime) { foreach ($downtimes as $downtime) {
$data = array(); $data = array();
$total = db_get_sql ("SELECT COUNT(id_agent) $total = db_get_sql ("SELECT COUNT(id_agent)