6 * Copyright (c) 1999-2002 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.
15 /* Path for SquirrelMail required files. */
16 define('SM_PATH','../');
18 /* SquirrelMail required files. */
19 require_once(SM_PATH
. 'include/validate.php');
20 require_once(SM_PATH
. 'functions/display_messages.php');
21 require_once(SM_PATH
. 'functions/imap.php');
22 require_once(SM_PATH
. 'functions/options.php');
23 require_once(SM_PATH
. 'functions/strings.php');
24 require_once(SM_PATH
. 'functions/html.php');
26 /*********************************/
27 /*** Build the resultant page. ***/
28 /*********************************/
30 displayPageHeader($color, 'None');
32 define('SMOPT_MODE_DISPLAY', 'display');
33 define('SMOPT_MODE_SUBMIT', 'submit');
34 define('SMOPT_MODE_LINK', 'link');
36 define('SMOPT_PAGE_MAIN', 'main');
37 define('SMOPT_PAGE_PERSONAL', 'personal');
38 define('SMOPT_PAGE_DISPLAY', 'display');
39 define('SMOPT_PAGE_HIGHLIGHT', 'highlight');
40 define('SMOPT_PAGE_FOLDER', 'folder');
41 define('SMOPT_PAGE_ORDER', 'order');
43 function process_optionmode_submit($optpage, $optpage_data) {
44 /* Initialize the maximum option refresh level. */
45 $max_refresh = SMOPT_REFRESH_NONE
;
47 /* Save each option in each option group. */
48 foreach ($optpage_data['options'] as $option_grp) {
49 foreach ($option_grp['options'] as $option) {
50 /* Remove Debug Mode Until Needed
51 echo "name = '$option->name', "
52 . "value = '$option->value', "
53 . "new_value = '$option->new_value'\n";
56 if ($option->changed()) {
58 $max_refresh = max($max_refresh, $option->refresh_level
);
63 /* Return the max refresh level. */
64 return ($max_refresh);
67 function process_optionmode_link($optpage) {
68 /* There will be something here, later. */
73 * This function prints out an option page row.
75 function print_optionpages_row($leftopt, $rightopt = false) {
79 $rightopt_name = html_tag( 'td', '<a href="' . $rightopt['url'] . '">' . $rightopt['name'] . '</a>', 'left', $color[9], 'valign="top" width="49%"' );
80 $rightopt_desc = html_tag( 'td', $rightopt['desc'], 'left', $color[0], 'valign="top" width="49%"' );
82 $rightopt_name = html_tag( 'td', ' ', 'left', $color[4], 'valign="top" width="49%"' );
83 $rightopt_desc = html_tag( 'td', ' ', 'left', $color[4], 'valign="top" width="49%"' );
87 html_tag( 'table', "\n" .
88 html_tag( 'tr', "\n" .
89 html_tag( 'td', "\n" .
90 html_tag( 'table', "\n" .
91 html_tag( 'tr', "\n" .
93 '<a href="' . $leftopt['url'] . '">' . $leftopt['name'] . '</a>' ,
94 'left', $color[9], 'valign="top" width="49%"' ) .
97 'left', $color[4], 'valign="top" width="2%"' ) . "\n" .
100 html_tag( 'tr', "\n" .
103 'left', $color[0], 'valign="top" width="49%"' ) .
106 'left', $color[4], 'valign="top" width="2%"' ) . "\n" .
109 '', '', 'width="100%" cellpadding="2" cellspacing="0" border="0"' ) ,
110 'left', '', 'valign="top"' )
112 '', $color[4], 'width="100%" cellpadding="0" cellspacing="5" border="0"' );
115 /* ---------------------------- main ---------------------------- */
117 /* get the globals that we may need */
118 if (isset($_GET['optpage'])) {
119 $optpage = $_GET['optpage'];
121 elseif (isset($_POST['optpage'])) {
122 $optpage = $_POST['optpage'];
124 if (isset($_POST['optmode'])) {
125 $optmode = $_POST['optmode'];
127 if (isset($_POST['optpage_data'])) {
128 $optpage_data = $_POST['optpage_data'];
130 $username = $_SESSION['username'];
131 $key = $_COOKIE['key'];
132 $onetimepad = $_SESSION['onetimepad'];
133 $delimiter = $_SESSION['delimiter'];
135 /* end of getting globals */
137 /* Make sure we have an Option Page set. Default to main. */
138 if ( !isset($optpage) ||
$optpage == '' ) {
139 $optpage = SMOPT_PAGE_MAIN
;
141 $optpage = strip_tags( $optpage );
144 /* Make sure we have an Option Mode set. Default to display. */
145 if (!isset($optmode)) {
146 $optmode = SMOPT_MODE_DISPLAY
;
150 * First, set the load information for each option page.
153 /* Initialize load information variables. */
156 $optpage_loader = '';
158 /* Set the load information for each page. */
160 case SMOPT_PAGE_MAIN
:
162 case SMOPT_PAGE_PERSONAL
:
163 $optpage_name = _("Personal Information");
164 $optpage_file = SM_PATH
. 'include/options/personal.php';
165 $optpage_loader = 'load_optpage_data_personal';
166 $optpage_loadhook = 'optpage_loadhook_personal';
168 case SMOPT_PAGE_DISPLAY
:
169 $optpage_name = _("Display Preferences");
170 $optpage_file = SM_PATH
. 'include/options/display.php';
171 $optpage_loader = 'load_optpage_data_display';
172 $optpage_loadhook = 'optpage_loadhook_display';
174 case SMOPT_PAGE_HIGHLIGHT
:
175 $optpage_name = _("Message Highlighting");
176 $optpage_file = SM_PATH
. 'include/options/highlight.php';
177 $optpage_loader = 'load_optpage_data_highlight';
178 $optpage_loadhook = 'optpage_loadhook_highlight';
180 case SMOPT_PAGE_FOLDER
:
181 $optpage_name = _("Folder Preferences");
182 $optpage_file = SM_PATH
. 'include/options/folder.php';
183 $optpage_loader = 'load_optpage_data_folder';
184 $optpage_loadhook = 'optpage_loadhook_folder';
186 case SMOPT_PAGE_ORDER
:
187 $optpage_name = _("Index Order");
188 $optpage_file = SM_PATH
. 'include/options/order.php';
189 $optpage_loader = 'load_optpage_data_order';
190 $optpage_loadhook = 'optpage_loadhook_order';
192 default: do_hook('optpage_set_loadinfo');
195 /**********************************************************/
196 /*** Second, load the option information for this page. ***/
197 /**********************************************************/
199 if ( !@is_file
( $optpage_file ) ) {
200 $optpage = SMOPT_PAGE_MAIN
;
201 } else if ($optpage != SMOPT_PAGE_MAIN
) {
202 /* Include the file for this optionpage. */
204 require_once($optpage_file);
206 /* Assemble the data for this option page. */
207 $optpage_data = array();
208 $optpage_data = $optpage_loader();
209 do_hook($optpage_loadhook);
210 $optpage_data['options'] =
211 create_option_groups($optpage_data['grps'], $optpage_data['vals']);
214 /***********************************************************/
215 /*** Next, process anything that needs to be processed. ***/
216 /***********************************************************/
218 if ( isset( $optpage_data ) ) {
220 case SMOPT_MODE_SUBMIT
:
221 $max_refresh = process_optionmode_submit($optpage, $optpage_data);
223 case SMOPT_MODE_LINK
:
224 $max_refresh = process_optionmode_link($optpage, $optpage_data);
228 /*** MOVE THIS DISPLAY CODE DOWN EVENTUALLY!!! ***/
230 $optpage_title = _("Options");
231 if (isset($optpage_name) && ($optpage_name != '')) {
232 $optpage_title .= " - $optpage_name";
235 echo html_tag( 'table', '', 'center', $color[0], 'width="95%" cellpadding="1" cellspacing="0" border="0"' ) . "\n" .
236 html_tag( 'tr' ) . "\n" .
237 html_tag( 'td', '', 'center' ) .
238 "<b>$optpage_title</b><br>\n".
239 html_tag( 'table', '', '', '', 'width="100%" cellpadding="5" cellspacing="0" border="0"' ) . "\n" .
240 html_tag( 'tr' ) . "\n" .
241 html_tag( 'td', '', 'center', $color[4] ) . "\n";
243 /*******************************************************************/
244 /* DO OLD SAVING OF SUBMITTED OPTIONS. THIS WILL BE REMOVED LATER. */
245 /*******************************************************************/
247 /* If in submit mode, select a save hook name and run it. */
248 if ($optmode == SMOPT_MODE_SUBMIT
) {
249 /* Select a save hook name. */
251 case SMOPT_PAGE_PERSONAL
:
252 $save_hook_name = 'options_personal_save';
254 case SMOPT_PAGE_DISPLAY
:
255 $save_hook_name = 'options_display_save';
257 case SMOPT_PAGE_FOLDER
:
258 $save_hook_name = 'options_folder_save';
261 $save_hook_name = 'options_save';
265 /* Run the options save hook. */
266 do_hook($save_hook_name);
269 /***************************************************************/
270 /* Apply logic to decide what optpage we want to display next. */
271 /***************************************************************/
273 /* If this is the result of an option page being submitted, then */
274 /* show the main page. Otherwise, show whatever page was called. */
276 if ($optmode == SMOPT_MODE_SUBMIT
) {
277 $optpage = SMOPT_PAGE_MAIN
;
280 /***************************************************************/
281 /* Finally, display whatever page we are supposed to show now. */
282 /***************************************************************/
285 * The main option page has a different layout then the rest of the option
286 * pages. Therefore, we create it here first, then the others below.
288 if ($optpage == SMOPT_PAGE_MAIN
) {
289 /**********************************************************/
290 /* First, display the results of a submission, if needed. */
291 /**********************************************************/
292 if ($optmode == SMOPT_MODE_SUBMIT
) {
293 if (!isset($frame_top)) {
296 /* Display a message indicating a successful save. */
297 echo '<b>' . _("Successfully Saved Options") . ": $optpage_name</b><br>\n";
299 /* If $max_refresh != SMOPT_REFRESH_NONE, provide a refresh link. */
300 if ( !isset( $max_refresh ) ) {
301 } else if ($max_refresh == SMOPT_REFRESH_FOLDERLIST
) {
302 echo '<a href="../src/left_main.php" target="left">' . _("Refresh Folder List") . '</a><br>';
303 } else if ($max_refresh) {
304 echo '<a href="../src/webmail.php?right_frame=options.php" target="' . $frame_top . '">' . _("Refresh Page") . '</a><br>';
307 /******************************************/
308 /* Build our array of Option Page Blocks. */
309 /******************************************/
310 $optpage_blocks = array();
312 /* Build a section for Personal Options. */
313 $optpage_blocks[] = array(
314 'name' => _("Personal Information"),
315 'url' => 'options.php?optpage=' . SMOPT_PAGE_PERSONAL
,
316 'desc' => _("This contains personal information about yourself such as your name, your email address, etc."),
320 /* Build a section for Display Options. */
321 $optpage_blocks[] = array(
322 'name' => _("Display Preferences"),
323 'url' => 'options.php?optpage=' . SMOPT_PAGE_DISPLAY
,
324 'desc' => _("You can change the way that SquirrelMail looks and displays information to you, such as the colors, the language, and other settings."),
328 /* Build a section for Message Highlighting Options. */
329 $optpage_blocks[] = array(
330 'name' =>_("Message Highlighting"),
331 'url' => 'options_highlight.php',
332 '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."),
336 /* Build a section for Folder Options. */
337 $optpage_blocks[] = array(
338 'name' => _("Folder Preferences"),
339 'url' => 'options.php?optpage=' . SMOPT_PAGE_FOLDER
,
340 'desc' => _("These settings change the way your folders are displayed and manipulated."),
344 /* Build a section for Index Order Options. */
345 $optpage_blocks[] = array(
346 'name' => _("Index Order"),
347 'url' => 'options_order.php',
348 'desc' => _("The order of the message index can be rearranged and changed to contain the headers in any order you want."),
352 /* Build a section for plugins wanting to register an optionpage. */
353 do_hook('optpage_register_block');
355 /*****************************************************/
356 /* Let's sort Javascript Option Pages to the bottom. */
357 /*****************************************************/
358 $js_optpage_blocks = array();
359 $reg_optpage_blocks = array();
360 foreach ($optpage_blocks as $cur_optpage) {
361 if (!$cur_optpage['js']) {
362 $reg_optpage_blocks[] = $cur_optpage;
363 } else if ($javascript_on == SMPREF_JS_ON
) {
364 $js_optpage_blocks[] = $cur_optpage;
367 $optpage_blocks = array_merge($reg_optpage_blocks, $js_optpage_blocks);
369 /********************************************/
370 /* Now, print out each option page section. */
371 /********************************************/
372 $first_optpage = false;
373 echo html_tag( 'table', '', '', $color[4], 'width="100%" cellpadding="0" cellspacing="5" border="0"' ) . "\n" .
374 html_tag( 'tr' ) . "\n" .
375 html_tag( 'td', '', 'left', '', 'valign="top"' ) .
376 html_tag( 'table', '', '', $color[4], 'width="100%" cellpadding="3" cellspacing="0" border="0"' ) . "\n" .
377 html_tag( 'tr' ) . "\n" .
378 html_tag( 'td', '', 'left' );
379 foreach ($optpage_blocks as $next_optpage) {
380 if ($first_optpage == false) {
381 $first_optpage = $next_optpage;
383 print_optionpages_row($first_optpage, $next_optpage);
384 $first_optpage = false;
388 if ($first_optpage != false) {
389 print_optionpages_row($first_optpage);
392 echo "</td></tr></table></td></tr></table>\n";
394 do_hook('options_link_and_description');
397 /*************************************************************************/
398 /* If we are not looking at the main option page, display the page here. */
399 /*************************************************************************/
401 echo '<form name="f" action="options.php" method="post"><br>' . "\n"
402 . create_optpage_element($optpage)
403 . create_optmode_element(SMOPT_MODE_SUBMIT
)
404 . html_tag( 'table', '', '', '', 'width="100%" cellpadding="2" cellspacing="0" border="0"' ) . "\n"
405 . html_tag( 'tr' ) . "\n"
406 . html_tag( 'td', '', 'left' ) . "\n";
408 /* Output the option groups for this page. */
409 print_option_groups($optpage_data['options']);
411 /* Set the inside_hook_name and submit_name. */
413 case SMOPT_PAGE_PERSONAL
:
414 $inside_hook_name = 'options_personal_inside';
415 $bottom_hook_name = 'options_personal_bottom';
416 $submit_name = 'submit_personal';
418 case SMOPT_PAGE_DISPLAY
:
419 $inside_hook_name = 'options_display_inside';
420 $bottom_hook_name = 'options_display_bottom';
421 $submit_name = 'submit_display';
423 case SMOPT_PAGE_HIGHLIGHT
:
424 $inside_hook_name = 'options_highlight_inside';
425 $bottom_hook_name = 'options_highlight_bottom';
426 $submit_name = 'submit_highlight';
428 case SMOPT_PAGE_FOLDER
:
429 $inside_hook_name = 'options_folder_inside';
430 $bottom_hook_name = 'options_folder_bottom';
431 $submit_name = 'submit_folder';
433 case SMOPT_PAGE_ORDER
:
434 $inside_hook_name = 'options_order_inside';
435 $bottom_hook_name = 'options_order_bottom';
436 $submit_name = 'submit_order';
439 $inside_hook_name = '';
440 $bottom_hook_name = '';
441 $submit_name = 'submit';
444 /* If it is not empty, trigger the inside hook. */
445 if ($inside_hook_name != '') {
446 do_hook($inside_hook_name);
449 /* Spit out a submit button. */
450 OptionSubmit($submit_name);
451 echo '</td></tr></table></form>';
453 /* If it is not empty, trigger the bottom hook. */
454 if ($bottom_hook_name != '') {
455 do_hook($bottom_hook_name);