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