public function IsUserAllowed()
 {
     if (array_key_exists('profile_list', $_SESSION)) {
         $aProfiles = $_SESSION['profile_list'];
     } else {
         $oUser = UserRights::GetUserObject();
         $oSet = $oUser->Get('profile_list');
         while (($oLnkUserProfile = $oSet->Fetch()) !== null) {
             $aProfiles[] = $oLnkUserProfile->Get('profileid_friendlyname');
         }
         $_SESSION['profile_list'] = $aProfiles;
     }
     foreach ($this->aData['deny'] as $sDeniedProfile) {
         // If one denied profile is present, it's enough => return false
         if (in_array($sDeniedProfile, $aProfiles)) {
             return false;
         }
     }
     foreach ($this->aData['allow'] as $sAllowProfile) {
         // if one required profile is missing, it's enough => return false
         if (!in_array($sAllowProfile, $aProfiles)) {
             return false;
         }
     }
     return true;
 }
 public function IsUserAllowed()
 {
     $bRet = true;
     if (array_key_exists('profile_list', $_SESSION)) {
         $aProfiles = $_SESSION['profile_list'];
     } else {
         $oUser = UserRights::GetUserObject();
         $oSet = $oUser->Get('profile_list');
         while (($oLnkUserProfile = $oSet->Fetch()) !== null) {
             $aProfiles[] = $oLnkUserProfile->Get('profileid_friendlyname');
         }
         $_SESSION['profile_list'] = $aProfiles;
     }
     foreach ($this->aData['deny'] as $sDeniedProfile) {
         // If one denied profile is present, it's enough => return false
         if (in_array($sDeniedProfile, $aProfiles)) {
             return false;
         }
     }
     // If there are some "allow" profiles, then by default the result is false
     // since the user must have at least one of the profiles to be allowed
     if (count($this->aData['allow']) > 0) {
         $bRet = false;
     }
     foreach ($this->aData['allow'] as $sAllowProfile) {
         // If one "allow" profile is present, it's enough => return true
         if (in_array($sAllowProfile, $aProfiles)) {
             return true;
         }
     }
     return $bRet;
 }
 /**
  * Attempt a login
  * 	 	
  * @param int iOnExit What action to take if the user is not logged on (one of the class constants EXIT_...)
  * @return int One of the class constants EXIT_CODE_...
  */
 protected static function Login($iOnExit)
 {
     if (self::SecureConnectionRequired() && !utils::IsConnectionSecure()) {
         // Non secured URL... request for a secure connection
         throw new Exception('Secure connection required!');
     }
     $aAllowedLoginTypes = MetaModel::GetConfig()->GetAllowedLoginTypes();
     if (isset($_SESSION['auth_user'])) {
         //echo "User: "******"\n";
         // Already authentified
         UserRights::Login($_SESSION['auth_user']);
         // Login & set the user's language
         return self::EXIT_CODE_OK;
     } else {
         $index = 0;
         $sLoginMode = '';
         $sAuthentication = 'internal';
         while ($sLoginMode == '' && $index < count($aAllowedLoginTypes)) {
             $sLoginType = $aAllowedLoginTypes[$index];
             switch ($sLoginType) {
                 case 'cas':
                     utils::InitCASClient();
                     // check CAS authentication
                     if (phpCAS::isAuthenticated()) {
                         $sAuthUser = phpCAS::getUser();
                         $sAuthPwd = '';
                         $sLoginMode = 'cas';
                         $sAuthentication = 'external';
                     }
                     break;
                 case 'form':
                     // iTop standard mode: form based authentication
                     $sAuthUser = utils::ReadPostedParam('auth_user', '', false, 'raw_data');
                     $sAuthPwd = utils::ReadPostedParam('auth_pwd', null, false, 'raw_data');
                     if ($sAuthUser != '' && $sAuthPwd !== null) {
                         $sLoginMode = 'form';
                     }
                     break;
                 case 'basic':
                     // Standard PHP authentication method, works with Apache...
                     // Case 1) Apache running in CGI mode + rewrite rules in .htaccess
                     if (isset($_SERVER['HTTP_AUTHORIZATION']) && !empty($_SERVER['HTTP_AUTHORIZATION'])) {
                         list($sAuthUser, $sAuthPwd) = explode(':', base64_decode(substr($_SERVER['HTTP_AUTHORIZATION'], 6)));
                         $sLoginMode = 'basic';
                     } else {
                         if (isset($_SERVER['PHP_AUTH_USER'])) {
                             $sAuthUser = $_SERVER['PHP_AUTH_USER'];
                             // Unfortunately, the RFC is not clear about the encoding...
                             // IE and FF supply the user and password encoded in ISO-8859-1 whereas Chrome provides them encoded in UTF-8
                             // So let's try to guess if it's an UTF-8 string or not... fortunately all encodings share the same ASCII base
                             if (!self::LooksLikeUTF8($sAuthUser)) {
                                 // Does not look like and UTF-8 string, try to convert it from iso-8859-1 to UTF-8
                                 // Supposed to be harmless in case of a plain ASCII string...
                                 $sAuthUser = iconv('iso-8859-1', 'utf-8', $sAuthUser);
                             }
                             $sAuthPwd = $_SERVER['PHP_AUTH_PW'];
                             if (!self::LooksLikeUTF8($sAuthPwd)) {
                                 // Does not look like and UTF-8 string, try to convert it from iso-8859-1 to UTF-8
                                 // Supposed to be harmless in case of a plain ASCII string...
                                 $sAuthPwd = iconv('iso-8859-1', 'utf-8', $sAuthPwd);
                             }
                             $sLoginMode = 'basic';
                         }
                     }
                     break;
                 case 'external':
                     // Web server supplied authentication
                     $bExternalAuth = false;
                     $sExtAuthVar = MetaModel::GetConfig()->GetExternalAuthenticationVariable();
                     // In which variable is the info passed ?
                     eval('$sAuthUser = isset(' . $sExtAuthVar . ') ? ' . $sExtAuthVar . ' : false;');
                     // Retrieve the value
                     if ($sAuthUser && strlen($sAuthUser) > 0) {
                         $sAuthPwd = '';
                         // No password in this case the web server already authentified the user...
                         $sLoginMode = 'external';
                         $sAuthentication = 'external';
                     }
                     break;
                 case 'url':
                     // Credentials passed directly in the url
                     $sAuthUser = utils::ReadParam('auth_user', '', false, 'raw_data');
                     $sAuthPwd = utils::ReadParam('auth_pwd', null, false, 'raw_data');
                     if ($sAuthUser != '' && $sAuthPwd !== null) {
                         $sLoginMode = 'url';
                     }
                     break;
             }
             $index++;
         }
         //echo "\nsLoginMode: $sLoginMode (user: $sAuthUser / pwd: $sAuthPwd\n)";
         if ($sLoginMode == '') {
             // First connection
             $sDesiredLoginMode = utils::ReadParam('login_mode');
             if (in_array($sDesiredLoginMode, $aAllowedLoginTypes)) {
                 $sLoginMode = $sDesiredLoginMode;
             } else {
                 $sLoginMode = $aAllowedLoginTypes[0];
                 // First in the list...
             }
             if (array_key_exists('HTTP_X_COMBODO_AJAX', $_SERVER)) {
                 // X-Combodo-Ajax is a special header automatically added to all ajax requests
                 // Let's reply that we're currently logged-out
                 header('HTTP/1.0 401 Unauthorized');
                 exit;
             }
             if ($iOnExit == self::EXIT_HTTP_401 || $sLoginMode == 'basic') {
                 header('WWW-Authenticate: Basic realm="' . Dict::Format('UI:iTopVersion:Short', ITOP_VERSION));
                 header('HTTP/1.0 401 Unauthorized');
                 header('Content-type: text/html; charset=iso-8859-1');
                 exit;
             } else {
                 if ($iOnExit == self::EXIT_RETURN) {
                     if ($sAuthUser !== '' && $sAuthPwd === null) {
                         return self::EXIT_CODE_MISSINGPASSWORD;
                     } else {
                         return self::EXIT_CODE_MISSINGLOGIN;
                     }
                 } else {
                     $oPage = self::NewLoginWebPage();
                     $oPage->DisplayLoginForm($sLoginMode, false);
                     $oPage->output();
                     exit;
                 }
             }
         } else {
             if (!UserRights::CheckCredentials($sAuthUser, $sAuthPwd, $sLoginMode, $sAuthentication)) {
                 //echo "Check Credentials returned false for user $sAuthUser!";
                 self::ResetSession();
                 if ($iOnExit == self::EXIT_HTTP_401 || $sLoginMode == 'basic') {
                     header('WWW-Authenticate: Basic realm="' . Dict::Format('UI:iTopVersion:Short', ITOP_VERSION));
                     header('HTTP/1.0 401 Unauthorized');
                     header('Content-type: text/html; charset=iso-8859-1');
                     exit;
                 } else {
                     if ($iOnExit == self::EXIT_RETURN) {
                         return self::EXIT_CODE_WRONGCREDENTIALS;
                     } else {
                         $oPage = self::NewLoginWebPage();
                         $oPage->DisplayLoginForm($sLoginMode, true);
                         $oPage->output();
                         exit;
                     }
                 }
             } else {
                 // User is Ok, let's save it in the session and proceed with normal login
                 UserRights::Login($sAuthUser, $sAuthentication);
                 // Login & set the user's language
                 if (MetaModel::GetConfig()->Get('log_usage')) {
                     $oLog = new EventLoginUsage();
                     $oLog->Set('userinfo', UserRights::GetUser());
                     $oLog->Set('user_id', UserRights::GetUserObject()->GetKey());
                     $oLog->Set('message', 'Successful login');
                     $oLog->DBInsertNoReload();
                 }
                 $_SESSION['auth_user'] = $sAuthUser;
                 $_SESSION['login_mode'] = $sLoginMode;
                 UserRights::_InitSessionCache();
             }
         }
     }
     return self::EXIT_CODE_OK;
 }
