From 606e29684b0c2f61f93ce69f97405b65e433f99f Mon Sep 17 00:00:00 2001
From: m-lopez-f
Date: Wed, 8 Jul 2015 16:09:00 +0200
Subject: [PATCH] Add pagination in custom reports and visual console. Tiquet:
#2398
---
.../general/firts_task/map_builder.php | 3 +-
.../godmode/reporting/map_builder.php | 28 +++++++++++++------
.../godmode/reporting/reporting_builder.php | 19 +++++++++----
.../include/functions_visual_map.php | 4 +--
4 files changed, 38 insertions(+), 16 deletions(-)
diff --git a/pandora_console/general/firts_task/map_builder.php b/pandora_console/general/firts_task/map_builder.php
index 45b5261ea6..6e16c6d048 100755
--- a/pandora_console/general/firts_task/map_builder.php
+++ b/pandora_console/general/firts_task/map_builder.php
@@ -35,7 +35,8 @@ ui_print_info_message(
ignore it or will update its information.There are three types of detection: Based on ICMP (pings),
SNMP (detecting the topology of networks and their interfaces), and other customized
type. You can define your own customized recon script.'); ?>
-
diff --git a/pandora_console/godmode/reporting/map_builder.php b/pandora_console/godmode/reporting/map_builder.php
index 1056af7dbd..47c098619a 100644
--- a/pandora_console/godmode/reporting/map_builder.php
+++ b/pandora_console/godmode/reporting/map_builder.php
@@ -44,6 +44,8 @@ $id_layout = (int) get_parameter ('id_layout');
$copy_layout = (bool) get_parameter ('copy_layout');
$delete_layout = (bool) get_parameter ('delete_layout');
$refr = (int) get_parameter('refr');
+$offset = (int) get_parameter('offset', 0);
+$pagination = (int) get_parameter ("pagination", $config["block_size"]);
if ($delete_layout || $copy_layout) {
// Visual console required
@@ -206,9 +208,6 @@ $table->head[0] = __('Map name');
$table->head[1] = __('Group');
$table->head[2] = __('Items');
-if (defined("METACONSOLE"))
- $table->styleTable = "margin-top:0px";
-
// Fix: IW was the old ACL for report editing, now is RW
//Only for RW flag
if ($vconsoles_write || $vconsoles_manage) {
@@ -227,13 +226,24 @@ $table->align[4] = 'left';
// Only display maps of "All" group if user is administrator
// or has "VR" privileges, otherwise show only maps of user group
+$filters['offset'] = $offset;
+$filters['limit'] = $pagination;
$own_info = get_user_info ($config['id_user']);
-if ($own_info['is_admin'] || $vconsoles_read)
- $maps = visual_map_get_user_layouts ();
-else
+if (!defined('METACONSOLE')) {
+ $url = 'index.php?sec=reporting&sec2=godmode/reporting/map_builder&pagination='.$pagination;
+}
+else {
+ $url = 'index.php?sec=screen&sec2=screens/screens&action=visualmap&pagination='.$pagination;
+}
+if ($own_info['is_admin'] || $vconsoles_read) {
+ $maps = visual_map_get_user_layouts (0,false,$filters);
+ $total_maps = count(visual_map_get_user_layouts());
+} else {
$maps = visual_map_get_user_layouts ($config['id_user'], false,
- false, false);
-
+ $filters, false);
+ $total_maps = count(visual_map_get_user_layouts ($config['id_user'], false,
+ false, false));
+}
if (!$maps && !defined("METACONSOLE")) {
require_once ($config['homedir'] . "/general/firts_task/map_builder.php");
}
@@ -244,6 +254,8 @@ elseif (!$maps && defined("METACONSOLE")) {
'message'=> __('There are no visual console defined yet.')));
}
else {
+ ui_pagination ($total_maps, $url, $offset, $pagination);
+
foreach ($maps as $map) {
// ACL for the visual console permission
$vconsole_write = check_acl ($config['id_user'],
diff --git a/pandora_console/godmode/reporting/reporting_builder.php b/pandora_console/godmode/reporting/reporting_builder.php
index accdf00902..13b907d621 100755
--- a/pandora_console/godmode/reporting/reporting_builder.php
+++ b/pandora_console/godmode/reporting/reporting_builder.php
@@ -46,11 +46,11 @@ define ('_MPDF_TTFONTPATH', 'include/fonts/');
$activeTab = get_parameter('tab', 'main');
$action = get_parameter('action', 'list');
$idReport = get_parameter('id_report', 0);
-$offset = get_parameter('offset', 0);
+$offset = (int) get_parameter('offset', 0);
$idItem = get_parameter('id_item', 0);
$pure = get_parameter('pure',0);
$schedule_report = get_parameter('schbutton', '');
-
+$pagination = (int) get_parameter ("pagination", $config["block_size"]);
$strict_user = db_get_value('strict_acl', 'tusuario', 'id_user', $config['id_user']);
if ($schedule_report != '') {
@@ -440,7 +440,8 @@ switch ($action) {
else {
$group = false;
}
-
+ $filter['offset'] = $offset;
+ $filter['limit'] = $pagination;
// Filter normal and metaconsole reports
if ($config['metaconsole'] == 1 and defined('METACONSOLE'))
@@ -458,9 +459,17 @@ switch ($action) {
'id_group',
'non_interactive'), $return_all_group, 'RR', $group, $strict_user);
- $table = new stdClass();
- $table->width = '0px';
+
+ unset($filter['offset']);
+ unset($filter['limit']);
+ $total_reports = (int) count(reports_get_reports ($filter,
+ array ('name'), $return_all_group, 'RR', $group, $strict_user));
+
+
if (sizeof ($reports)) {
+ $url = "index.php?sec=reporting&sec2=godmode/reporting/reporting_builder";
+ ui_pagination ($total_reports, $url, $offset, $pagination);
+
$table = new stdClass();
$table->id = 'report_list';
$table->width = '100%';
diff --git a/pandora_console/include/functions_visual_map.php b/pandora_console/include/functions_visual_map.php
index de3bb01463..f1812e6cde 100755
--- a/pandora_console/include/functions_visual_map.php
+++ b/pandora_console/include/functions_visual_map.php
@@ -1874,8 +1874,6 @@ function visual_map_get_user_layouts ($id_user = 0, $only_names = false, $filter
if (! is_array ($filter))
$filter = array ();
- $where = db_format_array_where_clause_sql ($filter);
-
if ($returnAllGroup)
$groups = users_get_groups ($id_user, 'RR');
else
@@ -1888,6 +1886,8 @@ function visual_map_get_user_layouts ($id_user = 0, $only_names = false, $filter
$where .= sprintf ('id_group IN (%s)', implode (",", array_keys ($groups)));
}
+ $where .= db_format_array_where_clause_sql ($filter);
+
if ($where == '') {
$where = array();
}