cb3bd0e9898afb4593dad30df2799083eccd728d
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 return (strtolower($a["name"]) > strtolower($b["name"])) ?
1 : -1;
39 // Output form to add and modify address data
40 function address_form($name, $submittext, $values = array()) {
42 print "<TABLE BORDER=0 CELLPADDING=1 COLS=2 WIDTH=\"90%\" ALIGN=center>\n";
43 printf("<TR><TD WIDTH=50 BGCOLOR=\"$color[4]\" ALIGN=RIGHT>%s:</TD>",
45 printf("<TD BGCOLOR=\"%s\" ALIGN=left>".
46 "<INPUT NAME=\"%s[nickname]\" SIZE=15 VALUE=\"%s\">".
47 " <SMALL>%s</SMALL></TD></TR>\n",
48 $color[4], $name, htmlspecialchars($values["nickname"]),
50 printf("<TR><TD WIDTH=50 BGCOLOR=\"$color[4]\" ALIGN=RIGHT>%s:</TD>",
52 printf("<TD BGCOLOR=\"%s\" ALIGN=left>".
53 "<INPUT NAME=\"%s[email]\" SIZE=45 VALUE=\"%s\"></TD></TR>\n",
54 $color[4], $name, htmlspecialchars($values["email"]));
55 printf("<TR><TD WIDTH=50 BGCOLOR=\"$color[4]\" ALIGN=RIGHT>%s:</TD>",
57 printf("<TD BGCOLOR=\"%s\" ALIGN=left>".
58 "<INPUT NAME=\"%s[firstname]\" SIZE=45 VALUE=\"%s\"></TD></TR>\n",
59 $color[4], $name, htmlspecialchars($values["firstname"]));
60 printf("<TR><TD WIDTH=50 BGCOLOR=\"$color[4]\" ALIGN=RIGHT>%s:</TD>",
62 printf("<TD BGCOLOR=\"%s\" ALIGN=left>".
63 "<INPUT NAME=\"%s[lastname]\" SIZE=45 VALUE=\"%s\"></TD></TR>\n",
64 $color[4], $name, htmlspecialchars($values["lastname"]));
65 printf("<TR><TD WIDTH=50 BGCOLOR=\"$color[4]\" ALIGN=RIGHT>%s:</TD>",
66 _("Additional info"));
67 printf("<TD BGCOLOR=\"%s\" ALIGN=left>".
68 "<INPUT NAME=\"%s[label]\" SIZE=45 VALUE=\"%s\"></TD></TR>\n",
69 $color[4], $name, htmlspecialchars($values["label"]));
71 printf("<TR><TD COLSPAN=2 BGCOLOR=\"%s\" ALIGN=center>\n".
72 "<INPUT TYPE=submit NAME=\"%s[SUBMIT]\" VALUE=\"%s\"></TD></TR>\n",
73 $color[4], $name, $submittext);
80 $imapConnection = sqimap_login ($username, $key,
81 $imapServerAddress, $imapPort, 10);
82 include("../src/load_prefs.php");
83 sqimap_logout ($imapConnection);
86 // Open addressbook, with error messages on but without LDAP (the
87 // second "true"). Don't need LDAP here anyway
88 $abook = addressbook_init(true, true);
89 if($abook->localbackend
== 0) {
90 plain_error_message(_("No personal address book is defined. Contact administrator."), $color);
94 print "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">\n";
95 print "<HTML><HEAD><TITLE>\n";
96 printf("%s: %s\n", $org_title, _("Address Book"));
97 print "</TITLE></HEAD>\n\n";
99 printf('<BODY TEXT="%s" BGCOLOR="%s" LINK="%s" VLINK="%s" ALINK="%s">',
100 $color[8], $color[4], $color[7], $color[7], $color[7]);
101 displayPageHeader($color, "None");
107 $showaddrlist = true;
110 // Handle user's actions
111 if($REQUEST_METHOD == "POST") {
113 // Check for user addition
114 $add_data = $HTTP_POST_VARS["addaddr"];
115 if(!empty($add_data["nickname"])) {
117 $r = $abook->add($add_data, $abook->localbackend
);
119 // Handle error messages
121 // Remove backend name from error string
122 $errstr = $abook->error
;
123 $errstr = ereg_replace("^\[.*\] *", "", $errstr);
125 $formerror = $errstr;
126 $showaddrlist = false;
127 $defdata = $add_data;
132 // Check for "delete address"
133 if((!empty($HTTP_POST_VARS["deladdr"])) &&
134 sizeof($HTTP_POST_VARS["sel"]) > 0) {
135 plain_error_message("Delete address not implemented yet", $color);
139 // Check for "edit address"
140 if((!empty($HTTP_POST_VARS["editaddr"])) &&
141 sizeof($HTTP_POST_VARS["sel"]) > 0) {
142 plain_error_message("Edit address not implemented yet", $color);
146 // Some times we end output before forms are printed
148 print "</BODY></HTML>\n";
154 // ===================================================================
155 // The following is only executed on a GET request, or on a POST when
156 // a user is added, or when "delete" or "modify" was successful.
157 // ===================================================================
159 // Display error messages
160 if(!empty($formerror)) {
161 print "<TABLE WIDTH=100% COLS=1 ALIGN=CENTER>\n";
162 print "<TR><TD ALIGN=CENTER>\n<br><STRONG>";
163 print "<FONT COLOR=\"$color[2]\">"._("ERROR").": $formerror</FONT>";
164 print "<STRONG>\n</TD></TR>\n";
168 // Display the address management part
170 printf("<FORM ACTION=\"%s\" METHOD=\"POST\">\n", $PHP_SELF);
172 print "<TABLE WIDTH=100% COLS=1 ALIGN=CENTER>\n";
173 print "<TR><TD BGCOLOR=\"$color[0]\" ALIGN=CENTER>\n<STRONG>";
174 print _("Personal address book");
175 print "<STRONG>\n</TD></TR>\n";
178 // Get and sort address list
179 $alist = $abook->list_addr();
180 usort($alist,'alistcmp');
182 print "<table cols=5 border=0 width=\"90%\" align=center>";
183 printf("<tr bgcolor=\"$color[9]\"><TH align=left width=\"3%%\"> ".
184 "<TH align=left width=\"10%%\">%s<TH align=left>%s<TH align=left>%s".
185 "<TH align=left>%s</TR>\n",
186 _("Nickname"), _("Name"), _("E-mail"), _("Info"));
187 while(list($key,$row) = each($alist)) {
188 printf("<TR%s NOWRAP><TD align=center><small>".
189 "<INPUT TYPE=checkbox NAME=\"sel[]\" VALUE=\"%s\"></small>".
190 "<TD NOWRAP> %s <TD NOWRAP> %s ".
191 "<TD NOWRAP> <A HREF=\"compose.php?send_to=%s\">%s</A> ".
192 "<TD NOWRAP> %s</TR>\n",
193 ($line %
2) ?
" bgcolor=\"$color[0]\"" : "", $row["nickname"],
194 $row["nickname"], $row["name"], rawurlencode($row["email"]),
195 $row["email"], $row["label"]);
198 print "<TR><TD COLSPAN=5 ALIGN=center>\n";
199 printf("<INPUT TYPE=submit NAME=editaddr VALUE=\"%s\">\n",
201 printf("<INPUT TYPE=submit NAME=deladdr VALUE=\"%s\">\n",
202 _("Delete selected"));
203 print "</TR></TABLE></FORM>";
206 // Display the "new address" form
207 printf("<FORM ACTION=\"%s\" METHOD=\"POST\">\n", $PHP_SELF);
208 print "<TABLE WIDTH=100% COLS=1 ALIGN=CENTER>\n";
209 print "<TR><TD BGCOLOR=\"$color[0]\" ALIGN=CENTER>\n<STRONG>";
210 print _("Add to personal address book");
211 print "<STRONG>\n</TD></TR>\n";
213 address_form("addaddr", _("Add address"), $defdata);