From a2e4bf7f236a46f0337b3c56bd8f0eca2f4a6b0e Mon Sep 17 00:00:00 2001 From: skodak Date: Sat, 29 Nov 2008 14:22:10 +0000 Subject: [PATCH] MDL-17463 - reparate capabilities for course and admin reports --- admin/qtypes.php | 2 +- admin/report/capability/settings.php | 4 +- admin/report/courseoverview/db/access.php | 42 ++++++++++++ admin/report/courseoverview/index.php | 6 +- admin/report/courseoverview/reportsgraph.php | 2 +- admin/report/courseoverview/settings.php | 2 +- admin/report/courseoverview/version.php | 29 ++++++++ admin/report/log/index.php | 30 --------- admin/report/log/settings.php | 3 +- admin/report/questioninstances/db/access.php | 39 +++++++++++ admin/report/questioninstances/settings.php | 2 +- admin/report/questioninstances/version.php | 29 ++++++++ admin/report/stats/index.php | 69 -------------------- admin/report/stats/settings.php | 3 +- blocks/admin/block_admin.php | 2 +- course/lib.php | 2 +- course/report.php | 2 +- course/report/log/db/access.php | 42 ++++++++++++ course/report/log/graph.php | 9 +-- course/report/log/index.php | 4 +- course/report/log/lib.php | 18 ++--- course/report/log/live.php | 4 +- course/report/log/mod.php | 2 +- course/report/log/version.php | 29 ++++++++ course/report/outline/db/access.php | 42 ++++++++++++ course/report/outline/index.php | 2 +- course/report/outline/mod.php | 2 +- course/report/outline/version.php | 29 ++++++++ course/report/participation/db/access.php | 42 ++++++++++++ course/report/participation/index.php | 2 +- course/report/participation/mod.php | 2 +- course/report/participation/version.php | 29 ++++++++ course/report/progress/index.php | 3 +- course/report/progress/mod.php | 2 +- course/report/stats/db/access.php | 42 ++++++++++++ course/report/stats/graph.php | 6 +- course/report/stats/index.php | 42 +++++++----- course/report/stats/lib.php | 3 +- course/report/stats/mod.php | 2 +- course/report/stats/report.php | 2 +- course/report/stats/version.php | 29 ++++++++ course/user.php | 2 +- lang/en_utf8/coursereport_log.php | 5 ++ lang/en_utf8/coursereport_outline.php | 5 ++ lang/en_utf8/coursereport_participation.php | 5 ++ lang/en_utf8/coursereport_stats.php | 5 ++ lang/en_utf8/report_courseoverview.php | 5 ++ lang/en_utf8/report_questioninstances.php | 2 + lib/statslib.php | 4 +- lib/weblib.php | 4 +- version.php | 2 +- 51 files changed, 527 insertions(+), 169 deletions(-) create mode 100644 admin/report/courseoverview/db/access.php create mode 100644 admin/report/courseoverview/version.php delete mode 100644 admin/report/log/index.php create mode 100644 admin/report/questioninstances/db/access.php create mode 100644 admin/report/questioninstances/version.php delete mode 100644 admin/report/stats/index.php create mode 100644 course/report/log/db/access.php create mode 100644 course/report/log/version.php create mode 100644 course/report/outline/db/access.php create mode 100644 course/report/outline/version.php create mode 100644 course/report/participation/db/access.php create mode 100644 course/report/participation/version.php create mode 100644 course/report/stats/db/access.php create mode 100644 course/report/stats/version.php create mode 100644 lang/en_utf8/coursereport_log.php create mode 100644 lang/en_utf8/coursereport_outline.php create mode 100644 lang/en_utf8/coursereport_participation.php create mode 100644 lang/en_utf8/coursereport_stats.php create mode 100644 lang/en_utf8/report_courseoverview.php diff --git a/admin/qtypes.php b/admin/qtypes.php index de4fa33f26..f9f789596e 100644 --- a/admin/qtypes.php +++ b/admin/qtypes.php @@ -10,7 +10,7 @@ require_login(); $systemcontext = get_context_instance(CONTEXT_SYSTEM); require_capability('moodle/question:config', $systemcontext); - $canviewreports = has_capability('moodle/site:viewreports', $systemcontext); + $canviewreports = has_capability('report/questioninstances:view', $systemcontext); admin_externalpage_setup('manageqtypes'); diff --git a/admin/report/capability/settings.php b/admin/report/capability/settings.php index 009052d294..0a1eeb34b8 100644 --- a/admin/report/capability/settings.php +++ b/admin/report/capability/settings.php @@ -1,5 +1,3 @@ add('roles', new admin_externalpage('reportcapability', get_string('capability', 'report_capability'), "$CFG->wwwroot/$CFG->admin/report/capability/index.php",'moodle/role:manage')); -} +$ADMIN->add('roles', new admin_externalpage('reportcapability', get_string('capability', 'report_capability'), "$CFG->wwwroot/$CFG->admin/report/capability/index.php",'moodle/role:manage')); ?> \ No newline at end of file diff --git a/admin/report/courseoverview/db/access.php b/admin/report/courseoverview/db/access.php new file mode 100644 index 0000000000..ebb0e44646 --- /dev/null +++ b/admin/report/courseoverview/db/access.php @@ -0,0 +1,42 @@ + array( + 'riskbitmask' => RISK_PERSONAL, + 'captype' => 'read', + 'contextlevel' => CONTEXT_SYSTEM, + 'legacy' => array( + 'teacher' => CAP_ALLOW, + 'editingteacher' => CAP_ALLOW, + 'admin' => CAP_ALLOW + ), + + 'clonepermissionsfrom' => 'moodle/site:viewreports', + ) +); + +?> diff --git a/admin/report/courseoverview/index.php b/admin/report/courseoverview/index.php index 712b32adc1..645ce9665b 100644 --- a/admin/report/courseoverview/index.php +++ b/admin/report/courseoverview/index.php @@ -12,7 +12,11 @@ admin_externalpage_print_header(); if (empty($CFG->enablestats)) { - redirect("$CFG->wwwroot/$CFG->admin/settings.php?section=stats", get_string('mustenablestats', 'admin'), 3); + if (has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM))) { + redirect("$CFG->wwwroot/$CFG->admin/settings.php?section=stats", get_string('mustenablestats', 'admin'), 3); + } else { + error("Stats is not enabled."); + } } $course = get_site(); diff --git a/admin/report/courseoverview/reportsgraph.php b/admin/report/courseoverview/reportsgraph.php index dc99e73013..db3e71a2a9 100644 --- a/admin/report/courseoverview/reportsgraph.php +++ b/admin/report/courseoverview/reportsgraph.php @@ -10,7 +10,7 @@ require_login(); - require_capability('moodle/site:viewreports', get_context_instance(CONTEXT_SYSTEM)); + require_capability('report/courseoverview:view', get_context_instance(CONTEXT_SYSTEM)); stats_check_uptodate(); diff --git a/admin/report/courseoverview/settings.php b/admin/report/courseoverview/settings.php index cb54298156..16c390c4a8 100644 --- a/admin/report/courseoverview/settings.php +++ b/admin/report/courseoverview/settings.php @@ -1,3 +1,3 @@ add('reports', new admin_externalpage('reportcourseoverview', get_string('courseoverview', 'admin'), "$CFG->wwwroot/$CFG->admin/report/courseoverview/index.php",'moodle/site:viewreports')); +$ADMIN->add('reports', new admin_externalpage('reportcourseoverview', get_string('courseoverview', 'admin'), "$CFG->wwwroot/$CFG->admin/report/courseoverview/index.php",'report/courseoverview:view')); ?> \ No newline at end of file diff --git a/admin/report/courseoverview/version.php b/admin/report/courseoverview/version.php new file mode 100644 index 0000000000..702efd5e03 --- /dev/null +++ b/admin/report/courseoverview/version.php @@ -0,0 +1,29 @@ +version = 2007101502; +$plugin->requires = 2007101532; + +?> diff --git a/admin/report/log/index.php b/admin/report/log/index.php deleted file mode 100644 index 2878ee76c0..0000000000 --- a/admin/report/log/index.php +++ /dev/null @@ -1,30 +0,0 @@ -dirroot.'/course/lib.php'); - require_once($CFG->dirroot.'/course/report/log/lib.php'); - require_once($CFG->libdir.'/adminlib.php'); - - admin_externalpage_setup('reportlog'); - admin_externalpage_print_header(); - - - $course = get_site(); - - print_heading(get_string('chooselogs') .':'); - - print_mnet_log_selector_form($CFG->mnet_localhost_id, $course); - - echo '
'; - print_heading(get_string('chooselivelogs') .':'); - - $heading = link_to_popup_window('/course/report/log/live.php?id='. $course->id, - 'livelog', get_string('livelogs'), - 500, 800, '', 'none', true); - - print_heading($heading, 'center', 3); - - - admin_externalpage_print_footer(); - -?> \ No newline at end of file diff --git a/admin/report/log/settings.php b/admin/report/log/settings.php index 1f11339668..4bccaf7e7b 100644 --- a/admin/report/log/settings.php +++ b/admin/report/log/settings.php @@ -1,3 +1,4 @@ add('reports', new admin_externalpage('reportlog', get_string('log', 'admin'), "$CFG->wwwroot/$CFG->admin/report/log/index.php",'moodle/site:viewreports')); +// just a link to course report +$ADMIN->add('reports', new admin_externalpage('reportlog', get_string('log', 'admin'), "$CFG->wwwroot/course/report/log/index.php?id=".SITEID, 'coursereport/log:view')); ?> \ No newline at end of file diff --git a/admin/report/questioninstances/db/access.php b/admin/report/questioninstances/db/access.php new file mode 100644 index 0000000000..0a73868f8c --- /dev/null +++ b/admin/report/questioninstances/db/access.php @@ -0,0 +1,39 @@ + array( + 'captype' => 'read', + 'contextlevel' => CONTEXT_SYSTEM, + 'legacy' => array( + 'admin' => CAP_ALLOW + ), + + 'clonepermissionsfrom' => 'moodle/site:config', + ) +); + +?> diff --git a/admin/report/questioninstances/settings.php b/admin/report/questioninstances/settings.php index fea0d3c800..3ef1808e5a 100644 --- a/admin/report/questioninstances/settings.php +++ b/admin/report/questioninstances/settings.php @@ -1,3 +1,3 @@ add('reports', new admin_externalpage('reportquestioninstances', get_string('questioninstances', 'report_questioninstances'), "$CFG->wwwroot/$CFG->admin/report/questioninstances/index.php", 'moodle/site:viewreports')); +$ADMIN->add('reports', new admin_externalpage('reportquestioninstances', get_string('questioninstances', 'report_questioninstances'), "$CFG->wwwroot/$CFG->admin/report/questioninstances/index.php", 'report/questioninstances:view')); ?> \ No newline at end of file diff --git a/admin/report/questioninstances/version.php b/admin/report/questioninstances/version.php new file mode 100644 index 0000000000..702efd5e03 --- /dev/null +++ b/admin/report/questioninstances/version.php @@ -0,0 +1,29 @@ +version = 2007101502; +$plugin->requires = 2007101532; + +?> diff --git a/admin/report/stats/index.php b/admin/report/stats/index.php deleted file mode 100644 index 8f0e86853e..0000000000 --- a/admin/report/stats/index.php +++ /dev/null @@ -1,69 +0,0 @@ -dirroot.'/lib/statslib.php'); - require_once($CFG->dirroot.'/course/report/stats/lib.php'); - - require_once($CFG->libdir.'/adminlib.php'); - - $courseid = optional_param('course', SITEID, PARAM_INT); - $report = optional_param('report', 0, PARAM_INT); - $time = optional_param('time', 0, PARAM_INT); - $mode = optional_param('mode', STATS_MODE_GENERAL, PARAM_INT); - $userid = optional_param('userid', 0, PARAM_INT); - $roleid = 0; - - admin_externalpage_setup('reportstats'); - admin_externalpage_print_header(); - - if (empty($CFG->enablestats)) { - redirect("$CFG->wwwroot/$CFG->admin/settings.php?section=stats", get_string('mustenablestats', 'admin'), 3); - } - - if ($report > 50) { - $roleid = substr($report,1); - $report = 5; - } - - if ($report == STATS_REPORT_USER_LOGINS) { - $courseid = SITEID; //override - } - - if ($mode == STATS_MODE_RANKED) { - redirect($CFG->wwwroot.'/'.$CFG->admin.'/report/stats/index.php?time='.$time, '', 3); - } - - if (!$course = $DB->get_record("course", array("id"=>$courseid))) { - print_error('invalidcourse', 'error'); - } - - if (!empty($userid)) { - if (!$user = $DB->get_record('user', array('id'=>$userid))) { - print_error('invaliduser', 'error'); - } - } - - add_to_log($course->id, "course", "report stats", "report/stats/index.php?course=$course->id", $course->id); - - stats_check_uptodate($course->id); - - -// $strreports = get_string("reports"); -// $strstats = get_string('stats'); -// -// $menu = report_stats_mode_menu($course, $mode, $time); // add 4th $url parameter if uncommented! -// -// -// $crumb = "wwwroot}/admin\">".get_string('administration')." -> -// wwwroot}/admin/report.php\">$strreports -> -// $strstats"; - -// print_header("$course->shortname: $strstats", "$course->fullname", -// $crumb, '', '', true, ' ', $menu); - - - require_once($CFG->dirroot.'/course/report/stats/report.php'); - - admin_externalpage_print_footer(); - -?> diff --git a/admin/report/stats/settings.php b/admin/report/stats/settings.php index 5eca48c38e..ce1d3e3047 100644 --- a/admin/report/stats/settings.php +++ b/admin/report/stats/settings.php @@ -1,3 +1,4 @@ add('reports', new admin_externalpage('reportstats', get_string('stats', 'admin'), "$CFG->wwwroot/$CFG->admin/report/stats/index.php",'moodle/site:viewreports')); +// just a link to course report +$ADMIN->add('reports', new admin_externalpage('reportstats', get_string('stats', 'admin'), "$CFG->wwwroot/course/report/stats/index.php", 'coursereport/stats:view')); ?> \ No newline at end of file diff --git a/blocks/admin/block_admin.php b/blocks/admin/block_admin.php index fea86c40cb..892c00bcae 100644 --- a/blocks/admin/block_admin.php +++ b/blocks/admin/block_admin.php @@ -154,7 +154,7 @@ class block_admin extends block_list { } /// View course reports - if ($course->id !== SITEID and has_capability('moodle/site:viewreports', $context)) { + if ($course->id !== SITEID and has_capability('moodle/site:viewreports', $context)) { // basic capability for listing of reports $this->content->items[]=''.get_string('reports').''; $this->content->icons[]=''; } diff --git a/course/lib.php b/course/lib.php index 0407eb820b..a608c5e9c3 100644 --- a/course/lib.php +++ b/course/lib.php @@ -775,7 +775,7 @@ function print_log_graph($course, $userid=0, $type="course.png", $date=0) { echo "(".get_string("gdneed").")"; } else { // MDL-10818, do not display broken graph when user has no permission to view graph - if (has_capability('moodle/site:viewreports', get_context_instance(CONTEXT_COURSE, $course->id)) || + if (has_capability('coursereport/log:view', get_context_instance(CONTEXT_COURSE, $course->id)) || ($course->showreports and $USER->id == $userid)) { echo ''; diff --git a/course/report.php b/course/report.php index 21e3632d27..593da6bc3b 100644 --- a/course/report.php +++ b/course/report.php @@ -12,7 +12,7 @@ require_login($course); $context = get_context_instance(CONTEXT_COURSE, $course->id); - require_capability('moodle/site:viewreports', $context); + require_capability('moodle/site:viewreports', $context); // basic capability for listing of reports $strreports = get_string('reports'); diff --git a/course/report/log/db/access.php b/course/report/log/db/access.php new file mode 100644 index 0000000000..b8873df06f --- /dev/null +++ b/course/report/log/db/access.php @@ -0,0 +1,42 @@ + array( + 'riskbitmask' => RISK_PERSONAL, + 'captype' => 'read', + 'contextlevel' => CONTEXT_COURSE, + 'legacy' => array( + 'teacher' => CAP_ALLOW, + 'editingteacher' => CAP_ALLOW, + 'admin' => CAP_ALLOW + ), + + 'clonepermissionsfrom' => 'moodle/site:viewreports', + ) +); + +?> diff --git a/course/report/log/graph.php b/course/report/log/graph.php index 11b4ba84a3..f06b5e38ac 100644 --- a/course/report/log/graph.php +++ b/course/report/log/graph.php @@ -14,12 +14,13 @@ print_error('invalidcourseid'); } - require_login($course->id); + require_login($course); $context = get_context_instance(CONTEXT_COURSE, $course->id); - if (! (has_capability('moodle/site:viewreports', $context) - or ($course->showreports and $USER->id == $user)) ) { - print_error("nopermissions"); + if ($course->showreports and $USER->id == $user and !isguestuser()) { + // no cap required to view own graph + } else { + require_capability('coursereport/log:view', $context); } if ($user) { diff --git a/course/report/log/index.php b/course/report/log/index.php index 601cd4044b..b23670bf7e 100644 --- a/course/report/log/index.php +++ b/course/report/log/index.php @@ -44,11 +44,11 @@ $course->fullname = $course_stub->coursename; } - require_login($course->id); + require_login($course); $context = get_context_instance(CONTEXT_COURSE, $course->id); - require_capability('moodle/site:viewreports', $context); + require_capability('coursereport/log:view', $context); add_to_log($course->id, "course", "report log", "report/log/index.php?id=$course->id", $course->id); diff --git a/course/report/log/lib.php b/course/report/log/lib.php index 82297081cf..c2b2f32591 100644 --- a/course/report/log/lib.php +++ b/course/report/log/lib.php @@ -95,7 +95,7 @@ function print_mnet_log_selector_form($hostid, $course, $selecteduser=0, $select $courses = array(); $sites = array(); if ($CFG->mnet_localhost_id == $hostid) { - if (has_capability('moodle/site:viewreports', $sitecontext) && $showcourses) { + if (has_capability('coursereport/log:view', $sitecontext) && $showcourses) { if ($ccc = $DB->get_records("course", null, "fullname","id,fullname,category")) { foreach ($ccc as $cc) { if ($cc->id == SITEID) { @@ -107,7 +107,7 @@ function print_mnet_log_selector_form($hostid, $course, $selecteduser=0, $select } } } else { - if (has_capability('moodle/site:viewreports', $sitecontext) && $showcourses) { + if (has_capability('coursereport/log:view', $sitecontext) && $showcourses) { $sql = "SELECT DISTINCT course, coursename FROM {mnet_log} where hostid = ?"; if ($ccc = $DB->get_records_sql($sql, array($hostid))) { foreach ($ccc as $cc) { @@ -160,7 +160,7 @@ function print_mnet_log_selector_form($hostid, $course, $selecteduser=0, $select } } - if (has_capability('moodle/site:viewreports', $sitecontext) && !$course->category) { + if (has_capability('coursereport/log:view', $sitecontext) && !$course->category) { $activities["site_errors"] = get_string("siteerrors"); if ($modid === "site_errors") { $selectedactivity = "site_errors"; @@ -214,14 +214,14 @@ function print_mnet_log_selector_form($hostid, $course, $selecteduser=0, $select echo "\n"; echo "\n"; echo "\n"; - if (has_capability('moodle/site:viewreports', $sitecontext) && $showcourses) { + if (has_capability('coursereport/log:view', $sitecontext) && $showcourses) { $cid = empty($course->id)? '1' : $course->id; choose_from_menu_nested($dropdown, "host_course", $hostid.'/'.$cid, ""); } else { $courses = array(); $courses[$course->id] = $course->fullname . ((empty($course->category)) ? ' ('.get_string('site').') ' : ''); choose_from_menu($courses,"id",$course->id,false); - if (has_capability('moodle/site:viewreports', $sitecontext)) { + if (has_capability('coursereport/log:view', $sitecontext)) { $a = new object(); $a->url = "$CFG->wwwroot/course/report/log/index.php?chooselog=0&group=$selectedgroup&user=$selecteduser" ."&id=$course->id&date=$selecteddate&modid=$selectedactivity&showcourses=1&showusers=$showusers"; @@ -325,7 +325,7 @@ function print_log_selector_form($course, $selecteduser=0, $selecteddate='today' } } - if (has_capability('moodle/site:viewreports', $sitecontext) && $showcourses) { + if (has_capability('coursereport/log:view', $sitecontext) && $showcourses) { if ($ccc = $DB->get_records("course", null, "fullname", "id,fullname,category")) { foreach ($ccc as $cc) { if ($cc->category) { @@ -372,7 +372,7 @@ function print_log_selector_form($course, $selecteduser=0, $selecteddate='today' } } - if (has_capability('moodle/site:viewreports', $sitecontext) && ($course->id == SITEID)) { + if (has_capability('coursereport/log:view', $sitecontext) && ($course->id == SITEID)) { $activities["site_errors"] = get_string("siteerrors"); if ($modid === "site_errors") { $selectedactivity = "site_errors"; @@ -426,14 +426,14 @@ function print_log_selector_form($course, $selecteduser=0, $selecteddate='today' echo "\n"; echo "\n"; echo "\n"; - if (has_capability('moodle/site:viewreports', $sitecontext) && $showcourses) { + if (has_capability('coursereport/log:view', $sitecontext) && $showcourses) { choose_from_menu ($courses, "id", $course->id, ""); } else { // echo ''; $courses = array(); $courses[$course->id] = $course->fullname . (($course->id == SITEID) ? ' ('.get_string('site').') ' : ''); choose_from_menu($courses,"id",$course->id,false); - if (has_capability('moodle/site:viewreports', $sitecontext)) { + if (has_capability('coursereport/log:view', $sitecontext)) { $a = new object(); $a->url = "$CFG->wwwroot/course/report/log/index.php?chooselog=0&group=$selectedgroup&user=$selecteduser" ."&id=$course->id&date=$selecteddate&modid=$selectedactivity&showcourses=1&showusers=$showusers"; diff --git a/course/report/log/live.php b/course/report/log/live.php index 370b6a6d8a..3f1f518ea3 100644 --- a/course/report/log/live.php +++ b/course/report/log/live.php @@ -14,9 +14,7 @@ require_login($course); $context = get_context_instance(CONTEXT_COURSE, $course->id); - if (!has_capability('moodle/site:viewreports', $context)) { - print_error('nopermissions'); - } + require_capability('coursereport/log:view', $context); add_to_log($course->id, "course", "report live", "report/log/live.php?id=$course->id", $course->id); diff --git a/course/report/log/mod.php b/course/report/log/mod.php index e9470d8dec..a3eff2b780 100644 --- a/course/report/log/mod.php +++ b/course/report/log/mod.php @@ -7,7 +7,7 @@ require_once($CFG->dirroot.'/course/lib.php'); require_once($CFG->dirroot.'/course/report/log/lib.php'); - if (has_capability('moodle/site:viewreports', $context)) { + if (has_capability('coursereport/log:view', $context)) { print_heading(get_string('chooselogs') .':'); print_log_selector_form($course); diff --git a/course/report/log/version.php b/course/report/log/version.php new file mode 100644 index 0000000000..c62920f9d7 --- /dev/null +++ b/course/report/log/version.php @@ -0,0 +1,29 @@ +version = 2007101500; +$plugin->requires = 2007101532; + +?> diff --git a/course/report/outline/db/access.php b/course/report/outline/db/access.php new file mode 100644 index 0000000000..05cfadcc3f --- /dev/null +++ b/course/report/outline/db/access.php @@ -0,0 +1,42 @@ + array( + 'riskbitmask' => RISK_PERSONAL, + 'captype' => 'read', + 'contextlevel' => CONTEXT_COURSE, + 'legacy' => array( + 'teacher' => CAP_ALLOW, + 'editingteacher' => CAP_ALLOW, + 'admin' => CAP_ALLOW + ), + + 'clonepermissionsfrom' => 'moodle/site:viewreports', + ) +); + +?> diff --git a/course/report/outline/index.php b/course/report/outline/index.php index a7de0e5978..d21574704b 100644 --- a/course/report/outline/index.php +++ b/course/report/outline/index.php @@ -12,7 +12,7 @@ } require_login($course); - require_capability('moodle/site:viewreports', get_context_instance(CONTEXT_COURSE, $course->id)); + require_capability('coursereport/outline:view', get_context_instance(CONTEXT_COURSE, $course->id)); add_to_log($course->id, 'course', 'report outline', "report/outline/index.php?id=$course->id", $course->id); diff --git a/course/report/outline/mod.php b/course/report/outline/mod.php index 042e57b0f0..1caf681ac3 100644 --- a/course/report/outline/mod.php +++ b/course/report/outline/mod.php @@ -4,7 +4,7 @@ die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page } - if (has_capability('moodle/site:viewreports', $context)) { + if (has_capability('coursereport/outline:view', $context)) { echo '

