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