6 * Displays all optinos about display preferences
8 * @copyright © 1999-2007 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);
20 if (! isset($use_iframe)) $use_iframe=false;
23 * This function builds an array with all the information about
24 * the options available to the user, and returns it. The options
25 * are grouped by the groups in which they are displayed.
26 * For each option, the following information is stored:
27 * - name: the internal (variable) name
28 * - caption: the description of the option in the UI
29 * - type: one of SMOPT_TYPE_*
30 * - refresh: one of SMOPT_REFRESH_*
31 * - size: one of SMOPT_SIZE_*
32 * - save: the name of a function to call when saving this option
33 * @return array all option information
35 function load_optpage_data_display() {
36 global $theme, $fontsets, $language, $languages,$aTemplateSet,
37 $default_use_mdn, $squirrelmail_language, $allow_thread_sort,
38 $show_alternative_names, $use_iframe, $use_icons,
39 $sTemplateID, $oTemplate,
40 $user_themes, $chosen_theme;
42 /* Build a simple array into which we will build options. */
46 /******************************************************/
47 /* LOAD EACH GROUP OF OPTIONS INTO THE OPTIONS ARRAY. */
48 /******************************************************/
50 /*** Load the General Options into the array ***/
51 $optgrps[SMOPT_GRP_GENERAL
] = _("General Display Options");
52 $optvals[SMOPT_GRP_GENERAL
] = array();
54 /* load the template set option */
55 $templateset_values = array();
57 foreach ($aTemplateSet as $sKey => $aTemplateSetAttributes) {
58 $templateset_values[$aTemplateSetAttributes['NAME']] = $aTemplateSetAttributes['ID'];
60 ksort($templateset_values);
61 $templateset_values = array_flip($templateset_values);
62 // display template options only when there is more than one template
63 if (count($templateset_values)>1) {
64 $optvals[SMOPT_GRP_GENERAL
][] = array(
65 'name' => 'sTemplateID',
66 'caption' => _("Skin"),
67 'type' => SMOPT_TYPE_STRLIST
,
68 'refresh' => SMOPT_REFRESH_ALL
,
69 'posvals' => $templateset_values,
70 'save' => 'save_option_template'
74 /* Load the theme option. */
75 $theme_values = array();
77 // Always provide the template default first.
78 $theme_values['none'] = 'Template Default Theme';
80 // List alternate themes provided by templates first
81 $template_themes = $oTemplate->get_alternative_stylesheets(true);
82 asort($template_themes);
83 foreach ($template_themes as $sheet=>$name) {
84 $theme_values[$sheet] = 'Template Theme - '.htmlspecialchars($name);
86 // Next, list user-provided styles
88 foreach ($user_themes as $style) {
89 if ($style['PATH'] == 'none')
91 $theme_values[$style['PATH']] = 'User Theme - '.htmlspecialchars($style['NAME']);
94 if (count($user_themes) +
count($template_themes) > 1) {
95 $optvals[SMOPT_GRP_GENERAL
][] = array(
96 'name' => 'chosen_theme',
97 'caption' => _("Theme"),
98 'type' => SMOPT_TYPE_STRLIST
,
99 'refresh' => SMOPT_REFRESH_ALL
,
100 'posvals' => $theme_values,
101 'save' => 'css_theme_save'
105 /* Icon theme selection */
107 global $icon_themes, $icon_theme;
111 for ($count = 0; $count < sizeof($icon_themes); $count++
) {
112 $temp[$icon_themes[$count]['PATH']] = $icon_themes[$count]['NAME'];
114 if (sizeof($icon_themes) > 0) {
115 $optvals[SMOPT_GRP_GENERAL
][] = array(
116 'name' => 'icon_theme',
117 'caption' => _("Icon Theme"),
118 'type' => SMOPT_TYPE_STRLIST
,
119 'refresh' => SMOPT_REFRESH_NONE
,
121 'save' => 'icon_theme_save'
126 $fontset_values = array();
127 $fontset_list = array();
129 if (!empty($fontsets) && is_array($fontsets)) {
131 foreach (array_keys($fontsets) as $fontset_key) {
132 $fontset_list[$fontset_key]=$fontset_key;
134 ksort($fontset_list);
137 if (count($fontset_list) > 1) {
138 $fontset_list = array_merge(array('' => _("Default font style")), $fontset_list);
139 $optvals[SMOPT_GRP_GENERAL
][] = array(
140 'name' => 'chosen_fontset',
141 'caption' => _("Font style"),
142 'type' => SMOPT_TYPE_STRLIST
,
143 'refresh' => SMOPT_REFRESH_ALL
,
144 'posvals' => $fontset_list
148 $optvals[SMOPT_GRP_GENERAL
][] = array(
149 'name' => 'chosen_fontsize',
150 'caption' => _("Font size"),
151 'type' => SMOPT_TYPE_STRLIST
,
152 'refresh' => SMOPT_REFRESH_ALL
,
153 'posvals' => array('' => _("Default font size"),
160 $language_values = array();
161 foreach ($languages as $lang_key => $lang_attributes) {
162 if (isset($lang_attributes['NAME'])) {
163 $language_values[$lang_key] = $lang_attributes['NAME'];
164 if ( isset($show_alternative_names) &&
165 $show_alternative_names &&
166 isset($lang_attributes['ALTNAME']) ) {
167 $language_values[$lang_key] .= " / " . $lang_attributes['ALTNAME'];
172 asort($language_values);
174 array_merge(array('' => _("Default")), $language_values);
175 $language = $squirrelmail_language;
177 // add language selection only when more than 2 languages are available
178 // (default, English and some other)
179 if (count($language_values)>2) {
180 $optvals[SMOPT_GRP_GENERAL
][] = array(
181 'name' => 'language',
182 'caption' => _("Language"),
183 'type' => SMOPT_TYPE_STRLIST
,
184 'refresh' => SMOPT_REFRESH_ALL
,
185 'posvals' => $language_values,
186 'htmlencoded' => true
190 /* Set values for the "use javascript" option. */
191 $optvals[SMOPT_GRP_GENERAL
][] = array(
192 'name' => 'javascript_setting',
193 'caption' => _("Use Javascript"),
194 'type' => SMOPT_TYPE_STRLIST
,
195 'refresh' => SMOPT_REFRESH_ALL
,
196 'posvals' => array(SMPREF_JS_AUTODETECT
=> _("Autodetect"),
197 SMPREF_JS_ON
=> _("Always"),
198 SMPREF_JS_OFF
=> _("Never")),
199 'save' => 'save_option_javascript_autodetect',
200 'extra_attributes' => array('onclick' => 'document.forms[0].new_js_autodetect_results.value = \'' . SMPREF_JS_ON
. '\';'),
203 $optvals[SMOPT_GRP_GENERAL
][] = array(
204 'name' => 'js_autodetect_results',
206 'type' => SMOPT_TYPE_HIDDEN
,
207 'refresh' => SMOPT_REFRESH_NONE
208 //'post_script' => $js_autodetect_script,
211 $optvals[SMOPT_GRP_GENERAL
][] = array(
212 'name' => 'hour_format',
213 'caption' => _("Hour Format"),
214 'type' => SMOPT_TYPE_STRLIST
,
215 'refresh' => SMOPT_REFRESH_FOLDERLIST
,
216 'posvals' => array(SMPREF_TIME_12HR
=> _("12-hour clock"),
217 SMPREF_TIME_24HR
=> _("24-hour clock"))
220 /*** Load the General Options into the array ***/
221 $optgrps[SMOPT_GRP_MAILBOX
] = _("Mailbox Display Options");
222 $optvals[SMOPT_GRP_MAILBOX
] = array();
224 $optvals[SMOPT_GRP_MAILBOX
][] = array(
225 'name' => 'show_num',
226 'caption' => _("Number of Messages per Page"),
227 'type' => SMOPT_TYPE_INTEGER
,
228 'refresh' => SMOPT_REFRESH_NONE
,
229 'size' => SMOPT_SIZE_TINY
232 $optvals[SMOPT_GRP_MAILBOX
][] = array(
233 'name' => 'alt_index_colors',
234 'caption' => _("Enable Alternating Row Colors"),
235 'type' => SMOPT_TYPE_BOOLEAN
,
236 'refresh' => SMOPT_REFRESH_NONE
239 $optvals[SMOPT_GRP_MAILBOX
][] = array(
240 'name' => 'fancy_index_highlite',
241 'caption' => _("Enable Fancy Row Mouseover Highlighting"),
242 'type' => SMOPT_TYPE_BOOLEAN
,
243 'refresh' => SMOPT_REFRESH_NONE
246 $optvals[SMOPT_GRP_MAILBOX
][] = array(
247 'name' => 'show_flag_buttons',
248 'caption' => _("Show Flag / Unflag Buttons"),
249 'type' => SMOPT_TYPE_BOOLEAN
,
250 'refresh' => SMOPT_REFRESH_NONE
253 $optvals[SMOPT_GRP_MAILBOX
][] = array(
254 'name' => 'show_copy_buttons',
255 'caption' => _("Enable Message Copy Buttons"),
256 'type' => SMOPT_TYPE_BOOLEAN
,
257 'refresh' => SMOPT_REFRESH_NONE
260 $optvals[SMOPT_GRP_MAILBOX
][] = array(
261 'name' => 'page_selector',
262 'caption' => _("Enable Page Selector"),
263 'type' => SMOPT_TYPE_BOOLEAN
,
264 'refresh' => SMOPT_REFRESH_NONE
267 $optvals[SMOPT_GRP_MAILBOX
][] = array(
268 'name' => 'compact_paginator',
269 'caption' => _("Use Compact Page Selector"),
270 'type' => SMOPT_TYPE_BOOLEAN
,
271 'refresh' => SMOPT_REFRESH_NONE
274 $optvals[SMOPT_GRP_MAILBOX
][] = array(
275 'name' => 'page_selector_max',
276 'caption' => _("Maximum Number of Pages to Show"),
277 'type' => SMOPT_TYPE_INTEGER
,
278 'refresh' => SMOPT_REFRESH_NONE
,
279 'size' => SMOPT_SIZE_TINY
282 $optvals[SMOPT_GRP_MAILBOX
][] = array(
283 'name' => 'show_full_date',
284 'caption' => _("Always Show Full Date"),
285 'type' => SMOPT_TYPE_BOOLEAN
,
286 'refresh' => SMOPT_REFRESH_NONE
289 $optvals[SMOPT_GRP_MAILBOX
][] = array(
290 'name' => 'truncate_sender',
291 'caption' => _("Length of From/To Field (0 for full)"),
292 'type' => SMOPT_TYPE_INTEGER
,
293 'refresh' => SMOPT_REFRESH_NONE
,
294 'size' => SMOPT_SIZE_TINY
297 $optvals[SMOPT_GRP_MAILBOX
][] = array(
298 'name' => 'truncate_subject',
299 'caption' => _("Length of Subject Field (0 for full)"),
300 'type' => SMOPT_TYPE_INTEGER
,
301 'refresh' => SMOPT_REFRESH_NONE
,
302 'size' => SMOPT_SIZE_TINY
306 disabled because the template doesn't support it (yet?)
307 $optvals[SMOPT_GRP_MAILBOX][] = array(
308 'name' => 'show_recipient_instead',
309 'caption' => _("Show recipient name if the message is from your default identity"),
310 'type' => SMOPT_TYPE_BOOLEAN,
311 'refresh' => SMOPT_REFRESH_NONE,
312 'size' => SMOPT_SIZE_TINY
316 if ($allow_thread_sort == TRUE) {
317 $optvals[SMOPT_GRP_MAILBOX
][] = array(
318 'name' => 'sort_by_ref',
319 'caption' => _("Enable Thread Sort by References Header"),
320 'type' => SMOPT_TYPE_BOOLEAN
,
321 'refresh' => SMOPT_REFRESH_ALL
327 /*** Load the General Options into the array ***/
328 $optgrps[SMOPT_GRP_MESSAGE
] = _("Message Display Options");
329 $optvals[SMOPT_GRP_MESSAGE
] = array();
331 $optvals[SMOPT_GRP_MESSAGE
][] = array(
333 'caption' => _("Wrap Incoming Text At"),
334 'type' => SMOPT_TYPE_INTEGER
,
335 'refresh' => SMOPT_REFRESH_NONE
,
336 'size' => SMOPT_SIZE_TINY
339 $optvals[SMOPT_GRP_MESSAGE
][] = array(
340 'name' => 'show_html_default',
341 'caption' => _("Show HTML Version by Default"),
342 'type' => SMOPT_TYPE_BOOLEAN
,
343 'refresh' => SMOPT_REFRESH_NONE
347 // Type is set to string in order to be able to use 100%.
348 $optvals[SMOPT_GRP_MESSAGE
][] = array(
349 'name' => 'iframe_height',
350 'caption' => _("Height of inline frame"),
351 'type' => SMOPT_TYPE_STRING
,
352 'size' => SMOPT_SIZE_TINY
,
353 'refresh' => SMOPT_REFRESH_NONE
356 $optvals[SMOPT_GRP_MESSAGE
][] = array(
357 'name' => 'enable_forward_as_attachment',
358 'caption' => _("Enable Forward as Attachment"),
359 'type' => SMOPT_TYPE_BOOLEAN
,
360 'refresh' => SMOPT_REFRESH_NONE
363 $optvals[SMOPT_GRP_MESSAGE
][] = array(
364 'name' => 'show_xmailer_default',
365 'caption' => _("Enable Mailer Display"),
366 'type' => SMOPT_TYPE_BOOLEAN
,
367 'refresh' => SMOPT_REFRESH_NONE
370 $optvals[SMOPT_GRP_MESSAGE
][] = array(
371 'name' => 'attachment_common_show_images',
372 'caption' => _("Display Attached Images with Message"),
373 'type' => SMOPT_TYPE_BOOLEAN
,
374 'refresh' => SMOPT_REFRESH_NONE
377 if ($default_use_mdn) {
378 $optvals[SMOPT_GRP_MESSAGE
][] = array(
379 'name' => 'mdn_user_support',
380 'caption' => _("Enable Mail Delivery Notification"),
381 'type' => SMOPT_TYPE_BOOLEAN
,
382 'refresh' => SMOPT_REFRESH_NONE
386 $optvals[SMOPT_GRP_MESSAGE
][] = array(
387 'name' => 'delete_prev_next_display',
388 'caption' => _("Show 'Delete & Prev/Next' Links"),
389 'type' => SMOPT_TYPE_BOOLEAN
,
390 'refresh' => SMOPT_REFRESH_ALL
393 /* Assemble all this together and return it as our result. */
401 /******************************************************************/
402 /** Define any specialized save functions for this option page. ***/
403 /******************************************************************/
406 * This function saves a new template setting.
407 * It updates the template array.
409 function save_option_template($option) {
410 global $aTemplateSet;
412 /* Do checking to make sure new template is in the available templates array. */
413 $templateset_in_array = false;
414 for ($i = 0; $i < count($aTemplateSet); ++
$i) {
415 if ($aTemplateSet[$i]['ID'] == $option->new_value
) {
416 $templateset_in_array = true;
421 if (!$templateset_in_array) {
422 $option->new_value
= '';
425 // clear template cache when changing template sets
426 // (in order to do so, we have to change the global
427 // template set ID now... should not be a problem --
428 // in fact, if we don't do it now, very anomalous
432 $sTemplateID = $option->new_value
;
433 Template
::cache_template_file_hierarchy(TRUE);
438 * TODO: If the template changes and we are using a template provided theme
439 * ($user_theme), do we want to reset $user_theme?
441 /* Save the option like normal. */
442 save_option($option);
446 * This function saves the javascript detection option.
448 function save_option_javascript_autodetect($option) {
449 save_option($option);
450 checkForJavascript(TRUE);
454 * This function saves the user's icon theme setting
456 function icon_theme_save($option) {
460 // Don't assume the new value is there, double check
461 // and only save if found
463 while (!$found && (list($index, $data) = each($icon_themes))) {
464 if ($data['PATH'] == $option->new_value
)
469 $option->new_value
= 'none';
471 save_option($option);
474 function css_theme_save ($option) {
475 global $user_themes, $oTemplate;
477 // Don't assume the new value is there, double check
478 // and only save if found
481 while (!$found && (list($index, $data) = each($user_themes))) {
482 if ($data['PATH'] == $option->new_value
)
487 $template_themes = $oTemplate->get_alternative_stylesheets(true);
488 while (!$found && (list($path, $name) = each($template_themes))) {
489 if ($path == $option->new_value
)
495 $option->new_value
= 'none';
497 save_option($option);