* Added "add/edit room graphic" screens.
[citadel.git] / webcit / graphics.c
1 #include <stdlib.h>
2 #include <unistd.h>
3 #include <stdio.h>
4 #include <ctype.h>
5 #include <string.h>
6 #include <errno.h>
7 #include <time.h>
8 #include "webcit.h"
9 #include "child.h"
10
11
12 void display_graphics_upload(char *description, char *check_cmd, char *uplurl) {
13         char buf[256];
14
15         serv_puts(check_cmd);
16         serv_gets(buf);
17         if (buf[0] != '2') {
18                 display_error(&buf[4]);
19                 return;
20                 }
21
22         printf("HTTP/1.0 200 OK\n");
23         output_headers(1);
24         wprintf("<TABLE WIDTH=100% BORDER=0 BGCOLOR=770000><TR><TD>");
25         wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
26         wprintf("<B>Set/change %s</B>\n", description);
27         wprintf("</FONT></TD></TR></TABLE>\n");
28
29         wprintf("<CENTER>\n");
30
31         wprintf("<FORM ENCTYPE=\"multipart/form-data\" ACTION=\"%s&which_room=%s\" METHOD=\"POST\">\n", uplurl, bstr("which_room"));
32         wprintf("Please select a file to upload:<BR>\n");
33         wprintf("<INPUT TYPE=\"FILE\" NAME=\"filename\" SIZE=\"35\">\n");
34         wprintf("<BR>");
35         wprintf("<INPUT TYPE=\"SUBMIT\" VALUE=\"Upload\">\n");
36         wprintf("<INPUT TYPE=\"RESET\" VALUE=\"Reset Form\">\n");
37         wprintf("</FORM>\n");
38         wprintf("<A HREF=\"/display_main_menu\">Cancel</A>\n");
39         wprintf("</CENTER></BODY></HTML>\n");
40         wDumpContent();
41         }
42
43 void do_graphics_upload(char *upl_cmd) {
44         char buf[256];
45         int bytes_remaining;
46         int pos = 0;
47         int thisblock;
48
49         if (upload_length == 0) {
50                 display_error("You didn't upload a file.\n");
51                 return;
52                 }
53
54         serv_puts(upl_cmd);
55         serv_gets(buf);
56         if (buf[0] != '2') {
57                 display_error(&buf[4]);
58                 return;
59                 }
60
61         bytes_remaining = upload_length;
62         while (bytes_remaining) {
63                 thisblock = ((bytes_remaining > 4096) ? 4096 : bytes_remaining);
64                 serv_printf("WRIT %d", thisblock);
65                 serv_gets(buf);
66                 if (buf[0] != '7') {
67                         display_error(&buf[4]);
68                         serv_puts("UCLS 0");
69                         serv_gets(buf);
70                         return;
71                         }
72                 thisblock = extract_int(&buf[4], 0);
73                 serv_write(&upload[pos], thisblock);
74                 pos = pos + thisblock;
75                 bytes_remaining = bytes_remaining - thisblock;
76                 }
77
78         serv_puts("UCLS 1");
79         serv_gets(buf);
80         /* FIX display something other than an error if it's ok */
81         if (buf[0] != 'x') {
82                 display_error(&buf[4]);
83                 return;
84                 }
85         }
86
87
88
89 void select_floor_to_edit_pic(void) {
90         int a;
91
92         printf("HTTP/1.0 200 OK\n");
93         output_headers(1);
94
95         wprintf("<TABLE WIDTH=100% BORDER=0 BGCOLOR=770000><TR><TD>");
96         wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
97         wprintf("<B>Select floor to edit label graphic</B>\n");
98         wprintf("</FONT></TD></TR></TABLE>\n");
99
100         load_floorlist();
101         for (a=0; a<128; ++a) if (strlen(floorlist[a])>0) {
102                 wprintf("<A HREF=\"/display_editfloorpic&which_floor=%d\">", a);
103                 escputs(floorlist[a]);
104                 wprintf("</A>\n");
105                 }
106         
107         wprintf("</BODY></HTML>\n");
108         wDumpContent();
109         }