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");
14 require_once("export_form.php");
16 list($thispageurl, $contexts, $cmid, $cm, $module, $pagevars) = question_edit_setup('export');
19 // get display strings
21 $txt->category
= get_string('category', 'quiz');
22 $txt->download
= get_string('download', 'quiz');
23 $txt->downloadextra
= get_string('downloadextra', 'quiz');
24 $txt->exporterror
= get_string('exporterror', 'quiz');
25 $txt->exportname
= get_string('exportname', 'quiz');
26 $txt->exportquestions
= get_string('exportquestions', 'quiz');
27 $txt->fileformat
= get_string('fileformat', 'quiz');
28 $txt->exportcategory
= get_string('exportcategory', 'quiz');
29 $txt->modulename
= get_string('modulename', 'quiz');
30 $txt->modulenameplural
= get_string('modulenameplural', 'quiz');
31 $txt->tofile
= get_string('tofile', 'quiz');
35 // make sure we are using the user's most recent category choice
36 if (empty($categoryid)) {
37 $categoryid = $pagevars['cat'];
40 // ensure the files area exists for this course
41 make_upload_directory("$COURSE->id");
42 list($catid, $catcontext) = explode(',', $pagevars['cat']);
43 if (!$category = get_record("question_categories", "id", $catid, 'contextid', $catcontext)) {
44 print_error('nocategory','quiz');
49 $strupdatemodule = has_capability('moodle/course:manageactivities', $contexts->lowest())
50 ?
update_module_button($cm->id
, $COURSE->id
, get_string('modulename', $cm->modname
))
53 $navlinks[] = array('name' => get_string('modulenameplural', $cm->modname
), 'link' => "$CFG->wwwroot/mod/{$cm->modname}/index.php?id=$COURSE->id", 'type' => 'activity');
54 $navlinks[] = array('name' => format_string($module->name
), 'link' => "$CFG->wwwroot/mod/{$cm->modname}/view.php?id={$cm->id}", 'type' => 'title');
55 $navlinks[] = array('name' => $txt->exportquestions
, 'link' => '', 'type' => 'title');
56 $navigation = build_navigation($navlinks);
57 print_header_simple($txt->exportquestions
, '', $navigation, "", "", true, $strupdatemodule);
61 $
{$cm->modname
} = $module;
62 include($CFG->dirroot
."/mod/$cm->modname/tabs.php");
64 // Print basic page layout.
66 $navlinks[] = array('name' => $txt->exportquestions
, 'link' => '', 'type' => 'title');
67 $navigation = build_navigation($navlinks);
69 print_header_simple($txt->exportquestions
, '', $navigation);
71 $currenttab = 'export';
75 $exportfilename = default_export_filename($COURSE, $category);
76 $export_form = new question_export_form($thispageurl, array('contexts'=>$contexts->having_one_edit_tab_cap('export'), 'defaultcategory'=>$pagevars['cat'],
77 'defaultfilename'=>$exportfilename));
80 if ($from_form = $export_form->get_data()) { /// Filename
83 if (! is_readable("format/$from_form->format/format.php")) {
84 error("Format not known ($from_form->format)");
87 // load parent class for import/export
88 require_once("format.php");
90 // and then the class for the selected format
91 require_once("format/$from_form->format/format.php");
93 $classname = "qformat_$from_form->format";
94 $qformat = new $classname();
95 $qformat->setContexts($contexts->having_one_edit_tab_cap('export'));
96 $qformat->setCategory($category);
97 $qformat->setCourse($COURSE);
99 if (empty($from_form->exportfilename
)) {
100 $from_form->exportfilename
= default_export_filename($COURSE, $category);
102 $qformat->setFilename($from_form->exportfilename
);
103 $qformat->setCattofile(!empty($from_form->cattofile
));
104 $qformat->setContexttofile(!empty($from_form->contexttofile
));
106 if (! $qformat->exportpreprocess()) { // Do anything before that we need to
107 error($txt->exporterror
, $thispageurl->out());
110 if (! $qformat->exportprocess()) { // Process the export data
111 error($txt->exporterror
, $thispageurl->out());
114 if (! $qformat->exportpostprocess()) { // In case anything needs to be done after
115 error($txt->exporterror
, $thispageurl->out());
119 // link to download the finished file
120 $file_ext = $qformat->export_file_extension();
121 if ($CFG->slasharguments
) {
122 $efile = "{$CFG->wwwroot}/file.php/".$qformat->question_get_export_dir()."/$from_form->exportfilename".$file_ext."?forcedownload=1";
125 $efile = "{$CFG->wwwroot}/file.php?file=/".$qformat->question_get_export_dir()."/$from_form->exportfilename".$file_ext."&forcedownload=1";
127 echo "<p><div class=\"boxaligncenter\"><a href=\"$efile\">$txt->download</a></div></p>";
128 echo "<p><div class=\"boxaligncenter\"><font size=\"-1\">$txt->downloadextra</font></div></p>";
130 print_continue("edit.php?".$thispageurl->get_query_string());
131 print_footer($COURSE);
135 /// Display export form
138 print_heading_with_help($txt->exportquestions
, 'export', 'quiz');
140 $export_form->display();
142 print_footer($COURSE);