Tylerization
[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, '');
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, '');
60
61 $num = 1;
62 while (LoadInfo($full_name, $email_address, $reply_to, $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, $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;
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 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
153 function CheckAndDoDefault() {
154 global $username, $data_dir, $full_name, $email_address, $reply_to;
155
156 $i = 1;
157 $name = 'form_for_' . $i;
158 global $$name;
159 while (isset($$name))
160 {
161 $name = 'make_default_' . $i;
162 global $$name;
163 if (isset($$name)) {
164 do_hook('options_identities_renumber', $i, 'default');
165 global $full_name, $email_address, $reply_to;
166
167 $name = 'full_name' . $i;
168 global $$name;
169 $temp = $full_name;
170 $full_name = $$name;
171 $$name = $temp;
172
173 $name = 'email_address' . $i;
174 global $$name;
175 $temp = $email_address;
176 $email_address = $$name;
177 $$name = $temp;
178
179 $name = 'reply_to' . $i;
180 global $$name;
181 $temp = $reply_to;
182 $reply_to = $$name;
183 $$name = $temp;
184
185 return true;
186 }
187
188 $i ++;
189 $name = 'form_for_' . $i;
190 global $$name;
191 }
192 return FALSE;
193 }
194
195 function CheckForDelete() {
196 global $username, $data_dir, $full_name, $email_address, $reply_to;
197
198 $i = 1;
199 $name = 'form_for_' . $i;
200 global $$name;
201 while (isset($$name))
202 {
203 $name = 'delete_' . $i;
204 global $$name;
205 if (isset($$name)) {
206 return true;
207 }
208
209 $i ++;
210 $name = 'form_for_' . $i;
211 global $$name;
212 }
213 return false;
214 }
215
216 function CheckAndDoPromote() {
217 global $username, $data_dir, $full_name, $email_address, $reply_to;
218
219 $i = 1;
220 $name = 'form_for_' . $i;
221 global $$name;
222 while (isset($$name)) {
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 global $username, $data_dir;
261
262 $n = getPref($data_dir, $username, 'full_name' . $post);
263 $e = getPref($data_dir, $username, 'email_address' . $post);
264 $r = getPref($data_dir, $username, 'reply_to' . $post);
265
266 if ($n != '' || $e != '' || $r != '')
267 return true;
268 }
269
270 function sti_input( $title, $hd, $data, $post, $bg ) {
271
272 echo "<tr$bg><td align=right nowrap>$title:".
273 '</td><td>'.
274 '<input size=50 type=text value="' . htmlspecialchars($data) .
275 "\" name=\"$hd$post\"></td></tr>";
276
277 }
278
279 function ShowTableInfo($full_name, $email_address, $reply_to, $post) {
280 global $color;
281
282 $OtherBG = ' bgcolor="' . $color[0] . '"';
283 if ($full_name == '' && $email_address == '' && $reply_to == '')
284 $OtherBG = '';
285
286 if ($full_name == '' && $email_address == '' && $reply_to == '')
287 $isEmptySection = true;
288 else
289 $isEmptySection = false;
290
291 sti_input( _("Full Name"), 'full_name', $full_name, $post, $OtherBG );
292 sti_input( _("E-Mail Address"), 'email_address', $email_address, $post, $OtherBG );
293 sti_input( _("Reply To"), 'reply_to', $reply_to, $post, $OtherBG );
294
295 do_hook('options_identities_table', $OtherBG, $isEmptySection, $post);
296 echo "<tr$OtherBG>".
297 '<td>&nbsp;</td><td>'.
298 "<input type=hidden name=\"form_for_$post\" value=\"1\">".
299 '<input type=submit name="update" value="'.
300 _("Save / Update") . '">';
301 if (! $isEmptySection && $post != '') {
302 echo "<input type=submit name=\"make_default_$post\" value=\"".
303 _("Make Default") . '">'.
304 "<input type=submit name=\"delete_$post\" value=\"".
305 _("Delete") . '">';
306 }
307 if (! $isEmptySection && $post != '' && $post > 1) {
308 echo '<input type=submit name="promote_' . $post . '" value="'.
309 _("Move Up") . '">';
310 }
311 do_hook('options_identities_buttons', $isEmptySection, $post);
312 echo '</td></tr>'.
313 '<tr><td colspan="2">&nbsp;</td></tr>';
314 }
315 ?>