Merge branch 'm26_MDL-44015' of https://github.com/greg-or/moodle-mod_assign into...
[moodle.git] / enrol / mnet / addinstance.php
blob9678b400bf5eb8483d517362325971e503359608
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.
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/>.
17 /**
18 * Adds new instance of enrol_mnet into the specified course
20 * @package enrol_mnet
21 * @copyright 2010 David Mudrak <david@moodle.com>
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 require(dirname(dirname(dirname(__FILE__))).'/config.php');
26 require_once($CFG->dirroot.'/enrol/mnet/addinstance_form.php');
27 require_once($CFG->dirroot.'/mnet/service/enrol/locallib.php');
29 $id = required_param('id', PARAM_INT); // course id
31 $course = $DB->get_record('course', array('id'=>$id), '*', MUST_EXIST);
32 $context = context_course::instance($course->id, MUST_EXIST);
34 require_login($course);
35 require_capability('moodle/course:enrolconfig', $context);
37 $PAGE->set_url('/enrol/mnet/addinstance.php', array('id'=>$course->id));
38 $PAGE->set_pagelayout('standard');
40 // Try and make the manage instances node on the navigation active
41 $courseadmin = $PAGE->settingsnav->get('courseadmin');
42 if ($courseadmin && $courseadmin->get('users') && $courseadmin->get('users')->get('manageinstances')) {
43 $courseadmin->get('users')->get('manageinstances')->make_active();
46 $enrol = enrol_get_plugin('mnet');
47 // make sure we were allowed to get here form the Enrolment methods page
48 if (!$enrol->get_newinstance_link($course->id)) {
49 redirect(new moodle_url('/enrol/instances.php', array('id'=>$course->id)));
51 $service = mnetservice_enrol::get_instance();
52 $mform = new enrol_mnet_addinstance_form(null, array('course'=>$course, 'enrol'=>$enrol, 'service'=>$service));
54 if ($mform->is_cancelled()) {
55 redirect(new moodle_url('/enrol/instances.php', array('id'=>$course->id)));
57 } else if ($data = $mform->get_data()) {
58 $enrol->add_instance($course, array('customint1'=>$data->hostid, 'roleid'=>$data->roleid, 'name'=>$data->name));
59 redirect(new moodle_url('/enrol/instances.php', array('id'=>$course->id)));
62 $PAGE->set_heading($course->fullname);
63 $PAGE->set_title(get_string('pluginname', 'enrol_mnet'));
65 echo $OUTPUT->header();
66 $mform->display();
67 echo $OUTPUT->footer();