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