Remove APPDIR support in database_cleanup.sh
[citadel] / webcit / addressbook_popup.c
1 /*
2  * AJAX-powered auto-completion
3  *
4  * Copyright (c) 1996-2012 by the citadel.org team
5  *
6  * This program is open source software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License, version 3.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  */
14
15 #include "webcit.h"
16
17
18 /*
19  * Address book popup results
20  */
21 HashList* GetAddressbookList()
22 {
23         HashList *List = NULL;
24         const StrBuf *WhichAddrBook;
25         StrBuf *saved_roomname;
26         StrBuf *Name;
27         StrBuf *Line;
28         long BufLen;
29         int IsLocalAddrBook;
30
31         WhichAddrBook = sbstr("which_addr_book");
32         IsLocalAddrBook = strcasecmp(ChrPtr(WhichAddrBook), "__LOCAL_USERS__") == 1;
33
34         if (IsLocalAddrBook) {
35                 serv_puts("LIST");
36         }
37         else {
38                 /* remember the default addressbook for this room */
39                 set_room_pref("defaddrbook", NewStrBufDup(WhichAddrBook), 0);
40                 saved_roomname = NewStrBufDup(WC->CurRoom.name);
41                 gotoroom(WhichAddrBook);
42                 serv_puts("DVCA");
43         }
44         
45         Line = NewStrBuf();
46         StrBuf_ServGetln(Line);
47         if (GetServerStatus(Line, NULL)  == 1) {
48                 List = NewHash(1, NULL);
49                 while (BufLen = StrBuf_ServGetln(Line), 
50                        ((BufLen >= 0) && 
51                         ((BufLen != 3) || strcmp(ChrPtr(Line), "000"))))
52                 {
53                         if (IsLocalAddrBook &&
54                             (BufLen > 5) &&
55                             (strncmp(ChrPtr(Line), "SYS_", 4) == 0))
56                         {
57                                 continue;
58                         }
59                         Name = NewStrBufPlain(NULL, StrLength(Line));
60                         StrBufExtract_token(Name, Line, 0, '|');
61                         Put(List, SKEY(Name), Name, HFreeStrBuf);
62
63                 }
64                 SortByHashKey(List, 1);
65         }
66
67         if (!IsLocalAddrBook) {
68                 gotoroom(saved_roomname);
69                 FreeStrBuf(&saved_roomname);
70         }
71
72         return List;
73 }
74
75
76
77
78 void 
79 InitModule_ADDRBOOK_POPUP
80 (void)
81 {
82
83         RegisterIterator("ITERATE:ABNAMES", 0, NULL, GetAddressbookList, NULL, NULL, CTX_STRBUF, CTX_NONE, IT_NOFLAG);
84 }