* move serv_info into the session, here we can control its de/allocation the right...
[citadel.git] / webcit / userlist.c
index 8fd97db3538772189e4f33c83c35cfe44b58d9e1..83d82e3cf10b1606367bd2c746949dac7ffe772a 100644 (file)
@@ -1,30 +1,15 @@
-#include <ctype.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <stdio.h>
-#include <fcntl.h>
-#include <signal.h>
-#include <sys/types.h>
-#include <sys/wait.h>
-#include <sys/socket.h>
-#include <sys/time.h>
-#include <limits.h>
-#include <netinet/in.h>
-#include <netdb.h>
-#include <string.h>
-#include <pwd.h>
-#include <errno.h>
-#include <stdarg.h>
-#include <pthread.h>
-#include <signal.h>
-#include "webcit.h"
-
-
+/*
+ * $Id$
+ */
 
+#include "webcit.h"
 
+/* 
+ * structure to keep namelists in
+ */
 struct namelist {
-       struct namelist *next;
-       char name[32];
+       struct namelist *next; /**< next item of the linked list */
+       char name[32];         /**< name of the userentry */
 };
 
 /*
@@ -32,51 +17,66 @@ struct namelist {
  */
 void userlist(void)
 {
-       char buf[SIZ];
-       char fl[SIZ];
-       struct tm *tmbuf;
-       long lc;
+       char buf[256];
+       char fl[256];
+       char title[256];
+       struct tm tmbuf;
+       time_t lc;
        struct namelist *bio = NULL;
        struct namelist *bptr;
        int has_bio;
+       int bg = 0;
 
        serv_puts("LBIO");
-       serv_gets(buf);
+       serv_getln(buf, sizeof buf);
        if (buf[0] == '1')
-               while (serv_gets(buf), strcmp(buf, "000")) {
+               while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
                        bptr = (struct namelist *) malloc(sizeof(struct namelist));
                        bptr->next = bio;
                        strcpy(bptr->name, buf);
                        bio = bptr;
                }
-       output_headers(1);
+       output_headers(1, 1, 2, 0, 0, 0);
+       wprintf("<div id=\"banner\">\n");
+       wprintf("<h1>");
+       snprintf(title, sizeof title, _("User list for %s"), ChrPtr(WC->serv_info->serv_humannode));
+       escputs(title);
+       wprintf("</h1>");
+        wprintf("</div>");
+
+        wprintf("<div id=\"content\" class=\"service\">\n");
 
        serv_puts("LIST");
-       serv_gets(buf);
+       serv_getln(buf, sizeof buf);
        if (buf[0] != '1') {
-               wprintf("<EM>%s</EM><BR>\n", &buf[4]);
+               wprintf("<em>%s</em><br />\n", &buf[4]);
                goto DONE;
        }
-       wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=007700><TR><TD>");
-       wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
-       wprintf("<B>User list for ");
-       escputs(serv_info.serv_humannode);
-       wprintf("</B></FONT></TD></TR></TABLE>\n");
-
-       wprintf("<CENTER><TABLE border>");
-       wprintf("<TR><TH>User Name</TH><TH>Number</TH><TH>Access Level</TH>");
-       wprintf("<TH>Last Call</TH><TH>Total Calls</TH><TH>Total Posts</TH></TR>\n");
-
-       while (serv_gets(buf), strcmp(buf, "000")) {
-               extract(fl, buf, 0);
+
+       wprintf("<div class=\"fix_scrollbar_bug\">"
+               "<table class=\"userlist_background\"><tr><td>\n");
+       wprintf("<tr><th>%s</th><th>%s</th><th>%s</th>"
+                       "<th>%s</th><th>%s</th><th>%s</th></tr>",
+                       _("User Name"),
+                       _("Number"),
+                       _("Access Level"),
+                       _("Last Login"),
+                       _("Total Logins"),
+                       _("Total Posts"));
+
+       while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
+               extract_token(fl, buf, 0, '|', sizeof fl);
                has_bio = 0;
                for (bptr = bio; bptr != NULL; bptr = bptr->next) {
                        if (!strcasecmp(fl, bptr->name))
                                has_bio = 1;
                }
-               wprintf("<TR><TD>");
+               bg = 1 - bg;
+               wprintf("<tr bgcolor=\"#%s\"><td>",
+                       (bg ? "DDDDDD" : "FFFFFF")
+               );
                if (has_bio) {
-                       wprintf("<A HREF=\"/showuser&who=");
+                       wprintf("<a href=\"showuser&who=");
                        urlescputs(fl);
                        wprintf("\">");
                        escputs(fl);
@@ -84,23 +84,23 @@ void userlist(void)
                } else {
                        escputs(fl);
                }
-               wprintf("</TD><TD>%ld</TD><TD>%d</TD><TD>",
+               wprintf("</td><td>%ld</td><td>%d</td><td>",
                        extract_long(buf, 2),
                        extract_int(buf, 1));
                lc = extract_long(buf, 3);
-               tmbuf = (struct tm *) localtime(&lc);
+               localtime_r(&lc, &tmbuf);
                wprintf("%02d/%02d/%04d ",
-                       (tmbuf->tm_mon + 1),
-                       tmbuf->tm_mday,
-                       (tmbuf->tm_year + 1900));
+                       (tmbuf.tm_mon + 1),
+                       tmbuf.tm_mday,
+                       (tmbuf.tm_year + 1900));
 
 
-               wprintf("</TD><TD>%ld</TD><TD>%5ld</TD></TR>\n",
+               wprintf("</td><td>%ld</td><td>%5ld</td></tr>\n",
                        extract_long(buf, 4), extract_long(buf, 5));
 
        }
-       wprintf("</TABLE></CENTER>\n");
-      DONE:wDumpContent(1);
+       wprintf("</table></div>\n");
+DONE:  wDumpContent(1);
 }
 
 
@@ -109,46 +109,66 @@ void userlist(void)
  */
 void showuser(void)
 {
-       char who[SIZ];
-       char buf[SIZ];
+       char who[256];
+       char buf[256];
        int have_pic;
 
-       output_headers(1);
+       strcpy(who, bstr("who"));
+
+       output_headers(1, 1, 2, 0, 0, 0);
+       wprintf("<div id=\"banner\">\n");
+       wprintf("<img src=\"static/usermanag_48x.gif\">");
+        wprintf("<h1>");
+       wprintf(_("User profile"));
+        wprintf("</h1>");
+        wprintf("</div>");
 
+        wprintf("<div id=\"content\" class=\"service\">\n");
 
-       wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=007700><TR><TD>");
-       wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"<B>User profile");
-       wprintf("</B></FONT></TD></TR></TABLE>\n");
+       wprintf("<div class=\"fix_scrollbar_bug\">"
+               "<table class=\"userlist_background\"><tr><td>\n");
 
-       strcpy(who, bstr("who"));
        serv_printf("OIMG _userpic_|%s", who);
-       serv_gets(buf);
+       serv_getln(buf, sizeof buf);
        if (buf[0] == '2') {
                have_pic = 1;
                serv_puts("CLOS");
-               serv_gets(buf);
+               serv_getln(buf, sizeof buf);
        } else {
                have_pic = 0;
        }
 
-       wprintf("<CENTER><TABLE><TR><TD>");
+       wprintf("<center><table><tr><td>");
        if (have_pic == 1) {
-               wprintf("<IMG SRC=\"/image&name=_userpic_&parm=");
+               wprintf("<img src=\"image&name=_userpic_&parm=");
                urlescputs(who);
                wprintf("\">");
        }
-       wprintf("</TD><TD><H1>%s</H1></TD></TR></TABLE></CENTER>\n", who);
+       wprintf("</td><td><h1>");
+       escputs(who);
+       wprintf("</h1></td></tr></table></center>\n");
        serv_printf("RBIO %s", who);
-       serv_gets(buf);
+       serv_getln(buf, sizeof buf);
        if (buf[0] == '1') {
-               fmout(NULL);
+               fmout("JUSTIFY");
        }
-       wprintf("<BR><A HREF=\"/display_page&recp=");
+       wprintf("<br /><a href=\"display_page?recp=");
        urlescputs(who);
        wprintf("\">"
-               "<IMG SRC=\"/static/page.gif\" ALIGN=MIDDLE BORDER=0>"
-               "&nbsp;&nbsp;"
-               "Click here to page this user (send an instant message)"
-               "</A>\n");
+               "<img src=\"static/citadelchat_24x.gif\" "
+               "align=middle border=0>&nbsp;&nbsp;");
+       snprintf(buf, sizeof buf, _("Click here to send an instant message to %s"), who);
+       escputs(buf);
+       wprintf("</a>\n");
+
+       wprintf("</td></tr></table></div>\n");
        wDumpContent(1);
 }
+
+void 
+InitModule_USERLIST
+(void)
+{
+       WebcitAddUrlHandler(HKEY("userlist"), userlist, 0);
+       WebcitAddUrlHandler(HKEY("showuser"), showuser, 0);
+}