* Set all version numbers to 7.41 for upcoming beta.
[citadel.git] / webcit / addressbook_popup.c
blob8e687f3debe1a26ebfbe01a0816b1e3baaea0220
1 /*
2 * $Id$
4 * AJAX-powered auto-completion
5 */
7 #include "webcit.h"
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>");
20 wprintf("</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) {
28 char buf[256];
29 long len;
30 char *Name;
31 const char *VCName;
32 void *Namee;
33 StrBuf *DefAddrBook;
34 HashList *List;
35 HashPos *it;
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>");
45 wprintf("<form>"
46 "<select class=\"address_book_popup_title\" size=1 id=\"which_addr_book\" "
47 " onChange=\"PopulateAddressBookInnerDiv($('which_addr_book').value,'%s')\">",
48 bstr("target_input")
51 wprintf("<option value=\"__LOCAL_USERS__\" %s>",
52 (strcmp(ChrPtr(DefAddrBook), "__LOCAL_USERS__") == 0)?
53 "selected=\"selected\" ":"");
54 escputs(ChrPtr(WC->serv_info->serv_humannode));
55 wprintf("</option>\n");
58 List = NewHash(1, NULL);
59 serv_puts("LKRA");
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\" >");
76 else
77 wprintf("\">");
78 escputs((char*)Namee);
79 wprintf("</option>\n");
81 DeleteHashPos(&it);
82 DeleteHash(&List);
83 wprintf("</select></form>");
85 wprintf("</td>");
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>",
92 bstr("target_input")
95 end_ajax_response();
101 * Address book popup results
103 void display_address_book_inner_div() {
104 char buf[256];
105 int num_targets = 0;
106 char target_id[64];
107 char target_label[64];
108 long len;
109 char *Name;
110 const char *VCName;
111 void *Namee;
112 HashList *List;
113 HashPos *it;
114 int i;
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__")) {
124 serv_puts("LIST");
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)) {
130 free(Name);
131 continue;
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);
141 wprintf("\">");
142 escputs((char*)Namee);
143 wprintf("</option>\n");
145 DeleteHashPos(&it);
146 DeleteHash(&List);
149 else {
150 set_room_pref("defaddrbook",NewStrBufDup(sbstr("which_addr_book")), 0);
151 saved_roomname = NewStrBufDup(WC->wc_roomname);
152 gotoroom(sbstr("which_addr_book"));
153 serv_puts("DVCA");
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);
166 wprintf("\">");
167 escputs((char*)Namee);
168 wprintf("</option>\n");
170 DeleteHashPos(&it);
171 DeleteHash(&List);
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");
197 end_ajax_response();
203 void
204 InitModule_ADDRBOOK_POPUP
205 (void)
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);