From 22a4491ae90069aedac8e1eccbadba093d3debb5 Mon Sep 17 00:00:00 2001 From: moodler Date: Mon, 21 Jul 2003 03:16:19 +0000 Subject: [PATCH] Some new code related to the new reports - uploading for testing on other server - still very early --- lang/en/chat.php | 7 +++- mod/chat/db/mysql.php | 11 ++++- mod/chat/db/mysql.sql | 4 +- mod/chat/insert.php | 5 --- mod/chat/lib.php | 11 +++++ mod/chat/mod.html | 35 ++++++++++++++-- mod/chat/report.php | 94 +++++++++++++++++++++++++++++++++++++++++++ mod/chat/version.php | 2 +- mod/chat/view.php | 5 +++ 9 files changed, 161 insertions(+), 13 deletions(-) create mode 100644 mod/chat/report.php diff --git a/lang/en/chat.php b/lang/en/chat.php index 163fb0c6a8..76de69ad46 100644 --- a/lang/en/chat.php +++ b/lang/en/chat.php @@ -8,6 +8,7 @@ $string['modulenameplural'] = "Chats"; $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"; @@ -15,7 +16,11 @@ $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"; ?> diff --git a/mod/chat/db/mysql.php b/mod/chat/db/mysql.php index fe9b6d3265..79e9f94f62 100644 --- a/mod/chat/db/mysql.php +++ b/mod/chat/db/mysql.php @@ -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; diff --git a/mod/chat/db/mysql.sql b/mod/chat/db/mysql.sql index 1dd573b90b..44ee87b4ce 100644 --- a/mod/chat/db/mysql.sql +++ b/mod/chat/db/mysql.sql @@ -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'); diff --git a/mod/chat/insert.php b/mod/chat/insert.php index 780006f6e9..36e70a2306 100644 --- a/mod/chat/insert.php +++ b/mod/chat/insert.php @@ -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 diff --git a/mod/chat/lib.php b/mod/chat/lib.php index c00254473d..4f9d040cce 100644 --- a/mod/chat/lib.php +++ b/mod/chat/lib.php @@ -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) diff --git a/mod/chat/mod.html b/mod/chat/mod.html index 44782ae7b3..a225e1051f 100644 --- a/mod/chat/mod.html +++ b/mod/chat/mod.html @@ -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; } ?>
action="mod.php"> @@ -39,8 +42,32 @@

:

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, "", "", ""); + ?> + + + +

:

+ + studentlogs, "", "", ""); ?> diff --git a/mod/chat/report.php b/mod/chat/report.php new file mode 100644 index 0000000000..0e8311df0e --- /dev/null +++ b/mod/chat/report.php @@ -0,0 +1,94 @@ +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 = "id\">$course->shortname ->"; + } + + $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 id\">$strchats -> + id\">$chat->name -> $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); + +?> diff --git a/mod/chat/version.php b/mod/chat/version.php index 7582545cf2..0e3ad435c4 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 = 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)? ?> diff --git a/mod/chat/view.php b/mod/chat/view.php index 2e33ba6937..b826f2de80 100644 --- a/mod/chat/view.php +++ b/mod/chat/view.php @@ -52,6 +52,11 @@ "", "", true, update_module_button($cm->id, $course->id, $strchat), navmenu($course, $cm)); + if ($chat->studentlogs or isteacher($course->id)) { + echo "

id\">". + get_string("viewreport", "chat")."

"; + } + /// Print the main part of the page // Do the browser-detection etc later on. -- 2.39.5