3 $nomoodlecookie = true; // Session not needed!
5 require('../../../config.php');
8 $chat_sid = required_param('chat_sid', PARAM_ALPHANUM
);
9 $chat_lasttime = optional_param('chat_lasttime', 0, PARAM_INT
);
10 $chat_lastrow = optional_param('chat_lastrow', 1, PARAM_INT
);
12 if (!$chatuser = get_record('chat_users', 'sid', $chat_sid)) {
13 error('Not logged in!');
16 //Get the minimal course
17 if (!$course = get_record('course','id',$chatuser->course
,'','','','','id,theme,lang')) {
18 error('incorrect course id');
21 //Get the user theme and enough info to be used in chat_format_message() which passes it along to
22 if (!$USER = get_record('user','id',$chatuser->userid
,'','','','','id, lang, theme, username, timezone')) {
23 error('User does not exist!');
25 $USER->description
= '';
27 //Setup course, lang and theme
28 course_setup($course);
30 // force deleting of timed out users if there is a silence in room or just entering
31 if ((time() - $chat_lasttime) > $CFG->chat_old_ping
) {
32 // must be done before chat_get_latest_message!!!
33 chat_delete_old_users();
36 if ($message = chat_get_latest_message($chatuser->chatid
, $chatuser->groupid
)) {
37 $chat_newlasttime = $message->timestamp
;
39 $chat_newlasttime = 0;
42 if ($chat_lasttime == 0) { //display some previous messages
43 $chat_lasttime = time() - $CFG->chat_old_ping
; //TO DO - any better value??
48 $groupselect = $chatuser->groupid ?
" AND (groupid='".$chatuser->groupid
."' OR groupid='0') " : "";
50 $messages = get_records_select("chat_messages",
51 "chatid = '$chatuser->chatid' AND timestamp > '$chat_lasttime' $groupselect",
55 $num = count($messages);
60 $chat_newrow = ($chat_lastrow +
$num) %
2;
62 // no & in url, does not work in header!
63 $refreshurl = "{$CFG->wwwroot}/mod/chat/gui_header_js/jsupdate.php?chat_sid=$chat_sid&chat_lasttime=$chat_newlasttime&chat_lastrow=$chat_newrow";
64 $refreshurlamp = "{$CFG->wwwroot}/mod/chat/gui_header_js/jsupdate.php?chat_sid=$chat_sid&chat_lasttime=$chat_newlasttime&chat_lastrow=$chat_newrow";
66 header('Expires: Sun, 28 Dec 1997 09:32:45 GMT');
67 header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
68 header('Cache-Control: no-cache, must-revalidate');
69 header('Pragma: no-cache');
70 header('Content-Type: text/html; charset=utf-8');
71 header("Refresh: $CFG->chat_refresh_room; url=$refreshurl");
73 /// required stylesheets
74 $stylesheetshtml = '';
75 foreach ($CFG->stylesheets
as $stylesheet) {
76 $stylesheetshtml .= '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'" />';
79 // use ob to be able to send Content-Length headers
80 // needed for Keep-Alive to work
84 <!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
88 <meta http
-equiv
="content-type" content
="text/html; charset=utf-8" />
89 <script type
="text/javascript">
91 if (parent
.msg
.document
.getElementById("msgStarted") == null) {
92 parent
.msg
.document
.close();
93 parent
.msg
.document
.open("text/html","replace");
94 parent
.msg
.document
.write("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">");
95 parent
.msg
.document
.write("<html><head>");
96 parent
.msg
.document
.write("<meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\" />");
97 parent
.msg
.document
.write("<base target=\"_blank\" />");
98 parent
.msg
.document
.write("<?php echo addslashes_js($stylesheetshtml) ?>");
99 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>");
103 $refreshusers = false;
105 if (($chat_lasttime != $chat_newlasttime) and $messages) {
107 foreach ($messages as $message) {
108 $chat_lastrow = ($chat_lastrow +
1) %
2;
109 $formatmessage = chat_format_message($message, $chatuser->course
, $USER, $chat_lastrow);
110 if ($formatmessage->beep
) {
113 if ($formatmessage->refreshusers
) {
114 $refreshusers = true;
116 $us[$message->userid
] = $timenow - $message->timestamp
;
117 echo "parent.msg.document.write('".addslashes_js($formatmessage->html
)."\\n');\n";
121 $chatuser->lastping
= time();
122 set_field('chat_users', 'lastping', $chatuser->lastping
, 'id', $chatuser->id
);
125 echo "if (parent.users.document.anchors[0] != null) {" .
126 "parent.users.location.href = parent.users.document.anchors[0].href;}\n";
128 foreach($us as $uid=>$lastping) {
129 $min = (int) ($lastping/60);
130 $sec = $lastping - ($min*60);
131 $min = $min < 10 ?
'0'.$min : $min;
132 $sec = $sec < 10 ?
'0'.$sec : $sec;
133 $idle = $min.':'.$sec;
134 echo "if (parent.users.document.getElementById('uidle{$uid}') != null) {".
135 "parent.users.document.getElementById('uidle{$uid}').innerHTML = '$idle';}\n";
139 parent
.msg
.scroll(1,5000000);
146 echo '<embed src="../beep.wav" autostart="true" hidden="true" name="beep" />';
149 <a href
="<?php echo $refreshurlamp ?>" name
="refreshLink">Refresh link
</a
>
154 // support HTTP Keep-Alive
155 header("Content-Length: " . ob_get_length() );