From ceca482158cd98a07cd4168751399ce567944356 Mon Sep 17 00:00:00 2001 From: mdtrooper Date: Tue, 24 Mar 2015 17:52:57 +0100 Subject: [PATCH] Working in the refactoring code of reporting. --- .../include/functions_reporting.php | 48 +++++--- .../include/functions_reporting_html.php | 113 +++++++++++++++++- 2 files changed, 142 insertions(+), 19 deletions(-) diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index 6c2f1bd706..1c2c5f220f 100644 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -86,6 +86,14 @@ function reporting_get_type($content) { return $content["type"]; } +function reporting_get_description($id_report) { + return db_get_value('description', 'treport', 'id_report', $id_report); +} + +function reporting_get_name($id_report) { + return db_get_value('name', 'treport', 'id_report', $id_report); +} + function reporting_make_reporting_data($id_report, $date, $time, $period = null, $type = 'dinamic', $force_width_chart = null, $force_height_chart = null) { @@ -161,6 +169,7 @@ function reporting_sql($report, $content) { global $config; $return = array(); + $return['type'] = 'sql'; if (empty($content['name'])) { $content['name'] = __('SQL'); @@ -168,9 +177,7 @@ function reporting_sql($report, $content) { $return['title'] = $content['name']; $return["description"] = $content["description"]; - $return["date"] = reporting_get_date_text( - $report, - $content); + $return["date"] = reporting_get_date_text(); if ($content['treport_custom_sql_id'] != 0) { switch ($config["dbtype"]) { @@ -238,6 +245,7 @@ function reporting_general($report, $content) { global $config; $return = array(); + $return['type'] = 'general'; if (empty($content['name'])) { $content['name'] = __('General'); @@ -482,6 +490,7 @@ function reporting_simple_graph($report, $content, $type = 'dinamic', global $config; $return = array(); + $return['type'] = 'simple_graph'; if (empty($content['name'])) { $content['name'] = __('Simple graph'); @@ -598,29 +607,32 @@ function reporting_simple_graph($report, $content, $type = 'dinamic', return reporting_check_structure_content($return); } -function reporting_get_date_text($report, $content) { +function reporting_get_date_text($report = null, $content = null) { global $config; $return = array(); - $return['date'] = ""; - $return['period'] = ""; - $return['from'] = ""; - $return['to'] = ""; + $return['date'] = null; + $return['period'] = null; + $return['from'] = null; + $return['to'] = null; - if ($content['period'] == 0) { - $es = json_decode($content['external_source'], true); - if ($es['date'] == 0) { - $return['date'] = __('Last data'); + if (!empty($report) && !empty($content)) { + + if ($content['period'] == 0) { + $es = json_decode($content['external_source'], true); + if ($es['date'] == 0) { + $return['period'] = 0; + } + else { + $return['date'] = $es['date']; + } } else { - $return['date'] = date($config["date_format"], $es['date']); + $return['period'] = $content['period']; + $return['from'] = $report["datetime"] - $content['period']; + $return['to'] = $report["datetime"]; } } - else { - $return['period'] = human_time_description_raw ($content['period']); - $return['from'] = date($config["date_format"], $report["datetime"] - $content['period']); - $return['from'] = date($config["date_format"], $report["datetime"]); - } return $return; } diff --git a/pandora_console/include/functions_reporting_html.php b/pandora_console/include/functions_reporting_html.php index a8f53d2d3c..031af34b35 100644 --- a/pandora_console/include/functions_reporting_html.php +++ b/pandora_console/include/functions_reporting_html.php @@ -37,6 +37,115 @@ include_once($config['homedir'] . "/include/functions_forecast.php"); include_once($config['homedir'] . "/include/functions_ui.php"); include_once($config['homedir'] . "/include/functions_netflow.php"); +function reporting_html_header(&$table, $mini, $title, $subtitle, + $period, $date, $from, $to) { + + global $config; + + + if ($mini) { + $sizh = ''; + $sizhfin = ''; + } + else { + $sizh = '

'; + $sizhfin = '

'; + } + + + $date_text = ""; + if (!empty($date)) { + $date_text = date($config["date_format"], $date); + } + else if (!empty($from) && !empty($to)) { + $date_text = + "(" . human_time_description_raw ($period) . ") " . + __("From:") . " " . date($config["date_format"], $from) . "
" . + __("To:") . " " . date($config["date_format"], $to); + } + else if ($period > 0) { + $date_text = human_time_description_raw($period); + } + else if ($period === 0) { + $date_text = __('Last data'); + } + + + $data = array(); + if (empty($subtitle) && (empty($date_text))) { + $data[] = $sizh . $title . $sizhfin; + $table->colspan[0][0] = 3; + } + else if (empty($subtitle)) { + $data[] = $sizh . $title . $sizhfin; + $data[] = "
" . $sizh . $date_text . $sizhfin . "
"; + $table->colspan[0][1] = 2; + } + else if (empty($date_text)) { + $data[] = $sizh . $title . $sizhfin; + $data[] = $sizh . $subtitle . $sizhfin; + $table->colspan[0][1] = 2; + } + else { + $data[] = $sizh . $title . $sizhfin; + $data[] = $sizh . $subtitle . $sizhfin; + $data[] = "
" . $sizh . $date_text . $sizhfin . "
"; + } + + array_push ($table->data, $data); +} + +function reporting_html_print_report($report, $mini = false) { + + foreach ($report['contents'] as $item) { + $table->size = array (); + $table->style = array (); + $table->width = '98%'; + $table->class = 'databox'; + $table->rowclass = array (); + $table->rowclass[0] = 'datos3'; + $table->data = array (); + $table->head = array (); + $table->style = array (); + $table->colspan = array (); + $table->rowstyle = array (); + + + reporting_html_header($table, + $mini, $item['title'], + $item['subtitle'], + $item['date']['period'], + $item['date']['date'], + $item['date']['from'], + $item['date']['to']); + + if ($item["description"] != "") { + $table->data['description_row']['description'] = $item["description"]; + $table->colspan['description_row']['description'] = 3; + } + + switch ($item['type']) { + case 'general': + break; + case 'sql': + break; + case 'simple_graph': + $table->colspan['chart']['cell'] = 3; + $table->cellstyle['chart']['cell'] = 'text-align: center;'; + $table->data['chart']['cell'] = $item['chart']; + break; + } + + if ($item['type'] == 'agent_module') + echo '
'; + + html_print_table ($table); + + if ($item['type'] == 'agent_module') + echo '
'; + } +} + /** * Get the average value of an agent module in a period of time. * @@ -2804,7 +2913,9 @@ function sla_value_asc_cmp($a, $b) { /** * Make the header for each content. */ -function reporting_header_content($mini, $content, $report, &$table, $title = false, $name = false, $period = false) { +function reporting_header_content($mini, $content, $report, &$table, + $title = false, $name = false, $period = false) { + global $config; if ($mini) {