Advanced menu items
[citadel.git] / webcit / 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, 1, 0, 0, 0);
24
25         svprintf("BOXTITLE", WCS_STRING, _("Image upload"));
26         do_template("beginbox");
27
28         wprintf("<form enctype=\"multipart/form-data\" action=\"%s\" "
29                 "method=\"post\" name=\"graphicsupload\">\n", uplurl);
30
31         wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%ld\">\n", WC->nonce);
32         wprintf("<input type=\"hidden\" name=\"which_room\" value=\"");
33         urlescputs(bstr("which_room"));
34         wprintf("\">\n");
35
36         wprintf(_("You can upload any image directly from your computer, "
37                 "as long as it is in GIF format (JPEG, PNG, etc. won't "
38                 "work)."));
39         wprintf("<br /><br />\n");
40
41         wprintf(_("Please select a file to upload:"));
42         wprintf("<input type=\"file\" name=\"filename\" size=\"35\">\n");
43         wprintf("<div class=\"buttons\">");
44         wprintf("<input type=\"submit\" name=\"upload_button\" value=\"%s\">\n", _("Upload"));
45         wprintf("&nbsp;");
46         wprintf("<input type=\"reset\" value=\"%s\">\n", _("Reset form"));
47         wprintf("&nbsp;");
48         wprintf("<input type=\"submit\" name=\"cancel_button\" value=\"%s\">\n", _("Cancel"));
49         wprintf("</div>\n");
50         wprintf("</form>\n");
51
52         do_template("endbox");
53
54         wDumpContent(1);
55 }
56
57 void do_graphics_upload(char *upl_cmd)
58 {
59         char buf[SIZ];
60         int bytes_remaining;
61         int pos = 0;
62         int thisblock;
63
64         if (!IsEmptyStr(bstr("cancel_button"))) {
65                 strcpy(WC->ImportantMessage,
66                         _("Graphics upload has been cancelled."));
67                 display_main_menu();
68                 return;
69         }
70
71         if (WC->upload_length == 0) {
72                 strcpy(WC->ImportantMessage,
73                         _("You didn't upload a file."));
74                 display_main_menu();
75                 return;
76         }
77         serv_puts(upl_cmd);
78         serv_getln(buf, sizeof buf);
79         if (buf[0] != '2') {
80                 strcpy(WC->ImportantMessage, &buf[4]);
81                 display_main_menu();
82                 return;
83         }
84         bytes_remaining = WC->upload_length;
85         while (bytes_remaining) {
86                 thisblock = ((bytes_remaining > 4096) ? 4096 : bytes_remaining);
87                 serv_printf("WRIT %d", thisblock);
88                 serv_getln(buf, sizeof buf);
89                 if (buf[0] != '7') {
90                         strcpy(WC->ImportantMessage, &buf[4]);
91                         serv_puts("UCLS 0");
92                         serv_getln(buf, sizeof buf);
93                         display_main_menu();
94                         return;
95                 }
96                 thisblock = extract_int(&buf[4], 0);
97                 serv_write(&WC->upload[pos], thisblock);
98                 pos = pos + thisblock;
99                 bytes_remaining = bytes_remaining - thisblock;
100         }
101
102         serv_puts("UCLS 1");
103         serv_getln(buf, sizeof buf);
104         if (buf[0] != 'x') {
105                 display_success(&buf[4]);
106                 return;
107         }
108 }