Very early version of new chat module, made by Martin using ARSC as
[moodle.git] / mod / chat / gui_header_js / jsupdate.php
CommitLineData
1515a89e 1<?php
2
3require("../../../config.php");
4require("../lib.php");
5
6if (!$chatuser = get_record("chat_users", "sid", $chat_sid)) {
7 echo "Not logged in!";
8}
9
10if ($message = chat_get_latest_message($chatuser->chatid)) {
11 $chat_newlasttime = $message->timestamp;
12} else {
13 $chat_newlasttime = 0;
14}
15
16if (empty($chat_lasttime)) {
17 $chat_lasttime = 0;
18}
19
20
21header("Expires: Sun, 28 Dec 1997 09:32:45 GMT");
22header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
23header("Cache-Control: no-cache, must-revalidate");
24header("Pragma: no-cache");
25header("Content-Type: text/html");
26header("Refresh: 4; URL=jsupdate.php?chat_sid=".$chat_sid."&chat_lasttime=".$chat_newlasttime);
27
28?>
29 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
30 <html>
31 <head>
32 <script language="Javascript">
33 <!--
34<?php
35 if ($chat_lasttime) {
36 if ($messages = get_records_select("chat_messages",
37 "chatid = '$chatuser->chatid' AND timestamp > '$chat_lasttime'",
38 "timestamp ASC")) {
39 foreach ($messages as $message) {
40 $formatmessage = chat_format_message($message->userid, $message->chatid,
41 $message->timestamp, $message->message, $message->system);
42?>
43 parent.msg.document.write('<?php echo $formatmessage ?>\n');
44<?php
45 }
46 }
47 }
48
49 $chatuser->lastping = time();
50 update_record("chat_users", $chatuser);
51 ?>
52 parent.msg.scroll(1,5000000);
53 // -->
54 </script>
55 </head>
56 <body bgcolor="<?php echo $THEME->body ?>">
57 </body>
58 </html>