moodle/mod/chat/insert.php

70 lines
2.0 KiB
PHP
Raw Normal View History

<?php
2003-07-07 09:45:08 +00:00
include("../../config.php");
include("lib.php");
2003-07-07 09:45:08 +00:00
require_variable($chat_sid);
require_variable($chat_version);
require_variable($chat_message);
optional_variable($groupid);
2003-07-07 09:45:08 +00:00
if (!$chatuser = get_record("chat_users", "sid", $chat_sid)) {
echo "Not logged in!";
die;
}
2004-07-30 15:36:39 +00:00
2003-07-07 09:45:08 +00:00
if (!$chat = get_record("chat", "id", $chatuser->chatid)) {
error("No chat found");
}
2004-07-30 15:36:39 +00:00
2003-07-07 09:45:08 +00:00
require_login($chat->course);
if ($groupid) {
if (!isteacheredit($chat->course) and !ismember($groupid)) {
error("You can't chat here!");
}
}
2004-07-30 15:36:39 +00:00
2003-07-07 09:45:08 +00:00
/// Clean up the message
$chat_message = addslashes(clean_text(stripslashes($chat_message), FORMAT_MOODLE)); // Strip bad tags
2003-07-07 09:45:08 +00:00
/// Add the message to the database
2003-07-07 09:45:08 +00:00
if (!empty($chat_message)) {
2004-07-30 15:36:39 +00:00
2003-07-07 09:45:08 +00:00
$message->chatid = $chatuser->chatid;
$message->userid = $chatuser->userid;
$message->groupid = $groupid;
2003-07-07 09:45:08 +00:00
$message->message = $chat_message;
$message->timestamp = time();
2004-07-30 15:36:39 +00:00
2003-07-07 09:45:08 +00:00
if (!insert_record("chat_messages", $message)) {
error("Could not insert a chat message!");
}
2004-07-30 15:36:39 +00:00
$chatuser->lastmessageping = time() - 2;
2003-07-07 09:45:08 +00:00
update_record("chat_users", $chatuser);
if ($cm = get_coursemodule_from_instance("chat", $chat->id, $chat->course)) {
add_to_log($chat->course, "chat", "talk", "view.php?id=$cm->id", $chat->id, $cm->id);
}
2003-07-07 09:45:08 +00:00
}
2004-07-30 15:36:39 +00:00
2003-07-07 09:45:08 +00:00
/// Go back to the other page
if ($chat_version == "header" OR $chat_version == "box") {
redirect("../gui_$chat_version/chatinput.php?chat_sid=$chat_sid&amp;groupid=$groupid");
2004-07-30 15:36:39 +00:00
} else if ($chat_version == 'sockets') {
//redirect('./gui_sockets/chatinput.php?chat_sid='.$chat_sid.'&amp;groupid='.$groupid);
2004-07-30 15:36:39 +00:00
2003-07-07 09:45:08 +00:00
} else if ($chat_version == "text") {
redirect("../gui_$chat_version/index.php?chat_sid=$chat_sid&chat_lastid=$chat_lastid&amp;groupid=$groupid");
2004-07-30 15:36:39 +00:00
2003-07-07 09:45:08 +00:00
} else {
redirect("empty.php");
}
?>