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