diff --git a/admin/index.php b/admin/index.php index 304ad60887a..2340eb39df9 100644 --- a/admin/index.php +++ b/admin/index.php @@ -473,6 +473,9 @@ /// Check all message output plugins and upgrade if necessary upgrade_plugins('message','message/output',"$CFG->wwwroot/$CFG->admin/index.php"); +/// Check all course report plugins and upgrade if necessary + upgrade_plugins('coursereport', 'course/report', "$CFG->wwwroot/$CFG->admin/index.php"); + /// Check all admin report plugins and upgrade if necessary upgrade_plugins('report', $CFG->admin.'/report', "$CFG->wwwroot/$CFG->admin/index.php"); diff --git a/course/report.php b/course/report.php index 515e0bb5d4d..668576ea61d 100644 --- a/course/report.php +++ b/course/report.php @@ -9,9 +9,10 @@ error("That's an invalid course id"); } - require_login($course->id); + require_login($course); - require_capability('moodle/site:viewreports', get_context_instance(CONTEXT_COURSE, $course->id)); + $context = get_context_instance(CONTEXT_COURSE, $course->id); + require_capability('moodle/site:viewreports', $context); $strreports = get_string('reports'); @@ -25,10 +26,16 @@ foreach ($directories as $directory) { $pluginfile = $CFG->dirroot.'/course/report/'.$directory.'/mod.php'; if (file_exists($pluginfile)) { - echo '
'; - //echo $pluginfile; - include_once($pluginfile); // Fragment for listing - echo '
'; + ob_start(); + include($pluginfile); // Fragment for listing + $html = ob_get_contents(); + ob_end_clean(); + // add div only if plugin accessible + if ($html !== '') { + echo '
'; + echo $html; + echo '
'; + } } } diff --git a/course/report/log/mod.php b/course/report/log/mod.php index 6673a1c307f..e9470d8decc 100644 --- a/course/report/log/mod.php +++ b/course/report/log/mod.php @@ -7,13 +7,14 @@ require_once($CFG->dirroot.'/course/lib.php'); require_once($CFG->dirroot.'/course/report/log/lib.php'); + if (has_capability('moodle/site:viewreports', $context)) { + print_heading(get_string('chooselogs') .':'); - print_heading(get_string('chooselogs') .':'); + print_log_selector_form($course); - print_log_selector_form($course); - - print_heading(get_string('chooselivelogs') .':'); - echo '

'; - link_to_popup_window('/course/report/log/live.php?id='. $course->id,'livelog', get_string('livelogs'), 500, 800); - echo '

'; + print_heading(get_string('chooselivelogs') .':'); + echo '

'; + link_to_popup_window('/course/report/log/live.php?id='. $course->id,'livelog', get_string('livelogs'), 500, 800); + echo '

'; + } ?> \ No newline at end of file diff --git a/course/report/outline/mod.php b/course/report/outline/mod.php index 4dfc569fcf4..042e57b0f04 100644 --- a/course/report/outline/mod.php +++ b/course/report/outline/mod.php @@ -4,9 +4,11 @@ die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page } - echo '

'; - $activityreport = get_string( 'activityreport' ); - echo "wwwroot}/course/report/outline/index.php?id={$course->id}\">"; - echo "$activityreport\n"; - echo '

'; + if (has_capability('moodle/site:viewreports', $context)) { + echo '

'; + $activityreport = get_string( 'activityreport' ); + echo "wwwroot}/course/report/outline/index.php?id={$course->id}\">"; + echo "$activityreport\n"; + echo '

'; + } ?> \ No newline at end of file diff --git a/course/report/participation/mod.php b/course/report/participation/mod.php index 22146808d04..77c4472646d 100644 --- a/course/report/participation/mod.php +++ b/course/report/participation/mod.php @@ -4,10 +4,11 @@ die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page } - echo '

'; - $participationreport = get_string('participationreport'); - echo "wwwroot}/course/report/participation/index.php?id={$course->id}\">"; - echo "$participationreport\n"; - echo '

'; - + if (has_capability('moodle/site:viewreports', $context)) { + echo '

'; + $participationreport = get_string('participationreport'); + echo "wwwroot}/course/report/participation/index.php?id={$course->id}\">"; + echo "$participationreport\n"; + echo '

'; + } ?> diff --git a/course/report/stats/mod.php b/course/report/stats/mod.php index 1f305d42c46..5e2a37f0360 100644 --- a/course/report/stats/mod.php +++ b/course/report/stats/mod.php @@ -4,13 +4,15 @@ die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page } - if (!empty($CFG->enablestats)) { - echo '

'; - echo ''.get_string('stats').''; - echo '

'; - } else { - echo '

'; - echo get_string('statsoff'); - echo '

'; + if (has_capability('moodle/site:viewreports', $context)) { + if (!empty($CFG->enablestats)) { + echo '

'; + echo ''.get_string('stats').''; + echo '

'; + } else { + echo '

'; + echo get_string('statsoff'); + echo '

'; + } } ?> diff --git a/lib/accesslib.php b/lib/accesslib.php index 93fc7daf456..1c9e3e1a7ad 100755 --- a/lib/accesslib.php +++ b/lib/accesslib.php @@ -3093,6 +3093,10 @@ function load_capability_def($component) { $defpath = $CFG->dirroot.'/grade/report/'.$compparts[1].'/db/access.php'; $varprefix = $compparts[0].'_'.$compparts[1]; + } else if ($compparts[0] == 'coursereport') { + $defpath = $CFG->dirroot.'/course/report/'.$compparts[1].'/db/access.php'; + $varprefix = $compparts[0].'_'.$compparts[1]; + } else { $defpath = $CFG->dirroot.'/'.$component.'/db/access.php'; $varprefix = str_replace('/', '_', $component); @@ -3818,6 +3822,10 @@ function get_capability_string($capabilityname) { $string = get_string($stringname, 'gradereport_'.$componentname); break; + case 'coursereport': + $string = get_string($stringname, 'coursereport_'.$componentname); + break; + default: $string = get_string($stringname); break; @@ -3866,6 +3874,8 @@ function get_component_string($component, $contextlevel) { || preg_match('|^gradeexport/|', $component) || preg_match('|^gradereport/|', $component)) { $string = get_string('gradebook', 'admin'); + } else if (preg_match('|^coursereport/|', $component)) { + $string = get_string('reports'); } else { $string = get_string('course'); } @@ -5257,7 +5267,7 @@ function component_level_changed($cap, $comp, $contextlevel) { $compsb = explode('/', $comp); // list of system reports - if (($compsa[0] == 'report') &&($compsb[0] == 'report')) { + if (($compsa[0] == 'report') && ($compsb[0] == 'report')) { return false; } @@ -5266,6 +5276,10 @@ function component_level_changed($cap, $comp, $contextlevel) { ($compsb[0] == 'gradeexport' || $compsb[0] == 'gradeimport' || $compsb[0] == 'gradereport')) { return false; } + + if (($compsa[0] == 'coursereport') && ($compsb[0] == 'coursereport')) { + return false; + } } return ($cap->component != $comp || $cap->contextlevel != $contextlevel);