Fix redirect in website when we must not propaget parameters

This commit is contained in:
Laurent Destailleur (aka Eldy) 2025-01-26 19:00:32 +01:00
parent 3c048e8116
commit b5229f7b3e
2 changed files with 19 additions and 14 deletions

View File

@ -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

View File

@ -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<string,mixed> $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<string,mixed> $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) {