From e13cc88f021b30abc45aa3f155e3fc2386006716 Mon Sep 17 00:00:00 2001 From: jamiesensei Date: Tue, 17 Oct 2006 11:08:13 +0000 Subject: [PATCH] migrated to new formslib code. Also removed $course variable which was been used in a number of places in this file but not set anywhere. --- course/request.php | 113 +++++++++------------------------------- course/request_form.php | 76 +++++++++++++++++++++++++++ 2 files changed, 102 insertions(+), 87 deletions(-) create mode 100644 course/request_form.php diff --git a/course/request.php b/course/request.php index a4d9fd2a36..009e4a7933 100644 --- a/course/request.php +++ b/course/request.php @@ -3,8 +3,11 @@ /// this allows a student to request a course be created for them. require_once('../config.php'); - + include_once $CFG->libdir.'/formslib.php'; + require_login(); + + require_once('request_form.php'); if (isguest()) { error("No guests here!"); @@ -13,104 +16,40 @@ if (empty($CFG->enablecourserequests)) { error(get_string('courserequestdisabled')); } + $strtitle = get_string('courserequest'); - print_header($strtitle,$strtitle,$strtitle); - if (($form = data_submitted()) and confirm_sesskey()) { - validate_form($form,$err) ; - - if (empty($err)) { - $form->requester = $USER->id; - - if (insert_record('course_request',$form)) { - notice(get_string('courserequestsuccess')); - } - else { - notice(get_string('courserequestfailed')); - } - print_footer(); - exit; - } else { - $form = stripslashes_safe($form); - } - - // !! no db access using data from $form beyond this point !! - } - -// print_simple_box(get_string('courserequestintro'),'center'); print_simple_box_start("center"); print_string('courserequestintro'); - include("request.html"); print_simple_box_end(); - - print_footer($course); - - if ($usehtmleditor) { - use_html_editor("summary"); - use_html_editor("reason"); - } - - exit; - - -function validate_form(&$form,&$err) { - - if (empty($form->shortname)) { - $err['shortname'] = get_string('missingshortname'); - } - if (empty($form->fullname)) { - $err['fullname'] = get_string('missingfullname'); - } - - if (empty($form->summary)) { - $err["summary"] = get_string("missingsummary"); - } - - if (empty($form->reason)) { - $err["reason"] = get_string("missingreqreason"); - } + $requestform = new course_request_form('request.php'); - $foundcourses = null; - $foundreqcourses = null; - - if (!empty($form->shortname)) { - $foundcourses = get_records("course", "shortname", $form->shortname); - $foundreqcourses = get_records("course_request", "shortname", $form->shortname); - } - if (!empty($foundreqcourses)) { - if (!empty($foundcourses)) { - $foundcourses = array_merge($foundcourses,$foundreqcourses); - } else { - $foundcourses = $foundreqcourses; - } - } + if (($data = $requestform->data_submitted())) { + + $data->requester = $USER->id; - if (!empty($foundcourses)) { - if (!empty($course->id)) { - unset($foundcourses[$course->id]); + if (insert_record('course_request',$data)) { + notice(get_string('courserequestsuccess')); } - if (!empty($foundcourses)) { - foreach ($foundcourses as $foundcourse) { - if ($foundcourse->requester) { - $pending = 1; - $foundcoursenames[] = $foundcourse->fullname.' [*]'; - } - else { - $foundcoursenames[] = $foundcourse->fullname; - } - } - $foundcoursenamestring = addslashes(implode(',', $foundcoursenames)); - - $err["shortname"] = get_string("shortnametaken", "", $foundcoursenamestring); - if (!empty($pending)) { - $err["shortname"] .= '
'.get_string('starpending'); - } + else { + notice(get_string('courserequestfailed')); } - } -} + print_footer(); + exit; + + + } + + + $requestform->display(); + + print_footer(); + + exit; + ?> \ No newline at end of file diff --git a/course/request_form.php b/course/request_form.php new file mode 100644 index 0000000000..884481276c --- /dev/null +++ b/course/request_form.php @@ -0,0 +1,76 @@ +_form; + + $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); + + $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); + + $mform->addElement('textarea','summary',get_string("summary"),array('rows'=>'15','cols'=>'50')); + $mform->addRule('summary',get_string('missingsummary'),'required', null, 'client'); + $mform->setType('summary', PARAM_TEXT); + + $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); + + $mform->addElement('text','password',get_string("enrolmentkey"),'size="25"'); + $mform->setType('password', PARAM_RAW); + + + $mform->addElement('submit','',get_string("savechanges")); + } + + function validation($data) { + $errors=array(); + $foundcourses = null; + $foundreqcourses = null; + + if (!empty($data['shortname'])) { + $foundcourses = get_records("course", "shortname", $data['shortname']); + $foundreqcourses = get_records("course_request", "shortname", $data['shortname']); + } + if (!empty($foundreqcourses)) { + if (!empty($foundcourses)) { + $foundcourses = array_merge($foundcourses,$foundreqcourses); + } else { + $foundcourses = $foundreqcourses; + } + } + + if (!empty($foundcourses)) { + + if (!empty($foundcourses)) { + foreach ($foundcourses as $foundcourse) { + if (isset($foundcourse->requester) && $foundcourse->requester) { + $pending = 1; + $foundcoursenames[] = $foundcourse->fullname.' [*]'; + } + else { + $foundcoursenames[] = $foundcourse->fullname; + } + } + $foundcoursenamestring = addslashes(implode(',', $foundcoursenames)); + + $errors["shortname"] = get_string("shortnametaken", "", $foundcoursenamestring); + if (!empty($pending)) { + $errors["shortname"] .= get_string('starpending'); + } + } + } + if (0==count($errors)){ + return true; + }else { + return $errors; + } + + } + + +} +?> \ No newline at end of file -- 2.39.5