abdfb4d0 |
1 | <?php |
2 | /** |
3 | ** addressbook.php |
4 | ** |
5 | ** Manage personal address book. |
6 | ** |
7 | **/ |
8 | |
9 | if(!isset($logged_in)) { |
10 | echo _("You must login first."); |
11 | exit; |
12 | } |
13 | if(!isset($username) || !isset($key)) { |
14 | echo _("You need a valid user and password to access this page!"); |
15 | exit; |
16 | } |
17 | |
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"); |
32 | |
33 | |
34 | // Sort array by the key "name" |
35 | function alistcmp($a,$b) { |
36 | return (strtolower($a["name"]) > strtolower($b["name"])) ? 1 : -1; |
37 | } |
38 | |
39 | // Output form to add and modify address data |
40 | function address_form($name, $submittext, $values = array()) { |
41 | global $color; |
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>", |
44 | _("Nickname")); |
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"]), |
49 | _("Must be unique")); |
50 | printf("<TR><TD WIDTH=50 BGCOLOR=\"$color[4]\" ALIGN=RIGHT>%s:</TD>", |
51 | _("E-mail address")); |
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>", |
56 | _("First name")); |
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>", |
61 | _("Last name")); |
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"])); |
70 | |
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); |
74 | |
75 | print "</TABLE>\n"; |
76 | } |
77 | |
78 | |
79 | // IMAP Login |
80 | $imapConnection = sqimap_login ($username, $key, |
81 | $imapServerAddress, $imapPort, 10); |
82 | include("../src/load_prefs.php"); |
83 | sqimap_logout ($imapConnection); |
84 | |
85 | |
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); |
91 | exit(); |
92 | } |
93 | |
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"; |
98 | |
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"); |
102 | |
103 | |
104 | $defdata = array(); |
105 | $formerror = ""; |
106 | $abortform = false; |
107 | $showaddrlist = true; |
108 | |
109 | |
110 | // Handle user's actions |
111 | if($REQUEST_METHOD == "POST") { |
112 | |
113 | // Check for user addition |
114 | $add_data = $HTTP_POST_VARS["addaddr"]; |
115 | if(!empty($add_data["nickname"])) { |
116 | |
117 | $r = $abook->add($add_data, $abook->localbackend); |
118 | |
119 | // Handle error messages |
120 | if(!$r) { |
121 | // Remove backend name from error string |
122 | $errstr = $abook->error; |
123 | $errstr = ereg_replace("^\[.*\] *", "", $errstr); |
124 | |
125 | $formerror = $errstr; |
126 | $showaddrlist = false; |
127 | $defdata = $add_data; |
128 | } |
129 | |
130 | } |
131 | |
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); |
136 | $abortform = true; |
137 | } |
138 | |
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); |
143 | $abortform = true; |
144 | } |
145 | |
146 | // Some times we end output before forms are printed |
147 | if($abortform) { |
148 | print "</BODY></HTML>\n"; |
149 | exit(); |
150 | } |
151 | |
152 | } |
153 | |
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 | // =================================================================== |
158 | |
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"; |
165 | print "</TABLE>\n"; |
166 | } |
167 | |
168 | // Display the address management part |
169 | if($showaddrlist) { |
170 | printf("<FORM ACTION=\"%s\" METHOD=\"POST\">\n", $PHP_SELF); |
171 | |
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"; |
176 | print "</TABLE>\n"; |
177 | |
178 | // Get and sort address list |
179 | $alist = $abook->list_addr(); |
180 | usort($alist,'alistcmp'); |
181 | |
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"]); |
196 | $line++; |
197 | } |
198 | print "<TR><TD COLSPAN=5 ALIGN=center>\n"; |
199 | printf("<INPUT TYPE=submit NAME=editaddr VALUE=\"%s\">\n", |
200 | _("Edit selected")); |
201 | printf("<INPUT TYPE=submit NAME=deladdr VALUE=\"%s\">\n", |
202 | _("Delete selected")); |
203 | print "</TR></TABLE></FORM>"; |
204 | } |
205 | |
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"; |
212 | print "</TABLE>\n"; |
213 | address_form("addaddr", _("Add address"), $defdata); |
214 | print "</FORM>"; |
215 | |
216 | ?> |
217 | |
218 | </BODY></HTML> |