From 95d1d0373b9ad95da517722580d3dd87df74e04e Mon Sep 17 00:00:00 2001 From: Frederic Massart Date: Mon, 5 Nov 2012 14:31:37 +0800 Subject: [PATCH] MDL-34435 reports: Log category actions --- course/category.php | 2 ++ course/editcategory.php | 3 +++ course/index.php | 1 + course/lib.php | 15 +++++++++++---- lib/db/log.php | 8 ++++++++ version.php | 2 +- 6 files changed, 26 insertions(+), 5 deletions(-) diff --git a/course/category.php b/course/category.php index 37138b5281a..71ea312e7b7 100644 --- a/course/category.php +++ b/course/category.php @@ -144,6 +144,7 @@ if ($editingon && $sesskeyprovided) { require_capability('moodle/course:visibility', $coursecontext); // Set the visibility of the course. we set the old flag when user manually changes visibility of course. $DB->update_record('course', array('id' => $course->id, 'visible' => $visible, 'visibleold' => $visible, 'timemodified' => time())); + add_to_log($course->id, "course", ($visible ? 'show' : 'hide'), "edit.php?id=$course->id", $course->id); } } @@ -172,6 +173,7 @@ if ($editingon && $sesskeyprovided) { } $DB->set_field('course', 'sortorder', $swapcourse->sortorder, array('id' => $movecourse->id)); $DB->set_field('course', 'sortorder', $movecourse->sortorder, array('id' => $swapcourse->id)); + add_to_log($movecourse->id, "course", "move", "edit.php?id=$movecourse->id", $movecourse->id); } } diff --git a/course/editcategory.php b/course/editcategory.php index f6d47e83864..fab0f52bde6 100644 --- a/course/editcategory.php +++ b/course/editcategory.php @@ -102,6 +102,7 @@ if ($mform->is_cancelled()) { $newcategory->theme = $data->theme; } + $logaction = 'update'; if ($id) { // Update an existing category. $newcategory->id = $category->id; @@ -119,10 +120,12 @@ if ($mform->is_cancelled()) { $category = create_course_category($newcategory); $newcategory->id = $category->id; $categorycontext = $category->context; + $logaction = 'add'; } $newcategory = file_postupdate_standard_editor($newcategory, 'description', $editoroptions, $categorycontext, 'coursecat', 'description', 0); $DB->update_record('course_categories', $newcategory); + add_to_log(SITEID, "category", $logaction, "editcategory.php?id=$newcategory->id", $newcategory->id); fix_course_sortorder(); redirect('category.php?id='.$newcategory->id.'&categoryedit=on'); diff --git a/course/index.php b/course/index.php index a1a5e569957..1847111fa28 100644 --- a/course/index.php +++ b/course/index.php @@ -232,6 +232,7 @@ if ((!empty($moveup) or !empty($movedown)) and confirm_sesskey()) { if ($swapcategory and $movecategory) { $DB->set_field('course_categories', 'sortorder', $swapcategory->sortorder, array('id'=>$movecategory->id)); $DB->set_field('course_categories', 'sortorder', $movecategory->sortorder, array('id'=>$swapcategory->id)); + add_to_log(SITEID, "category", "move", "editcategory.php?id=$movecategory->id", $movecategory->id); } // finally reorder courses diff --git a/course/lib.php b/course/lib.php index a58b86ad3c9..c9e6c9e531b 100644 --- a/course/lib.php +++ b/course/lib.php @@ -68,6 +68,7 @@ function make_log_url($module, $url) { case 'lib': case 'admin': case 'calendar': + case 'category': case 'mnet course': if (strpos($url, '../') === 0) { $url = ltrim($url, '.'); @@ -3472,6 +3473,7 @@ function category_delete_full($category, $showfeedback=true) { // finally delete the category and it's context $DB->delete_records('course_categories', array('id'=>$category->id)); delete_context(CONTEXT_COURSECAT, $category->id); + add_to_log(SITEID, "category", "delete", "index.php", "$category->name (ID $category->id)"); events_trigger('course_category_deleted', $category); @@ -3527,6 +3529,7 @@ function category_delete_move($category, $newparentid, $showfeedback=true) { // finally delete the category and it's context $DB->delete_records('course_categories', array('id'=>$category->id)); delete_context(CONTEXT_COURSECAT, $category->id); + add_to_log(SITEID, "category", "delete", "index.php", "$category->name (ID $category->id)"); events_trigger('course_category_deleted', $category); @@ -3573,6 +3576,7 @@ function move_courses($courseids, $categoryid) { } $DB->update_record('course', $course); + add_to_log($course->id, "course", "move", "edit.php?id=$course->id", $course->id); $context = context_course::instance($course->id); context_moved($context, $newparent); @@ -3605,6 +3609,7 @@ function course_category_hide($category) { $DB->set_field('course', 'visible', 0, array('category' => $cat->id)); } } + add_to_log(SITEID, "category", "hide", "editcategory.php?id=$category->id", $category->id); } /** @@ -3628,6 +3633,7 @@ function course_category_show($category) { $DB->execute("UPDATE {course} SET visible = visibleold WHERE category = ?", array($cat->id)); } } + add_to_log(SITEID, "category", "show", "editcategory.php?id=$category->id", $category->id); } /** @@ -3641,12 +3647,10 @@ function move_category($category, $newparentcat) { $hidecat = false; if (empty($newparentcat->id)) { - $DB->set_field('course_categories', 'parent', 0, array('id'=>$category->id)); - + $DB->set_field('course_categories', 'parent', 0, array('id' => $category->id)); $newparent = context_system::instance(); - } else { - $DB->set_field('course_categories', 'parent', $newparentcat->id, array('id'=>$category->id)); + $DB->set_field('course_categories', 'parent', $newparentcat->id, array('id' => $category->id)); $newparent = context_coursecat::instance($newparentcat->id); if (!$newparentcat->visible and $category->visible) { @@ -3660,6 +3664,9 @@ function move_category($category, $newparentcat) { // now make it last in new category $DB->set_field('course_categories', 'sortorder', MAX_COURSES_IN_CATEGORY*MAX_COURSE_CATEGORIES, array('id'=>$category->id)); + // Log action. + add_to_log(SITEID, "category", "move", "editcategory.php?id=$category->id", $category->id); + // and fix the sortorders fix_course_sortorder(); diff --git a/lib/db/log.php b/lib/db/log.php index 94abc819603..8d62b39c5c4 100644 --- a/lib/db/log.php +++ b/lib/db/log.php @@ -40,6 +40,9 @@ $logs = array( array('module'=>'course', 'action'=>'view', 'mtable'=>'course', 'field'=>'fullname'), array('module'=>'course', 'action'=>'view section', 'mtable'=>'course_sections', 'field'=>'name'), array('module'=>'course', 'action'=>'update', 'mtable'=>'course', 'field'=>'fullname'), + array('module'=>'course', 'action'=>'hide', 'mtable'=>'course', 'field'=>'fullname'), + array('module'=>'course', 'action'=>'show', 'mtable'=>'course', 'field'=>'fullname'), + array('module'=>'course', 'action'=>'move', 'mtable'=>'course', 'field'=>'fullname'), array('module'=>'course', 'action'=>'enrol', 'mtable'=>'course', 'field'=>'fullname'), // there should be some way to store user id of the enrolled user! array('module'=>'course', 'action'=>'unenrol', 'mtable'=>'course', 'field'=>'fullname'), // there should be some way to store user id of the enrolled user! array('module'=>'course', 'action'=>'report log', 'mtable'=>'course', 'field'=>'fullname'), @@ -47,6 +50,11 @@ $logs = array( array('module'=>'course', 'action'=>'report outline', 'mtable'=>'course', 'field'=>'fullname'), array('module'=>'course', 'action'=>'report participation', 'mtable'=>'course', 'field'=>'fullname'), array('module'=>'course', 'action'=>'report stats', 'mtable'=>'course', 'field'=>'fullname'), + array('module'=>'category', 'action'=>'add', 'mtable'=>'course_categories', 'field'=>'name'), + array('module'=>'category', 'action'=>'hide', 'mtable'=>'course_categories', 'field'=>'name'), + array('module'=>'category', 'action'=>'move', 'mtable'=>'course_categories', 'field'=>'name'), + array('module'=>'category', 'action'=>'show', 'mtable'=>'course_categories', 'field'=>'name'), + array('module'=>'category', 'action'=>'update', 'mtable'=>'course_categories', 'field'=>'name'), array('module'=>'message', 'action'=>'write', 'mtable'=>'user', 'field'=>$DB->sql_concat('firstname', "' '" , 'lastname')), array('module'=>'message', 'action'=>'read', 'mtable'=>'user', 'field'=>$DB->sql_concat('firstname', "' '" , 'lastname')), array('module'=>'message', 'action'=>'add contact', 'mtable'=>'user', 'field'=>$DB->sql_concat('firstname', "' '" , 'lastname')), diff --git a/version.php b/version.php index cb5b903c606..c7e0032426a 100644 --- a/version.php +++ b/version.php @@ -30,7 +30,7 @@ defined('MOODLE_INTERNAL') || die(); -$version = 2012120300.06; // YYYYMMDD = weekly release date of this DEV branch +$version = 2012120300.09; // YYYYMMDD = weekly release date of this DEV branch // RR = release increments - 00 in DEV branches // .XX = incremental changes