Add FIXME
[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 *
4b5049de 9 * @copyright &copy; 1999-2007 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
ebd2391c 16/** This is the options page */
17define('PAGE_NAME', 'options');
18
30967a1e 19/**
202bcbcc 20 * Include the SquirrelMail initialization file.
30967a1e 21 */
202bcbcc 22require('../include/init.php');
86725763 23
24/* SquirrelMail required files. */
202bcbcc 25
26//include(SM_PATH . 'functions/imap_general.php');
27require_once(SM_PATH . 'functions/options.php');
28require_once(SM_PATH . 'functions/forms.php');
cbe5423b 29
cbe5423b 30/*********************************/
31/*** Build the resultant page. ***/
32/*********************************/
33
cbe5423b 34define('SMOPT_MODE_DISPLAY', 'display');
35define('SMOPT_MODE_SUBMIT', 'submit');
36define('SMOPT_MODE_LINK', 'link');
37
38define('SMOPT_PAGE_MAIN', 'main');
39define('SMOPT_PAGE_PERSONAL', 'personal');
40define('SMOPT_PAGE_DISPLAY', 'display');
5ed9d4fd 41define('SMOPT_PAGE_COMPOSE', 'compose');
cbe5423b 42define('SMOPT_PAGE_HIGHLIGHT', 'highlight');
43define('SMOPT_PAGE_FOLDER', 'folder');
44define('SMOPT_PAGE_ORDER', 'order');
45
8abb7e3a 46/**
47 * Save submitted options and calculate the most
48 * we need to refresh the page
49 *
50 * @param string $optpage The name of the page being submitted
51 * @param array $optpage_data An array of all the submitted options
52 *
53 * @return int The highest level of screen refresh needed per
54 * the options that were changed. This value will
55 * correspond to the SMOPT_REFRESH_* constants found
56 * in functions/options.php.
57 *
58 */
cbe5423b 59function process_optionmode_submit($optpage, $optpage_data) {
60 /* Initialize the maximum option refresh level. */
61 $max_refresh = SMOPT_REFRESH_NONE;
62
209e24bb 63
64
cbe5423b 65 /* Save each option in each option group. */
66 foreach ($optpage_data['options'] as $option_grp) {
67 foreach ($option_grp['options'] as $option) {
209e24bb 68
69 /* Special case: need to make sure emailaddress
70 * is saved if we use it as a test for ask_user_info */
71 global $ask_user_info;
72 if ( $optpage = SMOPT_PAGE_PERSONAL && $ask_user_info &&
73 $option->name == 'email_address' ) {
74 $option->setValue('');
75 }
76
534367eb 77 /* Remove Debug Mode Until Needed
cbe5423b 78 echo "name = '$option->name', "
79 . "value = '$option->value', "
6206f6c4 80 . "new_value = '$option->new_value'\n";
244a64a4 81//FIXME: NO HTML IN THE CORE!
39bfea8f 82 echo "<br />";
534367eb 83 */
cbe5423b 84 if ($option->changed()) {
85 $option->save();
86 $max_refresh = max($max_refresh, $option->refresh_level);
87 }
88 }
89 }
1e0628fb 90
cbe5423b 91 /* Return the max refresh level. */
92 return ($max_refresh);
93}
94
95function process_optionmode_link($optpage) {
96 /* There will be something here, later. */
97}
98
0b0e96c5 99
0b0e96c5 100
101/* ---------------------------- main ---------------------------- */
102
a32985a5 103/* get the globals that we may need */
1e12d1ff 104sqgetGlobalVar('optpage', $optpage);
5ccba4f3 105sqgetGlobalVar('optmode', $optmode, SQ_FORM);
1e12d1ff 106sqgetGlobalVar('optpage_data',$optpage_data, SQ_POST);
a32985a5 107/* end of getting globals */
108
cbe5423b 109/* Make sure we have an Option Page set. Default to main. */
c1f7790a 110if ( !isset($optpage) || $optpage == '' ) {
111 $optpage = SMOPT_PAGE_MAIN;
112} else {
113 $optpage = strip_tags( $optpage );
cbe5423b 114}
115
116/* Make sure we have an Option Mode set. Default to display. */
117if (!isset($optmode)) {
118 $optmode = SMOPT_MODE_DISPLAY;
119}
120
0b0e96c5 121/*
91e0dccc 122 * First, set the load information for each option page.
0b0e96c5 123 */
cbe5423b 124
125/* Initialize load information variables. */
126$optpage_name = '';
127$optpage_file = '';
128$optpage_loader = '';
129
130/* Set the load information for each page. */
131switch ($optpage) {
91e0dccc 132 case SMOPT_PAGE_MAIN:
c1f7790a 133 break;
cbe5423b 134 case SMOPT_PAGE_PERSONAL:
a3439b27 135 $optpage_name = _("Personal Information");
08185f2a 136 $optpage_file = SM_PATH . 'include/options/personal.php';
a3439b27 137 $optpage_loader = 'load_optpage_data_personal';
138 $optpage_loadhook = 'optpage_loadhook_personal';
cbe5423b 139 break;
140 case SMOPT_PAGE_DISPLAY:
141 $optpage_name = _("Display Preferences");
08185f2a 142 $optpage_file = SM_PATH . 'include/options/display.php';
cbe5423b 143 $optpage_loader = 'load_optpage_data_display';
a3439b27 144 $optpage_loadhook = 'optpage_loadhook_display';
cbe5423b 145 break;
5ed9d4fd 146 case SMOPT_PAGE_COMPOSE:
147 $optpage_name = _("Compose Preferences");
148 $optpage_file = SM_PATH . 'include/options/compose.php';
149 $optpage_loader = 'load_optpage_data_compose';
150 $optpage_loadhook = 'optpage_loadhook_compose';
151 break;
cbe5423b 152 case SMOPT_PAGE_HIGHLIGHT:
153 $optpage_name = _("Message Highlighting");
08185f2a 154 $optpage_file = SM_PATH . 'include/options/highlight.php';
cbe5423b 155 $optpage_loader = 'load_optpage_data_highlight';
a3439b27 156 $optpage_loadhook = 'optpage_loadhook_highlight';
cbe5423b 157 break;
158 case SMOPT_PAGE_FOLDER:
159 $optpage_name = _("Folder Preferences");
08185f2a 160 $optpage_file = SM_PATH . 'include/options/folder.php';
cbe5423b 161 $optpage_loader = 'load_optpage_data_folder';
a3439b27 162 $optpage_loadhook = 'optpage_loadhook_folder';
cbe5423b 163 break;
164 case SMOPT_PAGE_ORDER:
165 $optpage_name = _("Index Order");
08185f2a 166 $optpage_file = SM_PATH . 'include/options/order.php';
cbe5423b 167 $optpage_loader = 'load_optpage_data_order';
a3439b27 168 $optpage_loadhook = 'optpage_loadhook_order';
cbe5423b 169 break;
6e515418 170 default: do_hook('optpage_set_loadinfo', $null);
cbe5423b 171}
172
173/**********************************************************/
174/*** Second, load the option information for this page. ***/
175/**********************************************************/
176
a32985a5 177if ( !@is_file( $optpage_file ) ) {
c1f7790a 178 $optpage = SMOPT_PAGE_MAIN;
64033e1c 179} elseif ($optpage != SMOPT_PAGE_MAIN ) {
cbe5423b 180 /* Include the file for this optionpage. */
91e0dccc 181
cbe5423b 182 require_once($optpage_file);
183
184 /* Assemble the data for this option page. */
185 $optpage_data = array();
186 $optpage_data = $optpage_loader();
6e515418 187 do_hook($optpage_loadhook, $null);
64033e1c 188 $optpage_data['options'] = create_option_groups($optpage_data['grps'], $optpage_data['vals']);
cbe5423b 189}
190
191/***********************************************************/
192/*** Next, process anything that needs to be processed. ***/
193/***********************************************************/
194
288df1a0 195$optpage_save_error=array();
196
cc61478a 197if ( isset( $optpage_data ) ) {
198 switch ($optmode) {
199 case SMOPT_MODE_SUBMIT:
200 $max_refresh = process_optionmode_submit($optpage, $optpage_data);
201 break;
202 case SMOPT_MODE_LINK:
203 $max_refresh = process_optionmode_link($optpage, $optpage_data);
204 break;
205 }
cbe5423b 206}
cbe5423b 207
2de8b87f 208$optpage_title = _("Options");
209if (isset($optpage_name) && ($optpage_name != '')) {
210 $optpage_title .= " - $optpage_name";
211}
212
cbe5423b 213/*******************************************************************/
214/* DO OLD SAVING OF SUBMITTED OPTIONS. THIS WILL BE REMOVED LATER. */
215/*******************************************************************/
216
21f6d2ea 217//FIXME: let's remove these finally in 1.5.2..... but first, are there any plugins using them?
cbe5423b 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;
10ad5e30 228 case SMOPT_PAGE_COMPOSE:
229 $save_hook_name = 'options_compose_save';
230 break;
cbe5423b 231 case SMOPT_PAGE_FOLDER:
232 $save_hook_name = 'options_folder_save';
233 break;
91e0dccc 234 default:
cc61478a 235 $save_hook_name = 'options_save';
cbe5423b 236 break;
237 }
b5efadfa 238
cbe5423b 239 /* Run the options save hook. */
6e515418 240 do_hook($save_hook_name, $null);
cbe5423b 241}
242
243/***************************************************************/
244/* Apply logic to decide what optpage we want to display next. */
245/***************************************************************/
246
247/* If this is the result of an option page being submitted, then */
248/* show the main page. Otherwise, show whatever page was called. */
249
250if ($optmode == SMOPT_MODE_SUBMIT) {
251 $optpage = SMOPT_PAGE_MAIN;
252}
253
2de8b87f 254/***************************************************************/
255/* Finally, display whatever page we are supposed to show now. */
256/***************************************************************/
257
876fdb60 258displayPageHeader($color, null, (isset($optpage_data['xtra']) ? $optpage_data['xtra'] : ''));
2de8b87f 259
2de8b87f 260/*
261 * The main option page has a different layout then the rest of the option
262 * pages. Therefore, we create it here first, then the others below.
263 */
264if ($optpage == SMOPT_PAGE_MAIN) {
265 /**********************************************************/
266 /* First, display the results of a submission, if needed. */
267 /**********************************************************/
268 $notice = '';
269 if ($optmode == SMOPT_MODE_SUBMIT) {
270 if (!isset($frame_top)) {
271 $frame_top = '_top';
272 }
273
274 if (isset($optpage_save_error) && $optpage_save_error!=array()) {
8befffa8 275//FIXME: REMOVE HTML FROM CORE
64033e1c 276 $notice = _("Error(s) occurred while saving your options") . "<br />\n<ul>\n";
2de8b87f 277 foreach ($optpage_save_error as $error_message) {
278 $notice.= '<li><small>' . $error_message . "</small></li>\n";
279 }
64033e1c 280 $notice.= "</ul>\n" . _("Some of your preference changes were not applied.") . "\n";
2de8b87f 281 } else {
282 /* Display a message indicating a successful save. */
64033e1c 283 $notice = _("Successfully Saved Options") . ": $optpage_name</b><br />\n";
2de8b87f 284 }
285
286 /* If $max_refresh != SMOPT_REFRESH_NONE, provide a refresh link. */
287 if ( !isset( $max_refresh ) ) {
288 } else if ($max_refresh == SMOPT_REFRESH_FOLDERLIST) {
8befffa8 289//FIXME: REMOVE HTML FROM CORE - when migrating, keep in mind that the javascript below assumes the folder list is in a separate sibling frame under the same parent, and it is called "left"
290 if (checkForJavascript()) {
291 $notice .= sprintf(_("Folder list should automatically %srefresh%s."), '<a href="../src/left_main.php" target="left">', '</a>') . '<br /><script type="text/javascript">' . "\n<!--\nparent.left.location = '../src/left_main.php';\n// -->\n</script>\n";
292 } else {
293 $notice .= '<a href="../src/left_main.php" target="left">' . _("Refresh Folder List") . '</a><br />';
294 }
2de8b87f 295 } else if ($max_refresh) {
8befffa8 296 if (checkForJavascript()) {
297//FIXME: REMOVE HTML FROM CORE - when migrating, keep in mind that the javascript below assumes the parent is the top-most SM frame and is what should be refreshed with webmail.php
298 $notice .= sprintf(_("This page should automatically %srefresh%s."), '<a href="../src/webmail.php?right_frame=options.php" target="' . $frame_top . '">', '</a>') . '<br /><script type="text/javascript">' . "\n<!--\nparent.location = '../src/webmail.php?right_frame=options.php';\n// -->\n</script>\n";
299 } else {
300 $notice .= '<a href="../src/webmail.php?right_frame=options.php" target="' . $frame_top . '">' . _("Refresh Page") . '</a><br />';
301 }
2de8b87f 302 }
303 }
64033e1c 304
305 if (!empty($notice)) {
203f4ab0 306 $oTemplate->assign('note', $notice);
64033e1c 307 $oTemplate->display('note.tpl');
308 }
309
2de8b87f 310 /******************************************/
311 /* Build our array of Option Page Blocks. */
312 /******************************************/
313 $optpage_blocks = array();
314
315 /* Build a section for Personal Options. */
316 $optpage_blocks[] = array(
317 'name' => _("Personal Information"),
318 'url' => 'options.php?optpage=' . SMOPT_PAGE_PERSONAL,
319 'desc' => _("This contains personal information about yourself such as your name, your email address, etc."),
320 'js' => false
321 );
322
323 /* Build a section for Display Options. */
324 $optpage_blocks[] = array(
325 'name' => _("Display Preferences"),
326 'url' => 'options.php?optpage=' . SMOPT_PAGE_DISPLAY,
327 'desc' => _("You can change the way that SquirrelMail looks and displays information to you, such as the colors, the language, and other settings."),
328 'js' => false
329 );
330
331 /* Build a section for Message Highlighting Options. */
332 $optpage_blocks[] = array(
333 'name' =>_("Message Highlighting"),
334 'url' => 'options_highlight.php',
335 '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."),
336 'js' => false
337 );
338
339 /* Build a section for Folder Options. */
340 $optpage_blocks[] = array(
341 'name' => _("Folder Preferences"),
342 'url' => 'options.php?optpage=' . SMOPT_PAGE_FOLDER,
343 'desc' => _("These settings change the way your folders are displayed and manipulated."),
344 'js' => false
345 );
346
347 /* Build a section for Index Order Options. */
348 $optpage_blocks[] = array(
349 'name' => _("Index Order"),
350 'url' => 'options_order.php',
351 'desc' => _("The order of the message index can be rearranged and changed to contain the headers in any order you want."),
352 'js' => false
353 );
354
355 /* Build a section for Compose Options. */
356 $optpage_blocks[] = array(
357 'name' => _("Compose Preferences"),
358 'url' => 'options.php?optpage=' . SMOPT_PAGE_COMPOSE,
359 'desc' => _("Control the behaviour and layout of writing new mail messages, replying to and forwarding messages."),
360 'js' => false
361 );
362
363 /* Build a section for plugins wanting to register an optionpage. */
6e515418 364 do_hook('optpage_register_block', $null);
2de8b87f 365
366 /*****************************************************/
367 /* Let's sort Javascript Option Pages to the bottom. */
368 /*****************************************************/
369 $js_optpage_blocks = array();
370 $reg_optpage_blocks = array();
371 foreach ($optpage_blocks as $cur_optpage) {
372 if (!isset($cur_optpage['js']) || !$cur_optpage['js']) {
373 $reg_optpage_blocks[] = $cur_optpage;
457e8593 374 } else if (checkForJavascript()) {
2de8b87f 375 $js_optpage_blocks[] = $cur_optpage;
376 }
377 }
378 $optpage_blocks = array_merge($reg_optpage_blocks, $js_optpage_blocks);
379
380 /********************************************/
381 /* Now, print out each option page section. */
382 /********************************************/
64033e1c 383 $oTemplate->assign('page_title', $optpage_title);
384 $oTemplate->assign('options', $optpage_blocks);
2de8b87f 385
2de8b87f 386 $oTemplate->display('option_groups.tpl');
64033e1c 387
6e515418 388 do_hook('options_link_and_description', $null);
cbe5423b 389
cbe5423b 390
2de8b87f 391/*************************************************************************/
392/* If we are not looking at the main option page, display the page here. */
393/*************************************************************************/
394} else {
fcc81e7a 395 /* Set the bottom_hook_name and submit_name. */
2de8b87f 396 switch ($optpage) {
397 case SMOPT_PAGE_PERSONAL:
2de8b87f 398 $bottom_hook_name = 'options_personal_bottom';
399 $submit_name = 'submit_personal';
400 break;
401 case SMOPT_PAGE_DISPLAY:
2de8b87f 402 $bottom_hook_name = 'options_display_bottom';
403 $submit_name = 'submit_display';
404 break;
405 case SMOPT_PAGE_COMPOSE:
2de8b87f 406 $bottom_hook_name = 'options_compose_bottom';
407 $submit_name = 'submit_compose';
408 break;
409 case SMOPT_PAGE_HIGHLIGHT:
2de8b87f 410 $bottom_hook_name = 'options_highlight_bottom';
411 $submit_name = 'submit_highlight';
412 break;
413 case SMOPT_PAGE_FOLDER:
2de8b87f 414 $bottom_hook_name = 'options_folder_bottom';
415 $submit_name = 'submit_folder';
416 break;
417 case SMOPT_PAGE_ORDER:
2de8b87f 418 $bottom_hook_name = 'options_order_bottom';
419 $submit_name = 'submit_order';
420 break;
421 default:
2de8b87f 422 $bottom_hook_name = '';
423 $submit_name = 'submit';
424 }
425
64033e1c 426 // Begin output form
427 echo addForm('options.php', 'post', 'f')
428 . create_optpage_element($optpage)
429 . create_optmode_element(SMOPT_MODE_SUBMIT);
430
64033e1c 431 // This is the only variable that is needed by *just* the template.
203f4ab0 432 $oTemplate->assign('options', $optpage_data['options']);
64033e1c 433
ad3aa533 434 global $ask_user_info, $org_name;
75b4ac6f 435 if ( $optpage == SMOPT_PAGE_PERSONAL && $ask_user_info
209e24bb 436 && getPref($data_dir, $username,'email_address') == "" ) {
437 $oTemplate->assign('topmessage',
ad3aa533 438 sprintf(_("Welcome to %s. Please supply your full name and email address."), $org_name) );
209e24bb 439 }
440
fcc81e7a 441 // These variables are not specifically needed by the template,
442 // but they are relevant to the page being built, so we'll add
443 // them in case some plugin is modifying the page, etc....
444 //
64033e1c 445 $oTemplate->assign('max_refresh', isset($max_refresh) ? $max_refresh : NULL);
446 $oTemplate->assign('page_title', $optpage_title);
fcc81e7a 447 $oTemplate->assign('optpage', $optpage);
448 $oTemplate->assign('optpage_name', $optpage_name);
449 $oTemplate->assign('optmode', $optmode);
450 $oTemplate->assign('optpage_data', $optpage_data);
64033e1c 451
835db280 452 $oTemplate->assign('submit_name', $submit_name);
64033e1c 453 $oTemplate->display('options.tpl');
454
244a64a4 455 $oTemplate->display('form_close.tpl');
2de8b87f 456
457 /* If it is not empty, trigger the bottom hook. */
458 if ($bottom_hook_name != '') {
6e515418 459 do_hook($bottom_hook_name, $null);
2de8b87f 460 }
64033e1c 461
2de8b87f 462}
a2b193bc 463
6e4bf7c9 464$oTemplate->display('footer.tpl');