c69fee4617235b27125fb841b658d0e7708786aa
5 ** Manage personal address book.
9 if(!isset($logged_in)) {
10 echo _("You must login first.");
13 if(!isset($username) ||
!isset($key)) {
14 echo _("You need a valid user and password to access this page!");
18 if (!isset($config_php))
19 include("../config/config.php");
20 if (!isset($array_php))
21 include("../functions/array.php");
22 if (!isset($strings_php))
23 include("../functions/strings.php");
24 if (!isset($imap_php))
25 include("../functions/imap.php");
26 if (!isset($page_header_php))
27 include("../functions/page_header.php");
28 if (!isset($display_messages_php))
29 include("../functions/display_messages.php");
30 if (!isset($addressbook_php))
31 include("../functions/addressbook.php");
34 // Sort array by the key "name"
35 function alistcmp($a,$b) {
36 if($a["backend"] > $b["backend"])
38 else if($a["backend"] < $b["backend"])
41 return (strtolower($a["name"]) > strtolower($b["name"])) ?
1 : -1;
44 // Output form to add and modify address data
45 function address_form($name, $submittext, $values = array()) {
47 print "<TABLE BORDER=0 CELLPADDING=1 COLS=2 WIDTH=\"90%\" ALIGN=center>\n";
48 printf("<TR><TD WIDTH=50 BGCOLOR=\"$color[4]\" ALIGN=RIGHT>%s:</TD>",
50 printf("<TD BGCOLOR=\"%s\" ALIGN=left>".
51 "<INPUT NAME=\"%s[nickname]\" SIZE=15 VALUE=\"%s\">".
52 " <SMALL>%s</SMALL></TD></TR>\n",
53 $color[4], $name, htmlspecialchars($values["nickname"]),
55 printf("<TR><TD WIDTH=50 BGCOLOR=\"$color[4]\" ALIGN=RIGHT>%s:</TD>",
57 printf("<TD BGCOLOR=\"%s\" ALIGN=left>".
58 "<INPUT NAME=\"%s[email]\" SIZE=45 VALUE=\"%s\"></TD></TR>\n",
59 $color[4], $name, htmlspecialchars($values["email"]));
60 printf("<TR><TD WIDTH=50 BGCOLOR=\"$color[4]\" ALIGN=RIGHT>%s:</TD>",
62 printf("<TD BGCOLOR=\"%s\" ALIGN=left>".
63 "<INPUT NAME=\"%s[firstname]\" SIZE=45 VALUE=\"%s\"></TD></TR>\n",
64 $color[4], $name, htmlspecialchars($values["firstname"]));
65 printf("<TR><TD WIDTH=50 BGCOLOR=\"$color[4]\" ALIGN=RIGHT>%s:</TD>",
67 printf("<TD BGCOLOR=\"%s\" ALIGN=left>".
68 "<INPUT NAME=\"%s[lastname]\" SIZE=45 VALUE=\"%s\"></TD></TR>\n",
69 $color[4], $name, htmlspecialchars($values["lastname"]));
70 printf("<TR><TD WIDTH=50 BGCOLOR=\"$color[4]\" ALIGN=RIGHT>%s:</TD>",
71 _("Additional info"));
72 printf("<TD BGCOLOR=\"%s\" ALIGN=left>".
73 "<INPUT NAME=\"%s[label]\" SIZE=45 VALUE=\"%s\"></TD></TR>\n",
74 $color[4], $name, htmlspecialchars($values["label"]));
76 printf("<TR><TD COLSPAN=2 BGCOLOR=\"%s\" ALIGN=center>\n".
77 "<INPUT TYPE=submit NAME=\"%s[SUBMIT]\" VALUE=\"%s\"></TD></TR>\n",
78 $color[4], $name, $submittext);
85 $imapConnection = sqimap_login ($username, $key,
86 $imapServerAddress, $imapPort, 10);
87 include("../src/load_prefs.php");
88 sqimap_logout ($imapConnection);
91 // Open addressbook, with error messages on but without LDAP (the
92 // second "true"). Don't need LDAP here anyway
93 $abook = addressbook_init(true, true);
94 if($abook->localbackend
== 0) {
95 plain_error_message(_("No personal address book is defined. Contact administrator."), $color);
99 print "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">\n";
100 print "<HTML><HEAD><TITLE>\n";
101 printf("%s: %s\n", $org_title, _("Address Book"));
102 print "</TITLE></HEAD>\n\n";
104 printf('<BODY TEXT="%s" BGCOLOR="%s" LINK="%s" VLINK="%s" ALINK="%s">',
105 $color[8], $color[4], $color[7], $color[7], $color[7]);
106 displayPageHeader($color, "None");
112 $showaddrlist = true;
113 $defselected = array();
116 // Handle user's actions
117 if($REQUEST_METHOD == "POST") {
119 // ***********************************************
121 // ***********************************************
122 if(!empty($addaddr["nickname"])) {
124 $r = $abook->add($addaddr, $abook->localbackend
);
126 // Handle error messages
128 // Remove backend name from error string
129 $errstr = $abook->error
;
130 $errstr = ereg_replace("^\[.*\] *", "", $errstr);
132 $formerror = $errstr;
133 $showaddrlist = false;
140 // ***********************************************
141 // Delete address(es)
142 // ***********************************************
143 else if((!empty($deladdr)) &&
148 // The selected addresses are identidied by "backend:nickname".
149 // Sort the list and process one backend at the time
154 for($i = 0 ; (($i < sizeof($sel)) && !$delfailed) ; $i++
) {
155 list($sbackend, $snick) = split(":", $sel[$i]);
157 // When we get to a new backend, process addresses in
159 if($prevback != $sbackend && $prevback != -1) {
161 $r = $abook->remove($subsel, $prevback);
163 $formerror = $abook->error
;
171 // Queue for processing
172 array_push($subsel, $snick);
173 $prevback = $sbackend;
177 $r = $abook->remove($subsel, $prevback);
178 if(!$r) { // Handle errors
179 $formerror = $abook->error
;
185 $showaddrlist = true;
186 $defselected = $orig_sel;
191 // ***********************************************
192 // Update/modify address
193 // ***********************************************
194 else if(!empty($editaddr)) {
196 // Stage one: Copy data into form
197 if(sizeof($sel) > 0) {
198 if(sizeof($sel) > 1) {
199 $formerror = _("You can only edit one address at the time");
200 $showaddrlist = true;
204 list($ebackend, $enick) = split(":", $sel[0]);
205 $olddata = $abook->lookup($enick, $ebackend);
207 // Display the "new address" form
208 printf("<FORM ACTION=\"%s\" METHOD=\"POST\">\n", $PHP_SELF);
209 print "<TABLE WIDTH=100% COLS=1 ALIGN=CENTER>\n";
210 print "<TR><TD BGCOLOR=\"$color[0]\" ALIGN=CENTER>\n<STRONG>";
211 print _("Update address");
212 print "<STRONG>\n</TD></TR>\n";
214 address_form("editaddr", _("Update address"), $olddata);
215 printf("<INPUT TYPE=hidden NAME=oldnick VALUE=\"%s\">\n",
216 htmlspecialchars($olddata["nickname"]));
217 printf("<INPUT TYPE=hidden NAME=backend VALUE=\"%s\">\n",
218 htmlspecialchars($olddata["backend"]));
219 print "<INPUT TYPE=hidden NAME=doedit VALUE=1>\n";
224 // Stage two: Write new data
225 else if($doedit = 1) {
226 $newdata = $editaddr;
227 $r = $abook->modify($oldnick, $newdata, $backend);
229 // Handle error messages
232 print "<TABLE WIDTH=100% COLS=1 ALIGN=CENTER>\n";
233 print "<TR><TD ALIGN=CENTER>\n<br><STRONG>";
234 print "<FONT COLOR=\"$color[2]\">"._("ERROR").": ".
235 $abook->error
."</FONT>";
236 print "<STRONG>\n</TD></TR>\n";
239 // Display the "new address" form again
240 printf("<FORM ACTION=\"%s\" METHOD=\"POST\">\n", $PHP_SELF);
241 print "<TABLE WIDTH=100% COLS=1 ALIGN=CENTER>\n";
242 print "<TR><TD BGCOLOR=\"$color[0]\" ALIGN=CENTER>\n<STRONG>";
243 print _("Update address");
244 print "<STRONG>\n</TD></TR>\n";
246 address_form("editaddr", _("Update address"), $newdata);
247 printf("<INPUT TYPE=hidden NAME=oldnick VALUE=\"%s\">\n",
248 htmlspecialchars($newdata["nickname"]));
249 printf("<INPUT TYPE=hidden NAME=backend VALUE=\"%s\">\n",
250 htmlspecialchars($newdata["backend"]));
251 print "<INPUT TYPE=hidden NAME=doedit VALUE=1>\n";
258 // Should not get here...
260 plain_error_message(_("Unknown error"), $color);
263 } // End of edit address
267 // Some times we end output before forms are printed
269 print "</BODY></HTML>\n";
275 // ===================================================================
276 // The following is only executed on a GET request, or on a POST when
277 // a user is added, or when "delete" or "modify" was successful.
278 // ===================================================================
280 // Display error messages
281 if(!empty($formerror)) {
282 print "<TABLE WIDTH=100% COLS=1 ALIGN=CENTER>\n";
283 print "<TR><TD ALIGN=CENTER>\n<br><STRONG>";
284 print "<FONT COLOR=\"$color[2]\">"._("ERROR").": $formerror</FONT>";
285 print "<STRONG>\n</TD></TR>\n";
290 // Display the address management part
292 printf("<FORM ACTION=\"%s\" METHOD=\"POST\">\n", $PHP_SELF);
294 // Get and sort address list
295 $alist = $abook->list_addr();
296 usort($alist,'alistcmp');
300 while(list($key,$row) = each($alist)) {
302 // New table header for each backend
303 if($prevbackend != $row["backend"]) {
304 if($prevbackend >= 0) {
305 print "<TR><TD COLSPAN=5 ALIGN=center>";
306 print " <BR></TD></TR></TABLE>\n";
309 print "<TABLE WIDTH=\"95%\" COLS=1 ALIGN=CENTER>\n";
310 print "<TR><TD BGCOLOR=\"$color[0]\" ALIGN=CENTER>\n<STRONG>";
311 print $row["source"];
312 print "<STRONG>\n</TD></TR>\n";
315 print "<TABLE COLS=5 BORDER=0 CELLPADDING=1 CELLSPACING=0 ".
316 "WIDTH=\"90%\" ALIGN=center>";
317 printf("<tr bgcolor=\"$color[9]\"><TH align=left width=\"3%%\">".
318 " <TH align=left width=\"10%%\">%s<TH align=left>%s".
319 "<TH align=left>%s<TH align=left>%s</TR>\n",
320 _("Nickname"), _("Name"), _("E-mail"), _("Info"));
324 $prevbackend = $row["backend"];
326 // Check if this user is selected
327 if(in_array($row["backend"].":".$row["nickname"], $defselected))
328 $selected = "CHECKED";
333 printf("<TR%s NOWRAP>\n <TD align=center><SMALL>".
334 "<INPUT TYPE=checkbox %s NAME=\"sel[]\" VALUE=\"%d:%s\">".
335 "</SMALL><TD NOWRAP> %s <TD NOWRAP> %s ".
336 "<TD NOWRAP> <A HREF=\"compose.php?send_to=%s\">%s</A>".
337 " <TD NOWRAP> %s</TR>\n",
338 ($line %
2) ?
" bgcolor=\"$color[0]\"" : "",
339 $selected, $row["backend"], $row["nickname"],
340 $row["nickname"], $row["name"],
341 rawurlencode($row["email"]), $row["email"], $row["label"]);
345 // End of list. Close table.
346 print "<TR><TD COLSPAN=5 ALIGN=center>\n";
347 printf("<INPUT TYPE=submit NAME=editaddr VALUE=\"%s\">\n",
349 printf("<INPUT TYPE=submit NAME=deladdr VALUE=\"%s\">\n",
350 _("Delete selected"));
351 print "</TR></TABLE></FORM>";
352 } // end of addresslist
355 // Display the "new address" form
356 printf("<FORM ACTION=\"%s\" METHOD=\"POST\">\n", $PHP_SELF);
357 print "<TABLE WIDTH=100% COLS=1 ALIGN=CENTER>\n";
358 print "<TR><TD BGCOLOR=\"$color[0]\" ALIGN=CENTER>\n<STRONG>";
359 printf(_("Add to %s"), $abook->localbackendname
);
360 print "<STRONG>\n</TD></TR>\n";
362 address_form("addaddr", _("Add address"), $defdata);