Working in the refactoring the code of reports (database_serialized).

This commit is contained in:
mdtrooper 2015-04-17 19:24:07 +02:00
parent 8182edb9fa
commit 1993dae682
2 changed files with 133 additions and 83 deletions

View File

@ -358,12 +358,119 @@ function reporting_make_reporting_data($id_report, $date, $time,
$report,
$content);
break;
case 'database_serialized':
$report['contents'][] = reporting_database_serialized(
$report,
$content);
break;
}
}
return reporting_check_structure_report($report);
}
function reporting_database_serialized($report, $content) {
global $config;
$return['type'] = 'database_serialized';
if (empty($content['name'])) {
$content['name'] = __('Database Serialized');
}
$return['title'] = $content['name'];
$return["description"] = $content["description"];
$return["date"] = reporting_get_date_text($report, $content);
$keys = array();
if ($content['header_definition'] != '') {
$keys = explode('|', $content['header_definition']);
}
$return['keys'] = $keys;
$datelimit = $report["datetime"] - $content['period'];
$search_in_history_db = db_search_in_history_db($datelimit);
// This query gets information from the default and the historic database
$result = db_get_all_rows_sql('SELECT *
FROM tagente_datos
WHERE id_agente_modulo = ' . $content['id_agent_module'] . '
AND utimestamp > ' . $datelimit . '
AND utimestamp <= ' . $report["datetime"], $search_in_history_db);
// Adds string data if there is no numeric data
if ((count($result) < 0) or (!$result)) {
// This query gets information from the default and the historic database
$result = db_get_all_rows_sql('SELECT *
FROM tagente_datos_string
WHERE id_agente_modulo = ' . $content['id_agent_module'] . '
AND utimestamp > ' . $datelimit . '
AND utimestamp <= ' . $report["datetime"], $search_in_history_db);
}
if ($result === false) {
$result = array();
}
$data = array();
foreach ($result as $row) {
$date = date($config["date_format"], $row['utimestamp']);
$serialized_data = $row['datos'];
// Cut line by line
if (empty($content['line_separator']) ||
empty($serialized_data)) {
$rowsUnserialize = array($row['datos']);
}
else {
$rowsUnserialize = explode($content['line_separator'], $serialized_data);
}
foreach ($rowsUnserialize as $rowUnser) {
$row = array();
$row['date'] = $date;
$row['data'] = array();
if (empty($content['column_separator'])) {
if (empty($keys)) {
$row['data'][][] = $rowUnser;
}
else {
$row['data'][][$keys[0]] = $rowUnser;
}
}
else {
$columnsUnserialize = explode($content['column_separator'], $rowUnser);
$i = 0;
$temp_row = array();
foreach ($columnsUnserialize as $cell) {
if (isset($keys[$i])) {
$temp_row[$keys[$i]] = $cell;
}
else {
$temp_row[] = $cell;
}
$i++;
}
$row['data'][] = $temp_row;
}
$data[] = $row;
}
}
$return["data"] = $data;
return reporting_check_structure_content($return);
}
function reporting_group_configuration($report, $content) {
global $config;

View File

@ -224,6 +224,9 @@ function reporting_html_print_report($report, $mini = false) {
case 'group_configuration':
reporting_html_group_configuration($table, $item);
break;
case 'database_serialized':
reporting_html_database_serialized($table, $item);
break;
}
if ($item['type'] == 'agent_module')
@ -236,6 +239,29 @@ function reporting_html_print_report($report, $mini = false) {
}
}
function reporting_html_database_serialized($table, $item) {
$table1->width = '100%';
$table1->head = array (__('Date'));
if (!empty($item['keys'])) {
$table1->head = array_merge($table1->head, $item['keys']);
}
$table1->style[0] = 'text-align: left';
$table1->data = array ();
foreach ($item['data'] as $data) {
foreach ($data['data'] as $data_unserialied) {
$row = array($data['date']);
$row = array_merge($row, $data_unserialied);
$table1->data[] = $row;
}
}
$table->colspan['database_serialized']['cell'] = 3;
$table->cellstyle['database_serialized']['cell'] = 'text-align: center;';
$table->data['database_serialized']['cell'] = html_print_table($table1, true);
}
function reporting_html_group_configuration($table, $item) {
$table1->width = '100%';
@ -4282,89 +4308,6 @@ function reporting_render_report_html_item ($content, $table, $report, $mini = f
array_push ($table->data, $data);
break;
case 'database_serialized':
if (empty($item_title)) {
$item_title = __('Serialize data');
}
reporting_header_content($mini, $content, $report, $table, $item_title,
ui_print_truncate_text($module_name, 'module_medium', false));
// Put description at the end of the module (if exists)
$next_row = 1;
if ($content["description"] != "") {
$data_desc = array();
$data_desc[0] = $content["description"];
$table->colspan[$next_row][0] = 3;
array_push ($table->data, $data_desc);
$next_row++;
}
$table->colspan[$next_row][0] = 3;
$table2->class = 'databox alternate';
$table2->width = '100%';
//Create the head
$table2->head = array();
if ($content['header_definition'] != '') {
$table2->head = explode('|', $content['header_definition']);
}
else {
$table2->head[] = __('Data');
}
array_unshift($table2->head, __('Date'));
$datelimit = $report["datetime"] - $content['period'];
$search_in_history_db = db_search_in_history_db($datelimit);
// This query gets information from the default and the historic database
$result = db_get_all_rows_sql('SELECT *
FROM tagente_datos
WHERE id_agente_modulo = ' . $content['id_agent_module'] . '
AND utimestamp > ' . $datelimit . '
AND utimestamp <= ' . $report["datetime"], $search_in_history_db);
// Adds string data if there is no numeric data
if ((count($result) < 0) or (!$result)) {
// This query gets information from the default and the historic database
$result = db_get_all_rows_sql('SELECT *
FROM tagente_datos_string
WHERE id_agente_modulo = ' . $content['id_agent_module'] . '
AND utimestamp > ' . $datelimit . '
AND utimestamp <= ' . $report["datetime"], $search_in_history_db);
}
if ($result === false) {
$result = array();
}
$table2->data = array();
foreach ($result as $row) {
$date = date ($config["date_format"], $row['utimestamp']);
$serialized = $row['datos'];
if (empty($content['line_separator']) ||
empty($serialized)) {
$rowsUnserialize = array($row['datos']);
}
else {
$rowsUnserialize = explode($content['line_separator'], $serialized);
}
foreach ($rowsUnserialize as $rowUnser) {
if (empty($content['column_separator'])) {
$columnsUnserialize = array($rowUnser);
}
else {
$columnsUnserialize = explode($content['column_separator'], $rowUnser);
}
array_unshift($columnsUnserialize, $date);
array_push($table2->data, $columnsUnserialize);
}
}
$cellContent = html_print_table($table2, true);
array_push($table->data, array($cellContent));
break;
case 'group_report':
$group_name = groups_get_name($content['id_group'], true);
$group_stats = reporting_get_group_stats($content['id_group']);