]> git.mjollnir.org Git - moodle.git/commitdiff
New logging format
authormartin <martin>
Fri, 31 May 2002 09:34:50 +0000 (09:34 +0000)
committermartin <martin>
Fri, 31 May 2002 09:34:50 +0000 (09:34 +0000)
Improved "Recent Activity" on home page
Better formatting.
Many other small fixes.

course/editweek.php
course/email.php
course/lib.php
course/login.php
course/loginas.php
course/new.php
course/social.php
course/user.php
course/view.php
course/weeks.php

index 7684ef1f3f7c079bbeebff33ad9caa58052f3a4d..4c3808d6d508703bdb1c2cab348e4fb49ea6bfbf 100644 (file)
@@ -13,8 +13,6 @@
     }
 
     require_login($course->id);
-
-    add_to_log("Edit week", $course->id);
     
     if (!isteacher($course->id)) {
         error("Only teachers can edit this!");
@@ -30,6 +28,8 @@
         if (! set_field("course_weeks", "summary", $summary, "id", $week->id)) {
             error("Could not update the summary!");
         }
+
+        add_to_log($course->id, "course", "editweek", "editweek.php?id=$week->id", "$week->week");
         
         redirect("view.php?id=$course->id");
         exit;
index c8f220c071cb0f29790ab958940f228959e945ae..d729f2b4b26577b77359ffd84e4ef37c7a4bc176 100644 (file)
 
         $link = "$CFG->wwwroot/course/view.php?id=$course->id";
 
+        //XXXX The following function is now wrong - needs fixing
+        //if (! email_to_course($USER, $course, true, $subject, $message, "$link")) {
+        //    error("An error occurred while trying to send mail!");
+        //}
 
-        if (! email_to_course($USER, $course, true, $subject, $message, "$link")) {
-            error("An error occurred while trying to send mail!");
-        }
-
-        add_to_log("Sent mail to everyone", $course->id);
+        add_to_log($course->id, "course", "email", "email.php?id=$course->id", "");
         
         redirect("view.php?id=$course->id", "Email sent", 1);
         exit;
index 6c2c3bbb76bebdce14ff73a109127f59efbf3c4b..4a2cc548044c3affeb639263c2394e05446cd42b 100644 (file)
@@ -57,6 +57,23 @@ function print_log_selector_form($course, $selecteduser=0, $selecteddate="today"
     echo "</CENTER>";
 }
 
+function make_log_url($module, $url) {
+    switch ($module) {
+        case "course":
+        case "user":
+        case "file":
+        case "login":
+        case "lib":
+        case "admin":
+            return "/$module/$url";
+            break;
+        default:
+            return "/mod/$module/$url";
+            break;
+    }
+}
+
+
 function print_log($course, $user=0, $date=0, $order="ORDER BY l.time ASC") {
 
     $selector = "WHERE l.course='$course->id' AND l.user = u.id";
@@ -71,7 +88,7 @@ function print_log($course, $user=0, $date=0, $order="ORDER BY l.time ASC") {
     }
 
     if (!$logs = get_records_sql("SELECT l.*, u.firstname, u.lastname, u.picture 
-                                  FROM logs l, user u $selector $order")){
+                                  FROM log l, user u $selector $order")){
         notify("No logs found!");
         print_footer($course);
         exit;
@@ -83,16 +100,19 @@ function print_log($course, $user=0, $date=0, $order="ORDER BY l.time ASC") {
     echo "<P ALIGN=CENTER>Displaying ".count($logs)." records</P>";
     echo "<TABLE BORDER=0 ALIGN=center CELLPADDING=3 CELLSPACING=3>";
     foreach ($logs as $log) {
-        $count++;
-        
+
+        if ($ld = get_record_sql("SELECT * FROM log_display WHERE module='$log->module' AND action='$log->action'")) {
+            $log->info = get_field($ld->table, $ld->field, "id", $log->info);
+        }
+
         echo "<TR>";
         echo "<TD ALIGN=right><FONT SIZE=2>".date("l", $log->time)."</TD>";
         echo "<TD><FONT SIZE=2>".date("j M Y, h:i A", $log->time)."</TD>";
         echo "<TD><FONT SIZE=2><B>$log->firstname $log->lastname</B></TD>";
         echo "<TD><FONT SIZE=2>";
-        $log->message = addslashes($log->message);
-        link_to_popup_window("$log->url","popup","$log->message", 400, 600);
+        link_to_popup_window( make_log_url($log->module,$log->url), "fromloglive","$log->module $log->action", 400, 600);
         echo "</TD>";
+        echo "<TD><FONT SIZE=2>$log->info</TD>";
         echo "</TR>";
     }
     echo "</TABLE>";
@@ -128,4 +148,127 @@ function print_course($course) {
      print_simple_box_end();
 }
 
+function print_headline($text, $size=2) {
+    echo "<B><FONT SIZE=\"$size\">$text</FONT></B><BR>\n";
+}
+
+function print_recent_activity($course) {
+    // $course is an object
+    // This function trawls through the logs looking for 
+    // anything new since the user's last login
+
+    global $CFG, $USER;
+
+    if (! $USER->lastlogin ) {
+        echo "<P>Welcome to the course! Here you will find a list of what's new since your last login.</P>";
+        return;
+    }
+
+    if (! $logs = get_records_sql("SELECT * FROM log WHERE time > '$USER->lastlogin' AND course = '$course->id' ORDER BY time ASC")) {
+        return;
+    }
+
+
+    // Firstly, have there been any new enrolments?
+
+    $heading = false;
+    $content = false;
+    foreach ($logs as $log) {
+        if ($log->module == "course" and $log->action == "enrol") {
+            if (! $heading) {
+                print_headline("New users");
+                $heading = true;
+                $content = true;
+            }
+            $user = get_record("user", "id", $log->info);
+            echo "<LI><FONT SIZE=1><A HREF=\"../user/view.php?id=$user->id&course=$course->id\">$user->firstname $user->lastname</A></FONT></LI>";
+        }
+    }
+
+    // Next, have there been any changes to the course structure?
+
+    if ($heading) {
+        echo "<BR>";
+        $heading = false;
+    }
+    foreach ($logs as $log) {
+        if ($log->module == "course") {
+            if ($log->action == "add mod" or $log->action == "update mod" or $log->action == "delete mod") {
+                if (! $heading) {
+                    print_headline("Changes");
+                    $heading = true;
+                    $content = true;
+                }
+                $info = split(" ", $log->info);
+                $modname = get_field($info[0], "name", "id", $info[1]);
+            
+                if ($info[0] == "discuss") {
+                    $info[0] == "discussion";  // nasty hack, really.
+                }
+
+                echo "<LI><FONT SIZE=1>";
+                switch ($log->action) {
+                    case "add mod":
+                       echo "Added a ".$info[0].": $modname";
+                    break;
+                    case "update mod":
+                       echo "Updated the ".$info[0].": <A HREF=\"$CFG->wwwroot/course/$log->url\">$modname</A>";
+                    break;
+                    case "delete mod":
+                       echo "Deleted a ".$info[0];
+                    break;
+                }
+                echo "</FONT></LI>";
+            }
+        }
+    }
+
+
+    // Now all we need to know are the new posts.
+
+    if ($heading) {
+        echo "<BR>";
+        $heading = false;
+        $content = true;
+    }
+    foreach ($logs as $log) {
+        
+        if ($log->module == "discuss") {
+            $post = NULL;
+
+            if ($log->action == "add post") {
+                $post = get_record_sql("SELECT p.*, u.firstname, u.lastname, 
+                                               u.email, u.picture, u.id as userid
+                                        FROM discuss_posts p, user u 
+                                        WHERE p.id = '$log->info' AND p.user = u.id");
+
+            } else if ($log->action == "add") {
+                $post = get_record_sql("SELECT p.*, u.firstname, u.lastname, 
+                                               u.email, u.picture, u.id as userid
+                                        FROM discuss d, discuss_posts p, user u 
+                                        WHERE d.id = '$log->info' AND d.firstpost = p.id AND p.user = u.id");
+            }
+
+            if ($post) {
+                if (! $heading) {
+                    print_headline("Discussion Posts");
+                    $heading = true;
+                    $content = true;
+                }
+                if ($log->action == "add") {
+                    echo "<LI><FONT SIZE=1>\"<A HREF=\"$CFG->wwwroot/mod/discuss/$log->url\"><B>$post->subject</B></A>\" by $post->firstname $post->lastname</FONT></LI>";
+                } else {
+                    echo "<LI><FONT SIZE=1>\"<A HREF=\"$CFG->wwwroot/mod/discuss/$log->url\">$post->subject</A>\" by $post->firstname $post->lastname</FONT></LI>";
+                }
+            }
+
+        }
+    }
+
+    if (! $content) {
+        echo "<FONT SIZE=2>Nothing new since your last login</FONT>";
+    }
+
+}
+
 ?>
index b0db697111e43559f358b4bee80819e424519770..4bb527755dd74e10544c96aad4167b394dbf7c53 100644 (file)
@@ -8,15 +8,18 @@
     require_login();
     require_variable($id);
 
+    if (! $course = get_record("course", "id", $id) ) {
+        error("That's an invalid course id");
+    }
 
     if (match_referer() && isset($HTTP_POST_VARS)) {    // form submitted
 
-        $actual_password = get_field("course", "password", "id", $id);
-
-        if ($password == $actual_password) {
+        if ($password == $course->password) {
 
-            enrol_student_in_course($USER->id, $id);
-            add_to_log("Enrolled in course", $id);
+            if (! enrol_student_in_course($USER->id, $course->id)) {
+                error("An error occurred while trying to enrol you.");
+            }
+            add_to_log($course->id, "course", "enrol", "view.php?id=$course->id", "$USER->id");
 
             $USER->student["$id"] = true;
             
@@ -35,9 +38,6 @@
         }
     }
 
-    if (! $course = get_record("course", "id", $id) ) {
-        error("That's an invalid course id");
-    }
 
     if (! $site = get_record("course", "category", "0") ) {
         error("Could not find a site!");
@@ -48,7 +48,7 @@
             error("An error occurred while trying to enrol you.");
         }
 
-        add_to_log("Enrolled in course", $id);
+        add_to_log($course->id, "course", "enrol", "view.php?id=$course->id", "$USER->id");
 
         $USER->student["$id"] = true;
         
index 97024a683c6bda167557b33b1945277ac4daf1aa..5a0a3454e76a4a4b95c6af9435181f9e63a9b06b 100644 (file)
 
     $student_name = "$USER->firstname $USER->lastname";
     
-    add_to_log("$teacher_name logged in as $student_name", $course->id);
+    add_to_log($course->id, "course", "loginas", "loginas.php?id=$course->id&user=$user", "$teacher_name");
 
     notice("You are now logged in as $student_name", "$CFG->wwwroot/course/view.php?id=$course->id");
 
-    die;
-
 ?>
index 1e6b3cd02b9c80babbde1d0b435742c56e02a7d8..d76ecbd6e465f1d7fda88444a90e1354af574b2c 100644 (file)
@@ -14,7 +14,7 @@
 
     require_login($course->id);
 
-    add_to_log("View Whats New", $course->id);
+    add_to_log($course->id, "course", "view new", "new.php?id=$course->id", ""); 
 
     print_header("$course->shortname: What's new", "$course->fullname",
                  "<A HREF=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->shortname</A> -> What's new");
index 3eefc613e6675764d1f5dc04370344e529a9b188..d0ca1474b6365ec6b1cbf4fa62427cc7f60b98fa 100644 (file)
       print_simple_box("Readings", $align="CENTER", $width="100%", $color="$THEME->cellheading");
 
       if ($readings = list_all_readings($course->id, "timemodified ASC", 0, true)) {
-         foreach ($readings as $reading) {
-             $readingdata[] = $reading;
-             $readingicon[] = "<IMG SRC=\"../mod/reading/icon.gif\" HEIGHT=16 WIDTH=16 ALT=\"Reading\">";
-         }
-         if ($USER->editing) {
-             $readingdata[] = "<A HREF=\"mod.php?id=$course->id&week=0&add=reading\">Add reading...</A>";
-             $readingicon[] = "&nbsp;";
-         }
+          foreach ($readings as $reading) {
+              $readingdata[] = $reading;
+              $readingicon[] = "<IMG SRC=\"../mod/reading/icon.gif\" HEIGHT=16 WIDTH=16 ALT=\"Reading\">";
+          }
+      }
+      if ($USER->editing) {
+          $readingdata[] = "<A HREF=\"mod.php?id=$course->id&week=0&add=reading\">Add reading...</A>";
+          $readingicon[] = "&nbsp;";
       }
       print_side_block("", $readingdata, "", $readingicon);
 
-      if (isteacher($USER->id)) {
+      // Print all the recent activity
+      print_simple_box("Recent Activity", $align="CENTER", $width="100%", $color="$THEME->cellheading");
+      echo "<TABLE CELLPADDING=4 CELLSPACING=0><TR><TD>";
+      print_recent_activity($course);
+      echo "</TD></TR></TABLE>";
+
+      // Print Admin links for teachers and admin.
+      if (isteacher($USER->id) || isadmin()) {
           print_simple_box("Admin", $align="CENTER", $width="100%", $color="$THEME->cellheading");
           $adminicon[]="<IMG SRC=\"../pix/i/edit.gif\" HEIGHT=16 WIDTH=16 ALT=\"Edit\">";
           if ($USER->editing) {
index 6029181567096004c4881909e79cd054045619dc..08864183daf58b3e7ce39eace535b11f2b0e8e62 100644 (file)
@@ -19,7 +19,7 @@
         error("User ID is incorrect");
     }
 
-    add_to_log("View total report of $user->firstname $user->lastname", $course->id);
+    add_to_log($course->id, "course", "user record", "user.php?id=$course->id&user=$user->id", "$user->id"); 
 
     print_header("$course->shortname: Report", "$course->fullname",
                  "<A HREF=\"../course/view.php?id=$course->id\">$course->shortname</A> ->
                   <A HREF=\"../user/view.php?id=$user->id&course=$course->id\">$user->firstname $user->lastname</A> -> 
                   Full Report", "");
 
-    if ($mods = get_records_sql("SELECT * FROM modules ORDER BY fullname")) {
-        foreach ($mods as $mod) {
-            $userfile = "$CFG->dirroot/mod/$mod->name/user.php";
-            if (file_exists($userfile)) {
-                echo "<H2>".$mod->fullname."s</H2>";
-                echo "<BLOCKQUOTE>";
-                include($userfile);
-                echo "</BLOCKQUOTE>";
-                echo "<HR WIDTH=100%>";
+    if ( $rawmods = get_records_sql("SELECT cm.*, m.name as modname, m.fullname as modfullname
+                                   FROM modules m, course_modules cm
+                                   WHERE cm.course = '$course->id' 
+                                     AND cm.deleted = '0'
+                                     AND cm.module = m.id") ) {
+
+        foreach($rawmods as $mod) {    // Index the mods
+            $mods[$mod->id] = $mod;
+            $modtype[$mod->modname] = $mod->modfullname;
+        }
+    }
+
+
+    // Replace all the following with a better log-based method.
+    if ($course->format == 1) {
+        if ($weeks = get_records_sql("SELECT * FROM course_weeks WHERE course = '$course->id' ORDER BY week")) {
+            foreach ($weeks as $www) {
+                $week = (object)$www;
+                echo "<H2>Week $week->week</H2>";
+                if ($week->sequence) {
+                    $weekmods = explode(",", $week->sequence);
+                    foreach ($weekmods as $weekmod) {
+                        $mod = $mods[$weekmod];
+                        $instance = get_record("$mod->modname", "id", "$mod->instance");
+                        $userfile = "$CFG->dirroot/mod/$mod->name/user.php";
+                        include($userfile);
+                    }
+                    
+                } else {
+                    echo "<P>No modules</P>";
+                }
             }
         }
+    } else { 
+        echo "<P>Not implemented yet</P>";
     }
 
     print_footer($course);
index 1a1d932aa7e7a8ae243b8670414177e0327595d8..c36ebecc4c29663aaec5d8e419e8978194115f67 100644 (file)
@@ -12,7 +12,7 @@
         error("That's an invalid course id");
     }
 
-    add_to_log("View course: $course->shortname", $id);
+    add_to_log($course->id, "course", "view", "view.php?id=$course->id", "$course->id");
 
     if ( isteacher($course->id) ) {
         if ($edit == "on") {
index 5bd19dc9201f5e8f74b25b668db4d0975e15d224..c780522ff461fdafcf758cab9a525e5163bb8c26 100644 (file)
@@ -1,7 +1,8 @@
 <?PHP // $Id$
+      // Display the whole course as "weeks" made of of modules
+      // Included from "view.php"
 
-//  Display the whole course as "weeks" made of of modules
-//  Included from "view.php"
+    include("../mod/discuss/lib.php");
 
     if (! $rawweeks = get_records("course_weeks", "course", $course->id) ) {
         $week->course = $course->id;   // Create a default week.
         $weeks[$cw->week] = $cw;
     }
 
+    if (isset($week)) {
+        if ($week == "all") {
+            unset($USER->week);
+        } else {
+            $USER->week = $week;
+        }
+    }
+
+
+
     // Layout the whole page as three big columns.
-    echo "<TABLE BORDER=0 CELLPADDING=4>";
+    echo "<TABLE BORDER=0 CELLPADDING=3 CELLSPACING=0 WIDTH=100%>";
     echo "<TR VALIGN=top><TD VALIGN=top WIDTH=180>";
-    echo "<IMG ALT=\"\" SRC=\"../pix/spacer.gif\" WIDTH=180 HEIGHT=1><BR>";
     
     // Layout the left column
 
@@ -42,7 +52,8 @@
     $moddata[]="<A HREF=\"../user/view.php?id=$USER->id&course=$course->id\">Edit my info</A>";
     $modicon[]="<IMG SRC=\"../user/user.gif\" HEIGHT=16 WIDTH=16 ALT=\"Me\">";
 
-    print_side_block("Activities", $moddata, "", $modicon);
+    print_simple_box("Activities", $align="CENTER", $width="100%", $color="$THEME->cellheading");
+    print_side_block("", $moddata, "", $modicon);
 
     // Admin links and controls
 
         $admindata[]="<A HREF=\"../files/index.php?id=$course->id\">Files...</A>";
         $adminicon[]="<IMG SRC=\"../files/pix/files.gif\" HEIGHT=16 WIDTH=16 ALT=\"Files\">";
 
-        print_side_block("Administration", $admindata, "", $adminicon);
+        print_simple_box("Administration", $align="CENTER", $width="100%", $color="$THEME->cellheading");
+        print_side_block("", $admindata, "", $adminicon);
     }
 
 
     // Start main column
     echo "</TD><TD WIDTH=\"*\">";
 
-    echo "<TABLE WIDTH=100% CELLSPACING=0 CELLPADDING=0><TR><TD>";
-    echo "<P><IMG ALT=\"\" SRC=\"../pix/spacer.gif\" WIDTH=100% HEIGHT=3><BR>";
-    echo "<B><FONT SIZE=2>Weekly Outline</FONT></B>\n";
+    print_simple_box("Weekly Outline", $align="CENTER", $width="100%", $color="$THEME->cellheading");
+    echo "<IMG SRC=\"../pix/spacer.gif\" HEIGHT=6 WIDTH=1><BR>";
     
-    echo "</FONT>";
-    echo "</TD></TR></TABLE>";
-
     // Now all the weekly modules
     $timenow = time();
     $weekdate = $course->startdate;    // this should be 0:00 Monday of that week
 
     echo "<TABLE BORDER=0 CELLPADDING=8 CELLSPACING=0 WIDTH=100%>";
     while ($weekdate < $course->enddate) {
-        echo "<TR>";
 
         $nextweekdate = $weekdate + ($weekofseconds);
+
+        if (isset($USER->week)) {         // Just display a single week
+            if ($USER->week != $week) { 
+                $week++;
+                $weekdate = $nextweekdate;
+                continue;
+            }
+        }
+
         $thisweek = (($weekdate <= $timenow) && ($timenow < $nextweekdate));
 
         $weekday = date("j F", $weekdate);
             $highlightcolor = $THEME->cellheading;
         }
 
+        echo "<TR>";
         echo "<TD NOWRAP BGCOLOR=\"$highlightcolor\" VALIGN=top>";
         echo "<P ALIGN=CENTER><FONT SIZE=3><B>$week</B></FONT></P>";
         echo "</TD>";
         }
 
         echo "</TD>";
-        echo "<TD NOWRAP BGCOLOR=\"$highlightcolor\" VALIGN=top>&nbsp;</TD>";
+        echo "<TD NOWRAP BGCOLOR=\"$highlightcolor\" VALIGN=top ALIGN=CENTER>";
+        echo "<FONT SIZE=1>";
+        if (isset($USER->week)) {
+            echo "<A HREF=\"view.php?id=$course->id&week=all\" TITLE=\"Show all weeks\"><IMG SRC=../pix/i/allweeks.gif BORDER=0></A></FONT>";
+        } else {
+            echo "<A HREF=\"view.php?id=$course->id&week=$week\" TITLE=\"Show only week $week\"><IMG SRC=../pix/i/oneweek.gif BORDER=0></A></FONT>";
+        }
+        echo "</TD>";
         echo "</TR>";
-        echo "<TR><TD COLSPAN=3><IMG ALT=\"\" SRC=\"../pix/spacer.gif\" WIDTH=1 HEIGHT=1></TD></TR>";
+        echo "<TR><TD COLSPAN=3><IMG SRC=\"../pix/spacer.gif\" WIDTH=1 HEIGHT=1></TD></TR>";
 
         $week++;
         $weekdate = $nextweekdate;
 
     echo "</TD><TD WIDTH=180>";
 
-    // Print What's New
-
-    print_side_block("<A HREF=\"new.php?id=$course->id\">What's New!</A>", 
-                     "", "<FONT SIZE=1>...since your last login</FONT>");
-
-    // Then, print all the news items.
+    // Print all the news items.
 
-    include("../mod/discuss/lib.php");
     if ($news = get_course_news_forum($course->id)) {
-        echo "<P><B><FONT SIZE=2>Latest News</FONT></B><BR>";
-        print_simple_box_start("CENTER", "100%", "#FFFFFF", 3);
+        print_simple_box("Latest News", $align="CENTER", $width="100%", $color="$THEME->cellheading");
+        print_simple_box_start("CENTER", "100%", "#FFFFFF", 3, 0);
         echo "<FONT SIZE=1>";
         forum_latest_topics($news->id, 5, "minimal", "DESC", false);
         echo "</FONT>";
         print_simple_box_end();
     }
+    echo "<BR>";
+    
+    // Print all the recent activity
+    print_simple_box("Recent Activity", $align="CENTER", $width="100%", $color="$THEME->cellheading");
+    print_simple_box_start("CENTER", "100%", "#FFFFFF", 3, 0);
+    print_recent_activity($course);
+    print_simple_box_end();
 
     echo "</TD></TR></TABLE>\n";