Back to index

webcit  8.12-dfsg
paging.c
Go to the documentation of this file.
00001 /*
00002  * This module handles instant message related functions.
00003  *
00004  * Copyright (c) 1996-2012 by the citadel.org team
00005  *
00006  * This program is open source software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License, version 3.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  */
00014 
00015 #include "webcit.h"
00016 
00017 /*
00018  * display the form for paging (x-messaging) another user
00019  */
00020 void display_page(void)
00021 {
00022        char recp[SIZ];
00023 
00024        strcpy(recp, bstr("recp"));
00025 
00026         output_headers(1, 1, 1, 0, 0, 0);
00027         wc_printf("<div id=\"room_banner_override\">\n");
00028         wc_printf("<h1>");
00029        wc_printf(_("Send instant message"));
00030        wc_printf("</h1>");
00031         wc_printf("</div>\n");
00032 
00033        wc_printf("<div id=\"content\" class=\"service\">\n");
00034 
00035        wc_printf("<table class=\"paging_background\"><tr><td>\n");
00036 
00037        wc_printf(_("Send an instant message to: "));
00038        escputs(recp);
00039        wc_printf("<br>\n");
00040 
00041        wc_printf("<FORM METHOD=\"POST\" action=\"page_user\">\n");
00042        wc_printf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
00043        wc_printf("<input type=\"hidden\" name=\"template\" value=\"who\">\n");
00044 
00045        wc_printf("<TABLE border=0 width=100%%><TR><TD>\n");
00046 
00047        wc_printf("<INPUT TYPE=\"hidden\" NAME=\"recp\" VALUE=\"");
00048        escputs(recp);
00049        wc_printf("\">\n");
00050 
00051        wc_printf(_("Enter message text:"));
00052        wc_printf("<br>");
00053 
00054        wc_printf("<TEXTAREA NAME=\"msgtext\" wrap=soft ROWS=5 COLS=40 "
00055               "WIDTH=40></TEXTAREA>\n");
00056 
00057        wc_printf("</TD></TR></TABLE><br>\n");
00058 
00059        wc_printf("<INPUT TYPE=\"submit\" NAME=\"send_button\" VALUE=\"%s\">", _("Send message"));
00060        wc_printf("<br><a href=\"javascript:window.close();\"%s</A>\n", _("Cancel"));
00061 
00062        wc_printf("</FORM></CENTER>\n");
00063        wc_printf("</td></tr></table>\n");
00064        wDumpContent(1);
00065 }
00066 
00067 /*
00068  * page another user
00069  */
00070 void page_user(void)
00071 {
00072        char recp[256];
00073        StrBuf *Line;
00074 
00075        safestrncpy(recp, bstr("recp"), sizeof recp);
00076 
00077        if (!havebstr("send_button")) {
00078               AppendImportantMessage(_("Message was not sent."), -1);
00079        } else {
00080               Line = NewStrBuf();
00081               serv_printf("SEXP %s|-", recp);
00082               StrBuf_ServGetln(Line);
00083               if (GetServerStatusMsg(Line, NULL, 0, 0) == 4) {
00084                      char buf[256];
00085                      text_to_server(bstr("msgtext"));
00086                      serv_puts("000");
00087                      stresc(buf, 256, recp, 0, 0);
00088                      AppendImportantMessage(buf, -1);
00089                      AppendImportantMessage(_("Message has been sent to "), -1);
00090               }
00091        }
00092 
00093        url_do_template();
00094 }
00095 
00096 
00097 
00098 /*
00099  * display page popup
00100  * If there are instant messages waiting, and we notice that we haven't checked them in
00101  * a while, it probably means that we need to open the instant messenger window.
00102  */
00103 int Conditional_PAGE_WAITING(StrBuf *Target, WCTemplputParams *TP)
00104 {
00105        int len;
00106        char buf[SIZ];
00107 
00110        serv_puts("NOOP");
00111        len = serv_getln(buf, sizeof buf);
00112        if ((len >= 3) && (buf[3] == '*')) {
00113               if ((time(NULL) - WC->last_pager_check) > 60) {
00114                      return 1;
00115               }
00116        }
00117        return 0;
00118        /* Then schedule it to happen again a minute from now if the user is idle. */
00119 }
00120 
00121 
00122 void ajax_send_instant_message(void) {
00123        char recp[256];
00124        char buf[256];
00125 
00126        safestrncpy(recp, bstr("recp"), sizeof recp);
00127 
00128        serv_printf("SEXP %s|-", recp);
00129        serv_getln(buf, sizeof buf);
00130 
00131        if (buf[0] == '4') {
00132               text_to_server(bstr("msg"));
00133               serv_puts("000");
00134        }
00135 
00136        escputs(buf); /* doesn't really matter what we return - the client ignores it */
00137 }
00138 
00139 
00140 void 
00141 InitModule_PAGING
00142 (void)
00143 {
00144        WebcitAddUrlHandler(HKEY("display_page"), "", 0, display_page, 0);
00145        WebcitAddUrlHandler(HKEY("page_user"), "", 0, page_user, 0);
00146        WebcitAddUrlHandler(HKEY("ajax_send_instant_message"), "", 0, ajax_send_instant_message, AJAX);
00147        RegisterConditional(HKEY("COND:PAGE:WAITING"), 0, Conditional_PAGE_WAITING, CTX_NONE);
00148 }
00149 
00150 
00151 void 
00152 SessionDestroyModule_PAGING
00153 (wcsession *sess)
00154 {
00155        /* nothing here anymore */
00156 }