Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.

Differences Between: [Versions 311 and 401] [Versions 311 and 402] [Versions 311 and 403]

   1  <?php
   2  // This file is part of Moodle - http://moodle.org/
   3  //
   4  // Moodle is free software: you can redistribute it and/or modify
   5  // it under the terms of the GNU General Public License as published by
   6  // the Free Software Foundation, either version 3 of the License, or
   7  // (at your option) any later version.
   8  //
   9  // Moodle is distributed in the hope that it will be useful,
  10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12  // GNU General Public License for more details.
  13  //
  14  // You should have received a copy of the GNU General Public License
  15  // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  16  
  17  require_once('../../../config.php');
  18  require_once ('../lib.php');
  19  
  20  $chatsid     = required_param('chat_sid', PARAM_ALPHANUM);
  21  $chatmessage = required_param('chat_message', PARAM_RAW);
  22  
  23  $PAGE->set_url('/mod/chat/gui_header_js/insert.php', array('chat_sid' => $chatsid, 'chat_message' => $chatmessage));
  24  
  25  if (!$chatuser = $DB->get_record('chat_users', array('sid' => $chatsid))) {
  26      print_error('notlogged', 'chat');
  27  }
  28  
  29  if (!$chat = $DB->get_record('chat', array('id' => $chatuser->chatid))) {
  30      print_error('nochat', 'chat');
  31  }
  32  
  33  if (!$course = $DB->get_record('course', array('id' => $chat->course))) {
  34      print_error('invalidcourseid');
  35  }
  36  
  37  if (!$cm = get_coursemodule_from_instance('chat', $chat->id, $course->id)) {
  38      print_error('invalidcoursemodule');
  39  }
  40  
  41  require_login($course, false, $cm);
  42  
  43  if (isguestuser()) {
  44      print_error('noguests');
  45  }
  46  
  47  \core\session\manager::write_close();
  48  
  49  // Delete old users now.
  50  
  51  chat_delete_old_users();
  52  
  53  // Clean up the message.
  54  
  55  $chatmessage = clean_text($chatmessage, FORMAT_MOODLE);  // Strip bad tags.
  56  
  57  // Add the message to the database.
  58  
  59  if (!empty($chatmessage)) {
  60  
  61      chat_send_chatmessage($chatuser, $chatmessage, 0, $cm);
  62  
  63      $chatuser->lastmessageping = time() - 2;
  64      $DB->update_record('chat_users', $chatuser);
  65  }
  66  
  67  if ($chatuser->version == 'header_js') {
  68  
  69      $forcerefreshasap = ($CFG->chat_normal_updatemode != 'jsupdated'); // See bug MDL-6791.
  70  
  71      $module = array(
  72          'name'      => 'mod_chat_header',
  73          'fullpath'  => '/mod/chat/gui_header_js/module.js'
  74      );
  75      $PAGE->requires->js_init_call('M.mod_chat_header.init_insert_nojsupdated', array($forcerefreshasap), true, $module);
  76  }
  77  
  78  redirect('../empty.php');