* Cleaned up the rcs/cvs Id tags and leading comments at the top of some files
[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
48         if (prepend_html != NULL) {
49                 client_write(prepend_html, strlen(prepend_html));
50         }
51
52         serv_printf("LFLR");    /* FIXME put a real test here */
53         serv_gets(buf);
54         if (buf[0] != '1') {
55                 wprintf("<div id=\"banner\">\n");
56                 wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#770000\"><TR><TD>");
57                 wprintf("<SPAN CLASS=\"titlebar\">Error</SPAN>\n");
58                 wprintf("</TD></TR></TABLE>\n");
59                 wprintf("</div>\n<div id=\"content\">\n");
60                 wprintf("%s<br />\n", &buf[4]);
61                 wDumpContent(1);
62                 return;
63         }
64
65         svprintf("BOXTITLE", WCS_STRING, "Floor configuration");
66         do_template("beginbox");
67
68         wprintf("<TABLE BORDER=1 WIDTH=100%>\n"
69                 "<TR><TH>Floor number</TH>"
70                 "<TH>Floor name</TH>"
71                 "<TH>Number of rooms</TH></TR>\n"
72         );
73
74         while (serv_gets(buf), strcmp(buf, "000")) {
75                 floornum = extract_int(buf, 0);
76                 extract(floorname, buf, 1);
77                 refcount = extract_int(buf, 2);
78
79                 wprintf("<TR><TD><TABLE border=0><TR><TD>%d", floornum);
80                 if (refcount == 0) {
81                         wprintf("</TD><TD>"
82                                 "<A HREF=\"/delete_floor?floornum=%d\">"
83                                 "<FONT SIZE=-1>(delete floor)</A>"
84                                 "</FONT><br />", floornum
85                         );
86                 }
87                 wprintf("<FONT SIZE=-1>"
88                         "<A HREF=\"/display_editfloorpic&"
89                         "which_floor=%d\">(edit graphic)</A>",
90                         floornum);
91                 wprintf("</TD></TR></TABLE>");
92                 wprintf("</TD>");
93
94                 wprintf("<TD>"
95                         "<FORM METHOD=\"POST\" ACTION=\"/rename_floor\">"
96                         "<INPUT TYPE=\"hidden\" NAME=\"floornum\" "
97                         "VALUE=\"%d\">"
98                         "<INPUT TYPE=\"text\" NAME=\"floorname\" "
99                         "VALUE=\"%s\" MAXLENGTH=\"250\">\n",
100                         floornum, floorname);
101                 wprintf("<INPUT TYPE=\"SUBMIT\" NAME=\"sc\" "
102                         "VALUE=\"Change name\">"
103                         "</FORM></TD>");
104
105                 wprintf("<TD>%d</TD></TR>\n", refcount);
106         }
107
108         wprintf("<TR><TD>&nbsp;</TD>"
109                 "<TD><FORM METHOD=\"POST\" ACTION=\"/create_floor\">"
110                 "<INPUT TYPE=\"text\" NAME=\"floorname\" "
111                 "MAXLENGTH=\"250\">\n"
112                 "<INPUT TYPE=\"SUBMIT\" NAME=\"sc\" "
113                 "VALUE=\"Create new floor\">"
114                 "</FORM></TD>"
115                 "<TD>&nbsp;</TD></TR>\n");
116
117         wprintf("</TABLE>\n");
118         do_template("endbox");
119         wDumpContent(1);
120 }
121
122
123
124 void delete_floor(void) {
125         int floornum;
126         char buf[SIZ];
127         char message[SIZ];
128
129         floornum = atoi(bstr("floornum"));
130
131         serv_printf("KFLR %d|1", floornum);
132         serv_gets(buf);
133
134         if (buf[0] == '2') {
135                 sprintf(message, "<B><I>Floor has been deleted."
136                                 "</I></B><br /><br />\n");
137         }
138         else {
139                 sprintf(message, "<B><I>%s</I></B>><br />", &buf[4]);
140         }
141
142         display_floorconfig(message);
143 }
144
145
146 void create_floor(void) {
147         char buf[SIZ];
148         char message[SIZ];
149         char floorname[SIZ];
150
151         strcpy(floorname, bstr("floorname"));
152
153         serv_printf("CFLR %s|1", floorname);
154         serv_gets(buf);
155
156         sprintf(message, "<B><I>%s</I></B>><br />", &buf[4]);
157
158         display_floorconfig(message);
159 }
160
161
162 void rename_floor(void) {
163         int floornum;
164         char buf[SIZ];
165         char message[SIZ];
166         char floorname[SIZ];
167
168         floornum = atoi(bstr("floornum"));
169         strcpy(floorname, bstr("floorname"));
170
171         serv_printf("EFLR %d|%s", floornum, floorname);
172         serv_gets(buf);
173
174         sprintf(message, "<B><I>%s</I></B>><br />", &buf[4]);
175
176         display_floorconfig(message);
177 }
178
179