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