'.Dict::S('UI:UndefinedObject').''; // Objects built in memory have negative IDs $oAppContext = new ApplicationContext(); $sExtClassNameAtt = MetaModel::GetNameAttributeCode($sObjClass); $sPage = self::ComputeUIPage($sObjClass); $sAbsoluteUrl = utils::GetAbsoluteUrl(false); // False => Don't get the query string $sAbsoluteUrl = substr($sAbsoluteUrl, 0, 1+strrpos($sAbsoluteUrl, '/')); // remove the current page, keep just the path, up to the last / // Use the "name" of the target class as the label of the hyperlink // unless it's not available in the external attributes... if (isset($aAvailableFields[$sExtClassNameAtt])) { $sLabel = $aAvailableFields[$sExtClassNameAtt]; } else { $sLabel = implode(' / ', $aAvailableFields); } // Safety belt // if (empty($sLabel)) { // Developer's note: // This is doing the job for you, but that is just there in case // the external fields associated to the external key are blanks // The ultimate solution will be to query the name automatically // and independantly from the data model (automatic external field) // AND make the name be a mandatory field // $sObject = MetaModel::GetObject($sObjClass, $sObjKey); $sLabel = $sObject->GetDisplayName(); } // Safety net // if (empty($sLabel)) { $sLabel = MetaModel::GetName($sObjClass)." #$sObjKey"; } $sHint = MetaModel::GetName($sObjClass)."::$sObjKey"; return "GetForLink()."\" title=\"$sHint\">$sLabel"; } function DisplayBareHeader(WebPage $oPage) { // Standard Header with name, actions menu and history block // $oPage->add("
\n"); // action menu $oSingletonFilter = new DBObjectSearch(get_class($this)); $oSingletonFilter->AddCondition('id', array($this->GetKey())); $oBlock = new MenuBlock($oSingletonFilter, 'popup', false); $oBlock->Display($oPage, -1); $oPage->add("

".MetaModel::GetName(get_class($this)).": ".$this->GetDisplayName()."

\n"); // history block (with toggle) $oHistoryFilter = new DBObjectSearch('CMDBChangeOp'); $oHistoryFilter->AddCondition('objkey', $this->GetKey()); $oHistoryFilter->AddCondition('objclass', get_class($this)); $oBlock = new HistoryBlock($oHistoryFilter, 'toggle', false); $oBlock->Display($oPage, -1); $oPage->add("
\n"); } function DisplayBareDetails(WebPage $oPage) { $oPage->add($this->GetBareDetails($oPage)); } function DisplayBareRelations(WebPage $oPage) { // Related objects $oPage->AddTabContainer('Related Objects'); $oPage->SetCurrentTabContainer('Related Objects'); foreach(MetaModel::ListAttributeDefs(get_class($this)) as $sAttCode=>$oAttDef) { if ((get_class($oAttDef) == 'AttributeLinkedSetIndirect') || (get_class($oAttDef) == 'AttributeLinkedSet')) { $oPage->SetCurrentTab($oAttDef->GetLabel()); $oPage->p($oAttDef->GetDescription()); if (get_class($oAttDef) == 'AttributeLinkedSet') { $sTargetClass = $oAttDef->GetLinkedClass(); $oFilter = new DBObjectSearch($sTargetClass); $oFilter->AddCondition($oAttDef->GetExtKeyToMe(), $this->GetKey()); // @@@ condition has same name as field ?? $oBlock = new DisplayBlock($oFilter, 'list', false); $oBlock->Display($oPage, 0); } else // get_class($oAttDef) == 'AttributeLinkedSetIndirect' { $sLinkClass = $oAttDef->GetLinkedClass(); // Transform the DBObjectSet into a CMBDObjectSet !!! $aLinkedObjects = $this->Get($sAttCode)->ToArray(false); if (count($aLinkedObjects) > 0) { $oSet = CMDBObjectSet::FromArray($sLinkClass, $aLinkedObjects); $aParams = array( 'link_attr' => $oAttDef->GetExtKeyToMe(), 'object_id' => $this->GetKey(), 'target_attr' => $oAttDef->GetExtKeyToRemote(), ); self::DisplaySet($oPage, $oSet, $aParams); } } } } $oPage->SetCurrentTab(''); } function GetDisplayName() { $sDisplayName = ''; if (MetaModel::GetNameAttributeCode(get_class($this)) != '') { $sDisplayName = $this->GetAsHTML(MetaModel::GetNameAttributeCode(get_class($this))); } return $sDisplayName; } function GetBareDetails(WebPage $oPage) { $sHtml = ''; $oAppContext = new ApplicationContext(); $sStateAttCode = MetaModel::GetStateAttributeCode(get_class($this)); $aDetails = array(); $sClass = get_class($this); $aList = MetaModel::GetZListItems($sClass, 'details'); foreach($aList as $sAttCode) { $iFlags = $this->GetAttributeFlags($sAttCode); if ( ($iFlags & OPT_ATT_HIDDEN) == 0) { // The field is visible in the current state of the object if ($sStateAttCode == $sAttCode) { // Special display for the 'state' attribute itself $sDisplayValue = $this->GetStateLabel(); } else { $sDisplayValue = $this->GetAsHTML($sAttCode); } $aDetails[] = array('label' => MetaModel::GetLabel($sClass, $sAttCode), 'value' => $sDisplayValue); } } $sHtml .= $oPage->GetDetails($aDetails); // Documents displayed inline (when possible: images, html...) foreach($aList as $sAttCode) { $oAttDef = Metamodel::GetAttributeDef($sClass, $sAttCode); if ( $oAttDef->GetEditClass() == 'Document') { $oDoc = $this->Get($sAttCode); if (is_object($oDoc) && !$oDoc->IsEmpty()) { $sHtml .= "

