buybuy plaintext important message.
[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         StrBuf *Line;
34
35         serv_puts(check_cmd);
36
37         StrBuf_ServGetln(Line);
38         if (GetServerStatusMsg(Line, NULL, 1, 2) != 2) {
39                 FreeStrBuf(&Line);
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         StrBuf_ServGetln(Line);
63         if (GetServerStatusMsg(Line, NULL, 0, 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         FreeStrBuf(&Line);
74 }
75
76
77 /**
78  *  save a screen which was displayed with display_edit()
79  *  description the window title???
80  *  enter_cmd which command to enter at the citadel server???
81  *  regoto should we go to that room again after executing that command?
82  */
83 void save_edit(char *description, char *enter_cmd, int regoto)
84 {
85         StrBuf *Line;
86
87         if (!havebstr("save_button")) {
88                 AppendImportantMessage(_("Cancelled.  %s was not saved."), -1);
89                 display_main_menu();
90                 return;
91         }
92         Line = NewStrBuf();
93         serv_puts(enter_cmd);
94         StrBuf_ServGetln(Line);
95         if (GetServerStatusMsg(Line, NULL, 1, 0) != 4) {
96                 FreeStrBuf(&Line);
97                 display_main_menu();
98                 return;
99         }
100         FreeStrBuf(&Line);
101         text_to_server(bstr("msgtext"));
102         serv_puts("000");
103
104         if (regoto) {
105                 smart_goto(WC->CurRoom.name);
106         } else {
107                 AppendImportantMessage(description, -1);
108                 AppendImportantMessage(_(" has been saved."), -1);
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 }