2006-11-09 21:58:12 +00:00
|
|
|
<?php // $Id$
|
|
|
|
|
2006-11-09 22:16:44 +00:00
|
|
|
require_once($CFG->libdir.'/formslib.php');
|
2006-11-09 21:58:12 +00:00
|
|
|
|
2006-10-17 11:08:13 +00:00
|
|
|
class course_request_form extends moodleform {
|
|
|
|
function definition() {
|
2006-11-09 21:58:12 +00:00
|
|
|
$mform =& $this->_form;
|
2006-10-17 11:08:13 +00:00
|
|
|
|
2008-03-19 08:49:23 +00:00
|
|
|
$mform->addElement('text', 'fullname', get_string('fullnamecourse'), 'maxlength="254" size="50"');
|
2007-06-04 12:42:17 +00:00
|
|
|
$mform->addRule('fullname', get_string('missingfullname'), 'required', null, 'client');
|
2006-10-17 11:08:13 +00:00
|
|
|
$mform->setType('fullname', PARAM_TEXT);
|
|
|
|
|
2008-03-19 08:49:23 +00:00
|
|
|
$mform->addElement('text', 'shortname', get_string('shortnamecourse'), 'maxlength="100" size="20"');
|
2007-06-04 12:42:17 +00:00
|
|
|
$mform->addRule('shortname', get_string('missingshortname'), 'required', null, 'client');
|
2006-10-17 11:08:13 +00:00
|
|
|
$mform->setType('shortname', PARAM_TEXT);
|
|
|
|
|
2006-11-09 21:58:12 +00:00
|
|
|
$mform->addElement('htmleditor', 'summary', get_string('summary'), array('rows'=>'15', 'cols'=>'50'));
|
|
|
|
$mform->addRule('summary', get_string('missingsummary'), 'required', null, 'client');
|
2006-10-17 11:44:13 +00:00
|
|
|
$mform->setType('summary', PARAM_RAW);
|
2008-09-25 07:12:46 +00:00
|
|
|
$mform->setHelpButton('summary', array('text2', get_string('helptext')));
|
2007-01-05 04:51:46 +00:00
|
|
|
|
2006-10-17 11:08:13 +00:00
|
|
|
|
2006-11-09 21:58:12 +00:00
|
|
|
$mform->addElement('textarea', 'reason', get_string('courserequestreason'), array('rows'=>'15', 'cols'=>'50'));
|
|
|
|
$mform->addRule('reason', get_string('missingreqreason'), 'required', null, 'client');
|
2006-10-17 11:08:13 +00:00
|
|
|
$mform->setType('reason', PARAM_TEXT);
|
|
|
|
|
2006-11-09 21:58:12 +00:00
|
|
|
$mform->addElement('text', 'password', get_string('enrolmentkey'), 'size="25"');
|
2006-10-17 11:08:13 +00:00
|
|
|
$mform->setType('password', PARAM_RAW);
|
|
|
|
|
2006-10-17 11:38:46 +00:00
|
|
|
|
2006-12-19 07:03:08 +00:00
|
|
|
$this->add_action_buttons();
|
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)) {
|
2006-10-17 11:38:46 +00:00
|
|
|
|
2006-10-17 11:08:13 +00:00
|
|
|
if (!empty($foundcourses)) {
|
|
|
|
foreach ($foundcourses as $foundcourse) {
|
|
|
|
if (isset($foundcourse->requester) && $foundcourse->requester) {
|
|
|
|
$pending = 1;
|
|
|
|
$foundcoursenames[] = $foundcourse->fullname.' [*]';
|
2006-10-17 11:38:46 +00:00
|
|
|
} else {
|
2006-10-17 11:08:13 +00:00
|
|
|
$foundcoursenames[] = $foundcourse->fullname;
|
|
|
|
}
|
|
|
|
}
|
2008-06-01 17:53:25 +00:00
|
|
|
$foundcoursenamestring = implode(',', $foundcoursenames);
|
2006-10-17 11:08:13 +00:00
|
|
|
|
2006-11-09 21:58:12 +00:00
|
|
|
$errors['shortname'] = get_string('shortnametaken', '', $foundcoursenamestring);
|
2006-10-17 11:08:13 +00:00
|
|
|
if (!empty($pending)) {
|
2006-11-09 21:58:12 +00:00
|
|
|
$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
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2007-06-04 12:42:17 +00:00
|
|
|
?>
|