Spanish Update
[squirrelmail.git] / src / options.php
CommitLineData
59177427 1<?php
d3cdb279 2
35586184 3/**
4 * options.php
5 *
15e6162e 6 * Copyright (c) 1999-2002 The SquirrelMail Project Team
35586184 7 * Licensed under the GNU GPL. For full terms see the file COPYING.
8 *
9 * Displays the options page. Pulls from proper user preference files
10 * and config.php. Displays preferences as selected and other options.
11 *
12 * $Id$
13 */
cbe5423b 14
86725763 15/* Path for SquirrelMail required files. */
16define('SM_PATH','../');
17
18/* SquirrelMail required files. */
08185f2a 19require_once(SM_PATH . 'include/validate.php');
86725763 20require_once(SM_PATH . 'functions/display_messages.php');
21require_once(SM_PATH . 'functions/imap.php');
22require_once(SM_PATH . 'functions/array.php');
23require_once(SM_PATH . 'functions/options.php');
24require_once(SM_PATH . 'functions/strings.php');
25require_once(SM_PATH . 'functions/html.php');
cbe5423b 26
cbe5423b 27/*********************************/
28/*** Build the resultant page. ***/
29/*********************************/
30
2d367c68 31displayPageHeader($color, 'None');
cbe5423b 32
33define('SMOPT_MODE_DISPLAY', 'display');
34define('SMOPT_MODE_SUBMIT', 'submit');
35define('SMOPT_MODE_LINK', 'link');
36
37define('SMOPT_PAGE_MAIN', 'main');
38define('SMOPT_PAGE_PERSONAL', 'personal');
39define('SMOPT_PAGE_DISPLAY', 'display');
40define('SMOPT_PAGE_HIGHLIGHT', 'highlight');
41define('SMOPT_PAGE_FOLDER', 'folder');
42define('SMOPT_PAGE_ORDER', 'order');
43
44function process_optionmode_submit($optpage, $optpage_data) {
45 /* Initialize the maximum option refresh level. */
46 $max_refresh = SMOPT_REFRESH_NONE;
47
48 /* Save each option in each option group. */
49 foreach ($optpage_data['options'] as $option_grp) {
50 foreach ($option_grp['options'] as $option) {
534367eb 51 /* Remove Debug Mode Until Needed
cbe5423b 52 echo "name = '$option->name', "
53 . "value = '$option->value', "
6206f6c4 54 . "new_value = '$option->new_value'\n";
55 echo "<br>";
534367eb 56 */
cbe5423b 57 if ($option->changed()) {
58 $option->save();
59 $max_refresh = max($max_refresh, $option->refresh_level);
60 }
61 }
62 }
1e0628fb 63
cbe5423b 64 /* Return the max refresh level. */
65 return ($max_refresh);
66}
67
68function process_optionmode_link($optpage) {
69 /* There will be something here, later. */
70}
71
0b0e96c5 72
73/**
74 * This function prints out an option page row.
75 */
76function print_optionpages_row($leftopt, $rightopt = false) {
77 global $color;
78
0b0e96c5 79 if ($rightopt) {
545238b1 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%"' );
0b0e96c5 82 } else {
545238b1 83 $rightopt_name = html_tag( 'td', '&nbsp;', 'left', $color[4], 'valign="top" width="49%"' );
84 $rightopt_desc = html_tag( 'td', '&nbsp;', 'left', $color[4], 'valign="top" width="49%"' );
0b0e96c5 85 }
86
545238b1 87 echo
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" .
93 html_tag( 'td',
94 '<a href="' . $leftopt['url'] . '">' . $leftopt['name'] . '</a>' ,
95 'left', $color[9], 'valign="top" width="49%"' ) .
96 html_tag( 'td',
97 '&nbsp;' ,
98 'left', $color[4], 'valign="top" width="2%"' ) . "\n" .
99 $rightopt_name
100 ) . "\n" .
101 html_tag( 'tr', "\n" .
102 html_tag( 'td',
103 $leftopt['desc'] ,
104 'left', $color[0], 'valign="top" width="49%"' ) .
105 html_tag( 'td',
106 '&nbsp;' ,
107 'left', $color[4], 'valign="top" width="2%"' ) . "\n" .
108 $rightopt_desc
109 ) ,
110 '', '', 'width="100%" cellpadding="2" cellspacing="0" border="0"' ) ,
111 'left', '', 'valign="top"' )
112 ) ,
113 '', $color[4], 'width="100%" cellpadding="0" cellspacing="5" border="0"' );
0b0e96c5 114}
115
116/* ---------------------------- main ---------------------------- */
117
cbe5423b 118/* Make sure we have an Option Page set. Default to main. */
c1f7790a 119if ( !isset($optpage) || $optpage == '' ) {
120 $optpage = SMOPT_PAGE_MAIN;
121} else {
122 $optpage = strip_tags( $optpage );
cbe5423b 123}
124
125/* Make sure we have an Option Mode set. Default to display. */
126if (!isset($optmode)) {
127 $optmode = SMOPT_MODE_DISPLAY;
128}
129
0b0e96c5 130/*
131 * First, set the load information for each option page.
132 */
cbe5423b 133
134/* Initialize load information variables. */
135$optpage_name = '';
136$optpage_file = '';
137$optpage_loader = '';
138
139/* Set the load information for each page. */
140switch ($optpage) {
c1f7790a 141 case SMOPT_PAGE_MAIN:
142 break;
cbe5423b 143 case SMOPT_PAGE_PERSONAL:
a3439b27 144 $optpage_name = _("Personal Information");
08185f2a 145 $optpage_file = SM_PATH . 'include/options/personal.php';
a3439b27 146 $optpage_loader = 'load_optpage_data_personal';
147 $optpage_loadhook = 'optpage_loadhook_personal';
cbe5423b 148 break;
149 case SMOPT_PAGE_DISPLAY:
150 $optpage_name = _("Display Preferences");
08185f2a 151 $optpage_file = SM_PATH . 'include/options/display.php';
cbe5423b 152 $optpage_loader = 'load_optpage_data_display';
a3439b27 153 $optpage_loadhook = 'optpage_loadhook_display';
cbe5423b 154 break;
155 case SMOPT_PAGE_HIGHLIGHT:
156 $optpage_name = _("Message Highlighting");
08185f2a 157 $optpage_file = SM_PATH . 'include/options/highlight.php';
cbe5423b 158 $optpage_loader = 'load_optpage_data_highlight';
a3439b27 159 $optpage_loadhook = 'optpage_loadhook_highlight';
cbe5423b 160 break;
161 case SMOPT_PAGE_FOLDER:
162 $optpage_name = _("Folder Preferences");
08185f2a 163 $optpage_file = SM_PATH . 'include/options/folder.php';
cbe5423b 164 $optpage_loader = 'load_optpage_data_folder';
a3439b27 165 $optpage_loadhook = 'optpage_loadhook_folder';
cbe5423b 166 break;
167 case SMOPT_PAGE_ORDER:
168 $optpage_name = _("Index Order");
08185f2a 169 $optpage_file = SM_PATH . 'include/options/order.php';
cbe5423b 170 $optpage_loader = 'load_optpage_data_order';
a3439b27 171 $optpage_loadhook = 'optpage_loadhook_order';
cbe5423b 172 break;
2fad95fa 173 default: do_hook('optpage_set_loadinfo');
cbe5423b 174}
175
176/**********************************************************/
177/*** Second, load the option information for this page. ***/
178/**********************************************************/
179
c1f7790a 180if ( !is_file( $optpage_file ) ) {
181 $optpage = SMOPT_PAGE_MAIN;
182} else if ($optpage != SMOPT_PAGE_MAIN ) {
cbe5423b 183 /* Include the file for this optionpage. */
c1f7790a 184
cbe5423b 185 require_once($optpage_file);
186
187 /* Assemble the data for this option page. */
188 $optpage_data = array();
189 $optpage_data = $optpage_loader();
a3439b27 190 do_hook($optpage_loadhook);
cbe5423b 191 $optpage_data['options'] =
192 create_option_groups($optpage_data['grps'], $optpage_data['vals']);
193}
194
195/***********************************************************/
196/*** Next, process anything that needs to be processed. ***/
197/***********************************************************/
198
cc61478a 199if ( isset( $optpage_data ) ) {
200 switch ($optmode) {
201 case SMOPT_MODE_SUBMIT:
202 $max_refresh = process_optionmode_submit($optpage, $optpage_data);
203 break;
204 case SMOPT_MODE_LINK:
205 $max_refresh = process_optionmode_link($optpage, $optpage_data);
206 break;
207 }
cbe5423b 208}
cbe5423b 209/*** MOVE THIS DISPLAY CODE DOWN EVENTUALLY!!! ***/
210
211$optpage_title = _("Options");
212if (isset($optpage_name) && ($optpage_name != '')) {
213 $optpage_title .= " - $optpage_name";
214}
f740c049 215
6206f6c4 216echo html_tag( 'table', '', 'center', $color[0], 'width="95%" cellpadding="1" cellspacing="0" border="0"' ) . "\n" .
545238b1 217 html_tag( 'tr' ) . "\n" .
218 html_tag( 'td', '', 'center' ) .
219 "<b>$optpage_title</b><br>\n".
220 html_tag( 'table', '', '', '', 'width="100%" cellpadding="5" cellspacing="0" border="0"' ) . "\n" .
221 html_tag( 'tr' ) . "\n" .
222 html_tag( 'td', '', 'center', $color[4] ) . "\n";
b5efadfa 223
cbe5423b 224/*******************************************************************/
225/* DO OLD SAVING OF SUBMITTED OPTIONS. THIS WILL BE REMOVED LATER. */
226/*******************************************************************/
227
228/* If in submit mode, select a save hook name and run it. */
7e235a1a 229if ($optmode == SMOPT_MODE_SUBMIT) {
cbe5423b 230 /* Select a save hook name. */
231 switch ($optpage) {
232 case SMOPT_PAGE_PERSONAL:
233 $save_hook_name = 'options_personal_save';
234 break;
235 case SMOPT_PAGE_DISPLAY:
236 $save_hook_name = 'options_display_save';
237 break;
238 case SMOPT_PAGE_FOLDER:
239 $save_hook_name = 'options_folder_save';
240 break;
cc61478a 241 default:
242 $save_hook_name = 'options_save';
cbe5423b 243 break;
244 }
b5efadfa 245
cbe5423b 246 /* Run the options save hook. */
247 do_hook($save_hook_name);
248}
249
250/***************************************************************/
251/* Apply logic to decide what optpage we want to display next. */
252/***************************************************************/
253
254/* If this is the result of an option page being submitted, then */
255/* show the main page. Otherwise, show whatever page was called. */
256
257if ($optmode == SMOPT_MODE_SUBMIT) {
258 $optpage = SMOPT_PAGE_MAIN;
259}
260
261/***************************************************************/
262/* Finally, display whatever page we are supposed to show now. */
263/***************************************************************/
264
265/*
266 * The main option page has a different layout then the rest of the option
267 * pages. Therefore, we create it here first, then the others below.
268 */
269if ($optpage == SMOPT_PAGE_MAIN) {
270 /**********************************************************/
271 /* First, display the results of a submission, if needed. */
272 /**********************************************************/
273 if ($optmode == SMOPT_MODE_SUBMIT) {
e362fff6 274 if (!isset($frame_top)) {
d03f3582 275 $frame_top = '_top';
276 }
cbe5423b 277 /* Display a message indicating a successful save. */
545238b1 278 echo '<b>' . _("Successfully Saved Options") . ": $optpage_name</b><br>\n";
cbe5423b 279
280 /* If $max_refresh != SMOPT_REFRESH_NONE, provide a refresh link. */
88cb1b4d 281 if ( !isset( $max_refresh ) ) {
282 } else if ($max_refresh == SMOPT_REFRESH_FOLDERLIST) {
545238b1 283 echo '<a href="../src/left_main.php" target="left">' . _("Refresh Folder List") . '</a><br>';
cbe5423b 284 } else if ($max_refresh) {
545238b1 285 echo '<a href="../src/webmail.php?right_frame=options.php" target="' . $frame_top . '">' . _("Refresh Page") . '</a><br>';
849bdf42 286 }
849bdf42 287 }
cbe5423b 288 /******************************************/
289 /* Build our array of Option Page Blocks. */
290 /******************************************/
291 $optpage_blocks = array();
849bdf42 292
293 /* Build a section for Personal Options. */
cbe5423b 294 $optpage_blocks[] = array(
849bdf42 295 'name' => _("Personal Information"),
cbe5423b 296 'url' => 'options.php?optpage=' . SMOPT_PAGE_PERSONAL,
849bdf42 297 'desc' => _("This contains personal information about yourself such as your name, your email address, etc."),
298 'js' => false
299 );
300
301 /* Build a section for Display Options. */
cbe5423b 302 $optpage_blocks[] = array(
849bdf42 303 'name' => _("Display Preferences"),
cbe5423b 304 'url' => 'options.php?optpage=' . SMOPT_PAGE_DISPLAY,
849bdf42 305 'desc' => _("You can change the way that SquirrelMail looks and displays information to you, such as the colors, the language, and other settings."),
306 'js' => false
307 );
308
309 /* Build a section for Message Highlighting Options. */
cbe5423b 310 $optpage_blocks[] = array(
849bdf42 311 'name' =>_("Message Highlighting"),
312 'url' => 'options_highlight.php',
313 '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."),
314 'js' => false
315 );
316
317 /* Build a section for Folder Options. */
cbe5423b 318 $optpage_blocks[] = array(
849bdf42 319 'name' => _("Folder Preferences"),
cbe5423b 320 'url' => 'options.php?optpage=' . SMOPT_PAGE_FOLDER,
849bdf42 321 'desc' => _("These settings change the way your folders are displayed and manipulated."),
322 'js' => false
323 );
324
325 /* Build a section for Index Order Options. */
cbe5423b 326 $optpage_blocks[] = array(
849bdf42 327 'name' => _("Index Order"),
328 'url' => 'options_order.php',
8aedb8c7 329 'desc' => _("The order of the message index can be rearranged and changed to contain the headers in any order you want."),
849bdf42 330 'js' => false
331 );
cbe5423b 332
849bdf42 333 /* Build a section for plugins wanting to register an optionpage. */
cbe5423b 334 do_hook('optpage_register_block');
849bdf42 335
336 /*****************************************************/
337 /* Let's sort Javascript Option Pages to the bottom. */
338 /*****************************************************/
cbe5423b 339 $js_optpage_blocks = array();
340 $reg_optpage_blocks = array();
341 foreach ($optpage_blocks as $cur_optpage) {
342 if (!$cur_optpage['js']) {
343 $reg_optpage_blocks[] = $cur_optpage;
23d6bd09 344 } else if ($javascript_on == SMPREF_JS_ON) {
cbe5423b 345 $js_optpage_blocks[] = $cur_optpage;
849bdf42 346 }
347 }
cbe5423b 348 $optpage_blocks = array_merge($reg_optpage_blocks, $js_optpage_blocks);
849bdf42 349
350 /********************************************/
351 /* Now, print out each option page section. */
352 /********************************************/
353 $first_optpage = false;
545238b1 354 echo html_tag( 'table', '', '', $color[4], 'width="100%" cellpadding="0" cellspacing="5" border="0"' ) . "\n" .
355 html_tag( 'tr' ) . "\n" .
356 html_tag( 'td', '', 'left', '', 'valign="top"' ) .
357 html_tag( 'table', '', '', $color[4], 'width="100%" cellpadding="3" cellspacing="0" border="0"' ) . "\n" .
358 html_tag( 'tr' ) . "\n" .
359 html_tag( 'td', '', 'left' );
cbe5423b 360 foreach ($optpage_blocks as $next_optpage) {
849bdf42 361 if ($first_optpage == false) {
362 $first_optpage = $next_optpage;
363 } else {
364 print_optionpages_row($first_optpage, $next_optpage);
365 $first_optpage = false;
366 }
367 }
368
369 if ($first_optpage != false) {
370 print_optionpages_row($first_optpage);
371 }
372
545238b1 373 echo "</td></tr></table></td></tr></table>\n";
dfec863e 374
849bdf42 375 do_hook('options_link_and_description');
376
cbe5423b 377
378/*************************************************************************/
379/* If we are not looking at the main option page, display the page here. */
380/*************************************************************************/
381} else {
545238b1 382 echo '<form name="f" action="options.php" method="post"><br>' . "\n"
cbe5423b 383 . create_optpage_element($optpage)
bd9bbfef 384 . create_optmode_element(SMOPT_MODE_SUBMIT)
545238b1 385 . html_tag( 'table', '', '', '', 'width="100%" cellpadding="2" cellspacing="0" border="0"' ) . "\n"
386 . html_tag( 'tr' ) . "\n"
387 . html_tag( 'td', '', 'left' ) . "\n";
cbe5423b 388
389 /* Output the option groups for this page. */
390 print_option_groups($optpage_data['options']);
391
cbe5423b 392 /* Set the inside_hook_name and submit_name. */
393 switch ($optpage) {
394 case SMOPT_PAGE_PERSONAL:
395 $inside_hook_name = 'options_personal_inside';
396 $bottom_hook_name = 'options_personal_bottom';
397 $submit_name = 'submit_personal';
398 break;
399 case SMOPT_PAGE_DISPLAY:
400 $inside_hook_name = 'options_display_inside';
401 $bottom_hook_name = 'options_display_bottom';
402 $submit_name = 'submit_display';
403 break;
404 case SMOPT_PAGE_HIGHLIGHT:
405 $inside_hook_name = 'options_highlight_inside';
2fad95fa 406 $bottom_hook_name = 'options_highlight_bottom';
cbe5423b 407 $submit_name = 'submit_highlight';
408 break;
409 case SMOPT_PAGE_FOLDER:
410 $inside_hook_name = 'options_folder_inside';
2fad95fa 411 $bottom_hook_name = 'options_folder_bottom';
cbe5423b 412 $submit_name = 'submit_folder';
413 break;
414 case SMOPT_PAGE_ORDER:
415 $inside_hook_name = 'options_order_inside';
416 $bottom_hook_name = 'options_order_bottom';
417 $submit_name = 'submit_order';
418 break;
419 default:
420 $inside_hook_name = '';
421 $bottom_hook_name = '';
422 $submit_name = 'submit';
423 }
424
425 /* If it is not empty, trigger the inside hook. */
426 if ($inside_hook_name != '') {
427 do_hook($inside_hook_name);
428 }
429
430 /* Spit out a submit button. */
431 OptionSubmit($submit_name);
545238b1 432 echo '</td></tr></table></form>';
cbe5423b 433
434 /* If it is not empty, trigger the bottom hook. */
435 if ($bottom_hook_name != '') {
436 do_hook($bottom_hook_name);
437 }
438}
439
545238b1 440echo '</td></tr>' .
441 '</table>'.
442 '</td></tr>'.
443 '</table>' .
444 '</body></html>';
e7db48af 445
2363ad39 446?>