MDL-28615 mod_forum: Fixed the users page that shows all of the users posts
[moodle.git] / enrol / guest / addinstance.php
blob63fb4067620a8b342370a0cbd64afa380561fae3
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_guest to specified course.
21 * @package enrol
22 * @subpackage guest
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');
29 $id = required_param('id', PARAM_INT); // course id
31 $course = $DB->get_record('course', array('id'=>$id), '*', MUST_EXIST);
32 $context = get_context_instance(CONTEXT_COURSE, $course->id, MUST_EXIST);
34 require_login($course);
35 require_capability('moodle/course:enrolconfig', $context);
36 require_sesskey();
38 $enrol = enrol_get_plugin('guest');
40 if ($enrol->get_newinstance_link($course->id)) {
41 $enrol->add_default_instance($course);
44 redirect(new moodle_url('/enrol/instances.php', array('id'=>$course->id)));