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_ACCESSIBILITY', 'accessibility');
43 define('SMOPT_PAGE_HIGHLIGHT', 'highlight');
44 define('SMOPT_PAGE_FOLDER', 'folder');
45 define('SMOPT_PAGE_ORDER', 'order');
48 * Save submitted options and calculate the most
49 * we need to refresh the page
51 * @param string $optpage The name of the page being submitted
52 * @param array $optpage_data An array of all the submitted options
54 * @return int The highest level of screen refresh needed per
55 * the options that were changed. This value will
56 * correspond to the SMOPT_REFRESH_* constants found
57 * in functions/options.php.
60 function process_optionmode_submit($optpage, $optpage_data) {
61 /* Initialize the maximum option refresh level. */
62 $max_refresh = SMOPT_REFRESH_NONE
;
66 /* Save each option in each option group. */
67 foreach ($optpage_data['options'] as $option_grp) {
68 foreach ($option_grp['options'] as $option) {
70 /* Special case: need to make sure emailaddress
71 * is saved if we use it as a test for ask_user_info */
72 global $ask_user_info;
73 if ( $optpage = SMOPT_PAGE_PERSONAL
&& $ask_user_info &&
74 $option->name
== 'email_address' ) {
75 $option->setValue('');
78 /* Remove Debug Mode Until Needed
79 echo "name = '$option->name', "
80 . "value = '$option->value', "
81 . "new_value = '$option->new_value'\n";
82 //FIXME: NO HTML IN THE CORE!
85 if ($option->changed()) {
87 $max_refresh = max($max_refresh, $option->refresh_level
);
92 /* Return the max refresh level. */
93 return ($max_refresh);
96 function process_optionmode_link($optpage) {
97 /* There will be something here, later. */
102 /* ---------------------------- main ---------------------------- */
104 /* get the globals that we may need */
105 sqgetGlobalVar('optpage', $optpage);
106 sqgetGlobalVar('optmode', $optmode, SQ_FORM
);
107 sqgetGlobalVar('optpage_data',$optpage_data, SQ_POST
);
108 /* end of getting globals */
110 /* Make sure we have an Option Page set. Default to main. */
111 if ( !isset($optpage) ||
$optpage == '' ) {
112 $optpage = SMOPT_PAGE_MAIN
;
114 $optpage = strip_tags( $optpage );
117 /* Make sure we have an Option Mode set. Default to display. */
118 if (!isset($optmode)) {
119 $optmode = SMOPT_MODE_DISPLAY
;
123 * First, set the load information for each option page.
126 /* Initialize load information variables. */
129 $optpage_loader = '';
131 /* Set the load information for each page. */
133 case SMOPT_PAGE_MAIN
:
135 case SMOPT_PAGE_PERSONAL
:
136 $optpage_name = _("Personal Information");
137 $optpage_file = SM_PATH
. 'include/options/personal.php';
138 $optpage_loader = 'load_optpage_data_personal';
139 $optpage_loadhook = 'optpage_loadhook_personal';
141 case SMOPT_PAGE_DISPLAY
:
142 $optpage_name = _("Display Preferences");
143 $optpage_file = SM_PATH
. 'include/options/display.php';
144 $optpage_loader = 'load_optpage_data_display';
145 $optpage_loadhook = 'optpage_loadhook_display';
147 case SMOPT_PAGE_COMPOSE
:
148 $optpage_name = _("Compose Preferences");
149 $optpage_file = SM_PATH
. 'include/options/compose.php';
150 $optpage_loader = 'load_optpage_data_compose';
151 $optpage_loadhook = 'optpage_loadhook_compose';
153 case SMOPT_PAGE_ACCESSIBILITY
:
154 $optpage_name = _("Accessibility Preferences");
155 $optpage_file = SM_PATH
. 'include/options/accessibility.php';
156 $optpage_loader = 'load_optpage_data_accessibility';
157 $optpage_loadhook = 'optpage_loadhook_accessibility';
159 case SMOPT_PAGE_HIGHLIGHT
:
160 $optpage_name = _("Message Highlighting");
161 $optpage_file = SM_PATH
. 'include/options/highlight.php';
162 $optpage_loader = 'load_optpage_data_highlight';
163 $optpage_loadhook = 'optpage_loadhook_highlight';
165 case SMOPT_PAGE_FOLDER
:
166 $optpage_name = _("Folder Preferences");
167 $optpage_file = SM_PATH
. 'include/options/folder.php';
168 $optpage_loader = 'load_optpage_data_folder';
169 $optpage_loadhook = 'optpage_loadhook_folder';
171 case SMOPT_PAGE_ORDER
:
172 $optpage_name = _("Index Order");
173 $optpage_file = SM_PATH
. 'include/options/order.php';
174 $optpage_loader = 'load_optpage_data_order';
175 $optpage_loadhook = 'optpage_loadhook_order';
177 default: do_hook('optpage_set_loadinfo', $null);
180 /**********************************************************/
181 /*** Second, load the option information for this page. ***/
182 /**********************************************************/
184 if ( !@is_file
( $optpage_file ) ) {
185 $optpage = SMOPT_PAGE_MAIN
;
186 } elseif ($optpage != SMOPT_PAGE_MAIN
) {
187 /* Include the file for this optionpage. */
189 require_once($optpage_file);
191 /* Assemble the data for this option page. */
192 $optpage_data = array();
193 $optpage_data = $optpage_loader();
194 do_hook($optpage_loadhook, $null);
195 $optpage_data['options'] = create_option_groups($optpage_data['grps'], $optpage_data['vals']);
198 /***********************************************************/
199 /*** Next, process anything that needs to be processed. ***/
200 /***********************************************************/
202 $optpage_save_error=array();
204 if ( isset( $optpage_data ) ) {
206 case SMOPT_MODE_SUBMIT
:
207 $max_refresh = process_optionmode_submit($optpage, $optpage_data);
209 case SMOPT_MODE_LINK
:
210 $max_refresh = process_optionmode_link($optpage, $optpage_data);
215 $optpage_title = _("Options");
216 if (isset($optpage_name) && ($optpage_name != '')) {
217 $optpage_title .= " - $optpage_name";
220 /*******************************************************************/
221 /* DO OLD SAVING OF SUBMITTED OPTIONS. THIS WILL BE REMOVED LATER. */
222 /*******************************************************************/
224 //FIXME: let's remove these finally in 1.5.2..... but first, are there any plugins using them?
225 /* If in submit mode, select a save hook name and run it. */
226 if ($optmode == SMOPT_MODE_SUBMIT
) {
227 /* Select a save hook name. */
229 case SMOPT_PAGE_PERSONAL
:
230 $save_hook_name = 'options_personal_save';
232 case SMOPT_PAGE_DISPLAY
:
233 $save_hook_name = 'options_display_save';
235 case SMOPT_PAGE_COMPOSE
:
236 $save_hook_name = 'options_compose_save';
238 case SMOPT_PAGE_ACCESSIBILITY
:
239 $save_hook_name = 'options_accessibility_save';
241 case SMOPT_PAGE_FOLDER
:
242 $save_hook_name = 'options_folder_save';
245 $save_hook_name = 'options_save';
249 /* Run the options save hook. */
250 do_hook($save_hook_name, $null);
253 /***************************************************************/
254 /* Apply logic to decide what optpage we want to display next. */
255 /***************************************************************/
257 /* If this is the result of an option page being submitted, then */
258 /* show the main page. Otherwise, show whatever page was called. */
260 if ($optmode == SMOPT_MODE_SUBMIT
) {
261 $optpage = SMOPT_PAGE_MAIN
;
262 $optpage_title = _("Options");
265 /***************************************************************/
266 /* Finally, display whatever page we are supposed to show now. */
267 /***************************************************************/
269 displayPageHeader($color, null, (isset($optpage_data['xtra']) ?
$optpage_data['xtra'] : ''));
272 * The main option page has a different layout then the rest of the option
273 * pages. Therefore, we create it here first, then the others below.
275 if ($optpage == SMOPT_PAGE_MAIN
) {
276 /**********************************************************/
277 /* First, display the results of a submission, if needed. */
278 /**********************************************************/
280 if ($optmode == SMOPT_MODE_SUBMIT
) {
281 if (!isset($frame_top)) {
285 if (isset($optpage_save_error) && $optpage_save_error!=array()) {
286 //FIXME: REMOVE HTML FROM CORE
287 $notice = _("Error(s) occurred while saving your options") . "<br />\n<ul>\n";
288 foreach ($optpage_save_error as $error_message) {
289 $notice.= '<li><small>' . $error_message . "</small></li>\n";
291 $notice.= "</ul>\n" . _("Some of your preference changes were not applied.") . "\n";
293 /* Display a message indicating a successful save. */
294 $notice = _("Successfully Saved Options") . ": $optpage_name</b><br />\n";
297 /* If $max_refresh != SMOPT_REFRESH_NONE, provide a refresh link. */
298 if ( !isset( $max_refresh ) ) {
299 } else if ($max_refresh == SMOPT_REFRESH_FOLDERLIST
) {
300 //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"
301 if (checkForJavascript()) {
302 $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";
304 $notice .= '<a href="../src/left_main.php" target="left">' . _("Refresh Folder List") . '</a><br />';
306 } else if ($max_refresh) {
307 if (checkForJavascript()) {
308 //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
309 $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";
311 $notice .= '<a href="../src/webmail.php?right_frame=options.php" target="' . $frame_top . '">' . _("Refresh Page") . '</a><br />';
316 if (!empty($notice)) {
317 $oTemplate->assign('note', $notice);
318 $oTemplate->display('note.tpl');
321 /******************************************/
322 /* Build our array of Option Page Blocks. */
323 /******************************************/
324 $optpage_blocks = array();
326 /* Build a section for Personal Options. */
327 $optpage_blocks[] = array(
328 'name' => _("Personal Information"),
329 'url' => 'options.php?optpage=' . SMOPT_PAGE_PERSONAL
,
330 'desc' => _("This contains personal information about yourself such as your name, your email address, etc."),
334 /* Build a section for Display Options. */
335 $optpage_blocks[] = array(
336 'name' => _("Display Preferences"),
337 'url' => 'options.php?optpage=' . SMOPT_PAGE_DISPLAY
,
338 'desc' => _("You can change the way that SquirrelMail looks and displays information to you, such as the colors, the language, and other settings."),
342 /* Build a section for Message Highlighting Options. */
343 $optpage_blocks[] = array(
344 'name' =>_("Message Highlighting"),
345 'url' => 'options_highlight.php',
346 '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."),
350 /* Build a section for Folder Options. */
351 $optpage_blocks[] = array(
352 'name' => _("Folder Preferences"),
353 'url' => 'options.php?optpage=' . SMOPT_PAGE_FOLDER
,
354 'desc' => _("These settings change the way your folders are displayed and manipulated."),
358 /* Build a section for Index Order Options. */
359 $optpage_blocks[] = array(
360 'name' => _("Index Order"),
361 'url' => 'options_order.php',
362 'desc' => _("The order of the message index can be rearranged and changed to contain the headers in any order you want."),
366 /* Build a section for Compose Options. */
367 $optpage_blocks[] = array(
368 'name' => _("Compose Preferences"),
369 'url' => 'options.php?optpage=' . SMOPT_PAGE_COMPOSE
,
370 'desc' => _("Control the behaviour and layout of writing new mail messages, replying to and forwarding messages."),
374 /* Build a section for Accessibility Options. */
375 $optpage_blocks[] = array(
376 'name' => _("Accessibility Preferences"),
377 'url' => 'options.php?optpage=' . SMOPT_PAGE_ACCESSIBILITY
,
378 'desc' => _("You can configure features that improve interface usability."),
382 /* Build a section for plugins wanting to register an optionpage. */
383 do_hook('optpage_register_block', $null);
385 /*****************************************************/
386 /* Let's sort Javascript Option Pages to the bottom. */
387 /*****************************************************/
388 $js_optpage_blocks = array();
389 $reg_optpage_blocks = array();
390 foreach ($optpage_blocks as $cur_optpage) {
391 if (!isset($cur_optpage['js']) ||
!$cur_optpage['js']) {
392 $reg_optpage_blocks[] = $cur_optpage;
393 } else if (checkForJavascript()) {
394 $js_optpage_blocks[] = $cur_optpage;
397 $optpage_blocks = array_merge($reg_optpage_blocks, $js_optpage_blocks);
399 /********************************************/
400 /* Now, print out each option page section. */
401 /********************************************/
402 $oTemplate->assign('page_title', $optpage_title);
403 $oTemplate->assign('options', $optpage_blocks);
405 $oTemplate->display('option_groups.tpl');
407 do_hook('options_link_and_description', $null);
410 /*************************************************************************/
411 /* If we are not looking at the main option page, display the page here. */
412 /*************************************************************************/
414 /* Set the bottom_hook_name and submit_name. */
416 case SMOPT_PAGE_PERSONAL
:
417 $bottom_hook_name = 'options_personal_bottom';
418 $submit_name = 'submit_personal';
420 case SMOPT_PAGE_DISPLAY
:
421 $bottom_hook_name = 'options_display_bottom';
422 $submit_name = 'submit_display';
424 case SMOPT_PAGE_COMPOSE
:
425 $bottom_hook_name = 'options_compose_bottom';
426 $submit_name = 'submit_compose';
428 case SMOPT_PAGE_ACCESSIBILITY
:
429 $bottom_hook_name = 'options_accessibility_bottom';
430 $submit_name = 'submit_accessibility';
432 case SMOPT_PAGE_HIGHLIGHT
:
433 $bottom_hook_name = 'options_highlight_bottom';
434 $submit_name = 'submit_highlight';
436 case SMOPT_PAGE_FOLDER
:
437 $bottom_hook_name = 'options_folder_bottom';
438 $submit_name = 'submit_folder';
440 case SMOPT_PAGE_ORDER
:
441 $bottom_hook_name = 'options_order_bottom';
442 $submit_name = 'submit_order';
445 $bottom_hook_name = '';
446 $submit_name = 'submit';
450 echo addForm('options.php', 'post', 'option_form')
451 . create_optpage_element($optpage)
452 . create_optmode_element(SMOPT_MODE_SUBMIT
);
454 // This is the only variable that is needed by *just* the template.
455 $oTemplate->assign('option_groups', $optpage_data['options']);
457 global $ask_user_info, $org_name;
458 if ( $optpage == SMOPT_PAGE_PERSONAL
&& $ask_user_info
459 && getPref($data_dir, $username,'email_address') == "" ) {
460 $oTemplate->assign('topmessage',
461 sprintf(_("Welcome to %s. Please supply your full name and email address."), $org_name) );
464 // These variables are not specifically needed by the template,
465 // but they are relevant to the page being built, so we'll add
466 // them in case some plugin is modifying the page, etc....
468 $oTemplate->assign('max_refresh', isset($max_refresh) ?
$max_refresh : NULL);
469 $oTemplate->assign('page_title', $optpage_title);
470 $oTemplate->assign('optpage', $optpage);
471 $oTemplate->assign('optpage_name', $optpage_name);
472 $oTemplate->assign('optmode', $optmode);
473 $oTemplate->assign('optpage_data', $optpage_data);
475 $oTemplate->assign('submit_name', $submit_name);
476 $oTemplate->display('options.tpl');
478 $oTemplate->display('form_close.tpl');
480 /* If it is not empty, trigger the bottom hook. */
481 if ($bottom_hook_name != '') {
482 do_hook($bottom_hook_name, $null);
487 $oTemplate->display('footer.tpl');