2 * AJAX-powered auto-completion
4 * Copyright (c) 1996-2012 by the citadel.org team
6 * This program is open source software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License, version 3.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
19 * Call this right before wDumpContent() on any page which requires the address book popup
21 void address_book_popup(void) {
22 /* Open a new div, hidden initially, for address book popups. */
23 wc_printf("</div>\n"); /* End of 'content' div */
24 wc_printf("<div id=\"address_book_popup\" style=\"display:none;\">");
25 wc_printf("<div id=\"address_book_popup_container_div\">");
26 wc_printf("<div id=\"address_book_popup_middle_div\"></div>");
27 wc_printf("<div id=\"address_book_inner_div\"></div>");
29 /* The 'address_book_popup' div will be closed by wDumpContent() */
33 * Address book popup window
35 void display_address_book_middle_div(void) {
45 begin_ajax_response();
47 DefAddrBook = get_room_pref("defaddrbook");
49 wc_printf("<table border=0 width=100%%><tr valign=middle>");
50 wc_printf("<td align=left><img src=\"static/webcit_icons/essen/32x32/contact.png\"></td>");
51 wc_printf("<td align=center>");
54 "<select class=\"address_book_popup_title\" size=1 id=\"which_addr_book\" "
55 " onChange=\"PopulateAddressBookInnerDiv($('which_addr_book').value,'%s')\">",
59 wc_printf("<option value=\"__LOCAL_USERS__\" %s>",
60 (strcmp(ChrPtr(DefAddrBook), "__LOCAL_USERS__") == 0)?
61 "selected=\"selected\" ":"");
62 escputs(ChrPtr(WC->serv_info->serv_humannode));
63 wc_printf("</option>\n");
66 List = NewHash(1, NULL);
68 serv_getln(buf, sizeof buf);
69 if (buf[0] == '1') while(len = serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
70 if (extract_int(buf, 6) == VIEW_ADDRESSBOOK) {
71 Name = (char*) malloc(len + 1);
72 len = extract_token(Name, buf, 0, '|', len);
73 Put(List, Name, len, Name, NULL);
77 SortByHashKey(List, 1);
78 it = GetNewHashPos(List, 0);
79 while (GetNextHashPos(List, it, &len, &VCName, &Namee)) {
80 wc_printf("<option value=\"");
81 urlescputs((char*)Namee);
82 if (strcmp(ChrPtr(DefAddrBook), Namee) == 0)
83 wc_printf("\" selected=\"selected\" >");
86 escputs((char*)Namee);
87 wc_printf("</option>\n");
91 wc_printf("</select></form>");
94 wc_printf("<td align=right "
95 "onclick=\"javascript:$('address_book_popup').style.display='none';\" "
96 "><img src=\"static/webcit_icons/closewindow.gif\">");
97 wc_printf("</td></tr></table>");
99 wc_printf("<script type=\"text/javascript\">PopulateAddressBookInnerDiv($('which_addr_book').value,'%s');</script>",
109 * Address book popup results
111 void display_address_book_inner_div() {
115 char target_label[64];
123 StrBuf *saved_roomname;
125 begin_ajax_response();
127 List = NewHash(1, NULL);
128 wc_printf("<div align=center><form onSubmit=\"return false;\">"
129 "<select multiple name=\"whichaddr\" id=\"whichaddr\" size=\"15\">\n");
131 if (!strcasecmp(bstr("which_addr_book"), "__LOCAL_USERS__")) {
133 serv_getln(buf, sizeof buf);
134 if (buf[0] == '1') while(len = serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
135 Name = (char*) malloc(len + 1);
136 len = extract_token(Name, buf, 0, '|', len + 1);
137 if((len > 5) && (strncmp(Name, "SYS_", 4) == 0)) {
141 Put(List, Name, len, Name, NULL);
144 SortByHashKey(List, 1);
145 it = GetNewHashPos(List, 0);
146 while (GetNextHashPos(List, it, &len, &VCName, &Namee)) {
147 wc_printf("<option value=\"");
148 escputs((char*)Namee);
150 escputs((char*)Namee);
151 wc_printf("</option>\n");
158 set_room_pref("defaddrbook",NewStrBufDup(sbstr("which_addr_book")), 0);
159 saved_roomname = NewStrBufDup(WC->CurRoom.name);
160 gotoroom(sbstr("which_addr_book"));
162 serv_getln(buf, sizeof buf);
163 if (buf[0] == '1') while(len = serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
164 Name = (char*) malloc(len + 1);
165 len = extract_token(Name, buf, 0, '|', len + 1);
166 Put(List, Name, len, Name, NULL);
169 SortByHashKey(List, 1);
170 it = GetNewHashPos(List, 0);
171 while (GetNextHashPos(List, it, &len, &VCName, (void**)&Namee)) {
172 wc_printf("<option value=\"");
173 escputs((char*)Namee);
175 escputs((char*)Namee);
176 wc_printf("</option>\n");
180 gotoroom(saved_roomname);
181 FreeStrBuf(&saved_roomname);
184 wc_printf("</select>\n");
186 wc_printf("%s: ", _("Add"));
188 num_targets = num_tokens(bstr("target_input"), '|');
189 for (i=0; i<num_targets; i+=2) {
190 extract_token(target_id, bstr("target_input"), i, '|', sizeof target_id);
191 extract_token(target_label, bstr("target_input"), i+1, '|', sizeof target_label);
192 wc_printf("<INPUT TYPE=\"submit\" NAME=\"select_button\" VALUE=\"%s\" ", target_label);
193 wc_printf("onClick=\"AddContactsToTarget($('%s'),$('whichaddr'));\">", target_id);
196 /* This 'close window' button works. Omitting it because we already have a close button
197 * in the upper right corner, and this one takes up space.
199 wc_printf("<INPUT TYPE=\"submit\" NAME=\"close_button\" VALUE=\"%s\" ", _("Close window"));
200 wc_printf("onclick=\"javascript:$('address_book_popup').style.display='none';\">");
203 wc_printf("</form></div>\n");
212 InitModule_ADDRBOOK_POPUP
215 WebcitAddUrlHandler(HKEY("display_address_book_middle_div"), "", 0, display_address_book_middle_div, 0);
216 WebcitAddUrlHandler(HKEY("display_address_book_inner_div"), "", 0, display_address_book_inner_div, 0);