3 $nomoodlecookie = true; // Session not needed!
5 include('../../../config.php');
8 $chat_sid = required_param('chat_sid', PARAM_ALPHANUM
);
9 $beep = optional_param('beep', 0, PARAM_INT
); // beep target
11 if (!$chatuser = get_record('chat_users', 'sid', $chat_sid)) {
12 error('Not logged in!');
15 //Get the minimal course
16 if (!$course = get_record('course','id',$chatuser->course
,'','','','','id,theme,lang')) {
17 error('incorrect course id');
20 //Get the user theme and enough info to be used in chat_format_message() which passes it along to
21 if (!$USER = get_record('user','id',$chatuser->userid
,'','','','','id, lang, theme, username, timezone')) {
22 error('User does not exist!');
24 $USER->description
= '';
26 //Setup course, lang and theme
27 course_setup($course);
29 $courseid = $chatuser->course
;
32 $message->chatid
= $chatuser->chatid
;
33 $message->userid
= $chatuser->userid
;
34 $message->groupid
= $chatuser->groupid
;
35 $message->message
= "beep $beep";
37 $message->timestamp
= time();
39 if (!insert_record('chat_messages', $message)) {
40 error('Could not insert a chat message!');
43 $chatuser->lastmessageping
= time(); // A beep is a ping ;-)
46 $chatuser->lastping
= time();
47 set_field('chat_users', 'lastping', $chatuser->lastping
, 'id', $chatuser->id
);
49 $refreshurl = "users.php?chat_sid=$chat_sid";
53 if (!$chatusers = chat_get_users($chatuser->chatid
, $chatuser->groupid
)) {
54 error(get_string('errornousers', 'chat'));
59 <script type
="text/javascript">
63 var uidles
= new Array(<?php
echo count($chatusers) ?
>);
66 foreach ($chatusers as $chatuser) {
67 echo "uidles[$i] = 'uidle{$chatuser->id}';\n";
77 timer
= setTimeout("update()", f
*1000);
81 for(i
=0; i
<uidles
.length
; i++
) {
82 el
= document
.getElementById(uidles
[i
]);
84 parts
= el
.innerHTML
.split(":");
85 time
= f +
(parseInt(parts
[0], 10)*60) +
parseInt(parts
[1], 10);
86 min
= Math
.floor(time
/60);
88 el
.innerHTML
= ((min
< 10) ?
"0" : "") + min +
":" +
((sec
< 10) ?
"0" : "") + sec
;
91 timer
= setTimeout("update()", f
*1000);
99 $meta = ob_get_clean();
102 // Use ob to support Keep-Alive
104 print_header('', '', '', '', $meta, false, '', '', false, 'onload="start()" onunload="stop()"');
107 /// Print user panel body
109 $stridle = get_string('idle', 'chat');
110 $strbeep = get_string('beep', 'chat');
113 echo '<div style="display: none"><a href="'.$refreshurl.'" name="refreshLink">Refresh link</a></div>';
114 echo '<table width="100%">';
115 foreach ($chatusers as $chatuser) {
116 $lastping = $timenow - $chatuser->lastmessageping
;
117 $min = (int) ($lastping/60);
118 $sec = $lastping - ($min*60);
119 $min = $min < 10 ?
'0'.$min : $min;
120 $sec = $sec < 10 ?
'0'.$sec : $sec;
121 $idle = $min.':'.$sec;
122 echo '<tr><td width="35">';
123 echo "<a target=\"_blank\" onClick=\"return openpopup('/user/view.php?id=$chatuser->id&course=$courseid','user$chatuser->id','');\" href=\"$CFG->wwwroot/user/view.php?id=$chatuser->id&course=$courseid\">";
124 print_user_picture($chatuser->id
, 0, $chatuser->picture
, false, false, false);
125 echo '</a></td><td valign="center">';
126 echo '<p><font size="1">';
127 echo fullname($chatuser).'<br />';
128 echo "<span class=\"dimmed_text\">$stridle <span name=\"uidles\" id=\"uidle{$chatuser->id}\">$idle</span></span>";
129 echo " <a href=\"users.php?chat_sid=$chat_sid&beep=$chatuser->id\">$strbeep</a>";
133 // added 2 </div>s, xhtml strict complaints
134 echo '</table></div></div></body></html>';
137 // Support HTTP Keep-Alive by printing Content-Length
139 // If the user pane is refreshing often, using keepalives
140 // is lighter on the server and faster for most clients.
142 // Apache is normally configured to have a 15s timeout on
143 // keepalives, so let's observe that. Unfortunately, we cannot
144 // autodetect the keepalive timeout.
146 // Using keepalives when the refresh is longer than the timeout
147 // wastes server resources keeping an apache child around on a
148 // connection that will timeout. So we don't.
149 if ($CFG->chat_refresh_userlist
< 15) {
150 header("Content-Length: " . ob_get_length() );
154 exit; // no further output