use the same way to display all banners and services contents
[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, 2, 0, 0, 0);
24         wprintf("<div id=\"banner\">\n");
25         wprintf("<h1>");
26         wprintf(_("Image upload"));
27         wprintf("</h1>");
28         wprintf("</div>\n");
29
30         wprintf("<div id=\"content\" class=\"service\">\n");
31
32         wprintf("<div class=\"fix_scrollbar_bug\">"
33                 "<table class=\"graphics_background\"><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=\"nonce\" value=\"%ld\">\n", WC->nonce);
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 (!IsEmptyStr(bstr("cancel_button"))) {
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 }