6 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
10 require_once("../../config.php");
11 require_once("lib.php");
12 require_once("locallib.php");
13 require_once($CFG->libdir
.'/questionlib.php');
15 $id = required_param('id', PARAM_INT
); // Course Module ID
16 $pageid = optional_param('pageid', '', PARAM_INT
); // Page ID
18 if (! $cm = get_coursemodule_from_id('lesson', $id)) {
19 error("Course Module ID was incorrect");
22 if (! $course = get_record("course", "id", $cm->course
)) {
23 error("Course is misconfigured");
26 if (! $lesson = get_record("lesson", "id", $cm->instance
)) {
27 error("Course module is incorrect");
31 require_login($course->id
, false, $cm);
32 $context = get_context_instance(CONTEXT_MODULE
, $cm->id
);
33 require_capability('mod/lesson:edit', $context);
35 $strimportquestions = get_string("importquestions", "lesson");
36 $strlessons = get_string("modulenameplural", "lesson");
39 $navlinks[] = array('name' => $strlesson, 'link' => "index.php?id=$course->id", 'type' => 'activity');
40 $navlinks[] = array('name' => format_string($lesson->name
,true), 'link' => "view.php?id=$cm->id", 'type' => 'activityinstance');
41 $navlinks[] = array('name' => $strimportquestions, 'link' => '', 'type' => 'title');
43 $navigation = build_navigation($navlinks);
45 print_header_simple("$strimportquestions", " $strimportquestions", $navigation);
47 if ($form = data_submitted()) { /// Filename
49 $form->format
= clean_param($form->format
, PARAM_SAFEDIR
); // For safety
51 if (empty($_FILES['newfile'])) { // file was just uploaded
52 notify(get_string("uploadproblem") );
55 if ((!is_uploaded_file($_FILES['newfile']['tmp_name']) or $_FILES['newfile']['size'] == 0)) {
56 notify(get_string("uploadnofilefound") );
58 } else { // Valid file is found
60 if (! is_readable("$CFG->dirroot/question/format/$form->format/format.php")) {
61 error("Format not known ($form->format)");
64 require("format.php"); // Parent class
65 require("$CFG->dirroot/question/format/$form->format/format.php");
67 $classname = "qformat_$form->format";
68 $format = new $classname();
70 if (! $format->importpreprocess()) { // Do anything before that we need to
71 error("Error occurred during pre-processing!");
74 if (! $format->importprocess($_FILES['newfile']['tmp_name'], $lesson, $pageid)) { // Process the uploaded file
75 error("Error occurred during processing!");
78 if (! $format->importpostprocess()) { // In case anything needs to be done after
79 error("Error occurred during post-processing!");
83 print_continue("view.php?id=$cm->id");
84 print_footer($course);
91 $fileformatnames = get_import_export_formats('import');
93 print_heading_with_help($strimportquestions, "import", "lesson");
95 print_simple_box_start("center");
96 echo "<form enctype=\"multipart/form-data\" method=\"post\" action=\"import.php\">";
97 echo "<input type=\"hidden\" name=\"id\" value=\"$cm->id\" />\n";
98 echo "<input type=\"hidden\" name=\"pageid\" value=\"$pageid\" />\n";
99 echo "<table cellpadding=\"5\">";
101 echo "<tr><td align=\"right\">";
102 print_string("fileformat", "lesson");
104 choose_from_menu($fileformatnames, "format", "gift", "");
107 echo "<tr><td align=\"right\">";
108 print_string("upload");
110 echo "<input name=\"newfile\" type=\"file\" size=\"50\" />";
111 echo "</td></tr><tr><td> </td><td>";
112 echo "<input type=\"submit\" name=\"save\" value=\"".get_string("uploadthisfile")."\" />";
117 print_simple_box_end();
119 print_footer($course);