3 ///////////////////////////////////////////////////////////////////////////
5 // NOTICE OF COPYRIGHT //
7 // Moodle - Modular Object-Oriented Dynamic Learning Environment //
8 // http://moodle.org //
10 // Copyright (C) 1999 onwards Martin Dougiamas http://dougiamas.com //
12 // This program is free software; you can redistribute it and/or modify //
13 // it under the terms of the GNU General Public License as published by //
14 // the Free Software Foundation; either version 2 of the License, or //
15 // (at your option) any later version. //
17 // This program is distributed in the hope that it will be useful, //
18 // but WITHOUT ANY WARRANTY; without even the implied warranty of //
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
20 // GNU General Public License for more details: //
22 // http://www.gnu.org/copyleft/gpl.html //
24 ///////////////////////////////////////////////////////////////////////////
27 * Allows a user to request a course be created for them.
29 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
33 require_once(dirname(__FILE__
) . '/../config.php');
34 require_once($CFG->dirroot
. '/course/request_form.php');
36 /// Where we came from. Used in a number of redirects.
37 $returnurl = $CFG->wwwroot
. '/course/index.php';
39 /// Check permissions.
42 print_error('guestsarenotallowed', '', $returnurl);
44 if (empty($CFG->enablecourserequests
)) {
45 print_error('courserequestdisabled', '', $returnurl);
47 $systemcontext = get_context_instance(CONTEXT_SYSTEM
);
48 require_capability('moodle/course:request', $systemcontext);
51 $requestform = new course_request_form($CFG->wwwroot
. '/course/request.php');
53 $strtitle = get_string('courserequest');
55 /// Standard form processing if statement.
56 if ($requestform->is_cancelled()){
59 } else if ($data = $requestform->get_data()) {
60 print_header($strtitle, $strtitle, build_navigation($strtitle), $requestform->focus());
61 print_heading($strtitle);
63 /// Record the request.
64 $data->requester
= $USER->id
;
65 if (!insert_record('course_request', $data)) {
66 print_error('errorsavingrequest', '', $returnurl);
69 /// Notify the admin if required.
70 if ($CFG->courserequestnotify
) {
71 $users = get_users_from_config($CFG->courserequestnotify
, 'moodle/site:approvecourse');
72 foreach ($users as $user) {
73 $subject = get_string('courserequest');
75 $a->link
= "$CFG->wwwroot/course/pending.php";
76 $a->user
= fullname($USER);
77 $messagetext = get_string('courserequestnotifyemail', 'admin', $a);
78 email_to_user($user, $USER, $subject, $messagetext);
82 /// and redirect back to the course listing.
83 notice(get_string('courserequestsuccess'), $returnurl);
86 /// Show the request form.
87 print_header($strtitle, $strtitle, build_navigation($strtitle), $requestform->focus());
88 print_heading($strtitle);
89 $requestform->display();