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