Back to index

webcit  8.12-dfsg
sysmsgs.c
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 1996-2012 by the citadel.org team
00003  *
00004  * This program is open source software.  You can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License, version 3.
00006  *
00007  * This program is distributed in the hope that it will be useful,
00008  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00009  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00010  * GNU General Public License for more details.
00011  */
00012 
00013 #include "webcit.h"
00014 
00015 
00024 void display_edit(char *description, char *check_cmd,
00025                 char *read_cmd, char *save_cmd, int with_room_banner)
00026 {
00027        StrBuf *Line;
00028 
00029        serv_puts(check_cmd);
00030        Line = NewStrBuf();
00031        StrBuf_ServGetln(Line);
00032        if (GetServerStatusMsg(Line, NULL, 1, 2) != 2) {
00033               FreeStrBuf(&Line);
00034               display_main_menu();
00035               FreeStrBuf(&Line);
00036               return;
00037        }
00038        if (with_room_banner) {
00039               output_headers(1, 1, 1, 0, 0, 0);
00040        }
00041        else {
00042               output_headers(1, 1, 0, 0, 0, 0);
00043        }
00044 
00045        do_template("box_begin_1");
00046        StrBufAppendPrintf (WC->WBuf, _("Edit %s"), description);
00047        do_template("box_begin_2");
00048 
00049        wc_printf(_("Enter %s below. Text is formatted to the reader's browser."
00050               " A newline is forced by preceding the next line by a blank."), description);
00051 
00052        wc_printf("<form method=\"post\" action=\"%s\">\n", save_cmd);
00053        wc_printf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
00054        wc_printf("<textarea name=\"msgtext\" wrap=soft "
00055               "rows=10 cols=80 width=80>\n");
00056        serv_puts(read_cmd);
00057        StrBuf_ServGetln(Line);
00058        if (GetServerStatusMsg(Line, NULL, 0, 0) == 1)
00059               server_to_text();
00060        wc_printf("</textarea><div class=\"buttons\" >\n");
00061        wc_printf("<input type=\"submit\" name=\"save_button\" value=\"%s\">", _("Save changes"));
00062        wc_printf("&nbsp;");
00063        wc_printf("<input type=\"submit\" name=\"cancel_button\" value=\"%s\"><br>\n", _("Cancel"));
00064        wc_printf("</div></form>\n");
00065 
00066        do_template("box_end");
00067        wDumpContent(1);
00068        FreeStrBuf(&Line);
00069 }
00070 
00071 
00078 void save_edit(char *description, char *enter_cmd, int regoto)
00079 {
00080        StrBuf *Line;
00081 
00082        if (!havebstr("save_button")) {
00083               AppendImportantMessage(_("Cancelled.  %s was not saved."), -1);
00084               display_main_menu();
00085               return;
00086        }
00087        Line = NewStrBuf();
00088        serv_puts(enter_cmd);
00089        StrBuf_ServGetln(Line);
00090        if (GetServerStatusMsg(Line, NULL, 1, 0) != 4) {
00091               FreeStrBuf(&Line);
00092               display_main_menu();
00093               return;
00094        }
00095        FreeStrBuf(&Line);
00096        text_to_server(bstr("msgtext"));
00097        serv_puts("000");
00098 
00099        if (regoto) {
00100               smart_goto(WC->CurRoom.name);
00101        } else {
00102               AppendImportantMessage(description, -1);
00103               AppendImportantMessage(_(" has been saved."), -1);
00104               display_main_menu();
00105               return;
00106        }
00107 }
00108 
00109 
00110 void display_editinfo(void){ display_edit(_("Room info"), "EINF 0", "RINF", "editinfo", 1);}
00111 void editinfo(void) {save_edit(_("Room info"), "EINF 1", 1);}
00112 void display_editbio(void) {
00113        char buf[SIZ];
00114 
00115        snprintf(buf, SIZ, "RBIO %s", ChrPtr(WC->wc_fullname));
00116        display_edit(_("Your bio"), "NOOP", buf, "editbio", 3);
00117 }
00118 void editbio(void) { save_edit(_("Your bio"), "EBIO", 0); }
00119 
00120 void 
00121 InitModule_SYSMSG
00122 (void)
00123 {
00124        WebcitAddUrlHandler(HKEY("display_editinfo"), "", 0, display_editinfo, 0);
00125        WebcitAddUrlHandler(HKEY("editinfo"), "", 0, editinfo, 0);
00126        WebcitAddUrlHandler(HKEY("display_editbio"), "", 0, display_editbio, 0);
00127        WebcitAddUrlHandler(HKEY("editbio"), "", 0, editbio, 0);
00128 }