Formatting and adding FIXME to addressbook.php
[squirrelmail.git] / src / options_identities.php
1 <?php
2
3 /**
4 * options_identities.php
5 *
6 * Copyright (c) 1999-2005 The SquirrelMail Project Team
7 * Licensed under the GNU GPL. For full terms see the file COPYING.
8 *
9 * Display Identities Options
10 *
11 * @version $Id$
12 * @package squirrelmail
13 * @subpackage prefs
14 */
15
16 /**
17 * Path for SquirrelMail required files.
18 * @ignore
19 */
20 define('SM_PATH','../');
21
22 /* SquirrelMail required files. */
23 require_once(SM_PATH . 'include/validate.php');
24 include_once(SM_PATH . 'functions/global.php');
25 include_once(SM_PATH . 'functions/display_messages.php');
26 include_once(SM_PATH . 'functions/html.php');
27
28 /* POST data var names are dynamic because
29 of the possible multiple idents so lets get
30 them all
31 FIXME! This circumvents the benefits of rg=0
32 */
33 if (!empty($_POST)) {
34 extract($_POST);
35 }
36 /* got 'em all */
37
38 if (isset($return)) {
39 SaveUpdateFunction();
40 header('Location: '.get_location().'/options_personal.php');
41 exit();
42 }
43
44 displayPageHeader($color, 'None');
45
46 $Info = do_hook('options_identities_process', 0);
47 if ($Info[1]) {
48 SaveUpdateFunction();
49 }
50
51 if (CheckAndDoDefault() || CheckAndDoPromote()) {
52 SaveUpdateFunction();
53 }
54 if (isset($update) || CheckForDelete()) {
55 SaveUpdateFunction();
56 }
57
58 do_hook('options_identities_top');
59 LoadInfo($full_name, $email_address, $reply_to, $signature, '');
60 $td_str = '';
61 $td_str .= '<form name="f" action="options_identities.php" method="post"><br />';
62 $td_str .= ShowTableInfo($full_name, $email_address, $reply_to, $signature, '');
63
64 $num = 1;
65 while (LoadInfo($full_name, $email_address, $reply_to, $signature, $num)) {
66 $td_str .= html_tag( 'tr',
67 html_tag( 'th', sprintf (_("Alternate Identity %d"), $num), 'center', '', 'colspan="2"' ) ,
68 '', $color[9]);
69 $td_str .= ShowTableInfo($full_name, $email_address, $reply_to, $signature, $num);
70 $num ++;
71 }
72
73 echo '<br />' .
74 html_tag( 'table', "\n" .
75 html_tag( 'tr', "\n" .
76 html_tag( 'td', "\n" .
77 '<b>'. _("Options") . ' - ' . _("Advanced Identities") .'</b><br />' .
78 html_tag( 'table', "\n" .
79 html_tag( 'tr', "\n" .
80 html_tag( 'td', "\n" .
81 html_tag( 'table', "\n" .
82 html_tag( 'tr', "\n" .
83 html_tag( 'th', _("Default Identity"), 'center', '', 'colspan="2"' ) ,
84 '', $color[9]) . "\n" .
85 $td_str . "\n" .
86 html_tag( 'tr',
87 html_tag( 'th', _("Add a New Identity") . ShowTableInfo('', '', '', '', $num), 'center', '', 'colspan="2"' ) ,
88 '', $color[9]) ,
89 '', '', 'width="80%" cellpadding="2" cellspacing="0" border="0"' ) ,
90 'center', $color[4] )
91 ) ,
92 '', '', 'width="100%" border="0" cellpadding="1" cellspacing="1"' ) ,
93 'center', $color[0] )
94 ) ,
95 'center', '', 'width="95%" border="0" cellpadding="2" cellspacing="0"' ) .
96
97 '</body></html>';
98
99 function SaveUpdateFunction() {
100 global $username, $data_dir, $full_name, $email_address, $reply_to, $signature;
101
102 $i = 1;
103 $fakeI = 1;
104 $name = 'form_for_' . $i;
105 global $$name;
106 while (isset($$name))
107 {
108 $name = 'delete_' . $i;
109 global $$name;
110 if (isset($$name)) {
111 $fakeI --;
112 } else {
113 do_hook('options_identities_renumber', $i, $fakeI);
114 $filled = 0;
115
116 $name = 'full_name' . $i;
117 global $$name;
118 if ($$name != '')
119 $filled ++;
120 setPref($data_dir, $username, 'full_name' . $fakeI, $$name);
121
122 $name = 'email_address' . $i;
123 global $$name;
124 if ($$name != '')
125 $filled ++;
126 setPref($data_dir, $username, 'email_address' . $fakeI, $$name);
127
128 $name = 'reply_to' . $i;
129 global $$name;
130 if ($$name != '')
131 $filled ++;
132 setPref($data_dir, $username, 'reply_to' . $fakeI, $$name);
133
134 $name = 'signature' . $i;
135 global $$name;
136 if ($$name != '')
137 $filled ++;
138 setSig($data_dir, $username, $fakeI, $$name);
139
140 if ($filled == 0)
141 $fakeI --;
142 }
143
144 $fakeI ++;
145 $i ++;
146 $name = 'form_for_' . $i;
147 global $$name;
148 }
149
150 setPref($data_dir, $username, 'identities', $fakeI);
151
152 while ($fakeI != $i)
153 {
154 removePref($data_dir, $username, 'full_name' . $fakeI);
155 removePref($data_dir, $username, 'email_address' . $fakeI);
156 removePref($data_dir, $username, 'reply_to' . $fakeI);
157 setSig($data_dir, $username, $fakeI, "");
158 $fakeI ++;
159 }
160
161 setPref($data_dir, $username, 'full_name', $full_name);
162 setPref($data_dir, $username, 'email_address', $email_address);
163 setPref($data_dir, $username, 'reply_to', $reply_to);
164 setSig($data_dir, $username, "g", $signature);
165
166 }
167
168 function CheckAndDoDefault() {
169 global $username, $data_dir, $full_name, $email_address, $reply_to, $signature;
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, $signature;
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 $name = 'signature' . $i;
201 global $$name;
202 $temp = $signature;
203 $signature = $$name;
204 $$name = $temp;
205
206
207 return true;
208 }
209
210 $i ++;
211 $name = 'form_for_' . $i;
212 global $$name;
213 }
214 return FALSE;
215 }
216
217 function CheckForDelete() {
218 global $username, $data_dir, $full_name, $email_address, $reply_to, $signature;
219
220 $i = 1;
221 $name = 'form_for_' . $i;
222 global $$name;
223 while (isset($$name))
224 {
225 $name = 'delete_' . $i;
226 global $$name;
227 if (isset($$name)) {
228 return true;
229 }
230
231 $i ++;
232 $name = 'form_for_' . $i;
233 global $$name;
234 }
235 return false;
236 }
237
238 function CheckAndDoPromote() {
239 global $username, $data_dir, $full_name, $email_address, $reply_to;
240
241 $i = 1;
242 $name = 'form_for_' . $i;
243 global $$name;
244 while (isset($$name)) {
245 $name = 'promote_' . $i;
246 global $$name;
247 if (isset($$name) && $i > 1) {
248 do_hook('options_identities_renumber', $i, $i - 1);
249
250 $nameA = 'full_name' . $i;
251 $nameB = 'full_name' . ($i - 1);
252 global $$nameA, $$nameB;
253 $temp = $$nameA;
254 $$nameA = $$nameB;
255 $$nameB = $temp;
256
257 $nameA = 'email_address' . $i;
258 $nameB = 'email_address' . ($i - 1);
259 global $$nameA, $$nameB;
260 $temp = $$nameA;
261 $$nameA = $$nameB;
262 $$nameB = $temp;
263
264 $nameA = 'reply_to' . $i;
265 $nameB = 'reply_to' . ($i - 1);
266 global $$nameA, $$nameB;
267 $temp = $$nameA;
268 $$nameA = $$nameB;
269 $$nameB = $temp;
270
271 $nameA = 'signature' . $i;
272 $nameB = 'signature' . ($i - 1);
273 global $$nameA, $$nameB;
274 $temp = $$nameA;
275 $$nameA = $$nameB;
276 $$nameB = $temp;
277
278 return true;
279 }
280
281 $i ++;
282 $name = 'form_for_' . $i;
283 global $$name;
284 }
285 return false;
286 }
287
288 function LoadInfo(&$n, &$e, &$r, &$s, $post) {
289 global $username, $data_dir;
290
291 $n = getPref($data_dir, $username, 'full_name' . $post);
292 $e = getPref($data_dir, $username, 'email_address' . $post);
293 $r = getPref($data_dir, $username, 'reply_to' . $post);
294 if ($post == '')
295 $post = 'g';
296 $s = getSig($data_dir,$username,$post);
297
298 if ($n != '' || $e != '' || $r != '' || $s != '')
299 return true;
300 }
301
302 function sti_input( $title, $hd, $data, $post, $bg ) {
303 $return_val = html_tag( 'tr',
304 html_tag( 'td', $title . ':', 'right', '', 'style="white-space: nowrap;"' ) .
305 html_tag( 'td', '<input size="50" type="text" value="' . htmlspecialchars($data) . '" name="' . $hd . $post . '" />' , 'left' ) ,
306 '', $bg );
307 return ($return_val);
308 }
309
310 function sti_textarea( $title, $hd, $data, $post, $bg ) {
311 $return_val = html_tag( 'tr',
312 html_tag( 'td', $title . ':', 'right', '', 'style="white-space: nowrap;"' ) .
313 html_tag( 'td', '<textarea cols="50" rows="5" name="' . $hd . $post . '">' . htmlspecialchars($data) . '</textarea>' , 'left' ) ,
314 '', $bg );
315 return ($return_val);
316 }
317
318 function ShowTableInfo($full_name, $email_address, $reply_to, $signature, $post) {
319 global $color;
320
321 $OtherBG = $color[0];
322 if ($full_name == '' && $email_address == '' && $reply_to == '' && $signature == '')
323 $OtherBG = '';
324
325 if ($full_name == '' && $email_address == '' && $reply_to == '' && $signature == '')
326 $isEmptySection = true;
327 else
328 $isEmptySection = false;
329
330 $return_val = '';
331 $return_val .= sti_input( _("Full Name"), 'full_name', $full_name, $post, $OtherBG );
332 $return_val .= sti_input( _("E-Mail Address"), 'email_address', $email_address, $post, $OtherBG );
333 $return_val .= sti_input( _("Reply To"), 'reply_to', $reply_to, $post, $OtherBG );
334 $return_val .= sti_textarea( _("Signature"), 'signature', $signature, $post, $OtherBG );
335
336 $return_val .= concat_hook_function('options_identities_table', array($OtherBG, $isEmptySection, $post));
337 $return_val .= html_tag( 'tr', '', '', $OtherBG);
338 $return_val .= html_tag( 'td', '&nbsp;', 'left' );
339 $return_val .= html_tag( 'td', '', 'left' );
340 $return_val .= '<input type="hidden" name="form_for_'. $post .'" value="1" />';
341 $return_val .= '<input type="submit" name="update" value="' . _("Save / Update") . '" />';
342
343
344 if (! $isEmptySection && $post != '') {
345 $return_val .= '<input type="submit" name="make_default_' . $post . '" value="'.
346 _("Make Default") . '" />'.
347 '<input type="submit" name="delete_' . $post . '" value="'.
348 _("Delete") . '" />';
349 }
350 if (! $isEmptySection && $post != '' && $post > 1) {
351 $return_val .= '<input type="submit" name="promote_' . $post . '" value="'.
352 _("Move Up") . '" />';
353 }
354 $return_val .= concat_hook_function('options_identities_buttons', array($isEmptySection, $post));
355 $return_val .= '</td></tr>'.
356 html_tag( 'tr', html_tag( 'td', '&nbsp;', 'left', '', 'colspan="2"' ));
357
358 return ($return_val);
359 }
360
361 ?>