public function __construct($sClass, $sAttCode, $iInputId, $sNameSuffix = '', $bDuplicatesAllowed = false)
 {
     $this->m_sClass = $sClass;
     $this->m_sAttCode = $sAttCode;
     $this->m_sNameSuffix = $sNameSuffix;
     $this->m_iInputId = $iInputId;
     $this->m_bDuplicatesAllowed = $bDuplicatesAllowed;
     $this->m_aEditableFields = array();
     $oAttDef = MetaModel::GetAttributeDef($this->m_sClass, $this->m_sAttCode);
     $this->m_sLinkedClass = $oAttDef->GetLinkedClass();
     $this->m_sExtKeyToRemote = $oAttDef->GetExtKeyToRemote();
     $this->m_sExtKeyToMe = $oAttDef->GetExtKeyToMe();
     $oLinkingAttDef = MetaModel::GetAttributeDef($this->m_sLinkedClass, $this->m_sExtKeyToRemote);
     $this->m_sRemoteClass = $oLinkingAttDef->GetTargetClass();
     $sExtKeyToMe = $oAttDef->GetExtKeyToMe();
     $sStateAttCode = MetaModel::GetStateAttributeCode($this->m_sClass);
     $sDefaultState = MetaModel::GetDefaultState($this->m_sClass);
     $this->m_aEditableFields = array();
     $this->m_aTableConfig = array();
     $this->m_aTableConfig['form::checkbox'] = array('label' => "<input class=\"select_all\" type=\"checkbox\" value=\"1\" onClick=\"CheckAll('#linkedset_{$this->m_sAttCode}{$this->m_sNameSuffix} .selection', this.checked); oWidget" . $this->m_iInputId . ".OnSelectChange();\">", 'description' => Dict::S('UI:SelectAllToggle+'));
     foreach (MetaModel::FlattenZList(MetaModel::GetZListItems($this->m_sLinkedClass, 'list')) as $sAttCode) {
         $oAttDef = MetaModel::GetAttributeDef($this->m_sLinkedClass, $sAttCode);
         if ($sStateAttCode == $sAttCode) {
             // State attribute is always hidden from the UI
         } else {
             if ($oAttDef->IsWritable() && $sAttCode != $sExtKeyToMe && $sAttCode != $this->m_sExtKeyToRemote && $sAttCode != 'finalclass') {
                 $iFlags = MetaModel::GetAttributeFlags($this->m_sLinkedClass, $sDefaultState, $sAttCode);
                 if (!($iFlags & OPT_ATT_HIDDEN) && !($iFlags & OPT_ATT_READONLY)) {
                     $this->m_aEditableFields[] = $sAttCode;
                     $this->m_aTableConfig[$sAttCode] = array('label' => $oAttDef->GetLabel(), 'description' => $oAttDef->GetDescription());
                 }
             }
         }
     }
     $this->m_aTableConfig['static::key'] = array('label' => MetaModel::GetName($this->m_sRemoteClass), 'description' => MetaModel::GetClassDescription($this->m_sRemoteClass));
     foreach (MetaModel::GetZListItems($this->m_sRemoteClass, 'list') as $sFieldCode) {
         // TO DO: check the state of the attribute: hidden or visible ?
         if ($sFieldCode != 'finalclass') {
             $oAttDef = MetaModel::GetAttributeDef($this->m_sRemoteClass, $sFieldCode);
             $this->m_aTableConfig['static::' . $sFieldCode] = array('label' => $oAttDef->GetLabel(), 'description' => $oAttDef->GetDescription());
         }
     }
 }
