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