* *** HUGE CHANGES *** *** WARNING: NOT FULLY FUNCTIONAL ***
[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(1, 1, 2, 0, 0, 0, 0);
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("<div id=\"banner\">\n");
54                 wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#770000\"><TR><TD>");
55                 wprintf("<SPAN CLASS=\"titlebar\">Error</SPAN>\n");
56                 wprintf("</TD></TR></TABLE>\n");
57                 wprintf("</div><div id=\"text\">\n");
58                 wprintf("%s<br />\n", &buf[4]);
59                 wDumpContent(1);
60                 return;
61         }
62
63         svprintf("BOXTITLE", WCS_STRING, "Floor configuration");
64         do_template("beginbox");
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 />", floornum
83                         );
84                 }
85                 wprintf("<FONT SIZE=-1>"
86                         "<A HREF=\"/display_editfloorpic&"
87                         "which_floor=%d\">(edit graphic)</A>",
88                         floornum);
89                 wprintf("</TD></TR></TABLE>");
90                 wprintf("</TD>");
91
92                 wprintf("<TD>"
93                         "<FORM METHOD=\"POST\" ACTION=\"/rename_floor\">"
94                         "<INPUT TYPE=\"hidden\" NAME=\"floornum\" "
95                         "VALUE=\"%d\">"
96                         "<INPUT TYPE=\"text\" NAME=\"floorname\" "
97                         "VALUE=\"%s\" MAXLENGTH=\"250\">\n",
98                         floornum, floorname);
99                 wprintf("<INPUT TYPE=\"SUBMIT\" NAME=\"sc\" "
100                         "VALUE=\"Change name\">"
101                         "</FORM></TD>");
102
103                 wprintf("<TD>%d</TD></TR>\n", refcount);
104         }
105
106         wprintf("<TR><TD>&nbsp;</TD>"
107                 "<TD><FORM METHOD=\"POST\" ACTION=\"/create_floor\">"
108                 "<INPUT TYPE=\"text\" NAME=\"floorname\" "
109                 "MAXLENGTH=\"250\">\n"
110                 "<INPUT TYPE=\"SUBMIT\" NAME=\"sc\" "
111                 "VALUE=\"Create new floor\">"
112                 "</FORM></TD>"
113                 "<TD>&nbsp;</TD></TR>\n");
114
115         wprintf("</TABLE>\n");
116         do_template("endbox");
117         wDumpContent(1);
118 }
119
120
121
122 void delete_floor(void) {
123         int floornum;
124         char buf[SIZ];
125         char message[SIZ];
126
127         floornum = atoi(bstr("floornum"));
128
129         serv_printf("KFLR %d|1", floornum);
130         serv_gets(buf);
131
132         if (buf[0] == '2') {
133                 sprintf(message, "<B><I>Floor has been deleted."
134                                 "</I></B><br /><br />\n");
135         }
136         else {
137                 sprintf(message, "<B><I>%s</I></B>><br />", &buf[4]);
138         }
139
140         display_floorconfig(message);
141 }
142
143
144 void create_floor(void) {
145         char buf[SIZ];
146         char message[SIZ];
147         char floorname[SIZ];
148
149         strcpy(floorname, bstr("floorname"));
150
151         serv_printf("CFLR %s|1", floorname);
152         serv_gets(buf);
153
154         sprintf(message, "<B><I>%s</I></B>><br />", &buf[4]);
155
156         display_floorconfig(message);
157 }
158
159
160 void rename_floor(void) {
161         int floornum;
162         char buf[SIZ];
163         char message[SIZ];
164         char floorname[SIZ];
165
166         floornum = atoi(bstr("floornum"));
167         strcpy(floorname, bstr("floorname"));
168
169         serv_printf("EFLR %d|%s", floornum, floorname);
170         serv_gets(buf);
171
172         sprintf(message, "<B><I>%s</I></B>><br />", &buf[4]);
173
174         display_floorconfig(message);
175 }
176
177