MDL-10910 Corrected two errors committed while fixing MDL-10870
[moodle-pu.git] / mod / chat / gui_header_js / insert.php
blob62f0dc8147e96aee0c380de1075a9862f1420445
1 <?php // $Id$
3 include('../../../config.php');
4 include('../lib.php');
6 $chat_sid = required_param('chat_sid', PARAM_ALPHANUM);
7 $chat_message = required_param('chat_message', PARAM_RAW);
9 if (!$chatuser = get_record('chat_users', 'sid', $chat_sid)) {
10 error('Not logged in!');
13 if (!$chat = get_record('chat', 'id', $chatuser->chatid)) {
14 error('No chat found');
17 if (!$course = get_record('course', 'id', $chat->course)) {
18 error('Could not find the course this belongs to!');
21 if (!$cm = get_coursemodule_from_instance('chat', $chat->id, $course->id)) {
22 error('Course Module ID was incorrect');
25 require_login($course->id, false, $cm);
27 if (isguest()) {
28 error('Guest does not have access to chat rooms');
31 session_write_close();
33 /// Delete old users now
35 chat_delete_old_users();
37 /// Clean up the message
39 $chat_message = addslashes(clean_text(stripslashes($chat_message), FORMAT_MOODLE)); // Strip bad tags
41 /// Add the message to the database
43 if (!empty($chat_message)) {
45 $message = new object();
46 $message->chatid = $chatuser->chatid;
47 $message->userid = $chatuser->userid;
48 $message->groupid = $chatuser->groupid;
49 $message->message = $chat_message;
50 $message->timestamp = time();
52 if (!insert_record('chat_messages', $message)) {
53 error('Could not insert a chat message!');
56 $chatuser->lastmessageping = time() - 2;
57 update_record('chat_users', $chatuser);
59 if ($cm = get_coursemodule_from_instance('chat', $chat->id, $course->id)) {
60 add_to_log($course->id, 'chat', 'talk', "view.php?id=$cm->id", $chat->id, $cm->id);
64 if ($chatuser->version == 'header_js') {
65 /// force msg referesh ASAP
66 if ($CFG->chat_normal_updatemode == 'jsupdated') { // See bug MDL-6791
67 echo '<script type="text/javascript">'.
68 "//<![CDATA[ \n".
69 ' parent.input.enableForm();'.
70 "//]]> \n".
71 '</script>';
72 } else {
73 echo '<script type="text/javascript">'.
74 "//<![CDATA[ \n".
75 ' parent.jsupdate.location.href = parent.jsupdate.document.anchors[0].href;'.
76 ' parent.input.enableForm();'.
77 "//]]> \n".
78 '</script>';
82 redirect('../empty.php');