* Started moving all of the global variables into a struct, to facilitate
[citadel.git] / webcit / sysmsgs.c
1 #include <stdlib.h>
2 #include <unistd.h>
3 #include <stdio.h>
4 #include <signal.h>
5 #include <sys/types.h>
6 #include <ctype.h>
7 #include <string.h>
8 #include "webcit.h"
9 #include "child.h"
10
11 /*
12  * display the form for editing something (room info, bio, etc)
13  */
14 void display_edit(char *description, char *check_cmd,
15                   char *read_cmd, char *save_cmd)
16 {
17         char buf[256];
18
19         serv_puts(check_cmd);
20         serv_gets(buf);
21
22         if (buf[0] != '2') {
23                 display_error(&buf[4]);
24                 return;
25         }
26         printf("HTTP/1.0 200 OK\n");
27         output_headers(1);
28
29         wprintf("<TABLE WIDTH=100% BORDER=0 BGCOLOR=007700><TR><TD>");
30         wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
31         wprintf("<B>Edit ");
32         escputs(description);
33         wprintf("</B></FONT></TD></TR></TABLE>\n");
34
35         wprintf("<CENTER>Enter %s below.  Text is formatted to\n", description);
36         wprintf("the <EM>reader's</EM> screen width.  To defeat the\n");
37         wprintf("formatting, indent a line at least one space.  \n");
38         wprintf("<BR>");
39
40         wprintf("<FORM METHOD=\"POST\" ACTION=\"%s\">\n", save_cmd);
41         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Save\">");
42         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\"><BR>\n");
43         wprintf("<TEXTAREA NAME=\"msgtext\" wrap=soft ROWS=30 COLS=80 WIDTH=80>");
44         serv_puts(read_cmd);
45         serv_gets(buf);
46         if (buf[0] == '1')
47                 server_to_text();
48         wprintf("</TEXTAREA><P>\n");
49
50         wprintf("</FORM></CENTER>\n");
51         wDumpContent(1);
52 }
53
54
55 /*
56  * save a screen which was displayed with display_edit()
57  */
58 void save_edit(char *description, char *enter_cmd, int regoto)
59 {
60         char buf[256];
61
62         if (strcmp(bstr("sc"), "Save")) {
63                 printf("HTTP/1.0 200 OK\n");
64                 output_headers(1);
65                 wprintf("Cancelled.  %s was not saved.<BR>\n", description);
66                 wDumpContent(1);
67                 return;
68         }
69         serv_puts(enter_cmd);
70         serv_gets(buf);
71         if (buf[0] != '4') {
72                 display_error(&buf[4]);
73                 return;
74         }
75         text_to_server(bstr("msgtext"));
76         serv_puts("000");
77
78         if (regoto) {
79                 smart_goto(WC->wc_roomname);
80         } else {
81                 printf("HTTP/1.0 200 OK\n");
82                 output_headers(1);
83                 wprintf("%s has been saved.\n", description);
84                 wDumpContent(1);
85         }
86 }