4e7e343348843a6b0f05122348e0def6d44f0e1c
[citadel.git] / webcit / sysmsgs.c
1 /*
2  * Copyright (c) 1996-2012 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, version 3.
6  * 
7  * 
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  * 
15  * 
16  * 
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         Line = NewStrBuf();
37         StrBuf_ServGetln(Line);
38         if (GetServerStatusMsg(Line, NULL, 1, 2) != 2) {
39                 FreeStrBuf(&Line);
40                 display_main_menu();
41                 FreeStrBuf(&Line);
42                 return;
43         }
44         if (with_room_banner) {
45                 output_headers(1, 1, 1, 0, 0, 0);
46         }
47         else {
48                 output_headers(1, 1, 0, 0, 0, 0);
49         }
50
51         do_template("box_begin_1");
52         StrBufAppendPrintf (WC->WBuf, _("Edit %s"), description);
53         do_template("box_begin_2");
54
55         wc_printf(_("Enter %s below. Text is formatted to the reader's browser."
56                 " A newline is forced by preceding the next line by a blank."), description);
57
58         wc_printf("<form method=\"post\" action=\"%s\">\n", save_cmd);
59         wc_printf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
60         wc_printf("<textarea name=\"msgtext\" wrap=soft "
61                 "rows=10 cols=80 width=80>\n");
62         serv_puts(read_cmd);
63         StrBuf_ServGetln(Line);
64         if (GetServerStatusMsg(Line, NULL, 0, 0) == 1)
65                 server_to_text();
66         wc_printf("</textarea><div class=\"buttons\" >\n");
67         wc_printf("<input type=\"submit\" name=\"save_button\" value=\"%s\">", _("Save changes"));
68         wc_printf("&nbsp;");
69         wc_printf("<input type=\"submit\" name=\"cancel_button\" value=\"%s\"><br>\n", _("Cancel"));
70         wc_printf("</div></form>\n");
71
72         do_template("box_end");
73         wDumpContent(1);
74         FreeStrBuf(&Line);
75 }
76
77
78 /**
79  *  save a screen which was displayed with display_edit()
80  *  description the window title???
81  *  enter_cmd which command to enter at the citadel server???
82  *  regoto should we go to that room again after executing that command?
83  */
84 void save_edit(char *description, char *enter_cmd, int regoto)
85 {
86         StrBuf *Line;
87
88         if (!havebstr("save_button")) {
89                 AppendImportantMessage(_("Cancelled.  %s was not saved."), -1);
90                 display_main_menu();
91                 return;
92         }
93         Line = NewStrBuf();
94         serv_puts(enter_cmd);
95         StrBuf_ServGetln(Line);
96         if (GetServerStatusMsg(Line, NULL, 1, 0) != 4) {
97                 FreeStrBuf(&Line);
98                 display_main_menu();
99                 return;
100         }
101         FreeStrBuf(&Line);
102         text_to_server(bstr("msgtext"));
103         serv_puts("000");
104
105         if (regoto) {
106                 smart_goto(WC->CurRoom.name);
107         } else {
108                 AppendImportantMessage(description, -1);
109                 AppendImportantMessage(_(" has been saved."), -1);
110                 display_main_menu();
111                 return;
112         }
113 }
114
115
116 void display_editinfo(void){ display_edit(_("Room info"), "EINF 0", "RINF", "editinfo", 1);}
117 void editinfo(void) {save_edit(_("Room info"), "EINF 1", 1);}
118 void display_editbio(void) {
119         char buf[SIZ];
120
121         snprintf(buf, SIZ, "RBIO %s", ChrPtr(WC->wc_fullname));
122         display_edit(_("Your bio"), "NOOP", buf, "editbio", 3);
123 }
124 void editbio(void) { save_edit(_("Your bio"), "EBIO", 0); }
125
126 void 
127 InitModule_SYSMSG
128 (void)
129 {
130         WebcitAddUrlHandler(HKEY("display_editinfo"), "", 0, display_editinfo, 0);
131         WebcitAddUrlHandler(HKEY("editinfo"), "", 0, editinfo, 0);
132         WebcitAddUrlHandler(HKEY("display_editbio"), "", 0, display_editbio, 0);
133         WebcitAddUrlHandler(HKEY("editbio"), "", 0, editbio, 0);
134 }