Example #1
0
            die;
        }
        if ($USER->id != $record->author) {
            // no-one else can amend your forms
            $message = get_string('form_unavailable', 'local_obu_forms');
        }
        $template = read_form_template_by_id($record->template_id);
        $form = read_form_settings($template->form_id);
    } else {
        if (isset($_REQUEST['template'])) {
            // A form being created/amended
            $template_id = $_REQUEST['template'];
            if ($template_id == 0) {
                redirect($home);
            }
            $template = read_form_template_by_id($template_id);
            $form = read_form_settings($template->form_id);
        } else {
            echo get_string('invalid_data', 'local_obu_forms');
            die;
        }
    }
}
$current_course = '';
$button_text = 'submit';
if ($form->student) {
    // A student form - the user must be enrolled in a current course (programme) of the right type in order to submit it
    $course = get_current_courses($USER->id, $form->modular);
    $current_course = current($course);
    // We're assuming only one
    if ($current_course === false) {
}
$data_id = $_REQUEST['id'];
if (!load_form_data($data_id, $record, $fields)) {
    echo get_string('invalid_data', 'local_obu_forms');
    die;
}
$home = new moodle_url('/');
$dir = $home . 'local/obu_forms/';
$program = $dir . 'process.php?id=' . $data_id;
$redirect_form = $dir . 'redirect.php?id=' . $data_id;
$PAGE->set_url($program);
$PAGE->set_context(context_system::instance());
$PAGE->set_pagelayout('standard');
$PAGE->set_heading($SITE->fullname);
$PAGE->set_title(get_string('form_title', 'local_obu_forms'));
$template = read_form_template_by_id($record->template_id);
$form = read_form_settings($template->form_id);
$PAGE->navbar->add(get_string('form', 'local_obu_forms') . ' ' . $form->formref);
$message = '';
// If not awaiting authorisation by someone, display the current status (prominently)
if ($record->authorisation_state == 0 && $record->authorisation_level == 0) {
    // Form not yet submitted
    if ($USER->id != $record->author) {
        // no-one else can look at your unsubmitted forms
        $message = get_string('form_unavailable', 'local_obu_forms');
    }
    $status_text = get_string('status_not_submitted', 'local_obu_forms');
    // For the time being, we auto-submit the form to avoid a two-stage process for the author (might change?)
    update_workflow(true);
    $status_text = '';
} else {
$PAGE->set_url($url);
$PAGE->set_pagelayout('standard');
$PAGE->set_context(context_system::instance());
$PAGE->set_title($heading);
$PAGE->set_heading($heading);
// The page contents
echo $OUTPUT->header();
echo $OUTPUT->heading($heading);
$process = $home . 'local/obu_forms/process.php';
$redirect = $home . 'local/obu_forms/redirect.php';
$auths = get_form_auths($authoriser_id);
// Get outstanding authorisation requests
foreach ($auths as $auth) {
    if ($authoriser_id != 0 || $auth->authoriser != $authoriser->id) {
        read_form_data($auth->data_id, $data);
        $template = read_form_template_by_id($data->template_id);
        $form = read_form_settings($template->form_id);
        // Check first that the user is a manager of this type of form and that it hasn't already been finally approved or rejected
        if (is_manager($form) && $data->authorisation_state == 0) {
            get_form_status($USER->id, $form, $data, $text, $button);
            // Get the authorisation trail and the next action (from the user's perspective)
            // If a staff form, extract any given student number
            $student_number = '';
            if (!$form->student) {
                load_form_fields($data, $fields);
                if (array_key_exists('student_number', $fields)) {
                    $student_number = ' [' . $fields['student_number'] . ']';
                }
            }
            echo '<h4><a href="' . $process . '?id=' . $data->id . '">' . $form->formref . ': ' . $form->name . $student_number . '</a></h4>';
            echo $text . '<' . $form->formref . '>';