Merge commit 'catalyst/MOODLE_19_STABLE' into mdl19-linuxchix
[moodle-linuxchix.git] / mod / lesson / import.php
blob8e41a64c38ab3b7d461bfc4c902fc0f1c26a70b5
1 <?php // $Id$
2 /**
3 * Imports lesson pages
5 * @version $Id$
6 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
7 * @package lesson
8 **/
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");
38 $navigation = build_navigation($strimportquestions, $cm);
39 print_header_simple("$strimportquestions", " $strimportquestions", $navigation);
41 if ($form = data_submitted()) { /// Filename
43 $form->format = clean_param($form->format, PARAM_SAFEDIR); // For safety
45 if (empty($_FILES['newfile'])) { // file was just uploaded
46 notify(get_string("uploadproblem") );
49 if ((!is_uploaded_file($_FILES['newfile']['tmp_name']) or $_FILES['newfile']['size'] == 0)) {
50 notify(get_string("uploadnofilefound") );
52 } else { // Valid file is found
54 if (! is_readable("$CFG->dirroot/question/format/$form->format/format.php")) {
55 error("Format not known ($form->format)");
58 require("format.php"); // Parent class
59 require("$CFG->dirroot/question/format/$form->format/format.php");
61 $classname = "qformat_$form->format";
62 $format = new $classname();
64 if (! $format->importpreprocess()) { // Do anything before that we need to
65 error("Error occurred during pre-processing!");
68 if (! $format->importprocess($_FILES['newfile']['tmp_name'], $lesson, $pageid)) { // Process the uploaded file
69 error("Error occurred during processing!");
72 if (! $format->importpostprocess()) { // In case anything needs to be done after
73 error("Error occurred during post-processing!");
76 echo "<hr>";
77 print_continue("view.php?id=$cm->id");
78 print_footer($course);
79 exit;
83 /// Print upload form
85 $fileformatnames = get_import_export_formats('import');
87 print_heading_with_help($strimportquestions, "import", "lesson");
89 print_simple_box_start("center");
90 echo "<form enctype=\"multipart/form-data\" method=\"post\" action=\"import.php\">";
91 echo "<input type=\"hidden\" name=\"id\" value=\"$cm->id\" />\n";
92 echo "<input type=\"hidden\" name=\"pageid\" value=\"$pageid\" />\n";
93 echo "<table cellpadding=\"5\">";
95 echo "<tr><td align=\"right\">";
96 print_string("fileformat", "lesson");
97 echo ":</td><td>";
98 choose_from_menu($fileformatnames, "format", "gift", "");
99 echo "</td></tr>";
101 echo "<tr><td align=\"right\">";
102 print_string("upload");
103 echo ":</td><td>";
104 echo "<input name=\"newfile\" type=\"file\" size=\"50\" />";
105 echo "</td></tr><tr><td>&nbsp;</td><td>";
106 echo "<input type=\"submit\" name=\"save\" value=\"".get_string("uploadthisfile")."\" />";
107 echo "</td></tr>";
109 echo "</table>";
110 echo "</form>";
111 print_simple_box_end();
113 print_footer($course);