$string['beep'] = "beep";
$string['chatintro'] = "Introduction text";
$string['chatname'] = "Name of this chat room";
+$string['chatreport'] = "Chat report";
$string['currentchats'] = "Currently active chats";
$string['enterchat'] = "Click here to enter the chat";
$string['idle'] = "Idle";
$string['messagebeepsyou'] = "\$a has just beeped you!";
$string['messageenter'] = "\$a has just entered this chat";
$string['messageexit'] = "\$a has left this chat";
-$string['savemessages'] = "Number of messages to save";
+$string['neverdeletemessages'] = "Never delete messages";
+$string['savemessages'] = "Save messages";
+$string['sessions'] = "Chat sessions";
$string['strftimemessage'] = "%%H:%%M";
+$string['studentseereports'] = "Allow everyone to see reports";
+$string['viewreport'] = "View chat reports";
?>
global $CFG;
- if ($oldversion < 2002080500) {
+ if ($oldversion < 2003072100) {
+ modify_database ("", " INSERT INTO prefix_log_display VALUES ('chat', 'report', 'chat', 'name'); ");
+ }
+
+ if ($oldversion < 2003072101) {
+ table_column("chat", "messages", "keepdays", "integer", "10", "unsigned", "0", "not null");
+ }
+
+ if ($oldversion < 2003072102) {
+ table_column("chat", "", "studentlogs", "integer", "4", "unsigned", "0", "not null", "keepdays");
}
return true;
`course` int(10) unsigned NOT NULL default '0',
`name` varchar(255) NOT NULL default '',
`intro` text NOT NULL,
- `messages` int(11) NOT NULL default '1000',
+ `keepdays` int(11) NOT NULL default '0',
+ `studentlogs` int(4) NOT NULL default '0',
`timemodified` int(10) unsigned NOT NULL default '0',
PRIMARY KEY (`id`)
) TYPE=MyISAM COMMENT='Each of these is a chat room';
INSERT INTO prefix_log_display VALUES ('chat', 'view', 'chat', 'name');
INSERT INTO prefix_log_display VALUES ('chat', 'add', 'chat', 'name');
INSERT INTO prefix_log_display VALUES ('chat', 'update', 'chat', 'name');
+INSERT INTO prefix_log_display VALUES ('chat', 'report', 'chat', 'name');
require_login($chat->course);
-
-/// Delete old messages here
-
-
-
/// Clean up the message
$chat_message = clean_text($chat_message, FORMAT_MOODLE); // Strip bad tags
chat_delete_old_users();
+ /// Delete old messages
+ if ($chats = get_records("chat")) {
+ foreach ($chats as $chat) {
+ if ($chat->keepdays) {
+ $timeold = time() - ($chat->keepdays * 24 * 3600);
+ delete_records_select("chat_messages", "chatid = '$chat->id' AND timestamp < '$timeold'");
+ }
+ }
+ }
+
return true;
}
}
}
+
function chat_browser_detect($HTTP_USER_AGENT) {
if(eregi("(opera) ([0-9]{1,2}.[0-9]{1,3}){0,1}", $HTTP_USER_AGENT, $match)
if (!isset($form->intro)) {
$form->intro = "";
}
- if (!isset($form->messages)) {
- $form->messages = 1000;
+ if (!isset($form->keepdays)) {
+ $form->keepdays = 30;
+ }
+ if (!isset($form->studentlogs)) {
+ $form->studentlogs = 0;
}
?>
<form name="form" method="post" <?php echo $onsubmit ?> action="mod.php">
<td align=right><p><b><?php print_string("savemessages", "chat")?>:</b></p>
<td>
<?php
- $options = array(5000, 1000, 500, 100);
- choose_from_menu ($options, "messages", $form->messages, "", "", "");
+ unset($options);
+ $options[0] = get_string("neverdeletemessages", "chat");
+ $options[365] = get_string("numdays", "", 365);
+ $options[180] = get_string("numdays", "", 180);
+ $options[150] = get_string("numdays", "", 150);
+ $options[120] = get_string("numdays", "", 120);
+ $options[90] = get_string("numdays", "", 90);
+ $options[60] = get_string("numdays", "", 60);
+ $options[30] = get_string("numdays", "", 30);
+ $options[21] = get_string("numdays", "", 21);
+ $options[14] = get_string("numdays", "", 14);
+ $options[7] = get_string("numdays", "", 7);
+ $options[2] = get_string("numdays", "", 2);
+
+ choose_from_menu ($options, "keepdays", $form->keepdays, "", "", "");
+ ?>
+ </td>
+</tr>
+<tr valign=top>
+ <td align=right><p><b><?php print_string("studentseereports", "chat")?>:</b></p>
+ <td>
+ <?php
+ unset($options);
+ $options[0] = get_string("no");
+ $options[1] = get_string("yes");
+ choose_from_menu ($options, "studentlogs", $form->studentlogs, "", "", "");
?>
</td>
</tr>
--- /dev/null
+<?PHP // $Id$
+
+/// This page prints reports and info about chats
+
+ require_once("../../config.php");
+ require_once("lib.php");
+
+ require_variable($id); // Chat Module ID, or
+
+ if (! $chat = get_record("chat", "id", $id)) {
+ 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);
+
+ if (!isteacher($course->id) and !$chat->studentlogs) {
+ error("Only teachers are allowed to view these chat reports");
+ }
+
+ add_to_log($course->id, "chat", "view", "view.php?id=$cm->id", "$chat->id");
+
+/// Print the page header
+
+ if ($course->category) {
+ $navigation = "<A HREF=\"../../course/view.php?id=$course->id\">$course->shortname</A> ->";
+ }
+
+ $strchats = get_string("modulenameplural", "chat");
+ $strchat = get_string("modulename", "chat");
+ $strchatreport = get_string("chatreport", "chat");
+
+ 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> -> $strchatreport",
+ "", "", true, "", navmenu($course, $cm));
+
+/// Print the main part of the page
+
+ print_heading($chat->name);
+
+ print_simple_box( get_string("sessions", "chat"), "center");
+
+ if (!$messages = get_records("chat_messages", "chatid", $chat->id, "timestamp DESC")) {
+ print_heading(get_string("nomessages", "chat"));
+ print_footer($course);
+ exit;
+ }
+
+ $sessiongap = 5 * 60; // 5 minutes
+ $sessionstart = 0;
+ $sessionend = 0;
+ $sessionusers = array();
+ $timelast = 0;
+
+ foreach ($messages as $message) {
+ if (!$timelast) {
+ $timelast = $message->timestamp;
+ }
+ if (!$sessionstart) {
+ $sessionstart = $message->timestamp;
+ }
+ if ($message->timestamp - $timelast < $sessiongap) { // Same session
+ $sessionusers[$message->user] = $message->timestamp; // Remember user
+ } else {
+ $sessionend = $lasttime;
+
+ print_heading(usertime($sessionstart)." --> ". usertime($sessionend));
+
+ print_simple_box_start("center");
+
+ foreach ($sessionusers as $sessionuser => $lastusertime) {
+ $user = get_record("user", "id", $sessionuser);
+ print_user_picture($user->id, $course->id, $user->picture);
+ }
+
+ print_simple_box_end();
+
+ $sessionstart = $message->timestamp;
+ $sessionusers = array();
+ $sessionusers[$message->user] = $message->timestamp; // Remember user
+ }
+ $timelast = $message->timestamp;
+ }
+
+/// Finish the page
+ print_footer($course);
+
+?>
/// This fragment is called by moodle_needs_upgrading() and /admin/index.php
/////////////////////////////////////////////////////////////////////////////////
-$module->version = 2003070600; // The (date) version of this module
+$module->version = 2003072102; // The (date) version of this module
$module->cron = 300; // How often should cron check this module (seconds)?
?>
"", "", true, update_module_button($cm->id, $course->id, $strchat),
navmenu($course, $cm));
+ if ($chat->studentlogs or isteacher($course->id)) {
+ echo "<p align=right><a href=\"report.php?id=$chat->id\">".
+ get_string("viewreport", "chat")."</a></p>";
+ }
+
/// Print the main part of the page
// Do the browser-detection etc later on.