2f605adccf23a0b7fe504de4ad2fd7666dd6a0a3
[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("<table class=\"userlist_background\"><tr><td>\n");
54         wc_printf("<tr><th>%s</th><th>%s</th><th>%s</th>"
55                         "<th>%s</th><th>%s</th><th>%s</th></tr>",
56                         _("User Name"),
57                         _("Number"),
58                         _("Access Level"),
59                         _("Last Login"),
60                         _("Total Logins"),
61                         _("Total Posts"));
62
63         while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
64                 extract_token(fl, buf, 0, '|', sizeof fl);
65                 has_bio = 0;
66                 for (bptr = bio; bptr != NULL; bptr = bptr->next) {
67                         if (!strcasecmp(fl, bptr->name))
68                                 has_bio = 1;
69                 }
70                 bg = 1 - bg;
71                 wc_printf("<tr bgcolor=\"#%s\"><td>",
72                         (bg ? "DDDDDD" : "FFFFFF")
73                 );
74                 if (has_bio) {
75                         wc_printf("<a href=\"showuser?who=");
76                         urlescputs(fl);
77                         wc_printf("\">");
78                         escputs(fl);
79                         wc_printf("</A>");
80                 } else {
81                         escputs(fl);
82                 }
83                 wc_printf("</td><td>%ld</td><td>%d</td><td>",
84                         extract_long(buf, 2),
85                         extract_int(buf, 1));
86                 lc = extract_long(buf, 3);
87                 localtime_r(&lc, &tmbuf);
88                 wc_printf("%02d/%02d/%04d ",
89                         (tmbuf.tm_mon + 1),
90                         tmbuf.tm_mday,
91                         (tmbuf.tm_year + 1900));
92
93
94                 wc_printf("</td><td>%ld</td><td>%5ld</td></tr>\n",
95                         extract_long(buf, 4), extract_long(buf, 5));
96
97         }
98         wc_printf("</table>\n");
99 DONE:   wDumpContent(1);
100 }
101
102
103 /*
104  * Display (non confidential) information about a particular user
105  */
106 void showuser(void)
107 {
108         char who[256];
109         char buf[256];
110         int have_pic;
111
112         strcpy(who, bstr("who"));
113
114         output_headers(1, 1, 2, 0, 0, 0);
115         wc_printf("<div id=\"banner\">\n");
116         wc_printf("<img src=\"static/usermanag_48x.gif\">");
117         wc_printf("<h1>");
118         wc_printf(_("User profile"));
119         wc_printf("</h1>");
120         wc_printf("</div>");
121
122         wc_printf("<div id=\"content\" class=\"service\">\n");
123
124         wc_printf("<table class=\"userlist_background\"><tr><td>\n");
125
126         serv_printf("OIMG _userpic_|%s", who);
127         serv_getln(buf, sizeof buf);
128         if (buf[0] == '2') {
129                 have_pic = 1;
130                 serv_puts("CLOS");
131                 serv_getln(buf, sizeof buf);
132         } else {
133                 have_pic = 0;
134         }
135
136         wc_printf("<center><table><tr><td>");
137         if (have_pic == 1) {
138                 wc_printf("<img src=\"image?name=_userpic_&parm=");
139                 urlescputs(who);
140                 wc_printf("\">");
141         }
142         wc_printf("</td><td><h1>");
143         escputs(who);
144         wc_printf("</h1></td></tr></table></center>\n");
145         serv_printf("RBIO %s", who);
146         serv_getln(buf, sizeof buf);
147         if (buf[0] == '1') {
148                 fmout("JUSTIFY");
149         }
150         wc_printf("<br /><a href=\"display_page?recp=");
151         urlescputs(who);
152         wc_printf("\">"
153                 "<img src=\"static/citadelchat_24x.gif\" "
154                 "align=middle border=0>&nbsp;&nbsp;");
155         snprintf(buf, sizeof buf, _("Click here to send an instant message to %s"), who);
156         escputs(buf);
157         wc_printf("</a>\n");
158
159         wc_printf("</td></tr></table>\n");
160         wDumpContent(1);
161 }
162
163 void 
164 InitModule_USERLIST
165 (void)
166 {
167         WebcitAddUrlHandler(HKEY("userlist"), "", 0, userlist, 0);
168         WebcitAddUrlHandler(HKEY("showuser"), "", 0, showuser, 0);
169 }