'; $activityreport = get_string( 'activityreport' ); echo "wwwroot}/course/report/outline/index.php?id={$course->id}\">"; diff --git a/course/report/outline/version.php b/course/report/outline/version.php new file mode 100644 index 0000000000..c62920f9d7 --- /dev/null +++ b/course/report/outline/version.php @@ -0,0 +1,29 @@ +version = 2007101500; +$plugin->requires = 2007101532; + +?> diff --git a/course/report/participation/db/access.php b/course/report/participation/db/access.php new file mode 100644 index 0000000000..420f633f98 --- /dev/null +++ b/course/report/participation/db/access.php @@ -0,0 +1,42 @@ + array( + 'riskbitmask' => RISK_PERSONAL, + 'captype' => 'read', + 'contextlevel' => CONTEXT_COURSE, + 'legacy' => array( + 'teacher' => CAP_ALLOW, + 'editingteacher' => CAP_ALLOW, + 'admin' => CAP_ALLOW + ), + + 'clonepermissionsfrom' => 'moodle/site:viewreports', + ) +); + +?> diff --git a/course/report/participation/index.php b/course/report/participation/index.php index 5e59d69a4d..9ffc9fbacd 100644 --- a/course/report/participation/index.php +++ b/course/report/participation/index.php @@ -28,7 +28,7 @@ require_login($course); $context = get_context_instance(CONTEXT_COURSE, $course->id); - require_capability('moodle/site:viewreports', $context); + require_capability('coursereport/participation:view', $context); add_to_log($course->id, "course", "report participation", "report/participation/index.php?id=$course->id", $course->id); diff --git a/course/report/participation/mod.php b/course/report/participation/mod.php index 77c4472646..38428141ec 100644 --- a/course/report/participation/mod.php +++ b/course/report/participation/mod.php @@ -4,7 +4,7 @@ die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page } - if (has_capability('moodle/site:viewreports', $context)) { + if (has_capability('coursereport/participation:view', $context)) { echo '

