diff --git a/addons/userrights/userrightsmatrix.class.inc.php b/addons/userrights/userrightsmatrix.class.inc.php index d7e7578d7..9919204d1 100644 --- a/addons/userrights/userrightsmatrix.class.inc.php +++ b/addons/userrights/userrightsmatrix.class.inc.php @@ -268,12 +268,6 @@ class UserRightsMatrix extends UserRightsAddOnAPI return true; } - public function GetFilter($sUserName, $sClass) - { - $oNullFilter = new DBObjectSearch($sClass); - return $oNullFilter; - } - public function GetSelectFilter($oUser, $sClass) { $oNullFilter = new DBObjectSearch($sClass); diff --git a/addons/userrights/userrightsnull.class.inc.php b/addons/userrights/userrightsnull.class.inc.php index 44fe4e305..ad1b807b8 100644 --- a/addons/userrights/userrightsnull.class.inc.php +++ b/addons/userrights/userrightsnull.class.inc.php @@ -47,12 +47,6 @@ class UserRightsNull extends UserRightsAddOnAPI return true; } - public function GetFilter($sUserName, $sClass) - { - $oNullFilter = new DBObjectSearch($sClass); - return $oNullFilter; - } - public function GetSelectFilter($oUser, $sClass) { $oNullFilter = new DBObjectSearch($sClass); diff --git a/addons/userrights/userrightsprofile.class.inc.php b/addons/userrights/userrightsprofile.class.inc.php index 3941cfb5f..ad0895fd7 100644 --- a/addons/userrights/userrightsprofile.class.inc.php +++ b/addons/userrights/userrightsprofile.class.inc.php @@ -729,12 +729,6 @@ exit; return true; } - public function GetFilter($sUserName, $sClass) - { - $oNullFilter = new DBObjectSearch($sClass); - return $oNullFilter; - } - public function GetSelectFilter($oUser, $sClass) { $aConditions = array(); diff --git a/application/application.inc.php b/application/application.inc.php index 962b88e71..6d63f8941 100644 --- a/application/application.inc.php +++ b/application/application.inc.php @@ -24,7 +24,6 @@ */ require_once('../application/applicationcontext.class.inc.php'); -require_once('../application/usercontext.class.inc.php'); require_once('../application/cmdbabstract.class.inc.php'); require_once('../application/displayblock.class.inc.php'); require_once('../application/audit.category.class.inc.php'); diff --git a/application/displayblock.class.inc.php b/application/displayblock.class.inc.php index 46c1d590d..aa68ed1a9 100644 --- a/application/displayblock.class.inc.php +++ b/application/displayblock.class.inc.php @@ -743,10 +743,9 @@ class HistoryBlock extends DisplayBlock if (is_object($oLatestChangeOp)) { - $oContext = new UserContext(); // There is one change in the list... only when the object has been created ! $sDate = $oLatestChangeOp->GetAsHTML('date'); - $oChange = $oContext->GetObject('CMDBChange', $oLatestChangeOp->Get('change')); + $oChange = MetaModel::GetObject('CMDBChange', $oLatestChangeOp->Get('change')); $sUserInfo = $oChange->GetAsHTML('userinfo'); $sHtml .= $oPage->GetStartCollapsibleSection(Dict::Format('UI:History:LastModified_On_By', $sDate, $sUserInfo)); $sHtml .= $this->GetHistoryTable($oPage, $oSet); diff --git a/application/itopwebpage.class.inc.php b/application/itopwebpage.class.inc.php index 7df18238d..9b276edf5 100644 --- a/application/itopwebpage.class.inc.php +++ b/application/itopwebpage.class.inc.php @@ -24,7 +24,6 @@ */ require_once("../application/nicewebpage.class.inc.php"); -require_once("../application/usercontext.class.inc.php"); require_once("../application/applicationcontext.class.inc.php"); require_once("../application/user.preferences.class.inc.php"); /** @@ -113,7 +112,7 @@ class iTopWebPage extends NiceWebPage } // Accordion Menu - $("#accordion").accordion({ header: "h3", navigation: true, autoHeight: false, collapsible: false, icons: false }); + $("#accordion").accordion({ header: "h3", navigation: true, autoHeight: false, collapsible: false, icons: false }); // collapsible will be enabled once the item will be selected }); //add new widget called TruncatedList to properly display truncated lists when they are sorted $.tablesorter.addWidget({ @@ -293,10 +292,9 @@ EOF { // List of visible Organizations $iCount = 0; - $oContext = new UserContext(); if (MetaModel::IsValidClass('Organization')) { - $oSearchFilter = $oContext->NewFilter('Organization'); + $oSearchFilter = new DBObjectSearch('Organization'); $oSet = new CMDBObjectSet($oSearchFilter); $iCount = $oSet->Count(); } @@ -346,7 +344,6 @@ EOF public function DisplayMenu() { - $oContext = new UserContext(); // Display the menu $oAppContext = new ApplicationContext(); $iActiveNodeId = ApplicationMenu::GetActiveNodeId(); diff --git a/application/menunode.class.inc.php b/application/menunode.class.inc.php index ab3b9e1f6..e511e85a5 100644 --- a/application/menunode.class.inc.php +++ b/application/menunode.class.inc.php @@ -110,6 +110,7 @@ class ApplicationMenu if ($bActive) { $oPage->add_ready_script("$('#accordion').accordion('activate', $iAccordion);"); + $oPage->add_ready_script("$('#accordion').accordion('option', {collapsible: true});"); // Make it auto-collapsible once it has been opened properly } } $oPage->AddToMenu(''); diff --git a/application/ui.linkswidget.class.inc.php b/application/ui.linkswidget.class.inc.php index 9843a247c..30cdecc5e 100644 --- a/application/ui.linkswidget.class.inc.php +++ b/application/ui.linkswidget.class.inc.php @@ -212,12 +212,11 @@ class UILinksWidget $sHtmlValue .= "
m_sAttCode}{$this->m_sNameSuffix}\">\n"; $oValue->Rewind(); $aForm = array(); - $oContext = new UserContext(); while($oCurrentLink = $oValue->Fetch()) { $aRow = array(); $key = $oCurrentLink->GetKey(); - $oLinkedObj = $oContext->GetObject($this->m_sRemoteClass, $oCurrentLink->Get($this->m_sExtKeyToRemote)); + $oLinkedObj = MetaModel::GetObject($this->m_sRemoteClass, $oCurrentLink->Get($this->m_sExtKeyToRemote)); $aForm[$key] = $this->GetFormRow($oPage, $oLinkedObj, $oCurrentLink, $aArgs); } @@ -238,14 +237,13 @@ EOF /** * This static function is called by the Ajax Page when there is a need to fill an autocomplete combo * @param $oPage WebPage The ajax page used for the output (sent back to the browser) - * @param $oContext UserContext The context of the user (for limiting the search) * @param $sClass string The name of the class of the current object being edited * @param $sAttCode string The name of the attribute being edited * @param $sName string The partial name that was typed by the user * @param $iMaxCount integer The maximum number of items to return * @return void */ - static public function Autocomplete(WebPage $oPage, UserContext $oContext, $sClass, $sAttCode, $sName, $iMaxCount) + static public function Autocomplete(WebPage $oPage, $sClass, $sAttCode, $sName, $iMaxCount) { // #@# todo - add context information, otherwise any value will be authorized for external keys $aAllowedValues = MetaModel::GetAllowedValues_att($sClass, $sAttCode, array() /* $aArgs */, $sName); @@ -265,7 +263,7 @@ EOF $oAttDef = $oAttDef = MetaModel::GetAttributeDef($sClass, $sAttCode); $sLinkedClass = $oAttDef->GetLinkedClass(); $sSearchClass = self::GetTargetClass($sClass, $sAttCode); - $oFilter = $oContext->NewFilter($sSearchClass); + $oFilter = new DBObjectSearch($sSearchClass); $sSearchAttCode = MetaModel::GetNameAttributeCode($sSearchClass); $oFilter->AddCondition($sSearchAttCode, $sName, 'Begins with'); $oSet = new CMDBObjectSet($oFilter, array($sSearchAttCode => true)); @@ -346,9 +344,8 @@ EOF { $sHtml = "
m_sAttCode}{$this->m_sNameSuffix}\">"; $sHtml .= "
\n"; - $oContext = new UserContext(); $iWidgetIndex = self::$iWidgetIndex; - $oFilter = $oContext->NewFilter($this->m_sRemoteClass); + $oFilter = new DBObjectSearch($this->m_sRemoteClass); $oSet = new CMDBObjectSet($oFilter); $oBlock = new DisplayBlock($oFilter, 'search', false); $sHtml .= $oBlock->GetDisplay($oPage, "SearchFormToAdd_{$this->m_sAttCode}{$this->m_sNameSuffix}", array('open' => true)); @@ -370,21 +367,20 @@ EOF /** * 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 UserContext $oContext User context to limit the search... * @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, UserContext $oContext, $sRemoteClass = '', $aAlreadyLinkedIds = array()) + public function SearchObjectsToAdd(WebPage $oP, $sRemoteClass = '', $aAlreadyLinkedIds = array()) { if ($sRemoteClass != '') { // assert(MetaModel::IsParentClass($this->m_sRemoteClass, $sRemoteClass)); - $oFilter = $oContext->NewFilter($sRemoteClass); + $oFilter = new DBObjectSearch($sRemoteClass); } else { // No remote class specified use the one defined in the linkedset - $oFilter = $oContext->NewFilter($this->m_sRemoteClass); + $oFilter = new DBObjectSearch($this->m_sRemoteClass); } if (count($aAlreadyLinkedIds) > 0) { @@ -407,7 +403,7 @@ EOF if (count($aLinkIds) >0) { // Search for the links to find to which "remote" object they are linked - $oLinkFilter = $oContext->NewFilter($this->m_sLinkedClass); + $oLinkFilter = new DBObjectSearch($this->m_sLinkedClass); $oLinkFilter->AddCondition('id', $aLinkIds, 'IN'); $oLinkSet = new CMDBObjectSet($oLinkFilter); while($oLink = $oLinkSet->Fetch()) @@ -422,12 +418,12 @@ EOF $oBlock->Display($oP, 'ResultsToAdd', array('menu' => false, 'selection_mode' => true, 'display_limit' => false)); // Don't display the 'Actions' menu on the results } - public function DoAddObjects(WebPage $oP, UserContext $oContext, $aLinkedObjectIds = array()) + public function DoAddObjects(WebPage $oP, $aLinkedObjectIds = array()) { $aTable = array(); foreach($aLinkedObjectIds as $iObjectId) { - $oLinkedObj = $oContext->GetObject($this->m_sRemoteClass, $iObjectId); + $oLinkedObj = MetaModel::GetObject($this->m_sRemoteClass, $iObjectId); if (is_object($oLinkedObj)) { $aRow = $this->GetFormRow($oP, $oLinkedObj, -$iObjectId ); // Not yet created link get negative Ids diff --git a/application/uilinkswizard.class.inc.php b/application/uilinkswizard.class.inc.php index efd9558ce..6eac53020 100644 --- a/application/uilinkswizard.class.inc.php +++ b/application/uilinkswizard.class.inc.php @@ -79,11 +79,11 @@ class UILinksWizard } } - public function Display(WebPage $oP, UserContext $oContext, $aExtraParams = array()) + public function Display(WebPage $oP, $aExtraParams = array()) { $oAttDef = MetaModel::GetAttributeDef($this->m_sClass, $this->m_sLinkageAttr); $sTargetClass = $oAttDef->GetTargetClass(); - $oTargetObj = $oContext->GetObject($sTargetClass, $this->m_iObjectId); + $oTargetObj = MetaModel::GetObject($sTargetClass, $this->m_iObjectId); $oP->set_title("iTop - ".MetaModel::GetName($this->m_sLinkedClass)." objects linked with ".MetaModel::GetName(get_class($oTargetObj)).": ".$oTargetObj->GetName()); $oP->add("
\n"); @@ -259,7 +259,7 @@ EOF ); $oP->Add("\n"); $oP->add_ready_script("InitForm();"); - $oFilter = $oContext->NewFilter($this->m_sClass); + $oFilter = new DBObjectSearch($this->m_sClass); $oFilter->AddCondition($this->m_sLinkageAttr, $this->m_iObjectId, '='); $oSet = new DBObjectSet($oFilter); $aForm = array(); @@ -267,7 +267,7 @@ EOF { $aRow = array(); $key = $oCurrentLink->GetKey(); - $oLinkedObj = $oContext->GetObject($this->m_sLinkedClass, $oCurrentLink->Get($this->m_sLinkingAttCode)); + $oLinkedObj = MetaModel::GetObject($this->m_sLinkedClass, $oCurrentLink->Get($this->m_sLinkingAttCode)); $aForm[$key] = $this->GetFormRow($oP, $oLinkedObj, $oCurrentLink); } @@ -363,17 +363,17 @@ EOF $oP->add("\n"); } - public function DisplayAddForm(WebPage $oP, UserContext $oContext) + public function DisplayAddForm(WebPage $oP) { $oAttDef = MetaModel::GetAttributeDef($this->m_sClass, $this->m_sLinkageAttr); $sTargetClass = $oAttDef->GetTargetClass(); - $oTargetObj = $oContext->GetObject($sTargetClass, $this->m_iObjectId); + $oTargetObj = MetaModel::GetObject($sTargetClass, $this->m_iObjectId); $oP->add("
\n"); //$oP->add("
\n"); //$oP->add("

".Dict::Format('UI:AddObjectsOf_Class_LinkedWith_Class_Instance', MetaModel::GetName($this->m_sLinkedClass), MetaModel::GetName(get_class($oTargetObj)), "".$oTargetObj->GetHyperlink()."")."

\n"); //$oP->add("
\n"); - $oFilter = $oContext->NewFilter($this->m_sLinkedClass); + $oFilter = new DBObjectSearch($this->m_sLinkedClass); $oSet = new CMDBObjectSet($oFilter); $oBlock = new DisplayBlock($oFilter, 'search', false); $oBlock->Display($oP, 'SearchFormToAdd', array('open' => true)); @@ -388,17 +388,17 @@ EOF $oP->add_ready_script("$('div#SearchFormToAdd form').bind('submit.uilinksWizard', SubmitHook);"); } - public function SearchObjectsToAdd(WebPage $oP, UserContext $oContext) + public function SearchObjectsToAdd(WebPage $oP) { //$oAttDef = MetaModel::GetAttributeDef($this->m_sClass, $this->m_sLinkageAttr); - $oFilter = $oContext->NewFilter($this->m_sLinkedClass); + $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, 'display_limit' => false)); // Don't display the 'Actions' menu on the results } - public function DoAddObjects(WebPage $oP, UserContext $oContext, $aLinkedObjectIds = array()) + public function DoAddObjects(WebPage $oP, $aLinkedObjectIds = array()) { //$oAttDef = MetaModel::GetAttributeDef($this->m_sClass, $this->m_sLinkageAttr); //$sTargetClass = $oAttDef->GetTargetClass(); @@ -406,7 +406,7 @@ EOF $aTable = array(); foreach($aLinkedObjectIds as $iObjectId) { - $oLinkedObj = $oContext->GetObject($this->m_sLinkedClass, $iObjectId); + $oLinkedObj = MetaModel::GetObject($this->m_sLinkedClass, $iObjectId); if (is_object($oLinkedObj)) { $aRow = $this->GetFormRow($oP, $oLinkedObj, -$iObjectId ); // Not yet created link get negative Ids diff --git a/application/usercontext.class.inc.php b/application/usercontext.class.inc.php deleted file mode 100644 index e38195ff1..000000000 --- a/application/usercontext.class.inc.php +++ /dev/null @@ -1,129 +0,0 @@ - - * @author Romain Quetiez - * @author Denis Flaven - * @license http://www.opensource.org/licenses/gpl-3.0.html LGPL - */ - -require_once('../core/cmdbobject.class.inc.php'); -/** - * Helper class to capture a user's restrictions (access rights, profiles...) as a set of limiting conditions - * - * **** NOW OBSOLETE *** SHOULD BE REPLACED EVERYWHERE BY UserRights ***** - * - * - * - * - * Usage: - * 1) Build the user's context (from her rights, a lookup in the database, a cookie, whatever) - * $oContext = new UserContext(); - * $oContext->AddCondition('SomeClass', 'someFilter', 'SomeValue', '='); - * ... - * - * 2) Use the restrictions contained in the context when retrieving objects either when: - * getting directly an instance of an object - * $oObj = $oContext->GetObject('myClass', 'someKey'); // Instead of $oObj = MetaModel::GetObject('Klass', 'someKey'); - * or when building a new search filter - * $oFilter = $oContext->NewFilter('myClass'); // Instead of $oFilter = new CMDBSearchFilter('Klass'); - */ -class UserContext -{ - /** - * Hash array to store the restricting conditions by myClass - */ - protected $m_aConditions; - - /** - * Constructor - */ - public function __construct() - { - $this->m_aConditions = array(); - } - /** - * Create a new search filter for the given class of objects that already contains the context's restrictions - */ - public function NewFilter($sClass) - { - return UserRights::GetFilter($sClass); - /* - $oFilter = new CMDBSearchFilter($sClass); - foreach($this->m_aConditions as $sConditionClass => $aConditionList) - { - // Add to the filter all the conditions of the parent classes of this class - if ($this->IsSubclass($sConditionClass,$sClass)) - { - foreach($aConditionList as $sFilterCode => $aCondition) - { - $oFilter->AddCondition($sFilterCode, $aCondition['value'], $aCondition['operator']); - } - } - } - return $oFilter; - */ - } - /** - * Retrieve an instance of an object (if allowed by the context) - */ - public function GetObject($sClass, $sKey) - { - $oObject = null; - $oFilter = $this->NewFilter($sClass); - $oFilter->AddCondition('id', $sKey, '='); - $oSet = new CMDBObjectSet($oFilter); - if ($oSet->Count() > 0) - { - $oObject = $oSet->Fetch(); - } - return $oObject; - } - - /** - * Add a restriction to the context for a given class of objects (and all its persistent subclasses) - */ - public function AddCondition($sClass, $sFilterCode, $value, $sOperator) - { - if(!isset($this->m_aConditions[$sClass])) - { - $this->m_aConditions[$sClass] = array(); - } - $this->m_aConditions[$sClass][$sFilterCode] = array('value'=>$value, 'operator'=>$sOperator); - } - - /** - * Check if a given class is a subclass of (or same as) another one - */ - protected function IsSubclass($sParentClass, $sSubclass) - { - $bResult = false; - if ($sParentClass == $sSubclass) - { - $bResult = true; - } - else - { - $aParentList = MetaModel::EnumParentClasses($sSubclass); - $bResult = in_array($sParentClass, $aParentList); - } - return $bResult; - } -} -?> diff --git a/core/userrights.class.inc.php b/core/userrights.class.inc.php index 7f9c60cc1..a4341a10f 100644 --- a/core/userrights.class.inc.php +++ b/core/userrights.class.inc.php @@ -55,8 +55,6 @@ abstract class UserRightsAddOnAPI abstract public function Init(); // loads data (possible optimizations) - // Cf UserContext... - abstract public function GetFilter($sLogin, $sClass); // returns a filter object // Used to build select queries showing only objects visible for the given user abstract public function GetSelectFilter($sLogin, $sClass); // returns a filter object @@ -494,23 +492,6 @@ class UserRights return true; } - public static function GetFilter($sClass) - { - // #@# to cleanup ! - return new DBObjectSearch($sClass); - - if (!self::CheckLogin()) return false; - if (self::IsAdministrator()) return new DBObjectSearch($sClass); - - // this module is forbidden for non admins - if (MetaModel::HasCategory($sClass, 'addon/userrights')) return false; - - // the rest is allowed (#@# to be improved) - if (!MetaModel::HasCategory($sClass, 'bizmodel')) return new DBObjectSearch($sClass); - - return self::$m_oAddOn->GetFilter(self::$m_oUser->GetKey(), $sClass); - } - public static function GetSelectFilter($sClass) { // Need to load some records before the login is performed (user preferences) diff --git a/pages/UI.php b/pages/UI.php index 456ad506a..42f2cb01d 100644 --- a/pages/UI.php +++ b/pages/UI.php @@ -445,7 +445,6 @@ try require_once('../application/wizardhelper.class.inc.php'); require_once('../application/startup.inc.php'); - $oContext = new UserContext(); $oAppContext = new ApplicationContext(); $currentOrganization = utils::ReadParam('org_id', ''); $operation = utils::ReadParam('operation', ''); @@ -469,7 +468,7 @@ try { throw new ApplicationException(Dict::Format('UI:Error:2ParametersMissing', 'class', 'id')); } - $oObj = $oContext->GetObject($sClass, $id); + $oObj = MetaModel::GetObject($sClass, $id); if ($oObj != null) { $oP->set_title(Dict::Format('UI:DetailsPageTitle', $oObj->GetName(), $sClassLabel)); @@ -540,7 +539,7 @@ try throw new ApplicationException(Dict::Format('UI:Error:1ParametersMissing', 'class')); } $oP->set_title(Dict::S('UI:SearchResultsPageTitle')); - $oFilter = $oContext->NewFilter($sClass); + $oFilter = new DBObjectSearch($sClass); $oSet = new DBObjectSet($oFilter); if ($bSearchForm) { @@ -762,7 +761,6 @@ try $oP->add_linked_script("../js/linkswidget.js"); $oP->add_linked_script("../js/jquery.blockUI.js"); - $oContext = new UserContext(); $aArgs = array_merge($oAppContext->GetAsHash(), utils::ReadParam('default', array())); // If the specified class has subclasses, ask the user an instance of which class to create @@ -860,7 +858,7 @@ try { throw new ApplicationException(Dict::Format('UI:Error:2ParametersMissing', 'class', 'id')); } - $oObj = $oContext->GetObject($sClass, $id); + $oObj = MetaModel::GetObject($sClass, $id); if (!utils::IsTransactionValid($sTransactionId)) { $oP->p("".Dict::S('UI:Error:ObjectAlreadyUpdated')."\n"); @@ -950,7 +948,7 @@ try } foreach($aSelectObject as $iId) { - $aObjects[] = $oContext->GetObject($sClass, $iId); + $aObjects[] = MetaModel::GetObject($sClass, $iId); } if (MetaModel::IsReadOnlyClass($sClass) || !UserRights::IsActionAllowed($sClass, UR_ACTION_BULK_DELETE, DBObjectSet::FromArray($sClass, $aObjects))) { @@ -965,7 +963,7 @@ try $sClass = utils::ReadParam('class', ''); $sClassLabel = MetaModel::GetName($sClass); $id = utils::ReadParam('id', ''); - $oObj = $oContext->GetObject($sClass, $id); + $oObj = MetaModel::GetObject($sClass, $id); if (MetaModel::IsReadOnlyClass($sClass) || !UserRights::IsActionAllowed($sClass, UR_ACTION_MODIFY, DBObjectSet::FromObject($oObj))) { @@ -985,7 +983,7 @@ try } else { - $oObj = $oContext->GetObject($sClass, $iCloneId); + $oObj = MetaModel::GetObject($sClass, $iCloneId); $oMyChange = MetaModel::NewObject("CMDBChange"); $oMyChange->Set("date", time()); if (UserRights::IsImpersonated()) @@ -1091,7 +1089,7 @@ try { throw new ApplicationException(Dict::Format('UI:Error:3ParametersMissing', 'class', 'id', 'stimulus')); } - $oObj = $oContext->GetObject($sClass, $id); + $oObj = MetaModel::GetObject($sClass, $id); if ($oObj != null) { $aTransitions = $oObj->EnumTransitions(); @@ -1183,7 +1181,7 @@ EOF { throw new ApplicationException(Dict::Format('UI:Error:3ParametersMissing', 'class', 'id', 'stimulus')); } - $oObj = $oContext->GetObject($sClass, $id); + $oObj = MetaModel::GetObject($sClass, $id); if ($oObj != null) { $aTransitions = $oObj->EnumTransitions(); @@ -1258,7 +1256,7 @@ EOF } require_once('../application/uilinkswizard.class.inc.php'); $oWizard = new UILinksWizard($sClass, $sLinkAttr, $id, $sTargetClass); - $oWizard->Display($oP, $oContext, array('StartWithAdd' => $bAddObjects)); + $oWizard->Display($oP, array('StartWithAdd' => $bAddObjects)); break; case 'do_modify_links': @@ -1291,7 +1289,7 @@ EOF { if ($iLinkId > 0) // Negative IDs are objects that were not even created { - $oLink = $oContext->GetObject($sClass, $iLinkId); + $oLink = MetaModel::GetObject($sClass, $iLinkId); $oLink->DBDeleteTracked($oMyChange); } } @@ -1314,7 +1312,7 @@ EOF if ($iLinkId > 0) { // This is an existing link to be modified - $oLink = $oContext->GetObject($sClass, $iLinkId); + $oLink = MetaModel::GetObject($sClass, $iLinkId); // Update all the attributes of the link foreach($aEditableFields as $sAttCode) @@ -1352,9 +1350,9 @@ EOF // Display again the details of the linked object $oAttDef = MetaModel::GetAttributeDef($sClass, $sLinkageAtt); $sTargetClass = $oAttDef->GetTargetClass(); - $oObj = $oContext->GetObject($sTargetClass, $iObjectId); + $oObj = MetaModel::GetObject($sTargetClass, $iObjectId); - $oSearch = $oContext->NewFilter(get_class($oObj)); + $oSearch = new DBObjectSearch(get_class($oObj)); $oBlock = new DisplayBlock($oSearch, 'search', false); $oBlock->Display($oP, 0); $oObj->DisplayDetails($oP); diff --git a/pages/UniversalSearch.php b/pages/UniversalSearch.php index ac0a08275..f4ecf5f1d 100644 --- a/pages/UniversalSearch.php +++ b/pages/UniversalSearch.php @@ -32,7 +32,6 @@ require_once('../application/startup.inc.php'); require_once('../application/loginwebpage.class.inc.php'); LoginWebPage::DoLogin(); // Check user rights and prompt if needed -$oContext = new UserContext(); $oAppContext = new ApplicationContext(); $iActiveNodeId = utils::ReadParam('menu', -1); $currentOrganization = utils::ReadParam('org_id', ''); diff --git a/pages/ajax.csvimport.php b/pages/ajax.csvimport.php index 42c280c14..58594d6b8 100644 --- a/pages/ajax.csvimport.php +++ b/pages/ajax.csvimport.php @@ -173,8 +173,6 @@ require_once('../application/loginwebpage.class.inc.php'); LoginWebPage::DoLogin(); // Check user rights and prompt if needed - -$oContext = new UserContext(); $sOperation = utils::ReadParam('operation', ''); switch($sOperation) diff --git a/pages/ajax.render.php b/pages/ajax.render.php index f5bee6edd..cbd1796da 100644 --- a/pages/ajax.render.php +++ b/pages/ajax.render.php @@ -38,7 +38,6 @@ LoginWebPage::DoLogin(); // Check user rights and prompt if needed $oPage = new ajax_page(""); $oPage->no_cache(); -$oContext = new UserContext(); $operation = utils::ReadParam('operation', ''); $sFilter = stripslashes(utils::ReadParam('filter', '')); $sEncoding = utils::ReadParam('encoding', 'serialize'); @@ -54,7 +53,7 @@ switch($operation) $sLinkageAttr = utils::ReadParam('linkageAttr', '', 'get'); $iObjectId = utils::ReadParam('objectId', '', 'get'); $oLinksWizard = new UILinksWizard($sClass, $sLinkageAttr, $iObjectId, $sLinkedClass); - $oLinksWizard->DisplayAddForm($oPage, $oContext); + $oLinksWizard->DisplayAddForm($oPage); break; // ui.linkswidget @@ -65,7 +64,7 @@ switch($operation) $sSuffix = utils::ReadParam('sSuffix', ''); $aAlreadyLinked = utils::ReadParam('aAlreadyLinked', array()); $oWidget = new UILinksWidget($sClass, $sAttCode, $iInputId, $sSuffix); - $oWidget->SearchObjectsToAdd($oPage, $oContext, $sRemoteClass, $aAlreadyLinked); + $oWidget->SearchObjectsToAdd($oPage, $sRemoteClass, $aAlreadyLinked); break; // ui.linkswidget @@ -75,7 +74,7 @@ switch($operation) $sSuffix = utils::ReadParam('sSuffix', ''); $aLinkedObjectIds = utils::ReadParam('selectObject', array(), 'get'); $oWidget = new UILinksWidget($sClass, $sAttCode, $iInputId, $sSuffix); - $oWidget->DoAddObjects($oPage, $oContext, $aLinkedObjectIds); + $oWidget->DoAddObjects($oPage, $aLinkedObjectIds); break; case 'wizard_helper_preview': @@ -145,7 +144,7 @@ switch($operation) case 'details': $key = utils::ReadParam('id', 0); - $oFilter = $oContext->NewFilter($sClass); + $oFilter = new DBObjectSearch($sClass); $oFilter->AddCondition('id', $key, '='); $oDisplayBlock = new DisplayBlock($oFilter, 'details', false); $oDisplayBlock->RenderContent($oPage); @@ -153,7 +152,7 @@ switch($operation) case 'preview': $key = utils::ReadParam('id', 0); - $oFilter = $oContext->NewFilter($sClass); + $oFilter = new DBObjectSearch($sClass); $oFilter->AddCondition('id', $key, '='); $oDisplayBlock = new DisplayBlock($oFilter, 'preview', false); $oDisplayBlock->RenderContent($oPage); @@ -205,7 +204,7 @@ switch($operation) case 'modal_details': $key = utils::ReadParam('id', 0); - $oFilter = $oContext->NewFilter($sClass); + $oFilter = new DBObjectSearch($sClass); $oFilter->AddCondition('id', $key, '='); $oPage->Add("

Object Details

\n"); $oDisplayBlock = new DisplayBlock($oFilter, 'details', false); @@ -220,7 +219,7 @@ switch($operation) $sOrg = utils::ReadParam('org_id', ''); $sName = utils::ReadParam('q', ''); $iMaxCount = utils::ReadParam('max', 30); - UILinksWidget::Autocomplete($oPage, $oContext, $sClass, $sAttCode, $sName, $iMaxCount); + UILinksWidget::Autocomplete($oPage, $sClass, $sAttCode, $sName, $iMaxCount); */ break; @@ -268,7 +267,7 @@ switch($operation) $sName = utils::ReadParam('q', ''); $iMaxCount = utils::ReadParam('max', 30); $iCount = 0; - $oFilter = $oContext->NewFilter($sClass); + $oFilter = new DBObjectSearch($sClass); $oFilter->AddCondition($sAttCode, $sName, 'Begins with'); //$oFilter->AddCondition('org_id', $sOrg, '='); $oSet = new CMDBObjectSet($oFilter, array($sAttCode => true)); @@ -300,7 +299,7 @@ switch($operation) $sField = utils::ReadParam('field', ''); if (!empty($sClass) && !empty($id) && !empty($sField)) { - DownloadDocument($oPage, $oContext, $sClass, $id, $sField, 'inline'); + DownloadDocument($oPage, $sClass, $id, $sField, 'inline'); } break; @@ -309,7 +308,7 @@ switch($operation) $sField = utils::ReadParam('field', ''); if (!empty($sClass) && !empty($id) && !empty($sField)) { - DownloadDocument($oPage, $oContext, $sClass, $id, $sField, 'attachement'); + DownloadDocument($oPage, $sClass, $id, $sField, 'attachement'); } break; @@ -317,7 +316,7 @@ switch($operation) $sClass = utils::ReadParam('className', ''); $sRootClass = utils::ReadParam('baseClass', ''); $currentId = utils::ReadParam('currentId', ''); - $oFilter = $oContext->NewFilter($sClass); + $oFilter = new DBObjectSearch($sClass); $oSet = new CMDBObjectSet($oFilter); $sHtml = cmdbAbstractObject::GetSearchForm($oPage, $oSet, array('currentId' => $currentId, 'baseClass' => $sRootClass)); $oPage->add($sHtml); @@ -343,18 +342,17 @@ $oPage->output(); * Downloads a document to the browser, either as 'inline' or 'attachment' * * @param WebPage $oPage The web page for the output - * @param UserContext $oContext The current User/security context to retreive the objects * @param string $sClass Class name of the object * @param mixed $id Identifier of the object * @param string $sAttCode Name of the attribute containing the document to download * @param string $sContentDisposition Either 'inline' or 'attachment' * @return none */ -function DownloadDocument(WebPage $oPage, UserContext $oContext, $sClass, $id, $sAttCode, $sContentDisposition = 'attachement') +function DownloadDocument(WebPage $oPage, $sClass, $id, $sAttCode, $sContentDisposition = 'attachement') { try { - $oObj = $oContext->GetObject($sClass, $id); + $oObj = MetaModel::GetObject($sClass, $id); if (is_object($oObj)) { $oDocument = $oObj->Get($sAttCode); diff --git a/pages/audit.php b/pages/audit.php index d3c282fee..2ba598f92 100644 --- a/pages/audit.php +++ b/pages/audit.php @@ -38,9 +38,7 @@ $oP = new iTopWebPage(Dict::S('UI:Audit:Title'), $currentOrganization); function GetRuleResultSet($iRuleId, $oDefinitionFilter) { - $oContext = new UserContext(); - - $oRule = $oContext->GetObject('AuditRule', $iRuleId); + $oRule = MetaModel::GetObject('AuditRule', $iRuleId); $sOql = $oRule->Get('query'); $oRuleFilter = DBObjectSearch::FromOQL($sOql); if ($oRule->Get('valid_flag') == 'false') @@ -87,8 +85,7 @@ switch($operation) $iCategory = utils::ReadParam('category', ''); $iRuleIndex = utils::ReadParam('rule', 0); - $oContext = new UserContext(); - $oAuditCategory = $oContext->GetObject('AuditCategory', $iCategory); + $oAuditCategory = MetaModel::GetObject('AuditCategory', $iCategory); $oDefinitionFilter = DBObjectSearch::FromOQL($oAuditCategory->Get('definition_set')); if (!empty($currentOrganization)) { @@ -96,7 +93,7 @@ switch($operation) } $oDefinitionSet = new CMDBObjectSet($oDefinitionFilter); $oErrorObjectSet = GetRuleResultSet($iRuleIndex, $oDefinitionFilter); - $oAuditRule = $oContext->GetObject('AuditRule', $iRuleIndex); + $oAuditRule = MetaModel::GetObject('AuditRule', $iRuleIndex); $oP->add(''); $oP->p('[Back to audit results]'); $sBlockId = 'audit_errors'; diff --git a/pages/csvimport.php b/pages/csvimport.php index accac719a..881dcaede 100644 --- a/pages/csvimport.php +++ b/pages/csvimport.php @@ -33,7 +33,6 @@ require_once('../application/startup.inc.php'); require_once('../application/loginwebpage.class.inc.php'); LoginWebPage::DoLogin(); // Check user rights and prompt if needed -$oContext = new UserContext(); $oAppContext = new ApplicationContext(); $currentOrganization = utils::ReadParam('org_id', 1); $iStep = utils::ReadParam('step', 1); @@ -208,11 +207,10 @@ function GuessParameters($sCSVData) /** * Process the CSV data, for real or as a simulation * @param WebPage $oPage The page used to display the wizard - * @param UserContext $oContext The current user context * @param bool $bSimulate Whether or not to simulate the data load * @return array The CSV lines in error that were rejected from the load (with the header line - if any) or null */ -function ProcessCSVData(WebPage $oPage, UserContext $oContext, $bSimulate = true) +function ProcessCSVData(WebPage $oPage, $bSimulate = true) { $aResult = array(); $sCSVData = utils::ReadParam('csvdata', ''); @@ -362,7 +360,7 @@ function ProcessCSVData(WebPage $oPage, UserContext $oContext, $bSimulate = true case 'RowStatus_NoChange': $iUnchanged++; $sFinalClass = $aRes[$iLine]['finalclass']; - $oObj = $oContext->GetObject($sFinalClass, $aRes[$iLine]['id']->GetValue()); + $oObj = MetaModel::GetObject($sFinalClass, $aRes[$iLine]['id']->GetValue()); $sUrl = $oObj->GetHyperlink(); $sStatus = ''; $sCSSRowClass = 'row_unchanged'; @@ -371,7 +369,7 @@ function ProcessCSVData(WebPage $oPage, UserContext $oContext, $bSimulate = true case 'RowStatus_Modify': $iModified++; $sFinalClass = $aRes[$iLine]['finalclass']; - $oObj = $oContext->GetObject($sFinalClass, $aRes[$iLine]['id']->GetValue()); + $oObj = MetaModel::GetObject($sFinalClass, $aRes[$iLine]['id']->GetValue()); $sUrl = $oObj->GetHyperlink(); $sStatus = ''; $sCSSRowClass = 'row_modified'; @@ -389,7 +387,7 @@ function ProcessCSVData(WebPage $oPage, UserContext $oContext, $bSimulate = true else { $sFinalClass = $aRes[$iLine]['finalclass']; - $oObj = $oContext->GetObject($sFinalClass, $aRes[$iLine]['id']->GetValue()); + $oObj = MetaModel::GetObject($sFinalClass, $aRes[$iLine]['id']->GetValue()); $sUrl = $oObj->GetHyperlink(); $sMessage = 'Object created'; } @@ -541,13 +539,12 @@ EOF /** * Perform the actual load of the CSV data and display the results * @param WebPage $oPage The web page to display the wizard - * @param UserContext $oContext Current user's context * @return void */ -function LoadData(WebPage $oPage, UserContext $oContext) +function LoadData(WebPage $oPage) { $oPage->add('

'.Dict::S('UI:Title:CSVImportStep5').'

'); - $aResult = ProcessCSVData($oPage, $oContext, false /* simulate = false */); + $aResult = ProcessCSVData($oPage, false /* simulate = false */); if (is_array($aResult)) { $oPage->StartCollapsibleSection(Dict::S('UI:CSVImport:LinesNotImported'), false); @@ -562,13 +559,12 @@ function LoadData(WebPage $oPage, UserContext $oContext) /** * Simulate the load of the CSV data and display the results * @param WebPage $oPage The web page to display the wizard - * @param UserContext $oContext Current user's context * @return void */ -function Preview(WebPage $oPage, UserContext $oContext) +function Preview(WebPage $oPage) { $oPage->add('

'.Dict::S('UI:Title:CSVImportStep4').'

'); - ProcessCSVData($oPage, $oContext, true /* simulate */); + ProcessCSVData($oPage, true /* simulate */); } /** @@ -1049,11 +1045,11 @@ EOF switch($iStep) { case 5: - LoadData($oPage, $oContext); + LoadData($oPage); break; case 4: - Preview($oPage, $oContext); + Preview($oPage); break; case 3: diff --git a/pages/logoff.php b/pages/logoff.php index b77b36b74..5f8c2ccd7 100644 --- a/pages/logoff.php +++ b/pages/logoff.php @@ -19,7 +19,6 @@ require_once('../application/itopwebpage.class.inc.php'); require_once('../application/wizardhelper.class.inc.php'); require_once('../application/startup.inc.php'); -$oContext = new UserContext(); $oAppContext = new ApplicationContext(); $currentOrganization = utils::ReadParam('org_id', ''); $operation = utils::ReadParam('operation', ''); diff --git a/pages/navigator.php b/pages/navigator.php index ec912999f..0d543a9db 100755 --- a/pages/navigator.php +++ b/pages/navigator.php @@ -26,7 +26,6 @@ require_once('../application/loginwebpage.class.inc.php'); LoginWebPage::DoLogin(); // Check user rights and prompt if needed $sOperation = utils::ReadParam('operation', 'menu'); -$oContext = new UserContext(); $oAppContext = new ApplicationContext(); $iActiveNodeId = utils::ReadParam('menu', -1); $currentOrganization = utils::ReadParam('org_id', ''); diff --git a/pages/run_query.php b/pages/run_query.php index fd7c5cf87..d1ef26029 100644 --- a/pages/run_query.php +++ b/pages/run_query.php @@ -91,7 +91,6 @@ function ShowExamples($oP, $sExpression) } $sOperation = utils::ReadParam('operation', 'menu'); -$oContext = new UserContext(); $oAppContext = new ApplicationContext(); $iActiveNodeId = utils::ReadParam('menu', -1); $currentOrganization = utils::ReadParam('org_id', ''); diff --git a/pages/schema.php b/pages/schema.php index 5ff26f348..1914bd31b 100644 --- a/pages/schema.php +++ b/pages/schema.php @@ -491,7 +491,6 @@ require_once('../application/loginwebpage.class.inc.php'); LoginWebPage::DoLogin(); // Check user rights and prompt if needed // Display the menu on the left -$oContext = new UserContext(); $oAppContext = new ApplicationContext(); $iActiveNodeId = utils::ReadParam('menu', -1); $currentOrganization = utils::ReadParam('org_id', 1); diff --git a/pages/testlist.inc.php b/pages/testlist.inc.php index ad2043fba..5d53f74aa 100644 --- a/pages/testlist.inc.php +++ b/pages/testlist.inc.php @@ -356,8 +356,6 @@ class TestUserRightsMatrixItop extends TestUserRights echo "

User: ".UserRights::GetUser()."

\n"; echo "

On behalf of...".UserRights::GetRealUser()."

\n"; - UserRights::GetFilter('bizOrganization'); // returns a filter object - $oSet = new DBObjectSet(DBObjectSearch::FromOQL("SELECT bizOrganization")); echo "

IsActionAllowed...".(UserRights::IsActionAllowed('bizOrganization', UR_ACTION_MODIFY, $oSet) == UR_ALLOWED_YES ? 'ok' : 'NO')."

\n"; echo "

IsStimulusAllowed...".(UserRights::IsStimulusAllowed('bizOrganization', 'myStimulus', $oSet) == UR_ALLOWED_YES ? 'ok' : 'NO')."

\n"; diff --git a/pages/usermanagement_classproj.php b/pages/usermanagement_classproj.php index 22db2525a..379b8d7a0 100644 --- a/pages/usermanagement_classproj.php +++ b/pages/usermanagement_classproj.php @@ -107,7 +107,6 @@ require_once('../application/loginwebpage.class.inc.php'); LoginWebPage::DoLogin(); // Check user rights and prompt if needed // Display the menu on the left -$oContext = new UserContext(); $oAppContext = new ApplicationContext(); $iActiveNodeId = utils::ReadParam('menu', -1); $currentOrganization = utils::ReadParam('org_id', 1); diff --git a/pages/usermanagement_profileproj.php b/pages/usermanagement_profileproj.php index 24cda4f70..2b018b8cb 100644 --- a/pages/usermanagement_profileproj.php +++ b/pages/usermanagement_profileproj.php @@ -118,7 +118,6 @@ require_once('../application/loginwebpage.class.inc.php'); LoginWebPage::DoLogin(); // Check user rights and prompt if needed // Display the menu on the left -$oContext = new UserContext(); $oAppContext = new ApplicationContext(); $iActiveNodeId = utils::ReadParam('menu', -1); $currentOrganization = utils::ReadParam('org_id', 1); diff --git a/pages/usermanagement_userstatus.php b/pages/usermanagement_userstatus.php index 6ba64e54d..9c5f6ff3d 100644 --- a/pages/usermanagement_userstatus.php +++ b/pages/usermanagement_userstatus.php @@ -270,7 +270,6 @@ require_once('../application/loginwebpage.class.inc.php'); LoginWebPage::DoLogin(); // Check user rights and prompt if needed // Display the menu on the left -$oContext = new UserContext(); $oAppContext = new ApplicationContext(); $iActiveNodeId = utils::ReadParam('menu', -1); $currentOrganization = utils::ReadParam('org_id', 1); diff --git a/pages/xml.navigator.php b/pages/xml.navigator.php index 66188dc9c..04c398a72 100755 --- a/pages/xml.navigator.php +++ b/pages/xml.navigator.php @@ -60,7 +60,6 @@ function AddNodeDetails(&$oNode, $oObj) */ function GetRelatedObjects(DBObject $oObj, $sRelationName, &$oLinks, &$oXmlDoc, &$oXmlNode) { - $oContext = new UserContext(); $aResults = array(); $oObj->GetRelatedObjects($sRelationName, 1 /* iMaxDepth */, $aResults); static $iDepth = 0; @@ -115,7 +114,6 @@ LoginWebPage::DoLogin(); // Check user rights and prompt if needed $oPage = new ajax_page(""); $oPage->no_cache(); -$oContext = new UserContext(); $sClass = utils::ReadParam('class', 'Contact'); $id = utils::ReadParam('id', 1); $sRelation = utils::ReadParam('relation', 'impacts'); @@ -129,7 +127,7 @@ if (!in_array($sRelation, $aValidRelations)) if ($id != 0) { - $oObj = $oContext->GetObject($sClass, $id); + $oObj = MetaModel::GetObject($sClass, $id); // Build the root XML part $oXmlDoc = new DOMDocument( '1.0', 'UTF-8' ); $oXmlRoot = $oXmlDoc->CreateElement('root'); diff --git a/webservices/export.php b/webservices/export.php index 94aa77ef3..8469754d9 100644 --- a/webservices/export.php +++ b/webservices/export.php @@ -34,7 +34,6 @@ require_once('../application/loginwebpage.class.inc.php'); LoginWebPage::DoLogin(); // Check user rights and prompt if needed $sOperation = utils::ReadParam('operation', 'menu'); -$oContext = new UserContext(); $oAppContext = new ApplicationContext(); $iActiveNodeId = utils::ReadParam('menu', -1); $currentOrganization = utils::ReadParam('org_id', ''); diff --git a/webservices/import.php b/webservices/import.php index b78d2a92c..a151a424e 100644 --- a/webservices/import.php +++ b/webservices/import.php @@ -53,7 +53,6 @@ class WebServiceException extends Exception LoginWebPage::DoLogin(); // Check user rights and prompt if needed -$oContext = new UserContext(); $oAppContext = new ApplicationContext(); //$iActiveNodeId = utils::ReadParam('menu', -1); //$currentOrganization = utils::ReadParam('org_id', '');