Logs now include a field called modid which contains the coursemodule id.
This makes it now possible to
- see complete logs per-activity
- do backup/restore of logs
The upgrade process will currently try to scan all the old logs and
rebuild this field based on available data (especially forums).
STILL TO DO: alter all the non-forum modules to send the coursemodule id
function print_log_selector_form($course, $selecteduser=0, $selecteddate="today",
- $mod="", $modpage="", $modid=0) {
+ $mod="", $modid=0, $modaction="") {
global $USER, $CFG;
if (!$mod->visible) {
$mod->name = "(".$mod->name.")";
}
- $activities["$mod->mod/view.php?id=$mod->cm"] = $mod->name;
+ $activities["$mod->cm"] = $mod->name;
if ($mod->cm == $modid) {
- $selectedactivity = "$mod->mod/view.php?id=$mod->cm";
+ $selectedactivity = "$mod->cm";
}
}
}
}
choose_from_menu ($users, "user", $selecteduser, get_string("allparticipants") );
choose_from_menu ($dates, "date", $selecteddate, get_string("alldays"));
- choose_from_menu ($activities, "url", $selectedactivity, get_string("allactivities"), "", "");
+ choose_from_menu ($activities, "modid", $selectedactivity, get_string("allactivities"), "", "");
echo "<input type=submit value=\"".get_string("showtheselogs")."\">";
echo "</form>";
echo "</center>";
function print_log($course, $user=0, $date=0, $order="l.time ASC", $page=0, $perpage=100,
- $url="", $mod="", $modpage="", $modid=0) {
+ $url="", $mod="", $modid=0, $modaction="") {
// It is assumed that $date is the GMT time of midnight for that day,
// and so the next 86400 seconds worth of logs are printed.
$selector .= " AND l.module = '$mod'";
}
- if ($modpage and $modid) {
- $LIKE = $CFG->dbtype == "mysql" ? "LIKE" : "ILIKE";
- $selector .= " AND l.url $LIKE '%id=$modid%'";
+ if ($modid) {
+ $selector .= " AND l.cmid = '$modid'";
+ }
+
+ if ($modaction) {
+ $selector .= " AND l.action = '$modaction'";
}
if ($user) {
require_variable($id); // Course ID
optional_variable($user, 0); // User to display
optional_variable($date, 0); // Date to display
- optional_variable($url, ""); // eg resource/view.php?id=66
+ optional_variable($modid, ""); // course_module->id
+ optional_variable($modaction, ""); // an action as recorded in the logs
optional_variable($page, "0"); // which page to show
optional_variable($perpage, "100"); // how many per page
$dateinfo = userdate($date, get_string("strftimedaydate"));
}
- if ($url) { // parse into parts: resource/view.php?id=66
- $urlraw = urldecode($url);
- $urlparts = split("/", $urlraw);
- if ($urlparts[0] != "section" and $urlparts[0] != "") {
- $modname = $urlparts[0];
- $modparts = split('.php\?id=', $urlparts[1]);
- if (count($modparts) == 2) {
- if (record_exists('course_modules', 'id', $modparts[1], 'course', $course->id)) {
- $modpage = $modparts[0];
- $modid = $modparts[1];
- }
- }
- }
- }
-
if ($course->category) {
print_header("$course->shortname: $strlogs", "$course->fullname",
"<a href=\"view.php?id=$course->id\">$course->shortname</a> ->
print_heading("$course->fullname: $userinfo, $dateinfo (".usertimezone().")");
- print_log_selector_form($course, $user, $date, $modname, $modpage, $modid);
+ print_log_selector_form($course, $user, $date, $modname, $modid, $modaction);
print_log($course, $user, $date, "l.time DESC", $page, $perpage,
- "log.php?id=$course->id&chooselog=1&user=$user&date=$date&url=$url",
- $modname, $modpage, $modid);
+ "log.php?id=$course->id&chooselog=1&user=$user&date=$date&modid=$modid&modaction=$modaction",
+ $modname, $modid, $modaction);
} else {
if ($course->category) {
* than web server hits, and provide a way to easily reconstruct what
* any particular student has been doing.
*
-* @param int $course the course id
-* @param string $module the module name - e.g. forum, journal, resource, course, user etc
-* @param string $action view, edit, post (often but not always the same as the file.php)
-* @param string $url the file and parameters used to see the results of the action
-* @param string $info additional description information
-* @param string $user optional, if log regards $user other than $USER
+* @param int $course the course id
+* @param string $module the module name - e.g. forum, journal, resource, course, user etc
+* @param string $action view, edit, post (often but not always the same as the file.php)
+* @param string $url the file and parameters used to see the results of the action
+* @param string $info additional description information
+* @param string $cm the course_module->id if there is one
+* @param string $user if log regards $user other than $USER
*/
-function add_to_log($courseid, $module, $action, $url="", $info="", $user="") {
+function add_to_log($courseid, $module, $action, $url="", $info="", $cm=0, $user=0) {
global $db, $CFG, $USER, $REMOTE_ADDR;
$timenow = time();
$info = addslashes($info);
- $result = $db->Execute("INSERT INTO {$CFG->prefix}log (time,
- userid,
- course,
- ip,
- module,
- action,
- url,
- info)
- VALUES ('$timenow',
- '$userid',
- '$courseid',
- '$REMOTE_ADDR',
- '$module',
- '$action',
- '$url',
- '$info')");
+ $result = $db->Execute("INSERT INTO {$CFG->prefix}log (time, userid, course, ip, module, cmid, action, url, info)
+ VALUES ('$timenow', '$userid', '$courseid', '$REMOTE_ADDR', '$module', '$cm', '$action', '$url', '$info')");
if (!$result and ($CFG->debug > 7)) {
echo "<P>Error: Could not insert a new entry to the Moodle log</P>"; // Don't throw an error
table_column("config", "value", "value", "text", "", "", "");
}
+ if ($oldversion < 2004013101) {
+ table_column("log", "", "cmid", "integer", "10", "unsigned", "0", "", "module");
+
+ /// try and extract as many cmids as possible from the existing logs
+
+ if ($coursemodules = get_records_sql("SELECT cm.*, m.name
+ FROM {$CFG->prefix}course_modules cm,
+ {$CFG->prefix}modules m
+ WHERE cm.module = m.id")) {
+ foreach ($coursemodules as $cm) {
+ execute_sql("UPDATE {$CFG->prefix}log SET cmid = '$cm->id'
+ WHERE module = '$cm->name' AND url LIKE 'view.php?id=$cm->id%'");
+ if ($cm->name == "forum") {
+ execute_sql("UPDATE {$CFG->prefix}log SET cmid = '$cm->id'
+ WHERE module = 'forum' AND url LIKE '%?f=$cm->instance%'");
+ if ($discussions = get_records("forum_discussions", "forum", $cm->instance)) {
+ foreach ($discussions as $discussion) {
+ execute_sql("UPDATE {$CFG->prefix}log SET cmid = '$cm->id'
+ WHERE module = 'forum' AND url LIKE '%?d=$discussion->id%'");
+ }
+ }
+ }
+ }
+ }
+ }
+
return $result;
}
`ip` varchar(15) NOT NULL default '',
`course` int(10) unsigned NOT NULL default '0',
`module` varchar(10) NOT NULL default '',
+ `cmid` int(10) unsigned NOT NULL default '0',
`action` varchar(15) NOT NULL default '',
`url` varchar(100) NOT NULL default '',
`info` varchar(255) NOT NULL default '',
if ($oldversion < 2004012900) {
table_column("config", "value", "value", "text", "", "", "");
}
+
+ if ($oldversion < 2004013101) {
+ table_column("log", "", "cmid", "integer", "10", "unsigned", "0", "", "module");
+
+ /// try and extract as many cmids as possible from the existing logs
+
+ if ($coursemodules = get_records_sql("SELECT cm.*, m.name
+ FROM {$CFG->prefix}course_modules cm,
+ {$CFG->prefix}modules m
+ WHERE cm.module = m.id")) {
+ foreach ($coursemodules as $cm) {
+ execute_sql("UPDATE {$CFG->prefix}log SET cmid = '$cm->id'
+ WHERE module = '$cm->name' AND url ILIKE 'view.php?id=$cm->id%'");
+ if ($cm->name == "forum") {
+ execute_sql("UPDATE {$CFG->prefix}log SET cmid = '$cm->id'
+ WHERE module = 'forum' AND url ILIKE '%?f=$cm->instance%'");
+ if ($discussions = get_records("forum_discussions", "forum", $cm->instance)) {
+ foreach ($discussions as $discussion) {
+ execute_sql("UPDATE {$CFG->prefix}log SET cmid = '$cm->id'
+ WHERE module = 'forum' AND url ILIKE '%?d=$discussion->id%'");
+ }
+ }
+ }
+ }
+ }
+ }
return $result;
}
ip varchar(15) NOT NULL default '',
course integer NOT NULL default '0',
module varchar(20) NOT NULL default '',
+ cmid integer NOT NULL default '0',
action varchar(20) NOT NULL default '',
url varchar(100) NOT NULL default '',
info varchar(255) NOT NULL default ''
$previousmod = $mod;
}
}
- if ($selected and $isteacher) {
- $logslink = "<td><a href=\"$CFG->wwwroot/course/log.php?chooselog=1&user=0&date=0&id=$course->id&url=".
- urlencode($selected).
- "\"><img border=\"0\" height=\"16\" width=\"16\" src=\"$CFG->pixpath/i/log.gif\"></a></td>";
+ if ($selectmod and $isteacher) {
+ $logslink = "<td><a href=".
+ "\"$CFG->wwwroot/course/log.php?chooselog=1&user=0&date=0&id=$course->id&modid=$selectmod->cm\">".
+ "<img border=\"0\" height=\"16\" width=\"16\" src=\"$CFG->pixpath/i/log.gif\"></a></td>";
}
if ($backmod) {
}
set_field("forum_discussions", "forum", $forum->id, "id", $discussion->id);
$discussion->forum = $forum->id;
- add_to_log($course->id, "forum", "move discussion", "discuss.php?d=$discussion->id", "$discussion->id");
+ if ($cm = get_coursemodule_from_instance("forum", $forum->id, $course->id)) {
+ add_to_log($course->id, "forum", "move discussion", "discuss.php?d=$discussion->id", "$discussion->id",
+ $cm->id);
+ } else {
+ add_to_log($course->id, "forum", "move discussion", "discuss.php?d=$discussion->id", "$discussion->id");
+ }
$discussionmoved = true;
} else {
error("You can't move to that forum - it doesn't exist!");
}
}
- if (!$cm = get_coursemodule_from_instance("forum", $forum->id, $course->id)) {
- //notify("Bad coursemodule for this discussion"); // Only affects navmenu
- }
-
$logparameters = "d=$discussion->id";
if ($parent) {
$logparameters .= "&parent=$parent";
}
- add_to_log($course->id, "forum", "view discussion", "discuss.php?$logparameters", "$discussion->id");
+
+ if ($cm = get_coursemodule_from_instance("forum", $forum->id, $course->id)) {
+ add_to_log($course->id, "forum", "view discussion", "discuss.php?$logparameters", "$discussion->id", $cm->id);
+ } else {
+ add_to_log($course->id, "forum", "view discussion", "discuss.php?$logparameters", "$discussion->id");
+ }
unset($SESSION->fromdiscussion);
error("Could not add the discussion for this forum");
}
}
- add_to_log($forum->course, "forum", "add", "index.php?f=$forum->id", "$forum->id");
return $forum->id;
}
}
}
- if (update_record("forum", $forum)) {
- add_to_log($forum->course, "forum", "update", "index.php?f=$forum->id", "$forum->id");
- return true;
- } else {
- return false;
- }
+ return update_record("forum", $forum);
}
continue; // Be safe and don't send it to anyone
}
}
- }
+ } else {
+ $cm->id = 0;
+ }
if ($users = forum_subscribed_users($course, $forum)) {
if (! email_to_user($userto, $userfrom, $postsubject, $posttext, $posthtml)) {
echo "Error: mod/forum/cron.php: Could not send out mail for id $post->id to user $userto->id ($userto->email) .. not trying again.\n";
- add_to_log($course->id, 'forum', 'mail error', "discuss.php?d=$discussion->id#$post->id", substr($post->subject,0,15), $userto->id);
+ add_to_log($course->id, 'forum', 'mail error', "discuss.php?d=$discussion->id#$post->id", substr($post->subject,0,15), $cm->id, $userto->id);
$errorcount++;
} else {
$mailcount++;
$post->attachment = $_FILES["attachment"];
+ if (!$cm = get_coursemodule_from_instance("forum", $post->forum, $post->course)) { // For the logs
+ $cm->id = 0;
+ }
+
if (!$post->subject or !$post->message) {
$post->error = get_string("emptymessage", "forum");
} else if ($post->edit) { // Updating a post
$post->id = $post->edit;
if (forum_update_post($post)) {
- add_to_log($post->course, "forum", "update post", "discuss.php?d=$post->discussion&parent=$post->id", "$post->id");
+
+ add_to_log($post->course, "forum", "update post",
+ "discuss.php?d=$post->discussion&parent=$post->id", "$post->id", $cm->id);
+
$message = get_string("postupdated", "forum");
$timemessage = 1;
} else if ($post->discussion) { // Adding a new post to an existing discussion
if ($post->id = forum_add_new_post($post)) {
- add_to_log($post->course, "forum", "add post", "discuss.php?d=$post->discussion&parent=$post->id", "$post->id");
+
+ add_to_log($post->course, "forum", "add post",
+ "discuss.php?d=$post->discussion&parent=$post->id", "$post->id", $cm->id);
+
$message = get_string("postadded", "forum", format_time($CFG->maxeditingtime));
$timemessage = 2;
$discussion->name = $post->subject;
$discussion->intro = $post->message;
if ($discussion->id = forum_add_discussion($discussion)) {
- add_to_log($post->course, "forum", "add discussion", "discuss.php?d=$discussion->id", "$discussion->id");
+
+ add_to_log($post->course, "forum", "add discussion",
+ "discuss.php?d=$discussion->id", "$discussion->id", $cm->id);
+
$message = get_string("postadded", "forum", format_time($CFG->maxeditingtime));
$timemessage = 2;
forum_go_back_to("discuss.php?id=$post->discussion"));
} else {
+ if (!$cm = get_coursemodule_from_instance("forum", $forum->id, $forum->course)) { // For the logs
+ $cm->id = 0;
+ }
if (! $post->parent) { // post is a discussion topic as well, so delete discussion
if ($forum->type == "single") {
notice("Sorry, but you are not allowed to delete that discussion!",
}
forum_delete_discussion($discussion);
- add_to_log($discussion->course, "forum", "delete discussion", "view.php?id=$discussion->forum", "$post->id");
+ add_to_log($discussion->course, "forum", "delete discussion",
+ "view.php?id=$discussion->forum", "$post->id", $cm->id);
+
redirect("view.php?f=$discussion->forum",
get_string("deleteddiscussion", "forum"), 1);
} else if (forum_delete_post($post)) {
- add_to_log($discussion->course, "forum", "delete post", "discuss.php?d=$post->discussion", "$post->id");
+ add_to_log($discussion->course, "forum", "delete post",
+ "discuss.php?d=$post->discussion", "$post->id", $cm->id);
+
redirect(forum_go_back_to("discuss.php?d=$post->discussion"),
get_string("deletedpost", "forum"), 1);
} else {
error("Sorry, but you must be a group member to subscribe.");
}
}
+ } else {
+ $cm->id = NULL;
}
$returnto = forum_go_back_to("index.php?id=$course->id");
if ( forum_is_subscribed($user->id, $forum->id) ) {
if (forum_unsubscribe($user->id, $forum->id) ) {
- add_to_log($course->id, "forum", "unsubscribe", "view.php?f=$forum->id", "$forum->id");
+ add_to_log($course->id, "forum", "unsubscribe", "view.php?f=$forum->id", $forum->id, $cm->id);
redirect($returnto, get_string("nownotsubscribed", "forum", $info), 1);
} else {
error("Could not unsubscribe you from that forum", $_SERVER["HTTP_REFERER"]);
} else { // subscribe
if (forum_subscribe($user->id, $forum->id) ) {
- add_to_log($course->id, "forum", "subscribe", "view.php?f=$forum->id", "$forum->id");
+ add_to_log($course->id, "forum", "subscribe", "view.php?f=$forum->id", $forum->id, $cm->id);
redirect($returnto, get_string("nowsubscribed", "forum", $info), 1);
} else {
error("Could not subscribe you to that forum", $_SERVER["HTTP_REFERER"]);
error("Could not find this course!");
}
+ if (! $cm = get_coursemodule_from_instance("forum", $forum->id, $course->id)) {
+ $cm->id = 0;
+ }
+
require_login($course->id);
if (!isteacher($course->id)) {
unset($SESSION->fromdiscussion);
- add_to_log($course->id, "forum", "view subscribers", "subscribers.php?id=$forum->id", "");
+ add_to_log($course->id, "forum", "view subscribers", "subscribers.php?id=$forum->id", "", $cm->id);
$strsubscribers = get_string("subscribers", "forum");
$strforums = get_string("forums", "forum");
if ($course->category) {
- $navigation = "<A HREF=\"../../course/view.php?id=$course->id\">$course->shortname</A> ->
- <A HREF=\"index.php?id=$course->id\">$strforums</A> ->
- <A HREF=\"view.php?f=$forum->id\">$forum->name</A> -> $strsubscribers";
+ $navigation = "<a href=\"../../course/view.php?id=$course->id\">$course->shortname</a> ->
+ <a href=\"index.php?id=$course->id\">$strforums</a> ->
+ <a href=\"view.php?f=$forum->id\">$forum->name</a> -> $strsubscribers";
} else {
- $navigation = "<A HREF=\"index.php?id=$course->id\">$strforums</A> ->
- <A HREF=\"view.php?f=$forum->id\">$forum->name</A> -> $strsubscribers";
+ $navigation = "<a href=\"index.php?id=$course->id\">$strforums</a> ->
+ <a href=\"view.php?f=$forum->id\">$forum->name</a> -> $strsubscribers";
}
print_header("$course->shortname: $strsubscribers", "$course->fullname", "$navigation");
} else {
print_heading(get_string("subscribersto","forum", "'$forum->name'"));
- echo "<TABLE ALIGN=CENTER cellpadding=5 cellspacing=5>";
+ echo '<table align="center" cellpadding="5" cellspacing="5">';
foreach ($users as $user) {
- echo "<TR><TD>";
+ echo "<tr><td>";
print_user_picture($user->id, $course->id, $user->picture);
- echo "</TD><TD BGCOLOR=\"$THEME->cellcontent\">";
+ echo "</td><td bgcolor=\"$THEME->cellcontent\">";
echo "$user->firstname $user->lastname";
- echo "</TD><TD BGCOLOR=\"$THEME->cellcontent\">";
+ echo "</td><td bgcolor=\"$THEME->cellcontent\">";
echo "$user->email";
- echo "</TD><TD>";
- echo "<FONT SIZE=1><A HREF=\"subscribe.php?id=$forum->id&user=$user->id\">unsubscribe</A></FONT>";
- echo "</TD></TR>";
+ echo "</td><td>";
+ echo "<font size=1><a href=\"subscribe.php?id=$forum->id&user=$user->id\">unsubscribe</a></font>";
+ echo "</td></tr>";
}
- echo "</TABLE>";
+ echo "</table>";
}
print_footer($course);
// This fragment is called by /admin/index.php
////////////////////////////////////////////////////////////////////////////////
-$module->version = 2004013000;
-$module->requires = 2004013000; // Requires this Moodle version
+$module->version = 2004013100;
+$module->requires = 2004013101; // Requires this Moodle version
$module->cron = 60;
?>
if ($cm = get_coursemodule_from_instance("forum", $forum->id, $course->id)) {
$buttontext = update_module_button($cm->id, $course->id, $strforum);
} else {
+ $cm->id = NULL;
$buttontext = "";
}
}
if ($cm) {
- add_to_log($course->id, "forum", "view forum", "view.php?id=$cm->id", "$forum->id");
+ add_to_log($course->id, "forum", "view forum", "view.php?id=$cm->id", "$forum->id", $cm->id);
} else {
add_to_log($course->id, "forum", "view forum", "view.php?f=$forum->id", "$forum->id");
}
// database to determine whether upgrades should
// be performed (see lib/db/*.php)
-$version = 2004013100; // The current version is a date (YYYYMMDDXX)
+$version = 2004013101; // The current version is a date (YYYYMMDDXX)
$release = "1.2 development"; // User-friendly version number