4 * Handles HTTP upload of graphics files into the system.
5 * \ingroup WebcitHttpServer
10 void display_graphics_upload(char *description, char *filename, char *uplurl)
15 snprintf(buf, SIZ, "UIMG 0||%s", filename);
17 serv_getln(buf, sizeof buf);
19 strcpy(WC->ImportantMessage, &buf[4]);
23 output_headers(1, 1, 0, 0, 0, 0);
25 output_headers(1, 1, 1, 0, 0, 0);
27 svput("BOXTITLE", WCS_STRING, _("Image upload"));
28 do_template("beginbox", NULL);
30 wprintf("<form enctype=\"multipart/form-data\" action=\"%s\" "
31 "method=\"post\" name=\"graphicsupload\">\n", uplurl);
33 wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
34 wprintf("<input type=\"hidden\" name=\"which_room\" value=\"");
35 urlescputs(bstr("which_room"));
38 wprintf(_("You can upload an image directly from your computer"));
39 wprintf("<br /><br />\n");
41 wprintf(_("Please select a file to upload:"));
42 wprintf("<input type=\"file\" name=\"filename\" size=\"35\">\n");
44 wprintf("<div class=\"uploadpic\"><img src=\"image&name=%s\"></div>\n", filename);
46 wprintf("<div class=\"buttons\">");
47 wprintf("<input type=\"submit\" name=\"upload_button\" value=\"%s\">\n", _("Upload"));
49 wprintf("<input type=\"reset\" value=\"%s\">\n", _("Reset form"));
51 wprintf("<input type=\"submit\" name=\"cancel_button\" value=\"%s\">\n", _("Cancel"));
55 do_template("endbox", NULL);
60 void do_graphics_upload(char *filename)
67 bytes_remaining = WC->upload_length;
69 if (havebstr("cancel_button")) {
70 strcpy(WC->ImportantMessage,
71 _("Graphics upload has been cancelled."));
76 if (WC->upload_length == 0) {
77 strcpy(WC->ImportantMessage,
78 _("You didn't upload a file."));
83 MimeType = GuessMimeType(&WC->upload[0], bytes_remaining);
84 snprintf(buf, SIZ, "UIMG 1|%s|%s", MimeType, filename);
87 serv_getln(buf, sizeof buf);
89 strcpy(WC->ImportantMessage, &buf[4]);
93 while (bytes_remaining) {
94 thisblock = ((bytes_remaining > 4096) ? 4096 : bytes_remaining);
95 serv_printf("WRIT %d", thisblock);
96 serv_getln(buf, sizeof buf);
98 strcpy(WC->ImportantMessage, &buf[4]);
100 serv_getln(buf, sizeof buf);
104 thisblock = extract_int(&buf[4], 0);
105 serv_write(&WC->upload[pos], thisblock);
106 pos = pos + thisblock;
107 bytes_remaining = bytes_remaining - thisblock;
111 serv_getln(buf, sizeof buf);
113 display_success(&buf[4]);
119 void edithellopic(void) { do_graphics_upload("hello"); }
120 void editpic(void) { do_graphics_upload("_userpic_"); }
121 void editgoodbuyepic(void) { do_graphics_upload("UIMG 1|%s|goodbuye"); }
123 /* The users photo display / upload facility */
124 void display_editpic(void) {
125 display_graphics_upload(_("your photo"),
129 /* room picture dispay / upload facility */
130 void display_editroompic(void) {
131 display_graphics_upload(_("the icon for this room"),
136 /* the greetingpage hello pic */
137 void display_edithello(void) {
138 display_graphics_upload(_("the Greetingpicture for the login prompt"),
143 /* the logoff banner */
144 void display_editgoodbyepic(void) {
145 display_graphics_upload(_("the Logoff banner picture"),
146 "UIMG 0|%s|goodbuye",
150 void display_editfloorpic(void) {
152 snprintf(buf, SIZ, "UIMG 0|_floorpic_|%s",
153 bstr("which_floor"));
154 display_graphics_upload(_("the icon for this floor"),
159 void editfloorpic(void){
161 snprintf(buf, SIZ, "UIMG 1|_floorpic_|%s",
162 bstr("which_floor"));
163 do_graphics_upload(buf);
170 WebcitAddUrlHandler(HKEY("display_editpic"), display_editpic, 0);
171 WebcitAddUrlHandler(HKEY("editpic"), editpic, 0);
172 WebcitAddUrlHandler(HKEY("display_editroompic"), display_editroompic, 0);
173 WebcitAddUrlHandler(HKEY("display_edithello"), display_edithello, 0);
174 WebcitAddUrlHandler(HKEY("edithellopic"), edithellopic, 0);
175 WebcitAddUrlHandler(HKEY("display_editgoodbyepic"), display_editgoodbyepic, 0);
176 WebcitAddUrlHandler(HKEY("editgoodbuyepic"), editgoodbuyepic, 0);
177 WebcitAddUrlHandler(HKEY("display_editfloorpic"), display_editfloorpic, 0);
178 WebcitAddUrlHandler(HKEY("editfloorpic"), editfloorpic, 0);