1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
|
<?php // $Id: users.php,v 1.7 2006/04/17 21:05:51 martinlanghoff Exp $
$nomoodlecookie = true; // Session not needed!
include('../../../config.php');
include('../lib.php');
$chat_sid = required_param('chat_sid', PARAM_ALPHANUM);
$beep = optional_param('beep', 0, PARAM_INT); // beep target
if (!$chatuser = get_record('chat_users', 'sid', $chat_sid)) {
error('Not logged in!');
}
//Get the course theme
$course = get_record('course','id',$chatuser->course,'','','','','id,theme');
//Set the course theme if necessary
if (!empty($course->theme)) {
if (!empty($CFG->allowcoursethemes)) {
$CFG->coursetheme = $course->theme;
}
}
//Get the user theme
$USER = get_record('user','id',$chatuser->userid,'','','','','id, theme');
//Adjust the prefered theme (main, course, user)
theme_setup();
chat_force_language($chatuser->lang);
$courseid = $chatuser->course;
if ($beep) {
$message->chatid = $chatuser->chatid;
$message->userid = $chatuser->userid;
$message->groupid = $chatuser->groupid;
$message->message = "beep $beep";
$message->system = 0;
$message->timestamp = time();
if (!insert_record('chat_messages', $message)) {
error('Could not insert a chat message!');
}
$chatuser->lastmessageping = time(); // A beep is a ping ;-)
}
$chatuser->lastping = time();
set_field('chat_users', 'lastping', $chatuser->lastping, 'id', $chatuser->id );
$refreshurl = "users.php?chat_sid=$chat_sid";
/// Get list of users
if (!$chatusers = chat_get_users($chatuser->chatid, $chatuser->groupid)) {
error(get_string('errornousers', 'chat'));
}
ob_start();
?>
<script type="text/javascript">
<!--
var timer = null
var f = 1; //seconds
var uidles = new Array(<?php echo count($chatusers) ?>);
<?php
$i = 0;
foreach ($chatusers as $chatuser) {
echo "uidles[$i] = 'uidle{$chatuser->id}';\n";
$i++;
}
?>
function stop() {
clearTimeout(timer)
}
function start() {
timer = setTimeout("update()", f*1000);
}
function update() {
for(i=0; i<uidles.length; i++) {
el = document.getElementById(uidles[i]);
if (el != null) {
parts = el.innerHTML.split(":");
time = f + (parseInt(parts[0], 10)*60) + parseInt(parts[1], 10);
min = Math.floor(time/60);
sec = time % 60;
el.innerHTML = ((min < 10) ? "0" : "") + min + ":" + ((sec < 10) ? "0" : "") + sec;
}
}
timer = setTimeout("update()", f*1000);
}
// -->
</script>
<?php
/// Print headers
$meta = ob_get_clean();
// Use ob to support Keep-Alive
ob_start();
print_header('', '', '', '', $meta, false, '', '', false, 'onload="start()" onunload="stop()"');
/// Print user panel body
$timenow = time();
$stridle = get_string('idle', 'chat');
$strbeep = get_string('beep', 'chat');
echo '<div style="display: none"><a href="'.$refreshurl.'" name="refreshLink">Refresh link</a></div>';
echo '<table width="100%">';
foreach ($chatusers as $chatuser) {
$lastping = $timenow - $chatuser->lastmessageping;
$min = (int) ($lastping/60);
$sec = $lastping - ($min*60);
$min = $min < 10 ? '0'.$min : $min;
$sec = $sec < 10 ? '0'.$sec : $sec;
$idle = $min.':'.$sec;
echo '<tr><td width="35">';
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\">";
print_user_picture($chatuser->id, 0, $chatuser->picture, false, false, false);
echo '</a></td><td valign="center">';
echo '<p><font size="1">';
echo fullname($chatuser).'<br />';
echo "<span class=\"dimmed_text\">$stridle <span name=\"uidles\" id=\"uidle{$chatuser->id}\">$idle</span></span>";
echo " <a href=\"users.php?chat_sid=$chat_sid&beep=$chatuser->id\">$strbeep</a>";
echo '</font></p>';
echo '<td></tr>';
}
echo '</table></body></html>';
//
// Support HTTP Keep-Alive by printing Content-Length
//
// If the user pane is refreshing often, using keepalives
// is lighter on the server and faster for most clients.
//
// Apache is normally configured to have a 15s timeout on
// keepalives, so let's observe that. Unfortunately, we cannot
// autodetect the keepalive timeout.
//
// Using keepalives when the refresh is longer than the timeout
// wastes server resources keeping an apache child around on a
// connection that will timeout. So we don't.
if ($CFG->chat_refresh_userlist < 15) {
header("Content-Length: " . ob_get_length() );
ob_end_flush();
}
exit; // no further output
?>
|