[ Index ]

PHP Cross Reference of Moodle 1.9.3 [Build 15-Oct-2008]

title

Body

[close]

/message/ -> refresh.php (source)

   1  <?php // $Id: refresh.php,v 1.11.4.1 2008/05/08 03:41:10 jerome Exp $
   2  
   3      require ('../config.php');
   4  
   5      define('MESSAGE_DEFAULT_REFRESH', 5);
   6  
   7      require_login();
   8  
   9      if (isguest()) {
  10          redirect($CFG->wwwroot);
  11      }
  12  
  13      if (empty($CFG->messaging)) {
  14          error("Messaging is disabled on this site");
  15      }
  16  
  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);
  21  
  22      $stylesheetshtml = '';
  23      foreach ($CFG->stylesheets as $stylesheet) {
  24          $stylesheetshtml .= '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'" />';
  25      }
  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');
  31  
  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";
  46  
  47      @ob_implicit_flush(true);
  48      @ob_end_flush();
  49  
  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'));
  54  
  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";
  64  
  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);
  72              }
  73          }
  74          if (get_user_preferences('message_beepnewmessage', 0)) {
  75              $playbeep = true;
  76          }
  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
  83          }
  84      }
  85  
  86      echo '-->'."\n";
  87      echo '</script>'."\n";
  88      echo '</head>'."\n";
  89      echo '<body>'."\n";
  90  
  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";
  98      }
  99  
 100      // Javascript for Mozilla to cope with the redirect bug from editor being on in this page
 101      ?>
 102  
 103  <script type="text/javascript">
 104  <!--
 105  
 106    function redirect() {
 107      document.location.replace('refresh.php?id=<?php echo $userid ?>&name=<?php echo urlencode($userfullname) ?>&wait=<?php echo $wait ?>');
 108    }
 109  
 110    setTimeout("redirect()", <?php echo ($wait*1000) ?>);
 111  -->
 112  </script>
 113  
 114  </body>
 115  </html>


Generated: Wed Jan 14 11:33:29 2009 Cross-referenced by PHPXref 0.7