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