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 require_once('../src/validate.php');
16 require_once('../functions/display_messages.php');
17 require_once('../functions/imap.php');
18 require_once('../functions/array.php');
19 require_once('../functions/options.php');
20 require_once('../functions/strings.php');
21 require_once('../functions/html.php');
23 /*********************************/
24 /*** Build the resultant page. ***/
25 /*********************************/
27 displayPageHeader($color, 'None');
29 define('SMOPT_MODE_DISPLAY', 'display');
30 define('SMOPT_MODE_SUBMIT', 'submit');
31 define('SMOPT_MODE_LINK', 'link');
33 define('SMOPT_PAGE_MAIN', 'main');
34 define('SMOPT_PAGE_PERSONAL', 'personal');
35 define('SMOPT_PAGE_DISPLAY', 'display');
36 define('SMOPT_PAGE_HIGHLIGHT', 'highlight');
37 define('SMOPT_PAGE_FOLDER', 'folder');
38 define('SMOPT_PAGE_ORDER', 'order');
40 function process_optionmode_submit($optpage, $optpage_data) {
41 /* Initialize the maximum option refresh level. */
42 $max_refresh = SMOPT_REFRESH_NONE
;
44 /* Save each option in each option group. */
45 foreach ($optpage_data['options'] as $option_grp) {
46 foreach ($option_grp['options'] as $option) {
47 /* Remove Debug Mode Until Needed
48 echo "name = '$option->name', "
49 . "value = '$option->value', "
50 . "new_value = '$option->new_value'<br>\n";
52 if ($option->changed()) {
54 $max_refresh = max($max_refresh, $option->refresh_level
);
59 /* Return the max refresh level. */
60 return ($max_refresh);
63 function process_optionmode_link($optpage) {
64 /* There will be something here, later. */
69 * This function prints out an option page row.
71 function print_optionpages_row($leftopt, $rightopt = false) {
75 $rightopt_name = html_tag( 'td', '<a href="' . $rightopt['url'] . '">' . $rightopt['name'] . '</a>', 'left', $color[9], 'valign="top" width="49%"' );
76 $rightopt_desc = html_tag( 'td', $rightopt['desc'], 'left', $color[0], 'valign="top" width="49%"' );
78 $rightopt_name = html_tag( 'td', ' ', 'left', $color[4], 'valign="top" width="49%"' );
79 $rightopt_desc = html_tag( 'td', ' ', 'left', $color[4], 'valign="top" width="49%"' );
83 html_tag( 'table', "\n" .
84 html_tag( 'tr', "\n" .
85 html_tag( 'td', "\n" .
86 html_tag( 'table', "\n" .
87 html_tag( 'tr', "\n" .
89 '<a href="' . $leftopt['url'] . '">' . $leftopt['name'] . '</a>' ,
90 'left', $color[9], 'valign="top" width="49%"' ) .
93 'left', $color[4], 'valign="top" width="2%"' ) . "\n" .
96 html_tag( 'tr', "\n" .
99 'left', $color[0], 'valign="top" width="49%"' ) .
102 'left', $color[4], 'valign="top" width="2%"' ) . "\n" .
105 '', '', 'width="100%" cellpadding="2" cellspacing="0" border="0"' ) ,
106 'left', '', 'valign="top"' )
108 '', $color[4], 'width="100%" cellpadding="0" cellspacing="5" border="0"' );
111 /* ---------------------------- main ---------------------------- */
113 /* Make sure we have an Option Page set. Default to main. */
114 if (!isset($optpage)) {
118 /* Make sure we have an Option Mode set. Default to display. */
119 if (!isset($optmode)) {
120 $optmode = SMOPT_MODE_DISPLAY
;
124 * First, set the load information for each option page.
127 /* Initialize load information variables. */
130 $optpage_loader = '';
132 /* Set the load information for each page. */
134 case SMOPT_PAGE_MAIN
: break;
135 case SMOPT_PAGE_PERSONAL
:
136 $optpage_name = _("Personal Information");
137 $optpage_file = '../src/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 = '../src/options_display.php';
144 $optpage_loader = 'load_optpage_data_display';
145 $optpage_loadhook = 'optpage_loadhook_display';
147 case SMOPT_PAGE_HIGHLIGHT
:
148 $optpage_name = _("Message Highlighting");
149 $optpage_file = '../src/options_highlight.php';
150 $optpage_loader = 'load_optpage_data_highlight';
151 $optpage_loadhook = 'optpage_loadhook_highlight';
153 case SMOPT_PAGE_FOLDER
:
154 $optpage_name = _("Folder Preferences");
155 $optpage_file = '../src/options_folder.php';
156 $optpage_loader = 'load_optpage_data_folder';
157 $optpage_loadhook = 'optpage_loadhook_folder';
159 case SMOPT_PAGE_ORDER
:
160 $optpage_name = _("Index Order");
161 $optpage_file = '../src/options_order.php';
162 $optpage_loader = 'load_optpage_data_order';
163 $optpage_loadhook = 'optpage_loadhook_order';
165 default: do_hook('optpage_set_loadinfo');
168 /**********************************************************/
169 /*** Second, load the option information for this page. ***/
170 /**********************************************************/
172 if ($optpage != SMOPT_PAGE_MAIN
) {
173 /* Include the file for this optionpage. */
174 require_once($optpage_file);
176 /* Assemble the data for this option page. */
177 $optpage_data = array();
178 $optpage_data = $optpage_loader();
179 do_hook($optpage_loadhook);
180 $optpage_data['options'] =
181 create_option_groups($optpage_data['grps'], $optpage_data['vals']);
184 /***********************************************************/
185 /*** Next, process anything that needs to be processed. ***/
186 /***********************************************************/
188 if ( isset( $optpage_data ) ) {
190 case SMOPT_MODE_SUBMIT
:
191 $max_refresh = process_optionmode_submit($optpage, $optpage_data);
193 case SMOPT_MODE_LINK
:
194 $max_refresh = process_optionmode_link($optpage, $optpage_data);
198 /*** MOVE THIS DISPLAY CODE DOWN EVENTUALLY!!! ***/
200 $optpage_title = _("Options");
201 if (isset($optpage_name) && ($optpage_name != '')) {
202 $optpage_title .= " - $optpage_name";
206 html_tag( 'table', '', 'center', $color[0], 'width="95%" cellpadding="2" cellspacing="0" border="0"' ) . "\n" .
207 html_tag( 'tr' ) . "\n" .
208 html_tag( 'td', '', 'center' ) .
209 "<b>$optpage_title</b><br>\n".
210 html_tag( 'table', '', '', '', 'width="100%" cellpadding="5" cellspacing="0" border="0"' ) . "\n" .
211 html_tag( 'tr' ) . "\n" .
212 html_tag( 'td', '', 'center', $color[4] ) . "\n";
214 /*******************************************************************/
215 /* DO OLD SAVING OF SUBMITTED OPTIONS. THIS WILL BE REMOVED LATER. */
216 /*******************************************************************/
218 /* If in submit mode, select a save hook name and run it. */
219 if ($optmode == SMOPT_MODE_SUBMIT
) {
220 /* Select a save hook name. */
222 case SMOPT_PAGE_PERSONAL
:
223 $save_hook_name = 'options_personal_save';
225 case SMOPT_PAGE_DISPLAY
:
226 $save_hook_name = 'options_display_save';
228 case SMOPT_PAGE_FOLDER
:
229 $save_hook_name = 'options_folder_save';
232 $save_hook_name = 'options_save';
236 /* Run the options save hook. */
237 do_hook($save_hook_name);
240 /***************************************************************/
241 /* Apply logic to decide what optpage we want to display next. */
242 /***************************************************************/
244 /* If this is the result of an option page being submitted, then */
245 /* show the main page. Otherwise, show whatever page was called. */
247 if ($optmode == SMOPT_MODE_SUBMIT
) {
248 $optpage = SMOPT_PAGE_MAIN
;
251 /***************************************************************/
252 /* Finally, display whatever page we are supposed to show now. */
253 /***************************************************************/
256 * The main option page has a different layout then the rest of the option
257 * pages. Therefore, we create it here first, then the others below.
259 if ($optpage == SMOPT_PAGE_MAIN
) {
260 /**********************************************************/
261 /* First, display the results of a submission, if needed. */
262 /**********************************************************/
263 if ($optmode == SMOPT_MODE_SUBMIT
) {
264 if (!isset($frame_top)) {
267 /* Display a message indicating a successful save. */
268 echo '<b>' . _("Successfully Saved Options") . ": $optpage_name</b><br>\n";
270 /* If $max_refresh != SMOPT_REFRESH_NONE, provide a refresh link. */
271 if ( !isset( $max_refresh ) ) {
272 } else if ($max_refresh == SMOPT_REFRESH_FOLDERLIST
) {
273 echo '<a href="../src/left_main.php" target="left">' . _("Refresh Folder List") . '</a><br>';
274 } else if ($max_refresh) {
275 echo '<a href="../src/webmail.php?right_frame=options.php" target="' . $frame_top . '">' . _("Refresh Page") . '</a><br>';
278 /******************************************/
279 /* Build our array of Option Page Blocks. */
280 /******************************************/
281 $optpage_blocks = array();
283 /* Build a section for Personal Options. */
284 $optpage_blocks[] = array(
285 'name' => _("Personal Information"),
286 'url' => 'options.php?optpage=' . SMOPT_PAGE_PERSONAL
,
287 'desc' => _("This contains personal information about yourself such as your name, your email address, etc."),
291 /* Build a section for Display Options. */
292 $optpage_blocks[] = array(
293 'name' => _("Display Preferences"),
294 'url' => 'options.php?optpage=' . SMOPT_PAGE_DISPLAY
,
295 'desc' => _("You can change the way that SquirrelMail looks and displays information to you, such as the colors, the language, and other settings."),
299 /* Build a section for Message Highlighting Options. */
300 $optpage_blocks[] = array(
301 'name' =>_("Message Highlighting"),
302 'url' => 'options_highlight.php',
303 '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."),
307 /* Build a section for Folder Options. */
308 $optpage_blocks[] = array(
309 'name' => _("Folder Preferences"),
310 'url' => 'options.php?optpage=' . SMOPT_PAGE_FOLDER
,
311 'desc' => _("These settings change the way your folders are displayed and manipulated."),
315 /* Build a section for Index Order Options. */
316 $optpage_blocks[] = array(
317 'name' => _("Index Order"),
318 'url' => 'options_order.php',
319 'desc' => _("The order of the message index can be rearranged and changed to contain the headers in any order you want."),
323 /* Build a section for plugins wanting to register an optionpage. */
324 do_hook('optpage_register_block');
326 /*****************************************************/
327 /* Let's sort Javascript Option Pages to the bottom. */
328 /*****************************************************/
329 $js_optpage_blocks = array();
330 $reg_optpage_blocks = array();
331 foreach ($optpage_blocks as $cur_optpage) {
332 if (!$cur_optpage['js']) {
333 $reg_optpage_blocks[] = $cur_optpage;
334 } else if ($javascript_on == SMPREF_JS_ON
) {
335 $js_optpage_blocks[] = $cur_optpage;
338 $optpage_blocks = array_merge($reg_optpage_blocks, $js_optpage_blocks);
340 /********************************************/
341 /* Now, print out each option page section. */
342 /********************************************/
343 $first_optpage = false;
344 echo html_tag( 'table', '', '', $color[4], 'width="100%" cellpadding="0" cellspacing="5" border="0"' ) . "\n" .
345 html_tag( 'tr' ) . "\n" .
346 html_tag( 'td', '', 'left', '', 'valign="top"' ) .
347 html_tag( 'table', '', '', $color[4], 'width="100%" cellpadding="3" cellspacing="0" border="0"' ) . "\n" .
348 html_tag( 'tr' ) . "\n" .
349 html_tag( 'td', '', 'left' );
350 foreach ($optpage_blocks as $next_optpage) {
351 if ($first_optpage == false) {
352 $first_optpage = $next_optpage;
354 print_optionpages_row($first_optpage, $next_optpage);
355 $first_optpage = false;
359 if ($first_optpage != false) {
360 print_optionpages_row($first_optpage);
363 echo "</td></tr></table></td></tr></table>\n";
365 do_hook('options_link_and_description');
368 /*************************************************************************/
369 /* If we are not looking at the main option page, display the page here. */
370 /*************************************************************************/
372 echo '<form name="f" action="options.php" method="post"><br>' . "\n"
373 . create_optpage_element($optpage)
374 . create_optmode_element(SMOPT_MODE_SUBMIT
)
375 . html_tag( 'table', '', '', '', 'width="100%" cellpadding="2" cellspacing="0" border="0"' ) . "\n"
376 . html_tag( 'tr' ) . "\n"
377 . html_tag( 'td', '', 'left' ) . "\n";
379 /* Output the option groups for this page. */
380 print_option_groups($optpage_data['options']);
382 /* Set the inside_hook_name and submit_name. */
384 case SMOPT_PAGE_PERSONAL
:
385 $inside_hook_name = 'options_personal_inside';
386 $bottom_hook_name = 'options_personal_bottom';
387 $submit_name = 'submit_personal';
389 case SMOPT_PAGE_DISPLAY
:
390 $inside_hook_name = 'options_display_inside';
391 $bottom_hook_name = 'options_display_bottom';
392 $submit_name = 'submit_display';
394 case SMOPT_PAGE_HIGHLIGHT
:
395 $inside_hook_name = 'options_highlight_inside';
396 $bottom_hook_name = 'options_highlight_bottom';
397 $submit_name = 'submit_highlight';
399 case SMOPT_PAGE_FOLDER
:
400 $inside_hook_name = 'options_folder_inside';
401 $bottom_hook_name = 'options_folder_bottom';
402 $submit_name = 'submit_folder';
404 case SMOPT_PAGE_ORDER
:
405 $inside_hook_name = 'options_order_inside';
406 $bottom_hook_name = 'options_order_bottom';
407 $submit_name = 'submit_order';
410 $inside_hook_name = '';
411 $bottom_hook_name = '';
412 $submit_name = 'submit';
415 /* If it is not empty, trigger the inside hook. */
416 if ($inside_hook_name != '') {
417 do_hook($inside_hook_name);
420 /* Spit out a submit button. */
421 OptionSubmit($submit_name);
422 echo '</td></tr></table></form>';
424 /* If it is not empty, trigger the bottom hook. */
425 if ($bottom_hook_name != '') {
426 do_hook($bottom_hook_name);