String and PHP fix
[squirrelmail.git] / include / options / display.php
1 <?php
2
3 /**
4 * options_display.php
5 *
6 * Copyright (c) 1999-2005 The SquirrelMail Project Team
7 * Licensed under the GNU GPL. For full terms see the file COPYING.
8 *
9 * Displays all optinos about display preferences
10 *
11 * @version $Id$
12 * @package squirrelmail
13 */
14
15 /** Define the group constants for the display options page. */
16 define('SMOPT_GRP_GENERAL', 0);
17 define('SMOPT_GRP_MAILBOX', 1);
18 define('SMOPT_GRP_MESSAGE', 2);
19
20 // load icon themes if in use
21 global $use_icons;
22 if ($use_icons) {
23 global $icon_themes;
24 $dirName = SM_PATH . 'images/themes';
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 }
32 }
33 }
34 }
35
36 global $use_iframe;
37 if (! isset($use_iframe)) $use_iframe=false;
38
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 */
52 function load_optpage_data_display() {
53 global $theme, $language, $languages,
54 $default_use_mdn, $squirrelmail_language, $allow_thread_sort,
55 $show_alternative_names, $use_icons, $use_iframe;
56
57 /* Build a simple array into which we will build options. */
58 $optgrps = array();
59 $optvals = array();
60
61 /******************************************************/
62 /* LOAD EACH GROUP OF OPTIONS INTO THE OPTIONS ARRAY. */
63 /******************************************************/
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. */
70 $theme_values = array();
71 foreach ($theme as $theme_key => $theme_attributes) {
72 $theme_values[$theme_attributes['NAME']] = $theme_attributes['PATH'];
73 }
74 ksort($theme_values);
75 $theme_values = array_flip($theme_values);
76 $optvals[SMOPT_GRP_GENERAL][] = array(
77 'name' => 'chosen_theme',
78 'caption' => _("Theme"),
79 'type' => SMOPT_TYPE_STRLIST,
80 'refresh' => SMOPT_REFRESH_ALL,
81 'posvals' => $theme_values,
82 'save' => 'save_option_theme'
83 );
84
85 $css_values = array( 'none' => _("Default" ) );
86 $css_dir = SM_PATH . 'themes/css';
87 if (is_readable($css_dir) && is_dir($css_dir)) {
88 $handle=opendir($css_dir);
89 while ($file = readdir($handle) ) {
90 if ( substr( $file, -4 ) == '.css' ) {
91 $css_values[$file] = substr( $file, 0, strlen( $file ) - 4 );
92 }
93 }
94 closedir($handle);
95 }
96
97 if ( count( $css_values ) > 1 ) {
98
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 );
106
107 }
108
109 $language_values = array();
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'];
117 }
118 }
119 }
120
121 asort($language_values);
122 $language_values =
123 array_merge(array('' => _("Default")), $language_values);
124 $language = $squirrelmail_language;
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 );
135
136 /* Set values for the "use javascript" option. */
137 $optvals[SMOPT_GRP_GENERAL][] = array(
138 'name' => 'javascript_setting',
139 'caption' => _("Use Javascript"),
140 'type' => SMOPT_TYPE_STRLIST,
141 'refresh' => SMOPT_REFRESH_ALL,
142 'posvals' => array(SMPREF_JS_AUTODETECT => _("Autodetect"),
143 SMPREF_JS_ON => _("Always"),
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 . '\';"'
147 );
148
149 $optvals[SMOPT_GRP_GENERAL][] = array(
150 'name' => 'js_autodetect_results',
151 'caption' => '',
152 'type' => SMOPT_TYPE_HIDDEN,
153 'refresh' => SMOPT_REFRESH_NONE
154 //'post_script' => $js_autodetect_script,
155 );
156
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 );
165
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(
171 'name' => 'show_num',
172 'caption' => _("Number of Messages per Page"),
173 'type' => SMOPT_TYPE_INTEGER,
174 'refresh' => SMOPT_REFRESH_NONE,
175 'size' => SMOPT_SIZE_TINY
176 );
177
178 $optvals[SMOPT_GRP_MAILBOX][] = array(
179 'name' => 'alt_index_colors',
180 'caption' => _("Enable Alternating Row Colors"),
181 'type' => SMOPT_TYPE_BOOLEAN,
182 'refresh' => SMOPT_REFRESH_NONE
183 );
184
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
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 }
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 }
211 }
212
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
220 $optvals[SMOPT_GRP_MAILBOX][] = array(
221 'name' => 'page_selector',
222 'caption' => _("Enable Page Selector"),
223 'type' => SMOPT_TYPE_BOOLEAN,
224 'refresh' => SMOPT_REFRESH_NONE
225 );
226
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
234 $optvals[SMOPT_GRP_MAILBOX][] = array(
235 'name' => 'page_selector_max',
236 'caption' => _("Maximum Number of Pages to Show"),
237 'type' => SMOPT_TYPE_INTEGER,
238 'refresh' => SMOPT_REFRESH_NONE,
239 'size' => SMOPT_SIZE_TINY
240 );
241
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
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
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 );
264 /*
265 disabled because the template doesn't support it (yet?)
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 );
273 */
274
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
284
285
286 /*** Load the General Options into the array ***/
287 $optgrps[SMOPT_GRP_MESSAGE] = _("Message Display Options");
288 $optvals[SMOPT_GRP_MESSAGE] = array();
289
290 $optvals[SMOPT_GRP_MESSAGE][] = array(
291 'name' => 'wrap_at',
292 'caption' => _("Wrap Incoming Text At"),
293 'type' => SMOPT_TYPE_INTEGER,
294 'refresh' => SMOPT_REFRESH_NONE,
295 'size' => SMOPT_SIZE_TINY
296 );
297
298 $optvals[SMOPT_GRP_MESSAGE][] = array(
299 'name' => 'show_html_default',
300 'caption' => _("Show HTML Version by Default"),
301 'type' => SMOPT_TYPE_BOOLEAN,
302 'refresh' => SMOPT_REFRESH_NONE
303 );
304
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 }
315 $optvals[SMOPT_GRP_MESSAGE][] = array(
316 'name' => 'enable_forward_as_attachment',
317 'caption' => _("Enable Forward as Attachment"),
318 'type' => SMOPT_TYPE_BOOLEAN,
319 'refresh' => SMOPT_REFRESH_NONE
320 );
321
322 $optvals[SMOPT_GRP_MESSAGE][] = array(
323 'name' => 'show_xmailer_default',
324 'caption' => _("Enable Mailer Display"),
325 'type' => SMOPT_TYPE_BOOLEAN,
326 'refresh' => SMOPT_REFRESH_NONE
327 );
328
329 $optvals[SMOPT_GRP_MESSAGE][] = array(
330 'name' => 'attachment_common_show_images',
331 'caption' => _("Display Attached Images with Message"),
332 'type' => SMOPT_TYPE_BOOLEAN,
333 'refresh' => SMOPT_REFRESH_NONE
334 );
335
336 if ($default_use_mdn) {
337 $optvals[SMOPT_GRP_MESSAGE][] = array(
338 'name' => 'mdn_user_support',
339 'caption' => _("Enable Mail Delivery Notification"),
340 'type' => SMOPT_TYPE_BOOLEAN,
341 'refresh' => SMOPT_REFRESH_NONE
342 );
343 }
344
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 );
351
352 /* Assemble all this together and return it as our result. */
353 $result = array(
354 'grps' => $optgrps,
355 'vals' => $optvals
356 );
357 return ($result);
358 }
359
360 /******************************************************************/
361 /** Define any specialized save functions for this option page. ***/
362 /******************************************************************/
363
364 /**
365 * This function saves a new theme setting.
366 * It updates the theme array.
367 */
368 function save_option_theme($option) {
369 global $theme;
370
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 }
383
384 /* Save the option like normal. */
385 save_option($option);
386 }
387
388 /**
389 * This function saves the javascript detection option.
390 */
391 function save_option_javascript_autodetect($option) {
392 save_option($option);
393 checkForJavascript(TRUE);
394 }
395
396 /**
397 * This function saves the user's icon theme setting
398 */
399 function icon_theme_save($option) {
400
401 global $icon_themes, $data_dir, $username;
402
403
404 // Don't assume the new value is there, double check
405 // and only save if found
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
414 ?>