51eebb73c1400a4d4b5ba1435d38be124bbfff0c
[squirrelmail.git] / src / options_identities.php
1 <?php
2
3 /**
4 * options_identities.php
5 *
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 *
11 * $Id$
12 */
13
14 /*****************************************************************/
15 /*** THIS FILE NEEDS TO HAVE ITS FORMATTING FIXED!!! ***/
16 /*** PLEASE DO SO AND REMOVE THIS COMMENT SECTION. ***/
17 /*** + Base level indent should begin at left margin, as ***/
18 /*** the require_once below looks. ***/
19 /*** + All identation should consist of four space blocks ***/
20 /*** + Tab characters are evil. ***/
21 /*** + all comments should use "slash-star ... star-slash" ***/
22 /*** style -- no pound characters, no slash-slash style ***/
23 /*** + FLOW CONTROL STATEMENTS (if, while, etc) SHOULD ***/
24 /*** ALWAYS USE { AND } CHARACTERS!!! ***/
25 /*** + Please use ' instead of ", when possible. Note " ***/
26 /*** should always be used in _( ) function calls. ***/
27 /*** Thank you for your help making the SM code more readable. ***/
28 /*****************************************************************/
29
30 require_once('../src/validate.php');
31 require_once('../functions/display_messages.php');
32
33 if (isset($return)) {
34 SaveUpdateFunction();
35 header('Location: options_personal.php');
36 exit();
37 }
38
39 displayPageHeader($color, 'None');
40
41 $Info = do_hook('options_identities_process', 0);
42 if ($Info[1])
43 SaveUpdateFunction();
44
45 if (CheckAndDoDefault() || CheckAndDoPromote()) {
46 SaveUpdateFunction();
47 }
48 if (isset($update) || CheckForDelete())
49 SaveUpdateFunction();
50
51 LoadInfo($full_name, $email_address, $reply_to, '');
52
53 ?>
54 <br>
55 <table width=95% align=center border=0 cellpadding=2 cellspacing=0>
56 <tr><td bgcolor="<?php echo $color[0] ?>" align="center">
57
58 <b><?php echo _("Options") . ' - ' . _("Advanced Identities"); ?></b>
59
60 <table width="100%" border="0" cellpadding="1" cellspacing="1">
61 <tr><td bgcolor="<?php echo $color[4] ?>" align="center">
62
63 <form name=f action="options_identities.php" method=post><br>
64
65 <?PHP do_hook('options_identities_top'); ?>
66
67 <table width=80% cellpadding=2 cellspacing=0 border=0>
68 <tr bgcolor="<?PHP echo $color[9] ?>">
69 <th colspan=2 align=center><?PHP echo _("Default Identity") ?></th>
70 </tr>
71 <?PHP
72
73 ShowTableInfo($full_name, $email_address, $reply_to, '');
74
75 $num = 1;
76 while (LoadInfo($full_name, $email_address, $reply_to, $num))
77 {
78 ?>
79 <tr bgcolor="<?PHP echo $color[9] ?>">
80 <th colspan=2 align=center><?PHP printf (_("Alternate Identity %d"),
81 $num) ?></th>
82 </tr>
83 <?PHP
84 ShowTableInfo($full_name, $email_address, $reply_to, $num);
85 $num ++;
86 }
87
88 ?>
89 <tr bgcolor="<?PHP echo $color[9] ?>">
90 <th colspan=2 align=center><?PHP echo _("Add a New Identity") ?></th>
91 </tr>
92 <?
93
94 ShowTableInfo('', '', '', $num);
95 ?>
96 </table>
97 </form>
98
99 </td></tr>
100 </table>
101
102 </td></tr>
103 </table>
104 </body></html>
105
106 <?PHP
107
108 function SaveUpdateFunction() {
109 global $username, $data_dir, $full_name, $email_address, $reply_to;
110
111 $i = 1;
112 $fakeI = 1;
113 $name = 'form_for_' . $i;
114 global $$name;
115 while (isset($$name))
116 {
117 $name = 'delete_' . $i;
118 global $$name;
119 if (isset($$name)) {
120 $fakeI --;
121 } else {
122 do_hook('options_identities_renumber', $i, $fakeI);
123 $filled = 0;
124
125 $name = 'full_name' . $i;
126 global $$name;
127 if ($$name != '')
128 $filled ++;
129 setPref($data_dir, $username, 'full_name' . $fakeI, $$name);
130
131 $name = 'email_address' . $i;
132 global $$name;
133 if ($$name != '')
134 $filled ++;
135 setPref($data_dir, $username, 'email_address' . $fakeI, $$name);
136
137 $name = 'reply_to' . $i;
138 global $$name;
139 if ($$name != '')
140 $filled ++;
141 setPref($data_dir, $username, 'reply_to' . $fakeI, $$name);
142
143 if ($filled == 0)
144 $fakeI --;
145 }
146
147 $fakeI ++;
148 $i ++;
149 $name = 'form_for_' . $i;
150 global $$name;
151 }
152
153 setPref($data_dir, $username, 'identities', $fakeI);
154
155 while ($fakeI != $i)
156 {
157 removePref($data_dir, $username, 'full_name' . $fakeI);
158 removePref($data_dir, $username, 'email_address' . $fakeI);
159 removePref($data_dir, $username, 'reply_to' . $fakeI);
160 $fakeI ++;
161 }
162
163 setPref($data_dir, $username, 'full_name', $full_name);
164 setPref($data_dir, $username, 'email_address', $email_address);
165 setPref($data_dir, $username, 'reply_to', $reply_to);
166 }
167
168 function CheckAndDoDefault() {
169 global $username, $data_dir, $full_name, $email_address, $reply_to;
170
171 $i = 1;
172 $name = 'form_for_' . $i;
173 global $$name;
174 while (isset($$name))
175 {
176 $name = 'make_default_' . $i;
177 global $$name;
178 if (isset($$name)) {
179 do_hook('options_identities_renumber', $i, 'default');
180 global $full_name, $email_address, $reply_to;
181
182 $name = 'full_name' . $i;
183 global $$name;
184 $temp = $full_name;
185 $full_name = $$name;
186 $$name = $temp;
187
188 $name = 'email_address' . $i;
189 global $$name;
190 $temp = $email_address;
191 $email_address = $$name;
192 $$name = $temp;
193
194 $name = 'reply_to' . $i;
195 global $$name;
196 $temp = $reply_to;
197 $reply_to = $$name;
198 $$name = $temp;
199
200 return true;
201 }
202
203 $i ++;
204 $name = 'form_for_' . $i;
205 global $$name;
206 }
207 return FALSE;
208 }
209
210 function CheckForDelete() {
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 = 'delete_' . $i;
219 global $$name;
220 if (isset($$name)) {
221 return true;
222 }
223
224 $i ++;
225 $name = 'form_for_' . $i;
226 global $$name;
227 }
228 return false;
229 }
230
231 function CheckAndDoPromote() {
232 global $username, $data_dir, $full_name, $email_address, $reply_to;
233
234 $i = 1;
235 $name = 'form_for_' . $i;
236 global $$name;
237 while (isset($$name)) {
238 $name = 'promote_' . $i;
239 global $$name;
240 if (isset($$name) && $i > 1) {
241 do_hook('options_identities_renumber', $i, $i - 1);
242
243 $nameA = 'full_name' . $i;
244 $nameB = 'full_name' . ($i - 1);
245 global $$nameA, $$nameB;
246 $temp = $$nameA;
247 $$nameA = $$nameB;
248 $$nameB = $temp;
249
250 $nameA = 'email_address' . $i;
251 $nameB = 'email_address' . ($i - 1);
252 global $$nameA, $$nameB;
253 $temp = $$nameA;
254 $$nameA = $$nameB;
255 $$nameB = $temp;
256
257 $nameA = 'reply_to' . $i;
258 $nameB = 'reply_to' . ($i - 1);
259 global $$nameA, $$nameB;
260 $temp = $$nameA;
261 $$nameA = $$nameB;
262 $$nameB = $temp;
263
264 return true;
265 }
266
267 $i ++;
268 $name = 'form_for_' . $i;
269 global $$name;
270 }
271 return false;
272 }
273
274 function LoadInfo(&$n, &$e, &$r, $post) {
275 global $username, $data_dir;
276
277 $n = getPref($data_dir, $username, 'full_name' . $post);
278 $e = getPref($data_dir, $username, 'email_address' . $post);
279 $r = getPref($data_dir, $username, 'reply_to' . $post);
280
281 if ($n != '' || $e != '' || $r != '')
282 return true;
283 }
284
285 function sti_input( $title, $hd, $data, $post, $bg ) {
286
287 echo "<tr$bg><td align=right nowrap>$title:".
288 '</td><td>'.
289 '<input size=50 type=text value="' . htmlspecialchars($data) .
290 "\" name=\"$hd$post\"></td></tr>";
291
292 }
293
294 function ShowTableInfo($full_name, $email_address, $reply_to, $post) {
295 global $color;
296
297 $OtherBG = ' bgcolor="' . $color[0] . '"';
298 if ($full_name == '' && $email_address == '' && $reply_to == '')
299 $OtherBG = '';
300
301 if ($full_name == '' && $email_address == '' && $reply_to == '')
302 $isEmptySection = true;
303 else
304 $isEmptySection = false;
305
306 sti_input( _("Full Name"), 'full_name', $full_name, $post, $OtherBG );
307 sti_input( _("E-Mail Address"), 'email_address', $email_address, $post, $OtherBG );
308 sti_input( _("Reply To"), 'reply_to', $reply_to, $post, $OtherBG );
309
310 do_hook('options_identities_table', $OtherBG, $isEmptySection, $post);
311 echo "<tr$OtherBG>".
312 '<td>&nbsp;</td><td>'.
313 "<input type=hidden name=\"form_for_$post\" value=\"1\">".
314 '<input type=submit name="update" value="'.
315 _("Save / Update") . '">';
316 if (! $isEmptySection && $post != '') {
317 echo "<input type=submit name=\"make_default_$post\" value=\"".
318 _("Make Default") . '">'.
319 "<input type=submit name=\"delete_$post\" value=\"".
320 _("Delete") . '">';
321 }
322 if (! $isEmptySection && $post != '' && $post > 1) {
323 echo '<input type=submit name="promote_' . $post . '" value="'.
324 _("Move Up") . '">';
325 }
326 do_hook('options_identities_buttons', $isEmptySection, $post);
327 echo '</td></tr>'.
328 '<tr><td colspan="2">&nbsp;</td></tr>';
329 }
330 ?>