Esempio n. 4
0
 /**
  * Renders the "Actions" popup menu for the given set of objects
  * 
  * Note that the menu links containing (or ending) with a hash (#) will have their fragment
  * part (whatever is after the hash) dynamically replaced (by javascript) when the menu is
  * displayed, to correspond to the current hash/fragment in the page. This allows modifying
  * an object in with the same tab active by default as the tab that was active when selecting
  * the "Modify..." action.
  */
 public function GetRenderContent(WebPage $oPage, $aExtraParams = array(), $sId)
 {
     if ($this->m_sStyle == 'popup') {
         $this->m_sStyle = 'list';
     }
     $sHtml = '';
     $oAppContext = new ApplicationContext();
     $sContext = $oAppContext->GetForLink();
     if (!empty($sContext)) {
         $sContext = '&' . $sContext;
     }
     $sClass = $this->m_oFilter->GetClass();
     $oReflectionClass = new ReflectionClass($sClass);
     $oSet = new CMDBObjectSet($this->m_oFilter);
     $sFilter = $this->m_oFilter->serialize();
     $sFilterDesc = $this->m_oFilter->ToOql(true);
     $aActions = array();
     $sUIPage = cmdbAbstractObject::ComputeStandardUIPage($sClass);
     $sRootUrl = utils::GetAbsoluteUrlAppRoot();
     // 1:n links, populate the target object as a default value when creating a new linked object
     if (isset($aExtraParams['target_attr'])) {
         $aExtraParams['default'][$aExtraParams['target_attr']] = $aExtraParams['object_id'];
     }
     $sDefault = '';
     if (!empty($aExtraParams['default'])) {
         foreach ($aExtraParams['default'] as $sKey => $sValue) {
             $sDefault .= "&default[{$sKey}]={$sValue}";
         }
     }
     $bIsCreationAllowed = UserRights::IsActionAllowed($sClass, UR_ACTION_CREATE) == UR_ALLOWED_YES && $oReflectionClass->IsSubclassOf('cmdbAbstractObject');
     switch ($oSet->Count()) {
         case 0:
             // No object in the set, the only possible action is "new"
             if ($bIsCreationAllowed) {
                 $aActions['UI:Menu:New'] = array('label' => Dict::S('UI:Menu:New'), 'url' => "{$sRootUrl}pages/{$sUIPage}?operation=new&class={$sClass}{$sContext}{$sDefault}");
             }
             break;
         case 1:
             $oObj = $oSet->Fetch();
             $id = $oObj->GetKey();
             $bLocked = false;
             if (MetaModel::GetConfig()->Get('concurrent_lock_enabled')) {
                 $aLockInfo = iTopOwnershipLock::IsLocked(get_class($oObj), $id);
                 if ($aLockInfo['locked']) {
                     $bLocked = true;
                     //$this->AddMenuSeparator($aActions);
                     //$aActions['concurrent_lock_unlock'] = array ('label' => Dict::S('UI:Menu:ReleaseConcurrentLock'), 'url' => "{$sRootUrl}pages/$sUIPage?operation=kill_lock&class=$sClass&id=$id{$sContext}");
                 }
             }
             $bRawModifiedAllowed = UserRights::IsActionAllowed($sClass, UR_ACTION_MODIFY, $oSet) == UR_ALLOWED_YES && $oReflectionClass->IsSubclassOf('cmdbAbstractObject');
             $bIsModifyAllowed = !$bLocked && $bRawModifiedAllowed;
             $bIsDeleteAllowed = !$bLocked && UserRights::IsActionAllowed($sClass, UR_ACTION_DELETE, $oSet);
             // Just one object in the set, possible actions are "new / clone / modify and delete"
             if (!isset($aExtraParams['link_attr'])) {
                 if ($bIsModifyAllowed) {
                     $aActions['UI:Menu:Modify'] = array('label' => Dict::S('UI:Menu:Modify'), 'url' => "{$sRootUrl}pages/{$sUIPage}?operation=modify&class={$sClass}&id={$id}{$sContext}#");
                 }
                 if ($bIsCreationAllowed) {
                     $aActions['UI:Menu:New'] = array('label' => Dict::S('UI:Menu:New'), 'url' => "{$sRootUrl}pages/{$sUIPage}?operation=new&class={$sClass}{$sContext}{$sDefault}");
                 }
                 if ($bIsDeleteAllowed) {
                     $aActions['UI:Menu:Delete'] = array('label' => Dict::S('UI:Menu:Delete'), 'url' => "{$sRootUrl}pages/{$sUIPage}?operation=delete&class={$sClass}&id={$id}{$sContext}");
                 }
                 // Transitions / Stimuli
                 if (!$bLocked) {
                     $aTransitions = $oObj->EnumTransitions();
                     if (count($aTransitions)) {
                         $this->AddMenuSeparator($aActions);
                         $aStimuli = Metamodel::EnumStimuli(get_class($oObj));
                         foreach ($aTransitions as $sStimulusCode => $aTransitionDef) {
                             $iActionAllowed = get_class($aStimuli[$sStimulusCode]) == 'StimulusUserAction' ? UserRights::IsStimulusAllowed($sClass, $sStimulusCode, $oSet) : UR_ALLOWED_NO;
                             switch ($iActionAllowed) {
                                 case UR_ALLOWED_YES:
                                     $aActions[$sStimulusCode] = array('label' => $aStimuli[$sStimulusCode]->GetLabel(), 'url' => "{$sRootUrl}pages/UI.php?operation=stimulus&stimulus={$sStimulusCode}&class={$sClass}&id={$id}{$sContext}");
                                     break;
                                 default:
                                     // Do nothing
                             }
                         }
                     }
                 }
                 // Relations...
                 $aRelations = MetaModel::EnumRelationsEx($sClass);
                 if (count($aRelations)) {
                     $this->AddMenuSeparator($aActions);
                     foreach ($aRelations as $sRelationCode => $aRelationInfo) {
                         if (array_key_exists('down', $aRelationInfo)) {
                             $aActions[$sRelationCode . '_down'] = array('label' => $aRelationInfo['down'], 'url' => "{$sRootUrl}pages/{$sUIPage}?operation=swf_navigator&relation={$sRelationCode}&direction=down&class={$sClass}&id={$id}{$sContext}");
                         }
                         if (array_key_exists('up', $aRelationInfo)) {
                             $aActions[$sRelationCode . '_up'] = array('label' => $aRelationInfo['up'], 'url' => "{$sRootUrl}pages/{$sUIPage}?operation=swf_navigator&relation={$sRelationCode}&direction=up&class={$sClass}&id={$id}{$sContext}");
                         }
                     }
                 }
                 if ($bLocked && $bRawModifiedAllowed) {
                     // Add a special menu to kill the lock, but only to allowed users who can also modify this object
                     $aAllowedProfiles = MetaModel::GetConfig()->Get('concurrent_lock_override_profiles');
                     $bCanKill = false;
                     $oUser = UserRights::GetUserObject();
                     $aUserProfiles = array();
                     if (!is_null($oUser)) {
                         $oProfileSet = $oUser->Get('profile_list');
                         while ($oProfile = $oProfileSet->Fetch()) {
                             $aUserProfiles[$oProfile->Get('profile')] = true;
                         }
                     }
                     foreach ($aAllowedProfiles as $sProfile) {
                         if (array_key_exists($sProfile, $aUserProfiles)) {
                             $bCanKill = true;
                             break;
                         }
                     }
                     if ($bCanKill) {
                         $this->AddMenuSeparator($aActions);
                         $aActions['concurrent_lock_unlock'] = array('label' => Dict::S('UI:Menu:KillConcurrentLock'), 'url' => "{$sRootUrl}pages/{$sUIPage}?operation=kill_lock&class={$sClass}&id={$id}{$sContext}");
                     }
                 }
                 /*
                 $this->AddMenuSeparator($aActions);
                 // Static menus: Email this page & CSV Export
                 $sUrl = ApplicationContext::MakeObjectUrl($sClass, $id);
                 $aActions['UI:Menu:EMail'] = array ('label' => Dict::S('UI:Menu:EMail'), 'url' => "mailto:?subject=".urlencode($oObj->GetRawName())."&body=".urlencode($sUrl));
                 $aActions['UI:Menu:CSVExport'] = array ('label' => Dict::S('UI:Menu:CSVExport'), 'url' => "{$sRootUrl}pages/$sUIPage?operation=search&filter=".urlencode($sFilter)."&format=csv{$sContext}");
                 // The style tells us whether the menu is displayed on a list of one object, or on the details of the given object 
                 if ($this->m_sStyle == 'list')
                 {
                 	// Actions specific to the list
                 	$sOQL = addslashes($sFilterDesc);
                 	$aActions['UI:Menu:AddToDashboard'] = array ('label' => Dict::S('UI:Menu:AddToDashboard'), 'url' => "#", 'onclick' => "return DashletCreationDlg('$sOQL')");
                 }
                 */
             }
             $this->AddMenuSeparator($aActions);
             foreach (MetaModel::EnumPlugins('iApplicationUIExtension') as $oExtensionInstance) {
                 $oSet->Rewind();
                 foreach ($oExtensionInstance->EnumAllowedActions($oSet) as $sLabel => $sUrl) {
                     $aActions[$sLabel] = array('label' => $sLabel, 'url' => $sUrl);
                 }
             }
             break;
         default:
             // Check rights
             // New / Modify
             $bIsModifyAllowed = UserRights::IsActionAllowed($sClass, UR_ACTION_MODIFY, $oSet) && $oReflectionClass->IsSubclassOf('cmdbAbstractObject');
             $bIsBulkModifyAllowed = !MetaModel::IsAbstract($sClass) && UserRights::IsActionAllowed($sClass, UR_ACTION_BULK_MODIFY, $oSet) && $oReflectionClass->IsSubclassOf('cmdbAbstractObject');
             $bIsBulkDeleteAllowed = UserRights::IsActionAllowed($sClass, UR_ACTION_BULK_DELETE, $oSet);
             if (isset($aExtraParams['link_attr'])) {
                 $id = $aExtraParams['object_id'];
                 $sTargetAttr = $aExtraParams['target_attr'];
                 $oAttDef = MetaModel::GetAttributeDef($sClass, $sTargetAttr);
                 $sTargetClass = $oAttDef->GetTargetClass();
                 $bIsDeleteAllowed = UserRights::IsActionAllowed($sClass, UR_ACTION_DELETE, $oSet);
                 if ($bIsModifyAllowed) {
                     $aActions['UI:Menu:Add'] = array('label' => Dict::S('UI:Menu:Add'), 'url' => "{$sRootUrl}pages/{$sUIPage}?operation=modify_links&class={$sClass}&link_attr=" . $aExtraParams['link_attr'] . "&target_class={$sTargetClass}&id={$id}&addObjects=true{$sContext}");
                 }
                 if ($bIsBulkModifyAllowed) {
                     $aActions['UI:Menu:Manage'] = array('label' => Dict::S('UI:Menu:Manage'), 'url' => "{$sRootUrl}pages/{$sUIPage}?operation=modify_links&class={$sClass}&link_attr=" . $aExtraParams['link_attr'] . "&target_class={$sTargetClass}&id={$id}{$sContext}");
                 }
                 //if ($bIsBulkDeleteAllowed) { $aActions[] = array ('label' => 'Remove All...', 'url' => "#"); }
             } else {
                 // many objects in the set, possible actions are: new / modify all / delete all
                 if ($bIsCreationAllowed) {
                     $aActions['UI:Menu:New'] = array('label' => Dict::S('UI:Menu:New'), 'url' => "{$sRootUrl}pages/{$sUIPage}?operation=new&class={$sClass}{$sContext}{$sDefault}");
                 }
                 if ($bIsBulkModifyAllowed) {
                     $aActions['UI:Menu:ModifyAll'] = array('label' => Dict::S('UI:Menu:ModifyAll'), 'url' => "{$sRootUrl}pages/{$sUIPage}?operation=select_for_modify_all&class={$sClass}&filter=" . urlencode($sFilter) . "{$sContext}");
                 }
                 if ($bIsBulkDeleteAllowed) {
                     $aActions['UI:Menu:BulkDelete'] = array('label' => Dict::S('UI:Menu:BulkDelete'), 'url' => "{$sRootUrl}pages/{$sUIPage}?operation=select_for_deletion&filter=" . urlencode($sFilter) . "{$sContext}");
                 }
                 // Stimuli
                 $aStates = MetaModel::EnumStates($sClass);
                 // Do not perform time consuming computations if there are too may objects in the list
                 $iLimit = MetaModel::GetConfig()->Get('complex_actions_limit');
                 if (count($aStates) > 0 && ($iLimit == 0 || $oSet->Count() < $iLimit)) {
                     // Life cycle actions may be available... if all objects are in the same state
                     //
                     // Group by <state>
                     $oGroupByExp = new FieldExpression(MetaModel::GetStateAttributeCode($sClass), $this->m_oFilter->GetClassAlias());
                     $aGroupBy = array('__state__' => $oGroupByExp);
                     $aQueryParams = array();
                     if (isset($aExtraParams['query_params'])) {
                         $aQueryParams = $aExtraParams['query_params'];
                     }
                     $sSql = $this->m_oFilter->MakeGroupByQuery($aQueryParams, $aGroupBy);
                     $aRes = CMDBSource::QueryToArray($sSql);
                     if (count($aRes) == 1) {
                         // All objects are in the same state...
                         $sState = $aRes[0]['__state__'];
                         $aTransitions = Metamodel::EnumTransitions($sClass, $sState);
                         if (count($aTransitions)) {
                             $this->AddMenuSeparator($aActions);
                             $aStimuli = Metamodel::EnumStimuli($sClass);
                             foreach ($aTransitions as $sStimulusCode => $aTransitionDef) {
                                 $oSet->Rewind();
                                 // As soon as the user rights implementation will browse the object set,
                                 // then we might consider using OptimizeColumnLoad() here
                                 $iActionAllowed = UserRights::IsStimulusAllowed($sClass, $sStimulusCode, $oSet);
                                 $iActionAllowed = get_class($aStimuli[$sStimulusCode]) == 'StimulusUserAction' ? $iActionAllowed : UR_ALLOWED_NO;
                                 switch ($iActionAllowed) {
                                     case UR_ALLOWED_YES:
                                     case UR_ALLOWED_DEPENDS:
                                         $aActions[$sStimulusCode] = array('label' => $aStimuli[$sStimulusCode]->GetLabel(), 'url' => "{$sRootUrl}pages/UI.php?operation=select_bulk_stimulus&stimulus={$sStimulusCode}&state={$sState}&class={$sClass}&filter=" . urlencode($sFilter) . "{$sContext}");
                                         break;
                                     default:
                                         // Do nothing
                                 }
                             }
                         }
                     }
                 }
                 /*
                 $this->AddMenuSeparator($aActions);
                 $sUrl = utils::GetAbsoluteUrlAppRoot();
                 $aActions['UI:Menu:EMail'] = array ('label' => Dict::S('UI:Menu:EMail'), 'url' => "mailto:?subject=$sFilterDesc&body=".urlencode("{$sUrl}pages/$sUIPage?operation=search&filter=".urlencode($sFilter)."{$sContext}"));
                 $aActions['UI:Menu:CSVExport'] = array ('label' => Dict::S('UI:Menu:CSVExport'), 'url' => "{$sRootUrl}pages/$sUIPage?operation=search&filter=".urlencode($sFilter)."&format=csv{$sContext}");
                 $sOQL = addslashes($sFilterDesc);
                 $aActions['UI:Menu:AddToDashboard'] = array ('label' => Dict::S('UI:Menu:AddToDashboard'), 'url' => "#", 'onclick' => "return DashletCreationDlg('$sOQL')");
                 */
             }
     }
     $this->AddMenuSeparator($aActions);
     foreach (MetaModel::EnumPlugins('iApplicationUIExtension') as $oExtensionInstance) {
         $oSet->Rewind();
         foreach ($oExtensionInstance->EnumAllowedActions($oSet) as $sLabel => $data) {
             if (is_array($data)) {
                 // New plugins can provide javascript handlers via the 'onclick' property
                 //TODO: enable extension of different menus by checking the 'target' property ??
                 $aActions[$sLabel] = array('label' => $sLabel, 'url' => isset($data['url']) ? $data['url'] : '#', 'onclick' => isset($data['onclick']) ? $data['onclick'] : '');
             } else {
                 // Backward compatibility with old plugins
                 $aActions[$sLabel] = array('label' => $sLabel, 'url' => $data);
             }
         }
     }
     // New extensions based on iPopupMenuItem interface
     switch ($this->m_sStyle) {
         case 'list':
             $oSet->Rewind();
             $param = $oSet;
             $iMenuId = iPopupMenuExtension::MENU_OBJLIST_ACTIONS;
             break;
         case 'details':
             $oSet->Rewind();
             $param = $oSet->Fetch();
             $iMenuId = iPopupMenuExtension::MENU_OBJDETAILS_ACTIONS;
             break;
     }
     utils::GetPopupMenuItems($oPage, $iMenuId, $param, $aActions);
     $aFavoriteActions = array();
     $aCallSpec = array($sClass, 'GetShortcutActions');
     if (is_callable($aCallSpec)) {
         $aShortcutActions = call_user_func($aCallSpec, $sClass);
         foreach ($aActions as $key => $aAction) {
             if (in_array($key, $aShortcutActions)) {
                 $aFavoriteActions[] = $aAction;
                 unset($aActions[$key]);
             }
         }
     } else {
         $aShortcutActions = array();
     }
     if (count($aFavoriteActions) > 0) {
         $sHtml .= "<div class=\"itop_popup actions_menu\"><ul>\n<li>" . Dict::S('UI:Menu:OtherActions') . "\n<ul>\n";
     } else {
         $sHtml .= "<div class=\"itop_popup actions_menu\"><ul>\n<li>" . Dict::S('UI:Menu:Actions') . "\n<ul>\n";
     }
     $sHtml .= $oPage->RenderPopupMenuItems($aActions, $aFavoriteActions);
     static $bPopupScript = false;
     if (!$bPopupScript) {
         // Output this once per page...
         $oPage->add_ready_script("\$(\"div.itop_popup>ul\").popupmenu();\n");
         $bPopupScript = true;
     }
     return $sHtml;
 }
