3 * Export quiz questions into the given category
6 * @author Martin Dougiamas, Howard Miller, and many others.
7 * {@link http://moodle.org}
8 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
12 require_once("../config.php");
13 require_once( "editlib.php" );
15 $categoryid = optional_param('category',0, PARAM_INT
);
16 $courseid = required_param('courseid',PARAM_INT
);
17 $format = optional_param('format','', PARAM_FILE
);
18 $exportfilename = optional_param('exportfilename','',PARAM_FILE
);
20 if (! $course = get_record("course", "id", $courseid)) {
21 error("Course does not exist!");
25 if ($categoryid) { // update category in session variable
26 $SESSION->questioncat
= $categoryid;
27 } else { // try to get category from modform
28 $showcatmenu = true; // will ensure that user can choose category
29 if (isset($SESSION->questioncat
)) {
30 $categoryid = $SESSION->questioncat
;
34 if (! $category = get_record("question_categories", "id", $categoryid)) {
35 $category = get_default_question_category($courseid);
38 if (! $categorycourse = get_record("course", "id", $category->course
)) {
39 error( get_string('nocategory','quiz') );
42 require_login($course->id
, false);
44 $context = get_context_instance(CONTEXT_COURSE
, $course->id
);
45 require_capability('moodle/question:export', $context);
47 // ensure the files area exists for this course
48 make_upload_directory( "$course->id" );
50 $strexportquestions = get_string("exportquestions", "quiz");
51 $strquestions = get_string("questions", "quiz");
53 $strquizzes = get_string('modulenameplural', 'quiz');
54 $streditingquiz = get_string(isset($SESSION->modform
->instance
) ?
"editingquiz" : "editquestions", "quiz");
56 $dirname = get_string("exportfilename","quiz");
60 if (isset($SESSION->modform
->instance
) and $quiz = get_record('quiz', 'id', $SESSION->modform
->instance
)) {
61 $strupdatemodule = has_capability('moodle/course:manageactivities', $context)
62 ?
update_module_button($SESSION->modform
->cmid
, $course->id
, get_string('modulename', 'quiz'))
64 print_header_simple($strexportquestions, '',
65 "<a href=\"$CFG->wwwroot/mod/quiz/index.php?id=$course->id\">".get_string('modulenameplural', 'quiz').'</a>'.
66 " -> <a href=\"$CFG->wwwroot/mod/quiz/view.php?q=$quiz->id\">".format_string($quiz->name
).'</a>'.
67 ' -> '.$strexportquestions,
68 "", "", true, $strupdatemodule);
71 include($CFG->dirroot
.'/mod/quiz/tabs.php');
73 print_header_simple($strexportquestions, '', $strexportquestions);
75 $currenttab = 'export';
79 if (!empty($format)) { /// Filename
81 if (!confirm_sesskey()) {
82 echo( 'Sesskey error' );
85 if (! is_readable("format/$format/format.php")) {
86 error('Format not known ('.clean_text($form->format
).')');
89 require("format.php"); // Parent class
90 require("format/$format/format.php");
92 $classname = "qformat_$format";
93 $qformat = new $classname();
95 if (! $qformat->exportpreprocess($category, $course)) { // Do anything before that we need to
96 error( get_string('exporterror','quiz'),
97 "$CFG->wwwroot/question/export.php?courseid={$course->id}&category=$category->id");
100 if (! $qformat->exportprocess($exportfilename)) { // Process the export data
101 error( get_string('exporterror','quiz'),
102 "$CFG->wwwroot/question/export.php?courseid={$course->id}&category=$category->id");
105 if (! $qformat->exportpostprocess()) { // In case anything needs to be done after
106 error( get_string('exporterror','quiz'),
107 "$CFG->wwwroot/question/export.php?courseid={$course->id}&category=$category->id");
111 // link to download the finished file
112 $file_ext = $qformat->export_file_extension();
113 $download_str = get_string( 'download', 'quiz' );
114 $downloadextra_str = get_string( 'downloadextra','quiz' );
115 if ($CFG->slasharguments
) {
116 $efile = "{$CFG->wwwroot}/file.php/".$qformat->question_get_export_dir()."/$exportfilename".$file_ext."?forcedownload=1";
119 $efile = "{$CFG->wwwroot}/file.php?file=/".$qformat->question_get_export_dir()."/$exportfilename".$file_ext."&forcedownload=1";
121 echo "</p><center><a href=\"$efile\">$download_str</a></center></p>";
122 echo "</p><center><font size=\"-1\">$downloadextra_str</font></center></p>";
124 print_continue("edit.php?courseid=$course->id");
125 print_footer($course);
129 /// Print upload form
131 // get valid formats to generate dropdown list
132 $fileformatnames = get_import_export_formats( "export" );
135 if (empty($exportfilename)) {
136 $exportfilename = default_export_filename($course, $category);
139 print_heading_with_help($strexportquestions, "export", "quiz");
141 print_simple_box_start("center");
142 echo "<form enctype=\"multipart/form-data\" method=\"post\" action=\"export.php\">\n";
143 echo "<input type=\"hidden\" name=\"sesskey\" value=\"" . sesskey() . "\" />\n";
144 echo "<table cellpadding=\"5\">\n";
146 echo "<tr><td align=\"right\">\n";
147 print_string("category", "quiz");
149 if (!$showcatmenu) { // category already specified
150 echo question_category_coursename($category);
151 echo " <input type=\"hidden\" name=\"category\" value=\"$category->id\" />";
152 } else { // no category specified, let user choose
153 question_category_select_menu($course->id
, true, false, $category->id
);
155 //echo str_replace(' ', '', $category->name) . " ($categorycourse->shortname)";
158 echo "<tr><td align=\"right\">";
159 print_string("fileformat", "quiz");
161 choose_from_menu($fileformatnames, "format", "gift", "");
162 helpbutton("export", $strexportquestions, "quiz");
165 echo "<tr><td align=\"right\">";
166 print_string("exportname", "quiz" );
168 echo "<input type=\"text\" size=\"40\" name=\"exportfilename\" value=\"$exportfilename\" />";
171 echo "<tr><td align=\"center\" colspan=\"2\">";
172 echo " <input type=\"hidden\" name=\"courseid\" value=\"$course->id\" />";
173 echo " <input type=\"submit\" name=\"save\" value=\"".get_string("exportquestions","quiz")."\" />";
178 print_simple_box_end();
180 print_footer($course);