Fetch()) { $aRanks[$oMenu->GetKey()] = $oMenu->Get('rank'); } asort($aRanks); // sort by ascending rank: menuId => rank $aKeys = array_keys($aRanks); $iActiveNodeId = array_shift($aKeys); // Takes the first key, i.e. the menuId with the lowest rank } } $currentOrganization = utils::ReadParam('org_id', ''); $operation = utils::ReadParam('operation', ''); require_once('../application/loginwebpage.class.inc.php'); login_web_page::DoLogin(); // Check user rights and prompt if needed $oP = new iTopWebPage("Welcome to ITop", $currentOrganization); // From now on the context is limited to the the selected organization ?? if ($iActiveNodeId != -1) { $oActiveNode = $oContext->GetObject('menuNode', $iActiveNodeId); } else { $oActiveNode = null; } switch($operation) { case 'details': $sClass = utils::ReadParam('class', ''); $sClassLabel = MetaModel::GetName($sClass); $id = utils::ReadParam('id', ''); $oSearch = new DBObjectSearch($sClass); $oBlock = new DisplayBlock($oSearch, 'search', false); $oBlock->Display($oP, 0); if ( empty($sClass) || empty($id)) // TO DO: check that the class name is valid ! { $oP->add("
'class' and 'id' parameters must be specifed for this operation.
\n"); } else { $oObj = $oContext->GetObject($sClass, $id); if ($oObj != null) { $oP->set_title("iTop - ".$oObj->GetDisplayName()." - $sClassLabel details"); $oObj->DisplayDetails($oP); } else { $oP->set_title("iTop - Error"); $oP->add("Sorry this object does not exist (or you are not allowed to view it).
\n"); } } break; case 'search_form': $sOQLClass = utils::ReadParam('oql_class', ''); $sOQLClause = utils::ReadParam('oql_clause', ''); $sFormat = utils::ReadParam('format', ''); $bSearchForm = utils::ReadParam('search_form', true); if (empty($sOQLClass)) { $oP->set_title("iTop - Error"); $oP->add("'oql_class' must be specifed for this operation.
\n"); } else { $oP->set_title("iTop - Search results"); $sOQL = "SELECT $sOQLClass $sOQLClause"; try { $oFilter = DBObjectSearch::FromOQL($sOQL); // To Do: Make sure we don't bypass security $oSet = new DBObjectSet($oFilter); if ($bSearchForm) { $oBlock = new DisplayBlock($oFilter, 'search', false); $oBlock->Display($oP, 0); } if (strtolower($sFormat) == 'csv') { $oBlock = new DisplayBlock($oFilter, 'csv', false); $oBlock->Display($oP, 'csv'); $oPage->add_ready_script(" $('#csv').css('height', '95%');"); // adjust the size of the block } else { $oBlock = new DisplayBlock($oFilter, 'list', false); $oBlock->Display($oP, 1); } } catch(CoreException $e) { $oFilter = new DBObjectSearch($sOQLClass); // To Do: Make sure we don't bypass security $oSet = new DBObjectSet($oFilter); if ($bSearchForm) { $oBlock = new DisplayBlock($oFilter, 'search', false); $oBlock->Display($oP, 0); } $oP->P("Error incorrect OQL query:"); $oP->P($e->getHtmlDesc()); } catch(Exception $e) { $oP->p('An error occured while running the query:'); $oP->p($e->getMessage()); } } break; case 'search': $sFilter = utils::ReadParam('filter', ''); $sFormat = utils::ReadParam('format', ''); $bSearchForm = utils::ReadParam('search_form', true); if (empty($sFilter)) { $oP->set_title("iTop - Error"); $oP->add("'filter' must be specifed for this operation.
\n"); } else { $oP->set_title("iTop - Search results"); // TO DO: limit the search filter by the user context $oFilter = CMDBSearchFilter::unserialize($sFilter); // TO DO : check that the filter is valid $oSet = new DBObjectSet($oFilter); if ($bSearchForm) { $oBlock = new DisplayBlock($oFilter, 'search', false); $oBlock->Display($oP, 0); } if (strtolower($sFormat) == 'csv') { $oBlock = new DisplayBlock($oFilter, 'csv', false); $oBlock->Display($oP, 'csv'); $oP->add_ready_script(" $('#csv').css('height', '95%');"); // adjust the size of the block } else { $oBlock = new DisplayBlock($oFilter, 'list', false); $oBlock->Display($oP, 0); } } break; case 'full_text': $sFullText = trim(utils::ReadParam('text', '')); if (empty($sFullText)) { $oP->p('Nothing to search.'); } else { $oP->p("'class' and 'id' parameters must be specifed for this operation.
\n"); } else { // Check if the user can modify this object $oSearch = new DBObjectSearch($sClass); $oSearch->AddCondition('pkey', $id, '='); $oSet = new CMDBObjectSet($oSearch); if ($oSet->Count() > 0) { $oObj = $oSet->Fetch(); } $bIsModifiedAllowed = (UserRights::IsActionAllowed($sClass, UR_ACTION_MODIFY, $oSet) == UR_ALLOWED_YES); $bIsReadAllowed = (UserRights::IsActionAllowed($sClass, UR_ACTION_READ, $oSet) == UR_ALLOWED_YES); if( ($oObj != null) && ($bIsModifiedAllowed) && ($bIsReadAllowed)) { $oP->set_title("iTop - ".$oObj->GetName()." - $sClassLabel modification"); $oP->add("Sorry this object does not exist (or you are not allowed to view it).
\n"); } } break; case 'clone': $sClass = utils::ReadParam('class', ''); $sClassLabel = MetaModel::GetName($sClass); $id = utils::ReadParam('id', ''); if ( empty($sClass) || empty($id)) // TO DO: check that the class name is valid ! { $oP->add("'class' and 'id' parameters must be specifed for this operation.
\n"); } else { // Check if the user can modify this object $oSearch = new DBObjectSearch($sClass); $oSearch->AddCondition('pkey', $id, '='); $oSet = new CMDBObjectSet($oSearch); if ($oSet->Count() > 0) { $oObjToClone = $oSet->Fetch(); } $bIsModifiedAllowed = (UserRights::IsActionAllowed($sClass, UR_ACTION_MODIFY, $oSet) == UR_ALLOWED_YES); $bIsReadAllowed = (UserRights::IsActionAllowed($sClass, UR_ACTION_READ, $oSet) == UR_ALLOWED_YES); if( ($oObjToClone != null) && ($bIsModifiedAllowed) && ($bIsReadAllowed)) { $oP->add_linked_script("../js/json.js"); $oP->add_linked_script("../js/forms-json-utils.js"); $oP->add_linked_script("../js/wizardhelper.js"); $oP->add_linked_script("../js/wizard.utils.js"); $oP->add_linked_script("../js/linkswidget.js"); $oP->add_linked_script("../js/jquery.blockUI.js"); $oP->set_title("iTop - ".$oObjToClone->GetName()." - $sClassLabel clone"); $oP->add("Sorry this object does not exist (or you are not allowed to view it).
\n"); } } break; case 'new': $sClass = utils::ReadParam('class', ''); $sStateCode = utils::ReadParam('state', ''); if ( empty($sClass) ) { $oP->p("The class must be specified for this operation!"); } else { $oP->add_linked_script("../js/json.js"); $oP->add_linked_script("../js/forms-json-utils.js"); $oP->add_linked_script("../js/wizardhelper.js"); $oP->add_linked_script("../js/wizard.utils.js"); $oP->add_linked_script("../js/linkswidget.js"); $oP->add_linked_script("../js/jquery.blockUI.js"); $oWizard = new UIWizard($oP, $sClass, $sStateCode); $sStateCode = $oWizard->GetTargetState(); // Will computes the default state if none was supplied $sClassLabel = MetaModel::GetName($sClass); $oP->p("'class' and 'id' parameters must be specifed for this operation.
\n"); } else if (!utils::IsTransactionValid($sTransactionId)) { $oP->p("Error: object has already be updated!\n"); } else { $oObj = $oContext->GetObject($sClass, $id); if ($oObj != null) { $oP->set_title("iTop - ".$oObj->GetName()." - $sClassLabel modification"); $oP->add("Sorry this object does not exist (or you are not allowed to edit it).
\n"); } } $oObj->DisplayDetails($oP); break; case 'delete': case 'delete_confirmed': $sClass = utils::ReadParam('class', ''); $sClassLabel = MetaModel::GetName($sClass); $id = utils::ReadParam('id', ''); $oObj = $oContext->GetObject($sClass, $id); $sName = $oObj->GetName(); if ($operation == 'delete_confirmed') { $oMyChange = MetaModel::NewObject("CMDBChange"); $oMyChange->Set("date", time()); if (UserRights::GetUser() != UserRights::GetRealUser()) { $sUserString = UserRights::GetRealUser()." on behalf of ".UserRights::GetUser(); } else { $sUserString = UserRights::GetUser(); } $oMyChange->Set("userinfo", $sUserString); $oMyChange->DBInsert(); $oObj->DBDeleteTracked($oMyChange); $oP->add("".MetaModel::GetName($sRemoteClass)."\n"); $oP->add("
'class', 'id' and 'stimulus' parameters must be specifed for this operation.
\n"); } else { $oObj = $oContext->GetObject($sClass, $id); if ($oObj != null) { $aTransitions = $oObj->EnumTransitions(); $aStimuli = MetaModel::EnumStimuli($sClass); if (!isset($aTransitions[$sStimulus])) { $oP->add("Error: Invalid stimulus: '$sStimulus' on object: {$oObj->GetName()} in state {$oObj->GetState()}.
\n"); } else { $sActionLabel = $aStimuli[$sStimulus]->Get('label'); $sActionDetails = $aStimuli[$sStimulus]->Get('description'); $aTransition = $aTransitions[$sStimulus]; $sTargetState = $aTransition['target_state']; $aTargetStates = MetaModel::EnumStates($sClass); $oP->add("Applying '$sActionLabel' on object: {$oObj->GetName()} in state {$oObj->GetState()} to target state: $sTargetState.
\n"); $oP->add("Sorry this object does not exist (or you are not allowed to edit it).
\n"); } } break; case 'apply_stimulus': $sClass = utils::ReadPostedParam('class', ''); $id = utils::ReadPostedParam('id', ''); $sTransactionId = utils::ReadPostedParam('transaction_id', ''); $sStimulus = utils::ReadPostedParam('stimulus', ''); if ( empty($sClass) || empty($id) || empty($sStimulus) ) // TO DO: check that the class name is valid ! { $oP->add("'class', 'id' and 'stimulus' parameters must be specifed for this operation.
\n"); } else { $oObj = $oContext->GetObject($sClass, $id); if ($oObj != null) { $aTransitions = $oObj->EnumTransitions(); $aStimuli = MetaModel::EnumStimuli($sClass); if (!isset($aTransitions[$sStimulus])) { $oP->add("Error: Invalid stimulus: '$sStimulus' on object: {$oObj->GetName()} in state {$oObj->GetState()}.
\n"); } else if (!utils::IsTransactionValid($sTransactionId)) { $oP->p("Error: object has already been updated!\n"); } else { $sActionLabel = $aStimuli[$sStimulus]->Get('label'); $sActionDetails = $aStimuli[$sStimulus]->Get('description'); $aTransition = $aTransitions[$sStimulus]; $sTargetState = $aTransition['target_state']; $aTargetStates = MetaModel::EnumStates($sClass); $oP->add("$sActionDetails
\n"); $oP->add("Applying '$sActionLabel' on object: {$oObj->GetName()} in state {$oObj->GetState()} to target state: $sTargetState.
\n"); $oP->add("Sorry this object does not exist (or you are not allowed to edit it).
\n"); } } break; case 'modify_links': $sClass = utils::ReadParam('class', ''); $sLinkAttr = utils::ReadParam('link_attr', ''); $sTargetClass = utils::ReadParam('target_class', ''); $id = utils::ReadParam('id', ''); $bAddObjects = utils::ReadParam('addObjects', false); if ( empty($sClass) || empty($id) || empty($sLinkAttr) || empty($sTargetClass)) // TO DO: check that the class name is valid ! { $oP->set_title("iTop - Error"); $oP->add("4 parameters are mandatory for this operation: class, id, target_class and link_attr.
\n"); } else { require_once('../application/uilinkswizard.class.inc.php'); $oWizard = new UILinksWizard($sClass, $sLinkAttr, $id, $sTargetClass); $oWizard->Display($oP, $oContext, array('StartWithAdd' => $bAddObjects)); } break; case 'do_modify_links': $aLinks = utils::ReadParam('linkId', array(), 'post'); $sLinksToRemove = trim(utils::ReadParam('linksToRemove', '', 'post')); $aLinksToRemove = array(); if (!empty($sLinksToRemove)) { $aLinksToRemove = explode(' ', trim($sLinksToRemove)); } $sClass = utils::ReadParam('class', '', 'post'); $sLinkageAtt = utils::ReadParam('linkage', '', 'post'); $iObjectId = utils::ReadParam('object_id', '', 'post'); $sLinkingAttCode = utils::ReadParam('linking_attcode', '', 'post'); $oMyChange = MetaModel::NewObject("CMDBChange"); $oMyChange->Set("date", time()); if (UserRights::GetUser() != UserRights::GetRealUser()) { $sUserString = UserRights::GetRealUser()." on behalf of ".UserRights::GetUser(); } else { $sUserString = UserRights::GetUser(); } $oMyChange->Set("userinfo", $sUserString); $iChangeId = $oMyChange->DBInsert(); // Delete links that are to be deleted foreach($aLinksToRemove as $iLinkId) { if ($iLinkId > 0) // Negative IDs are objects that were not even created { $oLink = $oContext->GetObject($sClass, $iLinkId); $oLink->DBDeleteTracked($oMyChange); } } $aEditableFields = array(); $aData = array(); foreach(MetaModel::GetAttributesList($sClass) as $sAttCode) { $oAttDef = MetaModel::GetAttributeDef($sClass, $sAttCode); if ( (!$oAttDef->IsExternalKey()) && (!$oAttDef->IsExternalField())) { $aEditableFields[] = $sAttCode; $aData[$sAttCode] = utils::ReadParam('attr_'.$sAttCode, array(), 'post'); } } // Update existing links or create new links foreach($aLinks as $iLinkId) { if ($iLinkId > 0) { // This is an existing link to be modified $oLink = $oContext->GetObject($sClass, $iLinkId); // Update all the attributes of the link foreach($aEditableFields as $sAttCode) { $value = $aData[$sAttCode][$iLinkId]; $oLink->Set($sAttCode, $value); } if ($oLink->IsModified()) { $oLink->DBUpdateTracked($oMyChange); } //echo "Updated link: