|
| 1 | +<?php |
| 2 | + |
| 3 | +// This file is part of Moodle - http://moodle.org/ |
| 4 | +// |
| 5 | +// Moodle is free software: you can redistribute it and/or modify |
| 6 | +// it under the terms of the GNU General Public License as published by |
| 7 | +// the Free Software Foundation, either version 3 of the License, or |
| 8 | +// (at your option) any later version. |
| 9 | +// |
| 10 | +// Moodle is distributed in the hope that it will be useful, |
| 11 | +// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | +// GNU General Public License for more details. |
| 14 | +// |
| 15 | +// You should have received a copy of the GNU General Public License |
| 16 | +// along with Moodle. If not, see <http://www.gnu.org/licenses/>. |
| 17 | + |
| 18 | +/** |
| 19 | + * Wrapper script redirecting user operations to correct destination. |
| 20 | + * |
| 21 | + * @copyright 1999 Martin Dougiamas http://dougiamas.com |
| 22 | + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
| 23 | + * @package user |
| 24 | + */ |
| 25 | + |
| 26 | +require_once("../../config.php"); |
| 27 | +require("{$CFG->dirroot}/enrol/locallib.php"); |
| 28 | + |
| 29 | +$action = required_param('formaction', PARAM_TEXT); |
| 30 | +$id = required_param('id', PARAM_INT); |
| 31 | +$users = optional_param_array('user', array(), PARAM_INT); |
| 32 | +$returnto = required_param('returnto', PARAM_TEXT); |
| 33 | + |
| 34 | +if (!confirm_sesskey()) { |
| 35 | + print_error('confirmsesskeybad'); |
| 36 | +} |
| 37 | + |
| 38 | +if (count($users) == 0) { |
| 39 | + print_error('invalidformdata', '', $returnto); |
| 40 | +} |
| 41 | + |
| 42 | +$role_confirmed = get_config(null, 'report_ilbenrol_confirmed'); |
| 43 | +$role_revoked = get_config(null, 'report_ilbenrol_revoked'); |
| 44 | + |
| 45 | +if (!$role_confirmed or !$role_revoked) { |
| 46 | + print_error('invalidargorconf'); |
| 47 | +} |
| 48 | + |
| 49 | +$course = $DB->get_record('course',array('id'=>$id)); |
| 50 | + |
| 51 | +if (!$course) { |
| 52 | + print_error('invalidcourseid'); |
| 53 | +} |
| 54 | + |
| 55 | +require_login($course); |
| 56 | + |
| 57 | +$context = context_course::instance($course->id); |
| 58 | +$manager = new course_enrolment_manager($PAGE, $course); |
| 59 | +$roles = $manager->get_all_roles(); |
| 60 | +$PAGE->set_heading($course->fullname); |
| 61 | +$PAGE->set_url('/user/action.php', array('action'=>$action,'id'=>$id)); |
| 62 | +$PAGE->set_pagelayout('report'); |
| 63 | +$PAGE->set_title(get_string('title','report_ilbenrol')); |
| 64 | +$PAGE->set_heading($course->fullname); |
| 65 | + |
| 66 | +require_login($course); |
| 67 | +require_capability('report/ilbenrol:view',$context); |
| 68 | + |
| 69 | +if (!array_key_exists($role_confirmed, $roles) or !array_key_exists($role_revoked, $roles)) { |
| 70 | + print_error('invalidargorconf'); |
| 71 | +} |
| 72 | + |
| 73 | +echo $OUTPUT->header(); |
| 74 | + |
| 75 | +if ($action === 'confirmenrol') { |
| 76 | + $from_role = $roles[$role_revoked]; |
| 77 | + $to_role = $roles[$role_confirmed]; |
| 78 | +} else if ($action === 'revokeenrol') { |
| 79 | + $from_role = $roles[$role_confirmed]; |
| 80 | + $to_role = $roles[$role_revoked]; |
| 81 | +} else { |
| 82 | + print_error('unknownuseraction'); |
| 83 | +} |
| 84 | + |
| 85 | +echo "<ul>"; |
| 86 | +foreach ($users as $userid=>$nothing) { |
| 87 | + $user = $DB->get_record('user', array('id'=>$userid), '*', MUST_EXIST); |
| 88 | + echo '<li>' . get_string('changeduser', 'report_ilbenrol', array('user'=>fullname($user), 'from'=>$from_role->localname, 'to'=>$to_role->localname)) . '</li>'; |
| 89 | + $manager->assign_role_to_user($to_role->id, $user->id); |
| 90 | + $manager->unassign_role_from_user($user->id, $from_role->id); |
| 91 | +} |
| 92 | + |
| 93 | +echo '</ul><br/>'; |
| 94 | + |
| 95 | +echo "<a href=\"{$returnto}\">".get_string('return', 'report_ilbenrol').'</a>'; |
| 96 | +echo $OUTPUT->footer(); |
0 commit comments