3 * This module handles instant message related functions.
5 * Copyright (c) 1996-2012 by the citadel.org team
7 * This program is open source software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License, version 3.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
19 * display the form for paging (x-messaging) another user
21 void display_page(void) {
24 strcpy(recp, bstr("recp"));
26 output_headers(1, 1, 1, 0, 0, 0);
27 wc_printf("<div id=\"room_banner_override\">\n");
29 wc_printf(_("Send instant message"));
31 wc_printf("</div>\n");
33 wc_printf("<div id=\"content\" class=\"service\">\n");
35 wc_printf("<table class=\"paging_background\"><tr><td>\n");
37 wc_printf(_("Send an instant message to: "));
41 wc_printf("<FORM METHOD=\"POST\" action=\"page_user\">\n");
42 wc_printf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
43 wc_printf("<input type=\"hidden\" name=\"template\" value=\"who\">\n");
45 wc_printf("<TABLE border=0 width=100%%><TR><TD>\n");
47 wc_printf("<INPUT TYPE=\"hidden\" NAME=\"recp\" VALUE=\"");
51 wc_printf(_("Enter message text:"));
54 wc_printf("<TEXTAREA NAME=\"msgtext\" wrap=soft ROWS=5 COLS=40 " "WIDTH=40></TEXTAREA>\n");
56 wc_printf("</TD></TR></TABLE><br>\n");
58 wc_printf("<INPUT TYPE=\"submit\" NAME=\"send_button\" VALUE=\"%s\">", _("Send message"));
59 wc_printf("<br><a href=\"javascript:window.close();\"%s</A>\n", _("Cancel"));
61 wc_printf("</FORM></CENTER>\n");
62 wc_printf("</td></tr></table>\n");
69 void page_user(void) {
73 safestrncpy(recp, bstr("recp"), sizeof recp);
75 if (!havebstr("send_button")) {
76 AppendImportantMessage(_("Message was not sent."), -1);
80 serv_printf("SEXP %s|-", recp);
81 StrBuf_ServGetln(Line);
82 if (GetServerStatusMsg(Line, NULL, 0, 0) == 4) {
84 text_to_server(bstr("msgtext"));
86 stresc(buf, 256, recp, 0, 0);
87 AppendImportantMessage(buf, -1);
88 AppendImportantMessage(_("Message has been sent to "), -1);
99 * If there are instant messages waiting, and we notice that we haven't checked them in
100 * a while, it probably means that we need to open the instant messenger window.
102 int Conditional_PAGE_WAITING(StrBuf * Target, WCTemplputParams * TP) {
106 /** JavaScript function to alert the user that popups are probably blocked */
108 /** First, do the check as part of our page load. */
110 len = serv_getln(buf, sizeof buf);
111 if ((len >= 3) && (buf[3] == '*')) {
112 if ((time(NULL) - WC->last_pager_check) > 60) {
117 /* Then schedule it to happen again a minute from now if the user is idle. */
121 void ajax_send_instant_message(void) {
125 safestrncpy(recp, bstr("recp"), sizeof recp);
127 serv_printf("SEXP %s|-", recp);
128 serv_getln(buf, sizeof buf);
131 text_to_server(bstr("msg"));
135 escputs(buf); /* doesn't really matter what we return - the client ignores it */
139 void InitModule_PAGING(void) {
140 WebcitAddUrlHandler(HKEY("display_page"), "", 0, display_page, 0);
141 WebcitAddUrlHandler(HKEY("page_user"), "", 0, page_user, 0);
142 WebcitAddUrlHandler(HKEY("ajax_send_instant_message"), "", 0, ajax_send_instant_message, AJAX);
143 RegisterConditional("COND:PAGE:WAITING", 0, Conditional_PAGE_WAITING, CTX_NONE);
147 void SessionDestroyModule_PAGING(wcsession * sess) {
148 /* nothing here anymore */