mirror of
https://github.com/moodle/moodle.git
synced 2025-01-19 14:27:22 +01:00
e452210a18
1/ email notification when course requested 2/ course request capability so that we can limit who can request new course 3/ list of my pending course requests on the request form Implemented in 1.9 by Petr Skoda, and reviewed and merged to HEAD by me.
101 lines
4.5 KiB
PHP
101 lines
4.5 KiB
PHP
<?php // $Id$
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
// //
|
|
// NOTICE OF COPYRIGHT //
|
|
// //
|
|
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
|
|
// http://moodle.org //
|
|
// //
|
|
// Copyright (C) 1999 onwards Martin Dougiamas http://dougiamas.com //
|
|
// //
|
|
// This program is free software; you can redistribute it and/or modify //
|
|
// it under the terms of the GNU General Public License as published by //
|
|
// the Free Software Foundation; either version 2 of the License, or //
|
|
// (at your option) any later version. //
|
|
// //
|
|
// This program is distributed in the hope that it will be useful, //
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
|
// GNU General Public License for more details: //
|
|
// //
|
|
// http://www.gnu.org/copyleft/gpl.html //
|
|
// //
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
/**
|
|
* Allows a user to request a course be created for them.
|
|
*
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
|
|
* @package course
|
|
*//** */
|
|
|
|
require_once(dirname(__FILE__) . '/../config.php');
|
|
require_once($CFG->dirroot . '/course/request_form.php');
|
|
|
|
/// Where we came from. Used in a number of redirects.
|
|
$returnurl = $CFG->wwwroot . '/course/index.php';
|
|
|
|
/// Check permissions.
|
|
require_login();
|
|
if (isguestuser()) {
|
|
print_error('guestsarenotallowed', '', $returnurl);
|
|
}
|
|
if (empty($CFG->enablecourserequests)) {
|
|
print_error('courserequestdisabled', '', $returnurl);
|
|
}
|
|
$systemcontext = get_context_instance(CONTEXT_SYSTEM);
|
|
require_capability('moodle/course:request', $systemcontext);
|
|
|
|
/// Set up the form.
|
|
$requestform = new course_request_form($CFG->wwwroot . '/course/request.php');
|
|
|
|
$strtitle = get_string('courserequest');
|
|
|
|
/// Standard form processing if statement.
|
|
if ($requestform->is_cancelled()){
|
|
redirect($returnurl);
|
|
|
|
} else if ($data = $requestform->get_data()) {
|
|
print_header($strtitle, $strtitle, build_navigation($strtitle), $requestform->focus());
|
|
print_heading($strtitle);
|
|
|
|
/// Record the request.
|
|
$data->requester = $USER->id;
|
|
if (!$DB->insert_record('course_request', $data)) {
|
|
print_error('errorsavingrequest', '', $returnurl);
|
|
}
|
|
|
|
/// Notify the admin if required.
|
|
if ($CFG->courserequestnotify) {
|
|
if ($user = $user = $DB->get_record('user', array('username' => $CFG->courserequestnotify,
|
|
'mnethostid' => $CFG->mnet_localhost_id))) {
|
|
$eventdata = new object();
|
|
$eventdata->modulename = 'moodle';
|
|
$eventdata->component = 'course';
|
|
$eventdata->name = 'courserequested';
|
|
$eventdata->userfrom = $USER;
|
|
$eventdata->userto = $user;
|
|
$eventdata->subject = get_string('courserequest');
|
|
$a = new object();
|
|
$a->link = "$CFG->wwwroot/course/pending.php";
|
|
$a->user = fullname($USER);
|
|
$eventdata->fullmessage = get_string('courserequestnotifyemail', 'admin', $a);
|
|
$eventdata->fullmessageformat = FORMAT_PLAIN;
|
|
$eventdata->fullmessagehtml = '';
|
|
$eventdata->smallmessage = '';
|
|
events_trigger('message_send', $eventdata);
|
|
}
|
|
}
|
|
|
|
/// and redirect back to the course listing.
|
|
notice(get_string('courserequestsuccess'), $returnurl);
|
|
}
|
|
|
|
/// Show the request form.
|
|
print_header($strtitle, $strtitle, build_navigation($strtitle), $requestform->focus());
|
|
print_heading($strtitle);
|
|
$requestform->display();
|
|
print_footer();
|
|
|
|
?>
|