Skip to content
This repository has been archived by the owner on Dec 13, 2022. It is now read-only.

Commit

Permalink
fix(ui): filters and pagination in the configuration menus (#7348)
Browse files Browse the repository at this point in the history
* fix(ui): saving configuration > hosts filters (#7348 )
* fix(ui): setting current pagination from history
* fix(ui): saving configuration > hosts filters
* fix(ui): saving configuration > hostgroups filter
* fix(ui): saving configuration > hostTemplate filters
* fix(ui): saving configuration > hostCategories filter

* fix(ui): saving configuration > services filters (#7355)
* fix(ui): saving configuration > services by host filters
* fix(ui): saving configuration > services by hostgroups filters
* fix(ui): saving configuration > servicesgroups filters
* fix(ui): saving configuration > service template filters
* fix(ui): saving configuration > service categories filters
* fix(ui): saving configuration > meta services filters

* fix(ui): saving configuration > contacts filters (#7360)
* fix(ui): saving configuration > contact users filters
* fix(ui): saving configuration > contact template filters
* fix(ui): saving configuration > contactgroup filters
* fix(ui): saving configuration > timeperiod filters

* fix(ui): saving configuration > commands filters (#7369)
* fix(ui): saving configuration > commands checks filter
* fix(ui): saving configuration > other command pages filters

* fix(ui): saving configuration > poller and other menus filters (#7375)
* fix(ui): configuration > poller > engine configuration
* fix(ui): configuration > resources
* fix(ui): configuration > pollers
* fix(ui): configuration > escalations
* fix(ui): configuration > host dependency
* fix(ui): configuration > hostgroup dependency
* fix(ui): configuration > servicegroup dependency
* fix(ui): configuration > service dependency
* fix(ui): configuration > meta service dependency
* fix(ui): configuration > centreon-broker
* fix(ui): configuration > traps
* fix(ui): configuration > trap manufacturer
* fix(ui): configuration > trap groups

* fix(ui): pagination feedbacks from validation process
  • Loading branch information
sc979 authored Apr 5, 2019
1 parent 6584a43 commit ff56af4
Show file tree
Hide file tree
Showing 40 changed files with 1,874 additions and 2,015 deletions.
21 changes: 18 additions & 3 deletions www/class/centreon.class.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/*
* Copyright 2005-2015 Centreon
* Centreon is developped by : Julien Mathis and Romain Le Merlus under
* Copyright 2005-2019 Centreon
* Centreon is developed by : Julien Mathis and Romain Le Merlus under
* GPL Licence 2.0.
*
* This program is free software; you can redistribute it and/or modify it under
Expand Down Expand Up @@ -56,8 +56,22 @@ class Centreon
public $plugins;
public $status_graph_service;
public $status_graph_host;

/*
* @var array : saved user's pagination filter value
*/
public $historyPage;

/*
* @var string : saved last page's file name
*/
public $historyLastUrl;

/*
* @var array : saved user's filters
*/
public $historySearch;

public $historySearchService;
public $historySearchOutput;
public $historyLimit;
Expand Down Expand Up @@ -217,6 +231,7 @@ public function initHooks()
public function createHistory()
{
$this->historyPage = array();
$this->historyLastUrl = '';
$this->historySearch = array();
$this->historySearchService = array();
$this->historySearchOutput = array();
Expand All @@ -234,7 +249,7 @@ public function initNagiosCFG()
{
$this->Nagioscfg = array();
/*
* We don't check activate because we can a server without a engine on localhost running
* We don't check activate because we can a server without a engine on localhost running
* (but we order to get if we have one)
*/
$DBRESULT = CentreonDBInstance::getConfInstance()->query("SELECT * FROM cfg_nagios, nagios_server
Expand Down
26 changes: 17 additions & 9 deletions www/include/common/autoNumLimit.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/*
* Copyright 2005-2015 Centreon
* Copyright 2005-2019 Centreon
* Centreon is developed by : Julien Mathis and Romain Le Merlus under
* GPL Licence 2.0.
*
Expand Down Expand Up @@ -41,6 +41,7 @@
$historyLimitNotDefault = isset($centreon->historyLimit[$url]) && $centreon->historyLimit[$url] !== 30;
$sessionLimitKey = "results_limit_{$url}";

// Setting the limit filter
if (isset($_POST['limit']) && $_POST['limit']) {
$limit = $_POST['limit'];
} elseif (isset($_GET['limit'])) {
Expand All @@ -63,17 +64,24 @@

$_SESSION[$sessionLimitKey] = $limit;

if (isset($_POST['num']) && $_POST['num']) {
$num = $_POST['num'];
} elseif (isset($_GET['num']) && $_GET['num']) {
$num = $_GET['num'];
} elseif (!isset($_POST['num']) && !isset($_GET['num']) && isset($centreon->historyPage[$url])) {
$num = $centreon->historyPage[$url];
} else {
// Setting the pagination filter
if (isset($_POST['num']) && isset($_POST['search'])
|| (isset($centreon->historyLastUrl) && $centreon->historyLastUrl !== $url)
) {
// Checking if the current page and the last displayed page are the same and resetting the filters
$num = 0;
} elseif (isset($_REQUEST['num'])) {
// Checking if a pagination filter has been sent in the http request
$num = filter_var(
$_GET['num'] ?? $_POST['num'] ?? 0,
FILTER_VALIDATE_INT
);
} else {
// Resetting the pagination filter
$num = $centreon->historyPage[$url] ?? 0;
}

/* cast limit and num to avoid sql error on prepared statement (PDO::PARAM_INT) */
// Cast limit and num to avoid sql error on prepared statement (PDO::PARAM_INT)
$limit = (int)$limit;
$num = (int)$num;

Expand Down
6 changes: 3 additions & 3 deletions www/include/common/checkPagination.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/*
* Copyright 2005-2015 Centreon
* Centreon is developped by : Julien Mathis and Romain Le Merlus under
* Copyright 2005-2019 Centreon
* Centreon is developed by : Julien Mathis and Romain Le Merlus under
* GPL Licence 2.0.
*
* This program is free software; you can redistribute it and/or modify it under
Expand Down Expand Up @@ -37,7 +37,7 @@
if ($num >= $page_max && $rows) {
$num = $page_max - 1;
}

if ($rows == 0) {
$num = 0;
$page_max = 0;
Expand Down
14 changes: 11 additions & 3 deletions www/include/common/common-Func.php
Original file line number Diff line number Diff line change
Expand Up @@ -2211,12 +2211,20 @@ function reset_search_page($url)
if (!isset($url)) {
return;
}
if (isset($_GET['search']) &&
isset($centreon->historySearch[$url]) && $_GET['search'] != $centreon->historySearch[$url] &&
!isset($_GET['num']) && !isset($_POST['num'])
if (isset($_GET['search'])
&& isset($centreon->historySearch[$url])
&& $_GET['search'] != $centreon->historySearch[$url]
&& !isset($_GET['num'])
&& !isset($_POST['num'])
) {
$_POST['num'] = 0;
$_GET['num'] = 0;
} elseif (isset($_GET["search"])
&& isset($_POST["search"])
&& $_GET["search"] === $_POST["search"]
) {
//if the user change the search filter, we reset the num argument sent in the hybride POST and GET request
$_POST['num'] = $_GET['num'] = 0;
}
}

Expand Down
86 changes: 38 additions & 48 deletions www/include/common/pagination.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/*
* Copyright 2005-2015 Centreon
* Centreon is developped by : Julien Mathis and Romain Le Merlus under
* Copyright 2005-2019 Centreon
* Centreon is developed by : Julien Mathis and Romain Le Merlus under
* GPL Licence 2.0.
*
* This program is free software; you can redistribute it and/or modify it under
Expand Down Expand Up @@ -42,16 +42,12 @@
global $num, $limit, $search, $url, $pearDB, $search_type_service, $search_type_host,
$host_name, $hostgroup, $rows, $p, $gopt, $pagination, $poller, $template, $search_output, $search_service;

$type = isset($_REQUEST["type"]) ? $_REQUEST["type"] : null;
isset($_GET["o"]) ? $o = $_GET["o"] : $o = null;
$type = $_REQUEST["type"] ?? null;
$o = $_GET["o"] ?? $o = null;

if (isset($_GET["num"])) {
$num = $_GET["num"];
} elseif (!isset($_GET["num"]) && isset($centreon->historyPage[$url]) && $centreon->historyPage[$url]) {
$num = $centreon->historyPage[$url];
} else {
$num = 0;
}
//saving current pagination filter value and current displayed page
$centreon->historyPage[$url] = $num;
$centreon->historyLastUrl = $url;

$num = addslashes($num);

Expand All @@ -75,10 +71,10 @@
$search_type_host = null;
}

if (!isset($_GET["search_type_host"]) &&
!isset($centreon->search_type_host) &&
!isset($_GET["search_type_service"]) &&
!isset($centreon->search_type_service)
if (!isset($_GET["search_type_host"])
&& !isset($centreon->search_type_host)
&& !isset($_GET["search_type_service"])
&& !isset($centreon->search_type_service)
) {
$search_type_host = 1;
$centreon->search_type_host = 1;
Expand Down Expand Up @@ -140,14 +136,14 @@
/* Start Fix for performance management under administration - parameters */
if (isset($_REQUEST['searchS'])) {
$url_var .= '&searchS=' . $_REQUEST['searchS'];
if (isset($_POST['num'])){
if (isset($_POST['num'])) {
$num = 0;
}
}

if (isset($_REQUEST['searchH'])) {
$url_var .= '&searchH=' . $_REQUEST['searchH'];
if (isset($_POST['num'])){
if (isset($_POST['num'])) {
$num = 0;
}
}
Expand All @@ -169,19 +165,19 @@
}

$pageArr = array();
$istart = 0;
for ($i = 5, $istart = $num; $istart && $i > 0; $i--) {
$istart--;
$iStart = 0;
for ($i = 5, $iStart = $num; $iStart && $i > 0; $i--) {
$iStart--;
}
for ($i2 = 0, $iend = $num; ($iend < ($rows / $limit - 1)) && ($i2 < (5 + $i)); $i2++) {
$iend++;
for ($i2 = 0, $iEnd = $num; ($iEnd < ($rows / $limit - 1)) && ($i2 < (5 + $i)); $i2++) {
$iEnd++;
}

if ($rows != 0) {
for ($i = $istart; $i <= $iend; $i++) {
for ($i = $iStart; $i <= $iEnd; $i++) {

$urlPage = "main.php?p=" . $p . "&num=$i&limit=" . $limit . "&poller=" . $poller .
"&template=$template&search=" . $search . "&type=" . $type . "&o=" . $o . $url_var;
$urlPage = "main.php?p=" . $p . "&num=" . $i . "&limit=" . $limit . "&poller=" . $poller .
"&template=" . $template . "&search=" . $search . "&type=" . $type . "&o=" . $o . $url_var;
$pageArr[$i] = array(
"url_page" => $urlPage,
"label_page" => "<b>" . ($i + 1) . "</b>",
Expand All @@ -202,16 +198,16 @@
if (($prev = $num - 1) >= 0) {
$tpl->assign(
'pagePrev',
("main.php?p=" . $p . "&num=$prev&limit=" . $limit . "&poller=" . $poller .
"&template=$template&search=" . $search . "&type=" . $type . "&o=" . $o . $url_var)
("main.php?p=" . $p . "&num=" . $prev . "&limit=" . $limit . "&poller=" . $poller .
"&template=" . $template . "&search=" . $search . "&type=" . $type . "&o=" . $o . $url_var)
);
}

if (($next = $num + 1) < ($rows / $limit)) {
$tpl->assign(
'pageNext',
("main.php?p=" . $p . "&num=$next&limit=" . $limit . "&poller=" . $poller .
"&template=$template&search=" . $search . "&type=" . $type . "&o=" . $o . $url_var)
("main.php?p=" . $p . "&num=" . $next . "&limit=" . $limit . "&poller=" . $poller .
"&template=" . $template . "&search=" . $search . "&type=" . $type . "&o=" . $o . $url_var)
);
}

Expand All @@ -226,21 +222,19 @@
$tpl->assign(
'firstPage',
("main.php?p=" . $p . "&num=0&limit=" . $limit . "&poller=" . $poller .
"&template=$template&search=" . $search . "&type=" . $type . "&o=" . $o . $url_var)
"&template=" . $template . "&search=" . $search . "&type=" . $type . "&o=" . $o . $url_var)
);
}
if ($page_max > 5 && $num != ($pageNumber - 1)) {
$tpl->assign(
'lastPage',
("main.php?p=" . $p . "&num=" . ($pageNumber - 1) . "&limit=" . $limit .
"&template=$template&poller=" . $poller . "&search=" . $search .
"&template=" . $template . "&poller=" . $poller . "&search=" . $search .
"&type=" . $type . "&o=" . $o . $url_var)
);
}

/*
* Select field to change the number of row on the page
*/
// Select field to change the number of row on the page
for ($i = 10; $i <= 100; $i = $i + 10) {
$select[$i] = $i;
}
Expand All @@ -258,14 +252,14 @@
}

?>
<script type="text/javascript">
function setL(_this) {
var _l = document.getElementsByName('l');
document.forms['form'].elements['limit'].value = _this;
_l[0].value = _this;
_l[1].value = _this;
}
</SCRIPT>
<script type="text/javascript">
function setL(_this) {
var _l = document.getElementsByName('l');
document.forms['form'].elements['limit'].value = _this;
_l[0].value = _this;
_l[1].value = _this;
}
</script>
<?php
$form = new HTML_QuickFormCustom(
'select_form',
Expand All @@ -281,9 +275,7 @@ function setL(_this) {
);
$selLim->setSelected($limit);

/*
* Element we need when we reload the page
*/
// Element we need when we reload the page
$form->addElement('hidden', 'p');
$form->addElement('hidden', 'search');
$form->addElement('hidden', 'num');
Expand All @@ -292,9 +284,7 @@ function setL(_this) {
$form->addElement('hidden', 'sort_types');
$form->setDefaults(array("p" => $p, "search" => $search, "num" => $num));

/*
* Init QuickForm
*/
// Init QuickForm
$renderer = new HTML_QuickForm_Renderer_ArraySmarty($tpl);
$form->accept($renderer);

Expand Down
Loading

0 comments on commit ff56af4

Please sign in to comment.