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
;
31 if (!$cm = get_coursemodule_from_instance('chat', $chatuser->chatid
, $courseid)) {
32 error('Course Module ID was incorrect');
36 $message->chatid
= $chatuser->chatid
;
37 $message->userid
= $chatuser->userid
;
38 $message->groupid
= $chatuser->groupid
;
39 $message->message
= "beep $beep";
41 $message->timestamp
= time();
43 if (!insert_record('chat_messages', $message)) {
44 error('Could not insert a chat message!');
47 $chatuser->lastmessageping
= time(); // A beep is a ping ;-)
50 $chatuser->lastping
= time();
51 set_field('chat_users', 'lastping', $chatuser->lastping
, 'id', $chatuser->id
);
53 $refreshurl = "users.php?chat_sid=$chat_sid";
57 if (!$chatusers = chat_get_users($chatuser->chatid
, $chatuser->groupid
, $cm->groupingid
)) {
58 error(get_string('errornousers', 'chat'));
63 <script type
="text/javascript">
67 var uidles
= new Array(<?php
echo count($chatusers) ?
>);
70 foreach ($chatusers as $chatuser) {
71 echo "uidles[$i] = 'uidle{$chatuser->id}';\n";
81 timer
= setTimeout("update()", f
*1000);
85 for(i
=0; i
<uidles
.length
; i++
) {
86 el
= document
.getElementById(uidles
[i
]);
88 parts
= el
.innerHTML
.split(":");
89 time
= f +
(parseInt(parts
[0], 10)*60) +
parseInt(parts
[1], 10);
90 min
= Math
.floor(time
/60);
92 el
.innerHTML
= ((min
< 10) ?
"0" : "") + min +
":" +
((sec
< 10) ?
"0" : "") + sec
;
95 timer
= setTimeout("update()", f
*1000);
103 $meta = ob_get_clean();
106 // Use ob to support Keep-Alive
108 print_header('', '', '', '', $meta, false, '', '', false, 'onload="start()" onunload="stop()"');
111 /// Print user panel body
113 $stridle = get_string('idle', 'chat');
114 $strbeep = get_string('beep', 'chat');
117 echo '<div style="display: none"><a href="'.$refreshurl.'" name="refreshLink">Refresh link</a></div>';
118 echo '<table width="100%">';
119 foreach ($chatusers as $chatuser) {
120 $lastping = $timenow - $chatuser->lastmessageping
;
121 $min = (int) ($lastping/60);
122 $sec = $lastping - ($min*60);
123 $min = $min < 10 ?
'0'.$min : $min;
124 $sec = $sec < 10 ?
'0'.$sec : $sec;
125 $idle = $min.':'.$sec;
126 echo '<tr><td width="35">';
127 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\">";
128 print_user_picture($chatuser->id
, 0, $chatuser->picture
, false, false, false);
129 echo '</a></td><td valign="center">';
130 echo '<p><font size="1">';
131 echo fullname($chatuser).'<br />';
132 echo "<span class=\"dimmed_text\">$stridle <span name=\"uidles\" id=\"uidle{$chatuser->id}\">$idle</span></span>";
133 echo " <a href=\"users.php?chat_sid=$chat_sid&beep=$chatuser->id\">$strbeep</a>";
137 // added 2 </div>s, xhtml strict complaints
138 echo '</table></div></div></body></html>';
141 // Support HTTP Keep-Alive by printing Content-Length
143 // If the user pane is refreshing often, using keepalives
144 // is lighter on the server and faster for most clients.
146 // Apache is normally configured to have a 15s timeout on
147 // keepalives, so let's observe that. Unfortunately, we cannot
148 // autodetect the keepalive timeout.
150 // Using keepalives when the refresh is longer than the timeout
151 // wastes server resources keeping an apache child around on a
152 // connection that will timeout. So we don't.
153 if ($CFG->chat_refresh_userlist
< 15) {
154 header("Content-Length: " . ob_get_length() );
158 exit; // no further output