diff --git a/application/cmdbabstract.class.inc.php b/application/cmdbabstract.class.inc.php index d0edfdbde..126aa2bc4 100644 --- a/application/cmdbabstract.class.inc.php +++ b/application/cmdbabstract.class.inc.php @@ -56,26 +56,28 @@ abstract class cmdbAbstractObject extends CMDBObject implements iDisplay protected $m_iFormId; // The ID of the form used to edit the object (when in edition mode !) static $iGlobalFormId = 1; protected $aFieldsMap; - + /** * If true, bypass IsActionAllowedOnAttribute when writing this object + * * @var bool */ protected $bAllowWrite; /** * Constructor from a row of data (as a hash 'attcode' => value) - * @param hash $aRow + * + * @param array $aRow * @param string $sClassAlias - * @param hash $aAttToLoad - * @param hash $aExtendedDataSpec + * @param array $aAttToLoad + * @param array $aExtendedDataSpec */ public function __construct($aRow = null, $sClassAlias = '', $aAttToLoad = null, $aExtendedDataSpec = null) { parent::__construct($aRow, $sClassAlias, $aAttToLoad, $aExtendedDataSpec); $this->bAllowWrite = false; } - + /** * returns what will be the next ID for the forms */ @@ -83,11 +85,12 @@ abstract class cmdbAbstractObject extends CMDBObject implements iDisplay { return 1 + self::$iGlobalFormId; } + public static function GetUIPage() { return 'UI.php'; } - + public static function ReloadAndDisplay($oPage, $oObj, $aParams) { $oAppContext = new ApplicationContext(); @@ -104,7 +107,7 @@ abstract class cmdbAbstractObject extends CMDBObject implements iDisplay } $sUrl = utils::GetAbsoluteUrlAppRoot().'pages/'.$oObj->GetUIPage().'?'.$sParams.'class='.get_class($oObj).'&id='.$oObj->getKey().'&'.$oAppContext->GetForLink().'&a=1'; $oPage->add_script( -<<IsPrintableVersion()) { // Is there a message for this object ?? @@ -168,18 +173,21 @@ EOF if ($aLockInfo['locked']) { $aRanks[] = 0; - $sName = $aLockInfo['owner']->GetName(); + $sName = $aLockInfo['owner']->GetName(); if ($aLockInfo['owner']->Get('contactid') != 0) { $sName .= ' ('.$aLockInfo['owner']->Get('contactid_friendlyname').')'; } - $aResult['message'] = Dict::Format('UI:CurrentObjectIsLockedBy_User', $sName); $aMessages[] = "
".Dict::Format('UI:CurrentObjectIsLockedBy_User', $sName)."
"; + $aResult['message'] = Dict::Format('UI:CurrentObjectIsLockedBy_User', $sName); + $aMessages[] = "
".Dict::Format('UI:CurrentObjectIsLockedBy_User', + $sName)."
"; } } $sMessageKey = get_class($this).'::'.$this->GetKey(); - if (array_key_exists('obj_messages', $_SESSION) && array_key_exists($sMessageKey, $_SESSION['obj_messages'])) + if (array_key_exists('obj_messages', $_SESSION) && array_key_exists($sMessageKey, + $_SESSION['obj_messages'])) { - foreach ($_SESSION['obj_messages'][$sMessageKey] as $sMessageId => $aMessageData) + foreach($_SESSION['obj_messages'][$sMessageKey] as $sMessageId => $aMessageData) { $sMsgClass = 'message_'.$aMessageData['severity']; $aMessages[] = "
".$aMessageData['message']."
"; @@ -188,12 +196,12 @@ EOF unset($_SESSION['obj_messages'][$sMessageKey]); } array_multisort($aRanks, $aMessages); - foreach ($aMessages as $sMessage) + foreach($aMessages as $sMessage) { $oPage->add($sMessage); } } - + if (!$oPage->IsPrintableVersion()) { // action menu @@ -216,11 +224,11 @@ EOF if (count($aSyncData) > 0) { $bSynchronized = true; - foreach ($aSyncData as $iSourceId => $aSourceData) + foreach($aSyncData as $iSourceId => $aSourceData) { $oDataSource = $aSourceData['source']; $oReplica = reset($aSourceData['replica']); // Take the first one! - + $sApplicationURL = $oDataSource->GetApplicationUrl($this, $oReplica); $sLink = $oDataSource->GetName(); if (!empty($sApplicationURL)) @@ -260,13 +268,14 @@ EOF $aMasterSources[$iSourceId]['url'] = $sLink; $aMasterSources[$iSourceId]['last_synchro'] = $oReplica->Get('status_last_seen'); } - + if (is_object($oCreatorTask)) { $sTaskUrl = $aMasterSources[$oCreatorTask->GetKey()]['url']; if (!$bCanBeDeletedByUser) { - $sTip = "

".Dict::Format('Core:Synchro:TheObjectCannotBeDeletedByUser_Source', $sTaskUrl)."

"; + $sTip = "

".Dict::Format('Core:Synchro:TheObjectCannotBeDeletedByUser_Source', + $sTaskUrl)."

"; } else { @@ -281,7 +290,7 @@ EOF { $sTip = "

".Dict::S('Core:Synchro:ThisObjectIsSynchronized')."

"; } - + $sTip .= "

".Dict::S('Core:Synchro:ListOfDataSources')."

"; foreach($aMasterSources as $aStruct) { @@ -292,8 +301,9 @@ EOF $oDataSource = $aStruct['datasource']; $sLink = $aStruct['url']; - $sTip .= "

".$oDataSource->GetIcon(true, 'style="vertical-align:middle"')." $sLink
"; - $sTip .= Dict::S('Core:Synchro:LastSynchro') . '
' . $sLastSynchro . "

"; + $sTip .= "

".$oDataSource->GetIcon(true, + 'style="vertical-align:middle"')." $sLink
"; + $sTip .= Dict::S('Core:Synchro:LastSynchro').'
'.$sLastSynchro."

