WHQ: templatize editing of user; fix handling of output after edit.
[citadel.git] / webcit / who.c
index 408cf590dc4948002a21971a216c1608231cf9b1..1c2984584ada5534ebe22ed4f95780ef461cb351 100644 (file)
@@ -1,6 +1,3 @@
-/*
- * $Id$
- */
 
 #include "webcit.h"
 
@@ -51,7 +48,10 @@ int GetWholistSection(HashList *List, time_t now, StrBuf *Buf)
        serv_puts("RWHO");
        StrBuf_ServGetln(Buf);
        if (GetServerStatus(Buf, NULL) == 1) {
-               while (BufLen = StrBuf_ServGetln(Buf), strcmp(ChrPtr(Buf), "000")) {
+               while (BufLen = StrBuf_ServGetln(Buf), 
+                      ((BufLen >= 0) && 
+                       ((BufLen != 3) || strcmp(ChrPtr(Buf), "000"))))
+               {
                        if (BufLen <= 0)
                            continue;
                        Pos = NULL;
@@ -131,77 +131,25 @@ void edit_me(void)
 {
        char buf[SIZ];
 
+       output_headers(1, 0, 0, 0, 0, 0);
        if (havebstr("change_room_name_button")) {
                serv_printf("RCHG %s", bstr("fake_roomname"));
                serv_getln(buf, sizeof buf);
-               http_redirect("who");
+               do_template("who");
        } else if (havebstr("change_host_name_button")) {
                serv_printf("HCHG %s", bstr("fake_hostname"));
                serv_getln(buf, sizeof buf);
-               http_redirect("who");
+               do_template("who");
        } else if (havebstr("change_user_name_button")) {
                serv_printf("UCHG %s", bstr("fake_username"));
                serv_getln(buf, sizeof buf);
-               http_redirect("who");
+               do_template("who");
        } else if (havebstr("cancel_button")) {
-               http_redirect("who");
+               do_template("who");
        } else {
-               output_headers(1, 1, 0, 0, 0, 0);
-
-               wprintf("<div id=\"banner\">\n");
-               wprintf("<table class=\"who_banner\"><tr><td>");
-               wprintf("<span class=\"titlebar\">");
-               wprintf(_("Edit your session display"));
-               wprintf("</span></td></tr></table>\n");
-               wprintf("</div>\n<div id=\"content\">\n");
-
-               wprintf(_("This screen allows you to change the way your "
-                       "session appears in the 'Who is online' listing. "
-                       "To turn off any 'fake' name you've previously "
-                       "set, simply click the appropriate 'change' button "
-                       "without typing anything in the corresponding box. "));
-               wprintf("<br />\n");
-
-               wprintf("<form method=\"POST\" action=\"edit_me\">\n");
-               wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
-
-               wprintf("<table border=0 width=100%%>\n");
-
-               wprintf("<tr><td><b>");
-               wprintf(_("Room name:"));
-               wprintf("</b></td>\n<td>");
-               wprintf("<input type=\"text\" name=\"fake_roomname\" maxlength=\"64\">\n");
-               wprintf("</td>\n<td align=center>");
-               wprintf("<input type=\"submit\" name=\"change_room_name_button\" value=\"%s\">",
-                       _("Change room name"));
-               wprintf("</td>\n</tr>\n");
-
-               wprintf("<tr><td><b>");
-               wprintf(_("Host name:"));
-               wprintf("</b></td><td>");
-               wprintf("<input type=\"text\" name=\"fake_hostname\" maxlength=\"64\">\n");
-               wprintf("</td>\n<td align=center>");
-               wprintf("<input type=\"submit\" name=\"change_host_name_button\" value=\"%s\">",
-                       _("Change host name"));
-               wprintf("</td>\n</tr>\n");
-
-               if (WC->is_aide) {
-                       wprintf("<tr><td><b>");
-                       wprintf(_("User name:"));
-                       wprintf("</b></td><td>");
-                       wprintf("<input type=\"text\" name=\"fake_username\" maxlength=\"64\">\n");
-                       wprintf("</td>\n<td align=center>");
-                       wprintf("<input type=\"submit\" name \"change_user_name_button\" value=\"%s\">",
-                               _("Change user name"));
-                       wprintf("</td>\n</tr>\n");
-               }
-               wprintf("<tr><td> </td><td> </td><td align=center>");
-               wprintf("<input type=\"submit\" name=\"cancel_button\" value=\"%s\">",
-                       _("Cancel"));
-               wprintf("</td></tr></table>\n");
-               wprintf("</form></center>\n");
-               wDumpContent(1);
+               do_template("who_edit");
        }
+       end_burst();
 }
 
 void _terminate_session(void) {
@@ -274,6 +222,11 @@ void tmplput_who_realhost(StrBuf *Target, WCTemplputParams *TP)
        UserStateStruct *User = (UserStateStruct*) CTX;
        StrBufAppendTemplate(Target, TP, User->RealHost, 0);
 }
+int conditional_who_realhost(StrBuf *Target, WCTemplputParams *TP)
+{
+       UserStateStruct *User = (UserStateStruct*) CTX;
+       return StrLength(User->RealHost) > 0;
+}
 
 void tmplput_who_lastactive(StrBuf *Target, WCTemplputParams *TP)
 {
@@ -323,24 +276,25 @@ InitModule_WHO
 {
        
 
-       WebcitAddUrlHandler(HKEY("terminate_session"), _terminate_session, 0);
-       WebcitAddUrlHandler(HKEY("edit_me"), edit_me, 0);
+       WebcitAddUrlHandler(HKEY("terminate_session"), "", 0, _terminate_session, 0);
+       WebcitAddUrlHandler(HKEY("edit_me"), "", 0, edit_me, 0);
 
        RegisterIterator("WHOLIST", 0, NULL, GetWholistHash, NULL, DeleteWholistHash, CTX_WHO, CTX_NONE, IT_NOFLAG);
 
-       RegisterNamespace("WHO:NAME",        0, 1, tmplput_who_username, CTX_WHO);
-       RegisterNamespace("WHO:ROOM",        0, 1, tmplput_who_room, CTX_WHO);
-       RegisterNamespace("WHO:HOST",        0, 1, tmplput_who_host, CTX_WHO);
-       RegisterNamespace("WHO:REALROOM",    0, 1, tmplput_who_realroom, CTX_WHO);
-       RegisterNamespace("WHO:REALHOST",    0, 1, tmplput_who_realhost, CTX_WHO);
-       RegisterNamespace("WHO:LASTACTIVE",  0, 1, tmplput_who_lastactive, CTX_WHO);
-       RegisterNamespace("WHO:IDLESINCE",   0, 1, tmplput_who_idlesince, CTX_WHO);
-       RegisterNamespace("WHO:SESSION",     0, 1, tmplput_who_session, CTX_WHO);
-       RegisterNamespace("WHO:NSESSIONS",   0, 1, tmplput_who_nsessions, CTX_WHO);
-       RegisterNamespace("WHO:NSESSIONS",   0, 1, tmplput_who_nsessions, CTX_WHO);
+       RegisterNamespace("WHO:NAME",        0, 1, tmplput_who_username, NULL, CTX_WHO);
+       RegisterNamespace("WHO:ROOM",        0, 1, tmplput_who_room, NULL, CTX_WHO);
+       RegisterNamespace("WHO:HOST",        0, 1, tmplput_who_host, NULL, CTX_WHO);
+       RegisterNamespace("WHO:REALROOM",    0, 1, tmplput_who_realroom, NULL, CTX_WHO);
+       RegisterNamespace("WHO:REALHOST",    0, 1, tmplput_who_realhost, NULL, CTX_WHO);
+       RegisterNamespace("WHO:LASTACTIVE",  0, 1, tmplput_who_lastactive, NULL, CTX_WHO);
+       RegisterNamespace("WHO:IDLESINCE",   0, 1, tmplput_who_idlesince, NULL, CTX_WHO);
+       RegisterNamespace("WHO:SESSION",     0, 1, tmplput_who_session, NULL, CTX_WHO);
+       RegisterNamespace("WHO:NSESSIONS",   0, 1, tmplput_who_nsessions, NULL, CTX_WHO);
+       RegisterNamespace("WHO:NSESSIONS",   0, 1, tmplput_who_nsessions, NULL, CTX_WHO);
 
        RegisterConditional(HKEY("WHO:IDLE"),      1, conditional_who_idle, CTX_WHO);
        RegisterConditional(HKEY("WHO:NSESSIONS"), 1, conditional_who_nsessions, CTX_WHO);
        RegisterConditional(HKEY("WHO:ISME"),      1, conditional_who_isme, CTX_WHO);
        RegisterConditional(HKEY("WHO:REALROOM"),  1, conditional_who_realroom, CTX_WHO);
+       RegisterConditional(HKEY("WHO:REALHOST"),  1, conditional_who_realhost, CTX_WHO);
 }