* we have now several bstrs:
[citadel.git] / webcit / downloads.c
index d29e7fc7ebd635f8658436332dd2ccaca2c7fbf8..a208e51b7dc317fb4248c7dbe94bcab4ca32344e 100644 (file)
@@ -2,33 +2,36 @@
  * $Id$
  */
 #include "webcit.h"
+#include "webserver.h"
 
 void display_room_directory(void)
 {
        char buf[1024];
        char filename[256];
        char filesize[256];
+       char mimetype[64];
        char comment[512];
        int bg = 0;
        char title[256];
+       int havepics = 0;
 
        output_headers(1, 1, 2, 0, 0, 0);
-       wprintf("<div id=\"banner\">\n"
-               "<table class=\"downloads_banner\"><tr><td>"
-               "<span class=\"titlebar\">");
+       wprintf("<div id=\"banner\">\n");
+       wprintf("<h1>");
        snprintf(title, sizeof title, _("Files available for download in %s"), WC->wc_roomname);
        escputs(title);
-       wprintf("</span>"
-               "</td></tr></table>\n"
-               "</div>\n<div id=\"content\">\n"
-       );
+       wprintf("</h1>");
+       wprintf("</div>\n");
+
+       wprintf("<div id=\"content\" class=\"service\">\n");
 
        wprintf("<div class=\"fix_scrollbar_bug\">"
                "<table class=\"downloads_background\"><tr><td>\n");
-       wprintf("<tr><th>%s</th><th>%s</th><th>%s</th></tr>\n",
-                       _("Filename"),
-                       _("Size"),
-                       _("Description")
+       wprintf("<tr><th>%s</th><th>%s</th><th>%s</th><th>%s</th></tr>\n",
+               _("Filename"),
+               _("Size"),
+               _("Content"),
+               _("Description")
        );
 
        serv_puts("RDIR");
@@ -37,19 +40,22 @@ void display_room_directory(void)
        {
                extract_token(filename, buf, 0, '|', sizeof filename);
                extract_token(filesize, buf, 1, '|', sizeof filesize);
-               extract_token(comment, buf, 2, '|', sizeof comment);
+               extract_token(mimetype, buf, 2, '|', sizeof mimetype);
+               extract_token(comment,  buf, 3, '|', sizeof comment);
                bg = 1 - bg;
                wprintf("<tr bgcolor=\"#%s\">", (bg ? "DDDDDD" : "FFFFFF"));
                wprintf("<td>"
                        "<a href=\"download_file/");
                urlescputs(filename);
-               wprintf("\"><img src=\"static/diskette_24x.gif\" border=0 align=middle>\n");
+               wprintf("\"><img src=\"display_mime_icon?type=%s\" border=0 align=middle>\n", mimetype);
                                        escputs(filename);      wprintf("</a></td>");
                wprintf("<td>");        escputs(filesize);      wprintf("</td>");
+               wprintf("<td>");        escputs(mimetype);      wprintf("</td>");
                wprintf("<td>");        escputs(comment);       wprintf("</td>");
                wprintf("</tr>\n");
+               if (!havepics && (strstr(mimetype, "image") != NULL))
+                       havepics = 1;
        }
-
        wprintf("</table>\n");
 
        /** Now offer the ability to upload files... */
@@ -76,9 +82,93 @@ void display_room_directory(void)
        }
 
        wprintf("</div>\n");
+       if (havepics)
+               wprintf("<div class=\"buttons\"><a href=\"display_pictureview&frame=1\">%s</a></div>", _("Slideshow"));
+       wDumpContent(1);
+}
+
+
+void display_pictureview(void)
+{
+       char buf[1024];
+       char filename[256];
+       char filesize[256];
+       char mimetype[64];
+       char comment[512];
+       char title[256];
+       int n = 0;
+               
+
+       if (lbstr("frame") == 1) {
+
+               output_headers(1, 1, 2, 0, 0, 0);
+               wprintf("<div id=\"banner\">\n");
+               wprintf("<h1>");
+               snprintf(title, sizeof title, _("Pictures in %s"), WC->wc_roomname);
+               escputs(title);
+               wprintf("</h1>");
+               wprintf("</div>\n");
+               
+               wprintf("<div id=\"content\" class=\"service\">\n");
+
+               wprintf("<div class=\"fix_scrollbar_bug\">"
+                       "<table class=\"downloads_background\"><tr><td>\n");
+
+
+
+               wprintf("<script type=\"text/javascript\" language=\"JavaScript\" > \nvar fadeimages=new Array()\n");
+
+               serv_puts("RDIR");
+               serv_getln(buf, sizeof buf);
+               if (buf[0] == '1') while (serv_getln(buf, sizeof buf), strcmp(buf, "000"))  {
+                               extract_token(filename, buf, 0, '|', sizeof filename);
+                               extract_token(filesize, buf, 1, '|', sizeof filesize);
+                               extract_token(mimetype, buf, 2, '|', sizeof mimetype);
+                               extract_token(comment,  buf, 3, '|', sizeof comment);
+                               if (strstr(mimetype, "image") != NULL) {
+                                       wprintf("fadeimages[%d]=[\"download_file/", n);
+                                       escputs(filename);
+                                       wprintf("\", \"\", \"\"]\n");
+
+                                       /*
+                                                          //mimetype);
+                                          escputs(filename);   wprintf("</a></td>");
+                                          wprintf("<td>");     escputs(filesize);      wprintf("</td>");
+                                          wprintf("<td>");     escputs(mimetype);      wprintf("</td>");
+                                          wprintf("<td>");     escputs(comment);       wprintf("</td>");
+                                          wprintf("</tr>\n");
+                                       */
+                                       n++;
+                               }
+                       }
+               wprintf("</script>\n");
+               wprintf("<tr><td><script type=\"text/javascript\" src=\"static/fadeshow.js\">\n</script>\n");
+               wprintf("<script type=\"text/javascript\" >\n");
+               wprintf("new fadeshow(fadeimages, 500, 400, 0, 3000, 1, \"R\");\n");
+               wprintf("</script></td><th>\n");
+               wprintf("</div>\n");
+       }
        wDumpContent(1);
+
+
 }
 
