]> code.citadel.org Git - citadel.git/blobdiff - webcit/floors.c
* New COND:FLOOR:NROOMS : whether this floor has n-rooms
[citadel.git] / webcit / floors.c
index 0eb2da44e1aabd213b1fafe5de7e2c4f6465b380..b183d6be18b7b28be8051fa3354a03b511ff2867 100644 (file)
@@ -1,28 +1,23 @@
 /*
- * Administrative screens for floor maintenance
+ * $Id$
  *
+ * Copyright (c) 1996-2010 by the citadel.org team
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-
-#include <ctype.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <stdio.h>
-#include <fcntl.h>
-#include <signal.h>
-#include <sys/types.h>
-#include <sys/wait.h>
-#include <sys/socket.h>
-#include <sys/time.h>
-#include <limits.h>
-#include <netinet/in.h>
-#include <netdb.h>
-#include <string.h>
-#include <pwd.h>
-#include <errno.h>
-#include <stdarg.h>
-#include <pthread.h>
-#include <signal.h>
 #include "webcit.h"
 #include "webserver.h"
 
@@ -33,7 +28,7 @@
  * Display floor configuration.  If prepend_html is not NULL, its contents
  * will be displayed at the top of the screen.
  */
-void display_floorconfig(char *prepend_html)
+void display_floorconfig(StrBuf *prepend_html)
 {
        char buf[SIZ];
 
@@ -41,137 +36,186 @@ void display_floorconfig(char *prepend_html)
        char floorname[SIZ];
        int refcount;
 
-       output_headers(1, 1, 2, 0, 0, 0, 0);
+        output_headers(1, 1, 2, 0, 0, 0);
+        wc_printf("<div id=\"banner\">\n");
+        wc_printf("<h1>");
+       wc_printf(_("Add/change/delete floors"));
+       wc_printf("</h1>");
+        wc_printf("</div>\n");
 
+       wc_printf("<div id=\"content\" class=\"service\">\n");
+                                                                                                                             
        if (prepend_html != NULL) {
-               client_write(prepend_html, strlen(prepend_html));
+               wc_printf("<br /><b><i>");
+               StrBufAppendBuf(WC->WBuf, prepend_html, 0);
+               wc_printf("</i></b><br /><br />\n");
        }
 
-       serv_printf("LFLR");    /* FIXME put a real test here */
-       serv_gets(buf);
+       serv_printf("LFLR");
+       serv_getln(buf, sizeof buf);
        if (buf[0] != '1') {
-               wprintf("<div id=\"banner\">\n");
-               wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#770000\"><TR><TD>");
-               wprintf("<SPAN CLASS=\"titlebar\">Error</SPAN>\n");
-               wprintf("</TD></TR></TABLE>\n");
-               wprintf("</div>\n<div id=\"text\">\n");
-               wprintf("%s<br />\n", &buf[4]);
+               wc_printf("<TABLE  class=\"floors_config\"><TR><TD>");
+               wc_printf("<SPAN CLASS=\"titlebar\">");
+               wc_printf(_("Error"));
+               wc_printf("</SPAN>\n");
+               wc_printf("</TD></TR></TABLE>\n");
+               wc_printf("%s<br />\n", &buf[4]);
                wDumpContent(1);
                return;
        }
 
-       svprintf("BOXTITLE", WCS_STRING, "Floor configuration");
-       do_template("beginbox");
-
-       wprintf("<TABLE BORDER=1 WIDTH=100%>\n"
-               "<TR><TH>Floor number</TH>"
-               "<TH>Floor name</TH>"
-               "<TH>Number of rooms</TH></TR>\n"
-       );
-
-       while (serv_gets(buf), strcmp(buf, "000")) {
+       wc_printf("<div class=\"fix_scrollbar_bug\">"
+               "<TABLE BORDER=1 WIDTH=100%% bgcolor=\"#ffffff\">\n"
+               "<TR><TH>");
+       wc_printf(_("Floor number"));
+       wc_printf("</TH><TH>");
+       wc_printf(_("Floor name"));
+       wc_printf("</TH><TH>");
+       wc_printf(_("Number of rooms"));
+       wc_printf("</TH><TH>");
+       wc_printf(_("Floor CSS"));
+       wc_printf("</TH></TR>\n");
+
+       while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
                floornum = extract_int(buf, 0);
-               extract(floorname, buf, 1);
+               extract_token(floorname, buf, 1, '|', sizeof floorname);
                refcount = extract_int(buf, 2);
 
-               wprintf("<TR><TD><TABLE border=0><TR><TD>%d", floornum);
+               wc_printf("<TR><TD><TABLE border=0><TR><TD>%d", floornum);
                if (refcount == 0) {
-                       wprintf("</TD><TD>"
-                               "<A HREF=\"/delete_floor?floornum=%d\">"
-                               "<FONT SIZE=-1>(delete floor)</A>"
-                               "</FONT><br />", floornum
-                       );
+                       wc_printf("</TD><TD>"
+                               "<a href=\"delete_floor?floornum=%d\">"
+                               "<FONT SIZE=-1>", floornum);
+                       wc_printf(_("(delete floor)"));
+                       wc_printf("</A></FONT><br />");
                }
-               wprintf("<FONT SIZE=-1>"
-                       "<A HREF=\"/display_editfloorpic&"
-                       "which_floor=%d\">(edit graphic)</A>",
-                       floornum);
-               wprintf("</TD></TR></TABLE>");
-               wprintf("</TD>");
-
-               wprintf("<TD>"
-                       "<FORM METHOD=\"POST\" ACTION=\"/rename_floor\">"
+               wc_printf("<FONT SIZE=-1>"
+                       "<a href=\"display_editfloorpic?"
+                       "which_floor=%d\">", floornum);
+               wc_printf(_("(edit graphic)"));
+               wc_printf("</A></TD></TR></TABLE>");
+               wc_printf("</TD>");
+
+               wc_printf("<TD>"
+                       "<FORM METHOD=\"POST\" action=\"rename_floor\">"
                        "<INPUT TYPE=\"hidden\" NAME=\"floornum\" "
                        "VALUE=\"%d\">"
                        "<INPUT TYPE=\"text\" NAME=\"floorname\" "
                        "VALUE=\"%s\" MAXLENGTH=\"250\">\n",
                        floornum, floorname);
-               wprintf("<INPUT TYPE=\"SUBMIT\" NAME=\"sc\" "
-                       "VALUE=\"Change name\">"
-                       "</FORM></TD>");
+               wc_printf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
+               wc_printf("<INPUT TYPE=\"SUBMIT\" NAME=\"sc\" "
+                       "VALUE=\"%s\">"
+                       "</FORM></TD>", _("Change name"));
+
+               wc_printf("<TD>%d</TD>\n", refcount);
 
-               wprintf("<TD>%d</TD></TR>\n", refcount);
+               wc_printf("<TD>"
+                       "<FORM METHOD=\"POST\" action=\"set_floor_css\">"
+                       "<INPUT TYPE=\"hidden\" NAME=\"floornum\" "
+                       "VALUE=\"%d\">"
+                       "<INPUT TYPE=\"text\" NAME=\"floorcss\" "
+                       "VALUE=\"%s\" MAXLENGTH=\"250\">\n",
+                       floornum, floorname);
+               wc_printf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
+               wc_printf("<INPUT TYPE=\"SUBMIT\" NAME=\"sc\" "
+                       "VALUE=\"%s\">"
+                       "</FORM></TD>", _("Change CSS"));
+
+               wc_printf("</TR>\n");
        }
 
-       wprintf("<TR><TD>&nbsp;</TD>"
-               "<TD><FORM METHOD=\"POST\" ACTION=\"/create_floor\">"
-               "<INPUT TYPE=\"text\" NAME=\"floorname\" "
+       wc_printf("<TR><TD>&nbsp;</TD>"
+               "<TD><FORM METHOD=\"POST\" action=\"create_floor\">");
+       wc_printf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
+       wc_printf("<INPUT TYPE=\"text\" NAME=\"floorname\" "
                "MAXLENGTH=\"250\">\n"
                "<INPUT TYPE=\"SUBMIT\" NAME=\"sc\" "
-               "VALUE=\"Create new floor\">"
+               "VALUE=\"%s\">"
                "</FORM></TD>"
-               "<TD>&nbsp;</TD></TR>\n");
+               "<TD>&nbsp;</TD></TR>\n", _("Create new floor"));
 
-       wprintf("</TABLE>\n");
-       do_template("endbox");
+       wc_printf("</table></div>\n");
        wDumpContent(1);
 }
 
 
-
+/*
+ * delete the actual floor
+ */
 void delete_floor(void) {
        int floornum;
-       char buf[SIZ];
-       char message[SIZ];
-
-       floornum = atoi(bstr("floornum"));
-
+       StrBuf *Buf;
+       const char *Err;
+               
+       floornum = ibstr("floornum");
+       Buf = NewStrBuf();
        serv_printf("KFLR %d|1", floornum);
-       serv_gets(buf);
+       
+       StrBufTCP_read_line(Buf, &WC->serv_sock, 0, &Err);
 
-       if (buf[0] == '2') {
-               sprintf(message, "<B><I>Floor has been deleted."
-                               "</I></B><br /><br />\n");
+       if (GetServerStatus(Buf, NULL) == 2) {
+               StrBufPlain(Buf, _("Floor has been deleted."),-1);
        }
        else {
-               sprintf(message, "<B><I>%s</I></B>><br />", &buf[4]);
+               StrBufCutLeft(Buf, 4);
        }
 
-       display_floorconfig(message);
+       FlushRoomlist();
+       display_floorconfig(Buf);
+       FreeStrBuf(&Buf);
 }
 
-
+/*
+ * start creating a new floor
+ */
 void create_floor(void) {
-       char buf[SIZ];
-       char message[SIZ];
-       char floorname[SIZ];
-
-       strcpy(floorname, bstr("floorname"));
+       StrBuf *Buf;
+       const char *Err;
 
-       serv_printf("CFLR %s|1", floorname);
-       serv_gets(buf);
+       Buf = NewStrBuf();
+       serv_printf("CFLR %s|1", bstr("floorname"));
+       StrBufTCP_read_line(Buf, &WC->serv_sock, 0, &Err);
 
-       sprintf(message, "<B><I>%s</I></B>><br />", &buf[4]);
+       if (GetServerStatus(Buf, NULL) == 2) {
+               StrBufPlain(Buf, _("New floor has been created."),-1);
+       }
+       else {
+               StrBufCutLeft(Buf, 4);
+       }
 
-       display_floorconfig(message);
+       FlushRoomlist();
+       display_floorconfig(Buf);
+       FreeStrBuf(&Buf);
 }
 
 
+/*
+ * rename this floor
+ */
 void rename_floor(void) {
-       int floornum;
-       char buf[SIZ];
-       char message[SIZ];
-       char floorname[SIZ];
+       StrBuf *Buf;
 
-       floornum = atoi(bstr("floornum"));
-       strcpy(floorname, bstr("floorname"));
+       Buf = NewStrBuf();
+       FlushRoomlist();
 
-       serv_printf("EFLR %d|%s", floornum, floorname);
-       serv_gets(buf);
+       serv_printf("EFLR %d|%s", ibstr("floornum"), bstr("floorname"));
+       StrBuf_ServGetln(Buf);
 
-       sprintf(message, "<B><I>%s</I></B>><br />", &buf[4]);
+       StrBufCutLeft(Buf, 4);
 
-       display_floorconfig(message);
+       display_floorconfig(Buf);
+       FreeStrBuf(&Buf);
 }
 
+void _display_floorconfig(void) {display_floorconfig(NULL);}
 
+void 
+InitModule_FLOORS
+(void)
+{
+       WebcitAddUrlHandler(HKEY("delete_floor"), "", 0, delete_floor, 0);
+       WebcitAddUrlHandler(HKEY("rename_floor"), "", 0, rename_floor, 0);
+       WebcitAddUrlHandler(HKEY("create_floor"), "", 0, create_floor, 0);
+       WebcitAddUrlHandler(HKEY("display_floorconfig"), "", 0, _display_floorconfig, 0);
+}