webcit_before_automake is now the trunk
[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                 "<table width=100%% border=0 bgcolor=\"#444455\"><tr><td>"
47                 "<span class=\"titlebar\">");
48         snprintf(title, sizeof title, _("User list for %s"), serv_info.serv_humannode);
49         escputs(title);
50         wprintf("</span>"
51                 "</td></tr></table>\n"
52                 "</div>\n<div id=\"content\">\n"
53         );
54
55         serv_puts("LIST");
56         serv_getln(buf, sizeof buf);
57         if (buf[0] != '1') {
58                 wprintf("<em>%s</em><br />\n", &buf[4]);
59                 goto DONE;
60         }
61
62         wprintf("<div class=\"fix_scrollbar_bug\">"
63                 "<table border=0 width=100%% bgcolor=\"#ffffff\"><tr><td>\n");
64         wprintf("<tr><th>%s</th><th>%s</th><th>%s</th>"
65                         "<th>%s</th><th>%s</th><th>%s</th></tr>",
66                         _("User Name"),
67                         _("Number"),
68                         _("Access Level"),
69                         _("Last Login"),
70                         _("Total Logins"),
71                         _("Total Posts"));
72
73         while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
74                 extract_token(fl, buf, 0, '|', sizeof fl);
75                 has_bio = 0;
76                 for (bptr = bio; bptr != NULL; bptr = bptr->next) {
77                         if (!strcasecmp(fl, bptr->name))
78                                 has_bio = 1;
79                 }
80                 bg = 1 - bg;
81                 wprintf("<tr bgcolor=\"#%s\"><td>",
82                         (bg ? "DDDDDD" : "FFFFFF")
83                 );
84                 if (has_bio) {
85                         wprintf("<a href=\"showuser&who=");
86                         urlescputs(fl);
87                         wprintf("\">");
88                         escputs(fl);
89                         wprintf("</A>");
90                 } else {
91                         escputs(fl);
92                 }
93                 wprintf("</td><td>%ld</td><td>%d</td><td>",
94                         extract_long(buf, 2),
95                         extract_int(buf, 1));
96                 lc = extract_long(buf, 3);
97                 localtime_r(&lc, &tmbuf);
98                 wprintf("%02d/%02d/%04d ",
99                         (tmbuf.tm_mon + 1),
100                         tmbuf.tm_mday,
101                         (tmbuf.tm_year + 1900));
102
103
104                 wprintf("</td><td>%ld</td><td>%5ld</td></tr>\n",
105                         extract_long(buf, 4), extract_long(buf, 5));
106
107         }
108         wprintf("</table></div>\n");
109 DONE:   wDumpContent(1);
110 }
111
112
113 /**
114  * \brief Display (non confidential) information about a particular user
115  */
116 void showuser(void)
117 {
118         char who[256];
119         char buf[256];
120         int have_pic;
121
122         strcpy(who, bstr("who"));
123
124         output_headers(1, 1, 2, 0, 0, 0);
125         wprintf("<div id=\"banner\">\n"
126                 "<table width=100%% border=0 bgcolor=\"#444455\"><tr>"
127                 "<td><img src=\"static/usermanag_48x.gif\"></td>"
128                 "<td align=left><span class=\"titlebar\">");
129         wprintf(_("User profile"));
130         wprintf("</span>"
131                 "</td></tr></table>\n"
132                 "</div>\n<div id=\"content\">\n"
133         );
134
135         wprintf("<div class=\"fix_scrollbar_bug\">"
136                 "<table border=0 width=100%% bgcolor=\"#ffffff\"><tr><td>\n");
137
138         serv_printf("OIMG _userpic_|%s", who);
139         serv_getln(buf, sizeof buf);
140         if (buf[0] == '2') {
141                 have_pic = 1;
142                 serv_puts("CLOS");
143                 serv_getln(buf, sizeof buf);
144         } else {
145                 have_pic = 0;
146         }
147
148         wprintf("<center><table><tr><td>");
149         if (have_pic == 1) {
150                 wprintf("<img src=\"image&name=_userpic_&parm=");
151                 urlescputs(who);
152                 wprintf("\">");
153         }
154         wprintf("</td><td><h1>%s</h1></td></tr></table></center>\n", who);
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 /*@}*/