2009-09-23 07:08:43 +00:00
|
|
|
<?php
|
2005-02-03 20:39:27 +00:00
|
|
|
|
2009-09-23 07:08:43 +00:00
|
|
|
include('../../../config.php');
|
|
|
|
include('../lib.php');
|
2005-02-03 20:39:27 +00:00
|
|
|
|
2009-09-23 07:08:43 +00:00
|
|
|
$chat_sid = required_param('chat_sid', PARAM_ALPHANUM);
|
|
|
|
$chat_message = required_param('chat_message', PARAM_RAW);
|
2005-02-03 20:39:27 +00:00
|
|
|
|
2010-01-16 15:39:56 +00:00
|
|
|
$PAGE->set_url('/mod/chat/gui_header_js/insert.php', array('chat_sid'=>$chat_sid,'chat_message'=>$chat_message));
|
2005-02-03 20:39:27 +00:00
|
|
|
|
2009-09-23 07:08:43 +00:00
|
|
|
if (!$chatuser = $DB->get_record('chat_users', array('sid'=>$chat_sid))) {
|
|
|
|
print_error('notlogged', 'chat');
|
|
|
|
}
|
2005-02-03 20:39:27 +00:00
|
|
|
|
2009-09-23 07:08:43 +00:00
|
|
|
if (!$chat = $DB->get_record('chat', array('id'=>$chatuser->chatid))) {
|
|
|
|
print_error('nochat', 'chat');
|
|
|
|
}
|
2005-02-03 20:39:27 +00:00
|
|
|
|
2009-09-23 07:08:43 +00:00
|
|
|
if (!$course = $DB->get_record('course', array('id'=>$chat->course))) {
|
|
|
|
print_error('invalidcourseid');
|
|
|
|
}
|
2008-07-24 03:15:03 +00:00
|
|
|
|
2009-09-23 07:08:43 +00:00
|
|
|
if (!$cm = get_coursemodule_from_instance('chat', $chat->id, $course->id)) {
|
|
|
|
print_error('invalidcoursemodule');
|
|
|
|
}
|
2005-02-03 20:39:27 +00:00
|
|
|
|
2009-09-23 07:08:43 +00:00
|
|
|
require_login($course->id, false, $cm);
|
|
|
|
|
|
|
|
if (has_capability('moodle/legacy:guest', get_context_instance(CONTEXT_SYSTEM), 0, false)) {
|
|
|
|
print_error('noguests');
|
|
|
|
}
|
2005-02-03 20:39:27 +00:00
|
|
|
|
2009-09-23 07:08:43 +00:00
|
|
|
session_get_instance()->write_close();
|
2005-02-03 20:39:27 +00:00
|
|
|
|
|
|
|
/// Delete old users now
|
|
|
|
|
2009-09-23 07:08:43 +00:00
|
|
|
chat_delete_old_users();
|
2005-02-03 20:39:27 +00:00
|
|
|
|
|
|
|
/// Clean up the message
|
|
|
|
|
2009-09-23 07:08:43 +00:00
|
|
|
$chat_message = clean_text($chat_message, FORMAT_MOODLE); // Strip bad tags
|
2005-02-03 20:39:27 +00:00
|
|
|
|
|
|
|
/// Add the message to the database
|
|
|
|
|
2009-09-23 07:08:43 +00:00
|
|
|
if (!empty($chat_message)) {
|
2005-02-03 20:39:27 +00:00
|
|
|
|
2009-09-23 07:08:43 +00:00
|
|
|
$message = new object();
|
|
|
|
$message->chatid = $chatuser->chatid;
|
|
|
|
$message->userid = $chatuser->userid;
|
|
|
|
$message->groupid = $chatuser->groupid;
|
|
|
|
$message->message = $chat_message;
|
|
|
|
$message->timestamp = time();
|
2005-02-03 20:39:27 +00:00
|
|
|
|
2009-09-23 07:08:43 +00:00
|
|
|
$DB->insert_record('chat_messages', $message);
|
|
|
|
$DB->insert_record('chat_messages_current', $message);
|
2005-02-03 20:39:27 +00:00
|
|
|
|
2009-09-23 07:08:43 +00:00
|
|
|
$chatuser->lastmessageping = time() - 2;
|
|
|
|
$DB->update_record('chat_users', $chatuser);
|
2005-02-03 20:39:27 +00:00
|
|
|
|
2009-09-23 07:08:43 +00:00
|
|
|
if ($cm = get_coursemodule_from_instance('chat', $chat->id, $course->id)) {
|
|
|
|
add_to_log($course->id, 'chat', 'talk', "view.php?id=$cm->id", $chat->id, $cm->id);
|
2005-02-03 20:39:27 +00:00
|
|
|
}
|
2009-09-23 07:08:43 +00:00
|
|
|
}
|
2005-02-03 20:39:27 +00:00
|
|
|
|
2009-09-23 07:08:43 +00:00
|
|
|
if ($chatuser->version == 'header_js') {
|
2010-02-15 06:08:41 +00:00
|
|
|
|
2009-09-23 07:08:43 +00:00
|
|
|
/// force msg referesh ASAP
|
|
|
|
if ($CFG->chat_normal_updatemode != 'jsupdated') { // See bug MDL-6791
|
2010-02-15 06:08:41 +00:00
|
|
|
$module = array(
|
|
|
|
'name' => 'mod_chat_js',
|
|
|
|
'fullpath' => '/mod/chat/gui_header_js/module.js',
|
|
|
|
'requires' => array('base', 'node')
|
|
|
|
);
|
|
|
|
$PAGE->requires->js_init_call('M.mod_chat.js.insert_redirect', array(false), false, $module);
|
2005-02-03 20:39:27 +00:00
|
|
|
}
|
2010-01-26 09:58:19 +00:00
|
|
|
$PAGE->requires->js_function_call('parent.input.enableForm');
|
2009-09-23 07:08:43 +00:00
|
|
|
}
|
2005-02-03 20:39:27 +00:00
|
|
|
|
2009-09-23 07:08:43 +00:00
|
|
|
redirect('../empty.php');
|