Integrated the DKIM signer into serv_smtpclient, but disabled it
[citadel.git] / webcit / static / instant_messenger.html
1 <html>
2 <head>
3         <title>Citadel Instant Messenger</title>
4         <script type="text/javascript" src="prototype.js"></script>
5         <script type="text/javascript" src="wclib.js"></script>
6         <script type="text/javascript" src="authmethods.js"></script>
7 </head>
8 <body onLoad='FetchNewMsgs();'>
9
10 <div id="thetop" style="position:fixed;width:100%;height:15%;top:0%;left:0%">
11 <div id="spacer1" style="background:#aaaaaa"><br></div>
12 <div id="tab_bar" style="background:#aaaaaa">&nbsp;&nbsp;</div>
13 <div id="spacer2" style="background:#aaaaaa"><br></div>
14 </div>
15
16 <div id="main" style="position:fixed;width:100%;height:85%;top:15%;left:0%;overflow:auto;background:#ffffff"></div>
17
18 <script type="text/javascript">
19 /*
20  * Copyright 2000 - 2010 The Citadel Team
21  * Licensed under the GPL V3
22  *
23  * Chat window for Person 2 Person Chat
24  *
25  */
26
27 var gexp_divs = new Array();
28 var num_gexp_divs = 0;
29 var shown_div = '';
30 var my_name = '';
31
32 function SendSomething(which_div, sendform, recipient) {
33         thetext = document.forms[sendform].elements['sendthis'].value;
34
35         // If the user didn't type anything, don't do anything.
36         if (thetext == '') {
37                 return false;
38         }
39
40         // Clear the box
41         document.forms[sendform].elements['sendthis'].value = '';
42
43         // Write it to the tab
44         $(which_div).innerHTML = $(which_div).innerHTML
45                                 + '<b>'
46                                 + '<font color=\"#FF0000\">'
47                                 + my_name
48                                 + '</font>'
49                                 + ':</b> '
50                                 + thetext
51                                 + '<br>\n';
52
53         // Scroll to the bottom of the tab
54         $('main').scrollTop = 999999;
55
56         // Send the text to the server
57         parms = 'r=' + Math.random()
58                 + '&recp=' + encodeURIComponent(recipient)
59                 + '&msg=' + encodeURIComponent(thetext);
60         new Ajax.Request('../ajax_send_instant_message',
61                 {
62                         method: 'post',
63                         parameters: parms
64                 }
65         );
66
67         // Refocus to the text box
68         document.forms[sendform].elements['sendthis'].focus();
69
70         // Don't submit the form
71         return false;
72 }
73
74 function TabSelect(which_div) {
75         if (shown_div != '') {
76                 $(shown_div).style.display = 'none' ;
77                 if ($('select_'+shown_div)) {
78                         $('select_'+shown_div).style.fontWeight = 'normal';
79                         $('select_'+shown_div).style.backgroundColor = '#cccccc';
80                 }
81         }
82         shown_div = 'tab_' + which_div;
83         $(shown_div).style.display = 'block' ;
84         if ($('select_'+shown_div)) {
85                 $('select_'+shown_div).style.fontWeight='bold';
86                 $('select_'+shown_div).style.backgroundColor = '#ffffff';
87         }
88 }
89
90
91 function ShowNewMsg(gexp_xmlresponse) {
92
93         // It isn't really XML.  It's a Citadel server response.
94         gexp_response = gexp_xmlresponse.responseText;
95
96         if (gexp_response.substring(0, 1) != '1') {
97                 return;
98         }
99
100         // Extract fields...
101         breakpos = gexp_response.indexOf('\n');
102         result = gexp_response.substring(0, breakpos-1);
103         the_message = gexp_response.substring(breakpos+1);
104         the_message = the_message.substring(0, the_message.indexOf('\n000'));
105
106         // Sanitize HTML in the message
107         the_message = the_message.replaceAll("&", "&amp;");
108         the_message = the_message.replaceAll("<", "&lt;");
109         the_message = the_message.replaceAll(">", "&gt;");
110
111         sender = extract_token(result.substring(4), 3, '|');
112
113         // Figure out which div to write it to...
114         which_div = '';
115         if (num_gexp_divs > 0) {
116                 for (i=0; i<num_gexp_divs; ++i) {
117                         if (gexp_divs[i] == sender) {
118                                 which_div = 'gexp' + i ;
119                         }
120                 }
121         }
122
123         // Not found?  Create it.
124         if (which_div == '') {
125                 gexp_divs[num_gexp_divs] = sender;
126                 which_div = 'gexp' + num_gexp_divs;
127                 ++num_gexp_divs;
128                 $('main').innerHTML =
129                           $('main').innerHTML
130                         + '<div id=\"tab_' + which_div + '\" style=\"display:none;cursor:pointer\">'
131                         + '<div id=\"' + which_div + '\">'
132                         + '<br><br><br><br><br><br><br><br><br><br>'
133                         + '<br><br><br><br><br><br><br><br><br><br>'
134                         + '</div>'
135                         + '<div align=\"center\" id=\"response_'
136                         + which_div + '\" style=\"background:#ddddee\">'
137                         + '<br><form method=\"post\" action=\"null\" name=\"sendform_' + which_div + '\" '
138                         + 'onSubmit=\"return SendSomething(\'' + which_div + '\', \'sendform_'
139                         + which_div + '\', \'' + sender + '\');\">'
140                         + '<img src=\"webcit_icons/essen/16x16/chat.png\">&nbsp;'
141                         + '<input type=\"text\" size=\"72\" maxlength=\"600\" name=\"sendthis\">'
142                         + '</form>'
143                         + '<br></div>'
144                         + '</div>\n';
145                 $('tab_bar').innerHTML =
146                           $('tab_bar').innerHTML
147                         + '<span id=\"select_tab_' + which_div + '\" onClick=\"TabSelect(\'' + which_div + '\');\">'
148                         + '&nbsp;' + sender + '&nbsp;'
149                         + '</span>&nbsp;&nbsp;&nbsp;';
150
151                 // Raise the window in case it was buried
152                 window.focus();
153         }
154
155         // Switch tabs
156         TabSelect(which_div);
157
158         // Write it to the tab
159         $(which_div).innerHTML = $(which_div).innerHTML
160                                 + '<b>'
161                                 + '<font color=\"#0000FF\">'
162                                 + sender
163                                 + '</font>'
164                                 + ':</b> '
165                                 + the_message
166                                 + '<br>\n';
167
168         // Scroll to the bottom of the tab
169         $('main').scrollTop = 999999;
170
171         // Refocus to the send box
172         document.forms['sendform_'+which_div].elements['sendthis'].focus();
173
174         // Keep trying for new messages until the server tells us to stop.
175         FetchNewMsgs();
176 }
177
178 // This is called periodically to check for new incoming messages
179 function FetchNewMsgs() {
180         parms = encodeURI('g_cmd=GEXP&r=' + Math.random());
181         new Ajax.Request('../ajax_servcmd',
182                 {
183                         method: 'get',
184                         parameters: parms,
185                         onSuccess: ShowNewMsg
186                 }
187         );
188 }
189
190 // Perform some initialization.
191 parms = encodeURI('g_cmd=GREG _SELF_&r=' + Math.random());
192 new Ajax.Request('../ajax_servcmd',
193         {
194                 method: 'get',
195                 parameters: parms,
196                 onSuccess: GrabMyName
197         }
198 );
199
200 // Learn my name.
201 function GrabMyName(greg_xmlresponse) {
202
203         // It isn't really XML.  It's a Citadel server response.
204         greg_response = greg_xmlresponse.responseText;
205
206         if (greg_response.substring(0, 1) != '1') {
207                 return;
208         }
209
210         // Extract fields...
211         breakpos = greg_response.indexOf('\n');
212         result = greg_response.substring(0, breakpos);
213         my_name = result.substring(4);
214 }
215
216
217 // Cause FetchNewMsgs() to be called periodically.
218 new PeriodicalExecuter(FetchNewMsgs, 10);
219
220 </script>
221
222
223 </body>
224 </html>