]> git.mjollnir.org Git - moodle.git/commitdiff
Some new code related to the new reports - uploading for testing on
authormoodler <moodler>
Mon, 21 Jul 2003 03:16:19 +0000 (03:16 +0000)
committermoodler <moodler>
Mon, 21 Jul 2003 03:16:19 +0000 (03:16 +0000)
other server - still very early

lang/en/chat.php
mod/chat/db/mysql.php
mod/chat/db/mysql.sql
mod/chat/insert.php
mod/chat/lib.php
mod/chat/mod.html
mod/chat/report.php [new file with mode: 0644]
mod/chat/version.php
mod/chat/view.php

index 163fb0c6a80713db087db356dd6c0bdd8a026b17..76de69ad46c67cfe422fc4c655a5bba1cafa4b00 100644 (file)
@@ -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";
 
 ?>
index fe9b6d326585bb1803acbc5ac68228d8c03c8a31..79e9f94f6262878c11dc14c4af30e0e10d9dd948 100644 (file)
@@ -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;
index 1dd573b90bc520215d9910e4afada7c224600a05..44ee87b4cefd0101f12da7b2a95bef20ea47c0e1 100644 (file)
@@ -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');
 
index 780006f6e93c96cb8decefbd627056a4ebe78a7e..36e70a2306da453590b6a0c4c39430e4c92a04d5 100644 (file)
     
     require_login($chat->course);
     
-
-/// Delete old messages here
-
-
-
 /// Clean up the message
 
     $chat_message = clean_text($chat_message, FORMAT_MOODLE);  // Strip bad tags
index c00254473d76816af35cf8bacde40b23a6f60eac..4f9d040ccefee9728674cc2bb9e2053f35f909f8 100644 (file)
@@ -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)
index 44782ae7b328438959d98c6371eb36138e70ad90..a225e1051fee949e64a5cc57cbfe8b1628577352 100644 (file)
@@ -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">
        <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>
diff --git a/mod/chat/report.php b/mod/chat/report.php
new file mode 100644 (file)
index 0000000..0e8311d
--- /dev/null
@@ -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);
+
+?>
index 7582545cf2738332f1c5a6852c944cfd0fe7d7cf..0e3ad435c45f2ad7930fbf1359a3495b8bbb970b 100644 (file)
@@ -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)?
 
 ?>
index 2e33ba69371f008d0ebfddbd8a0d5109c83b40c0..b826f2de806c7f8bbb8fd9c08d0aed3410128eac 100644 (file)
                   "", "", 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.