MDL-27445 Fixed the deprecated call
[moodle.git] / question / export.php
blob79f1152d6c3f51b2c6313aad6dc2d035ab5bd9f8
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', 'question');
24 // make sure we are using the user's most recent category choice
25 if (empty($categoryid)) {
26 $categoryid = $pagevars['cat'];
29 list($catid, $catcontext) = explode(',', $pagevars['cat']);
30 if (!$category = $DB->get_record("question_categories", array("id" => $catid, 'contextid' => $catcontext))) {
31 print_error('nocategory','quiz');
34 /// Header
35 $PAGE->set_url($thispageurl->out());
36 $PAGE->set_title($strexportquestions);
37 $PAGE->set_heading($COURSE->fullname);
38 echo $OUTPUT->header();
40 $export_form = new question_export_form($thispageurl, array('contexts'=>$contexts->having_one_edit_tab_cap('export'), 'defaultcategory'=>$pagevars['cat']));
43 if ($from_form = $export_form->get_data()) {
44 $thiscontext = $contexts->lowest();
45 if (!is_readable("format/$from_form->format/format.php")) {
46 print_error('unknowformat', '', '', $from_form->format);
48 $withcategories = 'nocategories';
49 if (!empty($from_form->cattofile)) {
50 $withcategories = 'withcategories';
52 $withcontexts = 'nocontexts';
53 if (!empty($from_form->contexttofile)) {
54 $withcontexts = 'withcontexts';
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);
64 echo $OUTPUT->box_start();
65 echo get_string('yourfileshoulddownload', 'question', $export_url->out());
66 echo $OUTPUT->box_end();
68 $PAGE->requires->js_function_call('document.location.replace', array($export_url->out()), false, 1);
70 echo $OUTPUT->continue_button(new moodle_url('edit.php', $thispageurl->params()));
71 echo $OUTPUT->footer();
72 exit;
75 /// Display export form
76 echo $OUTPUT->heading_with_help($strexportquestions, 'exportquestions', 'question');
78 $export_form->display();
80 echo $OUTPUT->footer();