From 3fe91ed0b46b06087dcb645a22c4e0056b485346 Mon Sep 17 00:00:00 2001 From: Anne-Cath Date: Mon, 3 Aug 2026 16:39:19 +0200 Subject: [PATCH] =?UTF-8?q?N=C2=B08397=20-=20Suppress=20export=20V1=20from?= =?UTF-8?q?=20iTop=20packages?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/cmdbabstract.class.inc.php | 184 ------------------------- application/displayblock.class.inc.php | 4 +- pages/audit.php | 2 +- webservices/export-v2.php | 1 - 4 files changed, 3 insertions(+), 188 deletions(-) diff --git a/application/cmdbabstract.class.inc.php b/application/cmdbabstract.class.inc.php index af72499fd..40d4458e9 100644 --- a/application/cmdbabstract.class.inc.php +++ b/application/cmdbabstract.class.inc.php @@ -1535,190 +1535,6 @@ HTML return $sHtml; } - /** - * @param WebPage $oPage - * @param \CMDBObjectSet $oSet - * @param array $aParams - * - * @throws \Exception - * only used in old and deprecated export.php - * - * @internal Only to be used by `/webservices/export.php` : this is a legacy method that produces wrong HTML (no TR on table body rows) - */ - public static function DisplaySetAsHTMLSpreadsheet(WebPage $oPage, CMDBObjectSet $oSet, $aParams = []) - { - $oPage->add(self::GetSetAsHTMLSpreadsheet($oSet, $aParams)); - } - - /** - * Spreadsheet output: designed for end users doing some reporting - * Then the ids are excluded and replaced by the corresponding friendlyname - * - * @param \DBObjectSet $oSet - * @param array $aParams - * - * @return string - * @throws \CoreException - * @throws \CoreUnexpectedValue - * @throws \MissingQueryArgument - * @throws \MySQLException - * @throws \MySQLHasGoneAwayException - * @throws \Exception - * - * @internal Only to be used by `/webservices/export.php` : this is a legacy method that produces wrong HTML (no TR on table body rows) - */ - public static function GetSetAsHTMLSpreadsheet(DBObjectSet $oSet, $aParams = []) - { - $aFields = null; - if (isset($aParams['fields']) && (strlen($aParams['fields']) > 0)) { - $aFields = explode(',', $aParams['fields']); - } - - $bFieldsAdvanced = false; - if (isset($aParams['fields_advanced'])) { - $bFieldsAdvanced = (bool)$aParams['fields_advanced']; - } - - $bLocalize = true; - if (isset($aParams['localize_values'])) { - $bLocalize = (bool)$aParams['localize_values']; - } - - $aList = []; - - $aClasses = $oSet->GetFilter()->GetSelectedClasses(); - $aAuthorizedClasses = []; - foreach ($aClasses as $sAlias => $sClassName) { - if (UserRights::IsActionAllowed($sClassName, UR_ACTION_READ, $oSet) != UR_ALLOWED_NO) { - $aAuthorizedClasses[$sAlias] = $sClassName; - } - } - $aHeader = []; - foreach ($aAuthorizedClasses as $sAlias => $sClassName) { - $aList[$sAlias] = []; - - foreach (MetaModel::ListAttributeDefs($sClassName) as $sAttCode => $oAttDef) { - if (is_null($aFields) || (count($aFields) == 0)) { - // Standard list of attributes (no link sets) - if ($oAttDef->IsScalar() && ($oAttDef->IsWritable() || $oAttDef->IsExternalField())) { - $sAttCodeEx = $oAttDef->IsExternalField() ? $oAttDef->GetKeyAttCode().'->'.$oAttDef->GetExtAttCode() : $sAttCode; - - $aList[$sAlias][$sAttCodeEx] = $oAttDef; - - if ($bFieldsAdvanced && $oAttDef->IsExternalKey(EXTKEY_RELATIVE)) { - $sRemoteClass = $oAttDef->GetTargetClass(); - foreach (MetaModel::GetReconcKeys($sRemoteClass) as $sRemoteAttCode) { - $aList[$sAlias][$sAttCode.'->'.$sRemoteAttCode] = MetaModel::GetAttributeDef( - $sRemoteClass, - $sRemoteAttCode - ); - } - } - } - } else { - // User defined list of attributes - if (in_array($sAttCode, $aFields) || in_array($sAlias.'.'.$sAttCode, $aFields)) { - $aList[$sAlias][$sAttCode] = $oAttDef; - } - } - } - // Replace external key by the corresponding friendly name (if not already in the list) - foreach ($aList[$sAlias] as $sAttCode => $oAttDef) { - if ($oAttDef->IsExternalKey()) { - unset($aList[$sAlias][$sAttCode]); - $sFriendlyNameAttCode = $sAttCode.'_friendlyname'; - if (!array_key_exists( - $sFriendlyNameAttCode, - $aList[$sAlias] - ) && MetaModel::IsValidAttCode($sClassName, $sFriendlyNameAttCode)) { - $oFriendlyNameAtt = MetaModel::GetAttributeDef($sClassName, $sFriendlyNameAttCode); - $aList[$sAlias][$sFriendlyNameAttCode] = $oFriendlyNameAtt; - } - } - } - - foreach ($aList[$sAlias] as $sAttCodeEx => $oAttDef) { - $sColLabel = $bLocalize ? MetaModel::GetLabel($sClassName, $sAttCodeEx) : $sAttCodeEx; - - $oFinalAttDef = $oAttDef->GetFinalAttDef(); - if (get_class($oFinalAttDef) == 'AttributeDateTime') { - $aHeader[] = $sColLabel.' ('.Dict::S('UI:SplitDateTime-Date').')'; - $aHeader[] = $sColLabel.' ('.Dict::S('UI:SplitDateTime-Time').')'; - } else { - $aHeader[] = $sColLabel; - } - } - } - - $sHtml = "\n"; - $sHtml .= "\n"; - $sHtml .= "\n"; - $sHtml .= "\n"; - $oSet->Seek(0); - while ($aObjects = $oSet->FetchAssoc()) { - $aRow = []; - foreach ($aAuthorizedClasses as $sAlias => $sClassName) { - $oObj = $aObjects[$sAlias]; - foreach ($aList[$sAlias] as $sAttCodeEx => $oAttDef) { - if (is_null($oObj)) { - $aRow[] = ''; - } else { - $oFinalAttDef = $oAttDef->GetFinalAttDef(); - if (get_class($oFinalAttDef) == 'AttributeDateTime') { - $sDate = $oObj->Get($sAttCodeEx); - if ($sDate === null) { - $aRow[] = ''; - $aRow[] = ''; - } else { - $iDate = AttributeDateTime::GetAsUnixSeconds($sDate); - $aRow[] = ''; // Format kept as-is for 100% backward compatibility of the exports - $aRow[] = ''; // Format kept as-is for 100% backward compatibility of the exports - } - } else { - if ($oAttDef instanceof AttributeCaseLog) { - $rawValue = $oObj->Get($sAttCodeEx); - $outputValue = str_replace( - "\n", - "
", - utils::EscapeHtml($rawValue->__toString()) - ); - // Trick for Excel: treat the content as text even if it begins with an equal sign - $aRow[] = ''; - } else { - $rawValue = $oObj->Get($sAttCodeEx); - // Due to custom formatting rules, empty friendlynames may be rendered as non-empty strings - // let's fix this and make sure we render an empty string if the key == 0 - if ($oAttDef instanceof AttributeExternalField && $oAttDef->IsFriendlyName()) { - $sKeyAttCode = $oAttDef->GetKeyAttCode(); - if ($oObj->Get($sKeyAttCode) == 0) { - $rawValue = ''; - } - } - if ($bLocalize) { - $outputValue = utils::EscapeHtml($oFinalAttDef->GetEditValue($rawValue)); - } else { - $outputValue = utils::EscapeHtml($rawValue); - } - $aRow[] = ''; - } - } - } - } - } - $sHtml .= implode("\n", $aRow); - $sHtml .= "\n"; - } - $sHtml .= "
".implode("", $aHeader)."
'.date( - 'Y-m-d', - $iDate - ).''.date( - 'H:i:s', - $iDate - ).''.$outputValue.''.$outputValue.'
\n"; - - return $sHtml; - } - /** * @param WebPage $oPage * @param \CMDBObjectSet $oSet diff --git a/application/displayblock.class.inc.php b/application/displayblock.class.inc.php index df6dc1e1e..b7940b90d 100644 --- a/application/displayblock.class.inc.php +++ b/application/displayblock.class.inc.php @@ -1707,7 +1707,7 @@ JS $oBlock->bAdvancedMode = utils::ReadParam('advanced', false); $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->sDownloadLink = utils::GetAbsoluteUrlAppRoot().'webservices/export-v2.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(true).'&filter='.rawurlencode($this->m_oFilter->serialize()).'&format=csv'; // Pass the parameters via POST, since expression may be very long $aParamsToPost = [ @@ -1724,7 +1724,7 @@ JS $oBlock->sLinkToToggle = $oBlock->sLinkToToggle.'&advanced=1'; $oBlock->sChecked = ''; } - $oBlock->sAjaxLink = utils::GetAbsoluteUrlAppRoot().'webservices/export.php'; + $oBlock->sAjaxLink = utils::GetAbsoluteUrlAppRoot().'webservices/export-v2.php'; $oBlock->sCharsetNotice = false; $oBlock->sJsonParams = json_encode($aParamsToPost); diff --git a/pages/audit.php b/pages/audit.php index 3e9a3051a..6f1f95818 100644 --- a/pages/audit.php +++ b/pages/audit.php @@ -199,7 +199,7 @@ try { $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()); - $oP->add_ready_script("$('a[href*=\"webservices/export.php?expression=\"]').attr('href', '".$sExportUrl."&filename=audit.csv".$sAdvanced."');"); + $oP->add_ready_script("$('a[href*=\"webservices/export-v2.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; } );"); } break; diff --git a/webservices/export-v2.php b/webservices/export-v2.php index ad268232c..06b1f6727 100644 --- a/webservices/export-v2.php +++ b/webservices/export-v2.php @@ -145,7 +145,6 @@ function DisplayExpressionForm(WebPage $oP, $sAction, $sExpression = '', $sExcep $oPanel->AddSubBlock(ButtonUIBlockFactory::MakeForPrimaryAction(Dict::S('UI:Button:Next'), "", "", true, "next-btn")); $oP->p(''.Dict::S('Core:BulkExportCanRunNonInteractive').''); - $oP->p(''.Dict::S('Core:BulkExportLegacyExport').''); $sJSEmptyOQL = json_encode(Dict::S('Core:BulkExportMessageEmptyOQL')); $sJSEmptyQueryId = json_encode(Dict::S('Core:BulkExportMessageEmptyPhrasebookEntry'));