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