2 * AJAX-powered auto-completion
4 * Copyright (c) 1996-2011 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 as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 * Call this right before wDumpContent() on any page which requires the address book popup
26 void address_book_popup(void) {
27 /* Open a new div, hidden initially, for address book popups. */
28 wc_printf("</div>\n"); /* End of 'content' div */
29 wc_printf("<div id=\"address_book_popup\" style=\"display:none;\">");
30 wc_printf("<div id=\"address_book_popup_container_div\">");
31 wc_printf("<div id=\"address_book_popup_middle_div\"></div>");
32 wc_printf("<div id=\"address_book_inner_div\"></div>");
34 /* The 'address_book_popup' div will be closed by wDumpContent() */
38 * Address book popup window
40 void display_address_book_middle_div(void) {
50 begin_ajax_response();
52 DefAddrBook = get_room_pref("defaddrbook");
54 wc_printf("<table border=0 width=100%%><tr valign=middle>");
55 wc_printf("<td align=left><img src=\"static/webcit_icons/essen/32x32/contact.png\"></td>");
56 wc_printf("<td align=center>");
59 "<select class=\"address_book_popup_title\" size=1 id=\"which_addr_book\" "
60 " onChange=\"PopulateAddressBookInnerDiv($('which_addr_book').value,'%s')\">",
64 wc_printf("<option value=\"__LOCAL_USERS__\" %s>",
65 (strcmp(ChrPtr(DefAddrBook), "__LOCAL_USERS__") == 0)?
66 "selected=\"selected\" ":"");
67 escputs(ChrPtr(WC->serv_info->serv_humannode));
68 wc_printf("</option>\n");
71 List = NewHash(1, NULL);
73 serv_getln(buf, sizeof buf);
74 if (buf[0] == '1') while(len = serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
75 if (extract_int(buf, 6) == VIEW_ADDRESSBOOK) {
76 Name = (char*) malloc(len + 1);
77 len = extract_token(Name, buf, 0, '|', len);
78 Put(List, Name, len, Name, NULL);
82 SortByHashKey(List, 1);
83 it = GetNewHashPos(List, 0);
84 while (GetNextHashPos(List, it, &len, &VCName, &Namee)) {
85 wc_printf("<option value=\"");
86 urlescputs((char*)Namee);
87 if (strcmp(ChrPtr(DefAddrBook), Namee) == 0)
88 wc_printf("\" selected=\"selected\" >");
91 escputs((char*)Namee);
92 wc_printf("</option>\n");
96 wc_printf("</select></form>");
99 wc_printf("<td align=right "
100 "onclick=\"javascript:$('address_book_popup').style.display='none';\" "
101 "><img src=\"static/webcit_icons/closewindow.gif\">");
102 wc_printf("</td></tr></table>");
104 wc_printf("<script type=\"text/javascript\">PopulateAddressBookInnerDiv($('which_addr_book').value,'%s');</script>",
114 * Address book popup results
116 void display_address_book_inner_div() {
120 char target_label[64];
128 StrBuf *saved_roomname;
130 begin_ajax_response();
132 List = NewHash(1, NULL);
133 wc_printf("<div align=center><form onSubmit=\"return false;\">"
134 "<select multiple name=\"whichaddr\" id=\"whichaddr\" size=\"15\">\n");
136 if (!strcasecmp(bstr("which_addr_book"), "__LOCAL_USERS__")) {
138 serv_getln(buf, sizeof buf);
139 if (buf[0] == '1') while(len = serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
140 Name = (char*) malloc(len + 1);
141 len = extract_token(Name, buf, 0, '|', len + 1);
142 if((len > 5) && (strncmp(Name, "SYS_", 4) == 0)) {
146 Put(List, Name, len, Name, NULL);
149 SortByHashKey(List, 1);
150 it = GetNewHashPos(List, 0);
151 while (GetNextHashPos(List, it, &len, &VCName, &Namee)) {
152 wc_printf("<option value=\"");
153 escputs((char*)Namee);
155 escputs((char*)Namee);
156 wc_printf("</option>\n");
163 set_room_pref("defaddrbook",NewStrBufDup(sbstr("which_addr_book")), 0);
164 saved_roomname = NewStrBufDup(WC->CurRoom.name);
165 gotoroom(sbstr("which_addr_book"));
167 serv_getln(buf, sizeof buf);
168 if (buf[0] == '1') while(len = serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
169 Name = (char*) malloc(len + 1);
170 len = extract_token(Name, buf, 0, '|', len + 1);
171 Put(List, Name, len, Name, NULL);
174 SortByHashKey(List, 1);
175 it = GetNewHashPos(List, 0);
176 while (GetNextHashPos(List, it, &len, &VCName, (void**)&Namee)) {
177 wc_printf("<option value=\"");
178 escputs((char*)Namee);
180 escputs((char*)Namee);
181 wc_printf("</option>\n");
185 gotoroom(saved_roomname);
186 FreeStrBuf(&saved_roomname);
189 wc_printf("</select>\n");
191 wc_printf("%s: ", _("Add"));
193 num_targets = num_tokens(bstr("target_input"), '|');
194 for (i=0; i<num_targets; i+=2) {
195 extract_token(target_id, bstr("target_input"), i, '|', sizeof target_id);
196 extract_token(target_label, bstr("target_input"), i+1, '|', sizeof target_label);
197 wc_printf("<INPUT TYPE=\"submit\" NAME=\"select_button\" VALUE=\"%s\" ", target_label);
198 wc_printf("onClick=\"AddContactsToTarget($('%s'),$('whichaddr'));\">", target_id);
201 /* This 'close window' button works. Omitting it because we already have a close button
202 * in the upper right corner, and this one takes up space.
204 wc_printf("<INPUT TYPE=\"submit\" NAME=\"close_button\" VALUE=\"%s\" ", _("Close window"));
205 wc_printf("onclick=\"javascript:$('address_book_popup').style.display='none';\">");
208 wc_printf("</form></div>\n");
217 InitModule_ADDRBOOK_POPUP
220 WebcitAddUrlHandler(HKEY("display_address_book_middle_div"), "", 0, display_address_book_middle_div, 0);
221 WebcitAddUrlHandler(HKEY("display_address_book_inner_div"), "", 0, display_address_book_inner_div, 0);