Exemplo n.º 1
0
function update_authoriser($form, $data, $authoriser_id)
{
    // Update the stored authorisation requests
    read_form_auths($data->id, $auth);
    if ($authoriser_id == 0) {
        delete_form_auths($auth);
    } else {
        $auth->authoriser = $authoriser_id;
        $auth->request_date = time();
        write_form_auths($auth);
    }
    // Determine the URL to use to link to the form
    $program = new moodle_url('/local/obu_forms/process.php') . '?id=' . $data->id;
    // Email the new status to the author and to Student Central (if not the next authoriser)
    $author = get_complete_user_data('id', $data->author);
    $sc = get_complete_user_data('username', 'csa');
    $sc_id = $sc->id;
    if (!$form->modular) {
        // Use the default CSA Team contact and notification details (PG)
        $sc_contact = $sc;
        $sc_notifications = $sc;
    } else {
        // Use the SCAT contact and notification details (UMP)
        $sc_contact = get_complete_user_data('username', 'scat');
        $sc_notifications = get_complete_user_data('username', 'scat_notifications');
    }
    // Add email headers to help prevent auto-responders
    $author->customheaders = array('Precedence: Bulk', 'X-Auto-Response-Suppress: All', 'Auto-Submitted: auto-generated');
    $sc_contact->customheaders = array('Precedence: Bulk', 'X-Auto-Response-Suppress: All', 'Auto-Submitted: auto-generated');
    get_form_status($author->id, $form, $data, $text, $button_text);
    // get the status from the author'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'] . ']';
        }
    }
    $html = '<h4><a href="' . $program . '">' . $form->formref . ': ' . $form->name . $student_number . '</a></h4>' . $text;
    email_to_user($author, $sc_contact, 'The Status of Your Form ' . $form->formref . $student_number, html_to_text($html), $html);
    if ($authoriser_id != $sc_id) {
        get_form_status($sc_id, $form, $data, $text, $button_text);
        // get the status from the perspective of Student Central
        $html = '<h4><a href="' . $program . '">' . $form->formref . ': ' . $form->name . $student_number . '</a></h4>' . $text;
        email_to_user($sc_notifications, $author, 'Form ' . $form->formref . $student_number . ' Status Update (' . $author->username . ')', html_to_text($html), $html);
    }
    // Notify the next authoriser (if there is one)
    if ($authoriser_id) {
        if ($authoriser_id == $sc_id) {
            $authoriser = $sc_notifications;
        } else {
            $authoriser = get_complete_user_data('id', $authoriser_id);
        }
        if ($authoriser->username != 'csa-tbd') {
            // No notification possible if authoriser TBD
            $form_link = '<a href="' . $program . '">' . $form->formref . ' ' . get_string('form_title', 'local_obu_forms') . $student_number . '</a>';
            $email_link = '<a href="mailto:' . $sc_contact->email . '?Subject=' . get_string('auths', 'local_obu_forms') . '" target="_top">' . $sc_contact->email . '</a>';
            $html = get_string('request_authorisation', 'local_obu_forms', array('form' => $form_link, 'name' => $sc_contact->alternatename, 'phone' => $sc_contact->phone1, 'email' => $email_link));
            email_to_user($authoriser, $author, 'Request for Form ' . $form->formref . $student_number . ' Authorisation (' . $author->username . ')', html_to_text($html), $html);
        }
    }
}
$heading = get_string('auths_title', 'local_obu_forms');
$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);
$auths = get_form_auths($authoriser_id);
// Get outstanding authorisation requests
foreach ($auths as $auth) {
    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
    if (is_manager($form)) {
        get_form_status($USER->id, $form, $data, $text, $button);
        // Get the authorisation trail and the next action (from the user's perspective)
        echo '<h4><a href="' . $process . '?id=' . $data->id . '">' . $form->formref . ': ' . $form->name . '</a></h4>';
        echo $text . '<' . $form->formref . '>';
        if ($data->authorisation_state == 0) {
            // Not yet finally approved or rejected
            echo '<p>VALID</p>';
        } else {
            delete_form_auths($auth);
            echo '<p>*** PURGED ***</p>';
        }
    }
}
echo $OUTPUT->footer();