6 * Displays the options page. Pulls from proper user preference files
7 * and config.php. Displays preferences as selected and other options.
9 * @copyright © 1999-2007 The SquirrelMail Project Team
10 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
12 * @package squirrelmail
16 /** This is the options page */
17 define('PAGE_NAME', 'options');
20 * Include the SquirrelMail initialization file.
22 require('../include/init.php');
24 /* SquirrelMail required files. */
26 //include(SM_PATH . 'functions/imap_general.php');
27 require_once(SM_PATH
. 'functions/options.php');
28 require_once(SM_PATH
. 'functions/forms.php');
30 /*********************************/
31 /*** Build the resultant page. ***/
32 /*********************************/
34 define('SMOPT_MODE_DISPLAY', 'display');
35 define('SMOPT_MODE_SUBMIT', 'submit');
36 define('SMOPT_MODE_LINK', 'link');
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');
46 function process_optionmode_submit($optpage, $optpage_data) {
47 /* Initialize the maximum option refresh level. */
48 $max_refresh = SMOPT_REFRESH_NONE
;
52 /* Save each option in each option group. */
53 foreach ($optpage_data['options'] as $option_grp) {
54 foreach ($option_grp['options'] as $option) {
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('');
64 /* Remove Debug Mode Until Needed
65 echo "name = '$option->name', "
66 . "value = '$option->value', "
67 . "new_value = '$option->new_value'\n";
70 if ($option->changed()) {
72 $max_refresh = max($max_refresh, $option->refresh_level
);
77 /* Return the max refresh level. */
78 return ($max_refresh);
81 function process_optionmode_link($optpage) {
82 /* There will be something here, later. */
87 /* ---------------------------- main ---------------------------- */
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 */
95 /* Make sure we have an Option Page set. Default to main. */
96 if ( !isset($optpage) ||
$optpage == '' ) {
97 $optpage = SMOPT_PAGE_MAIN
;
99 $optpage = strip_tags( $optpage );
102 /* Make sure we have an Option Mode set. Default to display. */
103 if (!isset($optmode)) {
104 $optmode = SMOPT_MODE_DISPLAY
;
108 * First, set the load information for each option page.
111 /* Initialize load information variables. */
114 $optpage_loader = '';
116 /* Set the load information for each page. */
118 case SMOPT_PAGE_MAIN
:
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';
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';
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';
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';
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';
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';
156 default: do_hook('optpage_set_loadinfo', $null);
159 /**********************************************************/
160 /*** Second, load the option information for this page. ***/
161 /**********************************************************/
163 if ( !@is_file
( $optpage_file ) ) {
164 $optpage = SMOPT_PAGE_MAIN
;
165 } elseif ($optpage != SMOPT_PAGE_MAIN
) {
166 /* Include the file for this optionpage. */
168 require_once($optpage_file);
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']);
177 /***********************************************************/
178 /*** Next, process anything that needs to be processed. ***/
179 /***********************************************************/
181 $optpage_save_error=array();
183 if ( isset( $optpage_data ) ) {
185 case SMOPT_MODE_SUBMIT
:
186 $max_refresh = process_optionmode_submit($optpage, $optpage_data);
188 case SMOPT_MODE_LINK
:
189 $max_refresh = process_optionmode_link($optpage, $optpage_data);
194 $optpage_title = _("Options");
195 if (isset($optpage_name) && ($optpage_name != '')) {
196 $optpage_title .= " - $optpage_name";
199 /*******************************************************************/
200 /* DO OLD SAVING OF SUBMITTED OPTIONS. THIS WILL BE REMOVED LATER. */
201 /*******************************************************************/
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. */
207 case SMOPT_PAGE_PERSONAL
:
208 $save_hook_name = 'options_personal_save';
210 case SMOPT_PAGE_DISPLAY
:
211 $save_hook_name = 'options_display_save';
213 case SMOPT_PAGE_COMPOSE
:
214 $save_hook_name = 'options_compose_save';
216 case SMOPT_PAGE_FOLDER
:
217 $save_hook_name = 'options_folder_save';
220 $save_hook_name = 'options_save';
224 /* Run the options save hook. */
225 do_hook($save_hook_name, $null);
228 /***************************************************************/
229 /* Apply logic to decide what optpage we want to display next. */
230 /***************************************************************/
232 /* If this is the result of an option page being submitted, then */
233 /* show the main page. Otherwise, show whatever page was called. */
235 if ($optmode == SMOPT_MODE_SUBMIT
) {
236 $optpage = SMOPT_PAGE_MAIN
;
239 /***************************************************************/
240 /* Finally, display whatever page we are supposed to show now. */
241 /***************************************************************/
243 displayPageHeader($color, null, (isset($optpage_data['xtra']) ?
$optpage_data['xtra'] : ''));
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.
249 if ($optpage == SMOPT_PAGE_MAIN
) {
250 /**********************************************************/
251 /* First, display the results of a submission, if needed. */
252 /**********************************************************/
254 if ($optmode == SMOPT_MODE_SUBMIT
) {
255 if (!isset($frame_top)) {
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";
265 $notice.= "</ul>\n" . _("Some of your preference changes were not applied.") . "\n";
267 /* Display a message indicating a successful save. */
268 $notice = _("Successfully Saved Options") . ": $optpage_name</b><br />\n";
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";
278 $notice .= '<a href="../src/left_main.php" target="left">' . _("Refresh Folder List") . '</a><br />';
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";
285 $notice .= '<a href="../src/webmail.php?right_frame=options.php" target="' . $frame_top . '">' . _("Refresh Page") . '</a><br />';
290 if (!empty($notice)) {
291 $oTemplate->assign('note', $notice);
292 $oTemplate->display('note.tpl');
295 /******************************************/
296 /* Build our array of Option Page Blocks. */
297 /******************************************/
298 $optpage_blocks = array();
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."),
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."),
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."),
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."),
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."),
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."),
348 /* Build a section for plugins wanting to register an optionpage. */
349 do_hook('optpage_register_block', $null);
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;
363 $optpage_blocks = array_merge($reg_optpage_blocks, $js_optpage_blocks);
365 /********************************************/
366 /* Now, print out each option page section. */
367 /********************************************/
368 $oTemplate->assign('page_title', $optpage_title);
369 $oTemplate->assign('options', $optpage_blocks);
371 $oTemplate->display('option_groups.tpl');
373 do_hook('options_link_and_description', $null);
376 /*************************************************************************/
377 /* If we are not looking at the main option page, display the page here. */
378 /*************************************************************************/
380 /* Set the inside_hook_name and submit_name. */
382 case SMOPT_PAGE_PERSONAL
:
383 $inside_hook_name = 'options_personal_inside';
384 $bottom_hook_name = 'options_personal_bottom';
385 $submit_name = 'submit_personal';
387 case SMOPT_PAGE_DISPLAY
:
388 $inside_hook_name = 'options_display_inside';
389 $bottom_hook_name = 'options_display_bottom';
390 $submit_name = 'submit_display';
392 case SMOPT_PAGE_COMPOSE
:
393 $inside_hook_name = 'options_compose_inside';
394 $bottom_hook_name = 'options_compose_bottom';
395 $submit_name = 'submit_compose';
397 case SMOPT_PAGE_HIGHLIGHT
:
398 $inside_hook_name = 'options_highlight_inside';
399 $bottom_hook_name = 'options_highlight_bottom';
400 $submit_name = 'submit_highlight';
402 case SMOPT_PAGE_FOLDER
:
403 $inside_hook_name = 'options_folder_inside';
404 $bottom_hook_name = 'options_folder_bottom';
405 $submit_name = 'submit_folder';
407 case SMOPT_PAGE_ORDER
:
408 $inside_hook_name = 'options_order_inside';
409 $bottom_hook_name = 'options_order_bottom';
410 $submit_name = 'submit_order';
413 $inside_hook_name = '';
414 $bottom_hook_name = '';
415 $submit_name = 'submit';
419 echo addForm('options.php', 'post', 'f')
420 . create_optpage_element($optpage)
421 . create_optmode_element(SMOPT_MODE_SUBMIT
);
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" .
427 " <td colspan=\"2\">\n";
429 // This is the only variable that is needed by *just* the template.
430 $oTemplate->assign('options', $optpage_data['options']);
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) );
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.
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);
456 $oTemplate->assign('submit_name', $submit_name);
457 $oTemplate->display('options.tpl');
459 //FIXME: need to remove HTML from here!
463 /* If it is not empty, trigger the inside hook. */
464 if ($inside_hook_name != '') {
465 do_hook($inside_hook_name, $null);
468 //FIXME: need to remove HTML from here!
472 /* If it is not empty, trigger the bottom hook. */
473 if ($bottom_hook_name != '') {
474 do_hook($bottom_hook_name, $null);
479 $oTemplate->display('footer.tpl');