require("../../../config.php");
require("../lib.php");
+require_variable($chat_sid);
+
if (!$chatuser = get_record("chat_users", "sid", $chat_sid)) {
echo "Not logged in!";
+ die;
+}
+
+if (!$chat = get_record("chat", "id", $chatuser->chatid)) {
+ error("No chat found");
}
+require_login($chat->course);
+
?>
<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\" \"http://www.w3.org/TR/REC-html40/loose.dtd\">
error("Could not find the course this belongs to!");
}
+require_login($course->id);
+
if (!$chat_sid = chat_login_user($chat->id, "header_js")) {
error("Could not log in to chat room!!");
}
if (!$chatuser = get_record("chat_users", "sid", $chat_sid)) {
echo "Not logged in!";
+ die;
}
+if (!$chat = get_record("chat", "id", $chatuser->chatid)) {
+ error("No chat found");
+}
+
+require_login($chat->course);
+
+
if ($message = chat_get_latest_message($chatuser->chatid)) {
$chat_newlasttime = $message->timestamp;
} else {
<?php
-include("../../config.php");
-include("lib.php");
+ include("../../config.php");
+ include("lib.php");
-require_variable($chat_sid);
-require_variable($chat_version);
-require_variable($chat_message);
+ require_variable($chat_sid);
+ require_variable($chat_version);
+ require_variable($chat_message);
-if (!$chatuser = get_record("chat_users", "sid", $chat_sid)) {
- echo "Not logged in!";
- die;
-}
+ if (!$chatuser = get_record("chat_users", "sid", $chat_sid)) {
+ echo "Not logged in!";
+ die;
+ }
+
+ if (!$chat = get_record("chat", "id", $chatuser->chatid)) {
+ error("No chat found");
+ }
+
+ require_login($chat->course);
+
/// Delete old messages here
-/// Clean up the message
-$chat_message = clean_text($chat_message, FORMAT_MOODLE); // Strip bad tags
-if (!empty($chat_message)) {
+/// Clean up the message
- $message->chatid = $chatuser->chatid;
- $message->userid = $chatuser->userid;
- $message->message = $chat_message;
- $message->timestamp = time();
-
- if (!insert_record("chat_messages", $message)) {
- error("Could not insert a chat message!");
- }
-}
+ $chat_message = clean_text($chat_message, FORMAT_MOODLE); // Strip bad tags
-if ($chat_version == "header" OR $chat_version == "box") {
- redirect("../gui_$chat_version/chatinput.php?chat_sid=$chat_sid");
+/// Add the message to the database
-} else if ($chat_version == "text") {
- redirect("../gui_$chat_version/index.php?chat_sid=$chat_sid&chat_lastid=$chat_lastid");
+ if (!empty($chat_message)) {
+
+ $message->chatid = $chatuser->chatid;
+ $message->userid = $chatuser->userid;
+ $message->message = $chat_message;
+ $message->timestamp = time();
+
+ if (!insert_record("chat_messages", $message)) {
+ error("Could not insert a chat message!");
+ }
-} else {
- redirect("empty.php");
-}
+ $chatuser->lastmessageping = time();
+ update_record("chat_users", $chatuser);
+ }
+
+/// Go back to the other page
+
+ if ($chat_version == "header" OR $chat_version == "box") {
+ redirect("../gui_$chat_version/chatinput.php?chat_sid=$chat_sid");
+
+ } else if ($chat_version == "text") {
+ redirect("../gui_$chat_version/index.php?chat_sid=$chat_sid&chat_lastid=$chat_lastid");
+
+ } else {
+ redirect("empty.php");
+ }
?>
global $CFG;
- return get_records_sql("SELECT u.id, u.firstname, u.lastname, u.picture
+ return get_records_sql("SELECT u.id, u.firstname, u.lastname, u.picture, c.lastmessageping
FROM {$CFG->prefix}chat_users c,
{$CFG->prefix}user u
WHERE c.chatid = '$chatid'
$chatuser->userid = $USER->id;
$chatuser->version = $version;
$chatuser->ip = $USER->lastIP;
- $chatuser->lastping = time();
+ $chatuser->lastping = $chatuser->firstping = $chatuser->lastmessageping = time();
$chatuser->sid = random_string(32);
if (!insert_record("chat_users", $chatuser)) {
die;
}
+if (!$chat = get_record("chat", "id", $chatuser->chatid)) {
+ error("No chat found");
+}
+
+require_login($chat->course);
+
+
if (!$chat = get_record("chat", "id", $chatuser->chatid)) {
error("Could not find chat! id = $chatuser->chatid");
}
print_header();
+$timenow = time();
+
+$stridle = get_string("idle", "chat");
+$str->day = get_string("day");
+$str->days = get_string("days");
+$str->hour = get_string("hour");
+$str->hours = get_string("hours");
+$str->min = get_string("min");
+$str->mins = get_string("mins");
+$str->sec = get_string("sec");
+$str->secs = get_string("secs");
+
echo "<table width=\"100%\">";
foreach ($chatusers as $chatuser) {
+ $lastping = $timenow - $chatuser->lastmessageping;
echo "<tr><td width=35>";
print_user_picture($chatuser->id, 0, $chatuser->picture, false, false, false);
echo "</td><td valign=center>";
- echo "<p><font size=1>$chatuser->firstname $chatuser->lastname</font></p>";
+ echo "<p><font size=1>";
+ echo "$chatuser->firstname $chatuser->lastname<br />";
+ echo "<font color=\"#888888\">$stridle: ".format_time($lastping, $str)."</font>";
+ echo "</font></p>";
echo "<td></tr>";
}
echo "</table>";