37b471594438fa2483bfb39e489a4da94095bc26
[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 #include "webserver.h"
28
29
30
31
32 /*
33  * Display floor configuration.  If prepend_html is not NULL, its contents
34  * will be displayed at the top of the screen.
35  */
36 void display_floorconfig(char *prepend_html)
37 {
38         char buf[SIZ];
39
40         int floornum;
41         char floorname[SIZ];
42         int refcount;
43
44         output_headers(3);
45
46         if (prepend_html != NULL) {
47                 client_write(prepend_html, strlen(prepend_html));
48         }
49
50         serv_printf("LFLR");    /* FIXME put a real test here */
51         serv_gets(buf);
52         if (buf[0] != '1') {
53                 wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#770000\"><TR><TD>");
54                 wprintf("<SPAN CLASS=\"titlebar\">Error</SPAN>\n");
55                 wprintf("</TD></TR></TABLE><BR>\n");
56                 wprintf("%s<BR>\n", &buf[4]);
57                 wDumpContent(1);
58                 return;
59         }
60
61         svprintf("BOXTITLE", WCS_STRING, "Floor configuration");
62         do_template("beginbox");
63
64         wprintf("<TABLE BORDER=1 WIDTH=100%>\n"
65                 "<TR><TH>Floor number</TH>"
66                 "<TH>Floor name</TH>"
67                 "<TH>Number of rooms</TH></TR>\n"
68         );
69
70         while (serv_gets(buf), strcmp(buf, "000")) {
71                 floornum = extract_int(buf, 0);
72                 extract(floorname, buf, 1);
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>(delete floor)</A>"
80                                 "</FONT><BR>", floornum
81                         );
82                 }
83                 wprintf("<FONT SIZE=-1>"
84                         "<A HREF=\"/display_editfloorpic&"
85                         "which_floor=%d\">(edit graphic)</A>",
86                         floornum);
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         do_template("endbox");
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