4 * Handles HTTP upload of graphics files into the system.
5 * \ingroup WebcitHttpServer
10 void display_graphics_upload(char *description, char *filename, char *uplurl)
16 snprintf(buf, SIZ, "UIMG 0||%s", filename);
18 serv_getln(buf, sizeof buf);
20 strcpy(WC->ImportantMessage, &buf[4]);
24 output_headers(1, 1, 0, 0, 0, 0);
26 output_headers(1, 1, 1, 0, 0, 0);
28 Buf = NewStrBufPlain(_("Image upload"), -1);
29 DoTemplate(HKEY("beginbox"), NULL, Buf, CTX_STRBUF);
33 wprintf("<form enctype=\"multipart/form-data\" action=\"%s\" "
34 "method=\"post\" name=\"graphicsupload\">\n", uplurl);
36 wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
37 wprintf("<input type=\"hidden\" name=\"which_room\" value=\"");
38 urlescputs(bstr("which_room"));
41 wprintf(_("You can upload an image directly from your computer"));
42 wprintf("<br /><br />\n");
44 wprintf(_("Please select a file to upload:"));
45 wprintf("<input type=\"file\" name=\"filename\" size=\"35\">\n");
47 wprintf("<div class=\"uploadpic\"><img src=\"image&name=%s\"></div>\n", filename);
49 wprintf("<div class=\"buttons\">");
50 wprintf("<input type=\"submit\" name=\"upload_button\" value=\"%s\">\n", _("Upload"));
52 wprintf("<input type=\"reset\" value=\"%s\">\n", _("Reset form"));
54 wprintf("<input type=\"submit\" name=\"cancel_button\" value=\"%s\">\n", _("Cancel"));
58 do_template("endbox", NULL);
63 void do_graphics_upload(char *filename)
70 bytes_remaining = WC->upload_length;
72 if (havebstr("cancel_button")) {
73 strcpy(WC->ImportantMessage,
74 _("Graphics upload has been cancelled."));
79 if (WC->upload_length == 0) {
80 strcpy(WC->ImportantMessage,
81 _("You didn't upload a file."));
86 MimeType = GuessMimeType(&WC->upload[0], bytes_remaining);
87 snprintf(buf, SIZ, "UIMG 1|%s|%s", MimeType, filename);
90 serv_getln(buf, sizeof buf);
92 strcpy(WC->ImportantMessage, &buf[4]);
96 while (bytes_remaining) {
97 thisblock = ((bytes_remaining > 4096) ? 4096 : bytes_remaining);
98 serv_printf("WRIT %d", thisblock);
99 serv_getln(buf, sizeof buf);
101 strcpy(WC->ImportantMessage, &buf[4]);
103 serv_getln(buf, sizeof buf);
107 thisblock = extract_int(&buf[4], 0);
108 serv_write(&WC->upload[pos], thisblock);
109 pos = pos + thisblock;
110 bytes_remaining = bytes_remaining - thisblock;
114 serv_getln(buf, sizeof buf);
116 display_success(&buf[4]);
122 void edithellopic(void) { do_graphics_upload("hello"); }
123 void editpic(void) { do_graphics_upload("_userpic_"); }
124 void editgoodbuyepic(void) { do_graphics_upload("UIMG 1|%s|goodbuye"); }
126 /* The users photo display / upload facility */
127 void display_editpic(void) {
128 display_graphics_upload(_("your photo"),
132 /* room picture dispay / upload facility */
133 void display_editroompic(void) {
134 display_graphics_upload(_("the icon for this room"),
139 /* the greetingpage hello pic */
140 void display_edithello(void) {
141 display_graphics_upload(_("the Greetingpicture for the login prompt"),
146 /* the logoff banner */
147 void display_editgoodbyepic(void) {
148 display_graphics_upload(_("the Logoff banner picture"),
149 "UIMG 0|%s|goodbuye",
153 void display_editfloorpic(void) {
155 snprintf(buf, SIZ, "UIMG 0|_floorpic_|%s",
156 bstr("which_floor"));
157 display_graphics_upload(_("the icon for this floor"),
162 void editfloorpic(void){
164 snprintf(buf, SIZ, "UIMG 1|_floorpic_|%s",
165 bstr("which_floor"));
166 do_graphics_upload(buf);
173 WebcitAddUrlHandler(HKEY("display_editpic"), display_editpic, 0);
174 WebcitAddUrlHandler(HKEY("editpic"), editpic, 0);
175 WebcitAddUrlHandler(HKEY("display_editroompic"), display_editroompic, 0);
176 WebcitAddUrlHandler(HKEY("display_edithello"), display_edithello, 0);
177 WebcitAddUrlHandler(HKEY("edithellopic"), edithellopic, 0);
178 WebcitAddUrlHandler(HKEY("display_editgoodbyepic"), display_editgoodbyepic, 0);
179 WebcitAddUrlHandler(HKEY("editgoodbuyepic"), editgoodbuyepic, 0);
180 WebcitAddUrlHandler(HKEY("display_editfloorpic"), display_editfloorpic, 0);
181 WebcitAddUrlHandler(HKEY("editfloorpic"), editfloorpic, 0);