function DisplayBareProperties(WebPage $oPage, $bEditMode = false, $sPrefix = '', $aExtraParams = array()) { $aFieldsMap = parent::DisplayBareProperties($oPage, $bEditMode, $sPrefix, $aExtraParams); if (!$bEditMode) { $sUrl = utils::GetAbsoluteUrlAppRoot() . 'webservices/export-v2.php?format=spreadsheet&login_mode=basic&query=' . $this->GetKey(); $sOql = $this->Get('oql'); $sMessage = null; try { $oSearch = DBObjectSearch::FromOQL($sOql); $aParameters = $oSearch->GetQueryParams(); foreach ($aParameters as $sParam => $val) { $sUrl .= '&arg_' . $sParam . '=["' . $sParam . '"]'; } $oPage->p(Dict::S('UI:Query:UrlForExcel') . ':<br/><textarea cols="80" rows="3" READONLY>' . $sUrl . '</textarea>'); if (count($aParameters) == 0) { $oBlock = new DisplayBlock($oSearch, 'list'); $aExtraParams = array('table_id' => 'query_preview_' . $this->getKey()); $sBlockId = 'block_query_preview_' . $this->GetKey(); // make a unique id (edition occuring in the same DOM) $oBlock->Display($oPage, $sBlockId, $aExtraParams); } } catch (OQLException $e) { $sMessage = '<div class="message message_error" style="padding-left: 30px;"><div style="padding: 10px;">' . Dict::Format('UI:RunQuery:Error', $e->getHtmlDesc()) . '</div></div>'; $oPage->p($sMessage); } } return $aFieldsMap; }
public function RenderContent(WebPage $oPage, $aExtraParams = array()) { $oSearch = new DBObjectSearch($this->sClass); $aParams = array_merge(array('open' => true, 'table_id' => 'Menu_' . utils::GetSafeId($this->GetMenuId())), $aExtraParams); $oBlock = new DisplayBlock($oSearch, 'search', false, $aParams); $oBlock->Display($oPage, 0); }
/** * Search for objects to be selected * @param WebPage $oP The page used for the output (usually an AjaxWebPage) * @param string $sRemoteClass Name of the "remote" class to perform the search on, must be a derived class of m_sRemoteClass * @param Array $aAlreadyLinkedIds List of IDs of objects of "remote" class already linked, to be filtered out of the search */ public function SearchObjectsToSelect(WebPage $oP, $sFilter, $sRemoteClass = '', $oObj = null) { if (is_null($sFilter)) { throw new Exception('Implementation: null value for allowed values definition'); } $oFilter = DBObjectSearch::FromOQL($sFilter); if (strlen($sRemoteClass) > 0) { $oFilter->ChangeClass($sRemoteClass); } $oFilter->SetModifierProperty('UserRightsGetSelectFilter', 'bSearchMode', $this->bSearchMode); $oBlock = new DisplayBlock($oFilter, 'list', false, array('query_params' => array('this' => $oObj))); $oBlock->Display($oP, $this->iId . '_results', array('this' => $oObj, 'cssCount' => '#count_' . $this->iId, 'menu' => false, 'selection_mode' => true, 'selection_type' => 'single', 'table_id' => 'select_' . $this->sAttCode)); // Don't display the 'Actions' menu on the results }
function DisplayBareRelations(WebPage $oPage, $bEditMode = false) { parent::DisplayBareRelations($oPage, $bEditMode); if (!$bEditMode) { $oPage->SetCurrentTab(Dict::S('Class:Subnet/Tab:IPUsage')); $bit_ip = ip2long($this->Get('ip')); $bit_mask = ip2long($this->Get('ip_mask')); $iIPMin = sprintf('%u', $bit_ip & $bit_mask | 1); // exclude the first one: identifies the subnet itself $iIPMax = sprintf('%u', ($bit_ip | ~$bit_mask) & 0xfffffffe); // exclude the last one : broadcast address $sIPMin = long2ip($iIPMin); $sIPMax = long2ip($iIPMax); $oPage->p(Dict::Format('Class:Subnet/Tab:IPUsage-explain', $sIPMin, $sIPMax)); $oIfFilter = DBObjectSearch::FromOQL("SELECT IPInterface AS if WHERE INET_ATON(if.ipaddress) >= INET_ATON('{$sIPMin}') AND INET_ATON(if.ipaddress) <= INET_ATON('{$sIPMax}')"); $oIfSet = new CMDBObjectSet($oIfFilter); $oBlock = new DisplayBlock($oIfFilter, 'list', false); $oBlock->Display($oPage, 'nwif', array('menu' => false)); $iCountUsed = $oIfSet->Count(); $iCountRange = $iIPMax - $iIPMin; // On 32-bit systems the substraction will be computed using floats for values greater than PHP_MAX_INT; $iFreeCount = $iCountRange - $iCountUsed; $oPage->SetCurrentTab(Dict::S('Class:Subnet/Tab:FreeIPs')); $oPage->p(Dict::Format('Class:Subnet/Tab:FreeIPs-count', $iFreeCount)); $oPage->p(Dict::S('Class:Subnet/Tab:FreeIPs-explain')); $aUsedIPs = $oIfSet->GetColumnAsArray('ipaddress', false); $iAnIP = $iIPMin; $iFound = 0; while ($iFound < min($iFreeCount, 10) && $iAnIP <= $iIPMax) { $sAnIP = long2ip($iAnIP); if (!in_array($sAnIP, $aUsedIPs)) { $iFound++; $oPage->p($sAnIP); } else { } $iAnIP++; } } }
$oP->add('<h2>' . Dict::S('UI:NotificationsMenu:AvailableTriggers') . '</h2>'); $oFilter = new DBObjectSearch('Trigger'); $aParams = array(); $oBlock = new DisplayBlock($oFilter, 'list', false, $aParams); $oBlock->Display($oP, 'block_0', $aParams); $aActionClasses = array(); foreach (MetaModel::EnumChildClasses('Action', ENUM_CHILD_CLASSES_EXCLUDETOP) as $sActionClass) { if (!MetaModel::IsAbstract($sActionClass)) { $aActionClasses[] = $sActionClass; } } $oP->SetCurrentTab(Dict::S('UI:NotificationsMenu:Actions')); if (count($aActionClasses) == 1) { // Preserve old style $oP->add('<h2>' . Dict::S('UI:NotificationsMenu:AvailableActions') . '</h2>'); } $iBlock = 0; foreach ($aActionClasses as $sActionClass) { if (count($aActionClasses) > 1) { // New style $oP->add('<h2>' . MetaModel::GetName($sActionClass) . '</h2>'); } $oFilter = new DBObjectSearch($sActionClass); $aParams = array(); $oBlock = new DisplayBlock($oFilter, 'list', false, $aParams); $oBlock->Display($oP, 'block_action_' . $iBlock, $aParams); $iBlock++; } $oP->SetCurrentTab(''); $oP->SetCurrentTabContainer(''); $oP->output();
/** * Displays a form (checkboxes) to select the objects for which to apply a given action * Only the objects for which the action is valid can be checked. By default all valid objects are checked * @param $oP WebPage The page for output * @param $oFilter DBObjectSearch The filter that defines the list of objects * @param $sNextOperation string The next operation (code) to be executed when the form is submitted * @param $oChecker ActionChecker The helper class/instance used to check for which object the action is valid * @return none */ function DisplayMultipleSelectionForm($oP, $oFilter, $sNextOperation, $oChecker, $aExtraFormParams = array()) { $oAppContext = new ApplicationContext(); $iBulkActionAllowed = $oChecker->IsAllowed(); $sClass = $oFilter->GetClass(); $aExtraParams = array('selection_type' => 'multiple', 'selection_mode' => true, 'display_limit' => false, 'menu' => false); if ($iBulkActionAllowed == UR_ALLOWED_DEPENDS) { $aAllowed = array(); $aExtraParams['selection_enabled'] = $oChecker->GetAllowedIDs(); } else { if (UR_ALLOWED_NO) { throw new ApplicationException(Dict::Format('UI:ActionNotAllowed')); } } $oBlock = new DisplayBlock($oFilter, 'list', false); $oP->add("<form method=\"post\" action=\"./UI.php\">\n"); $oP->add("<input type=\"hidden\" name=\"operation\" value=\"{$sNextOperation}\">\n"); $oP->add("<input type=\"hidden\" name=\"class\" value=\"" . $oFilter->GetClass() . "\">\n"); $oP->add("<input type=\"hidden\" name=\"filter\" value=\"" . $oFilter->Serialize() . "\">\n"); $oP->add("<input type=\"hidden\" name=\"transaction_id\" value=\"" . utils::GetNewTransactionId() . "\">\n"); foreach ($aExtraFormParams as $sName => $sValue) { $oP->add("<input type=\"hidden\" name=\"{$sName}\" value=\"{$sValue}\">\n"); } $oP->add($oAppContext->GetForForm()); $oBlock->Display($oP, 1, $aExtraParams); $oP->add("<input type=\"button\" value=\"" . Dict::S('UI:Button:Cancel') . "\" onClick=\"window.history.back()\"> <input type=\"submit\" value=\"" . Dict::S('UI:Button:Next') . "\">\n"); $oP->add("</form>\n"); $oP->add_ready_script("\$('#1 table.listResults').trigger('check_all');"); }
$oP->set_base($sUrl . 'pages/'); if (count($aFields) > 0) { $iSearch = array_search('id', $aFields); if ($iSearch !== false) { $bViewLink = true; unset($aFields[$iSearch]); } else { $bViewLink = false; } $sFields = implode(',', $aFields); $aExtraParams = array('menu' => false, 'toolkit_menu' => false, 'display_limit' => false, 'localize_values' => $bLocalize, 'zlist' => false, 'extra_fields' => $sFields, 'view_link' => $bViewLink); } else { $aExtraParams = array('menu' => false, 'toolkit_menu' => false, 'display_limit' => false, 'localize_values' => $bLocalize, 'zlist' => 'details'); } $oResultBlock = new DisplayBlock($oFilter, 'list', false, $aExtraParams); $oResultBlock->Display($oP, 'expresult'); break; case 'csv': $oP = new CSVPage("iTop - Export"); $sFields = implode(',', $aFields); $sCharset = utils::ReadParam('charset', MetaModel::GetConfig()->Get('csv_file_default_charset'), true, 'raw_data'); $sCSVData = cmdbAbstractObject::GetSetAsCSV($oSet, array('fields' => $sFields, 'fields_advanced' => $bFieldsAdvanced, 'localize_values' => $bLocalize), $sCharset); if ($sCharset == 'UTF-8') { $sOutputData = UTF8_BOM . $sCSVData; } else { $sOutputData = $sCSVData; } if ($sFileName == '') { // Plain text => Firefox will NOT propose to download the file $oP->add_header("Content-type: text/plain; charset={$sCharset}"); } else {
/** * Search for objects to be linked to the current object (i.e "remote" objects) * @param WebPage $oP The page used for the output (usually an AjaxWebPage) * @param string $sRemoteClass Name of the "remote" class to perform the search on, must be a derived class of $this->sLinkedClass * @param array $aAlreadyLinked Array of indentifiers of objects which are already linke to the current object (or about to be linked) * @param DBObject $oCurrentObj The object currently being edited... if known... */ public function SearchObjectsToAdd(WebPage $oP, $sRemoteClass = '', $aAlreadyLinked = array(), $oCurrentObj = null) { if ($sRemoteClass == '') { $sRemoteClass = $this->sLinkedClass; } $oLinksetDef = MetaModel::GetAttributeDef($this->sClass, $this->sAttCode); $valuesDef = $oLinksetDef->GetValuesDef(); if ($valuesDef === null) { $oFilter = new DBObjectSearch($this->sLinkedClass); } else { if (!$valuesDef instanceof ValueSetObjects) { throw new Exception('Error: only ValueSetObjects are supported for "allowed_values" in AttributeLinkedSet (' . $this->sClass . '/' . $this->sAttCode . ').'); } $oFilter = DBObjectSearch::FromOQL($valuesDef->GetFilterExpression()); } if ($oCurrentObj != null && MetaModel::IsSameFamilyBranch($sRemoteClass, $this->sClass)) { // Prevent linking to self if the linked object is of the same family // and laready present in the database if (!$oCurrentObj->IsNew()) { $oFilter->AddCondition('id', $oCurrentObj->GetKey(), '!='); } } if (count($aAlreadyLinked) > 0) { $oFilter->AddCondition('id', $aAlreadyLinked, 'NOTIN'); } if ($oCurrentObj != null) { $aArgs = array_merge($oCurrentObj->ToArgs('this'), $oFilter->GetInternalParams()); $oFilter->SetInternalParams($aArgs); } $oBlock = new DisplayBlock($oFilter, 'list', false); $oBlock->Display($oP, "ResultsToAdd_{$this->sInputid}", array('menu' => false, 'cssCount' => '#count_' . $this->sInputid, 'selection_mode' => true, 'table_id' => 'add_' . $this->sInputid)); // Don't display the 'Actions' menu on the results }
/** * Search for objects to be linked to the current object (i.e "remote" objects) * @param WebPage $oP The page used for the output (usually an AjaxWebPage) * @param string $sRemoteClass Name of the "remote" class to perform the search on, must be a derived class of m_sRemoteClass * @param Array $aAlreadyLinkedIds List of IDs of objects of "remote" class already linked, to be filtered out of the search */ public function SearchObjectsToAdd(WebPage $oP, $sRemoteClass = '', $aAlreadyLinkedIds = array()) { if ($sRemoteClass != '') { // assert(MetaModel::IsParentClass($this->m_sRemoteClass, $sRemoteClass)); $oFilter = new DBObjectSearch($sRemoteClass); } else { // No remote class specified use the one defined in the linkedset $oFilter = new DBObjectSearch($this->m_sRemoteClass); } if (!$this->m_bDuplicatesAllowed && count($aAlreadyLinkedIds) > 0) { // Positive IDs correspond to existing link records // negative IDs correspond to "remote" objects to be linked $aLinkIds = array(); $aRemoteObjIds = array(); foreach ($aAlreadyLinkedIds as $iId) { if ($iId > 0) { $aLinkIds[] = $iId; } else { $aRemoteObjIds[] = -$iId; } } if (count($aLinkIds) > 0) { // Search for the links to find to which "remote" object they are linked $oLinkFilter = new DBObjectSearch($this->m_sLinkedClass); $oLinkFilter->AddCondition('id', $aLinkIds, 'IN'); $oLinkSet = new CMDBObjectSet($oLinkFilter); while ($oLink = $oLinkSet->Fetch()) { $aRemoteObjIds[] = $oLink->Get($this->m_sExtKeyToRemote); } } $oFilter->AddCondition('id', $aRemoteObjIds, 'NOTIN'); } $oSet = new CMDBObjectSet($oFilter); $oBlock = new DisplayBlock($oFilter, 'list', false); $oBlock->Display($oP, "ResultsToAdd_{$this->m_sAttCode}", array('menu' => false, 'cssCount' => '#count_' . $this->m_sAttCode . $this->m_sNameSuffix, 'selection_mode' => true, 'table_id' => 'add_' . $this->m_sAttCode)); // Don't display the 'Actions' menu on the results }
public function Render($oPage, $bEditMode = false, $aExtraParams = array()) { $sClass = $this->aProperties['class']; $oPage->add('<div class="dashlet-content">'); $oFilter = new DBObjectSearch($sClass); $oBlock = new DisplayBlock($oFilter, 'actions'); $aExtraParams = array('context_filter' => 1); $sBlockId = 'block_' . $this->sId . ($bEditMode ? '_edit' : ''); // make a unique id (edition occuring in the same DOM) $oBlock->Display($oPage, $sBlockId, $aExtraParams); $oPage->add('</div>'); }
$oP->add("<textarea cols=\"120\" rows=\"8\" name=\"expression\">" . htmlentities($sExpression, ENT_QUOTES, 'UTF-8') . "</textarea>\n"); if (count($aArgs) > 0) { $oP->add("<div class=\"wizContainer\">\n"); $oP->add("<h3>Query arguments</h3>\n"); foreach ($aArgs as $sParam => $sValue) { $oP->p("{$sParam}: <input type=\"string\" name=\"arg_{$sParam}\" value=\"{$sValue}\">\n"); } $oP->add("</div>\n"); } $oP->add("<input type=\"submit\" value=\"" . Dict::S('UI:Button:Evaluate') . "\">\n"); $oP->add($oAppContext->GetForForm()); $oP->add("</form>\n"); if ($oFilter) { $oP->add("<h3>Query results</h3>\n"); $oResultBlock = new DisplayBlock($oFilter, 'list', false); $oResultBlock->Display($oP, 'runquery'); $oP->p(''); $oP->StartCollapsibleSection(Dict::S('UI:RunQuery:MoreInfo'), false); $oP->p(Dict::S('UI:RunQuery:DevelopedQuery') . htmlentities($oFilter->ToOQL(), ENT_QUOTES, 'UTF-8')); $oP->p(Dict::S('UI:RunQuery:SerializedFilter') . $oFilter->serialize()); $oP->EndCollapsibleSection(); } elseif ($sSyntaxError) { if ($e instanceof OqlException) { $sWrongWord = $e->GetWrongWord(); $aSuggestedWords = $e->GetSuggestions(); if (count($aSuggestedWords) > 0) { $sSuggestedWord = OqlException::FindClosestString($sWrongWord, $aSuggestedWords); if (strlen($sSuggestedWord) > 0) { $oP->p('<b>' . Dict::Format('UI:RunQuery:Error', $e->GetIssue() . ' <em>' . $sWrongWord) . '</em></b>'); $sBefore = substr($sExpression, 0, $e->GetColumn()); $sAfter = substr($sExpression, $e->GetColumn() + strlen($sWrongWord));
$oPage->SetContentType('application/json'); break; case 'relation_groups': $aGroups = utils::ReadParam('groups'); $iBlock = 1; // Zero is not a valid blockid foreach ($aGroups as $idx => $aDefinition) { $sListClass = $aDefinition['class']; $oSearch = new DBObjectSearch($sListClass); $oSearch->AddCondition('id', $aDefinition['keys'], 'IN'); $oPage->add("<h1>" . Dict::Format('UI:RelationGroupNumber_N', 1 + $idx) . "</h1>\n"); $oPage->add("<div id=\"relation_group_{$idx}\" class=\"page_header\">\n"); $oPage->add("<h2>" . MetaModel::GetClassIcon($sListClass) . " <span class=\"hilite\">" . Dict::Format('UI:Search:Count_ObjectsOf_Class_Found', count($aDefinition['keys']), Metamodel::GetName($sListClass)) . "</h2>\n"); $oPage->add("</div>\n"); $oBlock = new DisplayBlock($oSearch, 'list'); $oBlock->Display($oPage, 'group_' . $iBlock++); $oPage->p(' '); // Some space ? } break; case 'ticket_impact': require_once APPROOT . 'core/simplegraph.class.inc.php'; require_once APPROOT . 'core/relationgraph.class.inc.php'; require_once APPROOT . 'core/displayablegraph.class.inc.php'; $sRelation = utils::ReadParam('relation', 'impacts'); $sDirection = utils::ReadParam('direction', 'down'); $iGroupingThreshold = utils::ReadParam('g', 5); $sClass = utils::ReadParam('class', '', false, 'class'); $sAttCode = utils::ReadParam('attcode', 'functionalcis_list'); $sImpactAttCode = utils::ReadParam('impact_attcode', 'impact_code'); $sImpactAttCodeValue = utils::ReadParam('impact_attcode_value', 'manual');
throw new ApplicationException(Dict::Format('UI:Error:1ParametersMissing', 'id')); } $oReplica = MetaModel::GetObject('SynchroReplica', $iId); $oReplica->DisplayDetails($oP); break; case 'oql': $sOQL = utils::ReadParam('oql', null, false, 'raw_data'); if ($sOQL == null) { throw new ApplicationException(Dict::Format('UI:Error:1ParametersMissing', 'oql')); } $oFilter = DBObjectSearch::FromOQL($sOQL); $oBlock1 = new DisplayBlock($oFilter, 'search', false, array('menu' => false)); $oBlock1->Display($oP, 0); $oP->add('<p class="page-header">' . MetaModel::GetClassIcon('SynchroReplica') . Dict::S('Core:SynchroReplica:ListOfReplicas') . '</p>'); $iSourceId = utils::ReadParam('datasource', null); if ($iSourceId != null) { $oSource = MetaModel::GetObject('SynchroDataSource', $iSourceId); $oP->p(Dict::Format('Core:SynchroReplica:BackToDataSource', $oSource->GetHyperlink()) . '</a>'); } $oBlock = new DisplayBlock($oFilter, 'list', false, array('menu' => false)); $oBlock->Display($oP, 1); break; } } catch (CoreException $e) { $oP->p('<b>An error occured while running the query:</b>'); $oP->p($e->getHtmlDesc()); } catch (Exception $e) { $oP->p('<b>An error occured while running the query:</b>'); $oP->p($e->getMessage()); } $oP->output();
public function SearchObjectsToAdd(WebPage $oP) { //$oAttDef = MetaModel::GetAttributeDef($this->m_sClass, $this->m_sLinkageAttr); $oFilter = new DBObjectSearch($this->m_sLinkedClass); $oSet = new CMDBObjectSet($oFilter); $oBlock = new DisplayBlock($oFilter, 'list', false); $oBlock->Display($oP, 'ResultsToAdd', array('menu' => false, 'selection_mode' => true)); // Don't display the 'Actions' menu on the results }
function DisplayBareRelations(WebPage $oPage, $bEditMode = false) { $aRedundancySettings = $this->FindVisibleRedundancySettings(); // Related objects: display all the linkset attributes, each as a separate tab // In the order described by the 'display' ZList $aList = $this->FlattenZList(MetaModel::GetZListItems(get_class($this), 'details')); if (count($aList) == 0) { // Empty ZList defined, display all the linkedset attributes defined $aList = array_keys(MetaModel::ListAttributeDefs(get_class($this))); } $sClass = get_class($this); foreach ($aList as $sAttCode) { $oAttDef = MetaModel::GetAttributeDef(get_class($this), $sAttCode); // Display mode if (!$oAttDef->IsLinkset()) { continue; } // Process only linkset attributes... // $oSet = new DBObjectSet($this->Get($sAttCode)->GetFilter()); // Why do something so useless ? $oSet = $this->Get($sAttCode); $iCount = $oSet->Count(); $sCount = ''; if ($iCount != 0) { $sCount = " ({$iCount})"; } $oPage->SetCurrentTab($oAttDef->GetLabel() . $sCount); if ($this->IsNew()) { $iFlags = $this->GetInitialStateAttributeFlags($sAttCode); } else { $iFlags = $this->GetAttributeFlags($sAttCode); } // Adjust the flags according to user rights if ($oAttDef->IsIndirect()) { $sLinkedClass = $oAttDef->GetLinkedClass(); $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)) { $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)) { $iFlags |= OPT_ATT_HIDDEN; } } else { // 1:n links => must be allowed to modify the linked class in order to edit the linkedset if (!UserRights::IsActionAllowed($oAttDef->GetLinkedClass(), UR_ACTION_MODIFY)) { $iFlags |= OPT_ATT_READONLY; } // 1:n links => must be allowed to read the linked class in order to display the linkedset if (!UserRights::IsActionAllowed($oAttDef->GetLinkedClass(), UR_ACTION_READ)) { $iFlags |= OPT_ATT_HIDDEN; } } // Non-readable/hidden linkedset... don't display anything if ($iFlags & OPT_ATT_HIDDEN) { continue; } $aArgs = array('this' => $this); $bReadOnly = $iFlags & (OPT_ATT_READONLY | OPT_ATT_SLAVE); if ($bEditMode && !$bReadOnly) { $sInputId = $this->m_iFormId . '_' . $sAttCode; $sLinkedClass = $oAttDef->GetLinkedClass(); if ($oAttDef->IsIndirect()) { $oLinkingAttDef = MetaModel::GetAttributeDef($sLinkedClass, $oAttDef->GetExtKeyToRemote()); $sTargetClass = $oLinkingAttDef->GetTargetClass(); } else { $sTargetClass = $sLinkedClass; } $oPage->p(MetaModel::GetClassIcon($sTargetClass) . " " . $oAttDef->GetDescription() . '<span id="busy_' . $sInputId . '"></span>'); $oValue = $this->Get($sAttCode); $sDisplayValue = ''; // not used $sHTMLValue = "<span id=\"field_{$sInputId}\">" . self::GetFormElementForField($oPage, $sClass, $sAttCode, $oAttDef, $oValue, $sDisplayValue, $sInputId, '', $iFlags, $aArgs) . '</span>'; $this->AddToFieldsMap($sAttCode, $sInputId); $oPage->add($sHTMLValue); } else { // Display mode if (!$oAttDef->IsIndirect()) { // 1:n links $sTargetClass = $oAttDef->GetLinkedClass(); $aDefaults = array($oAttDef->GetExtKeyToMe() => $this->GetKey()); $oAppContext = new ApplicationContext(); foreach ($oAppContext->GetNames() as $sKey) { // The linked object inherits the parent's value for the context if (MetaModel::IsValidAttCode($sClass, $sKey)) { $aDefaults[$sKey] = $this->Get($sKey); } } $aParams = array('target_attr' => $oAttDef->GetExtKeyToMe(), 'object_id' => $this->GetKey(), 'menu' => false, 'default' => $aDefaults, 'table_id' => $sClass . '_' . $sAttCode); } else { // n:n links $sLinkedClass = $oAttDef->GetLinkedClass(); $oLinkingAttDef = MetaModel::GetAttributeDef($sLinkedClass, $oAttDef->GetExtKeyToRemote()); $sTargetClass = $oLinkingAttDef->GetTargetClass(); $bMenu = $this->Get($sAttCode)->Count() > 0; // The menu is enabled only if there are already some elements... $aParams = array('link_attr' => $oAttDef->GetExtKeyToMe(), 'object_id' => $this->GetKey(), 'target_attr' => $oAttDef->GetExtKeyToRemote(), 'view_link' => false, 'menu' => false, 'display_limit' => true, 'table_id' => $sClass . '_' . $sAttCode); } $oPage->p(MetaModel::GetClassIcon($sTargetClass) . " " . $oAttDef->GetDescription()); $oBlock = new DisplayBlock($this->Get($sAttCode)->GetFilter(), 'list', false); $oBlock->Display($oPage, 'rel_' . $sAttCode, $aParams); } if (array_key_exists($sAttCode, $aRedundancySettings)) { foreach ($aRedundancySettings[$sAttCode] as $oRedundancyAttDef) { $sRedundancyAttCode = $oRedundancyAttDef->GetCode(); $sValue = $this->Get($sRedundancyAttCode); $iRedundancyFlags = $this->GetFormAttributeFlags($sRedundancyAttCode); $bRedundancyReadOnly = $iRedundancyFlags & (OPT_ATT_READONLY | OPT_ATT_SLAVE); $oPage->add('<fieldset>'); $oPage->add('<legend>' . $oRedundancyAttDef->GetLabel() . '</legend>'); if ($bEditMode && !$bRedundancyReadOnly) { $sInputId = $this->m_iFormId . '_' . $sRedundancyAttCode; $oPage->add("<span id=\"field_{$sInputId}\">" . self::GetFormElementForField($oPage, $sClass, $sRedundancyAttCode, $oRedundancyAttDef, $sValue, '', $sInputId, '', $iFlags, $aArgs) . '</span>'); } else { $oPage->add($oRedundancyAttDef->GetDisplayForm($sValue, $oPage, false, $this->m_iFormId)); } $oPage->add('</fieldset>'); } } } $oPage->SetCurrentTab(''); foreach (MetaModel::EnumPlugins('iApplicationUIExtension') as $oExtensionInstance) { $oExtensionInstance->OnDisplayRelations($this, $oPage, $bEditMode); } // Display Notifications after the other tabs since this tab disappears in edition if (!$bEditMode) { // Look for any trigger that considers this object as "In Scope" // If any trigger has been found then display a tab with notifications // $oTriggerSet = new CMDBObjectSet(new DBObjectSearch('Trigger')); $aTriggers = array(); while ($oTrigger = $oTriggerSet->Fetch()) { if ($oTrigger->IsInScope($this)) { $aTriggers[] = $oTrigger->GetKey(); } } if (count($aTriggers) > 0) { $iId = $this->GetKey(); $sTriggersList = implode(',', $aTriggers); $aNotifSearches = array(); $iNotifsCount = 0; $aNotificationClasses = MetaModel::EnumChildClasses('EventNotification', ENUM_CHILD_CLASSES_EXCLUDETOP); foreach ($aNotificationClasses as $sNotifClass) { $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(); } // 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)); $oBlock = new DisplayBlock($aNotifSearches[$sNotifClass], 'list', false); $oBlock->Display($oPage, 'notifications_' . $sNotifClass, array('menu' => false)); } } } }
// Second part: advanced search form: if (!empty($sFilter)) { $oFilter = CMDBSearchFilter::unserialize($sFilter); } else { if (!empty($sClass)) { $oFilter = new CMDBSearchFilter($sClass); } } } } catch (CoreException $e) { $oFilter = new CMDBSearchFilter($sClass); $oP->P("<b>" . Dict::Format('UI:UniversalSearch:Error', $e->getHtmlDesc()) . "</b>"); } if ($oFilter != null) { $oSet = new CMDBObjectSet($oFilter); $oBlock = new DisplayBlock($oFilter, 'search', false); $aExtraParams = $oAppContext->GetAsHash(); $aExtraParams['open'] = true; $aExtraParams['baseClass'] = $sBaseClass; $aExtraParams['action'] = utils::GetAbsoluteUrlAppRoot() . 'pages/UniversalSearch.php'; //$aExtraParams['class'] = $sClassName; $oBlock->Display($oP, 0, $aExtraParams); // Search results $oResultBlock = new DisplayBlock($oFilter, 'list', false); $oResultBlock->Display($oP, 1); // Menu node $sFilter = $oFilter->ToOQL(); $oP->add("\n<!-- {$sFilter} -->\n"); } $oP->add("</div>\n"); $oP->output();
/** * DisplayObjectLinkset * @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 * @param $sEmptyListMessage The message to display if the list is empty * @return void */ public function DisplayObjectLinkset($oObj, $sLinkSetAttCode, $sRemoteAttCode, $aZList, $sEmptyListMessage = '', $oSearchRestriction = null) { if (empty($sEmptyListMessage)) { $sEmptyListMessage = Dict::S('UI:Search:NoObjectFound'); } $oLinkSet = $oObj->Get($sLinkSetAttCode); if ($oLinkSet->Count() > 0) { $sClass = $oLinkSet->GetClass(); $oExtKeyToRemote = MetaModel::GetAttributeDef($sClass, $sRemoteAttCode); $sRemoteClass = $oExtKeyToRemote->GetTargetClass(); if (is_null($oSearchRestriction)) { $oObjSearch = new DBObjectSearch($sRemoteClass); } else { $oObjSearch = $oSearchRestriction; } $oObjSearch->AddCondition_ReferencedBy($oLinkSet->GetFilter(), $sRemoteAttCode); $aExtraParams = array('menu' => false, 'toolkit_menu' => false, 'zlist' => false, 'extra_fields' => implode(',', $aZList)); $oBlock = new DisplayBlock($oObjSearch, 'list', false); $oBlock->Display($this, 1, $aExtraParams); } elseif (strlen($sEmptyListMessage) > 0) { $this->add($sEmptyListMessage); } }
/** * Displays the user's changeable preferences * @param $oP WebPage The web page used for the output */ function DisplayPreferences($oP) { $oAppContext = new ApplicationContext(); $sURL = utils::GetAbsoluteUrlAppRoot() . 'pages/UI.php?' . $oAppContext->GetForLink(); $oP->add('<div class="page_header"><h1><img style="vertical-align:middle" src="../images/preferences.png"/> ' . Dict::S('UI:Preferences') . "</h1></div>\n"); $oP->add('<div id="user_prefs" style="max-width:800px; min-width:400px;">'); ////////////////////////////////////////////////////////////////////////// // // User Language selection // ////////////////////////////////////////////////////////////////////////// $oP->add('<fieldset><legend>' . Dict::S('UI:FavoriteLanguage') . '</legend>'); $oP->add('<form method="post">'); $aLanguages = Dict::GetLanguages(); $aSortedlang = array(); foreach ($aLanguages as $sCode => $aLang) { if (MetaModel::GetConfig()->Get('demo_mode')) { if ($sCode != Dict::GetUserLanguage()) { // Demo mode: only the current user language is listed in the available choices continue; } } $aSortedlang[$aLang['description']] = $sCode; } ksort($aSortedlang); $oP->add('<p>' . Dict::S('UI:Favorites:SelectYourLanguage') . ' <select name="language">'); foreach ($aSortedlang as $sCode) { $sSelected = $sCode == Dict::GetUserLanguage() ? 'selected' : ''; $oP->add('<option value="' . $sCode . '" ' . $sSelected . '/>' . $aLanguages[$sCode]['description'] . ' (' . $aLanguages[$sCode]['localized_description'] . ')</option>'); } $oP->add('</select></p>'); $oP->add('<input type="hidden" name="operation" value="apply_language"/>'); $oP->add($oAppContext->GetForForm()); $oP->add('<p><input type="button" onClick="window.location.href=\'' . $sURL . '\'" value="' . Dict::S('UI:Button:Cancel') . '"/>'); $oP->add(' '); $oP->add('<input type="submit" value="' . Dict::S('UI:Button:Apply') . '"/></p>'); $oP->add('</form>'); $oP->add('</fieldset>'); ////////////////////////////////////////////////////////////////////////// // // Other (miscellaneous) settings // ////////////////////////////////////////////////////////////////////////// $oP->add('<fieldset><legend>' . Dict::S('UI:FavoriteOtherSettings') . '</legend>'); $oP->add('<form method="post" onsubmit="return ValidateOtherSettings()">'); $iDefaultPageSize = appUserPreferences::GetPref('default_page_size', MetaModel::GetConfig()->GetMinDisplayLimit()); $oP->add('<p>' . Dict::Format('UI:Favorites:Default_X_ItemsPerPage', '<input id="default_page_size" name="default_page_size" type="text" size="3" value="' . $iDefaultPageSize . '"/><span id="v_default_page_size"></span>') . '</p>'); $oP->add('<input type="hidden" name="operation" value="apply_others"/>'); $oP->add($oAppContext->GetForForm()); $oP->add('<p><input type="button" onClick="window.location.href=\'' . $sURL . '\'" value="' . Dict::S('UI:Button:Cancel') . '"/>'); $oP->add(' '); $oP->add('<input id="other_submit" type="submit" value="' . Dict::S('UI:Button:Apply') . '"/></p>'); $oP->add('</form>'); $oP->add('</fieldset>'); $oP->add_script(<<<EOF function ValidateOtherSettings() { \tvar sPageLength = \$('#default_page_size').val(); \tvar iPageLength = parseInt(sPageLength , 10); \tif (/^[0-9]+\$/.test(sPageLength) && (iPageLength > 0)) \t{ \t\t\$('#v_default_page_size').html(''); \t\t\$('#other_submit').removeAttr('disabled'); \t\treturn true; \t} \telse \t{ \t\t\$('#v_default_page_size').html('<img src="../images/validation_error.png"/>'); \t\t\$('#other_submit').attr('disabled', 'disabled'); \t\treturn false; \t} } EOF ); ////////////////////////////////////////////////////////////////////////// // // Favorite Organizations // ////////////////////////////////////////////////////////////////////////// $oP->add('<fieldset><legend>' . Dict::S('UI:FavoriteOrganizations') . '</legend>'); $oP->p(Dict::S('UI:FavoriteOrganizations+')); $oP->add('<form method="post">'); // Favorite organizations: the organizations listed in the drop-down menu $sOQL = ApplicationMenu::GetFavoriteSiloQuery(); $oFilter = DBObjectSearch::FromOQL($sOQL); $oBlock = new DisplayBlock($oFilter, 'list', false); $oBlock->Display($oP, 1, array('menu' => false, 'selection_mode' => true, 'selection_type' => 'multiple', 'cssCount' => '.selectedCount', 'table_id' => 'user_prefs')); $oP->add($oAppContext->GetForForm()); $oP->add('<input type="hidden" name="operation" value="apply"/>'); $oP->add('<p><input type="button" onClick="window.location.href=\'' . $sURL . '\'" value="' . Dict::S('UI:Button:Cancel') . '"/>'); $oP->add(' '); $oP->add('<input type="submit" value="' . Dict::S('UI:Button:Apply') . '"/></p>'); $oP->add('</form>'); $oP->add('</fieldset>'); $aFavoriteOrgs = appUserPreferences::GetPref('favorite_orgs', null); if ($aFavoriteOrgs == null) { // All checked $oP->add_ready_script(<<<EOF \tif (\$('#user_prefs table.pagination').length > 0) \t{ \t\t// paginated display, restore the selection \t\tvar pager = \$('#user_prefs form .pager'); \t\t\$(':input[name=selectionMode]', pager).val('negative'); \t\t\$('#user_prefs table.listResults').trigger('load_selection'); \t} \telse \t{ \t\t\$('#user_prefs table.listResults').trigger('check_all'); \t} EOF ); } else { $sChecked = implode('","', $aFavoriteOrgs); $oP->add_ready_script(<<<EOF \tvar aChecked = ["{$sChecked}"]; \tif (\$('#user_prefs table.pagination').length > 0) \t{ \t\t// paginated display, restore the selection \t\tvar pager = \$('#user_prefs form .pager'); \t\t\$(':input[name=selectionMode]', pager).val('positive'); \t\tfor (i=0; i<aChecked.length; i++) \t\t{ \t\t\tpager.append('<input type="hidden" name="storedSelection[]" id="'+aChecked[i]+'" value="'+aChecked[i]+'"/>'); \t\t} \t\t\$('#user_prefs table.listResults').trigger('load_selection'); \t\t \t} \telse \t{ \t\t\$('#user_prefs form :checkbox[name^=selectObject]').each( function() \t\t\t{ \t\t\t\tif (\$.inArray(\$(this).val(), aChecked) > -1) \t\t\t\t{ \t\t\t\t\t\$(this).attr('checked', true); \t\t\t\t\t\$(this).trigger('change'); \t\t\t\t} \t\t\t}); \t} EOF ); } ////////////////////////////////////////////////////////////////////////// // // Shortcuts // ////////////////////////////////////////////////////////////////////////// $oP->add('<fieldset><legend>' . Dict::S('Menu:MyShortcuts') . '</legend>'); //$oP->p(Dict::S('UI:Menu:MyShortcuts+')); $oBMSearch = new DBObjectSearch('Shortcut'); $oBMSearch->AddCondition('user_id', UserRights::GetUserId(), '='); //$aExtraParams = array('menu' => false, 'toolkit_menu' => false, 'display_limit' => false, 'localize_values' => $bLocalize, 'zlist' => 'details'); $aExtraParams = array(); $oBlock = new DisplayBlock($oBMSearch, 'list', false, $aExtraParams); $oBlock->Display($oP, 'shortcut_list', array('view_link' => false, 'menu' => false, 'toolkit_menu' => false, 'selection_mode' => true, 'selection_type' => 'multiple', 'cssCount' => '#shortcut_selection_count', 'table_id' => 'user_prefs_shortcuts')); $oP->add('<p>'); $oSet = new DBObjectSet($oBMSearch); if ($oSet->Count() > 0) { $sButtons = '<img src="../images/tv-item-last.gif">'; $sButtons .= ' '; $sButtons .= '<button id="shortcut_btn_rename">' . Dict::S('UI:Button:Rename') . '</button>'; $sButtons .= ' '; $sButtons .= '<button id="shortcut_btn_delete">' . Dict::S('UI:Button:Delete') . '</button>'; // Selection count updated by the pager, and used to enable buttons $oP->add('<input type="hidden" id="shortcut_selection_count"/>'); $oP->add('</fieldset>'); $sConfirmDelete = addslashes(Dict::S('UI:ShortcutDelete:Confirm')); $oP->add_ready_script(<<<EOF function OnShortcutBtnRename() { \tvar oParams = \$('#datatable_shortcut_list').datatable('GetMultipleSelectionParams'); \toParams.operation = 'shortcut_rename_dlg'; \t\$.post(GetAbsoluteUrlAppRoot()+'pages/ajax.render.php', oParams, function(data){ \t\t\$('body').append(data); \t}); \treturn false; } function OnShortcutBtnDelete() { \tif (confirm('{$sConfirmDelete}')) \t{ \t\tvar oParams = \$('#datatable_shortcut_list').datatable('GetMultipleSelectionParams'); \t\toParams.operation = 'shortcut_delete_go'; \t\t\$.post(GetAbsoluteUrlAppRoot()+'pages/ajax.render.php', oParams, function(data){ \t\t\t\$('body').append(data); \t\t}); \t} \treturn false; } function OnSelectionCountChange() { \tvar iCountSelected = \$("#shortcut_selection_count").val(); \tif (iCountSelected == 0) \t{ \t\t\$('#shortcut_btn_rename').attr('disabled', 'disabled'); \t\t\$('#shortcut_btn_delete').attr('disabled', 'disabled'); \t} \telse if (iCountSelected == 1) \t{ \t\t\$('#shortcut_btn_rename').removeAttr('disabled'); \t\t\$('#shortcut_btn_delete').removeAttr('disabled'); \t} \telse \t{ \t\t\$('#shortcut_btn_rename').attr('disabled', 'disabled'); \t\t\$('#shortcut_btn_delete').removeAttr('disabled'); \t} } var oUpperCheckBox = \$('#datatable_shortcut_list .checkAll').first(); oUpperCheckBox.parent().width(oUpperCheckBox.width() + 2); \$('#datatable_shortcut_list').append('<tr><td colspan="2"> {$sButtons}</td></tr>'); \$('#shortcut_selection_count').bind('change', OnSelectionCountChange); \$('#shortcut_btn_rename').bind('click', OnShortcutBtnRename); \$('#shortcut_btn_delete').bind('click', OnShortcutBtnDelete); OnSelectionCountChange(); EOF ); } // if count > 0 ////////////////////////////////////////////////////////////////////////// // // Footer // $oP->add('</div>'); $oP->add_ready_script("\$('#fav_page_length').bind('keyup change', function(){ ValidateOtherSettings(); })"); }