aae67d9304b26604fdb627f42f019cdfa8c0796a
[citadel.git] / webcit / sysmsgs.c
1 /*
2  * Copyright (c) 1996-2011 by the citadel.org team
3  *
4  * This program is open source software.  You can redistribute it and/or
5  * modify it under the terms of the GNU General Public License as
6  * published by the Free Software Foundation; either version 3 of the
7  * License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  */
18
19 #include "webcit.h"
20
21
22 /**
23  *  display the form for editing something (room info, bio, etc)
24  *  description the descriptive text for the box
25  *  check_cmd command to check????
26  *  read_cmd read answer from citadel server???
27  *  save_cmd save comand to the citadel server??
28  *  with_room_banner should we bisplay a room banner?
29  */
30 void display_edit(char *description, char *check_cmd,
31                   char *read_cmd, char *save_cmd, int with_room_banner)
32 {
33         char buf[SIZ];
34
35         serv_puts(check_cmd);
36         serv_getln(buf, sizeof buf);
37
38         if (buf[0] != '2') {
39                 safestrncpy(WC->ImportantMessage, &buf[4], sizeof WC->ImportantMessage);
40                 display_main_menu();
41                 return;
42         }
43         if (with_room_banner) {
44                 output_headers(1, 1, 1, 0, 0, 0);
45         }
46         else {
47                 output_headers(1, 1, 0, 0, 0, 0);
48         }
49
50         do_template("box_begin_1");
51         StrBufAppendPrintf (WC->WBuf, _("Edit %s"), description);
52         do_template("box_begin_2");
53
54         wc_printf(_("Enter %s below. Text is formatted to the reader's browser."
55                 " A newline is forced by preceding the next line by a blank."), description);
56
57         wc_printf("<form method=\"post\" action=\"%s\">\n", save_cmd);
58         wc_printf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
59         wc_printf("<textarea name=\"msgtext\" wrap=soft "
60                 "rows=10 cols=80 width=80>\n");
61         serv_puts(read_cmd);
62         serv_getln(buf, sizeof buf);
63         if (buf[0] == '1')
64                 server_to_text();
65         wc_printf("</textarea><div class=\"buttons\" >\n");
66         wc_printf("<input type=\"submit\" name=\"save_button\" value=\"%s\">", _("Save changes"));
67         wc_printf("&nbsp;");
68         wc_printf("<input type=\"submit\" name=\"cancel_button\" value=\"%s\"><br>\n", _("Cancel"));
69         wc_printf("</div></form>\n");
70
71         do_template("box_end");
72         wDumpContent(1);
73 }
74
75
76 /**
77  *  save a screen which was displayed with display_edit()
78  *  description the window title???
79  *  enter_cmd which command to enter at the citadel server???
80  *  regoto should we go to that room again after executing that command?
81  */
82 void save_edit(char *description, char *enter_cmd, int regoto)
83 {
84         char buf[SIZ];
85
86         if (!havebstr("save_button")) {
87                 sprintf(WC->ImportantMessage,
88                         _("Cancelled.  %s was not saved."),
89                         description);
90                 display_main_menu();
91                 return;
92         }
93         serv_puts(enter_cmd);
94         serv_getln(buf, sizeof buf);
95         if (buf[0] != '4') {
96                 safestrncpy(WC->ImportantMessage, &buf[4], sizeof WC->ImportantMessage);
97                 display_main_menu();
98                 return;
99         }
100         text_to_server(bstr("msgtext"));
101         serv_puts("000");
102
103         if (regoto) {
104                 smart_goto(WC->CurRoom.name);
105         } else {
106                 sprintf(WC->ImportantMessage,
107                         _("%s has been saved."),
108                         description);
109                 display_main_menu();
110                 return;
111         }
112 }
113
114
115 void display_editinfo(void){ display_edit(_("Room info"), "EINF 0", "RINF", "editinfo", 1);}
116 void editinfo(void) {save_edit(_("Room info"), "EINF 1", 1);}
117 void display_editbio(void) {
118         char buf[SIZ];
119
120         snprintf(buf, SIZ, "RBIO %s", ChrPtr(WC->wc_fullname));
121         display_edit(_("Your bio"), "NOOP", buf, "editbio", 3);
122 }
123 void editbio(void) { save_edit(_("Your bio"), "EBIO", 0); }
124
125 void 
126 InitModule_SYSMSG
127 (void)
128 {
129         WebcitAddUrlHandler(HKEY("display_editinfo"), "", 0, display_editinfo, 0);
130         WebcitAddUrlHandler(HKEY("editinfo"), "", 0, editinfo, 0);
131         WebcitAddUrlHandler(HKEY("display_editbio"), "", 0, display_editbio, 0);
132         WebcitAddUrlHandler(HKEY("editbio"), "", 0, editbio, 0);
133 }