fix for MDL-13174 : replace calls to html_entity_decode() with hotpot_charcode_to_utf...
[moodle.git] / message / refresh.php
blob58659de31fa915c8ae4e00ab6fea7a29b23971d1
1 <?php // $Id$
3 require('../config.php');
5 define('MESSAGE_DEFAULT_REFRESH', 5);
7 require_login();
9 if (isguest()) {
10 redirect($CFG->wwwroot);
13 if (empty($CFG->messaging)) {
14 error("Messaging is disabled on this site");
17 /// Select encoding
18 $encoding = current_charset();
20 /// Script parameters
21 $userid = required_param('id', PARAM_INT);
22 $userfullname = strip_tags(required_param('name', PARAM_RAW));
23 $wait = optional_param('wait', MESSAGE_DEFAULT_REFRESH, PARAM_INT);
25 $stylesheetshtml = '';
26 foreach ($CFG->stylesheets as $stylesheet) {
27 $stylesheetshtml .= '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'" />';
29 header('Expires: Sun, 28 Dec 1997 09:32:45 GMT');
30 header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
31 header('Cache-Control: no-cache, must-revalidate');
32 header('Pragma: no-cache');
33 header('Content-Type: text/html; charset='.$encoding);
35 echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'."\n";
36 echo '<html><head><title> </title>';
37 echo '<meta http-equiv="content-type" content="text/html; charset='.$encoding.'" />';
38 echo '<script type="text/javascript">'."\n";
39 echo '<!--'."\n";
40 echo 'if (parent.messages.document.getElementById("messagestarted") == null) {'."\n";
41 echo ' parent.messages.document.close();'."\n";
42 echo ' parent.messages.document.open("text/html","replace");'."\n";
43 echo ' parent.messages.document.write("<html><head><title> <\/title>");'."\n";
44 echo ' parent.messages.document.write("<meta http-equiv=\"content-type\" content=\"text/html; charset='.current_charset().'\" />");'."\n";
45 echo ' parent.messages.document.write("<base target=\"_blank\" />");'."\n";
46 echo ' parent.messages.document.write("'.addslashes($stylesheetshtml).'");'."\n";
47 echo ' parent.messages.document.write("<\/head><body class=\"message course-1\" id=\"message-messages\"><div style=\"display: none\" id=\"messagestarted\">&nbsp;<\/div>");'."\n";
48 echo '}'."\n";
50 @ob_implicit_flush(true);
51 @ob_end_flush();
53 if ($messages = get_records_select('message', "useridto = '$USER->id' AND useridfrom = '$userid'",
54 'timecreated')) {
55 foreach ($messages as $message) {
56 $time = userdate($message->timecreated, get_string('strftimedaytime'));
58 $options = NULL;
59 $options->para = false;
60 $options->newlines = true;
61 $printmessage = format_text($message->message, $message->format, $options, 0);
62 $printmessage = str_replace("\r", ' ', $printmessage);
63 $printmessage = str_replace("\n", ' ', $printmessage);
64 $printmessage = '<div class="message other"><span class="author">'.s($userfullname).'</span> '.
65 '<span class="time">['.$time.']</span>: '.
66 '<span class="content">'.$printmessage.'</span></div>';
67 $printmessage = addslashes($printmessage); // So Javascript can write it
68 $printmessage = str_replace('</', '<\/', $printmessage); // XHTML compliance
69 echo "parent.messages.document.write('".$printmessage."');\n";
71 /// Move the entry to the other table
72 $message->timeread = time();
73 $message->message = addslashes($message->message);
74 $messageid = $message->id;
75 unset($message->id);
76 if (insert_record('message_read', $message)) {
77 delete_records('message', 'id', $messageid);
80 if (get_user_preferences('message_beepnewmessage', 0)) {
81 $playbeep = true;
83 echo 'parent.messages.scroll(1,5000000);'."\n";
84 echo 'parent.send.focus();'."\n";
85 $wait = MESSAGE_DEFAULT_REFRESH;
86 } else {
87 if ($wait < 300) { // Until the wait is five minutes
88 $wait = ceil(1.2 * (float)$wait); // Exponential growth
92 echo '-->'."\n";
93 echo '</script>'."\n";
94 echo '</head>'."\n";
95 echo '<body>'."\n";
97 if (!empty($playbeep)) {
98 echo '<embed src="bell.wav" autostart="true" hidden="true" name="bell" />';
99 echo '<script type="text/javascript">'."\n";
100 echo '<!--'."\n";
101 echo 'parent.send.focus();'."\n";
102 echo '-->'."\n";
103 echo '</script>'."\n";
106 // Javascript for Mozilla to cope with the redirect bug from editor being on in this page
109 <script type="text/javascript">
110 <!--
112 function redirect() {
113 document.location.replace('refresh.php?id=<?php echo $userid ?>&name=<?php echo urlencode($userfullname) ?>&wait=<?php echo $wait ?>');
116 setTimeout("redirect()", <?php echo ($wait*1000) ?>);
118 </script>
120 </body>
121 </html>