Skip to content

Commit

Permalink
Working in the refactoring code of reporting.
Browse files Browse the repository at this point in the history
  • Loading branch information
mdtrooper committed Mar 24, 2015
1 parent a5eaeb3 commit ceca482
Show file tree
Hide file tree
Showing 2 changed files with 143 additions and 20 deletions.
50 changes: 31 additions & 19 deletions pandora_console/include/functions_reporting.php
Expand Up @@ -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) {
Expand Down Expand Up @@ -161,16 +169,15 @@ function reporting_sql($report, $content) {
global $config;

$return = array();
$return['type'] = 'sql';

if (empty($content['name'])) {
$content['name'] = __('SQL');
}

$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"]) {
Expand Down Expand Up @@ -238,6 +245,7 @@ function reporting_general($report, $content) {
global $config;

$return = array();
$return['type'] = 'general';

if (empty($content['name'])) {
$content['name'] = __('General');
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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'] = "";

if ($content['period'] == 0) {
$es = json_decode($content['external_source'], true);
if ($es['date'] == 0) {
$return['date'] = __('Last data');
$return['date'] = null;
$return['period'] = null;
$return['from'] = null;
$return['to'] = null;

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;
}
Expand Down
113 changes: 112 additions & 1 deletion pandora_console/include/functions_reporting_html.php
Expand Up @@ -37,6 +37,115 @@
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 = '<h4>';
$sizhfin = '</h4>';
}


$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) . "<br />" .
__("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[] = "<div style='text-align: right;'>" . $sizh . $date_text . $sizhfin . "</div>";
$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[] = "<div style='text-align: right;'>" . $sizh . $date_text . $sizhfin . "</div>";
}

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 '<div style="width: 99%; overflow: auto;">';

html_print_table ($table);

if ($item['type'] == 'agent_module')
echo '</div>';
}
}

/**
* Get the average value of an agent module in a period of time.
*
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit ceca482

Please sign in to comment.