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 = "
| ".implode(" | ", $aHeader)." | \n"; - $sHtml .= "'; - } else { - $oFinalAttDef = $oAttDef->GetFinalAttDef(); - if (get_class($oFinalAttDef) == 'AttributeDateTime') { - $sDate = $oObj->Get($sAttCodeEx); - if ($sDate === null) { - $aRow[] = ' | '; - $aRow[] = ' | '; - } else { - $iDate = AttributeDateTime::GetAsUnixSeconds($sDate); - $aRow[] = ' | '.date( - 'Y-m-d', - $iDate - ).' | '; // Format kept as-is for 100% backward compatibility of the exports - $aRow[] = ''.date( - 'H:i:s', - $iDate - ).' | '; // Format kept as-is for 100% backward compatibility of the exports - } - } else { - if ($oAttDef instanceof AttributeCaseLog) { - $rawValue = $oObj->Get($sAttCodeEx); - $outputValue = str_replace( - "\n", - "'.$outputValue.' | '; - } 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[] = ''.$outputValue.' | '; - } - } - } - } - } - $sHtml .= implode("\n", $aRow); - $sHtml .= "\n"; - } - $sHtml .= "