MDL-11328 Added the missing variable
[moodle-pu.git] / course / request_form.php
blobab40d4b20d2c1f14d60e41b1fa020dd1e5507b99
1 <?php // $Id$
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) {
35 $errors = array();
36 $foundcourses = null;
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);
46 } else {
47 $foundcourses = $foundreqcourses;
51 if (!empty($foundcourses)) {
53 if (!empty($foundcourses)) {
54 foreach ($foundcourses as $foundcourse) {
55 if (isset($foundcourse->requester) && $foundcourse->requester) {
56 $pending = 1;
57 $foundcoursenames[] = $foundcourse->fullname.' [*]';
58 } else {
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');
70 if (0 == count($errors)){
71 return true;
72 } else {
73 return $errors;