MDL-19817 Converted all print_footer() calls
[moodle.git] / question / export.php
CommitLineData
aca318e1 1<?php // $Id$
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
271e6dec 16 list($thispageurl, $contexts, $cmid, $cm, $module, $pagevars) = question_edit_setup('export');
b72ff476 17
d187f660 18
f1abd39f 19 // get display strings
1b8b535d 20 $strexportquestions = get_string('exportquestions', 'quiz');
0c1e3a14 21
46d79818 22 // make sure we are using the user's most recent category choice
23 if (empty($categoryid)) {
24 $categoryid = $pagevars['cat'];
25 }
aca318e1 26
aca318e1 27 // ensure the files area exists for this course
271e6dec 28 make_upload_directory("$COURSE->id");
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
b72ff476 35 if ($cm!==null) {
271e6dec 36 $strupdatemodule = has_capability('moodle/course:manageactivities', $contexts->lowest())
37 ? update_module_button($cm->id, $COURSE->id, get_string('modulename', $cm->modname))
aca318e1 38 : "";
3b27b0fe 39 $navlinks = array();
83601351 40 $navlinks[] = array('name' => get_string('modulenameplural', $cm->modname), 'link' => "$CFG->wwwroot/mod/{$cm->modname}/index.php?id=$COURSE->id", 'type' => 'activity');
0cbddd85 41 $navlinks[] = array('name' => format_string($module->name), 'link' => "$CFG->wwwroot/mod/{$cm->modname}/view.php?id={$cm->id}", 'type' => 'title');
1b8b535d 42 $navlinks[] = array('name' => $strexportquestions, 'link' => '', 'type' => 'title');
3b27b0fe 43 $navigation = build_navigation($navlinks);
1b8b535d 44 print_header_simple($strexportquestions, '', $navigation, "", "", true, $strupdatemodule);
b72ff476 45
aca318e1 46 $currenttab = 'edit';
47 $mode = 'export';
b72ff476 48 ${$cm->modname} = $module;
49 include($CFG->dirroot."/mod/$cm->modname/tabs.php");
aca318e1 50 } else {
b72ff476 51 // Print basic page layout.
3b27b0fe 52 $navlinks = array();
1b8b535d 53 $navlinks[] = array('name' => $strexportquestions, 'link' => '', 'type' => 'title');
3b27b0fe 54 $navigation = build_navigation($navlinks);
271e6dec 55
1b8b535d 56 print_header_simple($strexportquestions, '', $navigation);
567709c4 57 // print tabs
58 $currenttab = 'export';
59 include('tabs.php');
aca318e1 60 }
61
271e6dec 62 $exportfilename = default_export_filename($COURSE, $category);
63 $export_form = new question_export_form($thispageurl, array('contexts'=>$contexts->having_one_edit_tab_cap('export'), 'defaultcategory'=>$pagevars['cat'],
64 'defaultfilename'=>$exportfilename));
aca318e1 65
aca318e1 66
271e6dec 67 if ($from_form = $export_form->get_data()) { /// Filename
68
69
70 if (! is_readable("format/$from_form->format/format.php")) {
0be2c858 71 print_error('unknowformat', '', '', $from_form->format);
271e6dec 72 }
aca318e1 73
f1abd39f 74 // load parent class for import/export
271e6dec 75 require_once("format.php");
d187f660 76
f1abd39f 77 // and then the class for the selected format
271e6dec 78 require_once("format/$from_form->format/format.php");
aca318e1 79
271e6dec 80 $classname = "qformat_$from_form->format";
f5565b69 81 $qformat = new $classname();
271e6dec 82 $qformat->setContexts($contexts->having_one_edit_tab_cap('export'));
83 $qformat->setCategory($category);
84 $qformat->setCourse($COURSE);
aca318e1 85
271e6dec 86 if (empty($from_form->exportfilename)) {
87 $from_form->exportfilename = default_export_filename($COURSE, $category);
88 }
89 $qformat->setFilename($from_form->exportfilename);
1b8b535d 90 $canaccessbackupdata = has_capability('moodle/site:backup', $contexts->lowest());
91 $qformat->set_can_access_backupdata($canaccessbackupdata);
271e6dec 92 $qformat->setCattofile(!empty($from_form->cattofile));
93 $qformat->setContexttofile(!empty($from_form->contexttofile));
08892d5b 94
95 if (! $qformat->exportpreprocess()) { // Do anything before that we need to
bd8ee7c1 96 print_error('exporterror', 'question', $thispageurl->out());
aca318e1 97 }
98
08892d5b 99 if (! $qformat->exportprocess()) { // Process the export data
bd8ee7c1 100 print_error('exporterror', 'question', $thispageurl->out());
aca318e1 101 }
102
f5565b69 103 if (! $qformat->exportpostprocess()) { // In case anything needs to be done after
bd8ee7c1 104 print_error('exporterror', 'question', $thispageurl->out());
aca318e1 105 }
106 echo "<hr />";
107
108 // link to download the finished file
f5565b69 109 $file_ext = $qformat->export_file_extension();
1b8b535d 110 $filename = $from_form->exportfilename . $file_ext;
111 if ($canaccessbackupdata) {
112 $efile = get_file_url($qformat->question_get_export_dir() . '/' . $filename,
113 array('forcedownload' => 1));
114 echo '<p><div class="boxaligncenter"><a href="' . $efile . '">' .
115 get_string('download', 'quiz') . '</a></div></p>';
116 echo '<p><div class="boxaligncenter"><font size="-1">' .
117 get_string('downloadextra', 'quiz') . '</font></div></p>';
118 } else {
5a254a29 119 $efile = get_file_url($filename, null, 'questionfile');
1b8b535d 120 echo '<p><div class="boxaligncenter">' .
29305001 121 get_string('yourfileshoulddownload', 'question', $efile) . '</div></p>';
cf615522 122 $PAGE->requires->js_function_call('document.location.replace', array($efile))->after_delay(1);
aca318e1 123 }
aca318e1 124
1b8b535d 125 print_continue('edit.php?' . $thispageurl->get_query_string());
271e6dec 126 print_footer($COURSE);
aca318e1 127 exit;
128 }
129
271e6dec 130 /// Display export form
1b8b535d 131 print_heading_with_help($strexportquestions, 'export', 'quiz');
aca318e1 132
271e6dec 133 $export_form->display();
134
135 print_footer($COURSE);
f1abd39f 136?>