a0b4edf1061cd5a6776576671e9a8e430bbf73e6
[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("<div id=\"fix_scrollbar_bug\">"
72                 "<TABLE BORDER=1 WIDTH=100%% bgcolor=\"#ffffff\">\n"
73                 "<TR><TH>Floor number</TH>"
74                 "<TH>Floor name</TH>"
75                 "<TH>Number of rooms</TH></TR>\n"
76         );
77
78         while (serv_gets(buf), strcmp(buf, "000")) {
79                 floornum = extract_int(buf, 0);
80                 extract(floorname, buf, 1);
81                 refcount = extract_int(buf, 2);
82
83                 wprintf("<TR><TD><TABLE border=0><TR><TD>%d", floornum);
84                 if (refcount == 0) {
85                         wprintf("</TD><TD>"
86                                 "<A HREF=\"/delete_floor?floornum=%d\">"
87                                 "<FONT SIZE=-1>(delete floor)</A>"
88                                 "</FONT><br />", floornum
89                         );
90                 }
91                 wprintf("<FONT SIZE=-1>"
92                         "<A HREF=\"/display_editfloorpic&"
93                         "which_floor=%d\">(edit graphic)</A>",
94                         floornum);
95                 wprintf("</TD></TR></TABLE>");
96                 wprintf("</TD>");
97
98                 wprintf("<TD>"
99                         "<FORM METHOD=\"POST\" ACTION=\"/rename_floor\">"
100                         "<INPUT TYPE=\"hidden\" NAME=\"floornum\" "
101                         "VALUE=\"%d\">"
102                         "<INPUT TYPE=\"text\" NAME=\"floorname\" "
103                         "VALUE=\"%s\" MAXLENGTH=\"250\">\n",
104                         floornum, floorname);
105                 wprintf("<INPUT TYPE=\"SUBMIT\" NAME=\"sc\" "
106                         "VALUE=\"Change name\">"
107                         "</FORM></TD>");
108
109                 wprintf("<TD>%d</TD></TR>\n", refcount);
110         }
111
112         wprintf("<TR><TD>&nbsp;</TD>"
113                 "<TD><FORM METHOD=\"POST\" ACTION=\"/create_floor\">"
114                 "<INPUT TYPE=\"text\" NAME=\"floorname\" "
115                 "MAXLENGTH=\"250\">\n"
116                 "<INPUT TYPE=\"SUBMIT\" NAME=\"sc\" "
117                 "VALUE=\"Create new floor\">"
118                 "</FORM></TD>"
119                 "<TD>&nbsp;</TD></TR>\n");
120
121         wprintf("</table></div>\n");
122         wDumpContent(1);
123 }
124
125
126
127 void delete_floor(void) {
128         int floornum;
129         char buf[SIZ];
130         char message[SIZ];
131
132         floornum = atoi(bstr("floornum"));
133
134         serv_printf("KFLR %d|1", floornum);
135         serv_gets(buf);
136
137         if (buf[0] == '2') {
138                 sprintf(message, "Floor has been deleted.");
139         }
140         else {
141                 sprintf(message, "%s", &buf[4]);
142         }
143
144         display_floorconfig(message);
145 }
146
147
148 void create_floor(void) {
149         char buf[SIZ];
150         char message[SIZ];
151         char floorname[SIZ];
152
153         strcpy(floorname, bstr("floorname"));
154
155         serv_printf("CFLR %s|1", floorname);
156         serv_gets(buf);
157
158         if (buf[0] == '2') {
159                 sprintf(message, "New floor has been created.");
160         } else {
161                 sprintf(message, "%s", &buf[4]);
162         }
163
164         display_floorconfig(message);
165 }
166
167
168 void rename_floor(void) {
169         int floornum;
170         char buf[SIZ];
171         char message[SIZ];
172         char floorname[SIZ];
173
174         floornum = atoi(bstr("floornum"));
175         strcpy(floorname, bstr("floorname"));
176
177         serv_printf("EFLR %d|%s", floornum, floorname);
178         serv_gets(buf);
179
180         sprintf(message, "%s", &buf[4]);
181
182         display_floorconfig(message);
183 }
184
185