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;
}
`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',
`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',
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;
}
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',
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',
require("../lib.php");
require_variable($chat_sid);
+optional_variable($groupid);
if (!$chatuser = get_record("chat_users", "sid", $chat_sid)) {
echo "Not logged in!";
<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>
<?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>
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;
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;
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">
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) {
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!";
}
require_login($chat->course);
+
+ if ($groupid) {
+ if (!isteacheredit($course->id) and !ismember($groupid)) {
+ error("You can't chat here!");
+ }
+ }
/// Clean up the message
$message->chatid = $chatuser->chatid;
$message->userid = $chatuser->userid;
+ $message->groupid = $groupid;
$message->message = $chat_message;
$message->timestamp = time();
/// 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");
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);
//////////////////////////////////////////////////////////////////////
/// 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
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;
}
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();
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);
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
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
}
if (!$deletesession or !$isteacheredit) {
- print_continue("report.php?id=$chat->id");
+ print_continue("report.php?id=$cm->id");
}
print_footer($course);
"", "", 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);
/// 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;
}
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();
include("lib.php");
require_variable($chat_sid);
+optional_variable($groupid, 0);
if (!$chatuser = get_record("chat_users", "sid", $chat_sid)) {
echo "Not logged in!";
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();
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();
/// Get list of users
-if (!$chatusers = chat_get_users($chatuser->chatid)) {
+if (!$chatusers = chat_get_users($chatuser->chatid, $groupid)) {
print_string("errornousers", "chat");
exit;
}
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>";
}
/// 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)?
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.
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();
}