'; $participationreport = get_string('participationreport'); echo "wwwroot}/course/report/participation/index.php?id={$course->id}\">"; diff --git a/course/report/participation/version.php b/course/report/participation/version.php new file mode 100644 index 0000000000..c62920f9d7 --- /dev/null +++ b/course/report/participation/version.php @@ -0,0 +1,29 @@ +version = 2007101500; +$plugin->requires = 2007101532; + +?> diff --git a/course/report/progress/index.php b/course/report/progress/index.php index 264c099fd0..4d03f5ab2a 100644 --- a/course/report/progress/index.php +++ b/course/report/progress/index.php @@ -1,6 +1,5 @@ id); +require_login($course); // Check basic permission $context=get_context_instance(CONTEXT_COURSE,$course->id); diff --git a/course/report/progress/mod.php b/course/report/progress/mod.php index 5ce896e280..b6418bff30 100644 --- a/course/report/progress/mod.php +++ b/course/report/progress/mod.php @@ -4,7 +4,7 @@ die('Direct access to this script is forbidden.'); // It must be included from a Moodle page } - if (has_capability('moodle/site:viewreports', $context)) { + if (has_capability('moodle/course:viewprogress', $context)) { $completion = new completion_info($course); if ($completion->is_enabled() && has_capability('moodle/course:viewprogress', $context)) { echo '

