/** * User preferences page * Displays / edit some user preferences * * @copyright Copyright (C) 2010-2012 Combodo SARL * @license http://opensource.org/licenses/AGPL-3.0 */ require_once('../approot.inc.php'); require_once(APPROOT.'/application/application.inc.php'); require_once(APPROOT.'/application/itopwebpage.class.inc.php'); require_once(APPROOT.'/application/startup.inc.php'); /** * Displays the user's changeable preferences * @param $oP WebPage The web page used for the output */ function DisplayPreferences($oP) { $oAppContext = new ApplicationContext(); $sURL = utils::GetAbsoluteUrlAppRoot().'pages/UI.php?'.$oAppContext->GetForLink(); $oP->add('\n"); $oP->add('
'); ////////////////////////////////////////////////////////////////////////// // // User Language selection // ////////////////////////////////////////////////////////////////////////// $oP->add('
'.Dict::S('UI:FavoriteLanguage').''); $oP->add('
'); $aLanguages = Dict::GetLanguages(); $aSortedlang = array(); foreach($aLanguages as $sCode => $aLang) { if (MetaModel::GetConfig()->Get('demo_mode')) { if ($sCode != Dict::GetUserLanguage()) { // Demo mode: only the current user language is listed in the available choices continue; } } $aSortedlang[$aLang['description']] = $sCode; } ksort($aSortedlang); $oP->add('

'.Dict::S('UI:Favorites:SelectYourLanguage').'

'); $oP->add(''); $oP->add($oAppContext->GetForForm()); $oP->add('

'); $oP->add('  '); $oP->add('

'); $oP->add('
'); $oP->add('
'); ////////////////////////////////////////////////////////////////////////// // // Other (miscellaneous) settings // ////////////////////////////////////////////////////////////////////////// $oP->add('
'.Dict::S('UI:FavoriteOtherSettings').''); $oP->add('
'); $iDefaultPageSize = appUserPreferences::GetPref('default_page_size', MetaModel::GetConfig()->GetMinDisplayLimit()); $oP->add('

'.Dict::Format('UI:Favorites:Default_X_ItemsPerPage', '').'

'); $oP->add(''); $oP->add($oAppContext->GetForForm()); $oP->add('

'); $oP->add('  '); $oP->add('

'); $oP->add('
'); $oP->add('
'); $oP->add_script( << 0)) { $('#v_default_page_size').html(''); $('#other_submit').removeAttr('disabled'); return true; } else { $('#v_default_page_size').html(''); $('#other_submit').attr('disabled', 'disabled'); return false; } } EOF ); ////////////////////////////////////////////////////////////////////////// // // Favorite Organizations // ////////////////////////////////////////////////////////////////////////// $oP->add('
'.Dict::S('UI:FavoriteOrganizations').''); $oP->p(Dict::S('UI:FavoriteOrganizations+')); $oP->add('
'); // Favorite organizations: the organizations listed in the drop-down menu $sOQL = ApplicationMenu::GetFavoriteSiloQuery(); $oFilter = DBObjectSearch::FromOQL($sOQL); $oBlock = new DisplayBlock($oFilter, 'list', false); $oBlock->Display($oP, 1, array('menu' => false, 'selection_mode' => true, 'selection_type' => 'multiple', 'cssCount'=> '.selectedCount', 'table_id' => 'user_prefs')); $oP->add($oAppContext->GetForForm()); $oP->add(''); $oP->add('

'); $oP->add('  '); $oP->add('

'); $oP->add('
'); $oP->add('
'); $aFavoriteOrgs = appUserPreferences::GetPref('favorite_orgs', null); if ($aFavoriteOrgs == null) { // All checked $oP->add_ready_script( << 0) { // paginated display, restore the selection var pager = $('#user_prefs form .pager'); $(':input[name=selectionMode]', pager).val('negative'); $('#user_prefs table.listResults').trigger('load_selection'); } else { $('#user_prefs table.listResults').trigger('check_all'); } EOF ); } else { $sChecked = implode('","', $aFavoriteOrgs); $oP->add_ready_script( << 0) { // paginated display, restore the selection var pager = $('#user_prefs form .pager'); $(':input[name=selectionMode]', pager).val('positive'); for (i=0; i'); } $('#user_prefs table.listResults').trigger('load_selection'); } else { $('#user_prefs form :checkbox[name^=selectObject]').each( function() { if ($.inArray($(this).val(), aChecked) > -1) { $(this).attr('checked', true); $(this).trigger('change'); } }); } EOF ); } ////////////////////////////////////////////////////////////////////////// // // Shortcuts // ////////////////////////////////////////////////////////////////////////// $oP->add('
'.Dict::S('Menu:MyShortcuts').''); //$oP->p(Dict::S('UI:Menu:MyShortcuts+')); $oBMSearch = new DBObjectSearch('Shortcut'); $oBMSearch->AddCondition('user_id', UserRights::GetUserId(), '='); //$aExtraParams = array('menu' => false, 'toolkit_menu' => false, 'display_limit' => false, 'localize_values' => $bLocalize, 'zlist' => 'details'); $aExtraParams = array(); $oBlock = new DisplayBlock($oBMSearch, 'list', false, $aExtraParams); $oBlock->Display($oP, 'shortcut_list', array('view_link' => false, 'menu' => false, 'toolkit_menu' => false, 'selection_mode' => true, 'selection_type' => 'multiple', 'cssCount'=> '#shortcut_selection_count', 'table_id' => 'user_prefs_shortcuts')); $oP->add('

'); $oSet = new DBObjectSet($oBMSearch); if ($oSet->Count() > 0) { $sButtons = ''; $sButtons .= ' '; $sButtons .= ''; $sButtons .= ' '; $sButtons .= ''; // Selection count updated by the pager, and used to enable buttons $oP->add(''); $oP->add('

'); $sConfirmDelete = addslashes(Dict::S('UI:ShortcutDelete:Confirm')); $oP->add_ready_script( <<   $sButtons'); $('#shortcut_selection_count').bind('change', OnSelectionCountChange); $('#shortcut_btn_rename').bind('click', OnShortcutBtnRename); $('#shortcut_btn_delete').bind('click', OnShortcutBtnDelete); OnSelectionCountChange(); EOF ); } // if count > 0 ////////////////////////////////////////////////////////////////////////// // // Footer // $oP->add('
'); $oP->add_ready_script("$('#fav_page_length').bind('keyup change', function(){ ValidateOtherSettings(); })"); } ///////////////////////////////////////////////////////////////////////////// // // Main program // ///////////////////////////////////////////////////////////////////////////// require_once(APPROOT.'/application/loginwebpage.class.inc.php'); LoginWebPage::DoLogin(); // Check user rights and prompt if needed $iStep = utils::ReadParam('step', 1); $oPage = new iTopWebPage(Dict::S('UI:Preferences')); $sOperation = utils::ReadParam('operation', ''); try { switch($sOperation) { case 'apply': $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': default: DisplayPreferences($oPage); } $oPage->output(); } catch(CoreException $e) { require_once(APPROOT.'/setup/setuppage.class.inc.php'); $oP = new SetupPage(Dict::S('UI:PageTitle:FatalError')); $oP->add("

