* All OS-level includes are now included from webcit.h instead of from
[citadel.git] / webcit / floors.c
1 /*
2  * $Id$
3  *
4  * Administrative screens for floor maintenance
5  *
6  */
7
8
9 #include "webcit.h"
10 #include "webserver.h"
11
12
13
14
15 /*
16  * Display floor configuration.  If prepend_html is not NULL, its contents
17  * will be displayed at the top of the screen.
18  */
19 void display_floorconfig(char *prepend_html)
20 {
21         char buf[SIZ];
22
23         int floornum;
24         char floorname[SIZ];
25         int refcount;
26
27         output_headers(1, 1, 2, 0, 0, 0, 0);
28         wprintf("<div id=\"banner\">\n"
29                 "<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#444455\"><TR><TD>"
30                 "<SPAN CLASS=\"titlebar\">Add/change/delete floors</SPAN>"
31                 "</TD></TR></TABLE>\n"
32                 "</div>\n<div id=\"content\">\n"
33         );
34                                                                                                                              
35         if (prepend_html != NULL) {
36                 wprintf("<br /><b><i>");
37                 client_write(prepend_html, strlen(prepend_html));
38                 wprintf("</i></b><br /><br />\n");
39         }
40
41         serv_printf("LFLR");
42         serv_getln(buf, sizeof buf);
43         if (buf[0] != '1') {
44                 wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#770000\"><TR><TD>");
45                 wprintf("<SPAN CLASS=\"titlebar\">Error</SPAN>\n");
46                 wprintf("</TD></TR></TABLE>\n");
47                 wprintf("%s<br />\n", &buf[4]);
48                 wDumpContent(1);
49                 return;
50         }
51
52         wprintf("<div id=\"fix_scrollbar_bug\">"
53                 "<TABLE BORDER=1 WIDTH=100%% bgcolor=\"#ffffff\">\n"
54                 "<TR><TH>Floor number</TH>"
55                 "<TH>Floor name</TH>"
56                 "<TH>Number of rooms</TH></TR>\n"
57         );
58
59         while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
60                 floornum = extract_int(buf, 0);
61                 extract_token(floorname, buf, 1, '|', sizeof floorname);
62                 refcount = extract_int(buf, 2);
63
64                 wprintf("<TR><TD><TABLE border=0><TR><TD>%d", floornum);
65                 if (refcount == 0) {
66                         wprintf("</TD><TD>"
67                                 "<A HREF=\"/delete_floor?floornum=%d\">"
68                                 "<FONT SIZE=-1>(delete floor)</A>"
69                                 "</FONT><br />", floornum
70                         );
71                 }
72                 wprintf("<FONT SIZE=-1>"
73                         "<A HREF=\"/display_editfloorpic&"
74                         "which_floor=%d\">(edit graphic)</A>",
75                         floornum);
76                 wprintf("</TD></TR></TABLE>");
77                 wprintf("</TD>");
78
79                 wprintf("<TD>"
80                         "<FORM METHOD=\"POST\" ACTION=\"/rename_floor\">"
81                         "<INPUT TYPE=\"hidden\" NAME=\"floornum\" "
82                         "VALUE=\"%d\">"
83                         "<INPUT TYPE=\"text\" NAME=\"floorname\" "
84                         "VALUE=\"%s\" MAXLENGTH=\"250\">\n",
85                         floornum, floorname);
86                 wprintf("<INPUT TYPE=\"SUBMIT\" NAME=\"sc\" "
87                         "VALUE=\"Change name\">"
88                         "</FORM></TD>");
89
90                 wprintf("<TD>%d</TD></TR>\n", refcount);
91         }
92
93         wprintf("<TR><TD>&nbsp;</TD>"
94                 "<TD><FORM METHOD=\"POST\" ACTION=\"/create_floor\">"
95                 "<INPUT TYPE=\"text\" NAME=\"floorname\" "
96                 "MAXLENGTH=\"250\">\n"
97                 "<INPUT TYPE=\"SUBMIT\" NAME=\"sc\" "
98                 "VALUE=\"Create new floor\">"
99                 "</FORM></TD>"
100                 "<TD>&nbsp;</TD></TR>\n");
101
102         wprintf("</table></div>\n");
103         wDumpContent(1);
104 }
105
106
107
108 void delete_floor(void) {
109         int floornum;
110         char buf[SIZ];
111         char message[SIZ];
112
113         floornum = atoi(bstr("floornum"));
114
115         serv_printf("KFLR %d|1", floornum);
116         serv_getln(buf, sizeof buf);
117
118         if (buf[0] == '2') {
119                 sprintf(message, "Floor has been deleted.");
120         }
121         else {
122                 sprintf(message, "%s", &buf[4]);
123         }
124
125         display_floorconfig(message);
126 }
127
128
129 void create_floor(void) {
130         char buf[SIZ];
131         char message[SIZ];
132         char floorname[SIZ];
133
134         strcpy(floorname, bstr("floorname"));
135
136         serv_printf("CFLR %s|1", floorname);
137         serv_getln(buf, sizeof buf);
138
139         if (buf[0] == '2') {
140                 sprintf(message, "New floor has been created.");
141         } else {
142                 sprintf(message, "%s", &buf[4]);
143         }
144
145         display_floorconfig(message);
146 }
147
148
149 void rename_floor(void) {
150         int floornum;
151         char buf[SIZ];
152         char message[SIZ];
153         char floorname[SIZ];
154
155         floornum = atoi(bstr("floornum"));
156         strcpy(floorname, bstr("floorname"));
157
158         serv_printf("EFLR %d|%s", floornum, floorname);
159         serv_getln(buf, sizeof buf);
160
161         sprintf(message, "%s", &buf[4]);
162
163         display_floorconfig(message);
164 }
165
166