2009-11-04 06:14:06 +00:00
|
|
|
<?php
|
2006-11-09 21:58:12 +00:00
|
|
|
|
2008-12-05 08:56:54 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
// //
|
|
|
|
// 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 //
|
|
|
|
// //
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Forms associated with requesting courses, and having requests approved.
|
|
|
|
* Note that several related forms are defined in this one file.
|
|
|
|
*
|
|
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
|
|
|
|
* @package course
|
2009-11-04 06:14:06 +00:00
|
|
|
*/
|
2008-12-05 08:56:54 +00:00
|
|
|
|
2010-05-13 02:02:05 +00:00
|
|
|
if (!defined('MOODLE_INTERNAL')) {
|
|
|
|
die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page
|
|
|
|
}
|
|
|
|
|
2006-11-09 22:16:44 +00:00
|
|
|
require_once($CFG->libdir.'/formslib.php');
|
2013-02-21 10:37:52 +11:00
|
|
|
require_once($CFG->libdir.'/coursecatlib.php');
|
2006-11-09 21:58:12 +00:00
|
|
|
|
2008-12-05 08:56:54 +00:00
|
|
|
/**
|
|
|
|
* A form for a user to request a course.
|
|
|
|
*/
|
2006-10-17 11:08:13 +00:00
|
|
|
class course_request_form extends moodleform {
|
|
|
|
function definition() {
|
2012-08-16 14:10:39 +08:00
|
|
|
global $CFG, $DB, $USER;
|
2008-12-10 02:57:41 +00:00
|
|
|
|
2006-11-09 21:58:12 +00:00
|
|
|
$mform =& $this->_form;
|
2006-10-17 11:08:13 +00:00
|
|
|
|
2008-12-10 02:57:41 +00:00
|
|
|
if ($pending = $DB->get_records('course_request', array('requester' => $USER->id))) {
|
|
|
|
$mform->addElement('header', 'pendinglist', get_string('coursespending'));
|
|
|
|
$list = array();
|
|
|
|
foreach ($pending as $cp) {
|
|
|
|
$list[] = format_string($cp->fullname);
|
|
|
|
}
|
|
|
|
$list = implode(', ', $list);
|
|
|
|
$mform->addElement('static', 'pendingcourses', get_string('courses'), $list);
|
|
|
|
}
|
|
|
|
|
2008-12-05 08:56:54 +00:00
|
|
|
$mform->addElement('header','coursedetails', get_string('courserequestdetails'));
|
|
|
|
|
2010-05-06 18:06:05 +00:00
|
|
|
$mform->addElement('text', 'fullname', get_string('fullnamecourse'), 'maxlength="254" size="50"');
|
|
|
|
$mform->addHelpButton('fullname', 'fullnamecourse');
|
2007-06-04 12:42:17 +00:00
|
|
|
$mform->addRule('fullname', get_string('missingfullname'), 'required', null, 'client');
|
2012-05-11 15:50:09 +08:00
|
|
|
$mform->setType('fullname', PARAM_TEXT);
|
2006-10-17 11:08:13 +00:00
|
|
|
|
MDL-13481 Strings fullname and shortname are now deprecated
This is a final cleanup commit of fullname and shortname issue. All
places where these strings were detected yet have been replaced with
proper fullnamecourse or fullnameuser or some other context specific
string.
AMOS BEGIN
CPY [fullname,core],[outcomefullname,core_grades]
CPY [shortname,core],[outcomeshortname,core_grades]
CPY [name,core],[rolefullname,core_role]
CPY [shortname,core],[roleshortname,core_role]
AMOS END
2011-02-22 10:12:10 +01:00
|
|
|
$mform->addElement('text', 'shortname', get_string('shortnamecourse'), 'maxlength="100" size="20"');
|
2010-05-06 18:32:03 +00:00
|
|
|
$mform->addHelpButton('shortname', 'shortnamecourse');
|
2007-06-04 12:42:17 +00:00
|
|
|
$mform->addRule('shortname', get_string('missingshortname'), 'required', null, 'client');
|
2012-05-11 15:50:09 +08:00
|
|
|
$mform->setType('shortname', PARAM_TEXT);
|
2006-10-17 11:08:13 +00:00
|
|
|
|
2012-08-16 14:10:39 +08:00
|
|
|
if (!empty($CFG->requestcategoryselection)) {
|
2013-02-21 10:37:52 +11:00
|
|
|
$displaylist = coursecat::make_categories_list();
|
2013-05-20 09:15:01 +08:00
|
|
|
$mform->addElement('select', 'category', get_string('coursecategory'), $displaylist);
|
2012-08-16 14:10:39 +08:00
|
|
|
$mform->setDefault('category', $CFG->defaultrequestcategory);
|
2013-05-20 09:15:01 +08:00
|
|
|
$mform->addHelpButton('category', 'coursecategory');
|
2012-08-16 14:10:39 +08:00
|
|
|
}
|
|
|
|
|
2009-11-04 06:14:06 +00:00
|
|
|
$mform->addElement('editor', 'summary_editor', get_string('summary'), null, course_request::summary_editor_options());
|
2010-05-06 18:32:03 +00:00
|
|
|
$mform->addHelpButton('summary_editor', 'coursesummary');
|
2009-11-04 06:14:06 +00:00
|
|
|
$mform->setType('summary_editor', PARAM_RAW);
|
2007-01-05 04:51:46 +00:00
|
|
|
|
2008-12-05 08:56:54 +00:00
|
|
|
$mform->addElement('header','requestreason', get_string('courserequestreason'));
|
|
|
|
|
|
|
|
$mform->addElement('textarea', 'reason', get_string('courserequestsupport'), array('rows'=>'15', 'cols'=>'50'));
|
2006-11-09 21:58:12 +00:00
|
|
|
$mform->addRule('reason', get_string('missingreqreason'), 'required', null, 'client');
|
2006-10-17 11:08:13 +00:00
|
|
|
$mform->setType('reason', PARAM_TEXT);
|
|
|
|
|
2008-12-05 08:56:54 +00:00
|
|
|
$this->add_action_buttons(true, get_string('requestcourse'));
|
2006-10-17 11:08:13 +00:00
|
|
|
}
|
|
|
|
|
2007-11-23 22:15:07 +00:00
|
|
|
function validation($data, $files) {
|
2008-06-01 17:53:25 +00:00
|
|
|
global $DB;
|
|
|
|
|
2007-11-23 22:15:07 +00:00
|
|
|
$errors = parent::validation($data, $files);
|
2006-10-17 11:08:13 +00:00
|
|
|
$foundcourses = null;
|
|
|
|
$foundreqcourses = null;
|
|
|
|
|
|
|
|
if (!empty($data['shortname'])) {
|
2008-06-01 17:53:25 +00:00
|
|
|
$foundcourses = $DB->get_records('course', array('shortname'=>$data['shortname']));
|
|
|
|
$foundreqcourses = $DB->get_records('course_request', array('shortname'=>$data['shortname']));
|
2006-10-17 11:08:13 +00:00
|
|
|
}
|
|
|
|
if (!empty($foundreqcourses)) {
|
|
|
|
if (!empty($foundcourses)) {
|
2006-11-09 21:58:12 +00:00
|
|
|
$foundcourses = array_merge($foundcourses, $foundreqcourses);
|
2006-10-17 11:08:13 +00:00
|
|
|
} else {
|
|
|
|
$foundcourses = $foundreqcourses;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!empty($foundcourses)) {
|
2008-12-05 08:56:54 +00:00
|
|
|
foreach ($foundcourses as $foundcourse) {
|
|
|
|
if (!empty($foundcourse->requester)) {
|
|
|
|
$pending = 1;
|
|
|
|
$foundcoursenames[] = $foundcourse->fullname.' [*]';
|
|
|
|
} else {
|
|
|
|
$foundcoursenames[] = $foundcourse->fullname;
|
2006-10-17 11:08:13 +00:00
|
|
|
}
|
2008-12-05 08:56:54 +00:00
|
|
|
}
|
|
|
|
$foundcoursenamestring = implode(',', $foundcoursenames);
|
2006-10-17 11:08:13 +00:00
|
|
|
|
2008-12-05 08:56:54 +00:00
|
|
|
$errors['shortname'] = get_string('shortnametaken', '', $foundcoursenamestring);
|
|
|
|
if (!empty($pending)) {
|
|
|
|
$errors['shortname'] .= get_string('starpending');
|
2006-10-17 11:08:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-11-23 22:15:07 +00:00
|
|
|
return $errors;
|
2006-10-17 11:08:13 +00:00
|
|
|
}
|
2008-12-05 08:56:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A form for an administrator to reject a course request.
|
|
|
|
*/
|
|
|
|
class reject_request_form extends moodleform {
|
|
|
|
function definition() {
|
|
|
|
$mform =& $this->_form;
|
2006-10-17 11:08:13 +00:00
|
|
|
|
2008-12-05 08:56:54 +00:00
|
|
|
$mform->addElement('hidden', 'reject', 0);
|
2009-09-26 17:07:08 +00:00
|
|
|
$mform->setType('reject', PARAM_INT);
|
2008-12-05 08:56:54 +00:00
|
|
|
|
|
|
|
$mform->addElement('header','coursedetails', get_string('coursereasonforrejecting'));
|
|
|
|
|
|
|
|
$mform->addElement('textarea', 'rejectnotice', get_string('coursereasonforrejectingemail'), array('rows'=>'15', 'cols'=>'50'));
|
|
|
|
$mform->addRule('rejectnotice', get_string('missingreqreason'), 'required', null, 'client');
|
|
|
|
$mform->setType('rejectnotice', PARAM_TEXT);
|
|
|
|
|
|
|
|
$this->add_action_buttons(true, get_string('reject'));
|
|
|
|
}
|
2006-10-17 11:08:13 +00:00
|
|
|
}
|
2009-11-04 08:11:02 +00:00
|
|
|
|