* All OS-level includes are now included from webcit.h instead of from
[citadel.git] / webcit / graphics.c
1 /*
2  * $Id$
3  *
4  * Handles HTTP upload of graphics files into the system.
5  */
6
7 #include "webcit.h"
8
9 void display_graphics_upload(char *description, char *check_cmd, char *uplurl)
10 {
11         char buf[SIZ];
12
13         serv_puts(check_cmd);
14         serv_getln(buf, sizeof buf);
15         if (buf[0] != '2') {
16                 strcpy(WC->ImportantMessage, &buf[4]);
17                 display_main_menu();
18                 return;
19         }
20         output_headers(1, 1, 0, 0, 0, 0, 0);
21
22         output_headers(1, 1, 2, 0, 0, 0, 0);
23         wprintf("<div id=\"banner\">\n"
24                 "<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#444455\"><TR><TD>"
25                 "<SPAN CLASS=\"titlebar\">Image upload</SPAN>"
26                 "</TD></TR></TABLE>\n"
27                 "</div>\n<div id=\"content\">\n"
28         );
29
30         wprintf("<div id=\"fix_scrollbar_bug\">"
31                 "<table border=0 width=100%% bgcolor=\"#ffffff\"><tr><td>\n");
32
33         wprintf("<CENTER>\n");
34
35         wprintf("<FORM ENCTYPE=\"multipart/form-data\" ACTION=\"%s\" "
36                 "METHOD=\"POST\" NAME=\"graphicsupload\">\n", uplurl);
37
38         wprintf("<INPUT TYPE=\"hidden\" NAME=\"which_room\" VALUE=\"");
39         urlescputs(bstr("which_room"));
40         wprintf("\">\n");
41
42         wprintf("You can upload any image directly from your computer,\n");
43         wprintf("as long as it is in GIF format (JPEG, PNG, etc. won't\n");
44         wprintf("work).<br /><br />\n");
45
46         wprintf("Please select a file to upload:<br /><br />\n");
47         wprintf("<INPUT TYPE=\"FILE\" NAME=\"filename\" SIZE=\"35\">\n");
48         wprintf("<br /><br />");
49         wprintf("<INPUT TYPE=\"SUBMIT\" NAME=\"sc\" VALUE=\"Upload\">\n");
50         wprintf("&nbsp;");
51         wprintf("<INPUT TYPE=\"RESET\" VALUE=\"Reset Form\">\n");
52         wprintf("&nbsp;");
53         wprintf("<INPUT TYPE=\"SUBMIT\" NAME=\"sc\" VALUE=\"Cancel\">\n");
54         wprintf("</FORM>\n");
55         wprintf("</CENTER>\n");
56         wprintf("</td></tr></table></div>\n");
57         wDumpContent(1);
58 }
59
60 void do_graphics_upload(char *upl_cmd)
61 {
62         char buf[SIZ];
63         int bytes_remaining;
64         int pos = 0;
65         int thisblock;
66
67         if (!strcasecmp(bstr("sc"), "Cancel")) {
68                 strcpy(WC->ImportantMessage,
69                         "Graphics upload cancelled.");
70                 display_main_menu();
71                 return;
72         }
73
74         if (WC->upload_length == 0) {
75                 strcpy(WC->ImportantMessage,
76                         "You didn't upload a file.");
77                 display_main_menu();
78                 return;
79         }
80         serv_puts(upl_cmd);
81         serv_getln(buf, sizeof buf);
82         if (buf[0] != '2') {
83                 strcpy(WC->ImportantMessage, &buf[4]);
84                 display_main_menu();
85                 return;
86         }
87         bytes_remaining = WC->upload_length;
88         while (bytes_remaining) {
89                 thisblock = ((bytes_remaining > 4096) ? 4096 : bytes_remaining);
90                 serv_printf("WRIT %d", thisblock);
91                 serv_getln(buf, sizeof buf);
92                 if (buf[0] != '7') {
93                         strcpy(WC->ImportantMessage, &buf[4]);
94                         serv_puts("UCLS 0");
95                         serv_getln(buf, sizeof buf);
96                         display_main_menu();
97                         return;
98                 }
99                 thisblock = extract_int(&buf[4], 0);
100                 serv_write(&WC->upload[pos], thisblock);
101                 pos = pos + thisblock;
102                 bytes_remaining = bytes_remaining - thisblock;
103         }
104
105         serv_puts("UCLS 1");
106         serv_getln(buf, sizeof buf);
107         if (buf[0] != 'x') {
108                 display_success(&buf[4]);
109                 return;
110         }
111 }