MDL-70324 Question: get_all_response_file_areas() not work correctly
[moodle.git] / question / export.php
CommitLineData
aeb15530 1<?php
d3603157
TH
2// This file is part of Moodle - http://moodle.org/
3//
4// Moodle is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// Moodle is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16
aca318e1 17/**
d3603157 18 * Script for importing questions into the question bank.
4323d029 19 *
d3603157
TH
20 * @package moodlecore
21 * @subpackage questionbank
22 * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
4323d029 24 */
aca318e1 25
aca318e1 26
1fcf0ca8 27require_once(__DIR__ . '/../config.php');
d3603157
TH
28require_once($CFG->dirroot . '/question/editlib.php');
29require_once($CFG->dirroot . '/question/export_form.php');
44a7f384 30require_once($CFG->dirroot . '/question/format.php');
56ed242b 31
d3603157
TH
32list($thispageurl, $contexts, $cmid, $cm, $module, $pagevars) =
33 question_edit_setup('export', '/question/export.php');
0c1e3a14 34
d3603157
TH
35// get display strings
36$strexportquestions = get_string('exportquestions', 'question');
aca318e1 37
d3603157 38list($catid, $catcontext) = explode(',', $pagevars['cat']);
5e8a85aa 39$category = $DB->get_record('question_categories', array("id" => $catid, 'contextid' => $catcontext), '*', MUST_EXIST);
d3603157
TH
40
41/// Header
f19ed874 42$PAGE->set_url($thispageurl);
d3603157
TH
43$PAGE->set_title($strexportquestions);
44$PAGE->set_heading($COURSE->fullname);
45echo $OUTPUT->header();
46
0fa21eb7
AA
47// Print horizontal nav if needed.
48$renderer = $PAGE->get_renderer('core_question', 'bank');
49echo $renderer->extra_horizontal_navigation();
50
87b564df
TH
51$export_form = new question_export_form($thispageurl,
52 array('contexts' => $contexts->having_one_edit_tab_cap('export'), 'defaultcategory' => $pagevars['cat']));
22afe6d6 53
d3603157
TH
54
55if ($from_form = $export_form->get_data()) {
56 $thiscontext = $contexts->lowest();
f4fe3968 57 if (!is_readable("format/{$from_form->format}/format.php")) {
d3603157
TH
58 print_error('unknowformat', '', '', $from_form->format);
59 }
60 $withcategories = 'nocategories';
61 if (!empty($from_form->cattofile)) {
62 $withcategories = 'withcategories';
aca318e1 63 }
d3603157
TH
64 $withcontexts = 'nocontexts';
65 if (!empty($from_form->contexttofile)) {
66 $withcontexts = 'withcontexts';
67 }
68
69 $classname = 'qformat_' . $from_form->format;
70 $qformat = new $classname();
71 $filename = question_default_export_filename($COURSE, $category) .
72 $qformat->export_file_extension();
73 $export_url = question_make_export_url($thiscontext->id, $category->id,
74 $from_form->format, $withcategories, $withcontexts, $filename);
aca318e1 75
d3603157
TH
76 echo $OUTPUT->box_start();
77 echo get_string('yourfileshoulddownload', 'question', $export_url->out());
78 echo $OUTPUT->box_end();
aca318e1 79
4ca60a56
V
80 // Log the export of these questions.
81 $eventparams = [
93e435b9 82 'contextid' => $category->contextid,
4ca60a56
V
83 'other' => ['format' => $from_form->format, 'categoryid' => $category->id],
84 ];
85 $event = \core\event\questions_exported::create($eventparams);
86 $event->trigger();
93e435b9 87
c3b72e58
RT
88 // Don't allow force download for behat site, as pop-up can't be handled by selenium.
89 if (!defined('BEHAT_SITE_RUNNING')) {
90 $PAGE->requires->js_function_call('document.location.replace', array($export_url->out(false)), false, 1);
91 }
271e6dec 92
d3603157 93 echo $OUTPUT->continue_button(new moodle_url('edit.php', $thispageurl->params()));
9b59580b 94 echo $OUTPUT->footer();
d3603157
TH
95 exit;
96}
97
98/// Display export form
99echo $OUTPUT->heading_with_help($strexportquestions, 'exportquestions', 'question');
100
101$export_form->display();
102
103echo $OUTPUT->footer();