2 * Handles HTTP upload of graphics files into the system.
4 * Copyright (c) 1996-2011 by the citadel.org team
6 * This program is open source software. You can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 3 of the
9 * License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 void display_graphics_upload(char *description, char *filename, char *uplurl)
25 WCTemplputParams SubTP;
30 snprintf(buf, SIZ, "UIMG 0||%s", filename);
32 serv_getln(buf, sizeof buf);
34 strcpy(WC->ImportantMessage, &buf[4]);
38 /*output_headers(1, 1, 0, 0, 0, 0); */
40 output_headers(1, 1, 1, 0, 0, 0);
42 Buf = NewStrBufPlain(_("Image upload"), -1);
43 memset(&SubTP, 0, sizeof(WCTemplputParams));
44 SubTP.Filter.ContextType = CTX_STRBUF;
46 DoTemplate(HKEY("box_begin"), NULL, &SubTP);
50 wc_printf("<form enctype=\"multipart/form-data\" action=\"%s\" "
51 "method=\"post\" name=\"graphicsupload\">\n", uplurl);
53 wc_printf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
54 wc_printf("<input type=\"hidden\" name=\"which_room\" value=\"");
55 urlescputs(bstr("which_room"));
58 wc_printf(_("You can upload an image directly from your computer"));
59 wc_printf("<br><br>\n");
61 wc_printf(_("Please select a file to upload:"));
62 wc_printf("<input type=\"file\" name=\"filename\" size=\"35\">\n");
64 wc_printf("<div class=\"uploadpic\"><img src=\"image?name=%s\"></div>\n", filename);
66 wc_printf("<div class=\"buttons\">");
67 wc_printf("<input type=\"submit\" name=\"upload_button\" value=\"%s\">\n", _("Upload"));
69 wc_printf("<input type=\"reset\" value=\"%s\">\n", _("Reset form"));
71 wc_printf("<input type=\"submit\" name=\"cancel_button\" value=\"%s\">\n", _("Cancel"));
72 wc_printf("</div>\n");
73 wc_printf("</form>\n");
75 do_template("box_end");
80 void do_graphics_upload(char *filename)
88 bytes_remaining = WCC->upload_length;
90 if (havebstr("cancel_button")) {
91 strcpy(WC->ImportantMessage,
92 _("Graphics upload has been cancelled."));
97 if (WCC->upload_length == 0) {
98 strcpy(WC->ImportantMessage,
99 _("You didn't upload a file."));
104 MimeType = GuessMimeType(ChrPtr(WCC->upload), bytes_remaining);
105 snprintf(buf, SIZ, "UIMG 1|%s|%s", MimeType, filename);
108 serv_getln(buf, sizeof buf);
110 strcpy(WCC->ImportantMessage, &buf[4]);
114 while (bytes_remaining) {
115 thisblock = ((bytes_remaining > 4096) ? 4096 : bytes_remaining);
116 serv_printf("WRIT %d", thisblock);
117 serv_getln(buf, sizeof buf);
119 strcpy(WCC->ImportantMessage, &buf[4]);
121 serv_getln(buf, sizeof buf);
125 thisblock = extract_int(&buf[4], 0);
126 serv_write(&ChrPtr(WCC->upload)[pos], thisblock);
127 pos = pos + thisblock;
128 bytes_remaining = bytes_remaining - thisblock;
132 serv_getln(buf, sizeof buf);
134 display_success(&buf[4]);
140 void edithellopic(void) { do_graphics_upload("hello"); }
141 void editpic(void) { do_graphics_upload("_userpic_"); }
142 void editgoodbuyepic(void) { do_graphics_upload("UIMG 1|%s|goodbuye"); }
144 /* The users photo display / upload facility */
145 void display_editpic(void) {
146 display_graphics_upload(_("your photo"),
150 /* room picture dispay / upload facility */
151 void display_editroompic(void) {
152 display_graphics_upload(_("the icon for this room"),
157 /* the greetingpage hello pic */
158 void display_edithello(void) {
159 display_graphics_upload(_("the Greetingpicture for the login prompt"),
164 /* the logoff banner */
165 void display_editgoodbyepic(void) {
166 display_graphics_upload(_("the Logoff banner picture"),
167 "UIMG 0|%s|goodbuye",
171 void display_editfloorpic(void) {
173 snprintf(buf, SIZ, "_floorpic_|%s",
174 bstr("which_floor"));
175 display_graphics_upload(_("the icon for this floor"),
180 void editroompic(void) {
182 snprintf(buf, SIZ, "_roompic_|%s",
184 do_graphics_upload(buf);
187 void editfloorpic(void){
189 snprintf(buf, SIZ, "_floorpic_|%s",
190 bstr("which_floor"));
191 do_graphics_upload(buf);
198 WebcitAddUrlHandler(HKEY("display_editpic"), "", 0, display_editpic, 0);
199 WebcitAddUrlHandler(HKEY("editpic"), "", 0, editpic, 0);
200 WebcitAddUrlHandler(HKEY("display_editroompic"), "", 0, display_editroompic, 0);
201 WebcitAddUrlHandler(HKEY("editroompic"), "", 0, editroompic, 0);
202 WebcitAddUrlHandler(HKEY("display_edithello"), "", 0, display_edithello, 0);
203 WebcitAddUrlHandler(HKEY("edithellopic"), "", 0, edithellopic, 0);
204 WebcitAddUrlHandler(HKEY("display_editgoodbuye"), "", 0, display_editgoodbyepic, 0);
205 WebcitAddUrlHandler(HKEY("editgoodbuyepic"), "", 0, editgoodbuyepic, 0);
206 WebcitAddUrlHandler(HKEY("display_editfloorpic"), "", 0, display_editfloorpic, 0);
207 WebcitAddUrlHandler(HKEY("editfloorpic"), "", 0, editfloorpic, 0);