4 * AJAX-powered auto-completion
11 * Call this right before wDumpContent() on any page which requires the address book popup
13 void address_book_popup(void) {
14 /* Open a new div, hidden initially, for address book popups. */
15 wprintf("</div>\n"); /* End of 'content' div */
16 wprintf("<div id=\"address_book_popup\" style=\"display:none;\">");
17 wprintf("<div id=\"address_book_popup_container_div\">");
18 wprintf("<div id=\"address_book_popup_middle_div\"></div>");
19 wprintf("<div id=\"address_book_inner_div\"></div>");
21 /* The 'address_book_popup' div will be closed by wDumpContent() */
25 * Address book popup window
27 void display_address_book_middle_div(void) {
35 begin_ajax_response();
37 wprintf("<table border=0 width=100%%><tr valign=middle>");
38 wprintf("<td align=left><img src=\"static/viewcontacts_32x.gif\"></td>");
39 wprintf("<td align=center>");
42 "<select class=\"address_book_popup_title\" size=1 id=\"which_addr_book\" "
43 " onChange=\"PopulateAddressBookInnerDiv($('which_addr_book').value,'%s')\">",
47 wprintf("<option value=\"__LOCAL_USERS__\">");
48 escputs(serv_info.serv_humannode);
49 wprintf("</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);
65 while (GetNextHashPos(List, it, &len, &Name, &Namee)) {
66 wprintf("<option value=\"");
67 urlescputs((char*)Namee);
69 escputs((char*)Namee);
70 wprintf("</option>\n");
74 wprintf("</select></form>");
77 wprintf("<td align=right "
78 "onclick=\"javascript:$('address_book_popup').style.display='none';\" "
79 "><img src=\"static/closewindow.gif\">");
80 wprintf("</td></tr></table>");
82 wprintf("<script type=\"text/javascript\">"
83 "PopulateAddressBookInnerDiv($('which_addr_book').value,'%s');"
94 * Address book popup results
96 void display_address_book_inner_div() {
100 char target_label[64];
107 char saved_roomname[128];
109 begin_ajax_response();
111 List = NewHash(1, NULL);
112 wprintf("<div align=center><form onSubmit=\"return false;\">"
113 "<select multiple name=\"whichaddr\" id=\"whichaddr\" size=\"15\">\n");
115 if (!strcasecmp(bstr("which_addr_book"), "__LOCAL_USERS__")) {
117 serv_getln(buf, sizeof buf);
118 if (buf[0] == '1') while(len = serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
119 Name = (char*) malloc(len + 1);
120 len = extract_token(Name, buf, 0, '|', len + 1);
121 if((len > 5) && (strncmp(Name, "SYS_", 4) == 0)) {
125 Put(List, Name, len, Name, NULL);
128 SortByHashKey(List, 1);
129 it = GetNewHashPos();
130 while (GetNextHashPos(List, it, &len, &Name, &Namee)) {
131 wprintf("<option value=\"");
132 escputs((char*)Namee);
134 escputs((char*)Namee);
135 wprintf("</option>\n");
142 safestrncpy(saved_roomname, WC->wc_roomname, sizeof saved_roomname);
143 gotoroom(bstr("which_addr_book"));
145 serv_getln(buf, sizeof buf);
146 if (buf[0] == '1') while(len = serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
147 Name = (char*) malloc(len + 1);
148 len = extract_token(Name, buf, 0, '|', len + 1);
149 Put(List, Name, len, Name, NULL);
152 SortByHashKey(List, 1);
153 it = GetNewHashPos();
154 while (GetNextHashPos(List, it, &len, &Name, (void**)&Namee)) {
155 wprintf("<option value=\"");
156 escputs((char*)Namee);
158 escputs((char*)Namee);
159 wprintf("</option>\n");
163 gotoroom(saved_roomname);
166 wprintf("</select>\n");
168 wprintf("%s: ", _("Add"));
170 num_targets = num_tokens(bstr("target_input"), '|');
171 for (i=0; i<num_targets; i+=2) {
172 extract_token(target_id, bstr("target_input"), i, '|', sizeof target_id);
173 extract_token(target_label, bstr("target_input"), i+1, '|', sizeof target_label);
174 wprintf("<INPUT TYPE=\"submit\" NAME=\"select_button\" VALUE=\"%s\" ", target_label);
175 wprintf("onClick=\"AddContactsToTarget($('%s'),$('whichaddr'));\">", target_id);
178 /* This 'close window' button works. Omitting it because we already have a close button
179 * in the upper right corner, and this one takes up space.
181 wprintf("<INPUT TYPE=\"submit\" NAME=\"close_button\" VALUE=\"%s\" ", _("Close window"));
182 wprintf("onclick=\"javascript:$('address_book_popup').style.display='none';\">");
185 wprintf("</form></div>\n");
194 InitModule_ADDRBOOK_POPUP
197 WebcitAddUrlHandler(HKEY("display_address_book_middle_div"), display_address_book_middle_div, 0);
198 WebcitAddUrlHandler(HKEY("display_address_book_inner_div"), display_address_book_inner_div, 0);