/** * Hook to insert a link in settings navigation menu block * * @param settings_navigation $navigation * @param course_context $context * @return void */ function local_userenrols_extend_settings_navigation(settings_navigation $navigation, $context) { // If not in a course context, then leave if ($context == null || $context->contextlevel != CONTEXT_COURSE) { return; } // When on front page there is 'frontpagesettings' node, other // courses will have 'courseadmin' node if (null == ($courseadmin_node = $navigation->get('courseadmin'))) { // Keeps us off the front page return; } if (null == ($useradmin_node = $courseadmin_node->get('users'))) { return; } // Add our links $useradmin_node->add(get_string('IMPORT_MENU_LONG', local_userenrols_plugin::PLUGIN_NAME), local_userenrols_plugin::get_plugin_url('import', $context->instanceid), navigation_node::TYPE_SETTING, get_string('IMPORT_MENU_SHORT', local_userenrols_plugin::PLUGIN_NAME), null, new pix_icon('i/import', 'import')); $useradmin_node->add(get_string('UNENROLL_MENU_LONG', local_userenrols_plugin::PLUGIN_NAME), local_userenrols_plugin::get_plugin_url('unenroll', $context->instanceid), navigation_node::TYPE_SETTING, get_string('UNENROLL_MENU_SHORT', local_userenrols_plugin::PLUGIN_NAME), null, new pix_icon('i/export', 'export')); $useradmin_node->add(get_string('ASSIGN_MENU_LONG', local_userenrols_plugin::PLUGIN_NAME), local_userenrols_plugin::get_plugin_url('assign', $context->instanceid), navigation_node::TYPE_SETTING, get_string('ASSIGN_MENU_SHORT', local_userenrols_plugin::PLUGIN_NAME), null, new pix_icon('t/move', 'assign')); }
print_error('ERR_NO_MANUAL_ENROL', local_userenrols_plugin::PLUGIN_NAME, $course_url); } // Iterate the list of active enrol plugins looking for // the meta course plugin reset($enrols_enabled); foreach ($enrols_enabled as $enrol) { if ($enrol->enrol == 'meta') { $data->metacourse = true; $data->default_role_id = 0; break; } } // Set some options for the filepicker $file_picker_options = array('accepted_types' => array('.csv', '.txt'), 'maxbytes' => local_userenrols_plugin::MAXFILESIZE); $formdata = null; $mform = new local_userenrols_index_form(local_userenrols_plugin::get_plugin_url('import', $COURSE->id)->out(), array('data' => $data, 'options' => $file_picker_options)); if ($mform->is_cancelled()) { // POST request, but cancel button clicked, or formdata not // valid. Either event, clear out draft file area to remove // unused uploads, then send back to course view 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_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();
} // Deal breaker if (!$meta_enrols) { print_error('ERR_NO_META_ENROL', local_userenrols_plugin::PLUGIN_NAME, $course_url); } // Fix up the form. Have not determined yet whether this is a // GET or POST, but the form will be used in either case. // Fix up our customdata object to pass to the form constructor $data = new stdClass(); $data->course = $COURSE; $data->context = $PAGE->context; $data->meta_enrols = $meta_enrols; $data->groups = groups_get_all_groups($course_id); $data->group_prefs = local_userenrols_plugin::get_group_prefs($COURSE->id); $formdata = null; $mform = new local_userenrols_assign_form(local_userenrols_plugin::get_plugin_url('assign', $COURSE->id)->out(), array('data' => $data)); if ($mform->is_cancelled()) { // POST request, but cancel button clicked 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_ASSIGN_TITLE', local_userenrols_plugin::PLUGIN_NAME), 'HELP_PAGE_ASSIGN', local_userenrols_plugin::PLUGIN_NAME); $mform->display(); echo $OUTPUT->footer(); } else { // POST request, submit button clicked and formdata // passed validation, first check session spoofing require_sesskey(); // Collect the input