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