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