Index: request.php =================================================================== RCS file: /cvsroot/moodle/moodle/course/request.php,v retrieving revision 1.4 diff -u -r1.4 request.php --- request.php 17 May 2006 16:47:45 -0000 1.4 +++ request.php 16 Oct 2006 08:39:00 -0000 @@ -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($course); + + exit; + ?> \ No newline at end of file