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