removed old rcptaddress
[squirrelmail.git] / src / options.php
1 <?php
2
3 /**
4 * options.php
5 *
6 * Copyright (c) 1999-2002 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 * $Id$
13 */
14
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');
22
23 /*********************************/
24 /*** Build the resultant page. ***/
25 /*********************************/
26
27 displayPageHeader($color, 'None');
28
29 define('SMOPT_MODE_DISPLAY', 'display');
30 define('SMOPT_MODE_SUBMIT', 'submit');
31 define('SMOPT_MODE_LINK', 'link');
32
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');
39
40 function 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) {
47 /* Remove Debug Mode Until Needed
48 echo "name = '$option->name', "
49 . "value = '$option->value', "
50 . "new_value = '$option->new_value'<br>\n";
51 */
52 if ($option->changed()) {
53 $option->save();
54 $max_refresh = max($max_refresh, $option->refresh_level);
55 }
56 }
57 }
58
59 /* Return the max refresh level. */
60 return ($max_refresh);
61 }
62
63 function process_optionmode_link($optpage) {
64 /* There will be something here, later. */
65 }
66
67
68 /**
69 * This function prints out an option page row.
70 */
71 function print_optionpages_row($leftopt, $rightopt = false) {
72 global $color;
73
74 if ($rightopt) {
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%"' );
77 } else {
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%"' );
80 }
81
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"' );
109 }
110
111 /* ---------------------------- main ---------------------------- */
112
113 /* Make sure we have an Option Page set. Default to main. */
114 if (!isset($optpage)) {
115 $optpage = 'main';
116 }
117
118 /* Make sure we have an Option Mode set. Default to display. */
119 if (!isset($optmode)) {
120 $optmode = SMOPT_MODE_DISPLAY;
121 }
122
123 /*
124 * First, set the load information for each option page.
125 */
126
127 /* Initialize load information variables. */
128 $optpage_name = '';
129 $optpage_file = '';
130 $optpage_loader = '';
131
132 /* Set the load information for each page. */
133 switch ($optpage) {
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';
140 break;
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';
146 break;
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';
152 break;
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';
158 break;
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';
164 break;
165 default: do_hook('optpage_set_loadinfo');
166 }
167
168 /**********************************************************/
169 /*** Second, load the option information for this page. ***/
170 /**********************************************************/
171
172 if ($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();
179 do_hook($optpage_loadhook);
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
188 if ( 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 }
197 }
198 /*** MOVE THIS DISPLAY CODE DOWN EVENTUALLY!!! ***/
199
200 $optpage_title = _("Options");
201 if (isset($optpage_name) && ($optpage_name != '')) {
202 $optpage_title .= " - $optpage_name";
203 }
204
205 echo '<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";
213
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. */
219 if ($optmode == SMOPT_MODE_SUBMIT) {
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;
231 default:
232 $save_hook_name = 'options_save';
233 break;
234 }
235
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
247 if ($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 */
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)) {
265 $frame_top = '_top';
266 }
267 /* Display a message indicating a successful save. */
268 echo '<b>' . _("Successfully Saved Options") . ": $optpage_name</b><br>\n";
269
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>';
276 }
277 }
278 /******************************************/
279 /* Build our array of Option Page Blocks. */
280 /******************************************/
281 $optpage_blocks = array();
282
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."),
288 'js' => false
289 );
290
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."),
296 'js' => false
297 );
298
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."),
304 'js' => false
305 );
306
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."),
312 'js' => false
313 );
314
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."),
320 'js' => false
321 );
322
323 /* Build a section for plugins wanting to register an optionpage. */
324 do_hook('optpage_register_block');
325
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;
336 }
337 }
338 $optpage_blocks = array_merge($reg_optpage_blocks, $js_optpage_blocks);
339
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;
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
363 echo "</td></tr></table></td></tr></table>\n";
364
365 do_hook('options_link_and_description');
366
367
368 /*************************************************************************/
369 /* If we are not looking at the main option page, display the page here. */
370 /*************************************************************************/
371 } else {
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";
378
379 /* Output the option groups for this page. */
380 print_option_groups($optpage_data['options']);
381
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';
396 $bottom_hook_name = 'options_highlight_bottom';
397 $submit_name = 'submit_highlight';
398 break;
399 case SMOPT_PAGE_FOLDER:
400 $inside_hook_name = 'options_folder_inside';
401 $bottom_hook_name = 'options_folder_bottom';
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);
422 echo '</td></tr></table></form>';
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
430 echo '</td></tr>' .
431 '</table>'.
432 '</td></tr>'.
433 '</table>' .
434 '</body></html>';
435
436 ?>