16f9f0543655b97016c278035a6da0f3fe82c2ba
[citadel.git] / webcit / sysmsgs.c
1 /*
2  * $Id$
3  */
4 #include "webcit.h"
5
6
7 /**
8  *  display the form for editing something (room info, bio, etc)
9  *  description the descriptive text for the box
10  *  check_cmd command to check????
11  *  read_cmd read answer from citadel server???
12  *  save_cmd save comand to the citadel server??
13  *  with_room_banner should we bisplay a room banner?
14  */
15 void display_edit(char *description, char *check_cmd,
16                   char *read_cmd, char *save_cmd, int with_room_banner)
17 {
18         char buf[SIZ];
19
20         serv_puts(check_cmd);
21         serv_getln(buf, sizeof buf);
22
23         if (buf[0] != '2') {
24                 safestrncpy(WC->ImportantMessage, &buf[4], sizeof WC->ImportantMessage);
25                 display_main_menu();
26                 return;
27         }
28         if (with_room_banner) {
29                 output_headers(1, 1, 1, 0, 0, 0);
30         }
31         else {
32                 output_headers(1, 1, 0, 0, 0, 0);
33         }
34
35         do_template("beginbox_1", NULL);
36         StrBufAppendPrintf (WC->WBuf, _("Edit %s"), description);
37         do_template("beginbox_2", NULL);
38
39         wc_printf(_("Enter %s below. Text is formatted to the reader's browser."
40                 " A newline is forced by preceding the next line by a blank."), description);
41
42         wc_printf("<form method=\"post\" action=\"%s\">\n", save_cmd);
43         wc_printf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
44         wc_printf("<textarea name=\"msgtext\" wrap=soft "
45                 "rows=10 cols=80 width=80>\n");
46         serv_puts(read_cmd);
47         serv_getln(buf, sizeof buf);
48         if (buf[0] == '1')
49                 server_to_text();
50         wc_printf("</textarea><div class=\"buttons\" >\n");
51         wc_printf("<input type=\"submit\" name=\"save_button\" value=\"%s\">", _("Save changes"));
52         wc_printf("&nbsp;");
53         wc_printf("<input type=\"submit\" name=\"cancel_button\" value=\"%s\"><br />\n", _("Cancel"));
54         wc_printf("</div></form>\n");
55
56         do_template("endbox", NULL);
57         wDumpContent(1);
58 }
59
60
61 /**
62  *  save a screen which was displayed with display_edit()
63  *  description the window title???
64  *  enter_cmd which command to enter at the citadel server???
65  *  regoto should we go to that room again after executing that command?
66  */
67 void save_edit(char *description, char *enter_cmd, int regoto)
68 {
69         char buf[SIZ];
70
71         if (!havebstr("save_button")) {
72                 sprintf(WC->ImportantMessage,
73                         _("Cancelled.  %s was not saved."),
74                         description);
75                 display_main_menu();
76                 return;
77         }
78         serv_puts(enter_cmd);
79         serv_getln(buf, sizeof buf);
80         if (buf[0] != '4') {
81                 safestrncpy(WC->ImportantMessage, &buf[4], sizeof WC->ImportantMessage);
82                 display_main_menu();
83                 return;
84         }
85         text_to_server(bstr("msgtext"));
86         serv_puts("000");
87
88         if (regoto) {
89                 smart_goto(WC->CurRoom.name);
90         } else {
91                 sprintf(WC->ImportantMessage,
92                         _("%s has been saved."),
93                         description);
94                 display_main_menu();
95                 return;
96         }
97 }
98
99
100 void display_editinfo(void){ display_edit(_("Room info"), "EINF 0", "RINF", "editinfo", 1);}
101 void editinfo(void) {save_edit(_("Room info"), "EINF 1", 1);}
102 void display_editbio(void) {
103         char buf[SIZ];
104
105         snprintf(buf, SIZ, "RBIO %s", ChrPtr(WC->wc_fullname));
106         display_edit(_("Your bio"), "NOOP", buf, "editbio", 3);
107 }
108 void editbio(void) { save_edit(_("Your bio"), "EBIO", 0); }
109
110 void 
111 InitModule_SYSMSG
112 (void)
113 {
114         WebcitAddUrlHandler(HKEY("display_editinfo"), "", 0, display_editinfo, 0);
115         WebcitAddUrlHandler(HKEY("editinfo"), "", 0, editinfo, 0);
116         WebcitAddUrlHandler(HKEY("display_editbio"), "", 0, display_editbio, 0);
117         WebcitAddUrlHandler(HKEY("editbio"), "", 0, editbio, 0);
118 }