A single address book popup now supports multiple
[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
91         begin_ajax_response();
92
93         wprintf("<div align=center><form onSubmit=\"return false;\">"
94                 "<select multiple name=\"whichaddr\" id=\"whichaddr\" size=\"15\">\n");
95
96         if (!strcasecmp(bstr("which_addr_book"), "__LOCAL_USERS__")) {
97                 serv_puts("LIST");
98                 serv_getln(buf, sizeof buf);
99                 if (buf[0] == '1') while(serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
100                         extract_token(username, buf, 0, '|', sizeof username);
101                         wprintf("<option value=\"");
102                         escputs(username);
103                         wprintf("\">");
104                         escputs(username);
105                         wprintf("</option>\n");
106                 }
107         }
108
109         else {
110                 serv_printf("GOTO %s", bstr("which_addr_book"));
111                 serv_getln(buf, sizeof buf);
112                 serv_puts("DVCA");
113                 serv_getln(buf, sizeof buf);
114                 if (buf[0] == '1') while(serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
115                         wprintf("<option value=\"");
116                         escputs(buf);
117                         wprintf("\">");
118                         escputs(buf);
119                         wprintf("</option>\n");
120                 }
121         }
122
123         wprintf("</select>\n");
124
125         wprintf("%s: ", _("Add"));
126
127         num_targets = num_tokens(bstr("target_input"), '|');
128         for (i=0; i<num_targets; i+=2) {
129                 extract_token(target_id, bstr("target_input"), i, '|', sizeof target_id);
130                 extract_token(target_label, bstr("target_input"), i+1, '|', sizeof target_label);
131                 wprintf("<INPUT TYPE=\"submit\" NAME=\"select_button\" VALUE=\"%s\" ", target_label);
132                 wprintf("onClick=\"AddContactsToTarget($('%s'),$('whichaddr'));\">", target_id);
133         }
134
135         /* This 'close window' button works.  Omitting it because we already have a close button
136          * in the upper right corner, and this one takes up space.
137          *
138         wprintf("<INPUT TYPE=\"submit\" NAME=\"close_button\" VALUE=\"%s\" ", _("Close window"));
139         wprintf("onclick=\"javascript:$('address_book_popup').style.display='none';\">");
140          */
141
142         wprintf("</form></div>\n");
143
144         end_ajax_response();
145 }
146
147
148 /** @} */