When populating the address book popup with the contents of
[citadel.git] / webcit / addressbook_popup.c
1 /*
2  * $Id$
3  *
4  * \defgroup AjaxAutoCompletion ajax-powered autocompletion...
5  * \ingroup ClientPower
6  */
7
8 /*@{*/
9 #include "webcit.h"
10
11
12 /**
13  * \brief Call this right before wDumpContent() on any page which requires the address book popup
14  */
15 void address_book_popup(void) {
16         /* Open a new div, hidden initially, for address book popups. */
17         wprintf("</div>\n");    /* End of 'content' div */
18         wprintf("<div id=\"address_book_popup\" style=\"display:none;\">");
19         wprintf("<div id=\"address_book_popup_container_div\">");
20         wprintf("<div id=\"address_book_popup_middle_div\"></div>");
21         wprintf("<div id=\"address_book_inner_div\"></div>");
22         wprintf("</div>");
23         /* The 'address_book_popup' div will be closed by wDumpContent() */
24 }
25
26 /**
27  * \brief Address book popup window
28  */
29 void display_address_book_middle_div(void) {
30         char buf[256];
31         char ebuf[256];
32
33         begin_ajax_response();
34
35         wprintf("<table border=0 width=100%%><tr valign=middle>");
36         wprintf("<td align=left><img src=\"static/viewcontacts_32x.gif\"></td>");
37         wprintf("<td align=center>");
38
39         wprintf("<form>"
40                 "<select class=\"address_book_popup_title\" size=1 id=\"which_addr_book\" "
41                 " onChange=\"PopulateAddressBookInnerDiv($('which_addr_book').value,'%s')\">",
42                 bstr("target_input")
43         );
44
45         wprintf("<option value=\"__LOCAL_USERS__\">");
46         escputs(serv_info.serv_humannode);
47         wprintf("</option>\n");
48
49         serv_puts("LKRA");
50         serv_getln(buf, sizeof buf);
51         if (buf[0] == '1') while(serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
52                 if (extract_int(buf, 6) == VIEW_ADDRESSBOOK) {
53                         extract_token(ebuf, buf, 0, '|', sizeof ebuf);
54                         wprintf("<option value=\"");
55                         urlescputs(ebuf);
56                         wprintf("\">");
57                         escputs(ebuf);
58                         wprintf("</option>\n");
59                 }
60         }
61         wprintf("</select></form>");
62
63         wprintf("</td>");
64         wprintf("<td align=right "
65                 "onclick=\"javascript:$('address_book_popup').style.display='none';\" "
66                 "><img src=\"static/closewindow.gif\">");
67         wprintf("</td></tr></table>");
68
69         wprintf("<script type=\"text/javascript\">"
70                 "PopulateAddressBookInnerDiv($('which_addr_book').value,'%s');"
71                 "</script>\n",
72                 bstr("target_input")
73         );
74
75         end_ajax_response();
76 }
77
78
79
80 /**
81  * \brief Address book popup results
82  */
83 void display_address_book_inner_div() {
84         char buf[256];
85         char username[256];
86         int num_targets = 0;
87         char target_id[64];
88         char target_label[64];
89         int i;
90         char saved_roomname[128];
91
92         begin_ajax_response();
93
94         wprintf("<div align=center><form onSubmit=\"return false;\">"
95                 "<select multiple name=\"whichaddr\" id=\"whichaddr\" size=\"15\">\n");
96
97         if (!strcasecmp(bstr("which_addr_book"), "__LOCAL_USERS__")) {
98                 serv_puts("LIST");
99                 serv_getln(buf, sizeof buf);
100                 if (buf[0] == '1') while(serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
101                         extract_token(username, buf, 0, '|', sizeof username);
102                         wprintf("<option value=\"");
103                         escputs(username);
104                         wprintf("\">");
105                         escputs(username);
106                         wprintf("</option>\n");
107                 }
108         }
109
110         else {
111                 safestrncpy(saved_roomname, WC->wc_roomname, sizeof saved_roomname);
112                 gotoroom(bstr("which_addr_book"));
113                 serv_puts("DVCA");
114                 serv_getln(buf, sizeof buf);
115                 if (buf[0] == '1') while(serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
116                         wprintf("<option value=\"");
117                         escputs(buf);
118                         wprintf("\">");
119                         escputs(buf);
120                         wprintf("</option>\n");
121                 }
122                 gotoroom(bstr(saved_roomname));
123         }
124
125         wprintf("</select>\n");
126
127         wprintf("%s: ", _("Add"));
128
129         num_targets = num_tokens(bstr("target_input"), '|');
130         for (i=0; i<num_targets; i+=2) {
131                 extract_token(target_id, bstr("target_input"), i, '|', sizeof target_id);
132                 extract_token(target_label, bstr("target_input"), i+1, '|', sizeof target_label);
133                 wprintf("<INPUT TYPE=\"submit\" NAME=\"select_button\" VALUE=\"%s\" ", target_label);
134                 wprintf("onClick=\"AddContactsToTarget($('%s'),$('whichaddr'));\">", target_id);
135         }
136
137         /* This 'close window' button works.  Omitting it because we already have a close button
138          * in the upper right corner, and this one takes up space.
139          *
140         wprintf("<INPUT TYPE=\"submit\" NAME=\"close_button\" VALUE=\"%s\" ", _("Close window"));
141         wprintf("onclick=\"javascript:$('address_book_popup').style.display='none';\">");
142          */
143
144         wprintf("</form></div>\n");
145
146         end_ajax_response();
147 }
148
149
150 /** @} */