incorrect use of preg_quote(), add '/' to list of quoted chars - see man page; merged...
[moodle.git] / mod / chat / gui_header_js / jsupdate.php
CommitLineData
1515a89e 1<?php
2
3require("../../../config.php");
4require("../lib.php");
5
84a2fdd7 6$groupid = empty($_GET['groupid']) ? 0 : $_GET['groupid'];
7$groupselect = $groupid ? " AND (groupid='$groupid' OR groupid='0') " : "";
8
1515a89e 9if (!$chatuser = get_record("chat_users", "sid", $chat_sid)) {
10 echo "Not logged in!";
f7e648da 11 die;
1515a89e 12}
13
f7e648da 14if (!$chat = get_record("chat", "id", $chatuser->chatid)) {
15 error("No chat found");
16}
17
18require_login($chat->course);
19
84a2fdd7 20if ($message = chat_get_latest_message($chatuser->chatid, $groupid)) {
1515a89e 21 $chat_newlasttime = $message->timestamp;
22} else {
23 $chat_newlasttime = 0;
24}
25
26if (empty($chat_lasttime)) {
27 $chat_lasttime = 0;
28}
29
30
31header("Expires: Sun, 28 Dec 1997 09:32:45 GMT");
32header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
33header("Cache-Control: no-cache, must-revalidate");
34header("Pragma: no-cache");
35header("Content-Type: text/html");
8f0cd6ef 36header("Refresh: $CFG->chat_refresh_room; url=jsupdate.php?chat_sid=$chat_sid&chat_lasttime=$chat_newlasttime&groupid=$groupid");
1515a89e 37
38?>
39 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
40 <html>
41 <head>
42 <script language="Javascript">
43 <!--
44<?php
7d792369 45 $beep = false;
46
1515a89e 47 if ($chat_lasttime) {
8f0cd6ef 48 if ($messages = get_records_select("chat_messages",
49 "chatid = '$chatuser->chatid' AND timestamp > '$chat_lasttime' $groupselect",
84a2fdd7 50 "timestamp ASC")) {
1515a89e 51 foreach ($messages as $message) {
62a575d1 52 $formatmessage = chat_format_message($message, $chat->course);
7d792369 53 if ($formatmessage->beep) {
54 $beep = $formatmessage->beep;
55 }
7d494f1c 56 echo "parent.msg.document.write('".addslashes($formatmessage->html)."\\n');";
1515a89e 57 }
58 }
59 }
60
61 $chatuser->lastping = time();
62 update_record("chat_users", $chatuser);
63 ?>
64 parent.msg.scroll(1,5000000);
65 // -->
66 </script>
67 </head>
d2c538f1 68 <body>
7d792369 69 <?php if ($beep) { ?>
70 <embed src="../beep.wav" autostart="true" hidden="true" />
71 <?php } ?>
1515a89e 72 </body>
73 </html>