* Replaced serv_gets() with serv_getln() - which now requires the caller
[citadel.git] / webcit / sysmsgs.c
1 /*
2  * $Id$
3  *
4  * Editing of various text files on the Citadel server.
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  * display the form for editing something (room info, bio, etc)
31  */
32 void display_edit(char *description, char *check_cmd,
33                   char *read_cmd, char *save_cmd, int with_room_banner)
34 {
35         char buf[SIZ];
36
37         serv_puts(check_cmd);
38         serv_getln(buf, sizeof buf);
39
40         if (buf[0] != '2') {
41                 strcpy(WC->ImportantMessage, &buf[4]);
42                 display_main_menu();
43                 return;
44         }
45         if (with_room_banner) {
46                 output_headers(1, 1, 1, 0, 0, 0, 0);
47         }
48         else {
49                 output_headers(1, 1, 0, 0, 0, 0, 0);
50         }
51
52         svprintf("BOXTITLE", WCS_STRING, "Edit %s", description);
53         do_template("beginbox");
54
55         wprintf("<CENTER>Enter %s below.  Text is formatted to\n", description);
56         wprintf("the <EM>reader's</EM> screen width.  To defeat the\n");
57         wprintf("formatting, indent a line at least one space.  \n");
58         wprintf("<br />");
59
60         wprintf("<FORM METHOD=\"POST\" ACTION=\"%s\">\n", save_cmd);
61         wprintf("<TEXTAREA NAME=\"msgtext\" wrap=soft "
62                 "ROWS=10 COLS=80 WIDTH=80>\n");
63         serv_puts(read_cmd);
64         serv_getln(buf, sizeof buf);
65         if (buf[0] == '1')
66                 server_to_text();
67         wprintf("</TEXTAREA><br /><br />\n");
68         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Save\">");
69         wprintf("&nbsp;");
70         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\"><br />\n");
71
72         wprintf("</FORM></CENTER>\n");
73         do_template("endbox");
74         wDumpContent(1);
75 }
76
77
78 /*
79  * save a screen which was displayed with display_edit()
80  */
81 void save_edit(char *description, char *enter_cmd, int regoto)
82 {
83         char buf[SIZ];
84
85         if (strcmp(bstr("sc"), "Save")) {
86                 sprintf(WC->ImportantMessage,
87                         "Cancelled.  %s was not saved.\n", description);
88                 display_main_menu();
89                 return;
90         }
91         serv_puts(enter_cmd);
92         serv_getln(buf, sizeof buf);
93         if (buf[0] != '4') {
94                 strcpy(WC->ImportantMessage, &buf[4]);
95                 display_main_menu();
96                 return;
97         }
98         text_to_server(bstr("msgtext"), 0);
99         serv_puts("000");
100
101         if (regoto) {
102                 smart_goto(WC->wc_roomname);
103         } else {
104                 sprintf(WC->ImportantMessage,
105                         "%s has been saved.\n", description);
106                 display_main_menu();
107                 return;
108         }
109 }