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 * Address book popup window
21 void display_address_book_middle_div(void) {
31 begin_ajax_response();
33 DefAddrBook = get_room_pref("defaddrbook");
35 wc_printf("<table border=0 width=100%%><tr valign=middle>");
36 wc_printf("<td align=left><img src=\"static/webcit_icons/essen/32x32/contact.png\"></td>");
37 wc_printf("<td align=center>");
40 "<select class=\"address_book_popup_title\" size=1 id=\"which_addr_book\" "
41 " onChange=\"PopulateAddressBookInnerDiv($('which_addr_book').value,'%s')\">",
45 wc_printf("<option value=\"__LOCAL_USERS__\" %s>",
46 (strcmp(ChrPtr(DefAddrBook), "__LOCAL_USERS__") == 0)?
47 "selected=\"selected\" ":"");
48 escputs(ChrPtr(WC->serv_info->serv_humannode));
49 wc_printf("</option>\n");
52 List = NewHash(1, NULL);
54 serv_getln(buf, sizeof buf);
55 if (buf[0] == '1') while(len = serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
56 if (extract_int(buf, 6) == VIEW_ADDRESSBOOK) {
57 Name = (char*) malloc(len + 1);
58 len = extract_token(Name, buf, 0, '|', len);
59 Put(List, Name, len, Name, NULL);
63 SortByHashKey(List, 1);
64 it = GetNewHashPos(List, 0);
65 while (GetNextHashPos(List, it, &len, &VCName, &Namee)) {
66 wc_printf("<option value=\"");
67 urlescputs((char*)Namee);
68 if (strcmp(ChrPtr(DefAddrBook), Namee) == 0)
69 wc_printf("\" selected=\"selected\" >");
72 escputs((char*)Namee);
73 wc_printf("</option>\n");
77 wc_printf("</select></form>");
80 wc_printf("<td align=right "
81 "onclick=\"javascript:$('address_book_popup').style.display='none';\" "
82 "><img src=\"static/webcit_icons/closewindow.gif\">");
83 wc_printf("</td></tr></table>");
85 wc_printf("<script type=\"text/javascript\">PopulateAddressBookInnerDiv($('which_addr_book').value,'%s');</script>",
95 * Address book popup results
97 void display_address_book_inner_div() {
101 char target_label[64];
109 StrBuf *saved_roomname;
111 begin_ajax_response();
113 List = NewHash(1, NULL);
114 wc_printf("<div align=center><form onSubmit=\"return false;\">"
115 "<select multiple name=\"whichaddr\" id=\"whichaddr\" size=\"15\">\n");
117 if (!strcasecmp(bstr("which_addr_book"), "__LOCAL_USERS__")) {
119 serv_getln(buf, sizeof buf);
120 if (buf[0] == '1') while(len = serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
121 Name = (char*) malloc(len + 1);
122 len = extract_token(Name, buf, 0, '|', len + 1);
123 if((len > 5) && (strncmp(Name, "SYS_", 4) == 0)) {
127 Put(List, Name, len, Name, NULL);
130 SortByHashKey(List, 1);
131 it = GetNewHashPos(List, 0);
132 while (GetNextHashPos(List, it, &len, &VCName, &Namee)) {
133 wc_printf("<option value=\"");
134 escputs((char*)Namee);
136 escputs((char*)Namee);
137 wc_printf("</option>\n");
144 set_room_pref("defaddrbook",NewStrBufDup(sbstr("which_addr_book")), 0);
145 saved_roomname = NewStrBufDup(WC->CurRoom.name);
146 gotoroom(sbstr("which_addr_book"));
148 serv_getln(buf, sizeof buf);
149 if (buf[0] == '1') while(len = serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
150 Name = (char*) malloc(len + 1);
151 len = extract_token(Name, buf, 0, '|', len + 1);
152 Put(List, Name, len, Name, NULL);
155 SortByHashKey(List, 1);
156 it = GetNewHashPos(List, 0);
157 while (GetNextHashPos(List, it, &len, &VCName, (void**)&Namee)) {
158 wc_printf("<option value=\"");
159 escputs((char*)Namee);
161 escputs((char*)Namee);
162 wc_printf("</option>\n");
166 gotoroom(saved_roomname);
167 FreeStrBuf(&saved_roomname);
170 wc_printf("</select>\n");
172 wc_printf("%s: ", _("Add"));
174 num_targets = num_tokens(bstr("target_input"), '|');
175 for (i=0; i<num_targets; i+=2) {
176 extract_token(target_id, bstr("target_input"), i, '|', sizeof target_id);
177 extract_token(target_label, bstr("target_input"), i+1, '|', sizeof target_label);
178 wc_printf("<INPUT TYPE=\"submit\" NAME=\"select_button\" VALUE=\"%s\" ", target_label);
179 wc_printf("onClick=\"AddContactsToTarget($('%s'),$('whichaddr'));\">", target_id);
182 /* This 'close window' button works. Omitting it because we already have a close button
183 * in the upper right corner, and this one takes up space.
185 wc_printf("<INPUT TYPE=\"submit\" NAME=\"close_button\" VALUE=\"%s\" ", _("Close window"));
186 wc_printf("onclick=\"javascript:$('address_book_popup').style.display='none';\">");
189 wc_printf("</form></div>\n");
198 InitModule_ADDRBOOK_POPUP
201 WebcitAddUrlHandler(HKEY("display_address_book_middle_div"), "", 0, display_address_book_middle_div, 0);
202 WebcitAddUrlHandler(HKEY("display_address_book_inner_div"), "", 0, display_address_book_inner_div, 0);