예제 #2
0
 /**
  * Helper function to build a select from the list of valid classes for a given action
  * @param string $sName The name of the select in the HTML form
  * @param string $sDefaulfValue The defaut value (i.e the value selected by default)
  * @param integer $iWidthPx The width (in pixels) of the drop-down list
  * @param integer $iActionCode The ActionCode (from UserRights) to check for authorization for the classes
  * @return string The HTML fragment corresponding to the select tag
  */
 function GetClassesSelect($sName, $sDefaultValue, $iWidthPx, $iActionCode = null)
 {
     $sHtml = "<select id=\"select_{$sName}\" name=\"{$sName}\">";
     $sHtml .= "<option tyle=\"width: " . $iWidthPx . "px;\" title=\"Select the class you want to load\" value=\"\">" . Dict::S('UI:CSVImport:ClassesSelectOne') . "</option>\n";
     $aValidClasses = array();
     $aClassCategories = array('bizmodel');
     if (UserRights::IsAdministrator()) {
         $aClassCategories = array('bizmodel', 'application', 'addon/authentication');
     }
     foreach ($aClassCategories as $sClassCategory) {
         foreach (MetaModel::GetClasses($sClassCategory) as $sClassName) {
             if ((is_null($iActionCode) || UserRights::IsActionAllowed($sClassName, $iActionCode)) && !MetaModel::IsAbstract($sClassName)) {
                 $sSelected = $sClassName == $sDefaultValue ? " selected" : "";
                 $sDescription = MetaModel::GetClassDescription($sClassName);
                 $sDisplayName = MetaModel::GetName($sClassName);
                 $aValidClasses[$sDisplayName] = "<option style=\"width: " . $iWidthPx . "px;\" title=\"{$sDescription}\" value=\"{$sClassName}\"{$sSelected}>{$sDisplayName}</option>";
             }
         }
     }
     ksort($aValidClasses);
     $sHtml .= implode("\n", $aValidClasses);
     $sHtml .= "</select>";
     return $sHtml;
 }
 public function MakeClassesSelect($sName, $sDefaultValue, $iWidthPx, $iActionCode = null)
 {
     // $aTopLevelClasses = array('bizService', 'bizContact', 'logInfra', 'bizDocument');
     // These are classes wich root class is cmdbAbstractObject !
     $this->add("<select id=\"select_{$sName}\" name=\"{$sName}\">");
     $aValidClasses = array();
     foreach (MetaModel::GetClasses('bizmodel') as $sClassName) {
         if (is_null($iActionCode) || UserRights::IsActionAllowed($sClassName, $iActionCode)) {
             $sSelected = $sClassName == $sDefaultValue ? " SELECTED" : "";
             $sDescription = MetaModel::GetClassDescription($sClassName);
             $sDisplayName = MetaModel::GetName($sClassName);
             $aValidClasses[$sDisplayName] = "<option style=\"width: " . $iWidthPx . " px;\" title=\"{$sDescription}\" value=\"{$sClassName}\"{$sSelected}>{$sDisplayName}</option>";
         }
     }
     ksort($aValidClasses);
     $this->add(implode("\n", $aValidClasses));
     $this->add("</select>");
 }
예제 #4
0
/**
 * Display the details of a given class of objects
 */
