diff --git a/application/portalwebpage.class.inc.php b/application/portalwebpage.class.inc.php index 3f76927f8..18e6a438a 100644 --- a/application/portalwebpage.class.inc.php +++ b/application/portalwebpage.class.inc.php @@ -26,6 +26,7 @@ require_once(APPROOT."/application/nicewebpage.class.inc.php"); require_once(APPROOT."/application/applicationcontext.class.inc.php"); require_once(APPROOT."/application/user.preferences.class.inc.php"); + /** * Web page with some associated CSS and scripts (jquery) for a fancier display * of the Portal web page @@ -62,6 +63,7 @@ class PortalWebPage extends NiceWebPage $this->add_linked_script("../js/jquery.popupmenu.js"); $this->add_linked_script("../js/date.js"); $this->add_linked_script("../js/jquery.tablesorter.min.js"); + $this->add_linked_script("../js/jquery.tablesorter.pager.js"); $this->add_linked_script("../js/jquery.blockUI.js"); $this->add_linked_script("../js/utils.js"); $this->add_linked_script("../js/forms-json-utils.js"); @@ -173,5 +175,296 @@ EOF $this->s_content = '
'.$this->s_content.'
'; parent::output(); } + + /** + * Displays a list of objects, without any hyperlink (except for the object's details) + * @param DBObjectSet $oSet The set of objects to display + * @param Array $aZList The ZList (list of field codes) to use for the tabular display + * @param String $sEmptyListMessage Message displayed whenever the list is empty + * @return string The HTML text representing the list + */ + function DisplaySet($oSet, $aZList, $sEmptyListMessage = '') + { + if ($oSet->Count() > 0) + { + $sClass = $oSet->GetClass(); + if (is_subclass_of($sClass, 'cmdbAbstractObject')) + { + // Home-made and very limited display of an object set + + // + //$oSet->Seek(0);// juste pour que le warning soit moins crado + //$oSet->Fetch();// juste pour que le warning soit moins crado + // + + $this->add("
\n"); + cmdbAbstractObject::DisplaySet($this, $oSet, array('currentId' => "listOf$sClass", 'menu' => false, 'zlist' => false, 'extra_fields' => implode(',', $aZList))); + $this->add("
\n"); + } + else + { + // Home-made and very limited display of an object set + $aAttribs = array(); + $aValues = array(); + $aAttribs['key'] = array('label' => MetaModel::GetName($sClass), 'description' => ''); + foreach($aZList as $sAttCode) + { + $oAttDef = MetaModel::GetAttributeDef($sClass, $sAttCode); + $aAttribs[$sAttCode] = array('label' => $oAttDef->GetLabel(), 'description' => $oAttDef->GetDescription()); + } + while($oObj = $oSet->Fetch()) + { + $aRow = array(); + + $aRow['key'] = ''.$oObj->Get('friendlyname').''; + $sHilightClass = $oObj->GetHilightClass(); + if ($sHilightClass != '') + { + $aRow['@class'] = $sHilightClass; + } + foreach($aZList as $sAttCode) + { + $aRow[$sAttCode] = GetFieldAsHtml($oObj, $sAttCode); + } + $aValues[$oObj->GetKey()] = $aRow; + } + $this->table($aAttribs, $aValues); + } + } + elseif (strlen($sEmptyListMessage) > 0) + { + $this->add($sEmptyListMessage); + } + } + /** + * Display the attributes of an object (no title, no form) + * @param Object $oObj Any kind of object + * @param aAttList The list of attributes to display + * @return void + */ + function DisplayObjectDetails($oObj, $aAttList) + { + $sClass = get_class($oObj); + $aDetails = array(); + foreach($aAttList as $sAttCode) + { + $iFlags = $oObj->GetAttributeFlags($sAttCode); + $oAttDef = MetaModel::GetAttributeDef(get_class($oObj), $sAttCode); + if ( (!$oAttDef->IsLinkSet()) && (($iFlags & OPT_ATT_HIDDEN) == 0) ) + { + // Don't display linked set and non-visible attributes (in this state) + $sDisplayValue = GetFieldAsHtml($oObj, $sAttCode); + $aDetails[] = array('label' => ''.MetaModel::GetLabel($sClass, $sAttCode).'', 'value' => $sDisplayValue); + } + } + if (false) // Attachements !!!!! + { + $sAttachements = ''; + while($oDoc = $oDocSet->Fetch()) + { + $sAttachements .= ''; + } + $sAttachements .= '
'.$oDoc->GetAsHtml('contents').'
'; + $aDetails[] = array('label' => Dict::S('Portal:Attachments'), 'value' => $sAttachements); + } + $this->details($aDetails); + } + + /** + * xxxx + * @param Object $oObj Any kind of object + * @param $sLinkSetAttCode The attribute code of the link set attribute to display + * @param $sRemoteAttCode The external key on the linked class, pointing to the remote objects + * @param $aZList The list of attribute of the remote object + * @return void + */ + function DisplayObjectLinkset($oObj, $sLinkSetAttCode, $sRemoteAttCode, $aZList, $sEmptyListMessage = '') + { + if (empty($sEmptyListMessage)) + { + $sEmptyListMessage = Dict::S('UI:Search:NoObjectFound'); + } + + $oSet = $oObj->Get($sLinkSetAttCode); + + if ($oSet->Count() > 0) + { + $sClass = $oSet->GetClass(); + $oExtKeyToRemote = MetaModel::GetAttributeDef($sClass, $sRemoteAttCode); + $sRemoteClass = $oExtKeyToRemote->GetTargetClass(); + + $aAttribs = array(); + $aValues = array(); + $aAttribs['key'] = array('label' => MetaModel::GetName($sRemoteClass), 'description' => ''); + foreach($aZList as $sAttCode) + { + $oAttDef = MetaModel::GetAttributeDef($sRemoteClass, $sAttCode); + $aAttribs[$sAttCode] = array('label' => $oAttDef->GetLabel(), 'description' => $oAttDef->GetDescription()); + } + while($oLink = $oSet->Fetch()) + { + $aRow = array(); + + $oObj = MetaModel::GetObject($sRemoteClass, $oLink->Get($sRemoteAttCode)); + + $aRow['key'] = ''.$oObj->Get('friendlyname').''; + $sHilightClass = $oObj->GetHilightClass(); + if ($sHilightClass != '') + { + $aRow['@class'] = $sHilightClass; + } + foreach($aZList as $sAttCode) + { + $aRow[$sAttCode] = GetFieldAsHtml($oObj, $sAttCode); + } + $aValues[$oObj->GetKey()] = $aRow; + } + $this->Table($aAttribs, $aValues); + } + elseif (strlen($sEmptyListMessage) > 0) + { + $this->add($sEmptyListMessage); + } + } + + + protected function DisplaySearchField($sClass, $sAttSpec, $aExtraParams, $sPrefix, $sFieldName = null) + { + if (is_null($sFieldName)) + { + $sFieldName = str_replace('->', '_x_', $sAttSpec); + } + + $iPos = strpos($sAttSpec, '->'); + if ($iPos !== false) + { + $sAttCode = substr($sAttSpec, 0, $iPos); + $sSubSpec = substr($sAttSpec, $iPos + 2); + + if (!MetaModel::IsValidAttCode($sClass, $sAttCode)) + { + throw new Exception("Invalid attribute code '$sClass/$sAttCode' in search specification '$sAttSpec'"); + } + + $oAttDef = MetaModel::GetAttributeDef($sClass, $sAttCode); + if ($oAttDef->IsLinkSet()) + { + $sTargetClass = $oAttDef->GetLinkedClass(); + } + elseif ($oAttDef->IsExternalKey(EXTKEY_ABSOLUTE)) + { + $sTargetClass = $oAttDef->GetTargetClass(EXTKEY_ABSOLUTE); + } + else + { + throw new Exception("Attribute specification '$sAttSpec', '$sAttCode' should be either a link set or an external key"); + } + $this->DisplaySearchField($sTargetClass, $sSubSpec, $aExtraParams, $sPrefix, $sFieldName); + } + else + { + // $sAttSpec is an attribute code + // + $this->add(''); + $sFilterValue = ''; + $sFilterValue = utils::ReadParam($sPrefix.$sFieldName, ''); + $sFilterOpCode = null; // Use the default 'loose' OpCode + $oAttDef = MetaModel::GetAttributeDef($sClass, $sAttSpec); + if ($oAttDef->IsExternalKey()) + { + $sTargetClass = $oAttDef->GetTargetClass(); + $oAllowedValues = new DBObjectSet(new DBObjectSearch($sTargetClass)); + + $iFieldSize = $oAttDef->GetMaxSize(); + $iMaxComboLength = $oAttDef->GetMaximumComboLength(); + $this->add(" "); + //$oWidget = UIExtKeyWidget::DIsplayFromAttCode($sAttSpec, $sClass, $oAttDef->GetLabel(), $oAllowedValues, $sFilterValue, $sPrefix.$sFieldName, false, '', $sPrefix, ''); + //$this->add($oWidget->Display($this, $aExtraParams, true /* bSearchMode */)); + $aExtKeyParams = $aExtraParams; + $aExtKeyParams['iFieldSize'] = $oAttDef->GetMaxSize(); + $aExtKeyParams['iMinChars'] = $oAttDef->GetMinAutoCompleteChars(); + // DisplayFromAttCode($this, $sAttCode, $sClass, $sTitle, $oAllowedValues, $value, $iInputId, $bMandatory, $sFieldName = '', $sFormPrefix = '', $aArgs, $bSearchMode = false) + $sHtml = UIExtKeyWidget::DisplayFromAttCode($this, $sAttSpec, $sClass, $oAttDef->GetLabel(), $oAllowedValues, $sFilterValue, $sPrefix.$sFieldName, false, $sPrefix.$sFieldName, $sPrefix, $aExtKeyParams, true); + $this->add($sHtml); + } + else + { + $aAllowedValues = MetaModel::GetAllowedValues_flt($sClass, $sAttSpec, $aExtraParams); + if (is_null($aAllowedValues)) + { + // Any value is possible, display an input box + $this->add(" \n"); + } + else + { + //Enum field or external key, display a combo + $sValue = "\n"; + $this->add(" $sValue\n"); + } + } + unset($aExtraParams[$sFieldName]); + $this->add(' '); + } + } + + + public function DisplaySearchForm($sClass, $aAttList, $aExtraParams, $sPrefix) + { + $this->add("
\n"); // Don't use $_SERVER['SCRIPT_NAME'] since the form may be called asynchronously (from ajax.php) + // $this->add("

".Dict::Format('UI:SearchFor_Class_Objects', 'xxxxxx')."

\n"); + $this->add("

\n"); + foreach($aAttList as $sAttSpec) + { + //$oAppContext->Reset($sAttSpec); // Make sure the same parameter will not be passed twice + $this->DisplaySearchField($sClass, $sAttSpec, $aExtraParams, $sPrefix); + } + $this->add("

\n"); + $this->add("

\n"); + foreach($aExtraParams as $sName => $sValue) + { + $this->add("\n"); + } + // $this->add($oAppContext->GetForForm()); + $this->add("
\n"); + } + + + public function PostedParamsToFilter($sClass, $aAttList, $sPrefix) + { + $oFilter = new DBObjectSearch($sClass); + $iCountParams = 0; + foreach($aAttList as $sAttSpec) + { + $sFieldName = str_replace('->', '_x_', $sAttSpec); + $value = utils::ReadPostedParam($sPrefix.$sFieldName, null); + if (!is_null($value) && strlen($value) > 0) + { + $oFilter->AddConditionAdvanced($sAttSpec, $value); + $iCountParams++; + } + } + if ($iCountParams == 0) + { + return null; + } + else + { + return $oFilter; + } + } } ?>