/*
- * $Id$
+ * AJAX-powered auto-completion
*
- * \defgroup AjaxAutoCompletion ajax-powered autocompletion...
- * \ingroup ClientPower
+ * Copyright (c) 1996-2012 by the citadel.org team
+ *
+ * This program is open source software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 3.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
*/
-/*@{*/
#include "webcit.h"
-/**
- * \brief Call this right before wDumpContent() on any page which requires the address book popup
- */
-void address_book_popup(void) {
- /* Open a new div, hidden initially, for address book popups. */
- wprintf("</div>\n"); /* End of 'content' div */
- wprintf("<div id=\"address_book_popup\" style=\"display:none;\">");
- wprintf("<div id=\"address_book_popup_container_div\">");
- wprintf("<div id=\"address_book_popup_middle_div\"></div>");
- wprintf("<div id=\"address_book_inner_div\"></div>");
- wprintf("</div>");
- /* The 'address_book_popup' div will be closed by wDumpContent() */
-}
-
-/**
- * \brief Address book popup window
- */
-void display_address_book_middle_div(void) {
- char buf[256];
- char ebuf[256];
-
- begin_ajax_response();
-
- wprintf("<table border=0 width=100%%><tr valign=middle>");
- wprintf("<td align=left><img src=\"static/viewcontacts_32x.gif\"></td>");
- wprintf("<td align=center>");
-
- wprintf("<form>"
- "<select class=\"address_book_popup_title\" size=1 id=\"which_addr_book\" "
- " onChange=\"PopulateAddressBookInnerDiv($('which_addr_book').value,'%s')\">",
- bstr("target_input")
- );
-
- wprintf("<option value=\"__LOCAL_USERS__\">");
- escputs(serv_info.serv_humannode);
- wprintf("</option>\n");
-
- serv_puts("LKRA");
- serv_getln(buf, sizeof buf);
- if (buf[0] == '1') while(serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
- if (extract_int(buf, 6) == VIEW_ADDRESSBOOK) {
- extract_token(ebuf, buf, 0, '|', sizeof ebuf);
- wprintf("<option value=\"");
- urlescputs(ebuf);
- wprintf("\">");
- escputs(ebuf);
- wprintf("</option>\n");
- }
- }
- wprintf("</select></form>");
-
- wprintf("</td>");
- wprintf("<td align=right "
- "onclick=\"javascript:$('address_book_popup').style.display='none';\" "
- "><img src=\"static/closewindow.gif\">");
- wprintf("</td></tr></table>");
-
- wprintf("<script type=\"text/javascript\">"
- "PopulateAddressBookInnerDiv($('which_addr_book').value,'%s');"
- "</script>\n",
- bstr("target_input")
- );
-
- end_ajax_response();
-}
-
-
-
-/**
- * \brief Address book popup results
+/*
+ * Address book popup results
*/
-void display_address_book_inner_div() {
- char buf[256];
- char username[256];
- int num_targets = 0;
- char target_id[64];
- char target_label[64];
- int i;
- char saved_roomname[128];
-
- begin_ajax_response();
-
- wprintf("<div align=center><form onSubmit=\"return false;\">"
- "<select multiple name=\"whichaddr\" id=\"whichaddr\" size=\"15\">\n");
-
- if (!strcasecmp(bstr("which_addr_book"), "__LOCAL_USERS__")) {
+HashList* GetAddressbookList()
+{
+ HashList *List = NULL;
+ const StrBuf *WhichAddrBook;
+ StrBuf *saved_roomname;
+ StrBuf *Name;
+ StrBuf *Line;
+ long BufLen;
+ int IsLocalAddrBook;
+
+ WhichAddrBook = SBSTR("which_addr_book");
+ IsLocalAddrBook = strcasecmp(ChrPtr(WhichAddrBook), "__LOCAL_USERS__") == 1;
+
+ if (IsLocalAddrBook) {
serv_puts("LIST");
- serv_getln(buf, sizeof buf);
- if (buf[0] == '1') while(serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
- extract_token(username, buf, 0, '|', sizeof username);
- wprintf("<option value=\"");
- escputs(username);
- wprintf("\">");
- escputs(username);
- wprintf("</option>\n");
- }
}
-
else {
- safestrncpy(saved_roomname, WC->wc_roomname, sizeof saved_roomname);
- gotoroom(bstr("which_addr_book"));
+ /* remember the default addressbook for this room */
+ set_room_pref("defaddrbook", NewStrBufDup(WhichAddrBook), 0);
+ saved_roomname = NewStrBufDup(WC->CurRoom.name);
+ gotoroom(WhichAddrBook);
serv_puts("DVCA");
- serv_getln(buf, sizeof buf);
- if (buf[0] == '1') while(serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
- wprintf("<option value=\"");
- escputs(buf);
- wprintf("\">");
- escputs(buf);
- wprintf("</option>\n");
- }
- gotoroom(bstr(saved_roomname));
}
+
+ Line = NewStrBuf();
+ StrBuf_ServGetln(Line);
+ if (GetServerStatus(Line, NULL) == 1) {
+ List = NewHash(1, NULL);
+ while (BufLen = StrBuf_ServGetln(Line),
+ ((BufLen >= 0) &&
+ ((BufLen != 3) || strcmp(ChrPtr(Line), "000"))))
+ {
+ if (IsLocalAddrBook &&
+ (BufLen > 5) &&
+ (strncmp(ChrPtr(Line), "SYS_", 4) == 0))
+ {
+ continue;
+ }
+ Name = NewStrBufPlain(NULL, StrLength(Line));
+ StrBufExtract_token(Name, Line, 0, '|');
+ Put(List, SKEY(Name), Name, HFreeStrBuf);
- wprintf("</select>\n");
-
- wprintf("%s: ", _("Add"));
+ }
+ SortByHashKey(List, 1);
+ }
- num_targets = num_tokens(bstr("target_input"), '|');
- for (i=0; i<num_targets; i+=2) {
- extract_token(target_id, bstr("target_input"), i, '|', sizeof target_id);
- extract_token(target_label, bstr("target_input"), i+1, '|', sizeof target_label);
- wprintf("<INPUT TYPE=\"submit\" NAME=\"select_button\" VALUE=\"%s\" ", target_label);
- wprintf("onClick=\"AddContactsToTarget($('%s'),$('whichaddr'));\">", target_id);
+ if (!IsLocalAddrBook) {
+ gotoroom(saved_roomname);
+ FreeStrBuf(&saved_roomname);
}
- /* This 'close window' button works. Omitting it because we already have a close button
- * in the upper right corner, and this one takes up space.
- *
- wprintf("<INPUT TYPE=\"submit\" NAME=\"close_button\" VALUE=\"%s\" ", _("Close window"));
- wprintf("onclick=\"javascript:$('address_book_popup').style.display='none';\">");
- */
+ return List;
+}
- wprintf("</form></div>\n");
- end_ajax_response();
-}
-/** @} */
+void
+InitModule_ADDRBOOK_POPUP
+(void)
+{
+
+ RegisterIterator("ITERATE:ABNAMES", 0, NULL, GetAddressbookList, NULL, NULL, CTX_STRBUF, CTX_NONE, IT_NOFLAG);
+}