From 88a53868aabca959c2385a42c034700c2c68fd5c Mon Sep 17 00:00:00 2001 From: Arturo Gonzalez Diaz Date: Mon, 13 Jul 2015 15:59:08 +0200 Subject: [PATCH] Acces to non-privilege user to planned downtime (cherry picked from commit bbbddf2fff07d372a52a4dedfcec598d356b6932) Conflicts resolved: pandora_console/godmode/agentes/planned_downtime.list.php --- .../godmode/agentes/planned_downtime.list.php | 195 +++++++++++------- 1 file changed, 125 insertions(+), 70 deletions(-) diff --git a/pandora_console/godmode/agentes/planned_downtime.list.php b/pandora_console/godmode/agentes/planned_downtime.list.php index b0d24c185e..88d93eaaa3 100755 --- a/pandora_console/godmode/agentes/planned_downtime.list.php +++ b/pandora_console/godmode/agentes/planned_downtime.list.php @@ -197,42 +197,29 @@ if ($delete_downtime) { // 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) : ""; +$search_text = $filter_params['search_text'] = (string) get_parameter('search_text'); +$date_from = $filter_params['date_from'] = (string) get_parameter('date_from'); +$date_to = $filter_params['date_to'] = (string) get_parameter('date_to'); +$execution_type = $filter_params['execution_type'] = (string) get_parameter('execution_type'); +$show_archived = $filter_params['archived'] = (bool) get_parameter('archived'); +$agent_id = $filter_params['agent_id'] = (int) get_parameter('agent_id'); +$agent_name = $filter_params['agent_name'] = (string) (!empty($agent_id) ? get_parameter('agent_name') : ''); +$module_id = $filter_params['module_id'] = (int) get_parameter('module_name_hidden'); +$module_name = $filter_params['module_name'] = (string) (!empty($module_id) ? get_parameter('module_name') : ''); + +$filter_params_str = http_build_query($filter_params); // 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(); +$table_form = new StdClass(); +$table_form->class = 'databox filters'; +$table_form->width = '100%'; +$table_form->rowstyle = array(); +$table_form->rowstyle[0] = "background-color: #f9faf9;"; +$table_form->rowstyle[1] = "background-color: #f9faf9;"; +$table_form->rowstyle[2] = "background-color: #f9faf9;"; +$table_form->data = array(); $row = array(); @@ -244,7 +231,7 @@ $date_inputs .= "  "; $date_inputs .= __('To') . ' ' . html_print_input_text('date_to', $date_to, '', 10, 10, true); $row[] = $date_inputs; -$table->data[] = $row; +$table_form->data[] = $row; $row = array(); @@ -254,7 +241,7 @@ $row[] = __('Execution type') . ' ' . html_print_select($execution_type_fie // Show past downtimes $row[] = __('Show past downtimes') . ' ' . html_print_checkbox ("archived", 1, $show_archived, true); -$table->data[] = $row; +$table_form->data[] = $row; $row = array(); @@ -271,22 +258,18 @@ $agent_input = __('Agent') . ' ' . ui_print_agent_autocomplete_input($param $row[] = $agent_input; // Module -$module_input = __('Module') . ' ' . html_print_autocomplete_modules('module_name', $module_name, false, true, '', array(), true); -$row[] = $module_input; +$row[] = __('Module') . ' ' . html_print_autocomplete_modules('module_name', $module_name, false, true, '', array(), true); $row[] = html_print_submit_button('Search', 'search', false, 'class="sub search"', true); -$table->data[] = $row; +$table_form->data[] = $row; -echo "
"; -html_print_table($table); -echo "
"; // View available downtimes present in database (if any of them) $table = new StdClass(); -$table->class = 'databox'; +$table->class = 'databox data'; //Start Overview of existing planned downtime -$table->width = '98%'; +$table->width = '100%'; $table->cellstyle = array(); $table->data = array(); $table->head = array(); @@ -299,9 +282,7 @@ $table->head[5] = __('Configuration'); $table->head[6] = __('Running'); $table->head[7] = __('Stop downtime'); $table->head[8] = __('Edit'); -if (check_acl ($config['id_user'], 0, "AW")) { - $table->head[9] = __('delete'); -} +$table->head[9] = __('Delete'); $table->align[2] = "center"; $table->align[6] = "center"; $table->align[7] = "center"; @@ -309,7 +290,7 @@ $table->align[8] = "center"; $table->align[9] = "center"; $groups = users_get_groups (); -if(!empty($groups)) { +if (!empty($groups)) { $where_values = "1=1"; $groups_string = implode (",", array_keys ($groups)); @@ -374,16 +355,77 @@ if(!empty($groups)) { AND tam.id_agente_modulo = $module_id AND tpda.all_modules = 1))"; } + + // 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": + case "postgresql": + $columns_str = implode(',', $columns); + $sql = "SELECT $columns_str + FROM tplanned_downtime + WHERE $where_values + ORDER BY type_execution DESC, date_from DESC + LIMIT ".$config["block_size"]." + OFFSET $offset"; + break; + case "oracle": + // 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); + + $set = array (); + $set['limit'] = $config["block_size"]; + $set['offset'] = $offset; + + $sql = "SELECT $columns_str + FROM tplanned_downtime + WHERE $where_values + ORDER BY type_execution DESC, date_from DESC"; + + $sql = oracle_recode_query ($sql, $set); + break; + } - $sql = "SELECT * - 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; @@ -396,6 +438,10 @@ if (!$downtimes) { echo '
'.__('No planned downtime').'
'; } else { + echo "
"; + html_print_table($table_form); + echo "
"; + ui_pagination($downtimes_number, "index.php?sec=estado&sec2=godmode/agentes/planned_downtime.list&$filter_params_str", $offset); foreach ($downtimes as $downtime) { @@ -421,9 +467,9 @@ else { switch ($downtime['type_execution']) { case 'once': - $data[5] = date ("Y-m-d H:i", $downtime['date_from']) . + $data[5] = date ("Y-m-d H:i:s", $downtime['date_from']) . " " . __('to') . " ". - date ("Y-m-d H:i", $downtime['date_to']); + date ("Y-m-d H:i:s", $downtime['date_to']); break; case 'periodically': switch ($downtime['type_periodicity']) { @@ -458,7 +504,7 @@ else { $data[5] .= __('Sun'); $data[5] .= " "; } - $data[5] .= " (" . $downtime['periodically_time_from']; + $data[5] .= " (" . $downtime['periodically_time_from']; $data[5] .= "-" . $downtime['periodically_time_to'] . ")"; break; case 'monthly': @@ -484,9 +530,8 @@ else { if ($downtime['type_execution'] == 'once' && $downtime["executed"] == 1) { - $data[7] .= '' . + $data[7] .= '' . html_print_image("images/cancel.png", true, array("border" => '0', "alt" => __('Stop downtime'))); } else { @@ -494,8 +539,7 @@ else { } if ($downtime["executed"] == 0) { - $data[8] = '' . + $data[8] = '' . html_print_image("images/config.png", true, array("border" => '0', "alt" => __('Update'))) . ''; if (check_acl ($config['id_user'], 0, "AW")) { $data[9] = ' '0', "alt" => __('Delete'))); } } + elseif ($downtime["executed"] == 1 + && $downtime['type_execution'] == 'once') { + + $data[8] = '' . + html_print_image("images/config.png", true, + array("border" => '0', "alt" => __('Update'))) . ''; + $data[9]= "N/A"; + } else { $data[8]= "N/A"; $data[9]= "N/A"; @@ -521,20 +574,22 @@ else { 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 ' '; -if (check_acl ($config['id_user'], 0, "AW")) { + 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 ' '; + if (check_acl ($config['id_user'], 0, "AW")) { echo '
'; html_print_submit_button (__('Create'), 'create', false, 'class="sub next"'); - echo '
'; + } + echo ''; + echo '
'; } -echo '
'; + ui_require_jquery_file("ui.datepicker-" . get_user_language(), "include/javascript/i18n/");