Exemplo n.º 1
0
//==========
// 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.
    $realfilename = $import_form->get_new_filename('newfile');
    $importfile = "{$CFG->tempdir}/questionimport/{$realfilename}";
    make_temp_directory('questionimport');
    if (!($result = $import_form->save_file('newfile', $importfile, true))) {
        throw new moodle_exception('uploadproblem');
    }
    $formatfile = 'format/' . $form->format . '/format.php';
    if (!is_readable($formatfile)) {
        throw new moodle_exception('formatnotfound', 'question', '', $form->format);
    }
    require_once $formatfile;
    $classname = 'qformat_' . $form->format;
    $qformat = new $classname();
    // load data into class
    $qformat->setCategory($category);
    $qformat->setContexts($contexts->having_one_edit_tab_cap('import'));
    $qformat->setCourse($COURSE);
    $qformat->setFilename($importfile);
    $qformat->setRealfilename($realfilename);