4bc9e8e1146a5f47ce0c8299264c8cb59b648567
[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);
21
22         output_headers(1, 1, 2, 0, 0, 0);
23         wprintf("<div id=\"banner\">\n"
24                 "<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#444455\"><TR><TD>"
25                 "<SPAN CLASS=\"titlebar\">");
26         wprintf(_("Image upload"));
27         wprintf("</SPAN>"
28                 "</TD></TR></TABLE>\n"
29                 "</div>\n<div id=\"content\">\n"
30         );
31
32         wprintf("<div class=\"fix_scrollbar_bug\">"
33                 "<table border=0 width=100%% bgcolor=\"#ffffff\"><tr><td>\n");
34
35         wprintf("<CENTER>\n");
36
37         wprintf("<FORM ENCTYPE=\"multipart/form-data\" action=\"%s\" "
38                 "METHOD=\"POST\" NAME=\"graphicsupload\">\n", uplurl);
39
40         wprintf("<INPUT TYPE=\"hidden\" NAME=\"which_room\" VALUE=\"");
41         urlescputs(bstr("which_room"));
42         wprintf("\">\n");
43
44         wprintf(_("You can upload any image directly from your computer, "
45                 "as long as it is in GIF format (JPEG, PNG, etc. won't "
46                 "work)."));
47         wprintf("<br /><br />\n");
48
49         wprintf(_("Please select a file to upload:"));
50         wprintf("<br /><br />\n");
51         wprintf("<INPUT TYPE=\"FILE\" NAME=\"filename\" SIZE=\"35\">\n");
52         wprintf("<br /><br />");
53         wprintf("<INPUT TYPE=\"SUBMIT\" NAME=\"upload_button\" VALUE=\"%s\">\n", _("Upload"));
54         wprintf("&nbsp;");
55         wprintf("<INPUT TYPE=\"RESET\" VALUE=\"%s\">\n", _("Reset form"));
56         wprintf("&nbsp;");
57         wprintf("<INPUT TYPE=\"SUBMIT\" NAME=\"cancel_button\" VALUE=\"%s\">\n", _("Cancel"));
58         wprintf("</FORM>\n");
59         wprintf("</CENTER>\n");
60         wprintf("</td></tr></table></div>\n");
61         wDumpContent(1);
62 }
63
64 void do_graphics_upload(char *upl_cmd)
65 {
66         char buf[SIZ];
67         int bytes_remaining;
68         int pos = 0;
69         int thisblock;
70
71         if (strlen(bstr("cancel_button")) > 0) {
72                 strcpy(WC->ImportantMessage,
73                         _("Graphics upload has been cancelled."));
74                 display_main_menu();
75                 return;
76         }
77
78         if (WC->upload_length == 0) {
79                 strcpy(WC->ImportantMessage,
80                         _("You didn't upload a file."));
81                 display_main_menu();
82                 return;
83         }
84         serv_puts(upl_cmd);
85         serv_getln(buf, sizeof buf);
86         if (buf[0] != '2') {
87                 strcpy(WC->ImportantMessage, &buf[4]);
88                 display_main_menu();
89                 return;
90         }
91         bytes_remaining = WC->upload_length;
92         while (bytes_remaining) {
93                 thisblock = ((bytes_remaining > 4096) ? 4096 : bytes_remaining);
94                 serv_printf("WRIT %d", thisblock);
95                 serv_getln(buf, sizeof buf);
96                 if (buf[0] != '7') {
97                         strcpy(WC->ImportantMessage, &buf[4]);
98                         serv_puts("UCLS 0");
99                         serv_getln(buf, sizeof buf);
100                         display_main_menu();
101                         return;
102                 }
103                 thisblock = extract_int(&buf[4], 0);
104                 serv_write(&WC->upload[pos], thisblock);
105                 pos = pos + thisblock;
106                 bytes_remaining = bytes_remaining - thisblock;
107         }
108
109         serv_puts("UCLS 1");
110         serv_getln(buf, sizeof buf);
111         if (buf[0] != 'x') {
112                 display_success(&buf[4]);
113                 return;
114         }
115 }