MDL-20808 "Create AMF test client" Some updates to client
[moodle.git] / question / export.php
blobfd832593d2a5c46dffe7a9401b815ba67038218e
1 <?php
2 /**
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 $PAGE->set_pagelayout('standard');
18 list($thispageurl, $contexts, $cmid, $cm, $module, $pagevars) =
19 question_edit_setup('export', '/question/export.php');
21 // get display strings
22 $strexportquestions = get_string('exportquestions', 'quiz');
24 // make sure we are using the user's most recent category choice
25 if (empty($categoryid)) {
26 $categoryid = $pagevars['cat'];
29 // ensure the files area exists for this course
30 make_upload_directory("$COURSE->id");
31 list($catid, $catcontext) = explode(',', $pagevars['cat']);
32 if (!$category = $DB->get_record("question_categories", array("id" => $catid, 'contextid' => $catcontext))) {
33 print_error('nocategory','quiz');
36 /// Header
37 $PAGE->set_url($thispageurl->out());
38 $PAGE->set_title($strexportquestions);
39 $PAGE->set_heading($COURSE->fullname);
40 echo $OUTPUT->header();
42 $exportfilename = default_export_filename($COURSE, $category);
43 $export_form = new question_export_form($thispageurl, array('contexts'=>$contexts->having_one_edit_tab_cap('export'), 'defaultcategory'=>$pagevars['cat'],
44 'defaultfilename'=>$exportfilename));
47 if ($from_form = $export_form->get_data()) { /// Filename
50 if (! is_readable("format/$from_form->format/format.php")) {
51 print_error('unknowformat', '', '', $from_form->format);
54 // load parent class for import/export
55 require_once("format.php");
57 // and then the class for the selected format
58 require_once("format/$from_form->format/format.php");
60 $classname = "qformat_$from_form->format";
61 $qformat = new $classname();
62 $qformat->setContexts($contexts->having_one_edit_tab_cap('export'));
63 $qformat->setCategory($category);
64 $qformat->setCourse($COURSE);
66 if (empty($from_form->exportfilename)) {
67 $from_form->exportfilename = default_export_filename($COURSE, $category);
69 $qformat->setFilename($from_form->exportfilename);
70 $canaccessbackupdata = has_capability('moodle/backup:backupcourse', $contexts->lowest());
71 $qformat->set_can_access_backupdata($canaccessbackupdata);
72 $qformat->setCattofile(!empty($from_form->cattofile));
73 $qformat->setContexttofile(!empty($from_form->contexttofile));
75 if (! $qformat->exportpreprocess()) { // Do anything before that we need to
76 print_error('exporterror', 'question', $thispageurl->out());
79 if (! $qformat->exportprocess()) { // Process the export data
80 print_error('exporterror', 'question', $thispageurl->out());
83 if (! $qformat->exportpostprocess()) { // In case anything needs to be done after
84 print_error('exporterror', 'question', $thispageurl->out());
86 echo "<hr />";
88 // link to download the finished file
89 $file_ext = $qformat->export_file_extension();
90 $filename = $from_form->exportfilename . $file_ext;
91 if ($canaccessbackupdata) {
92 $efile = get_file_url($qformat->question_get_export_dir() . '/' . $filename,
93 array('forcedownload' => 1));
94 echo '<p><div class="boxaligncenter"><a href="' . $efile . '">' .
95 get_string('download', 'quiz') . '</a></div></p>';
96 echo '<p><div class="boxaligncenter"><font size="-1">' .
97 get_string('downloadextra', 'quiz') . '</font></div></p>';
98 } else {
99 $efile = get_file_url($filename, null, 'questionfile');
100 echo '<p><div class="boxaligncenter">' .
101 get_string('yourfileshoulddownload', 'question', $efile) . '</div></p>';
102 $PAGE->requires->js_function_call('document.location.replace', array($efile), false, 1);
105 echo $OUTPUT->continue_button(new moodle_url('edit.php', $thispageurl->params()));
106 echo $OUTPUT->footer();
107 exit;
110 /// Display export form
111 echo $OUTPUT->heading_with_help($strexportquestions, 'export', 'quiz');
113 $export_form->display();
115 echo $OUTPUT->footer();