Skip to content

Commit

Permalink
New logging format
Browse files Browse the repository at this point in the history
Improved "Recent Activity" on home page
Better formatting.
Many other small fixes.
  • Loading branch information
martin committed May 31, 2002
1 parent b50b67e commit 600149b
Show file tree
Hide file tree
Showing 10 changed files with 266 additions and 69 deletions.
4 changes: 2 additions & 2 deletions course/editweek.php
Expand Up @@ -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!");
Expand All @@ -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;
Expand Down
10 changes: 5 additions & 5 deletions course/email.php
Expand Up @@ -21,12 +21,12 @@

$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;
Expand Down
153 changes: 148 additions & 5 deletions course/lib.php
Expand Up @@ -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";
Expand All @@ -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;
Expand All @@ -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>";
Expand Down Expand Up @@ -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>";
}

}

?>
18 changes: 9 additions & 9 deletions course/login.php
Expand Up @@ -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;

Expand All @@ -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!");
Expand All @@ -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;

Expand Down
4 changes: 1 addition & 3 deletions course/loginas.php
Expand Up @@ -31,10 +31,8 @@

$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;

?>
2 changes: 1 addition & 1 deletion course/new.php
Expand Up @@ -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");
Expand Down
25 changes: 16 additions & 9 deletions course/social.php
Expand Up @@ -32,18 +32,25 @@
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) {
Expand Down
44 changes: 34 additions & 10 deletions course/user.php
Expand Up @@ -19,25 +19,49 @@
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/index.php?id=$course->id\">Participants</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);
Expand Down
2 changes: 1 addition & 1 deletion course/view.php
Expand Up @@ -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") {
Expand Down

0 comments on commit 600149b

Please sign in to comment.