removed a bunch of blank comment lines
[citadel.git] / webcit / paging.c
1 /*
2  * This module handles instant message related functions.
3  *
4  * Copyright (c) 1996-2012 by the citadel.org team
5  *
6  * This program is open source software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License, version 3.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  */
14
15 #include "webcit.h"
16
17 /*
18  * display the form for paging (x-messaging) another user
19  */
20 void display_page(void)
21 {
22         char recp[SIZ];
23
24         strcpy(recp, bstr("recp"));
25
26         output_headers(1, 1, 1, 0, 0, 0);
27         wc_printf("<div id=\"room_banner_override\">\n");
28         wc_printf("<h1>");
29         wc_printf(_("Send instant message"));
30         wc_printf("</h1>");
31         wc_printf("</div>\n");
32
33         wc_printf("<div id=\"content\" class=\"service\">\n");
34
35         wc_printf("<table class=\"paging_background\"><tr><td>\n");
36
37         wc_printf(_("Send an instant message to: "));
38         escputs(recp);
39         wc_printf("<br>\n");
40
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");
44
45         wc_printf("<TABLE border=0 width=100%%><TR><TD>\n");
46
47         wc_printf("<INPUT TYPE=\"hidden\" NAME=\"recp\" VALUE=\"");
48         escputs(recp);
49         wc_printf("\">\n");
50
51         wc_printf(_("Enter message text:"));
52         wc_printf("<br>");
53
54         wc_printf("<TEXTAREA NAME=\"msgtext\" wrap=soft ROWS=5 COLS=40 "
55                 "WIDTH=40></TEXTAREA>\n");
56
57         wc_printf("</TD></TR></TABLE><br>\n");
58
59         wc_printf("<INPUT TYPE=\"submit\" NAME=\"send_button\" VALUE=\"%s\">", _("Send message"));
60         wc_printf("<br><a href=\"javascript:window.close();\"%s</A>\n", _("Cancel"));
61
62         wc_printf("</FORM></CENTER>\n");
63         wc_printf("</td></tr></table>\n");
64         wDumpContent(1);
65 }
66
67 /*
68  * page another user
69  */
70 void page_user(void)
71 {
72         char recp[256];
73         StrBuf *Line;
74
75         safestrncpy(recp, bstr("recp"), sizeof recp);
76
77         if (!havebstr("send_button")) {
78                 AppendImportantMessage(_("Message was not sent."), -1);
79         } else {
80                 Line = NewStrBuf();
81                 serv_printf("SEXP %s|-", recp);
82                 StrBuf_ServGetln(Line);
83                 if (GetServerStatusMsg(Line, NULL, 0, 0) == 4) {
84                         char buf[256];
85                         text_to_server(bstr("msgtext"));
86                         serv_puts("000");
87                         stresc(buf, 256, recp, 0, 0);
88                         AppendImportantMessage(buf, -1);
89                         AppendImportantMessage(_("Message has been sent to "), -1);
90                 }
91         }
92
93         url_do_template();
94 }
95
96
97
98 /*
99  * display page popup
100  * If there are instant messages waiting, and we notice that we haven't checked them in
101  * a while, it probably means that we need to open the instant messenger window.
102  */
103 int Conditional_PAGE_WAITING(StrBuf *Target, WCTemplputParams *TP)
104 {
105         int len;
106         char buf[SIZ];
107
108         /** JavaScript function to alert the user that popups are probably blocked */
109         /** First, do the check as part of our page load. */
110         serv_puts("NOOP");
111         len = serv_getln(buf, sizeof buf);
112         if ((len >= 3) && (buf[3] == '*')) {
113                 if ((time(NULL) - WC->last_pager_check) > 60) {
114                         return 1;
115                 }
116         }
117         return 0;
118         /* Then schedule it to happen again a minute from now if the user is idle. */
119 }
120
121
122 void ajax_send_instant_message(void) {
123         char recp[256];
124         char buf[256];
125
126         safestrncpy(recp, bstr("recp"), sizeof recp);
127
128         serv_printf("SEXP %s|-", recp);
129         serv_getln(buf, sizeof buf);
130
131         if (buf[0] == '4') {
132                 text_to_server(bstr("msg"));
133                 serv_puts("000");
134         }
135
136         escputs(buf);   /* doesn't really matter what we return - the client ignores it */
137 }
138
139
140 void 
141 InitModule_PAGING
142 (void)
143 {
144         WebcitAddUrlHandler(HKEY("display_page"), "", 0, display_page, 0);
145         WebcitAddUrlHandler(HKEY("page_user"), "", 0, page_user, 0);
146         WebcitAddUrlHandler(HKEY("ajax_send_instant_message"), "", 0, ajax_send_instant_message, AJAX);
147         RegisterConditional(HKEY("COND:PAGE:WAITING"), 0, Conditional_PAGE_WAITING, CTX_NONE);
148 }
149
150
151 void 
152 SessionDestroyModule_PAGING
153 (wcsession *sess)
154 {
155         /* nothing here anymore */
156 }