PageRenderTime 37ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/grade/report/grader/preferences.php

http://github.com/moodle/moodle
PHP | 87 lines | 44 code | 19 blank | 24 comment | 11 complexity | 0b6cf6fe404ba92b6d73e72f5665a1e5 MD5 | raw file
Possible License(s): MIT, AGPL-3.0, MPL-2.0-no-copyleft-exception, LGPL-3.0, GPL-3.0, Apache-2.0, LGPL-2.1, BSD-3-Clause
  1. <?php
  2. // This file is part of Moodle - http://moodle.org/
  3. //
  4. // Moodle is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // Moodle is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License
  15. // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
  16. /**
  17. * Grader report preferences configuration page
  18. *
  19. * @package gradereport_grader
  20. * @copyright 2007 Nicolas Connault
  21. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  22. */
  23. require_once '../../../config.php';
  24. require_once $CFG->libdir . '/gradelib.php';
  25. require_once '../../lib.php';
  26. core_php_time_limit::raise();
  27. $courseid = required_param('id', PARAM_INT);
  28. $PAGE->set_url(new moodle_url('/grade/report/grader/preferences.php', array('id'=>$courseid)));
  29. $PAGE->set_pagelayout('admin');
  30. /// Make sure they can even access this course
  31. if (!$course = $DB->get_record('course', array('id' => $courseid))) {
  32. print_error('invalidcourseid');
  33. }
  34. require_login($course);
  35. $context = context_course::instance($course->id);
  36. $systemcontext = context_system::instance();
  37. require_capability('gradereport/grader:view', $context);
  38. require('preferences_form.php');
  39. $mform = new grader_report_preferences_form('preferences.php', compact('course'));
  40. // If data submitted, then process and store.
  41. if (!$mform->is_cancelled() && $data = $mform->get_data()) {
  42. foreach ($data as $preference => $value) {
  43. if (substr($preference, 0, 6) !== 'grade_') {
  44. continue;
  45. }
  46. if ($value == GRADE_REPORT_PREFERENCE_DEFAULT || strlen($value) == 0) {
  47. unset_user_preference($preference);
  48. } else {
  49. set_user_preference($preference, $value);
  50. }
  51. }
  52. redirect($CFG->wwwroot . '/grade/report/grader/index.php?id='.$courseid); // message here breaks accessability and is sloooowww
  53. exit;
  54. }
  55. if ($mform->is_cancelled()){
  56. redirect($CFG->wwwroot . '/grade/report/grader/index.php?id='.$courseid);
  57. }
  58. print_grade_page_head($courseid, 'settings', 'grader', get_string('preferences', 'gradereport_grader'));
  59. // If USER has admin capability, print a link to the site config page for this report
  60. if (has_capability('moodle/site:config', $systemcontext)) {
  61. echo '<div id="siteconfiglink"><a href="'.$CFG->wwwroot.'/'.$CFG->admin.'/settings.php?section=gradereportgrader">';
  62. echo get_string('changereportdefaults', 'grades');
  63. echo "</a></div>\n";
  64. }
  65. echo $OUTPUT->box_start();
  66. $mform->display();
  67. echo $OUTPUT->box_end();
  68. echo $OUTPUT->footer();