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