Set up an option in output_headers() to optionally print the most
[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);
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:   wprintf("</BODY></HTML>\n");
94         wDumpContent();
95         }
96
97
98 /*
99  * Display (non confidential) information about a particular user
100  */
101 void showuser(void) {
102         char who[256];
103         char buf[256];
104         int have_pic;
105
106         printf("HTTP/1.0 200 OK\n");
107         output_headers(1);
108
109
110         wprintf("<TABLE WIDTH=100% BORDER=0 BGCOLOR=007700><TR><TD>");
111         wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"<B>User profile");
112         wprintf("</B></FONT></TD></TR></TABLE>\n");
113
114         strcpy(who, bstr("who"));
115         serv_printf("OIMG _userpic_|%s", who);
116         serv_gets(buf);
117         if (buf[0]=='2') {
118                 have_pic = 1;
119                 serv_puts("CLOS");
120                 serv_gets(buf);
121                 }
122         else {
123                 have_pic = 0;
124                 }
125
126         wprintf("<CENTER><TABLE><TR><TD>");
127         if (have_pic == 1) {
128                 wprintf("<IMG SRC=\"/image&name=_userpic_&parm=");
129                 urlescputs(who);
130                 wprintf("\">");
131                 }
132         wprintf("</TD><TD><H1>%s</H1></TD></TR></TABLE></CENTER>\n",who);
133         serv_printf("RBIO %s",who);
134         serv_gets(buf);
135         if (buf[0]=='1') fmout(NULL);
136         wprintf("</BODY></HTML>\n");
137         wDumpContent();
138         }