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