4 * Handles HTTP upload of graphics files into the system.
6 * Copyright (c) 1996-2010 by the citadel.org team
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 void display_graphics_upload(char *description, char *filename, char *uplurl)
27 WCTemplputParams SubTP;
32 snprintf(buf, SIZ, "UIMG 0||%s", filename);
34 serv_getln(buf, sizeof buf);
36 strcpy(WC->ImportantMessage, &buf[4]);
40 /*output_headers(1, 1, 0, 0, 0, 0); */
42 output_headers(1, 1, 1, 0, 0, 0);
44 Buf = NewStrBufPlain(_("Image upload"), -1);
45 memset(&SubTP, 0, sizeof(WCTemplputParams));
46 SubTP.Filter.ContextType = CTX_STRBUF;
48 DoTemplate(HKEY("beginbox"), NULL, &SubTP);
52 wc_printf("<form enctype=\"multipart/form-data\" action=\"%s\" "
53 "method=\"post\" name=\"graphicsupload\">\n", uplurl);
55 wc_printf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
56 wc_printf("<input type=\"hidden\" name=\"which_room\" value=\"");
57 urlescputs(bstr("which_room"));
60 wc_printf(_("You can upload an image directly from your computer"));
61 wc_printf("<br /><br />\n");
63 wc_printf(_("Please select a file to upload:"));
64 wc_printf("<input type=\"file\" name=\"filename\" size=\"35\">\n");
66 wc_printf("<div class=\"uploadpic\"><img src=\"image?name=%s\"></div>\n", filename);
68 wc_printf("<div class=\"buttons\">");
69 wc_printf("<input type=\"submit\" name=\"upload_button\" value=\"%s\">\n", _("Upload"));
71 wc_printf("<input type=\"reset\" value=\"%s\">\n", _("Reset form"));
73 wc_printf("<input type=\"submit\" name=\"cancel_button\" value=\"%s\">\n", _("Cancel"));
74 wc_printf("</div>\n");
75 wc_printf("</form>\n");
77 do_template("endbox", NULL);
82 void do_graphics_upload(char *filename)
90 bytes_remaining = WCC->upload_length;
92 if (havebstr("cancel_button")) {
93 strcpy(WC->ImportantMessage,
94 _("Graphics upload has been cancelled."));
99 if (WCC->upload_length == 0) {
100 strcpy(WC->ImportantMessage,
101 _("You didn't upload a file."));
106 MimeType = GuessMimeType(ChrPtr(WCC->upload), bytes_remaining);
107 snprintf(buf, SIZ, "UIMG 1|%s|%s", MimeType, filename);
110 serv_getln(buf, sizeof buf);
112 strcpy(WCC->ImportantMessage, &buf[4]);
116 while (bytes_remaining) {
117 thisblock = ((bytes_remaining > 4096) ? 4096 : bytes_remaining);
118 serv_printf("WRIT %d", thisblock);
119 serv_getln(buf, sizeof buf);
121 strcpy(WCC->ImportantMessage, &buf[4]);
123 serv_getln(buf, sizeof buf);
127 thisblock = extract_int(&buf[4], 0);
128 serv_write(&ChrPtr(WCC->upload)[pos], thisblock);
129 pos = pos + thisblock;
130 bytes_remaining = bytes_remaining - thisblock;
134 serv_getln(buf, sizeof buf);
136 display_success(&buf[4]);
142 void edithellopic(void) { do_graphics_upload("hello"); }
143 void editpic(void) { do_graphics_upload("_userpic_"); }
144 void editgoodbuyepic(void) { do_graphics_upload("UIMG 1|%s|goodbuye"); }
146 /* The users photo display / upload facility */
147 void display_editpic(void) {
148 display_graphics_upload(_("your photo"),
152 /* room picture dispay / upload facility */
153 void display_editroompic(void) {
154 display_graphics_upload(_("the icon for this room"),
159 /* the greetingpage hello pic */
160 void display_edithello(void) {
161 display_graphics_upload(_("the Greetingpicture for the login prompt"),
166 /* the logoff banner */
167 void display_editgoodbyepic(void) {
168 display_graphics_upload(_("the Logoff banner picture"),
169 "UIMG 0|%s|goodbuye",
173 void display_editfloorpic(void) {
175 snprintf(buf, SIZ, "_floorpic_|%s",
176 bstr("which_floor"));
177 display_graphics_upload(_("the icon for this floor"),
182 void editroompic(void) {
184 snprintf(buf, SIZ, "_roompic_|%s",
186 do_graphics_upload(buf);
189 void editfloorpic(void){
191 snprintf(buf, SIZ, "_floorpic_|%s",
192 bstr("which_floor"));
193 do_graphics_upload(buf);
200 WebcitAddUrlHandler(HKEY("display_editpic"), "", 0, display_editpic, 0);
201 WebcitAddUrlHandler(HKEY("editpic"), "", 0, editpic, 0);
202 WebcitAddUrlHandler(HKEY("display_editroompic"), "", 0, display_editroompic, 0);
203 WebcitAddUrlHandler(HKEY("editroompic"), "", 0, editroompic, 0);
204 WebcitAddUrlHandler(HKEY("display_edithello"), "", 0, display_edithello, 0);
205 WebcitAddUrlHandler(HKEY("edithellopic"), "", 0, edithellopic, 0);
206 WebcitAddUrlHandler(HKEY("display_editgoodbuye"), "", 0, display_editgoodbyepic, 0);
207 WebcitAddUrlHandler(HKEY("editgoodbuyepic"), "", 0, editgoodbuyepic, 0);
208 WebcitAddUrlHandler(HKEY("display_editfloorpic"), "", 0, display_editfloorpic, 0);
209 WebcitAddUrlHandler(HKEY("editfloorpic"), "", 0, editfloorpic, 0);