Esempio n. 5
0
     $oFilter = DBObjectSearch::FromOQL('SELECT Organization');
     $sSelectionMode = utils::ReadParam('selectionMode', '');
     $aExceptions = utils::ReadParam('storedSelection', array());
     if ($sSelectionMode == 'negative' && count($aExceptions) == 0) {
         // All Orgs selected
         appUserPreferences::SetPref('favorite_orgs', null);
     } else {
         // Some organizations selected... store them
         $aSelectOrgs = utils::ReadMultipleSelection($oFilter);
         appUserPreferences::SetPref('favorite_orgs', $aSelectOrgs);
     }
     DisplayPreferences($oPage);
     break;
 case 'apply_language':
     $sLangCode = utils::ReadParam('language', 'EN US');
     $oUser = UserRights::GetUserObject();
     $oUser->Set('language', $sLangCode);
     $oUser->DBUpdate();
     // Redirect to force a reload/display of the page with the new language
     $oAppContext = new ApplicationContext();
     $sURL = utils::GetAbsoluteUrlAppRoot() . 'pages/preferences.php?' . $oAppContext->GetForLink();
     $oPage->add_header('Location: ' . $sURL);
     break;
 case 'apply_others':
     $iDefaultPageSize = (int) utils::ReadParam('default_page_size', -1);
     if ($iDefaultPageSize > 0) {
         appUserPreferences::SetPref('default_page_size', $iDefaultPageSize);
     }
     DisplayPreferences($oPage);
     break;
 case 'display':