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