From 600149be34bf366a7dad7f2e9d8f089f3422aefb Mon Sep 17 00:00:00 2001 From: martin Date: Fri, 31 May 2002 09:34:50 +0000 Subject: [PATCH] New logging format Improved "Recent Activity" on home page Better formatting. Many other small fixes. --- course/editweek.php | 4 +- course/email.php | 10 +-- course/lib.php | 153 ++++++++++++++++++++++++++++++++++++++++++-- course/login.php | 18 +++--- course/loginas.php | 4 +- course/new.php | 2 +- course/social.php | 25 +++++--- course/user.php | 44 ++++++++++--- course/view.php | 2 +- course/weeks.php | 73 ++++++++++++++------- 10 files changed, 266 insertions(+), 69 deletions(-) diff --git a/course/editweek.php b/course/editweek.php index 7684ef1f3f..4c3808d6d5 100644 --- a/course/editweek.php +++ b/course/editweek.php @@ -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; diff --git a/course/email.php b/course/email.php index c8f220c071..d729f2b4b2 100644 --- a/course/email.php +++ b/course/email.php @@ -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; diff --git a/course/lib.php b/course/lib.php index 6c2c3bbb76..4a2cc54804 100644 --- a/course/lib.php +++ b/course/lib.php @@ -57,6 +57,23 @@ function print_log_selector_form($course, $selecteduser=0, $selecteddate="today" echo ""; } +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 "

Displaying ".count($logs)." records

"; echo ""; 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 ""; echo ""; echo ""; echo ""; echo ""; + echo ""; echo ""; } echo "
".date("l", $log->time)."".date("j M Y, h:i A", $log->time)."$log->firstname $log->lastname"; - $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 "$log->info
"; @@ -128,4 +148,127 @@ function print_course($course) { print_simple_box_end(); } +function print_headline($text, $size=2) { + echo "$text
\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 "

Welcome to the course! Here you will find a list of what's new since your last login.

"; + 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 "
  • id&course=$course->id\">$user->firstname $user->lastname
  • "; + } + } + + // Next, have there been any changes to the course structure? + + if ($heading) { + echo "
    "; + $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 "
  • "; + switch ($log->action) { + case "add mod": + echo "Added a ".$info[0].": $modname"; + break; + case "update mod": + echo "Updated the ".$info[0].": wwwroot/course/$log->url\">$modname"; + break; + case "delete mod": + echo "Deleted a ".$info[0]; + break; + } + echo "
  • "; + } + } + } + + + // Now all we need to know are the new posts. + + if ($heading) { + echo "
    "; + $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 "
  • \"wwwroot/mod/discuss/$log->url\">$post->subject\" by $post->firstname $post->lastname
  • "; + } else { + echo "
  • \"wwwroot/mod/discuss/$log->url\">$post->subject\" by $post->firstname $post->lastname
  • "; + } + } + + } + } + + if (! $content) { + echo "Nothing new since your last login"; + } + +} + ?> diff --git a/course/login.php b/course/login.php index b0db697111..4bb527755d 100644 --- a/course/login.php +++ b/course/login.php @@ -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; diff --git a/course/loginas.php b/course/loginas.php index 97024a683c..5a0a3454e7 100644 --- a/course/loginas.php +++ b/course/loginas.php @@ -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; - ?> diff --git a/course/new.php b/course/new.php index 1e6b3cd02b..d76ecbd6e4 100644 --- a/course/new.php +++ b/course/new.php @@ -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", "wwwroot/course/view.php?id=$course->id\">$course->shortname -> What's new"); diff --git a/course/social.php b/course/social.php index 3eefc613e6..d0ca1474b6 100644 --- a/course/social.php +++ b/course/social.php @@ -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[] = "\"Reading\""; - } - if ($USER->editing) { - $readingdata[] = "id&week=0&add=reading\">Add reading..."; - $readingicon[] = " "; - } + foreach ($readings as $reading) { + $readingdata[] = $reading; + $readingicon[] = "\"Reading\""; + } + } + if ($USER->editing) { + $readingdata[] = "id&week=0&add=reading\">Add reading..."; + $readingicon[] = " "; } 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 "
    "; + print_recent_activity($course); + echo "
    "; + + // Print Admin links for teachers and admin. + if (isteacher($USER->id) || isadmin()) { print_simple_box("Admin", $align="CENTER", $width="100%", $color="$THEME->cellheading"); $adminicon[]="\"Edit\""; if ($USER->editing) { diff --git a/course/user.php b/course/user.php index 6029181567..08864183da 100644 --- a/course/user.php +++ b/course/user.php @@ -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", "id\">$course->shortname -> @@ -27,17 +27,41 @@ id&course=$course->id\">$user->firstname $user->lastname -> 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 "

    ".$mod->fullname."s

    "; - echo "
    "; - include($userfile); - echo "
    "; - echo "
    "; + 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 "

    Week $week->week

    "; + 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 "

    No modules

    "; + } } } + } else { + echo "

    Not implemented yet

    "; } print_footer($course); diff --git a/course/view.php b/course/view.php index 1a1d932aa7..c36ebecc4c 100644 --- a/course/view.php +++ b/course/view.php @@ -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") { diff --git a/course/weeks.php b/course/weeks.php index 5bd19dc920..c780522ff4 100644 --- a/course/weeks.php +++ b/course/weeks.php @@ -1,7 +1,8 @@ id) ) { $week->course = $course->id; // Create a default week. @@ -16,10 +17,19 @@ $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 ""; + echo "
    "; echo "
    "; - echo "\"\"
    "; // Layout the left column @@ -42,7 +52,8 @@ $moddata[]="id&course=$course->id\">Edit my info"; $modicon[]="\"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 @@ -61,20 +72,17 @@ $admindata[]="id\">Files..."; $adminicon[]="\"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 "
    "; - echo "
    "; - echo "

    \"\"
    "; - echo "Weekly Outline\n"; + print_simple_box("Weekly Outline", $align="CENTER", $width="100%", $color="$THEME->cellheading"); + echo "
    "; - echo ""; - echo "

    "; - // Now all the weekly modules $timenow = time(); $weekdate = $course->startdate; // this should be 0:00 Monday of that week @@ -83,9 +91,17 @@ echo ""; while ($weekdate < $course->enddate) { - echo ""; $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); @@ -97,6 +113,7 @@ $highlightcolor = $THEME->cellheading; } + echo ""; echo ""; @@ -142,9 +159,16 @@ } echo ""; - echo ""; + echo ""; echo ""; - echo ""; + echo ""; $week++; $weekdate = $nextweekdate; @@ -154,22 +178,23 @@ echo "
    "; echo "

    $week

    "; echo "
     "; + echo ""; + if (isset($USER->week)) { + echo "id&week=all\" TITLE=\"Show all weeks\">"; + } else { + echo "id&week=$week\" TITLE=\"Show only week $week\">"; + } + echo "
    \"\"
    "; - // Print What's New - - print_side_block("id\">What's New!", - "", "...since your last login"); - - // 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 "

    Latest News
    "; - 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 ""; forum_latest_topics($news->id, 5, "minimal", "DESC", false); echo ""; print_simple_box_end(); } + echo "
    "; + + // 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 "

    \n"; -- 2.39.5