function DisplayClassDetails($oPage, $sClass, $sContext)
{
    $oPage->add("<h2>" . MetaModel::GetName($sClass) . " ({$sClass}) - " . MetaModel::GetClassDescription($sClass) . "</h2>\n");
    if (MetaModel::IsAbstract($sClass)) {
        $oPage->p(Dict::S('UI:Schema:AbstractClass'));
    } else {
        $oPage->p(Dict::S('UI:Schema:NonAbstractClass'));
    }
    //	$oPage->p("<h3>".Dict::S('UI:Schema:ClassHierarchyTitle')."</h3>");
    $aParentClasses = array();
    foreach (MetaModel::EnumParentClasses($sClass) as $sParentClass) {
        $aParentClasses[] = MakeClassHLink($sParentClass, $sContext);
    }
    if (count($aParentClasses) > 0) {
        $sParents = implode(' &gt;&gt; ', $aParentClasses) . " &gt;&gt; <b>{$sClass}</b>";
    } else {
        $sParents = '';
    }
    $oPage->p("[<a href=\"schema.php?operation=list{$sContext}\">" . Dict::S('UI:Schema:AllClasses') . "</a>] {$sParents}");
    if (MetaModel::HasChildrenClasses($sClass)) {
        $oPage->add("<ul id=\"ClassHierarchy\">");
        $oPage->add("<li class=\"closed\">" . $sClass . "\n");
        DisplaySubclasses($oPage, $sClass, $sContext);
        $oPage->add("</li>\n");
        $oPage->add("</ul>\n");
        $oPage->add_ready_script('$("#ClassHierarchy").treeview();');
    }
    $oPage->p('');
    $oPage->AddTabContainer('details');
    $oPage->SetCurrentTabContainer('details');
    // List the attributes of the object
    $aForwardChangeTracking = MetaModel::GetTrackForwardExternalKeys($sClass);
    $aDetails = array();
    foreach (MetaModel::ListAttributeDefs($sClass) as $sAttCode => $oAttDef) {
        if ($oAttDef->IsExternalKey()) {
            $sValue = Dict::Format('UI:Schema:ExternalKey_To', MakeClassHLink($oAttDef->GetTargetClass(), $sContext));
            if (array_key_exists($sAttCode, $aForwardChangeTracking)) {
                $oLinkSet = $aForwardChangeTracking[$sAttCode];
                $sRemoteClass = $oLinkSet->GetHostClass();
                $sValue = $sValue . "<span title=\"Forward changes to {$sRemoteClass}\">*</span>";
            }
        } elseif ($oAttDef->IsLinkSet()) {
            $sValue = MakeClassHLink($oAttDef->GetLinkedClass(), $sContext);
        } else {
            $sValue = $oAttDef->GetDescription();
        }
        $sType = $oAttDef->GetType() . ' (' . $oAttDef->GetTypeDesc() . ')';
        $sOrigin = MetaModel::GetAttributeOrigin($sClass, $sAttCode);
        $sAllowedValues = "";
        $sMoreInfo = "";
        $aCols = array();
        foreach ($oAttDef->GetSQLColumns() as $sCol => $sFieldDesc) {
            $aCols[] = "{$sCol}: {$sFieldDesc}";
        }
        if (count($aCols) > 0) {
            $sCols = implode(', ', $aCols);
            $aMoreInfo = array();
            $aMoreInfo[] = Dict::Format('UI:Schema:Columns_Description', $sCols);
            $aMoreInfo[] = Dict::Format('UI:Schema:Default_Description', $oAttDef->GetDefaultValue());
            $aMoreInfo[] = $oAttDef->IsNullAllowed() ? Dict::S('UI:Schema:NullAllowed') : Dict::S('UI:Schema:NullNotAllowed');
            $sMoreInfo .= implode(', ', $aMoreInfo);
        }
        if ($oAttDef instanceof AttributeEnum) {
            // Display localized values for the enum (which depend on the localization provided by the class)
            $aLocalizedValues = MetaModel::GetAllowedValues_att($sClass, $sAttCode, array());
            $aDescription = array();
            foreach ($aLocalizedValues as $val => $sDisplay) {
                $aDescription[] = htmlentities("{$val} => ", ENT_QUOTES, 'UTF-8') . $sDisplay;
            }
            $sAllowedValues = implode(', ', $aDescription);
        } else {
            $sAllowedValues = '';
        }
        $aDetails[] = array('code' => $oAttDef->GetCode(), 'type' => $sType, 'origin' => $sOrigin, 'label' => $oAttDef->GetLabel(), 'description' => $sValue, 'values' => $sAllowedValues, 'moreinfo' => $sMoreInfo);
    }
    $oPage->SetCurrentTab(Dict::S('UI:Schema:Attributes'));
    $aConfig = array('code' => array('label' => Dict::S('UI:Schema:AttributeCode'), 'description' => Dict::S('UI:Schema:AttributeCode+')), 'label' => array('label' => Dict::S('UI:Schema:Label'), 'description' => Dict::S('UI:Schema:Label+')), 'type' => array('label' => Dict::S('UI:Schema:Type'), 'description' => Dict::S('UI:Schema:Type+')), 'origin' => array('label' => Dict::S('UI:Schema:Origin'), 'description' => Dict::S('UI:Schema:Origin+')), 'description' => array('label' => Dict::S('UI:Schema:Description'), 'description' => Dict::S('UI:Schema:Description+')), 'values' => array('label' => Dict::S('UI:Schema:AllowedValues'), 'description' => Dict::S('UI:Schema:AllowedValues+')), 'moreinfo' => array('label' => Dict::S('UI:Schema:MoreInfo'), 'description' => Dict::S('UI:Schema:MoreInfo+')));
    $oPage->table($aConfig, $aDetails);
    // List the search criteria for this object
    $aDetails = array();
    foreach (MetaModel::GetClassFilterDefs($sClass) as $sFilterCode => $oFilterDef) {
        $aOpDescs = array();
        foreach ($oFilterDef->GetOperators() as $sOpCode => $sOpDescription) {
            $sIsTheLooser = $sOpCode == $oFilterDef->GetLooseOperator() ? " (loose search)" : "";
            $aOpDescs[] = "{$sOpCode} ({$sOpDescription}){$sIsTheLooser}";
        }
        $aDetails[] = array('code' => $sFilterCode, 'description' => $oFilterDef->GetLabel(), 'operators' => implode(" / ", $aOpDescs));
    }
    $oPage->SetCurrentTab(Dict::S('UI:Schema:SearchCriteria'));
    $aConfig = array('code' => array('label' => Dict::S('UI:Schema:FilterCode'), 'description' => Dict::S('UI:Schema:FilterCode+')), 'description' => array('label' => Dict::S('UI:Schema:FilterDescription'), 'description' => Dict::S('UI:Schema:FilterDescription+')), 'operators' => array('label' => Dict::S('UI:Schema:AvailOperators'), 'description' => Dict::S('UI:Schema:AvailOperators+')));
    $oPage->table($aConfig, $aDetails);
    $oPage->SetCurrentTab(Dict::S('UI:Schema:ChildClasses'));
    DisplaySubclasses($oPage, $sClass, $sContext);
    $oPage->SetCurrentTab(Dict::S('UI:Schema:ReferencingClasses'));
    DisplayReferencingClasses($oPage, $sClass, $sContext);
    $oPage->SetCurrentTab(Dict::S('UI:Schema:RelatedClasses'));
    DisplayRelatedClasses($oPage, $sClass, $sContext);
    $oPage->SetCurrentTab(Dict::S('UI:Schema:LifeCycle'));
    DisplayLifecycle($oPage, $sClass, $sContext);
    $oPage->SetCurrentTab(Dict::S('UI:Schema:Triggers'));
    DisplayTriggers($oPage, $sClass, $sContext);
    $oPage->SetCurrentTab();
    $oPage->SetCurrentTabContainer();
}
예제 #5
0
// Now render the content of the page
$sBaseClass = utils::ReadParam('baseClass', 'Organization', false, 'class');
$sClass = utils::ReadParam('class', $sBaseClass, false, 'class');
$sOQLClause = utils::ReadParam('oql_clause', '', false, 'raw_data');
$sFilter = utils::ReadParam('filter', '', false, 'raw_data');
$sOperation = utils::ReadParam('operation', '');
// First part: select the class to search for
$oP->add("<form>");
$oP->add(Dict::S('UI:UniversalSearch:LabelSelectTheClass') . "<select style=\"width: 150px;\" id=\"select_class\" name=\"baseClass\" onChange=\"this.form.submit();\">");
$aClassLabels = array();
foreach (MetaModel::GetClasses('bizmodel') as $sCurrentClass) {
    $aClassLabels[$sCurrentClass] = MetaModel::GetName($sCurrentClass);
}
asort($aClassLabels);
foreach ($aClassLabels as $sCurrentClass => $sLabel) {
    $sDescription = MetaModel::GetClassDescription($sCurrentClass);
    $sSelected = $sCurrentClass == $sBaseClass ? " SELECTED" : "";
    $oP->add("<option value=\"{$sCurrentClass}\" title=\"{$sDescription}\"{$sSelected}>{$sLabel}</option>");
}
$oP->add("</select>\n");
$oP->add($oAppContext->GetForForm());
$oP->add("</form>\n");
try {
    if ($sOperation == 'search_form') {
        $sOQL = "SELECT {$sClass} {$sOQLClause}";
        $oFilter = DBObjectSearch::FromOQL($sOQL);
    } else {
        // Second part: advanced search form:
        if (!empty($sFilter)) {
            $oFilter = CMDBSearchFilter::unserialize($sFilter);
        } else {
 /**
  * Display the details of an import
  */
 static function DisplayImportHistoryDetails(iTopWebPage $oPage, $iChange)
 {
     if ($iChange == 0) {
         throw new Exception("Missing parameter changeid");
     }
     $oChange = MetaModel::GetObject('CMDBChange', $iChange, false);
     if (is_null($oChange)) {
         throw new Exception("Unknown change: {$iChange}");
     }
     $oPage->add("<div><p><h1>" . Dict::Format('UI:History:BulkImportDetails', $oChange->Get('date'), $oChange->GetUserName()) . "</h1></p></div>\n");
     // Assumption : change made one single class of objects
     $aObjects = array();
     $aAttributes = array();
     // array of attcode => occurences
     $oOpSearch = DBObjectSearch::FromOQL("SELECT CMDBChangeOp WHERE change = :change_id");
     $oOpSet = new DBObjectSet($oOpSearch, array(), array('change_id' => $iChange));
     while ($oOperation = $oOpSet->Fetch()) {
         $sClass = $oOperation->Get('objclass');
         $iKey = $oOperation->Get('objkey');
         $iObjId = "{$sClass}::{$iKey}";
         if (!isset($aObjects[$iObjId])) {
             $aObjects[$iObjId] = array();
             $aObjects[$iObjId]['__class__'] = $sClass;
             $aObjects[$iObjId]['__id__'] = $iKey;
         }
         if (get_class($oOperation) == 'CMDBChangeOpCreate') {
             $aObjects[$iObjId]['__created__'] = true;
         } elseif ($oOperation instanceof CMDBChangeOpSetAttribute) {
             $sAttCode = $oOperation->Get('attcode');
             if (get_class($oOperation) == 'CMDBChangeOpSetAttributeScalar') {
                 $oAttDef = MetaModel::GetAttributeDef($sClass, $sAttCode);
                 if ($oAttDef->IsExternalKey()) {
                     $sOldValue = Dict::S('UI:UndefinedObject');
                     if ($oOperation->Get('oldvalue') != 0) {
                         $oOldTarget = MetaModel::GetObject($oAttDef->GetTargetClass(), $oOperation->Get('oldvalue'));
                         $sOldValue = $oOldTarget->GetHyperlink();
                     }
                     $sNewValue = Dict::S('UI:UndefinedObject');
                     if ($oOperation->Get('newvalue') != 0) {
                         $oNewTarget = MetaModel::GetObject($oAttDef->GetTargetClass(), $oOperation->Get('newvalue'));
                         $sNewValue = $oNewTarget->GetHyperlink();
                     }
                 } else {
                     $sOldValue = $oOperation->GetAsHTML('oldvalue');
                     $sNewValue = $oOperation->GetAsHTML('newvalue');
                 }
                 $aObjects[$iObjId][$sAttCode] = $sOldValue . ' -&gt; ' . $sNewValue;
             } else {
                 $aObjects[$iObjId][$sAttCode] = 'n/a';
             }
             if (isset($aAttributes[$sAttCode])) {
                 $aAttributes[$sAttCode]++;
             } else {
                 $aAttributes[$sAttCode] = 1;
             }
         }
     }
     $aDetails = array();
     foreach ($aObjects as $iUId => $aObjData) {
         $aRow = array();
         $oObject = MetaModel::GetObject($aObjData['__class__'], $aObjData['__id__'], false);
         if (is_null($oObject)) {
             $aRow['object'] = $aObjData['__class__'] . '::' . $aObjData['__id__'] . ' (deleted)';
         } else {
             $aRow['object'] = $oObject->GetHyperlink();
         }
         if (isset($aObjData['__created__'])) {
             $aRow['operation'] = Dict::S('Change:ObjectCreated');
         } else {
             $aRow['operation'] = Dict::S('Change:ObjectModified');
         }
         foreach ($aAttributes as $sAttCode => $iOccurences) {
             if (isset($aObjData[$sAttCode])) {
                 $aRow[$sAttCode] = $aObjData[$sAttCode];
             } elseif (!is_null($oObject)) {
                 // This is the current vaslue: $oObject->GetAsHtml($sAttCode)
                 // whereas we are displaying the value that was set at the time
                 // the object was created
                 // This requires addtional coding...let's do that later
                 $aRow[$sAttCode] = '';
             } else {
                 $aRow[$sAttCode] = '';
             }
         }
         $aDetails[] = $aRow;
     }
     $aConfig = array();
     $aConfig['object'] = array('label' => MetaModel::GetName($sClass), 'description' => MetaModel::GetClassDescription($sClass));
     $aConfig['operation'] = array('label' => Dict::S('UI:History:Changes'), 'description' => Dict::S('UI:History:Changes+'));
     foreach ($aAttributes as $sAttCode => $iOccurences) {
         $aConfig[$sAttCode] = array('label' => MetaModel::GetLabel($sClass, $sAttCode), 'description' => MetaModel::GetDescription($sClass, $sAttCode));
     }
     $oPage->table($aConfig, $aDetails);
 }