Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/enrol/bulkchange.php
Go to the documentation of this file.
00001 <?php
00002 // This file is part of Moodle - http://moodle.org/
00003 //
00004 // Moodle is free software: you can redistribute it and/or modify
00005 // it under the terms of the GNU General Public License as published by
00006 // the Free Software Foundation, either version 3 of the License, or
00007 // (at your option) any later version.
00008 //
00009 // Moodle is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 // GNU General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU General Public License
00015 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
00016 
00026 require('../config.php');
00027 require_once("$CFG->dirroot/enrol/locallib.php");
00028 require_once("$CFG->dirroot/enrol/users_forms.php");
00029 require_once("$CFG->dirroot/enrol/renderer.php");
00030 require_once("$CFG->dirroot/group/lib.php");
00031 
00032 $id         = required_param('id', PARAM_INT); // course id
00033 $bulkuserop = required_param('bulkuserop', PARAM_ALPHANUMEXT);
00034 $userids    = required_param_array('bulkuser', PARAM_INT);
00035 $action     = optional_param('action', '', PARAM_ACTION);
00036 $filter     = optional_param('ifilter', 0, PARAM_INT);
00037 
00038 $course = $DB->get_record('course', array('id'=>$id), '*', MUST_EXIST);
00039 $context = get_context_instance(CONTEXT_COURSE, $course->id, MUST_EXIST);
00040 
00041 if ($course->id == SITEID) {
00042     redirect(new moodle_url('/'));
00043 }
00044 
00045 require_login($course);
00046 require_capability('moodle/course:enrolreview', $context);
00047 $PAGE->set_pagelayout('admin');
00048 
00049 $manager = new course_enrolment_manager($PAGE, $course, $filter);
00050 $table = new course_enrolment_users_table($manager, $PAGE);
00051 $returnurl = new moodle_url('/enrol/users.php', $table->get_combined_url_params());
00052 $actionurl = new moodle_url('/enrol/bulkchange.php', $table->get_combined_url_params()+array('bulkuserop' => $bulkuserop));
00053 
00054 $PAGE->set_url($actionurl);
00055 navigation_node::override_active_url(new moodle_url('/enrol/users.php', array('id' => $id)));
00056 
00057 $ops = $table->get_bulk_user_enrolment_operations();
00058 if (!array_key_exists($bulkuserop, $ops)) {
00059     throw new moodle_exception('invalidbulkenrolop');
00060 }
00061 $operation = $ops[$bulkuserop];
00062 
00063 // Prepare the properties of the form
00064 $users = $manager->get_users_enrolments($userids);
00065 
00066 // Get the form for the bulk operation
00067 $mform = $operation->get_form($actionurl, array('users' => $users));
00068 // If the mform is false then attempt an immediate process. This may be an immediate action that
00069 // doesn't require user input OR confirmation.... who know what but maybe one day
00070 if ($mform === false) {
00071     if ($operation->process($manager, $users, new stdClass)) {
00072         redirect($returnurl);
00073     } else {
00074         print_error('errorwithbulkoperation', 'enrol');
00075     }
00076 }
00077 // Check if the bulk operation has been cancelled
00078 if ($mform->is_cancelled()) {
00079     redirect($returnurl);
00080 }
00081 if ($mform->is_submitted() && $mform->is_validated() && confirm_sesskey()) {
00082     if ($operation->process($manager, $users, $mform->get_data())) {
00083         redirect($returnurl);
00084     }
00085 }
00086 
00087 $pagetitle = get_string('bulkuseroperation', 'enrol');
00088 
00089 $PAGE->set_title($pagetitle);
00090 $PAGE->set_heading($pagetitle);
00091 echo $OUTPUT->header();
00092 echo $OUTPUT->heading($operation->get_title());
00093 $mform->display();
00094 echo $OUTPUT->footer();
 All Data Structures Namespaces Files Functions Variables Enumerations