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