4 * Handles HTTP upload of graphics files into the system.
5 * \ingroup WebcitHttpServer
10 void display_graphics_upload(char *description
, char *filename
, char *uplurl
)
12 WCTemplputParams SubTP
;
17 snprintf(buf
, SIZ
, "UIMG 0||%s", filename
);
19 serv_getln(buf
, sizeof buf
);
21 strcpy(WC
->ImportantMessage
, &buf
[4]);
25 //output_headers(1, 1, 0, 0, 0, 0);
27 output_headers(1, 1, 1, 0, 0, 0);
29 Buf
= NewStrBufPlain(_("Image upload"), -1);
30 memset(&SubTP
, 0, sizeof(WCTemplputParams
));
31 SubTP
.Filter
.ContextType
= CTX_STRBUF
;
33 DoTemplate(HKEY("beginbox"), NULL
, &SubTP
);
37 wprintf("<form enctype=\"multipart/form-data\" action=\"%s\" "
38 "method=\"post\" name=\"graphicsupload\">\n", uplurl
);
40 wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC
->nonce
);
41 wprintf("<input type=\"hidden\" name=\"which_room\" value=\"");
42 urlescputs(bstr("which_room"));
45 wprintf(_("You can upload an image directly from your computer"));
46 wprintf("<br /><br />\n");
48 wprintf(_("Please select a file to upload:"));
49 wprintf("<input type=\"file\" name=\"filename\" size=\"35\">\n");
51 wprintf("<div class=\"uploadpic\"><img src=\"image&name=%s\"></div>\n", filename
);
53 wprintf("<div class=\"buttons\">");
54 wprintf("<input type=\"submit\" name=\"upload_button\" value=\"%s\">\n", _("Upload"));
56 wprintf("<input type=\"reset\" value=\"%s\">\n", _("Reset form"));
58 wprintf("<input type=\"submit\" name=\"cancel_button\" value=\"%s\">\n", _("Cancel"));
62 do_template("endbox", NULL
);
67 void do_graphics_upload(char *filename
)
74 bytes_remaining
= WC
->upload_length
;
76 if (havebstr("cancel_button")) {
77 strcpy(WC
->ImportantMessage
,
78 _("Graphics upload has been cancelled."));
83 if (WC
->upload_length
== 0) {
84 strcpy(WC
->ImportantMessage
,
85 _("You didn't upload a file."));
90 MimeType
= GuessMimeType(&WC
->upload
[0], bytes_remaining
);
91 snprintf(buf
, SIZ
, "UIMG 1|%s|%s", MimeType
, filename
);
94 serv_getln(buf
, sizeof buf
);
96 strcpy(WC
->ImportantMessage
, &buf
[4]);
100 while (bytes_remaining
) {
101 thisblock
= ((bytes_remaining
> 4096) ? 4096 : bytes_remaining
);
102 serv_printf("WRIT %d", thisblock
);
103 serv_getln(buf
, sizeof buf
);
105 strcpy(WC
->ImportantMessage
, &buf
[4]);
107 serv_getln(buf
, sizeof buf
);
111 thisblock
= extract_int(&buf
[4], 0);
112 serv_write(&WC
->upload
[pos
], thisblock
);
113 pos
= pos
+ thisblock
;
114 bytes_remaining
= bytes_remaining
- thisblock
;
118 serv_getln(buf
, sizeof buf
);
120 display_success(&buf
[4]);
126 void edithellopic(void) { do_graphics_upload("hello"); }
127 void editpic(void) { do_graphics_upload("_userpic_"); }
128 void editgoodbuyepic(void) { do_graphics_upload("UIMG 1|%s|goodbuye"); }
130 /* The users photo display / upload facility */
131 void display_editpic(void) {
132 display_graphics_upload(_("your photo"),
136 /* room picture dispay / upload facility */
137 void display_editroompic(void) {
138 display_graphics_upload(_("the icon for this room"),
143 /* the greetingpage hello pic */
144 void display_edithello(void) {
145 display_graphics_upload(_("the Greetingpicture for the login prompt"),
150 /* the logoff banner */
151 void display_editgoodbyepic(void) {
152 display_graphics_upload(_("the Logoff banner picture"),
153 "UIMG 0|%s|goodbuye",
157 void display_editfloorpic(void) {
159 snprintf(buf
, SIZ
, "UIMG 0|_floorpic_|%s",
160 bstr("which_floor"));
161 display_graphics_upload(_("the icon for this floor"),
166 void editfloorpic(void){
168 snprintf(buf
, SIZ
, "UIMG 1|_floorpic_|%s",
169 bstr("which_floor"));
170 do_graphics_upload(buf
);
177 WebcitAddUrlHandler(HKEY("display_editpic"), display_editpic
, 0);
178 WebcitAddUrlHandler(HKEY("editpic"), editpic
, 0);
179 WebcitAddUrlHandler(HKEY("display_editroompic"), display_editroompic
, 0);
180 WebcitAddUrlHandler(HKEY("display_edithello"), display_edithello
, 0);
181 WebcitAddUrlHandler(HKEY("edithellopic"), edithellopic
, 0);
182 WebcitAddUrlHandler(HKEY("display_editgoodbyepic"), display_editgoodbyepic
, 0);
183 WebcitAddUrlHandler(HKEY("editgoodbuyepic"), editgoodbuyepic
, 0);
184 WebcitAddUrlHandler(HKEY("display_editfloorpic"), display_editfloorpic
, 0);
185 WebcitAddUrlHandler(HKEY("editfloorpic"), editfloorpic
, 0);