]> code.citadel.org Git - citadel.git/blob - webcit/floors.c
* Repaired all my b0rken COLOR tags
[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("<SPAN CLASS=\"titlebar\">Error</SPAN>\n");
54                 wprintf("</TD></TR></TABLE><BR>\n");
55                 wprintf("%s<BR>\n", &buf[4]);
56                 wDumpContent(1);
57                 return;
58         }
59
60         wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#007700\"><TR><TD>"
61                 "<SPAN CLASS=\"titlebar\">Floor configuration</SPAN>"
62                 "</TD></TR></TABLE>\n"
63         );
64
65         wprintf("<TABLE BORDER=1 WIDTH=100%>\n"
66                 "<TR><TH>Floor number</TH>"
67                 "<TH>Floor name</TH>"
68                 "<TH>Number of rooms</TH></TR>\n"
69         );
70
71         while (serv_gets(buf), strcmp(buf, "000")) {
72                 floornum = extract_int(buf, 0);
73                 extract(floorname, buf, 1);
74                 refcount = extract_int(buf, 2);
75
76                 wprintf("<TR><TD><TABLE border=0><TR><TD>%d", floornum);
77                 if (refcount == 0) {
78                         wprintf("</TD><TD>"
79                                 "<A HREF=\"/delete_floor?floornum=%d\">"
80                                 "<FONT SIZE=-1>(delete floor)</A>"
81                                 "</FONT><BR>", floornum
82                         );
83                 }
84                 wprintf("<FONT SIZE=-1>"
85                         "<A HREF=\"/display_editfloorpic&"
86                         "which_floor=%d\">(edit graphic)</A>",
87                         floornum);
88                 wprintf("</TD></TR></TABLE>");
89                 wprintf("</TD>");
90
91                 wprintf("<TD>"
92                         "<FORM METHOD=\"POST\" ACTION=\"/rename_floor\">"
93                         "<INPUT TYPE=\"hidden\" NAME=\"floornum\" "
94                         "VALUE=\"%d\">"
95                         "<INPUT TYPE=\"text\" NAME=\"floorname\" "
96                         "VALUE=\"%s\" MAXLENGTH=\"250\">\n",
97                         floornum, floorname);
98                 wprintf("<INPUT TYPE=\"SUBMIT\" NAME=\"sc\" "
99                         "VALUE=\"Change name\">"
100                         "</FORM></TD>");
101
102                 wprintf("<TD>%d</TD></TR>\n", refcount);
103         }
104
105         wprintf("<TR><TD>&nbsp;</TD>"
106                 "<TD><FORM METHOD=\"POST\" ACTION=\"/create_floor\">"
107                 "<INPUT TYPE=\"text\" NAME=\"floorname\" "
108                 "MAXLENGTH=\"250\">\n"
109                 "<INPUT TYPE=\"SUBMIT\" NAME=\"sc\" "
110                 "VALUE=\"Create new floor\">"
111                 "</FORM></TD>"
112                 "<TD>&nbsp;</TD></TR>\n");
113
114         wprintf("</TABLE>\n");
115
116         wDumpContent(1);
117 }
118
119
120
121 void delete_floor(void) {
122         int floornum;
123         char buf[SIZ];
124         char message[SIZ];
125
126         floornum = atoi(bstr("floornum"));
127
128         serv_printf("KFLR %d|1", floornum);
129         serv_gets(buf);
130
131         if (buf[0] == '2') {
132                 sprintf(message, "<B><I>Floor has been deleted."
133                                 "</I></B><BR><BR>\n");
134         }
135         else {
136                 sprintf(message, "<B><I>%s</I></B>><BR>", &buf[4]);
137         }
138
139         display_floorconfig(message);
140 }
141
142
143 void create_floor(void) {
144         char buf[SIZ];
145         char message[SIZ];
146         char floorname[SIZ];
147
148         strcpy(floorname, bstr("floorname"));
149
150         serv_printf("CFLR %s|1", floorname);
151         serv_gets(buf);
152
153         sprintf(message, "<B><I>%s</I></B>><BR>", &buf[4]);
154
155         display_floorconfig(message);
156 }
157
158
159 void rename_floor(void) {
160         int floornum;
161         char buf[SIZ];
162         char message[SIZ];
163         char floorname[SIZ];
164
165         floornum = atoi(bstr("floornum"));
166         strcpy(floorname, bstr("floorname"));
167
168         serv_printf("EFLR %d|%s", floornum, floorname);
169         serv_gets(buf);
170
171         sprintf(message, "<B><I>%s</I></B>><BR>", &buf[4]);
172
173         display_floorconfig(message);
174 }
175
176