MDL-13766, improve repository plugins' icons
[moodle.git] / enrol / mnet / addinstance.php
blob227bf823c5c53919ca7de902e94ea2223f68cb70
1 <?php
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.
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/>.
18 /**
19 * Adds new instance of enrol_mnet into the specified course
21 * @package enrol
22 * @subpackage mnet
23 * @copyright 2010 David Mudrak <david@moodle.com>
24 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
27 require(dirname(dirname(dirname(__FILE__))).'/config.php');
28 require_once($CFG->dirroot.'/enrol/mnet/addinstance_form.php');
29 require_once($CFG->dirroot.'/mnet/service/enrol/locallib.php');
31 $id = required_param('id', PARAM_INT); // course id
33 $course = $DB->get_record('course', array('id'=>$id), '*', MUST_EXIST);
34 $context = get_context_instance(CONTEXT_COURSE, $course->id, MUST_EXIST);
36 require_login($course);
37 require_capability('moodle/course:enrolconfig', $context);
39 $PAGE->set_url('/enrol/mnet/addinstance.php', array('id'=>$course->id));
40 $PAGE->set_pagelayout('standard');
42 // Try and make the manage instances node on the navigation active
43 $courseadmin = $PAGE->settingsnav->get('courseadmin');
44 if ($courseadmin && $courseadmin->get('users') && $courseadmin->get('users')->get('manageinstances')) {
45 $courseadmin->get('users')->get('manageinstances')->make_active();
48 $enrol = enrol_get_plugin('mnet');
49 // make sure we were allowed to get here form the Enrolment methods page
50 if (!$enrol->get_newinstance_link($course->id)) {
51 redirect(new moodle_url('/enrol/instances.php', array('id'=>$course->id)));
53 $service = mnetservice_enrol::get_instance();
54 $mform = new enrol_mnet_addinstance_form(null, array('course'=>$course, 'enrol'=>$enrol, 'service'=>$service));
56 if ($mform->is_cancelled()) {
57 redirect(new moodle_url('/enrol/instances.php', array('id'=>$course->id)));
59 } else if ($data = $mform->get_data()) {
60 $enrol->add_instance($course, array('customint1'=>$data->hostid, 'roleid'=>$data->roleid, 'name'=>$data->name));
61 redirect(new moodle_url('/enrol/instances.php', array('id'=>$course->id)));
64 $PAGE->set_heading($course->fullname);
65 $PAGE->set_title(get_string('pluginname', 'enrol_mnet'));
67 echo $OUTPUT->header();
68 $mform->display();
69 echo $OUTPUT->footer();