".Dict::S('UI:FatalErrorMessage')."

\n"); $oP->error(Dict::Format('UI:Error_Details', $e->getHtmlDesc())); $oP->output(); if (MetaModel::IsLogEnabledIssue()) { if (MetaModel::IsValidClass('EventIssue')) { $oLog = new EventIssue(); $oLog->Set('message', $e->getMessage()); $oLog->Set('userinfo', ''); $oLog->Set('issue', $e->GetIssue()); $oLog->Set('impact', 'Page could not be displayed'); $oLog->Set('callstack', $e->getTrace()); $oLog->Set('data', $e->getContextData()); $oLog->DBInsertNoReload(); } IssueLog::Error($e->getMessage()); } // For debugging only //throw $e; } catch(Exception $e) { require_once(APPROOT.'/setup/setuppage.class.inc.php'); $oP = new SetupPage(Dict::S('UI:PageTitle:FatalError')); $oP->add("

".Dict::S('UI:FatalErrorMessage')."

\n"); $oP->error(Dict::Format('UI:Error_Details', $e->getMessage())); $oP->output(); if (MetaModel::IsLogEnabledIssue()) { if (MetaModel::IsValidClass('EventIssue')) { $oLog = new EventIssue(); $oLog->Set('message', $e->getMessage()); $oLog->Set('userinfo', ''); $oLog->Set('issue', 'PHP Exception'); $oLog->Set('impact', 'Page could not be displayed'); $oLog->Set('callstack', $e->getTrace()); $oLog->Set('data', array()); $oLog->DBInsertNoReload(); } IssueLog::Error($e->getMessage()); } } ?>