String and PHP fix
[squirrelmail.git] / include / options / display.php
CommitLineData
c36ed9cf 1<?php
e7db48af 2
35586184 3/**
4 * options_display.php
5 *
6c84ba1e 6 * Copyright (c) 1999-2005 The SquirrelMail Project Team
35586184 7 * Licensed under the GNU GPL. For full terms see the file COPYING.
8 *
9 * Displays all optinos about display preferences
10 *
763b63fe 11 * @version $Id$
2b646597 12 * @package squirrelmail
35586184 13 */
cbe5423b 14
2b646597 15/** Define the group constants for the display options page. */
cbe5423b 16define('SMOPT_GRP_GENERAL', 0);
17define('SMOPT_GRP_MAILBOX', 1);
18define('SMOPT_GRP_MESSAGE', 2);
19
6395c46d 20// load icon themes if in use
21global $use_icons;
22if ($use_icons) {
23 global $icon_themes;
24 $dirName = SM_PATH . 'images/themes';
4f7a5870 25 if (is_readable($dirName) && is_dir($dirName)) {
26 $d = dir($dirName);
27 while($dir = $d->read()) {
28 if ($dir != "." && $dir != "..") {
29 if (is_dir($dirName."/".$dir) && file_exists("$dirName/$dir/theme.php"))
30 include("$dirName/$dir/theme.php");
31 }
6395c46d 32 }
33 }
34}
35
a144f6b8 36global $use_iframe;
37if (! isset($use_iframe)) $use_iframe=false;
38
48af4b64 39/**
40 * This function builds an array with all the information about
41 * the options available to the user, and returns it. The options
42 * are grouped by the groups in which they are displayed.
43 * For each option, the following information is stored:
44 * - name: the internal (variable) name
45 * - caption: the description of the option in the UI
46 * - type: one of SMOPT_TYPE_*
47 * - refresh: one of SMOPT_REFRESH_*
48 * - size: one of SMOPT_SIZE_*
49 * - save: the name of a function to call when saving this option
50 * @return array all option information
51 */
cbe5423b 52function load_optpage_data_display() {
91e0dccc 53 global $theme, $language, $languages,
ce68b76b 54 $default_use_mdn, $squirrelmail_language, $allow_thread_sort,
5ba5dc8e 55 $show_alternative_names, $use_icons, $use_iframe;
a3ec3c91 56
ce393174 57 /* Build a simple array into which we will build options. */
bbcafebd 58 $optgrps = array();
59 $optvals = array();
a3ec3c91 60
bbcafebd 61 /******************************************************/
62 /* LOAD EACH GROUP OF OPTIONS INTO THE OPTIONS ARRAY. */
63 /******************************************************/
bbcafebd 64
65 /*** Load the General Options into the array ***/
66 $optgrps[SMOPT_GRP_GENERAL] = _("General Display Options");
67 $optvals[SMOPT_GRP_GENERAL] = array();
68
69 /* Load the theme option. */
ce393174 70 $theme_values = array();
71 foreach ($theme as $theme_key => $theme_attributes) {
be278741 72 $theme_values[$theme_attributes['NAME']] = $theme_attributes['PATH'];
ce393174 73 }
be278741 74 ksort($theme_values);
75 $theme_values = array_flip($theme_values);
bbcafebd 76 $optvals[SMOPT_GRP_GENERAL][] = array(
ce393174 77 'name' => 'chosen_theme',
78 'caption' => _("Theme"),
79 'type' => SMOPT_TYPE_STRLIST,
80 'refresh' => SMOPT_REFRESH_ALL,
cbe5423b 81 'posvals' => $theme_values,
82 'save' => 'save_option_theme'
ce393174 83 );
5d110fa6 84
8f1ba72b 85 $css_values = array( 'none' => _("Default" ) );
bb7173fa 86 $css_dir = SM_PATH . 'themes/css';
87 if (is_readable($css_dir) && is_dir($css_dir)) {
88 $handle=opendir($css_dir);
4f7a5870 89 while ($file = readdir($handle) ) {
90 if ( substr( $file, -4 ) == '.css' ) {
91 $css_values[$file] = substr( $file, 0, strlen( $file ) - 4 );
92 }
8f1ba72b 93 }
4f7a5870 94 closedir($handle);
dcd6f144 95 }
5d110fa6 96
54078578 97 if ( count( $css_values ) > 1 ) {
5d110fa6 98
e2cdae1f 99 $optvals[SMOPT_GRP_GENERAL][] = array(
100 'name' => 'custom_css',
101 'caption' => _("Custom Stylesheet"),
102 'type' => SMOPT_TYPE_STRLIST,
103 'refresh' => SMOPT_REFRESH_ALL,
104 'posvals' => $css_values
105 );
5d110fa6 106
e2cdae1f 107 }
39d3ec89 108
e557fdb0 109 $language_values = array();
5ba5dc8e 110 foreach ($languages as $lang_key => $lang_attributes) {
111 if (isset($lang_attributes['NAME'])) {
112 $language_values[$lang_key] = $lang_attributes['NAME'];
113 if ( isset($show_alternative_names) &&
114 $show_alternative_names &&
115 isset($lang_attributes['ALTNAME']) ) {
116 $language_values[$lang_key] .= " / " . $lang_attributes['ALTNAME'];
0bb37159 117 }
118 }
ce393174 119 }
5ba5dc8e 120
e557fdb0 121 asort($language_values);
8405d0a4 122 $language_values =
123 array_merge(array('' => _("Default")), $language_values);
ec2c91a1 124 $language = $squirrelmail_language;
5ba5dc8e 125
126 // TODO: maybe we can add count($language_values) check here
127 $optvals[SMOPT_GRP_GENERAL][] = array(
128 'name' => 'language',
129 'caption' => _("Language"),
130 'type' => SMOPT_TYPE_STRLIST,
131 'refresh' => SMOPT_REFRESH_ALL,
132 'posvals' => $language_values,
133 'htmlencoded' => true
134 );
ce393174 135
a3ec3c91 136 /* Set values for the "use javascript" option. */
bbcafebd 137 $optvals[SMOPT_GRP_GENERAL][] = array(
a3ec3c91 138 'name' => 'javascript_setting',
ce393174 139 'caption' => _("Use Javascript"),
a3ec3c91 140 'type' => SMOPT_TYPE_STRLIST,
141 'refresh' => SMOPT_REFRESH_ALL,
142 'posvals' => array(SMPREF_JS_AUTODETECT => _("Autodetect"),
143 SMPREF_JS_ON => _("Always"),
ae958cd3 144 SMPREF_JS_OFF => _("Never")),
145 'save' => 'save_option_javascript_autodetect',
146 'script' => 'onclick="document.forms[0].new_js_autodetect_results.value = \'' . SMPREF_JS_ON . '\';"'
a3ec3c91 147 );
148
bbcafebd 149 $optvals[SMOPT_GRP_GENERAL][] = array(
a3ec3c91 150 'name' => 'js_autodetect_results',
151 'caption' => '',
152 'type' => SMOPT_TYPE_HIDDEN,
ae958cd3 153 'refresh' => SMOPT_REFRESH_NONE
5826affb 154 //'post_script' => $js_autodetect_script,
a3ec3c91 155 );
f2df3fa1 156
5bcd1b00 157 $optvals[SMOPT_GRP_GENERAL][] = array(
158 'name' => 'hour_format',
159 'caption' => _("Hour Format"),
160 'type' => SMOPT_TYPE_STRLIST,
161 'refresh' => SMOPT_REFRESH_FOLDERLIST,
162 'posvals' => array(SMPREF_TIME_12HR => _("12-hour clock"),
163 SMPREF_TIME_24HR => _("24-hour clock"))
164 );
a3ec3c91 165
bbcafebd 166 /*** Load the General Options into the array ***/
167 $optgrps[SMOPT_GRP_MAILBOX] = _("Mailbox Display Options");
168 $optvals[SMOPT_GRP_MAILBOX] = array();
169
170 $optvals[SMOPT_GRP_MAILBOX][] = array(
a3ec3c91 171 'name' => 'show_num',
f2df3fa1 172 'caption' => _("Number of Messages per Page"),
a3ec3c91 173 'type' => SMOPT_TYPE_INTEGER,
bbcafebd 174 'refresh' => SMOPT_REFRESH_NONE,
175 'size' => SMOPT_SIZE_TINY
a3ec3c91 176 );
177
bbcafebd 178 $optvals[SMOPT_GRP_MAILBOX][] = array(
a440e68f 179 'name' => 'alt_index_colors',
180 'caption' => _("Enable Alternating Row Colors"),
181 'type' => SMOPT_TYPE_BOOLEAN,
182 'refresh' => SMOPT_REFRESH_NONE
183 );
184
18adc53f 185 $optvals[SMOPT_GRP_MAILBOX][] = array(
186 'name' => 'fancy_index_highlite',
187 'caption' => _("Enable Fancy Row Mouseover Highlighting"),
188 'type' => SMOPT_TYPE_BOOLEAN,
189 'refresh' => SMOPT_REFRESH_NONE
190 );
191
6395c46d 192 if ($use_icons) {
193 global $icon_themes, $icon_theme;
194 $temp = array();
195 for ($count = 0; $count < sizeof($icon_themes); $count++) {
196 $temp[$count] = $icon_themes[$count]['NAME'];
197 if ($icon_theme == $icon_themes[$count]['PATH'])
198 $value = $count;
199 }
4f7a5870 200 if (sizeof($icon_themes) > 0) {
201 $optvals[SMOPT_GRP_MAILBOX][] = array(
202 'name' => 'icon_theme',
203 'caption' => _("Message Flags Icon Theme"),
204 'type' => SMOPT_TYPE_STRLIST,
205 'refresh' => SMOPT_REFRESH_NONE,
206 'posvals' => $temp,
207 'initial_value' => $value,
208 'save' => 'icon_theme_save'
209 );
210 }
6395c46d 211 }
212
fd181f53 213 $optvals[SMOPT_GRP_MAILBOX][] = array(
214 'name' => 'show_flag_buttons',
215 'caption' => _("Show Flag / Unflag Buttons"),
216 'type' => SMOPT_TYPE_BOOLEAN,
217 'refresh' => SMOPT_REFRESH_NONE
218 );
219
bbcafebd 220 $optvals[SMOPT_GRP_MAILBOX][] = array(
a440e68f 221 'name' => 'page_selector',
222 'caption' => _("Enable Page Selector"),
223 'type' => SMOPT_TYPE_BOOLEAN,
224 'refresh' => SMOPT_REFRESH_NONE
225 );
226
0bb37159 227 $optvals[SMOPT_GRP_MAILBOX][] = array(
228 'name' => 'compact_paginator',
229 'caption' => _("Use Compact Page Selector"),
230 'type' => SMOPT_TYPE_BOOLEAN,
231 'refresh' => SMOPT_REFRESH_NONE
232 );
233
bbcafebd 234 $optvals[SMOPT_GRP_MAILBOX][] = array(
a440e68f 235 'name' => 'page_selector_max',
236 'caption' => _("Maximum Number of Pages to Show"),
237 'type' => SMOPT_TYPE_INTEGER,
bbcafebd 238 'refresh' => SMOPT_REFRESH_NONE,
239 'size' => SMOPT_SIZE_TINY
a440e68f 240 );
241
3e3b60e3 242 $optvals[SMOPT_GRP_MAILBOX][] = array(
243 'name' => 'show_full_date',
244 'caption' => _("Always Show Full Date"),
245 'type' => SMOPT_TYPE_BOOLEAN,
246 'refresh' => SMOPT_REFRESH_NONE
247 );
248
459e3347 249 $optvals[SMOPT_GRP_MAILBOX][] = array(
250 'name' => 'truncate_sender',
251 'caption' => _("Length of From/To Field (0 for full)"),
252 'type' => SMOPT_TYPE_INTEGER,
253 'refresh' => SMOPT_REFRESH_NONE,
254 'size' => SMOPT_SIZE_TINY
255 );
256
3fc1a95f 257 $optvals[SMOPT_GRP_MAILBOX][] = array(
258 'name' => 'truncate_subject',
259 'caption' => _("Length of Subject Field (0 for full)"),
260 'type' => SMOPT_TYPE_INTEGER,
261 'refresh' => SMOPT_REFRESH_NONE,
262 'size' => SMOPT_SIZE_TINY
263 );
91c27aee 264/*
265 disabled because the template doesn't support it (yet?)
1ae2832e 266 $optvals[SMOPT_GRP_MAILBOX][] = array(
267 'name' => 'show_recipient_instead',
268 'caption' => _("Show recipient name if the message is from your default identity"),
269 'type' => SMOPT_TYPE_BOOLEAN,
270 'refresh' => SMOPT_REFRESH_NONE,
271 'size' => SMOPT_SIZE_TINY
272 );
91c27aee 273*/
f2df3fa1 274
5ed9d4fd 275 if ($allow_thread_sort == TRUE) {
276 $optvals[SMOPT_GRP_MAILBOX][] = array(
277 'name' => 'sort_by_ref',
278 'caption' => _("Enable Thread Sort by References Header"),
279 'type' => SMOPT_TYPE_BOOLEAN,
280 'refresh' => SMOPT_REFRESH_ALL
281 );
282 }
283
1ae2832e 284
459e3347 285
bbcafebd 286 /*** Load the General Options into the array ***/
5ed9d4fd 287 $optgrps[SMOPT_GRP_MESSAGE] = _("Message Display Options");
bbcafebd 288 $optvals[SMOPT_GRP_MESSAGE] = array();
289
290 $optvals[SMOPT_GRP_MESSAGE][] = array(
a3ec3c91 291 'name' => 'wrap_at',
292 'caption' => _("Wrap Incoming Text At"),
293 'type' => SMOPT_TYPE_INTEGER,
bbcafebd 294 'refresh' => SMOPT_REFRESH_NONE,
295 'size' => SMOPT_SIZE_TINY
a3ec3c91 296 );
297
bbcafebd 298 $optvals[SMOPT_GRP_MESSAGE][] = array(
fd87494d 299 'name' => 'show_html_default',
300 'caption' => _("Show HTML Version by Default"),
301 'type' => SMOPT_TYPE_BOOLEAN,
302 'refresh' => SMOPT_REFRESH_NONE
303 );
304
a144f6b8 305 if ($use_iframe) {
306 // Type is set to string in order to be able to use 100%.
307 $optvals[SMOPT_GRP_MESSAGE][] = array(
308 'name' => 'iframe_height',
309 'caption' => _("Height of inline frame"),
310 'type' => SMOPT_TYPE_STRING,
311 'size' => SMOPT_SIZE_TINY,
312 'refresh' => SMOPT_REFRESH_NONE
313 );
314 }
bbcafebd 315 $optvals[SMOPT_GRP_MESSAGE][] = array(
6206f6c4 316 'name' => 'enable_forward_as_attachment',
317 'caption' => _("Enable Forward as Attachment"),
fd87494d 318 'type' => SMOPT_TYPE_BOOLEAN,
319 'refresh' => SMOPT_REFRESH_NONE
320 );
321
bbcafebd 322 $optvals[SMOPT_GRP_MESSAGE][] = array(
9ab0d96f 323 'name' => 'show_xmailer_default',
a440e68f 324 'caption' => _("Enable Mailer Display"),
9ab0d96f 325 'type' => SMOPT_TYPE_BOOLEAN,
326 'refresh' => SMOPT_REFRESH_NONE
327 );
328
7baf86a9 329 $optvals[SMOPT_GRP_MESSAGE][] = array(
330 'name' => 'attachment_common_show_images',
10f0ce72 331 'caption' => _("Display Attached Images with Message"),
7baf86a9 332 'type' => SMOPT_TYPE_BOOLEAN,
333 'refresh' => SMOPT_REFRESH_NONE
334 );
335
57257333 336 if ($default_use_mdn) {
337 $optvals[SMOPT_GRP_MESSAGE][] = array(
338 'name' => 'mdn_user_support',
6206f6c4 339 'caption' => _("Enable Mail Delivery Notification"),
57257333 340 'type' => SMOPT_TYPE_BOOLEAN,
341 'refresh' => SMOPT_REFRESH_NONE
342 );
343 }
07687736 344
4267d5de 345 $optvals[SMOPT_GRP_MESSAGE][] = array(
346 'name' => 'delete_prev_next_display',
347 'caption' => _("Show 'Delete & Prev/Next' Links"),
348 'type' => SMOPT_TYPE_BOOLEAN,
349 'refresh' => SMOPT_REFRESH_ALL
350 );
5d110fa6 351
cbe5423b 352 /* Assemble all this together and return it as our result. */
353 $result = array(
354 'grps' => $optgrps,
ae958cd3 355 'vals' => $optvals
cbe5423b 356 );
357 return ($result);
358}
a3ec3c91 359
cbe5423b 360/******************************************************************/
361/** Define any specialized save functions for this option page. ***/
362/******************************************************************/
f1e6f580 363
48af4b64 364/**
365 * This function saves a new theme setting.
366 * It updates the theme array.
367 */
cbe5423b 368function save_option_theme($option) {
369 global $theme;
bb7173fa 370
cbe5423b 371 /* Do checking to make sure $new_theme is in the array. */
372 $theme_in_array = false;
373 for ($i = 0; $i < count($theme); ++$i) {
374 if ($theme[$i]['PATH'] == $option->new_value) {
375 $theme_in_array = true;
376 break;
377 }
378 }
379
380 if (!$theme_in_array) {
381 $option->new_value = '';
382 }
e7db48af 383
cbe5423b 384 /* Save the option like normal. */
385 save_option($option);
386}
e7db48af 387
48af4b64 388/**
389 * This function saves the javascript detection option.
390 */
cbe5423b 391function save_option_javascript_autodetect($option) {
ae958cd3 392 save_option($option);
393 checkForJavascript(TRUE);
cbe5423b 394}
395
5d110fa6 396/**
6395c46d 397 * This function saves the user's icon theme setting
398 */
399function icon_theme_save($option) {
400
401 global $icon_themes, $data_dir, $username;
402
403
5d110fa6 404 // Don't assume the new value is there, double check
405 // and only save if found
6395c46d 406 //
407 if (isset($icon_themes[$option->new_value]['PATH']))
408 setPref($data_dir, $username, 'icon_theme', $icon_themes[$option->new_value]['PATH']);
409 else
410 setPref($data_dir, $username, 'icon_theme', 'none');
411
412}
413
f8a1ed5a 414?>