Added support for using Squirrelmail without frames
[squirrelmail.git] / src / options.php
CommitLineData
59177427 1<?php
d3cdb279 2
35586184 3/**
4 * options.php
5 *
76911253 6 * Copyright (c) 1999-2003 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 *
12 * $Id$
8f6f9ba5 13 * @package squirrelmail
35586184 14 */
cbe5423b 15
8f6f9ba5 16/** Path for SquirrelMail required files. */
86725763 17define('SM_PATH','../');
18
19/* SquirrelMail required files. */
08185f2a 20require_once(SM_PATH . 'include/validate.php');
1e12d1ff 21require_once(SM_PATH . 'functions/global.php');
86725763 22require_once(SM_PATH . 'functions/display_messages.php');
23require_once(SM_PATH . 'functions/imap.php');
86725763 24require_once(SM_PATH . 'functions/options.php');
25require_once(SM_PATH . 'functions/strings.php');
26require_once(SM_PATH . 'functions/html.php');
cbe5423b 27
cbe5423b 28/*********************************/
29/*** Build the resultant page. ***/
30/*********************************/
31
cbe5423b 32define('SMOPT_MODE_DISPLAY', 'display');
33define('SMOPT_MODE_SUBMIT', 'submit');
34define('SMOPT_MODE_LINK', 'link');
35
36define('SMOPT_PAGE_MAIN', 'main');
37define('SMOPT_PAGE_PERSONAL', 'personal');
38define('SMOPT_PAGE_DISPLAY', 'display');
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";
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/*
141 * First, set the load information for each option page.
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) {
c1f7790a 151 case SMOPT_PAGE_MAIN:
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;
165 case SMOPT_PAGE_HIGHLIGHT:
166 $optpage_name = _("Message Highlighting");
08185f2a 167 $optpage_file = SM_PATH . 'include/options/highlight.php';
cbe5423b 168 $optpage_loader = 'load_optpage_data_highlight';
a3439b27 169 $optpage_loadhook = 'optpage_loadhook_highlight';
cbe5423b 170 break;
171 case SMOPT_PAGE_FOLDER:
172 $optpage_name = _("Folder Preferences");
08185f2a 173 $optpage_file = SM_PATH . 'include/options/folder.php';
cbe5423b 174 $optpage_loader = 'load_optpage_data_folder';
a3439b27 175 $optpage_loadhook = 'optpage_loadhook_folder';
cbe5423b 176 break;
177 case SMOPT_PAGE_ORDER:
178 $optpage_name = _("Index Order");
08185f2a 179 $optpage_file = SM_PATH . 'include/options/order.php';
cbe5423b 180 $optpage_loader = 'load_optpage_data_order';
a3439b27 181 $optpage_loadhook = 'optpage_loadhook_order';
cbe5423b 182 break;
2fad95fa 183 default: do_hook('optpage_set_loadinfo');
cbe5423b 184}
185
186/**********************************************************/
187/*** Second, load the option information for this page. ***/
188/**********************************************************/
189
a32985a5 190if ( !@is_file( $optpage_file ) ) {
c1f7790a 191 $optpage = SMOPT_PAGE_MAIN;
192} else if ($optpage != SMOPT_PAGE_MAIN ) {
cbe5423b 193 /* Include the file for this optionpage. */
c1f7790a 194
cbe5423b 195 require_once($optpage_file);
196
197 /* Assemble the data for this option page. */
198 $optpage_data = array();
199 $optpage_data = $optpage_loader();
a3439b27 200 do_hook($optpage_loadhook);
cbe5423b 201 $optpage_data['options'] =
202 create_option_groups($optpage_data['grps'], $optpage_data['vals']);
203}
204
205/***********************************************************/
206/*** Next, process anything that needs to be processed. ***/
207/***********************************************************/
208
cc61478a 209if ( isset( $optpage_data ) ) {
210 switch ($optmode) {
211 case SMOPT_MODE_SUBMIT:
212 $max_refresh = process_optionmode_submit($optpage, $optpage_data);
213 break;
214 case SMOPT_MODE_LINK:
215 $max_refresh = process_optionmode_link($optpage, $optpage_data);
216 break;
217 }
cbe5423b 218}
cbe5423b 219
220$optpage_title = _("Options");
221if (isset($optpage_name) && ($optpage_name != '')) {
222 $optpage_title .= " - $optpage_name";
223}
f740c049 224
cbe5423b 225/*******************************************************************/
226/* DO OLD SAVING OF SUBMITTED OPTIONS. THIS WILL BE REMOVED LATER. */
227/*******************************************************************/
228
229/* If in submit mode, select a save hook name and run it. */
7e235a1a 230if ($optmode == SMOPT_MODE_SUBMIT) {
cbe5423b 231 /* Select a save hook name. */
232 switch ($optpage) {
233 case SMOPT_PAGE_PERSONAL:
234 $save_hook_name = 'options_personal_save';
235 break;
236 case SMOPT_PAGE_DISPLAY:
237 $save_hook_name = 'options_display_save';
238 break;
239 case SMOPT_PAGE_FOLDER:
240 $save_hook_name = 'options_folder_save';
241 break;
cc61478a 242 default:
243 $save_hook_name = 'options_save';
cbe5423b 244 break;
245 }
b5efadfa 246
cbe5423b 247 /* Run the options save hook. */
248 do_hook($save_hook_name);
249}
250
251/***************************************************************/
252/* Apply logic to decide what optpage we want to display next. */
253/***************************************************************/
254
255/* If this is the result of an option page being submitted, then */
256/* show the main page. Otherwise, show whatever page was called. */
257
258if ($optmode == SMOPT_MODE_SUBMIT) {
259 $optpage = SMOPT_PAGE_MAIN;
260}
261
262/***************************************************************/
263/* Finally, display whatever page we are supposed to show now. */
264/***************************************************************/
265
4081f486 266displayPageHeader($color, 'None', (isset($optpage_data['xtra']) ? $optpage_data['xtra'] : ''));
267
268echo html_tag( 'table', '', 'center', $color[0], 'width="95%" cellpadding="1" cellspacing="0" border="0"' ) . "\n" .
269 html_tag( 'tr' ) . "\n" .
270 html_tag( 'td', '', 'center' ) .
271 "<b>$optpage_title</b><br>\n".
272 html_tag( 'table', '', '', '', 'width="100%" cellpadding="5" cellspacing="0" border="0"' ) . "\n" .
273 html_tag( 'tr' ) . "\n" .
274 html_tag( 'td', '', 'center', $color[4] ) . "\n";
275
cbe5423b 276/*
277 * The main option page has a different layout then the rest of the option
278 * pages. Therefore, we create it here first, then the others below.
279 */
280if ($optpage == SMOPT_PAGE_MAIN) {
281 /**********************************************************/
282 /* First, display the results of a submission, if needed. */
283 /**********************************************************/
284 if ($optmode == SMOPT_MODE_SUBMIT) {
e362fff6 285 if (!isset($frame_top)) {
d03f3582 286 $frame_top = '_top';
287 }
cbe5423b 288 /* Display a message indicating a successful save. */
545238b1 289 echo '<b>' . _("Successfully Saved Options") . ": $optpage_name</b><br>\n";
cbe5423b 290
291 /* If $max_refresh != SMOPT_REFRESH_NONE, provide a refresh link. */
88cb1b4d 292 if ( !isset( $max_refresh ) ) {
293 } else if ($max_refresh == SMOPT_REFRESH_FOLDERLIST) {
1d80c108 294 if ($use_frames)
295 echo '<a href="../src/left_main.php" target="left">' . _("Refresh Folder List") . '</a><br>';
296 else
297 echo '<a href="../src/options.php">' . _("Refresh Folder List") . '</a><br>';
cbe5423b 298 } else if ($max_refresh) {
545238b1 299 echo '<a href="../src/webmail.php?right_frame=options.php" target="' . $frame_top . '">' . _("Refresh Page") . '</a><br>';
849bdf42 300 }
849bdf42 301 }
cbe5423b 302 /******************************************/
303 /* Build our array of Option Page Blocks. */
304 /******************************************/
305 $optpage_blocks = array();
849bdf42 306
307 /* Build a section for Personal Options. */
cbe5423b 308 $optpage_blocks[] = array(
849bdf42 309 'name' => _("Personal Information"),
cbe5423b 310 'url' => 'options.php?optpage=' . SMOPT_PAGE_PERSONAL,
849bdf42 311 'desc' => _("This contains personal information about yourself such as your name, your email address, etc."),
312 'js' => false
313 );
314
315 /* Build a section for Display Options. */
cbe5423b 316 $optpage_blocks[] = array(
849bdf42 317 'name' => _("Display Preferences"),
cbe5423b 318 'url' => 'options.php?optpage=' . SMOPT_PAGE_DISPLAY,
849bdf42 319 'desc' => _("You can change the way that SquirrelMail looks and displays information to you, such as the colors, the language, and other settings."),
320 'js' => false
321 );
322
323 /* Build a section for Message Highlighting Options. */
cbe5423b 324 $optpage_blocks[] = array(
849bdf42 325 'name' =>_("Message Highlighting"),
326 'url' => 'options_highlight.php',
327 '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."),
328 'js' => false
329 );
330
331 /* Build a section for Folder Options. */
cbe5423b 332 $optpage_blocks[] = array(
849bdf42 333 'name' => _("Folder Preferences"),
cbe5423b 334 'url' => 'options.php?optpage=' . SMOPT_PAGE_FOLDER,
849bdf42 335 'desc' => _("These settings change the way your folders are displayed and manipulated."),
336 'js' => false
337 );
338
339 /* Build a section for Index Order Options. */
cbe5423b 340 $optpage_blocks[] = array(
849bdf42 341 'name' => _("Index Order"),
342 'url' => 'options_order.php',
8aedb8c7 343 'desc' => _("The order of the message index can be rearranged and changed to contain the headers in any order you want."),
849bdf42 344 'js' => false
345 );
cbe5423b 346
849bdf42 347 /* Build a section for plugins wanting to register an optionpage. */
cbe5423b 348 do_hook('optpage_register_block');
849bdf42 349
350 /*****************************************************/
351 /* Let's sort Javascript Option Pages to the bottom. */
352 /*****************************************************/
cbe5423b 353 $js_optpage_blocks = array();
354 $reg_optpage_blocks = array();
355 foreach ($optpage_blocks as $cur_optpage) {
812e328a 356 if (!isset($cur_optpage['js']) || !$cur_optpage['js']) {
cbe5423b 357 $reg_optpage_blocks[] = $cur_optpage;
23d6bd09 358 } else if ($javascript_on == SMPREF_JS_ON) {
cbe5423b 359 $js_optpage_blocks[] = $cur_optpage;
849bdf42 360 }
361 }
cbe5423b 362 $optpage_blocks = array_merge($reg_optpage_blocks, $js_optpage_blocks);
849bdf42 363
364 /********************************************/
365 /* Now, print out each option page section. */
366 /********************************************/
367 $first_optpage = false;
545238b1 368 echo html_tag( 'table', '', '', $color[4], 'width="100%" cellpadding="0" cellspacing="5" border="0"' ) . "\n" .
369 html_tag( 'tr' ) . "\n" .
370 html_tag( 'td', '', 'left', '', 'valign="top"' ) .
371 html_tag( 'table', '', '', $color[4], 'width="100%" cellpadding="3" cellspacing="0" border="0"' ) . "\n" .
372 html_tag( 'tr' ) . "\n" .
373 html_tag( 'td', '', 'left' );
cbe5423b 374 foreach ($optpage_blocks as $next_optpage) {
849bdf42 375 if ($first_optpage == false) {
376 $first_optpage = $next_optpage;
377 } else {
378 print_optionpages_row($first_optpage, $next_optpage);
379 $first_optpage = false;
380 }
381 }
382
383 if ($first_optpage != false) {
384 print_optionpages_row($first_optpage);
385 }
386
545238b1 387 echo "</td></tr></table></td></tr></table>\n";
dfec863e 388
849bdf42 389 do_hook('options_link_and_description');
390
cbe5423b 391
392/*************************************************************************/
393/* If we are not looking at the main option page, display the page here. */
394/*************************************************************************/
395} else {
545238b1 396 echo '<form name="f" action="options.php" method="post"><br>' . "\n"
cbe5423b 397 . create_optpage_element($optpage)
bd9bbfef 398 . create_optmode_element(SMOPT_MODE_SUBMIT)
545238b1 399 . html_tag( 'table', '', '', '', 'width="100%" cellpadding="2" cellspacing="0" border="0"' ) . "\n"
400 . html_tag( 'tr' ) . "\n"
401 . html_tag( 'td', '', 'left' ) . "\n";
cbe5423b 402
403 /* Output the option groups for this page. */
404 print_option_groups($optpage_data['options']);
405
cbe5423b 406 /* Set the inside_hook_name and submit_name. */
407 switch ($optpage) {
408 case SMOPT_PAGE_PERSONAL:
409 $inside_hook_name = 'options_personal_inside';
410 $bottom_hook_name = 'options_personal_bottom';
411 $submit_name = 'submit_personal';
412 break;
413 case SMOPT_PAGE_DISPLAY:
414 $inside_hook_name = 'options_display_inside';
415 $bottom_hook_name = 'options_display_bottom';
416 $submit_name = 'submit_display';
417 break;
418 case SMOPT_PAGE_HIGHLIGHT:
419 $inside_hook_name = 'options_highlight_inside';
2fad95fa 420 $bottom_hook_name = 'options_highlight_bottom';
cbe5423b 421 $submit_name = 'submit_highlight';
422 break;
423 case SMOPT_PAGE_FOLDER:
424 $inside_hook_name = 'options_folder_inside';
2fad95fa 425 $bottom_hook_name = 'options_folder_bottom';
cbe5423b 426 $submit_name = 'submit_folder';
427 break;
428 case SMOPT_PAGE_ORDER:
429 $inside_hook_name = 'options_order_inside';
430 $bottom_hook_name = 'options_order_bottom';
431 $submit_name = 'submit_order';
432 break;
433 default:
434 $inside_hook_name = '';
435 $bottom_hook_name = '';
436 $submit_name = 'submit';
437 }
438
439 /* If it is not empty, trigger the inside hook. */
440 if ($inside_hook_name != '') {
441 do_hook($inside_hook_name);
442 }
443
444 /* Spit out a submit button. */
445 OptionSubmit($submit_name);
545238b1 446 echo '</td></tr></table></form>';
cbe5423b 447
448 /* If it is not empty, trigger the bottom hook. */
449 if ($bottom_hook_name != '') {
450 do_hook($bottom_hook_name);
451 }
452}
453
545238b1 454echo '</td></tr>' .
455 '</table>'.
456 '</td></tr>'.
1d80c108 457 '</table>';
e7db48af 458
1d80c108 459noframes_bottom();
460
461
462?>