6 * Copyright (c) 1999-2004 The SquirrelMail Project Team
7 * Licensed under the GNU GPL. For full terms see the file COPYING.
9 * Displays the options page. Pulls from proper user preference files
10 * and config.php. Displays preferences as selected and other options.
13 * @package squirrelmail
17 * Path for SquirrelMail required files.
20 define('SM_PATH','../');
22 /* SquirrelMail required files. */
23 require_once(SM_PATH
. 'include/validate.php');
24 require_once(SM_PATH
. 'functions/global.php');
25 require_once(SM_PATH
. 'functions/display_messages.php');
26 require_once(SM_PATH
. 'functions/imap.php');
27 require_once(SM_PATH
. 'functions/options.php');
28 require_once(SM_PATH
. 'functions/strings.php');
29 require_once(SM_PATH
. 'functions/html.php');
30 require_once(SM_PATH
. 'functions/forms.php');
32 /*********************************/
33 /*** Build the resultant page. ***/
34 /*********************************/
36 define('SMOPT_MODE_DISPLAY', 'display');
37 define('SMOPT_MODE_SUBMIT', 'submit');
38 define('SMOPT_MODE_LINK', 'link');
40 define('SMOPT_PAGE_MAIN', 'main');
41 define('SMOPT_PAGE_PERSONAL', 'personal');
42 define('SMOPT_PAGE_DISPLAY', 'display');
43 define('SMOPT_PAGE_HIGHLIGHT', 'highlight');
44 define('SMOPT_PAGE_FOLDER', 'folder');
45 define('SMOPT_PAGE_ORDER', 'order');
47 function process_optionmode_submit($optpage, $optpage_data) {
48 /* Initialize the maximum option refresh level. */
49 $max_refresh = SMOPT_REFRESH_NONE
;
51 /* Save each option in each option group. */
52 foreach ($optpage_data['options'] as $option_grp) {
53 foreach ($option_grp['options'] as $option) {
54 /* Remove Debug Mode Until Needed
55 echo "name = '$option->name', "
56 . "value = '$option->value', "
57 . "new_value = '$option->new_value'\n";
60 if ($option->changed()) {
62 $max_refresh = max($max_refresh, $option->refresh_level
);
67 /* Return the max refresh level. */
68 return ($max_refresh);
71 function process_optionmode_link($optpage) {
72 /* There will be something here, later. */
77 * This function prints out an option page row.
79 function print_optionpages_row($leftopt, $rightopt = false) {
83 $rightopt_name = html_tag( 'td', '<a href="' . $rightopt['url'] . '">' . $rightopt['name'] . '</a>', 'left', $color[9], 'valign="top" width="49%"' );
84 $rightopt_desc = html_tag( 'td', $rightopt['desc'], 'left', $color[0], 'valign="top" width="49%"' );
86 $rightopt_name = html_tag( 'td', ' ', 'left', $color[4], 'valign="top" width="49%"' );
87 $rightopt_desc = html_tag( 'td', ' ', 'left', $color[4], 'valign="top" width="49%"' );
91 html_tag( 'table', "\n" .
92 html_tag( 'tr', "\n" .
93 html_tag( 'td', "\n" .
94 html_tag( 'table', "\n" .
95 html_tag( 'tr', "\n" .
97 '<a href="' . $leftopt['url'] . '">' . $leftopt['name'] . '</a>' ,
98 'left', $color[9], 'valign="top" width="49%"' ) .
101 'left', $color[4], 'valign="top" width="2%"' ) . "\n" .
104 html_tag( 'tr', "\n" .
107 'left', $color[0], 'valign="top" width="49%"' ) .
110 'left', $color[4], 'valign="top" width="2%"' ) . "\n" .
113 '', '', 'width="100%" cellpadding="2" cellspacing="0" border="0"' ) ,
114 'left', '', 'valign="top"' )
116 '', $color[4], 'width="100%" cellpadding="0" cellspacing="5" border="0"' );
119 /* ---------------------------- main ---------------------------- */
121 /* get the globals that we may need */
122 sqgetGlobalVar('key', $key, SQ_COOKIE
);
123 sqgetGlobalVar('username', $username, SQ_SESSION
);
124 sqgetGlobalVar('onetimepad',$onetimepad, SQ_SESSION
);
125 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION
);
127 sqgetGlobalVar('optpage', $optpage);
128 sqgetGlobalVar('optmode', $optmode, SQ_FORM
);
129 sqgetGlobalVar('optpage_data',$optpage_data, SQ_POST
);
130 /* end of getting globals */
132 /* Make sure we have an Option Page set. Default to main. */
133 if ( !isset($optpage) ||
$optpage == '' ) {
134 $optpage = SMOPT_PAGE_MAIN
;
136 $optpage = strip_tags( $optpage );
139 /* Make sure we have an Option Mode set. Default to display. */
140 if (!isset($optmode)) {
141 $optmode = SMOPT_MODE_DISPLAY
;
145 * First, set the load information for each option page.
148 /* Initialize load information variables. */
151 $optpage_loader = '';
153 /* Set the load information for each page. */
155 case SMOPT_PAGE_MAIN
:
157 case SMOPT_PAGE_PERSONAL
:
158 $optpage_name = _("Personal Information");
159 $optpage_file = SM_PATH
. 'include/options/personal.php';
160 $optpage_loader = 'load_optpage_data_personal';
161 $optpage_loadhook = 'optpage_loadhook_personal';
163 case SMOPT_PAGE_DISPLAY
:
164 $optpage_name = _("Display Preferences");
165 $optpage_file = SM_PATH
. 'include/options/display.php';
166 $optpage_loader = 'load_optpage_data_display';
167 $optpage_loadhook = 'optpage_loadhook_display';
169 case SMOPT_PAGE_HIGHLIGHT
:
170 $optpage_name = _("Message Highlighting");
171 $optpage_file = SM_PATH
. 'include/options/highlight.php';
172 $optpage_loader = 'load_optpage_data_highlight';
173 $optpage_loadhook = 'optpage_loadhook_highlight';
175 case SMOPT_PAGE_FOLDER
:
176 $optpage_name = _("Folder Preferences");
177 $optpage_file = SM_PATH
. 'include/options/folder.php';
178 $optpage_loader = 'load_optpage_data_folder';
179 $optpage_loadhook = 'optpage_loadhook_folder';
181 case SMOPT_PAGE_ORDER
:
182 $optpage_name = _("Index Order");
183 $optpage_file = SM_PATH
. 'include/options/order.php';
184 $optpage_loader = 'load_optpage_data_order';
185 $optpage_loadhook = 'optpage_loadhook_order';
187 default: do_hook('optpage_set_loadinfo');
190 /**********************************************************/
191 /*** Second, load the option information for this page. ***/
192 /**********************************************************/
194 if ( !@is_file
( $optpage_file ) ) {
195 $optpage = SMOPT_PAGE_MAIN
;
196 } else if ($optpage != SMOPT_PAGE_MAIN
) {
197 /* Include the file for this optionpage. */
199 require_once($optpage_file);
201 /* Assemble the data for this option page. */
202 $optpage_data = array();
203 $optpage_data = $optpage_loader();
204 do_hook($optpage_loadhook);
205 $optpage_data['options'] =
206 create_option_groups($optpage_data['grps'], $optpage_data['vals']);
209 /***********************************************************/
210 /*** Next, process anything that needs to be processed. ***/
211 /***********************************************************/
213 if ( isset( $optpage_data ) ) {
215 case SMOPT_MODE_SUBMIT
:
216 $max_refresh = process_optionmode_submit($optpage, $optpage_data);
218 case SMOPT_MODE_LINK
:
219 $max_refresh = process_optionmode_link($optpage, $optpage_data);
224 $optpage_title = _("Options");
225 if (isset($optpage_name) && ($optpage_name != '')) {
226 $optpage_title .= " - $optpage_name";
229 /*******************************************************************/
230 /* DO OLD SAVING OF SUBMITTED OPTIONS. THIS WILL BE REMOVED LATER. */
231 /*******************************************************************/
233 /* If in submit mode, select a save hook name and run it. */
234 if ($optmode == SMOPT_MODE_SUBMIT
) {
235 /* Select a save hook name. */
237 case SMOPT_PAGE_PERSONAL
:
238 $save_hook_name = 'options_personal_save';
240 case SMOPT_PAGE_DISPLAY
:
241 $save_hook_name = 'options_display_save';
243 case SMOPT_PAGE_FOLDER
:
244 $save_hook_name = 'options_folder_save';
247 $save_hook_name = 'options_save';
251 /* Run the options save hook. */
252 do_hook($save_hook_name);
255 /***************************************************************/
256 /* Apply logic to decide what optpage we want to display next. */
257 /***************************************************************/
259 /* If this is the result of an option page being submitted, then */
260 /* show the main page. Otherwise, show whatever page was called. */
262 if ($optmode == SMOPT_MODE_SUBMIT
) {
263 $optpage = SMOPT_PAGE_MAIN
;
266 /***************************************************************/
267 /* Finally, display whatever page we are supposed to show now. */
268 /***************************************************************/
270 displayPageHeader($color, 'None', (isset($optpage_data['xtra']) ?
$optpage_data['xtra'] : ''));
272 echo html_tag( 'table', '', 'center', $color[0], 'width="95%" cellpadding="1" cellspacing="0" border="0"' ) . "\n" .
273 html_tag( 'tr' ) . "\n" .
274 html_tag( 'td', '', 'center' ) .
275 "<b>$optpage_title</b><br>\n".
276 html_tag( 'table', '', '', '', 'width="100%" cellpadding="5" cellspacing="0" border="0"' ) . "\n" .
277 html_tag( 'tr' ) . "\n" .
278 html_tag( 'td', '', 'center', $color[4] ) . "\n";
281 * The main option page has a different layout then the rest of the option
282 * pages. Therefore, we create it here first, then the others below.
284 if ($optpage == SMOPT_PAGE_MAIN
) {
285 /**********************************************************/
286 /* First, display the results of a submission, if needed. */
287 /**********************************************************/
288 if ($optmode == SMOPT_MODE_SUBMIT
) {
289 if (!isset($frame_top)) {
292 /* Display a message indicating a successful save. */
293 echo '<b>' . _("Successfully Saved Options") . ": $optpage_name</b><br>\n";
295 /* If $max_refresh != SMOPT_REFRESH_NONE, provide a refresh link. */
296 if ( !isset( $max_refresh ) ) {
297 } else if ($max_refresh == SMOPT_REFRESH_FOLDERLIST
) {
298 echo '<a href="../src/left_main.php" target="left">' . _("Refresh Folder List") . '</a><br>';
299 } else if ($max_refresh) {
300 echo '<a href="../src/webmail.php?right_frame=options.php" target="' . $frame_top . '">' . _("Refresh Page") . '</a><br>';
303 /******************************************/
304 /* Build our array of Option Page Blocks. */
305 /******************************************/
306 $optpage_blocks = array();
308 /* Build a section for Personal Options. */
309 $optpage_blocks[] = array(
310 'name' => _("Personal Information"),
311 'url' => 'options.php?optpage=' . SMOPT_PAGE_PERSONAL
,
312 'desc' => _("This contains personal information about yourself such as your name, your email address, etc."),
316 /* Build a section for Display Options. */
317 $optpage_blocks[] = array(
318 'name' => _("Display Preferences"),
319 'url' => 'options.php?optpage=' . SMOPT_PAGE_DISPLAY
,
320 'desc' => _("You can change the way that SquirrelMail looks and displays information to you, such as the colors, the language, and other settings."),
324 /* Build a section for Message Highlighting Options. */
325 $optpage_blocks[] = array(
326 'name' =>_("Message Highlighting"),
327 'url' => 'options_highlight.php',
328 '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."),
332 /* Build a section for Folder Options. */
333 $optpage_blocks[] = array(
334 'name' => _("Folder Preferences"),
335 'url' => 'options.php?optpage=' . SMOPT_PAGE_FOLDER
,
336 'desc' => _("These settings change the way your folders are displayed and manipulated."),
340 /* Build a section for Index Order Options. */
341 $optpage_blocks[] = array(
342 'name' => _("Index Order"),
343 'url' => 'options_order.php',
344 'desc' => _("The order of the message index can be rearranged and changed to contain the headers in any order you want."),
348 /* Build a section for plugins wanting to register an optionpage. */
349 do_hook('optpage_register_block');
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 ($javascript_on == SMPREF_JS_ON
) {
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 $first_optpage = false;
369 echo html_tag( 'table', '', '', $color[4], 'width="100%" cellpadding="0" cellspacing="5" border="0"' ) . "\n" .
370 html_tag( 'tr' ) . "\n" .
371 html_tag( 'td', '', 'left', '', 'valign="top"' ) .
372 html_tag( 'table', '', '', $color[4], 'width="100%" cellpadding="3" cellspacing="0" border="0"' ) . "\n" .
373 html_tag( 'tr' ) . "\n" .
374 html_tag( 'td', '', 'left' );
375 foreach ($optpage_blocks as $next_optpage) {
376 if ($first_optpage == false) {
377 $first_optpage = $next_optpage;
379 print_optionpages_row($first_optpage, $next_optpage);
380 $first_optpage = false;
384 if ($first_optpage != false) {
385 print_optionpages_row($first_optpage);
388 echo "</td></tr></table></td></tr></table>\n";
390 do_hook('options_link_and_description');
393 /*************************************************************************/
394 /* If we are not looking at the main option page, display the page here. */
395 /*************************************************************************/
397 echo addForm('options.php', 'POST', 'f')
398 . create_optpage_element($optpage)
399 . create_optmode_element(SMOPT_MODE_SUBMIT
)
400 . html_tag( 'table', '', '', '', 'width="100%" cellpadding="2" cellspacing="0" border="0"' ) . "\n"
401 . html_tag( 'tr' ) . "\n"
402 . html_tag( 'td', '', 'left' ) . "\n";
404 /* Output the option groups for this page. */
405 print_option_groups($optpage_data['options']);
407 /* Set the inside_hook_name and submit_name. */
409 case SMOPT_PAGE_PERSONAL
:
410 $inside_hook_name = 'options_personal_inside';
411 $bottom_hook_name = 'options_personal_bottom';
412 $submit_name = 'submit_personal';
414 case SMOPT_PAGE_DISPLAY
:
415 $inside_hook_name = 'options_display_inside';
416 $bottom_hook_name = 'options_display_bottom';
417 $submit_name = 'submit_display';
419 case SMOPT_PAGE_HIGHLIGHT
:
420 $inside_hook_name = 'options_highlight_inside';
421 $bottom_hook_name = 'options_highlight_bottom';
422 $submit_name = 'submit_highlight';
424 case SMOPT_PAGE_FOLDER
:
425 $inside_hook_name = 'options_folder_inside';
426 $bottom_hook_name = 'options_folder_bottom';
427 $submit_name = 'submit_folder';
429 case SMOPT_PAGE_ORDER
:
430 $inside_hook_name = 'options_order_inside';
431 $bottom_hook_name = 'options_order_bottom';
432 $submit_name = 'submit_order';
435 $inside_hook_name = '';
436 $bottom_hook_name = '';
437 $submit_name = 'submit';
440 /* If it is not empty, trigger the inside hook. */
441 if ($inside_hook_name != '') {
442 do_hook($inside_hook_name);
445 /* Spit out a submit button. */
446 OptionSubmit($submit_name);
447 echo '</td></tr></table></form>';
449 /* If it is not empty, trigger the bottom hook. */
450 if ($bottom_hook_name != '') {
451 do_hook($bottom_hook_name);