diff --git a/pandora_console/godmode/reporting/reporting_builder.php b/pandora_console/godmode/reporting/reporting_builder.php index 03179dd4d4..90009ea20d 100755 --- a/pandora_console/godmode/reporting/reporting_builder.php +++ b/pandora_console/godmode/reporting/reporting_builder.php @@ -1,5 +1,4 @@ $id_unsort) { if ($pos == $position_to_sort) { @@ -340,8 +355,6 @@ switch ($action) { $items = $sorted_items; - - foreach ($items as $order => $id) { switch ($config['dbtype']) { case 'mysql': @@ -372,6 +385,10 @@ switch ($action) { $resultOperationDB = false; } break; + + default: + // Default. + break; } break; @@ -380,7 +397,8 @@ switch ($action) { $ids_serialize = (string) get_parameter('ids_items_to_delete', ''); if (!empty($ids_serialize)) { - $sql = "DELETE FROM treport_content WHERE id_rc IN ($ids_serialize)"; + $sql = 'DELETE FROM treport_content + WHERE id_rc IN ('.$ids_serialize.')'; $resultOperationDB = db_process_sql($sql); } else { $resultOperationDB = false; @@ -400,7 +418,9 @@ switch ($action) { if (($countItems < $position_to_delete) || ($position_to_delete < 1)) { $resultOperationDB = false; } else { - $sql = "SELECT id_rc FROM treport_content WHERE id_report=$idReport ORDER BY '`order`'"; + $sql = 'SELECT id_rc + FROM treport_content + WHERE id_report='.$idReport." ORDER BY '`order`'"; $items = db_get_all_rows_sql($sql); switch ($pos_delete) { case 'above': @@ -410,7 +430,10 @@ switch ($action) { $i = 1; foreach ($items as $key => $item) { if ($i < $position_to_delete) { - $resultOperationDB = db_process_sql_delete('treport_content', ['id_rc' => $item['id_rc']]); + $resultOperationDB = db_process_sql_delete( + 'treport_content', + ['id_rc' => $item['id_rc']] + ); } $i++; @@ -464,7 +487,10 @@ switch ($action) { break; default: - $subsection = reporting_enterprise_add_subsection_main($activeTab, $buttons); + $subsection = reporting_enterprise_add_subsection_main( + $activeTab, + $buttons + ); break; } @@ -482,11 +508,19 @@ switch ($action) { // Print header. ui_meta_print_header(__('Reporting'), '', $buttons); - } - - // Page header for normal console. - else { - ui_print_page_header(__('Custom reporting'), 'images/op_reporting.png', false, '', false, $buttons, false, '', 60); + } else { + // Page header for normal console. + ui_print_page_header( + __('Custom reporting'), + 'images/op_reporting.png', + false, + '', + false, + $buttons, + false, + '', + 60 + ); } @@ -494,7 +528,9 @@ switch ($action) { $delete = false; switch ($type_access_selected) { case 'group_view': - if ($config['id_user'] == $report['id_user'] || is_user_admin($config['id_user'])) { + if ($config['id_user'] == $report['id_user'] + || is_user_admin($config['id_user']) + ) { $delete = true; // Owner can delete. } else { @@ -507,7 +543,9 @@ switch ($action) { break; case 'group_edit': - if ($config['id_user'] == $report['id_user'] || is_user_admin($config['id_user'])) { + if ($config['id_user'] == $report['id_user'] + || is_user_admin($config['id_user']) + ) { $delete = true; // Owner can delete. } else { @@ -543,9 +581,15 @@ switch ($action) { $result = reports_delete_report($idReport); if ($result !== false) { - db_pandora_audit('Report management', "Delete report #$idReport"); + db_pandora_audit( + 'Report management', + 'Delete report #'.$idReport + ); } else { - db_pandora_audit('Report management', "Fail try to delete report #$idReport"); + db_pandora_audit( + 'Report management', + 'Fail try to delete report #'.$idReport + ); } ui_print_result_message( @@ -560,7 +604,7 @@ switch ($action) { $search_sql = ''; if ($search != '') { - $search_name = "%$search%' OR description LIKE '%$search%"; + $search_name = '%'.$search."%' OR description LIKE '%".$search.'%'; } $table_aux = new stdClass(); @@ -572,25 +616,57 @@ switch ($action) { $table_aux->colspan[0][0] = 4; $table_aux->data[0][0] = ''.__('Group').''; - $table_aux->data[0][1] = html_print_select_groups(false, $access, true, 'id_group', $id_group, '', '', '', true, false, true, '', false, '', false, false, 'id_grupo', $strict_user).'
'; + $table_aux->data[0][1] = html_print_select_groups( + false, + $access, + true, + 'id_group', + $id_group, + '', + '', + '', + true, + false, + true, + '', + false, + '', + false, + false, + 'id_grupo' + ).'
'; - $table_aux->data[0][2] = ''.__('Free text for search: ').ui_print_help_tip( + $table_aux->data[0][2] = ''.__('Free text for search: '); + $table_aux->data[0][2] .= ui_print_help_tip( __('Search by report name or description, list matches.'), true - ).''; - $table_aux->data[0][3] = html_print_input_text('search', $search, '', 30, '', true); + ); + $table_aux->data[0][2] .= ''; + $table_aux->data[0][3] = html_print_input_text( + 'search', + $search, + '', + 30, + '', + true + ); - $table_aux->data[0][6] = html_print_submit_button(__('Search'), 'search_submit', false, 'class="sub upd"', true); + $table_aux->data[0][6] = html_print_submit_button( + __('Search'), + 'search_submit', + false, + 'class="sub upd"', + true + ); + $url_rb = 'index.php?sec=reporting&sec2=godmode/reporting/reporting_builder'; if (is_metaconsole()) { - $filter = "
"; + $filter = ''; $filter .= html_print_table($table_aux, true); $filter .= '
'; ui_toggle($filter, __('Show Option')); } else { - echo "
"; + echo ''; html_print_table($table_aux); echo '
'; } @@ -602,7 +678,7 @@ switch ($action) { // Show only selected groups. if ($id_group > 0) { - $group = ["$id_group" => $id_group]; + $group = [$id_group => $id_group]; } else { $group = false; } @@ -626,7 +702,7 @@ switch ($action) { // Fix : group filter was not working // Show only selected groups. if ($id_group > 0) { - $group = ["$id_group" => $id_group]; + $group = [$id_group => $id_group]; $filter['id_group'] = $id_group; } else { $group = false; @@ -652,8 +728,7 @@ switch ($action) { ], $return_all_group, $access, - $group, - $strict_user + $group ); $total_reports = (int) count( @@ -662,13 +737,12 @@ switch ($action) { ['name'], $return_all_group, $access, - $group, - $strict_user + $group ) ); - if (sizeof($reports)) { + if (count($reports)) { $url = 'index.php?sec=reporting&sec2=godmode/reporting/reporting_builder'; ui_pagination($total_reports, $url, $offset, $pagination); @@ -744,18 +818,44 @@ switch ($action) { foreach ($reports as $report) { if (!is_user_admin($config['id_user'])) { - if ($report['private'] && $report['id_user'] != $config['id_user']) { - if (!check_acl($config['id_user'], $report['id_group'], 'RR') - && !check_acl($config['id_user'], $report['id_group'], 'RW') - && !check_acl($config['id_user'], $report['id_group'], 'RM') + if ($report['private'] + && $report['id_user'] != $config['id_user'] + ) { + if (!check_acl( + $config['id_user'], + $report['id_group'], + 'RR' + ) + && !check_acl( + $config['id_user'], + $report['id_group'], + 'RW' + ) + && !check_acl( + $config['id_user'], + $report['id_group'], + 'RM' + ) ) { continue; } } - if (!check_acl($config['id_user'], $report['id_group'], 'RR') - && !check_acl($config['id_user'], $report['id_group'], 'RW') - && !check_acl($config['id_user'], $report['id_group'], 'RM') + if (!check_acl( + $config['id_user'], + $report['id_group'], + 'RR' + ) + && !check_acl( + $config['id_user'], + $report['id_group'], + 'RW' + ) + && !check_acl( + $config['id_user'], + $report['id_group'], + 'RM' + ) ) { continue; } @@ -763,7 +863,9 @@ switch ($action) { $data = []; - if (check_acl($config['id_user'], $report['id_group'], 'RW') || check_acl($config['id_user'], $report['id_group'], 'RM')) { + if (check_acl($config['id_user'], $report['id_group'], 'RW') + || check_acl($config['id_user'], $report['id_group'], 'RM') + ) { $data[0] = ''.ui_print_truncate_text($report['name'], 70).''; } else { $data[0] = ui_print_truncate_text($report['name'], 70); @@ -773,15 +875,35 @@ switch ($action) { $data[1] = ui_print_truncate_text($report['description'], 70); // Remove html and xml button if items are larger than limit. - $item_count = db_get_num_rows('SELECT * FROM treport_content WHERE id_report='.$report['id_report']); + $item_count = db_get_num_rows( + 'SELECT * FROM treport_content + WHERE id_report='.$report['id_report'] + ); $report['overload'] = $item_count >= $config['report_limit']; if ($report['overload']) { - $data[2] = html_print_image('images/application_not_writable.png', true, ['title' => __('This report exceeds the item limit for realtime operations')]); + $data[2] = html_print_image( + 'images/application_not_writable.png', + true, + ['title' => __('This report exceeds the item limit for realtime operations')] + ); $data[3] = null; } else if (!$report['non_interactive']) { - $data[2] = ''.html_print_image('images/html.png', true, ['title' => __('HTML view')]).''; - $data[3] = ''.html_print_image('images/xml.png', true, ['title' => __('Export to XML')]).''; - // I chose ajax.php because it's supposed to give XML anyway. + $data[2] = ''; + $data[2] .= html_print_image( + 'images/html.png', + true, + ['title' => __('HTML view')] + ); + $data[2] .= ''; + $data[3] = ''; + $data[3] .= html_print_image( + 'images/xml.png', + true, + ['title' => __('Export to XML')] + ); + $data[3] .= ''; + // I chose ajax.php because it's supposed + // to give XML anyway. } else { $data[2] = html_print_image( 'images/html_disabled.png', @@ -793,14 +915,12 @@ switch ($action) { ); } - // Calculate dinamically the number of the column. $next = 4; if (enterprise_hook('load_custom_reporting_2') !== ENTERPRISE_NOT_HOOK) { $next = 7; } - // Admin options only for RM flag. if (check_acl($config['id_user'], 0, 'RM')) { if ($report['private'] == 1) { @@ -828,14 +948,22 @@ switch ($action) { switch ($type_access_selected) { case 'group_view': - $edit = check_acl($config['id_user'], $report['id_group'], 'RW'); + $edit = check_acl( + $config['id_user'], + $report['id_group'], + 'RW' + ); $delete = $edit || is_user_admin($config['id_user']) || $config['id_user'] == $report['id_user']; break; case 'group_edit': - $edit = check_acl($config['id_user'], $report['id_group_edit'], 'RW'); + $edit = check_acl( + $config['id_user'], + $report['id_group_edit'], + 'RW' + ); $delete = $edit || is_user_admin($config['id_user']) || $config['id_user'] == $report['id_user']; @@ -894,10 +1022,26 @@ switch ($action) { true, ['title' => __('Delete')] ); - $data[$next] .= html_print_input_hidden('id_report', $report['id_report'], true); - $data[$next] .= html_print_input_hidden('action', 'delete_report', true); + $data[$next] .= html_print_input_hidden( + 'id_report', + $report['id_report'], + true + ); + $data[$next] .= html_print_input_hidden( + 'action', + 'delete_report', + true + ); - $data[$next] .= html_print_checkbox_extended('massive_report_check', $report['id_report'], false, false, '', 'class="check_delete"', true); + $data[$next] .= html_print_checkbox_extended( + 'massive_report_check', + $report['id_report'], + false, + false, + '', + 'class="check_delete"', + true + ); $data[$next] .= ''; } @@ -922,12 +1066,28 @@ switch ($action) { } html_print_table($table); - ui_pagination($total_reports, $url, $offset, $pagination, false, 'offset', true, 'pagination-bottom'); + ui_pagination( + $total_reports, + $url, + $offset, + $pagination, + false, + 'offset', + true, + 'pagination-bottom' + ); } else { - ui_print_info_message([ 'no_close' => true, 'message' => __('No data found.') ]); + ui_print_info_message( + [ + 'no_close' => true, + 'message' => __('No data found.'), + ] + ); } - if (check_acl($config['id_user'], 0, 'RW') || check_acl($config['id_user'], 0, 'RM')) { + if (check_acl($config['id_user'], 0, 'RW') + || check_acl($config['id_user'], 0, 'RM') + ) { echo '
'; if (defined('METACONSOLE')) { echo '
'; @@ -935,7 +1095,12 @@ switch ($action) { echo '
'; } - html_print_submit_button(__('Create report'), 'create', false, 'class="sub next"'); + html_print_submit_button( + __('Create report'), + 'create', + false, + 'class="sub next"' + ); echo ''; echo '
'; @@ -945,7 +1110,12 @@ switch ($action) { } echo ''; - html_print_submit_button(__('Delete'), 'delete_btn', false, 'class="sub delete" style="margin-left:5px;"'); + html_print_submit_button( + __('Delete'), + 'delete_btn', + false, + 'class="sub delete" style="margin-left:5px;"' + ); echo '
'; echo '
'; } @@ -959,7 +1129,7 @@ switch ($action) { case 'main': $reportName = ''; $idGroupReport = 0; - // All groups + // All groups. $description = ''; $resultOperationDB = null; $report_id_user = 0; @@ -992,12 +1162,15 @@ switch ($action) { $reportName = get_parameter('name'); $idGroupReport = get_parameter('id_group'); $description = get_parameter('description'); - $type_access_selected = get_parameter('type_access', 'group_view'); + $type_access_selected = get_parameter( + 'type_access', + 'group_view' + ); $id_group_edit_param = (int) get_parameter('id_group_edit', 0); $report_id_user = get_parameter('report_id_user'); $non_interactive = get_parameter('non_interactive', 0); - // Pretty font by default for pdf + // Pretty font by default for pdf. $custom_font = 'FreeSans.ttf'; switch ($type_access_selected) { @@ -1054,12 +1227,12 @@ switch ($action) { if ($resultOperationDB !== false) { db_pandora_audit( 'Report management', - "Update report #$idReport" + 'Update report #'.$idReport ); } else { db_pandora_audit( 'Report management', - "Fail try to update report #$idReport" + 'Fail try to update report #'.$idReport ); } } else { @@ -1069,10 +1242,10 @@ switch ($action) { $action = 'edit'; } else if ($action == 'save') { if ($reportName != '' && $idGroupReport != '') { - // This flag allow to differentiate between normal console and metaconsole reports. + // This flag allow to differentiate + // between normal console and metaconsole reports. $metaconsole_report = (int) is_metaconsole(); - // Juanma (07/05/2014) New feature: Custom front page for reports. if ($config['custom_report_front']) { $custom_font = $config['custom_report_front_font']; $logo = $config['custom_report_front_logo']; @@ -1080,9 +1253,16 @@ switch ($action) { $first_page = $config['custom_report_front_firstpage']; $footer = $config['custom_report_front_footer']; } else { - $start_url = ui_get_full_url(false, false, false, false); + $start_url = ui_get_full_url( + false, + false, + false, + false + ); $first_page = '<p style="text-align: center;">&nbsp;</p> <p style="text-align: center;">&nbsp;</p> <p style="text-align: center;">&nbsp;</p> <p style="text-align: center;">&nbsp;</p> <p style="text-align: center;">&nbsp;</p> <p style="text-align: center;">&nbsp;</p> <p style="text-align: center;">&nbsp;</p> <p style="text-align: center;"><img src="'.$start_url.'/images/pandora_report_logo.png" alt="" width="800" /></p> <p style="text-align: center;">&nbsp;</p> <p style="text-align: center;"><span style="font-size: xx-large;">(_REPORT_NAME_)</span></p> <p style="text-align: center;"><span style="font-size: large;">(_DATETIME_)</span></p>'; - $logo = $header = $footer = null; + $logo = null; + $header = null; + $footer = null; } $idOrResult = db_process_sql_insert( @@ -1105,9 +1285,15 @@ switch ($action) { ); if ($idOrResult !== false) { - db_pandora_audit('Report management', "Create report #$idOrResult"); + db_pandora_audit( + 'Report management', + 'Create report #'.$idOrResult + ); } else { - db_pandora_audit('Report management', 'Fail try to create report'); + db_pandora_audit( + 'Report management', + 'Fail try to create report' + ); } } else { $idOrResult = false; @@ -1121,7 +1307,7 @@ switch ($action) { $report_id_user = $config['id_user']; } - $action = $resultOperationDB ? 'edit' : 'new'; + $action = ($resultOperationDB) ? 'edit' : 'new'; } break; @@ -1132,9 +1318,6 @@ switch ($action) { ['id_report' => $idReport] ); - - - $reportName = $report['name']; $idGroupReport = $report['id_group']; $description = $report['description']; @@ -1143,20 +1326,23 @@ switch ($action) { case 'update': $values = []; $values['id_report'] = $idReport; - // --------------------------------------------------- - // $values['name'] = (string) get_parameter('name'); $values['description'] = get_parameter('description'); $values['type'] = get_parameter('type', null); $values['recursion'] = get_parameter('recursion', null); $label = get_parameter('label', ''); - // Add macros name + // Add macros name. $items_label = []; $items_label['type'] = get_parameter('type'); $items_label['id_agent'] = get_parameter('id_agent'); - $items_label['id_agent_module'] = get_parameter('id_agent_module'); + $items_label['id_agent_module'] = get_parameter( + 'id_agent_module' + ); $name_it = (string) get_parameter('name'); - $values['name'] = reporting_label_macro($items_label, $name_it); + $values['name'] = reporting_label_macro( + $items_label, + $name_it + ); /* Added support for projection graphs, @@ -1168,7 +1354,9 @@ switch ($action) { switch ($values['type']) { case 'projection_graph': $values['period'] = get_parameter('period1'); - $values['top_n_value'] = get_parameter('period2'); + $values['top_n_value'] = get_parameter( + 'period2' + ); $values['text'] = get_parameter('text'); $good_format = true; break; @@ -1191,16 +1379,29 @@ switch ($action) { case 'prediction_date': $values['period'] = get_parameter('period1'); - $values['top_n'] = get_parameter('radiobutton_max_min_avg'); - $values['top_n_value'] = get_parameter('quantity'); + $values['top_n'] = get_parameter( + 'radiobutton_max_min_avg' + ); + $values['top_n_value'] = get_parameter( + 'quantity' + ); $interval_max = get_parameter('max_interval'); $interval_min = get_parameter('min_interval'); // Checks intervals fields. - if (preg_match('/^(\-)*[0-9]*\.?[0-9]+$/', $interval_max) and preg_match('/^(\-)*[0-9]*\.?[0-9]+$/', $interval_min)) { + if (preg_match( + '/^(\-)*[0-9]*\.?[0-9]+$/', + $interval_max + ) + && preg_match( + '/^(\-)*[0-9]*\.?[0-9]+$/', + $interval_min + ) + ) { $good_format = true; } - $intervals = get_parameter('max_interval').';'.get_parameter('min_interval'); + $intervals = get_parameter('max_interval').';'; + $intervals .= get_parameter('min_interval'); $values['text'] = $intervals; break; @@ -1211,19 +1412,32 @@ switch ($action) { case 'SLA': case 'availability_graph': $values['period'] = get_parameter('period'); - $values['top_n'] = get_parameter('combo_sla_sort_options', 0); - $values['top_n_value'] = get_parameter('quantity'); + $values['top_n'] = get_parameter( + 'combo_sla_sort_options', + 0 + ); + $values['top_n_value'] = get_parameter( + 'quantity' + ); $values['text'] = get_parameter('text'); - $values['show_graph'] = get_parameter('combo_graph_options'); + $values['show_graph'] = get_parameter( + 'combo_graph_options' + ); $good_format = true; break; case 'agent_module': $agents_to_report = get_parameter('id_agents2'); - $modules_to_report = get_parameter('module', ''); + $modules_to_report = get_parameter( + 'module', + '' + ); - $es['module'] = get_same_modules($agents_to_report, $modules_to_report); + $es['module'] = get_same_modules( + $agents_to_report, + $modules_to_report + ); $es['id_agents'] = $agents_to_report; $values['external_source'] = json_encode($es); @@ -1234,7 +1448,9 @@ switch ($action) { $values['period'] = 0; $es['date'] = get_parameter('date'); $es['id_agents'] = get_parameter('id_agents'); - $es['inventory_modules'] = get_parameter('inventory_modules'); + $es['inventory_modules'] = get_parameter( + 'inventory_modules' + ); $description = get_parameter('description'); $values['external_source'] = json_encode($es); $good_format = true; @@ -1243,7 +1459,9 @@ switch ($action) { case 'inventory_changes': $values['period'] = get_parameter('period'); $es['id_agents'] = get_parameter('id_agents'); - $es['inventory_modules'] = get_parameter('inventory_modules'); + $es['inventory_modules'] = get_parameter( + 'inventory_modules' + ); $description = get_parameter('description'); $values['external_source'] = json_encode($es); $good_format = true; @@ -1252,38 +1470,74 @@ switch ($action) { case 'netflow_area': case 'netflow_data': case 'netflow_summary': - $values['text'] = get_parameter('netflow_filter'); - $values['description'] = get_parameter('description'); + $values['text'] = get_parameter( + 'netflow_filter' + ); + $values['description'] = get_parameter( + 'description' + ); $values['period'] = get_parameter('period'); $values['top_n'] = get_parameter('resolution'); - $values['top_n_value'] = get_parameter('max_values'); + $values['top_n_value'] = get_parameter( + 'max_values' + ); $good_format = true; break; case 'availability': // HACK it is saved in show_graph field. // Show interfaces instead the modules. - $values['show_graph'] = get_parameter('checkbox_show_address_agent'); - $values['period'] = get_parameter('period'); - $values['total_time'] = get_parameter('total_time'); - $values['time_failed'] = get_parameter('time_failed'); - $values['time_in_ok_status'] = get_parameter('time_in_ok_status'); - $values['time_in_unknown_status'] = get_parameter('time_in_unknown_status'); - $values['time_of_not_initialized_module'] = get_parameter('time_of_not_initialized_module'); - $values['time_of_downtime'] = get_parameter('time_of_downtime'); - $values['total_checks'] = get_parameter('total_checks'); - $values['checks_failed'] = get_parameter('checks_failed'); - $values['checks_in_ok_status'] = get_parameter('checks_in_ok_status'); - $values['unknown_checks'] = get_parameter('unknown_checks'); - $values['agent_max_value'] = get_parameter('agent_max_value'); - $values['agent_min_value'] = get_parameter('agent_min_value'); + $values['show_graph'] = get_parameter( + 'checkbox_show_address_agent' + ); + $values['period'] = get_parameter( + 'period' + ); + $values['total_time'] = get_parameter( + 'total_time' + ); + $values['time_failed'] = get_parameter( + 'time_failed' + ); + $values['time_in_ok_status'] = get_parameter( + 'time_in_ok_status' + ); + $values['time_in_unknown_status'] = get_parameter( + 'time_in_unknown_status' + ); + $values['time_of_not_initialized_module'] = get_parameter( + 'time_of_not_initialized_module' + ); + $values['time_of_downtime'] = get_parameter( + 'time_of_downtime' + ); + $values['total_checks'] = get_parameter( + 'total_checks' + ); + $values['checks_failed'] = get_parameter( + 'checks_failed' + ); + $values['checks_in_ok_status'] = get_parameter( + 'checks_in_ok_status' + ); + $values['unknown_checks'] = get_parameter( + 'unknown_checks' + ); + $values['agent_max_value'] = get_parameter( + 'agent_max_value' + ); + $values['agent_min_value'] = get_parameter( + 'agent_min_value' + ); $good_format = true; break; case 'simple_graph': case 'simple_baseline_graph': // HACK it is saved in show_graph field. - $values['show_graph'] = (int) get_parameter('time_compare_overlapped'); + $values['show_graph'] = (int) get_parameter( + 'time_compare_overlapped' + ); $values['period'] = get_parameter('period'); $good_format = true; break; @@ -1292,24 +1546,37 @@ switch ($action) { case 'max_value': case 'avg_value': $values['period'] = get_parameter('period'); - $values['lapse_calc'] = get_parameter('lapse_calc'); + $values['lapse_calc'] = get_parameter( + 'lapse_calc' + ); $values['lapse'] = get_parameter('lapse'); - $values['visual_format'] = get_parameter('visual_format'); + $values['visual_format'] = get_parameter( + 'visual_format' + ); $good_format = true; break; case 'nt_top_n': $values['period'] = get_parameter('period'); - $values['top_n_value'] = get_parameter('quantity'); + $values['top_n_value'] = get_parameter( + 'quantity' + ); $good_format = true; break; default: $values['period'] = get_parameter('period'); - $values['top_n'] = get_parameter('radiobutton_max_min_avg', 0); - $values['top_n_value'] = get_parameter('quantity'); + $values['top_n'] = get_parameter( + 'radiobutton_max_min_avg', + 0 + ); + $values['top_n_value'] = get_parameter( + 'quantity' + ); $values['text'] = get_parameter('text'); - $values['show_graph'] = get_parameter('combo_graph_options'); + $values['show_graph'] = get_parameter( + 'combo_graph_options' + ); $good_format = true; break; } @@ -1319,16 +1586,27 @@ switch ($action) { $values['id_agent_module'] = ''; if (isset($values['type'])) { - if (($values['type'] == 'alert_report_agent') or ($values['type'] == 'event_report_agent') or ($values['type'] == 'agent_configuration') or ($values['type'] == 'group_configuration')) { + if (($values['type'] == 'alert_report_agent') + || ($values['type'] == 'event_report_agent') + || ($values['type'] == 'agent_configuration') + || ($values['type'] == 'group_configuration') + ) { $values['id_agent_module'] = ''; } else { - $values['id_agent_module'] = get_parameter('id_agent_module'); + $values['id_agent_module'] = get_parameter( + 'id_agent_module' + ); } } else { - $values['id_agent_module'] = get_parameter('id_agent_module'); + $values['id_agent_module'] = get_parameter( + 'id_agent_module' + ); } - $values['only_display_wrong'] = (int) get_parameter('checkbox_only_display_wrong', 0); + $values['only_display_wrong'] = (int) get_parameter( + 'checkbox_only_display_wrong', + 0 + ); $values['monday'] = get_parameter('monday', 0); $values['tuesday'] = get_parameter('tuesday', 0); $values['wednesday'] = get_parameter('wednesday', 0); @@ -1337,105 +1615,220 @@ switch ($action) { $values['saturday'] = get_parameter('saturday', 0); $values['sunday'] = get_parameter('sunday', 0); $values['total_time'] = get_parameter('total_time', 0); - $values['time_failed'] = get_parameter('time_failed', 0); - $values['time_in_ok_status'] = get_parameter('time_in_ok_status', 0); - $values['time_in_unknown_status'] = get_parameter('time_in_unknown_status', 0); - $values['time_of_not_initialized_module'] = get_parameter('time_of_not_initialized_module', 0); - $values['time_of_downtime'] = get_parameter('time_of_downtime', 0); - $values['total_checks'] = get_parameter('total_checks', 0); - $values['checks_failed'] = get_parameter('checks_failed', 0); - $values['checks_in_ok_status'] = get_parameter('checks_in_ok_status', 0); - $values['unknown_checks'] = get_parameter('unknown_checks', 0); - $values['agent_max_value'] = get_parameter('agent_max_value', 0); - $values['agent_min_value'] = get_parameter('agent_min_value', 0); + $values['time_failed'] = get_parameter( + 'time_failed', + 0 + ); + $values['time_in_ok_status'] = get_parameter( + 'time_in_ok_status', + 0 + ); + $values['time_in_unknown_status'] = get_parameter( + 'time_in_unknown_status', + 0 + ); + $values['time_of_not_initialized_module'] = get_parameter( + 'time_of_not_initialized_module', + 0 + ); + $values['time_of_downtime'] = get_parameter( + 'time_of_downtime', + 0 + ); + $values['total_checks'] = get_parameter( + 'total_checks', + 0 + ); + $values['checks_failed'] = get_parameter( + 'checks_failed', + 0 + ); + $values['checks_in_ok_status'] = get_parameter( + 'checks_in_ok_status', + 0 + ); + $values['unknown_checks'] = get_parameter( + 'unknown_checks', + 0 + ); + $values['agent_max_value'] = get_parameter( + 'agent_max_value', + 0 + ); + $values['agent_min_value'] = get_parameter( + 'agent_min_value', + 0 + ); - switch ($config['dbtype']) { - case 'mysql': - case 'postgresql': - $values['time_from'] = get_parameter('time_from'); - $values['time_to'] = get_parameter('time_to'); - break; + $values['time_from'] = get_parameter( + 'time_from' + ); + $values['time_to'] = get_parameter('time_to'); - case 'oracle': - $values['time_from'] = '#to_date(\''.get_parameter('time_from').'\',\'hh24:mi:ss\')'; - $values['time_to'] = '#to_date(\''.get_parameter('time_to').'\', \'hh24:mi:ss\')'; - break; - - default: - // Default. - break; - } - - $values['group_by_agent'] = get_parameter('checkbox_row_group_by_agent'); - $values['show_resume'] = get_parameter('checkbox_show_resume'); - $values['order_uptodown'] = get_parameter('radiobutton_order_uptodown'); - $values['exception_condition'] = (int) get_parameter('exception_condition', 0); - $values['exception_condition_value'] = get_parameter('exception_condition_value'); - $values['id_module_group'] = get_parameter('combo_modulegroup'); + $values['group_by_agent'] = get_parameter( + 'checkbox_row_group_by_agent' + ); + $values['show_resume'] = get_parameter( + 'checkbox_show_resume' + ); + $values['order_uptodown'] = get_parameter( + 'radiobutton_order_uptodown' + ); + $values['exception_condition'] = (int) get_parameter( + 'exception_condition', + 0 + ); + $values['exception_condition_value'] = get_parameter( + 'exception_condition_value' + ); + $values['id_module_group'] = get_parameter( + 'combo_modulegroup' + ); $values['id_group'] = get_parameter('combo_group'); $values['server_name'] = get_parameter('server_name'); $server_id = (int) get_parameter('server_id'); if ($server_id != 0) { - $connection = metaconsole_get_connection_by_id($server_id); + $connection = metaconsole_get_connection_by_id( + $server_id + ); $values['server_name'] = $connection['server_name']; } if ($values['server_name'] == '') { - $values['server_name'] = get_parameter('combo_server'); + $values['server_name'] = get_parameter( + 'combo_server' + ); } - if ((($values['type'] == 'custom_graph') || ($values['type'] == 'automatic_custom_graph')) && ($values['id_gs'] == 0 || $values['id_gs'] == '')) { + if ((($values['type'] == 'custom_graph') + || ($values['type'] == 'automatic_custom_graph')) + && ($values['id_gs'] == 0 || $values['id_gs'] == '') + ) { $resultOperationDB = false; break; } - $show_summary_group = get_parameter('show_summary_group', 0); - $filter_event_severity = get_parameter('filter_event_severity', 0); - $filter_event_type = get_parameter('filter_event_type', ''); - $filter_event_status = get_parameter('filter_event_status', 0); + $show_summary_group = get_parameter( + 'show_summary_group', + 0 + ); + $filter_event_severity = get_parameter( + 'filter_event_severity', + 0 + ); + $filter_event_type = get_parameter( + 'filter_event_type', + '' + ); + $filter_event_status = get_parameter( + 'filter_event_status', + 0 + ); - $event_graph_by_agent = get_parameter('event_graph_by_agent', 0); - $event_graph_by_user_validator = get_parameter('event_graph_by_user_validator', 0); - $event_graph_by_criticity = get_parameter('event_graph_by_criticity', 0); - $event_graph_validated_vs_unvalidated = get_parameter('event_graph_validated_vs_unvalidated', 0); + $event_graph_by_agent = get_parameter( + 'event_graph_by_agent', + 0 + ); + $event_graph_by_user_validator = get_parameter( + 'event_graph_by_user_validator', + 0 + ); + $event_graph_by_criticity = get_parameter( + 'event_graph_by_criticity', + 0 + ); + $event_graph_validated_vs_unvalidated = get_parameter( + 'event_graph_validated_vs_unvalidated', + 0 + ); - $event_filter_search = get_parameter('filter_search', ''); + $event_filter_search = get_parameter( + 'filter_search', + '' + ); // If metaconsole is activated. - if ($config['metaconsole'] == 1 && defined('METACONSOLE')) { - if (($values['type'] == 'custom_graph') or ($values['type'] == 'automatic_custom_graph')) { - $id_gs = substr($values['id_gs'], 0, strpos($values['id_gs'], '|')); + if ($config['metaconsole'] == 1 + && defined('METACONSOLE') + ) { + if (($values['type'] == 'custom_graph') + || ($values['type'] == 'automatic_custom_graph') + ) { + $id_gs = substr( + $values['id_gs'], + 0, + strpos($values['id_gs'], '|') + ); if ($id_gs !== false) { - $server_name = strstr($values['id_gs'], '|'); + $server_name = strstr( + $values['id_gs'], + '|' + ); $values['id_gs'] = $id_gs; - $values['server_name'] = substr($server_name, 1, strlen($server_name)); + $values['server_name'] = substr( + $server_name, + 1, + strlen($server_name) + ); } } // Get agent and server name. - $agent_name_server = io_safe_output(get_parameter('agent')); + $agent_name_server = io_safe_output( + get_parameter('agent') + ); if (isset($agent_name_server)) { - $separator_pos = strpos($agent_name_server, '('); + $separator_pos = strpos( + $agent_name_server, + '(' + ); - if (($separator_pos != false) and ($separator_pos != 0)) { - $server_name = substr($agent_name_server, $separator_pos); - $server_name = str_replace('(', '', $server_name); - $server_name = str_replace(')', '', $server_name); + if (($separator_pos != false) + || ($separator_pos != 0) + ) { + $server_name = substr( + $agent_name_server, + $separator_pos + ); + $server_name = str_replace( + '(', + '', + $server_name + ); + $server_name = str_replace( + ')', + '', + $server_name + ); // Will update server_name variable. $values['server_name'] = trim($server_name); - $agent_name = substr($agent_name_server, 0, $separator_pos); + $agent_name = substr( + $agent_name_server, + 0, + $separator_pos + ); } } } - if (($values['type'] == 'sql') or ($values['type'] == 'sql_graph_hbar') or ($values['type'] == 'sql_graph_vbar') or ($values['type'] == 'sql_graph_pie')) { - $values['treport_custom_sql_id'] = get_parameter('id_custom'); + if (($values['type'] == 'sql') + || ($values['type'] == 'sql_graph_hbar') + || ($values['type'] == 'sql_graph_vbar') + || ($values['type'] == 'sql_graph_pie') + ) { + $values['treport_custom_sql_id'] = get_parameter( + 'id_custom' + ); if ($values['treport_custom_sql_id'] == 0) { - $values['external_source'] = get_parameter('sql'); + $values['external_source'] = get_parameter( + 'sql' + ); } - $values['historical_db'] = get_parameter('historical_db_check'); + $values['historical_db'] = get_parameter( + 'historical_db_check' + ); $values['top_n_value'] = get_parameter('max_items'); } else if ($values['type'] == 'url') { $values['external_source'] = get_parameter('url'); @@ -1448,21 +1841,42 @@ switch ($action) { $values['line_separator'] = get_parameter('line'); $style = []; - $style['show_in_same_row'] = get_parameter('show_in_same_row', 0); - $style['show_in_landscape'] = get_parameter('show_in_landscape', 0); - $style['hide_notinit_agents'] = get_parameter('hide_notinit_agents', 0); - $style['priority_mode'] = get_parameter('priority_mode', REPORT_PRIORITY_MODE_OK); - $style['dyn_height'] = get_parameter('dyn_height', 230); + $style['show_in_same_row'] = get_parameter( + 'show_in_same_row', + 0 + ); + $style['show_in_landscape'] = get_parameter( + 'show_in_landscape', + 0 + ); + $style['hide_notinit_agents'] = get_parameter( + 'hide_notinit_agents', + 0 + ); + $style['priority_mode'] = get_parameter( + 'priority_mode', + REPORT_PRIORITY_MODE_OK + ); + $style['dyn_height'] = get_parameter( + 'dyn_height', + 230 + ); switch ($values['type']) { case 'event_report_agent': case 'event_report_group': case 'event_report_module': - // Added for events items - $style['show_summary_group'] = $show_summary_group; - $style['filter_event_severity'] = json_encode($filter_event_severity); - $style['filter_event_type'] = json_encode($filter_event_type); - $style['filter_event_status'] = json_encode($filter_event_status); + // Added for events items. + $style['show_summary_group'] = $show_summary_group; + $style['filter_event_severity'] = json_encode( + $filter_event_severity + ); + $style['filter_event_type'] = json_encode( + $filter_event_type + ); + $style['filter_event_status'] = json_encode( + $filter_event_status + ); $style['event_graph_by_agent'] = $event_graph_by_agent; $style['event_graph_by_user_validator'] = $event_graph_by_user_validator; @@ -1478,10 +1892,15 @@ switch ($action) { break; case 'simple_graph': - // Warning. We are using this column to hold this value to avoid - // the modification of the database for compatibility reasons. - $style['percentil'] = (int) get_parameter('percentil'); - $style['fullscale'] = (int) get_parameter('fullscale'); + // Warning. We are using this column to hold + // this value to avoid the modification of the + // database for compatibility reasons. + $style['percentil'] = (int) get_parameter( + 'percentil' + ); + $style['fullscale'] = (int) get_parameter( + 'fullscale' + ); if ($label != '') { $style['label'] = $label; } else { @@ -1490,7 +1909,9 @@ switch ($action) { break; case 'network_interfaces_report': - $style['fullscale'] = (int) get_parameter('fullscale'); + $style['fullscale'] = (int) get_parameter( + 'fullscale' + ); break; case 'module_histogram_graph': @@ -1553,11 +1974,9 @@ switch ($action) { break; case 'save': - $values = []; $values['id_report'] = $idReport; $values['type'] = get_parameter('type', null); - // $values['name'] = (string) get_parameter('name'); $values['description'] = get_parameter('description'); $label = get_parameter('label', ''); @@ -1565,42 +1984,71 @@ switch ($action) { $items_label = []; $items_label['type'] = get_parameter('type'); $items_label['id_agent'] = get_parameter('id_agent'); - $items_label['id_agent_module'] = get_parameter('id_agent_module'); + $items_label['id_agent_module'] = get_parameter( + 'id_agent_module' + ); $name_it = (string) get_parameter('name'); $values['recursion'] = get_parameter('recursion', null); - $values['name'] = reporting_label_macro($items_label, $name_it); + $values['name'] = reporting_label_macro( + $items_label, + $name_it + ); - // Support for projection graph, prediction date and SLA reports - // 'top_n_value', 'top_n' and 'text' fields will be reused for these types of report. + // Support for projection graph, prediction date + // and SLA reports 'top_n_value', 'top_n' and 'text' + // fields will be reused for these types of report. switch ($values['type']) { case 'projection_graph': $values['period'] = get_parameter('period1'); - $values['top_n_value'] = get_parameter('period2'); + $values['top_n_value'] = get_parameter( + 'period2' + ); $values['text'] = get_parameter('text'); $good_format = true; break; case 'prediction_date': $values['period'] = get_parameter('period1'); - $values['top_n'] = get_parameter('radiobutton_max_min_avg'); - $values['top_n_value'] = get_parameter('quantity'); + $values['top_n'] = get_parameter( + 'radiobutton_max_min_avg' + ); + $values['top_n_value'] = get_parameter( + 'quantity' + ); $interval_max = get_parameter('max_interval'); $interval_min = get_parameter('min_interval'); - // Checks intervals fields - if (preg_match('/^(\-)*[0-9]*\.?[0-9]+$/', $interval_max) and preg_match('/^(\-)*[0-9]*\.?[0-9]+$/', $interval_min)) { + // Checks intervals fields. + if (preg_match( + '/^(\-)*[0-9]*\.?[0-9]+$/', + $interval_max + ) + && preg_match( + '/^(\-)*[0-9]*\.?[0-9]+$/', + $interval_min + ) + ) { $good_format = true; } - $intervals = get_parameter('max_interval').';'.get_parameter('min_interval'); + $intervals = get_parameter( + 'max_interval' + ).';'.get_parameter('min_interval'); $values['text'] = $intervals; break; case 'SLA': $values['period'] = get_parameter('period'); - $values['top_n'] = get_parameter('combo_sla_sort_options', 0); - $values['top_n_value'] = get_parameter('quantity'); + $values['top_n'] = get_parameter( + 'combo_sla_sort_options', + 0 + ); + $values['top_n_value'] = get_parameter( + 'quantity' + ); $values['text'] = get_parameter('text'); - $values['show_graph'] = get_parameter('combo_graph_options'); + $values['show_graph'] = get_parameter( + 'combo_graph_options' + ); $good_format = true; break; @@ -1609,7 +2057,9 @@ switch ($action) { $values['period'] = 0; $es['date'] = get_parameter('date'); $es['id_agents'] = get_parameter('id_agents'); - $es['inventory_modules'] = get_parameter('inventory_modules'); + $es['inventory_modules'] = get_parameter( + 'inventory_modules' + ); $values['external_source'] = json_encode($es); $good_format = true; break; @@ -1632,9 +2082,15 @@ switch ($action) { case 'agent_module': $agents_to_report = get_parameter('id_agents2'); - $modules_to_report = get_parameter('module', ''); + $modules_to_report = get_parameter( + 'module', + '' + ); - $es['module'] = get_same_modules($agents_to_report, $modules_to_report); + $es['module'] = get_same_modules( + $agents_to_report, + $modules_to_report + ); $es['id_agents'] = $agents_to_report; $values['external_source'] = json_encode($es); @@ -1644,7 +2100,9 @@ switch ($action) { case 'inventory_changes': $values['period'] = get_parameter('period'); $es['id_agents'] = get_parameter('id_agents'); - $es['inventory_modules'] = get_parameter('inventory_modules'); + $es['inventory_modules'] = get_parameter( + 'inventory_modules' + ); $values['external_source'] = json_encode($es); $good_format = true; break; @@ -1662,11 +2120,17 @@ switch ($action) { case 'netflow_area': case 'netflow_data': case 'netflow_summary': - $values['text'] = get_parameter('netflow_filter'); - $values['description'] = get_parameter('description'); + $values['text'] = get_parameter( + 'netflow_filter' + ); + $values['description'] = get_parameter( + 'description' + ); $values['period'] = get_parameter('period'); $values['top_n'] = get_parameter('resolution'); - $values['top_n_value'] = get_parameter('max_values'); + $values['top_n_value'] = get_parameter( + 'max_values' + ); $good_format = true; break; @@ -1674,14 +2138,18 @@ switch ($action) { $values['period'] = get_parameter('period'); // HACK it is saved in show_graph field. // Show interfaces instead the modules. - $values['show_graph'] = get_parameter('checkbox_show_address_agent'); + $values['show_graph'] = get_parameter( + 'checkbox_show_address_agent' + ); $good_format = true; break; case 'simple_graph': case 'simple_baseline_graph': // HACK it is saved in show_graph field. - $values['show_graph'] = (int) get_parameter('time_compare_overlapped'); + $values['show_graph'] = (int) get_parameter( + 'time_compare_overlapped' + ); $values['period'] = get_parameter('period'); $good_format = true; break; @@ -1690,24 +2158,37 @@ switch ($action) { case 'max_value': case 'avg_value': $values['period'] = get_parameter('period'); - $values['lapse_calc'] = get_parameter('lapse_calc'); + $values['lapse_calc'] = get_parameter( + 'lapse_calc' + ); $values['lapse'] = get_parameter('lapse'); - $values['visual_format'] = get_parameter('visual_format'); + $values['visual_format'] = get_parameter( + 'visual_format' + ); $good_format = true; break; case 'nt_top_n': - $values['top_n_value'] = get_parameter('quantity'); + $values['top_n_value'] = get_parameter( + 'quantity' + ); $values['period'] = get_parameter('period'); $good_format = true; break; default: $values['period'] = get_parameter('period'); - $values['top_n'] = get_parameter('radiobutton_max_min_avg', 0); - $values['top_n_value'] = get_parameter('quantity'); + $values['top_n'] = get_parameter( + 'radiobutton_max_min_avg', + 0 + ); + $values['top_n_value'] = get_parameter( + 'quantity' + ); $values['text'] = get_parameter('text'); - $values['show_graph'] = get_parameter('combo_graph_options'); + $values['show_graph'] = get_parameter( + 'combo_graph_options' + ); $good_format = true; break; } @@ -1717,42 +2198,37 @@ switch ($action) { $values['server_name'] = get_parameter('server_name'); $server_id = (int) get_parameter('server_id'); if ($server_id != 0) { - $connection = metaconsole_get_connection_by_id($server_id); + $connection = metaconsole_get_connection_by_id( + $server_id + ); $values['server_name'] = $connection['server_name']; } if ($values['server_name'] == '') { - $values['server_name'] = get_parameter('combo_server'); + $values['server_name'] = get_parameter( + 'combo_server' + ); } $values['id_agent'] = get_parameter('id_agent'); $values['id_gs'] = get_parameter('id_custom_graph'); - if (($values['type'] == 'alert_report_agent') or ($values['type'] == 'event_report_agent') or ($values['type'] == 'agent_configuration') or ($values['type'] == 'group_configuration')) { + if (($values['type'] == 'alert_report_agent') + || ($values['type'] == 'event_report_agent') + || ($values['type'] == 'agent_configuration') + || ($values['type'] == 'group_configuration') + ) { $values['id_agent_module'] = ''; } else { - $values['id_agent_module'] = get_parameter('id_agent_module'); + $values['id_agent_module'] = get_parameter( + 'id_agent_module' + ); } - switch ($config['dbtype']) { - case 'mysql': - case 'postgresql': - $values['only_display_wrong'] = (int) get_parameter('checkbox_only_display_wrong', 0); - break; - - case 'oracle': - $only_display_wrong_tmp = get_parameter('checkbox_only_display_wrong'); - if (empty($only_display_wrong_tmp)) { - $values['only_display_wrong'] = 0; - } else { - $values['only_display_wrong'] = $only_display_wrong_tmp; - } - break; - - default: - // Default. - break; - } + $values['only_display_wrong'] = (int) get_parameter( + 'checkbox_only_display_wrong', + 0 + ); $values['monday'] = get_parameter('monday', 0); $values['tuesday'] = get_parameter('tuesday', 0); @@ -1762,68 +2238,132 @@ switch ($action) { $values['saturday'] = get_parameter('saturday', 0); $values['sunday'] = get_parameter('sunday', 0); $values['total_time'] = get_parameter('total_time', 0); - $values['time_failed'] = get_parameter('time_failed', 0); - $values['time_in_ok_status'] = get_parameter('time_in_ok_status', 0); - $values['time_in_unknown_status'] = get_parameter('time_in_unknown_status', 0); - $values['time_of_not_initialized_module'] = get_parameter('time_of_not_initialized_module', 0); - $values['time_of_downtime'] = get_parameter('time_of_downtime', 0); - $values['total_checks'] = get_parameter('total_checks', 0); - $values['checks_failed'] = get_parameter('checks_failed', 0); - $values['checks_in_ok_status'] = get_parameter('checks_in_ok_status', 0); - $values['unknown_checks'] = get_parameter('unknown_checks', 0); - $values['agent_max_value'] = get_parameter('agent_max_value', 0); - $values['agent_min_value'] = get_parameter('agent_min_value', 0); - switch ($config['dbtype']) { - case 'mysql': - case 'postgresql': - $values['time_from'] = get_parameter('time_from'); - $values['time_to'] = get_parameter('time_to'); - break; + $values['time_failed'] = get_parameter( + 'time_failed', + 0 + ); + $values['time_in_ok_status'] = get_parameter( + 'time_in_ok_status', + 0 + ); + $values['time_in_unknown_status'] = get_parameter( + 'time_in_unknown_status', + 0 + ); + $values['time_of_not_initialized_module'] = get_parameter( + 'time_of_not_initialized_module', + 0 + ); + $values['time_of_downtime'] = get_parameter( + 'time_of_downtime', + 0 + ); + $values['total_checks'] = get_parameter( + 'total_checks', + 0 + ); + $values['checks_failed'] = get_parameter( + 'checks_failed', + 0 + ); + $values['checks_in_ok_status'] = get_parameter( + 'checks_in_ok_status', + 0 + ); + $values['unknown_checks'] = get_parameter( + 'unknown_checks', + 0 + ); + $values['agent_max_value'] = get_parameter( + 'agent_max_value', + 0 + ); + $values['agent_min_value'] = get_parameter( + 'agent_min_value', + 0 + ); - case 'oracle': - $values['time_from'] = '#to_date(\''.get_parameter('time_from').'\',\'hh24:mi:ss\')'; - $values['time_to'] = '#to_date(\''.get_parameter('time_to').'\', \'hh24:mi:ss\')'; - break; + $values['time_from'] = get_parameter( + 'time_from' + ); + $values['time_to'] = get_parameter('time_to'); - default: - // Default. - break; - } - - $values['group_by_agent'] = get_parameter('checkbox_row_group_by_agent', 0); - $values['show_resume'] = get_parameter('checkbox_show_resume', 0); - $values['order_uptodown'] = get_parameter('radiobutton_order_uptodown', 0); - $values['exception_condition'] = (int) get_parameter('radiobutton_exception_condition', 0); - $values['exception_condition_value'] = get_parameter('exception_condition_value'); - $values['id_module_group'] = get_parameter('combo_modulegroup'); + $values['group_by_agent'] = get_parameter( + 'checkbox_row_group_by_agent', + 0 + ); + $values['show_resume'] = get_parameter( + 'checkbox_show_resume', + 0 + ); + $values['order_uptodown'] = get_parameter( + 'radiobutton_order_uptodown', + 0 + ); + $values['exception_condition'] = (int) get_parameter( + 'radiobutton_exception_condition', + 0 + ); + $values['exception_condition_value'] = get_parameter( + 'exception_condition_value' + ); + $values['id_module_group'] = get_parameter( + 'combo_modulegroup' + ); $values['id_group'] = get_parameter('combo_group'); - if ((($values['type'] == 'custom_graph') or ($values['type'] == 'automatic_custom_graph')) && ($values['id_gs'] == 0 || $values['id_gs'] == '')) { + if ((($values['type'] == 'custom_graph') + || ($values['type'] == 'automatic_custom_graph')) + && ($values['id_gs'] == 0 || $values['id_gs'] == '') + ) { $resultOperationDB = false; break; } - if ($config['metaconsole'] == 1 && defined('METACONSOLE')) { - if (($values['type'] == 'custom_graph') or ($values['type'] == 'automatic_custom_graph')) { - $id_gs = substr($values['id_gs'], 0, strpos($values['id_gs'], '|')); + if ($config['metaconsole'] == 1 + && defined('METACONSOLE') + ) { + if (($values['type'] == 'custom_graph') + || ($values['type'] == 'automatic_custom_graph') + ) { + $id_gs = substr( + $values['id_gs'], + 0, + strpos($values['id_gs'], '|') + ); if ($id_gs !== false && $id_gs !== '') { - $server_name = strstr($values['id_gs'], '|'); + $server_name = strstr( + $values['id_gs'], + '|' + ); $values['id_gs'] = $id_gs; - $values['server_name'] = substr($server_name, 1, strlen($server_name)); + $values['server_name'] = substr( + $server_name, + 1, + strlen($server_name) + ); } } } - if (($values['type'] == 'sql') || ($values['type'] == 'sql_graph_hbar') - || ($values['type'] == 'sql_graph_vbar') || ($values['type'] == 'sql_graph_pie') + if (($values['type'] == 'sql') + || ($values['type'] == 'sql_graph_hbar') + || ($values['type'] == 'sql_graph_vbar') + || ($values['type'] == 'sql_graph_pie') ) { - $values['treport_custom_sql_id'] = get_parameter('id_custom'); + $values['treport_custom_sql_id'] = get_parameter( + 'id_custom' + ); if ($values['treport_custom_sql_id'] == 0) { - $values['external_source'] = get_parameter('sql'); + $values['external_source'] = get_parameter( + 'sql' + ); } - $values['historical_db'] = get_parameter('historical_db_check'); + $values['historical_db'] = get_parameter( + 'historical_db_check' + ); $values['top_n_value'] = get_parameter('max_items'); } else if ($values['type'] == 'url') { $values['external_source'] = get_parameter('url'); @@ -1836,37 +2376,82 @@ switch ($action) { $values['line_separator'] = get_parameter('line'); $style = []; - $style['show_in_same_row'] = get_parameter('show_in_same_row', 0); - $style['show_in_landscape'] = get_parameter('show_in_landscape', 0); - $style['hide_notinit_agents'] = get_parameter('hide_notinit_agents', 0); - $style['priority_mode'] = get_parameter('priority_mode', REPORT_PRIORITY_MODE_OK); + $style['show_in_same_row'] = get_parameter( + 'show_in_same_row', + 0 + ); + $style['show_in_landscape'] = get_parameter( + 'show_in_landscape', + 0 + ); + $style['hide_notinit_agents'] = get_parameter( + 'hide_notinit_agents', + 0 + ); + $style['priority_mode'] = get_parameter( + 'priority_mode', + REPORT_PRIORITY_MODE_OK + ); $style['dyn_height'] = get_parameter('dyn_height', 230); switch ($values['type']) { case 'event_report_agent': case 'event_report_group': case 'event_report_module': - $show_summary_group = get_parameter('show_summary_group', 0); - $filter_event_severity = get_parameter('filter_event_severity', ''); - $filter_event_type = get_parameter('filter_event_type', ''); - $filter_event_status = get_parameter('filter_event_status', ''); + $show_summary_group = get_parameter( + 'show_summary_group', + 0 + ); + $filter_event_severity = get_parameter( + 'filter_event_severity', + '' + ); + $filter_event_type = get_parameter( + 'filter_event_type', + '' + ); + $filter_event_status = get_parameter( + 'filter_event_status', + '' + ); - $event_graph_by_agent = get_parameter('event_graph_by_agent', 0); - $event_graph_by_user_validator = get_parameter('event_graph_by_user_validator', 0); - $event_graph_by_criticity = get_parameter('event_graph_by_criticity', 0); - $event_graph_validated_vs_unvalidated = get_parameter('event_graph_validated_vs_unvalidated', 0); + $event_graph_by_agent = get_parameter( + 'event_graph_by_agent', + 0 + ); + $event_graph_by_user_validator = get_parameter( + 'event_graph_by_user_validator', + 0 + ); + $event_graph_by_criticity = get_parameter( + 'event_graph_by_criticity', + 0 + ); + $event_graph_validated_vs_unvalidated = get_parameter( + 'event_graph_validated_vs_unvalidated', + 0 + ); - $event_filter_search = get_parameter('filter_search', ''); + $event_filter_search = get_parameter( + 'filter_search', + '' + ); // Added for events items. - $style['show_summary_group'] = $show_summary_group; - $style['filter_event_severity'] = json_encode($filter_event_severity); - $style['filter_event_type'] = json_encode($filter_event_type); - $style['filter_event_status'] = json_encode($filter_event_status); + $style['show_summary_group'] = $show_summary_group; + $style['filter_event_severity'] = json_encode( + $filter_event_severity + ); + $style['filter_event_type'] = json_encode( + $filter_event_type + ); + $style['filter_event_status'] = json_encode( + $filter_event_status + ); - $style['event_graph_by_agent'] = $event_graph_by_agent; - $style['event_graph_by_user_validator'] = $event_graph_by_user_validator; - $style['event_graph_by_criticity'] = $event_graph_by_criticity; + $style['event_graph_by_agent'] = $event_graph_by_agent; + $style['event_graph_by_user_validator'] = $event_graph_by_user_validator; + $style['event_graph_by_criticity'] = $event_graph_by_criticity; $style['event_graph_validated_vs_unvalidated'] = $event_graph_validated_vs_unvalidated; @@ -1888,10 +2473,15 @@ switch ($action) { break; case 'simple_graph': - // Warning. We are using this column to hold this value to avoid - // the modification of the database for compatibility reasons. - $style['percentil'] = (int) get_parameter('percentil'); - $style['fullscale'] = (int) get_parameter('fullscale'); + // Warning. We are using this column to hold + // this value to avoid the modification + // of the database for compatibility reasons. + $style['percentil'] = (int) get_parameter( + 'percentil' + ); + $style['fullscale'] = (int) get_parameter( + 'fullscale' + ); if ($label != '') { $style['label'] = $label; } else { @@ -1900,7 +2490,9 @@ switch ($action) { break; case 'network_interfaces_report': - $style['fullscale'] = (int) get_parameter('fullscale'); + $style['fullscale'] = (int) get_parameter( + 'fullscale' + ); break; case 'module_histogram_graph': @@ -1937,21 +2529,6 @@ switch ($action) { $values['style'] = io_safe_input(json_encode($style)); if ($good_format) { - switch ($config['dbtype']) { - case 'oracle': - if (isset($values['type'])) { - $values[db_escape_key_identifier( - 'type' - )] = $values['type']; - unset($values['type']); - } - break; - - default: - // Default. - break; - } - $result = db_process_sql_insert( 'treport_content', $values @@ -1962,28 +2539,11 @@ switch ($action) { } else { $idItem = $result; - switch ($config['dbtype']) { - case 'mysql': - $max = db_get_all_rows_sql( - 'SELECT max(`order`) AS max - FROM treport_content - WHERE id_report = '.$idReport.';' - ); - break; - - case 'postgresql': - case 'oracle': - $max = db_get_all_rows_sql( - 'SELECT max("order") AS max - FROM treport_content - WHERE id_report = '.$idReport - ); - break; - - default: - // Default. - break; - } + $max = db_get_all_rows_sql( + 'SELECT max(`order`) AS max + FROM treport_content + WHERE id_report = '.$idReport.';' + ); if ($max === false) { $max = 0; @@ -1991,39 +2551,25 @@ switch ($action) { $max = $max[0]['max']; } - switch ($config['dbtype']) { - case 'mysql': - db_process_sql_update( - 'treport_content', - ['`order`' => ($max + 1)], - ['id_rc' => $idItem] - ); - break; - - case 'postgresql': - case 'oracle': - db_process_sql_update( - 'treport_content', - ['"order"' => ($max + 1)], - ['id_rc' => $idItem] - ); - break; - - default: - // Default. - break; - } + db_process_sql_update( + 'treport_content', + ['`order`' => ($max + 1)], + ['id_rc' => $idItem] + ); $resultOperationDB = true; } break; - } - - // If fields dont have good format. - else { + } else { + // If fields dont have good format. $resultOperationDB = false; } + break; + + default: + // Default. + break; } break; @@ -2058,20 +2604,35 @@ switch ($action) { $report = db_get_row_filter('treport', ['id_report' => $idReport]); $reportName = $report['name']; - $resultOperationDB = db_process_sql_delete('treport_content_sla_combined', ['id_report_content' => $idItem]); - $resultOperationDB2 = db_process_sql_delete('treport_content_item', ['id_report_content' => $idItem]); + $resultOperationDB = db_process_sql_delete( + 'treport_content_sla_combined', + ['id_report_content' => $idItem] + ); + $resultOperationDB2 = db_process_sql_delete( + 'treport_content_item', + ['id_report_content' => $idItem] + ); if ($resultOperationDB !== false) { - $resultOperationDB = db_process_sql_delete('treport_content', ['id_rc' => $idItem]); + $resultOperationDB = db_process_sql_delete( + 'treport_content', + ['id_rc' => $idItem] + ); } if ($resultOperationDB2 !== false) { - $resultOperationDB2 = db_process_sql_delete('treport_content', ['id_rc' => $idItem]); + $resultOperationDB2 = db_process_sql_delete( + 'treport_content', + ['id_rc' => $idItem] + ); } break; case 'order': $resultOperationDB = null; - $report = db_get_row_filter('treport', ['id_report' => $idReport]); + $report = db_get_row_filter( + 'treport', + ['id_report' => $idReport] + ); $reportName = $report['name']; $idGroupReport = $report['id_group']; @@ -2142,14 +2703,17 @@ switch ($action) { } $ids = db_get_all_rows_sql($sql); - } - // Sort functionality for metaconsole. - else if ($config['metaconsole'] == 1) { + } else if ($config['metaconsole'] == 1) { + // Sort functionality for metaconsole. switch ($field) { case 'agent': case 'module': $sql = 'SELECT id_rc, id_agent, id_agent_module, server_name FROM treport_content WHERE %s ORDER BY server_name'; - $sql = sprintf($sql, 'id_report = '.$idReport, '%s'); + $sql = sprintf( + $sql, + 'id_report = '.$idReport, + '%s' + ); $report_items = db_get_all_rows_sql($sql); @@ -2159,26 +2723,35 @@ switch ($action) { if (!empty($report_items)) { foreach ($report_items as $report_item) { - $connection = metaconsole_get_connection($report_item['server_name']); + $connection = metaconsole_get_connection( + $report_item['server_name'] + ); if (metaconsole_load_external_db($connection) != NOERR) { - // ui_print_error_message ("Error connecting to ".$server_name);. + continue; } switch ($field) { case 'agent': - $agents_name = agents_get_agents(['id_agente' => $report_item['id_agent']], 'nombre'); + $agents_name = agents_get_agents( + ['id_agente' => $report_item['id_agent']], + 'nombre' + ); // Item without agent. if (!$agents_name) { $element_name = ''; } else { - $agent_name = array_shift($agents_name); + $agent_name = array_shift( + $agents_name + ); $element_name = $agent_name['nombre']; } break; case 'module': - $module_name = modules_get_agentmodule_name($report_item['id_agent_module']); + $module_name = modules_get_agentmodule_name( + $report_item['id_agent_module'] + ); // Item without module. if (!$module_name) { @@ -2252,50 +2825,38 @@ switch ($action) { $ids = db_get_all_rows_sql($sql); break; + + default: + // Default. + break; } } $count = 1; $resultOperationDB = true; foreach ($ids as $id) { - $result = db_process_sql_update('treport_content', ['order' => $count], ['id_rc' => $id['id_rc']]); + $result = db_process_sql_update( + 'treport_content', + ['order' => $count], + ['id_rc' => $id['id_rc']] + ); if ($result === false) { $resultOperationDB = false; break; } - $count = ($count + 1); + $count++; } break; default: - switch ($config['dbtype']) { - case 'mysql': - $oldOrder = db_get_value_sql( - ' - SELECT `order` - FROM treport_content - WHERE id_rc = '.$idItem - ); - break; + $oldOrder = db_get_value_sql( + 'SELECT `order` + FROM treport_content + WHERE id_rc = '.$idItem + ); - case 'postgresql': - case 'oracle': - $oldOrder = db_get_value_sql( - ' - SELECT "order" - FROM treport_content - WHERE id_rc = '.$idItem - ); - break; - - default: - // Default. - break; - } - - // db_get_value_filter('order', 'treport_content', array('id_rc' => $idItem)); switch ($dir) { case 'up': $newOrder = ($oldOrder - 1); @@ -2310,79 +2871,22 @@ switch ($action) { break; } - switch ($config['dbtype']) { - case 'mysql': - $resultOperationDB = db_process_sql_update( - 'treport_content', - ['`order`' => $oldOrder], - [ - '`order`' => $newOrder, - 'id_report' => $idReport, - ] - ); - break; + $resultOperationDB = db_process_sql_update( + 'treport_content', + ['`order`' => $oldOrder], + [ + '`order`' => $newOrder, + 'id_report' => $idReport, + ] + ); - case 'postgresql': - $resultOperationDB = db_process_sql_update( - 'treport_content', - ['"order"' => $oldOrder], - [ - '"order"' => $newOrder, - 'id_report' => $idReport, - ] - ); - break; - - case 'oracle': - $resultOperationDB = db_process_sql_update( - 'treport_content', - ['"order"' => $oldOrder], - [ - '"order"' => $newOrder, - 'id_report' => $idReport, - ], - 'AND', - false - ); - break; - - default: - // Default. - break; - } if ($resultOperationDB !== false) { - switch ($config['dbtype']) { - case 'mysql': - $resultOperationDB = db_process_sql_update( - 'treport_content', - ['`order`' => $newOrder], - ['id_rc' => $idItem] - ); - break; - - case 'postgresql': - $resultOperationDB = db_process_sql_update( - 'treport_content', - ['"order"' => $newOrder], - ['id_rc' => $idItem] - ); - break; - - case 'oracle': - $resultOperationDB = db_process_sql_update( - 'treport_content', - ['"order"' => $newOrder], - ['id_rc' => $idItem], - 'AND', - false - ); - break; - - default: - // Default. - break; - } + $resultOperationDB = db_process_sql_update( + 'treport_content', + ['`order`' => $newOrder], + ['id_rc' => $idItem] + ); } break; } @@ -2408,13 +2912,16 @@ switch ($action) { break; default: - $subsection = reporting_enterprise_add_subsection_main($activeTab, $buttons); + $subsection = reporting_enterprise_add_subsection_main( + $activeTab, + $buttons + ); break; } // Page header for metaconsole. - if ($enterpriseEnable and defined('METACONSOLE')) { - // Bread crumbs + if ($enterpriseEnable && defined('METACONSOLE')) { + // Bread crumbs. ui_meta_add_breadcrumb( [ 'link' => 'index.php?sec=reporting&sec2=godmode/reporting/reporting_builder&pure='.$pure, @@ -2426,12 +2933,20 @@ switch ($action) { // Print header. ui_meta_print_header(__('Reporting'), '', $buttons); + } else { + // Page header for normal console. + ui_print_page_header( + $subsection, + 'images/op_reporting.png', + false, + '', + false, + $buttons, + false, + '', + 60 + ); } - // Page header for normal console. - else { - ui_print_page_header($subsection, 'images/op_reporting.png', false, '', false, $buttons, false, '', 60); - } - reporting_enterprise_select_main_tab($action); } @@ -2466,7 +2981,10 @@ $buttons = [ ]; if ($enterpriseEnable) { - $buttons = reporting_enterprise_add_Tabs($buttons, $idReport); + $buttons = reporting_enterprise_add_Tabs( + $buttons, + $idReport + ); } $buttons['view'] = [ @@ -2491,7 +3009,7 @@ if ($idReport != 0) { } // Page header for metaconsole. -if ($enterpriseEnable and defined('METACONSOLE')) { +if ($enterpriseEnable && defined('METACONSOLE')) { // Bread crumbs. ui_meta_add_breadcrumb( [ @@ -2532,7 +3050,11 @@ if ($resultOperationDB !== null) { break; } - ui_print_result_message($resultOperationDB, __('Successfull action'), __('Unsuccessful action

'.$err)); + ui_print_result_message( + $resultOperationDB, + __('Successfull action'), + __('Unsuccessful action

'.$err) + ); } switch ($activeTab) {