abf23cc97abee2256a5bb4a7d87acca801893f67
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/array.php');
23 require_once(SM_PATH
. 'functions/options.php');
24 require_once(SM_PATH
. 'functions/strings.php');
25 require_once(SM_PATH
. 'functions/html.php');
27 /*********************************/
28 /*** Build the resultant page. ***/
29 /*********************************/
31 displayPageHeader($color, 'None');
33 define('SMOPT_MODE_DISPLAY', 'display');
34 define('SMOPT_MODE_SUBMIT', 'submit');
35 define('SMOPT_MODE_LINK', 'link');
37 define('SMOPT_PAGE_MAIN', 'main');
38 define('SMOPT_PAGE_PERSONAL', 'personal');
39 define('SMOPT_PAGE_DISPLAY', 'display');
40 define('SMOPT_PAGE_HIGHLIGHT', 'highlight');
41 define('SMOPT_PAGE_FOLDER', 'folder');
42 define('SMOPT_PAGE_ORDER', 'order');
44 function process_optionmode_submit($optpage, $optpage_data) {
45 /* Initialize the maximum option refresh level. */
46 $max_refresh = SMOPT_REFRESH_NONE
;
48 /* Save each option in each option group. */
49 foreach ($optpage_data['options'] as $option_grp) {
50 foreach ($option_grp['options'] as $option) {
51 /* Remove Debug Mode Until Needed
52 echo "name = '$option->name', "
53 . "value = '$option->value', "
54 . "new_value = '$option->new_value'\n";
57 if ($option->changed()) {
59 $max_refresh = max($max_refresh, $option->refresh_level
);
64 /* Return the max refresh level. */
65 return ($max_refresh);
68 function process_optionmode_link($optpage) {
69 /* There will be something here, later. */
74 * This function prints out an option page row.
76 function print_optionpages_row($leftopt, $rightopt = false) {
80 $rightopt_name = html_tag( 'td', '<a href="' . $rightopt['url'] . '">' . $rightopt['name'] . '</a>', 'left', $color[9], 'valign="top" width="49%"' );
81 $rightopt_desc = html_tag( 'td', $rightopt['desc'], 'left', $color[0], 'valign="top" width="49%"' );
83 $rightopt_name = html_tag( 'td', ' ', 'left', $color[4], 'valign="top" width="49%"' );
84 $rightopt_desc = html_tag( 'td', ' ', 'left', $color[4], 'valign="top" width="49%"' );
88 html_tag( 'table', "\n" .
89 html_tag( 'tr', "\n" .
90 html_tag( 'td', "\n" .
91 html_tag( 'table', "\n" .
92 html_tag( 'tr', "\n" .
94 '<a href="' . $leftopt['url'] . '">' . $leftopt['name'] . '</a>' ,
95 'left', $color[9], 'valign="top" width="49%"' ) .
98 'left', $color[4], 'valign="top" width="2%"' ) . "\n" .
101 html_tag( 'tr', "\n" .
104 'left', $color[0], 'valign="top" width="49%"' ) .
107 'left', $color[4], 'valign="top" width="2%"' ) . "\n" .
110 '', '', 'width="100%" cellpadding="2" cellspacing="0" border="0"' ) ,
111 'left', '', 'valign="top"' )
113 '', $color[4], 'width="100%" cellpadding="0" cellspacing="5" border="0"' );
116 /* ---------------------------- main ---------------------------- */
118 /* get the globals that we may need */
119 if (isset($_GET['optpage'])) {
120 $optpage = $_GET['optpage'];
122 elseif (isset($_POST['optpage'])) {
123 $optpage = $_POST['optpage'];
125 if (isset($_POST['optmode'])) {
126 $optmode = $_POST['optmode'];
128 if (isset($_POST['optpage_data'])) {
129 $optpage_data = $_POST['optpage_data'];
131 $username = $_SESSION['username'];
132 $key = $_COOKIE['key'];
133 $onetimepad = $_SESSION['onetimepad'];
134 $delimiter = $_SESSION['delimiter'];
136 /* end of getting globals */
138 /* Make sure we have an Option Page set. Default to main. */
139 if ( !isset($optpage) ||
$optpage == '' ) {
140 $optpage = SMOPT_PAGE_MAIN
;
142 $optpage = strip_tags( $optpage );
145 /* Make sure we have an Option Mode set. Default to display. */
146 if (!isset($optmode)) {
147 $optmode = SMOPT_MODE_DISPLAY
;
151 * First, set the load information for each option page.
154 /* Initialize load information variables. */
157 $optpage_loader = '';
159 /* Set the load information for each page. */
161 case SMOPT_PAGE_MAIN
:
163 case SMOPT_PAGE_PERSONAL
:
164 $optpage_name = _("Personal Information");
165 $optpage_file = SM_PATH
. 'include/options/personal.php';
166 $optpage_loader = 'load_optpage_data_personal';
167 $optpage_loadhook = 'optpage_loadhook_personal';
169 case SMOPT_PAGE_DISPLAY
:
170 $optpage_name = _("Display Preferences");
171 $optpage_file = SM_PATH
. 'include/options/display.php';
172 $optpage_loader = 'load_optpage_data_display';
173 $optpage_loadhook = 'optpage_loadhook_display';
175 case SMOPT_PAGE_HIGHLIGHT
:
176 $optpage_name = _("Message Highlighting");
177 $optpage_file = SM_PATH
. 'include/options/highlight.php';
178 $optpage_loader = 'load_optpage_data_highlight';
179 $optpage_loadhook = 'optpage_loadhook_highlight';
181 case SMOPT_PAGE_FOLDER
:
182 $optpage_name = _("Folder Preferences");
183 $optpage_file = SM_PATH
. 'include/options/folder.php';
184 $optpage_loader = 'load_optpage_data_folder';
185 $optpage_loadhook = 'optpage_loadhook_folder';
187 case SMOPT_PAGE_ORDER
:
188 $optpage_name = _("Index Order");
189 $optpage_file = SM_PATH
. 'include/options/order.php';
190 $optpage_loader = 'load_optpage_data_order';
191 $optpage_loadhook = 'optpage_loadhook_order';
193 default: do_hook('optpage_set_loadinfo');
196 /**********************************************************/
197 /*** Second, load the option information for this page. ***/
198 /**********************************************************/
200 if ( !@is_file
( $optpage_file ) ) {
201 $optpage = SMOPT_PAGE_MAIN
;
202 } else if ($optpage != SMOPT_PAGE_MAIN
) {
203 /* Include the file for this optionpage. */
205 require_once($optpage_file);
207 /* Assemble the data for this option page. */
208 $optpage_data = array();
209 $optpage_data = $optpage_loader();
210 do_hook($optpage_loadhook);
211 $optpage_data['options'] =
212 create_option_groups($optpage_data['grps'], $optpage_data['vals']);
215 /***********************************************************/
216 /*** Next, process anything that needs to be processed. ***/
217 /***********************************************************/
219 if ( isset( $optpage_data ) ) {
221 case SMOPT_MODE_SUBMIT
:
222 $max_refresh = process_optionmode_submit($optpage, $optpage_data);
224 case SMOPT_MODE_LINK
:
225 $max_refresh = process_optionmode_link($optpage, $optpage_data);
229 /*** MOVE THIS DISPLAY CODE DOWN EVENTUALLY!!! ***/
231 $optpage_title = _("Options");
232 if (isset($optpage_name) && ($optpage_name != '')) {
233 $optpage_title .= " - $optpage_name";
236 echo html_tag( 'table', '', 'center', $color[0], 'width="95%" cellpadding="1" cellspacing="0" border="0"' ) . "\n" .
237 html_tag( 'tr' ) . "\n" .
238 html_tag( 'td', '', 'center' ) .
239 "<b>$optpage_title</b><br>\n".
240 html_tag( 'table', '', '', '', 'width="100%" cellpadding="5" cellspacing="0" border="0"' ) . "\n" .
241 html_tag( 'tr' ) . "\n" .
242 html_tag( 'td', '', 'center', $color[4] ) . "\n";
244 /*******************************************************************/
245 /* DO OLD SAVING OF SUBMITTED OPTIONS. THIS WILL BE REMOVED LATER. */
246 /*******************************************************************/
248 /* If in submit mode, select a save hook name and run it. */
249 if ($optmode == SMOPT_MODE_SUBMIT
) {
250 /* Select a save hook name. */
252 case SMOPT_PAGE_PERSONAL
:
253 $save_hook_name = 'options_personal_save';
255 case SMOPT_PAGE_DISPLAY
:
256 $save_hook_name = 'options_display_save';
258 case SMOPT_PAGE_FOLDER
:
259 $save_hook_name = 'options_folder_save';
262 $save_hook_name = 'options_save';
266 /* Run the options save hook. */
267 do_hook($save_hook_name);
270 /***************************************************************/
271 /* Apply logic to decide what optpage we want to display next. */
272 /***************************************************************/
274 /* If this is the result of an option page being submitted, then */
275 /* show the main page. Otherwise, show whatever page was called. */
277 if ($optmode == SMOPT_MODE_SUBMIT
) {
278 $optpage = SMOPT_PAGE_MAIN
;
281 /***************************************************************/
282 /* Finally, display whatever page we are supposed to show now. */
283 /***************************************************************/
286 * The main option page has a different layout then the rest of the option
287 * pages. Therefore, we create it here first, then the others below.
289 if ($optpage == SMOPT_PAGE_MAIN
) {
290 /**********************************************************/
291 /* First, display the results of a submission, if needed. */
292 /**********************************************************/
293 if ($optmode == SMOPT_MODE_SUBMIT
) {
294 if (!isset($frame_top)) {
297 /* Display a message indicating a successful save. */
298 echo '<b>' . _("Successfully Saved Options") . ": $optpage_name</b><br>\n";
300 /* If $max_refresh != SMOPT_REFRESH_NONE, provide a refresh link. */
301 if ( !isset( $max_refresh ) ) {
302 } else if ($max_refresh == SMOPT_REFRESH_FOLDERLIST
) {
303 echo '<a href="../src/left_main.php" target="left">' . _("Refresh Folder List") . '</a><br>';
304 } else if ($max_refresh) {
305 echo '<a href="../src/webmail.php?right_frame=options.php" target="' . $frame_top . '">' . _("Refresh Page") . '</a><br>';
308 /******************************************/
309 /* Build our array of Option Page Blocks. */
310 /******************************************/
311 $optpage_blocks = array();
313 /* Build a section for Personal Options. */
314 $optpage_blocks[] = array(
315 'name' => _("Personal Information"),
316 'url' => 'options.php?optpage=' . SMOPT_PAGE_PERSONAL
,
317 'desc' => _("This contains personal information about yourself such as your name, your email address, etc."),
321 /* Build a section for Display Options. */
322 $optpage_blocks[] = array(
323 'name' => _("Display Preferences"),
324 'url' => 'options.php?optpage=' . SMOPT_PAGE_DISPLAY
,
325 'desc' => _("You can change the way that SquirrelMail looks and displays information to you, such as the colors, the language, and other settings."),
329 /* Build a section for Message Highlighting Options. */
330 $optpage_blocks[] = array(
331 'name' =>_("Message Highlighting"),
332 'url' => 'options_highlight.php',
333 '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."),
337 /* Build a section for Folder Options. */
338 $optpage_blocks[] = array(
339 'name' => _("Folder Preferences"),
340 'url' => 'options.php?optpage=' . SMOPT_PAGE_FOLDER
,
341 'desc' => _("These settings change the way your folders are displayed and manipulated."),
345 /* Build a section for Index Order Options. */
346 $optpage_blocks[] = array(
347 'name' => _("Index Order"),
348 'url' => 'options_order.php',
349 'desc' => _("The order of the message index can be rearranged and changed to contain the headers in any order you want."),
353 /* Build a section for plugins wanting to register an optionpage. */
354 do_hook('optpage_register_block');
356 /*****************************************************/
357 /* Let's sort Javascript Option Pages to the bottom. */
358 /*****************************************************/
359 $js_optpage_blocks = array();
360 $reg_optpage_blocks = array();
361 foreach ($optpage_blocks as $cur_optpage) {
362 if (!$cur_optpage['js']) {
363 $reg_optpage_blocks[] = $cur_optpage;
364 } else if ($javascript_on == SMPREF_JS_ON
) {
365 $js_optpage_blocks[] = $cur_optpage;
368 $optpage_blocks = array_merge($reg_optpage_blocks, $js_optpage_blocks);
370 /********************************************/
371 /* Now, print out each option page section. */
372 /********************************************/
373 $first_optpage = false;
374 echo html_tag( 'table', '', '', $color[4], 'width="100%" cellpadding="0" cellspacing="5" border="0"' ) . "\n" .
375 html_tag( 'tr' ) . "\n" .
376 html_tag( 'td', '', 'left', '', 'valign="top"' ) .
377 html_tag( 'table', '', '', $color[4], 'width="100%" cellpadding="3" cellspacing="0" border="0"' ) . "\n" .
378 html_tag( 'tr' ) . "\n" .
379 html_tag( 'td', '', 'left' );
380 foreach ($optpage_blocks as $next_optpage) {
381 if ($first_optpage == false) {
382 $first_optpage = $next_optpage;
384 print_optionpages_row($first_optpage, $next_optpage);
385 $first_optpage = false;
389 if ($first_optpage != false) {
390 print_optionpages_row($first_optpage);
393 echo "</td></tr></table></td></tr></table>\n";
395 do_hook('options_link_and_description');
398 /*************************************************************************/
399 /* If we are not looking at the main option page, display the page here. */
400 /*************************************************************************/
402 echo '<form name="f" action="options.php" method="post"><br>' . "\n"
403 . create_optpage_element($optpage)
404 . create_optmode_element(SMOPT_MODE_SUBMIT
)
405 . html_tag( 'table', '', '', '', 'width="100%" cellpadding="2" cellspacing="0" border="0"' ) . "\n"
406 . html_tag( 'tr' ) . "\n"
407 . html_tag( 'td', '', 'left' ) . "\n";
409 /* Output the option groups for this page. */
410 print_option_groups($optpage_data['options']);
412 /* Set the inside_hook_name and submit_name. */
414 case SMOPT_PAGE_PERSONAL
:
415 $inside_hook_name = 'options_personal_inside';
416 $bottom_hook_name = 'options_personal_bottom';
417 $submit_name = 'submit_personal';
419 case SMOPT_PAGE_DISPLAY
:
420 $inside_hook_name = 'options_display_inside';
421 $bottom_hook_name = 'options_display_bottom';
422 $submit_name = 'submit_display';
424 case SMOPT_PAGE_HIGHLIGHT
:
425 $inside_hook_name = 'options_highlight_inside';
426 $bottom_hook_name = 'options_highlight_bottom';
427 $submit_name = 'submit_highlight';
429 case SMOPT_PAGE_FOLDER
:
430 $inside_hook_name = 'options_folder_inside';
431 $bottom_hook_name = 'options_folder_bottom';
432 $submit_name = 'submit_folder';
434 case SMOPT_PAGE_ORDER
:
435 $inside_hook_name = 'options_order_inside';
436 $bottom_hook_name = 'options_order_bottom';
437 $submit_name = 'submit_order';
440 $inside_hook_name = '';
441 $bottom_hook_name = '';
442 $submit_name = 'submit';
445 /* If it is not empty, trigger the inside hook. */
446 if ($inside_hook_name != '') {
447 do_hook($inside_hook_name);
450 /* Spit out a submit button. */
451 OptionSubmit($submit_name);
452 echo '</td></tr></table></form>';
454 /* If it is not empty, trigger the bottom hook. */
455 if ($bottom_hook_name != '') {
456 do_hook($bottom_hook_name);