Preliminary support for groups in Chat.

It's not well tested yet - I'm hoping to do some testing on moodle.org
with some real people and get this refined enough for the Beta release
later today.
This commit is contained in:
moodler
2004-02-24 06:35:57 +00:00
parent 4c17698e77
commit 84a2fdd706
13 changed files with 162 additions and 60 deletions
+5
View File
@@ -23,6 +23,11 @@ function chat_upgrade($oldversion) {
table_column("chat", "", "schedule", "integer", "4", "", "0", "not null", "studentlogs");
}
if ($oldversion < 2004022300) {
table_column("chat_messages", "", "groupid", "integer", "10", "unsigned", "0", "not null", "userid");
table_column("chat_users", "", "groupid", "integer", "10", "unsigned", "0", "not null", "userid");
}
return true;
}
+2
View File
@@ -24,6 +24,7 @@ CREATE TABLE `prefix_chat_messages` (
`id` int(10) unsigned NOT NULL auto_increment,
`chatid` int(10) NOT NULL default '0',
`userid` int(10) NOT NULL default '0',
`groupid` int(10) NOT NULL default '0',
`system` int(1) unsigned NOT NULL default '0',
`message` text NOT NULL,
`timestamp` int(10) unsigned NOT NULL default '0',
@@ -40,6 +41,7 @@ CREATE TABLE `prefix_chat_users` (
`id` int(10) unsigned NOT NULL auto_increment,
`chatid` int(11) NOT NULL default '0',
`userid` int(11) NOT NULL default '0',
`groupid` int(11) NOT NULL default '0',
`version` varchar(16) NOT NULL default '',
`ip` varchar(15) NOT NULL default '',
`firstping` int(10) unsigned NOT NULL default '0',
+6
View File
@@ -6,6 +6,12 @@ function chat_upgrade($oldversion) {
global $CFG;
if ($oldversion < 2004022300) {
table_column("chat_messages", "", "groupid", "integer", "10", "unsigned", "0", "not null", "userid");
table_column("chat_users", "", "groupid", "integer", "10", "unsigned", "0", "not null", "userid");
}
return true;
}
+2
View File
@@ -24,6 +24,7 @@ CREATE TABLE prefix_chat_messages (
id SERIAL,
chatid integer NOT NULL default '0',
userid integer NOT NULL default '0',
groupid integer NOT NULL default '0',
system integer NOT NULL default '0',
message text NOT NULL,
timestamp integer NOT NULL default '0',
@@ -39,6 +40,7 @@ CREATE TABLE prefix_chat_users (
id SERIAL,
chatid integer NOT NULL default '0',
userid integer NOT NULL default '0',
groupid integer NOT NULL default '0',
version varchar(16) NOT NULL default '',
ip varchar(15) NOT NULL default '',
firstping integer NOT NULL default '0',
+3 -1
View File
@@ -4,6 +4,7 @@ require("../../../config.php");
require("../lib.php");
require_variable($chat_sid);
optional_variable($groupid);
if (!$chatuser = get_record("chat_users", "sid", $chat_sid)) {
echo "Not logged in!";
@@ -51,7 +52,8 @@ function empty_field_and_submit() {
<form action="../insert.php" method="GET" target="empty" name="fdummy"
OnSubmit="return empty_field_and_submit()">
<input type="hidden" name="chat_sid" value="<?php echo $chat_sid; ?>">
<input type="hidden" name="chat_sid" value="<?php echo $chat_sid ?>">
<input type="hidden" name="groupid" value="<?php echo $groupid ?>">
<input type="hidden" name="chat_version" value="header_js">
<input type="hidden" name="chat_message">
</form>
+46 -24
View File
@@ -1,49 +1,71 @@
<?php
require_once('../../../config.php');
require_once('../lib.php');
require_once('../../../config.php');
require_once('../lib.php');
require_variable($id);
require_variable($id);
optional_variable($groupid);
if (!$chat = get_record("chat", "id", $id)) {
error("Could not find that chat room!");
}
if (!$chat = get_record("chat", "id", $id)) {
error("Could not find that chat room!");
}
if (!$course = get_record("course", "id", $chat->course)) {
error("Could not find the course this belongs to!");
}
require_login($course->id);
if (isguest()) {
error("Guest does not have access to chat rooms");
}
if (!$course = get_record("course", "id", $chat->course)) {
error("Could not find the course this belongs to!");
}
/// Check to see if groups are being used here
if ($groupmode = groupmode($course, $cm)) { // Groups are being used
if ($currentgroup = get_and_set_current_group($course->id, $groupmode, $groupid)) {
if (!$group = get_record('groups', 'id', $currentgroup)) {
error("That group (id $currentgroup) doesn't exist!");
}
$groupname = ': '.$group->name;
} else {
$groupname = ': '.get_string('allparticipants');
}
} else {
$currentgroup = false;
$groupname = '';
}
require_login($course->id);
if (!$chat_sid = chat_login_user($chat->id, "header_js")) {
error("Could not log in to chat room!!");
}
if (isguest()) {
error("Guest does not have access to chat rooms");
}
if (!$chat_sid = chat_login_user($chat->id, "header_js")) {
error("Could not log in to chat room!!");
}
$strchat = get_string("modulename", "chat");
if ($currentgroup !== false) {
$params = "chat_enter=true&chat_sid=$chat_sid&groupid=$currentgroup";
} else {
$params = "chat_enter=true&chat_sid=$chat_sid";
}
$strchat = get_string("modulename", "chat");
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">
<html>
<head>
<title>
<?php echo "$strchat: $course->shortname: $chat->name" ?>
<?php echo "$strchat: $course->shortname: $chat->name$groupname" ?>
</title>
</head>
<frameset cols="*,200" border="5" framespacing="no" frameborder="yes" marginwidth="2" marginheight="1">
<frameset rows="0,0,*,40" border="0" framespacing="no" frameborder="no" marginwidth="2" marginheight="1">
<frame src="../empty.php" NAME="empty" scrolling="no" marginwidth="0" marginheight="0">
<frame src="jsupdate.php?chat_sid=<?php echo $chat_sid; ?>&chat_enter=true" scrolling="no" marginwidth="0" marginheight="0">
<frame src="jsupdate.php?<?php echo $params ?>" scrolling="no" marginwidth="0" marginheight="0">
<frame src="chatmsg.php" NAME="msg" scrolling="auto" marginwidth="2" marginheight="1">
<frame src="chatinput.php?chat_sid=<?php echo $chat_sid; ?>" name="input" scrolling="no" marginwidth="2" marginheight="1">
<frame src="chatinput.php?<?php echo $params ?>" name="input" scrolling="no" marginwidth="2" marginheight="1">
</frameset>
<frame src="../users.php?chat_sid=<?php echo $chat_sid; ?>&chat_enter=true" name="users" scrolling="auto" marginwidth="5" marginheight="5">
<frame src="../users.php?<?php echo $params ?>" name="users" scrolling="auto" marginwidth="5" marginheight="5">
</frameset>
<noframes>
Sorry, this version of ARSC needs a browser that understands framesets. We have a Lynx friendly version too.
Sorry, this version of Moodle Chat needs a browser that handles frames.
</noframes>
</html>
+7 -5
View File
@@ -3,6 +3,9 @@
require("../../../config.php");
require("../lib.php");
$groupid = empty($_GET['groupid']) ? 0 : $_GET['groupid'];
$groupselect = $groupid ? " AND (groupid='$groupid' OR groupid='0') " : "";
if (!$chatuser = get_record("chat_users", "sid", $chat_sid)) {
echo "Not logged in!";
die;
@@ -14,8 +17,7 @@ if (!$chat = get_record("chat", "id", $chatuser->chatid)) {
require_login($chat->course);
if ($message = chat_get_latest_message($chatuser->chatid)) {
if ($message = chat_get_latest_message($chatuser->chatid, $groupid)) {
$chat_newlasttime = $message->timestamp;
} else {
$chat_newlasttime = 0;
@@ -31,7 +33,7 @@ header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");
header("Content-Type: text/html");
header("Refresh: $CFG->chat_refresh_room; URL=jsupdate.php?chat_sid=".$chat_sid."&chat_lasttime=".$chat_newlasttime);
header("Refresh: $CFG->chat_refresh_room; URL=jsupdate.php?chat_sid=$chat_sid&chat_lasttime=$chat_newlasttime&groupid=$groupid");
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
@@ -44,8 +46,8 @@ header("Refresh: $CFG->chat_refresh_room; URL=jsupdate.php?chat_sid=".$chat_sid.
if ($chat_lasttime) {
if ($messages = get_records_select("chat_messages",
"chatid = '$chatuser->chatid' AND timestamp > '$chat_lasttime'",
"timestamp ASC")) {
"chatid = '$chatuser->chatid' AND timestamp > '$chat_lasttime' $groupselect",
"timestamp ASC")) {
foreach ($messages as $message) {
$formatmessage = chat_format_message($message, $chat->course);
if ($formatmessage->beep) {
+10 -2
View File
@@ -6,6 +6,7 @@
require_variable($chat_sid);
require_variable($chat_version);
require_variable($chat_message);
optional_variable($groupid);
if (!$chatuser = get_record("chat_users", "sid", $chat_sid)) {
echo "Not logged in!";
@@ -17,6 +18,12 @@
}
require_login($chat->course);
if ($groupid) {
if (!isteacheredit($course->id) and !ismember($groupid)) {
error("You can't chat here!");
}
}
/// Clean up the message
@@ -28,6 +35,7 @@
$message->chatid = $chatuser->chatid;
$message->userid = $chatuser->userid;
$message->groupid = $groupid;
$message->message = $chat_message;
$message->timestamp = time();
@@ -42,10 +50,10 @@
/// 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&groupid=$groupid");
} 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&groupid=$groupid");
} else {
redirect("empty.php");
+26 -7
View File
@@ -165,18 +165,24 @@ function chat_cron () {
return true;
}
function chat_get_participants($chatid) {
function chat_get_participants($chatid, $groupid=0) {
//Returns the users with data in one chat
//(users with records in chat_messages, students)
global $CFG;
if ($groupid) {
$groupselect = " AND (c.groupid='$groupid' OR c.groupid='0')";
} else {
$groupselect = "";
}
//Get students
$students = get_records_sql("SELECT DISTINCT u.*
FROM {$CFG->prefix}user u,
{$CFG->prefix}chat_messages c
WHERE c.chatid = '$chatid' and
u.id = c.userid");
WHERE c.chatid = '$chatid' $groupselect
AND u.id = c.userid");
//Return students array (it contains an array of unique users)
return ($students);
@@ -185,20 +191,26 @@ function chat_get_participants($chatid) {
//////////////////////////////////////////////////////////////////////
/// Functions that require some SQL
function chat_get_users($chatid) {
function chat_get_users($chatid, $groupid=0) {
global $CFG;
if ($groupid) {
$groupselect = " AND (c.groupid='$groupid' OR c.groupid='0')";
} else {
$groupselect = "";
}
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'
AND u.id = c.userid
AND u.id = c.userid $groupselect
GROUP BY u.id
ORDER BY c.firstping ASC");
}
function chat_get_latest_message($chatid) {
function chat_get_latest_message($chatid, $groupid=0) {
/// Efficient way to extract just the latest message
/// Uses ADOdb directly instead of get_record_sql()
/// because the LIMIT command causes problems with
@@ -206,9 +218,15 @@ function chat_get_latest_message($chatid) {
global $db, $CFG;
if ($groupid) {
$groupselect = " AND (groupid='$groupid' OR groupid='0')";
} else {
$groupselect = "";
}
if (!$rs = $db->Execute("SELECT *
FROM {$CFG->prefix}chat_messages
WHERE chatid = '$chatid'
WHERE chatid = '$chatid' $groupselect
ORDER BY timestamp DESC LIMIT 1")) {
return false;
}
@@ -251,6 +269,7 @@ function chat_delete_old_users() {
foreach ($oldusers as $olduser) {
$message->chatid = $olduser->chatid;
$message->userid = $olduser->userid;
$message->groupid = $olduser->groupid;
$message->message = "exit";
$message->system = 1;
$message->timestamp = time();
+30 -15
View File
@@ -5,21 +5,22 @@
require_once("../../config.php");
require_once("lib.php");
require_variable($id); // Chat Module ID, or
require_variable($id); // Course module ID
optional_variable($group, ""); // Start of period
optional_variable($start, ""); // Start of period
optional_variable($end, ""); // End of period
optional_variable($deletesession, ""); // Delete a session
optional_variable($confirmdelete, ""); // End of period
if (! $chat = get_record("chat", "id", $id)) {
if (! $cm = get_record("course_modules", "id", $id)) {
error("Course Module ID was incorrect");
}
if (! $chat = get_record("chat", "id", $cm->instance)) {
error("Course module is incorrect");
}
if (! $course = get_record("course", "id", $chat->course)) {
error("Course is misconfigured");
}
if (! $cm = get_coursemodule_from_instance("chat", $chat->id, $course->id)) {
error("Course Module ID was incorrect");
}
require_login($course->id);
@@ -30,7 +31,7 @@
error("You can not view these chat reports");
}
add_to_log($course->id, "chat", "view", "view.php?id=$cm->id", "$chat->id", "$cm->id");
add_to_log($course->id, "chat", "report", "report.php?id=$cm->id", "$chat->id", "$cm->id");
/// Print the page header
@@ -52,13 +53,13 @@
print_header("$course->shortname: $chat->name: $strchatreport", "$course->fullname",
"$navigation <a href=\"index.php?id=$course->id\">$strchats</a> ->
<a href=\"view.php?id=$cm->id\">$chat->name</a> ->
<a href=\"report.php?id=$chat->id\">$strchatreport</a>",
<a href=\"report.php?id=$cm->id\">$strchatreport</a>",
"", "", true, "", navmenu($course, $cm));
if ($deletesession and $isteacheredit) {
notice_yesno(get_string("deletesessionsure", "chat"),
"report.php?id=$chat->id&deletesession=1&confirmdelete=1&start=$start&end=$end",
"report.php?id=$chat->id");
"report.php?id=$cm->id&deletesession=1&confirmdelete=1&start=$start&end=$end",
"report.php?id=$cm->id");
}
if (!$messages = get_records_select("chat_messages", "chatid = $chat->id AND
@@ -78,7 +79,7 @@
}
if (!$deletesession or !$isteacheredit) {
print_continue("report.php?id=$chat->id");
print_continue("report.php?id=$cm->id");
}
print_footer($course);
@@ -94,15 +95,29 @@
"", "", true, "", navmenu($course, $cm));
print_heading($chat->name.": ".get_string("sessions", "chat"));
/// Check to see if groups are being used here
if ($groupmode = groupmode($course, $cm)) { // Groups are being used
$currentgroup = setup_and_print_groups($course, $groupmode, "report.php?id=$cm->id");
} else {
$currentgroup = false;
}
if ($currentgroup) {
$groupselect = " AND groupid = '$currentgroup'";
$groupparam = "&group=$currentgroup";
} else {
$groupselect = "";
$groupparam = "";
}
print_heading($chat->name.": ".get_string("sessions", "chat"));
/// Delete a session if one has been specified
if ($deletesession and $isteacheredit and $confirmdelete and $start and $end) {
delete_records_select("chat_messages", "chatid = $chat->id AND
timestamp >= '$start' AND
timestamp <= '$end'");
timestamp <= '$end' $groupselect");
$strdeleted = get_string("deleted");
notify("$strdeleted: ".userdate($start)." --> ". userdate($end));
unset($deletesession);
@@ -112,7 +127,7 @@
/// Get the messages
if (empty($messages)) { /// May have already got them above
if (!$messages = get_records("chat_messages", "chatid", $chat->id, "timestamp DESC")) {
if (!$messages = get_records_select("chat_messages", "chatid = '$chat->id' $groupselect", "timestamp DESC")) {
print_heading(get_string("nomessages", "chat"));
print_footer($course);
exit;
@@ -161,9 +176,9 @@
}
echo "<p align=\"right\">";
echo "<a href=\"report.php?id=$chat->id&start=$sessionstart&end=$sessionend\">$strseesession</a>";
echo "<a href=\"report.php?id=$cm->id&start=$sessionstart&end=$sessionend$groupparam\">$strseesession</a>";
if ($isteacheredit) {
echo "<br /><a href=\"report.php?id=$chat->id&start=$sessionstart&end=$sessionend&deletesession=1\">$strdeletesession</a>";
echo "<br /><a href=\"report.php?id=$cm->id&start=$sessionstart&end=$sessionend&deletesession=1$groupparam\">$strdeletesession</a>";
}
echo "</p>";
print_simple_box_end();
+5 -2
View File
@@ -4,6 +4,7 @@ include("../../config.php");
include("lib.php");
require_variable($chat_sid);
optional_variable($groupid, 0);
if (!$chatuser = get_record("chat_users", "sid", $chat_sid)) {
echo "Not logged in!";
@@ -24,6 +25,7 @@ if (!$chat = get_record("chat", "id", $chatuser->chatid)) {
if (isset($_GET['chat_enter'])) {
$message->chatid = $chatuser->chatid;
$message->userid = $chatuser->userid;
$message->groupid = $groupid;
$message->message = "enter";
$message->system = 1;
$message->timestamp = time();
@@ -36,6 +38,7 @@ if (isset($_GET['chat_enter'])) {
if (isset($_GET['beep'])) {
$message->chatid = $chatuser->chatid;
$message->userid = $chatuser->userid;
$message->groupid = $groupid;
$message->message = "beep $beep";
$message->system = 0;
$message->timestamp = time();
@@ -80,7 +83,7 @@ $str->secs = get_string("secs");
/// Get list of users
if (!$chatusers = chat_get_users($chatuser->chatid)) {
if (!$chatusers = chat_get_users($chatuser->chatid, $groupid)) {
print_string("errornousers", "chat");
exit;
}
@@ -96,7 +99,7 @@ foreach ($chatusers as $chatuser) {
echo "<p><font size=1>";
echo fullname($chatuser)."<br />";
echo "<font color=\"#888888\">$stridle: ".format_time($lastping, $str)."</font>";
echo " <a href=\"users.php?chat_sid=$chat_sid&beep=$chatuser->id\">$strbeep</a>";
echo " <a href=\"users.php?chat_sid=$chat_sid&beep=$chatuser->id&groupid=$groupid\">$strbeep</a>";
echo "</font></p>";
echo "<td></tr>";
}
+1 -1
View File
@@ -5,7 +5,7 @@
/// This fragment is called by moodle_needs_upgrading() and /admin/index.php
/////////////////////////////////////////////////////////////////////////////////
$module->version = 2004013101; // The (date) version of this module
$module->version = 2004022300; // The (date) version of this module
$module->requires = 2004013101; // Requires this Moodle version
$module->cron = 300; // How often should cron check this module (seconds)?
+19 -3
View File
@@ -60,10 +60,26 @@
navmenu($course, $cm));
if (($chat->studentlogs or isteacher($course->id)) and !isguest()) {
echo "<p align=right><a href=\"report.php?id=$chat->id\">".
echo "<p align=right><a href=\"report.php?id=$cm->id\">".
get_string("viewreport", "chat")."</a></p>";
}
/// Check to see if groups are being used here
if ($groupmode = groupmode($course, $cm)) { // Groups are being used
$currentgroup = setup_and_print_groups($course, $groupmode, "view.php?id=$cm->id");
} else {
$currentgroup = false;
}
if ($currentgroup) {
$groupselect = " AND groupid = '$currentgroup'";
$groupparam = "&group=$currentgroup";
} else {
$groupselect = "";
$groupparam = "";
}
/// Print the main part of the page
// Do the browser-detection etc later on.
@@ -88,8 +104,8 @@
if (!isguest()) {
print_simple_box_start("center");
link_to_popup_window ("/mod/chat/gui_$chatversion/index.php?id=$chat->id",
"chat$course->id$chat->id", "$strenterchat", 500, 700, $strchat);
link_to_popup_window ("/mod/chat/gui_$chatversion/index.php?id=$chat->id$groupparam",
"chat$course->id$chat->id$groupparam", "$strenterchat", 500, 700, $strchat);
print_simple_box_end();
}