"MDL-23308, bring course files back"
[moodle.git] / course / request.php
blob3919715342148bf8d8d738f502e64fd784c1d9c1
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 * Allows a user to request a course be created for them.
21 * @copyright 1999 Martin Dougiamas http://dougiamas.com
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23 * @package course
26 require_once(dirname(__FILE__) . '/../config.php');
27 require_once($CFG->dirroot . '/course/lib.php');
28 require_once($CFG->dirroot . '/course/request_form.php');
30 $PAGE->set_url('/course/request.php');
32 /// Where we came from. Used in a number of redirects.
33 $returnurl = $CFG->wwwroot . '/course/index.php';
35 /// Check permissions.
36 require_login();
37 if (isguestuser()) {
38 print_error('guestsarenotallowed', '', $returnurl);
40 if (empty($CFG->enablecourserequests)) {
41 print_error('courserequestdisabled', '', $returnurl);
43 require_capability('moodle/course:request', get_context_instance(CONTEXT_SYSTEM));
45 /// Set up the form.
46 $data = course_request::prepare();
47 $requestform = new course_request_form($CFG->wwwroot . '/course/request.php', compact('editoroptions'));
48 $requestform->set_data($data);
50 $strtitle = get_string('courserequest');
51 $PAGE->set_title($strtitle);
52 $PAGE->set_heading($strtitle);
54 /// Standard form processing if statement.
55 if ($requestform->is_cancelled()){
56 redirect($returnurl);
58 } else if ($data = $requestform->get_data()) {
59 $request = course_request::create($data);
61 // and redirect back to the course listing.
62 notice(get_string('courserequestsuccess'), $returnurl);
65 $PAGE->navbar->add($strtitle);
66 echo $OUTPUT->header();
67 echo $OUTPUT->heading($strtitle);
68 // Show the request form.
69 $requestform->display();
70 echo $OUTPUT->footer();