|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 00003 // This file is part of Moodle - http://moodle.org/ 00004 // 00005 // Moodle is free software: you can redistribute it and/or modify 00006 // it under the terms of the GNU General Public License as published by 00007 // the Free Software Foundation, either version 3 of the License, or 00008 // (at your option) any later version. 00009 // 00010 // Moodle is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 // GNU General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 00017 00027 require_once("../../config.php"); 00028 require_once($CFG->libdir.'/questionlib.php'); 00029 require_once($CFG->dirroot.'/mod/lesson/locallib.php'); 00030 require_once($CFG->dirroot.'/mod/lesson/import_form.php'); 00031 require_once($CFG->dirroot.'/mod/lesson/format.php'); // Parent class 00032 00033 $id = required_param('id', PARAM_INT); // Course Module ID 00034 $pageid = optional_param('pageid', '', PARAM_INT); // Page ID 00035 00036 $PAGE->set_url('/mod/lesson/import.php', array('id'=>$id, 'pageid'=>$pageid)); 00037 00038 $cm = get_coursemodule_from_id('lesson', $id, 0, false, MUST_EXIST);; 00039 $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST); 00040 $lesson = new lesson($DB->get_record('lesson', array('id' => $cm->instance), '*', MUST_EXIST)); 00041 00042 require_login($course, false, $cm); 00043 $context = get_context_instance(CONTEXT_MODULE, $cm->id); 00044 require_capability('mod/lesson:edit', $context); 00045 00046 $strimportquestions = get_string("importquestions", "lesson"); 00047 $strlessons = get_string("modulenameplural", "lesson"); 00048 00049 $manager = lesson_page_type_manager::get($lesson); 00050 00051 $data = new stdClass; 00052 $data->id = $PAGE->cm->id; 00053 $data->pageid = $pageid; 00054 00055 $mform = new lesson_import_form(null, array('formats'=>lesson_get_import_export_formats('import'))); 00056 $mform->set_data($data); 00057 00058 $PAGE->navbar->add($strimportquestions); 00059 $PAGE->set_title($strimportquestions); 00060 $PAGE->set_heading($strimportquestions); 00061 echo $OUTPUT->header(); 00062 00063 echo $OUTPUT->heading_with_help($strimportquestions, 'importquestions', 'lesson' ); 00064 00065 if ($data = $mform->get_data()) { 00066 00067 require_sesskey(); 00068 00069 $realfilename = $mform->get_new_filename('questionfile'); 00070 //TODO: Leave all imported questions in Questionimport for now. 00071 $importfile = "{$CFG->tempdir}/questionimport/{$realfilename}"; 00072 make_temp_directory('questionimport'); 00073 if (!$result = $mform->save_file('questionfile', $importfile, true)) { 00074 throw new moodle_exception('uploadproblem'); 00075 } 00076 00077 $formatclass = 'qformat_'.$data->format; 00078 $formatclassfile = $CFG->dirroot.'/question/format/'.$data->format.'/format.php'; 00079 if (!is_readable($formatclassfile)) { 00080 print_error('unknowformat','', '', $data->format); 00081 } 00082 require_once($formatclassfile); 00083 $format = new $formatclass(); 00084 00085 // Do anything before that we need to 00086 if (! $format->importpreprocess()) { 00087 print_error('preprocesserror', 'lesson'); 00088 } 00089 00090 // Process the uploaded file 00091 if (! $format->importprocess($importfile, $lesson, $pageid)) { 00092 print_error('processerror', 'lesson'); 00093 } 00094 00095 // In case anything needs to be done after 00096 if (! $format->importpostprocess()) { 00097 print_error('postprocesserror', 'lesson'); 00098 } 00099 00100 echo "<hr>"; 00101 echo $OUTPUT->continue_button('view.php?id='.$PAGE->cm->id); 00102 00103 } else { 00104 00105 // Print upload form 00106 $mform->display(); 00107 } 00108 00109 echo $OUTPUT->footer();