* New COND:FLOOR:NROOMS : whether this floor has n-rooms
[citadel.git] / webcit / floors.c
1 /*
2  * $Id$
3  *
4  * Copyright (c) 1996-2010 by the citadel.org team
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3 of the License, or
9  * (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 #include "webserver.h"
23
24
25
26
27 /*
28  * Display floor configuration.  If prepend_html is not NULL, its contents
29  * will be displayed at the top of the screen.
30  */
31 void display_floorconfig(StrBuf *prepend_html)
32 {
33         char buf[SIZ];
34
35         int floornum;
36         char floorname[SIZ];
37         int refcount;
38
39         output_headers(1, 1, 2, 0, 0, 0);
40         wc_printf("<div id=\"banner\">\n");
41         wc_printf("<h1>");
42         wc_printf(_("Add/change/delete floors"));
43         wc_printf("</h1>");
44         wc_printf("</div>\n");
45
46         wc_printf("<div id=\"content\" class=\"service\">\n");
47                                                                                                                              
48         if (prepend_html != NULL) {
49                 wc_printf("<br /><b><i>");
50                 StrBufAppendBuf(WC->WBuf, prepend_html, 0);
51                 wc_printf("</i></b><br /><br />\n");
52         }
53
54         serv_printf("LFLR");
55         serv_getln(buf, sizeof buf);
56         if (buf[0] != '1') {
57                 wc_printf("<TABLE  class=\"floors_config\"><TR><TD>");
58                 wc_printf("<SPAN CLASS=\"titlebar\">");
59                 wc_printf(_("Error"));
60                 wc_printf("</SPAN>\n");
61                 wc_printf("</TD></TR></TABLE>\n");
62                 wc_printf("%s<br />\n", &buf[4]);
63                 wDumpContent(1);
64                 return;
65         }
66
67         wc_printf("<div class=\"fix_scrollbar_bug\">"
68                 "<TABLE BORDER=1 WIDTH=100%% bgcolor=\"#ffffff\">\n"
69                 "<TR><TH>");
70         wc_printf(_("Floor number"));
71         wc_printf("</TH><TH>");
72         wc_printf(_("Floor name"));
73         wc_printf("</TH><TH>");
74         wc_printf(_("Number of rooms"));
75         wc_printf("</TH><TH>");
76         wc_printf(_("Floor CSS"));
77         wc_printf("</TH></TR>\n");
78
79         while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
80                 floornum = extract_int(buf, 0);
81                 extract_token(floorname, buf, 1, '|', sizeof floorname);
82                 refcount = extract_int(buf, 2);
83
84                 wc_printf("<TR><TD><TABLE border=0><TR><TD>%d", floornum);
85                 if (refcount == 0) {
86                         wc_printf("</TD><TD>"
87                                 "<a href=\"delete_floor?floornum=%d\">"
88                                 "<FONT SIZE=-1>", floornum);
89                         wc_printf(_("(delete floor)"));
90                         wc_printf("</A></FONT><br />");
91                 }
92                 wc_printf("<FONT SIZE=-1>"
93                         "<a href=\"display_editfloorpic?"
94                         "which_floor=%d\">", floornum);
95                 wc_printf(_("(edit graphic)"));
96                 wc_printf("</A></TD></TR></TABLE>");
97                 wc_printf("</TD>");
98
99                 wc_printf("<TD>"
100                         "<FORM METHOD=\"POST\" action=\"rename_floor\">"
101                         "<INPUT TYPE=\"hidden\" NAME=\"floornum\" "
102                         "VALUE=\"%d\">"
103                         "<INPUT TYPE=\"text\" NAME=\"floorname\" "
104                         "VALUE=\"%s\" MAXLENGTH=\"250\">\n",
105                         floornum, floorname);
106                 wc_printf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
107                 wc_printf("<INPUT TYPE=\"SUBMIT\" NAME=\"sc\" "
108                         "VALUE=\"%s\">"
109                         "</FORM></TD>", _("Change name"));
110
111                 wc_printf("<TD>%d</TD>\n", refcount);
112
113                 wc_printf("<TD>"
114                         "<FORM METHOD=\"POST\" action=\"set_floor_css\">"
115                         "<INPUT TYPE=\"hidden\" NAME=\"floornum\" "
116                         "VALUE=\"%d\">"
117                         "<INPUT TYPE=\"text\" NAME=\"floorcss\" "
118                         "VALUE=\"%s\" MAXLENGTH=\"250\">\n",
119                         floornum, floorname);
120                 wc_printf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
121                 wc_printf("<INPUT TYPE=\"SUBMIT\" NAME=\"sc\" "
122                         "VALUE=\"%s\">"
123                         "</FORM></TD>", _("Change CSS"));
124
125                 wc_printf("</TR>\n");
126         }
127
128         wc_printf("<TR><TD>&nbsp;</TD>"
129                 "<TD><FORM METHOD=\"POST\" action=\"create_floor\">");
130         wc_printf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
131         wc_printf("<INPUT TYPE=\"text\" NAME=\"floorname\" "
132                 "MAXLENGTH=\"250\">\n"
133                 "<INPUT TYPE=\"SUBMIT\" NAME=\"sc\" "
134                 "VALUE=\"%s\">"
135                 "</FORM></TD>"
136                 "<TD>&nbsp;</TD></TR>\n", _("Create new floor"));
137
138         wc_printf("</table></div>\n");
139         wDumpContent(1);
140 }
141
142
143 /*
144  * delete the actual floor
145  */
146 void delete_floor(void) {
147         int floornum;
148         StrBuf *Buf;
149         const char *Err;
150                 
151         floornum = ibstr("floornum");
152         Buf = NewStrBuf();
153         serv_printf("KFLR %d|1", floornum);
154         
155         StrBufTCP_read_line(Buf, &WC->serv_sock, 0, &Err);
156
157         if (GetServerStatus(Buf, NULL) == 2) {
158                 StrBufPlain(Buf, _("Floor has been deleted."),-1);
159         }
160         else {
161                 StrBufCutLeft(Buf, 4);
162         }
163
164         FlushRoomlist();
165         display_floorconfig(Buf);
166         FreeStrBuf(&Buf);
167 }
168
169 /*
170  * start creating a new floor
171  */
172 void create_floor(void) {
173         StrBuf *Buf;
174         const char *Err;
175
176         Buf = NewStrBuf();
177         serv_printf("CFLR %s|1", bstr("floorname"));
178         StrBufTCP_read_line(Buf, &WC->serv_sock, 0, &Err);
179
180         if (GetServerStatus(Buf, NULL) == 2) {
181                 StrBufPlain(Buf, _("New floor has been created."),-1);
182         }
183         else {
184                 StrBufCutLeft(Buf, 4);
185         }
186
187         FlushRoomlist();
188         display_floorconfig(Buf);
189         FreeStrBuf(&Buf);
190 }
191
192
193 /*
194  * rename this floor
195  */
196 void rename_floor(void) {
197         StrBuf *Buf;
198
199         Buf = NewStrBuf();
200         FlushRoomlist();
201
202         serv_printf("EFLR %d|%s", ibstr("floornum"), bstr("floorname"));
203         StrBuf_ServGetln(Buf);
204
205         StrBufCutLeft(Buf, 4);
206
207         display_floorconfig(Buf);
208         FreeStrBuf(&Buf);
209 }
210
211 void _display_floorconfig(void) {display_floorconfig(NULL);}
212
213 void 
214 InitModule_FLOORS
215 (void)
216 {
217         WebcitAddUrlHandler(HKEY("delete_floor"), "", 0, delete_floor, 0);
218         WebcitAddUrlHandler(HKEY("rename_floor"), "", 0, rename_floor, 0);
219         WebcitAddUrlHandler(HKEY("create_floor"), "", 0, create_floor, 0);
220         WebcitAddUrlHandler(HKEY("display_floorconfig"), "", 0, _display_floorconfig, 0);
221 }