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