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