* fix_scrollbar_bug is now a class instead of an id. Fixes validator warnings.
[citadel.git] / webcit / paging.c
index 6e200f6b2f5c66f239090a71b9ea74a7eb578851..ddc2fbbeaf1087422b7dbb255e2d15ce4f9bba01 100644 (file)
@@ -25,14 +25,14 @@ void display_page(void)
                 "</div>\n<div id=\"content\">\n"
         );
                                                                                                                              
-        wprintf("<div id=\"fix_scrollbar_bug\">"
+        wprintf("<div class=\"fix_scrollbar_bug\">"
                "<table border=0 width=100%% bgcolor=\"#ffffff\"><tr><td>\n");
 
        wprintf(_("Send an instant message to: "));
        escputs(recp);
        wprintf("<br>\n");
 
-       wprintf("<FORM METHOD=\"POST\" ACTION=\"/page_user\">\n");
+       wprintf("<FORM METHOD=\"POST\" action=\"page_user\">\n");
 
        wprintf("<TABLE border=0 width=100%%><TR><TD>\n");
 
@@ -53,7 +53,7 @@ void display_page(void)
        wprintf("</TD></TR></TABLE><br />\n");
 
        wprintf("<INPUT TYPE=\"submit\" NAME=\"send_button\" VALUE=\"%s\">", _("Send message"));
-       wprintf("<br /><A HREF=\"javascript:window.close();\"%s</A>\n", _("Cancel"));
+       wprintf("<br /><a href=\"javascript:window.close();\"%s</A>\n", _("Cancel"));
 
        wprintf("</FORM></CENTER>\n");
        wprintf("</td></tr></table></div>\n");
@@ -104,7 +104,7 @@ void page_user(void)
        }
        
        if (!strcasecmp(closewin, "yes")) {
-               wprintf("<CENTER><A HREF=\"javascript:window.close();\">");
+               wprintf("<CENTER><a href=\"javascript:window.close();\">");
                wprintf(_("[ close window ]"));
                wprintf("</A></CENTER>\n");
        }
@@ -138,42 +138,53 @@ void do_chat(void)
        }
 
        /* WebCit Chat works by having transmit, receive, and refresh
-        * frames.  Load the frameset.
+        * frames.  Load the frameset.  (This isn't AJAX but the headers
+        * output by begin_ajax_response() happen to be the ones we need.)
         */
+       begin_ajax_response();
        do_template("chatframeset");
+       end_ajax_response();
        return;
 }
 
 
 /*
- *
+ * If there are instant messages waiting, and we notice that we haven't checked them in
+ * a while, it probably means that we need to open the instant messenger window.
  */
 void page_popup(void)
 {
        char buf[SIZ];
-       char pagefrom[SIZ];
-
-       while (serv_puts("GEXP"), serv_getln(buf, sizeof buf), buf[0]=='1') {
 
-               extract_token(pagefrom, &buf[4], 3, '|', sizeof pagefrom);
-
-               wprintf("<table border=1 bgcolor=\"#880000\"><tr><td>");
-               wprintf("<span class=\"titlebar\">");
-               wprintf(_("Instant message from "));
-               escputs(pagefrom);
-               wprintf("</span></td></tr><tr><td><font color=\"#FFFFFF\">");
-               fmout("LEFT");
-               wprintf("</font></td></tr>"
-                       "<tr><td><div align=center><font color=\"#FFFFFF\">"
-                       "<a href=\"javascript:hide_page_popup()\">");
-               wprintf(_("[ close window ]"));
-               wprintf("</a>"
-                       "</font></div>"
-                       "</td></tr>"
-                       "</table>\n");
+       /* First, do the check as part of our page load. */
+       serv_puts("NOOP");
+       serv_getln(buf, sizeof buf);
+       if (buf[3] == '*') {
+               if ((time(NULL) - WC->last_pager_check) > 60) {
+                       wprintf("<script type=\"text/javascript\">"
+                               " window.open('static/instant_messenger.html', 'CTDL_MESSENGER', "
+                               " 'width=700,height=400');"
+                               "</script>"
+                       );      
+               }
        }
 
-       WC->HaveInstantMessages = 0;
+       /* Then schedule it to happen again a minute from now if the user is idle. */
+       wprintf("<script type=\"text/javascript\">      \n"
+               " function HandleSslp(sslg_xmlresponse) {       \n"
+               "  sslg_response = sslg_xmlresponse.responseText.substr(0, 1);  \n"
+               "  if (sslg_response == 'Y') {  \n"
+               "   window.open('static/instant_messenger.html', 'CTDL_MESSENGER',      \n"
+               "    'width=700,height=400');   \n"
+               "   }   \n"
+               " }     \n"
+               " function CheckPager() {       \n"
+               "  new Ajax.Request('sslg', { method: 'get', parameters: Math.random(), \n"
+               "   onSuccess: HandleSslp } );  \n"
+               " }     \n"
+               " new PeriodicalExecuter(CheckPager, 30);       \n"
+               "</script>      \n"
+       );
 }
 
 
@@ -317,7 +328,7 @@ void chat_recv(void) {
        if (end_chat_now) {
                close(WC->chat_sock);
                WC->chat_sock = (-1);
-               wprintf("<IMG SRC=\"/static/blank.gif\" onLoad=\"parent.window.close();\">\n");
+               wprintf("<img src=\"static/blank.gif\" onLoad=\"parent.window.close();\">\n");
        }
 
        if (strlen(output_data) > 0) {
@@ -327,7 +338,7 @@ void chat_recv(void) {
                }
 
                /* Output our fun to the other frame. */
-               wprintf("<IMG SRC=\"/static/blank.gif\" WIDTH=1 HEIGHT=1\n"
+               wprintf("<img src=\"static/blank.gif\" WIDTH=1 HEIGHT=1\n"
                        "onLoad=\" \n"
                );
 
@@ -362,7 +373,7 @@ void chat_recv(void) {
                                if (strcasecmp(cl_user, WC->last_chat_user)) {
                                        wprintf("<B>");
        
-                                       if (!strcasecmp(cl_user, WC->wc_username)) {
+                                       if (!strcasecmp(cl_user, WC->wc_fullname)) {
                                                wprintf("<FONT COLOR=&quot;#FF0000&quot;>");
                                        }
                                        else {
@@ -464,7 +475,7 @@ void chat_send(void) {
        WC->serv_sock = WC->chat_sock;
        WC->chat_sock = i;
 
-       wprintf("<FORM METHOD=\"POST\" ACTION=\"/chat_send\" NAME=\"chatsendform\">\n");
+       wprintf("<FORM METHOD=\"POST\" action=\"chat_send\" NAME=\"chatsendform\">\n");
        wprintf("<INPUT TYPE=\"text\" SIZE=\"80\" MAXLENGTH=\"%d\" "
                "NAME=\"send_this\">\n", SIZ-10);
        wprintf("<br />");
@@ -478,4 +489,3 @@ void chat_send(void) {
        wDumpContent(0);
 }
 
-