From ba50bd3d63c64c5a30b4e17eab92de741fa04fde Mon Sep 17 00:00:00 2001 From: Petr Skoda Date: Thu, 3 Nov 2011 11:20:46 +0100 Subject: [PATCH] MDL-29030 fix remaining report linking hacks Please note all plugin references from core should use callbacks, it is not ok to use capabilities or links to plugins because they may not be present in customised installs. --- admin/mnet/tabs.php | 2 +- course/user.php | 33 +++++++++++++++++---------------- lang/en/moodle.php | 2 +- lib/navigationlib.php | 24 ++++++++++++++---------- lib/outputrenderers.php | 4 ++-- lib/statslib.php | 4 ++-- report/participation/lib.php | 2 +- report/progress/lib.php | 2 +- 8 files changed, 39 insertions(+), 34 deletions(-) diff --git a/admin/mnet/tabs.php b/admin/mnet/tabs.php index c7c50a9d89e..efc0118cc07 100644 --- a/admin/mnet/tabs.php +++ b/admin/mnet/tabs.php @@ -38,7 +38,7 @@ $strmnetlog = get_string('mnetlog', 'mnet'); $strmnetedithost = get_string('reviewhostdetails', 'mnet'); $logurl = $CFG->wwwroot. - '/course/report/log/index.php?chooselog=1&showusers=1&showcourses=1&host_course='.$mnet_peer->id. + '/report/log/index.php?chooselog=1&showusers=1&showcourses=1&host_course='.$mnet_peer->id. '%2F1&user='.'0'. '&date=0'. '&modid=&modaction=0&logformat=showashtml'; diff --git a/course/user.php b/course/user.php index 21af6d71161..1face9aef98 100644 --- a/course/user.php +++ b/course/user.php @@ -1,5 +1,4 @@ deleted) { die; } +//TODO: all this is a hack - we can not link to plugins like this - all this must be abstracted to plugin callbacks! + // prepare list of allowed modes $myreports = ($course->showreports and $USER->id == $user->id); $anyreport = has_capability('moodle/user:viewuseractivitiesreport', $personalcontext); $modes = array(); -if ($myreports or $anyreport or has_capability('coursereport/outline:view', $coursecontext)) { +if ($myreports or $anyreport or has_capability('report/outline:view', $coursecontext)) { $modes[] = 'outline'; } -if ($myreports or $anyreport or has_capability('coursereport/outline:view', $coursecontext)) { +if ($myreports or $anyreport or has_capability('report/outline:view', $coursecontext)) { $modes[] = 'complete'; } -if ($myreports or $anyreport or has_capability('coursereport/log:viewtoday', $coursecontext)) { +if ($myreports or $anyreport or has_capability('report/log:viewtoday', $coursecontext)) { $modes[] = 'todaylogs'; } -if ($myreports or $anyreport or has_capability('coursereport/log:view', $coursecontext)) { +if ($myreports or $anyreport or has_capability('report/log:view', $coursecontext)) { $modes[] = 'alllogs'; } -if ($myreports or $anyreport or has_capability('coursereport/stats:view', $coursecontext)) { +if ($myreports or $anyreport or has_capability('report/stats:view', $coursecontext)) { $modes[] = 'stats'; } @@ -115,7 +116,7 @@ if (has_capability('moodle/grade:viewall', $coursecontext)) { // Course completion tab if (!empty($CFG->enablecompletion) && ($course->id == SITEID || !empty($course->enablecompletion)) && // completion enabled - ($myreports || $anyreport || ($course->id == SITEID || has_capability('coursereport/completion:view', $coursecontext)))) { // permissions to view the report + ($myreports || $anyreport || ($course->id == SITEID || has_capability('report/completion:view', $coursecontext)))) { // permissions to view the report // Decide if singular or plural if ($course->id == SITEID) { @@ -237,8 +238,8 @@ switch ($mode) { } // MDL-10818, do not display broken graph when user has no permission to view graph - if ($myreports or has_capability('coursereport/stats:view', $coursecontext)) { - echo '
'.get_string('statisticsgraph').'
'; + if ($myreports or has_capability('report/stats:view', $coursecontext)) { + echo '
'.get_string('statisticsgraph').'
'; } // What the heck is this about? -- MD @@ -413,9 +414,9 @@ switch ($mode) { if (!$rs->valid()) { if ($course->id != 1) { - $error = get_string('nocompletions', 'coursereport_completion'); + $error = get_string('nocompletions', 'report_completion'); } else { - $error = get_string('nocompletioncoursesenroled', 'coursereport_completion'); + $error = get_string('nocompletioncoursesenroled', 'report_completion'); } echo $OUTPUT->notification($error); @@ -456,7 +457,7 @@ switch ($mode) { // If there are courses with this status if (!empty($infos)) { - echo '

'.get_string($type, 'coursereport_completion').'

'; + echo '

