TinyMCE 3 integration.
[moodle/mihaisucan.git] / message / refresh.php
blob88532dee93a1899669126c2aac5b4ba50dac1369
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 /// Script parameters
18 $userid = required_param('id', PARAM_INT);
19 $userfullname = strip_tags(required_param('name', PARAM_RAW));
20 $wait = optional_param('wait', MESSAGE_DEFAULT_REFRESH, PARAM_INT);
22 $stylesheetshtml = '';
23 foreach ($CFG->stylesheets as $stylesheet) {
24 $stylesheetshtml .= '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'" />';
26 header('Expires: Sun, 28 Dec 1997 09:32:45 GMT');
27 header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
28 header('Cache-Control: no-cache, must-revalidate');
29 header('Pragma: no-cache');
30 header('Content-Type: text/html; charset=utf-8');
32 echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'."\n";
33 echo '<html><head><title> </title>';
34 echo '<meta http-equiv="content-type" content="text/html; charset=utf-8" />';
35 echo '<script type="text/javascript">'."\n";
36 echo '<!--'."\n";
37 echo 'if (parent.messages.document.getElementById("messagestarted") == null) {'."\n";
38 echo ' parent.messages.document.close();'."\n";
39 echo ' parent.messages.document.open("text/html","replace");'."\n";
40 echo ' parent.messages.document.write("<html><head><title> <\/title>");'."\n";
41 echo ' parent.messages.document.write("<meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\" />");'."\n";
42 echo ' parent.messages.document.write("<base target=\"_blank\" />");'."\n";
43 echo ' parent.messages.document.write("'.addslashes_js($stylesheetshtml).'");'."\n";
44 echo ' parent.messages.document.write("<\/head><body class=\"message course-1\" id=\"message-messages\"><div style=\"display: none\" id=\"messagestarted\">&nbsp;<\/div>");'."\n";
45 echo '}'."\n";
47 @ob_implicit_flush(true);
48 @ob_end_flush();
50 if ($messages = get_records_select('message', "useridto = '$USER->id' AND useridfrom = '$userid'",
51 'timecreated')) {
52 foreach ($messages as $message) {
53 $time = userdate($message->timecreated, get_string('strftimedatetimeshort'));
55 $options = new object();
56 $options->para = false;
57 $options->newlines = true;
58 $printmessage = format_text($message->message, $message->format, $options);
59 $printmessage = '<div class="message other"><span class="author">'.s($userfullname).'</span> '.
60 '<span class="time">['.$time.']</span>: '.
61 '<span class="content">'.$printmessage.'</span></div>';
62 $printmessage = addslashes_js($printmessage); // So Javascript can write it
63 echo "parent.messages.document.write('".$printmessage."');\n";
65 /// Move the entry to the other table
66 $message->timeread = time();
67 $message = addslashes_object($message);
68 $messageid = $message->id;
69 unset($message->id);
70 if (insert_record('message_read', $message)) {
71 delete_records('message', 'id', $messageid);
74 if (get_user_preferences('message_beepnewmessage', 0)) {
75 $playbeep = true;
77 echo 'parent.messages.scroll(1,5000000);'."\n";
78 echo 'parent.send.focus();'."\n";
79 $wait = MESSAGE_DEFAULT_REFRESH;
80 } else {
81 if ($wait < 300) { // Until the wait is five minutes
82 $wait = ceil(1.2 * (float)$wait); // Exponential growth
86 echo '-->'."\n";
87 echo '</script>'."\n";
88 echo '</head>'."\n";
89 echo '<body>'."\n";
91 if (!empty($playbeep)) {
92 echo '<embed src="bell.wav" autostart="true" hidden="true" name="bell" />';
93 echo '<script type="text/javascript">'."\n";
94 echo '<!--'."\n";
95 echo 'parent.send.focus();'."\n";
96 echo '-->'."\n";
97 echo '</script>'."\n";
100 // Javascript for Mozilla to cope with the redirect bug from editor being on in this page
103 <script type="text/javascript">
104 <!--
106 function redirect() {
107 document.location.replace('refresh.php?id=<?php echo $userid ?>&name=<?php echo urlencode($userfullname) ?>&wait=<?php echo $wait ?>');
110 setTimeout("redirect()", <?php echo ($wait*1000) ?>);
112 </script>
114 </body>
115 </html>