Remove $Id$ tags from most of webcit
[citadel.git] / webcit / userlist.c
1
2 #include "webcit.h"
3
4 /* 
5  * structure to keep namelists in
6  */
7 struct namelist {
8         struct namelist *next; /**< next item of the linked list */
9         char name[32];         /**< name of the userentry */
10 };
11
12 /*
13  * display the userlist
14  */
15 void userlist(void)
16 {
17         char buf[256];
18         char fl[256];
19         char title[256];
20         struct tm tmbuf;
21         time_t lc;
22         struct namelist *bio = NULL;
23         struct namelist *bptr;
24         int has_bio;
25         int bg = 0;
26
27         serv_puts("LBIO");
28         serv_getln(buf, sizeof buf);
29         if (buf[0] == '1')
30                 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
31                         bptr = (struct namelist *) malloc(sizeof(struct namelist));
32                         bptr->next = bio;
33                         strcpy(bptr->name, buf);
34                         bio = bptr;
35                 }
36         output_headers(1, 1, 2, 0, 0, 0);
37         wc_printf("<div id=\"banner\">\n");
38         wc_printf("<h1>");
39         snprintf(title, sizeof title, _("User list for %s"), ChrPtr(WC->serv_info->serv_humannode));
40         escputs(title);
41         wc_printf("</h1>");
42         wc_printf("</div>");
43
44         wc_printf("<div id=\"content\" class=\"service\">\n");
45
46         serv_puts("LIST");
47         serv_getln(buf, sizeof buf);
48         if (buf[0] != '1') {
49                 wc_printf("<em>%s</em><br />\n", &buf[4]);
50                 goto DONE;
51         }
52
53         wc_printf("<div class=\"fix_scrollbar_bug\">"
54                 "<table class=\"userlist_background\"><tr><td>\n");
55         wc_printf("<tr><th>%s</th><th>%s</th><th>%s</th>"
56                         "<th>%s</th><th>%s</th><th>%s</th></tr>",
57                         _("User Name"),
58                         _("Number"),
59                         _("Access Level"),
60                         _("Last Login"),
61                         _("Total Logins"),
62                         _("Total Posts"));
63
64         while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
65                 extract_token(fl, buf, 0, '|', sizeof fl);
66                 has_bio = 0;
67                 for (bptr = bio; bptr != NULL; bptr = bptr->next) {
68                         if (!strcasecmp(fl, bptr->name))
69                                 has_bio = 1;
70                 }
71                 bg = 1 - bg;
72                 wc_printf("<tr bgcolor=\"#%s\"><td>",
73                         (bg ? "DDDDDD" : "FFFFFF")
74                 );
75                 if (has_bio) {
76                         wc_printf("<a href=\"showuser?who=");
77                         urlescputs(fl);
78                         wc_printf("\">");
79                         escputs(fl);
80                         wc_printf("</A>");
81                 } else {
82                         escputs(fl);
83                 }
84                 wc_printf("</td><td>%ld</td><td>%d</td><td>",
85                         extract_long(buf, 2),
86                         extract_int(buf, 1));
87                 lc = extract_long(buf, 3);
88                 localtime_r(&lc, &tmbuf);
89                 wc_printf("%02d/%02d/%04d ",
90                         (tmbuf.tm_mon + 1),
91                         tmbuf.tm_mday,
92                         (tmbuf.tm_year + 1900));
93
94
95                 wc_printf("</td><td>%ld</td><td>%5ld</td></tr>\n",
96                         extract_long(buf, 4), extract_long(buf, 5));
97
98         }
99         wc_printf("</table></div>\n");
100 DONE:   wDumpContent(1);
101 }
102
103
104 /*
105  * Display (non confidential) information about a particular user
106  */
107 void showuser(void)
108 {
109         char who[256];
110         char buf[256];
111         int have_pic;
112
113         strcpy(who, bstr("who"));
114
115         output_headers(1, 1, 2, 0, 0, 0);
116         wc_printf("<div id=\"banner\">\n");
117         wc_printf("<img src=\"static/usermanag_48x.gif\">");
118         wc_printf("<h1>");
119         wc_printf(_("User profile"));
120         wc_printf("</h1>");
121         wc_printf("</div>");
122
123         wc_printf("<div id=\"content\" class=\"service\">\n");
124
125         wc_printf("<div class=\"fix_scrollbar_bug\">"
126                 "<table class=\"userlist_background\"><tr><td>\n");
127
128         serv_printf("OIMG _userpic_|%s", who);
129         serv_getln(buf, sizeof buf);
130         if (buf[0] == '2') {
131                 have_pic = 1;
132                 serv_puts("CLOS");
133                 serv_getln(buf, sizeof buf);
134         } else {
135                 have_pic = 0;
136         }
137
138         wc_printf("<center><table><tr><td>");
139         if (have_pic == 1) {
140                 wc_printf("<img src=\"image?name=_userpic_&parm=");
141                 urlescputs(who);
142                 wc_printf("\">");
143         }
144         wc_printf("</td><td><h1>");
145         escputs(who);
146         wc_printf("</h1></td></tr></table></center>\n");
147         serv_printf("RBIO %s", who);
148         serv_getln(buf, sizeof buf);
149         if (buf[0] == '1') {
150                 fmout("JUSTIFY");
151         }
152         wc_printf("<br /><a href=\"display_page?recp=");
153         urlescputs(who);
154         wc_printf("\">"
155                 "<img src=\"static/citadelchat_24x.gif\" "
156                 "align=middle border=0>&nbsp;&nbsp;");
157         snprintf(buf, sizeof buf, _("Click here to send an instant message to %s"), who);
158         escputs(buf);
159         wc_printf("</a>\n");
160
161         wc_printf("</td></tr></table></div>\n");
162         wDumpContent(1);
163 }
164
165 void 
166 InitModule_USERLIST
167 (void)
168 {
169         WebcitAddUrlHandler(HKEY("userlist"), "", 0, userlist, 0);
170         WebcitAddUrlHandler(HKEY("showuser"), "", 0, showuser, 0);
171 }