'.get_string($type, 'report_completion').'

'; echo ''; echo ''; echo ''; @@ -465,7 +466,7 @@ switch ($mode) { echo ''; if ($type === 'complete') { - echo ''; + echo ''; } echo ''; @@ -529,7 +530,7 @@ switch ($mode) { if (!empty($activities)) { $row = array(); - $row['title'] = get_string('activitiescomplete', 'coursereport_completion'); + $row['title'] = get_string('activitiescomplete', 'report_completion'); $row['status'] = $activities_complete.' of '.count($activities); $rows[] = $row; } @@ -565,7 +566,7 @@ switch ($mode) { break; case 'No': - echo get_string('incomplete', 'coursereport_completion'); + echo get_string('incomplete', 'report_completion'); break; default: @@ -575,7 +576,7 @@ switch ($mode) { // Display link on first row echo ''; diff --git a/lang/en/moodle.php b/lang/en/moodle.php index 113e0374b3b..52caf4ac51f 100644 --- a/lang/en/moodle.php +++ b/lang/en/moodle.php @@ -1174,7 +1174,7 @@ $string['notice'] = 'Notice'; $string['noticenewerbackup'] = 'This backup file has been created with Moodle {$a->backuprelease} ({$a->backupversion}) and it\'s newer than your currently installed Moodle {$a->serverrelease} ({$a->serverversion}). This could cause some inconsistencies because backwards compatibility of backup files cannot be guaranteed.'; $string['notifications'] = 'Notifications'; $string['notifyloginfailuresmessage'] = '{$a->time}, IP: {$a->ip}, User: {$a->info}'; -$string['notifyloginfailuresmessageend'] = 'You can view these logs at {$a}/course/report/log/index.php?id=1&chooselog=1&modid=site_errors.'; +$string['notifyloginfailuresmessageend'] = 'You can view these logs at {$a}/report/log/index.php?id=1&chooselog=1&modid=site_errors.'; $string['notifyloginfailuresmessagestart'] = 'Here is a list of failed login attempts at {$a} since you were last notified'; $string['notifyloginfailuressubject'] = '{$a} :: Failed logins notification'; $string['notincluded'] = 'Not included'; diff --git a/lib/navigationlib.php b/lib/navigationlib.php index ec10a71dba7..74d57b9f51c 100644 --- a/lib/navigationlib.php +++ b/lib/navigationlib.php @@ -1972,13 +1972,15 @@ class global_navigation extends navigation_node { $usernode->add(get_string('notes', 'notes'), $url); } + //TODO: all this is a hack - we can not link to plugins like this - all this must be abstracted to plugin callbacks! + // Add a reports tab and then add reports the the user has permission to see. $anyreport = has_capability('moodle/user:viewuseractivitiesreport', $usercontext); - $outlinetreport = ($anyreport || has_capability('coursereport/outline:view', $coursecontext)); - $logtodayreport = ($anyreport || has_capability('coursereport/log:viewtoday', $coursecontext)); - $logreport = ($anyreport || has_capability('coursereport/log:view', $coursecontext)); - $statsreport = ($anyreport || has_capability('coursereport/stats:view', $coursecontext)); + $outlinetreport = ($anyreport || has_capability('report/outline:view', $coursecontext)); + $logtodayreport = ($anyreport || has_capability('report/log:viewtoday', $coursecontext)); + $logreport = ($anyreport || has_capability('report/log:view', $coursecontext)); + $statsreport = ($anyreport || has_capability('report/stats:view', $coursecontext)); $somereport = $outlinetreport || $logtodayreport || $logreport || $statsreport; @@ -2090,10 +2092,10 @@ class global_navigation extends navigation_node { $usercoursenode->add(get_string('entercourse'), new moodle_url('/course/view.php', array('id'=>$usercourse->id)), self::TYPE_SETTING, null, null, new pix_icon('i/course', '')); } - $outlinetreport = ($anyreport || has_capability('coursereport/outline:view', $usercoursecontext)); - $logtodayreport = ($anyreport || has_capability('coursereport/log:viewtoday', $usercoursecontext)); - $logreport = ($anyreport || has_capability('coursereport/log:view', $usercoursecontext)); - $statsreport = ($anyreport || has_capability('coursereport/stats:view', $usercoursecontext)); + $outlinetreport = ($anyreport || has_capability('report/outline:view', $usercoursecontext)); + $logtodayreport = ($anyreport || has_capability('report/log:viewtoday', $usercoursecontext)); + $logreport = ($anyreport || has_capability('report/log:view', $usercoursecontext)); + $statsreport = ($anyreport || has_capability('report/stats:view', $usercoursecontext)); if ($outlinetreport || $logtodayreport || $logreport || $statsreport) { $reporttab = $usercoursenode->add(get_string('activityreports')); $reportargs = array('user'=>$user->id, 'id'=>$usercourse->id); @@ -3455,8 +3457,10 @@ class settings_navigation extends navigation_node { $modulenode->add(get_string('filters', 'admin'), $url, self::TYPE_SETTING, null, 'filtermanage'); } - if (has_capability('coursereport/log:view', get_context_instance(CONTEXT_COURSE, $this->page->cm->course))) { - $url = new moodle_url('/course/report/log/index.php', array('chooselog'=>'1','id'=>$this->page->cm->course,'modid'=>$this->page->cm->id)); + //TODO: all this is a hack - we can not link to plugins like this - this must be abstracted to plugin callbacks! + + if (has_capability('report/log:view', get_context_instance(CONTEXT_COURSE, $this->page->cm->course))) { + $url = new moodle_url('/report/log/index.php', array('chooselog'=>'1','id'=>$this->page->cm->course,'modid'=>$this->page->cm->id)); $modulenode->add(get_string('logs'), $url, self::TYPE_SETTING, null, 'logreport'); } diff --git a/lib/outputrenderers.php b/lib/outputrenderers.php index 8bd6252dc31..20929ee2e57 100644 --- a/lib/outputrenderers.php +++ b/lib/outputrenderers.php @@ -507,8 +507,8 @@ class core_renderer extends renderer_base { } else { $loggedinas .= get_string('failedloginattemptsall', '', $count); } - if (has_capability('coursereport/log:view', get_context_instance(CONTEXT_SYSTEM))) { - $loggedinas .= ' (wwwroot.'/report/log/index.php'. '?chooselog=1&id=1&modid=site_errors">'.get_string('logs').')'; } $loggedinas .= ''; diff --git a/lib/statslib.php b/lib/statslib.php index a65b7714373..4091dad30e2 100644 --- a/lib/statslib.php +++ b/lib/statslib.php @@ -1350,13 +1350,13 @@ function stats_get_report_options($courseid,$mode) { case STATS_MODE_DETAILED: $reportoptions[STATS_REPORT_USER_ACTIVITY] = get_string('statsreport'.STATS_REPORT_USER_ACTIVITY); $reportoptions[STATS_REPORT_USER_ALLACTIVITY] = get_string('statsreport'.STATS_REPORT_USER_ALLACTIVITY); - if (has_capability('coursereport/stats:view', get_context_instance(CONTEXT_SYSTEM))) { + if (has_capability('report/stats:view', get_context_instance(CONTEXT_SYSTEM))) { $site = get_site(); $reportoptions[STATS_REPORT_USER_LOGINS] = get_string('statsreport'.STATS_REPORT_USER_LOGINS); } break; case STATS_MODE_RANKED: - if (has_capability('coursereport/stats:view', get_context_instance(CONTEXT_SYSTEM))) { + if (has_capability('report/stats:view', get_context_instance(CONTEXT_SYSTEM))) { $reportoptions[STATS_REPORT_ACTIVE_COURSES] = get_string('statsreport'.STATS_REPORT_ACTIVE_COURSES); $reportoptions[STATS_REPORT_ACTIVE_COURSES_WEIGHTED] = get_string('statsreport'.STATS_REPORT_ACTIVE_COURSES_WEIGHTED); $reportoptions[STATS_REPORT_PARTICIPATORY_COURSES] = get_string('statsreport'.STATS_REPORT_PARTICIPATORY_COURSES); diff --git a/report/participation/lib.php b/report/participation/lib.php index f5cbe992521..ef83f457421 100644 --- a/report/participation/lib.php +++ b/report/participation/lib.php @@ -51,7 +51,7 @@ function report_participation_page_type_list($pagetype, $parentcontext, $current $array = array( '*' => get_string('page-x', 'pagetype'), 'course-report-*' => get_string('page-course-report-x', 'pagetype'), - 'course-report-participation-index' => get_string('pluginpagetype', 'coursereport_participation') + 'course-report-participation-index' => get_string('pluginpagetype', 'report_participation') ); return $array; } \ No newline at end of file diff --git a/report/progress/lib.php b/report/progress/lib.php index b56f6adfad3..9a69c1797bf 100644 --- a/report/progress/lib.php +++ b/report/progress/lib.php @@ -62,7 +62,7 @@ function report_progress_page_type_list($pagetype, $parentcontext, $currentconte $array = array( '*' => get_string('page-x', 'pagetype'), 'course-report-*' => get_string('page-course-report-x', 'pagetype'), - 'course-report-progress-index' => get_string('pluginpagetype', 'coursereport_progress') + 'course-report-progress-index' => get_string('pluginpagetype', 'report_progress') ); return $array; } \ No newline at end of file
'.get_string('course').''.get_string('info').''.get_string('completiondate', 'coursereport_completion').''.get_string('completiondate', 'report_completion').'
'; if ($first_row) { - echo ''.get_string('detailedview', 'coursereport_completion').''; + echo ''.get_string('detailedview', 'report_completion').''; } echo '