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