// pass validation, either case display the form echo $OUTPUT->header(); echo $OUTPUT->heading_with_help(get_string('LBL_IMPORT_TITLE', local_userenrols_plugin::PLUGIN_NAME), 'HELP_PAGE_IMPORT', 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}; $role_id = $data->metacourse ? 0 : intval($formdata->{local_userenrols_plugin::FORMID_ROLE_ID}); $group_assign = intval($formdata->{local_userenrols_plugin::FORMID_GROUP}); $group_id = intval($formdata->{local_userenrols_plugin::FORMID_GROUP_ID}); $group_create = intval($formdata->{local_userenrols_plugin::FORMID_GROUP_CREATE}); // 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::import_file($COURSE, $manual_enrol_instance, $user_id_field, $role_id, (bool) $group_assign, $group_id, (bool) $group_create, 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_IMPORT_TITLE', local_userenrols_plugin::PLUGIN_NAME), 'HELP_PAGE_IMPORT', local_userenrols_plugin::PLUGIN_NAME); // Output the processing result echo $OUTPUT->box(nl2br($result)); echo $OUTPUT->continue_button($groups_url); echo $OUTPUT->footer(); }