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