moodle/course/request_form.php

79 lines
2.9 KiB
PHP
Raw Normal View History

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
class course_request_form extends moodleform {
function definition() {
2006-11-09 21:58:12 +00:00
$mform =& $this->_form;
2006-11-09 21:58:12 +00:00
$mform->addElement('text', 'fullname', get_string('fullname'), 'maxlength="254" size="50"');
$mform->addRule('fullname', get_string('missingshortname'), 'required', null, 'client');
$mform->setType('fullname', PARAM_TEXT);
2006-11-09 21:58:12 +00:00
$mform->addElement('text', 'shortname', get_string('shortname'), 'maxlength="15" size="10"');
$mform->addRule('shortname', get_string('missingfullname'), 'required', null, 'client');
$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');
$mform->setType('summary', PARAM_RAW);
$mform->setHelpButton('summary', array('text', get_string('helptext')));
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');
$mform->setType('reason', PARAM_TEXT);
2006-11-09 21:58:12 +00:00
$mform->addElement('text', 'password', get_string('enrolmentkey'), 'size="25"');
$mform->setType('password', PARAM_RAW);
2006-10-17 11:38:46 +00:00
* Added setAdvanced functionality see http://docs.moodle.org/en/Development:lib/formslib.php_setAdvanced * Added MoodleQuickForm method closeHeaderBefore($elementName); http://docs.moodle.org/en/Development:lib/formslib.php_Form_Definition#Use_Fieldsets_to_group_Form_Elements * Added moodleform method add_action_buttons(); see http://docs.moodle.org/en/Development:lib/formslib.php_Form_Definition#add_action_buttons.28.24cancel_.3D_true.2C_.24revert_.3D_true.2C_.24submitlabel.3Dnull.29.3B * is_cancelled method added to moodleform http://docs.moodle.org/en/Development:lib/formslib.php_Usage#Basic_Usage_in_A_Normal_Page * added hidden labels to elements within groups such as the date_selector select boxes and other elements in 'groups' * quiz/mod.html migrated to formslib * glossary/edit.html migrated to formslib * extended registerNoSubmitButton() functionality to automatically add js to onclick to bypass client side js input validation. * added no_submit_button_pressed() function that can be used in a similar way to is_cancelled() as a test in the main script to see if some button in the page has been pressed that is a submit button that is used for some dynamic functionality within the form and not to submit the data for the whole form. * added new condition for disabledIf which allows to disable another form element if no options are selected from within a select element. * added default 'action' for moodleform - strip_querystring(qualified_me()) http://docs.moodle.org/en/Development:lib/formslib.php_Usage#Basic_Usage_in_A_Normal_Page
2006-12-19 07:03:08 +00:00
$this->add_action_buttons();
}
function validation($data) {
2006-11-09 21:58:12 +00:00
$errors = array();
$foundcourses = null;
$foundreqcourses = null;
if (!empty($data['shortname'])) {
2006-11-09 21:58:12 +00:00
$foundcourses = get_records('course', 'shortname', $data['shortname']);
$foundreqcourses = get_records('course_request', 'shortname', $data['shortname']);
}
if (!empty($foundreqcourses)) {
if (!empty($foundcourses)) {
2006-11-09 21:58:12 +00:00
$foundcourses = array_merge($foundcourses, $foundreqcourses);
} else {
$foundcourses = $foundreqcourses;
}
}
if (!empty($foundcourses)) {
2006-10-17 11:38:46 +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 {
$foundcoursenames[] = $foundcourse->fullname;
}
}
$foundcoursenamestring = addslashes(implode(',', $foundcoursenames));
2006-11-09 21:58:12 +00:00
$errors['shortname'] = get_string('shortnametaken', '', $foundcoursenamestring);
if (!empty($pending)) {
2006-11-09 21:58:12 +00:00
$errors['shortname'] .= get_string('starpending');
}
}
}
2006-11-09 21:58:12 +00:00
if (0 == count($errors)){
return true;
2006-11-09 21:58:12 +00:00
} else {
return $errors;
}
}
}
?>