* wDumpContent() is now responsible for </BODY></HTML> most of the
[citadel.git] / webcit / userlist.c
1 #include <stdlib.h>
2 #include <unistd.h>
3 #include <stdio.h>
4 #include <signal.h>
5 #include <sys/types.h>
6 #include <ctype.h>
7 #include <string.h>
8 #include <time.h>
9 #include "webcit.h"
10 #include "child.h"
11
12 struct namelist {
13         struct namelist *next;
14         char name[32];
15         };
16
17 /*
18  * display the userlist
19  */
20 void userlist(void) { 
21         char buf[256];
22         char fl[256];
23         struct tm *tmbuf;
24         long lc;
25         struct namelist *bio = NULL;
26         struct namelist *bptr;
27         int has_bio;
28
29         serv_puts("LBIO");
30         serv_gets(buf);
31         if (buf[0]=='1') while (serv_gets(buf), strcmp(buf,"000")) {
32                 bptr = (struct namelist *) malloc(sizeof(struct namelist));
33                 bptr->next = bio;
34                 strcpy(bptr->name, buf);
35                 bio = bptr;
36                 }
37
38
39         printf("HTTP/1.0 200 OK\n");
40         output_headers(1, "bottom");
41
42         serv_puts("LIST");
43         serv_gets(buf);
44         if (buf[0]!='1') {
45                 wprintf("<EM>%s</EM><BR>\n",&buf[4]);
46                 goto DONE;
47                 }
48
49
50         wprintf("<TABLE WIDTH=100% BORDER=0 BGCOLOR=007700><TR><TD>");
51         wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
52         wprintf("<B>User list for ");
53         escputs(serv_info.serv_humannode);
54         wprintf("</B></FONT></TD></TR></TABLE>\n");
55
56         wprintf("<CENTER><TABLE border>");
57         wprintf("<TR><TH>User Name</TH><TH>Number</TH><TH>Access Level</TH>");
58         wprintf("<TH>Last Call</TH><TH>Total Calls</TH><TH>Total Posts</TH></TR>\n");
59
60         while (serv_gets(buf), strcmp(buf,"000")) {
61                 extract(fl,buf,0);
62                 has_bio = 0;
63                 for (bptr=bio; bptr!=NULL; bptr=bptr->next) {
64                         if (!strcasecmp(fl,bptr->name)) has_bio = 1;
65                         }
66                 wprintf("<TR><TD>");
67                 if (has_bio) {
68                         wprintf("<A HREF=\"/showuser&who=");
69                         urlescputs(fl);
70                         wprintf("\">");
71                         escputs(fl);
72                         wprintf("</A>");
73                         }
74                 else {
75                         escputs(fl);
76                         }
77                 wprintf("</TD><TD>%ld</TD><TD>%d</TD><TD>",
78                         extract_long(buf,2),
79                         extract_int(buf,1));
80                 lc = extract_long(buf,3);
81                 tmbuf = (struct tm *)localtime(&lc);
82                 wprintf("%02d/%02d/%04d ",
83                         (tmbuf->tm_mon+1),
84                         tmbuf->tm_mday,
85                         (tmbuf->tm_year + 1900));
86                 
87
88                 wprintf("</TD><TD>%ld</TD><TD>%5ld</TD></TR>\n",
89                         extract_long(buf,4),extract_long(buf,5));
90
91                 }
92         wprintf("</TABLE></CENTER>\n");
93 DONE:   wDumpContent(1);
94         }
95
96
97 /*
98  * Display (non confidential) information about a particular user
99  */
100 void showuser(void) {
101         char who[256];
102         char buf[256];
103         int have_pic;
104
105         printf("HTTP/1.0 200 OK\n");
106         output_headers(1, "bottom");
107
108
109         wprintf("<TABLE WIDTH=100% BORDER=0 BGCOLOR=007700><TR><TD>");
110         wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"<B>User profile");
111         wprintf("</B></FONT></TD></TR></TABLE>\n");
112
113         strcpy(who, bstr("who"));
114         serv_printf("OIMG _userpic_|%s", who);
115         serv_gets(buf);
116         if (buf[0]=='2') {
117                 have_pic = 1;
118                 serv_puts("CLOS");
119                 serv_gets(buf);
120                 }
121         else {
122                 have_pic = 0;
123                 }
124
125         wprintf("<CENTER><TABLE><TR><TD>");
126         if (have_pic == 1) {
127                 wprintf("<IMG SRC=\"/image&name=_userpic_&parm=");
128                 urlescputs(who);
129                 wprintf("\">");
130                 }
131         wprintf("</TD><TD><H1>%s</H1></TD></TR></TABLE></CENTER>\n",who);
132         serv_printf("RBIO %s",who);
133         serv_gets(buf);
134         if (buf[0]=='1') fmout(NULL);
135         wDumpContent(1);
136         }