6 * Displays all optinos about display preferences
8 * @copyright © 1999-2006 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 * Icon themes and user CSS themes should probably both be moved to conf.pl
22 * TODO: move to conf.pl
24 // load icon themes if in use
28 $dirName = SM_PATH
. 'images/themes';
29 if (is_readable($dirName) && is_dir($dirName)) {
31 while($dir = $d->read()) {
32 if ($dir != "." && $dir != "..") {
33 if (is_dir($dirName."/".$dir) && file_exists("$dirName/$dir/theme.php"))
34 include("$dirName/$dir/theme.php");
41 if (! isset($use_iframe)) $use_iframe=false;
44 * This function builds an array with all the information about
45 * the options available to the user, and returns it. The options
46 * are grouped by the groups in which they are displayed.
47 * For each option, the following information is stored:
48 * - name: the internal (variable) name
49 * - caption: the description of the option in the UI
50 * - type: one of SMOPT_TYPE_*
51 * - refresh: one of SMOPT_REFRESH_*
52 * - size: one of SMOPT_SIZE_*
53 * - save: the name of a function to call when saving this option
54 * @return array all option information
56 function load_optpage_data_display() {
57 global $theme, $fontsets, $language, $languages,$aTemplateSet,
58 $default_use_mdn, $squirrelmail_language, $allow_thread_sort,
59 $show_alternative_names, $use_icons, $use_iframe, $sTemplateID,
60 $oTemplate, $user_themes;
62 /* Build a simple array into which we will build options. */
66 /******************************************************/
67 /* LOAD EACH GROUP OF OPTIONS INTO THE OPTIONS ARRAY. */
68 /******************************************************/
70 /*** Load the General Options into the array ***/
71 $optgrps[SMOPT_GRP_GENERAL
] = _("General Display Options");
72 $optvals[SMOPT_GRP_GENERAL
] = array();
74 /* load the template set option */
75 $templateset_values = array();
77 foreach ($aTemplateSet as $sKey => $aTemplateSetAttributes) {
78 $templateset_values[$aTemplateSetAttributes['NAME']] = $aTemplateSetAttributes['ID'];
80 ksort($templateset_values);
81 $templateset_values = array_flip($templateset_values);
82 // display template options only when there is more than one template
83 if (count($templateset_values)>1) {
84 $optvals[SMOPT_GRP_GENERAL
][] = array(
85 'name' => 'sTemplateID',
86 'caption' => _("Skin"),
87 'type' => SMOPT_TYPE_STRLIST
,
88 'refresh' => SMOPT_REFRESH_ALL
,
89 'posvals' => $templateset_values,
90 'save' => 'save_option_template'
94 /* Load the theme option. */
97 * User themes start with a 'u_', template themes start with a 't_' to
98 * differentiate which is which. This seems kind of hackish, but we can
99 * come up with a better solution later.
100 PL: No need for the prefixes. Just use full paths, no?
102 SB: Don't think so. If the user chooses a template theme than changes the
103 path to the template, it would error out, right? Or should we worry about
108 $theme_values = array();
110 // Always provide the template default first.
111 $theme_values['none'] = 'Template Default Theme';
113 // List alternate themes provided by templates first
114 $template_themes = array();
116 * Since this requires mods to the template class, I'm holding off on alternate
117 * template styles until Paul finishes template inheritence.
120 $template_themes = $oTemplate->get_alternative_stylesheets();
121 asort($template_provided);
122 foreach ($template_provided as $sheet=>$name) {
123 $theme_values['t_'.$sheet] = 'Template Theme - '.htmlspecialchars($name);
126 // Next, list styles provided in SM_PATH/css/
128 foreach ($user_themes as $style) {
129 if ($style['PATH'] == 'none')
131 $theme_values['u_'.$style['PATH']] = 'User Theme - '.htmlspecialchars($style['NAME']);
134 if (count($user_themes) +
count($template_themes) > 1) {
135 $optvals[SMOPT_GRP_GENERAL
][] = array(
136 'name' => 'chosen_theme',
137 'caption' => _("Theme"),
138 'type' => SMOPT_TYPE_STRLIST
,
139 'refresh' => SMOPT_REFRESH_ALL
,
140 'posvals' => $theme_values,
141 'save' => 'css_theme_save'
145 /* Icon theme selection */
147 global $icon_themes, $icon_theme;
151 for ($count = 0; $count < sizeof($icon_themes); $count++
) {
152 $temp[$icon_themes[$count]['PATH']] = $icon_themes[$count]['NAME'];
154 if (sizeof($icon_themes) > 0) {
155 $optvals[SMOPT_GRP_GENERAL
][] = array(
156 'name' => 'icon_theme',
157 'caption' => _("Icon Theme"),
158 'type' => SMOPT_TYPE_STRLIST
,
159 'refresh' => SMOPT_REFRESH_NONE
,
161 'save' => 'icon_theme_save'
166 $fontset_values = array();
167 $fontset_list = array();
169 if (!empty($fontsets) && is_array($fontsets)) {
171 foreach (array_keys($fontsets) as $fontset_key) {
172 $fontset_list[$fontset_key]=$fontset_key;
174 ksort($fontset_list);
177 if (count($fontset_list) > 1) {
178 $fontset_list = array_merge(array('' => _("Default font style")), $fontset_list);
179 $optvals[SMOPT_GRP_GENERAL
][] = array(
180 'name' => 'chosen_fontset',
181 'caption' => _("Font style"),
182 'type' => SMOPT_TYPE_STRLIST
,
183 'refresh' => SMOPT_REFRESH_ALL
,
184 'posvals' => $fontset_list
188 $optvals[SMOPT_GRP_GENERAL
][] = array(
189 'name' => 'chosen_fontsize',
190 'caption' => _("Font size"),
191 'type' => SMOPT_TYPE_STRLIST
,
192 'refresh' => SMOPT_REFRESH_ALL
,
193 'posvals' => array('' => _("Default font size"),
200 $language_values = array();
201 foreach ($languages as $lang_key => $lang_attributes) {
202 if (isset($lang_attributes['NAME'])) {
203 $language_values[$lang_key] = $lang_attributes['NAME'];
204 if ( isset($show_alternative_names) &&
205 $show_alternative_names &&
206 isset($lang_attributes['ALTNAME']) ) {
207 $language_values[$lang_key] .= " / " . $lang_attributes['ALTNAME'];
212 asort($language_values);
214 array_merge(array('' => _("Default")), $language_values);
215 $language = $squirrelmail_language;
217 // add language selection only when more than 2 languages are available
218 // (default, English and some other)
219 if (count($language_values)>2) {
220 $optvals[SMOPT_GRP_GENERAL
][] = array(
221 'name' => 'language',
222 'caption' => _("Language"),
223 'type' => SMOPT_TYPE_STRLIST
,
224 'refresh' => SMOPT_REFRESH_ALL
,
225 'posvals' => $language_values,
226 'htmlencoded' => true
230 /* Set values for the "use javascript" option. */
231 $optvals[SMOPT_GRP_GENERAL
][] = array(
232 'name' => 'javascript_setting',
233 'caption' => _("Use Javascript"),
234 'type' => SMOPT_TYPE_STRLIST
,
235 'refresh' => SMOPT_REFRESH_ALL
,
236 'posvals' => array(SMPREF_JS_AUTODETECT
=> _("Autodetect"),
237 SMPREF_JS_ON
=> _("Always"),
238 SMPREF_JS_OFF
=> _("Never")),
239 'save' => 'save_option_javascript_autodetect',
240 'script' => 'onclick="document.forms[0].new_js_autodetect_results.value = \'' . SMPREF_JS_ON
. '\';"'
243 $optvals[SMOPT_GRP_GENERAL
][] = array(
244 'name' => 'js_autodetect_results',
246 'type' => SMOPT_TYPE_HIDDEN
,
247 'refresh' => SMOPT_REFRESH_NONE
248 //'post_script' => $js_autodetect_script,
251 $optvals[SMOPT_GRP_GENERAL
][] = array(
252 'name' => 'hour_format',
253 'caption' => _("Hour Format"),
254 'type' => SMOPT_TYPE_STRLIST
,
255 'refresh' => SMOPT_REFRESH_FOLDERLIST
,
256 'posvals' => array(SMPREF_TIME_12HR
=> _("12-hour clock"),
257 SMPREF_TIME_24HR
=> _("24-hour clock"))
260 /*** Load the General Options into the array ***/
261 $optgrps[SMOPT_GRP_MAILBOX
] = _("Mailbox Display Options");
262 $optvals[SMOPT_GRP_MAILBOX
] = array();
264 $optvals[SMOPT_GRP_MAILBOX
][] = array(
265 'name' => 'show_num',
266 'caption' => _("Number of Messages per Page"),
267 'type' => SMOPT_TYPE_INTEGER
,
268 'refresh' => SMOPT_REFRESH_NONE
,
269 'size' => SMOPT_SIZE_TINY
272 $optvals[SMOPT_GRP_MAILBOX
][] = array(
273 'name' => 'alt_index_colors',
274 'caption' => _("Enable Alternating Row Colors"),
275 'type' => SMOPT_TYPE_BOOLEAN
,
276 'refresh' => SMOPT_REFRESH_NONE
279 $optvals[SMOPT_GRP_MAILBOX
][] = array(
280 'name' => 'fancy_index_highlite',
281 'caption' => _("Enable Fancy Row Mouseover Highlighting"),
282 'type' => SMOPT_TYPE_BOOLEAN
,
283 'refresh' => SMOPT_REFRESH_NONE
286 $optvals[SMOPT_GRP_MAILBOX
][] = array(
287 'name' => 'show_flag_buttons',
288 'caption' => _("Show Flag / Unflag Buttons"),
289 'type' => SMOPT_TYPE_BOOLEAN
,
290 'refresh' => SMOPT_REFRESH_NONE
293 $optvals[SMOPT_GRP_MAILBOX
][] = array(
294 'name' => 'show_copy_buttons',
295 'caption' => _("Enable Message Copy Buttons"),
296 'type' => SMOPT_TYPE_BOOLEAN
,
297 'refresh' => SMOPT_REFRESH_NONE
300 $optvals[SMOPT_GRP_MAILBOX
][] = array(
301 'name' => 'page_selector',
302 'caption' => _("Enable Page Selector"),
303 'type' => SMOPT_TYPE_BOOLEAN
,
304 'refresh' => SMOPT_REFRESH_NONE
307 $optvals[SMOPT_GRP_MAILBOX
][] = array(
308 'name' => 'compact_paginator',
309 'caption' => _("Use Compact Page Selector"),
310 'type' => SMOPT_TYPE_BOOLEAN
,
311 'refresh' => SMOPT_REFRESH_NONE
314 $optvals[SMOPT_GRP_MAILBOX
][] = array(
315 'name' => 'page_selector_max',
316 'caption' => _("Maximum Number of Pages to Show"),
317 'type' => SMOPT_TYPE_INTEGER
,
318 'refresh' => SMOPT_REFRESH_NONE
,
319 'size' => SMOPT_SIZE_TINY
322 $optvals[SMOPT_GRP_MAILBOX
][] = array(
323 'name' => 'show_full_date',
324 'caption' => _("Always Show Full Date"),
325 'type' => SMOPT_TYPE_BOOLEAN
,
326 'refresh' => SMOPT_REFRESH_NONE
329 $optvals[SMOPT_GRP_MAILBOX
][] = array(
330 'name' => 'truncate_sender',
331 'caption' => _("Length of From/To Field (0 for full)"),
332 'type' => SMOPT_TYPE_INTEGER
,
333 'refresh' => SMOPT_REFRESH_NONE
,
334 'size' => SMOPT_SIZE_TINY
337 $optvals[SMOPT_GRP_MAILBOX
][] = array(
338 'name' => 'truncate_subject',
339 'caption' => _("Length of Subject Field (0 for full)"),
340 'type' => SMOPT_TYPE_INTEGER
,
341 'refresh' => SMOPT_REFRESH_NONE
,
342 'size' => SMOPT_SIZE_TINY
346 disabled because the template doesn't support it (yet?)
347 $optvals[SMOPT_GRP_MAILBOX][] = array(
348 'name' => 'show_recipient_instead',
349 'caption' => _("Show recipient name if the message is from your default identity"),
350 'type' => SMOPT_TYPE_BOOLEAN,
351 'refresh' => SMOPT_REFRESH_NONE,
352 'size' => SMOPT_SIZE_TINY
356 if ($allow_thread_sort == TRUE) {
357 $optvals[SMOPT_GRP_MAILBOX
][] = array(
358 'name' => 'sort_by_ref',
359 'caption' => _("Enable Thread Sort by References Header"),
360 'type' => SMOPT_TYPE_BOOLEAN
,
361 'refresh' => SMOPT_REFRESH_ALL
367 /*** Load the General Options into the array ***/
368 $optgrps[SMOPT_GRP_MESSAGE
] = _("Message Display Options");
369 $optvals[SMOPT_GRP_MESSAGE
] = array();
371 $optvals[SMOPT_GRP_MESSAGE
][] = array(
373 'caption' => _("Wrap Incoming Text At"),
374 'type' => SMOPT_TYPE_INTEGER
,
375 'refresh' => SMOPT_REFRESH_NONE
,
376 'size' => SMOPT_SIZE_TINY
379 $optvals[SMOPT_GRP_MESSAGE
][] = array(
380 'name' => 'show_html_default',
381 'caption' => _("Show HTML Version by Default"),
382 'type' => SMOPT_TYPE_BOOLEAN
,
383 'refresh' => SMOPT_REFRESH_NONE
387 // Type is set to string in order to be able to use 100%.
388 $optvals[SMOPT_GRP_MESSAGE
][] = array(
389 'name' => 'iframe_height',
390 'caption' => _("Height of inline frame"),
391 'type' => SMOPT_TYPE_STRING
,
392 'size' => SMOPT_SIZE_TINY
,
393 'refresh' => SMOPT_REFRESH_NONE
396 $optvals[SMOPT_GRP_MESSAGE
][] = array(
397 'name' => 'enable_forward_as_attachment',
398 'caption' => _("Enable Forward as Attachment"),
399 'type' => SMOPT_TYPE_BOOLEAN
,
400 'refresh' => SMOPT_REFRESH_NONE
403 $optvals[SMOPT_GRP_MESSAGE
][] = array(
404 'name' => 'show_xmailer_default',
405 'caption' => _("Enable Mailer Display"),
406 'type' => SMOPT_TYPE_BOOLEAN
,
407 'refresh' => SMOPT_REFRESH_NONE
410 $optvals[SMOPT_GRP_MESSAGE
][] = array(
411 'name' => 'attachment_common_show_images',
412 'caption' => _("Display Attached Images with Message"),
413 'type' => SMOPT_TYPE_BOOLEAN
,
414 'refresh' => SMOPT_REFRESH_NONE
417 if ($default_use_mdn) {
418 $optvals[SMOPT_GRP_MESSAGE
][] = array(
419 'name' => 'mdn_user_support',
420 'caption' => _("Enable Mail Delivery Notification"),
421 'type' => SMOPT_TYPE_BOOLEAN
,
422 'refresh' => SMOPT_REFRESH_NONE
426 $optvals[SMOPT_GRP_MESSAGE
][] = array(
427 'name' => 'delete_prev_next_display',
428 'caption' => _("Show 'Delete & Prev/Next' Links"),
429 'type' => SMOPT_TYPE_BOOLEAN
,
430 'refresh' => SMOPT_REFRESH_ALL
433 /* Assemble all this together and return it as our result. */
441 /******************************************************************/
442 /** Define any specialized save functions for this option page. ***/
443 /******************************************************************/
446 * This function saves a new template setting.
447 * It updates the template array.
449 function save_option_template($option) {
450 global $aTemplateSet;
452 /* Do checking to make sure new template is in the available templates array. */
453 $templateset_in_array = false;
454 for ($i = 0; $i < count($aTemplateSet); ++
$i) {
455 if ($aTemplateSet[$i]['ID'] == $option->new_value
) {
456 $templateset_in_array = true;
461 if (!$templateset_in_array) {
462 $option->new_value
= '';
465 // clear template cache when changing template sets
466 // (in order to do so, we have to change the global
467 // template set ID now... should not be a problem --
468 // in fact, if we don't do it now, very anomalous
472 $sTemplateID = $option->new_value
;
473 Template
::cache_template_file_hierarchy(TRUE);
477 /* Save the option like normal. */
478 save_option($option);
482 * This function saves a new theme setting.
483 * It updates the theme array.
485 function save_option_theme($option) {
488 /* Do checking to make sure $new_theme is in the array. */
489 $theme_in_array = false;
490 for ($i = 0; $i < count($theme); ++
$i) {
491 if ($theme[$i]['PATH'] == $option->new_value
) {
492 $theme_in_array = true;
497 if (!$theme_in_array) {
498 $option->new_value
= '';
501 /* Save the option like normal. */
502 save_option($option);
506 * This function saves the javascript detection option.
508 function save_option_javascript_autodetect($option) {
509 save_option($option);
510 checkForJavascript(TRUE);
514 * This function saves the user's icon theme setting
516 function icon_theme_save($option) {
517 global $icon_themes, $data_dir, $username;
520 // Don't assume the new value is there, double check
521 // and only save if found
524 while (!$found && (list($index, $data) = each($icon_themes))) {
525 if ($data['PATH'] == $option->new_value
)
529 setPref($data_dir, $username, 'icon_theme', $option->new_value
);
531 setPref($data_dir, $username, 'icon_theme', 'none');
535 function css_theme_save ($option) {
536 global $user_themes, $data_dir, $username;
538 // Don't assume the new value is there, double check
539 // and only save if found
543 while (!$found && (list($index, $data) = each($user_themes))) {
544 if ('u_'.$data['PATH'] == $option->new_value
)
548 setPref($data_dir, $username, 'chosen_theme', $option->new_value
);
550 setPref($data_dir, $username, 'chosen_theme', 'none');