|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 00003 // This file is part of Moodle - http://moodle.org/ 00004 // 00005 // Moodle is free software: you can redistribute it and/or modify 00006 // it under the terms of the GNU General Public License as published by 00007 // the Free Software Foundation, either version 3 of the License, or 00008 // (at your option) any later version. 00009 // 00010 // Moodle is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 // GNU General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 00017 00027 require('../../config.php'); 00028 require_once("$CFG->dirroot/enrol/cohort/addinstance_form.php"); 00029 require_once("$CFG->dirroot/enrol/cohort/locallib.php"); 00030 00031 $id = required_param('id', PARAM_INT); // course id 00032 00033 $course = $DB->get_record('course', array('id'=>$id), '*', MUST_EXIST); 00034 $context = get_context_instance(CONTEXT_COURSE, $course->id, MUST_EXIST); 00035 00036 require_login($course); 00037 require_capability('moodle/course:enrolconfig', $context); 00038 require_capability('enrol/cohort:config', $context); 00039 00040 $PAGE->set_url('/enrol/cohort/addinstance.php', array('id'=>$course->id)); 00041 $PAGE->set_pagelayout('admin'); 00042 00043 navigation_node::override_active_url(new moodle_url('/enrol/instances.php', array('id'=>$course->id))); 00044 00045 // Try and make the manage instances node on the navigation active 00046 $courseadmin = $PAGE->settingsnav->get('courseadmin'); 00047 if ($courseadmin && $courseadmin->get('users') && $courseadmin->get('users')->get('manageinstances')) { 00048 $courseadmin->get('users')->get('manageinstances')->make_active(); 00049 } 00050 00051 00052 $enrol = enrol_get_plugin('cohort'); 00053 if (!$enrol->get_newinstance_link($course->id)) { 00054 redirect(new moodle_url('/enrol/instances.php', array('id'=>$course->id))); 00055 } 00056 00057 $mform = new enrol_cohort_addinstance_form(NULL, $course); 00058 00059 if ($mform->is_cancelled()) { 00060 redirect(new moodle_url('/enrol/instances.php', array('id'=>$course->id))); 00061 00062 } else if ($data = $mform->get_data()) { 00063 $enrol->add_instance($course, array('customint1'=>$data->cohortid, 'roleid'=>$data->roleid)); 00064 enrol_cohort_sync($course->id); 00065 redirect(new moodle_url('/enrol/instances.php', array('id'=>$course->id))); 00066 } 00067 00068 $PAGE->set_heading($course->fullname); 00069 $PAGE->set_title(get_string('pluginname', 'enrol_cohort')); 00070 00071 echo $OUTPUT->header(); 00072 $mform->display(); 00073 echo $OUTPUT->footer();