2005-02-03 20:39:27 +00:00
|
|
|
<?php // $Id$
|
|
|
|
|
|
|
|
include('../../../config.php');
|
|
|
|
include('../lib.php');
|
|
|
|
|
|
|
|
$chat_sid = required_param('chat_sid', PARAM_ALPHANUM);
|
|
|
|
$chat_message = required_param('chat_message', PARAM_RAW);
|
|
|
|
|
2008-06-08 15:49:36 +00:00
|
|
|
if (!$chatuser = $DB->get_record('chat_users', array('sid'=>$chat_sid))) {
|
2008-06-15 12:24:36 +00:00
|
|
|
print_error('notlogged', 'chat');
|
2005-02-03 20:39:27 +00:00
|
|
|
}
|
|
|
|
|
2008-06-08 15:49:36 +00:00
|
|
|
if (!$chat = $DB->get_record('chat', array('id'=>$chatuser->chatid))) {
|
2008-06-15 12:24:36 +00:00
|
|
|
print_error('nochat', 'chat');
|
2005-02-03 20:39:27 +00:00
|
|
|
}
|
|
|
|
|
2008-06-08 15:49:36 +00:00
|
|
|
if (!$course = $DB->get_record('course', array('id'=>$chat->course))) {
|
2008-06-15 12:24:36 +00:00
|
|
|
print_error('invalidcourseid');
|
2005-02-03 20:39:27 +00:00
|
|
|
}
|
|
|
|
|
2007-08-17 12:49:28 +00:00
|
|
|
if (!$cm = get_coursemodule_from_instance('chat', $chat->id, $course->id)) {
|
2008-06-15 12:24:36 +00:00
|
|
|
print_error('invalidcoursemodule');
|
2007-08-17 12:49:28 +00:00
|
|
|
}
|
2008-07-24 03:15:03 +00:00
|
|
|
|
2007-08-17 12:49:28 +00:00
|
|
|
require_login($course->id, false, $cm);
|
2005-02-03 20:39:27 +00:00
|
|
|
|
|
|
|
if (isguest()) {
|
2008-06-15 12:24:36 +00:00
|
|
|
print_error('noguests');
|
2005-02-03 20:39:27 +00:00
|
|
|
}
|
|
|
|
|
2009-01-17 15:25:08 +00:00
|
|
|
session_get_instance()->write_close();
|
2005-02-03 20:39:27 +00:00
|
|
|
|
|
|
|
/// Delete old users now
|
|
|
|
|
|
|
|
chat_delete_old_users();
|
|
|
|
|
|
|
|
/// Clean up the message
|
|
|
|
|
2008-06-09 16:53:30 +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
|
|
|
|
|
|
|
|
if (!empty($chat_message)) {
|
|
|
|
|
2006-12-29 18:33:41 +00:00
|
|
|
$message = new object();
|
2005-02-03 20:39:27 +00:00
|
|
|
$message->chatid = $chatuser->chatid;
|
|
|
|
$message->userid = $chatuser->userid;
|
|
|
|
$message->groupid = $chatuser->groupid;
|
|
|
|
$message->message = $chat_message;
|
|
|
|
$message->timestamp = time();
|
|
|
|
|
2009-06-03 20:25:27 +00:00
|
|
|
$DB->insert_record('chat_messages', $message);
|
|
|
|
$DB->insert_record('chat_messages_current', $message);
|
2005-02-03 20:39:27 +00:00
|
|
|
|
|
|
|
$chatuser->lastmessageping = time() - 2;
|
2008-06-08 15:49:36 +00:00
|
|
|
$DB->update_record('chat_users', $chatuser);
|
2005-02-03 20:39:27 +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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($chatuser->version == 'header_js') {
|
|
|
|
/// force msg referesh ASAP
|
2009-09-17 06:17:05 +00:00
|
|
|
echo $PAGE->requires->js('mod/chat/gui_header_js/chat_gui_header.js')->asap();
|
|
|
|
if ($CFG->chat_normal_updatemode != 'jsupdated') { // See bug MDL-6791
|
|
|
|
echo $PAGE->requires->js_function_call('insert_redirect')->asap();;
|
2006-10-04 12:58:09 +00:00
|
|
|
}
|
2009-09-17 06:17:05 +00:00
|
|
|
echo $PAGE->requires->js_function_call('parent.input.enableForm')->asap();
|
2005-02-03 20:39:27 +00:00
|
|
|
}
|
|
|
|
|
2005-02-07 20:33:44 +00:00
|
|
|
redirect('../empty.php');
|
2005-02-03 20:39:27 +00:00
|
|
|
?>
|