5 ** Manage personal address book.
11 if(!isset($logged_in)) {
12 echo _("You must login first.");
15 if(!isset($username) ||
!isset($key)) {
16 echo _("You need a valid user and password to access this page!");
20 if (!isset($config_php))
21 include("../config/config.php");
22 if (!isset($array_php))
23 include("../functions/array.php");
24 if (!isset($strings_php))
25 include("../functions/strings.php");
26 if (!isset($imap_php))
27 include("../functions/imap.php");
28 if (!isset($page_header_php))
29 include("../functions/page_header.php");
30 if (!isset($display_messages_php))
31 include("../functions/display_messages.php");
32 if (!isset($addressbook_php))
33 include("../functions/addressbook.php");
36 // Sort array by the key "name"
37 function alistcmp($a,$b) {
38 if($a["backend"] > $b["backend"])
40 else if($a["backend"] < $b["backend"])
43 return (strtolower($a["name"]) > strtolower($b["name"])) ?
1 : -1;
46 // Output form to add and modify address data
47 function address_form($name, $submittext, $values = array()) {
49 print "<TABLE BORDER=0 CELLPADDING=1 COLS=2 WIDTH=\"90%\" ALIGN=center>\n";
50 printf("<TR><TD WIDTH=50 BGCOLOR=\"$color[4]\" ALIGN=RIGHT>%s:</TD>",
52 printf("<TD BGCOLOR=\"%s\" ALIGN=left>".
53 "<INPUT NAME=\"%s[nickname]\" SIZE=15 VALUE=\"%s\">".
54 " <SMALL>%s</SMALL></TD></TR>\n",
55 $color[4], $name, htmlspecialchars($values["nickname"]),
57 printf("<TR><TD WIDTH=50 BGCOLOR=\"$color[4]\" ALIGN=RIGHT>%s:</TD>",
59 printf("<TD BGCOLOR=\"%s\" ALIGN=left>".
60 "<INPUT NAME=\"%s[email]\" SIZE=45 VALUE=\"%s\"></TD></TR>\n",
61 $color[4], $name, htmlspecialchars($values["email"]));
62 printf("<TR><TD WIDTH=50 BGCOLOR=\"$color[4]\" ALIGN=RIGHT>%s:</TD>",
64 printf("<TD BGCOLOR=\"%s\" ALIGN=left>".
65 "<INPUT NAME=\"%s[firstname]\" SIZE=45 VALUE=\"%s\"></TD></TR>\n",
66 $color[4], $name, htmlspecialchars($values["firstname"]));
67 printf("<TR><TD WIDTH=50 BGCOLOR=\"$color[4]\" ALIGN=RIGHT>%s:</TD>",
69 printf("<TD BGCOLOR=\"%s\" ALIGN=left>".
70 "<INPUT NAME=\"%s[lastname]\" SIZE=45 VALUE=\"%s\"></TD></TR>\n",
71 $color[4], $name, htmlspecialchars($values["lastname"]));
72 printf("<TR><TD WIDTH=50 BGCOLOR=\"$color[4]\" ALIGN=RIGHT>%s:</TD>",
73 _("Additional info"));
74 printf("<TD BGCOLOR=\"%s\" ALIGN=left>".
75 "<INPUT NAME=\"%s[label]\" SIZE=45 VALUE=\"%s\"></TD></TR>\n",
76 $color[4], $name, htmlspecialchars($values["label"]));
78 printf("<TR><TD COLSPAN=2 BGCOLOR=\"%s\" ALIGN=center>\n".
79 "<INPUT TYPE=submit NAME=\"%s[SUBMIT]\" VALUE=\"%s\"></TD></TR>\n",
80 $color[4], $name, $submittext);
87 $imapConnection = sqimap_login ($username, $key,
88 $imapServerAddress, $imapPort, 10);
89 include("../src/load_prefs.php");
90 sqimap_logout ($imapConnection);
93 // Open addressbook, with error messages on but without LDAP (the
94 // second "true"). Don't need LDAP here anyway
95 $abook = addressbook_init(true, true);
96 if($abook->localbackend
== 0) {
97 plain_error_message(_("No personal address book is defined. Contact administrator."), $color);
101 print "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">\n";
102 print "<HTML><HEAD><TITLE>\n";
103 printf("%s: %s\n", $org_title, _("Address Book"));
104 print "</TITLE></HEAD>\n\n";
106 printf('<BODY TEXT="%s" BGCOLOR="%s" LINK="%s" VLINK="%s" ALINK="%s">',
107 $color[8], $color[4], $color[7], $color[7], $color[7]);
108 displayPageHeader($color, "None");
114 $showaddrlist = true;
115 $defselected = array();
118 // Handle user's actions
119 if($REQUEST_METHOD == "POST") {
121 // ***********************************************
123 // ***********************************************
124 if(!empty($addaddr["nickname"])) {
126 $r = $abook->add($addaddr, $abook->localbackend
);
128 // Handle error messages
130 // Remove backend name from error string
131 $errstr = $abook->error
;
132 $errstr = ereg_replace("^\[.*\] *", "", $errstr);
134 $formerror = $errstr;
135 $showaddrlist = false;
142 // ***********************************************
143 // Delete address(es)
144 // ***********************************************
145 else if((!empty($deladdr)) &&
150 // The selected addresses are identidied by "backend:nickname".
151 // Sort the list and process one backend at the time
156 for($i = 0 ; (($i < sizeof($sel)) && !$delfailed) ; $i++
) {
157 list($sbackend, $snick) = split(":", $sel[$i]);
159 // When we get to a new backend, process addresses in
161 if($prevback != $sbackend && $prevback != -1) {
163 $r = $abook->remove($subsel, $prevback);
165 $formerror = $abook->error
;
173 // Queue for processing
174 array_push($subsel, $snick);
175 $prevback = $sbackend;
179 $r = $abook->remove($subsel, $prevback);
180 if(!$r) { // Handle errors
181 $formerror = $abook->error
;
187 $showaddrlist = true;
188 $defselected = $orig_sel;
193 // ***********************************************
194 // Update/modify address
195 // ***********************************************
196 else if(!empty($editaddr)) {
198 // Stage one: Copy data into form
199 if(sizeof($sel) > 0) {
200 if(sizeof($sel) > 1) {
201 $formerror = _("You can only edit one address at the time");
202 $showaddrlist = true;
206 list($ebackend, $enick) = split(":", $sel[0]);
207 $olddata = $abook->lookup($enick, $ebackend);
209 // Display the "new address" form
210 printf("<FORM ACTION=\"%s\" METHOD=\"POST\">\n", $PHP_SELF);
211 print "<TABLE WIDTH=100% COLS=1 ALIGN=CENTER>\n";
212 print "<TR><TD BGCOLOR=\"$color[0]\" ALIGN=CENTER>\n<STRONG>";
213 print _("Update address");
214 print "<STRONG>\n</TD></TR>\n";
216 address_form("editaddr", _("Update address"), $olddata);
217 printf("<INPUT TYPE=hidden NAME=oldnick VALUE=\"%s\">\n",
218 htmlspecialchars($olddata["nickname"]));
219 printf("<INPUT TYPE=hidden NAME=backend VALUE=\"%s\">\n",
220 htmlspecialchars($olddata["backend"]));
221 print "<INPUT TYPE=hidden NAME=doedit VALUE=1>\n";
226 // Stage two: Write new data
227 else if($doedit = 1) {
228 $newdata = $editaddr;
229 $r = $abook->modify($oldnick, $newdata, $backend);
231 // Handle error messages
234 print "<TABLE WIDTH=100% COLS=1 ALIGN=CENTER>\n";
235 print "<TR><TD ALIGN=CENTER>\n<br><STRONG>";
236 print "<FONT COLOR=\"$color[2]\">"._("ERROR").": ".
237 $abook->error
."</FONT>";
238 print "<STRONG>\n</TD></TR>\n";
241 // Display the "new address" form again
242 printf("<FORM ACTION=\"%s\" METHOD=\"POST\">\n", $PHP_SELF);
243 print "<TABLE WIDTH=100% COLS=1 ALIGN=CENTER>\n";
244 print "<TR><TD BGCOLOR=\"$color[0]\" ALIGN=CENTER>\n<STRONG>";
245 print _("Update address");
246 print "<STRONG>\n</TD></TR>\n";
248 address_form("editaddr", _("Update address"), $newdata);
249 printf("<INPUT TYPE=hidden NAME=oldnick VALUE=\"%s\">\n",
250 htmlspecialchars($newdata["nickname"]));
251 printf("<INPUT TYPE=hidden NAME=backend VALUE=\"%s\">\n",
252 htmlspecialchars($newdata["backend"]));
253 print "<INPUT TYPE=hidden NAME=doedit VALUE=1>\n";
260 // Should not get here...
262 plain_error_message(_("Unknown error"), $color);
265 } // End of edit address
269 // Some times we end output before forms are printed
271 print "</BODY></HTML>\n";
277 // ===================================================================
278 // The following is only executed on a GET request, or on a POST when
279 // a user is added, or when "delete" or "modify" was successful.
280 // ===================================================================
282 // Display error messages
283 if(!empty($formerror)) {
284 print "<TABLE WIDTH=100% COLS=1 ALIGN=CENTER>\n";
285 print "<TR><TD ALIGN=CENTER>\n<br><STRONG>";
286 print "<FONT COLOR=\"$color[2]\">"._("ERROR").": $formerror</FONT>";
287 print "<STRONG>\n</TD></TR>\n";
292 // Display the address management part
294 printf("<FORM ACTION=\"%s\" METHOD=\"POST\">\n", $PHP_SELF);
296 // Get and sort address list
297 $alist = $abook->list_addr();
298 usort($alist,'alistcmp');
300 $headerprinted = false;
303 while(list($key,$row) = each($alist)) {
305 // New table header for each backend
306 if($prevbackend != $row["backend"]) {
307 if($prevbackend >= 0) {
308 print "<TR><TD COLSPAN=5 ALIGN=center>";
309 print " <BR></TD></TR></TABLE>\n";
312 print "<TABLE WIDTH=\"95%\" COLS=1 ALIGN=CENTER>\n";
313 print "<TR><TD BGCOLOR=\"$color[0]\" ALIGN=CENTER>\n<STRONG>";
314 print $row["source"];
315 print "<STRONG>\n</TD></TR>\n";
318 print "<TABLE COLS=5 BORDER=0 CELLPADDING=1 CELLSPACING=0 ".
319 "WIDTH=\"90%\" ALIGN=center>";
320 printf("<tr bgcolor=\"$color[9]\"><TH align=left width=\"3%%\">".
321 " <TH align=left width=\"10%%\">%s<TH align=left>%s".
322 "<TH align=left>%s<TH align=left>%s</TR>\n",
323 _("Nickname"), _("Name"), _("E-mail"), _("Info"));
325 $headerprinted = true;
328 $prevbackend = $row["backend"];
330 // Check if this user is selected
331 if(in_array($row["backend"].":".$row["nickname"], $defselected))
332 $selected = "CHECKED";
337 printf("<TR%s NOWRAP>\n <TD align=center><SMALL>".
338 "<INPUT TYPE=checkbox %s NAME=\"sel[]\" VALUE=\"%d:%s\">".
339 "</SMALL><TD NOWRAP> %s <TD NOWRAP> %s ".
340 "<TD NOWRAP> <A HREF=\"compose.php?send_to=%s\">%s</A>".
341 " <TD NOWRAP> %s</TR>\n",
342 ($line %
2) ?
" bgcolor=\"$color[0]\"" : "",
343 $selected, $row["backend"], $row["nickname"],
344 $row["nickname"], $row["name"],
345 rawurlencode($row["email"]), $row["email"], $row["label"]);
349 // End of list. Close table.
351 print "<TR><TD COLSPAN=5 ALIGN=center>\n";
352 printf("<INPUT TYPE=submit NAME=editaddr VALUE=\"%s\">\n",
354 printf("<INPUT TYPE=submit NAME=deladdr VALUE=\"%s\">\n",
355 _("Delete selected"));
356 print "</TR></TABLE></FORM>";
358 } // end of addresslist
361 // Display the "new address" form
362 printf("<FORM ACTION=\"%s\" METHOD=\"POST\">\n", $PHP_SELF);
363 print "<TABLE WIDTH=100% COLS=1 ALIGN=CENTER>\n";
364 print "<TR><TD BGCOLOR=\"$color[0]\" ALIGN=CENTER>\n<STRONG>";
365 printf(_("Add to %s"), $abook->localbackendname
);
366 print "<STRONG>\n</TD></TR>\n";
368 address_form("addaddr", _("Add address"), $defdata);