Add support for user-provided alternate stylesheets
[squirrelmail.git] / include / options / display.php
1 <?php
2
3 /**
4 * options_display.php
5 *
6 * Displays all optinos about display preferences
7 *
8 * @copyright &copy; 1999-2006 The SquirrelMail Project Team
9 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
10 * @version $Id$
11 * @package squirrelmail
12 */
13
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
19 /**
20 * Icon themes and user CSS themes should probably both be moved to conf.pl
21 *
22 * TODO: move to conf.pl
23 **/
24 // load icon themes if in use
25 global $use_icons;
26 if ($use_icons) {
27 global $icon_themes;
28 $dirName = SM_PATH . 'images/themes';
29 if (is_readable($dirName) && is_dir($dirName)) {
30 $d = 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");
35 }
36 }
37 }
38 }
39
40 // load user-provided CSS themes
41 global $css_themes;
42 $dirName = SM_PATH . 'css';
43 if (is_readable($dirName) && is_dir($dirName)) {
44 $d = dir($dirName);
45 while($dir = $d->read()) {
46 if ($dir != "." && $dir != "..") {
47 if (is_dir($dirName."/".$dir) && file_exists("$dirName/$dir/config.php"))
48 include("$dirName/$dir/config.php");
49 }
50 }
51 }
52
53 global $use_iframe;
54 if (! isset($use_iframe)) $use_iframe=false;
55
56 /**
57 * This function builds an array with all the information about
58 * the options available to the user, and returns it. The options
59 * are grouped by the groups in which they are displayed.
60 * For each option, the following information is stored:
61 * - name: the internal (variable) name
62 * - caption: the description of the option in the UI
63 * - type: one of SMOPT_TYPE_*
64 * - refresh: one of SMOPT_REFRESH_*
65 * - size: one of SMOPT_SIZE_*
66 * - save: the name of a function to call when saving this option
67 * @return array all option information
68 */
69 function load_optpage_data_display() {
70 global $theme, $fontsets, $language, $languages,$aTemplateSet,
71 $default_use_mdn, $squirrelmail_language, $allow_thread_sort,
72 $show_alternative_names, $use_icons, $use_iframe, $sTemplateID,
73 $oTemplate, $css_themes;
74
75 /* Build a simple array into which we will build options. */
76 $optgrps = array();
77 $optvals = array();
78
79 /******************************************************/
80 /* LOAD EACH GROUP OF OPTIONS INTO THE OPTIONS ARRAY. */
81 /******************************************************/
82
83 /*** Load the General Options into the array ***/
84 $optgrps[SMOPT_GRP_GENERAL] = _("General Display Options");
85 $optvals[SMOPT_GRP_GENERAL] = array();
86
87 /* load the template set option */
88 $templateset_values = array();
89
90 foreach ($aTemplateSet as $sKey => $aTemplateSetAttributes) {
91 $templateset_values[$aTemplateSetAttributes['NAME']] = $aTemplateSetAttributes['ID'];
92 }
93 ksort($templateset_values);
94 $templateset_values = array_flip($templateset_values);
95 // display template options only when there is more than one template
96 if (count($templateset_values)>1) {
97 $optvals[SMOPT_GRP_GENERAL][] = array(
98 'name' => 'sTemplateID',
99 'caption' => _("Skin"),
100 'type' => SMOPT_TYPE_STRLIST,
101 'refresh' => SMOPT_REFRESH_ALL,
102 'posvals' => $templateset_values,
103 'save' => 'save_option_template'
104 );
105 }
106
107 /* Load the theme option. */
108
109 /**
110 * User themes start with a 'u_', template themes start with a 't_' to
111 * differentiate which is which. This seems kind of hackish, but we can
112 * come up with a better solution later.
113 *
114 * TODO: Clean me.
115 **/
116 $theme_values = array();
117
118 // Always provide the template default first.
119 $theme_values['none'] = 'Template Default Theme';
120
121 // List alternate themes provided by templates first
122 /*
123 * Since this requires mods to the template class, I'm holding off on alternate
124 * template styles until Paul finishes template inheritence.
125 * -- SB, 2006-09-30
126 *
127 $template_provided = $oTemplate->get_alternative_stylesheets();
128 asort($template_provided);
129 foreach ($template_provided as $sheet=>$name) {
130 $theme_values['t_'.$sheet] = 'Template Theme - '.htmlspecialchars($name);
131 }
132 */
133 // Next, list styles provided in SM_PATH/css/
134 // FIXME, these should probably be defined in conf.pl!!
135 asort($css_themes);
136 foreach ($css_themes as $style) {
137 $theme_values['u_'.$style['PATH']] = 'User Theme - '.htmlspecialchars($style['NAME']);
138 }
139
140 $optvals[SMOPT_GRP_GENERAL][] = array(
141 'name' => 'chosen_theme',
142 'caption' => _("Theme"),
143 'type' => SMOPT_TYPE_STRLIST,
144 'refresh' => SMOPT_REFRESH_ALL,
145 'posvals' => $theme_values,
146 'save' => 'css_theme_save'
147 );
148
149 /* Icon theme selection */
150 if ($use_icons) {
151 global $icon_themes, $icon_theme;
152
153 $temp = array();
154 $value = 0;
155 for ($count = 0; $count < sizeof($icon_themes); $count++) {
156 $temp[$icon_themes[$count]['PATH']] = $icon_themes[$count]['NAME'];
157 }
158 if (sizeof($icon_themes) > 0) {
159 $optvals[SMOPT_GRP_GENERAL][] = array(
160 'name' => 'icon_theme',
161 'caption' => _("Icon Theme"),
162 'type' => SMOPT_TYPE_STRLIST,
163 'refresh' => SMOPT_REFRESH_NONE,
164 'posvals' => $temp,
165 'save' => 'icon_theme_save'
166 );
167 }
168 }
169
170 $fontset_values = array();
171 $fontset_list = array();
172
173 if (!empty($fontsets) && is_array($fontsets)) {
174
175 foreach (array_keys($fontsets) as $fontset_key) {
176 $fontset_list[$fontset_key]=$fontset_key;
177 }
178 ksort($fontset_list);
179 }
180
181 if (count($fontset_list) > 1) {
182 $fontset_list = array_merge(array('' => _("Default font style")), $fontset_list);
183 $optvals[SMOPT_GRP_GENERAL][] = array(
184 'name' => 'chosen_fontset',
185 'caption' => _("Font style"),
186 'type' => SMOPT_TYPE_STRLIST,
187 'refresh' => SMOPT_REFRESH_ALL,
188 'posvals' => $fontset_list
189 );
190 }
191
192 $optvals[SMOPT_GRP_GENERAL][] = array(
193 'name' => 'chosen_fontsize',
194 'caption' => _("Font size"),
195 'type' => SMOPT_TYPE_STRLIST,
196 'refresh' => SMOPT_REFRESH_ALL,
197 'posvals' => array('' => _("Default font size"),
198 '8' => '8 px',
199 '10' => '10 px',
200 '12' => '12 px',
201 '14' => '14 px')
202 );
203
204 $language_values = array();
205 foreach ($languages as $lang_key => $lang_attributes) {
206 if (isset($lang_attributes['NAME'])) {
207 $language_values[$lang_key] = $lang_attributes['NAME'];
208 if ( isset($show_alternative_names) &&
209 $show_alternative_names &&
210 isset($lang_attributes['ALTNAME']) ) {
211 $language_values[$lang_key] .= " / " . $lang_attributes['ALTNAME'];
212 }
213 }
214 }
215
216 asort($language_values);
217 $language_values =
218 array_merge(array('' => _("Default")), $language_values);
219 $language = $squirrelmail_language;
220
221 // add language selection only when more than 2 languages are available
222 // (default, English and some other)
223 if (count($language_values)>2) {
224 $optvals[SMOPT_GRP_GENERAL][] = array(
225 'name' => 'language',
226 'caption' => _("Language"),
227 'type' => SMOPT_TYPE_STRLIST,
228 'refresh' => SMOPT_REFRESH_ALL,
229 'posvals' => $language_values,
230 'htmlencoded' => true
231 );
232 }
233
234 /* Set values for the "use javascript" option. */
235 $optvals[SMOPT_GRP_GENERAL][] = array(
236 'name' => 'javascript_setting',
237 'caption' => _("Use Javascript"),
238 'type' => SMOPT_TYPE_STRLIST,
239 'refresh' => SMOPT_REFRESH_ALL,
240 'posvals' => array(SMPREF_JS_AUTODETECT => _("Autodetect"),
241 SMPREF_JS_ON => _("Always"),
242 SMPREF_JS_OFF => _("Never")),
243 'save' => 'save_option_javascript_autodetect',
244 'script' => 'onclick="document.forms[0].new_js_autodetect_results.value = \'' . SMPREF_JS_ON . '\';"'
245 );
246
247 $optvals[SMOPT_GRP_GENERAL][] = array(
248 'name' => 'js_autodetect_results',
249 'caption' => '',
250 'type' => SMOPT_TYPE_HIDDEN,
251 'refresh' => SMOPT_REFRESH_NONE
252 //'post_script' => $js_autodetect_script,
253 );
254
255 $optvals[SMOPT_GRP_GENERAL][] = array(
256 'name' => 'hour_format',
257 'caption' => _("Hour Format"),
258 'type' => SMOPT_TYPE_STRLIST,
259 'refresh' => SMOPT_REFRESH_FOLDERLIST,
260 'posvals' => array(SMPREF_TIME_12HR => _("12-hour clock"),
261 SMPREF_TIME_24HR => _("24-hour clock"))
262 );
263
264 /*** Load the General Options into the array ***/
265 $optgrps[SMOPT_GRP_MAILBOX] = _("Mailbox Display Options");
266 $optvals[SMOPT_GRP_MAILBOX] = array();
267
268 $optvals[SMOPT_GRP_MAILBOX][] = array(
269 'name' => 'show_num',
270 'caption' => _("Number of Messages per Page"),
271 'type' => SMOPT_TYPE_INTEGER,
272 'refresh' => SMOPT_REFRESH_NONE,
273 'size' => SMOPT_SIZE_TINY
274 );
275
276 $optvals[SMOPT_GRP_MAILBOX][] = array(
277 'name' => 'alt_index_colors',
278 'caption' => _("Enable Alternating Row Colors"),
279 'type' => SMOPT_TYPE_BOOLEAN,
280 'refresh' => SMOPT_REFRESH_NONE
281 );
282
283 $optvals[SMOPT_GRP_MAILBOX][] = array(
284 'name' => 'fancy_index_highlite',
285 'caption' => _("Enable Fancy Row Mouseover Highlighting"),
286 'type' => SMOPT_TYPE_BOOLEAN,
287 'refresh' => SMOPT_REFRESH_NONE
288 );
289
290 $optvals[SMOPT_GRP_MAILBOX][] = array(
291 'name' => 'show_flag_buttons',
292 'caption' => _("Show Flag / Unflag Buttons"),
293 'type' => SMOPT_TYPE_BOOLEAN,
294 'refresh' => SMOPT_REFRESH_NONE
295 );
296
297 $optvals[SMOPT_GRP_MAILBOX][] = array(
298 'name' => 'show_copy_buttons',
299 'caption' => _("Enable Message Copy Buttons"),
300 'type' => SMOPT_TYPE_BOOLEAN,
301 'refresh' => SMOPT_REFRESH_NONE
302 );
303
304 $optvals[SMOPT_GRP_MAILBOX][] = array(
305 'name' => 'page_selector',
306 'caption' => _("Enable Page Selector"),
307 'type' => SMOPT_TYPE_BOOLEAN,
308 'refresh' => SMOPT_REFRESH_NONE
309 );
310
311 $optvals[SMOPT_GRP_MAILBOX][] = array(
312 'name' => 'compact_paginator',
313 'caption' => _("Use Compact Page Selector"),
314 'type' => SMOPT_TYPE_BOOLEAN,
315 'refresh' => SMOPT_REFRESH_NONE
316 );
317
318 $optvals[SMOPT_GRP_MAILBOX][] = array(
319 'name' => 'page_selector_max',
320 'caption' => _("Maximum Number of Pages to Show"),
321 'type' => SMOPT_TYPE_INTEGER,
322 'refresh' => SMOPT_REFRESH_NONE,
323 'size' => SMOPT_SIZE_TINY
324 );
325
326 $optvals[SMOPT_GRP_MAILBOX][] = array(
327 'name' => 'show_full_date',
328 'caption' => _("Always Show Full Date"),
329 'type' => SMOPT_TYPE_BOOLEAN,
330 'refresh' => SMOPT_REFRESH_NONE
331 );
332
333 $optvals[SMOPT_GRP_MAILBOX][] = array(
334 'name' => 'truncate_sender',
335 'caption' => _("Length of From/To Field (0 for full)"),
336 'type' => SMOPT_TYPE_INTEGER,
337 'refresh' => SMOPT_REFRESH_NONE,
338 'size' => SMOPT_SIZE_TINY
339 );
340
341 $optvals[SMOPT_GRP_MAILBOX][] = array(
342 'name' => 'truncate_subject',
343 'caption' => _("Length of Subject Field (0 for full)"),
344 'type' => SMOPT_TYPE_INTEGER,
345 'refresh' => SMOPT_REFRESH_NONE,
346 'size' => SMOPT_SIZE_TINY
347 );
348 /*
349 FIXME!
350 disabled because the template doesn't support it (yet?)
351 $optvals[SMOPT_GRP_MAILBOX][] = array(
352 'name' => 'show_recipient_instead',
353 'caption' => _("Show recipient name if the message is from your default identity"),
354 'type' => SMOPT_TYPE_BOOLEAN,
355 'refresh' => SMOPT_REFRESH_NONE,
356 'size' => SMOPT_SIZE_TINY
357 );
358 */
359
360 if ($allow_thread_sort == TRUE) {
361 $optvals[SMOPT_GRP_MAILBOX][] = array(
362 'name' => 'sort_by_ref',
363 'caption' => _("Enable Thread Sort by References Header"),
364 'type' => SMOPT_TYPE_BOOLEAN,
365 'refresh' => SMOPT_REFRESH_ALL
366 );
367 }
368
369
370
371 /*** Load the General Options into the array ***/
372 $optgrps[SMOPT_GRP_MESSAGE] = _("Message Display Options");
373 $optvals[SMOPT_GRP_MESSAGE] = array();
374
375 $optvals[SMOPT_GRP_MESSAGE][] = array(
376 'name' => 'wrap_at',
377 'caption' => _("Wrap Incoming Text At"),
378 'type' => SMOPT_TYPE_INTEGER,
379 'refresh' => SMOPT_REFRESH_NONE,
380 'size' => SMOPT_SIZE_TINY
381 );
382
383 $optvals[SMOPT_GRP_MESSAGE][] = array(
384 'name' => 'show_html_default',
385 'caption' => _("Show HTML Version by Default"),
386 'type' => SMOPT_TYPE_BOOLEAN,
387 'refresh' => SMOPT_REFRESH_NONE
388 );
389
390 if ($use_iframe) {
391 // Type is set to string in order to be able to use 100%.
392 $optvals[SMOPT_GRP_MESSAGE][] = array(
393 'name' => 'iframe_height',
394 'caption' => _("Height of inline frame"),
395 'type' => SMOPT_TYPE_STRING,
396 'size' => SMOPT_SIZE_TINY,
397 'refresh' => SMOPT_REFRESH_NONE
398 );
399 }
400 $optvals[SMOPT_GRP_MESSAGE][] = array(
401 'name' => 'enable_forward_as_attachment',
402 'caption' => _("Enable Forward as Attachment"),
403 'type' => SMOPT_TYPE_BOOLEAN,
404 'refresh' => SMOPT_REFRESH_NONE
405 );
406
407 $optvals[SMOPT_GRP_MESSAGE][] = array(
408 'name' => 'show_xmailer_default',
409 'caption' => _("Enable Mailer Display"),
410 'type' => SMOPT_TYPE_BOOLEAN,
411 'refresh' => SMOPT_REFRESH_NONE
412 );
413
414 $optvals[SMOPT_GRP_MESSAGE][] = array(
415 'name' => 'attachment_common_show_images',
416 'caption' => _("Display Attached Images with Message"),
417 'type' => SMOPT_TYPE_BOOLEAN,
418 'refresh' => SMOPT_REFRESH_NONE
419 );
420
421 if ($default_use_mdn) {
422 $optvals[SMOPT_GRP_MESSAGE][] = array(
423 'name' => 'mdn_user_support',
424 'caption' => _("Enable Mail Delivery Notification"),
425 'type' => SMOPT_TYPE_BOOLEAN,
426 'refresh' => SMOPT_REFRESH_NONE
427 );
428 }
429
430 $optvals[SMOPT_GRP_MESSAGE][] = array(
431 'name' => 'delete_prev_next_display',
432 'caption' => _("Show 'Delete &amp; Prev/Next' Links"),
433 'type' => SMOPT_TYPE_BOOLEAN,
434 'refresh' => SMOPT_REFRESH_ALL
435 );
436
437 /* Assemble all this together and return it as our result. */
438 $result = array(
439 'grps' => $optgrps,
440 'vals' => $optvals
441 );
442 return ($result);
443 }
444
445 /******************************************************************/
446 /** Define any specialized save functions for this option page. ***/
447 /******************************************************************/
448
449 /**
450 * This function saves a new template setting.
451 * It updates the template array.
452 */
453 function save_option_template($option) {
454 global $aTemplateSet;
455
456 /* Do checking to make sure $new_theme is in the array. */
457 $templateset_in_array = false;
458 for ($i = 0; $i < count($aTemplateSet); ++$i) {
459 if ($aTemplateSet[$i]['ID'] == $option->new_value) {
460 $templateset_in_array = true;
461 break;
462 }
463 }
464
465 if (!$templateset_in_array) {
466 $option->new_value = '';
467 }
468 /* Save the option like normal. */
469 save_option($option);
470 }
471
472 /**
473 * This function saves a new theme setting.
474 * It updates the theme array.
475 */
476 function save_option_theme($option) {
477 global $theme;
478
479 /* Do checking to make sure $new_theme is in the array. */
480 $theme_in_array = false;
481 for ($i = 0; $i < count($theme); ++$i) {
482 if ($theme[$i]['PATH'] == $option->new_value) {
483 $theme_in_array = true;
484 break;
485 }
486 }
487
488 if (!$theme_in_array) {
489 $option->new_value = '';
490 }
491
492 /* Save the option like normal. */
493 save_option($option);
494 }
495
496 /**
497 * This function saves the javascript detection option.
498 */
499 function save_option_javascript_autodetect($option) {
500 save_option($option);
501 checkForJavascript(TRUE);
502 }
503
504 /**
505 * This function saves the user's icon theme setting
506 */
507 function icon_theme_save($option) {
508 global $icon_themes, $data_dir, $username;
509
510
511 // Don't assume the new value is there, double check
512 // and only save if found
513 //
514 $found = false;
515 while (!$found && (list($index, $data) = each($icon_themes))) {
516 if ($data['PATH'] == $option->new_value)
517 $found = true;
518 }
519 if ($found)
520 setPref($data_dir, $username, 'icon_theme', $option->new_value);
521 else
522 setPref($data_dir, $username, 'icon_theme', 'none');
523
524 }
525
526 function css_theme_save ($option) {
527 global $css_themes, $data_dir, $username;
528
529 // Don't assume the new value is there, double check
530 // and only save if found
531 //
532 $found = false;
533 reset($css_themes);
534 while (!$found && (list($index, $data) = each($css_themes))) {
535 if ('u_'.$data['PATH'] == $option->new_value)
536 $found = true;
537 }
538 if ($found)
539 setPref($data_dir, $username, 'chosen_theme', $option->new_value);
540 else
541 setPref($data_dir, $username, 'chosen_theme', 'none');
542 }
543
544