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";
68 //FIXME: NO HTML IN THE CORE!
71 if ($option->changed()) {
73 $max_refresh = max($max_refresh, $option->refresh_level
);
78 /* Return the max refresh level. */
79 return ($max_refresh);
82 function process_optionmode_link($optpage) {
83 /* There will be something here, later. */
88 /* ---------------------------- main ---------------------------- */
90 /* get the globals that we may need */
91 sqgetGlobalVar('optpage', $optpage);
92 sqgetGlobalVar('optmode', $optmode, SQ_FORM
);
93 sqgetGlobalVar('optpage_data',$optpage_data, SQ_POST
);
94 /* end of getting globals */
96 /* Make sure we have an Option Page set. Default to main. */
97 if ( !isset($optpage) ||
$optpage == '' ) {
98 $optpage = SMOPT_PAGE_MAIN
;
100 $optpage = strip_tags( $optpage );
103 /* Make sure we have an Option Mode set. Default to display. */
104 if (!isset($optmode)) {
105 $optmode = SMOPT_MODE_DISPLAY
;
109 * First, set the load information for each option page.
112 /* Initialize load information variables. */
115 $optpage_loader = '';
117 /* Set the load information for each page. */
119 case SMOPT_PAGE_MAIN
:
121 case SMOPT_PAGE_PERSONAL
:
122 $optpage_name = _("Personal Information");
123 $optpage_file = SM_PATH
. 'include/options/personal.php';
124 $optpage_loader = 'load_optpage_data_personal';
125 $optpage_loadhook = 'optpage_loadhook_personal';
127 case SMOPT_PAGE_DISPLAY
:
128 $optpage_name = _("Display Preferences");
129 $optpage_file = SM_PATH
. 'include/options/display.php';
130 $optpage_loader = 'load_optpage_data_display';
131 $optpage_loadhook = 'optpage_loadhook_display';
133 case SMOPT_PAGE_COMPOSE
:
134 $optpage_name = _("Compose Preferences");
135 $optpage_file = SM_PATH
. 'include/options/compose.php';
136 $optpage_loader = 'load_optpage_data_compose';
137 $optpage_loadhook = 'optpage_loadhook_compose';
139 case SMOPT_PAGE_HIGHLIGHT
:
140 $optpage_name = _("Message Highlighting");
141 $optpage_file = SM_PATH
. 'include/options/highlight.php';
142 $optpage_loader = 'load_optpage_data_highlight';
143 $optpage_loadhook = 'optpage_loadhook_highlight';
145 case SMOPT_PAGE_FOLDER
:
146 $optpage_name = _("Folder Preferences");
147 $optpage_file = SM_PATH
. 'include/options/folder.php';
148 $optpage_loader = 'load_optpage_data_folder';
149 $optpage_loadhook = 'optpage_loadhook_folder';
151 case SMOPT_PAGE_ORDER
:
152 $optpage_name = _("Index Order");
153 $optpage_file = SM_PATH
. 'include/options/order.php';
154 $optpage_loader = 'load_optpage_data_order';
155 $optpage_loadhook = 'optpage_loadhook_order';
157 default: do_hook('optpage_set_loadinfo', $null);
160 /**********************************************************/
161 /*** Second, load the option information for this page. ***/
162 /**********************************************************/
164 if ( !@is_file
( $optpage_file ) ) {
165 $optpage = SMOPT_PAGE_MAIN
;
166 } elseif ($optpage != SMOPT_PAGE_MAIN
) {
167 /* Include the file for this optionpage. */
169 require_once($optpage_file);
171 /* Assemble the data for this option page. */
172 $optpage_data = array();
173 $optpage_data = $optpage_loader();
174 do_hook($optpage_loadhook, $null);
175 $optpage_data['options'] = create_option_groups($optpage_data['grps'], $optpage_data['vals']);
178 /***********************************************************/
179 /*** Next, process anything that needs to be processed. ***/
180 /***********************************************************/
182 $optpage_save_error=array();
184 if ( isset( $optpage_data ) ) {
186 case SMOPT_MODE_SUBMIT
:
187 $max_refresh = process_optionmode_submit($optpage, $optpage_data);
189 case SMOPT_MODE_LINK
:
190 $max_refresh = process_optionmode_link($optpage, $optpage_data);
195 $optpage_title = _("Options");
196 if (isset($optpage_name) && ($optpage_name != '')) {
197 $optpage_title .= " - $optpage_name";
200 /*******************************************************************/
201 /* DO OLD SAVING OF SUBMITTED OPTIONS. THIS WILL BE REMOVED LATER. */
202 /*******************************************************************/
204 /* If in submit mode, select a save hook name and run it. */
205 if ($optmode == SMOPT_MODE_SUBMIT
) {
206 /* Select a save hook name. */
208 case SMOPT_PAGE_PERSONAL
:
209 $save_hook_name = 'options_personal_save';
211 case SMOPT_PAGE_DISPLAY
:
212 $save_hook_name = 'options_display_save';
214 case SMOPT_PAGE_COMPOSE
:
215 $save_hook_name = 'options_compose_save';
217 case SMOPT_PAGE_FOLDER
:
218 $save_hook_name = 'options_folder_save';
221 $save_hook_name = 'options_save';
225 /* Run the options save hook. */
226 do_hook($save_hook_name, $null);
229 /***************************************************************/
230 /* Apply logic to decide what optpage we want to display next. */
231 /***************************************************************/
233 /* If this is the result of an option page being submitted, then */
234 /* show the main page. Otherwise, show whatever page was called. */
236 if ($optmode == SMOPT_MODE_SUBMIT
) {
237 $optpage = SMOPT_PAGE_MAIN
;
240 /***************************************************************/
241 /* Finally, display whatever page we are supposed to show now. */
242 /***************************************************************/
244 displayPageHeader($color, null, (isset($optpage_data['xtra']) ?
$optpage_data['xtra'] : ''));
247 * The main option page has a different layout then the rest of the option
248 * pages. Therefore, we create it here first, then the others below.
250 if ($optpage == SMOPT_PAGE_MAIN
) {
251 /**********************************************************/
252 /* First, display the results of a submission, if needed. */
253 /**********************************************************/
255 if ($optmode == SMOPT_MODE_SUBMIT
) {
256 if (!isset($frame_top)) {
260 if (isset($optpage_save_error) && $optpage_save_error!=array()) {
261 //FIXME: REMOVE HTML FROM CORE
262 $notice = _("Error(s) occurred while saving your options") . "<br />\n<ul>\n";
263 foreach ($optpage_save_error as $error_message) {
264 $notice.= '<li><small>' . $error_message . "</small></li>\n";
266 $notice.= "</ul>\n" . _("Some of your preference changes were not applied.") . "\n";
268 /* Display a message indicating a successful save. */
269 $notice = _("Successfully Saved Options") . ": $optpage_name</b><br />\n";
272 /* If $max_refresh != SMOPT_REFRESH_NONE, provide a refresh link. */
273 if ( !isset( $max_refresh ) ) {
274 } else if ($max_refresh == SMOPT_REFRESH_FOLDERLIST
) {
275 //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"
276 if (checkForJavascript()) {
277 $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";
279 $notice .= '<a href="../src/left_main.php" target="left">' . _("Refresh Folder List") . '</a><br />';
281 } else if ($max_refresh) {
282 if (checkForJavascript()) {
283 //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
284 $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";
286 $notice .= '<a href="../src/webmail.php?right_frame=options.php" target="' . $frame_top . '">' . _("Refresh Page") . '</a><br />';
291 if (!empty($notice)) {
292 $oTemplate->assign('note', $notice);
293 $oTemplate->display('note.tpl');
296 /******************************************/
297 /* Build our array of Option Page Blocks. */
298 /******************************************/
299 $optpage_blocks = array();
301 /* Build a section for Personal Options. */
302 $optpage_blocks[] = array(
303 'name' => _("Personal Information"),
304 'url' => 'options.php?optpage=' . SMOPT_PAGE_PERSONAL
,
305 'desc' => _("This contains personal information about yourself such as your name, your email address, etc."),
309 /* Build a section for Display Options. */
310 $optpage_blocks[] = array(
311 'name' => _("Display Preferences"),
312 'url' => 'options.php?optpage=' . SMOPT_PAGE_DISPLAY
,
313 'desc' => _("You can change the way that SquirrelMail looks and displays information to you, such as the colors, the language, and other settings."),
317 /* Build a section for Message Highlighting Options. */
318 $optpage_blocks[] = array(
319 'name' =>_("Message Highlighting"),
320 'url' => 'options_highlight.php',
321 '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."),
325 /* Build a section for Folder Options. */
326 $optpage_blocks[] = array(
327 'name' => _("Folder Preferences"),
328 'url' => 'options.php?optpage=' . SMOPT_PAGE_FOLDER
,
329 'desc' => _("These settings change the way your folders are displayed and manipulated."),
333 /* Build a section for Index Order Options. */
334 $optpage_blocks[] = array(
335 'name' => _("Index Order"),
336 'url' => 'options_order.php',
337 'desc' => _("The order of the message index can be rearranged and changed to contain the headers in any order you want."),
341 /* Build a section for Compose Options. */
342 $optpage_blocks[] = array(
343 'name' => _("Compose Preferences"),
344 'url' => 'options.php?optpage=' . SMOPT_PAGE_COMPOSE
,
345 'desc' => _("Control the behaviour and layout of writing new mail messages, replying to and forwarding messages."),
349 /* Build a section for plugins wanting to register an optionpage. */
350 do_hook('optpage_register_block', $null);
352 /*****************************************************/
353 /* Let's sort Javascript Option Pages to the bottom. */
354 /*****************************************************/
355 $js_optpage_blocks = array();
356 $reg_optpage_blocks = array();
357 foreach ($optpage_blocks as $cur_optpage) {
358 if (!isset($cur_optpage['js']) ||
!$cur_optpage['js']) {
359 $reg_optpage_blocks[] = $cur_optpage;
360 } else if (checkForJavascript()) {
361 $js_optpage_blocks[] = $cur_optpage;
364 $optpage_blocks = array_merge($reg_optpage_blocks, $js_optpage_blocks);
366 /********************************************/
367 /* Now, print out each option page section. */
368 /********************************************/
369 $oTemplate->assign('page_title', $optpage_title);
370 $oTemplate->assign('options', $optpage_blocks);
372 $oTemplate->display('option_groups.tpl');
374 do_hook('options_link_and_description', $null);
377 /*************************************************************************/
378 /* If we are not looking at the main option page, display the page here. */
379 /*************************************************************************/
381 /* Set the inside_hook_name and submit_name. */
383 case SMOPT_PAGE_PERSONAL
:
384 $inside_hook_name = 'options_personal_inside';
385 $bottom_hook_name = 'options_personal_bottom';
386 $submit_name = 'submit_personal';
388 case SMOPT_PAGE_DISPLAY
:
389 $inside_hook_name = 'options_display_inside';
390 $bottom_hook_name = 'options_display_bottom';
391 $submit_name = 'submit_display';
393 case SMOPT_PAGE_COMPOSE
:
394 $inside_hook_name = 'options_compose_inside';
395 $bottom_hook_name = 'options_compose_bottom';
396 $submit_name = 'submit_compose';
398 case SMOPT_PAGE_HIGHLIGHT
:
399 $inside_hook_name = 'options_highlight_inside';
400 $bottom_hook_name = 'options_highlight_bottom';
401 $submit_name = 'submit_highlight';
403 case SMOPT_PAGE_FOLDER
:
404 $inside_hook_name = 'options_folder_inside';
405 $bottom_hook_name = 'options_folder_bottom';
406 $submit_name = 'submit_folder';
408 case SMOPT_PAGE_ORDER
:
409 $inside_hook_name = 'options_order_inside';
410 $bottom_hook_name = 'options_order_bottom';
411 $submit_name = 'submit_order';
414 $inside_hook_name = '';
415 $bottom_hook_name = '';
416 $submit_name = 'submit';
420 echo addForm('options.php', 'post', 'f')
421 . create_optpage_element($optpage)
422 . create_optmode_element(SMOPT_MODE_SUBMIT
);
424 // Wrap the template in a table to keep from breaking the hooks below
425 $oTemplate->assign('attributes', array('cellspacing' => 0, 'class' => 'table_blank'));
426 $oTemplate->display('table.tpl');
427 $oTemplate->display('table_row.tpl');
428 $oTemplate->assign('attributes', array('colspan' => 2));
429 $oTemplate->display('table_data.tpl');
431 // This is the only variable that is needed by *just* the template.
432 $oTemplate->assign('options', $optpage_data['options']);
434 global $ask_user_info, $org_name;
435 if ( $optpage == SMOPT_PAGE_PERSONAL
&& $ask_user_info
436 && getPref($data_dir, $username,'email_address') == "" ) {
437 $oTemplate->assign('topmessage',
438 sprintf(_("Welcome to %s. Please supply your full name and email address."), $org_name) );
442 * The variables below should not be needed by the template since all plugin
443 * hooks are called here, not in the template. If we find otherwise, these
444 * variables can be passed to the template. Commenting out for now.
447 $oTemplate->assign('max_refresh', isset($max_refresh) ? $max_refresh : NULL);
448 $oTemplate->assign('page_title', $optpage_title);
449 $oTemplate->assign('optpage',$optpage);
450 $oTemplate->assign('optpage_name',$optpage_name);
451 $oTemplate->assign('optmode',$optmode);
452 $oTemplate->assign('optpage_data',$optpage_data);
458 $oTemplate->assign('submit_name', $submit_name);
459 $oTemplate->display('options.tpl');
461 $oTemplate->display('table_data_close.tpl');
462 $oTemplate->display('table_row_close.tpl');
464 /* If it is not empty, trigger the inside hook. */
465 if ($inside_hook_name != '') {
466 do_hook($inside_hook_name, $null);
469 $oTemplate->display('table_close.tpl');
470 $oTemplate->display('form_close.tpl');
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');