MDL-20636 Fix new stdClass -> stdClass(), and trailing whitespace.
[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
56ed242b
SH
16 $PAGE->set_pagelayout('standard');
17
453b28d8
TH
18 list($thispageurl, $contexts, $cmid, $cm, $module, $pagevars) =
19 question_edit_setup('export', '/question/export.php');
d187f660 20
f1abd39f 21 // get display strings
5fcefc97 22 $strexportquestions = get_string('exportquestions', 'question');
0c1e3a14 23
46d79818 24 // make sure we are using the user's most recent category choice
25 if (empty($categoryid)) {
26 $categoryid = $pagevars['cat'];
27 }
aca318e1 28
271e6dec 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());
5fcefc97 36 $PAGE->set_title($strexportquestions);
0f56fde2 37 $PAGE->set_heading($COURSE->fullname);
56ed242b 38 echo $OUTPUT->header();
aca318e1 39
cde2709a 40 $export_form = new question_export_form($thispageurl, array('contexts'=>$contexts->having_one_edit_tab_cap('export'), 'defaultcategory'=>$pagevars['cat']));
aca318e1 41
aca318e1 42
cde2709a
DC
43 if ($from_form = $export_form->get_data()) {
44 $thiscontext = $contexts->lowest();
45 if (!is_readable("format/$from_form->format/format.php")) {
0be2c858 46 print_error('unknowformat', '', '', $from_form->format);
271e6dec 47 }
cde2709a
DC
48 $withcategories = 'nocategories';
49 if (!empty($from_form->cattofile)) {
50 $withcategories = 'withcategories';
271e6dec 51 }
cde2709a
DC
52 $withcontexts = 'nocontexts';
53 if (!empty($from_form->contexttofile)) {
54 $withcontexts = 'withcontexts';
aca318e1 55 }
56
b80d424c
TH
57 $classname = 'qformat_' . $from_form->format;
58 $qformat = new $classname();
59 $filename = question_default_export_filename($COURSE, $category) .
60 $qformat->export_file_extension();
61 $export_url = question_make_export_url($thiscontext->id, $category->id,
62 $from_form->format, $withcategories, $withcontexts, $filename);
aca318e1 63
cde2709a
DC
64 echo $OUTPUT->box_start();
65 echo get_string('yourfileshoulddownload', 'question', $export_url->out());
66 echo $OUTPUT->box_end();
67
68 $PAGE->requires->js_function_call('document.location.replace', array($export_url->out()), false, 1);
aca318e1 69
8afba50b 70 echo $OUTPUT->continue_button(new moodle_url('edit.php', $thispageurl->params()));
9b59580b 71 echo $OUTPUT->footer();
aca318e1 72 exit;
73 }
74
271e6dec 75 /// Display export form
5fcefc97 76 echo $OUTPUT->heading_with_help($strexportquestions, 'exportquestions', 'question');
aca318e1 77
271e6dec 78 $export_form->display();
79
9b59580b 80 echo $OUTPUT->footer();