From 89bd8357e91584945d62e231a9d0e0faea771d12 Mon Sep 17 00:00:00 2001 From: skodak Date: Tue, 24 Jul 2007 08:51:45 +0000 Subject: [PATCH] MDL-10579 capabilities for grade export plugins --- grade/export/csv/db/access.php | 14 +++++++++++ grade/export/csv/version.php | 6 +++++ grade/export/lib.php | 4 +-- grade/export/ods/db/access.php | 17 +++++++++++++ grade/export/ods/export.php | 46 +++++++++++++++++++++++++++++----- grade/export/ods/index.php | 29 ++++++++++++++------- grade/export/ods/version.php | 6 +++++ grade/export/txt/db/access.php | 17 +++++++++++++ grade/export/txt/export.php | 45 ++++++++++++++++++++++++++++----- grade/export/txt/index.php | 29 ++++++++++++++------- grade/export/txt/version.php | 6 ++--- grade/export/xls/db/access.php | 17 +++++++++++++ grade/export/xls/export.php | 45 ++++++++++++++++++++++++++++----- grade/export/xls/index.php | 26 ++++++++++++------- grade/export/xls/version.php | 6 +++++ grade/export/xml/db/access.php | 17 +++++++++++++ grade/export/xml/export.php | 45 ++++++++++++++++++++++++++++----- grade/export/xml/index.php | 26 ++++++++++++------- grade/export/xml/version.php | 6 +++++ lib/accesslib.php | 17 ++++++++----- version.php | 2 +- 21 files changed, 354 insertions(+), 72 deletions(-) create mode 100644 grade/export/csv/version.php create mode 100644 grade/export/ods/db/access.php create mode 100644 grade/export/ods/version.php create mode 100644 grade/export/txt/db/access.php create mode 100644 grade/export/xls/db/access.php create mode 100644 grade/export/xls/version.php create mode 100644 grade/export/xml/db/access.php create mode 100644 grade/export/xml/version.php diff --git a/grade/export/csv/db/access.php b/grade/export/csv/db/access.php index b28b04f643..8d7eec88a7 100644 --- a/grade/export/csv/db/access.php +++ b/grade/export/csv/db/access.php @@ -1,3 +1,17 @@ + array( + 'riskbitmask' => RISK_PERSONAL, + 'captype' => 'read', + 'contextlevel' => CONTEXT_COURSE, + 'legacy' => array( + 'teacher' => CAP_ALLOW, + 'editingteacher' => CAP_ALLOW, + 'admin' => CAP_ALLOW + ) + ) +); +?> diff --git a/grade/export/csv/version.php b/grade/export/csv/version.php new file mode 100644 index 0000000000..bb12a6cddc --- /dev/null +++ b/grade/export/csv/version.php @@ -0,0 +1,6 @@ +version = 2007072404; +$plugin->requires = 2007072402; + +?> diff --git a/grade/export/lib.php b/grade/export/lib.php index b277b21428..14ae50edb4 100755 --- a/grade/export/lib.php +++ b/grade/export/lib.php @@ -23,8 +23,8 @@ // // /////////////////////////////////////////////////////////////////////////// -include_once($CFG->dirroot.'/lib/gradelib.php'); -include_once($CFG->dirroot.'/grade/lib.php'); +require_once($CFG->dirroot.'/lib/gradelib.php'); +require_once($CFG->dirroot.'/grade/lib.php'); /** * Prints all grade items for selection * @input int id - course id diff --git a/grade/export/ods/db/access.php b/grade/export/ods/db/access.php new file mode 100644 index 0000000000..b7b6c2df09 --- /dev/null +++ b/grade/export/ods/db/access.php @@ -0,0 +1,17 @@ + array( + 'riskbitmask' => RISK_PERSONAL, + 'captype' => 'read', + 'contextlevel' => CONTEXT_COURSE, + 'legacy' => array( + 'teacher' => CAP_ALLOW, + 'editingteacher' => CAP_ALLOW, + 'admin' => CAP_ALLOW + ) + ) +); + +?> diff --git a/grade/export/ods/export.php b/grade/export/ods/export.php index eac52a141f..efeff42d41 100755 --- a/grade/export/ods/export.php +++ b/grade/export/ods/export.php @@ -1,12 +1,46 @@ -dirroot.'/grade/export/lib.php'); -require_once('grade_export_ods.php'); +/////////////////////////////////////////////////////////////////////////// +// // +// NOTICE OF COPYRIGHT // +// // +// Moodle - Modular Object-Oriented Dynamic Learning Environment // +// http://moodle.com // +// // +// Copyright (C) 2001-2003 Martin Dougiamas http://dougiamas.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 // +// // +/////////////////////////////////////////////////////////////////////////// -$id = required_param('id', PARAM_INT); // course id -$itemids = explode(",", required_param('itemids', PARAM_RAW)); +require_once '../../../config.php'; +require_once $CFG->dirroot.'/grade/export/lib.php'; +require_once 'grade_export_ods.php'; + +$id = required_param('id', PARAM_INT); // course id $feedback = optional_param('feedback', '', PARAM_ALPHA); +$itemids = explode(",", required_param('itemids', PARAM_RAW)); + +if (!$course = get_record('course', 'id', $id)) { + print_error('nocourseid'); +} + +require_login($course); +$context = get_context_instance(CONTEXT_COURSE, $id); + +require_capability('moodle/grade:export', $context); +require_capability('gradeexport/ods:view', $context); + // print all the exported data here $export = new grade_export_ods($id, $itemids); diff --git a/grade/export/ods/index.php b/grade/export/ods/index.php index 54a9a5b40c..1fc60c3311 100755 --- a/grade/export/ods/index.php +++ b/grade/export/ods/index.php @@ -1,4 +1,5 @@ -dirroot.'/grade/export/lib.php'); -require_once('grade_export_ods.php'); - -$id = required_param('id', PARAM_INT); // course id -require_login($id); -require_capability('moodle/grade:export', get_context_instance(CONTEXT_COURSE, $id)); +require_once '../../../config.php'; +require_once $CFG->dirroot.'/grade/export/lib.php'; +require_once 'grade_export_ods.php'; -$course = get_record('course', 'id', $id); +$id = required_param('id', PARAM_INT); // course id $feedback = optional_param('feedback', '', PARAM_ALPHA); + +if (!$course = get_record('course', 'id', $id)) { + print_error('nocourseid'); +} + +require_login($course); +$context = get_context_instance(CONTEXT_COURSE, $id); + +require_capability('moodle/grade:export', $context); +require_capability('gradeexport/ods:view', $context); + + $strgrades = get_string('grades', 'grades'); $actionstr = get_string('modulename', 'gradeexport_ods'); + $gradenav = "wwwroot/course/view.php?id=$course->id\">$course->shortname"; $gradenav .= " -> wwwroot/grade/index.php?id=$course->id\">$strgrades"; $gradenav .= " -> $actionstr"; + print_header($course->shortname.': '.get_string('grades'), $course->fullname, $gradenav); // process post information if (($data = data_submitted()) && confirm_sesskey()) { diff --git a/grade/export/ods/version.php b/grade/export/ods/version.php new file mode 100644 index 0000000000..5450dc1ff0 --- /dev/null +++ b/grade/export/ods/version.php @@ -0,0 +1,6 @@ +version = 2007072409; +$plugin->requires = 2007072402; + +?> diff --git a/grade/export/txt/db/access.php b/grade/export/txt/db/access.php new file mode 100644 index 0000000000..243bd9b027 --- /dev/null +++ b/grade/export/txt/db/access.php @@ -0,0 +1,17 @@ + array( + 'riskbitmask' => RISK_PERSONAL, + 'captype' => 'read', + 'contextlevel' => CONTEXT_COURSE, + 'legacy' => array( + 'teacher' => CAP_ALLOW, + 'editingteacher' => CAP_ALLOW, + 'admin' => CAP_ALLOW + ) + ) +); + +?> diff --git a/grade/export/txt/export.php b/grade/export/txt/export.php index a38782a071..9d368102f6 100755 --- a/grade/export/txt/export.php +++ b/grade/export/txt/export.php @@ -1,12 +1,45 @@ -dirroot.'/grade/export/lib.php'); -require_once('grade_export_txt.php'); +/////////////////////////////////////////////////////////////////////////// +// // +// NOTICE OF COPYRIGHT // +// // +// Moodle - Modular Object-Oriented Dynamic Learning Environment // +// http://moodle.com // +// // +// Copyright (C) 2001-2003 Martin Dougiamas http://dougiamas.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 // +// // +/////////////////////////////////////////////////////////////////////////// -$id = required_param('id', PARAM_INT); // course id -$itemids = explode(",", required_param('itemids', PARAM_RAW)); +require_once '../../../config.php'; +require_once $CFG->dirroot.'/grade/export/lib.php'; +require_once 'grade_export_txt.php'; + +$id = required_param('id', PARAM_INT); // course id $feedback = optional_param('feedback', '', PARAM_ALPHA); +$itemids = explode(",", required_param('itemids', PARAM_RAW)); + +if (!$course = get_record('course', 'id', $id)) { + print_error('nocourseid'); +} + +require_login($course); +$context = get_context_instance(CONTEXT_COURSE, $id); + +require_capability('moodle/grade:export', $context); +require_capability('gradeexport/txt:view', $context); // print all the exported data here $export = new grade_export_txt($id, $itemids); diff --git a/grade/export/txt/index.php b/grade/export/txt/index.php index ad681a00f7..d8612d9d64 100755 --- a/grade/export/txt/index.php +++ b/grade/export/txt/index.php @@ -1,4 +1,5 @@ -dirroot.'/grade/export/lib.php'); -require_once('grade_export_txt.php'); - -$id = required_param('id', PARAM_INT); // course id -require_login($id); -require_capability('moodle/grade:export', get_context_instance(CONTEXT_COURSE, $id)); +require_once '../../../config.php'; +require_once $CFG->dirroot.'/grade/export/lib.php'; +require_once 'grade_export_txt.php'; +$id = required_param('id', PARAM_INT); // course id $feedback = optional_param('feedback', '', PARAM_ALPHA); -$course = get_record('course', 'id', $id); + +if (!$course = get_record('course', 'id', $id)) { + print_error('nocourseid'); +} + +require_login($course); +$context = get_context_instance(CONTEXT_COURSE, $id); + +require_capability('moodle/grade:export', $context); +require_capability('gradeexport/txt:view', $context); + + $strgrades = get_string('grades', 'grades'); $actionstr = get_string('modulename', 'gradeexport_txt'); + $gradenav = "wwwroot/course/view.php?id=$course->id\">$course->shortname"; $gradenav .= " -> wwwroot/grade/index.php?id=$course->id\">$strgrades"; $gradenav .= " -> $actionstr"; + print_header($course->shortname.': '.get_string('grades'), $course->fullname, $gradenav); // process post information diff --git a/grade/export/txt/version.php b/grade/export/txt/version.php index 96db5bce31..7dcd2ffa31 100755 --- a/grade/export/txt/version.php +++ b/grade/export/txt/version.php @@ -1,6 +1,6 @@ -version = 2007052201; -$plugin->requires = 2007051801; +$plugin->version = 2007072403; +$plugin->requires = 2007072402; ?> diff --git a/grade/export/xls/db/access.php b/grade/export/xls/db/access.php new file mode 100644 index 0000000000..6ea4d57c13 --- /dev/null +++ b/grade/export/xls/db/access.php @@ -0,0 +1,17 @@ + array( + 'riskbitmask' => RISK_PERSONAL, + 'captype' => 'read', + 'contextlevel' => CONTEXT_COURSE, + 'legacy' => array( + 'teacher' => CAP_ALLOW, + 'editingteacher' => CAP_ALLOW, + 'admin' => CAP_ALLOW + ) + ) +); + +?> diff --git a/grade/export/xls/export.php b/grade/export/xls/export.php index fbea383dcd..d283ac8f8f 100755 --- a/grade/export/xls/export.php +++ b/grade/export/xls/export.php @@ -1,12 +1,45 @@ -dirroot.'/grade/export/lib.php'); -require_once('grade_export_xls.php'); +/////////////////////////////////////////////////////////////////////////// +// // +// NOTICE OF COPYRIGHT // +// // +// Moodle - Modular Object-Oriented Dynamic Learning Environment // +// http://moodle.com // +// // +// Copyright (C) 2001-2003 Martin Dougiamas http://dougiamas.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 // +// // +/////////////////////////////////////////////////////////////////////////// -$id = required_param('id', PARAM_INT); // course id -$itemids = explode(",", required_param('itemids', PARAM_RAW)); +require_once '../../../config.php'; +require_once $CFG->dirroot.'/grade/export/lib.php'; +require_once 'grade_export_xls.php'; + +$id = required_param('id', PARAM_INT); // course id $feedback = optional_param('feedback', '', PARAM_ALPHA); +$itemids = explode(",", required_param('itemids', PARAM_RAW)); + +if (!$course = get_record('course', 'id', $id)) { + print_error('nocourseid'); +} + +require_login($course); +$context = get_context_instance(CONTEXT_COURSE, $id); + +require_capability('moodle/grade:export', $context); +require_capability('gradeexport/xls:view', $context); // print all the exported data here $export = new grade_export_xls($id, $itemids); diff --git a/grade/export/xls/index.php b/grade/export/xls/index.php index 49dd07f4f4..7d7336c70a 100755 --- a/grade/export/xls/index.php +++ b/grade/export/xls/index.php @@ -1,4 +1,5 @@ -dirroot.'/grade/export/lib.php'); -require_once('grade_export_xls.php'); - -$id = required_param('id', PARAM_INT); // course id -require_login($id); -require_capability('moodle/grade:export', get_context_instance(CONTEXT_COURSE, $id)); +require_once '../../../config.php'; +require_once $CFG->dirroot.'/grade/export/lib.php'; +require_once 'grade_export_xls.php'; -$course = get_record('course', 'id', $id); +$id = required_param('id', PARAM_INT); // course id $feedback = optional_param('feedback', '', PARAM_ALPHA); +if (!$course = get_record('course', 'id', $id)) { + print_error('nocourseid'); +} + +require_login($course); +$context = get_context_instance(CONTEXT_COURSE, $id); + +require_capability('moodle/grade:export', $context); +require_capability('gradeexport/xls:view', $context); + + $strgrades = get_string('grades', 'grades'); $actionstr = get_string('modulename', 'gradeexport_xls'); $gradenav = "wwwroot/course/view.php?id=$course->id\">$course->shortname"; diff --git a/grade/export/xls/version.php b/grade/export/xls/version.php new file mode 100644 index 0000000000..7dcd2ffa31 --- /dev/null +++ b/grade/export/xls/version.php @@ -0,0 +1,6 @@ +version = 2007072403; +$plugin->requires = 2007072402; + +?> diff --git a/grade/export/xml/db/access.php b/grade/export/xml/db/access.php new file mode 100644 index 0000000000..51233ab985 --- /dev/null +++ b/grade/export/xml/db/access.php @@ -0,0 +1,17 @@ + array( + 'riskbitmask' => RISK_PERSONAL, + 'captype' => 'read', + 'contextlevel' => CONTEXT_COURSE, + 'legacy' => array( + 'teacher' => CAP_ALLOW, + 'editingteacher' => CAP_ALLOW, + 'admin' => CAP_ALLOW + ) + ) +); + +?> diff --git a/grade/export/xml/export.php b/grade/export/xml/export.php index e0d4af54bf..056161755d 100755 --- a/grade/export/xml/export.php +++ b/grade/export/xml/export.php @@ -1,12 +1,45 @@ -dirroot.'/grade/export/lib.php'); -require_once('grade_export_xml.php'); +/////////////////////////////////////////////////////////////////////////// +// // +// NOTICE OF COPYRIGHT // +// // +// Moodle - Modular Object-Oriented Dynamic Learning Environment // +// http://moodle.com // +// // +// Copyright (C) 2001-2003 Martin Dougiamas http://dougiamas.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 // +// // +/////////////////////////////////////////////////////////////////////////// -$id = required_param('id', PARAM_INT); // course id -$itemids = explode(",", required_param('itemids', PARAM_RAW)); +require_once '../../../config.php'; +require_once $CFG->dirroot.'/grade/export/lib.php'; +require_once 'grade_export_xml.php'; + +$id = required_param('id', PARAM_INT); // course id $feedback = optional_param('feedback', '', PARAM_ALPHA); +$itemids = explode(",", required_param('itemids', PARAM_RAW)); + +if (!$course = get_record('course', 'id', $id)) { + print_error('nocourseid'); +} + +require_login($course); +$context = get_context_instance(CONTEXT_COURSE, $id); + +require_capability('moodle/grade:export', $context); +require_capability('gradeexport/xml:view', $context); // print all the exported data here $export = new grade_export_xml($id, $itemids); diff --git a/grade/export/xml/index.php b/grade/export/xml/index.php index 9c2ca8adce..c673ed0cc9 100755 --- a/grade/export/xml/index.php +++ b/grade/export/xml/index.php @@ -1,4 +1,5 @@ -dirroot.'/grade/export/lib.php'); -require_once('grade_export_xml.php'); - -$id = required_param('id', PARAM_INT); // course id -require_login($id); -require_capability('moodle/grade:export', get_context_instance(CONTEXT_COURSE, $id)); +require_once '../../../config.php'; +require_once $CFG->dirroot.'/grade/export/lib.php'; +require_once 'grade_export_xml.php'; -$course = get_record('course', 'id', $id); +$id = required_param('id', PARAM_INT); // course id $feedback = optional_param('feedback', '', PARAM_ALPHA); +if (!$course = get_record('course', 'id', $id)) { + print_error('nocourseid'); +} + +require_login($course); +$context = get_context_instance(CONTEXT_COURSE, $id); + +require_capability('moodle/grade:export', $context); +require_capability('gradeexport/xml:view', $context); + + $strgrades = get_string('grades', 'grades'); $actionstr = get_string('modulename', 'gradeexport_xml'); $gradenav = "wwwroot/course/view.php?id=$course->id\">$course->shortname"; diff --git a/grade/export/xml/version.php b/grade/export/xml/version.php new file mode 100644 index 0000000000..7dcd2ffa31 --- /dev/null +++ b/grade/export/xml/version.php @@ -0,0 +1,6 @@ +version = 2007072403; +$plugin->requires = 2007072402; + +?> diff --git a/lib/accesslib.php b/lib/accesslib.php index f53baec362..5a12b611fe 100755 --- a/lib/accesslib.php +++ b/lib/accesslib.php @@ -2438,20 +2438,25 @@ function load_capability_def($component) { $defpath = $CFG->dirroot.'/'.$compparts[0]. 's/'.$compparts[1].'/db/access.php'; $varprefix = $compparts[0].'_'.$compparts[1]; + } else if ($compparts[0] == 'format') { // Similar to the above, course formats are 'format' while they // are stored in 'course/format'. $defpath = $CFG->dirroot.'/course/'.$component.'/db/access.php'; $varprefix = $compparts[0].'_'.$compparts[1]; + } else if ($compparts[0] == 'gradeimport') { - $defpath = $CFG->dirroot.'/grade/import/'.$component.'/db/access.php'; - $varprefix = $component; + $defpath = $CFG->dirroot.'/grade/import/'.$compparts[1].'/db/access.php'; + $varprefix = $compparts[0].'_'.$compparts[1]; + } else if ($compparts[0] == 'gradeexport') { - $defpath = $CFG->dirroot.'/grade/export/'.$component.'/db/access.php'; - $varprefix = $component; + $defpath = $CFG->dirroot.'/grade/export/'.$compparts[1].'/db/access.php'; + $varprefix = $compparts[0].'_'.$compparts[1]; + } else if ($compparts[0] == 'gradereport') { - $defpath = $CFG->dirroot.'/grade/report/'.$component.'/db/access.php'; - $varprefix = $component; + $defpath = $CFG->dirroot.'/grade/report/'.$compparts[1].'/db/access.php'; + $varprefix = $compparts[0].'_'.$compparts[1]; + } else { $defpath = $CFG->dirroot.'/'.$component.'/db/access.php'; $varprefix = str_replace('/', '_', $component); diff --git a/version.php b/version.php index c0095f2104..9ae7854dd7 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 = 2007072400; // YYYYMMDD = date + $version = 2007072402; // YYYYMMDD = date // XY = increments within a single day $release = '1.9 dev'; // Human-friendly version name -- 2.39.5