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 * Forms associated with requesting courses, and having requests approved.
28 * Note that several related forms are defined in this one file.
30 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
34 if (!defined('MOODLE_INTERNAL')) {
35 die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page
38 require_once($CFG->libdir
.'/formslib.php');
41 * A form for a user to request a course.
43 class course_request_form
extends moodleform
{
44 function definition() {
45 global $CFG, $DB, $USER;
47 $mform =& $this->_form
;
49 if ($pending = $DB->get_records('course_request', array('requester' => $USER->id
))) {
50 $mform->addElement('header', 'pendinglist', get_string('coursespending'));
52 foreach ($pending as $cp) {
53 $list[] = format_string($cp->fullname
);
55 $list = implode(', ', $list);
56 $mform->addElement('static', 'pendingcourses', get_string('courses'), $list);
59 $mform->addElement('header','coursedetails', get_string('courserequestdetails'));
61 $mform->addElement('text', 'fullname', get_string('fullnamecourse'), 'maxlength="254" size="50"');
62 $mform->addHelpButton('fullname', 'fullnamecourse');
63 $mform->addRule('fullname', get_string('missingfullname'), 'required', null, 'client');
64 $mform->setType('fullname', PARAM_TEXT
);
66 $mform->addElement('text', 'shortname', get_string('shortnamecourse'), 'maxlength="100" size="20"');
67 $mform->addHelpButton('shortname', 'shortnamecourse');
68 $mform->addRule('shortname', get_string('missingshortname'), 'required', null, 'client');
69 $mform->setType('shortname', PARAM_TEXT
);
71 if (!empty($CFG->requestcategoryselection
)) {
72 $displaylist = array();
73 $parentlist = array();
74 make_categories_list($displaylist, $parentlist, '');
75 $mform->addElement('select', 'category', get_string('category'), $displaylist);
76 $mform->setDefault('category', $CFG->defaultrequestcategory
);
77 $mform->addHelpButton('category', 'category');
80 $mform->addElement('editor', 'summary_editor', get_string('summary'), null, course_request
::summary_editor_options());
81 $mform->addHelpButton('summary_editor', 'coursesummary');
82 $mform->setType('summary_editor', PARAM_RAW
);
84 $mform->addElement('header','requestreason', get_string('courserequestreason'));
86 $mform->addElement('textarea', 'reason', get_string('courserequestsupport'), array('rows'=>'15', 'cols'=>'50'));
87 $mform->addRule('reason', get_string('missingreqreason'), 'required', null, 'client');
88 $mform->setType('reason', PARAM_TEXT
);
90 $this->add_action_buttons(true, get_string('requestcourse'));
93 function validation($data, $files) {
96 $errors = parent
::validation($data, $files);
98 $foundreqcourses = null;
100 if (!empty($data['shortname'])) {
101 $foundcourses = $DB->get_records('course', array('shortname'=>$data['shortname']));
102 $foundreqcourses = $DB->get_records('course_request', array('shortname'=>$data['shortname']));
104 if (!empty($foundreqcourses)) {
105 if (!empty($foundcourses)) {
106 $foundcourses = array_merge($foundcourses, $foundreqcourses);
108 $foundcourses = $foundreqcourses;
112 if (!empty($foundcourses)) {
113 foreach ($foundcourses as $foundcourse) {
114 if (!empty($foundcourse->requester
)) {
116 $foundcoursenames[] = $foundcourse->fullname
.' [*]';
118 $foundcoursenames[] = $foundcourse->fullname
;
121 $foundcoursenamestring = implode(',', $foundcoursenames);
123 $errors['shortname'] = get_string('shortnametaken', '', $foundcoursenamestring);
124 if (!empty($pending)) {
125 $errors['shortname'] .= get_string('starpending');
134 * A form for an administrator to reject a course request.
136 class reject_request_form
extends moodleform
{
137 function definition() {
138 $mform =& $this->_form
;
140 $mform->addElement('hidden', 'reject', 0);
141 $mform->setType('reject', PARAM_INT
);
143 $mform->addElement('header','coursedetails', get_string('coursereasonforrejecting'));
145 $mform->addElement('textarea', 'rejectnotice', get_string('coursereasonforrejectingemail'), array('rows'=>'15', 'cols'=>'50'));
146 $mform->addRule('rejectnotice', get_string('missingreqreason'), 'required', null, 'client');
147 $mform->setType('rejectnotice', PARAM_TEXT
);
149 $this->add_action_buttons(true, get_string('reject'));