mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 08:56:36 +02:00
Some minor improvements
This commit is contained in:
parent
1515a89e2d
commit
f7e648da70
6 changed files with 89 additions and 31 deletions
|
@ -3,10 +3,19 @@
|
||||||
require("../../../config.php");
|
require("../../../config.php");
|
||||||
require("../lib.php");
|
require("../lib.php");
|
||||||
|
|
||||||
|
require_variable($chat_sid);
|
||||||
|
|
||||||
if (!$chatuser = get_record("chat_users", "sid", $chat_sid)) {
|
if (!$chatuser = get_record("chat_users", "sid", $chat_sid)) {
|
||||||
echo "Not logged in!";
|
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\">
|
<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\" \"http://www.w3.org/TR/REC-html40/loose.dtd\">
|
||||||
|
|
|
@ -13,6 +13,8 @@ if (!$course = get_record("course", "id", $chat->course)) {
|
||||||
error("Could not find the course this belongs to!");
|
error("Could not find the course this belongs to!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
require_login($course->id);
|
||||||
|
|
||||||
if (!$chat_sid = chat_login_user($chat->id, "header_js")) {
|
if (!$chat_sid = chat_login_user($chat->id, "header_js")) {
|
||||||
error("Could not log in to chat room!!");
|
error("Could not log in to chat room!!");
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,8 +5,16 @@ require("../lib.php");
|
||||||
|
|
||||||
if (!$chatuser = get_record("chat_users", "sid", $chat_sid)) {
|
if (!$chatuser = get_record("chat_users", "sid", $chat_sid)) {
|
||||||
echo "Not logged in!";
|
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)) {
|
if ($message = chat_get_latest_message($chatuser->chatid)) {
|
||||||
$chat_newlasttime = $message->timestamp;
|
$chat_newlasttime = $message->timestamp;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -1,24 +1,35 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
include("../../config.php");
|
include("../../config.php");
|
||||||
include("lib.php");
|
include("lib.php");
|
||||||
|
|
||||||
require_variable($chat_sid);
|
require_variable($chat_sid);
|
||||||
require_variable($chat_version);
|
require_variable($chat_version);
|
||||||
require_variable($chat_message);
|
require_variable($chat_message);
|
||||||
|
|
||||||
if (!$chatuser = get_record("chat_users", "sid", $chat_sid)) {
|
if (!$chatuser = get_record("chat_users", "sid", $chat_sid)) {
|
||||||
echo "Not logged in!";
|
echo "Not logged in!";
|
||||||
die;
|
die;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!$chat = get_record("chat", "id", $chatuser->chatid)) {
|
||||||
|
error("No chat found");
|
||||||
|
}
|
||||||
|
|
||||||
|
require_login($chat->course);
|
||||||
|
|
||||||
|
|
||||||
/// Delete old messages here
|
/// Delete old messages here
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// Clean up the message
|
/// Clean up the message
|
||||||
|
|
||||||
$chat_message = clean_text($chat_message, FORMAT_MOODLE); // Strip bad tags
|
$chat_message = clean_text($chat_message, FORMAT_MOODLE); // Strip bad tags
|
||||||
|
|
||||||
if (!empty($chat_message)) {
|
/// Add the message to the database
|
||||||
|
|
||||||
|
if (!empty($chat_message)) {
|
||||||
|
|
||||||
$message->chatid = $chatuser->chatid;
|
$message->chatid = $chatuser->chatid;
|
||||||
$message->userid = $chatuser->userid;
|
$message->userid = $chatuser->userid;
|
||||||
|
@ -28,16 +39,21 @@ if (!empty($chat_message)) {
|
||||||
if (!insert_record("chat_messages", $message)) {
|
if (!insert_record("chat_messages", $message)) {
|
||||||
error("Could not insert a chat message!");
|
error("Could not insert a chat message!");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if ($chat_version == "header" OR $chat_version == "box") {
|
$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");
|
redirect("../gui_$chat_version/chatinput.php?chat_sid=$chat_sid");
|
||||||
|
|
||||||
} else if ($chat_version == "text") {
|
} else if ($chat_version == "text") {
|
||||||
redirect("../gui_$chat_version/index.php?chat_sid=$chat_sid&chat_lastid=$chat_lastid");
|
redirect("../gui_$chat_version/index.php?chat_sid=$chat_sid&chat_lastid=$chat_lastid");
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
redirect("empty.php");
|
redirect("empty.php");
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
|
@ -130,7 +130,7 @@ function chat_get_users($chatid) {
|
||||||
|
|
||||||
global $CFG;
|
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,
|
FROM {$CFG->prefix}chat_users c,
|
||||||
{$CFG->prefix}user u
|
{$CFG->prefix}user u
|
||||||
WHERE c.chatid = '$chatid'
|
WHERE c.chatid = '$chatid'
|
||||||
|
@ -158,7 +158,7 @@ function chat_login_user($chatid, $version="header_js") {
|
||||||
$chatuser->userid = $USER->id;
|
$chatuser->userid = $USER->id;
|
||||||
$chatuser->version = $version;
|
$chatuser->version = $version;
|
||||||
$chatuser->ip = $USER->lastIP;
|
$chatuser->ip = $USER->lastIP;
|
||||||
$chatuser->lastping = time();
|
$chatuser->lastping = $chatuser->firstping = $chatuser->lastmessageping = time();
|
||||||
$chatuser->sid = random_string(32);
|
$chatuser->sid = random_string(32);
|
||||||
|
|
||||||
if (!insert_record("chat_users", $chatuser)) {
|
if (!insert_record("chat_users", $chatuser)) {
|
||||||
|
|
|
@ -10,6 +10,13 @@ if (!$chatuser = get_record("chat_users", "sid", $chat_sid)) {
|
||||||
die;
|
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)) {
|
if (!$chat = get_record("chat", "id", $chatuser->chatid)) {
|
||||||
error("Could not find chat! id = $chatuser->chatid");
|
error("Could not find chat! id = $chatuser->chatid");
|
||||||
}
|
}
|
||||||
|
@ -51,12 +58,28 @@ header("Refresh: ".CHAT_REFRESH_USERLIST."; URL=users.php?chat_sid=".$chat_sid);
|
||||||
|
|
||||||
print_header();
|
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%\">";
|
echo "<table width=\"100%\">";
|
||||||
foreach ($chatusers as $chatuser) {
|
foreach ($chatusers as $chatuser) {
|
||||||
|
$lastping = $timenow - $chatuser->lastmessageping;
|
||||||
echo "<tr><td width=35>";
|
echo "<tr><td width=35>";
|
||||||
print_user_picture($chatuser->id, 0, $chatuser->picture, false, false, false);
|
print_user_picture($chatuser->id, 0, $chatuser->picture, false, false, false);
|
||||||
echo "</td><td valign=center>";
|
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 "<td></tr>";
|
||||||
}
|
}
|
||||||
echo "</table>";
|
echo "</table>";
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue