MDL-38352 - use ISO ISO 3166-1 name for Libya
[moodle.git] / enrol / meta / addinstance.php
blobb1bd857a7c1aac0f7954d4ad0eba7808cd06e011
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_meta to specified course.
21 * @package enrol
22 * @subpackage meta
23 * @copyright 2010 Petr Skoda {@link http://skodak.org}
24 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
27 require('../../config.php');
28 require_once("$CFG->dirroot/enrol/meta/addinstance_form.php");
29 require_once("$CFG->dirroot/enrol/meta/locallib.php");
31 $id = required_param('id', PARAM_INT); // course id
33 $course = $DB->get_record('course', array('id'=>$id), '*', MUST_EXIST);
34 $context = context_course::instance($course->id, MUST_EXIST);
36 $PAGE->set_url('/enrol/meta/addinstance.php', array('id'=>$course->id));
37 $PAGE->set_pagelayout('admin');
39 navigation_node::override_active_url(new moodle_url('/enrol/instances.php', array('id'=>$course->id)));
41 require_login($course);
42 require_capability('moodle/course:enrolconfig', $context);
44 $enrol = enrol_get_plugin('meta');
45 if (!$enrol->get_newinstance_link($course->id)) {
46 redirect(new moodle_url('/enrol/instances.php', array('id'=>$course->id)));
49 $mform = new enrol_meta_addinstance_form(NULL, $course);
51 if ($mform->is_cancelled()) {
52 redirect(new moodle_url('/enrol/instances.php', array('id'=>$course->id)));
54 } else if ($data = $mform->get_data()) {
55 $eid = $enrol->add_instance($course, array('customint1'=>$data->link));
56 enrol_meta_sync($course->id);
57 redirect(new moodle_url('/enrol/instances.php', array('id'=>$course->id)));
60 $PAGE->set_heading($course->fullname);
61 $PAGE->set_title(get_string('pluginname', 'enrol_meta'));
63 echo $OUTPUT->header();
65 $mform->display();
67 echo $OUTPUT->footer();