'; diff --git a/course/report/stats/db/access.php b/course/report/stats/db/access.php new file mode 100644 index 0000000000..573b38b962 --- /dev/null +++ b/course/report/stats/db/access.php @@ -0,0 +1,42 @@ + array( + 'riskbitmask' => RISK_PERSONAL, + 'captype' => 'read', + 'contextlevel' => CONTEXT_COURSE, + 'legacy' => array( + 'teacher' => CAP_ALLOW, + 'editingteacher' => CAP_ALLOW, + 'admin' => CAP_ALLOW + ), + + 'clonepermissionsfrom' => 'moodle/site:viewreports', + ) +); + +?> diff --git a/course/report/stats/graph.php b/course/report/stats/graph.php index aa45cb5bb3..dc8f89859e 100644 --- a/course/report/stats/graph.php +++ b/course/report/stats/graph.php @@ -21,12 +21,10 @@ } } - require_login(); + require_login($course); $context = get_context_instance(CONTEXT_COURSE, $course->id); - if (!has_capability('moodle/site:viewreports', $context)) { - print_error('nopermissions'); - } + require_capability('coursereport/stats:view', $context); stats_check_uptodate($course->id); diff --git a/course/report/stats/index.php b/course/report/stats/index.php index 99a4a603a6..453c33abc4 100644 --- a/course/report/stats/index.php +++ b/course/report/stats/index.php @@ -3,12 +3,9 @@ require_once('../../../config.php'); require_once($CFG->dirroot.'/lib/statslib.php'); require_once($CFG->dirroot.'/course/report/stats/lib.php'); + require_once($CFG->libdir.'/adminlib.php'); - if (empty($CFG->enablestats)) { - print_error("statsdisable"); - } - - $courseid = required_param('course', PARAM_INT); + $courseid = optional_param('course', SITEID, PARAM_INT); $report = optional_param('report', 0, PARAM_INT); $time = optional_param('time', 0, PARAM_INT); $mode = optional_param('mode', STATS_MODE_GENERAL, PARAM_INT); @@ -25,7 +22,7 @@ } if ($mode == STATS_MODE_RANKED) { - redirect($CFG->wwwroot.'/'.$CFG->admin.'/report/stats/index.php?time='.$time); + redirect($CFG->wwwroot.'/course/report/stats/index.php?time='.$time); } if (!$course = $DB->get_record("course", array("id"=>$courseid))) { @@ -41,26 +38,37 @@ require_login($course); $context = get_context_instance(CONTEXT_COURSE, $course->id); - require_capability('moodle/site:viewreports', $context); + require_capability('coursereport/stats:view', $context); add_to_log($course->id, "course", "report stats", "report/stats/index.php?course=$course->id", $course->id); stats_check_uptodate($course->id); + if ($course->id == SITEID) { + admin_externalpage_setup('reportstats'); + admin_externalpage_print_header(); + } else { + $strreports = get_string("reports"); + $strstats = get_string('stats'); - $strreports = get_string("reports"); - $strstats = get_string('stats'); - - $menu = report_stats_mode_menu($course, $mode, $time, "$CFG->wwwroot/course/report/stats/index.php"); + $menu = report_stats_mode_menu($course, $mode, $time, "$CFG->wwwroot/course/report/stats/index.php"); - $navlinks = array(); - $navlinks[] = array('name' => $strreports, 'link' => "../../report.php?id=$course->id", 'type' => 'misc'); - $navlinks[] = array('name' => $strstats, 'link' => null, 'type' => 'misc'); - $navigation = build_navigation($navlinks); + $navlinks = array(); + $navlinks[] = array('name' => $strreports, 'link' => "../../report.php?id=$course->id", 'type' => 'misc'); + $navlinks[] = array('name' => $strstats, 'link' => null, 'type' => 'misc'); + $navigation = build_navigation($navlinks); - print_header("$course->shortname: $strstats", $course->fullname, $navigation, '', '', true, ' ', $menu); + print_header("$course->shortname: $strstats", $course->fullname, $navigation, '', '', true, ' ', $menu); + } + require($CFG->dirroot.'/course/report/stats/report.php'); - require_once($CFG->dirroot.'/course/report/stats/report.php'); + if (empty($CFG->enablestats)) { + if (has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM))) { + redirect("$CFG->wwwroot/$CFG->admin/settings.php?section=stats", get_string('mustenablestats', 'admin'), 3); + } else { + error("Stats is not enabled."); + } + } print_footer(); diff --git a/course/report/stats/lib.php b/course/report/stats/lib.php index 9cee9848e3..237ea02bc2 100644 --- a/course/report/stats/lib.php +++ b/course/report/stats/lib.php @@ -4,7 +4,6 @@ */ - require_once('../../../config.php'); require_once($CFG->dirroot.'/lib/statslib.php'); @@ -21,7 +20,7 @@ $options = array(); $options[STATS_MODE_GENERAL] = get_string('statsmodegeneral'); $options[STATS_MODE_DETAILED] = get_string('statsmodedetailed'); - if (has_capability('moodle/site:viewreports', get_context_instance(CONTEXT_SYSTEM))) { + if (has_capability('coursereport/stats:view', get_context_instance(CONTEXT_SYSTEM))) { $options[STATS_MODE_RANKED] = get_string('reports'); } diff --git a/course/report/stats/mod.php b/course/report/stats/mod.php index a57ee59b89..e1257b4a9f 100644 --- a/course/report/stats/mod.php +++ b/course/report/stats/mod.php @@ -4,7 +4,7 @@ die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page } - if (has_capability('moodle/site:viewreports', $context)) { + if (has_capability('coursereport/stats:view', $context)) { if (!empty($CFG->enablestats)) { echo '

