3 require_once($CFG->libdir
.'/formslib.php');
5 class course_request_form
extends moodleform
{
6 function definition() {
7 $mform =& $this->_form
;
9 $mform->addElement('text', 'fullname', get_string('fullname'), 'maxlength="254" size="50"');
10 $mform->addRule('fullname', get_string('missingfullname'), 'required', null, 'client');
11 $mform->setType('fullname', PARAM_TEXT
);
13 $mform->addElement('text', 'shortname', get_string('shortname'), 'maxlength="100" size="20"');
14 $mform->addRule('shortname', get_string('missingshortname'), 'required', null, 'client');
15 $mform->setType('shortname', PARAM_TEXT
);
17 $mform->addElement('htmleditor', 'summary', get_string('summary'), array('rows'=>'15', 'cols'=>'50'));
18 $mform->addRule('summary', get_string('missingsummary'), 'required', null, 'client');
19 $mform->setType('summary', PARAM_RAW
);
20 $mform->setHelpButton('summary', array('text', get_string('helptext')));
23 $mform->addElement('textarea', 'reason', get_string('courserequestreason'), array('rows'=>'15', 'cols'=>'50'));
24 $mform->addRule('reason', get_string('missingreqreason'), 'required', null, 'client');
25 $mform->setType('reason', PARAM_TEXT
);
27 $mform->addElement('text', 'password', get_string('enrolmentkey'), 'size="25"');
28 $mform->setType('password', PARAM_RAW
);
31 $this->add_action_buttons();
34 function validation($data, $files) {
35 $errors = parent
::validation($data, $files);
37 $foundreqcourses = null;
39 if (!empty($data['shortname'])) {
40 $foundcourses = get_records('course', 'shortname', $data['shortname']);
41 $foundreqcourses = get_records('course_request', 'shortname', $data['shortname']);
43 if (!empty($foundreqcourses)) {
44 if (!empty($foundcourses)) {
45 $foundcourses = array_merge($foundcourses, $foundreqcourses);
47 $foundcourses = $foundreqcourses;
51 if (!empty($foundcourses)) {
53 if (!empty($foundcourses)) {
54 foreach ($foundcourses as $foundcourse) {
55 if (isset($foundcourse->requester
) && $foundcourse->requester
) {
57 $foundcoursenames[] = $foundcourse->fullname
.' [*]';
59 $foundcoursenames[] = $foundcourse->fullname
;
62 $foundcoursenamestring = addslashes(implode(',', $foundcoursenames));
64 $errors['shortname'] = get_string('shortnametaken', '', $foundcoursenamestring);
65 if (!empty($pending)) {
66 $errors['shortname'] .= get_string('starpending');