diff --git a/mod/chat/db/mysql.php b/mod/chat/db/mysql.php
index 15afb08ceff..bc762e6a5d9 100644
--- a/mod/chat/db/mysql.php
+++ b/mod/chat/db/mysql.php
@@ -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;
}
diff --git a/mod/chat/db/mysql.sql b/mod/chat/db/mysql.sql
index dde169848b0..d11b71c1a5e 100644
--- a/mod/chat/db/mysql.sql
+++ b/mod/chat/db/mysql.sql
@@ -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',
diff --git a/mod/chat/db/postgres7.php b/mod/chat/db/postgres7.php
index 371bd921620..82764d60077 100644
--- a/mod/chat/db/postgres7.php
+++ b/mod/chat/db/postgres7.php
@@ -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;
}
diff --git a/mod/chat/db/postgres7.sql b/mod/chat/db/postgres7.sql
index ff2143775a2..7b54e6749ef 100644
--- a/mod/chat/db/postgres7.sql
+++ b/mod/chat/db/postgres7.sql
@@ -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',
diff --git a/mod/chat/gui_header_js/chatinput.php b/mod/chat/gui_header_js/chatinput.php
index 01ba155146c..64793c93f0e 100644
--- a/mod/chat/gui_header_js/chatinput.php
+++ b/mod/chat/gui_header_js/chatinput.php
@@ -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() {
diff --git a/mod/chat/gui_header_js/index.php b/mod/chat/gui_header_js/index.php
index c74eac2de06..2948a4fbe80 100644
--- a/mod/chat/gui_header_js/index.php
+++ b/mod/chat/gui_header_js/index.php
@@ -1,49 +1,71 @@
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");
+
?>
- shortname: $chat->name" ?>
+ shortname: $chat->name$groupname" ?>
- 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.
diff --git a/mod/chat/gui_header_js/jsupdate.php b/mod/chat/gui_header_js/jsupdate.php
index d5734c6a3d0..659df29e327 100644
--- a/mod/chat/gui_header_js/jsupdate.php
+++ b/mod/chat/gui_header_js/jsupdate.php
@@ -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");
?>
@@ -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) {
diff --git a/mod/chat/insert.php b/mod/chat/insert.php
index 36e70a2306d..2b0031d1db0 100644
--- a/mod/chat/insert.php
+++ b/mod/chat/insert.php
@@ -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");
diff --git a/mod/chat/lib.php b/mod/chat/lib.php
index 94764119cec..f1cf1828109 100644
--- a/mod/chat/lib.php
+++ b/mod/chat/lib.php
@@ -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();
diff --git a/mod/chat/report.php b/mod/chat/report.php
index 9ea6211440f..b15b2d380db 100644
--- a/mod/chat/report.php
+++ b/mod/chat/report.php
@@ -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 id\">$strchats ->
id\">$chat->name ->
- id\">$strchatreport",
+ id\">$strchatreport",
"", "", 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 "";
- echo "id&start=$sessionstart&end=$sessionend\">$strseesession";
+ echo "id&start=$sessionstart&end=$sessionend$groupparam\">$strseesession";
if ($isteacheredit) {
- echo "
id&start=$sessionstart&end=$sessionend&deletesession=1\">$strdeletesession";
+ echo "
id&start=$sessionstart&end=$sessionend&deletesession=1$groupparam\">$strdeletesession";
}
echo "
";
print_simple_box_end();
diff --git a/mod/chat/users.php b/mod/chat/users.php
index 319b32a2c3a..5f9088c1e68 100644
--- a/mod/chat/users.php
+++ b/mod/chat/users.php
@@ -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 "";
echo fullname($chatuser)."
";
echo "$stridle: ".format_time($lastping, $str)."";
- echo " id\">$strbeep";
+ echo " id&groupid=$groupid\">$strbeep";
echo "
";
echo "";
}
diff --git a/mod/chat/version.php b/mod/chat/version.php
index d931424e101..3bd9ef5fd1e 100644
--- a/mod/chat/version.php
+++ b/mod/chat/version.php
@@ -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)?
diff --git a/mod/chat/view.php b/mod/chat/view.php
index a9c29a67afa..54b3b2b8aba 100644
--- a/mod/chat/view.php
+++ b/mod/chat/view.php
@@ -60,10 +60,26 @@
navmenu($course, $cm));
if (($chat->studentlogs or isteacher($course->id)) and !isguest()) {
- echo " id\">".
+ echo "id\">".
get_string("viewreport", "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, "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();
}
|