ebcafcaef81e8998a1f65d9e4c59476a929447fc
[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>%d", floornum);
78                 if (refcount == 0) {
79                         wprintf(" <A HREF=\"/delete_floor?floornum=%d\">"
80                                 "(delete floor)</A>");
81                 }
82                 wprintf("</TD>");
83
84                 wprintf("<TD>"
85                         "<FORM METHOD=\"POST\" ACTION=\"/rename_floor\">"
86                         "<INPUT TYPE=\"hidden\" NAME=\"floornum\" "
87                         "VALUE=\"%d\">"
88                         "<INPUT TYPE=\"text\" NAME=\"floorname\" "
89                         "VALUE=\"%s\" MAXLENGTH=\"250\">\n",
90                         floornum, floorname);
91                 wprintf("<INPUT TYPE=\"SUBMIT\" NAME=\"sc\" "
92                         "VALUE=\"Change name\">"
93                         "</FORM></TD>");
94
95                 wprintf("<TD>%d</TD></TR>\n", refcount);
96         }
97
98         wprintf("<TR><TD>&nbsp;</TD>"
99                 "<TD><FORM METHOD=\"POST\" ACTION=\"/create_floor\">"
100                 "<INPUT TYPE=\"text\" NAME=\"floorname\" "
101                 "MAXLENGTH=\"250\">\n"
102                 "<INPUT TYPE=\"SUBMIT\" NAME=\"sc\" "
103                 "VALUE=\"Create new floor\">"
104                 "</FORM></TD>"
105                 "<TD>&nbsp;</TD></TR>\n");
106
107         wprintf("</TABLE>\n");
108
109         wDumpContent(1);
110 }
111
112
113
114 void delete_floor(void) {
115         int floornum;
116         char buf[SIZ];
117         char message[SIZ];
118
119         floornum = atoi(bstr("floornum"));
120
121         serv_printf("KFLR %d|1", floornum);
122         serv_gets(buf);
123
124         if (buf[0] == '2') {
125                 sprintf(message, "<B><I>Floor has been deleted."
126                                 "</I></B><BR><BR>\n");
127         }
128         else {
129                 sprintf(message, "<B><I>%s</I></B>><BR>", &buf[4]);
130         }
131
132         display_floorconfig(message);
133 }
134
135
136 void create_floor(void) {
137         char buf[SIZ];
138         char message[SIZ];
139         char floorname[SIZ];
140
141         strcpy(floorname, bstr("floorname"));
142
143         serv_printf("CFLR %s|1", floorname);
144         serv_gets(buf);
145
146         sprintf(message, "<B><I>%s</I></B>><BR>", &buf[4]);
147
148         display_floorconfig(message);
149 }
150
151
152 void rename_floor(void) {
153         int floornum;
154         char buf[SIZ];
155         char message[SIZ];
156         char floorname[SIZ];
157
158         floornum = atoi(bstr("floornum"));
159         strcpy(floorname, bstr("floorname"));
160
161         serv_printf("EFLR %d|%s", floornum, floorname);
162         serv_gets(buf);
163
164         sprintf(message, "<B><I>%s</I></B>><BR>", &buf[4]);
165
166         display_floorconfig(message);
167 }
168
169