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 require_once($CFG->libdir
.'/formslib.php');
37 * A form for a user to request a course.
39 class course_request_form
extends moodleform
{
40 function definition() {
43 $mform =& $this->_form
;
45 if ($pending = get_records('course_request', 'requester', $USER->id
)) {
46 $mform->addElement('header', 'pendinglist', get_string('coursespending'));
48 foreach ($pending as $cp) {
49 $list[] = format_string($cp->fullname
);
51 $list = implode(', ', $list);
52 $mform->addElement('static', 'pendingcourses', get_string('courses'), $list);
55 $mform->addElement('header','coursedetails', get_string('courserequestdetails'));
57 $mform->addElement('text', 'fullname', get_string('fullname'), 'maxlength="254" size="50"');
58 $mform->setHelpButton('fullname', array('coursefullname', get_string('fullname')), true);
59 $mform->addRule('fullname', get_string('missingfullname'), 'required', null, 'client');
60 $mform->setType('fullname', PARAM_MULTILANG
);
62 $mform->addElement('text', 'shortname', get_string('shortname'), 'maxlength="15" size="20"');
63 $mform->setHelpButton('shortname', array('courseshortname', get_string('shortname')), true);
64 $mform->addRule('shortname', get_string('missingshortname'), 'required', null, 'client');
65 $mform->setType('shortname', PARAM_MULTILANG
);
67 $mform->addElement('htmleditor', 'summary', get_string('summary'), array('rows'=>'15', 'cols'=>'50'));
68 $mform->setHelpButton('summary', array('text', get_string('helptext')), true);
69 $mform->setType('summary', PARAM_RAW
);
71 $mform->addElement('passwordunmask', 'password', get_string('enrolmentkey'), 'size="25"');
72 $mform->setHelpButton('password', array('enrolmentkey', get_string('enrolmentkey')), true);
73 $mform->setDefault('password', '');
74 $mform->setType('password', PARAM_RAW
);
76 $mform->addElement('header','requestreason', get_string('courserequestreason'));
78 $mform->addElement('textarea', 'reason', get_string('courserequestsupport'), array('rows'=>'15', 'cols'=>'50'));
79 $mform->addRule('reason', get_string('missingreqreason'), 'required', null, 'client');
80 $mform->setType('reason', PARAM_TEXT
);
82 $this->add_action_buttons(true, get_string('requestcourse'));
85 function validation($data, $files) {
86 $errors = parent
::validation($data, $files);
88 $foundreqcourses = null;
90 if (!empty($data['shortname'])) {
91 $foundcourses = get_records('course', 'shortname', $data['shortname']);
92 $foundreqcourses = get_records('course_request', 'shortname', $data['shortname']);
94 if (!empty($foundreqcourses)) {
95 if (!empty($foundcourses)) {
96 $foundcourses = array_merge($foundcourses, $foundreqcourses);
98 $foundcourses = $foundreqcourses;
102 if (!empty($foundcourses)) {
103 foreach ($foundcourses as $foundcourse) {
104 if (!empty($foundcourse->requester
)) {
106 $foundcoursenames[] = $foundcourse->fullname
.' [*]';
108 $foundcoursenames[] = $foundcourse->fullname
;
111 $foundcoursenamestring = implode(',', $foundcoursenames);
113 $errors['shortname'] = get_string('shortnametaken', '', $foundcoursenamestring);
114 if (!empty($pending)) {
115 $errors['shortname'] .= get_string('starpending');
124 * A form for an administrator to reject a course request.
126 class reject_request_form
extends moodleform
{
127 function definition() {
128 $mform =& $this->_form
;
130 $mform->addElement('hidden', 'reject', 0);
131 $mform->setType('reject', PARAM_INT
);
133 $mform->addElement('header','coursedetails', get_string('coursereasonforrejecting'));
135 $mform->addElement('textarea', 'rejectnotice', get_string('coursereasonforrejectingemail'), array('rows'=>'15', 'cols'=>'50'));
136 $mform->addRule('rejectnotice', get_string('missingreqreason'), 'required', null, 'client');
137 $mform->setType('rejectnotice', PARAM_TEXT
);
139 $this->add_action_buttons(true, get_string('reject'));