get_file_storage()->delete_area_files($user_context->id, 'user', 'draft', file_get_submitted_draft_itemid(local_userenrols_plugin::FORMID_FILES)); redirect($course_url); } elseif (!$mform->is_submitted() || null == ($formdata = $mform->get_data())) { // GET request, or POST request where data did not // pass validation, either case display the form echo $OUTPUT->header(); echo $OUTPUT->heading_with_help(get_string('LBL_UNENROLL_TITLE', local_userenrols_plugin::PLUGIN_NAME), 'HELP_PAGE_UNENROLL', local_userenrols_plugin::PLUGIN_NAME); // Display the form with a filepicker echo $OUTPUT->container_start(); $mform->display(); echo $OUTPUT->container_end(); echo $OUTPUT->footer(); } else { // POST request, submit button clicked and formdata // passed validation, first check session spoofing require_sesskey(); // Collect the input $user_id_field = $formdata->{local_userenrols_plugin::FORMID_USER_ID_FIELD}; // Leave the file in the user's draft area since we // will not plan to keep it after processing $area_files = get_file_storage()->get_area_files($user_context->id, 'user', 'draft', $formdata->{local_userenrols_plugin::FORMID_FILES}, null, false); $result = local_userenrols_plugin::unenroll_file($COURSE, $user_id_field, array_shift($area_files)); // Clean up the file area get_file_storage()->delete_area_files($user_context->id, 'user', 'draft', $formdata->{local_userenrols_plugin::FORMID_FILES}); echo $OUTPUT->header(); echo $OUTPUT->heading_with_help(get_string('LBL_UNENROLL_TITLE', local_userenrols_plugin::PLUGIN_NAME), 'HELP_PAGE_UNENROLL', local_userenrols_plugin::PLUGIN_NAME); // Output the processing result echo $OUTPUT->box(nl2br($result)); echo $OUTPUT->continue_button($groups_url); echo $OUTPUT->footer(); }