From b5229f7b3e45a5fe6daf14d9c079311f22733c55 Mon Sep 17 00:00:00 2001 From: "Laurent Destailleur (aka Eldy)" Date: Sun, 26 Jan 2025 19:00:32 +0100 Subject: [PATCH] Fix redirect in website when we must not propaget parameters --- htdocs/categories/class/categorie.class.php | 16 +++++++++------- htdocs/core/lib/website.lib.php | 17 ++++++++++------- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/htdocs/categories/class/categorie.class.php b/htdocs/categories/class/categorie.class.php index 6e1b9083210..08a680c1e1b 100644 --- a/htdocs/categories/class/categorie.class.php +++ b/htdocs/categories/class/categorie.class.php @@ -1466,12 +1466,13 @@ class Categorie extends CommonObject // phpcs:enable $ways = array(); - $all_ways = $this->get_all_ways(); // Load array of categories - foreach ($all_ways as $way) { + $all_ways = $this->get_all_ways(); // Load array of categories to reach this->id + + foreach ($all_ways as $way) { // It seems we always have 1 entry in this array. $w = array(); $i = 0; $forced_color = ''; - foreach ($way as $cat) { + foreach ($way as $cat) { // Loop on each successive categories to reach the target of current category $i++; if (empty($nocolor)) { @@ -1511,6 +1512,7 @@ class Categorie extends CommonObject // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Returns an array containing the list of parent categories + * Note: A category can only have one parent but this method return an array to work the same way the get_filles is working. * * @return int|Categorie[] Return integer <0 KO, array OK */ @@ -1541,7 +1543,7 @@ class Categorie extends CommonObject // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** - * Returns in a table all possible paths to get to the category + * Returns in a array all possible paths to go to the category * starting with the major categories represented by Tables of categories * * @return Categorie[][] @@ -1554,7 +1556,7 @@ class Categorie extends CommonObject $parents = $this->get_meres(); if (is_array($parents)) { foreach ($parents as $parent) { - $all_ways = $parent->get_all_ways(); + $all_ways = $parent->get_all_ways(); // recursivity. TODO Add a protection for infinite loop foreach ($all_ways as $way) { $w = $way; $w[] = $this; @@ -1646,8 +1648,8 @@ class Categorie extends CommonObject } /** - * Returns categories whose id or name match - * add wildcards in the name unless $exact = true + * Returns categories whose id or name matches. + * It add wildcards in the name unless $exact = true * * @param int $id Id * @param string $nom Name diff --git a/htdocs/core/lib/website.lib.php b/htdocs/core/lib/website.lib.php index c9cbbb6dafa..697d3f5674d 100644 --- a/htdocs/core/lib/website.lib.php +++ b/htdocs/core/lib/website.lib.php @@ -509,14 +509,15 @@ function dolWebsiteSaveContent($content) /** * Make a redirect to another container. * - * @param string $containerref Ref of container to redirect to (Example: 'mypage' or 'mypage.php'). - * @param string $containeraliasalt Ref of alternative aliases to redirect to. - * @param int $containerid Id of container. - * @param int<0,1> $permanent 0=Use temporary redirect 302, 1=Use permanent redirect 301 - * @param array $parameters Array of parameters to append to the URL. + * @param string $containerref Ref of container to redirect to (Example: 'mypage' or 'mypage.php'). + * @param string $containeraliasalt Ref of alternative aliases to redirect to. + * @param int $containerid Id of container. + * @param int<0,1> $permanent 0=Use temporary redirect 302 (default), 1=Use permanent redirect 301 + * @param array $parameters Array of parameters to append to the URL. + * @param int<0,1> $parampropagation 0=Do not propagate query parameter in URL when doing the redirect, 1=Keep parameters (default) * @return void */ -function redirectToContainer($containerref, $containeraliasalt = '', $containerid = 0, $permanent = 0, $parameters = array()) +function redirectToContainer($containerref, $containeraliasalt = '', $containerid = 0, $permanent = 0, $parameters = array(), $parampropagation = 1) { global $db, $website; '@phan-var-force Website $website'; @@ -572,7 +573,9 @@ function redirectToContainer($containerref, $containeraliasalt = '', $containeri } } else { // When page called from virtual host server $newurl = '/'.$containerref.'.php'; - $newurl .= (empty($_SERVER["QUERY_STRING"]) ? '' : '?'.$_SERVER["QUERY_STRING"]); + if ($parampropagation) { + $newurl .= (empty($_SERVER["QUERY_STRING"]) ? '' : '?'.$_SERVER["QUERY_STRING"]); + } } if ($newurl) {