MDL-17372 admin reports: Added full plugin support for admin reports; added specail...
authorskodak <skodak>
Wed, 26 Nov 2008 19:27:39 +0000 (19:27 +0000)
committerskodak <skodak>
Wed, 26 Nov 2008 19:27:39 +0000 (19:27 +0000)
21 files changed:
admin/report/backups/index.php
admin/report/courseoverview/index.php
admin/report/courseoverview/settings.php [new file with mode: 0644]
admin/report/log/index.php
admin/report/log/settings.php [new file with mode: 0644]
admin/report/questioninstances/index.php
admin/report/questioninstances/settings.php [new file with mode: 0644]
admin/report/stats/index.php
admin/report/stats/settings.php
admin/report/unittest/db/access.php [new file with mode: 0644]
admin/report/unittest/dbtest.php
admin/report/unittest/index.php
admin/report/unittest/settings.php
admin/report/unittest/version.php [new file with mode: 0644]
admin/settings/report.php [new file with mode: 0644]
admin/settings/top.php
admin/settings/users.php
lang/en_utf8/report_unittest.php [new file with mode: 0644]
lib/accesslib.php
lib/adminlib.php
version.php

index 612501c..d380cbb 100644 (file)
@@ -5,13 +5,10 @@
     require_once($CFG->libdir.'/adminlib.php');
     require_once($CFG->dirroot.'/backup/lib.php');
 
-    admin_externalpage_setup('reportbackups');
-
-    admin_externalpage_print_header();
-
     $courseid = optional_param('courseid', 0, PARAM_INT);
 
