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