+extern char* static_dirs[];
+void display_mime_icon(void)
+{
+       char FileBuf[SIZ];
+       const char *FileName;
+       size_t tlen;
+
+       FileName = GetIconFilename(xbstr("type", &tlen), tlen);
+
+       if (FileName == NULL)
+               snprintf (FileBuf, SIZ, "%s%s", static_dirs[0], "/diskette_24x.gif");
+       else
+               snprintf (FileBuf, SIZ, "%s%s", static_dirs[3], FileName);
+       output_static(FileBuf);
+
+}
 
 void download_file(char *filename)
 {
@@ -123,38 +213,41 @@ void download_file(char *filename)
 
 void upload_file(void)
 {
+       const char *MimeType;
        char buf[1024];
        size_t bytes_transmitted = 0;
        size_t blocksize;
+       struct wcsession *WCC = WC;     /* stack this for faster access (WC is a function) */
 
-       serv_printf("UOPN %s|%s", WC->upload_filename, bstr("description"));
+       MimeType = GuessMimeType(WCC->upload, WCC->upload_length); 
+       serv_printf("UOPN %s|%s|%s", WCC->upload_filename, MimeType, bstr("description"));
        serv_getln(buf, sizeof buf);
        if (buf[0] != '2')
        {
-               strcpy(WC->ImportantMessage, &buf[4]);
+               strcpy(WCC->ImportantMessage, &buf[4]);
                display_room_directory();
                return;
        }
 
-       while (bytes_transmitted < WC->upload_length)
+       while (bytes_transmitted < WCC->upload_length)
        {
                blocksize = 4096;
-               if (blocksize > (WC->upload_length - bytes_transmitted))
+               if (blocksize > (WCC->upload_length - bytes_transmitted))
                {
-                       blocksize = (WC->upload_length - bytes_transmitted);
+                       blocksize = (WCC->upload_length - bytes_transmitted);
                }
                serv_printf("WRIT %d", blocksize);
                serv_getln(buf, sizeof buf);
                if (buf[0] == '7')
                {
                        blocksize = atoi(&buf[4]);
-                       serv_write(&WC->upload[bytes_transmitted], blocksize);
+                       serv_write(&WCC->upload[bytes_transmitted], blocksize);
                        bytes_transmitted += blocksize;
                }
        }
 
        serv_puts("UCLS 1");
        serv_getln(buf, sizeof buf);
-       strcpy(WC->ImportantMessage, &buf[4]);
+       strcpy(WCC->ImportantMessage, &buf[4]);
        display_room_directory();
 }