-    require_capability('moodle/site:backup', get_context_instance(CONTEXT_SYSTEM));
+    admin_externalpage_setup('reportbackups');
+    admin_externalpage_print_header();
 
 /// Scheduled backups are disabled by the server admin
     if (!empty($CFG->disablescheduledbackups)) {
index 6e0792f..712b32a 100644 (file)
@@ -4,15 +4,12 @@
     require_once($CFG->dirroot.'/lib/statslib.php');
     require_once($CFG->libdir.'/adminlib.php');
 
-    admin_externalpage_setup('reportcourseoverview');
-
-    admin_externalpage_print_header();
-
     $report     = optional_param('report', STATS_REPORT_ACTIVE_COURSES, PARAM_INT);
     $time       = optional_param('time', 0, PARAM_INT);
     $numcourses = optional_param('numcourses', 20, PARAM_INT);
 
-    require_capability('moodle/site:viewreports', get_context_instance(CONTEXT_SYSTEM));  // needed?
+    admin_externalpage_setup('reportcourseoverview');
+    admin_externalpage_print_header();
 
     if (empty($CFG->enablestats)) {
         redirect("$CFG->wwwroot/$CFG->admin/settings.php?section=stats", get_string('mustenablestats', 'admin'), 3);
diff --git a/admin/report/courseoverview/settings.php b/admin/report/courseoverview/settings.php
new file mode 100644 (file)
index 0000000..cb54298
--- /dev/null
@@ -0,0 +1,3 @@
+<?php  // $Id$
+$ADMIN->add('reports', new admin_externalpage('reportcourseoverview', get_string('courseoverview', 'admin'), "$CFG->wwwroot/$CFG->admin/report/courseoverview/index.php",'moodle/site:viewreports'));
+?>
\ No newline at end of file
index df808f3..2878ee7 100644 (file)
@@ -6,7 +6,6 @@
     require_once($CFG->libdir.'/adminlib.php');
 
     admin_externalpage_setup('reportlog');
-
     admin_externalpage_print_header();
 
 
diff --git a/admin/report/log/settings.php b/admin/report/log/settings.php
new file mode 100644 (file)
index 0000000..1f11339
--- /dev/null
@@ -0,0 +1,3 @@
+<?php  // $Id$
+$ADMIN->add('reports', new admin_externalpage('reportlog', get_string('log', 'admin'), "$CFG->wwwroot/$CFG->admin/report/log/index.php",'moodle/site:viewreports'));
+?>
\ No newline at end of file
index 598d4f4..d485242 100644 (file)
@@ -11,21 +11,16 @@ require_once(dirname(__FILE__).'/../../../config.php');
 require_once($CFG->libdir.'/adminlib.php');
 require_once($CFG->libdir.'/questionlib.php');
 
-// Check permissions.
-require_login();
-$systemcontext = get_context_instance(CONTEXT_SYSTEM);
-require_capability('moodle/site:viewreports', $systemcontext);
-
 // Get URL parameters.
 $requestedqtype = optional_param('qtype', '', PARAM_SAFEDIR);
 
-// Log.
-add_to_log(SITEID, "admin", "report questioninstances", "report/questioninstances/index.php?qtype=$requestedqtype", $requestedqtype);
-
-// Print the header.
+// Print the header & check permissions.
 admin_externalpage_setup('reportquestioninstances');
 admin_externalpage_print_header();
 
+// Log.
+add_to_log(SITEID, "admin", "report questioninstances", "report/questioninstances/index.php?qtype=$requestedqtype", $requestedqtype);
+
 // Prepare the list of capabilites to choose from
 $qtypechoices = array();
 foreach ($QTYPES as $qtype) {
diff --git a/admin/report/questioninstances/settings.php b/admin/report/questioninstances/settings.php
new file mode 100644 (file)
index 0000000..fea0d3c
--- /dev/null
@@ -0,0 +1,3 @@
+<?php  // $Id$
+$ADMIN->add('reports', new admin_externalpage('reportquestioninstances', get_string('questioninstances', 'report_questioninstances'), "$CFG->wwwroot/$CFG->admin/report/questioninstances/index.php", 'moodle/site:viewreports'));
+?>
\ No newline at end of file
index 86ce469..8f0e868 100644 (file)
@@ -6,11 +6,6 @@
 
     require_once($CFG->libdir.'/adminlib.php');
 
-    admin_externalpage_setup('reportstats');
-
-    admin_externalpage_print_header();
-
-
     $courseid = optional_param('course', SITEID, PARAM_INT);
     $report   = optional_param('report', 0, PARAM_INT);
     $time     = optional_param('time', 0, 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;
         }
     }
 
-    require_login();
-
-    if (empty($CFG->enablestats)) {
-        redirect("$CFG->wwwroot/$CFG->admin/settings.php?section=stats", get_string('mustenablestats', 'admin'), 3);
-    }
-
-    require_capability('moodle/site:viewreports', get_context_instance(CONTEXT_SYSTEM));
-
     add_to_log($course->id, "course", "report stats", "report/stats/index.php?course=$course->id", $course->id);
 
     stats_check_uptodate($course->id);
index beb5c03..5eca48c 100644 (file)
@@ -1,5 +1,3 @@
 <?php  // $Id$
-if (!empty($CFG->enablestats)) {
-    $ADMIN->add('reports', new admin_externalpage('reportstats', get_string('stats', 'admin'), "$CFG->wwwroot/$CFG->admin/report/stats/index.php",'moodle/site:viewreports'));
-}
+$ADMIN->add('reports', new admin_externalpage('reportstats', get_string('stats', 'admin'), "$CFG->wwwroot/$CFG->admin/report/stats/index.php",'moodle/site:viewreports'));
 ?>
\ No newline at end of file
diff --git a/admin/report/unittest/db/access.php b/admin/report/unittest/db/access.php
new file mode 100644 (file)
index 0000000..dd9915f
--- /dev/null
@@ -0,0 +1,40 @@
+<?php  // $Id$
+
+///////////////////////////////////////////////////////////////////////////
+//                                                                       //
+// NOTICE OF COPYRIGHT                                                   //
+//                                                                       //
+// Moodle - Modular Object-Oriented Dynamic Learning Environment         //
+//          http://moodle.com                                            //
+//                                                                       //
+// Copyright (C) 1999 onwards  Martin Dougiamas  http://moodle.com       //
+//                                                                       //
+// This program is free software; you can redistribute it and/or modify  //
+// it under the terms of the GNU General Public License as published by  //
+// the Free Software Foundation; either version 2 of the License, or     //
+// (at your option) any later version.                                   //
+//                                                                       //
+// This program is distributed in the hope that it will be useful,       //
+// but WITHOUT ANY WARRANTY; without even the implied warranty of        //
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         //
+// GNU General Public License for more details:                          //
+//                                                                       //
+//          http://www.gnu.org/copyleft/gpl.html                         //
+//                                                                       //
+///////////////////////////////////////////////////////////////////////////
+
+$report_unittest_capabilities = array(
+
+    'report/unittest:view' => array(
+        'riskbitmask' => RISK_DATALOSS,
+        'captype' => 'read',
+        'contextlevel' => CONTEXT_SYSTEM,
+        'legacy' => array(
+            'admin' => CAP_ALLOW
+        ),
+
+        'clonepermissionsfrom' => 'moodle/site:config',
+    )
+);
+
+?>
index 506b9d0..dd58e15 100644 (file)
@@ -11,12 +11,13 @@ require_once($CFG->libdir.'/simpletestlib.php');
 require_once('ex_simple_test.php');
 require_once('ex_reporter.php');
 
-require_login();
-require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM));
-
 $showpasses = optional_param('showpasses', 0, PARAM_BOOL);
 $selected   = optional_param('selected', array(), PARAM_INT);
 
