forked from moodle/moodle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexport.php
136 lines (110 loc) · 5.56 KB
/
export.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
<?php // $Id$
/**
* Export quiz questions into the given category
*
* @author Martin Dougiamas, Howard Miller, and many others.
* {@link http://moodle.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
* @package questionbank
* @subpackage importexport
*/
require_once("../config.php");
require_once("editlib.php");
require_once("export_form.php");
list($thispageurl, $contexts, $cmid, $cm, $module, $pagevars) = question_edit_setup('export');
// get display strings
$strexportquestions = get_string('exportquestions', 'quiz');
// make sure we are using the user's most recent category choice
if (empty($categoryid)) {
$categoryid = $pagevars['cat'];
}
// ensure the files area exists for this course
make_upload_directory("$COURSE->id");
list($catid, $catcontext) = explode(',', $pagevars['cat']);
if (!$category = $DB->get_record("question_categories", array("id" => $catid, 'contextid' => $catcontext))) {
print_error('nocategory','quiz');
}
/// Header
if ($cm!==null) {
$strupdatemodule = has_capability('moodle/course:manageactivities', $contexts->lowest())
? update_module_button($cm->id, $COURSE->id, get_string('modulename', $cm->modname))
: "";
$navlinks = array();
$navlinks[] = array('name' => get_string('modulenameplural', $cm->modname), 'link' => "$CFG->wwwroot/mod/{$cm->modname}/index.php?id=$COURSE->id", 'type' => 'activity');
$navlinks[] = array('name' => format_string($module->name), 'link' => "$CFG->wwwroot/mod/{$cm->modname}/view.php?id={$cm->id}", 'type' => 'title');
$navlinks[] = array('name' => $strexportquestions, 'link' => '', 'type' => 'title');
$navigation = build_navigation($navlinks);
print_header_simple($strexportquestions, '', $navigation, "", "", true, $strupdatemodule);
$currenttab = 'edit';
$mode = 'export';
${$cm->modname} = $module;
include($CFG->dirroot."/mod/$cm->modname/tabs.php");
} else {
// Print basic page layout.
$navlinks = array();
$navlinks[] = array('name' => $strexportquestions, 'link' => '', 'type' => 'title');
$navigation = build_navigation($navlinks);
print_header_simple($strexportquestions, '', $navigation);
// print tabs
$currenttab = 'export';
include('tabs.php');
}
$exportfilename = default_export_filename($COURSE, $category);
$export_form = new question_export_form($thispageurl, array('contexts'=>$contexts->having_one_edit_tab_cap('export'), 'defaultcategory'=>$pagevars['cat'],
'defaultfilename'=>$exportfilename));
if ($from_form = $export_form->get_data()) { /// Filename
if (! is_readable("format/$from_form->format/format.php")) {
print_error('unknowformat', '', '', $from_form->format);
}
// load parent class for import/export
require_once("format.php");
// and then the class for the selected format
require_once("format/$from_form->format/format.php");
$classname = "qformat_$from_form->format";
$qformat = new $classname();
$qformat->setContexts($contexts->having_one_edit_tab_cap('export'));
$qformat->setCategory($category);
$qformat->setCourse($COURSE);
if (empty($from_form->exportfilename)) {
$from_form->exportfilename = default_export_filename($COURSE, $category);
}
$qformat->setFilename($from_form->exportfilename);
$canaccessbackupdata = has_capability('moodle/site:backup', $contexts->lowest());
$qformat->set_can_access_backupdata($canaccessbackupdata);
$qformat->setCattofile(!empty($from_form->cattofile));
$qformat->setContexttofile(!empty($from_form->contexttofile));
if (! $qformat->exportpreprocess()) { // Do anything before that we need to
print_error('exporterror', 'question', $thispageurl->out());
}
if (! $qformat->exportprocess()) { // Process the export data
print_error('exporterror', 'question', $thispageurl->out());
}
if (! $qformat->exportpostprocess()) { // In case anything needs to be done after
print_error('exporterror', 'question', $thispageurl->out());
}
echo "<hr />";
// link to download the finished file
$file_ext = $qformat->export_file_extension();
$filename = $from_form->exportfilename . $file_ext;
if ($canaccessbackupdata) {
$efile = get_file_url($qformat->question_get_export_dir() . '/' . $filename,
array('forcedownload' => 1));
echo '<p><div class="boxaligncenter"><a href="' . $efile . '">' .
get_string('download', 'quiz') . '</a></div></p>';
echo '<p><div class="boxaligncenter"><font size="-1">' .
get_string('downloadextra', 'quiz') . '</font></div></p>';
} else {
$efile = get_file_url($filename, null, 'questionfile');
echo '<p><div class="boxaligncenter">' .
get_string('yourfileshoulddownload', 'question', $efile) . '</div></p>';
print_delayed_js_call(1, 'document.location.replace', array($efile));
}
print_continue('edit.php?' . $thispageurl->get_query_string());
print_footer($COURSE);
exit;
}
/// Display export form
print_heading_with_help($strexportquestions, 'export', 'quiz');
$export_form->display();
print_footer($COURSE);
?>