Lots of little UI tweaks and some handsome borders in the Options and Folder areas.
[squirrelmail.git] / src / options_identities.php
1 <?php
2 /**
3 ** options_identities.php
4 **
5 ** $Id$
6 **/
7
8 include('../src/validate.php');
9 include('../functions/page_header.php');
10 include('../functions/display_messages.php');
11 include('../src/load_prefs.php');
12
13 if (isset($return)) {
14 SaveUpdateFunction();
15 header('Location: options_personal.php');
16 exit();
17 }
18
19 displayPageHeader($color, 'None');
20
21 $Info = do_hook('options_identities_process', 0);
22 if ($Info[1])
23 SaveUpdateFunction();
24
25 if (CheckAndDoDefault() || CheckAndDoPromote()) {
26 SaveUpdateFunction();
27 }
28 if (isset($update) || CheckForDelete())
29 SaveUpdateFunction();
30
31 LoadInfo($full_name, $email_address, $reply_to, '');
32
33 ?>
34 <br>
35 <table width=95% align=center border=0 cellpadding=2 cellspacing=0>
36 <tr><td bgcolor="<?php echo $color[0] ?>" align="center">
37
38 <b><?php echo _("Options") . ' - ' . _("Advanced Identities"); ?></b>
39
40 <table width="100%" border="0" cellpadding="1" cellspacing="1">
41 <tr><td bgcolor="<?php echo $color[4] ?>" align="center">
42
43 <form name=f action="options_identities.php" method=post><br>
44
45 <?PHP do_hook('options_identities_top'); ?>
46
47 <table width=80% cellpadding=2 cellspacing=0 border=0>
48 <tr bgcolor="<?PHP echo $color[9] ?>">
49 <th colspan=2 align=center><?PHP echo _("Default Identity") ?></th>
50 </tr>
51 <?PHP
52
53 ShowTableInfo($full_name, $email_address, $reply_to, '');
54
55 $num = 1;
56 while (LoadInfo($full_name, $email_address, $reply_to, $num))
57 {
58 ?>
59 <tr bgcolor="<?PHP echo $color[9] ?>">
60 <th colspan=2 align=center><?PHP printf (_("Alternate Identity %d"),
61 $num) ?></th>
62 </tr>
63 <?PHP
64 ShowTableInfo($full_name, $email_address, $reply_to, $num);
65 $num ++;
66 }
67
68 ?>
69 <tr bgcolor="<?PHP echo $color[9] ?>">
70 <th colspan=2 align=center><?PHP echo _("Add a New Identity") ?></th>
71 </tr>
72 <?
73
74 ShowTableInfo('', '', '', $num);
75 ?>
76 </table>
77 </form>
78
79 </td></tr>
80 </table>
81
82 </td></tr>
83 </table>
84 </body></html>
85
86 <?PHP
87
88 function SaveUpdateFunction()
89 {
90 global $username, $data_dir, $full_name, $email_address, $reply_to;
91
92 $i = 1;
93 $fakeI = 1;
94 $name = 'form_for_' . $i;
95 global $$name;
96 while (isset($$name))
97 {
98 $name = 'delete_' . $i;
99 global $$name;
100 if (isset($$name)) {
101 $fakeI --;
102 } else {
103 do_hook('options_identities_renumber', $i, $fakeI);
104 $filled = 0;
105
106 $name = 'full_name' . $i;
107 global $$name;
108 if ($$name != '')
109 $filled ++;
110 setPref($data_dir, $username, 'full_name' . $fakeI, $$name);
111
112 $name = 'email_address' . $i;
113 global $$name;
114 if ($$name != '')
115 $filled ++;
116 setPref($data_dir, $username, 'email_address' . $fakeI, $$name);
117
118 $name = 'reply_to' . $i;
119 global $$name;
120 if ($$name != '')
121 $filled ++;
122 setPref($data_dir, $username, 'reply_to' . $fakeI, $$name);
123
124 if ($filled == 0)
125 $fakeI --;
126 }
127
128 $fakeI ++;
129 $i ++;
130 $name = 'form_for_' . $i;
131 global $$name;
132 }
133
134 setPref($data_dir, $username, 'identities', $fakeI);
135
136 while ($fakeI != $i)
137 {
138 removePref($data_dir, $username, 'full_name' . $fakeI);
139 removePref($data_dir, $username, 'email_address' . $fakeI);
140 removePref($data_dir, $username, 'reply_to' . $fakeI);
141 $fakeI ++;
142 }
143
144 setPref($data_dir, $username, 'full_name', $full_name);
145 setPref($data_dir, $username, 'email_address', $email_address);
146 setPref($data_dir, $username, 'reply_to', $reply_to);
147 }
148
149 function CheckAndDoDefault()
150 {
151 global $username, $data_dir, $full_name, $email_address, $reply_to;
152
153 $i = 1;
154 $name = 'form_for_' . $i;
155 global $$name;
156 while (isset($$name))
157 {
158 $name = 'make_default_' . $i;
159 global $$name;
160 if (isset($$name)) {
161 do_hook('options_identities_renumber', $i, 'default');
162 global $full_name, $email_address, $reply_to;
163
164 $name = 'full_name' . $i;
165 global $$name;
166 $temp = $full_name;
167 $full_name = $$name;
168 $$name = $temp;
169
170 $name = 'email_address' . $i;
171 global $$name;
172 $temp = $email_address;
173 $email_address = $$name;
174 $$name = $temp;
175
176 $name = 'reply_to' . $i;
177 global $$name;
178 $temp = $reply_to;
179 $reply_to = $$name;
180 $$name = $temp;
181
182 return true;
183 }
184
185 $i ++;
186 $name = 'form_for_' . $i;
187 global $$name;
188 }
189 return false;
190 }
191
192 function CheckForDelete()
193 {
194 global $username, $data_dir, $full_name, $email_address, $reply_to;
195
196 $i = 1;
197 $name = 'form_for_' . $i;
198 global $$name;
199 while (isset($$name))
200 {
201 $name = 'delete_' . $i;
202 global $$name;
203 if (isset($$name)) {
204 return true;
205 }
206
207 $i ++;
208 $name = 'form_for_' . $i;
209 global $$name;
210 }
211 return false;
212 }
213
214 function CheckAndDoPromote()
215 {
216 global $username, $data_dir, $full_name, $email_address, $reply_to;
217
218 $i = 1;
219 $name = 'form_for_' . $i;
220 global $$name;
221 while (isset($$name))
222 {
223 $name = 'promote_' . $i;
224 global $$name;
225 if (isset($$name) && $i > 1) {
226 do_hook('options_identities_renumber', $i, $i - 1);
227
228 $nameA = 'full_name' . $i;
229 $nameB = 'full_name' . ($i - 1);
230 global $$nameA, $$nameB;
231 $temp = $$nameA;
232 $$nameA = $$nameB;
233 $$nameB = $temp;
234
235 $nameA = 'email_address' . $i;
236 $nameB = 'email_address' . ($i - 1);
237 global $$nameA, $$nameB;
238 $temp = $$nameA;
239 $$nameA = $$nameB;
240 $$nameB = $temp;
241
242 $nameA = 'reply_to' . $i;
243 $nameB = 'reply_to' . ($i - 1);
244 global $$nameA, $$nameB;
245 $temp = $$nameA;
246 $$nameA = $$nameB;
247 $$nameB = $temp;
248
249 return true;
250 }
251
252 $i ++;
253 $name = 'form_for_' . $i;
254 global $$name;
255 }
256 return false;
257 }
258
259 function LoadInfo(&$n, &$e, &$r, $post)
260 {
261 global $username, $data_dir;
262
263 $n = getPref($data_dir, $username, 'full_name' . $post);
264 $e = getPref($data_dir, $username, 'email_address' . $post);
265 $r = getPref($data_dir, $username, 'reply_to' . $post);
266
267 if ($n != '' || $e != '' || $r != '')
268 return true;
269 }
270
271 function ShowTableInfo($full_name, $email_address, $reply_to, $post)
272 {
273 global $color;
274
275 $OtherBG = ' bgcolor="' . $color[0] . '"';
276 if ($full_name == '' && $email_address == '' && $reply_to == '')
277 $OtherBG = '';
278
279 if ($full_name == '' && $email_address == '' && $reply_to == '')
280 $isEmptySection = true;
281 else
282 $isEmptySection = false;
283
284 ?>
285 <tr<?PHP echo $OtherBG ?>>
286 <td align=right nowrap>
287 <?php echo _("Full Name"); ?>:
288 </td>
289 <td>
290 <input size=50 type=text value="<?php echo htmlspecialchars($full_name)
291 ?>" name="full_name<?PHP echo $post ?>">
292 </td>
293 </tr>
294 <tr<?PHP echo $OtherBG ?>>
295 <td align=right nowrap>
296 <?php echo _("E-Mail Address"); ?>:
297 </td>
298 <td>
299 <input size=50 type=text value="<?php echo htmlspecialchars($email_address)
300 ?>" name="email_address<?PHP echo $post ?>">
301 </td>
302 </tr>
303 <tr<?PHP echo $OtherBG ?>>
304 <td align=right nowrap>
305 <?php echo _("Reply To"); ?>:
306 </td>
307 <td>
308 <input size=50 type=text value="<?php echo htmlspecialchars($reply_to)
309 ?>" name="reply_to<?PHP echo $post ?>">
310 </td>
311 </tr>
312 <?PHP do_hook('options_identities_table', $OtherBG, $isEmptySection, $post); ?>
313 <tr<?PHP echo $OtherBG ?>>
314 <td>&nbsp;</td><td>
315 <input type=hidden name="form_for_<?PHP echo $post ?>" value="1">
316 <input type=submit name="update" value="<?PHP echo _("Save / Update") ?>">
317 <?PHP
318 if (! $isEmptySection && $post != '') {
319 ?>
320 <input type=submit name="make_default_<?PHP echo $post ?>" value="<?PHP
321 echo _("Make Default") ?>">
322 <input type=submit name="delete_<?PHP echo $post ?>" value="<?PHP echo _("Delete") ?>">
323 <?PHP
324 }
325 if (! $isEmptySection && $post != '' && $post > 1) {
326 ?>
327 <input type=submit name="promote_<?PHP echo $post ?>" value="<?PHP
328 echo _("Move Up") ?>">
329 <?PHP
330 }
331 do_hook('options_identities_buttons', $isEmptySection, $post);
332 ?>
333 </td>
334 </tr>
335 <tr>
336 <td colspan="2">&nbsp;</td>
337 </tr>
338 <?PHP
339 }