".Dict::Format('UI:Document:OpenInNewWindow:Download', $oDoc->GetDisplayLink($sClass, $this->GetKey(), $sAttCode), $oDoc->GetDownloadLink($sClass, $this->GetKey(), $sAttCode))."

\n"; $sHtml .= "
".$oDoc->GetDisplayInline($sClass, $this->GetKey(), $sAttCode)."
\n"; } } } return $sHtml; } function DisplayDetails(WebPage $oPage) { $sTemplate = Utils::ReadFromFile(MetaModel::GetDisplayTemplate(get_class($this))); if (!empty($sTemplate)) { $oTemplate = new DisplayTemplate($sTemplate); $sNameAttCode = MetaModel::GetNameAttributeCode(get_class($this)); // 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->Get($sNameAttCode))); } else { // Object's details // template not found display the object using the *old style* $this->DisplayBareHeader($oPage); $this->DisplayBareDetails($oPage); $this->DisplayBareRelations($oPage); } } function DisplayPreview(WebPage $oPage) { $aDetails = array(); $sClass = get_class($this); $aList = MetaModel::GetZListItems($sClass, 'preview'); foreach($aList as $sAttCode) { $aDetails[] = array('label' => MetaModel::GetLabel($sClass, $sAttCode), 'value' =>$this->GetAsHTML($sAttCode)); } $oPage->details($aDetails); } // Comment by Rom: this helper may be used to display objects of class DBObject // -> I am using this to display the changes history public static function DisplaySet(WebPage $oPage, CMDBObjectSet $oSet, $aExtraParams = array()) { $oPage->add(self::GetDisplaySet($oPage, $oSet, $aExtraParams)); } //public static function GetDisplaySet(WebPage $oPage, CMDBObjectSet $oSet, $sLinkageAttribute = '', $bDisplayMenu = true, $bSelectMode = false) public static function GetDisplaySet(WebPage $oPage, CMDBObjectSet $oSet, $aExtraParams = array()) { static $iListId = 0; $iListId++; // Initialize and check the parameters $sLinkageAttribute = isset($aExtraParams['link_attr']) ? $aExtraParams['link_attr'] : ''; $iLinkedObjectId = isset($aExtraParams['object_id']) ? $aExtraParams['object_id'] : 0; $sTargetAttr = isset($aExtraParams['target_attr']) ? $aExtraParams['target_attr'] : ''; if (!empty($sLinkageAttribute)) { 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 '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')); } } $bDisplayMenu = isset($aExtraParams['menu']) ? $aExtraParams['menu'] == true : true; $bSelectMode = isset($aExtraParams['selection_mode']) ? $aExtraParams['selection_mode'] == true : false; $bSingleSelectMode = isset($aExtraParams['selection_type']) ? ($aExtraParams['selection_type'] == 'single') : false; $sHtml = ''; $oAppContext = new ApplicationContext(); $sClassName = $oSet->GetFilter()->GetClass(); $aAttribs = array(); $aList = MetaModel::GetZListItems($sClassName, 'list'); if (!empty($sLinkageAttribute)) { // The set to display is in fact a set of links between the object specified in the $sLinkageAttribute // and other objects... // The display will then group all the attributes related to the link itself: // | Link_attr1 | link_attr2 | ... || Object_attr1 | Object_attr2 | Object_attr3 | .. | Object_attr_n | $aAttDefs = MetaModel::ListAttributeDefs($sClassName); assert(isset($aAttDefs[$sLinkageAttribute])); $oAttDef = $aAttDefs[$sLinkageAttribute]; assert($oAttDef->IsExternalKey()); // First display all the attributes specific to the link record foreach($aList as $sLinkAttCode) { $oLinkAttDef = $aAttDefs[$sLinkAttCode]; if ( (!$oLinkAttDef->IsExternalKey()) && (!$oLinkAttDef->IsExternalField()) ) { $aDisplayList[] = $sLinkAttCode; } } // Then display all the attributes neither specific to the link record nor to the 'linkage' object (because the latter are constant) foreach($aList as $sLinkAttCode) { $oLinkAttDef = $aAttDefs[$sLinkAttCode]; if (($oLinkAttDef->IsExternalKey() && ($sLinkAttCode != $sLinkageAttribute)) || ($oLinkAttDef->IsExternalField() && ($oLinkAttDef->GetKeyAttCode()!=$sLinkageAttribute)) ) { $aDisplayList[] = $sLinkAttCode; } } // First display all the attributes specific to the link // Then display all the attributes linked to the other end of the relationship $aList = $aDisplayList; } if ($bSelectMode) { if (!$bSingleSelectMode) { $aAttribs['form::select'] = array('label' => "", 'description' => Dict::S('UI:SelectAllToggle+')); } else { $aAttribs['form::select'] = array('label' => "", 'description' => ''); } } $aAttribs['key'] = array('label' => '', 'description' => Dict::S('UI:ClickToDisplay+')); foreach($aList as $sAttCode) { $aAttribs[$sAttCode] = array('label' => MetaModel::GetLabel($sClassName, $sAttCode), 'description' => MetaModel::GetDescription($sClassName, $sAttCode)); } $aValues = array(); $oSet->Seek(0); $bDisplayLimit = isset($aExtraParams['display_limit']) ? $aExtraParams['display_limit'] : true; $iMaxObjects = -1; if ($bDisplayLimit) { if ($oSet->Count() > utils::GetConfig()->GetMaxDisplayLimit()) { $iMaxObjects = utils::GetConfig()->GetMinDisplayLimit(); } } while (($oObj = $oSet->Fetch()) && ($iMaxObjects != 0)) { $aRow = array(); $aRow['key'] = $oObj->GetKey(); if ($bSelectMode) { if ($bSingleSelectMode) { $aRow['form::select'] = "GetKey()."\">"; } else { $aRow['form::select'] = "GetKey()."\">"; } } $aRow['key'] = $oObj->GetKey(); foreach($aList as $sAttCode) { $aRow[$sAttCode] = $oObj->GetAsHTML($sAttCode); } $aValues[] = $aRow; $iMaxObjects--; } $sHtml .= ''; $sColspan = ''; if ($bDisplayMenu) { $oMenuBlock = new MenuBlock($oSet->GetFilter()); $sColspan = 'colspan="2"'; $aMenuExtraParams = $aExtraParams; if (!empty($sLinkageAttribute)) { //$aMenuExtraParams['linkage'] = $sLinkageAttribute; $aMenuExtraParams = $aExtraParams; } if ($bDisplayLimit && ($oSet->Count() > utils::GetConfig()->GetMaxDisplayLimit())) { // list truncated $divId = $aExtraParams['block_id']; $sFilter = $oSet->GetFilter()->serialize(); $aExtraParams['display_limit'] = false; // To expand the full list $sExtraParams = addslashes(str_replace('"', "'", json_encode($aExtraParams))); // JSON encode, change the style of the quotes and escape them $sHtml .= ''; } $sHtml .= "'; $sHtml .= '
'.Dict::Format('UI:TruncatedResults', utils::GetConfig()->GetMinDisplayLimit(), $oSet->Count()).'  '.Dict::S('UI:DisplayAll').''; $oPage->add_ready_script("$('#{$divId} table.listResults').addClass('truncated');"); $oPage->add_ready_script("$('#{$divId} table.listResults tr:last td').addClass('truncated');"); } else { // Full list $sHtml .= '
 '.Dict::Format('UI:CountOfResults', $oSet->Count()).''; } $sHtml .= $oMenuBlock->GetRenderContent($oPage, $aMenuExtraParams); $sHtml .= '
"; $sHtml .= $oPage->GetTable($aAttribs, $aValues, array('class'=>$sClassName, 'filter'=>$oSet->GetFilter()->serialize(), 'preview' => true)); $sHtml .= '
'; return $sHtml; } public static function GetDisplayExtendedSet(WebPage $oPage, CMDBObjectSet $oSet, $aExtraParams = array()) { static $iListId = 0; $iListId++; $aList = array(); // Initialize and check the parameters $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(); $sHtml = ''; $oAppContext = new ApplicationContext(); $aClasses = $oSet->GetFilter()->GetSelectedClasses(); $aAuthorizedClasses = array(); foreach($aClasses as $sAlias => $sClassName) { if ((UserRights::IsActionAllowed($sClassName, UR_ACTION_READ, $oSet) == UR_ALLOWED_YES) && ( (count($aDisplayAliases) == 0) || (in_array($sAlias, $aDisplayAliases))) ) { $aAuthorizedClasses[$sAlias] = $sClassName; } } $aAttribs = array(); foreach($aAuthorizedClasses as $sAlias => $sClassName) // TO DO: check if the user has enough rights to view the classes of the list... { $aList[$sClassName] = MetaModel::GetZListItems($sClassName, 'list'); $aAttribs['key_'.$sAlias] = array('label' => '', 'description' => Dict::S('UI:ClickToDisplay+')); foreach($aList[$sClassName] as $sAttCode) { $aAttribs[$sAttCode.'_'.$sAlias] = array('label' => MetaModel::GetLabel($sClassName, $sAttCode), 'description' => MetaModel::GetDescription($sClassName, $sAttCode)); } } $aValues = array(); $oSet->Seek(0); $bDisplayLimit = isset($aExtraParams['display_limit']) ? $aExtraParams['display_limit'] : true; $iMaxObjects = -1; if ($bDisplayLimit) { if ($oSet->Count() > utils::GetConfig()->GetMaxDisplayLimit()) { $iMaxObjects = utils::GetConfig()->GetMinDisplayLimit(); } } while (($aObjects = $oSet->FetchAssoc()) && ($iMaxObjects != 0)) { $aRow = array(); foreach($aAuthorizedClasses as $sAlias => $sClassName) // TO DO: check if the user has enough rights to view the classes of the list... { $aRow['key_'.$sAlias] = $aObjects[$sAlias]->GetKey(); foreach($aList[$sClassName] as $sAttCode) { $aRow[$sAttCode.'_'.$sAlias] = $aObjects[$sAlias]->GetAsHTML($sAttCode); } } $aValues[] = $aRow; $iMaxObjects--; } $sHtml .= ''; $sColspan = ''; if ($bDisplayMenu) { $oMenuBlock = new MenuBlock($oSet->GetFilter()); $sColspan = 'colspan="2"'; $aMenuExtraParams = $aExtraParams; if (!empty($sLinkageAttribute)) { $aMenuExtraParams = $aExtraParams; } if ($bDisplayLimit && ($oSet->Count() > utils::GetConfig()->GetMaxDisplayLimit())) { // list truncated $divId = $aExtraParams['block_id']; $sFilter = $oSet->GetFilter()->serialize(); $aExtraParams['display_limit'] = false; // To expand the full list $sExtraParams = addslashes(str_replace('"', "'", json_encode($aExtraParams))); // JSON encode, change the style of the quotes and escape them $sHtml .= ''; } $sHtml .= "'; $sHtml .= '
'.Dict::Format('UI:TruncatedResults', utils::GetConfig()->GetMinDisplayLimit(), $oSet->Count()).'  '.Dict::S('UI:DisplayAll').''; $oPage->add_ready_script("$('#{$divId} table.listResults').addClass('truncated');"); $oPage->add_ready_script("$('#{$divId} table.listResults tr:last td').addClass('truncated');"); } else { // Full list $sHtml .= '
 '.Dict::Format('UI:CountOfResults', $oSet->Count()).''; } $sHtml .= $oMenuBlock->GetRenderContent($oPage, $aMenuExtraParams); $sHtml .= '
"; $sHtml .= $oPage->GetTable($aAttribs, $aValues, array('class'=>$aAuthorizedClasses, 'filter'=>$oSet->GetFilter()->serialize(), 'preview' => true)); $sHtml .= '
'; return $sHtml; } static function DisplaySetAsCSV(WebPage $oPage, CMDBObjectSet $oSet, $aParams = array()) { $oPage->add(self::GetSetAsCSV($oSet, $aParams)); } static function GetSetAsCSV(DBObjectSet $oSet, $aParams = array()) { $sSeparator = isset($aParams['separator']) ? $aParams['separator'] : ','; // default separator is comma $sTextQualifier = isset($aParams['text_qualifier']) ? $aParams['text_qualifier'] : '"'; // default text qualifier is double quote $aList = array(); $oAppContext = new ApplicationContext(); $aClasses = $oSet->GetFilter()->GetSelectedClasses(); $aAuthorizedClasses = array(); foreach($aClasses as $sAlias => $sClassName) { if (UserRights::IsActionAllowed($sClassName, UR_ACTION_READ, $oSet) == UR_ALLOWED_YES) { $aAuthorizedClasses[$sAlias] = $sClassName; } } $aAttribs = array(); $aHeader = array(); foreach($aAuthorizedClasses as $sAlias => $sClassName) { foreach(MetaModel::ListAttributeDefs($sClassName) as $sAttCode => $oAttDef) { if ((($oAttDef->IsExternalField()) || ($oAttDef->IsWritable())) && $oAttDef->IsScalar()) { $aList[$sClassName][$sAttCode] = $oAttDef; } } $aHeader[] = MetaModel::GetKeyLabel($sClassName); foreach($aList[$sClassName] as $sAttCode => $oAttDef) { if ($oAttDef->IsExternalField()) { $sExtKeyLabel = MetaModel::GetLabel($sClassName, $oAttDef->GetKeyAttCode()); $sRemoteAttLabel = MetaModel::GetLabel($oAttDef->GetTargetClass(), $oAttDef->GetExtAttCode()); $aHeader[] = $sExtKeyLabel.'->'.$sRemoteAttLabel; } else { $aHeader[] = MetaModel::GetLabel($sClassName, $sAttCode); } } } $sHtml = implode($sSeparator, $aHeader)."\n"; $oSet->Seek(0); while ($aObjects = $oSet->FetchAssoc()) { $aRow = array(); foreach($aAuthorizedClasses as $sAlias => $sClassName) { $oObj = $aObjects[$sAlias]; $aRow[] = $oObj->GetKey(); foreach($aList[$sClassName] as $sAttCode => $oAttDef) { $aRow[] = $oObj->GetAsCSV($sAttCode, $sSeparator, '\\'); } } $sHtml .= implode($sSeparator, $aRow)."\n"; } return $sHtml; } static function DisplaySetAsXML(WebPage $oPage, CMDBObjectSet $oSet, $aParams = array()) { $oAppContext = new ApplicationContext(); $aClasses = $oSet->GetFilter()->GetSelectedClasses(); $aAuthorizedClasses = array(); foreach($aClasses as $sAlias => $sClassName) { if (UserRights::IsActionAllowed($sClassName, UR_ACTION_READ, $oSet) == UR_ALLOWED_YES) { $aAuthorizedClasses[$sAlias] = $sClassName; } } $aAttribs = array(); $aList = array(); $aList[$sClassName] = MetaModel::GetZListItems($sClassName, 'details'); $oPage->add("\n"); $oSet->Seek(0); while ($aObjects = $oSet->FetchAssoc()) { if (count($aAuthorizedClasses) > 1) { $oPage->add("\n"); } foreach($aAuthorizedClasses as $sAlias => $sClassName) { $oObj = $aObjects[$sAlias]; $sClassName = get_class($oObj); $oPage->add("<$sClassName alias=\"$sAlias\" id=\"".$oObj->GetKey()."\">\n"); foreach(MetaModel::ListAttributeDefs($sClassName) as $sAttCode=>$oAttDef) { if (($oAttDef->IsWritable()) && ($oAttDef->IsScalar())) { $sValue = $oObj->GetAsXML($sAttCode); $oPage->add("<$sAttCode>$sValue\n"); } } $oPage->add("\n"); } if (count($aAuthorizedClasses) > 1) { $oPage->add("\n"); } } $oPage->add("\n"); } // By rom function DisplayChangesLog(WebPage $oPage) { $oFltChangeOps = new CMDBSearchFilter('CMDBChangeOpSetAttribute'); $oFltChangeOps->AddCondition('objkey', $this->GetKey(), '='); $oFltChangeOps->AddCondition('objclass', get_class($this), '='); $oSet = new CMDBObjectSet($oFltChangeOps, array('date' => false)); // order by date descending (i.e. false) $count = $oSet->Count(); if ($count > 0) { $oPage->p(Dict::Format('UI:ChangesLogTitle', $count)); self::DisplaySet($oPage, $oSet); } else { $oPage->p(Dict::S('UI:EmptyChangesLogTitle')); } } public static function DisplaySearchForm(WebPage $oPage, CMDBObjectSet $oSet, $aExtraParams = array()) { $oPage->add(self::GetSearchForm($oPage, $oSet, $aExtraParams)); } public static function GetSearchForm(WebPage $oPage, CMDBObjectSet $oSet, $aExtraParams = array()) { static $iSearchFormId = 0; $oAppContext = new ApplicationContext(); $sHtml = ''; $numCols=4; $sClassName = $oSet->GetFilter()->GetClass(); // Romain: temporarily removed the tab "OQL query" because it was not finalized // (especially when used to add a link) /* $sHtml .= "
\n"; */ // Simple search form if (isset($aExtraParams['currentId'])) { $sSearchFormId = $aExtraParams['currentId']; $iSearchFormId++; } else { $iSearchFormId++; $sSearchFormId = 'SimpleSearchForm'.$iSearchFormId; $sHtml .= "
\n"; } // Check if the current class has some sub-classes if (isset($aExtraParams['baseClass'])) { $sRootClass = $aExtraParams['baseClass']; } else { $sRootClass = $sClassName; } $aSubClasses = MetaModel::GetSubclasses($sRootClass); if (count($aSubClasses) > 0) { $aOptions = array(); $aOptions[MetaModel::GetName($sRootClass)] = "
\n"; } // OQL query builder $sHtml .= "
\n"; $sHtml .= "

