2 // Import quiz questions into the given category
4 require_once("../../config.php");
5 require_once("lib.php");
7 $id = required_param('id', PARAM_INT
); // Course Module ID
8 $pageid = optional_param('pageid', '', PARAM_INT
); // Page ID
10 if (! $cm = get_record("course_modules", "id", $id)) {
11 error("Course Module ID was incorrect");
14 if (! $course = get_record("course", "id", $cm->course
)) {
15 error("Course is misconfigured");
18 if (! $lesson = get_record("lesson", "id", $cm->instance
)) {
19 error("Course module is incorrect");
23 require_login($course->id
, false);
25 if (!isteacher($course->id
)) {
26 error("Only the teacher can import questions!");
29 $strimportquestions = get_string("importquestions", "lesson");
30 $strlessons = get_string("modulenameplural", "lesson");
32 print_header_simple("$strimportquestions", " $strimportquestions",
33 "<a href=index.php?id=$course->id>$strlessons</a> -> <a href=\"view.php?id=$cm->id\">".format_string($lesson->name
,true)."</a>-> $strimportquestions");
35 if ($form = data_submitted()) { /// Filename
37 $form->format
= clean_filename($form->format
); // For safety
39 if (empty($_FILES['newfile'])) { // file was just uploaded
40 notify(get_string("uploadproblem") );
43 if ((!is_uploaded_file($_FILES['newfile']['tmp_name']) or $_FILES['newfile']['size'] == 0)) {
44 notify(get_string("uploadnofilefound") );
46 } else { // Valid file is found
48 if (! is_readable("../quiz/format/$form->format/format.php")) {
49 error("Format not known ($form->format)");
52 require("format.php"); // Parent class
53 require("$CFG->dirroot/mod/quiz/lib.php"); // for the constants used in quiz/format/<format>/format.php
54 require("$CFG->dirroot/mod/quiz/format/$form->format/format.php");
56 $format = new quiz_file_format();
58 if (! $format->importpreprocess()) { // Do anything before that we need to
59 error("Error occurred during pre-processing!");
62 if (! $format->importprocess($_FILES['newfile']['tmp_name'], $lesson, $pageid)) { // Process the uploaded file
63 error("Error occurred during processing!");
66 if (! $format->importpostprocess()) { // In case anything needs to be done after
67 error("Error occurred during post-processing!");
71 print_continue("view.php?id=$cm->id");
72 print_footer($course);
79 $fileformats = get_list_of_plugins("mod/quiz/format");
80 $fileformatname = array();
81 foreach ($fileformats as $key => $fileformat) {
82 $formatname = get_string($fileformat, 'lesson');
83 if ($formatname == "[[$fileformat]]") {
84 $formatname = $fileformat; // Just use the raw folder name
86 $fileformatnames[$fileformat] = $formatname;
88 natcasesort($fileformatnames);
91 print_heading_with_help($strimportquestions, "import", "lesson");
93 print_simple_box_start("center");
94 echo "<form enctype=\"multipart/form-data\" method=\"post\" action=import.php>";
95 echo "<input type=\"hidden\" name=\"id\" value=\"$cm->id\">\n";
96 echo "<input type=\"hidden\" name=\"pageid\" value=\"$pageid\">\n";
97 echo "<table cellpadding=5>";
99 echo "<tr><td align=right>";
100 print_string("fileformat", "lesson");
102 choose_from_menu($fileformatnames, "format", "gift", "");
105 echo "<tr><td align=right>";
106 print_string("upload");
108 echo " <input name=\"newfile\" type=\"file\" size=\"50\">";
109 echo "</tr><tr><td> </td><td>";
110 echo " <input type=submit name=save value=\"".get_string("uploadthisfile")."\">";
115 print_simple_box_end();
117 print_footer($course);