2 * AJAX-powered auto-completion
4 * Copyright (c) 1996-2010 by the citadel.org team
6 * This program is open source software. You can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 3 of the
9 * License, or (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, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 * Call this right before wDumpContent() on any page which requires the address book popup
27 void address_book_popup(void) {
28 /* Open a new div, hidden initially, for address book popups. */
29 wc_printf("</div>\n"); /* End of 'content' div */
30 wc_printf("<div id=\"address_book_popup\" style=\"display:none;\">");
31 wc_printf("<div id=\"address_book_popup_container_div\">");
32 wc_printf("<div id=\"address_book_popup_middle_div\"></div>");
33 wc_printf("<div id=\"address_book_inner_div\"></div>");
35 /* The 'address_book_popup' div will be closed by wDumpContent() */
39 * Address book popup window
41 void display_address_book_middle_div(void) {
51 begin_ajax_response();
53 DefAddrBook = get_room_pref("defaddrbook");
55 wc_printf("<table border=0 width=100%%><tr valign=middle>");
56 wc_printf("<td align=left><img src=\"static/webcit_icons/essen/32x32/contact.png\"></td>");
57 wc_printf("<td align=center>");
60 "<select class=\"address_book_popup_title\" size=1 id=\"which_addr_book\" "
61 " onChange=\"PopulateAddressBookInnerDiv($('which_addr_book').value,'%s')\">",
65 wc_printf("<option value=\"__LOCAL_USERS__\" %s>",
66 (strcmp(ChrPtr(DefAddrBook), "__LOCAL_USERS__") == 0)?
67 "selected=\"selected\" ":"");
68 escputs(ChrPtr(WC->serv_info->serv_humannode));
69 wc_printf("</option>\n");
72 List = NewHash(1, NULL);
74 serv_getln(buf, sizeof buf);
75 if (buf[0] == '1') while(len = serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
76 if (extract_int(buf, 6) == VIEW_ADDRESSBOOK) {
77 Name = (char*) malloc(len + 1);
78 len = extract_token(Name, buf, 0, '|', len);
79 Put(List, Name, len, Name, NULL);
83 SortByHashKey(List, 1);
84 it = GetNewHashPos(List, 0);
85 while (GetNextHashPos(List, it, &len, &VCName, &Namee)) {
86 wc_printf("<option value=\"");
87 urlescputs((char*)Namee);
88 if (strcmp(ChrPtr(DefAddrBook), Namee) == 0)
89 wc_printf("\" selected=\"selected\" >");
92 escputs((char*)Namee);
93 wc_printf("</option>\n");
97 wc_printf("</select></form>");
100 wc_printf("<td align=right "
101 "onclick=\"javascript:$('address_book_popup').style.display='none';\" "
102 "><img src=\"static/webcit_icons/closewindow.gif\">");
103 wc_printf("</td></tr></table>");
105 wc_printf("<script type=\"text/javascript\">PopulateAddressBookInnerDiv($('which_addr_book').value,'%s');</script>",
115 * Address book popup results
117 void display_address_book_inner_div() {
121 char target_label[64];
129 StrBuf *saved_roomname;
131 begin_ajax_response();
133 List = NewHash(1, NULL);
134 wc_printf("<div align=center><form onSubmit=\"return false;\">"
135 "<select multiple name=\"whichaddr\" id=\"whichaddr\" size=\"15\">\n");
137 if (!strcasecmp(bstr("which_addr_book"), "__LOCAL_USERS__")) {
139 serv_getln(buf, sizeof buf);
140 if (buf[0] == '1') while(len = serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
141 Name = (char*) malloc(len + 1);
142 len = extract_token(Name, buf, 0, '|', len + 1);
143 if((len > 5) && (strncmp(Name, "SYS_", 4) == 0)) {
147 Put(List, Name, len, Name, NULL);
150 SortByHashKey(List, 1);
151 it = GetNewHashPos(List, 0);
152 while (GetNextHashPos(List, it, &len, &VCName, &Namee)) {
153 wc_printf("<option value=\"");
154 escputs((char*)Namee);
156 escputs((char*)Namee);
157 wc_printf("</option>\n");
164 set_room_pref("defaddrbook",NewStrBufDup(sbstr("which_addr_book")), 0);
165 saved_roomname = NewStrBufDup(WC->CurRoom.name);
166 gotoroom(sbstr("which_addr_book"));
168 serv_getln(buf, sizeof buf);
169 if (buf[0] == '1') while(len = serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
170 Name = (char*) malloc(len + 1);
171 len = extract_token(Name, buf, 0, '|', len + 1);
172 Put(List, Name, len, Name, NULL);
175 SortByHashKey(List, 1);
176 it = GetNewHashPos(List, 0);
177 while (GetNextHashPos(List, it, &len, &VCName, (void**)&Namee)) {
178 wc_printf("<option value=\"");
179 escputs((char*)Namee);
181 escputs((char*)Namee);
182 wc_printf("</option>\n");
186 gotoroom(saved_roomname);
187 FreeStrBuf(&saved_roomname);
190 wc_printf("</select>\n");
192 wc_printf("%s: ", _("Add"));
194 num_targets = num_tokens(bstr("target_input"), '|');
195 for (i=0; i<num_targets; i+=2) {
196 extract_token(target_id, bstr("target_input"), i, '|', sizeof target_id);
197 extract_token(target_label, bstr("target_input"), i+1, '|', sizeof target_label);
198 wc_printf("<INPUT TYPE=\"submit\" NAME=\"select_button\" VALUE=\"%s\" ", target_label);
199 wc_printf("onClick=\"AddContactsToTarget($('%s'),$('whichaddr'));\">", target_id);
202 /* This 'close window' button works. Omitting it because we already have a close button
203 * in the upper right corner, and this one takes up space.
205 wc_printf("<INPUT TYPE=\"submit\" NAME=\"close_button\" VALUE=\"%s\" ", _("Close window"));
206 wc_printf("onclick=\"javascript:$('address_book_popup').style.display='none';\">");
209 wc_printf("</form></div>\n");
218 InitModule_ADDRBOOK_POPUP
221 WebcitAddUrlHandler(HKEY("display_address_book_middle_div"), "", 0, display_address_book_middle_div, 0);
222 WebcitAddUrlHandler(HKEY("display_address_book_inner_div"), "", 0, display_address_book_inner_div, 0);