fixed typo for parameter value from treu to true.
[moodle.git] / question / export.php
CommitLineData
aeb15530 1<?php
aca318e1 2/**
4323d029 3 * Export quiz questions into the given category
4 *
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
10 */
aca318e1 11
12 require_once("../config.php");
271e6dec 13 require_once("editlib.php");
14 require_once("export_form.php");
aca318e1 15
453b28d8
TH
16 list($thispageurl, $contexts, $cmid, $cm, $module, $pagevars) =
17 question_edit_setup('export', '/question/export.php');
d187f660 18
f1abd39f 19 // get display strings
1b8b535d 20 $strexportquestions = get_string('exportquestions', 'quiz');
0c1e3a14 21
46d79818 22 // make sure we are using the user's most recent category choice
23 if (empty($categoryid)) {
24 $categoryid = $pagevars['cat'];
25 }
aca318e1 26
aca318e1 27 // ensure the files area exists for this course
271e6dec 28 make_upload_directory("$COURSE->id");
29 list($catid, $catcontext) = explode(',', $pagevars['cat']);
f34488b2 30 if (!$category = $DB->get_record("question_categories", array("id" => $catid, 'contextid' => $catcontext))) {
271e6dec 31 print_error('nocategory','quiz');
22afe6d6 32 }
33
f1abd39f 34 /// Header
5c0daafc 35 $PAGE->set_url($thispageurl->out());
d412354c 36 $PAGE->set_title($strexportquestions);
b72ff476 37 if ($cm!==null) {
d412354c 38 $PAGE->navbar->add($strexportquestions);
d412354c 39 echo $OUTPUT->header();
aca318e1 40 $currenttab = 'edit';
41 $mode = 'export';
b72ff476 42 ${$cm->modname} = $module;
43 include($CFG->dirroot."/mod/$cm->modname/tabs.php");
aca318e1 44 } else {
b72ff476 45 // Print basic page layout.
d412354c 46 $PAGE->navbar->add($strexportquestions);
47 echo $OUTPUT->header();
567709c4 48 // print tabs
49 $currenttab = 'export';
50 include('tabs.php');
aca318e1 51 }
52
271e6dec 53 $exportfilename = default_export_filename($COURSE, $category);
54 $export_form = new question_export_form($thispageurl, array('contexts'=>$contexts->having_one_edit_tab_cap('export'), 'defaultcategory'=>$pagevars['cat'],
55 'defaultfilename'=>$exportfilename));
aca318e1 56
aca318e1 57
271e6dec 58 if ($from_form = $export_form->get_data()) { /// Filename
59
60
61 if (! is_readable("format/$from_form->format/format.php")) {
0be2c858 62 print_error('unknowformat', '', '', $from_form->format);
271e6dec 63 }
aca318e1 64
f1abd39f 65 // load parent class for import/export
271e6dec 66 require_once("format.php");
d187f660 67
f1abd39f 68 // and then the class for the selected format
271e6dec 69 require_once("format/$from_form->format/format.php");
aca318e1 70
271e6dec 71 $classname = "qformat_$from_form->format";
f5565b69 72 $qformat = new $classname();
271e6dec 73 $qformat->setContexts($contexts->having_one_edit_tab_cap('export'));
74 $qformat->setCategory($category);
75 $qformat->setCourse($COURSE);
aca318e1 76
271e6dec 77 if (empty($from_form->exportfilename)) {
78 $from_form->exportfilename = default_export_filename($COURSE, $category);
79 }
80 $qformat->setFilename($from_form->exportfilename);
d2940003 81 $canaccessbackupdata = has_capability('moodle/backup:backupcourse', $contexts->lowest());
1b8b535d 82 $qformat->set_can_access_backupdata($canaccessbackupdata);
271e6dec 83 $qformat->setCattofile(!empty($from_form->cattofile));
84 $qformat->setContexttofile(!empty($from_form->contexttofile));
08892d5b 85
86 if (! $qformat->exportpreprocess()) { // Do anything before that we need to
bd8ee7c1 87 print_error('exporterror', 'question', $thispageurl->out());
aca318e1 88 }
89
08892d5b 90 if (! $qformat->exportprocess()) { // Process the export data
bd8ee7c1 91 print_error('exporterror', 'question', $thispageurl->out());
aca318e1 92 }
93
f5565b69 94 if (! $qformat->exportpostprocess()) { // In case anything needs to be done after
bd8ee7c1 95 print_error('exporterror', 'question', $thispageurl->out());
aca318e1 96 }
97 echo "<hr />";
98
99 // link to download the finished file
f5565b69 100 $file_ext = $qformat->export_file_extension();
1b8b535d 101 $filename = $from_form->exportfilename . $file_ext;
102 if ($canaccessbackupdata) {
103 $efile = get_file_url($qformat->question_get_export_dir() . '/' . $filename,
104 array('forcedownload' => 1));
105 echo '<p><div class="boxaligncenter"><a href="' . $efile . '">' .
106 get_string('download', 'quiz') . '</a></div></p>';
107 echo '<p><div class="boxaligncenter"><font size="-1">' .
108 get_string('downloadextra', 'quiz') . '</font></div></p>';
109 } else {
5a254a29 110 $efile = get_file_url($filename, null, 'questionfile');
1b8b535d 111 echo '<p><div class="boxaligncenter">' .
29305001 112 get_string('yourfileshoulddownload', 'question', $efile) . '</div></p>';
593f9b87 113 $PAGE->requires->js_function_call('document.location.replace', array($efile), false, 1);
aca318e1 114 }
aca318e1 115
8afba50b 116 echo $OUTPUT->continue_button(new moodle_url('edit.php', $thispageurl->params()));
9b59580b 117 echo $OUTPUT->footer();
aca318e1 118 exit;
119 }
120
271e6dec 121 /// Display export form
4bcc5118 122 echo $OUTPUT->heading_with_help($strexportquestions, 'export', 'quiz');
aca318e1 123
271e6dec 124 $export_form->display();
125
9b59580b 126 echo $OUTPUT->footer();
aeb15530 127