'; echo ''.get_string('stats').''; diff --git a/course/report/stats/report.php b/course/report/stats/report.php index bd18a6db6e..edefe6aad8 100644 --- a/course/report/stats/report.php +++ b/course/report/stats/report.php @@ -10,7 +10,7 @@ foreach ($courses as $c) { $context = get_context_instance(CONTEXT_COURSE, $c->id); - if (has_capability('moodle/site:viewreports', $context)) { + if (has_capability('coursereport/stats:view', $context)) { $courseoptions[$c->id] = $c->shortname; } } diff --git a/course/report/stats/version.php b/course/report/stats/version.php new file mode 100644 index 0000000000..c62920f9d7 --- /dev/null +++ b/course/report/stats/version.php @@ -0,0 +1,29 @@ +version = 2007101500; +$plugin->requires = 2007101532; + +?> diff --git a/course/user.php b/course/user.php index ee52a3b7d7..e8b21c2994 100644 --- a/course/user.php +++ b/course/user.php @@ -156,7 +156,7 @@ } // MDL-10818, do not display broken graph when user has no permission to view graph - if (has_capability('moodle/site:viewreports', get_context_instance(CONTEXT_COURSE, $id)) || + if (has_capability('coursereport/stats:view', get_context_instance(CONTEXT_COURSE, $id)) || ($course->showreports and $USER->id == $user->id)) { echo '

