4 * AJAX-powered auto-completion
6 * Copyright (c) 2005-2010 by the citadel.org team
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 * Call this right before wDumpContent() on any page which requires the address book popup
29 void address_book_popup(void) {
30 /* Open a new div, hidden initially, for address book popups. */
31 wc_printf("</div>\n"); /* End of 'content' div */
32 wc_printf("<div id=\"address_book_popup\" style=\"display:none;\">");
33 wc_printf("<div id=\"address_book_popup_container_div\">");
34 wc_printf("<div id=\"address_book_popup_middle_div\"></div>");
35 wc_printf("<div id=\"address_book_inner_div\"></div>");
37 /* The 'address_book_popup' div will be closed by wDumpContent() */
41 * Address book popup window
43 void display_address_book_middle_div(void) {
53 begin_ajax_response();
55 DefAddrBook = get_room_pref("defaddrbook");
57 wc_printf("<table border=0 width=100%%><tr valign=middle>");
58 wc_printf("<td align=left><img src=\"static/viewcontacts_32x.gif\"></td>");
59 wc_printf("<td align=center>");
62 "<select class=\"address_book_popup_title\" size=1 id=\"which_addr_book\" "
63 " onChange=\"PopulateAddressBookInnerDiv($('which_addr_book').value,'%s')\">",
67 wc_printf("<option value=\"__LOCAL_USERS__\" %s>",
68 (strcmp(ChrPtr(DefAddrBook), "__LOCAL_USERS__") == 0)?
69 "selected=\"selected\" ":"");
70 escputs(ChrPtr(WC->serv_info->serv_humannode));
71 wc_printf("</option>\n");
74 List = NewHash(1, NULL);
76 serv_getln(buf, sizeof buf);
77 if (buf[0] == '1') while(len = serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
78 if (extract_int(buf, 6) == VIEW_ADDRESSBOOK) {
79 Name = (char*) malloc(len + 1);
80 len = extract_token(Name, buf, 0, '|', len);
81 Put(List, Name, len, Name, NULL);
85 SortByHashKey(List, 1);
86 it = GetNewHashPos(List, 0);
87 while (GetNextHashPos(List, it, &len, &VCName, &Namee)) {
88 wc_printf("<option value=\"");
89 urlescputs((char*)Namee);
90 if (strcmp(ChrPtr(DefAddrBook), Namee) == 0)
91 wc_printf("\" selected=\"selected\" >");
94 escputs((char*)Namee);
95 wc_printf("</option>\n");
99 wc_printf("</select></form>");
102 wc_printf("<td align=right "
103 "onclick=\"javascript:$('address_book_popup').style.display='none';\" "
104 "><img src=\"static/closewindow.gif\">");
105 wc_printf("</td></tr></table>");
107 wc_printf("<script type=\"text/javascript\">PopulateAddressBookInnerDiv($('which_addr_book').value,'%s');</script>",
117 * Address book popup results
119 void display_address_book_inner_div() {
123 char target_label[64];
131 StrBuf *saved_roomname;
133 begin_ajax_response();
135 List = NewHash(1, NULL);
136 wc_printf("<div align=center><form onSubmit=\"return false;\">"
137 "<select multiple name=\"whichaddr\" id=\"whichaddr\" size=\"15\">\n");
139 if (!strcasecmp(bstr("which_addr_book"), "__LOCAL_USERS__")) {
141 serv_getln(buf, sizeof buf);
142 if (buf[0] == '1') while(len = serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
143 Name = (char*) malloc(len + 1);
144 len = extract_token(Name, buf, 0, '|', len + 1);
145 if((len > 5) && (strncmp(Name, "SYS_", 4) == 0)) {
149 Put(List, Name, len, Name, NULL);
152 SortByHashKey(List, 1);
153 it = GetNewHashPos(List, 0);
154 while (GetNextHashPos(List, it, &len, &VCName, &Namee)) {
155 wc_printf("<option value=\"");
156 escputs((char*)Namee);
158 escputs((char*)Namee);
159 wc_printf("</option>\n");
166 set_room_pref("defaddrbook",NewStrBufDup(sbstr("which_addr_book")), 0);
167 saved_roomname = NewStrBufDup(WC->CurRoom.name);
168 gotoroom(sbstr("which_addr_book"));
170 serv_getln(buf, sizeof buf);
171 if (buf[0] == '1') while(len = serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
172 Name = (char*) malloc(len + 1);
173 len = extract_token(Name, buf, 0, '|', len + 1);
174 Put(List, Name, len, Name, NULL);
177 SortByHashKey(List, 1);
178 it = GetNewHashPos(List, 0);
179 while (GetNextHashPos(List, it, &len, &VCName, (void**)&Namee)) {
180 wc_printf("<option value=\"");
181 escputs((char*)Namee);
183 escputs((char*)Namee);
184 wc_printf("</option>\n");
188 gotoroom(saved_roomname);
189 FreeStrBuf(&saved_roomname);
192 wc_printf("</select>\n");
194 wc_printf("%s: ", _("Add"));
196 num_targets = num_tokens(bstr("target_input"), '|');
197 for (i=0; i<num_targets; i+=2) {
198 extract_token(target_id, bstr("target_input"), i, '|', sizeof target_id);
199 extract_token(target_label, bstr("target_input"), i+1, '|', sizeof target_label);
200 wc_printf("<INPUT TYPE=\"submit\" NAME=\"select_button\" VALUE=\"%s\" ", target_label);
201 wc_printf("onClick=\"AddContactsToTarget($('%s'),$('whichaddr'));\">", target_id);
204 /* This 'close window' button works. Omitting it because we already have a close button
205 * in the upper right corner, and this one takes up space.
207 wc_printf("<INPUT TYPE=\"submit\" NAME=\"close_button\" VALUE=\"%s\" ", _("Close window"));
208 wc_printf("onclick=\"javascript:$('address_book_popup').style.display='none';\">");
211 wc_printf("</form></div>\n");
220 InitModule_ADDRBOOK_POPUP
223 WebcitAddUrlHandler(HKEY("display_address_book_middle_div"), "", 0, display_address_book_middle_div, 0);
224 WebcitAddUrlHandler(HKEY("display_address_book_inner_div"), "", 0, display_address_book_inner_div, 0);