Lots of changes for variable initialization - clean up, really,
[squirrelmail.git] / src / options_identities.php
CommitLineData
aaf9abef 1<?php
895905c0 2
35586184 3/**
4 * options_identities.php
5 *
76911253 6 * Copyright (c) 1999-2003 The SquirrelMail Project Team
35586184 7 * Licensed under the GNU GPL. For full terms see the file COPYING.
8 *
9 * Display Identities Options
10 *
11 * $Id$
12 */
13
86725763 14/* Path for SquirrelMail required files. */
15define('SM_PATH','../');
16
17/* SquirrelMail required files. */
08185f2a 18require_once(SM_PATH . 'include/validate.php');
1e12d1ff 19require_once(SM_PATH . 'functions/global.php');
86725763 20require_once(SM_PATH . 'functions/display_messages.php');
21require_once(SM_PATH . 'functions/html.php');
aaf9abef 22
fe369c70 23/* POST data var names are dynamic because
24 of the possible multiple idents so lets get
25 them all
26*/
27if (!empty($_POST)) {
28 extract($_POST);
29}
30/* got 'em all */
31
32f4e318 32 if (isset($return)) {
33 SaveUpdateFunction();
34 header('Location: options_personal.php');
35 exit();
36 }
37
38 displayPageHeader($color, 'None');
39
40 $Info = do_hook('options_identities_process', 0);
41 if ($Info[1]) {
42 SaveUpdateFunction();
43 }
44
45 if (CheckAndDoDefault() || CheckAndDoPromote()) {
46 SaveUpdateFunction();
47 }
ddfe5eef 48 if (isset($update) || CheckForDelete()) {
32f4e318 49 SaveUpdateFunction();
50 }
51
545238b1 52 do_hook('options_identities_top');
01265fba 53 LoadInfo($full_name, $email_address, $reply_to, $signature, '');
545238b1 54 $td_str = '';
55 $td_str .= '<form name="f" action="options_identities.php" method="post"><br>';
56 $td_str .= ShowTableInfo($full_name, $email_address, $reply_to, $signature, '');
aaf9abef 57
545238b1 58 $num = 1;
59 while (LoadInfo($full_name, $email_address, $reply_to, $signature, $num)) {
60 $td_str .= html_tag( 'tr',
61 html_tag( 'th', sprintf (_("Alternate Identity %d"), $num), 'center', '', 'colspan="2"' ) ,
62 '', $color[9]);
63 $td_str .= ShowTableInfo($full_name, $email_address, $reply_to, $signature, $num);
64 $num ++;
65 }
66
67 echo '<br>' .
68 html_tag( 'table', "\n" .
69 html_tag( 'tr', "\n" .
70 html_tag( 'td', "\n" .
71 '<b>'. _("Options") . ' - ' . _("Advanced Identities") .'</b><br>' .
72 html_tag( 'table', "\n" .
73 html_tag( 'tr', "\n" .
74 html_tag( 'td', "\n" .
75 html_tag( 'table', "\n" .
76 html_tag( 'tr', "\n" .
77 html_tag( 'th', _("Default Identity"), 'center', '', 'colspan="2"' ) ,
78 '', $color[9]) . "\n" .
79 $td_str . "\n" .
80 html_tag( 'tr',
81 html_tag( 'th', _("Add a New Identity") . ShowTableInfo('', '', '', '', $num), 'center', '', 'colspan="2"' ) ,
82 '', $color[9]) ,
83 '', '', 'width="80%" cellpadding="2" cellspacing="0" border="0"' ) ,
84 'center', $color[4] )
85 ) ,
86 '', '', 'width="100%" border="0" cellpadding="1" cellspacing="1"' ) ,
87 'center', $color[0] )
88 ) ,
89 'center', '', 'width="95%" border="0" cellpadding="2" cellspacing="0"' ) .
90
91 '</body></html>';
aaf9abef 92
e697b6cc 93 function SaveUpdateFunction() {
01265fba 94 global $username, $data_dir, $full_name, $email_address, $reply_to, $signature;
aaf9abef 95
e697b6cc 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;
aaf9abef 109
e697b6cc 110 $name = 'full_name' . $i;
111 global $$name;
112 if ($$name != '')
113 $filled ++;
114 setPref($data_dir, $username, 'full_name' . $fakeI, $$name);
aaf9abef 115
e697b6cc 116 $name = 'email_address' . $i;
117 global $$name;
118 if ($$name != '')
119 $filled ++;
120 setPref($data_dir, $username, 'email_address' . $fakeI, $$name);
d20f2df6 121
e697b6cc 122 $name = 'reply_to' . $i;
123 global $$name;
124 if ($$name != '')
125 $filled ++;
126 setPref($data_dir, $username, 'reply_to' . $fakeI, $$name);
127
01265fba 128 $name = 'signature' . $i;
129 global $$name;
130 if ($$name != '')
131 $filled ++;
132 setSig($data_dir, $username, $fakeI, $$name);
133
e697b6cc 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);
01265fba 151 setSig($data_dir, $username, $fakeI, "");
e697b6cc 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);
01265fba 158 setSig($data_dir, $username, "g", $signature);
159
e697b6cc 160 }
161
162 function CheckAndDoDefault() {
01265fba 163 global $username, $data_dir, $full_name, $email_address, $reply_to, $signature;
e697b6cc 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');
01265fba 174 global $full_name, $email_address, $reply_to, $signature;
e697b6cc 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
01265fba 194 $name = 'signature' . $i;
195 global $$name;
196 $temp = $signature;
197 $signature = $$name;
198 $$name = $temp;
199
200
e697b6cc 201 return true;
202 }
203
204 $i ++;
205 $name = 'form_for_' . $i;
206 global $$name;
207 }
208 return FALSE;
209 }
210
211 function CheckForDelete() {
01265fba 212 global $username, $data_dir, $full_name, $email_address, $reply_to, $signature;
aaf9abef 213
e697b6cc 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 }
aaf9abef 224
e697b6cc 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
32f4e318 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;
e697b6cc 264
01265fba 265 $nameA = 'signature' . $i;
266 $nameB = 'signature' . ($i - 1);
267 global $$nameA, $$nameB;
268 $temp = $$nameA;
269 $$nameA = $$nameB;
270 $$nameB = $temp;
271
32f4e318 272 return true;
e697b6cc 273 }
274
275 $i ++;
276 $name = 'form_for_' . $i;
277 global $$name;
278 }
279 return false;
280 }
281
01265fba 282 function LoadInfo(&$n, &$e, &$r, &$s, $post) {
e697b6cc 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);
01265fba 288 if ($post == '')
289 $post = 'g';
290 $s = getSig($data_dir,$username,$post);
e697b6cc 291
01265fba 292 if ($n != '' || $e != '' || $r != '' || $s != '')
e697b6cc 293 return true;
294 }
295
296function sti_input( $title, $hd, $data, $post, $bg ) {
545238b1 297 $return_val = html_tag( 'tr',
298 html_tag( 'td', $title . ':', 'right', '', 'nowrap' ) .
299 html_tag( 'td', '<input size="50" type="text" value="' . htmlspecialchars($data) . '" name="' . $hd . $post . '">' , 'left' ) ,
300 '', $bg );
301 return ($return_val);
aaf9abef 302}
303
01265fba 304function sti_textarea( $title, $hd, $data, $post, $bg ) {
545238b1 305 $return_val = html_tag( 'tr',
306 html_tag( 'td', $title . ':', 'right', '', 'nowrap' ) .
307 html_tag( 'td', '<textarea cols="50" rows="5" name="' . $hd . $post . '">' . htmlspecialchars($data) . '</textarea>' , 'left' ) ,
308 '', $bg );
309 return ($return_val);
01265fba 310}
311
312function ShowTableInfo($full_name, $email_address, $reply_to, $signature, $post) {
e697b6cc 313 global $color;
aaf9abef 314
545238b1 315 $OtherBG = $color[0];
01265fba 316 if ($full_name == '' && $email_address == '' && $reply_to == '' && $signature == '')
e697b6cc 317 $OtherBG = '';
aaf9abef 318
01265fba 319 if ($full_name == '' && $email_address == '' && $reply_to == '' && $signature == '')
e697b6cc 320 $isEmptySection = true;
321 else
322 $isEmptySection = false;
323
545238b1 324 $return_val = '';
325 $return_val .= sti_input( _("Full Name"), 'full_name', $full_name, $post, $OtherBG );
326 $return_val .= sti_input( _("E-Mail Address"), 'email_address', $email_address, $post, $OtherBG );
327 $return_val .= sti_input( _("Reply To"), 'reply_to', $reply_to, $post, $OtherBG );
328 $return_val .= sti_textarea( _("Signature"), 'signature', $signature, $post, $OtherBG );
e697b6cc 329
330 do_hook('options_identities_table', $OtherBG, $isEmptySection, $post);
545238b1 331 $return_val .= html_tag( 'tr', '', '', $OtherBG);
332 $return_val .= html_tag( 'td', '&nbsp;', 'left' );
333 $return_val .= html_tag( 'td', '', 'left' );
334 $return_val .= '<input type=hidden name="form_for_'. $post .'" value="1">';
335 $return_val .= '<input type="submit" name="update" value="' . _("Save / Update") . '">';
336
337
e697b6cc 338 if (! $isEmptySection && $post != '') {
545238b1 339 $return_val .= '<input type="submit" name="make_default_' . $post . '" value="'.
e697b6cc 340 _("Make Default") . '">'.
545238b1 341 '<input type=submit name="delete_' . $post . '" value="'.
e697b6cc 342 _("Delete") . '">';
343 }
344 if (! $isEmptySection && $post != '' && $post > 1) {
545238b1 345 $return_val .= '<input type=submit name="promote_' . $post . '" value="'.
e697b6cc 346 _("Move Up") . '">';
347 }
348 do_hook('options_identities_buttons', $isEmptySection, $post);
545238b1 349 $return_val .= '</td></tr>'.
350 html_tag( 'tr', html_tag( 'td', '&nbsp;', 'left', '', 'colspan="2"' ));
351
352 return ($return_val);
aaf9abef 353}
86725763 354?>