Skip to content
Permalink
Browse files

Some new code related to the new reports - uploading for testing on

other server - still very early
  • Loading branch information...
moodler
moodler committed Jul 21, 2003
1 parent cea5796 commit 22a4491ae90069aedac8e1eccbadba093d3debb5
Showing with 161 additions and 13 deletions.
  1. +6 −1 lang/en/chat.php
  2. +10 −1 mod/chat/db/mysql.php
  3. +3 −1 mod/chat/db/mysql.sql
  4. +0 −5 mod/chat/insert.php
  5. +11 −0 mod/chat/lib.php
  6. +31 −4 mod/chat/mod.html
  7. +94 −0 mod/chat/report.php
  8. +1 −1 mod/chat/version.php
  9. +5 −0 mod/chat/view.php
@@ -8,14 +8,19 @@
$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['messagebeepseveryone'] = "\$a beeps everyone!";
$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";
?>
@@ -6,7 +6,16 @@ function chat_upgrade($oldversion) {
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;
@@ -7,7 +7,8 @@ CREATE TABLE `prefix_chat` (
`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';
@@ -52,4 +53,5 @@ CREATE TABLE `prefix_chat_users` (
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');

@@ -18,11 +18,6 @@
require_login($chat->course);
/// Delete old messages here
/// Clean up the message
$chat_message = clean_text($chat_message, FORMAT_MOODLE); // Strip bad tags
@@ -138,6 +138,16 @@ function chat_cron () {
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;
}
@@ -218,6 +228,7 @@ function chat_delete_old_users() {
}
}
function chat_browser_detect($HTTP_USER_AGENT) {
if(eregi("(opera) ([0-9]{1,2}.[0-9]{1,3}){0,1}", $HTTP_USER_AGENT, $match)
@@ -5,8 +5,11 @@
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">
@@ -39,8 +42,32 @@
<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>
@@ -0,0 +1,94 @@
<?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);
?>
@@ -5,7 +5,7 @@
/// 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)?
?>
@@ -52,6 +52,11 @@
"", "", 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.

0 comments on commit 22a4491

Please sign in to comment.
You can’t perform that action at this time.