2009-09-25 05:24:13 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
// This file is part of Moodle - http://moodle.org/
|
|
|
|
//
|
|
|
|
// Moodle 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 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// Moodle 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.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
2008-12-05 08:56:54 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Allows a user to request a course be created for them.
|
|
|
|
*
|
2009-09-25 05:24:13 +00:00
|
|
|
* @copyright 1999 Martin Dougiamas http://dougiamas.com
|
|
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
2008-12-05 08:56:54 +00:00
|
|
|
* @package course
|
2009-09-25 05:24:13 +00:00
|
|
|
*/
|
|
|
|
|
2016-02-26 17:47:58 +11:00
|
|
|
require_once(__DIR__ . '/../config.php');
|
2009-11-04 06:14:06 +00:00
|
|
|
require_once($CFG->dirroot . '/course/lib.php');
|
2009-09-25 05:24:13 +00:00
|
|
|
require_once($CFG->dirroot . '/course/request_form.php');
|
2008-12-05 08:56:54 +00:00
|
|
|
|
2013-10-04 12:59:32 +13:00
|
|
|
// Where we came from. Used in a number of redirects.
|
|
|
|
$url = new moodle_url('/course/request.php');
|
|
|
|
$return = optional_param('return', null, PARAM_ALPHANUMEXT);
|
2019-09-23 16:37:23 +02:00
|
|
|
$categoryid = optional_param('category', null, PARAM_INT);
|
2013-10-04 12:59:32 +13:00
|
|
|
if ($return === 'management') {
|
|
|
|
$url->param('return', $return);
|
|
|
|
$returnurl = new moodle_url('/course/management.php', array('categoryid' => $CFG->defaultrequestcategory));
|
|
|
|
} else {
|
|
|
|
$returnurl = new moodle_url('/course/index.php');
|
|
|
|
}
|
2008-12-05 08:56:54 +00:00
|
|
|
|
2013-10-04 12:59:32 +13:00
|
|
|
$PAGE->set_url($url);
|
2010-12-30 15:48:50 +00:00
|
|
|
|
2013-10-04 12:59:32 +13:00
|
|
|
// Check permissions.
|
2014-12-01 14:36:06 +08:00
|
|
|
require_login(null, false);
|
2009-09-25 05:24:13 +00:00
|
|
|
if (isguestuser()) {
|
|
|
|
print_error('guestsarenotallowed', '', $returnurl);
|
|
|
|
}
|
|
|
|
if (empty($CFG->enablecourserequests)) {
|
|
|
|
print_error('courserequestdisabled', '', $returnurl);
|
|
|
|
}
|
2019-09-23 16:37:23 +02:00
|
|
|
|
2019-10-14 12:16:31 +02:00
|
|
|
if ($CFG->lockrequestcategory) {
|
|
|
|
// Course request category is locked, user will always request in the default request category.
|
2019-09-23 16:37:23 +02:00
|
|
|
$categoryid = null;
|
|
|
|
} else if (!$categoryid) {
|
|
|
|
// Category selection is enabled but category is not specified.
|
|
|
|
// Find a category where user has capability to request courses (preferably the default category).
|
|
|
|
$list = core_course_category::make_categories_list('moodle/course:request');
|
|
|
|
$categoryid = array_key_exists($CFG->defaultrequestcategory, $list) ? $CFG->defaultrequestcategory : key($list);
|
|
|
|
}
|
|
|
|
|
|
|
|
$context = context_coursecat::instance($categoryid ?: $CFG->defaultrequestcategory);
|
2010-12-30 15:48:50 +00:00
|
|
|
$PAGE->set_context($context);
|
|
|
|
require_capability('moodle/course:request', $context);
|
2006-10-17 11:38:46 +00:00
|
|
|
|
2013-10-04 12:59:32 +13:00
|
|
|
// Set up the form.
|
2019-09-23 16:37:23 +02:00
|
|
|
$data = $categoryid ? (object)['category' => $categoryid] : null;
|
|
|
|
$data = course_request::prepare($data);
|
2019-04-03 02:42:45 +02:00
|
|
|
$requestform = new course_request_form($url);
|
2009-11-04 06:14:06 +00:00
|
|
|
$requestform->set_data($data);
|
2006-10-17 11:38:46 +00:00
|
|
|
|
2009-09-25 05:24:13 +00:00
|
|
|
$strtitle = get_string('courserequest');
|
2009-11-04 06:14:06 +00:00
|
|
|
$PAGE->set_title($strtitle);
|
2022-02-22 12:03:32 +08:00
|
|
|
$coursecategory = core_course_category::get($categoryid, MUST_EXIST, true);
|
|
|
|
$PAGE->set_heading($coursecategory->get_formatted_name());
|
|
|
|
$PAGE->set_primary_active_tab('home');
|
2008-12-10 02:57:41 +00:00
|
|
|
|
2013-10-04 12:59:32 +13:00
|
|
|
// Standard form processing if statement.
|
2009-09-25 05:24:13 +00:00
|
|
|
if ($requestform->is_cancelled()){
|
|
|
|
redirect($returnurl);
|
2009-09-03 08:47:24 +00:00
|
|
|
|
2009-11-04 08:11:02 +00:00
|
|
|
} else if ($data = $requestform->get_data()) {
|
2009-11-04 06:14:06 +00:00
|
|
|
$request = course_request::create($data);
|
2009-09-25 05:24:13 +00:00
|
|
|
|
2013-10-04 12:59:32 +13:00
|
|
|
// And redirect back to the course listing.
|
2009-09-25 05:24:13 +00:00
|
|
|
notice(get_string('courserequestsuccess'), $returnurl);
|
|
|
|
}
|
|
|
|
|
2022-02-22 12:03:32 +08:00
|
|
|
$categoryurl = new moodle_url('/course/index.php');
|
|
|
|
if ($categoryid) {
|
|
|
|
$categoryurl->param('categoryid', $categoryid);
|
|
|
|
}
|
|
|
|
navigation_node::override_active_url($categoryurl);
|
|
|
|
|
2009-09-25 05:24:13 +00:00
|
|
|
$PAGE->navbar->add($strtitle);
|
|
|
|
echo $OUTPUT->header();
|
|
|
|
echo $OUTPUT->heading($strtitle);
|
2009-11-04 06:14:06 +00:00
|
|
|
// Show the request form.
|
2009-09-25 05:24:13 +00:00
|
|
|
$requestform->display();
|
2010-12-30 15:48:50 +00:00
|
|
|
echo $OUTPUT->footer();
|