+// Print the header and check access.
+admin_externalpage_setup('reportdbtest');
+admin_externalpage_print_header();
+
 global $UNITTEST;
 $UNITTEST = new object();
 
@@ -27,9 +28,6 @@ if (!data_submitted()) {
     }
 }
 
-// Print the header.
-admin_externalpage_setup('reportdbtest');
-admin_externalpage_print_header();
 
 $dbinfos     = array();
 $tests       = array();
index 10adcfd..47a350f 100644 (file)
@@ -16,12 +16,6 @@ require_once($CFG->libdir.'/simpletestlib.php');
 require_once('ex_simple_test.php');
 require_once('ex_reporter.php');
 
-require_login();
-require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM));
-
-$langfile = 'simpletest';
-$unittest = true;
-
 // CGI arguments
 $path = optional_param('path', null, PARAM_PATH);
 $showpasses = optional_param('showpasses', false, PARAM_BOOL);
@@ -35,13 +29,17 @@ $continuesetuptesttables = optional_param('continuesetuptesttables', false, PARA
 $droptesttables = optional_param('droptesttables', false, PARAM_BOOL);
 $testtablesok = optional_param('testtablesok', false, PARAM_BOOL);
 
+admin_externalpage_setup('reportsimpletest');
+admin_externalpage_print_header();
+
+$langfile = 'simpletest';
+$unittest = true;
+
 global $UNITTEST;
 $UNITTEST = new object();
 
 // Print the header.
-admin_externalpage_setup('reportsimpletest');
 $strtitle = get_string('unittests', $langfile);
-admin_externalpage_print_header();
 
 if ($testtablesok) {
     print_heading(get_string('testtablesok', 'simpletest'));
index 2c2d3f0..8bccf04 100644 (file)
@@ -1,6 +1,6 @@
 <?php  //$Id$
 if ($hassiteconfig) {
-    $ADMIN->add('development', new admin_externalpage('reportsimpletest', get_string('simpletest', 'admin'), "$CFG->wwwroot/$CFG->admin/report/unittest/index.php",'moodle/site:config'));
-    $ADMIN->add('development', new admin_externalpage('reportdbtest', get_string('dbtest', 'admin'), "$CFG->wwwroot/$CFG->admin/report/unittest/dbtest.php",'moodle/site:config'));
+    $ADMIN->add('development', new admin_externalpage('reportsimpletest', get_string('simpletest', 'admin'), "$CFG->wwwroot/$CFG->admin/report/unittest/index.php",'report/unittest:view'));
+    $ADMIN->add('development', new admin_externalpage('reportdbtest', get_string('dbtest', 'admin'), "$CFG->wwwroot/$CFG->admin/report/unittest/dbtest.php",'report/unittest:view'));
 }
 ?>
\ No newline at end of file
diff --git a/admin/report/unittest/version.php b/admin/report/unittest/version.php
new file mode 100644 (file)
index 0000000..645c20a
--- /dev/null
@@ -0,0 +1,29 @@
+<?PHP // $Id$
+
+///////////////////////////////////////////////////////////////////////////
+//                                                                       //
+// NOTICE OF COPYRIGHT                                                   //
+//                                                                       //
+// Moodle - Modular Object-Oriented Dynamic Learning Environment         //
+//          http://moodle.com                                            //
+//                                                                       //
+// Copyright (C) 1999 onwards  Martin Dougiamas  http://moodle.com       //
+//                                                                       //
+// This program is free software; you can redistribute it and/or modify  //
+// it under the terms of the GNU General Public License as published by  //
+// the Free Software Foundation; either version 2 of the License, or     //
+// (at your option) any later version.                                   //
+//                                                                       //
+// This program is distributed in the hope that it will be useful,       //
+// but WITHOUT ANY WARRANTY; without even the implied warranty of        //
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         //
+// GNU General Public License for more details:                          //
+//                                                                       //
+//          http://www.gnu.org/copyleft/gpl.html                         //
+//                                                                       //
+///////////////////////////////////////////////////////////////////////////
+
+$plugin->version  = 2008112601;
+$plugin->requires = 2008112600;
+
+?>
diff --git a/admin/settings/report.php b/admin/settings/report.php
new file mode 100644 (file)
index 0000000..790d0d7
--- /dev/null
@@ -0,0 +1,18 @@
+<?php //$Id$
+
+foreach (get_list_of_plugins($CFG->admin.'/report') as $plugin) {
+    $settings_path = "$CFG->dirroot/$CFG->admin/report/$plugin/settings.php";
+    if (file_exists($settings_path)) {
+        include($settings_path);
+        continue;
+    }
+
+    $index_path = "$CFG->dirroot/$CFG->admin/report/$plugin/index.php";
+    if (!file_exists($index_path)) {
+        continue;
+    }
+    // old style 3rd party plugin without settings.php
+    $ADMIN->add('reports', new admin_externalpage('report'.$plugin, $plugin, $index_path, 'moodle/site:viewreports'));
+}
+
+?>
index e295eae..b09703e 100644 (file)
@@ -24,6 +24,9 @@ if ($hassiteconfig) {
 }
 
 $ADMIN->add('root', new admin_category('users', get_string('users','admin')));
+  $ADMIN->add('users', new admin_category('authsettings', get_string('authentication','admin')));
+  $ADMIN->add('users', new admin_category('accounts', get_string('accounts', 'admin')));
+  $ADMIN->add('users', new admin_category('roles', get_string('permissions', 'role')));
 $ADMIN->add('root', new admin_category('courses', get_string('courses','admin')));
 $ADMIN->add('root', new admin_category('grades', get_string('grades')));
 $ADMIN->add('root', new admin_category('location', get_string('location','admin')));
@@ -36,8 +39,10 @@ $ADMIN->add('root', new admin_category('server', get_string('server','admin')));
 $ADMIN->add('root', new admin_category('mnet', get_string('net','mnet'), (isset($CFG->mnet_dispatcher_mode) and $CFG->mnet_dispatcher_mode === 'off')));
 $ADMIN->add('root', new admin_category('reports', get_string('reports')));
 $ADMIN->add('root', new admin_category('development', get_string('development', 'admin')));
+
 // hidden unsupported category
 $ADMIN->add('root', new admin_category('unsupported', get_string('unsupported', 'admin'), true));
+
 // hidden search script
 $ADMIN->add('root', new admin_externalpage('search', get_string('searchresults'), "$CFG->wwwroot/$CFG->admin/search.php", 'moodle/site:config', true));
 
index f703294..17de059 100644 (file)
@@ -11,8 +11,6 @@ if ($hassiteconfig
  or has_capability('moodle/role:assign', $systemcontext)) { // speedup for non-admins, add all caps used on this page
 
 
-    $ADMIN->add('users', new admin_category('authsettings', get_string('authentication','admin')));
-
     $temp = new admin_settingpage('manageauths', get_string('authsettings', 'admin'));
     $temp->add(new admin_setting_manageauths());
     $temp->add(new admin_setting_heading('manageauthscommonheading', get_string('commonsettings', 'admin'), ''));
@@ -70,7 +68,6 @@ if ($hassiteconfig
         $securewwwroot = str_replace('http:','https:',$CFG->wwwroot);
     }
     // stuff under the "accounts" subcategory
-    $ADMIN->add('users', new admin_category('accounts', get_string('accounts', 'admin')));
     $ADMIN->add('accounts', new admin_externalpage('editusers', get_string('userlist','admin'), "$CFG->wwwroot/$CFG->admin/user.php", array('moodle/user:update', 'moodle/user:delete')));
     $ADMIN->add('accounts', new admin_externalpage('userbulk', get_string('userbulk','admin'), "$CFG->wwwroot/$CFG->admin/user/user_bulk.php", array('moodle/user:update', 'moodle/user:delete')));
     $ADMIN->add('accounts', new admin_externalpage('addnewuser', get_string('addnewuser'), "$securewwwroot/user/editadvanced.php?id=-1", 'moodle/user:create'));
@@ -80,7 +77,6 @@ if ($hassiteconfig
 
 
     // stuff under the "roles" subcategory
-    $ADMIN->add('users', new admin_category('roles', get_string('permissions', 'role')));
 
     // "userpolicies" settingpage
     $temp = new admin_settingpage('userpolicies', get_string('userpolicies', 'admin'));
diff --git a/lang/en_utf8/report_unittest.php b/lang/en_utf8/report_unittest.php
new file mode 100644 (file)
index 0000000..2227cf0
--- /dev/null
@@ -0,0 +1,5 @@
+<?PHP // $Id$
+
+$string['unittest:view'] = 'Execute unit tests';
+
+?>
index 8160cce..b3c36b8 100755 (executable)
@@ -3028,7 +3028,11 @@ function load_capability_def($component) {
     } else {
         $compparts = explode('/', $component);
 
-        if ($compparts[0] == 'block') {
+        if ($compparts[0] == 'report') {
+            $defpath = $CFG->dirroot.'/'.$CFG->admin.'/report/'.$compparts[1].'/db/access.php';
+            $varprefix = $compparts[0].'_'.$compparts[1];
+
+        } else if ($compparts[0] == 'block') {
             // Blocks are an exception. Blocks directory is 'blocks', and not
             // 'block'. So we need to jump through hoops.
             $defpath = $CFG->dirroot.'/'.$compparts[0].
@@ -3884,6 +3888,10 @@ function get_capability_string($capabilityname) {
     $componentname = $components[0];               // choice
 
     switch ($names[0]) {
+        case 'report':
+            $string = get_string($stringname, 'report_'.$componentname);
+        break;
+
         case 'mod':
             $string = get_string($stringname, $componentname);
         break;
@@ -3952,6 +3960,8 @@ function get_component_string($component, $contextlevel) {
             } else if (preg_match('|^local|', $component)) {
                 $langname = str_replace('/', '_', $component);
                 $string = get_string('local');
+            } else if (preg_match('|^report/|', $component)) {
+                $string = get_string('reports');
             } else {
                 $string = get_string('coresystem');
             }
@@ -5547,7 +5557,10 @@ function component_level_changed($cap, $comp, $contextlevel) {
         $compsa = explode('/', $cap->component);
         $compsb = explode('/', $comp);
 
-
+        // list of system reports
+        if (($compsa[0] == 'report') &&($compsb[0] == 'report')) {
+            return false;
+        }
 
         // we are in gradebook, still
         if (($compsa[0] == 'gradeexport' || $compsa[0] == 'gradeimport' || $compsa[0] == 'gradereport') &&
index 89d0ac8..9cfb22f 100644 (file)
@@ -5380,21 +5380,6 @@ function &admin_get_root($reload=false, $requirefulltree=true) {
             }
         }
 
-        // Add all the report plugings. Do this last so they can choose where in the tree
-        // they want to be added.
-        foreach (get_list_of_plugins($CFG->admin.'/report') as $plugin) {
-            $settingsfile = "$CFG->dirroot/$CFG->admin/report/$plugin/settings.php";
-            if (file_exists($settingsfile)) {
-                include($settingsfile);
-            } else {
-                $reportname = get_string($plugin, 'report_' . $plugin);
-                if ($reportname[1] == '[') {
-                    $reportname = get_string($plugin, 'admin');
-                }
-                $ADMIN->add('reports', new admin_externalpage('report'.$plugin, $reportname, "$CFG->wwwroot/$CFG->admin/report/$plugin/index.php",'moodle/site:viewreports'));
-            }
-        }
-
         if (file_exists($CFG->dirroot.'/local/settings.php')) {
             include_once($CFG->dirroot.'/local/settings.php');
         }
index 9f793bb..0bc166b 100644 (file)
@@ -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 = 2008112400;  // YYYYMMDD   = date of the last version bump
+    $version = 2008112600;  // YYYYMMDD   = date of the last version bump
                             //         XX = daily increments
 
     $release = '2.0 dev (Build: 20081126)';  // Human-friendly version name