2004-09-12 17:34:35 +00:00
|
|
|
<?php // $Id$
|
2003-02-16 07:08:57 +00:00
|
|
|
// Import quiz questions into the given category
|
|
|
|
|
|
|
|
require_once("../../config.php");
|
2005-01-08 20:06:00 +00:00
|
|
|
require_once("locallib.php");
|
2003-02-16 07:08:57 +00:00
|
|
|
|
|
|
|
require_variable($category);
|
|
|
|
optional_variable($format);
|
|
|
|
|
|
|
|
if (! $category = get_record("quiz_categories", "id", $category)) {
|
|
|
|
error("This wasn't a valid category!");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! $course = get_record("course", "id", $category->course)) {
|
|
|
|
error("This category doesn't belong to a valid course!");
|
|
|
|
}
|
|
|
|
|
2005-02-16 10:40:48 +00:00
|
|
|
require_login($course->id, false);
|
2003-02-16 07:08:57 +00:00
|
|
|
|
|
|
|
if (!isteacher($course->id)) {
|
|
|
|
error("Only the teacher can import quiz questions!");
|
|
|
|
}
|
|
|
|
|
|
|
|
$strimportquestions = get_string("importquestions", "quiz");
|
2003-03-01 05:08:03 +00:00
|
|
|
$strquestions = get_string("questions", "quiz");
|
2003-02-16 07:08:57 +00:00
|
|
|
|
2004-05-16 10:20:26 +00:00
|
|
|
$strquizzes = get_string('modulenameplural', 'quiz');
|
|
|
|
$streditingquiz = get_string(isset($SESSION->modform->instance) ? "editingquiz" : "editquestions", "quiz");
|
|
|
|
|
2004-08-22 14:38:47 +00:00
|
|
|
print_header_simple("$strimportquestions", "$strimportquestions",
|
|
|
|
"<a href=\"$CFG->wwwroot/mod/quiz/index.php?id=$course->id\">$strquizzes</a>".
|
2004-05-16 10:20:26 +00:00
|
|
|
" -> <a href=\"edit.php\">$streditingquiz</a> -> $strimportquestions");
|
2003-02-16 07:08:57 +00:00
|
|
|
|
|
|
|
if ($form = data_submitted()) { /// Filename
|
|
|
|
|
2003-10-15 08:53:51 +00:00
|
|
|
if (isset($form->filename)) { // file already on server
|
2005-02-05 17:28:06 +00:00
|
|
|
$newfile['tmp_name'] = $form->filename;
|
2003-10-15 08:53:51 +00:00
|
|
|
$newfile['size'] = filesize($form->filename);
|
2005-02-05 17:28:06 +00:00
|
|
|
|
2003-10-15 08:53:51 +00:00
|
|
|
} else if (!empty($_FILES['newfile'])) { // file was just uploaded
|
2004-09-16 04:42:59 +00:00
|
|
|
require_once($CFG->dirroot.'/lib/uploadlib.php');
|
|
|
|
$um = new upload_manager('newfile',false,false,$course,false,0,false);
|
2005-02-05 17:28:06 +00:00
|
|
|
if ($um->preprocess_files()) { // validate and virus check!
|
2004-09-16 04:42:59 +00:00
|
|
|
$newfile = $_FILES['newfile'];
|
|
|
|
}
|
2003-02-16 07:08:57 +00:00
|
|
|
}
|
2003-04-10 13:12:40 +00:00
|
|
|
|
2004-09-16 04:42:59 +00:00
|
|
|
if (is_array($newfile)) { // either for file already on server or just uploaded file.
|
2003-02-16 07:08:57 +00:00
|
|
|
|
2004-09-29 06:52:24 +00:00
|
|
|
$form->format = clean_filename($form->format);
|
|
|
|
|
2003-12-12 07:35:55 +00:00
|
|
|
if (! is_readable("format/$form->format/format.php")) {
|
2004-09-29 06:52:24 +00:00
|
|
|
error('Format not known ('.clean_text($form->format).')');
|
2003-02-16 07:08:57 +00:00
|
|
|
}
|
|
|
|
|
2003-12-12 07:35:55 +00:00
|
|
|
require("format.php"); // Parent class
|
|
|
|
require("format/$form->format/format.php");
|
2003-02-16 07:08:57 +00:00
|
|
|
|
|
|
|
$format = new quiz_file_format();
|
|
|
|
|
2003-05-03 04:31:49 +00:00
|
|
|
if (! $format->importpreprocess($category)) { // Do anything before that we need to
|
2005-02-05 17:28:06 +00:00
|
|
|
error("Error occurred during pre-processing!",
|
2004-03-25 14:55:04 +00:00
|
|
|
"$CFG->wwwroot/mod/quiz/import.php?category=$category->id");
|
2003-04-10 13:12:40 +00:00
|
|
|
}
|
|
|
|
|
2003-05-03 04:31:49 +00:00
|
|
|
if (! $format->importprocess($newfile['tmp_name'])) { // Process the uploaded file
|
2005-02-05 17:28:06 +00:00
|
|
|
error("Error occurred during processing!",
|
2004-03-25 14:55:04 +00:00
|
|
|
"$CFG->wwwroot/mod/quiz/import.php?category=$category->id");
|
2003-02-16 07:08:57 +00:00
|
|
|
}
|
|
|
|
|
2003-05-03 04:31:49 +00:00
|
|
|
if (! $format->importpostprocess()) { // In case anything needs to be done after
|
2005-02-05 17:28:06 +00:00
|
|
|
error("Error occurred during post-processing!",
|
2004-03-25 14:55:04 +00:00
|
|
|
"$CFG->wwwroot/mod/quiz/import.php?category=$category->id");
|
2003-03-01 05:08:03 +00:00
|
|
|
}
|
2003-04-10 13:12:40 +00:00
|
|
|
|
2004-09-12 14:41:49 +00:00
|
|
|
echo "<hr />";
|
2003-02-16 07:08:57 +00:00
|
|
|
print_continue("edit.php");
|
|
|
|
print_footer($course);
|
|
|
|
exit;
|
|
|
|
}
|
2005-02-05 17:28:06 +00:00
|
|
|
}
|
2003-02-16 07:08:57 +00:00
|
|
|
|
|
|
|
/// Print upload form
|
|
|
|
|
2005-02-16 10:40:48 +00:00
|
|
|
if (!$categories = quiz_get_category_menu($course->id, false)) {
|
2003-02-16 08:03:55 +00:00
|
|
|
error("No categories!");
|
|
|
|
}
|
|
|
|
|
2003-12-12 07:35:55 +00:00
|
|
|
$fileformats = get_list_of_plugins("mod/quiz/format");
|
|
|
|
$fileformatname = array();
|
|
|
|
foreach ($fileformats as $key => $fileformat) {
|
|
|
|
$formatname = get_string($fileformat, 'quiz');
|
|
|
|
if ($formatname == "[[$fileformat]]") {
|
|
|
|
$formatname = $fileformat; // Just use the raw folder name
|
|
|
|
}
|
|
|
|
$fileformatnames[$fileformat] = $formatname;
|
|
|
|
}
|
|
|
|
natcasesort($fileformatnames);
|
|
|
|
|
|
|
|
|
2003-04-10 13:12:40 +00:00
|
|
|
print_heading_with_help($strimportquestions, "import", "quiz");
|
2003-02-16 08:03:55 +00:00
|
|
|
|
2005-02-05 17:28:06 +00:00
|
|
|
print_simple_box_start("center");
|
2004-09-12 17:34:35 +00:00
|
|
|
echo "<form enctype=\"multipart/form-data\" method=\"post\" action=\"import.php\">";
|
|
|
|
echo "<table cellpadding=\"5\">";
|
2003-05-02 15:31:24 +00:00
|
|
|
|
2004-09-12 17:34:35 +00:00
|
|
|
echo "<tr><td align=\"right\">";
|
2003-02-16 08:03:55 +00:00
|
|
|
print_string("category", "quiz");
|
2003-05-02 15:31:24 +00:00
|
|
|
echo ":</td><td>";
|
2004-06-17 17:31:12 +00:00
|
|
|
// choose_from_menu($categories, "category", "$category->id", "");
|
|
|
|
echo quiz_get_category_coursename($category);
|
2003-05-02 15:31:24 +00:00
|
|
|
echo "</tr>";
|
2003-02-16 08:03:55 +00:00
|
|
|
|
2004-09-12 17:34:35 +00:00
|
|
|
echo "<tr><td align=\"right\">";
|
2003-02-16 08:03:55 +00:00
|
|
|
print_string("fileformat", "quiz");
|
2003-05-02 15:31:24 +00:00
|
|
|
echo ":</td><td>";
|
2003-12-12 07:35:55 +00:00
|
|
|
choose_from_menu($fileformatnames, "format", "gift", "");
|
2003-02-16 07:08:57 +00:00
|
|
|
helpbutton("import", $strimportquestions, "quiz");
|
2003-05-02 15:31:24 +00:00
|
|
|
echo "</tr>";
|
|
|
|
|
2004-09-12 17:34:35 +00:00
|
|
|
echo "<tr><td align=\"right\">";
|
2003-02-16 08:03:55 +00:00
|
|
|
print_string("upload");
|
2003-05-02 15:31:24 +00:00
|
|
|
echo ":</td><td>";
|
2004-09-16 04:42:59 +00:00
|
|
|
require_once($CFG->dirroot.'/lib/uploadlib.php');
|
|
|
|
upload_print_form_fragment(1,array('newfile'),null,false,null,$course->maxbytes,0,false);
|
2003-05-02 15:31:24 +00:00
|
|
|
echo "</tr><tr><td> </td><td>";
|
2004-09-12 17:34:35 +00:00
|
|
|
echo " <input type=\"hidden\" name=\"category\" value=\"$category->id\" />";
|
|
|
|
echo " <input type=\"submit\" name=\"save\" value=\"".get_string("uploadthisfile")."\" />";
|
2003-05-02 15:31:24 +00:00
|
|
|
echo "</td></tr>";
|
|
|
|
|
|
|
|
echo "</table>";
|
|
|
|
echo "</form>";
|
2003-02-16 08:03:55 +00:00
|
|
|
print_simple_box_end();
|
2003-02-16 07:08:57 +00:00
|
|
|
|
|
|
|
print_footer($course);
|
|
|
|
|
|
|
|
?>
|