diff --git a/www/class/centreon.class.php b/www/class/centreon.class.php index 9c5a97ae487..916f4b6aaee 100644 --- a/www/class/centreon.class.php +++ b/www/class/centreon.class.php @@ -1,7 +1,7 @@ historyPage = array(); + $this->historyLastUrl = ''; $this->historySearch = array(); $this->historySearchService = array(); $this->historySearchOutput = array(); @@ -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 diff --git a/www/include/common/autoNumLimit.php b/www/include/common/autoNumLimit.php index ea9ef0ecf61..41e47eeea3a 100644 --- a/www/include/common/autoNumLimit.php +++ b/www/include/common/autoNumLimit.php @@ -1,6 +1,6 @@ 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'])) { @@ -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; diff --git a/www/include/common/checkPagination.php b/www/include/common/checkPagination.php index cbdc2712728..066c213f1c3 100644 --- a/www/include/common/checkPagination.php +++ b/www/include/common/checkPagination.php @@ -1,7 +1,7 @@ = $page_max && $rows) { $num = $page_max - 1; } - + if ($rows == 0) { $num = 0; $page_max = 0; diff --git a/www/include/common/common-Func.php b/www/include/common/common-Func.php index a107865f31c..b6dd8f0cd9e 100644 --- a/www/include/common/common-Func.php +++ b/www/include/common/common-Func.php @@ -2210,12 +2210,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; } } diff --git a/www/include/common/pagination.php b/www/include/common/pagination.php index 23900d15b55..d4b0fc9f8a7 100644 --- a/www/include/common/pagination.php +++ b/www/include/common/pagination.php @@ -1,7 +1,7 @@ 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); @@ -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; @@ -169,18 +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++) { - $urlPage = "main.php?p=" . $p . "&num=$i&limit=" . $limit . "&poller=" . $poller . - "&template=$template&search=" . $search . "&type=" . $type . "&o=" . $o . $url_var; + 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; $pageArr[$i] = array( "url_page" => $urlPage, "label_page" => "" . ($i + 1) . "", @@ -201,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) ); } @@ -225,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; } @@ -257,14 +252,14 @@ } ?> - + 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'); @@ -291,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); diff --git a/www/include/configuration/configCentreonBroker/listCentreonBroker.php b/www/include/configuration/configCentreonBroker/listCentreonBroker.php index a978b7c4e68..15376cabaaf 100644 --- a/www/include/configuration/configCentreonBroker/listCentreonBroker.php +++ b/www/include/configuration/configCentreonBroker/listCentreonBroker.php @@ -1,7 +1,7 @@ query("SELECT * FROM nagios_server ORDER BY name"); -while ($nagios_server = $DBRESULT->fetchRow()) { +$dbResult = $pearDB->query("SELECT * FROM nagios_server ORDER BY name"); +while ($nagios_server = $dbResult->fetch()) { $nagios_servers[$nagios_server["id"]] = $nagios_server["name"]; } -$DBRESULT->closeCursor(); +$dbResult->closeCursor(); -/* - * Smarty template Init - */ +// Smarty template Init $tpl = new Smarty(); $tpl = initSmartyTpl($path, $tpl); -/* Access level */ -($centreon->user->access->page($p) == 1) ? $lvl_access = 'w' : $lvl_access = 'r'; +// Access level +$lvl_access = ($centreon->user->access->page($p) == 1) ? 'w' : 'r'; $tpl->assign('mode_access', $lvl_access); -/* - * start header menu - */ +// start header menu $tpl->assign("headerMenu_name", _("Name")); $tpl->assign("headerMenu_desc", _("Requester")); $tpl->assign("headerMenu_outputs", _("Outputs")); @@ -73,20 +69,22 @@ $tpl->assign("headerMenu_options", _("Options")); /* - * Centreon Brober config list + * Centreon Broker config list */ -$aclCond = ""; -$search = null; + +$search = filter_var( + $_POST['searchCB'] ?? $_GET['searchCB'] ?? null, + FILTER_SANITIZE_STRING +); + if (isset($_POST['searchCB'])) { - $search = $_POST['searchCB']; - $centreon->historySearch[$url] = $search; -} elseif (isset($_GET['search'])) { - $search = $_GET['search']; - $centreon->historySearch[$url] = $search; -} elseif (isset($centreon->historySearch[$url])) { - $search = $centreon->historySearch[$url]; + $centreon->historySearch[$url] = array(); + $centreon->historySearch[$url]['search'] = $search; +} else { + $search = $centreon->historySearch[$url]['search'] ?? null; } +$aclCond = ""; if (!$centreon->user->admin && count($allowedBrokerConf)) { if ($search) { $aclCond = " AND "; @@ -95,41 +93,34 @@ } $aclCond .= "config_id IN (" . implode(',', array_keys($allowedBrokerConf)) . ") "; } + if ($search) { - $rq = "SELECT SQL_CALC_FOUND_ROWS config_id, config_name, ns_nagios_server, config_activate - FROM cfg_centreonbroker - WHERE config_name LIKE '%" . htmlentities($search, ENT_QUOTES, "UTF-8") . "%' - $aclCond - ORDER BY config_name - LIMIT " . $num * $limit . ", " . $limit; + $rq = "SELECT SQL_CALC_FOUND_ROWS config_id, config_name, ns_nagios_server, config_activate " . + "FROM cfg_centreonbroker " . + "WHERE config_name LIKE '%" . $search . "%'" . $aclCond . + " ORDER BY config_name " . + "LIMIT " . $num * $limit . ", " . $limit; } else { - $rq = "SELECT SQL_CALC_FOUND_ROWS config_id, config_name, ns_nagios_server, config_activate - FROM cfg_centreonbroker - $aclCond - ORDER BY config_name - LIMIT " . $num * $limit . ", " . $limit; + $rq = "SELECT SQL_CALC_FOUND_ROWS config_id, config_name, ns_nagios_server, config_activate " . + "FROM cfg_centreonbroker " . $aclCond . + " ORDER BY config_name " . + "LIMIT " . $num * $limit . ", " . $limit; } -$DBRESULT = $pearDB->query($rq); +$dbResult = $pearDB->query($rq); -/* - * Get results numbers - */ +// Get results numbers $rows = $pearDB->query("SELECT FOUND_ROWS()")->fetchColumn(); -include("./include/common/checkPagination.php"); +include "./include/common/checkPagination.php"; $form = new HTML_QuickFormCustom('select_form', 'POST', "?p=" . $p); -/* - * Different style between each lines - */ +// Different style between each lines $style = "one"; -/* - * Fill a tab with a mutlidimensionnal Array we put in $tpl - */ +// Fill a tab with a multidimensional Array we put in $tpl $elemArr = array(); -for ($i = 0; $config = $DBRESULT->fetchRow(); $i++) { +for ($i = 0; $config = $dbResult->fetch(); $i++) { $moptions = ""; $selectedElements = $form->addElement('checkbox', "select[" . $config['config_id'] . "]"); @@ -148,34 +139,34 @@ . " maxlength=\"3\" size=\"3\" value='1' " . "style=\"margin-bottom:0px;\" name='dupNbr[" . $config['config_id'] . "]'>"; - /* - * Number of output - */ - $res = $pearDB->query("SELECT COUNT(DISTINCT(config_group_id)) as num - FROM cfg_centreonbroker_info - WHERE config_group = 'output' - AND config_id = " . $config['config_id']); - $row = $res->fetchRow(); + // Number of output + $res = $pearDB->query( + "SELECT COUNT(DISTINCT(config_group_id)) as num " . + "FROM cfg_centreonbroker_info " . + "WHERE config_group = 'output' " . + "AND config_id = " . $config['config_id'] + ); + $row = $res->fetch(); $outputNumber = $row["num"]; - /* - * Number of input - */ - $res = $pearDB->query("SELECT COUNT(DISTINCT(config_group_id)) as num - FROM cfg_centreonbroker_info - WHERE config_group = 'input' - AND config_id = " . $config['config_id']); - $row = $res->fetchRow(); + // Number of input + $res = $pearDB->query( + "SELECT COUNT(DISTINCT(config_group_id)) as num " . + "FROM cfg_centreonbroker_info " . + "WHERE config_group = 'input' " . + "AND config_id = " . $config['config_id'] + ); + $row = $res->fetch(); $inputNumber = $row["num"]; - /* - * Number of logger - */ - $res = $pearDB->query("SELECT COUNT(DISTINCT(config_group_id)) as num - FROM cfg_centreonbroker_info - WHERE config_group = 'logger' - AND config_id = " . $config['config_id']); - $row = $res->fetchRow(); + // Number of logger + $res = $pearDB->query( + "SELECT COUNT(DISTINCT(config_group_id)) as num " . + "FROM cfg_centreonbroker_info " . + "WHERE config_group = 'logger' " . + "AND config_id = " . $config['config_id'] + ); + $row = $res->fetch(); $loggerNumber = $row["num"]; $elemArr[$i] = array( @@ -201,21 +192,22 @@ } $tpl->assign("elemArr", $elemArr); -/* - * Different messages we put in the template - */ -$tpl->assign('msg', array( - "addL" => "main.php?p=" . $p . "&o=a", - "addT" => _("Add"), - "addWizard" => _('Add with wizard'), - "delConfirm" => _("Do you confirm the deletion ?") -)); +// Different messages we put in the template +$tpl->assign( + 'msg', + array( + "addL" => "main.php?p=" . $p . "&o=a", + "addT" => _("Add"), + "addWizard" => _('Add with wizard'), + "delConfirm" => _("Do you confirm the deletion ?") + ) +); ?> + "javascript: " . @@ -272,13 +264,8 @@ function setO(_i) { $tpl->assign('limit', $limit); $tpl->assign('searchCB', $search); -/* - * Apply a template definition - */ +// Apply a template definition $renderer = new HTML_QuickForm_Renderer_ArraySmarty($tpl); $form->accept($renderer); $tpl->assign('form', $renderer->toArray()); - $tpl->display("listCentreonBroker.ihtml"); - -?> diff --git a/www/include/configuration/configNagios/listNagios.php b/www/include/configuration/configNagios/listNagios.php index d35e5f623a4..53d7e92b376 100644 --- a/www/include/configuration/configNagios/listNagios.php +++ b/www/include/configuration/configNagios/listNagios.php @@ -1,7 +1,7 @@ historySearch[$url] = $search; -} elseif (isset($_GET['searchN'])) { - $search = $_GET['searchN']; - $centreon->historySearch[$url] = $search; -} elseif (isset($centreon->historySearch[$url])) { - $search = $centreon->historySearch[$url]; + $centreon->historySearch[$url] = array(); + $centreon->historySearch[$url]['search'] = $search; +} else { + $search = $centreon->historySearch[$url]['search'] ?? null; } +$SearchTool = ''; if ($search) { $SearchTool .= " WHERE nagios_name LIKE '%" . htmlentities($search, ENT_QUOTES, "UTF-8") . "%' "; } @@ -70,23 +70,22 @@ * nagios servers comes from DB */ $nagios_servers = array(null => ""); -$DBRESULT = $pearDB->query("SELECT * FROM nagios_server ORDER BY name"); -while ($nagios_server = $DBRESULT->fetchRow()) { +$dbResult = $pearDB->query("SELECT * FROM nagios_server ORDER BY name"); +while ($nagios_server = $dbResult->fetch()) { $nagios_servers[$nagios_server["id"]] = $nagios_server["name"]; } -$DBRESULT->closeCursor(); +$dbResult->closeCursor(); -$query = 'SELECT SQL_CALC_FOUND_ROWS nagios_id, nagios_name, nagios_comment, nagios_activate, nagios_server_id ' . - 'FROM cfg_nagios ' . $SearchTool . $aclCond . ' ORDER BY nagios_name LIMIT ' . $num * $limit . ', ' . $limit; -$DBRESULT = $pearDB->query($query); +$dbResult = $pearDB->query( + 'SELECT SQL_CALC_FOUND_ROWS nagios_id, nagios_name, nagios_comment, nagios_activate, nagios_server_id ' . + 'FROM cfg_nagios ' . $SearchTool . $aclCond . ' ORDER BY nagios_name LIMIT ' . $num * $limit . ', ' . $limit +); $rows = $pearDB->query("SELECT FOUND_ROWS()")->fetchColumn(); -include("./include/common/checkPagination.php"); +include "./include/common/checkPagination.php"; -/* - * Smarty template Init - */ +// Smarty template Init $tpl = new Smarty(); $tpl = initSmartyTpl($path, $tpl); @@ -94,9 +93,7 @@ ($centreon->user->access->page($p) == 1) ? $lvl_access = 'w' : $lvl_access = 'r'; $tpl->assign('mode_access', $lvl_access); -/* - * start header menu - */ +// start header menu $tpl->assign("headerMenu_name", _("Name")); $tpl->assign("headerMenu_instance", _("Satellites")); $tpl->assign("headerMenu_desc", _("Description")); @@ -106,20 +103,14 @@ /* * Nagios list */ - - $form = new HTML_QuickFormCustom('select_form', 'POST', "?p=" . $p); -/* - * Different style between each lines - */ +// Different style between each lines $style = "one"; -/* - * Fill a tab with a mutlidimensionnal Array we put in $tpl - */ +// Fill a tab with a multidimensional Array we put in $tpl $elemArr = array(); -for ($i = 0; $nagios = $DBRESULT->fetchRow(); $i++) { +for ($i = 0; $nagios = $dbResult->fetch(); $i++) { $moptions = ""; $selectedElements = $form->addElement('checkbox', "select[" . $nagios['nagios_id'] . "]"); if ($nagios["nagios_activate"]) { @@ -151,20 +142,22 @@ $tpl->assign("elemArr", $elemArr); -/* - * Different messages we put in the template - */ +// Different messages we put in the template $tpl->assign( 'msg', - array("addL" => "main.php?p=" . $p . "&o=a", "addT" => _("Add"), "delConfirm" => _("Do you confirm the deletion ?")) + array( + "addL" => "main.php?p=" . $p . "&o=a", + "addT" => _("Add"), + "delConfirm" => _("Do you confirm the deletion ?") + ) ); ?> - + assign('limit', $limit); $tpl->assign('searchN', $search); -/* - * Apply a template definition - */ +// Apply a template definition $renderer = new HTML_QuickForm_Renderer_ArraySmarty($tpl); $form->accept($renderer); $tpl->assign('form', $renderer->toArray()); diff --git a/www/include/configuration/configObject/command/command.php b/www/include/configuration/configObject/command/command.php index 50714c68295..1d48713880a 100755 --- a/www/include/configuration/configObject/command/command.php +++ b/www/include/configuration/configObject/command/command.php @@ -1,7 +1,7 @@
\ No newline at end of file diff --git a/www/include/configuration/configObject/command/listCommand.php b/www/include/configuration/configObject/command/listCommand.php index 91130e4fd87..f936ed3788d 100755 --- a/www/include/configuration/configObject/command/listCommand.php +++ b/www/include/configuration/configObject/command/listCommand.php @@ -1,7 +1,7 @@ historyPage[$url] ?? 0, + FILTER_VALIDATE_INT +); + +$type = filter_var( + $_POST['type'] ?? $_GET['type'] ?? null, + FILTER_VALIDATE_INT +); + +// As the four pages of this menu are generated dynamically from the same ihtml and php files, +// we need to save $type and to overload the $num value set in the pagination.php file to restore each user's filter. +$savedType = $centreon->historySearch[$url]['type'] ?? null; + +// As pagination.php will already check if the current page was previously loaded or not, +// we're only checking if the last loaded page have the same $type value (1,2,3 or 4) +if (isset($type) && $type !== $savedType) { + //if so, we reset the pagination and save the current $type + $num = $centreon->historyPage[$url] = 0; + $centreon->historySearch[$url]['type'] = $type; } else { - $type_str = ""; + //saving again the pagination filter + $centreon->historyPage[$url] = $num; } -$search = null; if (isset($_POST['searchC'])) { - $search = $_POST['searchC']; - $centreon->historySearch[$url] = $search; - if ($type_str) { - $type_str = " AND " . $type_str; - } -} elseif (isset($_GET['search'])) { - $search = $_GET['search']; - $centreon->historySearch[$url] = $search; - if ($type_str) { - $type_str = " AND " . $type_str; - } -} elseif (isset($centreon->historySearch[$url])) { - $search = $centreon->historySearch[$url]; - if ($type_str) { - $type_str = " AND " . $type_str; - } + //saving user's search field value + $centreon->historySearch[$url] = array(); + // the four pages have the same $url, so we need to distinguish each page using its $type, + // and to save the four search filters. + $centreon->historySearch[$url]['search' . $type] = $search; +} else { + //restoring user's search field value + $search = $centreon->historySearch[$url]['search' . $type] ?? null; } +$type_str = $type ? " AND `command_type` = " . $type : ""; $search = tidySearchKey($search, $advanced_search); //List of elements - Depends on different criteria if (isset($search) && $search) { $rq = "SELECT SQL_CALC_FOUND_ROWS `command_id`, `command_name`, `command_line`, `command_type`, " . - "`command_activate` FROM `command` WHERE `command_name` LIKE '%" . htmlentities($search, ENT_QUOTES, "UTF-8") . - "%' $type_str ORDER BY `command_name` LIMIT " . $num * $limit . ", " . $limit; + "`command_activate` FROM `command` WHERE `command_name` LIKE '%" . $search . "%' " . + $type_str . " ORDER BY `command_name` LIMIT " . $num * $limit . ", " . $limit; } elseif ($type) { $rq = "SELECT SQL_CALC_FOUND_ROWS `command_id`, `command_name`, `command_line`, `command_type`, " . "`command_activate` FROM `command` WHERE `command_type` = '" . $type . @@ -82,7 +98,7 @@ "`command_activate` FROM `command` ORDER BY `command_name` LIMIT " . $num * $limit . ", " . $limit; } -$DBRESULT = $pearDB->query($rq); +$dbResult = $pearDB->query($rq); $rows = $pearDB->query("SELECT FOUND_ROWS()")->fetchColumn(); include_once "./include/common/checkPagination.php"; @@ -92,7 +108,7 @@ $tpl = initSmartyTpl($path, $tpl); // Access level -($centreon->user->access->page($p) == 1) ? $lvl_access = 'w' : $lvl_access = 'r'; +$lvl_access = ($centreon->user->access->page($p) == 1) ? 'w' : 'r'; $tpl->assign('mode_access', $lvl_access); /* @@ -107,21 +123,20 @@ $form = new HTML_QuickForm('form', 'POST', "?p=" . $p); -/* - * Different style between each lines - */ +// Different style between each lines $style = "one"; -/* - * Define command Type table - */ -$commandType = array("1" => _("Notification"), "2" => _("Check"), "3" => _("Miscellaneous"), "4" => _("Discovery")); +// Define command Type table +$commandType = array( + "1" => _("Notification"), + "2" => _("Check"), + "3" => _("Miscellaneous"), + "4" => _("Discovery") +); -/* - * Fill a tab with a mutlidimensionnal Array we put in $tpl - */ +// Fill a tab with a multidimensional Array we put in $tpl $elemArr = array(); -for ($i = 0; $cmd = $DBRESULT->fetchRow(); $i++) { +for ($i = 0; $cmd = $dbResult->fetch(); $i++) { $selectedElements = $form->addElement('checkbox', "select[" . $cmd['command_id'] . "]"); if ($cmd["command_activate"]) { @@ -137,17 +152,18 @@ if (isset($lockedElements[$cmd['command_id']])) { $selectedElements->setAttribute('disabled', 'disabled'); } else { - $moptions .= " 31 && (event.keyCode < 45 || event.keyCode > 57)) " . - "event.returnValue = false; if(event.which > 31 && (event.which < 45 || event.which > 57)) " . - "return false;\" maxlength=\"3\" size=\"3\" value='1' style=\"margin-bottom:0px;\" name='dupNbr[" . - $cmd['command_id'] . "]' />"; + $moptions .= " 31 && (event.keyCode < 45 || event.keyCode > 57)) " + . "event.returnValue = false; if(event.which > 31 && (event.which < 45 || event.which > 57)) " + . "return false;\" maxlength=\"3\" size=\"3\" value='1' style=\"margin-bottom:0px;\" name='dupNbr[" + . $cmd['command_id'] . "]' />"; } $elemArr[$i] = array( "MenuClass" => "list_" . $style, "RowMenu_select" => $selectedElements->toHtml(), "RowMenu_name" => $cmd["command_name"], - "RowMenu_link" => "main.php?p=" . $p . "&o=c&command_id=" . $cmd['command_id'] . "&type=" . $cmd['command_type'], + "RowMenu_link" => "main.php?p=" . $p . + "&o=c&command_id=" . $cmd['command_id'] . "&type=" . $cmd['command_type'], "RowMenu_desc" => CentreonUtils::escapeSecure(substr(myDecodeCommand($cmd["command_line"]), 0, 50)) . "...", "RowMenu_type" => $commandType[$cmd["command_type"]], "RowMenu_huse" => "" . @@ -162,27 +178,26 @@ } $tpl->assign("elemArr", $elemArr); -/* - * Different messages we put in the template - */ +// Different messages we put in the template if (isset($_GET['type']) && $_GET['type'] != "") { $type = htmlentities($_GET['type'], ENT_QUOTES, "UTF-8"); } elseif (!isset($_GET['type'])) { $type = 2; } -$tpl->assign('msg', array( - "addL" => "main.php?p=" . $p . "&o=a&type=" . $type, - "addT" => _("Add"), - "delConfirm" => _("Do you confirm the deletion ?") -)); +$tpl->assign( + 'msg', + array( + "addL" => "main.php?p=" . $p . "&o=a&type=" . $type, + "addT" => _("Add"), + "delConfirm" => _("Do you confirm the deletion ?") + ) +); $redirectType = $form->addElement('hidden', 'type'); $redirectType->setValue($type); -/* - * Toolbar select - */ +// Toolbar select foreach (array('o1', 'o2') as $option) { $attrs1 = array( 'onchange' => "javascript: " . @@ -201,13 +216,19 @@ " setO(this.form.elements['$option'].value); submit();} " . "this.form.elements['$option'].selectedIndex = 0" ); - $form->addElement('select', $option, null, array( - null => _("More actions..."), - "m" => _("Duplicate"), - "d" => _("Delete"), - "me" => _("Enable"), - "md" => _("Disable") - ), $attrs1); + $form->addElement( + 'select', + $option, + null, + array( + null => _("More actions..."), + "m" => _("Duplicate"), + "d" => _("Delete"), + "me" => _("Enable"), + "md" => _("Disable") + ), + $attrs1 + ); $form->setDefaults(array($option => null)); $o1 = $form->getElement($option); $o1->setValue(null); @@ -215,15 +236,14 @@ } ?> - + accept($renderer); $tpl->assign('form', $renderer->toArray()); diff --git a/www/include/configuration/configObject/connector/listConnector.php b/www/include/configuration/configObject/connector/listConnector.php index c97fb9b8f81..5d5c93e9e7a 100644 --- a/www/include/configuration/configObject/connector/listConnector.php +++ b/www/include/configuration/configObject/connector/listConnector.php @@ -1,7 +1,7 @@ historyLastUrl === $url && isset($_GET['num'])) { + $num = $_GET['num']; +} + try { $connectorsList = $connectorObj->getList(false, (int)$num, (int)$limit); @@ -48,11 +54,14 @@ $form = new HTML_QuickFormCustom('Form', 'post', "?p=" . $p); - $tpl->assign('msg', array( - "addL" => "main.php?p=" . $p . "&o=a", - "addT" => _("Add"), - "delConfirm" => _("Do you confirm the deletion ?") - )); + $tpl->assign( + 'msg', + array( + "addL" => "main.php?p=" . $p . "&o=a", + "addT" => _("Add"), + "delConfirm" => _("Do you confirm the deletion ?") + ) + ); /* * Toolbar select @@ -74,11 +83,17 @@ "this.form.elements['" . $option . "'].selectedIndex = 0" ); - $form->addElement('select', $option, null, array( - null => _("More actions..."), - "m" => _("Duplicate"), - "d" => _("Delete") - ), $attrs1); + $form->addElement( + 'select', + $option, + null, + array( + null => _("More actions..."), + "m" => _("Duplicate"), + "d" => _("Delete") + ), + $attrs1 + ); $form->setDefaults(array($option => null)); $o1 = $form->getElement($option); $o1->setValue(null); diff --git a/www/include/configuration/configObject/contact/listContact.php b/www/include/configuration/configObject/contact/listContact.php index 2e57370a257..04cbdcf9e29 100644 --- a/www/include/configuration/configObject/contact/listContact.php +++ b/www/include/configuration/configObject/contact/listContact.php @@ -1,7 +1,7 @@ ""); -$DBRESULT = $pearDB->query("SELECT tp_name, tp_id FROM timeperiod"); -while ($data = $DBRESULT->fetchRow()) { +$dbResult = $pearDB->query("SELECT tp_name, tp_id FROM timeperiod"); +while ($data = $dbResult->fetch()) { $tpCache[$data["tp_id"]] = $data["tp_name"]; } unset($data); -$DBRESULT->closeCursor(); +$dbResult->closeCursor(); + +$search = filter_var( + $_POST['searchC'] ?? $_GET['search'] ?? null, + FILTER_SANITIZE_STRING +); -$clauses = array(); $search = null; -if (isset($_POST['searchC'])) { - $search = $_POST['searchC']; - $centreon->historySearch[$url] = $search; -} elseif (isset($_GET['search'])) { - $search = $_GET['search']; - $centreon->historySearch[$url] = $search; -} elseif (isset($centreon->historySearch[$url])) { - $search = $centreon->historySearch[$url]; +if (isset($_POST['searchC']) || isset($_GET['search'])) { + $centreon->historySearch[$url] = array(); + $centreon->historySearch[$url]['search'] = $search; +} else { + $search = $centreon->historySearch[$url]['search'] ?? null; } +$clauses = array(); if ($search) { $clauses = array( 'contact_name' => array('LIKE', '%' . $search . '%'), @@ -94,21 +96,17 @@ $contacts = $acl->getContactAclConf($aclOptions); $rows = count($contacts); -include("./include/common/checkPagination.php"); +include "./include/common/checkPagination.php"; -/* - * Smarty template Init - */ +// Smarty template Init $tpl = new Smarty(); $tpl = initSmartyTpl($path, $tpl); -/* Access level */ +// Access level ($centreon->user->access->page($p) == 1) ? $lvl_access = 'w' : $lvl_access = 'r'; $tpl->assign('mode_access', $lvl_access); -/* - * start header menu - */ +// start header menu $tpl->assign("headerMenu_name", _("Full Name")); $tpl->assign("headerMenu_desc", _("Alias / Login")); $tpl->assign("headerMenu_email", _("Email")); @@ -130,9 +128,7 @@ $form = new HTML_QuickFormCustom('select_form', 'POST', "?p=" . $p); -/* - * Different style between each lines - */ +// Different style between each lines $style = "one"; $contactTypeIcone = array( 1 => "./img/icons/admin.png", @@ -145,13 +141,17 @@ 3 => _("This is a contact template.") ); -/* - * Fill a tab with a mutlidimensionnal Array we put in $tpl - */ +// Fill a tab with a multidimensional Array we put in $tpl $elemArr = array(); foreach ($contacts as $contact) { if ($centreon->user->get_id() == $contact['contact_id']) { - $selectedElements = $form->addElement('checkbox', "select[" . $contact['contact_id'] . "]", '', '', 'disabled'); + $selectedElements = $form->addElement( + 'checkbox', + "select[" . $contact['contact_id'] . "]", + '', + '', + 'disabled' + ); } else { $selectedElements = $form->addElement('checkbox', "select[" . $contact['contact_id'] . "]"); } @@ -229,38 +229,38 @@ } $tpl->assign("elemArr", $elemArr); -/* - * Different messages we put in the template - */ -$tpl->assign('msg', array( - "addL" => "main.php?p=" . $p . "&o=a", - "addT" => _("Add"), - "ldap_importL" => "main.php?p=" . $p . "&o=li", - "ldap_importT" => _("LDAP Import"), - "view_notif" => _("View contact notifications") -)); +// Different messages we put in the template +$tpl->assign( + 'msg', + array( + "addL" => "main.php?p=" . $p . "&o=a", + "addT" => _("Add"), + "ldap_importL" => "main.php?p=" . $p . "&o=li", + "ldap_importT" => _("LDAP Import"), + "view_notif" => _("View contact notifications") + ) +); -# Display import ldap users button if ldap is configured -$query = "SELECT count(ar_id) as count_ldap " - . "FROM auth_ressource "; -$res = $pearDB->query($query); -$row = $res->fetchRow(); +// Display import ldap users button if ldap is configured +$res = $pearDB->query( + "SELECT count(ar_id) as count_ldap " . + "FROM auth_ressource " +); +$row = $res->fetch(); if ($row['count_ldap'] > 0) { $tpl->assign('ldap', '1'); } -/* - * Toolbar select - */ +// Toolbar select ?> - + "javascript: " . @@ -278,14 +278,20 @@ function setO(_i) { " setO(this.form.elements['" . $option . "'].value); submit();} " . "this.form.elements['" . $option . "'].selectedIndex = 0" ); - $form->addElement('select', $option, null, array( - null => _("More actions..."), - "m" => _("Duplicate"), - "d" => _("Delete"), - "mc" => _("Massive Change"), - "ms" => _("Enable"), - "mu" => _("Disable") - ), $attrs1); + $form->addElement( + 'select', + $option, + null, + array( + null => _("More actions..."), + "m" => _("Duplicate"), + "d" => _("Delete"), + "mc" => _("Massive Change"), + "ms" => _("Enable"), + "mu" => _("Disable") + ), + $attrs1 + ); $form->setDefaults(array($option => null)); $o1 = $form->getElement($option); @@ -296,9 +302,7 @@ function setO(_i) { $tpl->assign('limit', $limit); $tpl->assign('searchC', $search); -/* - * Apply a template definition - */ +// Apply a template definition $renderer = new HTML_QuickForm_Renderer_ArraySmarty($tpl); $form->accept($renderer); $tpl->assign('form', $renderer->toArray()); diff --git a/www/include/configuration/configObject/contact_template_model/listContactTemplateModel.php b/www/include/configuration/configObject/contact_template_model/listContactTemplateModel.php index bb17be96c99..5f0e48acc52 100644 --- a/www/include/configuration/configObject/contact_template_model/listContactTemplateModel.php +++ b/www/include/configuration/configObject/contact_template_model/listContactTemplateModel.php @@ -1,8 +1,8 @@ "./img/icons/admin.png", @@ -52,26 +52,26 @@ * Create Timeperiod Cache */ $tpCache = array("" => ""); -$DBRESULT = $pearDB->query("SELECT tp_name, tp_id FROM timeperiod"); -while ($data = $DBRESULT->fetchRow()) { +$dbResult = $pearDB->query("SELECT tp_name, tp_id FROM timeperiod"); +while ($data = $dbResult->fetch()) { $tpCache[$data["tp_id"]] = $data["tp_name"]; } unset($data); -$DBRESULT->closeCursor(); +$dbResult->closeCursor(); -$clauses = array(); -$search = null; +$search = filter_var( + $_POST['searchCT'] ?? $_GET['searchCT'] ?? null, + FILTER_SANITIZE_STRING +); -if (isset($_POST['searchCT'])) { - $search = $_POST['searchCT']; - $centreon->historySearch[$url] = $search; -} elseif (isset($_GET['search'])) { - $search = $_GET['search']; - $centreon->historySearch[$url] = $search; -} elseif (isset($centreon->historySearch[$url])) { - $search = $centreon->historySearch[$url]; +if (isset($_POST['searchCT']) || isset($_GET['searchCT'])) { + $centreon->historySearch[$url] = array(); + $centreon->historySearch[$url]['search'] = $search; +} else { + $search = $centreon->historySearch[$url]['search'] ?? null; } +$clauses = array(); if ($search) { $clauses = array('contact_name' => '%' . $search . '%'); } @@ -91,7 +91,7 @@ array(($num * $limit), $limit) ); $rows = $pearDB->query("SELECT FOUND_ROWS()")->fetchColumn(); -include("./include/common/checkPagination.php"); +include "./include/common/checkPagination.php"; /* * Smarty template Init @@ -99,13 +99,11 @@ $tpl = new Smarty(); $tpl = initSmartyTpl($path, $tpl); -/* Access level */ +// Access level ($centreon->user->access->page($p) == 1) ? $lvl_access = 'w' : $lvl_access = 'r'; $tpl->assign('mode_access', $lvl_access); -/* - * start header menu - */ +// start header menu $tpl->assign("headerMenu_name", _("Full Name")); $tpl->assign("headerMenu_desc", _("Alias / Login")); $tpl->assign("headerMenu_email", _("Email")); @@ -117,21 +115,15 @@ $tpl->assign("headerMenu_admin", _("Admin")); $tpl->assign("headerMenu_options", _("Options")); -/* - * Contact list - */ +// Contact list $search = tidySearchKey($search, $advanced_search); $form = new HTML_QuickFormCustom('select_form', 'POST', "?p=" . $p); -/* - * Different style between each lines - */ +// Different style between each lines $style = "one"; -/* - * Fill a tab with a mutlidimensionnal Array we put in $tpl - */ +// Fill a tab with a multidimensional Array we put in $tpl $elemArr = array(); foreach ($contacts as $contact) { $selectedElements = $form->addElement('checkbox', "select[" . $contact['contact_id'] . "]"); @@ -199,17 +191,13 @@ } $tpl->assign("elemArr", $elemArr); -/* - * Different messages we put in the template - */ +// Different messages we put in the template $tpl->assign('msg', array("addL" => "main.php?p=" . $p . "&o=a", "addT" => _("Add"))); if ($centreon->optGen['ldap_auth_enable']) { $tpl->assign('ldap', $centreon->optGen['ldap_auth_enable']); } -/* - * Toolbar select - */ +// Toolbar select ?> + accept($renderer); $tpl->assign('form', $renderer->toArray()); diff --git a/www/include/configuration/configObject/escalation/listEscalation.php b/www/include/configuration/configObject/escalation/listEscalation.php index 50c3cc4e0d3..c6f325be965 100644 --- a/www/include/configuration/configObject/escalation/listEscalation.php +++ b/www/include/configuration/configObject/escalation/listEscalation.php @@ -1,7 +1,7 @@ historySearch[$url] = $search; -} elseif (isset($_GET['searchE'])) { - $search = $_GET['searchE']; - $centreon->historySearch[$url] = $search; -} elseif (isset($centreon->historySearch[$url])) { - $search = $centreon->historySearch[$url]; + $centreon->historySearch[$url] = array(); + $centreon->historySearch[$url]['search'] = $search; +} else { + $search = $centreon->historySearch[$url]['search'] ?? null; } $aclFrom = ""; @@ -76,25 +78,25 @@ $rq = "SELECT SQL_CALC_FOUND_ROWS esc_id, esc_name, esc_alias FROM escalation esc"; if ($list && $list == "h") { - $rq .= " WHERE (SELECT DISTINCT COUNT(host_host_id) - FROM escalation_host_relation ehr $aclFrom - WHERE ehr.escalation_esc_id = esc.esc_id " . $aclCond['h'] . ") > 0 "; + $rq .= " WHERE (SELECT DISTINCT COUNT(host_host_id) " . + " FROM escalation_host_relation ehr " . $aclFrom . + " WHERE ehr.escalation_esc_id = esc.esc_id " . $aclCond['h'] . ") > 0 "; } elseif ($list && $list == "sv") { - $rq .= " WHERE (SELECT DISTINCT COUNT(*) - FROM escalation_service_relation esr $aclFrom - WHERE esr.escalation_esc_id = esc.esc_id " . $aclCond['sv'] . ") > 0 "; + $rq .= " WHERE (SELECT DISTINCT COUNT(*) " . + " FROM escalation_service_relation esr " . $aclFrom . + "WHERE esr.escalation_esc_id = esc.esc_id " . $aclCond['sv'] . ") > 0 "; } elseif ($list && $list == "hg") { - $rq .= " WHERE (SELECT DISTINCT COUNT(*) - FROM escalation_hostgroup_relation ehgr - WHERE ehgr.escalation_esc_id = esc.esc_id " . $aclCond['hg'] . ") > 0 "; + $rq .= " WHERE (SELECT DISTINCT COUNT(*) " . + "FROM escalation_hostgroup_relation ehgr " . + "WHERE ehgr.escalation_esc_id = esc.esc_id " . $aclCond['hg'] . ") > 0 "; } elseif ($list && $list == "sg") { - $rq .= " WHERE (SELECT DISTINCT COUNT(*) - FROM escalation_servicegroup_relation esgr - WHERE esgr.escalation_esc_id = esc.esc_id " . $aclCond['sg'] . ") > 0 "; + $rq .= " WHERE (SELECT DISTINCT COUNT(*) " . + " FROM escalation_servicegroup_relation esgr " . + " WHERE esgr.escalation_esc_id = esc.esc_id " . $aclCond['sg'] . ") > 0 "; } elseif ($list && $list == "ms") { - $rq .= " WHERE (SELECT DISTINCT COUNT(*) - FROM escalation_meta_service_relation emsr - WHERE emsr.escalation_esc_id = esc.esc_id " . $aclCond['ms'] . ") > 0 "; + $rq .= " WHERE (SELECT DISTINCT COUNT(*) " . + " FROM escalation_meta_service_relation emsr " . + " WHERE emsr.escalation_esc_id = esc.esc_id " . $aclCond['ms'] . ") > 0 "; } //Check if $search was init @@ -104,29 +106,23 @@ $rq .= " WHERE (esc.esc_name LIKE '%" . $search . "%' OR esc.esc_alias LIKE '%" . $search . "%')"; } -/* - * Set Order and limits - */ +// Set Order and limits $rq .= " ORDER BY esc_name LIMIT " . $num * $limit . ", " . $limit; -$DBRESULT = $pearDB->query($rq); +$dbResult = $pearDB->query($rq); $rows = $pearDB->query("SELECT FOUND_ROWS()")->fetchColumn(); -include("./include/common/checkPagination.php"); +include "./include/common/checkPagination.php"; -/* - * Smarty template Init - */ +// Smarty template Init $tpl = new Smarty(); $tpl = initSmartyTpl($path, $tpl); -/* Access level */ -($centreon->user->access->page($p) == 1) ? $lvl_access = 'w' : $lvl_access = 'r'; +// Access level +$lvl_access = ($centreon->user->access->page($p) == 1) ? 'w' : 'r'; $tpl->assign('mode_access', $lvl_access); -/* - * start header menu - */ +// start header menu $tpl->assign("headerMenu_name", _("Name")); $tpl->assign("headerMenu_alias", _("Alias")); @@ -139,16 +135,12 @@ $form = new HTML_QuickFormCustom('select_form', 'POST', "?p=" . $p); -/* - * Different style between each lines - */ +// Different style between each lines $style = "one"; -/* - * Fill a tab with a mutlidimensionnal Array we put in $tpl - */ +// Fill a tab with a multidimensional Array we put in $tpl $elemArr = array(); -for ($i = 0; $esc = $DBRESULT->fetchRow(); $i++) { +for ($i = 0; $esc = $dbResult->fetch(); $i++) { $moptions = ""; $selectedElements = $form->addElement('checkbox', "select[" . $esc['esc_id'] . "]"); $moptions .= @@ -169,23 +161,23 @@ } $tpl->assign("elemArr", $elemArr); -/* - * Different messages we put in the template - */ +// Different messages we put in the template $tpl->assign( 'msg', - array("addL" => "main.php?p=" . $p . "&o=a", "addT" => _("Add"), "delConfirm" => _("Do you confirm the deletion ?")) + array( + "addL" => "main.php?p=" . $p . "&o=a", + "addT" => _("Add"), + "delConfirm" => _("Do you confirm the deletion ?") + ) ); -/* - * Toolbar select more_actions - */ +// Toolbar select more_actions ?> - + "javascript: " . @@ -254,9 +246,7 @@ function setO(_i) { $tpl->assign('limit', $limit); $tpl->assign('searchE', $search); -/* - * Apply a template definition - */ +// Apply a template definition $renderer = new HTML_QuickForm_Renderer_ArraySmarty($tpl); $form->accept($renderer); $tpl->assign('form', $renderer->toArray()); diff --git a/www/include/configuration/configObject/host/formHost.php b/www/include/configuration/configObject/host/formHost.php index 568cf161d5a..19439ca8a60 100644 --- a/www/include/configuration/configObject/host/formHost.php +++ b/www/include/configuration/configObject/host/formHost.php @@ -1,7 +1,7 @@ getHostCategoriesString(); -/* notification contacts */ +// notification contacts $notifCs = $acl->getContactAclConf(array( 'fields' => array('contact_id', 'contact_name'), 'get_row' => 'contact_name', @@ -63,7 +63,7 @@ 'order' => array('contact_name') )); -/* notification contact groups */ +// notification contact groups $notifCgs = $acl->getContactGroupAclConf(array( 'fields' => array('cg_id', 'cg_name'), 'get_row' => 'cg_name', @@ -127,9 +127,7 @@ function allInSameInstance($hosts, $instanceId) */ $host = array(); -/** - * define macros as empty array to avoid null counting - */ +// define macros as empty array to avoid null counting $aMacros = array(); if (($o == "c" || $o == "w") && $host_id) { @@ -138,40 +136,32 @@ function allInSameInstance($hosts, $instanceId) WHERE host_id = '" . $host_id . "' AND ehi.host_host_id = host.host_id LIMIT 1"); - /* - * Set base value - */ - $host_list = $DBRESULT->fetchRow(); + // Set base value + $host_list = $DBRESULT->fetch(); $host = array_map("myDecode", $host_list); $cmdId = $host['command_command_id']; - /* - * Set Host Notification Options - */ + // Set Host Notification Options $tmp = explode(',', $host["host_notification_options"]); foreach ($tmp as $key => $value) { $host["host_notifOpts"][trim($value)] = 1; } - /* - * Set Stalking Options - */ + // Set Stalking Options $tmp = explode(',', $host["host_stalking_options"]); foreach ($tmp as $key => $value) { $host["host_stalOpts"][trim($value)] = 1; } $DBRESULT->closeCursor(); - /* - * Set Host Category Parents - */ + // Set Host Category Parents $DBRESULT = $pearDB->query('SELECT DISTINCT hostcategories_hc_id FROM hostcategories_relation hcr, hostcategories hc WHERE hcr.hostcategories_hc_id = hc.hc_id AND hc.level IS NULL AND hcr.host_host_id = \'' . $host_id . '\''); - for ($i = 0; $hc = $DBRESULT->fetchRow(); $i++) { + for ($i = 0; $hc = $DBRESULT->fetch(); $i++) { if (!$centreon->user->admin && false === strpos($hcString, "'" . $hc['hostcategories_hc_id'] . "'")) { $initialValues['host_hcs'][] = $hc['hostcategories_hc_id']; $host["host_hcs"][$i] = $hc['hostcategories_hc_id']; @@ -181,21 +171,17 @@ function allInSameInstance($hosts, $instanceId) } $DBRESULT->closeCursor(); - /* - * Set Host and Nagios Server Relation - */ + // Set Host and Nagios Server Relation $DBRESULT = $pearDB->query("SELECT `nagios_server_id` FROM `ns_host_relation` WHERE `host_host_id` = '" . $host_id . "'"); - for (($o != "mc") ? $i = 0 : $i = 1; $ns = $DBRESULT->fetchRow(); $i++) { + for (($o != "mc") ? $i = 0 : $i = 1; $ns = $DBRESULT->fetch(); $i++) { $host["nagios_server_id"][$i] = $ns["nagios_server_id"]; } $DBRESULT->closeCursor(); unset($ns); - /* - * Set criticality - */ + // Set critically $res = $pearDB->query("SELECT hc.hc_id FROM hostcategories hc, hostcategories_relation hcr WHERE hcr.host_host_id = " . $pearDB->escape($host_id) . " @@ -204,7 +190,7 @@ function allInSameInstance($hosts, $instanceId) ORDER BY hc.level ASC LIMIT 1"); if ($res->rowCount()) { - $cr = $res->fetchRow(); + $cr = $res->fetch(); $host['criticality_id'] = $cr['hc_id']; } @@ -215,9 +201,8 @@ function allInSameInstance($hosts, $instanceId) $aMacros = $hostObj->getMacros($host_id, false, $aTemplates, $cmdId, $_POST); } -/* - * Preset values of macros - */ + +// Preset values of macros $cdata = CentreonData::getInstance(); $cdata->addJsData('clone-values-macro', htmlspecialchars( @@ -226,9 +211,8 @@ function allInSameInstance($hosts, $instanceId) )); $cdata->addJsData('clone-count-macro', count($aMacros)); -/* - * Preset values of host templates - */ + +// Preset values of host templates $tplArray = $hostObj->getTemplates(isset($host_id) ? $host_id : null); $cdata->addJsData('clone-values-template', htmlspecialchars( json_encode($tplArray), @@ -236,9 +220,7 @@ function allInSameInstance($hosts, $instanceId) )); $cdata->addJsData('clone-count-template', count($tplArray)); -/* - * Nagios Server comes from DB -> Store in $nsServer Array - */ +// Nagios Server comes from DB -> Store in $nsServer Array $nsServers = array(); if ($o == "mc") { $nsServers[null] = null; @@ -247,40 +229,32 @@ function allInSameInstance($hosts, $instanceId) FROM nagios_server " . ($aclPollerString != "''" ? $acl->queryBuilder('WHERE', 'id', $aclPollerString) : "") . " ORDER BY name"); -while ($nsServer = $DBRESULT->fetchRow()) { +while ($nsServer = $DBRESULT->fetch()) { $nsServers[$nsServer["id"]] = $nsServer["name"]; } $DBRESULT->closeCursor(); -/* - * IMG comes from DB -> Store in $extImg Array - */ +// IMG comes from DB -> Store in $extImg Array $extImg = array(); $extImg = return_image_list(1); $extImgStatusmap = array(); $extImgStatusmap = return_image_list(2); -/* - * Host multiple templates relations stored in DB - */ +// Host multiple templates relations stored in DB $mTp = array(); $k = 0; $DBRESULT = $pearDB->query("SELECT host_tpl_id FROM host_template_relation WHERE host_host_id = '" . $host_id . "' ORDER BY `order`"); -while ($multiTp = $DBRESULT->fetchRow()) { +while ($multiTp = $DBRESULT->fetch()) { $mTp[$k] = $multiTp["host_tpl_id"]; $k++; } $DBRESULT->closeCursor(); -# -# End of "database-retrieved" information -########################################################## -########################################################## -# Var information to format the element -# + +// Var information to format the element $attrsText = array("size" => "30"); $attrsText2 = array("size" => "6"); $attrsAdvSelect = array("style" => "width: 270px; height: 100px;"); @@ -421,7 +395,7 @@ function allInSameInstance($hosts, $instanceId) * Get deault poller id */ $DBRESULT = $pearDB->query("SELECT id FROM nagios_server WHERE is_default = '1'"); -$defaultServer = $DBRESULT->fetchRow(); +$defaultServer = $DBRESULT->fetch(); $DBRESULT->closeCursor(); if (isset($defaultServer) && $defaultServer && $o != "mc") { $form->setDefaults(array('nagios_server_id' => $defaultServer["id"])); diff --git a/www/include/configuration/configObject/host/listHost.ihtml b/www/include/configuration/configObject/host/listHost.ihtml index d966d2bb87d..a964e8cb9db 100644 --- a/www/include/configuration/configObject/host/listHost.ihtml +++ b/www/include/configuration/configObject/host/listHost.ihtml @@ -2,39 +2,39 @@ {literal} {/literal} \ No newline at end of file diff --git a/www/include/configuration/configObject/host/listHost.php b/www/include/configuration/configObject/host/listHost.php index 6aec7f2467c..6a56793ef01 100644 --- a/www/include/configuration/configObject/host/listHost.php +++ b/www/include/configuration/configObject/host/listHost.php @@ -1,7 +1,7 @@ query('SELECT ehi_icon_image, host_host_id FROM extended_host_information'); +$dbResult = $pearDB->query('SELECT ehi_icon_image, host_host_id FROM extended_host_information'); -while ($ehi = $DBRESULT->fetch()) { +while ($ehi = $dbResult->fetch()) { $ehiCache[$ehi['host_host_id']] = $ehi['ehi_icon_image']; } -$DBRESULT->closeCursor(); +$dbResult->closeCursor(); $mainQueryParameters = []; -$search = null; -$poller = 0; -$hostgroup = 0; -$template = 0; + +//initializing filters values +$search = filter_var( + $_POST["searchH"] ?? $_GET["search"] ?? null, + FILTER_SANITIZE_STRING +); +$poller = filter_var( + $_POST["poller"] ?? $_GET["poller"] ?? 0, + FILTER_VALIDATE_INT +); +$hostgroup = filter_var( + $_POST["hostgroup"] ?? $_GET["hostgroup"] ?? 0, + FILTER_VALIDATE_INT +); +$template = filter_var( + $_POST["template"] ?? $_GET["template"] ?? 0, + FILTER_VALIDATE_INT +); + $status = -1; -if (isset($_POST['SearchB'])) { - $num = 0; +if (isset($_POST['searchH']) || isset($_GET['search'])) { + //saving chosen filters values $centreon->historySearch[$url] = array(); - $search = $_POST["searchH"]; - $centreon->historySearch[$url]["searchH"] = $search; - $poller = $_POST["poller"]; + $centreon->historySearch[$url]["search"] = $search; $centreon->historySearch[$url]["poller"] = $poller; - $hostgroup = $_POST["hostgroup"]; $centreon->historySearch[$url]["hostgroup"] = $hostgroup; - $template = $_POST["template"]; $centreon->historySearch[$url]["template"] = $template; - $status = $_POST["status"]; - $centreon->historySearch[$url]["status"] = $status; -} elseif (isset($_GET['SearchB'])) { - $centreon->historySearch[$url] = array(); - $search = $_GET['searchH']; - $centreon->historySearch[$url]['searchH'] = $search; - $poller = $_GET["poller"]; - $centreon->historySearch[$url]["poller"] = $poller; - $hostgroup = $_GET["hostgroup"]; - $centreon->historySearch[$url]["hostgroup"] = $hostgroup; - $template = $_GET["template"]; - $centreon->historySearch[$url]["template"] = $template; - $status = $_GET["status"]; + $status = $_POST["status"] ?? ''; $centreon->historySearch[$url]["status"] = $status; } else { - if (isset($centreon->historySearch[$url]['searchH'])) { - $search = $centreon->historySearch[$url]['searchH']; - } - if (isset($centreon->historySearch[$url]["poller"])) { - $poller = $centreon->historySearch[$url]["poller"]; - } - if (isset($centreon->historySearch[$url]["hostgroup"])) { - $hostgroup = $centreon->historySearch[$url]["hostgroup"]; - } - if (isset($centreon->historySearch[$url]["template"])) { - $template = $centreon->historySearch[$url]["template"]; - } + //restoring saved values + $search = $centreon->historySearch[$url]['search'] ?? null; + $poller = $centreon->historySearch[$url]["poller"] ?? 0; + $hostgroup = $centreon->historySearch[$url]["hostgroup"] ?? 0; + $template = $centreon->historySearch[$url]["template"] ?? 0; if (isset($centreon->historySearch[$url]["status"])) { $status = $centreon->historySearch[$url]["status"]; } } // Security fix -$hostgroup = (int)$hostgroup; -$poller = (int)$poller; -$template = (int)$template; $status = (int)(($status != '') ? $status : -1); -/* - * set object history - */ +// set object history $centreon->poller = $poller; $centreon->hostgroup = $hostgroup; $centreon->template = $template; -/* - * Status Filter - */ +// Status Filter $statusFilter = ""; @@ -148,9 +127,7 @@ * Search active */ $searchFilterQuery = ''; -if (isset($search) && - !empty($search) -) { +if (isset($search) && !empty($search)) { $search = str_replace('_', "\_", $search); $mainQueryParameters[':search_string'] = "%{$search}%"; $searchFilterQuery = '(h.host_name LIKE :search_string @@ -166,16 +143,12 @@ $templateFROM = ''; $templateWHERE = ''; } -/* - * Smarty template Init - */ + +// Smarty template Init $tpl = new Smarty(); $tpl = initSmartyTpl($path, $tpl); -/* Access level */ -$lvl_access = ($centreon->user->access->page($p) == 1) - ? 'w' - : 'r'; +$lvl_access = ($centreon->user->access->page($p) == 1) ? 'w' : 'r'; $tpl->assign('mode_access', $lvl_access); @@ -190,49 +163,37 @@ $tpl->assign("headerMenu_status", _("Status")); $tpl->assign("headerMenu_options", _("Options")); -/* - * Host list - */ +// Host list $nagios_server = array(); -$DBRESULT = $pearDB->query('SELECT ns.name, ns.id FROM nagios_server ns ' . +$dbResult = $pearDB->query( + 'SELECT ns.name, ns.id FROM nagios_server ns ' . ($aclPollerString != "''" ? $acl->queryBuilder('WHERE', 'ns.id', $aclPollerString) : '') . - ' ORDER BY ns.name'); + ' ORDER BY ns.name' +); -while ($relation = $DBRESULT->fetch()) { +while ($relation = $dbResult->fetch()) { $nagios_server[$relation['id']] = $relation['name']; } -$DBRESULT->closeCursor(); +$dbResult->closeCursor(); unset($relation); $tab_relation = array(); $tab_relation_id = array(); -$DBRESULT = $pearDB->query( +$dbResult = $pearDB->query( 'SELECT nhr.host_host_id, nhr.nagios_server_id FROM ns_host_relation nhr' ); -while ($relation = $DBRESULT->fetchRow()) { - $tab_relation[$relation['host_host_id']] = - $nagios_server[$relation['nagios_server_id']]; - +while ($relation = $dbResult->fetch()) { + $tab_relation[$relation['host_host_id']] = $nagios_server[$relation['nagios_server_id']]; $tab_relation_id[$relation['host_host_id']] = $relation['nagios_server_id']; } -$DBRESULT->closeCursor(); - -/* - * Init Formulary - */ +$dbResult->closeCursor(); +// Init Form $form = new HTML_QuickFormCustom('select_form', 'POST', "?p={$p}"); -/* - * Different style between each lines - */ - +// Different style between each lines $style = 'one'; -/* - * Fill a tab with a mutlidimensionnal Array we put in $tpl - */ - /* * Select hosts */ @@ -240,14 +201,14 @@ $aclCond = ''; if (!$centreon->user->admin) { $aclFrom = ", {$aclDbName}.centreon_acl acl"; - $aclCond = - ' AND h.host_id = acl.host_id AND acl.service_id IS NULL ' + $aclCond + = ' AND h.host_id = acl.host_id AND acl.service_id IS NULL ' . 'AND acl.group_id IN (' . $acl->getAccessGroupsString() . ') '; } if ($hostgroup) { if ($poller) { - $DBRESULT = $pearDB->query( + $dbResult = $pearDB->query( "SELECT SQL_CALC_FOUND_ROWS DISTINCT h.host_id, h.host_name, host_alias, host_address, host_activate, host_template_model_htm_id FROM host h, ns_host_relation, hostgroup_relation hr $templateFROM $aclFrom @@ -260,7 +221,7 @@ $mainQueryParameters ); } else { - $DBRESULT = $pearDB->query( + $dbResult = $pearDB->query( "SELECT SQL_CALC_FOUND_ROWS DISTINCT h.host_id, h.host_name, host_alias, host_address, host_activate, host_template_model_htm_id FROM host h, hostgroup_relation hr $templateFROM $aclFrom @@ -273,7 +234,7 @@ } } else { if ($poller) { - $DBRESULT = $pearDB->query( + $dbResult = $pearDB->query( "SELECT SQL_CALC_FOUND_ROWS DISTINCT h.host_id, h.host_name, host_alias, host_address, host_activate, host_template_model_htm_id FROM host h, ns_host_relation $templateFROM $aclFrom @@ -284,7 +245,7 @@ $mainQueryParameters ); } else { - $DBRESULT = $pearDB->query( + $dbResult = $pearDB->query( "SELECT SQL_CALC_FOUND_ROWS DISTINCT h.host_id, h.host_name, host_alias, host_address, host_activate, host_template_model_htm_id FROM host h $templateFROM $aclFrom @@ -296,18 +257,22 @@ } $rows = $pearDB->query("SELECT FOUND_ROWS()")->fetchColumn(); -include('./include/common/checkPagination.php'); +include './include/common/checkPagination.php'; $search = tidySearchKey($search, $advanced_search); +// Fill a tab with a multidimensional Array we put in $tpl $elemArr = array(); $search = str_replace('\_', "_", $search); -for ($i = 0; $host = $DBRESULT->fetchRow(); $i++) { - if (!isset($poller) || - $poller == 0 || - ($poller != 0 && $poller == $tab_relation_id[$host["host_id"]]) +for ($i = 0; $host = $dbResult->fetch(); $i++) { + if (!isset($poller) + || $poller == 0 + || ($poller != 0 && $poller == $tab_relation_id[$host["host_id"]]) ) { - $selectedElements = $form->addElement('checkbox', "select[" . $host['host_id'] . "]"); + $selectedElements = $form->addElement( + 'checkbox', + "select[" . $host['host_id'] . "]" + ); if ($host["host_activate"]) { $moptions = "getFilename($ehiCache[$host["host_id"]]); } else { @@ -375,9 +334,7 @@ } } - /* - * Create Array Data for template list - */ + // Create Array Data for template list $elemArr[$i] = array( "MenuClass" => "list_" . $style, "RowMenu_select" => $selectedElements->toHtml(), @@ -403,9 +360,7 @@ } $tpl->assign("elemArr", $elemArr); -/* - * Different messages we put in the template - */ +// Different messages we put in the template $tpl->assign( 'msg', array( @@ -415,15 +370,13 @@ ) ); -/* - * Toolbar select - */ +// Toolbar select ?> - + " . _("All Pollers") . ""; foreach ($nagios_server as $key => $name) { $options .= ""; @@ -522,4 +473,4 @@ function setO(_i) { $tpl->assign("StatusFilter", $statusFilter); -$tpl->display("listHost.ihtml"); \ No newline at end of file +$tpl->display("listHost.ihtml"); diff --git a/www/include/configuration/configObject/host_categories/listHostCategories.php b/www/include/configuration/configObject/host_categories/listHostCategories.php index dcd86c4c94a..0f0fc96498b 100644 --- a/www/include/configuration/configObject/host_categories/listHostCategories.php +++ b/www/include/configuration/configObject/host_categories/listHostCategories.php @@ -1,7 +1,7 @@ historySearch[$url] = $search; -} elseif (isset($_GET['searchH'])) { - $search = $_GET['searchH']; - $centreon->historySearch[$url] = $search; -} elseif (isset($centreon->historySearch[$url])) { - $search = $centreon->historySearch[$url]; +$search = filter_var( + $_POST['searchH'] ?? $_GET['searchH'] ?? null, + FILTER_SANITIZE_STRING +); + +if (isset($_POST['searchH']) || isset($_GET['searchH'])) { + $centreon->historySearch[$url] = array(); + $centreon->historySearch[$url]['search'] = $search; +} else { + $search = $centreon->historySearch[$url]['search'] ?? null; } if ($search) { @@ -68,21 +67,17 @@ $hcFilter = $acl->queryBuilder(is_null($SearchTool) ? 'WHERE' : 'AND', 'hc_id', $hcString); } -/* - * Hostgroup list - */ +// Hostgroup list $query = "SELECT SQL_CALC_FOUND_ROWS hc_id, hc_name, hc_alias, level, hc_activate FROM hostcategories " . - $SearchTool . $hcFilter . "ORDER BY hc_name LIMIT " . $num * $limit . ", $limit"; + $SearchTool . $hcFilter . " ORDER BY hc_name LIMIT " . $num * $limit . ", " . $limit; $DBRESULT = $pearDB->query($query); $search = tidySearchKey($search, $advanced_search); $rows = $pearDB->query("SELECT FOUND_ROWS()")->fetchColumn(); -include("./include/common/checkPagination.php"); +include_once "./include/common/checkPagination.php"; -/* - * Smarty template Init - */ +// Smarty template Init $tpl = new Smarty(); $tpl = initSmartyTpl($path, $tpl); @@ -103,16 +98,12 @@ $form = new HTML_QuickFormCustom('select_form', 'POST', "?p=" . $p); -/* - * Different style between each lines - */ +// Different style between each lines $style = "one"; -/* - * Fill a tab with a mutlidimensionnal Array we put in $tpl - */ +// Fill a tab with a multidimensional Array we put in $tpl $elemArr = array(); -for ($i = 0; $hc = $DBRESULT->fetchRow(); $i++) { +for ($i = 0; $hc = $DBRESULT->fetch(); $i++) { $selectedElements = $form->addElement('checkbox', "select[" . $hc['hc_id'] . "]"); $moptions = ""; if ($hc["hc_activate"]) { @@ -128,9 +119,7 @@ "event.returnValue = false; if(event.which > 31 && (event.which < 45 || event.which > 57)) return false;" . "\" maxlength=\"3\" size=\"3\" value='1' style=\"margin-bottom:0px;\" name='dupNbr[" . $hc['hc_id'] . "]' />"; - /* - * Check Nbr of Host / hc - */ + // Check Nbr of Host / hc $nbrhostAct = array(); $nbrhostDeact = array(); $nbrhostgroupAct = array(); @@ -142,15 +131,16 @@ $aclFrom = ", $aclDbName.centreon_acl acl "; $aclCond = " AND h.host_id = acl.host_id AND acl.group_id IN (" . $acl->getAccessGroupsString() . ") "; } - $rq = "SELECT h.host_id, h.host_activate - FROM hostcategories_relation hcr, host h $aclFrom - WHERE hostcategories_hc_id = '" . $hc['hc_id'] . "' - AND h.host_id = hcr.host_host_id $aclCond - AND h.host_register = '1' "; - $DBRESULT2 = $pearDB->query($rq); + $DBRESULT2 = $pearDB->query( + "SELECT h.host_id, h.host_activate " . + "FROM hostcategories_relation hcr, host h " . $aclFrom . + " WHERE hostcategories_hc_id = '" . $hc['hc_id'] . "'" . + " AND h.host_id = hcr.host_host_id " . $aclCond . + " AND h.host_register = '1' " + ); $nbrhostActArr = array(); $nbrhostDeactArr = array(); - while ($row = $DBRESULT2->fetchRow()) { + while ($row = $DBRESULT2->fetch()) { if ($row['host_activate']) { $nbrhostActArr[$row['host_id']] = true; } else { @@ -173,27 +163,27 @@ "RowMenu_hostDeact" => $nbrhostDeact, "RowMenu_options" => $moptions ); - /* - * Switch color line - */ + // Switch color line $style != "two" ? $style = "two" : $style = "one"; } $tpl->assign("elemArr", $elemArr); -/* - * Different messages we put in the template - */ +// Different messages we put in the template $tpl->assign( 'msg', - array("addL" => "main.php?p=" . $p . "&o=a", "addT" => _("Add"), "delConfirm" => _("Do you confirm the deletion ?")) + array( + "addL" => "main.php?p=" . $p . "&o=a", + "addT" => _("Add"), + "delConfirm" => _("Do you confirm the deletion ?") + ) ); ?> - + addElement('select', $option, null, array( - null => _("More actions..."), - "m" => _("Duplicate"), - "d" => _("Delete"), - "ms" => _("Enable"), - "mu" => _("Disable") - ), $attrs1); + $form->addElement( + 'select', + $option, + null, + array( + null => _("More actions..."), + "m" => _("Duplicate"), + "d" => _("Delete"), + "ms" => _("Enable"), + "mu" => _("Disable") + ), + $attrs1 + ); $form->setDefaults(array($option => null)); $o1 = $form->getElement($option); $o1->setValue(null); diff --git a/www/include/configuration/configObject/host_dependency/listHostDependency.php b/www/include/configuration/configObject/host_dependency/listHostDependency.php index 4c2b7684b84..ada82bdbf90 100644 --- a/www/include/configuration/configObject/host_dependency/listHostDependency.php +++ b/www/include/configuration/configObject/host_dependency/listHostDependency.php @@ -1,7 +1,7 @@ historySearch[$url] = $search; -} elseif (isset($_GET['searchHD'])) { - $search = $_GET['searchHD']; - $centreon->historySearch[$url] = $search; -} elseif (isset($centreon->historySearch[$url])) { - $search = $centreon->historySearch[$url]; + $centreon->historySearch[$url] = array(); + $centreon->historySearch[$url]['search'] = $search; +} else { + $search = $centreon->historySearch[$url]['search'] ?? null; } $aclFrom = ""; @@ -62,7 +63,7 @@ AND acl.group_id IN (" . $acl->getAccessGroupsString() . ") "; } -# Dependency list +// Dependency list $rq = "SELECT SQL_CALC_FOUND_ROWS DISTINCT dep_id, dep_name, dep_description " . "FROM dependency dep, dependency_hostParent_relation dhpr " . $aclFrom . " " . "WHERE dhpr.dependency_dep_id = dep.dep_id " . $aclCond . " "; @@ -72,21 +73,21 @@ "%' OR dep_description LIKE '%" . CentreonDB::escape($search) . "%')"; } $rq .= " ORDER BY dep_name, dep_description LIMIT " . $num * $limit . ", " . $limit; -$DBRESULT = $pearDB->query($rq); +$dbResult = $pearDB->query($rq); -# Manage pagination +// Manage pagination $rows = $pearDB->query("SELECT FOUND_ROWS()")->fetchColumn(); -include("./include/common/checkPagination.php"); +include "./include/common/checkPagination.php"; -# Smarty template Init +// Smarty template Init $tpl = new Smarty(); $tpl = initSmartyTpl($path, $tpl); -# Access level +// Access level ($centreon->user->access->page($p) == 1) ? $lvl_access = 'w' : $lvl_access = 'r'; $tpl->assign('mode_access', $lvl_access); -# Start header menu +// Start header menu $tpl->assign("headerMenu_name", _("Name")); $tpl->assign("headerMenu_description", _("Description")); $tpl->assign("headerMenu_options", _("Options")); @@ -95,12 +96,12 @@ $form = new HTML_QuickFormCustom('select_form', 'POST', "?p=" . $p); -# Different style between each lines +// Different style between each lines $style = "one"; -# Fill a tab with a mutlidimensionnal Array we put in $tpl +// Fill a tab with a multidimensional Array we put in $tpl $elemArr = array(); -for ($i = 0; $dep = $DBRESULT->fetchRow(); $i++) { +for ($i = 0; $dep = $dbResult->fetch(); $i++) { $moptions = ""; $selectedElements = $form->addElement('checkbox', "select[" . $dep['dep_id'] . "]"); $moptions .= " 31 && (event.keyCode < 45 || event.keyCode > 57)) " . @@ -119,24 +120,24 @@ } $tpl->assign("elemArr", $elemArr); -/* - * Different messages we put in the template - */ +// Different messages we put in the template $tpl->assign( 'msg', - array("addL" => "main.php?p=" . $p . "&o=a", "addT" => _("Add"), "delConfirm" => _("Do you confirm the deletion ?")) + array( + "addL" => "main.php?p=" . $p . "&o=a", + "addT" => _("Add"), + "delConfirm" => _("Do you confirm the deletion ?") + ) ); -/* - * Toolbar select - */ +// Toolbar select ?> - + "javascript: " . @@ -197,9 +198,7 @@ function setO(_i) { $tpl->assign('limit', $limit); $tpl->assign('searchHD', $search); -/* - * Apply a template definition - */ +// Apply a template definition $renderer = new HTML_QuickForm_Renderer_ArraySmarty($tpl); $form->accept($renderer); diff --git a/www/include/configuration/configObject/host_template_model/listHostTemplateModel.php b/www/include/configuration/configObject/host_template_model/listHostTemplateModel.php index 5fc73d038d3..be92bd3cab3 100755 --- a/www/include/configuration/configObject/host_template_model/listHostTemplateModel.php +++ b/www/include/configuration/configObject/host_template_model/listHostTemplateModel.php @@ -1,7 +1,7 @@ query("SELECT ehi_icon_image, host_host_id FROM extended_host_information"); -while ($ehi = $DBRESULT->fetchRow()) { +while ($ehi = $DBRESULT->fetch()) { $ehiCache[$ehi["host_host_id"]] = $ehi["ehi_icon_image"]; } $DBRESULT->closeCursor(); -$search = null; -if (isset($_POST['searchHT'])) { - $search = $_POST['searchHT']; - $centreon->historySearch[$url] = $search; -} elseif (isset($_GET['searchHT'])) { - $search = $_GET['searchHT']; - $centreon->historySearch[$url] = $search; -} elseif (isset($centreon->historySearch[$url])) { - $search = $centreon->historySearch[$url]; +$search = filter_var( + $_POST['searchHT'] ?? $_GET['searchHT'] ?? null, + FILTER_SANITIZE_STRING +); + +if (isset($_POST['searchHT']) || isset($_GET['searchHT'])) { + $centreon->historySearch[$url] = array(); + $centreon->historySearch[$url]['search'] = $search; +} else { + $search = $centreon->historySearch[$url]['search'] ?? null; } -/* - * Host Template list - */ -$rq = "SELECT SQL_CALC_FOUND_ROWS host_id, host_name, host_alias, host_activate, host_template_model_htm_id FROM host" . +// Host Template list + +$rq = "SELECT SQL_CALC_FOUND_ROWS host_id, host_name, host_alias, host_activate, host_template_model_htm_id " . + "FROM host" . " WHERE host_register = '0' "; if ($search) { $rq .= "AND (host_name LIKE '%" . CentreonDB::escape($search) . "%' OR host_alias LIKE '%" . @@ -111,9 +108,9 @@ /* Different style between each lines */ $style = "one"; -/* Fill a tab with a mutlidimensionnal Array we put in $tpl */ +/* Fill a tab with a multidimensional Array we put in $tpl */ $elemArr = array(); -for ($i = 0; $host = $DBRESULT->fetchRow(); $i++) { +for ($i = 0; $host = $DBRESULT->fetch(); $i++) { $moptions = ""; $selectedElements = $form->addElement('checkbox', "select[" . $host['host_id'] . "]"); if (isset($lockedElements[$host['host_id']])) { @@ -190,15 +187,13 @@ } $tpl->assign("elemArr", $elemArr); -/* Different messages we put in the template */ +// Different messages we put in the template $tpl->assign( 'msg', array("addL" => "main.php?p=" . $p . "&o=a", "addT" => _("Add"), "delConfirm" => _("Do you confirm the deletion ?")) ); -# -## Toolbar select -# +// Toolbar select ?> + addElement('select', $option, null, array( - null => _("More actions..."), - "m" => _("Duplicate"), - "d" => _("Delete"), - "ms" => _("Enable"), - "mu" => _("Disable") - ), $attrs1); + $form->addElement( + 'select', + $option, + null, + array( + null => _("More actions..."), + "m" => _("Duplicate"), + "d" => _("Delete"), + "ms" => _("Enable"), + "mu" => _("Disable") + ), + $attrs1 + ); $form->setDefaults(array($option => null)); $o1 = $form->getElement($option); $o1->setValue(null); @@ -246,9 +242,7 @@ function setO(_i) { $tpl->assign('searchHg', $search); $tpl->assign('limit', $limit); -/* - * Apply a template definition - */ +// Apply a template definition $renderer = new HTML_QuickForm_Renderer_ArraySmarty($tpl); $form->accept($renderer); $tpl->assign('form', $renderer->toArray()); diff --git a/www/include/configuration/configObject/hostgroup_dependency/listHostGroupDependency.php b/www/include/configuration/configObject/hostgroup_dependency/listHostGroupDependency.php index 09b05c049a6..cd2d8a9d0ca 100644 --- a/www/include/configuration/configObject/hostgroup_dependency/listHostGroupDependency.php +++ b/www/include/configuration/configObject/hostgroup_dependency/listHostGroupDependency.php @@ -1,7 +1,7 @@ user->admin) { $aclCond = " AND hostgroup_hg_id IN ($hgstring) "; } -$search = null; +$search = filter_var( + $_POST['searchHGD'] ?? $_GET['searchHGD'] ?? null, + FILTER_SANITIZE_STRING +); + if (isset($_POST['searchHGD'])) { - $search = $_POST['searchHGD']; - $centreon->historySearch[$url] = $search; -} elseif (isset($_GET['searchHGD'])) { - $search = $_GET['searchHGD']; - $centreon->historySearch[$url] = $search; -} elseif (isset($centreon->historySearch[$url])) { - $search = $centreon->historySearch[$url]; + $centreon->historySearch[$url] = array(); + $centreon->historySearch[$url]['search'] = $search; +} else { + $search = $centreon->historySearch[$url]['search'] ?? null; } /* - * List dependancies + * List dependencies */ $rq = "SELECT SQL_CALC_FOUND_ROWS dep_id, dep_name, dep_description FROM dependency dep " . "WHERE ((SELECT DISTINCT COUNT(*) FROM dependency_hostgroupParent_relation dhgpr " . @@ -73,20 +74,18 @@ } $rq .= " ORDER BY dep_name, dep_description LIMIT " . $num * $limit . ", " . $limit; -$DBRESULT = $pearDB->query($rq); +$dbResult = $pearDB->query($rq); $rows = $pearDB->query("SELECT FOUND_ROWS()")->fetchColumn(); -include("./include/common/checkPagination.php"); +include "./include/common/checkPagination.php"; -/* - * Smarty template Init - */ +// Smarty template Init $tpl = new Smarty(); $tpl = initSmartyTpl($path, $tpl); -/* Access level */ -($centreon->user->access->page($p) == 1) ? $lvl_access = 'w' : $lvl_access = 'r'; +// Access level +$lvl_access = ($centreon->user->access->page($p) == 1) ? 'w' : 'r'; $tpl->assign('mode_access', $lvl_access); /* @@ -100,12 +99,12 @@ $form = new HTML_QuickFormCustom('select_form', 'POST', "?p=" . $p); -#Different style between each lines +//Different style between each lines $style = "one"; -#Fill a tab with a mutlidimensionnal Array we put in $tpl +//Fill a tab with a multidimensional Array we put in $tpl $elemArr = array(); -for ($i = 0; $dep = $DBRESULT->fetchRow(); $i++) { +for ($i = 0; $dep = $dbResult->fetch(); $i++) { $moptions = ""; $selectedElements = $form->addElement('checkbox', "select[" . $dep['dep_id'] . "]"); $moptions .= " 31 && (event.keyCode < 45 || event.keyCode > 57))" . @@ -124,21 +123,23 @@ } $tpl->assign("elemArr", $elemArr); -# Different messages we put in the template +// Different messages we put in the template $tpl->assign( 'msg', - array("addL" => "main.php?p=" . $p . "&o=a", "addT" => _("Add"), "delConfirm" => _("Do you confirm the deletion ?")) + array( + "addL" => "main.php?p=" . $p . "&o=a", + "addT" => _("Add"), + "delConfirm" => _("Do you confirm the deletion ?") + ) ); -/* - * Toolbar - */ +// Toolbar ?> - + "javascript: " . @@ -199,9 +200,7 @@ function setO(_i) { $tpl->assign('limit', $limit); $tpl->assign('searchHGD', $search); -/* - * Apply a template definition - */ +// Apply a template definition $renderer = new HTML_QuickForm_Renderer_ArraySmarty($tpl); $form->accept($renderer); $tpl->assign('form', $renderer->toArray()); diff --git a/www/include/configuration/configObject/meta_service/listMetaService.php b/www/include/configuration/configObject/meta_service/listMetaService.php index 885b751bcd0..54737afa3ad 100644 --- a/www/include/configuration/configObject/meta_service/listMetaService.php +++ b/www/include/configuration/configObject/meta_service/listMetaService.php @@ -1,7 +1,7 @@ historySearch[$url] = $search; -} elseif (isset($_GET['searchMS'])) { - $search = $_GET['searchMS']; - $centreon->historySearch[$url] = $search; -} elseif (isset($centreon->historySearch[$url])) { - $search = $centreon->historySearch[$url]; +$search = filter_var( + $_POST['searchMS'] ?? $_GET['searchMS'] ?? null, + FILTER_SANITIZE_STRING +); + +if (isset($_POST['searchMS']) || isset($_GET['searchMS'])) { + //initializing filters values + $centreon->historySearch[$url] = array(); + $centreon->historySearch[$url]["search"] = $search; +} else { + //restoring saved values + $search = $centreon->historySearch[$url]["search"] ?? null; } /* @@ -57,17 +60,17 @@ */ $rq = "SELECT SQL_CALC_FOUND_ROWS * FROM meta_service "; if ($search) { - $rq .= "WHERE meta_name LIKE '%" . htmlentities($search, ENT_QUOTES, "UTF-8") . "%' " . + $rq .= "WHERE meta_name LIKE '%" . $search . "%' " . $acl->queryBuilder("AND", "meta_id", $metaStr); } else { $rq .= $acl->queryBuilder("WHERE", "meta_id", $metaStr); } $rq .= " ORDER BY meta_name LIMIT " . $num * $limit . ", " . $limit; -$DBRESULT = $pearDB->query($rq); +$dbResult = $pearDB->query($rq); $rows = $pearDB->query("SELECT FOUND_ROWS()")->fetchColumn(); -include("./include/common/checkPagination.php"); +include "./include/common/checkPagination.php"; /* * Smarty template Init @@ -75,8 +78,8 @@ $tpl = new Smarty(); $tpl = initSmartyTpl($path, $tpl); -/* Access level */ -($centreon->user->access->page($p) == 1) ? $lvl_access = 'w' : $lvl_access = 'r'; +// Access level +$lvl_access = ($centreon->user->access->page($p) == 1) ? 'w' : 'r'; $tpl->assign('mode_access', $lvl_access); /* @@ -96,28 +99,24 @@ */ if ($search) { $rq = "SELECT * FROM meta_service " . - "WHERE meta_name LIKE '%" . htmlentities($search, ENT_QUOTES, "UTF-8") . "%' " . + "WHERE meta_name LIKE '%" . $search . "%' " . $acl->queryBuilder("AND", "meta_id", $metaStr) . - "ORDER BY meta_name LIMIT " . $num * $limit . ", " . $limit; + " ORDER BY meta_name LIMIT " . $num * $limit . ", " . $limit; } else { $rq = "SELECT * FROM meta_service " . $acl->queryBuilder("WHERE", "meta_id", $metaStr) . - "ORDER BY meta_name LIMIT " . $num * $limit . ", " . $limit; + " ORDER BY meta_name LIMIT " . $num * $limit . ", " . $limit; } -$DBRESULT = $pearDB->query($rq); +$dbResult = $pearDB->query($rq); $form = new HTML_QuickFormCustom('select_form', 'GET', "?p=" . $p); -/* - * Different style between each lines - */ +// Different style between each lines $style = "one"; -/* - * Fill a tab with a mutlidimensionnal Array we put in $tpl - */ +// Fill a tab with a multidimensional Array we put in $tpl $elemArr = array(); -for ($i = 0; $ms = $DBRESULT->fetchRow(); $i++) { +for ($i = 0; $ms = $dbResult->fetch(); $i++) { $moptions = ""; $selectedElements = $form->addElement('checkbox', "select[" . $ms['meta_id'] . "]"); if ($ms["meta_select_mode"] == 1) { @@ -130,12 +129,12 @@ if ($ms["meta_activate"]) { $moptions .= " "; + "&num=" . $num . "&search=" . $search . "'> "; } else { $moptions .= " "; + "&num=" . $num . "&search=" . $search . "'> "; } $moptions .= " "; @@ -160,9 +159,7 @@ } $tpl->assign("elemArr", $elemArr); -/* - * Different messages we put in the template - */ +// Different messages we put in the template $tpl->assign( 'msg', array( @@ -172,15 +169,13 @@ ) ); -/* - * Toolbar select - */ +// Toolbar select ?> - + assign('limit', $limit); $tpl->assign('searchMS', $search); -/* - * Apply a template definition - */ +// Apply a template definition $renderer = new HTML_QuickForm_Renderer_ArraySmarty($tpl); $form->accept($renderer); $tpl->assign('form', $renderer->toArray()); diff --git a/www/include/configuration/configObject/metaservice_dependency/listMetaServiceDependency.php b/www/include/configuration/configObject/metaservice_dependency/listMetaServiceDependency.php index cde9f62210c..3aa2ed7be51 100644 --- a/www/include/configuration/configObject/metaservice_dependency/listMetaServiceDependency.php +++ b/www/include/configuration/configObject/metaservice_dependency/listMetaServiceDependency.php @@ -1,7 +1,7 @@ user->admin) { $aclCond = " AND meta_service_meta_id IN ($metastr) "; } -$search = null; +$search = filter_var( + $_POST['searchMSD'] ?? $_GET['searchMSD'] ?? null, + FILTER_SANITIZE_STRING +); + if (isset($_POST['searchMSD'])) { - $search = $_POST['searchMSD']; - $centreon->historySearch[$url] = $search; -} elseif (isset($_GET['searchMSD'])) { - $search = $_GET['searchMSD']; - $centreon->historySearch[$url] = $search; -} elseif (isset($centreon->historySearch[$url])) { - $search = $centreon->historySearch[$url]; + $centreon->historySearch[$url] = array(); + $centreon->historySearch[$url]['search'] = $search; +} else { + $search = $centreon->historySearch[$url]['search'] ?? null; } -//Dependcy list +//Dependency list $rq = "SELECT SQL_CALC_FOUND_ROWS dep_id, dep_name, dep_description FROM dependency dep"; $rq .= " WHERE ((SELECT DISTINCT COUNT(*) FROM dependency_metaserviceParent_relation dmspr @@ -67,38 +68,39 @@ OR (SELECT DISTINCT COUNT(*) FROM dependency_metaserviceChild_relation dmspr WHERE dmspr.dependency_dep_id = dep.dep_id $aclCond) > 0)"; + if ($search) { $rq .= " AND (dep_name LIKE '%" . htmlentities($search, ENT_QUOTES, "UTF-8") . "%' OR dep_description LIKE '%" . htmlentities($search, ENT_QUOTES, "UTF-8") . "%')"; } $rq .= " ORDER BY dep_name, dep_description LIMIT " . $num * $limit . ", " . $limit; -$DBRESULT = $pearDB->query($rq); +$dbResult = $pearDB->query($rq); $rows = $pearDB->query("SELECT FOUND_ROWS()")->fetchColumn(); -include("./include/common/checkPagination.php"); +include "./include/common/checkPagination.php"; -# Smarty template Init +// Smarty template Init $tpl = new Smarty(); $tpl = initSmartyTpl($path, $tpl); /* Access level */ -($centreon->user->access->page($p) == 1) ? $lvl_access = 'w' : $lvl_access = 'r'; +$lvl_access = ($centreon->user->access->page($p) == 1) ? 'w' : 'r'; $tpl->assign('mode_access', $lvl_access); -# start header menu +// start header menu $tpl->assign("headerMenu_name", _("Name")); $tpl->assign("headerMenu_description", _("Description")); $tpl->assign("headerMenu_options", _("Options")); -# end header menu $search = tidySearchKey($search, $advanced_search); $form = new HTML_QuickFormCustom('select_form', 'POST', "?p=" . $p); -#Different style between each lines +//Different style between each lines $style = "one"; -#Fill a tab with a mutlidimensionnal Array we put in $tpl + +//Fill a tab with a multidimensional Array we put in $tpl $elemArr = array(); -for ($i = 0; $dep = $DBRESULT->fetchRow(); $i++) { +for ($i = 0; $dep = $dbResult->fetch(); $i++) { $moptions = ""; $selectedElements = $form->addElement('checkbox', "select[" . $dep['dep_id'] . "]"); $moptions .= " 31 && (event.keyCode < 45 || event.keyCode > 57)) " . @@ -116,24 +118,26 @@ $style != "two" ? $style = "two" : $style = "one"; } $tpl->assign("elemArr", $elemArr); -#Different messages we put in the template + +//Different messages we put in the template $tpl->assign( 'msg', - array("addL" => "main.php?p=" . $p . "&o=a", "addT" => _("Add"), "delConfirm" => _("Do you confirm the deletion ?")) + array( + "addL" => "main.php?p=" . $p . "&o=a", + "addT" => _("Add"), + "delConfirm" => _("Do you confirm the deletion ?") + ) ); +include "./include/common/checkPagination.php"; -include("./include/common/checkPagination.php"); - -# -##Toolbar select more_actions -# +//Toolbar select more_actions ?> - + "javascript: " . diff --git a/www/include/configuration/configObject/service/listService.ihtml b/www/include/configuration/configObject/service/listService.ihtml index 755027c32af..1770e4726b8 100644 --- a/www/include/configuration/configObject/service/listService.ihtml +++ b/www/include/configuration/configObject/service/listService.ihtml @@ -2,10 +2,10 @@