".Dict::S('UI:OQLQueryBuilderTitle')."

\n"; $sHtml .= "
\n"; $sHtml .= "\n"; $sHtml .= "\n"; $sHtml .= "\n"; foreach($aExtraParams as $sName => $sValue) { $sHtml .= "\n"; } $sHtml .= "\n"; $sHtml .= $oAppContext->GetForForm(); $sHtml .= "
 \n"; $sHtml .= "
\n"; $sHtml .= "
\n"; return $sHtml; } public static function GetFormElementForField($oPage, $sClass, $sAttCode, $oAttDef, $value = '', $sDisplayValue = '', $iId = '', $sNameSuffix = '', $iFlags = 0, $aArgs = array()) { static $iInputId = 0; if (isset($aArgs[$sAttCode]) && empty($value)) { // default value passed by the context (either the app context of the operation) $value = $aArgs[$sAttCode]; } if (!empty($iId)) { $iInputId = $iId; } else { $iInputId++; } if (!$oAttDef->IsExternalField()) { $aCSSClasses = array(); $bMandatory = 0; if ( (!$oAttDef->IsNullAllowed()) || ($iFlags & OPT_ATT_MANDATORY)) { $aCSSClasses[] = 'mandatory'; $bMandatory = 1; } $sCSSClasses = self::GetCSSClasses($aCSSClasses); $sValidationField = ""; switch($oAttDef->GetEditClass()) { case 'Date': case 'DateTime': $aCSSClasses[] = 'date-pick'; $sCSSClasses = self::GetCSSClasses($aCSSClasses); $sHTMLValue = "$sValidationField"; break; case 'Password': $sHTMLValue = "$sValidationField"; break; case 'Text': $sHTMLValue = "$sValidationField"; break; case 'List': $oWidget = new UILinksWidget($sClass, $sAttCode, $iInputId, $sNameSuffix); $sHTMLValue = $oWidget->Display($oPage, $value); break; case 'Document': $oDocument = $value; // Value is an ormDocument object $sFileName = ''; if (is_object($oDocument)) { $sFileName = $oDocument->GetFileName(); } $iMaxFileSize = utils::ConvertToBytes(ini_get('upload_max_filesize')); $sHTMLValue = "\n"; $sHTMLValue .= "\n"; $sHTMLValue .= "$sFileName
\n"; $sHTMLValue .= "\n"; break; case 'String': default: // #@# todo - add context information (depending on dimensions) $aAllowedValues = MetaModel::GetAllowedValues_att($sClass, $sAttCode, $aArgs); if ($aAllowedValues !== null) { //Enum field or external key, display a combo //if (count($aAllowedValues) == 0) //{ // $sHTMLValue = ""; //} //else if (count($aAllowedValues) > 50) if (count($aAllowedValues) > 50) { // too many choices, use an autocomplete // The input for the auto complete $sHTMLValue = "$sValidationField"; // another hidden input to store & pass the object's Id $sHTMLValue .= "\n"; $oPage->add_ready_script("\$('#label_$iInputId').autocomplete('./ajax.render.php', { scroll:true, minChars:3, onItemSelect:selectItem, onFindValue:findValue, formatItem:formatItem, autoFill:true, keyHolder:'#$iInputId', extraParams:{operation:'autocomplete', sclass:'$sClass',attCode:'".$sAttCode."'}});"); $oPage->add_ready_script("\$('#label_$iInputId').result( function(event, data, formatted) { if (data) { $('#{$iInputId}').val(data[1]); } } );"); // Prepopulate with a default value -- but no display value... //if (!empty($value)) //{ // $oPage->add_ready_script("\$('#label_$iInputId').search( 'domino.combodo.com' );"); //} } else { // Few choices, use a normal 'select' // In case there are no valid values, the select will be empty, thus blocking the user from validating the form $sHTMLValue = "$sValidationField\n"; } } else { $sHTMLValue = "$sValidationField"; } break; } $sPattern = addslashes($oAttDef->GetValidationPattern()); //'^([0-9]+)$'; $oPage->add_ready_script("$('#$iInputId').bind('validate blur', function(evt, sFormId) { return ValidateField('$iInputId', '$sPattern', $bMandatory, sFormId) } );"); // Bind to a custom event: validate $aDependencies = MetaModel::GetDependentAttributes($sClass, $sAttCode); // List of attributes that depend on the current one if (count($aDependencies) > 0) { $oPage->add_ready_script("$('#$iInputId').bind('change', function(evt, sFormId) { return UpdateDependentFields(['".implode("','", $aDependencies)."']) } );"); // Bind to a custom event: validate } } return $sHTMLValue; } public function DisplayModifyForm(WebPage $oPage, $aExtraParams = array()) { static $iFormId = 0; $iFormId++; $sClass = get_class($this); $oAppContext = new ApplicationContext(); $sStateAttCode = MetaModel::GetStateAttributeCode($sClass); $iKey = $this->GetKey(); $aDetails = array(); $aFieldsMap = array(); $oPage->add("
\n"); foreach(MetaModel::ListAttributeDefs($sClass) as $sAttCode=>$oAttDef) { if ($oAttDef->IsWritable()) { if ($sStateAttCode == $sAttCode) { // State attribute is always read-only from the UI $sHTMLValue = $this->GetStateLabel(); $aDetails[] = array('label' => $oAttDef->GetLabel(), 'value' => $sHTMLValue); } else { $iFlags = $this->GetAttributeFlags($sAttCode); if ($iFlags & OPT_ATT_HIDDEN) { // Attribute is hidden, do nothing } else { if ($iFlags & OPT_ATT_READONLY) { // Attribute is read-only $sHTMLValue = $this->GetAsHTML($sAttCode); } else { $sValue = $this->Get($sAttCode); $sDisplayValue = $this->GetEditValue($sAttCode); $aArgs = array('this' => $this); $sInputId = $iFormId.'_'.$sAttCode; $sHTMLValue = "".self::GetFormElementForField($oPage, $sClass, $sAttCode, $oAttDef, $sValue, $sDisplayValue, $sInputId, '', $iFlags, $aArgs); $aFieldsMap[$sAttCode] = $sInputId; } $aDetails[] = array('label' => $oAttDef->GetLabel(), 'value' => $sHTMLValue); } } } } $oPage->details($aDetails); $oPage->add("\n"); $oPage->add("\n"); $oPage->add("\n"); $oPage->add("\n"); foreach($aExtraParams as $sName => $value) { $oPage->add("\n"); } $oPage->add($oAppContext->GetForForm()); $oPage->add("    \n"); $oPage->add("\n"); $oPage->add("\n"); $iFieldsCount = count($aFieldsMap); $sJsonFieldsMap = json_encode($aFieldsMap); $oPage->add_script( <<add("
\n"); $aStates = MetaModel::EnumStates($sClass); if ($oObjectToClone == null) { $sTargetState = MetaModel::GetDefaultState($sClass); } else { $sTargetState = $oObjectToClone->GetState(); } foreach(MetaModel::ListAttributeDefs($sClass) as $sAttCode=>$oAttDef) { if ($sStateAttCode == $sAttCode) { // State attribute is always read-only from the UI $sHTMLValue = $oObjectToClone->GetStateLabel(); $aDetails[] = array('label' => $oAttDef->GetLabel(), 'value' => $sHTMLValue); } else if ((!$oAttDef->IsExternalField()) && ($oAttDef->IsWritable()) ) { $sValue = ($oObjectToClone == null) ? '' : $oObjectToClone->Get($sAttCode); $sDisplayValue = ($oObjectToClone == null) ? '' : $oObjectToClone->GetEditValue($sAttCode); $iOptions = isset($aStates[$sTargetState]['attribute_list'][$sAttCode]) ? $aStates[$sTargetState]['attribute_list'][$sAttCode] : 0; $sHTMLValue = self::GetFormElementForField($oPage, $sClass, $sAttCode, $oAttDef, $sValue, $sDisplayValue, '', '', $iOptions, $aArgs); $aDetails[] = array('label' => $oAttDef->GetLabel(), 'value' => $sHTMLValue); } } $oPage->details($aDetails); if ($oObjectToClone != null) { $oPage->add("GetKey()."\">\n"); } $oPage->add("\n"); $oPage->add("\n"); $oPage->add("\n"); $oPage->add($oAppContext->GetForForm()); foreach($aExtraParams as $sName => $value) { $oPage->add("\n"); } $oPage->add("    \n"); $oPage->add("\n"); $oPage->add("
\n"); } protected static function GetCSSClasses($aCSSClasses) { $sCSSClasses = ''; if (!empty($aCSSClasses)) { $sCSSClasses = ' class="'.implode(' ', $aCSSClasses).'" '; } return $sCSSClasses; } } ?>