3 * Export quiz questions into the given category
5 * @author Martin Dougiamas, Howard Miller, and many others.
6 * {@link http://moodle.org}
7 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
8 * @package questionbank
9 * @subpackage importexport
12 require_once("../config.php");
13 require_once( "editlib.php" );
16 $categoryid = optional_param('category',0, PARAM_INT
);
17 $cattofile = optional_param('cattofile',0, PARAM_BOOL
);
18 $courseid = required_param('courseid',PARAM_INT
);
19 $exportfilename = optional_param('exportfilename','',PARAM_FILE
);
20 $format = optional_param('format','', PARAM_FILE
);
23 // get display strings
25 $txt->category
= get_string('category','quiz');
26 $txt->download
= get_string('download','quiz');
27 $txt->downloadextra
= get_string('downloadextra','quiz');
28 $txt->exporterror
= get_string('exporterror','quiz');
29 $txt->exportname
= get_string('exportname','quiz');
30 $txt->exportquestions
= get_string('exportquestions', 'quiz');
31 $txt->fileformat
= get_string('fileformat','quiz');
32 $txt->exportcategory
= get_string('exportcategory','quiz');
33 $txt->modulename
= get_string('modulename','quiz');
34 $txt->modulenameplural
= get_string('modulenameplural','quiz');
35 $txt->tofile
= get_string('tofile','quiz');
38 if (!$course = get_record("course", "id", $courseid)) {
39 error("Course does not exist!");
42 if ($categoryid) { // update category in session variable
43 $SESSION->questioncat
= $categoryid;
44 } else { // try to get category from modform
45 if (isset($SESSION->questioncat
)) {
46 $categoryid = $SESSION->questioncat
;
50 if (!$category = get_record("question_categories", "id", $categoryid)) {
51 $category = get_default_question_category($courseid);
54 if (!$categorycourse = get_record("course", "id", $category->course
)) {
55 print_error('nocategory','quiz');
58 require_login($course->id
, false);
60 // check role capability
61 $context = get_context_instance(CONTEXT_COURSE
, $course->id
);
62 require_capability('moodle/question:export', $context);
64 // ensure the files area exists for this course
65 make_upload_directory( "$course->id" );
67 // check category is valid
68 if (!empty($categoryid)) {
69 $validcats = question_category_options( $course->id
, true, false );
70 if (!array_key_exists( $categoryid, $validcats)) {
71 print_error( "Category id ($categoryid) is not permitted." );
76 if (isset($SESSION->modform
->instance
) and $quiz = get_record('quiz', 'id', $SESSION->modform
->instance
)) {
77 $strupdatemodule = has_capability('moodle/course:manageactivities', $context)
78 ?
update_module_button($SESSION->modform
->cmid
, $course->id
, $txt->modulename
)
80 print_header_simple($txt->exportquestions
, '',
81 "<a href=\"$CFG->wwwroot/mod/quiz/index.php?id=$course->id\">$txt->modulenameplural</a>".
82 " -> <a href=\"$CFG->wwwroot/mod/quiz/view.php?q=$quiz->id\">".format_string($quiz->name
).'</a>'.
83 ' -> '.$txt->exportquestions
,
84 "", "", true, $strupdatemodule);
87 include($CFG->dirroot
.'/mod/quiz/tabs.php');
89 print_header_simple($txt->exportquestions
, '', $txt->exportquestions
);
91 $currenttab = 'export';
95 if (!empty($format)) { /// Filename
97 if (!confirm_sesskey()) {
98 print_error( 'sesskey' );
101 if (! is_readable("format/$format/format.php")) {
102 error( "Format not known ($format)" ); }
104 // load parent class for import/export
105 require("format.php");
107 // and then the class for the selected format
108 require("format/$format/format.php");
110 $classname = "qformat_$format";
111 $qformat = new $classname();
113 $qformat->setCategory( $category );
114 $qformat->setCourse( $course );
115 $qformat->setFilename( $exportfilename );
116 $qformat->setCattofile( $cattofile );
118 if (! $qformat->exportpreprocess()) { // Do anything before that we need to
119 error( $txt->exporterror
, "$CFG->wwwroot/question/export.php?courseid={$course->id}&category=$category->id");
122 if (! $qformat->exportprocess()) { // Process the export data
123 error( $txt->exporterror
, "$CFG->wwwroot/question/export.php?courseid={$course->id}&category=$category->id");
126 if (! $qformat->exportpostprocess()) { // In case anything needs to be done after
127 error( $txt->exporterror
, "$CFG->wwwroot/question/export.php?courseid={$course->id}&category=$category->id");
131 // link to download the finished file
132 $file_ext = $qformat->export_file_extension();
133 if ($CFG->slasharguments
) {
134 $efile = "{$CFG->wwwroot}/file.php/".$qformat->question_get_export_dir()."/$exportfilename".$file_ext."?forcedownload=1";
137 $efile = "{$CFG->wwwroot}/file.php?file=/".$qformat->question_get_export_dir()."/$exportfilename".$file_ext."&forcedownload=1";
139 echo "<p><div class=\"boxaligncenter\"><a href=\"$efile\">$txt->download</a></div></p>";
140 echo "<p><div class=\"boxaligncenter\"><font size=\"-1\">$txt->downloadextra</font></div></p>";
142 print_continue("edit.php?courseid=$course->id");
143 print_footer($course);
147 /// Display upload form
149 // get valid formats to generate dropdown list
150 $fileformatnames = get_import_export_formats( 'export' );
153 if (empty($exportfilename)) {
154 $exportfilename = default_export_filename($course, $category);
157 print_heading_with_help($txt->exportquestions
, 'export', 'quiz');
158 print_simple_box_start('center');
161 <form enctype
="multipart/form-data" method
="post" action
="export.php">
162 <fieldset
class="invisiblefieldset" style
="display: block;">
163 <input type
="hidden" name
="sesskey" value
="<?php echo sesskey(); ?>" />
164 <input type
="hidden" name
="courseid" value
="<?php echo $course->id; ?>" />
166 <table cellpadding
="5">
168 <td align
="right"><?php
echo $txt->category
; ?
>:</td
>
171 question_category_select_menu($course->id
, true, false, $category->id
);
172 echo $txt->tofile
; ?
>
173 <input name
="cattofile" type
="checkbox" />
174 <?php
helpbutton('exportcategory', $txt->exportcategory
, 'quiz'); ?
>
178 <td align
="right"><?php
echo $txt->fileformat
; ?
>:</td
>
180 <?php
choose_from_menu($fileformatnames, 'format', 'gift', '');
181 helpbutton('export', $txt->exportquestions
, 'quiz'); ?
>
185 <td align
="right"><?php
echo $txt->exportname
; ?
>:</td
>
187 <input type
="text" size
="40" name
="exportfilename" value
="<?php echo $exportfilename; ?>" />
192 <input type
="submit" name
="save" value
="<?php echo $txt->exportquestions; ?>" />
201 print_simple_box_end();
202 print_footer($course);