MDL-16553 Assignment, student view: whitespace fix
[moodle.git] / course / request.php
blob22c451944193f541a161a321df28e56ef13ba4e1
1 <?php // $Id$
3 ///////////////////////////////////////////////////////////////////////////
4 // //
5 // NOTICE OF COPYRIGHT //
6 // //
7 // Moodle - Modular Object-Oriented Dynamic Learning Environment //
8 // http://moodle.org //
9 // //
10 // Copyright (C) 1999 onwards Martin Dougiamas http://dougiamas.com //
11 // //
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. //
16 // //
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: //
21 // //
22 // http://www.gnu.org/copyleft/gpl.html //
23 // //
24 ///////////////////////////////////////////////////////////////////////////
26 /**
27 * Allows a user to request a course be created for them.
29 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
30 * @package course
31 *//** */
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.
40 require_login();
41 if (isguestuser()) {
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);
50 /// Set up the form.
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()){
57 redirect($returnurl);
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');
74 $a = new object();
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();
90 print_footer();