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