* Force reload of frameset if someone tries to escape it. Not perfect
[citadel.git] / webcit / paging.c
1 /* $Id$ */
2
3 #include <ctype.h>
4 #include <stdlib.h>
5 #include <unistd.h>
6 #include <stdio.h>
7 #include <fcntl.h>
8 #include <signal.h>
9 #include <sys/types.h>
10 #include <sys/wait.h>
11 #include <sys/socket.h>
12 #include <sys/time.h>
13 #include <limits.h>
14 #include <netinet/in.h>
15 #include <netdb.h>
16 #include <string.h>
17 #include <pwd.h>
18 #include <errno.h>
19 #include <stdarg.h>
20 #include <pthread.h>
21 #include <signal.h>
22 #include "webcit.h"
23
24
25 /*
26  * display the form for paging (x-messaging) another user
27  */
28 void display_page(void)
29 {
30         char recp[SIZ];
31
32         strcpy(recp, bstr("recp"));
33
34         output_headers(3);
35
36         svprintf("BOXTITLE", WCS_STRING, "Page: %s", recp);
37         do_template("beginbox");
38
39         wprintf("<FORM METHOD=\"POST\" ACTION=\"/page_user\">\n");
40
41         wprintf("<TABLE border=0 width=100%%><TR><TD>\n");
42
43         wprintf("<INPUT TYPE=\"hidden\" NAME=\"recp\" VALUE=\"");
44         escputs(recp);
45         wprintf("\">\n");
46
47         wprintf("<INPUT TYPE=\"hidden\" NAME=\"closewin\" VALUE=\"");
48         escputs(bstr("closewin"));
49         wprintf("\">\n");
50
51         wprintf("Enter message text:<BR>");
52
53         wprintf("<TEXTAREA NAME=\"msgtext\" wrap=soft ROWS=5 COLS=40 "
54                 "WIDTH=40></TEXTAREA>\n");
55
56         wprintf("</TD></TR></TABLE><BR>\n");
57
58         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Send message\">");
59         wprintf("<BR><A HREF=\"javascript:window.close();\"Cancel</A>\n");
60
61         wprintf("</FORM></CENTER>\n");
62         do_template("endbox");
63         wDumpContent(1);
64 }
65
66 /*
67  * page another user
68  */
69 void page_user(void)
70 {
71         char recp[SIZ];
72         char sc[SIZ];
73         char buf[SIZ];
74         char closewin[SIZ];
75
76         output_headers(3);
77
78         strcpy(recp, bstr("recp"));
79         strcpy(sc, bstr("sc"));
80         strcpy(closewin, bstr("closewin"));
81
82         if (strcmp(sc, "Send message")) {
83                 wprintf("<EM>Message was not sent.</EM><BR>\n");
84         } else {
85                 serv_printf("SEXP %s|-", recp);
86                 serv_gets(buf);
87
88                 if (buf[0] == '4') {
89                         text_to_server(bstr("msgtext"), 0);
90                         serv_puts("000");
91                         wprintf("<EM>Message has been sent to ");
92                         escputs(recp);
93                         wprintf(".</EM><BR>\n");
94                 }
95                 else {
96                         wprintf("<EM>%s</EM><BR>\n", &buf[4]);
97                 }
98         }
99         
100         if (!strcasecmp(closewin, "yes")) {
101                 wprintf("<CENTER><A HREF=\"javascript:window.close();\">"
102                         "[ close window ]</A></CENTER>\n");
103         }
104
105         wDumpContent(1);
106 }
107
108
109
110 /*
111  * multiuser chat
112  */
113 void do_chat(void)
114 {
115
116         output_headers(1);
117
118         wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#000077\"><TR><TD>");
119         wprintf("<SPAN CLASS=\"titlebar\">Real-time chat</SPAN>\n");
120         wprintf("</TD></TR></TABLE>\n");
121
122         if (!strcasecmp(ctdlhost, "uds")) {
123                 wprintf("<I>Sorry ... chat is not available here.</i></BR>\n");
124         }
125         else {
126                 wprintf("A chat window should be appearing on your screen ");
127                 wprintf("momentarily.  When you're ");
128                 wprintf("done, type <TT>/quit</TT> to exit.  You can also ");
129                 wprintf("type <TT>/help</TT> for more commands.\n");
130         
131                 wprintf("<applet codebase=\"/static\" ");
132                 wprintf("code=\"wcchat\" width=2 height=2>\n");
133                 wprintf("<PARAM NAME=username VALUE=\"%s\">\n", WC->wc_username);
134                 wprintf("<PARAM NAME=password VALUE=\"%s\">\n", WC->wc_password);
135                 wprintf("<PARAM NAME=roomname VALUE=\"%s\">\n", WC->wc_roomname);
136                 wprintf("<H2>Oops!</H2>Looks like your browser doesn't support Java, ");
137                 wprintf("so you won't be able to access Chat.  Sorry.\n");
138                 wprintf("</applet>\n");
139         }
140         wDumpContent(1);
141 }
142
143
144 /*
145  *
146  */
147 void page_popup(void)
148 {
149         char buf[SIZ];
150         char pagefrom[SIZ];
151
152         /* suppress express message check, do headers but no frames */
153         output_headers(0x08 | 0x03);
154
155         while (serv_puts("GEXP"), serv_gets(buf), buf[0]=='1') {
156
157                 extract(pagefrom, &buf[4], 3);
158
159                 wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#007700\"><TR><TD>");
160                 wprintf("<SPAN CLASS=\"titlebar\">Instant message from ");
161                 escputs(pagefrom);
162                 wprintf("</SPAN></TD></TR></TABLE>\n");
163                 
164                 fmout(NULL, "LEFT");
165         }
166
167         wprintf("<CENTER>");
168         wprintf("<A HREF=\"/display_page&closewin=yes&recp=");
169         urlescputs(pagefrom);
170         wprintf("\">[ reply ]</A>&nbsp;&nbsp;&nbsp;\n");
171
172         wprintf("<A HREF=\"javascript:window.close();\">"
173                 "[ close window ]</A></B>\n"
174                 "</CENTER>");
175
176         wDumpContent(1);
177         WC->HaveExpressMessages = 0;
178 }
179
180