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 require_login($course->id
);
24 error('Guest does not have access to chat rooms');
27 session_write_close();
29 /// Delete old users now
31 chat_delete_old_users();
33 /// Clean up the message
35 $chat_message = addslashes(clean_text(stripslashes($chat_message), FORMAT_MOODLE
)); // Strip bad tags
37 /// Add the message to the database
39 if (!empty($chat_message)) {
41 $message = new object();
42 $message->chatid
= $chatuser->chatid
;
43 $message->userid
= $chatuser->userid
;
44 $message->groupid
= $chatuser->groupid
;
45 $message->message
= $chat_message;
46 $message->timestamp
= time();
48 if (!insert_record('chat_messages', $message)) {
49 error('Could not insert a chat message!');
52 $chatuser->lastmessageping
= time() - 2;
53 update_record('chat_users', $chatuser);
55 if ($cm = get_coursemodule_from_instance('chat', $chat->id
, $course->id
)) {
56 add_to_log($course->id
, 'chat', 'talk', "view.php?id=$cm->id", $chat->id
, $cm->id
);
60 if ($chatuser->version
== 'header_js') {
61 /// force msg referesh ASAP
62 if ($CFG->chat_normal_updatemode
== 'jsupdated') { // See bug MDL-6791
63 echo '<script type="text/javascript">'.
65 ' parent.input.enableForm();'.
69 echo '<script type="text/javascript">'.
71 ' parent.jsupdate.location.href = parent.jsupdate.document.anchors[0].href;'.
72 ' parent.input.enableForm();'.
78 redirect('../empty.php');