coursereqest MDL-25589 set context
[moodle.git] / course / request.php
CommitLineData
d9cb06dc 1<?php
2
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.
14//
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/>.
77eddcd5 17
18/**
19 * Allows a user to request a course be created for them.
20 *
d9cb06dc 21 * @copyright 1999 Martin Dougiamas http://dougiamas.com
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
77eddcd5 23 * @package course
d9cb06dc 24 */
25
26require_once(dirname(__FILE__) . '/../config.php');
8bdc9cac 27require_once($CFG->dirroot . '/course/lib.php');
d9cb06dc 28require_once($CFG->dirroot . '/course/request_form.php');
77eddcd5 29
a6855934 30$PAGE->set_url('/course/request.php');
77eddcd5 31
32/// Where we came from. Used in a number of redirects.
d9cb06dc 33$returnurl = $CFG->wwwroot . '/course/index.php';
77eddcd5 34
f8f384b5 35
77eddcd5 36/// Check permissions.
d9cb06dc 37require_login();
38if (isguestuser()) {
39 print_error('guestsarenotallowed', '', $returnurl);
40}
41if (empty($CFG->enablecourserequests)) {
42 print_error('courserequestdisabled', '', $returnurl);
43}
f8f384b5
DP
44$context = get_context_instance(CONTEXT_SYSTEM);
45$PAGE->set_context($context);
46require_capability('moodle/course:request', $context);
b6241ce2 47
77eddcd5 48/// Set up the form.
8bdc9cac
SH
49$data = course_request::prepare();
50$requestform = new course_request_form($CFG->wwwroot . '/course/request.php', compact('editoroptions'));
51$requestform->set_data($data);
b6241ce2 52
d9cb06dc 53$strtitle = get_string('courserequest');
8bdc9cac
SH
54$PAGE->set_title($strtitle);
55$PAGE->set_heading($strtitle);
e452210a 56
77eddcd5 57/// Standard form processing if statement.
d9cb06dc 58if ($requestform->is_cancelled()){
59 redirect($returnurl);
0a122046 60
aa6c1ced 61} else if ($data = $requestform->get_data()) {
8bdc9cac 62 $request = course_request::create($data);
d9cb06dc 63
8bdc9cac 64 // and redirect back to the course listing.
d9cb06dc 65 notice(get_string('courserequestsuccess'), $returnurl);
66}
67
d9cb06dc 68$PAGE->navbar->add($strtitle);
d9cb06dc 69echo $OUTPUT->header();
70echo $OUTPUT->heading($strtitle);
8bdc9cac 71// Show the request form.
d9cb06dc 72$requestform->display();
f8f384b5 73echo $OUTPUT->footer();