set value returned by ini_get to boolean
[squirrelmail.git] / src / options.php
CommitLineData
59177427 1<?php
d3cdb279 2
35586184 3/**
4 * options.php
5 *
82d304a0 6 * Copyright (c) 1999-2004 The SquirrelMail Project Team
35586184 7 * Licensed under the GNU GPL. For full terms see the file COPYING.
8 *
9 * Displays the options page. Pulls from proper user preference files
10 * and config.php. Displays preferences as selected and other options.
11 *
30967a1e 12 * @version $Id$
8f6f9ba5 13 * @package squirrelmail
35586184 14 */
cbe5423b 15
30967a1e 16/**
17 * Path for SquirrelMail required files.
18 * @ignore
19 */
86725763 20define('SM_PATH','../');
21
22/* SquirrelMail required files. */
08185f2a 23require_once(SM_PATH . 'include/validate.php');
1e12d1ff 24require_once(SM_PATH . 'functions/global.php');
86725763 25require_once(SM_PATH . 'functions/display_messages.php');
26require_once(SM_PATH . 'functions/imap.php');
86725763 27require_once(SM_PATH . 'functions/options.php');
28require_once(SM_PATH . 'functions/strings.php');
29require_once(SM_PATH . 'functions/html.php');
62366261 30require_once(SM_PATH . 'functions/forms.php');
cbe5423b 31
cbe5423b 32/*********************************/
33/*** Build the resultant page. ***/
34/*********************************/
35
cbe5423b 36define('SMOPT_MODE_DISPLAY', 'display');
37define('SMOPT_MODE_SUBMIT', 'submit');
38define('SMOPT_MODE_LINK', 'link');
39
40define('SMOPT_PAGE_MAIN', 'main');
41define('SMOPT_PAGE_PERSONAL', 'personal');
42define('SMOPT_PAGE_DISPLAY', 'display');
43define('SMOPT_PAGE_HIGHLIGHT', 'highlight');
44define('SMOPT_PAGE_FOLDER', 'folder');
45define('SMOPT_PAGE_ORDER', 'order');
46
47function process_optionmode_submit($optpage, $optpage_data) {
48 /* Initialize the maximum option refresh level. */
49 $max_refresh = SMOPT_REFRESH_NONE;
50
51 /* Save each option in each option group. */
52 foreach ($optpage_data['options'] as $option_grp) {
53 foreach ($option_grp['options'] as $option) {
534367eb 54 /* Remove Debug Mode Until Needed
cbe5423b 55 echo "name = '$option->name', "
56 . "value = '$option->value', "
6206f6c4 57 . "new_value = '$option->new_value'\n";
39bfea8f 58 echo "<br />";
534367eb 59 */
cbe5423b 60 if ($option->changed()) {
61 $option->save();
62 $max_refresh = max($max_refresh, $option->refresh_level);
63 }
64 }
65 }
1e0628fb 66
cbe5423b 67 /* Return the max refresh level. */
68 return ($max_refresh);
69}
70
71function process_optionmode_link($optpage) {
72 /* There will be something here, later. */
73}
74
0b0e96c5 75
76/**
77 * This function prints out an option page row.
78 */
79function print_optionpages_row($leftopt, $rightopt = false) {
80 global $color;
81
0b0e96c5 82 if ($rightopt) {
545238b1 83 $rightopt_name = html_tag( 'td', '<a href="' . $rightopt['url'] . '">' . $rightopt['name'] . '</a>', 'left', $color[9], 'valign="top" width="49%"' );
84 $rightopt_desc = html_tag( 'td', $rightopt['desc'], 'left', $color[0], 'valign="top" width="49%"' );
0b0e96c5 85 } else {
545238b1 86 $rightopt_name = html_tag( 'td', '&nbsp;', 'left', $color[4], 'valign="top" width="49%"' );
87 $rightopt_desc = html_tag( 'td', '&nbsp;', 'left', $color[4], 'valign="top" width="49%"' );
0b0e96c5 88 }
89
545238b1 90 echo
91 html_tag( 'table', "\n" .
92 html_tag( 'tr', "\n" .
93 html_tag( 'td', "\n" .
94 html_tag( 'table', "\n" .
95 html_tag( 'tr', "\n" .
96 html_tag( 'td',
97 '<a href="' . $leftopt['url'] . '">' . $leftopt['name'] . '</a>' ,
98 'left', $color[9], 'valign="top" width="49%"' ) .
99 html_tag( 'td',
100 '&nbsp;' ,
101 'left', $color[4], 'valign="top" width="2%"' ) . "\n" .
102 $rightopt_name
103 ) . "\n" .
104 html_tag( 'tr', "\n" .
105 html_tag( 'td',
106 $leftopt['desc'] ,
107 'left', $color[0], 'valign="top" width="49%"' ) .
108 html_tag( 'td',
109 '&nbsp;' ,
110 'left', $color[4], 'valign="top" width="2%"' ) . "\n" .
111 $rightopt_desc
112 ) ,
113 '', '', 'width="100%" cellpadding="2" cellspacing="0" border="0"' ) ,
114 'left', '', 'valign="top"' )
115 ) ,
116 '', $color[4], 'width="100%" cellpadding="0" cellspacing="5" border="0"' );
0b0e96c5 117}
118
119/* ---------------------------- main ---------------------------- */
120
a32985a5 121/* get the globals that we may need */
1e12d1ff 122sqgetGlobalVar('key', $key, SQ_COOKIE);
123sqgetGlobalVar('username', $username, SQ_SESSION);
124sqgetGlobalVar('onetimepad',$onetimepad, SQ_SESSION);
125sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION);
126
127sqgetGlobalVar('optpage', $optpage);
5ccba4f3 128sqgetGlobalVar('optmode', $optmode, SQ_FORM);
1e12d1ff 129sqgetGlobalVar('optpage_data',$optpage_data, SQ_POST);
a32985a5 130/* end of getting globals */
131
cbe5423b 132/* Make sure we have an Option Page set. Default to main. */
c1f7790a 133if ( !isset($optpage) || $optpage == '' ) {
134 $optpage = SMOPT_PAGE_MAIN;
135} else {
136 $optpage = strip_tags( $optpage );
cbe5423b 137}
138
139/* Make sure we have an Option Mode set. Default to display. */
140if (!isset($optmode)) {
141 $optmode = SMOPT_MODE_DISPLAY;
142}
143
0b0e96c5 144/*
91e0dccc 145 * First, set the load information for each option page.
0b0e96c5 146 */
cbe5423b 147
148/* Initialize load information variables. */
149$optpage_name = '';
150$optpage_file = '';
151$optpage_loader = '';
152
153/* Set the load information for each page. */
154switch ($optpage) {
91e0dccc 155 case SMOPT_PAGE_MAIN:
c1f7790a 156 break;
cbe5423b 157 case SMOPT_PAGE_PERSONAL:
a3439b27 158 $optpage_name = _("Personal Information");
08185f2a 159 $optpage_file = SM_PATH . 'include/options/personal.php';
a3439b27 160 $optpage_loader = 'load_optpage_data_personal';
161 $optpage_loadhook = 'optpage_loadhook_personal';
cbe5423b 162 break;
163 case SMOPT_PAGE_DISPLAY:
164 $optpage_name = _("Display Preferences");
08185f2a 165 $optpage_file = SM_PATH . 'include/options/display.php';
cbe5423b 166 $optpage_loader = 'load_optpage_data_display';
a3439b27 167 $optpage_loadhook = 'optpage_loadhook_display';
cbe5423b 168 break;
169 case SMOPT_PAGE_HIGHLIGHT:
170 $optpage_name = _("Message Highlighting");
08185f2a 171 $optpage_file = SM_PATH . 'include/options/highlight.php';
cbe5423b 172 $optpage_loader = 'load_optpage_data_highlight';
a3439b27 173 $optpage_loadhook = 'optpage_loadhook_highlight';
cbe5423b 174 break;
175 case SMOPT_PAGE_FOLDER:
176 $optpage_name = _("Folder Preferences");
08185f2a 177 $optpage_file = SM_PATH . 'include/options/folder.php';
cbe5423b 178 $optpage_loader = 'load_optpage_data_folder';
a3439b27 179 $optpage_loadhook = 'optpage_loadhook_folder';
cbe5423b 180 break;
181 case SMOPT_PAGE_ORDER:
182 $optpage_name = _("Index Order");
08185f2a 183 $optpage_file = SM_PATH . 'include/options/order.php';
cbe5423b 184 $optpage_loader = 'load_optpage_data_order';
a3439b27 185 $optpage_loadhook = 'optpage_loadhook_order';
cbe5423b 186 break;
2fad95fa 187 default: do_hook('optpage_set_loadinfo');
cbe5423b 188}
189
190/**********************************************************/
191/*** Second, load the option information for this page. ***/
192/**********************************************************/
193
a32985a5 194if ( !@is_file( $optpage_file ) ) {
c1f7790a 195 $optpage = SMOPT_PAGE_MAIN;
196} else if ($optpage != SMOPT_PAGE_MAIN ) {
cbe5423b 197 /* Include the file for this optionpage. */
91e0dccc 198
cbe5423b 199 require_once($optpage_file);
200
201 /* Assemble the data for this option page. */
202 $optpage_data = array();
203 $optpage_data = $optpage_loader();
a3439b27 204 do_hook($optpage_loadhook);
cbe5423b 205 $optpage_data['options'] =
206 create_option_groups($optpage_data['grps'], $optpage_data['vals']);
207}
208
209/***********************************************************/
210/*** Next, process anything that needs to be processed. ***/
211/***********************************************************/
212
288df1a0 213$optpage_save_error=array();
214
cc61478a 215if ( isset( $optpage_data ) ) {
216 switch ($optmode) {
217 case SMOPT_MODE_SUBMIT:
218 $max_refresh = process_optionmode_submit($optpage, $optpage_data);
219 break;
220 case SMOPT_MODE_LINK:
221 $max_refresh = process_optionmode_link($optpage, $optpage_data);
222 break;
223 }
cbe5423b 224}
cbe5423b 225
226$optpage_title = _("Options");
227if (isset($optpage_name) && ($optpage_name != '')) {
228 $optpage_title .= " - $optpage_name";
229}
f740c049 230
cbe5423b 231/*******************************************************************/
232/* DO OLD SAVING OF SUBMITTED OPTIONS. THIS WILL BE REMOVED LATER. */
233/*******************************************************************/
234
235/* If in submit mode, select a save hook name and run it. */
7e235a1a 236if ($optmode == SMOPT_MODE_SUBMIT) {
cbe5423b 237 /* Select a save hook name. */
238 switch ($optpage) {
239 case SMOPT_PAGE_PERSONAL:
240 $save_hook_name = 'options_personal_save';
241 break;
242 case SMOPT_PAGE_DISPLAY:
243 $save_hook_name = 'options_display_save';
244 break;
245 case SMOPT_PAGE_FOLDER:
246 $save_hook_name = 'options_folder_save';
247 break;
91e0dccc 248 default:
cc61478a 249 $save_hook_name = 'options_save';
cbe5423b 250 break;
251 }
b5efadfa 252
cbe5423b 253 /* Run the options save hook. */
254 do_hook($save_hook_name);
255}
256
257/***************************************************************/
258/* Apply logic to decide what optpage we want to display next. */
259/***************************************************************/
260
261/* If this is the result of an option page being submitted, then */
262/* show the main page. Otherwise, show whatever page was called. */
263
264if ($optmode == SMOPT_MODE_SUBMIT) {
265 $optpage = SMOPT_PAGE_MAIN;
266}
267
268/***************************************************************/
269/* Finally, display whatever page we are supposed to show now. */
270/***************************************************************/
271
4081f486 272displayPageHeader($color, 'None', (isset($optpage_data['xtra']) ? $optpage_data['xtra'] : ''));
273
274echo html_tag( 'table', '', 'center', $color[0], 'width="95%" cellpadding="1" cellspacing="0" border="0"' ) . "\n" .
275 html_tag( 'tr' ) . "\n" .
276 html_tag( 'td', '', 'center' ) .
39bfea8f 277 "<b>$optpage_title</b><br />\n".
4081f486 278 html_tag( 'table', '', '', '', 'width="100%" cellpadding="5" cellspacing="0" border="0"' ) . "\n" .
279 html_tag( 'tr' ) . "\n" .
280 html_tag( 'td', '', 'center', $color[4] ) . "\n";
281
cbe5423b 282/*
283 * The main option page has a different layout then the rest of the option
284 * pages. Therefore, we create it here first, then the others below.
285 */
286if ($optpage == SMOPT_PAGE_MAIN) {
287 /**********************************************************/
288 /* First, display the results of a submission, if needed. */
289 /**********************************************************/
290 if ($optmode == SMOPT_MODE_SUBMIT) {
e362fff6 291 if (!isset($frame_top)) {
d03f3582 292 $frame_top = '_top';
293 }
288df1a0 294
295 if (isset($optpage_save_error) && $optpage_save_error!=array()) {
296 echo "<font color=\"$color[2]\"><b>" . _("Error(s) happened while saving your options") . "</b></font><br />\n";
297 echo "<ul>\n";
298 foreach ($optpage_save_error as $error_message) {
299 echo '<li><small>' . $error_message . "</small></li>\n";
300 }
301 echo "</ul>\n";
302 echo '<b>' . _("Some of your preference changes are not applied.") . "</b><br />\n";
303 } else {
304 /* Display a message indicating a successful save. */
39bfea8f 305 echo '<b>' . _("Successfully Saved Options") . ": $optpage_name</b><br />\n";
288df1a0 306 }
cbe5423b 307
308 /* If $max_refresh != SMOPT_REFRESH_NONE, provide a refresh link. */
88cb1b4d 309 if ( !isset( $max_refresh ) ) {
310 } else if ($max_refresh == SMOPT_REFRESH_FOLDERLIST) {
39bfea8f 311 echo '<a href="../src/left_main.php" target="left">' . _("Refresh Folder List") . '</a><br />';
cbe5423b 312 } else if ($max_refresh) {
39bfea8f 313 echo '<a href="../src/webmail.php?right_frame=options.php" target="' . $frame_top . '">' . _("Refresh Page") . '</a><br />';
849bdf42 314 }
849bdf42 315 }
cbe5423b 316 /******************************************/
317 /* Build our array of Option Page Blocks. */
318 /******************************************/
319 $optpage_blocks = array();
849bdf42 320
321 /* Build a section for Personal Options. */
cbe5423b 322 $optpage_blocks[] = array(
849bdf42 323 'name' => _("Personal Information"),
cbe5423b 324 'url' => 'options.php?optpage=' . SMOPT_PAGE_PERSONAL,
849bdf42 325 'desc' => _("This contains personal information about yourself such as your name, your email address, etc."),
326 'js' => false
327 );
328
329 /* Build a section for Display Options. */
cbe5423b 330 $optpage_blocks[] = array(
849bdf42 331 'name' => _("Display Preferences"),
cbe5423b 332 'url' => 'options.php?optpage=' . SMOPT_PAGE_DISPLAY,
849bdf42 333 'desc' => _("You can change the way that SquirrelMail looks and displays information to you, such as the colors, the language, and other settings."),
334 'js' => false
335 );
336
337 /* Build a section for Message Highlighting Options. */
cbe5423b 338 $optpage_blocks[] = array(
849bdf42 339 'name' =>_("Message Highlighting"),
340 'url' => 'options_highlight.php',
99aaff8b 341 'desc' =>_("Based upon given criteria, incoming messages can have different background colors in the message list. This helps to easily distinguish who the messages are from, especially for mailing lists."),
849bdf42 342 'js' => false
343 );
344
345 /* Build a section for Folder Options. */
cbe5423b 346 $optpage_blocks[] = array(
849bdf42 347 'name' => _("Folder Preferences"),
cbe5423b 348 'url' => 'options.php?optpage=' . SMOPT_PAGE_FOLDER,
849bdf42 349 'desc' => _("These settings change the way your folders are displayed and manipulated."),
350 'js' => false
351 );
352
353 /* Build a section for Index Order Options. */
cbe5423b 354 $optpage_blocks[] = array(
849bdf42 355 'name' => _("Index Order"),
356 'url' => 'options_order.php',
8aedb8c7 357 'desc' => _("The order of the message index can be rearranged and changed to contain the headers in any order you want."),
849bdf42 358 'js' => false
359 );
cbe5423b 360
849bdf42 361 /* Build a section for plugins wanting to register an optionpage. */
cbe5423b 362 do_hook('optpage_register_block');
849bdf42 363
364 /*****************************************************/
365 /* Let's sort Javascript Option Pages to the bottom. */
366 /*****************************************************/
cbe5423b 367 $js_optpage_blocks = array();
368 $reg_optpage_blocks = array();
369 foreach ($optpage_blocks as $cur_optpage) {
812e328a 370 if (!isset($cur_optpage['js']) || !$cur_optpage['js']) {
cbe5423b 371 $reg_optpage_blocks[] = $cur_optpage;
23d6bd09 372 } else if ($javascript_on == SMPREF_JS_ON) {
cbe5423b 373 $js_optpage_blocks[] = $cur_optpage;
849bdf42 374 }
375 }
cbe5423b 376 $optpage_blocks = array_merge($reg_optpage_blocks, $js_optpage_blocks);
849bdf42 377
378 /********************************************/
379 /* Now, print out each option page section. */
380 /********************************************/
381 $first_optpage = false;
545238b1 382 echo html_tag( 'table', '', '', $color[4], 'width="100%" cellpadding="0" cellspacing="5" border="0"' ) . "\n" .
383 html_tag( 'tr' ) . "\n" .
384 html_tag( 'td', '', 'left', '', 'valign="top"' ) .
385 html_tag( 'table', '', '', $color[4], 'width="100%" cellpadding="3" cellspacing="0" border="0"' ) . "\n" .
386 html_tag( 'tr' ) . "\n" .
387 html_tag( 'td', '', 'left' );
cbe5423b 388 foreach ($optpage_blocks as $next_optpage) {
849bdf42 389 if ($first_optpage == false) {
390 $first_optpage = $next_optpage;
391 } else {
392 print_optionpages_row($first_optpage, $next_optpage);
393 $first_optpage = false;
394 }
395 }
396
397 if ($first_optpage != false) {
398 print_optionpages_row($first_optpage);
399 }
400
545238b1 401 echo "</td></tr></table></td></tr></table>\n";
dfec863e 402
849bdf42 403 do_hook('options_link_and_description');
404
cbe5423b 405
406/*************************************************************************/
407/* If we are not looking at the main option page, display the page here. */
408/*************************************************************************/
409} else {
62366261 410 echo addForm('options.php', 'POST', 'f')
cbe5423b 411 . create_optpage_element($optpage)
bd9bbfef 412 . create_optmode_element(SMOPT_MODE_SUBMIT)
545238b1 413 . html_tag( 'table', '', '', '', 'width="100%" cellpadding="2" cellspacing="0" border="0"' ) . "\n"
414 . html_tag( 'tr' ) . "\n"
415 . html_tag( 'td', '', 'left' ) . "\n";
cbe5423b 416
417 /* Output the option groups for this page. */
418 print_option_groups($optpage_data['options']);
419
cbe5423b 420 /* Set the inside_hook_name and submit_name. */
421 switch ($optpage) {
422 case SMOPT_PAGE_PERSONAL:
423 $inside_hook_name = 'options_personal_inside';
424 $bottom_hook_name = 'options_personal_bottom';
425 $submit_name = 'submit_personal';
426 break;
427 case SMOPT_PAGE_DISPLAY:
428 $inside_hook_name = 'options_display_inside';
429 $bottom_hook_name = 'options_display_bottom';
430 $submit_name = 'submit_display';
431 break;
432 case SMOPT_PAGE_HIGHLIGHT:
433 $inside_hook_name = 'options_highlight_inside';
2fad95fa 434 $bottom_hook_name = 'options_highlight_bottom';
cbe5423b 435 $submit_name = 'submit_highlight';
436 break;
437 case SMOPT_PAGE_FOLDER:
438 $inside_hook_name = 'options_folder_inside';
2fad95fa 439 $bottom_hook_name = 'options_folder_bottom';
cbe5423b 440 $submit_name = 'submit_folder';
441 break;
442 case SMOPT_PAGE_ORDER:
443 $inside_hook_name = 'options_order_inside';
444 $bottom_hook_name = 'options_order_bottom';
445 $submit_name = 'submit_order';
446 break;
447 default:
448 $inside_hook_name = '';
449 $bottom_hook_name = '';
450 $submit_name = 'submit';
451 }
452
453 /* If it is not empty, trigger the inside hook. */
454 if ($inside_hook_name != '') {
91e0dccc 455 do_hook($inside_hook_name);
cbe5423b 456 }
457
458 /* Spit out a submit button. */
459 OptionSubmit($submit_name);
545238b1 460 echo '</td></tr></table></form>';
cbe5423b 461
462 /* If it is not empty, trigger the bottom hook. */
463 if ($bottom_hook_name != '') {
91e0dccc 464 do_hook($bottom_hook_name);
cbe5423b 465 }
466}
dcc1cc82 467?>
39bfea8f 468</td></tr>
469</table>
470</td></tr>
471</table>
91e0dccc 472</body></html>