GetForLink();
$oContentLayout->AddMainBlock(TitleUIBlockFactory::MakeForPage(Dict::S('UI:Preferences:Title')));
//////////////////////////////////////////////////////////////////////////
//
// User Language selection
//
//////////////////////////////////////////////////////////////////////////
$oUserLanguageBlock = new Panel(Dict::S('UI:FavoriteLanguage'), array(), 'grey', 'ibo-user-language-selection');
$oUserLanguageForm = GetUserLanguageForm($oAppContext, $sURL);
$oUserLanguageBlock->AddSubBlock($oUserLanguageForm);
$oContentLayout->AddMainBlock($oUserLanguageBlock);
//////////////////////////////////////////////////////////////////////////
//
// Other (miscellaneous) settings
//
//////////////////////////////////////////////////////////////////////////
$oMiscSettingsBlock = new Panel(Dict::S('UI:FavoriteOtherSettings'), array(), 'grey', 'ibo-misc-settings');
$oMiscSettingsStartForm = new Html('
');
$oMiscSettingsBlock->AddSubBlock($oMiscSettingsStartForm);
$oMiscSettingsBlock->AddSubBlock($oMiscSettingsHtml);
$oMiscSettingsBlock->AddSubBlock($oMiscSettingsButtonToolbar);
$oMiscSettingsBlock->AddSubBlock($oMiscSettingsEndHtmlBlock);
$oContentLayout->AddMainBlock($oMiscSettingsBlock);
$oP->add_script(
<< 0))
{
$('#v_default_page_size').html('');
$('#ibo-misc-settings-submit').prop('disabled', false);
return true;
}
else
{
$('#v_default_page_size').html('
');
$('#ibo-misc-settings-submit').prop('disabled', true);
return false;
}
}
JS
);
//////////////////////////////////////////////////////////////////////////
//
// Favorite Organizations
//
//////////////////////////////////////////////////////////////////////////
$oFavoriteOrganizationsBlock = new Panel(Dict::S('UI:FavoriteOrganizations'), array(), 'grey', 'ibo-favorite-organizations');
$oFavoriteOrganizationsBlock->AddHtml(Dict::S('UI:FavoriteOrganizations+'));
$oFavoriteOrganizationsForm = new Form();
$oFavoriteOrganizationsBlock->AddSubBlock($oFavoriteOrganizationsForm);
// Favorite organizations: the organizations listed in the drop-down menu
$sOQL = ApplicationMenu::GetFavoriteSiloQuery();
$oFilter = DBObjectSearch::FromOQL($sOQL);
$oBlock = new DisplayBlock($oFilter, 'list', false);
$aFavoriteOrgs = appUserPreferences::GetPref('favorite_orgs', null);
$sIdFavoriteOrganizations = 1;
$oFavoriteOrganizationsForm->AddSubBlock($oBlock->GetDisplay($oP, $sIdFavoriteOrganizations, [
'menu' => false,
'selection_mode' => true,
'selection_type' => 'multiple',
'table_id' => 'user_prefs',
'surround_with_panel' => false,
'selected_rows' => $aFavoriteOrgs
]));
$oFavoriteOrganizationsForm->AddSubBlock($oAppContext->GetForFormBlock());
// Button toolbar
$oFavoriteOrganizationsToolBar = ToolbarUIBlockFactory::MakeForButton(null, ['ibo-is-fullwidth']);
$oFavoriteOrganizationsForm->AddSubBlock($oFavoriteOrganizationsToolBar);
// - Cancel button
$oFavoriteOrganizationsCancelButton = ButtonUIBlockFactory::MakeForCancel(Dict::S('UI:Button:Cancel'));
$oFavoriteOrganizationsToolBar->AddSubBlock($oFavoriteOrganizationsCancelButton);
$oFavoriteOrganizationsCancelButton->SetOnClickJsCode("window.location.href = '$sURL'");
// - Submit button
$oFavoriteOrganizationsSubmitButton = ButtonUIBlockFactory::MakeForPrimaryAction(Dict::S('UI:Button:Apply'), 'operation', 'apply', true);
$oFavoriteOrganizationsToolBar->AddSubBlock($oFavoriteOrganizationsSubmitButton);
// TODO 3.0 have this code work again, currently it prevents the display of favorite organizations and shortcuts.
// if ($aFavoriteOrgs == null) {
// // All checked
// $oP->add_ready_script(
// <<AddMainBlock($oFavoriteOrganizationsBlock);
//////////////////////////////////////////////////////////////////////////
//
// Shortcuts
//
//////////////////////////////////////////////////////////////////////////
$oShortcutsBlock = new BlockShortcuts(Dict::S('Menu:MyShortcuts'), array(), 'grey', 'ibo-shortcuts');
$oShortcutsBlock->sIdShortcuts = 'shortcut_list';
$oShortcutsFilter = new DBObjectSearch('Shortcut');
$oShortcutsFilter->AddCondition('user_id', UserRights::GetUserId(), '=');
$oBlock = new DisplayBlock($oShortcutsFilter, 'list', false);
$oShortcutsBlock->AddSubBlock($oBlock->GetDisplay($oP, $oShortcutsBlock->sIdShortcuts, [
'view_link' => false,
'menu' => false,
'toolkit_menu' => false,
'selection_mode' => true,
'selection_type' => 'multiple',
'table_id' => 'user_prefs_shortcuts',
'surround_with_panel' => false,
]));
$oSet = new DBObjectSet($oShortcutsFilter);
if ($oSet->Count() > 0) {
$oShortcutsToolBar = ToolbarUIBlockFactory::MakeForButton();
$oShortcutsBlock->AddSubBlock($oShortcutsToolBar);
// - Rename button
$oShortcutsRenameButton = ButtonUIBlockFactory::MakeForSecondaryAction(Dict::S('UI:Button:Rename'), null, null, false,
"shortcut_btn_rename");
$oShortcutsToolBar->AddSubBlock($oShortcutsRenameButton);
// - Delete button
$oShortcutsDeleteButton = ButtonUIBlockFactory::MakeForSecondaryAction(Dict::S('UI:Button:Delete'), null, null, false,
"shortcut_btn_delete");
$oShortcutsToolBar->AddSubBlock($oShortcutsDeleteButton);
}
$oContentLayout->AddMainBlock($oShortcutsBlock);
//////////////////////////////////////////////////////////////////////////
//
// Newsroom
//
//////////////////////////////////////////////////////////////////////////
$iCountProviders = 0;
$oUser = UserRights::GetUserObject();
$aProviders = MetaModel::EnumPlugins('iNewsroomProvider');
foreach($aProviders as $oProvider)
{
if ($oProvider->IsApplicable($oUser))
{
$iCountProviders++;
}
}
$bNewsroomEnabled = (MetaModel::GetConfig()->Get('newsroom_enabled') !== false);
if ($bNewsroomEnabled && ($iCountProviders > 0))
{
$oNewsroomBlock = new Panel(Dict::S('UI:Newsroom:Preferences'), array(), 'grey', 'ibo-newsroom');
$sNewsroomHtml = '';
$sNewsroomHtml .= '';
$oNewsroomEndHtmlBlock = new Html($sNewsroomEndHtml);
$oNewsroomHtmlBlock = new Html($sNewsroomHtml);
$oNewsroomBlock->AddSubBlock($oNewsroomHtmlBlock);
$oNewsroomBlock->AddSubBlock($oNewsroomToolbar);
$oNewsroomBlock->AddSubBlock($oNewsroomEndHtmlBlock);
$oContentLayout->AddMainBlock($oNewsroomBlock);
}
//////////////////////////////////////////////////////////////////////////
//
// Rich text editor preferences
//
//////////////////////////////////////////////////////////////////////////
$oRichTextBlock = new Panel(Dict::S('UI:RichText:Preferences'), array(), 'grey', 'ibo-richtext');
$oRichTextForm = new Form();
$oRichTextForm->AddSubBlock(InputUIBlockFactory::MakeForHidden('operation', 'apply_richtext_config'));
$sRichTextToolbarDefaultState = isset(utils::GetCkeditorPref()['toolbarStartupExpanded']) ? (bool)utils::GetCkeditorPref()['toolbarStartupExpanded'] : false;
$oRichTextToolbarDefaultStateInput = InputUIBlockFactory::MakeForSelectWithLabel('toolbarexpanded', Dict::S('UI:RichText:ToolbarState'));
$oRichTextToolbarDefaultStateInput->GetInput()->AddOption(SelectOptionUIBlockFactory::MakeForSelectOption('true', Dict::S('UI:RichText:ToolbarState:Expanded'), $sRichTextToolbarDefaultState));
$oRichTextToolbarDefaultStateInput->GetInput()->AddOption(SelectOptionUIBlockFactory::MakeForSelectOption('false', Dict::S('UI:RichText:ToolbarState:Collapsed'), !$sRichTextToolbarDefaultState));
$oRichTextForm->AddSubBlock($oRichTextToolbarDefaultStateInput);
$oRichTextToolbar = ToolbarUIBlockFactory::MakeForButton();
$oRichTextForm->AddSubBlock($oRichTextToolbar);
// - Cancel button
$oRichTextCancelButton = ButtonUIBlockFactory::MakeForCancel(Dict::S('UI:Button:Cancel'));
$oRichTextCancelButton->SetOnClickJsCode("window.location.href = '$sURL'");
$oRichTextToolbar->AddSubBlock($oRichTextCancelButton);
// - Submit button
$oRichTextSubmitButton = ButtonUIBlockFactory::MakeForPrimaryAction(Dict::S('UI:Button:Apply'), null, null, true);
$oRichTextToolbar->AddSubBlock($oRichTextSubmitButton);
$oRichTextBlock->AddSubBlock($oRichTextForm);
$oContentLayout->AddMainBlock($oRichTextBlock);
//////////////////////////////////////////////////////////////////////////
//
// Tabs preferences
//
//////////////////////////////////////////////////////////////////////////
$oTabsBlock = new Panel(Dict::S('UI:Tabs:Preferences'), array(), 'grey', 'ibo-tabs');
$oTabsForm = new Form();
$oTabsForm->AddSubBlock(InputUIBlockFactory::MakeForHidden('operation', 'apply_tab_config'));
// Tab Layout
$sTabsLayoutValue = appUserPreferences::GetPref('tab_layout', false);;
$oTabsLayout = InputUIBlockFactory::MakeForSelectWithLabel('tab_layout', Dict::S('UI:Tabs:Layout:Label'));
$oTabsLayout->GetInput()->AddSubBlock(SelectOptionUIBlockFactory::MakeForSelectOption('horizontal', Dict::S('UI:Tabs:Layout:Horizontal'), 'horizontal' === $sTabsLayoutValue));
$oTabsLayout->GetInput()->AddSubBlock(SelectOptionUIBlockFactory::MakeForSelectOption('vertical', Dict::S('UI:Tabs:Layout:Vertical'), 'vertical' === $sTabsLayoutValue));
$oTabsForm->AddSubBlock($oTabsLayout);
// Tab navigation
$sTabsScrollableValue = appUserPreferences::GetPref('tab_scrollable', false);;
$oTabsScrollable = InputUIBlockFactory::MakeForSelectWithLabel('tab_scrollable', Dict::S('UI:Tabs:Scrollable:Label'));
$oTabsScrollable->GetInput()->AddSubBlock(SelectOptionUIBlockFactory::MakeForSelectOption('true', Dict::S('UI:Tabs:Scrollable:Scrollable'), true === $sTabsScrollableValue));
$oTabsScrollable->GetInput()->AddSubBlock(SelectOptionUIBlockFactory::MakeForSelectOption('false', Dict::S('UI:Tabs:Scrollable:Classic'), false === $sTabsScrollableValue));
$oTabsForm->AddSubBlock($oTabsScrollable);
$oTabsToolbar = ToolbarUIBlockFactory::MakeForButton();
$oTabsForm->AddSubBlock($oTabsToolbar);
// - Cancel button
$oTabsCancelButton = ButtonUIBlockFactory::MakeForCancel(Dict::S('UI:Button:Cancel'));
$oTabsCancelButton->SetOnClickJsCode("window.location.href = '$sURL'");
$oTabsToolbar->AddSubBlock($oTabsCancelButton);
// - Submit button
$oTabsSubmitButton = ButtonUIBlockFactory::MakeForPrimaryAction(Dict::S('UI:Button:Apply'), null, null, true);
$oTabsToolbar->AddSubBlock($oTabsSubmitButton);
$oTabsBlock->AddSubBlock($oTabsForm);
$oContentLayout->AddMainBlock($oTabsBlock);
//////////////////////////////////////////////////////////////////////////
//
// User picture placeholder
//
//////////////////////////////////////////////////////////////////////////
$oUserPicturePlaceHolderBlock = new Panel(Dict::S('UI:Preferences:ChooseAPlaceholder'), array(), 'grey', 'ibo-user-picture-placeholder');
$sUserPicturesFolder = '../images/user-pictures/';
$sUserDefaultPicture = appUserPreferences::GetPref('user_picture_placeholder', 'default-placeholder.png');
$sUserPicturePlaceHolderHtml = '';
$sUserPicturePlaceHolderHtml .= ''.Dict::S('UI:Preferences:ChooseAPlaceholder+').'
';
foreach (scandir($sUserPicturesFolder) as $sUserPicture)
{
if ($sUserPicture === '.' || $sUserPicture === '..')
{
continue;
}
$sAdditionalClass = '';
if ($sUserDefaultPicture === $sUserPicture)
{
$sAdditionalClass = ' ibo-is-active';
}
$sUserPicturePlaceHolderHtml .= '
';
}
$oP->add_ready_script(
<<
HTML
;
$oUserPicturePlaceHolderHtmlBlock = new Html($sUserPicturePlaceHolderHtml);
$oUserPicturePlaceHolderBlock->AddSubBlock($oUserPicturePlaceHolderHtmlBlock);
$oContentLayout->AddMainBlock($oUserPicturePlaceHolderBlock);
/** @var iPreferencesExtension $oLoginExtensionInstance */
foreach (MetaModel::EnumPlugins('iPreferencesExtension') as $oPreferencesExtensionInstance)
{
$oPreferencesExtensionInstance->DisplayPreferences($oP);
}
//////////////////////////////////////////////////////////////////////////
//
// Footer
//
$oP->add_ready_script("$('#fav_page_length').bind('keyup change', function(){ ValidateOtherSettings(); })");
$oP->SetContentLayout($oContentLayout);
}
/**
* @param \ApplicationContext $oAppContext
* @param string $sURL
*
* @return \Combodo\iTop\Application\UI\Base\Component\Form\Form
*/
function GetUserLanguageForm(ApplicationContext $oAppContext, string $sURL): Form
{
$oUserLanguageForm = new Form();
$oUserLanguageForm->AddSubBlock(InputUIBlockFactory::MakeForHidden('operation', 'apply_language'));
// Lang selector
$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);
$oUserLanguageBlockSelect = InputUIBlockFactory::MakeForSelectWithLabel('language', Dict::S('UI:Favorites:SelectYourLanguage'));
/** @var \Combodo\iTop\Application\UI\Base\Component\Input\Select $oUserLanguageBlockSelectInput */
$oUserLanguageBlockSelectInput = $oUserLanguageBlockSelect->GetInput();
foreach ($aSortedLang as $sCode) {
$bSelected = ($sCode == Dict::GetUserLanguage());
$oUserLanguageBlockSelectInput->AddSubBlock(SelectOptionUIBlockFactory::MakeForSelectOption($sCode, $aLanguages[$sCode]['description'].' ('.$aLanguages[$sCode]['localized_description'].')', $bSelected));
}
$oUserLanguageForm->AddSubBlock($oUserLanguageBlockSelect);
$oUserLanguageForm->AddSubBlock($oAppContext->GetForFormBlock());
$oUserLanguageButtonToolbar = ToolbarUIBlockFactory::MakeForButton();
$oUserLanguageForm->AddSubBlock($oUserLanguageButtonToolbar);
// - Cancel button
$oUserLanguageCancelButton = ButtonUIBlockFactory::MakeForCancel(Dict::S('UI:Button:Cancel'));
$oUserLanguageCancelButton->SetOnClickJsCode("window.location.href = '$sURL'");
$oUserLanguageButtonToolbar->AddSubBlock($oUserLanguageCancelButton);
// - Submit button
$oUserLanguageSubmitButton = ButtonUIBlockFactory::MakeForPrimaryAction(Dict::S('UI:Button:Apply'), null, null, true);
$oUserLanguageButtonToolbar->AddSubBlock($oUserLanguageSubmitButton);
return $oUserLanguageForm;
}
/////////////////////////////////////////////////////////////////////////////
//
// 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'));
$oPage->DisableBreadCrumb();
$sOperation = utils::ReadParam('operation', '');
try {
$bOperationUsed = false;
/** @var iPreferencesExtension $oLoginExtensionInstance */
foreach (MetaModel::EnumPlugins('iPreferencesExtension') as $oPreferencesExtensionInstance) {
if ($oPreferencesExtensionInstance->ApplyPreferences($oPage, $sOperation)) {
$bOperationUsed = true;
break;
}
}
if (!$bOperationUsed) {
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_richtext_config':
$aRichTextConfig = json_decode(appUserPreferences::GetPref('richtext_config', '{}'), true);
$bToolbarExpanded = utils::ReadParam('toolbarexpanded', 'false') === 'true';
$aRichTextConfig['toolbarStartupExpanded'] = $bToolbarExpanded;
appUserPreferences::SetPref('richtext_config', json_encode($aRichTextConfig));
DisplayPreferences($oPage);
break;
case 'apply_tab_config':
$sLayout = utils::ReadParam('tab_layout', 'horizontal');
$sLayoutAllowedValues = ['horizontal', 'vertical'];
if(in_array($sLayout, $sLayoutAllowedValues, true))
{
appUserPreferences::SetPref('tab_layout', $sLayout);
}
$bScrollable = utils::ReadParam('tab_scrollable', 'false') === 'true';
appUserPreferences::SetPref('tab_scrollable', $bScrollable);
DisplayPreferences($oPage);
break;
case 'apply_language':
$sLangCode = utils::ReadParam('language', 'EN US');
$oUser = UserRights::GetUserObject();
$oUser->Set('language', $sLangCode);
utils::PushArchiveMode(false);
$oUser->AllowWrite(true);
$oUser->DBUpdate();
utils::PopArchiveMode();
// 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);
}
$bShowObsoleteData = (bool)utils::ReadParam('show_obsolete_data', 0);
appUserPreferences::SetPref('show_obsolete_data', $bShowObsoleteData);
DisplayPreferences($oPage);
break;
case 'apply_newsroom_preferences':
$iCountProviders = 0;
$oUser = UserRights::GetUserObject();
$aProviders = MetaModel::EnumPlugins('iNewsroomProvider');
foreach ($aProviders as $oProvider)
{
if ($oProvider->IsApplicable($oUser))
{
$iCountProviders++;
}
}
$bNewsroomEnabled = (MetaModel::GetConfig()->Get('newsroom_enabled') !== false);
if ($bNewsroomEnabled && ($iCountProviders > 0))
{
$iNewsroomDisplaySize = (int)utils::ReadParam('newsroom_display_size', 7);
if ($iNewsroomDisplaySize < 1)
{
$iNewsroomDisplaySize = 1;
}
if ($iNewsroomDisplaySize > 20)
{
$iNewsroomDisplaySize = 20;
}
$iCurrentDisplaySize = (int)appUserPreferences::GetPref('newsroom_display_size', $iNewsroomDisplaySize);
if ($iCurrentDisplaySize != $iNewsroomDisplaySize)
{
// Save the preference only if it differs from the current (or default) value
appUserPreferences::SetPref('newsroom_display_size', $iNewsroomDisplaySize);
}
}
$bProvidersModified = false;
foreach ($aProviders as $oProvider)
{
if ($oProvider->IsApplicable($oUser))
{
$sProviderClass = get_class($oProvider);
$bProviderEnabled = (utils::ReadParam('newsroom_provider_'.$sProviderClass, 'off') == 'on');
$bCurrentValue = appUserPreferences::GetPref('newsroom_provider_'.$sProviderClass, true);
if ($bCurrentValue != $bProviderEnabled)
{
// Save the preference only if it differs from the current value
$bProvidersModified = true;
appUserPreferences::SetPref('newsroom_provider_'.$sProviderClass, $bProviderEnabled);
}
}
}
if ($bProvidersModified)
{
$oPage->add_ready_script('$(".itop-newsroom_menu").newsroom_menu("clearCache");');
}
DisplayPreferences($oPage);
break;
case 'display':
default:
$oPage->SetBreadCrumbEntry('ui-tool-preferences', Dict::S('UI:Preferences'), Dict::S('UI:Preferences'), '',
'fas fa-user-cog', iTopWebPage::ENUM_BREADCRUMB_ENTRY_ICON_TYPE_CSS_CLASSES);
DisplayPreferences($oPage);
}
}
$oPage->output();
}
catch(CoreException $e)
{
require_once(APPROOT.'/setup/setuppage.class.inc.php');
$oP = new ErrorPage(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 ErrorPage(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());
}
}