Back to index

webcit  8.12-dfsg
addressbook_popup.c
Go to the documentation of this file.
00001 /*
00002  * AJAX-powered auto-completion
00003  *
00004  * Copyright (c) 1996-2012 by the citadel.org team
00005  *
00006  * This program is open source software: you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License, version 3.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  */
00014 
00015 #include "webcit.h"
00016 
00017 
00018 /*
00019  * Call this right before wDumpContent() on any page which requires the address book popup
00020  */
00021 void address_book_popup(void) {
00022        /* Open a new div, hidden initially, for address book popups. */
00023        wc_printf("</div>\n");      /* End of 'content' div */
00024        wc_printf("<div id=\"address_book_popup\" style=\"display:none;\">");
00025        wc_printf("<div id=\"address_book_popup_container_div\">");
00026        wc_printf("<div id=\"address_book_popup_middle_div\"></div>");
00027        wc_printf("<div id=\"address_book_inner_div\"></div>");
00028        wc_printf("</div>");
00029        /* The 'address_book_popup' div will be closed by wDumpContent() */
00030 }
00031 
00032 /*
00033  * Address book popup window
00034  */
00035 void display_address_book_middle_div(void) {
00036        char buf[256];
00037        long len;
00038        char *Name;
00039        const char *VCName;
00040        void *Namee;
00041        StrBuf *DefAddrBook;
00042        HashList *List;
00043        HashPos  *it;
00044 
00045        begin_ajax_response();
00046 
00047        DefAddrBook = get_room_pref("defaddrbook");
00048 
00049        wc_printf("<table border=0 width=100%%><tr valign=middle>");
00050        wc_printf("<td align=left><img src=\"static/webcit_icons/essen/32x32/contact.png\"></td>");
00051        wc_printf("<td align=center>");
00052 
00053        wc_printf("<form>"
00054               "<select class=\"address_book_popup_title\" size=1 id=\"which_addr_book\" "
00055               " onChange=\"PopulateAddressBookInnerDiv($('which_addr_book').value,'%s')\">",
00056               bstr("target_input")
00057        );
00058 
00059        wc_printf("<option value=\"__LOCAL_USERS__\" %s>", 
00060               (strcmp(ChrPtr(DefAddrBook), "__LOCAL_USERS__") == 0)?
00061               "selected=\"selected\" ":"");
00062        escputs(ChrPtr(WC->serv_info->serv_humannode));
00063        wc_printf("</option>\n");
00064 
00065        
00066        List = NewHash(1, NULL);
00067        serv_puts("LKRA");
00068        serv_getln(buf, sizeof buf);
00069        if (buf[0] == '1') while(len = serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
00070               if (extract_int(buf, 6) == VIEW_ADDRESSBOOK) {
00071                      Name = (char*) malloc(len + 1);
00072                      len = extract_token(Name, buf, 0, '|', len);
00073                      Put(List, Name, len, Name, NULL);
00074               }
00075        }
00076 
00077        SortByHashKey(List, 1);
00078        it = GetNewHashPos(List, 0);
00079        while (GetNextHashPos(List, it, &len, &VCName, &Namee)) {
00080               wc_printf("<option value=\"");
00081               urlescputs((char*)Namee);
00082               if (strcmp(ChrPtr(DefAddrBook), Namee) == 0)
00083                      wc_printf("\" selected=\"selected\" >");
00084               else
00085                      wc_printf("\">");
00086               escputs((char*)Namee);
00087               wc_printf("</option>\n");
00088        }
00089        DeleteHashPos(&it);
00090        DeleteHash(&List);
00091        wc_printf("</select></form>");
00092 
00093        wc_printf("</td>");
00094        wc_printf("<td align=right "
00095               "onclick=\"javascript:$('address_book_popup').style.display='none';\" "
00096               "><img src=\"static/webcit_icons/closewindow.gif\">");
00097        wc_printf("</td></tr></table>");
00098 
00099        wc_printf("<script type=\"text/javascript\">PopulateAddressBookInnerDiv($('which_addr_book').value,'%s');</script>",
00100               bstr("target_input")
00101        );
00102 
00103        end_ajax_response();
00104 }
00105 
00106 
00107 
00108 /*
00109  * Address book popup results
00110  */
00111 void display_address_book_inner_div() {
00112        char buf[256];
00113        int num_targets = 0;
00114        char target_id[64];
00115        char target_label[64];
00116        long len;
00117        char *Name;
00118        const char *VCName;
00119        void *Namee;
00120        HashList *List;
00121        HashPos  *it;
00122        int i;
00123        StrBuf *saved_roomname;
00124 
00125        begin_ajax_response();
00126 
00127        List = NewHash(1, NULL);
00128        wc_printf("<div align=center><form onSubmit=\"return false;\">"
00129               "<select multiple name=\"whichaddr\" id=\"whichaddr\" size=\"15\">\n");
00130 
00131        if (!strcasecmp(bstr("which_addr_book"), "__LOCAL_USERS__")) {
00132               serv_puts("LIST");
00133               serv_getln(buf, sizeof buf);
00134               if (buf[0] == '1') while(len = serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
00135                      Name = (char*) malloc(len + 1);
00136                      len = extract_token(Name, buf, 0, '|', len + 1);
00137                      if((len > 5) && (strncmp(Name, "SYS_", 4) == 0)) {
00138                             free(Name);
00139                             continue;
00140                      }
00141                      Put(List, Name, len, Name, NULL);
00142 
00143               }
00144               SortByHashKey(List, 1);
00145               it = GetNewHashPos(List, 0);
00146               while (GetNextHashPos(List, it, &len, &VCName, &Namee)) {
00147                      wc_printf("<option value=\"");
00148                      escputs((char*)Namee);
00149                      wc_printf("\">");
00150                      escputs((char*)Namee);
00151                      wc_printf("</option>\n");
00152               }
00153               DeleteHashPos(&it);
00154               DeleteHash(&List);
00155        }
00156 
00157        else {
00158               set_room_pref("defaddrbook",NewStrBufDup(sbstr("which_addr_book")), 0);
00159               saved_roomname = NewStrBufDup(WC->CurRoom.name);
00160               gotoroom(sbstr("which_addr_book"));
00161               serv_puts("DVCA");
00162               serv_getln(buf, sizeof buf);
00163               if (buf[0] == '1') while(len = serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
00164                      Name = (char*) malloc(len + 1);
00165                      len = extract_token(Name, buf, 0, '|', len + 1);
00166                      Put(List, Name, len, Name, NULL);
00167 
00168               }
00169               SortByHashKey(List, 1);
00170               it = GetNewHashPos(List, 0);
00171               while (GetNextHashPos(List, it, &len, &VCName, (void**)&Namee)) {
00172                      wc_printf("<option value=\"");
00173                      escputs((char*)Namee);
00174                      wc_printf("\">");
00175                      escputs((char*)Namee);
00176                      wc_printf("</option>\n");
00177               }
00178               DeleteHashPos(&it);
00179               DeleteHash(&List);
00180               gotoroom(saved_roomname);
00181               FreeStrBuf(&saved_roomname);
00182        }
00183 
00184        wc_printf("</select>\n");
00185 
00186        wc_printf("%s: ", _("Add"));
00187 
00188        num_targets = num_tokens(bstr("target_input"), '|');
00189        for (i=0; i<num_targets; i+=2) {
00190               extract_token(target_id, bstr("target_input"), i, '|', sizeof target_id);
00191               extract_token(target_label, bstr("target_input"), i+1, '|', sizeof target_label);
00192               wc_printf("<INPUT TYPE=\"submit\" NAME=\"select_button\" VALUE=\"%s\" ", target_label);
00193               wc_printf("onClick=\"AddContactsToTarget($('%s'),$('whichaddr'));\">", target_id);
00194        }
00195 
00196        /* This 'close window' button works.  Omitting it because we already have a close button
00197         * in the upper right corner, and this one takes up space.
00198         *
00199        wc_printf("<INPUT TYPE=\"submit\" NAME=\"close_button\" VALUE=\"%s\" ", _("Close window"));
00200        wc_printf("onclick=\"javascript:$('address_book_popup').style.display='none';\">");
00201         */
00202 
00203        wc_printf("</form></div>\n");
00204 
00205        end_ajax_response();
00206 }
00207 
00208 
00209 
00210 
00211 void 
00212 InitModule_ADDRBOOK_POPUP
00213 (void)
00214 {
00215        WebcitAddUrlHandler(HKEY("display_address_book_middle_div"), "", 0, display_address_book_middle_div, 0);
00216        WebcitAddUrlHandler(HKEY("display_address_book_inner_div"), "", 0, display_address_book_inner_div, 0);
00217 }