'.get_string('statisticsgraph').'
'; } diff --git a/lang/en_utf8/coursereport_log.php b/lang/en_utf8/coursereport_log.php new file mode 100644 index 0000000000..6b1de33712 --- /dev/null +++ b/lang/en_utf8/coursereport_log.php @@ -0,0 +1,5 @@ + diff --git a/lang/en_utf8/coursereport_outline.php b/lang/en_utf8/coursereport_outline.php new file mode 100644 index 0000000000..fa57c1a98b --- /dev/null +++ b/lang/en_utf8/coursereport_outline.php @@ -0,0 +1,5 @@ + diff --git a/lang/en_utf8/coursereport_participation.php b/lang/en_utf8/coursereport_participation.php new file mode 100644 index 0000000000..9afda3c53d --- /dev/null +++ b/lang/en_utf8/coursereport_participation.php @@ -0,0 +1,5 @@ + diff --git a/lang/en_utf8/coursereport_stats.php b/lang/en_utf8/coursereport_stats.php new file mode 100644 index 0000000000..0ca5602b88 --- /dev/null +++ b/lang/en_utf8/coursereport_stats.php @@ -0,0 +1,5 @@ + diff --git a/lang/en_utf8/report_courseoverview.php b/lang/en_utf8/report_courseoverview.php new file mode 100644 index 0000000000..88e1c4bd90 --- /dev/null +++ b/lang/en_utf8/report_courseoverview.php @@ -0,0 +1,5 @@ + diff --git a/lang/en_utf8/report_questioninstances.php b/lang/en_utf8/report_questioninstances.php index a11580cf72..e928176a7a 100644 --- a/lang/en_utf8/report_questioninstances.php +++ b/lang/en_utf8/report_questioninstances.php @@ -1,5 +1,7 @@ wwwroot.'/course/report/log/index.php'. '?chooselog=1&id=1&modid=site_errors">'.get_string('logs').')'; } @@ -5497,7 +5497,7 @@ function navmenu($course, $cm=NULL, $targetwindow='self') { } //Accessibility: added Alt text, replaced > < with 'silent' character and 'accesshide' text. - if ($selectmod and has_capability('moodle/site:viewreports', $context)) { + if ($selectmod and has_capability('coursereport/log:view', $context)) { $logstext = get_string('alllogs'); $logslink = '
  • '."\n".'frametarget.'onclick="this.target=\''.$CFG->framename.'\';"'.' href="'. diff --git a/version.php b/version.php index dd2aea32bf..466df6e87a 100644 --- a/version.php +++ b/version.php @@ -6,7 +6,7 @@ // This is compared against the values stored in the database to determine // whether upgrades should be performed (see lib/db/*.php) - $version = 2008112600; // YYYYMMDD = date of the last version bump + $version = 2008112900; // YYYYMMDD = date of the last version bump // XX = daily increments $release = '2.0 dev (Build: 20081128)'; // Human-friendly version name -- 2.39.5