* added support for multi-line paging
[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 buf[256];
31         char user[256];
32
33         output_headers(1);
34
35         wprintf("<TABLE WIDTH=100% BORDER=0 BGCOLOR=007700><TR><TD>");
36         wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
37         wprintf("<B>Page another user</B>\n");
38         wprintf("</FONT></TD></TR></TABLE>\n");
39
40         wprintf("This command sends a near-real-time message to any currently\n");
41         wprintf("logged in user.<BR><BR>\n");
42
43         wprintf("<FORM METHOD=\"POST\" ACTION=\"/page_user\">\n");
44
45
46         wprintf("<TABLE border=0 width=100%%><TR><TD>\n");
47
48         wprintf("Select a user to send a message to: <BR>");
49
50         wprintf("<SELECT NAME=\"recp\" SIZE=10>\n");
51         serv_puts("RWHO");
52         serv_gets(buf);
53         if (buf[0] == '1') {
54                 while (serv_gets(buf), strcmp(buf, "000")) {
55                         extract(user, buf, 1);
56                         wprintf("<OPTION>");
57                         escputs(user);
58                         wprintf("\n");
59                 }
60         }
61         wprintf("</SELECT>\n");
62
63         wprintf("</TD><TD>");
64
65         wprintf("Enter message text:<BR>");
66
67         wprintf("<TEXTAREA NAME=\"msgtext\" wrap=soft ROWS=5 COLS=40 "
68                 "WIDTH=40></TEXTAREA><P>\n");
69
70         wprintf("</TD></TR></TABLE><BR>\n");
71
72         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Send message\">");
73         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\"><BR>\n");
74
75         wprintf("</FORM></CENTER>\n");
76         wDumpContent(1);
77 }
78
79 /*
80  * page another user
81  */
82 void page_user(void)
83 {
84         char recp[256];
85         char sc[256];
86         char buf[256];
87
88         output_headers(1);
89
90         strcpy(recp, bstr("recp"));
91         strcpy(sc, bstr("sc"));
92
93         if (strcmp(sc, "Send message")) {
94                 wprintf("<EM>Message was not sent.</EM><BR>\n");
95         } else {
96                 serv_printf("SEXP %s|-", recp);
97                 serv_gets(buf);
98
99                 if (buf[0] == '4') {
100                         text_to_server(bstr("msgtext"));
101                         serv_puts("000");
102                         wprintf("<EM>Message has been sent to ");
103                         escputs(recp);
104                         wprintf(".</EM><BR>\n");
105                 }
106                 else {
107                         wprintf("<EM>%s</EM><BR>\n", &buf[4]);
108                 }
109         }
110         wDumpContent(1);
111 }
112
113
114
115 /*
116  * multiuser chat
117  */
118 void do_chat(void)
119 {
120
121         output_headers(1);
122
123         wprintf("<TABLE WIDTH=100% BORDER=0 BGCOLOR=000077><TR><TD>");
124         wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
125         wprintf("<B>Real-time chat</B>\n");
126         wprintf("</FONT></TD></TR></TABLE>\n");
127
128         wprintf("A chat window should be appearing on your screen ");
129         wprintf("momentarily.  When you're ");
130         wprintf("done, type <TT>/quit</TT> to exit.  You can also ");
131         wprintf("type <TT>/help</TT> for more commands.\n");
132
133         wprintf("<applet codebase=\"/static\" ");
134         wprintf("code=\"wcchat\" width=2 height=2>\n");
135         wprintf("<PARAM NAME=username VALUE=\"%s\">\n", WC->wc_username);
136         wprintf("<PARAM NAME=password VALUE=\"%s\">\n", WC->wc_password);
137         wprintf("<PARAM NAME=roomname VALUE=\"%s\">\n", WC->wc_roomname);
138         wprintf("<H2>Oops!</H2>Looks like your browser doesn't support Java, ");
139         wprintf("so you won't be able to access Chat.  Sorry.\n");
140         wprintf("</applet>\n");
141         wDumpContent(1);
142 }
143
144
145 /*
146  *
147  */
148 void page_popup(void)
149 {
150         char buf[256];
151         char pagefrom[256];
152
153         /* suppress express message check, do headers but no fake frames */
154         output_headers(0x08 | 0x03);
155
156         while (serv_puts("GEXP"), serv_gets(buf), buf[0]=='1') {
157
158                 extract(pagefrom, &buf[4], 3);
159
160                 wprintf("<TABLE WIDTH=100% BORDER=0 BGCOLOR=007700><TR><TD>");
161                 wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\""
162                         "<B>Express message from ");
163                 escputs(pagefrom);
164                 wprintf("</B></FONT></TD></TR></TABLE>\n");
165                 
166                 fmout(NULL);
167         }
168
169         wprintf("<CENTER>"
170                 "<A HREF=\"javascript:window.close();\">"
171                 "[ close window ]</A></B>\n"
172                 "</CENTER>");
173
174         wDumpContent(1);
175         WC->HaveExpressMessages = 0;
176 }
177
178