<?php

namespace enrol_weeklyhours;

require '../../config.php';
require_once 'registration_form.php';
global $PAGE, $OUTPUT, $DB;
$course_id = required_param('courseid', PARAM_INT);
$course = $DB->get_record('course', array('id' => $course_id));
$PAGE->set_pagelayout('admin');
$PAGE->set_url('/enrol/weeklyhours/registration.php', array('courseid' => $course_id));
$mform = new registration_form();
if ($mform->is_cancelled()) {
    //TODO Handle form cancel operation, if cancel button is present on form
} else {
    if ($data = $mform->get_data()) {
        //TODO In this case you process validated data. $mform->get_data() returns data posted in form.
    } else {
        echo $OUTPUT->header();
        echo $OUTPUT->heading($course->fullname);
        $mform->display();
        echo $OUTPUT->footer();
    }
}
    echo $OUTPUT->box_start();
    $logout = new single_button(new moodle_url($CFG->httpswwwroot . '/local/obu_application/logout.php', array('sesskey' => sesskey(), 'loginpage' => 1)), get_string('logout'), 'post');
    $continue = new single_button($home, get_string('cancel'), 'get');
    echo $OUTPUT->confirm(get_string('cannotsignup', 'error', fullname($USER)), $logout, $continue);
    echo $OUTPUT->box_end();
    echo $OUTPUT->footer();
    exit;
}
include './signup_form.php';
$counties = get_counties();
$parameters = ['counties' => $counties];
$mform = new registration_form(null, $parameters);
if ($mform->is_cancelled()) {
    redirect($login);
} else {
    if ($user = $mform->get_data()) {
        if (strpos($user->email, '@brookes.ac.uk') !== false) {
            $message = get_string('preregistered', 'local_obu_application');
        } else {
            $message = '';
            $user->confirmed = 0;
            $user->lang = current_language();
            $user->firstaccess = time();
            $user->timecreated = time();
            $user->mnethostid = $CFG->mnet_localhost_id;
            $user->secret = random_string(15);
            $user->auth = 'email';
            // Initialize alternate name fields to empty strings.
            $namefields = array_diff(get_all_user_name_fields(), useredit_get_required_name_fields());
            foreach ($namefields as $namefield) {
                $user->{$namefield} = '';