* Move iconbar font size declaration to webcit.css
[citadel.git] / webcit / graphics.c
blob361c19752456bbe4eb81bd8acaa41f8982c58461
1 /*
2 * $Id$
4 * Handles HTTP upload of graphics files into the system.
5 * \ingroup WebcitHttpServer
6 */
8 #include "webcit.h"
10 void display_graphics_upload(char *description, char *filename, char *uplurl)
12 WCTemplputParams SubTP;
13 StrBuf *Buf;
14 char buf[SIZ];
17 snprintf(buf, SIZ, "UIMG 0||%s", filename);
18 serv_puts(buf);
19 serv_getln(buf, sizeof buf);
20 if (buf[0] != '2') {
21 strcpy(WC->ImportantMessage, &buf[4]);
22 display_main_menu();
23 return;
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;
32 SubTP.Context = Buf;
33 DoTemplate(HKEY("beginbox"), NULL, &SubTP);
35 FreeStrBuf(&Buf);
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"));
43 wprintf("\">\n");
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"));
55 wprintf("&nbsp;");
56 wprintf("<input type=\"reset\" value=\"%s\">\n", _("Reset form"));
57 wprintf("&nbsp;");
58 wprintf("<input type=\"submit\" name=\"cancel_button\" value=\"%s\">\n", _("Cancel"));
59 wprintf("</div>\n");
60 wprintf("</form>\n");
62 do_template("endbox", NULL);
64 wDumpContent(1);
67 void do_graphics_upload(char *filename)
69 const char *MimeType;
70 char buf[SIZ];
71 int bytes_remaining;
72 int pos = 0;
73 int thisblock;
74 bytes_remaining = WC->upload_length;
76 if (havebstr("cancel_button")) {
77 strcpy(WC->ImportantMessage,
78 _("Graphics upload has been cancelled."));
79 display_main_menu();
80 return;
83 if (WC->upload_length == 0) {
84 strcpy(WC->ImportantMessage,
85 _("You didn't upload a file."));
86 display_main_menu();
87 return;
90 MimeType = GuessMimeType(&WC->upload[0], bytes_remaining);
91 snprintf(buf, SIZ, "UIMG 1|%s|%s", MimeType, filename);
92 serv_puts(buf);
94 serv_getln(buf, sizeof buf);
95 if (buf[0] != '2') {
96 strcpy(WC->ImportantMessage, &buf[4]);
97 display_main_menu();
98 return;
100 while (bytes_remaining) {
101 thisblock = ((bytes_remaining > 4096) ? 4096 : bytes_remaining);
102 serv_printf("WRIT %d", thisblock);
103 serv_getln(buf, sizeof buf);
104 if (buf[0] != '7') {
105 strcpy(WC->ImportantMessage, &buf[4]);
106 serv_puts("UCLS 0");
107 serv_getln(buf, sizeof buf);
108 display_main_menu();
109 return;
111 thisblock = extract_int(&buf[4], 0);
112 serv_write(&WC->upload[pos], thisblock);
113 pos = pos + thisblock;
114 bytes_remaining = bytes_remaining - thisblock;
117 serv_puts("UCLS 1");
118 serv_getln(buf, sizeof buf);
119 if (buf[0] != 'x') {
120 display_success(&buf[4]);
121 return;
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"),
133 "_userpic_",
134 "editpic");
136 /* room picture dispay / upload facility */
137 void display_editroompic(void) {
138 display_graphics_upload(_("the icon for this room"),
139 "_roompic_",
140 "editroompic");
143 /* the greetingpage hello pic */
144 void display_edithello(void) {
145 display_graphics_upload(_("the Greetingpicture for the login prompt"),
146 "hello",
147 "edithellopic");
150 /* the logoff banner */
151 void display_editgoodbyepic(void) {
152 display_graphics_upload(_("the Logoff banner picture"),
153 "UIMG 0|%s|goodbuye",
154 "editgoodbuyepic");
157 void display_editfloorpic(void) {
158 char buf[SIZ];
159 snprintf(buf, SIZ, "UIMG 0|_floorpic_|%s",
160 bstr("which_floor"));
161 display_graphics_upload(_("the icon for this floor"),
162 buf,
163 "editfloorpic");
166 void editfloorpic(void){
167 char buf[SIZ];
168 snprintf(buf, SIZ, "UIMG 1|_floorpic_|%s",
169 bstr("which_floor"));
170 do_graphics_upload(buf);
173 void
174 InitModule_GRAPHICS
175 (void)
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);