bcdb43ad9e22d294b1eabc54c66bcbc8acf10b4e
[squirrelmail.git] / src / options.php
1 <?php
2 /**
3 * options.php
4 *
5 * Copyright (c) 1999-2001 The SquirrelMail Development Team
6 * Licensed under the GNU GPL. For full terms see the file COPYING.
7 *
8 * Displays the options page. Pulls from proper user preference files
9 * and config.php. Displays preferences as selected and other options.
10 *
11 * $Id$
12 */
13
14 require_once('../src/validate.php');
15 require_once('../functions/display_messages.php');
16 require_once('../functions/imap.php');
17 require_once('../functions/array.php');
18
19 ereg ("(^.*/)[^/]+/[^/]+$", $PHP_SELF, $regs);
20 $base_uri = $regs[1];
21
22 if (isset($language)) {
23 setcookie('squirrelmail_language', $language, time()+2592000, $base_uri);
24 $squirrelmail_language = $language;
25 }
26
27 displayPageHeader($color, _("None"));
28
29 ?>
30
31 <br>
32 <table bgcolor="<?php echo $color[0] ?>" width="95%" align="center" cellpadding="2" cellspacing="0" border="0">
33 <tr><td align="center">
34 <b><?php echo _("Options") ?></b><br>
35
36 <table width="100%" border="0" cellpadding="5" cellspacing="0">
37 <tr><td bgcolor="<?php echo $color[4] ?>" align="center">
38
39 <?php
40 if (isset($submit_personal)) {
41 /* Save personal information. */
42 setPref($data_dir, $username, 'full_name', $new_full_name);
43 setPref($data_dir, $username, 'email_address', $new_email_address);
44 setPref($data_dir, $username, 'reply_to', $new_reply_to);
45 setPref($data_dir, $username, 'reply_citation_style', $new_reply_citation_style);
46 setPref($data_dir, $username, 'reply_citation_start', $new_reply_citation_start);
47 setPref($data_dir, $username, 'reply_citation_end', $new_reply_citation_end);
48 setPref($data_dir, $username, 'use_signature', $new_use_signature);
49 setPref($data_dir, $username, 'prefix_sig', $new_prefix_sig);
50 setSig($data_dir, $username, $new_signature_abs);
51
52 do_hook('options_personal_save');
53
54 echo '<br><b>'._("Successfully saved personal information!").'</b><br>';
55 } else if (isset($submit_display)) {
56 /* Do checking to make sure $new_theme is in the array. */
57 $theme_in_array = false;
58 for ($i=0; $i < count($theme); $i++) {
59 if ($theme[$i]['PATH'] == $new_chosen_theme) {
60 $theme_in_array = true;
61 break;
62 }
63 }
64 if (!$theme_in_array) {
65 $new_chosen_theme = '';
66 }
67
68 /* Save display preferences. */
69 setPref($data_dir, $username, 'chosen_theme', $new_chosen_theme);
70 setPref($data_dir, $username, 'language', $new_language);
71 setPref($data_dir, $username, 'use_javascript_addr_book', $new_use_javascript_addr_book);
72 setPref($data_dir, $username, 'javascript_setting', $new_javascript_setting);
73 setPref($data_dir, $username, 'show_num', $new_show_num);
74 setPref($data_dir, $username, 'wrap_at', $new_wrap_at);
75 setPref($data_dir, $username, 'editor_size', $new_editor_size);
76 setPref($data_dir, $username, 'location_of_buttons', $new_location_of_buttons);
77 setPref($data_dir, $username, 'alt_index_colors', $new_alt_index_colors);
78 setPref($data_dir, $username, 'show_html_default', $new_show_html_default);
79 setPref($data_dir, $username, 'include_self_reply_all', $new_include_self_reply_all);
80 setPref($data_dir, $username, 'page_selector', $new_page_selector);
81 setPref($data_dir, $username, 'page_selector_max', $new_page_selector_max);
82 setPref($data_dir, $username, 'show_xmailer_default', $new_show_xmailer_default);
83
84 $js_autodetect_results = (isset($new_js_autodetect_results) ? $new_js_autodetect_results : SMPREF_JS_OFF);
85 if ($new_javascript_setting == SMPREF_JS_AUTODETECT) {
86 if ($js_autodetect_results == SMPREF_JS_ON) {
87 setPref($data_dir, $username, 'javascript_on', SMPREF_JS_ON);
88 } else {
89 setPref($data_dir, $username, 'javascript_on', SMPREF_JS_OFF);
90 }
91 } else {
92 setPref($data_dir, $username, 'javascript_on', $new_javascript_setting);
93 }
94
95 do_hook('options_display_save');
96
97 echo '<br><b>'._("Successfully saved display preferences!").'</b><br>';
98 echo '<a href="../src/webmail.php?right_frame=options.php" target=_top>' . _("Refresh Page") . '</a><br>';
99 } else if (isset($submit_folder)) {
100 /* Save trash folder preferences. */
101 if ($new_trash_folder != SMPREF_NONE) {
102 setPref($data_dir, $username, 'move_to_trash', SMPREF_ON);
103 setPref($data_dir, $username, 'trash_folder', $new_trash_folder);
104 } else {
105 setPref($data_dir, $username, 'move_to_trash', SMPREF_OFF);
106 setPref($data_dir, $username, 'trash_folder', SMPREF_NONE);
107 }
108
109 /* Save sent folder preferences. */
110 if ($new_sent_folder != SMPREF_NONE) {
111 setPref($data_dir, $username, 'move_to_sent', SMPREF_ON);
112 setPref($data_dir, $username, 'sent_folder', $new_sent_folder);
113 } else {
114 setPref($data_dir, $username, 'move_to_sent', SMPREF_OFF);
115 setPref($data_dir, $username, 'sent_folder', SMPREF_NONE);
116 }
117
118 /* Save draft folder preferences. */
119 if ($new_draft_folder != SMPREF_NONE) {
120 setPref($data_dir, $username, 'save_as_draft', SMPREF_ON);
121 setPref($data_dir, $username, 'draft_folder', $new_draft_folder);
122 } else {
123 setPref($data_dir, $username, 'save_as_draft', SMPREF_OFF);
124 setPref($data_dir, $username, 'draft_folder', SMPREF_NONE);
125 }
126
127 /* Save folder prefix preferences. */
128 if (isset($folderprefix)) {
129 setPref($data_dir, $username, 'folder_prefix', $folderprefix);
130 } else {
131 setPref($data_dir, $username, 'folder_prefix', '');
132 }
133
134 setPref($data_dir, $username, 'location_of_bar', $new_location_of_bar);
135 setPref($data_dir, $username, 'left_size', $new_left_size);
136 setPref($data_dir, $username, 'left_refresh', $new_left_refresh);
137 setPref($data_dir, $username, 'unseen_notify', $new_unseen_notify);
138 setPref($data_dir, $username, 'unseen_type', $new_unseen_type);
139 setPref($data_dir, $username, 'collapse_folders', $new_collapse_folders);
140 setPref($data_dir, $username, 'date_format', $new_date_format);
141 setPref($data_dir, $username, 'hour_format', $new_hour_format);
142
143 do_hook('options_folders_save');
144 echo '<br><b>'._("Successfully saved folder preferences!").'</b><br>';
145 echo '<a href="../src/left_main.php" target=left>' . _("Refresh Folder List") . '</a><br>';
146 } else {
147 do_hook('options_save');
148 }
149
150 /****************************************/
151 /* Now build our array of option pages. */
152 /****************************************/
153
154 /* Build a section for Personal Options. */
155 $optionpages[] = array(
156 'name' => _("Personal Information"),
157 'url' => 'options_personal.php',
158 'desc' => _("This contains personal information about yourself such as your name, your email address, etc."),
159 'js' => false
160 );
161
162 /* Build a section for Display Options. */
163 $optionpages[] = array(
164 'name' => _("Display Preferences"),
165 'url' => 'options_display.php',
166 'desc' => _("You can change the way that SquirrelMail looks and displays information to you, such as the colors, the language, and other settings."),
167 'js' => false
168 );
169
170 /* Build a section for Message Highlighting Options. */
171 $optionpages[] = array(
172 'name' =>_("Message Highlighting"),
173 'url' => 'options_highlight.php',
174 '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."),
175 'js' => false
176 );
177
178 /* Build a section for Folder Options. */
179 $optionpages[] = array(
180 'name' => _("Folder Preferences"),
181 'url' => 'options_folder.php',
182 'desc' => _("These settings change the way your folders are displayed and manipulated."),
183 'js' => false
184 );
185
186 /* Build a section for Index Order Options. */
187 $optionpages[] = array(
188 'name' => _("Index Order"),
189 'url' => 'options_order.php',
190 'desc' => _("The order of the message index can be rearanged and changed to contain the headers in any order you want."),
191 'js' => false
192 );
193 /* Build a section for plugins wanting to register an optionpage. */
194 do_hook('options_register');
195
196 /*****************************************************/
197 /* Let's sort Javascript Option Pages to the bottom. */
198 /*****************************************************/
199 $js_optionpages = array();
200 $reg_optionpages = array();
201 foreach ($optionpages as $optpage) {
202 if (!$optpage['js']) {
203 $reg_optionpages[] = $optpage;
204 } else if ($javascript_on == SMPREF_JS_ON) {
205 $js_optionpages[] = $optpage;
206 }
207 }
208 $optionpages = array_merge($reg_optionpages, $js_optionpages);
209
210 /********************************************/
211 /* Now, print out each option page section. */
212 /********************************************/
213 $first_optpage = false;
214 foreach ($optionpages as $next_optpage) {
215 if ($first_optpage == false) {
216 $first_optpage = $next_optpage;
217 } else {
218 print_optionpages_row($first_optpage, $next_optpage);
219 $first_optpage = false;
220 }
221 }
222
223 if ($first_optpage != false) {
224 print_optionpages_row($first_optpage);
225 }
226
227 do_hook('options_link_and_description');
228
229 ?>
230 </td></tr>
231 </table>
232
233 </td></tr>
234 </table>
235
236 </body></html>
237
238 <?php
239
240 /*******************************************************************/
241 /* Please be warned. The code below this point sucks. This is just */
242 /* my first implementation to make the option rows work for both */
243 /* Javascript and non-Javascript option chunks. */
244 /* */
245 /* Please, someone make these better for me. All three functions */
246 /* below REALLY do close to the same thing. */
247 /* */
248 /* This code would be GREATLY improved by a templating system. */
249 /* Don't try to implement that now, however. That will come later. */
250 /*******************************************************************/
251
252 /*******************************************************************/
253 /* Actually, now that I think about it, don't do anything with */
254 /* this code yet. There is ACTUALLY supposed to be a difference */
255 /* between the three functions that write the option rows. I just */
256 /* have not yet gotten to integrating that yet. */
257 /*******************************************************************/
258
259 /**
260 * This function prints out an option page row.
261 */
262 function print_optionpages_row($leftopt, $rightopt = false) {
263 global $color;
264
265 echo "<table bgcolor=\"$color[4]\" width=\"100%\" cellpadding=0 cellspacing=5 border=0>" .
266 '<tr><td valign="top">' .
267 '<table width="100%" cellpadding="3" cellspacing="0" border="0">' .
268 '<tr>' .
269 "<td valign=top bgcolor=\"$color[9]\" width=\"50%\">" .
270 '<a href="' . $leftopt['url'] . '">' . $leftopt['name'] . '</a>'.
271 '</td>'.
272 "<td valign=top bgcolor=\"$color[4]\">&nbsp;</td>";
273 if( $rightopt ) {
274 echo "<td valign=top bgcolor=\"$color[9]\" width=\"50%\">" .
275 '<a href="' . $rightopt['url'] . '">' . $rightopt['name'] . '</a>' .
276 '</td>';
277 } else {
278 echo "<td valign=top bgcolor=\"$color[4]\" width=\"50%\">&nbsp;</td>";
279 }
280
281 echo '</tr>' .
282 '<tr>' .
283 "<td valign=top bgcolor=\"$color[0]\">" .
284 $leftopt['desc'] .
285 '</td>' .
286 "<td valign=top bgcolor=\"$color[4]\">&nbsp;</td>";
287 if( $rightopt ) {
288 echo "<td valign=top bgcolor=\"$color[0]\">" .
289 $rightopt['desc'] .
290 '</td>';
291 }else {
292 echo "<td valign=top bgcolor=\"$color[4]\">&nbsp;</td>";
293 }
294
295 echo '</tr>' .
296 '</table>' .
297 '</td></tr>' .
298 "</table>\n";
299 }
300
301 ?>