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 @@
- - - - - - - - - - - - - -
{t}Filters{/t}

{t}Command{/t}

+ + + + + + + + + + + + + +
{t}Filters{/t}

{t}Command{/t}

{if $mode_access=='w'} - + {else} - + {/if} {php} - include('./include/common/pagination.php'); + include('./include/common/pagination.php'); {/php}
- {$msg.options}{$form.o1.html}   {$msg.addT} - + {$msg.options}{$form.o1.html}   {$msg.addT} +   
- + {if $type == 2} - - + + {/if} @@ -65,30 +67,37 @@ {if $type == 2} - - + + {/if} - - + + {/section}
+ + {$headerMenu_name} {$headerMenu_desc} {$headerMenu_type}{$headerMenu_huse}{$headerMenu_suse}{$headerMenu_huse}{$headerMenu_suse}{t}Status{/t} {$headerMenu_options}{$elemArr[elem].RowMenu_desc} {$elemArr[elem].RowMenu_type}{$elemArr[elem].RowMenu_huse}{$elemArr[elem].RowMenu_suse}{$elemArr[elem].RowMenu_huse}{$elemArr[elem].RowMenu_suse}{$elemArr[elem].RowMenu_status}{if $mode_access == 'w'}{$elemArr[elem].RowMenu_options}{else} {/if} + {$elemArr[elem].RowMenu_status} + + {if $mode_access == 'w'} + {$elemArr[elem].RowMenu_options} + {else}  + {/if} +
{if $mode_access == 'w'} - + {else} - + {/if} {php} - include('./include/common/pagination.php'); + include('./include/common/pagination.php'); {/php}
- {$msg.options}{$form.o2.html}   {$msg.addT} - + {$msg.options}{$form.o2.html}   {$msg.addT} +   
- -{$form.hidden} + + {$form.hidden}
\ 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 @@
- - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + +
{t}Filters{/t}

{$Hosts}

{$Hostgroup}

{$Poller}

{$Template}

{$headerMenu_status}

{t}Filters{/t}

{$Hosts}

{$Hostgroup}

{$Poller}

{$Template}

{$headerMenu_status}

{ if $mode_access == 'w' } - - { else } - + + { else } + { /if } {php} - include('./include/common/pagination.php'); + include('./include/common/pagination.php'); {/php}
- {$msg.options} {$form.o1.html}{$msg.addT} -   + {$msg.options} {$form.o1.html}{$msg.addT} +  
@@ -62,36 +62,43 @@ {/if} {$elemArr[elem].RowMenu_select} - - {if $elemArr[elem].pattern}{/if} -
{$elemArr[elem].RowMenu_name} + {if $elemArr[elem].pattern}{/if} + + {$elemArr[elem].RowMenu_name} + - - - + + + + + + {$elemArr[elem].RowMenu_desc} - {$elemArr[elem].RowMenu_desc} {$elemArr[elem].RowMenu_address} {$elemArr[elem].RowMenu_poller} {$elemArr[elem].RowMenu_parent} - {$elemArr[elem].RowMenu_status} - {if $mode_access == 'w' }{$elemArr[elem].RowMenu_options}{else} {/if} + + {$elemArr[elem].RowMenu_status} + + + {if $mode_access == 'w' }{$elemArr[elem].RowMenu_options}{else} {/if} + {/section} { if $mode_access == 'w' } - - { else } - + + { else } + { /if } {php} - include('./include/common/pagination.php'); + include('./include/common/pagination.php'); {/php}
- {$msg.options} {$form.o2.html}{$msg.addT} -   + {$msg.options} {$form.o2.html}{$msg.addT} +  
@@ -101,7 +108,7 @@
{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 .= "" . _("Disabled") . "  "; + "&num=" . $num . "&search=" . $search . "'>" . _("Disabled") . "  "; } else { $moptions .= "" . _("Enabled") . "  "; + "&num=" . $num . "&search=" . $search . "'>" . _("Enabled") . "  "; } $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 @@
- - - + + @@ -16,7 +16,6 @@ {/if} - @@ -29,7 +28,7 @@ {if (! isset($hostgroupsFilter))} - + {/if} @@ -38,11 +37,11 @@
-
{t}Filters{/t}
+
+
{t}Filters{/t}

{$Services}

{$ServiceTemplates}

{$ServiceStatus}

{$HostStatus}

{$HostStatus}

