3ea670d8fc1f6730513874ecd565a59103682550
[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(char *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                 "<TABLE class=\"floors_banner\"><TR><TD>"
33                 "<SPAN CLASS=\"titlebar\">");
34         wprintf(_("Add/change/delete floors"));
35         wprintf("</SPAN>"
36                 "</TD></TR></TABLE>\n"
37                 "</div>\n<div id=\"content\">\n"
38         );
39                                                                                                                              
40         if (prepend_html != NULL) {
41                 wprintf("<br /><b><i>");
42                 client_write(prepend_html, strlen(prepend_html));
43                 wprintf("</i></b><br /><br />\n");
44         }
45
46         serv_printf("LFLR");
47         serv_getln(buf, sizeof buf);
48         if (buf[0] != '1') {
49                 wprintf("<TABLE  class=\"floors_config\"><TR><TD>");
50                 wprintf("<SPAN CLASS=\"titlebar\">");
51                 wprintf(_("Error"));
52                 wprintf("</SPAN>\n");
53                 wprintf("</TD></TR></TABLE>\n");
54                 wprintf("%s<br />\n", &buf[4]);
55                 wDumpContent(1);
56                 return;
57         }
58
59         wprintf("<div class=\"fix_scrollbar_bug\">"
60                 "<TABLE BORDER=1 WIDTH=100%% bgcolor=\"#ffffff\">\n"
61                 "<TR><TH>");
62         wprintf(_("Floor number"));
63         wprintf("</TH><TH>");
64         wprintf(_("Floor name"));
65         wprintf("</TH><TH>");
66         wprintf(_("Number of rooms"));
67         wprintf("</TH><TH>");
68         wprintf(_("Floor CSS"));
69         wprintf("</TH></TR>\n");
70
71         while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
72                 floornum = extract_int(buf, 0);
73                 extract_token(floorname, buf, 1, '|', sizeof floorname);
74                 refcount = extract_int(buf, 2);
75
76                 wprintf("<TR><TD><TABLE border=0><TR><TD>%d", floornum);
77                 if (refcount == 0) {
78                         wprintf("</TD><TD>"
79                                 "<a href=\"delete_floor?floornum=%d\">"
80                                 "<FONT SIZE=-1>", floornum);
81                         wprintf(_("(delete floor)"));
82                         wprintf("</A></FONT><br />");
83                 }
84                 wprintf("<FONT SIZE=-1>"
85                         "<a href=\"display_editfloorpic&"
86                         "which_floor=%d\">", floornum);
87                 wprintf(_("(edit graphic)"));
88                 wprintf("</A></TD></TR></TABLE>");
89                 wprintf("</TD>");
90
91                 wprintf("<TD>"
92                         "<FORM METHOD=\"POST\" action=\"rename_floor\">"
93                         "<INPUT TYPE=\"hidden\" NAME=\"floornum\" "
94                         "VALUE=\"%d\">"
95                         "<INPUT TYPE=\"text\" NAME=\"floorname\" "
96                         "VALUE=\"%s\" MAXLENGTH=\"250\">\n",
97                         floornum, floorname);
98                 wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%ld\">\n", WC->nonce);
99                 wprintf("<INPUT TYPE=\"SUBMIT\" NAME=\"sc\" "
100                         "VALUE=\"%s\">"
101                         "</FORM></TD>", _("Change name"));
102
103                 wprintf("<TD>%d</TD>\n", refcount);
104
105                 wprintf("<TD>"
106                         "<FORM METHOD=\"POST\" action=\"set_floor_css\">"
107                         "<INPUT TYPE=\"hidden\" NAME=\"floornum\" "
108                         "VALUE=\"%d\">"
109                         "<INPUT TYPE=\"text\" NAME=\"floorcss\" "
110                         "VALUE=\"%s\" MAXLENGTH=\"250\">\n",
111                         floornum, floorname);
112                 wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%ld\">\n", WC->nonce);
113                 wprintf("<INPUT TYPE=\"SUBMIT\" NAME=\"sc\" "
114                         "VALUE=\"%s\">"
115                         "</FORM></TD>", _("Change CSS"));
116
117                 wprintf("</TR>\n");
118         }
119
120         wprintf("<TR><TD>&nbsp;</TD>"
121                 "<TD><FORM METHOD=\"POST\" action=\"create_floor\">");
122         wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%ld\">\n", WC->nonce);
123         wprintf("<INPUT TYPE=\"text\" NAME=\"floorname\" "
124                 "MAXLENGTH=\"250\">\n"
125                 "<INPUT TYPE=\"SUBMIT\" NAME=\"sc\" "
126                 "VALUE=\"%s\">"
127                 "</FORM></TD>"
128                 "<TD>&nbsp;</TD></TR>\n", _("Create new floor"));
129
130         wprintf("</table></div>\n");
131         wDumpContent(1);
132 }
133
134
135 /**
136  * \brief delete the actual floor
137  */
138 void delete_floor(void) {
139         int floornum;
140         char buf[SIZ];
141         char message[SIZ];
142
143         floornum = atoi(bstr("floornum"));
144
145         serv_printf("KFLR %d|1", floornum);
146         serv_getln(buf, sizeof buf);
147
148         if (buf[0] == '2') {
149                 sprintf(message, _("Floor has been deleted."));
150         }
151         else {
152                 sprintf(message, "%s", &buf[4]);
153         }
154
155         display_floorconfig(message);
156 }
157
158 /**
159  * \brief tart creating a new floor
160  */
161 void create_floor(void) {
162         char buf[SIZ];
163         char message[SIZ];
164         char floorname[SIZ];
165
166         strcpy(floorname, bstr("floorname"));
167
168         serv_printf("CFLR %s|1", floorname);
169         serv_getln(buf, sizeof buf);
170
171         if (buf[0] == '2') {
172                 sprintf(message, _("New floor has been created."));
173         } else {
174                 sprintf(message, "%s", &buf[4]);
175         }
176
177         display_floorconfig(message);
178 }
179
180 /**
181  * \brief rename this floor
182  */
183 void rename_floor(void) {
184         int floornum;
185         char buf[SIZ];
186         char message[SIZ];
187         char floorname[SIZ];
188
189         floornum = atoi(bstr("floornum"));
190         strcpy(floorname, bstr("floorname"));
191
192         serv_printf("EFLR %d|%s", floornum, floorname);
193         serv_getln(buf, sizeof buf);
194
195         sprintf(message, "%s", &buf[4]);
196
197         display_floorconfig(message);
198 }
199
200
201 /*@}*/