function update_workflow($authorised = true, $comment = null) { global $form, $record, $fields; // Update the form data record $authoriser_id = 0; if ($record->authorisation_level == 0) { // Being submitted $authoriser_id = get_authoriser($record->author, $form->modular, $form->auth_1_role, $fields); $record->auth_1_id = $authoriser_id; if ($authoriser_id != 0) { $record->authorisation_level = 1; } else { // Skip the level (OK for some roles) $authoriser_id = get_authoriser($record->author, $form->modular, $form->auth_2_role, $fields); $record->auth_2_id = $authoriser_id; $record->authorisation_level = 2; } } else { if ($record->authorisation_level == 1) { $record->auth_1_notes = $comment; $record->auth_1_date = time(); if (!$authorised) { $record->authorisation_state = 1; // Rejected } else { if ($form->auth_2_role == 0) { $record->authorisation_state = 2; // It ends here } else { $authoriser_id = get_authoriser($record->author, $form->modular, $form->auth_2_role, $fields); $record->auth_2_id = $authoriser_id; if ($authoriser_id != 0) { $record->authorisation_level = 2; } else { // Skip the level (OK for some roles) $authoriser_id = get_authoriser($record->author, $form->modular, $form->auth_3_role, $fields); $record->auth_3_id = $authoriser_id; $record->authorisation_level = 3; } } } } else { if ($record->authorisation_level == 2) { $record->auth_2_notes = $comment; $record->auth_2_date = time(); if (!$authorised) { $record->authorisation_state = 1; // Rejected } else { if ($form->auth_3_role == 0) { $record->authorisation_state = 2; // It ends here } else { $authoriser_id = get_authoriser($record->author, $form->modular, $form->auth_3_role, $fields); $record->auth_3_id = $authoriser_id; if ($authoriser_id != 0) { $record->authorisation_level = 3; } else { // Skip the level (OK for some roles) $authoriser_id = get_authoriser($record->author, $form->modular, $form->auth_4_role, $fields); $record->auth_4_id = $authoriser_id; $record->authorisation_level = 4; } } } } else { if ($record->authorisation_level == 3) { $record->auth_3_notes = $comment; $record->auth_3_date = time(); if (!$authorised) { $record->authorisation_state = 1; // Rejected } else { if ($form->auth_4_role == 0) { $record->authorisation_state = 2; // It ends here } else { $authoriser_id = get_authoriser($record->author, $form->modular, $form->auth_4_role, $fields); $record->auth_4_id = $authoriser_id; if ($authoriser_id != 0) { $record->authorisation_level = 4; } else { // Skip the level (OK for some roles) $authoriser_id = get_authoriser($record->author, $form->modular, $form->auth_5_role, $fields); $record->auth_5_id = $authoriser_id; $record->authorisation_level = 5; } } } } else { if ($record->authorisation_level == 4) { $record->auth_4_notes = $comment; $record->auth_4_date = time(); if (!$authorised) { $record->authorisation_state = 1; // Rejected } else { if ($form->auth_5_role == 0) { $record->authorisation_state = 2; // It ends here } else { $authoriser_id = get_authoriser($record->author, $form->modular, $form->auth_5_role, $fields); $record->auth_5_id = $authoriser_id; $record->authorisation_level = 5; } } } else { $record->auth_5_notes = $comment; $record->auth_5_date = time(); if (!$authorised) { $record->authorisation_state = 1; // Rejected } else { $record->authorisation_state = 2; // It ends here } } } } } } save_form_data($record, $fields); // Update the stored authorisation requests and send notification emails update_authoriser($form, $record, $authoriser_id); }
$value = $addition_reason[$value]; break; case 'deletion_reason': $value = $deletion_reason[$value]; break; default: } } $fields[$key] = $value; } $record = new stdClass(); $record->id = $data_id; $record->author = $USER->id; $record->template_id = $template->id; $record->date = time(); $record->authorisation_state = 0; // Awaiting submission/authorisation... $record->authorisation_level = 0; // ...by author $data_id = save_form_data($record, $fields); redirect($process_url . '?id=' . $data_id); // Perform initial form processing } } echo $OUTPUT->header(); if ($message) { notice($message, $home); } else { $mform->display(); } echo $OUTPUT->footer();