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