2005-02-03 20:39:27 +00:00
< ? php // $Id$
2003-07-07 06:44:16 +00:00
2005-02-03 20:39:27 +00:00
$nomoodlecookie = true ; // Session not needed!
2003-07-07 06:44:16 +00:00
2005-02-03 20:39:27 +00:00
require ( '../../../config.php' );
require ( '../lib.php' );
2004-02-24 06:35:57 +00:00
2005-02-03 20:39:27 +00:00
$chat_sid = required_param ( 'chat_sid' , PARAM_ALPHANUM );
$chat_lasttime = optional_param ( 'chat_lasttime' , 0 , PARAM_INT );
2005-09-10 22:57:21 +00:00
$chat_lastrow = optional_param ( 'chat_lastrow' , 1 , PARAM_INT );
2003-07-07 06:44:16 +00:00
2005-02-03 20:39:27 +00:00
if ( ! $chatuser = get_record ( 'chat_users' , 'sid' , $chat_sid )) {
error ( 'Not logged in!' );
}
2003-07-07 09:45:08 +00:00
2007-01-28 21:18:08 +00:00
//Get the minimal course
if ( ! $course = get_record ( 'course' , 'id' , $chatuser -> course , '' , '' , '' , '' , 'id,theme,lang' )) {
error ( 'incorrect course id' );
2005-09-10 22:57:21 +00:00
}
2006-04-17 21:06:28 +00:00
//Get the user theme and enough info to be used in chat_format_message() which passes it along to
2007-01-28 21:18:08 +00:00
if ( ! $USER = get_record ( 'user' , 'id' , $chatuser -> userid , '' , '' , '' , '' , 'id, lang, theme, username, timezone' )) {
2006-04-17 21:06:28 +00:00
error ( 'User does not exist!' );
}
$USER -> description = '' ;
2005-09-10 22:57:21 +00:00
2007-01-28 21:18:08 +00:00
//Setup course, lang and theme
course_setup ( $course );
2003-07-07 09:45:08 +00:00
2005-02-03 20:39:27 +00:00
// force deleting of timed out users if there is a silence in room or just entering
if (( time () - $chat_lasttime ) > $CFG -> chat_old_ping ) {
// must be done before chat_get_latest_message!!!
chat_delete_old_users ();
}
2003-07-07 06:44:16 +00:00
2005-02-03 20:39:27 +00:00
if ( $message = chat_get_latest_message ( $chatuser -> chatid , $chatuser -> groupid )) {
$chat_newlasttime = $message -> timestamp ;
} else {
$chat_newlasttime = 0 ;
}
2003-07-07 06:44:16 +00:00
2005-02-03 20:39:27 +00:00
if ( $chat_lasttime == 0 ) { //display some previous messages
$chat_lasttime = time () - $CFG -> chat_old_ping ; //TO DO - any better value??
}
2003-07-07 06:44:16 +00:00
2005-02-03 20:39:27 +00:00
$timenow = time ();
$groupselect = $chatuser -> groupid ? " AND (groupid=' " . $chatuser -> groupid . " ' OR groupid='0') " : " " ;
2005-09-10 22:57:21 +00:00
$messages = get_records_select ( " chat_messages " ,
" chatid = ' $chatuser->chatid ' AND timestamp > ' $chat_lasttime ' $groupselect " ,
" timestamp ASC " );
if ( $messages ) {
$num = count ( $messages );
} else {
$num = 0 ;
}
$chat_newrow = ( $chat_lastrow + $num ) % 2 ;
2006-04-17 21:04:19 +00:00
// no & in url, does not work in header!
$refreshurl = " { $CFG -> wwwroot } /mod/chat/gui_header_js/jsupdate.php?chat_sid= $chat_sid &chat_lasttime= $chat_newlasttime &chat_lastrow= $chat_newrow " ;
2006-12-22 05:42:36 +00:00
$refreshurlamp = " { $CFG -> wwwroot } /mod/chat/gui_header_js/jsupdate.php?chat_sid= $chat_sid &chat_lasttime= $chat_newlasttime &chat_lastrow= $chat_newrow " ;
2005-09-10 22:57:21 +00:00
2005-02-03 20:39:27 +00:00
header ( 'Expires: Sun, 28 Dec 1997 09:32:45 GMT' );
header ( 'Last-Modified: ' . gmdate ( 'D, d M Y H:i:s' ) . ' GMT' );
header ( 'Cache-Control: no-cache, must-revalidate' );
header ( 'Pragma: no-cache' );
2006-11-11 17:23:20 +00:00
header ( 'Content-Type: text/html; charset=utf-8' );
2005-02-03 20:39:27 +00:00
header ( " Refresh: $CFG->chat_refresh_room ; url= $refreshurl " );
2003-07-07 06:44:16 +00:00
2005-02-13 16:30:16 +00:00
/// required stylesheets
$stylesheetshtml = '' ;
foreach ( $CFG -> stylesheets as $stylesheet ) {
2007-01-01 13:26:20 +00:00
$stylesheetshtml .= '<link rel="stylesheet" type="text/css" href="' . $stylesheet . '" />' ;
2005-02-13 16:30:16 +00:00
}
2006-04-17 21:04:19 +00:00
// use ob to be able to send Content-Length headers
// needed for Keep-Alive to work
ob_start ();
2003-07-07 06:44:16 +00:00
?>
2005-09-10 22:57:21 +00:00
<! DOCTYPE html PUBLIC " -//W3C//DTD XHTML 1.0 Transitional//EN " " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd " >
2005-02-03 20:39:27 +00:00
< html >
< head >
2006-12-22 05:42:36 +00:00
< title > </ title >
2006-11-11 17:23:20 +00:00
< meta http - equiv = " content-type " content = " text/html; charset=utf-8 " />
2005-02-03 20:39:27 +00:00
< script type = " text/javascript " >
2006-12-22 05:42:36 +00:00
//<![CDATA[
2005-02-10 19:25:42 +00:00
if ( parent . msg . document . getElementById ( " msgStarted " ) == null ) {
parent . msg . document . close ();
parent . msg . document . open ( " text/html " , " replace " );
2005-09-10 22:57:21 +00:00
parent . msg . document . write ( " <!DOCTYPE html PUBLIC \" -//W3C//DTD XHTML 1.0 Transitional//EN \" \" http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd \" > " );
2005-02-10 19:25:42 +00:00
parent . msg . document . write ( " <html><head> " );
2006-11-11 17:23:20 +00:00
parent . msg . document . write ( " <meta http-equiv= \" content-type \" content= \" text/html; charset=utf-8 \" /> " );
2005-02-25 12:35:20 +00:00
parent . msg . document . write ( " <base target= \" _blank \" /> " );
2007-01-01 13:26:20 +00:00
parent . msg . document . write ( " <?php echo addslashes_js( $stylesheetshtml ) ?> " );
2006-12-22 05:42:36 +00:00
parent . msg . document . write ( " < \ /head><body class= \" mod-chat-gui_header_js course-<?php echo $chatuser->course ?> \" id= \" mod-chat-gui_header_js-jsupdate \" ><div style= \" display: none \" id= \" msgStarted \" > < \ /div> " );
2005-02-10 19:25:42 +00:00
}
2005-02-03 20:39:27 +00:00
< ? php
$beep = false ;
$refreshusers = false ;
$us = array ();
2005-09-10 22:57:21 +00:00
if (( $chat_lasttime != $chat_newlasttime ) and $messages ) {
2005-02-03 20:39:27 +00:00
foreach ( $messages as $message ) {
2005-09-10 22:57:21 +00:00
$chat_lastrow = ( $chat_lastrow + 1 ) % 2 ;
2006-04-17 21:06:28 +00:00
$formatmessage = chat_format_message ( $message , $chatuser -> course , $USER , $chat_lastrow );
2005-02-03 20:39:27 +00:00
if ( $formatmessage -> beep ) {
$beep = true ;
}
if ( $formatmessage -> refreshusers ) {
$refreshusers = true ;
}
$us [ $message -> userid ] = $timenow - $message -> timestamp ;
2007-01-01 13:26:20 +00:00
echo " parent.msg.document.write(' " . addslashes_js ( $formatmessage -> html ) . " \\ n'); \n " ;
2003-07-07 06:44:16 +00:00
}
2005-02-03 20:39:27 +00:00
}
$chatuser -> lastping = time ();
2006-04-17 21:05:51 +00:00
set_field ( 'chat_users' , 'lastping' , $chatuser -> lastping , 'id' , $chatuser -> id );
2005-02-03 20:39:27 +00:00
if ( $refreshusers ) {
2005-02-07 20:33:44 +00:00
echo " if (parent.users.document.anchors[0] != null) { " .
" parent.users.location.href = parent.users.document.anchors[0].href;} \n " ;
2005-02-03 20:39:27 +00:00
} else {
foreach ( $us as $uid => $lastping ) {
$min = ( int ) ( $lastping / 60 );
$sec = $lastping - ( $min * 60 );
$min = $min < 10 ? '0' . $min : $min ;
$sec = $sec < 10 ? '0' . $sec : $sec ;
$idle = $min . ':' . $sec ;
2005-02-07 20:33:44 +00:00
echo " if (parent.users.document.getElementById('uidle { $uid } ') != null) { " .
" parent.users.document.getElementById('uidle { $uid } ').innerHTML = ' $idle ';} \n " ;
2005-02-03 20:39:27 +00:00
}
}
?>
parent . msg . scroll ( 1 , 5000000 );
2006-12-22 05:42:36 +00:00
//]]>
2005-02-03 20:39:27 +00:00
</ script >
</ head >
< body >
< ? php
if ( $beep ) {
echo '<embed src="../beep.wav" autostart="true" hidden="true" name="beep" />' ;
}
?>
2006-12-22 05:42:36 +00:00
< a href = " <?php echo $refreshurlamp ?> " name = " refreshLink " > Refresh link </ a >
2005-02-03 20:39:27 +00:00
</ body >
</ html >
2006-04-17 21:04:19 +00:00
< ? php
// support HTTP Keep-Alive
header ( " Content-Length: " . ob_get_length () );
ob_end_flush ();
exit ;
?>