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