From a73ffad32bd809580d45793da9fa266d316e8c0a Mon Sep 17 00:00:00 2001 From: bdalsass Date: Tue, 3 Jun 2025 08:51:02 +0200 Subject: [PATCH 1/3] =?UTF-8?q?N=C2=B08148=20-=20CAS=20problem=20when=20se?= =?UTF-8?q?nding=20a=20link=20ending=20in=20&?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/applicationcontext.class.inc.php | 37 ++++++++++++++++- application/cmdbabstract.class.inc.php | 4 +- application/dashlet.class.inc.php | 2 +- application/displayblock.class.inc.php | 41 +++++++++---------- application/shortcut.class.inc.php | 2 +- application/utils.inc.php | 8 ++-- core/attributedef.class.inc.php | 8 ++-- core/bulkchange.class.inc.php | 6 +-- core/displayablegraph.class.inc.php | 4 +- pages/UI.php | 12 +++--- pages/audit.php | 10 ++--- pages/preferences.php | 4 +- pages/schema.php | 6 +-- .../Search/searchform.class.inc.php | 2 +- .../UI/Base/Component/DataTable/DataTable.php | 4 +- .../DataTable/DataTableUIBlockFactory.php | 2 +- .../Direct/BlockDirectLinkSetEditTable.php | 2 +- .../Set/BlockLinkSetDisplayAsProperty.php | 4 +- sources/Application/WebPage/NiceWebPage.php | 2 +- sources/Controller/AjaxRenderController.php | 4 +- 20 files changed, 96 insertions(+), 68 deletions(-) diff --git a/application/applicationcontext.class.inc.php b/application/applicationcontext.class.inc.php index 533427e11d..3b2b4987b8 100644 --- a/application/applicationcontext.class.inc.php +++ b/application/applicationcontext.class.inc.php @@ -195,6 +195,8 @@ public function GetCurrentValue($sParamName, $defaultValue = '') /** * Returns the context as string with the format name1=value1&name2=value2.... * @return string The context as a string to be appended to an href property + * + * @deprecated since 3.2.2 Use GetQueryParametersString() instead, responsible in adding the leading '&' */ public function GetForLink() { @@ -205,6 +207,39 @@ public function GetForLink() } return implode("&", $aParams); } + + /** + * Returns the context as string with the format c[name1]=value1&c[name2]=value2.... + * Add a leading ampersand if requested + * + * @param bool $bWithLeadingAmpersand + * + * @return string + * @since 3.2.2 + */ + public function GetQueryParametersString(bool $bWithLeadingAmpersand = true): string + { + // If there are no parameters, return an empty string + if(empty($this->aValues)){ + return ''; + } + + // Build the query string with ampersand separated parameters + $aParams = array(); + foreach($this->aValues as $sName => $sValue) + { + $aParams[] = "c[$sName]".'='.urlencode($sValue); + } + $sReturnValue = implode('&', $aParams); + + // add the leading ampersand if requested + if($bWithLeadingAmpersand){ + $sReturnValue = '&' . $sReturnValue; + } + + return $sReturnValue; + } + /** * @since 3.0.0 N°2534 - dashboard: bug with autorefresh that deactivates filtering on organisation * Returns the params as c[menu]:..., c[org_id]:.... @@ -382,7 +417,7 @@ public static function MakeObjectUrl($sObjClass, $sObjKey, $sUrlMakerClass = nul $sUrl = call_user_func(array($sUrlMakerClass, 'MakeObjectUrl'), $sObjClass, $sObjKey); if (utils::StrLen($sUrl) > 0) { if ($bWithNavigationContext) { - return $sUrl."&".$oAppContext->GetForLink(); + return $sUrl.$oAppContext->GetQueryParametersString(); } else { return $sUrl; } diff --git a/application/cmdbabstract.class.inc.php b/application/cmdbabstract.class.inc.php index 8a2ed6bfa0..04ab9233f1 100644 --- a/application/cmdbabstract.class.inc.php +++ b/application/cmdbabstract.class.inc.php @@ -311,7 +311,7 @@ public static function ReloadAndDisplay($oPage, $oObj, $aParams) { $sParams .= $sName.'='.urlencode($value).'&'; // Always add a trailing & } - $sUrl = utils::GetAbsoluteUrlAppRoot().'pages/'.$oObj->GetUIPage().'?'.$sParams.'class='.get_class($oObj).'&id='.$oObj->getKey().'&'.$oAppContext->GetForLink().'&a=1'; + $sUrl = utils::GetAbsoluteUrlAppRoot().'pages/'.$oObj->GetUIPage().'?'.$sParams.'class='.get_class($oObj).'&id='.$oObj->getKey().$oAppContext->GetQueryParametersString().'&a=1'; $oPage->add_early_script(<<add($oAppContext->GetForForm()); // Hook the cancel button via jQuery so that it can be unhooked easily as well if needed - $sDefaultUrl = utils::GetAbsoluteUrlAppRoot().'pages/UI.php?operation=search_form&class='.$sClass.'&'.$oAppContext->GetForLink(); + $sDefaultUrl = utils::GetAbsoluteUrlAppRoot().'pages/UI.php?operation=search_form&class='.$sClass.$oAppContext->GetQueryParametersString(); $sCancelButtonOnClickScript = "let fOnClick{$this->m_iFormId}CancelButton = "; if(isset($aExtraParams['js_handlers']['cancel_button_on_click'])){ diff --git a/application/dashlet.class.inc.php b/application/dashlet.class.inc.php index 4126cb0b50..82a75d1029 100644 --- a/application/dashlet.class.inc.php +++ b/application/dashlet.class.inc.php @@ -2138,7 +2138,7 @@ public function Render($oPage, $bEditMode = false, $aExtraParams = array()) $oSet = new DBObjectSet($oFilter); $iCount = $oSet->Count(); $oAppContext = new ApplicationContext(); - $sHyperlink = utils::GetAbsoluteUrlAppRoot().'pages/UI.php?operation=search&'.$oAppContext->GetForLink().'&filter='.rawurlencode($oFilter->serialize()); + $sHyperlink = utils::GetAbsoluteUrlAppRoot().'pages/UI.php?operation=search'.$oAppContext->GetQueryParametersString().'&filter='.rawurlencode($oFilter->serialize()); $oSubTitle->AddHtml(''.Dict::Format(str_replace('_', ':', $sSubtitle), $iCount).''); return $oPanel; diff --git a/application/displayblock.class.inc.php b/application/displayblock.class.inc.php index 12a0fe18ea..403ea4995b 100644 --- a/application/displayblock.class.inc.php +++ b/application/displayblock.class.inc.php @@ -1124,7 +1124,7 @@ protected function RenderSummary(array $aExtraParams): iUIBlock $oSingleGroupByValueFilter->SetShowObsoleteData($this->m_bShowObsoleteData); } $sHyperlink = utils::GetAbsoluteUrlAppRoot() - .'pages/UI.php?operation=search&'.$oAppContext->GetForLink() + .'pages/UI.php?operation=search'.$oAppContext->GetQueryParametersString() .'&filter='.rawurlencode($oSingleGroupByValueFilter->serialize()); $aCounts[$sStateValue] = ['link' => $sHyperlink, 'label' => $aCounts[$sStateValue]]; } @@ -1232,7 +1232,7 @@ protected function RenderActions(array $aExtraParams): iUIBlock $iCount = $this->m_oSet->Count(); $sClassLabel = MetaModel::GetName($sClass); $sClassIconUrl = MetaModel::GetClassIcon($sClass, false); - $sHyperlink = utils::GetAbsoluteUrlAppRoot().'pages/UI.php?operation=search&'.$oAppContext->GetForLink().'&filter='.rawurlencode($this->m_oFilter->serialize()); + $sHyperlink = utils::GetAbsoluteUrlAppRoot().'pages/UI.php?operation=search'.$oAppContext->GetQueryParametersString().'&filter='.rawurlencode($this->m_oFilter->serialize()); $aExtraParams['query_params'] = $this->m_oFilter->GetInternalParams(); $aRefreshParams = [ @@ -1241,7 +1241,7 @@ protected function RenderActions(array $aExtraParams): iUIBlock ]; if (UserRights::IsActionAllowed($sClass, UR_ACTION_MODIFY)) { - $sCreateActionUrl = utils::GetAbsoluteUrlAppRoot().'pages/UI.php?operation=new&class='.$sClass.'&'.$oAppContext->GetForLink(); + $sCreateActionUrl = utils::GetAbsoluteUrlAppRoot().'pages/UI.php?operation=new&class='.$sClass.$oAppContext->GetQueryParametersString(); $sCreateActionLabel = Dict::Format('UI:Button:Create'); $oBlock = DashletFactory::MakeForDashletBadge($sClassIconUrl, $sHyperlink, $iCount, $sClassLabel, $sCreateActionUrl, $sCreateActionLabel, $aRefreshParams); @@ -1289,7 +1289,7 @@ protected function RenderCount(array $aExtraParams): iUIBlock $aData = array(); $oAppContext = new ApplicationContext(); - $sParams = $oAppContext->GetForLink(); + $sParams = $oAppContext->GetQueryParametersString(); foreach ($aGroupBy as $iRow => $iCount) { // Build the search for this subset $oSubsetSearch = $this->m_oFilter->DeepClone(); @@ -1304,7 +1304,7 @@ protected function RenderCount(array $aExtraParams): iUIBlock $aData[] = array( 'group' => $aLabels[$iRow], - 'value' => "$iCount" + 'value' => "$iCount" ); // TO DO: add the context information } $aAttribs = array( @@ -1636,7 +1636,7 @@ protected function RenderChart(?string $sChartId, array $aQueryParams, array $aE $sGroupByExpr = isset($aExtraParams['group_by_expr']) ? '¶ms[group_by_expr]='.$aExtraParams['group_by_expr'] : ''; $sFilter = $this->m_oFilter->serialize(false, $aQueryParams); $oContext = new ApplicationContext(); - $sContextParam = $oContext->GetForLink(); + $sContextParam = $oContext->GetQueryParametersString(); $sAggregationFunction = isset($aExtraParams['aggregation_function']) ? $aExtraParams['aggregation_function'] : ''; $sAggregationAttr = isset($aExtraParams['aggregation_attribute']) ? $aExtraParams['aggregation_attribute'] : ''; $sLimit = isset($aExtraParams['limit']) ? $aExtraParams['limit'] : ''; @@ -1644,7 +1644,7 @@ protected function RenderChart(?string $sChartId, array $aQueryParams, array $aE $sOrderDirection = isset($aExtraParams['order_direction']) ? $aExtraParams['order_direction'] : ''; if (isset($aExtraParams['group_by_label'])) { - $sUrl = utils::GetAbsoluteUrlAppRoot()."pages/ajax.render.php?operation=chart¶ms[group_by]=$sGroupBy{$sGroupByExpr}¶ms[group_by_label]={$aExtraParams['group_by_label']}¶ms[chart_type]=$sChartType¶ms[currentId]=$sChartId{$iChartCounter}¶ms[order_direction]=$sOrderDirection¶ms[order_by]=$sOrderBy¶ms[limit]=$sLimit¶ms[aggregation_function]=$sAggregationFunction¶ms[aggregation_attribute]=$sAggregationAttr&id=$sChartId{$iChartCounter}&filter=".rawurlencode($sFilter).'&'.$sContextParam; + $sUrl = utils::GetAbsoluteUrlAppRoot()."pages/ajax.render.php?operation=chart¶ms[group_by]=$sGroupBy{$sGroupByExpr}¶ms[group_by_label]={$aExtraParams['group_by_label']}¶ms[chart_type]=$sChartType¶ms[currentId]=$sChartId{$iChartCounter}¶ms[order_direction]=$sOrderDirection¶ms[order_by]=$sOrderBy¶ms[limit]=$sLimit¶ms[aggregation_function]=$sAggregationFunction¶ms[aggregation_attribute]=$sAggregationAttr&id=$sChartId{$iChartCounter}&filter=".rawurlencode($sFilter).$sContextParam; } else { $sUrl = utils::GetAbsoluteUrlAppRoot()."pages/ajax.render.php?operation=chart¶ms[group_by]=$sGroupBy{$sGroupByExpr}¶ms[chart_type]=$sChartType¶ms[currentId]=$sChartId{$iChartCounter}¶ms[order_direction]=$sOrderDirection¶ms[order_by]=$sOrderBy¶ms[limit]=$sLimit¶ms[aggregation_function]=$sAggregationFunction¶ms[aggregation_attribute]=$sAggregationAttr&id=$sChartId{$iChartCounter}&filter=".rawurlencode($sFilter).'&'.$sContextParam; } @@ -1681,11 +1681,14 @@ protected function RenderChartAjax(array $aExtraParams) $oBlock = null; $sJSURLs = ''; + $oContext = new ApplicationContext(); + $sContextParam = $oContext->GetQueryParametersString(); + if (isset($aExtraParams['group_by'])) { $this->MakeGroupByQuery($aExtraParams, $oGroupByExp, $sGroupByLabel, $aGroupBy, $sAggregationFunction, $sFctVar, $sAggregationAttr, $sSql); $aRes = CMDBSource::QueryToArray($sSql); - $oContext = new ApplicationContext(); - $sContextParam = $oContext->GetForLink(); + + $iTotalCount = 0; $aURLs = array(); @@ -1705,14 +1708,14 @@ protected function RenderChartAjax(array $aExtraParams) $oSubsetSearch = $this->m_oFilter->DeepClone(); $oCondition = new BinaryExpression($oGroupByExp, '=', new ScalarExpression($sValue)); $oSubsetSearch->AddConditionExpression($oCondition); - $aURLs[] = utils::GetAbsoluteUrlAppRoot()."pages/UI.php?operation=search&format=html&filter=".rawurlencode($oSubsetSearch->serialize()).'&'.$sContextParam; + $aURLs[] = utils::GetAbsoluteUrlAppRoot()."pages/UI.php?operation=search&format=html&filter=".rawurlencode($oSubsetSearch->serialize()).$sContextParam; } $sJSURLs = json_encode($aURLs); } if (isset($aExtraParams['group_by_label'])) { - $sUrl = utils::GetAbsoluteUrlAppRoot()."pages/ajax.render.php?operation=chart¶ms[group_by]=$aExtraParams[group_by]¶ms[group_by_label]={$aExtraParams['group_by_label']}¶ms[chart_type]=$sChartType¶ms[currentId]=$aExtraParams[currentId]¶ms[order_direction]=$aExtraParams[order_direction]¶ms[order_by]=$aExtraParams[order_by]¶ms[limit]=$aExtraParams[limit]¶ms[aggregation_function]=$sAggregationFunction¶ms[aggregation_attribute]=$sAggregationAttr&id=$sId&filter=".rawurlencode($this->m_oFilter->ToOQL()).'&'.$sContextParam; + $sUrl = utils::GetAbsoluteUrlAppRoot()."pages/ajax.render.php?operation=chart¶ms[group_by]=$aExtraParams[group_by]¶ms[group_by_label]={$aExtraParams['group_by_label']}¶ms[chart_type]=$sChartType¶ms[currentId]=$aExtraParams[currentId]¶ms[order_direction]=$aExtraParams[order_direction]¶ms[order_by]=$aExtraParams[order_by]¶ms[limit]=$aExtraParams[limit]¶ms[aggregation_function]=$sAggregationFunction¶ms[aggregation_attribute]=$sAggregationAttr&id=$sId&filter=".rawurlencode($this->m_oFilter->ToOQL()).$sContextParam; } else { - $sUrl = utils::GetAbsoluteUrlAppRoot()."pages/ajax.render.php?operation=chart¶ms[group_by]=$aExtraParams[group_by]¶ms[chart_type]=$sChartType¶ms[currentId]=$aExtraParams[currentId]¶ms[order_direction]=$aExtraParams[order_direction]¶ms[order_by]=$aExtraParams[order_by]¶ms[limit]=$aExtraParams[limit]¶ms[aggregation_function]=$sAggregationFunction¶ms[aggregation_attribute]=$sAggregationAttr&id=$sId&filter=".rawurlencode($this->m_oFilter->ToOQL()).'&'.$sContextParam; + $sUrl = utils::GetAbsoluteUrlAppRoot()."pages/ajax.render.php?operation=chart¶ms[group_by]=$aExtraParams[group_by]¶ms[chart_type]=$sChartType¶ms[currentId]=$aExtraParams[currentId]¶ms[order_direction]=$aExtraParams[order_direction]¶ms[order_by]=$aExtraParams[order_by]¶ms[limit]=$aExtraParams[limit]¶ms[aggregation_function]=$sAggregationFunction¶ms[aggregation_attribute]=$sAggregationAttr&id=$sId&filter=".rawurlencode($this->m_oFilter->ToOQL()).$sContextParam; } switch ($sChartType) { @@ -1785,7 +1788,7 @@ protected function RenderCsv(ApplicationContext $oAppContext) $oBlock->sCsvFile = strtolower($this->m_oFilter->GetClass()).'.csv'; $oBlock->sDownloadLink = utils::GetAbsoluteUrlAppRoot().'webservices/export.php?expression='.urlencode($this->m_oFilter->ToOQL(true)).'&format=csv&filename='.urlencode($oBlock->sCsvFile); - $oBlock->sLinkToToggle = utils::GetAbsoluteUrlAppRoot().'pages/UI.php?operation=search&'.$oAppContext->GetForLink().'&filter='.rawurlencode($this->m_oFilter->serialize()).'&format=csv'; + $oBlock->sLinkToToggle = utils::GetAbsoluteUrlAppRoot().'pages/UI.php?operation=search'.$oAppContext->GetQueryParametersString().'&filter='.rawurlencode($this->m_oFilter->serialize()).'&format=csv'; // Pass the parameters via POST, since expression may be very long $aParamsToPost = array( 'expression' => $this->m_oFilter->ToOQL(true), @@ -1885,10 +1888,7 @@ public function GetRenderContent(WebPage $oPage, array $aExtraParams, string $sI && (!isset($aExtraParams['menu']) || $aExtraParams['menu'] === "1" || $aExtraParams['menu'] === true) ) { $oAppContext = new ApplicationContext(); - $sContext = $oAppContext->GetForLink(); - if (utils::IsNotNullOrEmptyString($sContext)) { - $sContext = '&'.$sContext; - } + $sContext = $oAppContext->GetQueryParametersString(); $sFilter = $this->GetFilter()->serialize(); @@ -2578,11 +2578,8 @@ private function PrepareUrlForStandardMenuAction(string $sClass, string $sUrlPar $sUrl = "{$sRootUrl}pages/{$sUIPage}?{$sUrlParams}"; $oAppContext = new ApplicationContext(); - $sContext = $oAppContext->GetForLink(); - if (utils::IsNotNullOrEmptyString($sContext)) { - $sUrl .= '&'.$sContext; - } + $sContext = $oAppContext->GetQueryParametersString(); - return $sUrl; + return $sUrl . $sContext; } } diff --git a/application/shortcut.class.inc.php b/application/shortcut.class.inc.php index a213cb8cd3..94d4949f5c 100644 --- a/application/shortcut.class.inc.php +++ b/application/shortcut.class.inc.php @@ -282,7 +282,7 @@ public static function GetCreationDlgFromOQL($oPage, $sOQL, $sTableSettings) $sCancelButtonLabel = Dict::S('UI:Button:Cancel'); $oAppContext = new ApplicationContext(); - $sContext = $oAppContext->GetForLink(); + $sContext = $oAppContext->GetQueryParametersString(false); $sRateTitle = addslashes(Dict::Format('Class:ShortcutOQL/Attribute:auto_reload_sec/tip', MetaModel::GetConfig()->Get('min_reload_interval'))); diff --git a/application/utils.inc.php b/application/utils.inc.php index 5803a3bc8b..aee95f98c2 100644 --- a/application/utils.inc.php +++ b/application/utils.inc.php @@ -1516,12 +1516,12 @@ public static function GetPopupMenuItemsBlock(iUIBlock &$oContainerBlock, $iMenu case iPopupMenuExtension::MENU_OBJLIST_TOOLKIT: /** @var \DBObjectSet $param */ $oAppContext = new ApplicationContext(); - $sContext = $oAppContext->GetForLink(); + $sContext = $oAppContext->GetQueryParametersString(); $sDataTableId = is_null($sDataTableId) ? '' : $sDataTableId; $sUIPage = cmdbAbstractObject::ComputeStandardUIPage($param->GetFilter()->GetClass()); $sOQL = addslashes($param->GetFilter()->ToOQL(true)); $sFilter = urlencode($param->GetFilter()->serialize()); - $sUrl = utils::GetAbsoluteUrlAppRoot()."pages/$sUIPage?operation=search&filter=".$sFilter."&{$sContext}"; + $sUrl = utils::GetAbsoluteUrlAppRoot()."pages/$sUIPage?operation=search&filter=".$sFilter.$sContext; $oContainerBlock->AddJsFileRelPath('js/tabularfieldsselector.js'); $oContainerBlock->AddJsFileRelPath('js/jquery.dragtable.js'); $oContainerBlock->AddCssFileRelPath('css/dragtable.css'); @@ -1696,8 +1696,8 @@ public static function GetDataTableSearchUrl(DBSearch $oFilter, array $aExtraPar $oAppContext = new ApplicationContext(); $sUrl = $sAppRootUrl - .'pages/UI.php?operation=search&' - .$oAppContext->GetForLink() + .'pages/UI.php?operation=search' + .$oAppContext->GetQueryParametersString() .'&filter='.rawurlencode($oDataTableSearchFilter->serialize()); $sUrl .= '&aParams='.rawurlencode($sParams); // Not working... yet, cause not handled by UI.php diff --git a/core/attributedef.class.inc.php b/core/attributedef.class.inc.php index 45e7157760..a520e4d0cc 100644 --- a/core/attributedef.class.inc.php +++ b/core/attributedef.class.inc.php @@ -10954,12 +10954,12 @@ public function GenerateViewHtmlForValues($aValues, $sCssClass = '', $bWithLink $sDescription = utils::EscapeHtml($this->GetValueDescription($sValue)); $oFilter = DBSearch::FromOQL("SELECT $sClass WHERE $sAttCode MATCHES '$sValue'"); $oAppContext = new ApplicationContext(); - $sContext = $oAppContext->GetForLink(); + $sContext = $oAppContext->GetQueryParametersString(); $sUIPage = cmdbAbstractObject::ComputeStandardUIPage($oFilter->GetClass()); $sFilter = rawurlencode($oFilter->serialize()); $sLink = ''; if ($bWithLink && $this->bDisplayLink) { - $sUrl = utils::GetAbsoluteUrlAppRoot()."pages/$sUIPage?operation=search&filter=".$sFilter."&{$sContext}"; + $sUrl = utils::GetAbsoluteUrlAppRoot()."pages/$sUIPage?operation=search&filter=".$sFilter.$sContext; $sLink = ' href="'.$sUrl.'"'; } @@ -12276,13 +12276,13 @@ public function GenerateViewHtmlForValues($aValues, $sCssClass = '', $bWithLink $sTagDescription = $oTag->Get('description'); $oFilter = DBSearch::FromOQL("SELECT $sClass WHERE $sAttCode MATCHES '$sTagCode'"); $oAppContext = new ApplicationContext(); - $sContext = $oAppContext->GetForLink(); + $sContext = $oAppContext->GetQueryParametersString(); $sUIPage = cmdbAbstractObject::ComputeStandardUIPage($oFilter->GetClass()); $sFilter = rawurlencode($oFilter->serialize()); $sLink = ''; if ($bWithLink && $this->bDisplayLink) { - $sUrl = utils::GetAbsoluteUrlAppRoot()."pages/$sUIPage?operation=search&filter=".$sFilter."&{$sContext}"; + $sUrl = utils::GetAbsoluteUrlAppRoot()."pages/$sUIPage?operation=search&filter=".$sFilter.$sContext; $sLink = ' href="'.$sUrl.'"'; } diff --git a/core/bulkchange.class.inc.php b/core/bulkchange.class.inc.php index ee60143248..57b4baf7ca 100644 --- a/core/bulkchange.class.inc.php +++ b/core/bulkchange.class.inc.php @@ -1406,7 +1406,7 @@ static function DisplayImportHistory(WebPage $oPage, $bFromAjax = false, $bShowA $aDetails = array(); while ($oChange = $oBulkChanges->Fetch()) { - $sDate = ''.$oChange->Get('date').''; + $sDate = ''.$oChange->Get('date').''; $sUser = $oChange->GetUserName(); if (preg_match('/^(.*)\\(CSV\\)$/i', $oChange->Get('userinfo'), $aMatches)) { @@ -1482,13 +1482,13 @@ static function DisplayImportHistory(WebPage $oPage, $bFromAjax = false, $bShowA ); - $sAppContext = $oAppContext->GetForLink(); + $sAppContext = $oAppContext->GetQueryParametersString(false); $oPage->add_script( <<'); - $.get(GetAbsoluteUrlAppRoot()+'pages/ajax.render.php?{$sAppContext}', {operation: 'displayCSVHistory', showall: bShowAll}, function(data) + $.get(GetAbsoluteUrlAppRoot()+'pages/ajax.render.php?$sAppContext', {operation: 'displayCSVHistory', showall: bShowAll}, function(data) { $('#$sAjaxDivId').html(data); } diff --git a/core/displayablegraph.class.inc.php b/core/displayablegraph.class.inc.php index b7fbe7475b..4cdb3e0c1e 100644 --- a/core/displayablegraph.class.inc.php +++ b/core/displayablegraph.class.inc.php @@ -1470,8 +1470,8 @@ function DisplayGraph(WebPage $oP, $sRelation, ApplicationContext $oAppContext, try { $this->InitFromGraphviz(); $sExportAsPdfURL = utils::GetAbsoluteUrlAppRoot().'pages/ajax.render.php?operation=relation_pdf&relation='.$sRelation.'&direction='.($this->bDirectionDown ? 'down' : 'up'); - $sContext = $oAppContext->GetForLink(); - $sDrillDownURL = utils::GetAbsoluteUrlAppRoot().'pages/UI.php?operation=details&class=%1$s&id=%2$s&'.$sContext; + $sContext = $oAppContext->GetQueryParametersString(); + $sDrillDownURL = utils::GetAbsoluteUrlAppRoot().'pages/UI.php?operation=details&class=%1$s&id=%2$s'.$sContext; $sExportAsDocumentURL = utils::GetAbsoluteUrlAppRoot().'pages/ajax.render.php?operation=relation_attachment&relation='.$sRelation.'&direction='.($this->bDirectionDown ? 'down' : 'up'); $sLoadFromURL = utils::GetAbsoluteUrlAppRoot().'pages/ajax.render.php?operation=relation_json&relation='.$sRelation.'&direction='.($this->bDirectionDown ? 'down' : 'up'); $sAttachmentExportTitle = ''; diff --git a/pages/UI.php b/pages/UI.php index 732b23f267..acfb9ada5e 100644 --- a/pages/UI.php +++ b/pages/UI.php @@ -90,7 +90,7 @@ function ApplyNextAction(Webpage $oP, CMDBObject $oObj, $sNextAction) $oAppContext = new ApplicationContext(); //echo "

Missing Attributes

".print_r($aExpectedAttributes, true)."

\n"; - $oP->add_header('Location: '.utils::GetAbsoluteUrlAppRoot().'pages/UI.php?operation=stimulus&class='.get_class($oObj).'&stimulus='.$sNextAction.'&id='.$oObj->getKey().'&'.$oAppContext->GetForLink()); + $oP->add_header('Location: '.utils::GetAbsoluteUrlAppRoot().'pages/UI.php?operation=stimulus&class='.get_class($oObj).'&stimulus='.$sNextAction.'&id='.$oObj->getKey().$oAppContext->GetQueryParametersString()); } } @@ -101,7 +101,7 @@ function ReloadAndDisplay($oPage, $oObj, $sMessageId = '', $sMessage = '', $sSev { cmdbAbstractObject::SetSessionMessage(get_class($oObj), $oObj->GetKey(), $sMessageId, $sMessage, $sSeverity, 0, true /* must not exist */); } - $oPage->add_header('Location: '.utils::GetAbsoluteUrlAppRoot().'pages/UI.php?operation=details&class='.get_class($oObj).'&id='.$oObj->getKey().'&'.$oAppContext->GetForLink()); + $oPage->add_header('Location: '.utils::GetAbsoluteUrlAppRoot().'pages/UI.php?operation=details&class='.get_class($oObj).'&id='.$oObj->getKey().$oAppContext->GetQueryParametersString()); } /** @@ -993,7 +993,7 @@ function DisplayNavigatorGroupTab($oP) $oForm->AddHtml($oP->GetDetails($aDetails)); $oForm->AddHtml(''); - $sURL = "./UI.php?operation=search&filter=".urlencode($sFilter)."&".$oAppContext->GetForLink(); + $sURL = "./UI.php?operation=search&filter=".urlencode($sFilter).$oAppContext->GetQueryParametersString(); $oCancelButton = ButtonUIBlockFactory::MakeForCancel(Dict::S('UI:Button:Cancel'), 'cancel', 'cancel'); $oCancelButton->SetOnClickJsCode("window.location.href='$sURL'"); $oForm->AddSubBlock($oCancelButton); @@ -1165,7 +1165,7 @@ function DisplayNavigatorGroupTab($oP) $oP->AddUiBlock($oBlock); // Back to the list - $sURL = "./UI.php?operation=search&filter=".urlencode($sFilter)."&".$oAppContext->GetForLink(); + $sURL = "./UI.php?operation=search&filter=".urlencode($sFilter).$oAppContext->GetQueryParametersString(); $oSubmitButton = ButtonUIBlockFactory::MakeForSecondaryAction(Dict::S('UI:Button:Done'), 'submit', 'submit', true); $oSubmitButton->SetOnClickJsCode("window.location.href='$sURL'"); $oToolbarButtons = ToolbarUIBlockFactory::MakeStandard(null); @@ -1606,7 +1606,7 @@ public static function OperationFormForModifyAll(iTopWebPage $oP, ApplicationCon // Add user filter $oFullSetFilter->UpdateContextFromUser(); $aSelectedObj = utils::ReadMultipleSelection($oFullSetFilter); - $sCancelUrl = "./UI.php?operation=search&filter=".urlencode($sFilter)."&".$oAppContext->GetForLink(); + $sCancelUrl = "./UI.php?operation=search&filter=".urlencode($sFilter).$oAppContext->GetQueryParametersString(); $aContext = array('filter' => utils::EscapeHtml($sFilter)); cmdbAbstractObject::DisplayBulkModifyForm($oP, $sClass, $aSelectedObj, 'preview_or_modify_all', $sCancelUrl, array(), $aContext); } @@ -1640,7 +1640,7 @@ public static function OperationPreviewOrModifyAll(iTopWebPage $oP, ApplicationC throw new ApplicationException(Dict::Format('UI:Error:2ParametersMissing', 'class', 'selectObj')); } $aSelectedObj = explode(',', $sSelectedObj); - $sCancelUrl = "./UI.php?operation=search&filter=".urlencode($sFilter)."&".$oAppContext->GetForLink(); + $sCancelUrl = "./UI.php?operation=search&filter=".urlencode($sFilter).$oAppContext->GetQueryParametersString(); $aContext = array( 'filter' => utils::EscapeHtml($sFilter), 'selectObj' => $sSelectedObj, diff --git a/pages/audit.php b/pages/audit.php index ed952ebbff..c581f86304 100644 --- a/pages/audit.php +++ b/pages/audit.php @@ -213,7 +213,7 @@ function GetRuleResultFilter($iRuleId, $oDefinitionFilter, $oAppContext) $sTitle = Dict::S('UI:Audit:AuditErrors'); $oP->SetBreadCrumbEntry('ui-tool-auditerrors', $sTitle, '', '', 'fas fa-stethoscope', iTopWebPage::ENUM_BREADCRUMB_ENTRY_ICON_TYPE_CSS_CLASSES); - $oBackButton = ButtonUIBlockFactory::MakeIconLink('fas fa-chevron-left', Dict::S('UI:Audit:InteractiveAudit:Back'), "./audit.php?".$oAppContext->GetForLink()); + $oBackButton = ButtonUIBlockFactory::MakeIconLink('fas fa-chevron-left', Dict::S('UI:Audit:InteractiveAudit:Back'), "./audit.php?".$oAppContext->GetQueryParametersString(false)); $oP->AddUiBlock($oBackButton); $oP->AddUiBlock(TitleUIBlockFactory::MakeForPage($sTitle.$oAuditRule->Get('description'))); @@ -225,7 +225,7 @@ function GetRuleResultFilter($iRuleId, $oDefinitionFilter, $oAppContext) // Adjust the size of the Textarea containing the CSV to fit almost all the remaining space $oP->add_ready_script(" $('#1>textarea').height(400);"); // adjust the size of the block $sExportUrl = utils::GetAbsoluteUrlAppRoot()."pages/audit.php?operation=csv&category=".$oAuditCategory->GetKey()."&rule=".$oAuditRule->GetKey(); - $oDownloadButton = ButtonUIBlockFactory::MakeForAlternativePrimaryAction('fas fa-chevron-left', Dict::S('UI:Audit:InteractiveAudit:Back'), "./audit.php?".$oAppContext->GetForLink()); + $oDownloadButton = ButtonUIBlockFactory::MakeForAlternativePrimaryAction('fas fa-chevron-left', Dict::S('UI:Audit:InteractiveAudit:Back'), "./audit.php?".$oAppContext->GetQueryParametersString(false)); $oP->add_ready_script("$('a[href*=\"webservices/export.php?expression=\"]').attr('href', '".$sExportUrl."&filename=audit.csv".$sAdvanced."');"); $oP->add_ready_script("$('#1 :checkbox').removeAttr('onclick').on('click', function() { var sAdvanced = ''; if (this.checked) sAdvanced = '&advanced=1'; window.location.href='$sExportUrl'+sAdvanced; } );"); @@ -248,7 +248,7 @@ function GetRuleResultFilter($iRuleId, $oDefinitionFilter, $oAppContext) $sDescription = get_class($oAuditRule).": ".$oAuditRule->GetName(); $oP->SetBreadCrumbEntry('ui-tool-auditerrors', $sTitle, $sDescription, '', 'fas fa-stethoscope', iTopWebPage::ENUM_BREADCRUMB_ENTRY_ICON_TYPE_CSS_CLASSES); - $oBackButton = ButtonUIBlockFactory::MakeIconLink('fas fa-chevron-left', Dict::S('UI:Audit:Interactive:Button:Back'), "./audit.php?".$oAppContext->GetForLink()); + $oBackButton = ButtonUIBlockFactory::MakeIconLink('fas fa-chevron-left', Dict::S('UI:Audit:Interactive:Button:Back'), "./audit.php?".$oAppContext->GetQueryParametersString(false)); $oP->AddUiBlock($oBackButton); $oP->AddUiBlock(TitleUIBlockFactory::MakeForPage($sTitle.$oAuditRule->Get('description'))); $sBlockId = 'audit_errors'; @@ -352,7 +352,7 @@ function GetRuleResultFilter($iRuleId, $oDefinitionFilter, $oAppContext) } $oP->SetBreadCrumbEntry('ui-tool-audit', $sBreadCrumbLabel, $sBreadCrumbTooltip, '', 'fas fa-stethoscope', iTopWebPage::ENUM_BREADCRUMB_ENTRY_ICON_TYPE_CSS_CLASSES); - $oBackButton = ButtonUIBlockFactory::MakeLinkNeutral("./audit.php?".$oAppContext->GetForLink(), Dict::S('UI:Audit:Interactive:Button:Back'), 'fas fa-chevron-left'); + $oBackButton = ButtonUIBlockFactory::MakeLinkNeutral("./audit.php?".$oAppContext->GetQueryParametersString(false), Dict::S('UI:Audit:Interactive:Button:Back'), 'fas fa-chevron-left'); $oP->AddUiBlock($oBackButton); $oP->AddUiBlock(TitleUIBlockFactory::MakeForPage($sTitle)); $oP->AddUiBlock(new Text($sSubTitle)); @@ -436,7 +436,7 @@ function GetRuleResultFilter($iRuleId, $oDefinitionFilter, $oAppContext) foreach ($aErrors as $aErrorRow) { $aObjectsWithErrors[$aErrorRow['id']] = true; } - $aRow['nb_errors'] = ($iErrorsCount == 0) ? '0' : "GetKey()."&rule=".$oAuditRule->GetKey()."&".$oAppContext->GetForLink()."\">$iErrorsCount GetKey()."&rule=".$oAuditRule->GetKey()."&".$oAppContext->GetForLink()."\">"; + $aRow['nb_errors'] = ($iErrorsCount == 0) ? '0' : "GetKey()."&rule=".$oAuditRule->GetKey().$oAppContext->GetQueryParametersString()."\">$iErrorsCount GetKey()."&rule=".$oAuditRule->GetKey().$oAppContext->GetQueryParametersString()."\">"; $aRow['percent_ok'] = sprintf('%.2f', 100.0 * (($iCount - $iErrorsCount) / $iCount)); $aRow['class'] = $oAuditCategory->GetReportColor($iCount, $iErrorsCount); } diff --git a/pages/preferences.php b/pages/preferences.php index a5495291c3..cec4dcb0e8 100644 --- a/pages/preferences.php +++ b/pages/preferences.php @@ -41,7 +41,7 @@ function DisplayPreferences($oP) { $oContentLayout = PageContentFactory::MakeStandardEmpty(); $oAppContext = new ApplicationContext(); - $sURL = utils::GetAbsoluteUrlAppRoot().'pages/UI.php?'.$oAppContext->GetForLink(); + $sURL = utils::GetAbsoluteUrlAppRoot().'pages/UI.php?'.$oAppContext->GetQueryParametersString(false); $oContentLayout->AddMainBlock(TitleUIBlockFactory::MakeForPage(Dict::S('UI:Preferences:Title'))); @@ -829,7 +829,7 @@ function GetToastsPositionFieldBlock(): iUIBlock // Redirect to force a reload/display of the page in case language has been changed $oAppContext = new ApplicationContext(); - $sURL = utils::GetAbsoluteUrlAppRoot().'pages/preferences.php?'.$oAppContext->GetForLink(); + $sURL = utils::GetAbsoluteUrlAppRoot().'pages/preferences.php?'.$oAppContext->GetQueryParametersString(false); $oPage->add_header('Location: '.$sURL); break; case 'apply_keyboard_shortcuts': diff --git a/pages/schema.php b/pages/schema.php index b6051b3225..b4bb5eb850 100644 --- a/pages/schema.php +++ b/pages/schema.php @@ -1174,11 +1174,7 @@ function DisplayClassDetails($oPage, $sClass, $sContext) $oAppContext = new ApplicationContext(); -$sContext = $oAppContext->GetForLink(); -if (!empty($sContext)) -{ - $sContext = '&'.$sContext; -} +$sContext = $oAppContext->GetQueryParametersString(); $operation = utils::ReadParam('operation', ''); $oLayout = new PageContentWithSideContent(); diff --git a/sources/Application/Search/searchform.class.inc.php b/sources/Application/Search/searchform.class.inc.php index b01ce94ece..c1b3cde313 100644 --- a/sources/Application/Search/searchform.class.inc.php +++ b/sources/Application/Search/searchform.class.inc.php @@ -118,7 +118,7 @@ public function GetSearchFormUIBlock(WebPage $oPage, DBObjectSet $oSet, $aExtraP } } - $sContext = $oAppContext->GetForLink(); + $sContext = $oAppContext->GetQueryParametersString(false); $sJsonExtraParams = utils::EscapeHtml(json_encode($aListParams)); $sOuterSelector = $aExtraParams['result_list_outer_selector']; diff --git a/sources/Application/UI/Base/Component/DataTable/DataTable.php b/sources/Application/UI/Base/Component/DataTable/DataTable.php index ff42777162..93f61d022f 100644 --- a/sources/Application/UI/Base/Component/DataTable/DataTable.php +++ b/sources/Application/UI/Base/Component/DataTable/DataTable.php @@ -99,9 +99,9 @@ public function SetAjaxUrl(string $sAjaxUrl) { $oAppContext = new ApplicationContext(); if(strpos ($sAjaxUrl,'?')) { - $this->sAjaxUrl = $sAjaxUrl."&".$oAppContext->GetForLink(); + $this->sAjaxUrl = $sAjaxUrl.$oAppContext->GetQueryParametersString(); } else { - $this->sAjaxUrl = $sAjaxUrl."?".$oAppContext->GetForLink(); + $this->sAjaxUrl = $sAjaxUrl."?".$oAppContext->GetQueryParametersString(false); } } else diff --git a/sources/Application/UI/Base/Component/DataTable/DataTableUIBlockFactory.php b/sources/Application/UI/Base/Component/DataTable/DataTableUIBlockFactory.php index ab083494c0..641c8aef23 100644 --- a/sources/Application/UI/Base/Component/DataTable/DataTableUIBlockFactory.php +++ b/sources/Application/UI/Base/Component/DataTable/DataTableUIBlockFactory.php @@ -819,7 +819,7 @@ public static function GetOptionsForRendering(array $aColumns, string $sSelectMo "columns" => $aColumnsDefinitions, "allColumns" => $aColumns, 'ajax' => '$.fn.dataTable.pipeline( { - "url": "ajax.render.php?'.$oAppContext->GetForLink().'", + "url": "ajax.render.php?'.$oAppContext->GetQueryParametersString(false).'", "data": '.$sAjaxData.', "method": "post", "pages": 5 // number of pages to cache diff --git a/sources/Application/UI/Links/Direct/BlockDirectLinkSetEditTable.php b/sources/Application/UI/Links/Direct/BlockDirectLinkSetEditTable.php index b302c5ce76..aece993894 100644 --- a/sources/Application/UI/Links/Direct/BlockDirectLinkSetEditTable.php +++ b/sources/Application/UI/Links/Direct/BlockDirectLinkSetEditTable.php @@ -98,7 +98,7 @@ public function __construct(UILinksWidgetDirect $oUILinksDirectWidget, string $s 'selection_title' => Dict::Format('UI:SelectionOf_Class', MetaModel::GetName($this->oUILinksDirectWidget->GetLinkedClass())), ); $oContext = new ApplicationContext(); - $this->sSubmitUrl = utils::GetAbsoluteUrlAppRoot().'pages/ajax.render.php?'.$oContext->GetForLink(); + $this->sSubmitUrl = utils::GetAbsoluteUrlAppRoot().'pages/ajax.render.php?'.$oContext->GetQueryParametersString(false); // Don't automatically launch the search if the table is huge $bDoSearch = !utils::IsHighCardinality($this->oUILinksDirectWidget->GetLinkedClass()); diff --git a/sources/Application/UI/Links/Set/BlockLinkSetDisplayAsProperty.php b/sources/Application/UI/Links/Set/BlockLinkSetDisplayAsProperty.php index 4dad47e81a..03e50126dd 100644 --- a/sources/Application/UI/Links/Set/BlockLinkSetDisplayAsProperty.php +++ b/sources/Application/UI/Links/Set/BlockLinkSetDisplayAsProperty.php @@ -97,7 +97,7 @@ private function Init() $this->oTwigEnv = TwigHelper::GetTwigEnvironment(TwigHelper::ENUM_TEMPLATES_BASE_PATH_BACKOFFICE); $oAppContext = new ApplicationContext(); - $this->sAppContext = $oAppContext->GetForLink(); + $this->sAppContext = $oAppContext->GetQueryParametersString(); $this->sUIPage = cmdbAbstractObject::ComputeStandardUIPage($this->sTargetClass); } @@ -160,7 +160,7 @@ private function GenerateLinkUrl($id): string { return ' href="' .utils::GetAbsoluteUrlAppRoot() - ."pages/$this->sUIPage?operation=details&class=$this->sTargetClass&id=$id&$this->sAppContext" + ."pages/$this->sUIPage?operation=details&class=$this->sTargetClass&id=$id$this->sAppContext" .'" target="_self"'; } } \ No newline at end of file diff --git a/sources/Application/WebPage/NiceWebPage.php b/sources/Application/WebPage/NiceWebPage.php index 4e105a5dc5..6bec3bc745 100644 --- a/sources/Application/WebPage/NiceWebPage.php +++ b/sources/Application/WebPage/NiceWebPage.php @@ -204,7 +204,7 @@ public function GetAbsoluteUrlModulesRoot() function GetApplicationContext() { $oAppContext = new ApplicationContext(); - return $oAppContext->GetForLink(); + return $oAppContext->GetQueryParametersString(false); } // By Rom, used by CSVImport and Advanced search diff --git a/sources/Controller/AjaxRenderController.php b/sources/Controller/AjaxRenderController.php index 8ca0967e2f..b1f835fea1 100644 --- a/sources/Controller/AjaxRenderController.php +++ b/sources/Controller/AjaxRenderController.php @@ -640,7 +640,7 @@ public static function RefreshDashletList(string $sStyle, string $sFilter): arra $aResult = array(); $oAppContext = new ApplicationContext(); - $sParams = $oAppContext->GetForLink(); + $sParams = $oAppContext->GetQueryParametersString(); foreach ($aGroupBy as $iRow => $iCount) { // Build the search for this subset $oSubsetSearch = $oFilter->DeepClone(); @@ -655,7 +655,7 @@ public static function RefreshDashletList(string $sStyle, string $sFilter): arra $aResult[] = array( 'group' => $aLabels[$iRow], - 'value' => "$iCount", + 'value' => "$iCount", ); // TO DO: add the context information } From 0f7fa4b05b971227d28f303fa7170f0a00d462b3 Mon Sep 17 00:00:00 2001 From: bdalsass Date: Tue, 3 Jun 2025 10:01:33 +0200 Subject: [PATCH 2/3] =?UTF-8?q?N=C2=B08148=20-=20CAS=20problem=20when=20se?= =?UTF-8?q?nding=20a=20link=20ending=20in=20&=20-=20Add=20a=20test?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/ApplicationContextTest.php | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 tests/php-unit-tests/unitary-tests/application/ApplicationContextTest.php diff --git a/tests/php-unit-tests/unitary-tests/application/ApplicationContextTest.php b/tests/php-unit-tests/unitary-tests/application/ApplicationContextTest.php new file mode 100644 index 0000000000..45625acec4 --- /dev/null +++ b/tests/php-unit-tests/unitary-tests/application/ApplicationContextTest.php @@ -0,0 +1,23 @@ +GetQueryParametersString(); + $this->assertEquals($sExpected, $sActual, 'Query parameters string should include all request parameters prefixed with &'); + + $sExpected = 'c[org_id]=3&c[menu]=TargetOverview'; + $sActual = $oApplicationContext->GetQueryParametersString(false); + $this->assertEquals($sExpected, $sActual, 'Query parameters string should not start with & when $bIncludeAmpersand is false'); + } + +} \ No newline at end of file From 1f4f2acdd0ff26b7fa2eba703484e0a52c1bab81 Mon Sep 17 00:00:00 2001 From: bdalsass Date: Fri, 6 Jun 2025 15:06:06 +0200 Subject: [PATCH 3/3] =?UTF-8?q?N=C2=B08148=20-=20CAS=20problem=20when=20se?= =?UTF-8?q?nding=20a=20link=20ending=20in=20&=20-=20Code=20review=20update?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/applicationcontext.class.inc.php | 24 ++----------------- application/cmdbabstract.class.inc.php | 4 ++-- application/dashlet.class.inc.php | 2 +- application/displayblock.class.inc.php | 18 +++++++------- application/shortcut.class.inc.php | 2 +- application/utils.inc.php | 4 ++-- core/attributedef.class.inc.php | 4 ++-- core/bulkchange.class.inc.php | 4 ++-- core/displayablegraph.class.inc.php | 2 +- pages/UI.php | 12 +++++----- pages/audit.php | 10 ++++---- pages/preferences.php | 4 ++-- pages/schema.php | 2 +- .../Search/searchform.class.inc.php | 2 +- .../UI/Base/Component/DataTable/DataTable.php | 4 ++-- .../DataTable/DataTableUIBlockFactory.php | 2 +- .../Direct/BlockDirectLinkSetEditTable.php | 2 +- .../Set/BlockLinkSetDisplayAsProperty.php | 2 +- sources/Application/WebPage/NiceWebPage.php | 2 +- sources/Controller/AjaxRenderController.php | 2 +- .../application/ApplicationContextTest.php | 6 ++--- 21 files changed, 47 insertions(+), 67 deletions(-) diff --git a/application/applicationcontext.class.inc.php b/application/applicationcontext.class.inc.php index 3b2b4987b8..ec29db46da 100644 --- a/application/applicationcontext.class.inc.php +++ b/application/applicationcontext.class.inc.php @@ -196,28 +196,8 @@ public function GetCurrentValue($sParamName, $defaultValue = '') * Returns the context as string with the format name1=value1&name2=value2.... * @return string The context as a string to be appended to an href property * - * @deprecated since 3.2.2 Use GetQueryParametersString() instead, responsible in adding the leading '&' */ - public function GetForLink() - { - $aParams = array(); - foreach($this->aValues as $sName => $sValue) - { - $aParams[] = "c[$sName]".'='.urlencode($sValue); - } - return implode("&", $aParams); - } - - /** - * Returns the context as string with the format c[name1]=value1&c[name2]=value2.... - * Add a leading ampersand if requested - * - * @param bool $bWithLeadingAmpersand - * - * @return string - * @since 3.2.2 - */ - public function GetQueryParametersString(bool $bWithLeadingAmpersand = true): string + public function GetForLink(bool $bWithLeadingAmpersand = false) { // If there are no parameters, return an empty string if(empty($this->aValues)){ @@ -417,7 +397,7 @@ public static function MakeObjectUrl($sObjClass, $sObjKey, $sUrlMakerClass = nul $sUrl = call_user_func(array($sUrlMakerClass, 'MakeObjectUrl'), $sObjClass, $sObjKey); if (utils::StrLen($sUrl) > 0) { if ($bWithNavigationContext) { - return $sUrl.$oAppContext->GetQueryParametersString(); + return $sUrl.$oAppContext->GetForLink(true); } else { return $sUrl; } diff --git a/application/cmdbabstract.class.inc.php b/application/cmdbabstract.class.inc.php index 04ab9233f1..e491882ad0 100644 --- a/application/cmdbabstract.class.inc.php +++ b/application/cmdbabstract.class.inc.php @@ -311,7 +311,7 @@ public static function ReloadAndDisplay($oPage, $oObj, $aParams) { $sParams .= $sName.'='.urlencode($value).'&'; // Always add a trailing & } - $sUrl = utils::GetAbsoluteUrlAppRoot().'pages/'.$oObj->GetUIPage().'?'.$sParams.'class='.get_class($oObj).'&id='.$oObj->getKey().$oAppContext->GetQueryParametersString().'&a=1'; + $sUrl = utils::GetAbsoluteUrlAppRoot().'pages/'.$oObj->GetUIPage().'?'.$sParams.'class='.get_class($oObj).'&id='.$oObj->getKey().$oAppContext->GetForLink(true).'&a=1'; $oPage->add_early_script(<<add($oAppContext->GetForForm()); // Hook the cancel button via jQuery so that it can be unhooked easily as well if needed - $sDefaultUrl = utils::GetAbsoluteUrlAppRoot().'pages/UI.php?operation=search_form&class='.$sClass.$oAppContext->GetQueryParametersString(); + $sDefaultUrl = utils::GetAbsoluteUrlAppRoot().'pages/UI.php?operation=search_form&class='.$sClass.$oAppContext->GetForLink(true); $sCancelButtonOnClickScript = "let fOnClick{$this->m_iFormId}CancelButton = "; if(isset($aExtraParams['js_handlers']['cancel_button_on_click'])){ diff --git a/application/dashlet.class.inc.php b/application/dashlet.class.inc.php index 82a75d1029..e257662683 100644 --- a/application/dashlet.class.inc.php +++ b/application/dashlet.class.inc.php @@ -2138,7 +2138,7 @@ public function Render($oPage, $bEditMode = false, $aExtraParams = array()) $oSet = new DBObjectSet($oFilter); $iCount = $oSet->Count(); $oAppContext = new ApplicationContext(); - $sHyperlink = utils::GetAbsoluteUrlAppRoot().'pages/UI.php?operation=search'.$oAppContext->GetQueryParametersString().'&filter='.rawurlencode($oFilter->serialize()); + $sHyperlink = utils::GetAbsoluteUrlAppRoot().'pages/UI.php?operation=search'.$oAppContext->GetForLink(true).'&filter='.rawurlencode($oFilter->serialize()); $oSubTitle->AddHtml(''.Dict::Format(str_replace('_', ':', $sSubtitle), $iCount).''); return $oPanel; diff --git a/application/displayblock.class.inc.php b/application/displayblock.class.inc.php index 403ea4995b..0c0e5d0c56 100644 --- a/application/displayblock.class.inc.php +++ b/application/displayblock.class.inc.php @@ -1124,7 +1124,7 @@ protected function RenderSummary(array $aExtraParams): iUIBlock $oSingleGroupByValueFilter->SetShowObsoleteData($this->m_bShowObsoleteData); } $sHyperlink = utils::GetAbsoluteUrlAppRoot() - .'pages/UI.php?operation=search'.$oAppContext->GetQueryParametersString() + .'pages/UI.php?operation=search'.$oAppContext->GetForLink(true) .'&filter='.rawurlencode($oSingleGroupByValueFilter->serialize()); $aCounts[$sStateValue] = ['link' => $sHyperlink, 'label' => $aCounts[$sStateValue]]; } @@ -1232,7 +1232,7 @@ protected function RenderActions(array $aExtraParams): iUIBlock $iCount = $this->m_oSet->Count(); $sClassLabel = MetaModel::GetName($sClass); $sClassIconUrl = MetaModel::GetClassIcon($sClass, false); - $sHyperlink = utils::GetAbsoluteUrlAppRoot().'pages/UI.php?operation=search'.$oAppContext->GetQueryParametersString().'&filter='.rawurlencode($this->m_oFilter->serialize()); + $sHyperlink = utils::GetAbsoluteUrlAppRoot().'pages/UI.php?operation=search'.$oAppContext->GetForLink(true).'&filter='.rawurlencode($this->m_oFilter->serialize()); $aExtraParams['query_params'] = $this->m_oFilter->GetInternalParams(); $aRefreshParams = [ @@ -1241,7 +1241,7 @@ protected function RenderActions(array $aExtraParams): iUIBlock ]; if (UserRights::IsActionAllowed($sClass, UR_ACTION_MODIFY)) { - $sCreateActionUrl = utils::GetAbsoluteUrlAppRoot().'pages/UI.php?operation=new&class='.$sClass.$oAppContext->GetQueryParametersString(); + $sCreateActionUrl = utils::GetAbsoluteUrlAppRoot().'pages/UI.php?operation=new&class='.$sClass.$oAppContext->GetForLink(true); $sCreateActionLabel = Dict::Format('UI:Button:Create'); $oBlock = DashletFactory::MakeForDashletBadge($sClassIconUrl, $sHyperlink, $iCount, $sClassLabel, $sCreateActionUrl, $sCreateActionLabel, $aRefreshParams); @@ -1289,7 +1289,7 @@ protected function RenderCount(array $aExtraParams): iUIBlock $aData = array(); $oAppContext = new ApplicationContext(); - $sParams = $oAppContext->GetQueryParametersString(); + $sParams = $oAppContext->GetForLink(true); foreach ($aGroupBy as $iRow => $iCount) { // Build the search for this subset $oSubsetSearch = $this->m_oFilter->DeepClone(); @@ -1636,7 +1636,7 @@ protected function RenderChart(?string $sChartId, array $aQueryParams, array $aE $sGroupByExpr = isset($aExtraParams['group_by_expr']) ? '¶ms[group_by_expr]='.$aExtraParams['group_by_expr'] : ''; $sFilter = $this->m_oFilter->serialize(false, $aQueryParams); $oContext = new ApplicationContext(); - $sContextParam = $oContext->GetQueryParametersString(); + $sContextParam = $oContext->GetForLink(true); $sAggregationFunction = isset($aExtraParams['aggregation_function']) ? $aExtraParams['aggregation_function'] : ''; $sAggregationAttr = isset($aExtraParams['aggregation_attribute']) ? $aExtraParams['aggregation_attribute'] : ''; $sLimit = isset($aExtraParams['limit']) ? $aExtraParams['limit'] : ''; @@ -1682,7 +1682,7 @@ protected function RenderChartAjax(array $aExtraParams) $sJSURLs = ''; $oContext = new ApplicationContext(); - $sContextParam = $oContext->GetQueryParametersString(); + $sContextParam = $oContext->GetForLink(true); if (isset($aExtraParams['group_by'])) { $this->MakeGroupByQuery($aExtraParams, $oGroupByExp, $sGroupByLabel, $aGroupBy, $sAggregationFunction, $sFctVar, $sAggregationAttr, $sSql); @@ -1788,7 +1788,7 @@ protected function RenderCsv(ApplicationContext $oAppContext) $oBlock->sCsvFile = strtolower($this->m_oFilter->GetClass()).'.csv'; $oBlock->sDownloadLink = utils::GetAbsoluteUrlAppRoot().'webservices/export.php?expression='.urlencode($this->m_oFilter->ToOQL(true)).'&format=csv&filename='.urlencode($oBlock->sCsvFile); - $oBlock->sLinkToToggle = utils::GetAbsoluteUrlAppRoot().'pages/UI.php?operation=search'.$oAppContext->GetQueryParametersString().'&filter='.rawurlencode($this->m_oFilter->serialize()).'&format=csv'; + $oBlock->sLinkToToggle = utils::GetAbsoluteUrlAppRoot().'pages/UI.php?operation=search'.$oAppContext->GetForLink(true).'&filter='.rawurlencode($this->m_oFilter->serialize()).'&format=csv'; // Pass the parameters via POST, since expression may be very long $aParamsToPost = array( 'expression' => $this->m_oFilter->ToOQL(true), @@ -1888,7 +1888,7 @@ public function GetRenderContent(WebPage $oPage, array $aExtraParams, string $sI && (!isset($aExtraParams['menu']) || $aExtraParams['menu'] === "1" || $aExtraParams['menu'] === true) ) { $oAppContext = new ApplicationContext(); - $sContext = $oAppContext->GetQueryParametersString(); + $sContext = $oAppContext->GetForLink(true); $sFilter = $this->GetFilter()->serialize(); @@ -2578,7 +2578,7 @@ private function PrepareUrlForStandardMenuAction(string $sClass, string $sUrlPar $sUrl = "{$sRootUrl}pages/{$sUIPage}?{$sUrlParams}"; $oAppContext = new ApplicationContext(); - $sContext = $oAppContext->GetQueryParametersString(); + $sContext = $oAppContext->GetForLink(true); return $sUrl . $sContext; } diff --git a/application/shortcut.class.inc.php b/application/shortcut.class.inc.php index 94d4949f5c..a213cb8cd3 100644 --- a/application/shortcut.class.inc.php +++ b/application/shortcut.class.inc.php @@ -282,7 +282,7 @@ public static function GetCreationDlgFromOQL($oPage, $sOQL, $sTableSettings) $sCancelButtonLabel = Dict::S('UI:Button:Cancel'); $oAppContext = new ApplicationContext(); - $sContext = $oAppContext->GetQueryParametersString(false); + $sContext = $oAppContext->GetForLink(); $sRateTitle = addslashes(Dict::Format('Class:ShortcutOQL/Attribute:auto_reload_sec/tip', MetaModel::GetConfig()->Get('min_reload_interval'))); diff --git a/application/utils.inc.php b/application/utils.inc.php index aee95f98c2..649483a682 100644 --- a/application/utils.inc.php +++ b/application/utils.inc.php @@ -1516,7 +1516,7 @@ public static function GetPopupMenuItemsBlock(iUIBlock &$oContainerBlock, $iMenu case iPopupMenuExtension::MENU_OBJLIST_TOOLKIT: /** @var \DBObjectSet $param */ $oAppContext = new ApplicationContext(); - $sContext = $oAppContext->GetQueryParametersString(); + $sContext = $oAppContext->GetForLink(true); $sDataTableId = is_null($sDataTableId) ? '' : $sDataTableId; $sUIPage = cmdbAbstractObject::ComputeStandardUIPage($param->GetFilter()->GetClass()); $sOQL = addslashes($param->GetFilter()->ToOQL(true)); @@ -1697,7 +1697,7 @@ public static function GetDataTableSearchUrl(DBSearch $oFilter, array $aExtraPar $sUrl = $sAppRootUrl .'pages/UI.php?operation=search' - .$oAppContext->GetQueryParametersString() + .$oAppContext->GetForLink(true) .'&filter='.rawurlencode($oDataTableSearchFilter->serialize()); $sUrl .= '&aParams='.rawurlencode($sParams); // Not working... yet, cause not handled by UI.php diff --git a/core/attributedef.class.inc.php b/core/attributedef.class.inc.php index a520e4d0cc..1e26b9a7fe 100644 --- a/core/attributedef.class.inc.php +++ b/core/attributedef.class.inc.php @@ -10954,7 +10954,7 @@ public function GenerateViewHtmlForValues($aValues, $sCssClass = '', $bWithLink $sDescription = utils::EscapeHtml($this->GetValueDescription($sValue)); $oFilter = DBSearch::FromOQL("SELECT $sClass WHERE $sAttCode MATCHES '$sValue'"); $oAppContext = new ApplicationContext(); - $sContext = $oAppContext->GetQueryParametersString(); + $sContext = $oAppContext->GetForLink(true); $sUIPage = cmdbAbstractObject::ComputeStandardUIPage($oFilter->GetClass()); $sFilter = rawurlencode($oFilter->serialize()); $sLink = ''; @@ -12276,7 +12276,7 @@ public function GenerateViewHtmlForValues($aValues, $sCssClass = '', $bWithLink $sTagDescription = $oTag->Get('description'); $oFilter = DBSearch::FromOQL("SELECT $sClass WHERE $sAttCode MATCHES '$sTagCode'"); $oAppContext = new ApplicationContext(); - $sContext = $oAppContext->GetQueryParametersString(); + $sContext = $oAppContext->GetForLink(true); $sUIPage = cmdbAbstractObject::ComputeStandardUIPage($oFilter->GetClass()); $sFilter = rawurlencode($oFilter->serialize()); diff --git a/core/bulkchange.class.inc.php b/core/bulkchange.class.inc.php index 57b4baf7ca..df6a238e55 100644 --- a/core/bulkchange.class.inc.php +++ b/core/bulkchange.class.inc.php @@ -1406,7 +1406,7 @@ static function DisplayImportHistory(WebPage $oPage, $bFromAjax = false, $bShowA $aDetails = array(); while ($oChange = $oBulkChanges->Fetch()) { - $sDate = ''.$oChange->Get('date').''; + $sDate = ''.$oChange->Get('date').''; $sUser = $oChange->GetUserName(); if (preg_match('/^(.*)\\(CSV\\)$/i', $oChange->Get('userinfo'), $aMatches)) { @@ -1482,7 +1482,7 @@ static function DisplayImportHistory(WebPage $oPage, $bFromAjax = false, $bShowA ); - $sAppContext = $oAppContext->GetQueryParametersString(false); + $sAppContext = $oAppContext->GetForLink(); $oPage->add_script( <<InitFromGraphviz(); $sExportAsPdfURL = utils::GetAbsoluteUrlAppRoot().'pages/ajax.render.php?operation=relation_pdf&relation='.$sRelation.'&direction='.($this->bDirectionDown ? 'down' : 'up'); - $sContext = $oAppContext->GetQueryParametersString(); + $sContext = $oAppContext->GetForLink(true); $sDrillDownURL = utils::GetAbsoluteUrlAppRoot().'pages/UI.php?operation=details&class=%1$s&id=%2$s'.$sContext; $sExportAsDocumentURL = utils::GetAbsoluteUrlAppRoot().'pages/ajax.render.php?operation=relation_attachment&relation='.$sRelation.'&direction='.($this->bDirectionDown ? 'down' : 'up'); $sLoadFromURL = utils::GetAbsoluteUrlAppRoot().'pages/ajax.render.php?operation=relation_json&relation='.$sRelation.'&direction='.($this->bDirectionDown ? 'down' : 'up'); diff --git a/pages/UI.php b/pages/UI.php index acfb9ada5e..c8efc163e7 100644 --- a/pages/UI.php +++ b/pages/UI.php @@ -90,7 +90,7 @@ function ApplyNextAction(Webpage $oP, CMDBObject $oObj, $sNextAction) $oAppContext = new ApplicationContext(); //echo "

Missing Attributes

".print_r($aExpectedAttributes, true)."

\n"; - $oP->add_header('Location: '.utils::GetAbsoluteUrlAppRoot().'pages/UI.php?operation=stimulus&class='.get_class($oObj).'&stimulus='.$sNextAction.'&id='.$oObj->getKey().$oAppContext->GetQueryParametersString()); + $oP->add_header('Location: '.utils::GetAbsoluteUrlAppRoot().'pages/UI.php?operation=stimulus&class='.get_class($oObj).'&stimulus='.$sNextAction.'&id='.$oObj->getKey().$oAppContext->GetForLink(true)); } } @@ -101,7 +101,7 @@ function ReloadAndDisplay($oPage, $oObj, $sMessageId = '', $sMessage = '', $sSev { cmdbAbstractObject::SetSessionMessage(get_class($oObj), $oObj->GetKey(), $sMessageId, $sMessage, $sSeverity, 0, true /* must not exist */); } - $oPage->add_header('Location: '.utils::GetAbsoluteUrlAppRoot().'pages/UI.php?operation=details&class='.get_class($oObj).'&id='.$oObj->getKey().$oAppContext->GetQueryParametersString()); + $oPage->add_header('Location: '.utils::GetAbsoluteUrlAppRoot().'pages/UI.php?operation=details&class='.get_class($oObj).'&id='.$oObj->getKey().$oAppContext->GetForLink(true)); } /** @@ -993,7 +993,7 @@ function DisplayNavigatorGroupTab($oP) $oForm->AddHtml($oP->GetDetails($aDetails)); $oForm->AddHtml(''); - $sURL = "./UI.php?operation=search&filter=".urlencode($sFilter).$oAppContext->GetQueryParametersString(); + $sURL = "./UI.php?operation=search&filter=".urlencode($sFilter).$oAppContext->GetForLink(true); $oCancelButton = ButtonUIBlockFactory::MakeForCancel(Dict::S('UI:Button:Cancel'), 'cancel', 'cancel'); $oCancelButton->SetOnClickJsCode("window.location.href='$sURL'"); $oForm->AddSubBlock($oCancelButton); @@ -1165,7 +1165,7 @@ function DisplayNavigatorGroupTab($oP) $oP->AddUiBlock($oBlock); // Back to the list - $sURL = "./UI.php?operation=search&filter=".urlencode($sFilter).$oAppContext->GetQueryParametersString(); + $sURL = "./UI.php?operation=search&filter=".urlencode($sFilter).$oAppContext->GetForLink(true); $oSubmitButton = ButtonUIBlockFactory::MakeForSecondaryAction(Dict::S('UI:Button:Done'), 'submit', 'submit', true); $oSubmitButton->SetOnClickJsCode("window.location.href='$sURL'"); $oToolbarButtons = ToolbarUIBlockFactory::MakeStandard(null); @@ -1606,7 +1606,7 @@ public static function OperationFormForModifyAll(iTopWebPage $oP, ApplicationCon // Add user filter $oFullSetFilter->UpdateContextFromUser(); $aSelectedObj = utils::ReadMultipleSelection($oFullSetFilter); - $sCancelUrl = "./UI.php?operation=search&filter=".urlencode($sFilter).$oAppContext->GetQueryParametersString(); + $sCancelUrl = "./UI.php?operation=search&filter=".urlencode($sFilter).$oAppContext->GetForLink(true); $aContext = array('filter' => utils::EscapeHtml($sFilter)); cmdbAbstractObject::DisplayBulkModifyForm($oP, $sClass, $aSelectedObj, 'preview_or_modify_all', $sCancelUrl, array(), $aContext); } @@ -1640,7 +1640,7 @@ public static function OperationPreviewOrModifyAll(iTopWebPage $oP, ApplicationC throw new ApplicationException(Dict::Format('UI:Error:2ParametersMissing', 'class', 'selectObj')); } $aSelectedObj = explode(',', $sSelectedObj); - $sCancelUrl = "./UI.php?operation=search&filter=".urlencode($sFilter).$oAppContext->GetQueryParametersString(); + $sCancelUrl = "./UI.php?operation=search&filter=".urlencode($sFilter).$oAppContext->GetForLink(true); $aContext = array( 'filter' => utils::EscapeHtml($sFilter), 'selectObj' => $sSelectedObj, diff --git a/pages/audit.php b/pages/audit.php index c581f86304..f4c705d316 100644 --- a/pages/audit.php +++ b/pages/audit.php @@ -213,7 +213,7 @@ function GetRuleResultFilter($iRuleId, $oDefinitionFilter, $oAppContext) $sTitle = Dict::S('UI:Audit:AuditErrors'); $oP->SetBreadCrumbEntry('ui-tool-auditerrors', $sTitle, '', '', 'fas fa-stethoscope', iTopWebPage::ENUM_BREADCRUMB_ENTRY_ICON_TYPE_CSS_CLASSES); - $oBackButton = ButtonUIBlockFactory::MakeIconLink('fas fa-chevron-left', Dict::S('UI:Audit:InteractiveAudit:Back'), "./audit.php?".$oAppContext->GetQueryParametersString(false)); + $oBackButton = ButtonUIBlockFactory::MakeIconLink('fas fa-chevron-left', Dict::S('UI:Audit:InteractiveAudit:Back'), "./audit.php?".$oAppContext->GetForLink()); $oP->AddUiBlock($oBackButton); $oP->AddUiBlock(TitleUIBlockFactory::MakeForPage($sTitle.$oAuditRule->Get('description'))); @@ -225,7 +225,7 @@ function GetRuleResultFilter($iRuleId, $oDefinitionFilter, $oAppContext) // Adjust the size of the Textarea containing the CSV to fit almost all the remaining space $oP->add_ready_script(" $('#1>textarea').height(400);"); // adjust the size of the block $sExportUrl = utils::GetAbsoluteUrlAppRoot()."pages/audit.php?operation=csv&category=".$oAuditCategory->GetKey()."&rule=".$oAuditRule->GetKey(); - $oDownloadButton = ButtonUIBlockFactory::MakeForAlternativePrimaryAction('fas fa-chevron-left', Dict::S('UI:Audit:InteractiveAudit:Back'), "./audit.php?".$oAppContext->GetQueryParametersString(false)); + $oDownloadButton = ButtonUIBlockFactory::MakeForAlternativePrimaryAction('fas fa-chevron-left', Dict::S('UI:Audit:InteractiveAudit:Back'), "./audit.php?".$oAppContext->GetForLink()); $oP->add_ready_script("$('a[href*=\"webservices/export.php?expression=\"]').attr('href', '".$sExportUrl."&filename=audit.csv".$sAdvanced."');"); $oP->add_ready_script("$('#1 :checkbox').removeAttr('onclick').on('click', function() { var sAdvanced = ''; if (this.checked) sAdvanced = '&advanced=1'; window.location.href='$sExportUrl'+sAdvanced; } );"); @@ -248,7 +248,7 @@ function GetRuleResultFilter($iRuleId, $oDefinitionFilter, $oAppContext) $sDescription = get_class($oAuditRule).": ".$oAuditRule->GetName(); $oP->SetBreadCrumbEntry('ui-tool-auditerrors', $sTitle, $sDescription, '', 'fas fa-stethoscope', iTopWebPage::ENUM_BREADCRUMB_ENTRY_ICON_TYPE_CSS_CLASSES); - $oBackButton = ButtonUIBlockFactory::MakeIconLink('fas fa-chevron-left', Dict::S('UI:Audit:Interactive:Button:Back'), "./audit.php?".$oAppContext->GetQueryParametersString(false)); + $oBackButton = ButtonUIBlockFactory::MakeIconLink('fas fa-chevron-left', Dict::S('UI:Audit:Interactive:Button:Back'), "./audit.php?".$oAppContext->GetForLink()); $oP->AddUiBlock($oBackButton); $oP->AddUiBlock(TitleUIBlockFactory::MakeForPage($sTitle.$oAuditRule->Get('description'))); $sBlockId = 'audit_errors'; @@ -352,7 +352,7 @@ function GetRuleResultFilter($iRuleId, $oDefinitionFilter, $oAppContext) } $oP->SetBreadCrumbEntry('ui-tool-audit', $sBreadCrumbLabel, $sBreadCrumbTooltip, '', 'fas fa-stethoscope', iTopWebPage::ENUM_BREADCRUMB_ENTRY_ICON_TYPE_CSS_CLASSES); - $oBackButton = ButtonUIBlockFactory::MakeLinkNeutral("./audit.php?".$oAppContext->GetQueryParametersString(false), Dict::S('UI:Audit:Interactive:Button:Back'), 'fas fa-chevron-left'); + $oBackButton = ButtonUIBlockFactory::MakeLinkNeutral("./audit.php?".$oAppContext->GetForLink(), Dict::S('UI:Audit:Interactive:Button:Back'), 'fas fa-chevron-left'); $oP->AddUiBlock($oBackButton); $oP->AddUiBlock(TitleUIBlockFactory::MakeForPage($sTitle)); $oP->AddUiBlock(new Text($sSubTitle)); @@ -436,7 +436,7 @@ function GetRuleResultFilter($iRuleId, $oDefinitionFilter, $oAppContext) foreach ($aErrors as $aErrorRow) { $aObjectsWithErrors[$aErrorRow['id']] = true; } - $aRow['nb_errors'] = ($iErrorsCount == 0) ? '0' : "GetKey()."&rule=".$oAuditRule->GetKey().$oAppContext->GetQueryParametersString()."\">$iErrorsCount GetKey()."&rule=".$oAuditRule->GetKey().$oAppContext->GetQueryParametersString()."\">"; + $aRow['nb_errors'] = ($iErrorsCount == 0) ? '0' : "GetKey()."&rule=".$oAuditRule->GetKey().$oAppContext->GetForLink(true)."\">$iErrorsCount GetKey()."&rule=".$oAuditRule->GetKey().$oAppContext->GetForLink(true)."\">"; $aRow['percent_ok'] = sprintf('%.2f', 100.0 * (($iCount - $iErrorsCount) / $iCount)); $aRow['class'] = $oAuditCategory->GetReportColor($iCount, $iErrorsCount); } diff --git a/pages/preferences.php b/pages/preferences.php index cec4dcb0e8..a5495291c3 100644 --- a/pages/preferences.php +++ b/pages/preferences.php @@ -41,7 +41,7 @@ function DisplayPreferences($oP) { $oContentLayout = PageContentFactory::MakeStandardEmpty(); $oAppContext = new ApplicationContext(); - $sURL = utils::GetAbsoluteUrlAppRoot().'pages/UI.php?'.$oAppContext->GetQueryParametersString(false); + $sURL = utils::GetAbsoluteUrlAppRoot().'pages/UI.php?'.$oAppContext->GetForLink(); $oContentLayout->AddMainBlock(TitleUIBlockFactory::MakeForPage(Dict::S('UI:Preferences:Title'))); @@ -829,7 +829,7 @@ function GetToastsPositionFieldBlock(): iUIBlock // Redirect to force a reload/display of the page in case language has been changed $oAppContext = new ApplicationContext(); - $sURL = utils::GetAbsoluteUrlAppRoot().'pages/preferences.php?'.$oAppContext->GetQueryParametersString(false); + $sURL = utils::GetAbsoluteUrlAppRoot().'pages/preferences.php?'.$oAppContext->GetForLink(); $oPage->add_header('Location: '.$sURL); break; case 'apply_keyboard_shortcuts': diff --git a/pages/schema.php b/pages/schema.php index b4bb5eb850..343c7bcb5b 100644 --- a/pages/schema.php +++ b/pages/schema.php @@ -1174,7 +1174,7 @@ function DisplayClassDetails($oPage, $sClass, $sContext) $oAppContext = new ApplicationContext(); -$sContext = $oAppContext->GetQueryParametersString(); +$sContext = $oAppContext->GetForLink(true); $operation = utils::ReadParam('operation', ''); $oLayout = new PageContentWithSideContent(); diff --git a/sources/Application/Search/searchform.class.inc.php b/sources/Application/Search/searchform.class.inc.php index c1b3cde313..b01ce94ece 100644 --- a/sources/Application/Search/searchform.class.inc.php +++ b/sources/Application/Search/searchform.class.inc.php @@ -118,7 +118,7 @@ public function GetSearchFormUIBlock(WebPage $oPage, DBObjectSet $oSet, $aExtraP } } - $sContext = $oAppContext->GetQueryParametersString(false); + $sContext = $oAppContext->GetForLink(); $sJsonExtraParams = utils::EscapeHtml(json_encode($aListParams)); $sOuterSelector = $aExtraParams['result_list_outer_selector']; diff --git a/sources/Application/UI/Base/Component/DataTable/DataTable.php b/sources/Application/UI/Base/Component/DataTable/DataTable.php index 93f61d022f..03d3d88356 100644 --- a/sources/Application/UI/Base/Component/DataTable/DataTable.php +++ b/sources/Application/UI/Base/Component/DataTable/DataTable.php @@ -99,9 +99,9 @@ public function SetAjaxUrl(string $sAjaxUrl) { $oAppContext = new ApplicationContext(); if(strpos ($sAjaxUrl,'?')) { - $this->sAjaxUrl = $sAjaxUrl.$oAppContext->GetQueryParametersString(); + $this->sAjaxUrl = $sAjaxUrl.$oAppContext->GetForLink(true); } else { - $this->sAjaxUrl = $sAjaxUrl."?".$oAppContext->GetQueryParametersString(false); + $this->sAjaxUrl = $sAjaxUrl."?".$oAppContext->GetForLink(); } } else diff --git a/sources/Application/UI/Base/Component/DataTable/DataTableUIBlockFactory.php b/sources/Application/UI/Base/Component/DataTable/DataTableUIBlockFactory.php index 641c8aef23..ab083494c0 100644 --- a/sources/Application/UI/Base/Component/DataTable/DataTableUIBlockFactory.php +++ b/sources/Application/UI/Base/Component/DataTable/DataTableUIBlockFactory.php @@ -819,7 +819,7 @@ public static function GetOptionsForRendering(array $aColumns, string $sSelectMo "columns" => $aColumnsDefinitions, "allColumns" => $aColumns, 'ajax' => '$.fn.dataTable.pipeline( { - "url": "ajax.render.php?'.$oAppContext->GetQueryParametersString(false).'", + "url": "ajax.render.php?'.$oAppContext->GetForLink().'", "data": '.$sAjaxData.', "method": "post", "pages": 5 // number of pages to cache diff --git a/sources/Application/UI/Links/Direct/BlockDirectLinkSetEditTable.php b/sources/Application/UI/Links/Direct/BlockDirectLinkSetEditTable.php index aece993894..b302c5ce76 100644 --- a/sources/Application/UI/Links/Direct/BlockDirectLinkSetEditTable.php +++ b/sources/Application/UI/Links/Direct/BlockDirectLinkSetEditTable.php @@ -98,7 +98,7 @@ public function __construct(UILinksWidgetDirect $oUILinksDirectWidget, string $s 'selection_title' => Dict::Format('UI:SelectionOf_Class', MetaModel::GetName($this->oUILinksDirectWidget->GetLinkedClass())), ); $oContext = new ApplicationContext(); - $this->sSubmitUrl = utils::GetAbsoluteUrlAppRoot().'pages/ajax.render.php?'.$oContext->GetQueryParametersString(false); + $this->sSubmitUrl = utils::GetAbsoluteUrlAppRoot().'pages/ajax.render.php?'.$oContext->GetForLink(); // Don't automatically launch the search if the table is huge $bDoSearch = !utils::IsHighCardinality($this->oUILinksDirectWidget->GetLinkedClass()); diff --git a/sources/Application/UI/Links/Set/BlockLinkSetDisplayAsProperty.php b/sources/Application/UI/Links/Set/BlockLinkSetDisplayAsProperty.php index 03e50126dd..39cef28c97 100644 --- a/sources/Application/UI/Links/Set/BlockLinkSetDisplayAsProperty.php +++ b/sources/Application/UI/Links/Set/BlockLinkSetDisplayAsProperty.php @@ -97,7 +97,7 @@ private function Init() $this->oTwigEnv = TwigHelper::GetTwigEnvironment(TwigHelper::ENUM_TEMPLATES_BASE_PATH_BACKOFFICE); $oAppContext = new ApplicationContext(); - $this->sAppContext = $oAppContext->GetQueryParametersString(); + $this->sAppContext = $oAppContext->GetForLink(true); $this->sUIPage = cmdbAbstractObject::ComputeStandardUIPage($this->sTargetClass); } diff --git a/sources/Application/WebPage/NiceWebPage.php b/sources/Application/WebPage/NiceWebPage.php index 6bec3bc745..4e105a5dc5 100644 --- a/sources/Application/WebPage/NiceWebPage.php +++ b/sources/Application/WebPage/NiceWebPage.php @@ -204,7 +204,7 @@ public function GetAbsoluteUrlModulesRoot() function GetApplicationContext() { $oAppContext = new ApplicationContext(); - return $oAppContext->GetQueryParametersString(false); + return $oAppContext->GetForLink(); } // By Rom, used by CSVImport and Advanced search diff --git a/sources/Controller/AjaxRenderController.php b/sources/Controller/AjaxRenderController.php index b1f835fea1..f6b2dc18df 100644 --- a/sources/Controller/AjaxRenderController.php +++ b/sources/Controller/AjaxRenderController.php @@ -640,7 +640,7 @@ public static function RefreshDashletList(string $sStyle, string $sFilter): arra $aResult = array(); $oAppContext = new ApplicationContext(); - $sParams = $oAppContext->GetQueryParametersString(); + $sParams = $oAppContext->GetForLink(true); foreach ($aGroupBy as $iRow => $iCount) { // Build the search for this subset $oSubsetSearch = $oFilter->DeepClone(); diff --git a/tests/php-unit-tests/unitary-tests/application/ApplicationContextTest.php b/tests/php-unit-tests/unitary-tests/application/ApplicationContextTest.php index 45625acec4..78c6aa30f2 100644 --- a/tests/php-unit-tests/unitary-tests/application/ApplicationContextTest.php +++ b/tests/php-unit-tests/unitary-tests/application/ApplicationContextTest.php @@ -5,18 +5,18 @@ */ class ApplicationContextTest extends \Combodo\iTop\Test\UnitTest\ItopTestCase { - public function testGetQueryParametersString() + public function testGetForLink() { $_REQUEST['c']['menu'] = 'TargetOverview'; $_REQUEST['c']['org_id'] = '3'; $oApplicationContext = new ApplicationContext(true); $sExpected = '&c[org_id]=3&c[menu]=TargetOverview'; - $sActual = $oApplicationContext->GetQueryParametersString(); + $sActual = $oApplicationContext->GetForLink(true); $this->assertEquals($sExpected, $sActual, 'Query parameters string should include all request parameters prefixed with &'); $sExpected = 'c[org_id]=3&c[menu]=TargetOverview'; - $sActual = $oApplicationContext->GetQueryParametersString(false); + $sActual = $oApplicationContext->GetForLink(); $this->assertEquals($sExpected, $sActual, 'Query parameters string should not start with & when $bIncludeAmpersand is false'); }