6 * Displays all optinos about display preferences
8 * @copyright 1999-2020 The SquirrelMail Project Team
9 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
11 * @package squirrelmail
14 /** Define the group constants for the display options page. */
15 define('SMOPT_GRP_GENERAL', 0);
16 define('SMOPT_GRP_MAILBOX', 1);
17 define('SMOPT_GRP_MESSAGE', 2);
18 define('SMOPT_GRP_ABOOK', 3);
21 if (! isset($use_iframe)) $use_iframe=false;
24 * This function builds an array with all the information about
25 * the options available to the user, and returns it. The options
26 * are grouped by the groups in which they are displayed.
27 * For each option, the following information is stored:
28 * - name: the internal (variable) name
29 * - caption: the description of the option in the UI
30 * - type: one of SMOPT_TYPE_*
31 * - refresh: one of SMOPT_REFRESH_*
32 * - size: one of SMOPT_SIZE_*
33 * - save: the name of a function to call when saving this option
34 * @return array all option information
36 function load_optpage_data_display() {
37 global $theme, $fontsets, $language, $languages,$aTemplateSet,
38 $default_use_mdn, $squirrelmail_language, $allow_thread_sort,
39 $show_alternative_names, $use_iframe, $use_icons,
40 $sTemplateID, $oTemplate,
41 $user_themes, $chosen_theme;
43 /* Build a simple array into which we will build options. */
47 /******************************************************/
48 /* LOAD EACH GROUP OF OPTIONS INTO THE OPTIONS ARRAY. */
49 /******************************************************/
51 /*** Load the General Options into the array ***/
52 $optgrps[SMOPT_GRP_GENERAL
] = _("General Display Options");
53 $optvals[SMOPT_GRP_GENERAL
] = array();
55 /* load the template set option */
56 $templateset_values = array();
58 foreach ($aTemplateSet as $sKey => $aTemplateSetAttributes) {
59 $templateset_values[$aTemplateSetAttributes['NAME']] = $aTemplateSetAttributes['ID'];
61 ksort($templateset_values);
62 $templateset_values = array_flip($templateset_values);
63 // display template options only when there is more than one template
64 if (count($templateset_values)>1) {
65 $optvals[SMOPT_GRP_GENERAL
][] = array(
66 'name' => 'sTemplateID',
67 'caption' => _("Skin"),
68 'type' => SMOPT_TYPE_STRLIST
,
69 'refresh' => SMOPT_REFRESH_ALL
,
70 'posvals' => $templateset_values,
71 'save' => 'save_option_template'
75 /* Load the theme option. */
76 $theme_values = array();
78 // Always provide the template default first.
79 $theme_values['none'] = 'Template Default Theme';
81 // List alternate themes provided by templates first
82 $template_themes = $oTemplate->get_alternative_stylesheets(true);
83 asort($template_themes);
84 foreach ($template_themes as $sheet=>$name) {
85 $theme_values[$sheet] = 'Template Theme - '.sm_encode_html_special_chars($name);
87 // Next, list user-provided styles
89 foreach ($user_themes as $style) {
90 if ($style['PATH'] == 'none')
92 $theme_values[$style['PATH']] = 'User Theme - '.sm_encode_html_special_chars($style['NAME']);
95 if (count($user_themes) +
count($template_themes) > 1) {
96 $optvals[SMOPT_GRP_GENERAL
][] = array(
97 'name' => 'chosen_theme',
98 'caption' => _("Theme"),
99 'type' => SMOPT_TYPE_STRLIST
,
100 'refresh' => SMOPT_REFRESH_ALL
,
101 'posvals' => $theme_values,
102 'save' => 'css_theme_save'
106 /* Icon theme selection */
108 global $icon_themes, $icon_theme;
112 for ($count = 0; $count < sizeof($icon_themes); $count++
) {
113 $temp[$icon_themes[$count]['PATH']] = $icon_themes[$count]['NAME'];
115 if (sizeof($icon_themes) > 0) {
116 $optvals[SMOPT_GRP_GENERAL
][] = array(
117 'name' => 'icon_theme',
118 'caption' => _("Icon Theme"),
119 'type' => SMOPT_TYPE_STRLIST
,
120 'refresh' => SMOPT_REFRESH_NONE
,
122 'save' => 'icon_theme_save'
127 $fontset_values = array();
128 $fontset_list = array();
130 if (!empty($fontsets) && is_array($fontsets)) {
132 foreach (array_keys($fontsets) as $fontset_key) {
133 $fontset_list[$fontset_key]=$fontset_key;
135 ksort($fontset_list);
138 if (count($fontset_list) > 1) {
139 $fontset_list = array_merge(array('' => _("Default font style")), $fontset_list);
140 $optvals[SMOPT_GRP_GENERAL
][] = array(
141 'name' => 'chosen_fontset',
142 'caption' => _("Font style"),
143 'type' => SMOPT_TYPE_STRLIST
,
144 'refresh' => SMOPT_REFRESH_ALL
,
145 'posvals' => $fontset_list
149 $optvals[SMOPT_GRP_GENERAL
][] = array(
150 'name' => 'chosen_fontsize',
151 'caption' => _("Font size"),
152 'type' => SMOPT_TYPE_STRLIST
,
153 'refresh' => SMOPT_REFRESH_ALL
,
154 'posvals' => array('' => _("Default font size"),
161 $language_values = array();
162 foreach ($languages as $lang_key => $lang_attributes) {
163 if (isset($lang_attributes['NAME'])) {
164 $language_values[$lang_key] = $lang_attributes['NAME'];
165 if ( isset($show_alternative_names) &&
166 $show_alternative_names &&
167 isset($lang_attributes['ALTNAME']) ) {
168 $language_values[$lang_key] .= " / " . $lang_attributes['ALTNAME'];
173 asort($language_values);
175 array_merge(array('' => _("Default")), $language_values);
176 $language = $squirrelmail_language;
178 // add language selection only when more than 2 languages are available
179 // (default, English and some other)
180 if (count($language_values)>2) {
181 $optvals[SMOPT_GRP_GENERAL
][] = array(
182 'name' => 'language',
183 'caption' => _("Language"),
184 'type' => SMOPT_TYPE_STRLIST
,
185 'refresh' => SMOPT_REFRESH_ALL
,
186 'posvals' => $language_values,
187 'htmlencoded' => true
191 /* Set values for the "use javascript" option. */
192 $optvals[SMOPT_GRP_GENERAL
][] = array(
193 'name' => 'javascript_setting',
194 'caption' => _("Use Javascript"),
195 'type' => SMOPT_TYPE_STRLIST
,
196 'refresh' => SMOPT_REFRESH_ALL
,
197 'posvals' => array(SMPREF_JS_AUTODETECT
=> _("Autodetect"),
198 SMPREF_JS_ON
=> _("Always"),
199 SMPREF_JS_OFF
=> _("Never")),
200 'save' => 'save_option_javascript_autodetect',
201 'extra_attributes' => array('onclick' => 'document.option_form.new_js_autodetect_results.value = \'' . SMPREF_JS_ON
. '\';'),
204 $optvals[SMOPT_GRP_GENERAL
][] = array(
205 'name' => 'js_autodetect_results',
207 'type' => SMOPT_TYPE_HIDDEN
,
208 'refresh' => SMOPT_REFRESH_NONE
209 //'post_script' => $js_autodetect_script,
212 $optvals[SMOPT_GRP_GENERAL
][] = array(
213 'name' => 'hour_format',
214 'caption' => _("Hour Format"),
215 'type' => SMOPT_TYPE_STRLIST
,
216 'refresh' => SMOPT_REFRESH_FOLDERLIST
,
217 'posvals' => array(SMPREF_TIME_12HR
=> _("12-hour clock"),
218 SMPREF_TIME_24HR
=> _("24-hour clock"))
221 /*** Load the General Options into the array ***/
222 $optgrps[SMOPT_GRP_MAILBOX
] = _("Mailbox Display Options");
223 $optvals[SMOPT_GRP_MAILBOX
] = array();
225 $optvals[SMOPT_GRP_MAILBOX
][] = array(
226 'name' => 'show_num',
227 'caption' => _("Number of Messages per Page"),
228 'type' => SMOPT_TYPE_INTEGER
,
229 'refresh' => SMOPT_REFRESH_NONE
,
230 'size' => SMOPT_SIZE_TINY
233 $optvals[SMOPT_GRP_MAILBOX
][] = array(
234 'name' => 'alt_index_colors',
235 'caption' => _("Enable Alternating Row Colors"),
236 'type' => SMOPT_TYPE_BOOLEAN
,
237 'refresh' => SMOPT_REFRESH_NONE
240 $optvals[SMOPT_GRP_MAILBOX
][] = array(
241 'name' => 'fancy_index_highlite',
242 'caption' => _("Enable Fancy Row Mouseover Highlighting"),
243 'type' => SMOPT_TYPE_BOOLEAN
,
244 'refresh' => SMOPT_REFRESH_NONE
247 $optvals[SMOPT_GRP_MAILBOX
][] = array(
248 'name' => 'show_flag_buttons',
249 'caption' => _("Show Flag / Unflag Buttons"),
250 'type' => SMOPT_TYPE_BOOLEAN
,
251 'refresh' => SMOPT_REFRESH_NONE
254 $optvals[SMOPT_GRP_MAILBOX
][] = array(
255 'name' => 'show_copy_buttons',
256 'caption' => _("Enable Message Copy Buttons"),
257 'type' => SMOPT_TYPE_BOOLEAN
,
258 'refresh' => SMOPT_REFRESH_NONE
261 $optvals[SMOPT_GRP_MAILBOX
][] = array(
262 'name' => 'page_selector',
263 'caption' => _("Enable Page Selector"),
264 'type' => SMOPT_TYPE_BOOLEAN
,
265 'refresh' => SMOPT_REFRESH_NONE
268 $optvals[SMOPT_GRP_MAILBOX
][] = array(
269 'name' => 'compact_paginator',
270 'caption' => _("Use Compact Page Selector"),
271 'type' => SMOPT_TYPE_BOOLEAN
,
272 'refresh' => SMOPT_REFRESH_NONE
275 $optvals[SMOPT_GRP_MAILBOX
][] = array(
276 'name' => 'page_selector_max',
277 'caption' => _("Maximum Number of Pages to Show"),
278 'type' => SMOPT_TYPE_INTEGER
,
279 'refresh' => SMOPT_REFRESH_NONE
,
280 'size' => SMOPT_SIZE_TINY
283 $optvals[SMOPT_GRP_MAILBOX
][] = array(
284 'name' => 'show_personal_names',
285 'caption' => _("Show Names Instead of Email Addresses"),
286 'type' => SMOPT_TYPE_BOOLEAN
,
287 'refresh' => SMOPT_REFRESH_NONE
,
290 $optvals[SMOPT_GRP_MAILBOX
][] = array(
291 'name' => 'show_full_date',
292 'caption' => _("Always Show Full Date"),
293 'type' => SMOPT_TYPE_BOOLEAN
,
294 'refresh' => SMOPT_REFRESH_NONE
297 $optvals[SMOPT_GRP_MAILBOX
][] = array(
298 'name' => 'custom_date_format',
299 'caption' => _("Custom Date Format"),
300 //FIXME: need better wording here. users should be made aware that this is for advanced use. It might be nice to provide a list of the more common date format characters. It may be helpful to know that it overrides settings such as the one above show_full_date, and only if kept empty will the other date formats apply. For non-English users, it also may be helpful to know that the format is still passed through our own date_intl() function which translates things like the day of the week, month names and abbreviations, etc.
301 'trailing_text' => ' ' . _("(Uses format of PHP date() function)"),
302 'type' => SMOPT_TYPE_STRING
,
303 'refresh' => SMOPT_REFRESH_NONE
,
304 'size' => SMOPT_SIZE_TINY
,
307 $optvals[SMOPT_GRP_MAILBOX
][] = array(
308 'name' => 'truncate_sender',
309 'caption' => _("Length of From/To Field (0 for full)"),
310 'type' => SMOPT_TYPE_INTEGER
,
311 'refresh' => SMOPT_REFRESH_NONE
,
312 'size' => SMOPT_SIZE_TINY
315 $optvals[SMOPT_GRP_MAILBOX
][] = array(
316 'name' => 'truncate_subject',
317 'caption' => _("Length of Subject Field (0 for full)"),
318 'type' => SMOPT_TYPE_INTEGER
,
319 'refresh' => SMOPT_REFRESH_NONE
,
320 'size' => SMOPT_SIZE_TINY
324 disabled because the template doesn't support it (yet?)
325 $optvals[SMOPT_GRP_MAILBOX][] = array(
326 'name' => 'show_recipient_instead',
327 'caption' => _("Show recipient name if the message is from your default identity"),
328 'type' => SMOPT_TYPE_BOOLEAN,
329 'refresh' => SMOPT_REFRESH_NONE,
330 'size' => SMOPT_SIZE_TINY
334 if ($allow_thread_sort == TRUE) {
335 $optvals[SMOPT_GRP_MAILBOX
][] = array(
336 'name' => 'sort_by_ref',
337 'caption' => _("Enable Thread Sort by References Header"),
338 'type' => SMOPT_TYPE_BOOLEAN
,
339 'refresh' => SMOPT_REFRESH_ALL
345 /*** Load the General Options into the array ***/
346 $optgrps[SMOPT_GRP_MESSAGE
] = _("Message Display Options");
347 $optvals[SMOPT_GRP_MESSAGE
] = array();
349 $optvals[SMOPT_GRP_MESSAGE
][] = array(
351 'caption' => _("Wrap Incoming Text At"),
352 'type' => SMOPT_TYPE_INTEGER
,
353 'refresh' => SMOPT_REFRESH_NONE
,
354 'size' => SMOPT_SIZE_TINY
357 $optvals[SMOPT_GRP_MESSAGE
][] = array(
358 'name' => 'show_html_default',
359 'caption' => _("Show HTML Version by Default"),
360 'type' => SMOPT_TYPE_BOOLEAN
,
361 'refresh' => SMOPT_REFRESH_NONE
365 // Type is set to string in order to be able to use 100%.
366 $optvals[SMOPT_GRP_MESSAGE
][] = array(
367 'name' => 'iframe_height',
368 'caption' => _("Height of inline frame"),
369 'type' => SMOPT_TYPE_STRING
,
370 'size' => SMOPT_SIZE_TINY
,
371 'refresh' => SMOPT_REFRESH_NONE
374 $optvals[SMOPT_GRP_MESSAGE
][] = array(
375 'name' => 'enable_forward_as_attachment',
376 'caption' => _("Enable Forward as Attachment"),
377 'type' => SMOPT_TYPE_BOOLEAN
,
378 'refresh' => SMOPT_REFRESH_NONE
381 $optvals[SMOPT_GRP_MESSAGE
][] = array(
382 'name' => 'show_xmailer_default',
383 'caption' => _("Enable Mailer Display"),
384 'type' => SMOPT_TYPE_BOOLEAN
,
385 'refresh' => SMOPT_REFRESH_NONE
388 $optvals[SMOPT_GRP_MESSAGE
][] = array(
389 'name' => 'attachment_common_show_images',
390 'caption' => _("Display Attached Images with Message"),
391 'type' => SMOPT_TYPE_BOOLEAN
,
392 'refresh' => SMOPT_REFRESH_NONE
395 if ($default_use_mdn) {
396 $optvals[SMOPT_GRP_MESSAGE
][] = array(
397 'name' => 'mdn_user_support',
398 'caption' => _("Enable Mail Delivery Notification"),
399 'type' => SMOPT_TYPE_BOOLEAN
,
400 'refresh' => SMOPT_REFRESH_NONE
404 $optvals[SMOPT_GRP_MESSAGE
][] = array(
405 'name' => 'delete_prev_next_display',
406 'caption' => _("Show 'Delete & Prev/Next' Links"),
407 'type' => SMOPT_TYPE_BOOLEAN
,
408 'refresh' => SMOPT_REFRESH_ALL
411 $optvals[SMOPT_GRP_MESSAGE
][] = array(
412 'name' => 'return_to_message_list_after_move',
413 'caption' => _("Return To Message List After Move"),
414 'type' => SMOPT_TYPE_BOOLEAN
,
415 'refresh' => SMOPT_REFRESH_NONE
420 /*** Load the Address Book Options into the array ***/
421 $optgrps[SMOPT_GRP_ABOOK
] = _("Address Book Display Options");
422 $optvals[SMOPT_GRP_ABOOK
] = array();
424 $optvals[SMOPT_GRP_ABOOK
][] = array(
425 'name' => 'abook_show_num',
426 'caption' => _("Number of Addresses per Page"),
427 'type' => SMOPT_TYPE_INTEGER
,
428 'refresh' => SMOPT_REFRESH_NONE
,
429 'size' => SMOPT_SIZE_TINY
432 $optvals[SMOPT_GRP_ABOOK
][] = array(
433 'name' => 'abook_page_selector',
434 'caption' => _("Enable Page Selector"),
435 'type' => SMOPT_TYPE_BOOLEAN
,
436 'refresh' => SMOPT_REFRESH_NONE
439 $optvals[SMOPT_GRP_ABOOK
][] = array(
440 'name' => 'abook_compact_paginator',
441 'caption' => _("Use Compact Page Selector"),
442 'type' => SMOPT_TYPE_BOOLEAN
,
443 'refresh' => SMOPT_REFRESH_NONE
446 $optvals[SMOPT_GRP_ABOOK
][] = array(
447 'name' => 'abook_page_selector_max',
448 'caption' => _("Maximum Number of Pages to Show"),
449 'type' => SMOPT_TYPE_INTEGER
,
450 'refresh' => SMOPT_REFRESH_NONE
,
451 'size' => SMOPT_SIZE_TINY
456 /* Assemble all this together and return it as our result. */
464 /******************************************************************/
465 /** Define any specialized save functions for this option page. ***/
466 /******************************************************************/
469 * This function saves a new template setting.
470 * It updates the template array.
472 function save_option_template($option) {
473 global $aTemplateSet;
475 /* Do checking to make sure new template is in the available templates array. */
476 $templateset_in_array = false;
477 for ($i = 0; $i < count($aTemplateSet); ++
$i) {
478 if ($aTemplateSet[$i]['ID'] == $option->new_value
) {
479 $templateset_in_array = true;
484 if (!$templateset_in_array) {
485 $option->new_value
= '';
488 // clear template cache when changing template sets
489 // (in order to do so, we have to change the global
490 // template set ID now... should not be a problem --
491 // in fact, if we don't do it now, very anomalous
495 $sTemplateID = $option->new_value
;
496 Template
::cache_template_file_hierarchy($sTemplateID, TRUE);
501 * TODO: If the template changes and we are using a template provided theme
502 * ($user_theme), do we want to reset $user_theme?
504 /* Save the option like normal. */
505 save_option($option);
509 * This function saves the javascript detection option.
511 function save_option_javascript_autodetect($option) {
512 save_option($option);
513 checkForJavascript(TRUE);
517 * This function saves the user's icon theme setting
519 function icon_theme_save($option) {
523 // Don't assume the new value is there, double check
524 // and only save if found
526 foreach ($icon_themes as $data) {
527 if ($data['PATH'] == $option->new_value
) {
534 $option->new_value
= 'none';
536 save_option($option);
539 function css_theme_save ($option) {
540 global $user_themes, $oTemplate;
542 // Don't assume the new value is there, double check
543 // and only save if found
545 foreach ($user_themes as $data) {
546 if ($data['PATH'] == $option->new_value
) {
553 $template_themes = $oTemplate->get_alternative_stylesheets(true);
554 foreach ($template_themes as $path => $name) {
555 if ($path == $option->new_value
) {
563 $option->new_value
= 'none';
565 save_option($option);