"; } $sLabel = htmlentities(Dict::S('Tag:Synchronized'), ENT_QUOTES, 'UTF-8'); $sSynchroTagId = 'synchro_icon-'.$this->GetKey(); @@ -329,7 +339,7 @@ EOF } $oPage->add( -<<
$sObjectIcon
@@ -356,12 +366,12 @@ EOF function DisplayBareProperties(WebPage $oPage, $bEditMode = false, $sPrefix = '', $aExtraParams = array()) { - $aFieldsMap = $this->GetBareProperties($oPage, $bEditMode, $sPrefix, $aExtraParams); + $aFieldsMap = $this->GetBareProperties($oPage, $bEditMode, $sPrefix, $aExtraParams); if (!isset($aExtraParams['disable_plugins']) || !$aExtraParams['disable_plugins']) { - foreach (MetaModel::EnumPlugins('iApplicationUIExtension') as $oExtensionInstance) + foreach(MetaModel::EnumPlugins('iApplicationUIExtension') as $oExtensionInstance) { $oExtensionInstance->OnDisplayProperties($this, $oPage, $bEditMode); } @@ -381,9 +391,10 @@ EOF return $aFieldsMap; } - + /** * Add a field to the map: attcode => id used when building a form + * * @param string $sAttCode The attribute code of the field being edited * @param string $sInputId The unique ID of the control/widget in the page */ @@ -409,7 +420,10 @@ EOF { $oAttDef = MetaModel::GetAttributeDef(get_class($this), $sAttCode); // Display mode - if (!$oAttDef->IsLinkset()) continue; // Process only linkset attributes... + if (!$oAttDef->IsLinkset()) + { + continue; + } // Process only linkset attributes... $sLinkedClass = $oAttDef->GetLinkedClass(); @@ -438,12 +452,14 @@ EOF $oLinkingAttDef = MetaModel::GetAttributeDef($sLinkedClass, $oAttDef->GetExtKeyToRemote()); $sTargetClass = $oLinkingAttDef->GetTargetClass(); // n:n links => must be allowed to modify the linking class AND read the target class in order to edit the linkedset - if (!UserRights::IsActionAllowed($sLinkedClass, UR_ACTION_MODIFY) || !UserRights::IsActionAllowed($sTargetClass, UR_ACTION_READ)) + if (!UserRights::IsActionAllowed($sLinkedClass, + UR_ACTION_MODIFY) || !UserRights::IsActionAllowed($sTargetClass, UR_ACTION_READ)) { $iFlags |= OPT_ATT_READONLY; } // n:n links => must be allowed to read the linking class AND the target class in order to display the linkedset - if (!UserRights::IsActionAllowed($sLinkedClass, UR_ACTION_READ) || !UserRights::IsActionAllowed($sTargetClass, UR_ACTION_READ)) + if (!UserRights::IsActionAllowed($sLinkedClass, + UR_ACTION_READ) || !UserRights::IsActionAllowed($sTargetClass, UR_ACTION_READ)) { $iFlags |= OPT_ATT_HIDDEN; } @@ -462,10 +478,13 @@ EOF } } // Non-readable/hidden linkedset... don't display anything - if ($iFlags & OPT_ATT_HIDDEN) continue; - + if ($iFlags & OPT_ATT_HIDDEN) + { + continue; + } + $aArgs = array('this' => $this); - $bReadOnly = ($iFlags & (OPT_ATT_READONLY|OPT_ATT_SLAVE)); + $bReadOnly = ($iFlags & (OPT_ATT_READONLY | OPT_ATT_SLAVE)); if ($bEditMode && (!$bReadOnly)) { $sInputId = $this->m_iFormId.'_'.$sAttCode; @@ -482,8 +501,9 @@ EOF $oPage->p(MetaModel::GetClassIcon($sTargetClass)." ".$oAttDef->GetDescription().''); $sDisplayValue = ''; // not used - $sHTMLValue = "".self::GetFormElementForField($oPage, $sClass, $sAttCode, $oAttDef, $oLinkSet, $sDisplayValue, $sInputId, '', $iFlags, $aArgs).''; - $this->AddToFieldsMap($sAttCode, $sInputId); + $sHTMLValue = "".self::GetFormElementForField($oPage, $sClass, $sAttCode, + $oAttDef, $oLinkSet, $sDisplayValue, $sInputId, '', $iFlags, $aArgs).''; + $this->AddToFieldsMap($sAttCode, $sInputId); $oPage->add($sHTMLValue); } else @@ -508,7 +528,7 @@ EOF 'target_attr' => $oAttDef->GetExtKeyToMe(), 'object_id' => $this->GetKey(), 'menu' => MetaModel::GetConfig()->Get('allow_menu_on_linkset'), - //'menu_actions_target' => '_blank', + //'menu_actions_target' => '_blank', 'default' => $aDefaults, 'table_id' => $sClass.'_'.$sAttCode, ); @@ -519,15 +539,15 @@ EOF $oLinkingAttDef = MetaModel::GetAttributeDef($sLinkedClass, $oAttDef->GetExtKeyToRemote()); $sTargetClass = $oLinkingAttDef->GetTargetClass(); $aParams = array( - 'link_attr' => $oAttDef->GetExtKeyToMe(), - 'object_id' => $this->GetKey(), - 'target_attr' => $oAttDef->GetExtKeyToRemote(), - 'view_link' => false, - 'menu' => false, - //'menu_actions_target' => '_blank', - 'display_limit' => true, // By default limit the list to speed up the initial load & display - 'table_id' => $sClass.'_'.$sAttCode, - ); + 'link_attr' => $oAttDef->GetExtKeyToMe(), + 'object_id' => $this->GetKey(), + 'target_attr' => $oAttDef->GetExtKeyToRemote(), + 'view_link' => false, + 'menu' => false, + //'menu_actions_target' => '_blank', + 'display_limit' => true, // By default limit the list to speed up the initial load & display + 'table_id' => $sClass.'_'.$sAttCode, + ); } $oPage->p(MetaModel::GetClassIcon($sTargetClass)." ".$oAttDef->GetDescription()); $oBlock = new DisplayBlock($oLinkSet->GetFilter(), 'list', false); @@ -535,19 +555,21 @@ EOF } if (array_key_exists($sAttCode, $aRedundancySettings)) { - foreach ($aRedundancySettings[$sAttCode] as $oRedundancyAttDef) + foreach($aRedundancySettings[$sAttCode] as $oRedundancyAttDef) { $sRedundancyAttCode = $oRedundancyAttDef->GetCode(); $sValue = $this->Get($sRedundancyAttCode); $iRedundancyFlags = $this->GetFormAttributeFlags($sRedundancyAttCode); - $bRedundancyReadOnly = ($iRedundancyFlags & (OPT_ATT_READONLY|OPT_ATT_SLAVE)); + $bRedundancyReadOnly = ($iRedundancyFlags & (OPT_ATT_READONLY | OPT_ATT_SLAVE)); $oPage->add('
'); $oPage->add(''.$oRedundancyAttDef->GetLabel().''); if ($bEditMode && (!$bRedundancyReadOnly)) { $sInputId = $this->m_iFormId.'_'.$sRedundancyAttCode; - $oPage->add("".self::GetFormElementForField($oPage, $sClass, $sRedundancyAttCode, $oRedundancyAttDef, $sValue, '', $sInputId, '', $iFlags, $aArgs).''); + $oPage->add("".self::GetFormElementForField($oPage, $sClass, + $sRedundancyAttCode, $oRedundancyAttDef, $sValue, '', $sInputId, '', $iFlags, + $aArgs).''); } else { @@ -559,7 +581,7 @@ EOF } $oPage->SetCurrentTab(''); - foreach (MetaModel::EnumPlugins('iApplicationUIExtension') as $oExtensionInstance) + foreach(MetaModel::EnumPlugins('iApplicationUIExtension') as $oExtensionInstance) { $oExtensionInstance->OnDisplayRelations($this, $oPage, $bEditMode); } @@ -572,9 +594,9 @@ EOF // $oTriggerSet = new CMDBObjectSet(new DBObjectSearch('Trigger')); $aTriggers = array(); - while($oTrigger = $oTriggerSet->Fetch()) + while ($oTrigger = $oTriggerSet->Fetch()) { - if($oTrigger->IsInScope($this)) + if ($oTrigger->IsInScope($this)) { $aTriggers[] = $oTrigger->GetKey(); } @@ -590,12 +612,12 @@ EOF { $aNotifSearches[$sNotifClass] = DBObjectSearch::FromOQL("SELECT $sNotifClass AS Ev JOIN Trigger AS T ON Ev.trigger_id = T.id WHERE T.id IN ($sTriggersList) AND Ev.object_id = $iId"); $oNotifSet = new DBObjectSet($aNotifSearches[$sNotifClass]); - $iNotifsCount += $oNotifSet->Count(); + $iNotifsCount += $oNotifSet->Count(); } // Display notifications regarding the object: on block per subclass to have the intersting columns $sCount = ($iNotifsCount > 0) ? ' ('.$iNotifsCount.')' : ''; $oPage->SetCurrentTab(Dict::S('UI:NotificationsTab').$sCount); - + foreach($aNotificationClasses as $sNotifClass) { $oPage->p(MetaModel::GetClassIcon($sNotifClass, true).' '.MetaModel::GetName($sNotifClass)); @@ -614,7 +636,8 @@ EOF $aDetails = array(); $sClass = get_class($this); $aDetailsList = MetaModel::GetZListItems($sClass, 'details'); - $aDetailsStruct = self::ProcessZlist($aDetailsList, array('UI:PropertiesTab' => array()), 'UI:PropertiesTab', 'col1', ''); + $aDetailsStruct = self::ProcessZlist($aDetailsList, array('UI:PropertiesTab' => array()), 'UI:PropertiesTab', + 'col1', ''); // Compute the list of properties to display, first the attributes in the 'details' list, then // all the remaining attributes that are not external fields $sHtml = ''; @@ -649,7 +672,8 @@ EOF } $oPage->SetCurrentTab(Dict::S($sTab)); - $oPage->add(''); + $oPage->add('
'); foreach($aCols as $sColIndex => $aFieldsets) { $oPage->add(''; // Format kept as-is for 100% backward compatibility of the exports - $aRow[] = ''; // Format kept as-is for 100% backward compatibility of the exports + $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", "
", htmlentities($rawValue->__toString(), ENT_QUOTES, 'UTF-8')); - // 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()) + if ($oAttDef instanceof AttributeCaseLog) { - $sKeyAttCode = $oAttDef->GetKeyAttCode(); - if ($oObj->Get($sKeyAttCode) == 0) - { - $rawValue = ''; - } - } - if ($bLocalize) - { - $outputValue = htmlentities($oFinalAttDef->GetEditValue($rawValue), ENT_QUOTES, 'UTF-8'); + $rawValue = $oObj->Get($sAttCodeEx); + $outputValue = str_replace("\n", "
", + htmlentities($rawValue->__toString(), ENT_QUOTES, 'UTF-8')); + // Trick for Excel: treat the content as text even if it begins with an equal sign + $aRow[] = ''; } else { - $outputValue = htmlentities($rawValue, ENT_QUOTES, 'UTF-8'); + $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 = htmlentities($oFinalAttDef->GetEditValue($rawValue), ENT_QUOTES, + 'UTF-8'); + } + else + { + $outputValue = htmlentities($rawValue, ENT_QUOTES, 'UTF-8'); + } + $aRow[] = ''; } - $aRow[] = ''; } } } @@ -1460,16 +1531,16 @@ EOF $sHtml .= "\n"; } $sHtml .= "
'); @@ -706,7 +730,13 @@ EOF { // State attribute is always read-only from the UI $sHTMLValue = $this->GetStateLabel(); - $val = array('label' => '', 'value' => $sHTMLValue, 'comments' => $sComments, 'infos' => $sInfos, 'attcode' => $sAttCode); + $val = array( + 'label' => '', + 'value' => $sHTMLValue, + 'comments' => $sComments, + 'infos' => $sInfos, + 'attcode' => $sAttCode + ); } else { @@ -721,8 +751,10 @@ EOF $sTip = ''; foreach($aReasons as $aRow) { - $sDescription = htmlentities($aRow['description'], ENT_QUOTES, 'UTF-8'); - $sDescription = str_replace(array("\r\n", "\n"), "
", $sDescription); + $sDescription = htmlentities($aRow['description'], ENT_QUOTES, + 'UTF-8'); + $sDescription = str_replace(array("\r\n", "\n"), "
", + $sDescription); $sTip .= "
"; $sTip .= "
Synchronized with {$aRow['name']}
"; $sTip .= "
$sDescription
"; @@ -740,10 +772,18 @@ EOF $sValue = $this->Get($sAttCode); $sDisplayValue = $this->GetEditValue($sAttCode); $aArgs = array('this' => $this, 'formPrefix' => $sPrefix); - $sHTMLValue = "".self::GetFormElementForField($oPage, $sClass, $sAttCode, $oAttDef, $sValue, $sDisplayValue, $sInputId, '', $iFlags, $aArgs).''; + $sHTMLValue = "".self::GetFormElementForField($oPage, $sClass, $sAttCode, + $oAttDef, $sValue, $sDisplayValue, $sInputId, '', $iFlags, + $aArgs).''; } $aFieldsMap[$sAttCode] = $sInputId; - $val = array('label' => ''.$oAttDef->GetLabel().'', 'value' => $sHTMLValue, 'comments' => $sComments, 'infos' => $sInfos, 'attcode' => $sAttCode); + $val = array( + 'label' => ''.$oAttDef->GetLabel().'', + 'value' => $sHTMLValue, + 'comments' => $sComments, + 'infos' => $sInfos, + 'attcode' => $sAttCode + ); } } else @@ -761,7 +801,8 @@ EOF // Checking how the field should be rendered // Note: For view mode, this is done in cmdbAbstractObject::GetFieldAsHtml() // Note 2: Shouldn't this be a property of the AttDef instead an array that we have to maintain? - if (in_array($oAttDef->GetEditClass(), array('Text', 'HTML', 'CaseLog', 'CustomFields', 'OQLExpression'))) + if (in_array($oAttDef->GetEditClass(), + array('Text', 'HTML', 'CaseLog', 'CustomFields', 'OQLExpression'))) { $val['layout'] = 'large'; } @@ -808,7 +849,7 @@ EOF return $aFieldsMap; } - + function DisplayDetails(WebPage $oPage, $bEditMode = false) { $sTemplate = Utils::ReadFromFile(MetaModel::GetDisplayTemplate(get_class($this))); @@ -817,7 +858,13 @@ EOF $oTemplate = new DisplayTemplate($sTemplate); // Note: to preserve backward compatibility with home-made templates, the placeholder '$pkey$' has been preserved // but the preferred method is to use '$id$' - $oTemplate->Render($oPage, array('class_name'=> MetaModel::GetName(get_class($this)),'class'=> get_class($this), 'pkey'=> $this->GetKey(), 'id'=> $this->GetKey(), 'name' => $this->GetName())); + $oTemplate->Render($oPage, array( + 'class_name' => MetaModel::GetName(get_class($this)), + 'class' => get_class($this), + 'pkey' => $this->GetKey(), + 'id' => $this->GetKey(), + 'name' => $this->GetName() + )); } else { @@ -832,11 +879,12 @@ EOF $this->DisplayBareRelations($oPage, $bEditMode); //$oPage->SetCurrentTab(Dict::S('UI:HistoryTab')); //$this->DisplayBareHistory($oPage, $bEditMode); - $oPage->AddAjaxTab(Dict::S('UI:HistoryTab'), utils::GetAbsoluteUrlAppRoot().'pages/ajax.render.php?operation=history&class='.get_class($this).'&id='.$this->GetKey()); + $oPage->AddAjaxTab(Dict::S('UI:HistoryTab'), + utils::GetAbsoluteUrlAppRoot().'pages/ajax.render.php?operation=history&class='.get_class($this).'&id='.$this->GetKey()); $oPage->add('
'); } } - + function DisplayPreview(WebPage $oPage) { $aDetails = array(); @@ -844,45 +892,51 @@ EOF $aList = MetaModel::GetZListItems($sClass, 'preview'); foreach($aList as $sAttCode) { - $aDetails[] = array('label' => MetaModel::GetLabel($sClass, $sAttCode), 'value' =>$this->GetAsHTML($sAttCode)); + $aDetails[] = array( + 'label' => MetaModel::GetLabel($sClass, $sAttCode), + 'value' => $this->GetAsHTML($sAttCode) + ); } - $oPage->details($aDetails); + $oPage->details($aDetails); } - + public static function DisplaySet(WebPage $oPage, CMDBObjectSet $oSet, $aExtraParams = array()) { $oPage->add(self::GetDisplaySet($oPage, $oSet, $aExtraParams)); } - + /** * Simplifed version of GetDisplaySet() with less "decoration" around the table (and no paging) * that fits better into a printed document (like a PDF or a printable view) + * * @param WebPage $oPage * @param DBObjectSet $oSet - * @param hash $aExtraParams + * @param array $aExtraParams + * * @return string The HTML representation of the table */ public static function GetDisplaySetForPrinting(WebPage $oPage, DBObjectSet $oSet, $aExtraParams = array()) { $iListId = empty($aExtraParams['currentId']) ? $oPage->GetUniqueId() : $aExtraParams['currentId']; $sTableId = isset($aExtraParams['table_id']) ? $aExtraParams['table_id'] : null; - + $bViewLink = true; $sSelectMode = 'none'; $iListId = $sTableId; $sClassAlias = $oSet->GetClassAlias(); $sClassName = $oSet->GetClass(); $sZListName = 'list'; - $aClassAliases = array( $sClassAlias => $sClassName); + $aClassAliases = array($sClassAlias => $sClassName); $aList = cmdbAbstractObject::FlattenZList(MetaModel::GetZListItems($sClassName, $sZListName)); - + $oDataTable = new PrintableDataTable($iListId, $oSet, $aClassAliases, $sTableId); $oSettings = DataTableSettings::GetDataModelSettings($aClassAliases, $bViewLink, array($sClassAlias => $aList)); $oSettings->iDefaultPageSize = 0; $oSettings->aSortOrder = MetaModel::GetOrderByDefault($sClassName); - - return $oDataTable->Display($oPage, $oSettings, false /* $bDisplayMenu */, $sSelectMode, $bViewLink, $aExtraParams); - + + return $oDataTable->Display($oPage, $oSettings, false /* $bDisplayMenu */, $sSelectMode, $bViewLink, + $aExtraParams); + } /** @@ -892,10 +946,11 @@ EOF * @param CMDBObjectSet The set of objects to display * @param array $aExtraParams Some extra configuration parameters to tweak the behavior of the display * - * @return String The HTML fragment representing the table of objects. Warning : no JS added to handled pagination or table sorting ! + * @return String The HTML fragment representing the table of objects. Warning : no JS added to handled + * pagination or table sorting ! * * @see DisplayBlock to get a similar table but with the JS for pagination & sorting - */ + */ public static function GetDisplaySet(WebPage $oPage, CMDBObjectSet $oSet, $aExtraParams = array()) { if ($oPage->IsPrintableVersion() || $oPage->is_pdf()) @@ -911,7 +966,7 @@ EOF { $iListId = $aExtraParams['currentId']; } - + // Initialize and check the parameters $bViewLink = isset($aExtraParams['view_link']) ? $aExtraParams['view_link'] : true; $sLinkageAttribute = isset($aExtraParams['link_attr']) ? $aExtraParams['link_attr'] : ''; @@ -919,12 +974,12 @@ EOF $sTargetAttr = isset($aExtraParams['target_attr']) ? $aExtraParams['target_attr'] : ''; if (!empty($sLinkageAttribute)) { - if($iLinkedObjectId == 0) + if ($iLinkedObjectId == 0) { // if 'links' mode is requested the id of the object to link to must be specified throw new ApplicationException(Dict::S('UI:Error:MandatoryTemplateParameter_object_id')); } - if($sTargetAttr == '') + if ($sTargetAttr == '') { // if 'links' mode is requested the d of the object to link to must be specified throw new ApplicationException(Dict::S('UI:Error:MandatoryTemplateParameter_target_attr')); @@ -935,9 +990,10 @@ EOF $bSelectMode = isset($aExtraParams['selection_mode']) ? $aExtraParams['selection_mode'] == true : false; $bSingleSelectMode = isset($aExtraParams['selection_type']) ? ($aExtraParams['selection_type'] == 'single') : false; - $aExtraFieldsRaw = isset($aExtraParams['extra_fields']) ? explode(',', trim($aExtraParams['extra_fields'])) : array(); + $aExtraFieldsRaw = isset($aExtraParams['extra_fields']) ? explode(',', + trim($aExtraParams['extra_fields'])) : array(); $aExtraFields = array(); - foreach ($aExtraFieldsRaw as $sFieldName) + foreach($aExtraFieldsRaw as $sFieldName) { // Ignore attributes not of the main queried class if (preg_match('/^(.*)\.(.*)$/', $sFieldName, $aMatches)) @@ -995,7 +1051,7 @@ EOF foreach($aList as $sLinkAttCode) { $oLinkAttDef = $aAttDefs[$sLinkAttCode]; - if ( (!$oLinkAttDef->IsExternalKey()) && (!$oLinkAttDef->IsExternalField()) ) + if ((!$oLinkAttDef->IsExternalKey()) && (!$oLinkAttDef->IsExternalField())) { $aDisplayList[] = $sLinkAttCode; } @@ -1005,7 +1061,7 @@ EOF { $oLinkAttDef = $aAttDefs[$sLinkAttCode]; if (($oLinkAttDef->IsExternalKey() && ($sLinkAttCode != $sLinkageAttribute)) - || ($oLinkAttDef->IsExternalField() && ($oLinkAttDef->GetKeyAttCode()!=$sLinkageAttribute)) ) + || ($oLinkAttDef->IsExternalField() && ($oLinkAttDef->GetKeyAttCode() != $sLinkageAttribute))) { $aDisplayList[] = $sLinkAttCode; } @@ -1014,24 +1070,25 @@ EOF // Then display all the attributes linked to the other end of the relationship $aList = $aDisplayList; } - + $sSelectMode = 'none'; if ($bSelectMode) { $sSelectMode = $bSingleSelectMode ? 'single' : 'multiple'; } - + $sClassAlias = $oSet->GetClassAlias(); $bDisplayLimit = isset($aExtraParams['display_limit']) ? $aExtraParams['display_limit'] : true; - + $sTableId = isset($aExtraParams['table_id']) ? $aExtraParams['table_id'] : null; - $aClassAliases = array( $sClassAlias => $sClassName); + $aClassAliases = array($sClassAlias => $sClassName); $oDataTable = new DataTable($iListId, $oSet, $aClassAliases, $sTableId); $oSettings = DataTableSettings::GetDataModelSettings($aClassAliases, $bViewLink, array($sClassAlias => $aList)); - + if ($bDisplayLimit) { - $iDefaultPageSize = appUserPreferences::GetPref('default_page_size', MetaModel::GetConfig()->GetMinDisplayLimit()); + $iDefaultPageSize = appUserPreferences::GetPref('default_page_size', + MetaModel::GetConfig()->GetMinDisplayLimit()); $oSettings->iDefaultPageSize = $iDefaultPageSize; } else @@ -1039,10 +1096,10 @@ EOF $oSettings->iDefaultPageSize = 0; } $oSettings->aSortOrder = MetaModel::GetOrderByDefault($sClassName); - + return $oDataTable->Display($oPage, $oSettings, $bDisplayMenu, $sSelectMode, $bViewLink, $aExtraParams); } - + public static function GetDisplayExtendedSet(WebPage $oPage, CMDBObjectSet $oSet, $aExtraParams = array()) { if (empty($aExtraParams['currentId'])) @@ -1054,18 +1111,20 @@ EOF $iListId = $aExtraParams['currentId']; } $aList = array(); - + // Initialize and check the parameters $bViewLink = isset($aExtraParams['view_link']) ? $aExtraParams['view_link'] : true; $bDisplayMenu = isset($aExtraParams['menu']) ? $aExtraParams['menu'] == true : true; // Check if there is a list of aliases to limit the display to... - $aDisplayAliases = isset($aExtraParams['display_aliases']) ? explode(',', $aExtraParams['display_aliases']) : array(); + $aDisplayAliases = isset($aExtraParams['display_aliases']) ? explode(',', + $aExtraParams['display_aliases']) : array(); $sZListName = isset($aExtraParams['zlist']) ? ($aExtraParams['zlist']) : 'list'; - $aExtraFieldsRaw = isset($aExtraParams['extra_fields']) ? explode(',', trim($aExtraParams['extra_fields'])) : array(); + $aExtraFieldsRaw = isset($aExtraParams['extra_fields']) ? explode(',', + trim($aExtraParams['extra_fields'])) : array(); $aExtraFields = array(); $sAttCode = ''; - foreach ($aExtraFieldsRaw as $sFieldName) + foreach($aExtraFieldsRaw as $sFieldName) { // Ignore attributes not of the main queried class if (preg_match('/^(.*)\.(.*)$/', $sFieldName, $aMatches)) @@ -1089,8 +1148,8 @@ EOF $aAuthorizedClasses = array(); foreach($aClasses as $sAlias => $sClassName) { - if ( (UserRights::IsActionAllowed($sClassName, UR_ACTION_READ, $oSet) != UR_ALLOWED_NO) && - ( (count($aDisplayAliases) == 0) || (in_array($sAlias, $aDisplayAliases))) ) + if ((UserRights::IsActionAllowed($sClassName, UR_ACTION_READ, $oSet) != UR_ALLOWED_NO) && + ((count($aDisplayAliases) == 0) || (in_array($sAlias, $aDisplayAliases)))) { $aAuthorizedClasses[$sAlias] = $sClassName; } @@ -1109,10 +1168,10 @@ EOF if ($sZListName !== false) { $aDefaultList = self::FlattenZList(MetaModel::GetZListItems($sClassName, $sZListName)); - + $aList[$sAlias] = array_merge($aDefaultList, $aList[$sAlias]); } - + // Filter the list to removed linked set since we are not able to display them here foreach($aList[$sAlias] as $index => $sAttCode) { @@ -1122,33 +1181,34 @@ EOF // Removed from the display list unset($aList[$sAlias][$index]); } - } + } } $sSelectMode = 'none'; - + $sClassAlias = $oSet->GetClassAlias(); $oDataTable = new DataTable($iListId, $oSet, $aAuthorizedClasses); $oSettings = DataTableSettings::GetDataModelSettings($aAuthorizedClasses, $bViewLink, $aList); - + $bDisplayLimit = isset($aExtraParams['display_limit']) ? $aExtraParams['display_limit'] : true; if ($bDisplayLimit) { - $iDefaultPageSize = appUserPreferences::GetPref('default_page_size', MetaModel::GetConfig()->GetMinDisplayLimit()); + $iDefaultPageSize = appUserPreferences::GetPref('default_page_size', + MetaModel::GetConfig()->GetMinDisplayLimit()); $oSettings->iDefaultPageSize = $iDefaultPageSize; } - + $oSettings->aSortOrder = MetaModel::GetOrderByDefault($sClassName); - + return $oDataTable->Display($oPage, $oSettings, $bDisplayMenu, $sSelectMode, $bViewLink, $aExtraParams); } - + static function DisplaySetAsCSV(WebPage $oPage, CMDBObjectSet $oSet, $aParams = array(), $sCharset = 'UTF-8') { $oPage->add(self::GetSetAsCSV($oSet, $aParams, $sCharset)); } - + static function GetSetAsCSV(DBObjectSet $oSet, $aParams = array(), $sCharset = 'UTF-8') { $sSeparator = isset($aParams['separator']) ? $aParams['separator'] : ','; // default separator is comma @@ -1162,13 +1222,13 @@ EOF $bFieldsAdvanced = false; if (isset($aParams['fields_advanced'])) { - $bFieldsAdvanced = (bool) $aParams['fields_advanced']; + $bFieldsAdvanced = (bool)$aParams['fields_advanced']; } $bLocalize = true; if (isset($aParams['localize_values'])) { - $bLocalize = (bool) $aParams['localize_values']; + $bLocalize = (bool)$aParams['localize_values']; } $aList = array(); @@ -1197,7 +1257,7 @@ EOF if ($oAttDef->IsScalar() && ($oAttDef->IsWritable() || $oAttDef->IsExternalField())) { $sAttCodeEx = $oAttDef->IsExternalField() ? $oAttDef->GetKeyAttCode().'->'.$oAttDef->GetExtAttCode() : $sAttCode; - + if ($oAttDef->IsExternalKey(EXTKEY_ABSOLUTE)) { if ($bFieldsAdvanced) @@ -1206,11 +1266,12 @@ EOF if ($oAttDef->IsExternalKey(EXTKEY_RELATIVE)) { - $sRemoteClass = $oAttDef->GetTargetClass(); + $sRemoteClass = $oAttDef->GetTargetClass(); foreach(MetaModel::GetReconcKeys($sRemoteClass) as $sRemoteAttCode) - { - $aList[$sAlias][$sAttCode.'->'.$sRemoteAttCode] = MetaModel::GetAttributeDef($sRemoteClass, $sRemoteAttCode); - } + { + $aList[$sAlias][$sAttCode.'->'.$sRemoteAttCode] = MetaModel::GetAttributeDef($sRemoteClass, + $sRemoteAttCode); + } } } } @@ -1236,7 +1297,8 @@ EOF } foreach($aList[$sAlias] as $sAttCodeEx => $oAttDef) { - $aHeader[] = $bLocalize ? MetaModel::GetLabel($sClassName, $sAttCodeEx, isset($aParams['showMandatoryFields'])) : $sAttCodeEx; + $aHeader[] = $bLocalize ? MetaModel::GetLabel($sClassName, $sAttCodeEx, + isset($aParams['showMandatoryFields'])) : $sAttCodeEx; } } $sHtml = implode($sSeparator, $aHeader)."\n"; @@ -1274,19 +1336,19 @@ EOF } $sHtml .= implode($sSeparator, $aRow)."\n"; } - + return $sHtml; } - + static function DisplaySetAsHTMLSpreadsheet(WebPage $oPage, CMDBObjectSet $oSet, $aParams = array()) { $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 - */ + */ static function GetSetAsHTMLSpreadsheet(DBObjectSet $oSet, $aParams = array()) { $aFields = null; @@ -1298,13 +1360,13 @@ EOF $bFieldsAdvanced = false; if (isset($aParams['fields_advanced'])) { - $bFieldsAdvanced = (bool) $aParams['fields_advanced']; + $bFieldsAdvanced = (bool)$aParams['fields_advanced']; } $bLocalize = true; if (isset($aParams['localize_values'])) { - $bLocalize = (bool) $aParams['localize_values']; + $bLocalize = (bool)$aParams['localize_values']; } $aList = array(); @@ -1333,16 +1395,17 @@ EOF 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(); + if ($bFieldsAdvanced && $oAttDef->IsExternalKey(EXTKEY_RELATIVE)) + { + $sRemoteClass = $oAttDef->GetTargetClass(); foreach(MetaModel::GetReconcKeys($sRemoteClass) as $sRemoteAttCode) - { - $aList[$sAlias][$sAttCode.'->'.$sRemoteAttCode] = MetaModel::GetAttributeDef($sRemoteClass, $sRemoteAttCode); - } + { + $aList[$sAlias][$sAttCode.'->'.$sRemoteAttCode] = MetaModel::GetAttributeDef($sRemoteClass, + $sRemoteAttCode); + } } } } @@ -1362,7 +1425,8 @@ EOF { unset($aList[$sAlias][$sAttCode]); $sFriendlyNameAttCode = $sAttCode.'_friendlyname'; - if (!array_key_exists($sFriendlyNameAttCode, $aList[$sAlias]) && MetaModel::IsValidAttCode($sClassName, $sFriendlyNameAttCode)) + if (!array_key_exists($sFriendlyNameAttCode, + $aList[$sAlias]) && MetaModel::IsValidAttCode($sClassName, $sFriendlyNameAttCode)) { $oFriendlyNameAtt = MetaModel::GetAttributeDef($sClassName, $sFriendlyNameAttCode); $aList[$sAlias][$sFriendlyNameAttCode] = $oFriendlyNameAtt; @@ -1419,39 +1483,46 @@ EOF else { $iDate = AttributeDateTime::GetAsUnixSeconds($sDate); - $aRow[] = '
'.date('Y-m-d', $iDate).''.date('H:i:s', $iDate).''.date('Y-m-d', + $iDate).''.date('H:i:s', + $iDate).''.$outputValue.''.$outputValue.''.$outputValue.''.$outputValue.'
\n"; - + return $sHtml; } - + static function DisplaySetAsXML(WebPage $oPage, CMDBObjectSet $oSet, $aParams = array()) { $bLocalize = true; if (isset($aParams['localize_values'])) { - $bLocalize = (bool) $aParams['localize_values']; + $bLocalize = (bool)$aParams['localize_values']; } $oAppContext = new ApplicationContext(); @@ -1491,7 +1562,7 @@ EOF { if (count($aAuthorizedClasses) > 1) { - $oPage->add("\n"); + $oPage->add("\n"); } foreach($aAuthorizedClasses as $sAlias => $sClassName) { @@ -1505,7 +1576,7 @@ EOF $sClassName = get_class($oObj); $oPage->add("<$sClassName alias=\"$sAlias\" id=\"".$oObj->GetKey()."\">\n"); } - foreach(MetaModel::ListAttributeDefs($sClassName) as $sAttCode=>$oAttDef) + foreach(MetaModel::ListAttributeDefs($sClassName) as $sAttCode => $oAttDef) { if (is_null($oObj)) { @@ -1527,7 +1598,7 @@ EOF } if (count($aAuthorizedClasses) > 1) { - $oPage->add("\n"); + $oPage->add("\n"); } } $oPage->add("\n"); @@ -1567,10 +1638,13 @@ EOF * @param int $iFlags * @param array $aArgs * @param bool $bPreserveCurrentValue Preserve the current value even if not allowed + * * @return string */ - public static function GetFormElementForField($oPage, $sClass, $sAttCode, $oAttDef, $value = '', $sDisplayValue = '', $iId = '', $sNameSuffix = '', $iFlags = 0, $aArgs = array(), $bPreserveCurrentValue = true) - { + public static function GetFormElementForField( + $oPage, $sClass, $sAttCode, $oAttDef, $value = '', $sDisplayValue = '', $iId = '', $sNameSuffix = '', + $iFlags = 0, $aArgs = array(), $bPreserveCurrentValue = true + ) { static $iInputId = 0; $sFieldPrefix = ''; $sFormPrefix = isset($aArgs['formPrefix']) ? $aArgs['formPrefix'] : ''; @@ -1599,7 +1673,7 @@ EOF if (!$oAttDef->IsExternalField()) { $bMandatory = 'false'; - if ( (!$oAttDef->IsNullAllowed()) || ($iFlags & OPT_ATT_MANDATORY)) + if ((!$oAttDef->IsNullAllowed()) || ($iFlags & OPT_ATT_MANDATORY)) { $bMandatory = 'true'; } @@ -1607,55 +1681,62 @@ EOF $sReloadSpan = ""; $sHelpText = htmlentities($oAttDef->GetHelpOnEdition(), ENT_QUOTES, 'UTF-8'); $aEventsList = array(); - switch($oAttDef->GetEditClass()) + switch ($oAttDef->GetEditClass()) { case 'Date': - $aEventsList[] ='validate'; - $aEventsList[] ='keyup'; - $aEventsList[] ='change'; - $sPlaceholderValue = 'placeholder="'.htmlentities(AttributeDate::GetFormat()->ToPlaceholder(), ENT_QUOTES, 'UTF-8').'"'; + $aEventsList[] = 'validate'; + $aEventsList[] = 'keyup'; + $aEventsList[] = 'change'; + $sPlaceholderValue = 'placeholder="'.htmlentities(AttributeDate::GetFormat()->ToPlaceholder(), + ENT_QUOTES, 'UTF-8').'"'; - $sHTMLValue = "
{$sValidationSpan}{$sReloadSpan}"; - break; + $sHTMLValue = "
{$sValidationSpan}{$sReloadSpan}"; + break; case 'DateTime': - $aEventsList[] ='validate'; - $aEventsList[] ='keyup'; - $aEventsList[] ='change'; + $aEventsList[] = 'validate'; + $aEventsList[] = 'keyup'; + $aEventsList[] = 'change'; - $sPlaceholderValue = 'placeholder="'.htmlentities(AttributeDateTime::GetFormat()->ToPlaceholder(), ENT_QUOTES, 'UTF-8').'"'; - $sHTMLValue = "
{$sValidationSpan}{$sReloadSpan}"; - break; + $sPlaceholderValue = 'placeholder="'.htmlentities(AttributeDateTime::GetFormat()->ToPlaceholder(), + ENT_QUOTES, 'UTF-8').'"'; + $sHTMLValue = "
{$sValidationSpan}{$sReloadSpan}"; + break; case 'Duration': - $aEventsList[] ='validate'; - $aEventsList[] ='change'; - $oPage->add_ready_script("$('#{$iId}_d').bind('keyup change', function(evt, sFormId) { return UpdateDuration('$iId'); });"); - $oPage->add_ready_script("$('#{$iId}_h').bind('keyup change', function(evt, sFormId) { return UpdateDuration('$iId'); });"); - $oPage->add_ready_script("$('#{$iId}_m').bind('keyup change', function(evt, sFormId) { return UpdateDuration('$iId'); });"); - $oPage->add_ready_script("$('#{$iId}_s').bind('keyup change', function(evt, sFormId) { return UpdateDuration('$iId'); });"); - $aVal = AttributeDuration::SplitDuration($value); - $sDays = ""; - $sHours = ""; - $sMinutes = ""; - $sSeconds = ""; - $sHidden = ""; - $sHTMLValue = Dict::Format('UI:DurationForm_Days_Hours_Minutes_Seconds', $sDays, $sHours, $sMinutes, $sSeconds).$sHidden." ".$sValidationSpan.$sReloadSpan; - $oPage->add_ready_script("$('#{$iId}').bind('update', function(evt, sFormId) { return ToggleDurationField('$iId'); });"); - break; - + $aEventsList[] = 'validate'; + $aEventsList[] = 'change'; + $oPage->add_ready_script("$('#{$iId}_d').bind('keyup change', function(evt, sFormId) { return UpdateDuration('$iId'); });"); + $oPage->add_ready_script("$('#{$iId}_h').bind('keyup change', function(evt, sFormId) { return UpdateDuration('$iId'); });"); + $oPage->add_ready_script("$('#{$iId}_m').bind('keyup change', function(evt, sFormId) { return UpdateDuration('$iId'); });"); + $oPage->add_ready_script("$('#{$iId}_s').bind('keyup change', function(evt, sFormId) { return UpdateDuration('$iId'); });"); + $aVal = AttributeDuration::SplitDuration($value); + $sDays = ""; + $sHours = ""; + $sMinutes = ""; + $sSeconds = ""; + $sHidden = ""; + $sHTMLValue = Dict::Format('UI:DurationForm_Days_Hours_Minutes_Seconds', $sDays, $sHours, $sMinutes, + $sSeconds).$sHidden." ".$sValidationSpan.$sReloadSpan; + $oPage->add_ready_script("$('#{$iId}').bind('update', function(evt, sFormId) { return ToggleDurationField('$iId'); });"); + break; + case 'Password': - $aEventsList[] ='validate'; - $aEventsList[] ='keyup'; - $aEventsList[] ='change'; - $sHTMLValue = "
{$sValidationSpan}{$sReloadSpan}"; - break; - + $aEventsList[] = 'validate'; + $aEventsList[] = 'keyup'; + $aEventsList[] = 'change'; + $sHTMLValue = "
{$sValidationSpan}{$sReloadSpan}"; + break; + case 'OQLExpression': case 'Text': - $aEventsList[] ='validate'; - $aEventsList[] ='keyup'; - $aEventsList[] ='change'; + $aEventsList[] = 'validate'; + $aEventsList[] = 'keyup'; + $aEventsList[] = 'change'; $sEditValue = $oAttDef->GetEditValue($value); $aStyles = array(); @@ -1688,10 +1769,11 @@ EOF $sAdditionalStuff = ""; } // Ok, the text area is drawn here - $sHTMLValue = "
$sAdditionalStuff
{$sValidationSpan}{$sReloadSpan}"; + $sHTMLValue = "
$sAdditionalStuff
{$sValidationSpan}{$sReloadSpan}"; - $oPage->add_ready_script( -<<add_ready_script( + <<