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