if (!empty($approve) and confirm_sesskey()) { /// Load the request. $course = new course_request($approve); $courseid = $course->approve(); if ($courseid !== false) { redirect($CFG->wwwroot . '/course/edit.php?id=' . $courseid); } else { print_error('courseapprovedfailed'); } } /// Process rejection of a course. if (!empty($reject)) { // Load the request. $course = new course_request($reject); // Prepare the form. $rejectform = new reject_request_form($baseurl); $default = new stdClass(); $default->reject = $course->id; $rejectform->set_data($default); /// Standard form processing if statement. if ($rejectform->is_cancelled()) { redirect($baseurl); } else { if ($data = $rejectform->get_data()) { /// Reject the request $course->reject($data->rejectnotice); /// Redirect back to the course listing. redirect($baseurl, get_string('courserejected')); } } /// Display the form for giving a reason for rejecting the request.
$a->url = $CFG->wwwroot . '/course/view.php?id=' . $courseid; $a->teacher = $course->teacher; email_to_user($user, $USER, get_string('courseapprovedsubject'), get_string('courseapprovedemail', 'moodle', $a)); redirect($CFG->wwwroot . '/course/edit.php?id=' . $courseid); } else { print_error('courseapprovedfailed'); } } /// Process rejection of a course. if (!empty($reject)) { /// Load the request. if (!($course = get_record('course_request', 'id', $reject))) { print_error('unknowncourserequest'); } /// Prepare the form. $rejectform = new reject_request_form($baseurl); $default = new stdClass(); $default->reject = $reject; $rejectform->set_data($default); /// Standard form processing if statement. if ($rejectform->is_cancelled()) { redirect($baseurl); } else { if ($data = $rejectform->get_data()) { /// Send an email to the requester. $user = get_record('user', 'id', $course->requester); email_to_user($user, $USER, get_string('courserejectsubject'), get_string('courserejectemail', '', $data->rejectnotice)); /// Delete the request delete_records('course_request', 'id', $course->id); /// Redirect back to the course listing. redirect($baseurl, get_string('courserejected'));