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) {
37 begin_ajax_response();
39 DefAddrBook
= get_room_pref("defaddrbook");
41 wprintf("<table border=0 width=100%%><tr valign=middle>");
42 wprintf("<td align=left><img src=\"static/viewcontacts_32x.gif\"></td>");
43 wprintf("<td align=center>");
46 "<select class=\"address_book_popup_title\" size=1 id=\"which_addr_book\" "
47 " onChange=\"PopulateAddressBookInnerDiv($('which_addr_book').value,'%s')\">",
51 wprintf("<option value=\"__LOCAL_USERS__\" %s>",
52 (strcmp(ChrPtr(DefAddrBook
), "__LOCAL_USERS__") == 0)?
53 "selected=\"selected\" ":"");
54 escputs(ChrPtr(serv_info
.serv_humannode
));
55 wprintf("</option>\n");
58 List
= NewHash(1, NULL
);
60 serv_getln(buf
, sizeof buf
);
61 if (buf
[0] == '1') while(len
= serv_getln(buf
, sizeof buf
), strcmp(buf
, "000")) {
62 if (extract_int(buf
, 6) == VIEW_ADDRESSBOOK
) {
63 Name
= (char*) malloc(len
+ 1);
64 len
= extract_token(Name
, buf
, 0, '|', len
);
65 Put(List
, Name
, len
, Name
, NULL
);
69 SortByHashKey(List
, 1);
70 it
= GetNewHashPos(List
, 0);
71 while (GetNextHashPos(List
, it
, &len
, &VCName
, &Namee
)) {
72 wprintf("<option value=\"");
73 urlescputs((char*)Namee
);
74 if (strcmp(ChrPtr(DefAddrBook
), Namee
) == 0)
75 wprintf("\" selected=\"selected\" >");
78 escputs((char*)Namee
);
79 wprintf("</option>\n");
83 wprintf("</select></form>");
86 wprintf("<td align=right "
87 "onclick=\"javascript:$('address_book_popup').style.display='none';\" "
88 "><img src=\"static/closewindow.gif\">");
89 wprintf("</td></tr></table>");
91 wprintf("<script type=\"text/javascript\">PopulateAddressBookInnerDiv($('which_addr_book').value,'%s');</script>",
101 * Address book popup results
103 void display_address_book_inner_div() {
107 char target_label
[64];
115 StrBuf
*saved_roomname
;
117 begin_ajax_response();
119 List
= NewHash(1, NULL
);
120 wprintf("<div align=center><form onSubmit=\"return false;\">"
121 "<select multiple name=\"whichaddr\" id=\"whichaddr\" size=\"15\">\n");
123 if (!strcasecmp(bstr("which_addr_book"), "__LOCAL_USERS__")) {
125 serv_getln(buf
, sizeof buf
);
126 if (buf
[0] == '1') while(len
= serv_getln(buf
, sizeof buf
), strcmp(buf
, "000")) {
127 Name
= (char*) malloc(len
+ 1);
128 len
= extract_token(Name
, buf
, 0, '|', len
+ 1);
129 if((len
> 5) && (strncmp(Name
, "SYS_", 4) == 0)) {
133 Put(List
, Name
, len
, Name
, NULL
);
136 SortByHashKey(List
, 1);
137 it
= GetNewHashPos(List
, 0);
138 while (GetNextHashPos(List
, it
, &len
, &VCName
, &Namee
)) {
139 wprintf("<option value=\"");
140 escputs((char*)Namee
);
142 escputs((char*)Namee
);
143 wprintf("</option>\n");
150 set_room_pref("defaddrbook",NewStrBufDup(sbstr("which_addr_book")), 0);
151 saved_roomname
= NewStrBufDup(WC
->wc_roomname
);
152 gotoroom(sbstr("which_addr_book"));
154 serv_getln(buf
, sizeof buf
);
155 if (buf
[0] == '1') while(len
= serv_getln(buf
, sizeof buf
), strcmp(buf
, "000")) {
156 Name
= (char*) malloc(len
+ 1);
157 len
= extract_token(Name
, buf
, 0, '|', len
+ 1);
158 Put(List
, Name
, len
, Name
, NULL
);
161 SortByHashKey(List
, 1);
162 it
= GetNewHashPos(List
, 0);
163 while (GetNextHashPos(List
, it
, &len
, &VCName
, (void**)&Namee
)) {
164 wprintf("<option value=\"");
165 escputs((char*)Namee
);
167 escputs((char*)Namee
);
168 wprintf("</option>\n");
172 gotoroom(saved_roomname
);
173 FreeStrBuf(&saved_roomname
);
176 wprintf("</select>\n");
178 wprintf("%s: ", _("Add"));
180 num_targets
= num_tokens(bstr("target_input"), '|');
181 for (i
=0; i
<num_targets
; i
+=2) {
182 extract_token(target_id
, bstr("target_input"), i
, '|', sizeof target_id
);
183 extract_token(target_label
, bstr("target_input"), i
+1, '|', sizeof target_label
);
184 wprintf("<INPUT TYPE=\"submit\" NAME=\"select_button\" VALUE=\"%s\" ", target_label
);
185 wprintf("onClick=\"AddContactsToTarget($('%s'),$('whichaddr'));\">", target_id
);
188 /* This 'close window' button works. Omitting it because we already have a close button
189 * in the upper right corner, and this one takes up space.
191 wprintf("<INPUT TYPE=\"submit\" NAME=\"close_button\" VALUE=\"%s\" ", _("Close window"));
192 wprintf("onclick=\"javascript:$('address_book_popup').style.display='none';\">");
195 wprintf("</form></div>\n");
204 InitModule_ADDRBOOK_POPUP
207 WebcitAddUrlHandler(HKEY("display_address_book_middle_div"), display_address_book_middle_div
, 0);
208 WebcitAddUrlHandler(HKEY("display_address_book_inner_div"), display_address_book_inner_div
, 0);