MDL-26199 keep track of the current category when switching pages in the question...
[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
d3603157
TH
27require_once(dirname(__FILE__) . '/../config.php');
28require_once($CFG->dirroot . '/question/editlib.php');
29require_once($CFG->dirroot . '/question/export_form.php');
56ed242b 30
d3603157 31$PAGE->set_pagelayout('standard');
d187f660 32
d3603157
TH
33list($thispageurl, $contexts, $cmid, $cm, $module, $pagevars) =
34 question_edit_setup('export', '/question/export.php');
0c1e3a14 35
d3603157
TH
36// get display strings
37$strexportquestions = get_string('exportquestions', 'question');
aca318e1 38
d3603157
TH
39// make sure we are using the user's most recent category choice
40if (empty($categoryid)) {
41 $categoryid = $pagevars['cat'];
42}
43
44list($catid, $catcontext) = explode(',', $pagevars['cat']);
5e8a85aa 45$category = $DB->get_record('question_categories', array("id" => $catid, 'contextid' => $catcontext), '*', MUST_EXIST);
d3603157
TH
46
47/// Header
48$PAGE->set_url($thispageurl->out());
49$PAGE->set_title($strexportquestions);
50$PAGE->set_heading($COURSE->fullname);
51echo $OUTPUT->header();
52
53$export_form = new question_export_form($thispageurl, array('contexts'=>$contexts->having_one_edit_tab_cap('export'), 'defaultcategory'=>$pagevars['cat']));
22afe6d6 54
d3603157
TH
55
56if ($from_form = $export_form->get_data()) {
57 $thiscontext = $contexts->lowest();
58 if (!is_readable("format/$from_form->format/format.php")) {
59 print_error('unknowformat', '', '', $from_form->format);
60 }
61 $withcategories = 'nocategories';
62 if (!empty($from_form->cattofile)) {
63 $withcategories = 'withcategories';
aca318e1 64 }
d3603157
TH
65 $withcontexts = 'nocontexts';
66 if (!empty($from_form->contexttofile)) {
67 $withcontexts = 'withcontexts';
68 }
69
70 $classname = 'qformat_' . $from_form->format;
71 $qformat = new $classname();
72 $filename = question_default_export_filename($COURSE, $category) .
73 $qformat->export_file_extension();
74 $export_url = question_make_export_url($thiscontext->id, $category->id,
75 $from_form->format, $withcategories, $withcontexts, $filename);
aca318e1 76
d3603157
TH
77 echo $OUTPUT->box_start();
78 echo get_string('yourfileshoulddownload', 'question', $export_url->out());
79 echo $OUTPUT->box_end();
aca318e1 80
d3603157 81 $PAGE->requires->js_function_call('document.location.replace', array($export_url->out()), false, 1);
271e6dec 82
d3603157 83 echo $OUTPUT->continue_button(new moodle_url('edit.php', $thispageurl->params()));
9b59580b 84 echo $OUTPUT->footer();
d3603157
TH
85 exit;
86}
87
88/// Display export form
89echo $OUTPUT->heading_with_help($strexportquestions, 'exportquestions', 'question');
90
91$export_form->display();
92
93echo $OUTPUT->footer();