{if $mode_access == 'w'} - + {else} - + {/if} {php} @@ -52,7 +51,9 @@
- {$msg.options} {$form.o1.html}{$msg.addT} - + {$msg.options} {$form.o1.html}{$msg.addT} +   
- + @@ -61,34 +62,41 @@ {section name=elem loop=$elemArr} - - - - - - - - - + + + + + + + + + {/section}
+ + {$headerMenu_name} {$headerMenu_desc} {$headerMenu_retry}{$headerMenu_options}
{$elemArr[elem].RowMenu_select} - {if $elemArr[elem].RowMenu_name != "" && $elemArr[elem].RowMenu_icone != ""} - - {/if} - {$elemArr[elem].RowMenu_name} - - {if $elemArr[elem].RowMenu_sicon != ""} - {/if}{$elemArr[elem].RowMenu_desc} - {$elemArr[elem].RowMenu_retry}{$elemArr[elem].RowMenu_parent}{$elemArr[elem].RowMenu_status}{if $mode_access == 'w' }{$elemArr[elem].RowMenu_options}{else} {/if}
{$elemArr[elem].RowMenu_select} + {if $elemArr[elem].RowMenu_name != "" && $elemArr[elem].RowMenu_icone != ""} + + {/if} + {$elemArr[elem].RowMenu_name} + + + {if $elemArr[elem].RowMenu_sicon != ""} + + {/if}{$elemArr[elem].RowMenu_desc} + + {$elemArr[elem].RowMenu_retry}{$elemArr[elem].RowMenu_parent} + {$elemArr[elem].RowMenu_status} + + {if $mode_access == 'w' }{$elemArr[elem].RowMenu_options}{else} {/if} +
{if $mode_access == 'w'} - + {else} - + {/if} {php} @@ -96,9 +104,9 @@ {/php}
- {$msg.options} {$form.o2.html} - {$msg.addT} - + {$msg.options} {$form.o2.html} + {$msg.addT} +   
- - -{$form.hidden} + + + {$form.hidden}
{literal} + "javascript: " . @@ -425,24 +396,29 @@ 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"), - "dv" => _("Detach") - ), $attrs1); + $form->addElement( + 'select', + $option, + null, + array( + null => _("More actions..."), + "m" => _("Duplicate"), + "d" => _("Delete"), + "mc" => _("Massive Change"), + "ms" => _("Enable"), + "mu" => _("Disable"), + "dv" => _("Detach") + ), + $attrs1 + ); + $o1 = $form->getElement($option); $o1->setValue(null); } $tpl->assign('limit', $limit); -/* - * Apply a template definition - */ +// Apply a template definition if (isset($searchH) && $searchH) { $searchH = html_entity_decode($searchH); $searchH = stripslashes(str_replace('"', """, $searchH)); diff --git a/www/include/configuration/configObject/service/listServiceByHostGroup.php b/www/include/configuration/configObject/service/listServiceByHostGroup.php index 3a799b6ee1c..0f5bcb4ca44 100644 --- a/www/include/configuration/configObject/service/listServiceByHostGroup.php +++ b/www/include/configuration/configObject/service/listServiceByHostGroup.php @@ -1,7 +1,7 @@ historySearch[$url] = array(); - $searchHG = $_POST['hostgroups']; $centreon->historySearch[$url]["hostgroups"] = $searchHG; - $searchS = $_POST["searchS"]; - $centreon->historySearch[$url]["searchS"] = $searchS; - $template = $_POST["template"]; - $centreon->historySearch[$url]["template"] = $template; - $status = $_POST["status"]; - $centreon->historySearch[$url]["status"] = $status; -} elseif (isset($_GET['Search'])) { - $centreon->historySearch[$url] = array(); - $searchHG = $_GET['hostgroups']; - $centreon->historySearch[$url]['hostgroups'] = $searchHG; - $searchS = $_GET["searchS"]; - $centreon->historySearch[$url]["searchS"] = $searchS; - $template = $_GET["template"]; + $centreon->historySearch[$url]["search"] = $searchS; $centreon->historySearch[$url]["template"] = $template; - $status = $_GET["status"]; $centreon->historySearch[$url]["status"] = $status; } else { - if (isset($centreon->historySearch[$url]['hostgroups'])) { - $searchHG = $centreon->historySearch[$url]['hostgroups']; - } - if (isset($centreon->historySearch[$url]["searchS"])) { - $searchS = $centreon->historySearch[$url]["searchS"]; - } - if (isset($centreon->historySearch[$url]["template"])) { - $template = $centreon->historySearch[$url]["template"]; - } - if (isset($centreon->historySearch[$url]["status"])) { - $status = $centreon->historySearch[$url]["status"]; - } + //restoring saved values + $searchHG = $centreon->historySearch[$url]['hostgroups'] ?? null; + $searchS = $centreon->historySearch[$url]["search"] ?? null; + $template = $centreon->historySearch[$url]["template"] ?? null; + $status = $centreon->historySearch[$url]["status"] ?? -1; } /* @@ -86,15 +81,16 @@ */ $tplService = array(); $templateFilter = ""; -$query = "SELECT service_id, service_description, service_alias FROM service " . - "WHERE service_register = '0' AND service_activate = '1' ORDER BY service_description"; -$DBRESULT = $pearDB->query($query); -while ($tpl = $DBRESULT->fetchRow()) { +$dbResult = $pearDB->query( + "SELECT service_id, service_description, service_alias FROM service " . + "WHERE service_register = '0' AND service_activate = '1' ORDER BY service_description" +); +while ($tpl = $dbResult->fetch()) { $tplService[$tpl["service_id"]] = $tpl["service_alias"]; $templateFilter .= ""; } -$DBRESULT->closeCursor(); +$dbResult->closeCursor(); //Status Filter $statusFilter = ""; @@ -109,7 +105,7 @@ $sqlFilterCase = " AND sv.service_activate = '0' "; } -include("./include/common/autoNumLimit.php"); +include "./include/common/autoNumLimit.php"; $rows = 0; $tmp = null; @@ -118,11 +114,11 @@ $searchS = $pearDB->escape($searchS); $aclfrom = ""; -$aclcond = ""; +$aclCond = ""; $distinct = ""; if (!$centreon->user->admin) { $aclfrom = ", $acldbname.centreon_acl acl "; - $aclcond = " AND sv.service_id = acl.service_id + $aclCond = " AND sv.service_id = acl.service_id AND acl.group_id IN (" . $acl->getAccessGroupsString() . ") "; $distinct = " DISTINCT "; } @@ -131,17 +127,21 @@ * Due to Description maybe in the Template definition, we have to search if the description * could match for each service with a Template. */ + +$templateStr = isset($template) && $template ? " AND service_template_model_stm_id = '" . $template . "' " : ""; + if ($searchS != "" || $searchHG != "") { if ($searchS && !$searchHG) { - $DBRESULT = $pearDB->query("SELECT $distinct hostgroup_hg_id, sv.service_id, sv.service_description, " . + $dbResult = $pearDB->query( + "SELECT " . $distinct . " hostgroup_hg_id, sv.service_id, sv.service_description, " . "service_template_model_stm_id " . - "FROM service sv, host_service_relation hsr $aclfrom" . - "WHERE sv.service_register = '1' $sqlFilterCase " . - " AND hsr.service_service_id = sv.service_id " . $aclcond . - " AND hsr.host_host_id IS NULL " . - " AND (sv.service_description LIKE '%$searchS%')" . - ((isset($template) && $template) ? " AND service_template_model_stm_id = '$template' " : "")); - while ($service = $DBRESULT->fetchRow()) { + "FROM service sv, host_service_relation hsr " . $aclfrom . + " WHERE sv.service_register = '1' " . $sqlFilterCase . + " AND hsr.service_service_id = sv.service_id " . $aclCond . + " AND hsr.host_host_id IS NULL" . + " AND (sv.service_description LIKE '%" . $searchS . "%')" . $templateStr + ); + while ($service = $dbResult->fetch()) { if (!isset($tab_buffer[$service["service_id"]])) { $tmp ? $tmp .= ", " . $service["service_id"] : $tmp = $service["service_id"]; } @@ -150,44 +150,46 @@ $rows++; } } elseif (!$searchS && $searchHG) { - $DBRESULT = $pearDB->query("SELECT $distinct hostgroup_hg_id, sv.service_id, sv.service_description, " . + $dbResult = $pearDB->query( + "SELECT " . $distinct . " hostgroup_hg_id, sv.service_id, sv.service_description, " . "service_template_model_stm_id " . - "FROM service sv, host_service_relation hsr, hostgroup hg $aclfrom" . - "WHERE sv.service_register = '1' $sqlFilterCase " . - " AND hsr.service_service_id = sv.service_id " . $aclcond . - " AND hsr.host_host_id IS NULL " . - " AND (hg.hg_name LIKE '%$searchHG%')" . - " AND hsr.hostgroup_hg_id = hg.hg_id" . - ((isset($template) && $template) ? " AND service_template_model_stm_id = '$template' " : "")); - while ($service = $DBRESULT->fetchRow()) { + "FROM service sv, host_service_relation hsr, hostgroup hg " . $aclfrom . + "WHERE sv.service_register = '1' " . $sqlFilterCase . + " AND hsr.service_service_id = sv.service_id " . $aclCond . + " AND hsr.host_host_id IS NULL " . + " AND (hg.hg_name LIKE '%" . $searchHG . "%')" . + " AND hsr.hostgroup_hg_id = hg.hg_id" . $templateStr + ); + while ($service = $dbResult->fetch()) { $tmp ? $tmp .= ", " . $service["service_id"] : $tmp = $service["service_id"]; $tmp2 ? $tmp2 .= ", " . $service["hostgroup_hg_id"] : $tmp2 = $service["hostgroup_hg_id"]; $rows++; } } else { - $DBRESULT = $pearDB->query("SELECT $distinct hostgroup_hg_id, sv.service_id, sv.service_description, " . + $dbResult = $pearDB->query( + "SELECT " . $distinct . " hostgroup_hg_id, sv.service_id, sv.service_description, " . "service_template_model_stm_id " . - "FROM service sv, host_service_relation hsr, hostgroup hg $aclfrom" . - "WHERE sv.service_register = '1' $sqlFilterCase " . - " AND hsr.service_service_id = sv.service_id " . $aclcond . - " AND hsr.host_host_id IS NULL " . - " AND hg.hg_name LIKE '%$searchHG%'" . - " AND sv.service_description LIKE '%$searchS%'" . - " AND hsr.hostgroup_hg_id = hg.hg_id" . - ((isset($template) && $template) ? " AND service_template_model_stm_id = '$template' " : "")); - while ($service = $DBRESULT->fetchRow()) { + "FROM service sv, host_service_relation hsr, hostgroup hg " . $aclfrom . + "WHERE sv.service_register = '1' " . $sqlFilterCase . + " AND hsr.service_service_id = sv.service_id " . $aclCond . + " AND hsr.host_host_id IS NULL " . + " AND hg.hg_name LIKE '%" . $searchHG . "%'" . + " AND sv.service_description LIKE '%" . $searchS . "%'" . + " AND hsr.hostgroup_hg_id = hg.hg_id" . $templateStr + ); + while ($service = $dbResult->fetch()) { $tmp ? $tmp .= ", " . $service["service_id"] : $tmp = $service["service_id"]; $tmp2 ? $tmp2 .= ", " . $service["hostgroup_hg_id"] : $tmp2 = $service["hostgroup_hg_id"]; $rows++; } } } else { - $query = "SELECT $distinct sv.service_description FROM service sv, host_service_relation hsr $aclfrom " . - "WHERE service_register = '1' $sqlFilterCase " . - ((isset($template) && $template) ? " AND service_template_model_stm_id = '$template' " : "") . - " AND hsr.service_service_id = sv.service_id AND hsr.host_host_id IS NULL $aclcond"; - $DBRESULT = $pearDB->query($query); - $rows = $DBRESULT->rowCount(); + $dbResult = $pearDB->query( + "SELECT " . $distinct . " sv.service_description FROM service sv, host_service_relation hsr " . $aclfrom . + "WHERE service_register = '1' " . $sqlFilterCase . $templateStr . + " AND hsr.service_service_id = sv.service_id AND hsr.host_host_id IS NULL " . $aclCond + ); + $rows = $dbResult->rowCount(); } /* @@ -196,11 +198,14 @@ $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); -include("./include/common/checkPagination.php"); +include "./include/common/checkPagination.php"; /* * start header menu @@ -223,7 +228,7 @@ "WHERE sv.service_register = '1' $sqlFilterCase AND sv.service_id IN (" . ($tmp ? $tmp : 'NULL') . ") AND hsr.hostgroup_hg_id IN (" . ($tmp2 ? $tmp2 : 'NULL') . ") " . ((isset($template) && $template) ? " AND service_template_model_stm_id = '$template' " : "") . - " AND hsr.service_service_id = sv.service_id AND hg.hg_id = hsr.hostgroup_hg_id $aclcond " . + " AND hsr.service_service_id = sv.service_id AND hg.hg_id = hsr.hostgroup_hg_id " . $aclCond . "ORDER BY hg.hg_name, sv.service_description LIMIT " . $num * $limit . ", " . $limit; } else { $query = "SELECT $distinct @nbr:=(SELECT COUNT(*) FROM host_service_relation " . @@ -232,28 +237,24 @@ "FROM service sv, hostgroup hg, host_service_relation hsr $aclfrom " . "WHERE sv.service_register = '1' $sqlFilterCase " . ((isset($template) && $template) ? " AND service_template_model_stm_id = '$template' " : "") . - " AND hsr.service_service_id = sv.service_id AND hg.hg_id = hsr.hostgroup_hg_id $aclcond " . + " AND hsr.service_service_id = sv.service_id AND hg.hg_id = hsr.hostgroup_hg_id " . $aclCond . "ORDER BY hg.hg_name, sv.service_description LIMIT " . $num * $limit . ", " . $limit; } -$DBRESULT = $pearDB->query($query); +$dbResult = $pearDB->query($query); $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 $interval_length = $centreon->optGen['interval_length']; $elemArr = array(); $fgHostgroup = array("value" => null, "print" => null); -for ($i = 0; $service = $DBRESULT->fetchRow(); $i++) { +for ($i = 0; $service = $dbResult->fetch(); $i++) { $moptions = ""; $fgHostgroup["value"] != $service["hg_name"] ? ($fgHostgroup["print"] = true && $fgHostgroup["value"] = $service["hg_name"]) @@ -262,11 +263,11 @@ if ($service["service_activate"]) { $moptions .= "" . _("Disabled") . ""; } else { $moptions .= "" . _("Enabled") . ""; } $moptions .= " "; @@ -295,10 +296,12 @@ if (isset($service['esi_icon_image']) && $service['esi_icon_image']) { $svc_icon = "./img/media/" . $mediaObj->getFilename($service['esi_icon_image']); - } elseif ($icone = $mediaObj->getFilename(getMyServiceExtendedInfoField( - $service["service_id"], - "esi_icon_image" - )) + } elseif ($icone = $mediaObj->getFilename( + getMyServiceExtendedInfoField( + $service["service_id"], + "esi_icon_image" + ) + ) ) { $svc_icon = "./img/media/" . $icone; } else { @@ -306,10 +309,10 @@ } //Get service intervals in seconds - $normal_check_interval = - getMyServiceField($service['service_id'], "service_normal_check_interval") * $interval_length; - $retry_check_interval = - getMyServiceField($service['service_id'], "service_retry_check_interval") * $interval_length; + $normal_check_interval + = getMyServiceField($service['service_id'], "service_normal_check_interval") * $interval_length; + $retry_check_interval + = getMyServiceField($service['service_id'], "service_retry_check_interval") * $interval_length; if ($normal_check_interval % 60 == 0) { $normal_units = "min"; @@ -335,10 +338,12 @@ "RowMenu_sicon" => $svc_icon, "RowMenu_retry" => CentreonUtils::escapeSecure("$normal_check_interval $normal_units / $retry_check_interval $retry_units"), - "RowMenu_attempts" => CentreonUtils::escapeSecure(getMyServiceField( - $service['service_id'], - "service_max_check_attempts" - )), + "RowMenu_attempts" => CentreonUtils::escapeSecure( + getMyServiceField( + $service['service_id'], + "service_max_check_attempts" + ) + ), "RowMenu_desc" => CentreonUtils::escapeSecure($service["service_description"]), "RowMenu_status" => $service["service_activate"] ? _("Enabled") : _("Disabled"), "RowMenu_badge" => $service["service_activate"] ? "service_ok" : "service_critical", @@ -350,9 +355,7 @@ } $tpl->assign("elemArr", $elemArr); -/* - * Different messages we put in the template - */ +// Different messages we put in the template $tpl->assign( 'msg', array( @@ -362,15 +365,13 @@ ) ); -/* - * Toolbar select - */ +// Toolbar select ?> - + "javascript: " . @@ -394,16 +395,22 @@ function setO(_i) { " setO(this.form.elements['o1'].value); submit();} " . "this.form.elements['o1'].selectedIndex = 0" ); -$form->addElement('select', 'o1', null, array( - null => _("More actions..."), - "m" => _("Duplicate"), - "d" => _("Delete"), - "mc" => _("Massive Change"), - "ms" => _("Enable"), - "mu" => _("Disable"), - "dv" => _("Detach host group services"), - "mvH" => _("Move host group's services to hosts") -), $attrs1); +$form->addElement( + 'select', + 'o1', + null, + array( + null => _("More actions..."), + "m" => _("Duplicate"), + "d" => _("Delete"), + "mc" => _("Massive Change"), + "ms" => _("Enable"), + "mu" => _("Disable"), + "dv" => _("Detach host group services"), + "mvH" => _("Move host group's services to hosts") + ), + $attrs1 +); $attrs2 = array( 'onchange' => "javascript: " . @@ -427,16 +434,22 @@ function setO(_i) { " setO(this.form.elements['o2'].value); submit();} " . "this.form.elements['o2'].selectedIndex = 0" ); -$form->addElement('select', 'o2', null, array( - null => _("More actions..."), - "m" => _("Duplicate"), - "d" => _("Delete"), - "mc" => _("Massive Change"), - "ms" => _("Enable"), - "mu" => _("Disable"), - "dv" => _("Detach host group services"), - "mvH" => _("Move host group's services to hosts") -), $attrs2); +$form->addElement( + 'select', + 'o2', + null, + array( + null => _("More actions..."), + "m" => _("Duplicate"), + "d" => _("Delete"), + "mc" => _("Massive Change"), + "ms" => _("Enable"), + "mu" => _("Disable"), + "dv" => _("Detach host group services"), + "mvH" => _("Move host group's services to hosts") + ), + $attrs2 +); $o1 = $form->getElement('o1'); $o1->setValue(null); @@ -459,9 +472,7 @@ function setO(_i) { $tpl->assign("templateFilter", $templateFilter); $tpl->assign("statusFilter", $statusFilter); -/* - * 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/service_categories/listServiceCategories.php b/www/include/configuration/configObject/service_categories/listServiceCategories.php index 3c2a03812b6..e20fd3a4726 100644 --- a/www/include/configuration/configObject/service_categories/listServiceCategories.php +++ b/www/include/configuration/configObject/service_categories/listServiceCategories.php @@ -1,7 +1,7 @@ historySearch[$url] = $search; -} elseif (isset($_GET['searchSC'])) { - $search = $_GET['searchSC']; - $centreon->historySearch[$url] = $search; -} elseif (isset($centreon->historySearch[$url])) { - $search = $centreon->historySearch[$url]; +if (isset($_POST['searchSC']) || isset($_GET['searchSC'])) { + //initializing filters values + $centreon->historySearch[$url] = array(); + $centreon->historySearch[$url]["search"] = $search; +} else { + //restoring saved values + $search = $centreon->historySearch[$url]["search"] ?? null; } +$searchTool = ''; if ($search) { - $SearchTool .= "WHERE (sc_name LIKE '%" . htmlentities($search, ENT_QUOTES, "UTF-8") . - "%' OR sc_description LIKE '%" . htmlentities($search, ENT_QUOTES, "UTF-8") . "%')"; + $searchTool .= "WHERE (sc_name LIKE '%" . $search . "%' ". + "OR sc_description LIKE '%" . $search . "%') "; } $aclCond = ""; if (!$oreon->user->admin && $scString != "''") { - if (is_null($SearchTool)) { + if (is_null($searchTool)) { $clause = " WHERE "; } else { $clause = " AND "; @@ -73,21 +75,20 @@ /* * Services Categories Lists */ -$query = "SELECT SQL_CALC_FOUND_ROWS * FROM service_categories $SearchTool $aclCond " . - "ORDER BY sc_name LIMIT " . $num * $limit . ", " . $limit; -$DBRESULT = $pearDB->query($query); - +$dbResult = $pearDB->query( + "SELECT SQL_CALC_FOUND_ROWS * FROM service_categories " . $searchTool . $aclCond . + "ORDER BY sc_name LIMIT " . $num * $limit . ", " . $limit +); $rows = $pearDB->query("SELECT FOUND_ROWS()")->fetchColumn(); -include("./include/common/checkPagination.php"); -/* - * Smarty template Init - */ +include "./include/common/checkPagination.php"; + +// 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); /* @@ -104,31 +105,28 @@ $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; $sc = $DBRESULT->fetchRow(); $i++) { +for ($i = 0; $sc = $dbResult->fetch(); $i++) { $moptions = ""; - $query = "SELECT COUNT(*) FROM `service_categories_relation` WHERE `sc_id` = '" . $sc['sc_id'] . "'"; - $DBRESULT2 = $pearDB->query($query); - $nb_svc = $DBRESULT2->fetchRow(); + $dbResult2 = $pearDB->query( + "SELECT COUNT(*) FROM `service_categories_relation` WHERE `sc_id` = '" . $sc['sc_id'] . "'" + ); + $nb_svc = $dbResult2->fetch(); $selectedElements = $form->addElement('checkbox', "select[" . $sc['sc_id'] . "]"); if ($sc["sc_activate"]) { $moptions .= "" . _("Disabled") . "  "; + "&num=" . $num . "&search=" . $search . "'>" . _("Disabled") . "  "; } else { $moptions .= "" . _("Enabled") . "  "; + "&num=" . $num . "&search=" . $search . "'>" . _("Enabled") . "  "; } $moptions .= " "; $moptions .= " 31 && (event.keyCode < 45 || event.keyCode > 57)) " . @@ -152,17 +150,15 @@ } $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"))); ?> - + "javascript: " . @@ -180,14 +176,20 @@ function setO(_i) { " setO(this.form.elements['o1'].value); submit();} " . "this.form.elements['o1'].selectedIndex = 0" ); -$form->addElement('select', 'o1', null, array( - null => _("More actions..."), - "m" => _("Duplicate"), - "d" => _("Delete"), - "mc" => _("Massive Change"), - "ms" => _("Enable"), - "mu" => _("Disable") -), $attrs1); +$form->addElement( + 'select', + 'o1', + null, + array( + null => _("More actions..."), + "m" => _("Duplicate"), + "d" => _("Delete"), + "mc" => _("Massive Change"), + "ms" => _("Enable"), + "mu" => _("Disable") + ), + $attrs1 +); $form->setDefaults(array('o1' => null)); $attrs2 = array( @@ -206,14 +208,20 @@ function setO(_i) { " setO(this.form.elements['o2'].value); submit();} " . "this.form.elements['o2'].selectedIndex = 0" ); -$form->addElement('select', 'o2', null, array( - null => _("More actions"), - "m" => _("Duplicate"), - "d" => _("Delete"), - "mc" => _("Massive Change"), - "ms" => _("Enable"), - "mu" => _("Disable") -), $attrs2); +$form->addElement( + 'select', + 'o2', + null, + array( + null => _("More actions"), + "m" => _("Duplicate"), + "d" => _("Delete"), + "mc" => _("Massive Change"), + "ms" => _("Enable"), + "mu" => _("Disable") + ), + $attrs2 +); $form->setDefaults(array('o2' => null)); $o1 = $form->getElement('o1'); @@ -227,9 +235,7 @@ function setO(_i) { $tpl->assign('limit', $limit); $tpl->assign('searchSC', $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/service_template_model/listServiceTemplateModel.php b/www/include/configuration/configObject/service_template_model/listServiceTemplateModel.php index 9092d49eaf7..342f7455209 100644 --- a/www/include/configuration/configObject/service_template_model/listServiceTemplateModel.php +++ b/www/include/configuration/configObject/service_template_model/listServiceTemplateModel.php @@ -1,7 +1,7 @@ historySearch[$url] = $search; -} elseif (isset($_GET['searchST'])) { - $search = $_GET['searchST']; - $search = str_replace('/', "#S#", $search); - $search = str_replace('\\', "#BS#", $search); - $centreon->historySearch[$url] = $search; -} elseif (isset($centreon->historySearch[$url])) { - $search = $centreon->historySearch[$url]; +$search = filter_var( + $_POST['searchST'] ?? $_GET['searchST'] ?? null, + FILTER_SANITIZE_STRING +); + +if (isset($_POST['searchST']) || isset($_GET['searchST'])) { + //initializing filters values + $centreon->historySearch[$url] = array(); + $centreon->historySearch[$url]["search"] = $search; +} else { + //restoring saved values + $search = $centreon->historySearch[$url]["search"] ?? null; } //Service Template Model list if ($search) { $query = "SELECT SQL_CALC_FOUND_ROWS sv.service_id, sv.service_description, sv.service_alias, " . - "sv.service_activate, sv.service_template_model_stm_id FROM service sv WHERE (sv.service_description LIKE '%" . - htmlentities($search, ENT_QUOTES, "UTF-8") . "%' OR sv.service_alias LIKE '%" . - htmlentities($search, ENT_QUOTES, "UTF-8") . "%') AND sv.service_register = '0' " . + "sv.service_activate, sv.service_template_model_stm_id " . + "FROM service sv " . + "WHERE (sv.service_description LIKE '%" . $search . "%' OR sv.service_alias LIKE '%" . $search . "%') " . + "AND sv.service_register = '0' " . "ORDER BY service_description LIMIT " . $num * $limit . ", " . $limit; } else { $query = "SELECT SQL_CALC_FOUND_ROWS sv.service_id, sv.service_description, sv.service_alias, " . - "sv.service_activate, sv.service_template_model_stm_id FROM service sv WHERE sv.service_register = '0' " . + "sv.service_activate, sv.service_template_model_stm_id " . + "FROM service sv " . + "WHERE sv.service_register = '0' " . "ORDER BY service_description LIMIT " . $num * $limit . ", " . $limit; } -$DBRESULT = $pearDB->query($query); +$dbResult = $pearDB->query($query); $rows = $pearDB->query("SELECT FOUND_ROWS()")->fetchColumn(); -include("./include/common/checkPagination.php"); +include "./include/common/checkPagination.php"; /* * Smarty template Init @@ -86,13 +88,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_desc", _("Name")); $tpl->assign("headerMenu_alias", _("Alias")); $tpl->assign("headerMenu_retry", _("Scheduling")); @@ -103,14 +103,10 @@ $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(); $interval_length = $oreon->optGen['interval_length']; @@ -118,7 +114,7 @@ $search = str_replace('#S#', "/", $search); $search = str_replace('#BS#', "\\", $search); -for ($i = 0; $service = $DBRESULT->fetchRow(); $i++) { +for ($i = 0; $service = $dbResult->fetch(); $i++) { $moptions = ""; $selectedElements = $form->addElement('checkbox', "select[" . $service['service_id'] . "]"); if (isset($lockedElements[$service['service_id']])) { @@ -171,11 +167,11 @@ $service["service_alias"] = str_replace("#S#", '/', $service["service_alias"]); $service["service_alias"] = str_replace("#BS#", '\\', $service["service_alias"]); - # Get service intervals in seconds - $normal_check_interval = - getMyServiceField($service['service_id'], "service_normal_check_interval") * $interval_length; - $retry_check_interval = - getMyServiceField($service['service_id'], "service_retry_check_interval") * $interval_length; + // Get service intervals in seconds + $normal_check_interval + = getMyServiceField($service['service_id'], "service_normal_check_interval") * $interval_length; + $retry_check_interval + = getMyServiceField($service['service_id'], "service_retry_check_interval") * $interval_length; if ($normal_check_interval % 60 == 0) { $normal_units = "min"; @@ -198,7 +194,8 @@ $service["service_id"], "esi_icon_image" ) - )) { + ) + ) { $svc_icon = "./img/media/" . $icone; } else { $svc_icon = "./img/icons/service.png"; @@ -224,23 +221,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 lgd_more_actions - */ +// Toolbar select lgd_more_actions ?> + "javascript: " . @@ -258,14 +255,20 @@ function setO(_i) { " setO(this.form.elements['o1'].value); submit();} " . "this.form.elements['o1'].selectedIndex = 0" ); -$form->addElement('select', 'o1', null, array( - null => _("More actions..."), - "m" => _("Duplicate"), - "d" => _("Delete"), - "mc" => _("Massive Change"), - "ms" => _("Enable"), - "mu" => _("Disable") -), $attrs1); +$form->addElement( + 'select', + 'o1', + null, + array( + null => _("More actions..."), + "m" => _("Duplicate"), + "d" => _("Delete"), + "mc" => _("Massive Change"), + "ms" => _("Enable"), + "mu" => _("Disable") + ), + $attrs1 +); $form->setDefaults(array('o1' => null)); $attrs2 = array( @@ -284,14 +287,20 @@ function setO(_i) { " setO(this.form.elements['o2'].value); submit();} " . "this.form.elements['o1'].selectedIndex = 0" ); -$form->addElement('select', 'o2', null, array( - null => _("More actions..."), - "m" => _("Duplicate"), - "d" => _("Delete"), - "mc" => _("Massive Change"), - "ms" => _("Enable"), - "mu" => _("Disable") -), $attrs2); +$form->addElement( + 'select', + 'o2', + null, + array( + null => _("More actions..."), + "m" => _("Duplicate"), + "d" => _("Delete"), + "mc" => _("Massive Change"), + "ms" => _("Enable"), + "mu" => _("Disable") + ), + $attrs2 +); $form->setDefaults(array('o2' => null)); $o1 = $form->getElement('o1'); @@ -305,9 +314,7 @@ function setO(_i) { $tpl->assign('limit', $limit); $tpl->assign('searchST', $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/servicegroup/listServiceGroup.php b/www/include/configuration/configObject/servicegroup/listServiceGroup.php index 02934923089..aead16c8017 100644 --- a/www/include/configuration/configObject/servicegroup/listServiceGroup.php +++ b/www/include/configuration/configObject/servicegroup/listServiceGroup.php @@ -1,7 +1,7 @@ historySearch[$url] = $search; -} elseif (isset($_GET['searchSG'])) { - $search = $_GET['searchSG']; - $centreon->historySearch[$url] = $search; -} elseif (isset($centreon->historySearch[$url])) { - $search = $centreon->historySearch[$url]; +if (isset($_POST['searchSG']) || isset($_GET['searchSG'])) { + //initializing filters values + $centreon->historySearch[$url] = array(); + $centreon->historySearch[$url]["search"] = $search; +} else { + //restoring saved values + $search = $centreon->historySearch[$url]["search"] ?? null; } if ($search) { $rq = "SELECT SQL_CALC_FOUND_ROWS sg_id, sg_name, sg_alias, sg_activate FROM servicegroup " . - "WHERE (sg_name LIKE '%" . htmlentities($search, ENT_QUOTES, "UTF-8") . - "%' OR sg_alias LIKE '%" . htmlentities($search, ENT_QUOTES, "UTF-8") . "%') " . + "WHERE (sg_name LIKE '%" . $search . "%' " . + "OR sg_alias LIKE '%" . $search . "%') " . $acl->queryBuilder('AND', 'sg_id', $sgString) . - " ORDER BY sg_name - LIMIT " . $num * $limit . ", " . $limit; + " ORDER BY sg_name LIMIT " . $num * $limit . ", " . $limit; } else { $rq = "SELECT SQL_CALC_FOUND_ROWS sg_id, sg_name, sg_alias, sg_activate FROM servicegroup " . $acl->queryBuilder('WHERE', 'sg_id', $sgString) . " ORDER BY sg_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); $tpl->assign("headerMenu_name", _("Name")); @@ -89,26 +88,22 @@ $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; $sg = $DBRESULT->fetchRow(); $i++) { +for ($i = 0; $sg = $dbResult->fetch(); $i++) { $selectedElements = $form->addElement('checkbox', "select[" . $sg['sg_id'] . "]"); $moptions = ""; if ($sg["sg_activate"]) { $moptions .= "" . _("Disabled") . ""; + "&num=" . $num . "&search=" . $search . "'>" . _("Disabled") . ""; } else { $moptions .= "" . _("Enabled") . ""; + "&num=" . $num . "&search=" . $search . "'>" . _("Enabled") . ""; } $moptions .= "  31 && (event.keyCode < 45 || event.keyCode > 57)) " . "event.returnValue = false; if(event.which > 31 && (event.which < 45 || event.which > 57)) return false;\" " . @@ -128,23 +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 select - */ +// Toolbar select ?> - + "javascript: " . @@ -199,9 +194,7 @@ function setO(_i) { $tpl->assign('limit', $limit); $tpl->assign('searchSG', $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/servicegroup_dependency/listServiceGroupDependency.php b/www/include/configuration/configObject/servicegroup_dependency/listServiceGroupDependency.php index be697cfc247..430b5239bf8 100644 --- a/www/include/configuration/configObject/servicegroup_dependency/listServiceGroupDependency.php +++ b/www/include/configuration/configObject/servicegroup_dependency/listServiceGroupDependency.php @@ -1,7 +1,7 @@ user->admin) { $aclCond = " AND servicegroup_sg_id IN ($sgstring) "; } -$search = null; +$search = filter_var( + $_POST['searchSGD'] ?? $_GET['searchSGD'] ?? null, + FILTER_SANITIZE_STRING +); if (isset($_POST['searchSGD'])) { - $search = $_POST['searchSGD']; - $centreon->historySearch[$url] = $search; -} elseif (isset($_GET['searchSGD'])) { - $search = $_GET['searchSGD']; - $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 +//Dependencies list $rq = "SELECT SQL_CALC_FOUND_ROWS dep_id, dep_name, dep_description FROM dependency dep"; $rq .= " WHERE ((SELECT DISTINCT COUNT(*) FROM dependency_servicegroupParent_relation dsgpr - WHERE dsgpr.dependency_dep_id = dep.dep_id $aclCond) > 0 + WHERE dsgpr.dependency_dep_id = dep.dep_id " . $aclCond . ") > 0 OR (SELECT DISTINCT COUNT(*) FROM dependency_servicegroupChild_relation dsgpr - WHERE dsgpr.dependency_dep_id = dep.dep_id $aclCond) > 0)"; + WHERE dsgpr.dependency_dep_id = dep.dep_id " . $aclCond . ") > 0)"; //Search Case 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'; +// 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_description", _("Description")); $tpl->assign("headerMenu_options", _("Options")); @@ -99,16 +95,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)) " . @@ -126,24 +118,19 @@ } $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 ?> - + "javascript: " . @@ -204,9 +191,7 @@ function setO(_i) { $tpl->assign('limit', $limit); $tpl->assign('searchSGD', $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/timeperiod/listTimeperiod.php b/www/include/configuration/configObject/timeperiod/listTimeperiod.php index 552f55341ef..0b843a6a406 100644 --- a/www/include/configuration/configObject/timeperiod/listTimeperiod.php +++ b/www/include/configuration/configObject/timeperiod/listTimeperiod.php @@ -1,7 +1,7 @@ historySearch[$url] = $search; -} elseif (isset($_GET['searchTP'])) { - $search = $_GET['searchTP']; - $centreon->historySearch[$url] = $search; -} elseif (isset($centreon->historySearch[$url])) { - $search = $centreon->historySearch[$url]; +$search = filter_var( + $_POST['searchTP'] ?? $_GET['searchTP'] ?? null, + FILTER_SANITIZE_STRING +); +if (isset($_POST['searchTP']) || $_GET['searchTP']) { + $centreon->historySearch[$url] = array(); + $centreon->historySearch[$url]['search'] = $search; +} else { + $search = $centreon->historySearch[$url]['search'] ?? null; } +$SearchTool = ''; if ($search) { $SearchTool .= " WHERE tp_name LIKE '%" . htmlentities($search, ENT_QUOTES, "UTF-8") . "%'"; } -//Timeperiod list +// Timeperiod list $query = "SELECT SQL_CALC_FOUND_ROWS tp_id, tp_name, tp_alias FROM timeperiod $SearchTool " . "ORDER BY tp_name LIMIT " . $num * $limit . ", " . $limit; -$DBRESULT = $pearDB->query($query); +$dbResult = $pearDB->query($query); $rows = $pearDB->query("SELECT FOUND_ROWS()")->fetchColumn(); -include("./include/common/checkPagination.php"); +include "./include/common/checkPagination.php"; /* * Smarty template Init @@ -70,13 +69,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", _("Name")); $tpl->assign("headerMenu_desc", _("Description")); $tpl->assign("headerMenu_options", _("Options")); @@ -84,17 +81,13 @@ $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; $timeperiod = $DBRESULT->fetchRow(); $i++) { +for ($i = 0; $timeperiod = $dbResult->fetch(); $i++) { $moptions = ""; $selectedElements = $form->addElement('checkbox', "select[" . $timeperiod['tp_id'] . "]"); $moptions .= "  31 && (event.keyCode < 45 || event.keyCode > 57)) " . @@ -113,23 +106,24 @@ $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 ?") + ) ); -/* - * Toolbar select - */ +// Toolbar select ?> - + assign('limit', $limit); $tpl->assign('searchTP', $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/traps-groups/listGroups.php b/www/include/configuration/configObject/traps-groups/listGroups.php index 2c063dc38af..59b325419e8 100644 --- a/www/include/configuration/configObject/traps-groups/listGroups.php +++ b/www/include/configuration/configObject/traps-groups/listGroups.php @@ -1,7 +1,7 @@ historySearch[$url] = $search; -} elseif (isset($_GET['searchTM'])) { - $search = $_GET['searchTM']; - $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 = null; if ($search) { - $SearchTool = " WHERE (traps_group_name LIKE '%" . htmlentities($search, ENT_QUOTES, "UTF-8") . "%')"; + $searchTool = " WHERE (traps_group_name LIKE '%" . $search . "%')"; } -$query = "SELECT SQL_CALC_FOUND_ROWS * FROM traps_group $SearchTool ORDER BY traps_group_name LIMIT " . - $num * $limit . ", " . $limit; -$DBRESULT = $pearDB->query($query); +$dbResult = $pearDB->query( + "SELECT SQL_CALC_FOUND_ROWS * FROM traps_group " . $searchTool . + " ORDER BY traps_group_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); -/* 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", _("Group Name")); -/* - * List of elements - Depends on different criteria - */ - +// List of elements - Depends on different criteria $form = new HTML_QuickFormCustom('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; $group = $DBRESULT->fetchRow(); $i++) { +for ($i = 0; $group = $dbResult->fetch(); $i++) { $moptions = ""; $selectedElements = $form->addElement('checkbox', "select[" . $group['traps_group_id'] . "]"); $moptions = "  31 && (event.keyCode < 45 || event.keyCode > 57)) " . @@ -113,23 +104,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 - */ +// Toolbar select ?> - + "javascript: " . @@ -190,9 +181,7 @@ function setO(_i) { $tpl->assign('limit', $limit); $tpl->assign('searchTM', $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/traps-manufacturer/listMnftr.php b/www/include/configuration/configObject/traps-manufacturer/listMnftr.php index e60e616e420..5f4e3a6e78f 100644 --- a/www/include/configuration/configObject/traps-manufacturer/listMnftr.php +++ b/www/include/configuration/configObject/traps-manufacturer/listMnftr.php @@ -1,7 +1,7 @@ historySearch[$url] = $search; -} elseif (isset($_GET['searchTM'])) { - $search = $_GET['searchTM']; - $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 (alias LIKE '%" . htmlentities($search, ENT_QUOTES, "UTF-8") . - "%') OR (name LIKE '%" . htmlentities($search, ENT_QUOTES, "UTF-8") . "%')"; + $SearchTool .= " WHERE (alias LIKE '%" . $search . "%') OR (name LIKE '%" . $search . "%')"; } -/* - * List of elements - Depends on different criteria - */ -$query = "SELECT SQL_CALC_FOUND_ROWS * FROM traps_vendor " . $SearchTool . - "ORDER BY name, alias LIMIT " . $num * $limit . ", " . $limit; -$DBRESULT = $pearDB->query($query); +// List of elements - Depends on different criteria +$dbResult = $pearDB->query( + "SELECT SQL_CALC_FOUND_ROWS * FROM traps_vendor " . $SearchTool . + "ORDER BY name, alias 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); -/* 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", _("Vendor Name")); $tpl->assign("headerMenu_alias", _("Alias")); $tpl->assign("headerMenu_options", _("Options")); $form = new HTML_QuickFormCustom('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; $mnftr = $DBRESULT->fetchRow(); $i++) { +for ($i = 0; $mnftr = $dbResult->fetch(); $i++) { $moptions = ""; $selectedElements = $form->addElement('checkbox', "select[" . $mnftr['id'] . "]"); $moptions = "  31 && (event.keyCode < 45 || event.keyCode > 57)) " . @@ -116,23 +106,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 - */ +// Toolbar select ?> - + "javascript: " . @@ -193,9 +183,7 @@ function setO(_i) { $tpl->assign('limit', $limit); $tpl->assign('searchTM', $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/traps/listTraps.php b/www/include/configuration/configObject/traps/listTraps.php index a07b5825a65..642d5992fb9 100644 --- a/www/include/configuration/configObject/traps/listTraps.php +++ b/www/include/configuration/configObject/traps/listTraps.php @@ -1,7 +1,7 @@ _("OK"), 1 => _("Warning"), 2 => _("Critical"), 3 => _("Unknown"), 4 => _("Pending")); - -$searchT = filter_input( - INPUT_POST, - 'searchT', - FILTER_SANITIZE_STRING +$tabStatus = array( + 0 => _("OK"), + 1 => _("Warning"), + 2 => _("Critical"), + 3 => _("Unknown"), + 4 => _("Pending") ); -$searchG = filter_input( - INPUT_GET, - 'searchT', +$search = filter_var( + $_POST['searchT'] ?? $_GET['searchT'] ?? null, FILTER_SANITIZE_STRING ); -$search = null; -if (isset($searchT)) { - $search = $searchT; - $centreon->historySearch[$url] = $search; -} elseif (isset($searchG)) { - $search = $searchG; - $centreon->historySearch[$url] = $search; -} elseif (isset($centreon->historySearch[$url])) { - $search = $centreon->historySearch[$url]; +if (isset($_POST['searchT']) || isset($_GET['searchT'])) { + $centreon->historySearch[$url] = array(); + $centreon->historySearch[$url]['search'] = $search; +} else { + $search = $centreon->historySearch[$url]['search'] ?? null; } -/* - * List of elements - Depends on different criteria - */ +// List of elements - Depends on different criteria if ($search) { - $rq = "SELECT SQL_CALC_FOUND_ROWS * FROM traps WHERE traps_oid LIKE '%" . - htmlentities($search, ENT_QUOTES, "UTF-8") . "%' OR traps_name LIKE '%" . - htmlentities($search, ENT_QUOTES, "UTF-8") . "%' OR manufacturer_id IN (SELECT id FROM traps_vendor " . - " WHERE alias LIKE '%" . htmlentities($search, ENT_QUOTES, "UTF-8") . "%' ) " . - " ORDER BY manufacturer_id, traps_name LIMIT " . $num * $limit . ", " . $limit; + $rq = "SELECT SQL_CALC_FOUND_ROWS * FROM traps " . + "WHERE traps_oid LIKE '%" . $search . "%' OR traps_name LIKE '%" . $search . "%' " . + "OR manufacturer_id IN (SELECT id FROM traps_vendor WHERE alias LIKE '%" . $search . "%' ) " . + "ORDER BY manufacturer_id, traps_name LIMIT " . $num * $limit . ", " . $limit; } else { - $rq = "SELECT SQL_CALC_FOUND_ROWS * FROM traps ORDER BY manufacturer_id, traps_name LIMIT " . - $num * $limit . ", " . $limit; + $rq = "SELECT SQL_CALC_FOUND_ROWS * FROM traps " . + "ORDER BY manufacturer_id, traps_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_desc", _("OID")); $tpl->assign("headerMenu_status", _("Status")); @@ -107,16 +95,12 @@ $form = new HTML_QuickFormCustom('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; $trap = $DBRESULT->fetchRow(); $i++) { +for ($i = 0; $trap = $dbResult->fetch(); $i++) { $trap = array_map(array("CentreonUtils", "escapeAll"), $trap); $moptions = ""; $selectedElements = $form->addElement('checkbox', "select[" . $trap['traps_id'] . "]"); @@ -125,9 +109,9 @@ "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[" . $trap['traps_id'] . "]' />"; - $DBRESULT2 = $pearDB->query("select alias from traps_vendor where id='" . $trap['manufacturer_id'] . "' LIMIT 1"); - $mnftr = $DBRESULT2->fetchRow(); - $DBRESULT2->closeCursor(); + $dbResult2 = $pearDB->query("select alias from traps_vendor where id='" . $trap['manufacturer_id'] . "' LIMIT 1"); + $mnftr = $dbResult2->fetch(); + $dbResult2->closeCursor(); $elemArr[$i] = array( "MenuClass" => "list_" . $style, "RowMenu_select" => $selectedElements->toHtml(), @@ -148,18 +132,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 ?") + ) ); ?> - + "javascript: " . @@ -228,7 +216,7 @@ function setO(_i) { $tpl->assign('limit', $limit); $tpl->assign('searchT', $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/configResources/listResources.php b/www/include/configuration/configResources/listResources.php index 12a75795df0..2c324f8adcf 100644 --- a/www/include/configuration/configResources/listResources.php +++ b/www/include/configuration/configResources/listResources.php @@ -1,7 +1,7 @@ historySearch[$url] = $search; -} elseif (isset($_GET['searchR'])) { - $search = $_GET['searchR']; - $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 resource_name LIKE '%" . htmlentities($search, ENT_QUOTES, "UTF-8") . "%'"; } @@ -70,30 +70,25 @@ $aclCond .= "resource_id IN (" . implode(',', array_keys($allowedResourceConf)) . ") "; } -/* - * resources list - */ -$rq = "SELECT SQL_CALC_FOUND_ROWS * FROM cfg_resource $SearchTool $aclCond - ORDER BY resource_name LIMIT " . $num * $limit . ", " . $limit; -$DBRESULT = $pearDB->query($rq); +// resources list +$dbResult = $pearDB->query( + "SELECT SQL_CALC_FOUND_ROWS * FROM cfg_resource " . $SearchTool . $aclCond . + " ORDER BY resource_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); -/* 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_values", _("Values")); $tpl->assign("headerMenu_comment", _("Description")); @@ -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; $resource = $DBRESULT->fetchRow(); $i++) { +for ($i = 0; $resource = $dbResult->fetch(); $i++) { preg_match("\$USER([0-9]*)\$", $resource["resource_name"], $tabResources); $selectedElements = $form->addElement('checkbox', "select[" . $resource['resource_id'] . "]"); $moptions = ""; @@ -184,23 +175,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 - */ +// Toolbar select ?> - + assign('limit', $limit); $tpl->assign('searchR', $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/configServers/listServers.php b/www/include/configuration/configServers/listServers.php index 51063074938..1960c0112c1 100644 --- a/www/include/configuration/configServers/listServers.php +++ b/www/include/configuration/configServers/listServers.php @@ -1,7 +1,7 @@ getMyGMTFromSession(session_id(), $pearDB); -$LCASearch = ''; -$search = null; + +$search = filter_var( + $_POST['searchP'] ?? $_GET['searchP'] ?? null, + FILTER_SANITIZE_STRING +); if (isset($_POST['searchP'])) { - $search = $_POST['searchP']; - $centreon->historySearch[$url] = $search; -} elseif (isset($_GET['searchP'])) { - $search = $_GET['searchP']; - $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; } +$LCASearch = ''; if ($search) { $LCASearch .= " name LIKE '%" . htmlentities($search, ENT_QUOTES, "UTF-8") . "%'"; } @@ -89,45 +88,43 @@ * Get information info RTM */ $nagiosInfo = array(); -$query = "SELECT start_time AS program_start_time, running AS is_currently_running, pid AS process_id, instance_id, " . - "name AS instance_name , last_alive FROM instances WHERE deleted = 0"; -$DBRESULT = $pearDBO->query($query); -while ($info = $DBRESULT->fetchRow()) { +$dbResult = $pearDBO->query( + "SELECT start_time AS program_start_time, running AS is_currently_running, pid AS process_id, instance_id, " . + "name AS instance_name , last_alive FROM instances WHERE deleted = 0" +); +while ($info = $dbResult->fetch()) { $nagiosInfo[$info["instance_id"]] = $info; } -$DBRESULT->closeCursor(); +$dbResult->closeCursor(); /* * Get Scheduler version */ -$query = "SELECT DISTINCT instance_id, version AS program_version, engine AS program_name, name AS instance_name " . - "FROM instances WHERE deleted = 0 "; -$DBRESULT = $pearDBO->query($query); -while ($info = $DBRESULT->fetchRow()) { +$dbResult = $pearDBO->query( + "SELECT DISTINCT instance_id, version AS program_version, engine AS program_name, name AS instance_name " . + "FROM instances WHERE deleted = 0 " +); +while ($info = $dbResult->fetch()) { if (isset($nagiosInfo[$info["instance_id"]])) { $nagiosInfo[$info["instance_id"]]["version"] = $info["program_name"] . " " . $info["program_version"]; } } -$DBRESULT->closeCursor(); +$dbResult->closeCursor(); $query = 'SELECT ip FROM remote_servers'; -$DBRESULT = $pearDB->query($query); -$remotesServerIPs = $DBRESULT->fetchAll(PDO::FETCH_COLUMN); -$DBRESULT->closeCursor(); +$dbResult = $pearDB->query($query); +$remotesServerIPs = $dbResult->fetchAll(PDO::FETCH_COLUMN); +$dbResult->closeCursor(); -/* - * 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_ip_address", _("IP Address")); $tpl->assign("headerMenu_type", _("Server type")); @@ -150,19 +147,17 @@ "FROM `nagios_server` " . $ACLString . " " . ($LCASearch != '' ? ($ACLString != "" ? "AND " : "WHERE ") . $LCASearch : "") . " ORDER BY name LIMIT " . $num * $limit . ", " . $limit; -$DBRESULT = $pearDB->query($query); +$dbResult = $pearDB->query($query); $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); -/* - * 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', @@ -173,12 +168,12 @@ ); if ($config["ns_activate"]) { $moptions .= "" . _("Disabled") . ""; + "&num=" . $num . "&search=" . $search . "'>" . _("Disabled") . ""; } else { $moptions .= "" . _("Enabled") . ""; + "&num=" . $num . "&search=" . $search . "'>" . _("Enabled") . ""; } $moptions .= " 31 && (event.keyCode < 45 || event.keyCode > 57)) " . "event.returnValue = false; if(event.which > 31 && (event.which < 45 || event.which > 57)) " . @@ -190,9 +185,7 @@ } - /* - * Manage flag for changes - */ + // Manage flag for changes $confChangedMessage = _("N/A"); $hasChanged = false; if ($config["ns_activate"] && isset($nagios_restart[$config['id']])) { @@ -203,9 +196,7 @@ $confChangedMessage = $hasChanged ? _("Yes") : _("No"); } - /* - * Manage flag for update time - */ + // Manage flag for update time $lastUpdateTimeFlag = 0; if (!isset($nagiosInfo[$config["id"]]["last_alive"])) { $lastUpdateTimeFlag = 0; @@ -214,10 +205,11 @@ } //Get cfg_id - $query = "SELECT nagios_id FROM cfg_nagios " . - "WHERE nagios_server_id = " . (int) $config["id"] . " AND nagios_activate = '1'"; - $DBRESULT2 = $pearDB->query($query); - $cfg_id = $DBRESULT2->rowCount() ? $DBRESULT2->fetchRow() : -1; + $dbResult2 = $pearDB->query( + "SELECT nagios_id FROM cfg_nagios " . + "WHERE nagios_server_id = " . (int) $config["id"] . " AND nagios_activate = '1'" + ); + $cfg_id = $dbResult2->rowCount() ? $dbResult2->fetch() : -1; $uptime = '-'; $isRunning = (isset($nagiosInfo[$config['id']]['is_currently_running']) && @@ -295,23 +287,23 @@ "template, it won't tell you the configuration had changed.") ); -/* - * 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 ?> - + _("More actions..."), "m" => _("Duplicate"), "d" => _("Delete"), "i" => _("Update informations")), + array( + null => _("More actions..."), + "m" => _("Duplicate"), + "d" => _("Delete"), + "i" => _("Update informations") + ), $attrs ); $form->setDefaults(array($option => null)); @@ -342,7 +339,7 @@ function setO(_i) { $o1->setValue(null); } -# Apply configuration button +// Apply configuration button $form->addElement( 'button', 'apply_configuration', @@ -355,9 +352,7 @@ function setO(_i) { $tpl->assign("can_generate", $can_generate); $tpl->assign("is_admin", $is_admin); -/* - * 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/main.get.php b/www/main.get.php index 38f50bb4aef..769650b5a07 100644 --- a/www/main.get.php +++ b/www/main.get.php @@ -1,7 +1,7 @@ $argumentFlag) { switch ($argumentName) { - case 'limit': - if (!is_null($inputGet[$argumentName])) { - $centreon->historyLimit[$url] = $inputGet[$argumentName]; - } elseif (!is_null($inputPost[$argumentName])) { - $centreon->historyLimit[$url] = $inputPost[$argumentName]; - } else { - $centreon->historyLimit[$url] = 30; - } - break; - case 'num': - if (!is_null($inputGet[$argumentName])) { - $centreon->historyPage[$url] = $inputGet[$argumentName]; - } elseif (!is_null($inputPost[$argumentName])) { - $centreon->historyPage[$url] = $inputPost[$argumentName]; - } else { - $centreon->historyPage[$url] = 0; - } - break; - default: - continue; - break; + case 'limit': + if (!is_null($inputGet[$argumentName])) { + $centreon->historyLimit[$url] = $inputGet[$argumentName]; + } elseif (!is_null($inputPost[$argumentName])) { + $centreon->historyLimit[$url] = $inputPost[$argumentName]; + } else { + $centreon->historyLimit[$url] = 30; + } + break; + + default: + continue; + break; } } } -/* - * Display Footer - */ +// Display Footer if (!$min) { print "\t\t\t\t\t\t\n"; } ?>