3 include('../../../config.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);
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">'.
69 ' parent.input.enableForm();'.
73 echo '<script type="text/javascript">'.
75 ' parent.jsupdate.location.href = parent.jsupdate.document.anchors[0].href;'.
76 ' parent.input.enableForm();'.
82 redirect('../empty.php');