* add a Display name to our handlers; this will be used by DAV handlers.
[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         svprintf(HKEY("BOXTITLE"), WCS_STRING, _("Edit %s"), description);
36         do_template("beginboxx", NULL);
37
38         wprintf(_("Enter %s below. Text is formatted to the reader's browser."
39                 " A newline is forced by preceding the next line by a blank."), description);
40
41         wprintf("<form method=\"post\" action=\"%s\">\n", save_cmd);
42         wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
43         wprintf("<textarea name=\"msgtext\" wrap=soft "
44                 "rows=10 cols=80 width=80>\n");
45         serv_puts(read_cmd);
46         serv_getln(buf, sizeof buf);
47         if (buf[0] == '1')
48                 server_to_text();
49         wprintf("</textarea><div class=\"buttons\" >\n");
50         wprintf("<input type=\"submit\" name=\"save_button\" value=\"%s\">", _("Save changes"));
51         wprintf("&nbsp;");
52         wprintf("<input type=\"submit\" name=\"cancel_button\" value=\"%s\"><br />\n", _("Cancel"));
53         wprintf("</div></form>\n");
54
55         do_template("endbox", NULL);
56         wDumpContent(1);
57 }
58
59
60 /**
61  *  save a screen which was displayed with display_edit()
62  *  description the window title???
63  *  enter_cmd which command to enter at the citadel server???
64  *  regoto should we go to that room again after executing that command?
65  */
66 void save_edit(char *description, char *enter_cmd, int regoto)
67 {
68         char buf[SIZ];
69
70         if (!havebstr("save_button")) {
71                 sprintf(WC->ImportantMessage,
72                         _("Cancelled.  %s was not saved."),
73                         description);
74                 display_main_menu();
75                 return;
76         }
77         serv_puts(enter_cmd);
78         serv_getln(buf, sizeof buf);
79         if (buf[0] != '4') {
80                 safestrncpy(WC->ImportantMessage, &buf[4], sizeof WC->ImportantMessage);
81                 display_main_menu();
82                 return;
83         }
84         text_to_server(bstr("msgtext"));
85         serv_puts("000");
86
87         if (regoto) {
88                 smart_goto(WC->wc_roomname);
89         } else {
90                 sprintf(WC->ImportantMessage,
91                         _("%s has been saved."),
92                         description);
93                 display_main_menu();
94                 return;
95         }
96 }
97
98
99 void display_editinfo(void){ display_edit(_("Room info"), "EINF 0", "RINF", "editinfo", 1);}
100 void editinfo(void) {save_edit(_("Room info"), "EINF 1", 1);}
101 void display_editbio(void) {
102         char buf[SIZ];
103
104         snprintf(buf, SIZ, "RBIO %s", ChrPtr(WC->wc_fullname));
105         display_edit(_("Your bio"), "NOOP", buf, "editbio", 3);
106 }
107 void editbio(void) { save_edit(_("Your bio"), "EBIO", 0); }
108
109 void 
110 InitModule_SYSMSG
111 (void)
112 {
113         WebcitAddUrlHandler(HKEY("display_editinfo"), "", 0, display_editinfo, 0);
114         WebcitAddUrlHandler(HKEY("editinfo"), "", 0, editinfo, 0);
115         WebcitAddUrlHandler(HKEY("display_editbio"), "", 0, display_editbio, 0);
116         WebcitAddUrlHandler(HKEY("editbio"), "", 0, editbio, 0);
117 }