//we get the context from the category object. if ($contexts === null) { // need to get the course from the chosen category $contexts = new question_edit_contexts(get_context_instance_by_id($category->contextid)); $thiscontext = $contexts->lowest(); if ($thiscontext->contextlevel == CONTEXT_COURSE) { require_login($thiscontext->instanceid, false); } elseif ($thiscontext->contextlevel == CONTEXT_MODULE) { list($module, $cm) = get_module_from_cmid($thiscontext->instanceid); require_login($cm->course, false, $cm); } $contexts->require_one_edit_tab_cap($edittab); } // ensure the files area exists for this course make_upload_directory("{$COURSE->id}"); $import_form = new question_import_form($thispageurl, array('contexts' => $contexts->having_one_edit_tab_cap('import'), 'defaultcategory' => $pagevars['cat'])); if ($import_form->is_cancelled()) { redirect($thispageurl); } //========== // PAGE HEADER //========== if ($cm !== null) { $strupdatemodule = has_capability('moodle/course:manageactivities', get_context_instance(CONTEXT_COURSE, $COURSE->id)) ? update_module_button($cm->id, $COURSE->id, get_string('modulename', $cm->modname)) : ""; $navlinks = array(); $navlinks[] = array('name' => get_string('modulenameplural', $cm->modname), 'link' => "{$CFG->wwwroot}/mod/{$cm->modname}/index.php?id={$COURSE->id}", 'type' => 'activity'); $navlinks[] = array('name' => format_string($module->name), 'link' => "{$CFG->wwwroot}/mod/{$cm->modname}/view.php?id={$cm->id}", 'type' => 'title'); $navlinks[] = array('name' => $txt->importquestions, 'link' => '', 'type' => 'title'); $navigation = build_navigation($navlinks); print_header_simple($txt->importquestions, '', $navigation, "", "", true, $strupdatemodule); $currenttab = 'edit';
//this page can be called without courseid or cmid in which case //we get the context from the category object. if ($contexts === null) { // need to get the course from the chosen category $contexts = new question_edit_contexts($categorycontext); $thiscontext = $contexts->lowest(); if ($thiscontext->contextlevel == CONTEXT_COURSE) { require_login($thiscontext->instanceid, false); } elseif ($thiscontext->contextlevel == CONTEXT_MODULE) { list($module, $cm) = get_module_from_cmid($thiscontext->instanceid); require_login($cm->course, false, $cm); } $contexts->require_one_edit_tab_cap($edittab); } $PAGE->set_url($thispageurl); $import_form = new question_import_form($thispageurl, array('contexts' => $contexts->having_one_edit_tab_cap('import'), 'defaultcategory' => $pagevars['cat'])); if ($import_form->is_cancelled()) { redirect($thispageurl); } //========== // PAGE HEADER //========== $PAGE->set_title($txt->importquestions); $PAGE->set_heading($COURSE->fullname); echo $OUTPUT->header(); // file upload form sumitted if ($form = $import_form->get_data()) { // file checks out ok $fileisgood = false; // work out if this is an uploaded file // or one from the filesarea.