buybuy plaintext important message.
[citadel.git] / webcit / graphics.c
1 /*
2  * Handles HTTP upload of graphics files into the system.
3  *
4  * Copyright (c) 1996-2011 by the citadel.org team
5  *
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.
10  *
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.
15  *
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
19  */
20
21 #include "webcit.h"
22
23 extern void output_static(const char* What);
24
25 void display_graphics_upload(char *filename)
26 {
27         StrBuf *Line;
28
29         Line = NewStrBuf();
30         serv_printf("UIMG 0||%s", filename);
31         StrBuf_ServGetln(Line);
32         if (GetServerStatusMsg(Line, NULL, 1, 2) != 2) {
33                 display_main_menu();
34                 return;
35         }
36         else
37         {
38                 output_headers(1, 0, 0, 0, 1, 0);
39                 do_template("files_graphicsupload");
40                 end_burst();
41         }
42         FreeStrBuf(&Line);
43 }
44
45 void do_graphics_upload(char *filename)
46 {
47         StrBuf *Line;
48         const char *MimeType;
49         wcsession *WCC = WC;
50         char buf[SIZ];
51         int bytes_remaining;
52         int pos = 0;
53         int thisblock;
54         bytes_remaining = WCC->upload_length;
55
56         if (havebstr("cancel_button")) {
57                 AppendImportantMessage(_("Graphics upload has been cancelled."), -1);
58                 display_main_menu();
59                 return;
60         }
61
62         if (WCC->upload_length == 0) {
63                 AppendImportantMessage(_("You didn't upload a file."), -1);
64                 display_main_menu();
65                 return;
66         }
67         
68         MimeType = GuessMimeType(ChrPtr(WCC->upload), bytes_remaining);
69         serv_printf("UIMG 1|%s|%s", MimeType, filename);
70
71         Line = NewStrBuf();
72         StrBuf_ServGetln(Line);
73         if (GetServerStatusMsg(Line, NULL, 1, 2) != 2) {
74                 display_main_menu();
75                 FreeStrBuf(&Line);
76                 return;
77         }
78         while (bytes_remaining) {
79                 thisblock = ((bytes_remaining > 4096) ? 4096 : bytes_remaining);
80                 serv_printf("WRIT %d", thisblock);
81         StrBuf_ServGetln(Line);
82         if (GetServerStatusMsg(Line, NULL, 1, 7) != 7) {
83                         serv_puts("UCLS 0");
84                         StrBuf_ServGetln(Line);
85                         display_main_menu();
86                         FreeStrBuf(&Line);
87                         return;
88                 }
89                 thisblock = extract_int(&buf[4], 0);
90                 serv_write(&ChrPtr(WCC->upload)[pos], thisblock);
91                 pos = pos + thisblock;
92                 bytes_remaining = bytes_remaining - thisblock;
93         }
94
95         serv_puts("UCLS 1");
96         StrBuf_ServGetln(Line);
97         if (*ChrPtr(Line) != 'x') {
98                 display_success(ChrPtr(Line) + 4);
99         
100         }
101         FreeStrBuf(&Line);
102
103 }
104
105
106 void edithellopic(void)    { do_graphics_upload("hello"); }
107 void editpic(void)         { do_graphics_upload("_userpic_"); }
108 void editgoodbuyepic(void) { do_graphics_upload("UIMG 1|%s|goodbuye"); }
109
110 /* The users photo display / upload facility */
111 void display_editpic(void) {
112         putbstr("__WHICHPIC", NewStrBufPlain(HKEY("_userpic_")));
113         putbstr("__PICDESC", NewStrBufPlain(_("your photo"), -1));
114         putbstr("__UPLURL", NewStrBufPlain(HKEY("editpic")));
115         display_graphics_upload("editpic");
116 }
117 /* room picture dispay / upload facility */
118 void display_editroompic(void) {
119         putbstr("__WHICHPIC", NewStrBufPlain(HKEY("_roompic_")));
120         putbstr("__PICDESC", NewStrBufPlain(_("the icon for this room"), -1));
121         putbstr("__UPLURL", NewStrBufPlain(HKEY("editroompic")));
122         display_graphics_upload("editroompic");
123 }
124
125 /* the greetingpage hello pic */
126 void display_edithello(void) {
127         putbstr("__WHICHPIC", NewStrBufPlain(HKEY("hello")));
128         putbstr("__PICDESC", NewStrBufPlain(_("the Greetingpicture for the login prompt"), -1));
129         putbstr("__UPLURL", NewStrBufPlain(HKEY("edithellopic")));
130         display_graphics_upload("edithellopic");
131 }
132
133 /* the logoff banner */
134 void display_editgoodbyepic(void) {
135         putbstr("__WHICHPIC", NewStrBufPlain(HKEY("UIMG 0|%s|goodbuye")));
136         putbstr("__PICDESC", NewStrBufPlain(_("the Logoff banner picture"), -1));
137         putbstr("__UPLURL", NewStrBufPlain(HKEY("editgoodbuyepic")));
138         display_graphics_upload("editgoodbuyepic");
139 }
140
141 void display_editfloorpic(void) {
142         StrBuf *PicAction;
143
144         PicAction = NewStrBuf();
145         StrBufPrintf(PicAction, "_floorpic_|%s", bstr("which_floor"));
146         putbstr("__WHICHPIC", PicAction);
147         putbstr("__PICDESC", NewStrBufPlain(_("the icon for this floor"), -1));
148         putbstr("__UPLURL", NewStrBufPlain(HKEY("editfloorpic")));
149         display_graphics_upload("editfloorpic");
150 }
151
152 void editroompic(void) {
153         char buf[SIZ];
154         snprintf(buf, SIZ, "_roompic_|%s",
155                  bstr("which_room"));
156         do_graphics_upload(buf);
157 }
158
159 void editfloorpic(void){
160         char buf[SIZ];
161         snprintf(buf, SIZ, "_floorpic_|%s",
162                  bstr("which_floor"));
163         do_graphics_upload(buf);
164 }
165
166 void 
167 InitModule_GRAPHICS
168 (void)
169 {
170         WebcitAddUrlHandler(HKEY("display_editpic"), "", 0, display_editpic, 0);
171         WebcitAddUrlHandler(HKEY("editpic"), "", 0, editpic, 0);
172         WebcitAddUrlHandler(HKEY("display_editroompic"), "", 0, display_editroompic, 0);
173         WebcitAddUrlHandler(HKEY("editroompic"), "", 0, editroompic, 0);
174         WebcitAddUrlHandler(HKEY("display_edithello"), "", 0, display_edithello, 0);
175         WebcitAddUrlHandler(HKEY("edithellopic"), "", 0, edithellopic, 0);
176         WebcitAddUrlHandler(HKEY("display_editgoodbuye"), "", 0, display_editgoodbyepic, 0);
177         WebcitAddUrlHandler(HKEY("editgoodbuyepic"), "", 0, editgoodbuyepic, 0);
178         WebcitAddUrlHandler(HKEY("display_editfloorpic"), "", 0, display_editfloorpic, 0);
179         WebcitAddUrlHandler(HKEY("editfloorpic"), "", 0, editfloorpic, 0);
180 }