* Moved "edit floor label pic" to the floor editing screen
[citadel.git] / webcit / graphics.c
1
2 #include <ctype.h>
3 #include <stdlib.h>
4 #include <unistd.h>
5 #include <stdio.h>
6 #include <fcntl.h>
7 #include <signal.h>
8 #include <sys/types.h>
9 #include <sys/wait.h>
10 #include <sys/socket.h>
11 #include <sys/time.h>
12 #include <limits.h>
13 #include <netinet/in.h>
14 #include <netdb.h>
15 #include <string.h>
16 #include <pwd.h>
17 #include <errno.h>
18 #include <stdarg.h>
19 #include <pthread.h>
20 #include <signal.h>
21 #include "webcit.h"
22
23 void display_graphics_upload(char *description, char *check_cmd, char *uplurl)
24 {
25         char buf[SIZ];
26
27         serv_puts(check_cmd);
28         serv_gets(buf);
29         if (buf[0] != '2') {
30                 display_error(&buf[4]);
31                 return;
32         }
33         output_headers(3);
34         wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=770000><TR><TD>");
35         wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
36         wprintf("<B>Set/change %s</B>\n", description);
37         wprintf("</FONT></TD></TR></TABLE>\n");
38
39         wprintf("<CENTER>\n");
40
41         wprintf("<FORM ENCTYPE=\"multipart/form-data\" ACTION=\"%s&which_room=%s\" METHOD=\"POST\">\n", uplurl, bstr("which_room"));
42
43         wprintf("You can upload any image directly from your computer,\n");
44         wprintf("as long as it is in GIF format (JPEG, PNG, etc. won't\n");
45         wprintf("work).<BR><BR>\n");
46
47         wprintf("Please select a file to upload:<BR>\n");
48         wprintf("<INPUT TYPE=\"FILE\" NAME=\"filename\" SIZE=\"35\">\n");
49         wprintf("<BR>");
50         wprintf("<INPUT TYPE=\"SUBMIT\" VALUE=\"Upload\">\n");
51         wprintf("<INPUT TYPE=\"RESET\" VALUE=\"Reset Form\">\n");
52         wprintf("</FORM>\n");
53         wprintf("<A HREF=\"/display_main_menu\">Cancel</A>\n");
54         wprintf("</CENTER>\n");
55         wDumpContent(1);
56 }
57
58 void do_graphics_upload(char *upl_cmd)
59 {
60         char buf[SIZ];
61         int bytes_remaining;
62         int pos = 0;
63         int thisblock;
64
65         if (WC->upload_length == 0) {
66                 display_error("You didn't upload a file.\n");
67                 return;
68         }
69         serv_puts(upl_cmd);
70         serv_gets(buf);
71         if (buf[0] != '2') {
72                 display_error(&buf[4]);
73                 return;
74         }
75         bytes_remaining = WC->upload_length;
76         while (bytes_remaining) {
77                 thisblock = ((bytes_remaining > 4096) ? 4096 : bytes_remaining);
78                 serv_printf("WRIT %d", thisblock);
79                 serv_gets(buf);
80                 if (buf[0] != '7') {
81                         display_error(&buf[4]);
82                         serv_puts("UCLS 0");
83                         serv_gets(buf);
84                         return;
85                 }
86                 thisblock = extract_int(&buf[4], 0);
87                 serv_write(&WC->upload[pos], thisblock);
88                 pos = pos + thisblock;
89                 bytes_remaining = bytes_remaining - thisblock;
90         }
91
92         serv_puts("UCLS 1");
93         serv_gets(buf);
94         if (buf[0] != 'x') {
95                 display_success(&buf[4]);
96                 return;
97         }
98 }