-
Notifications
You must be signed in to change notification settings - Fork 0
/
export.php
172 lines (147 loc) · 5.73 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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* prints the form to export the items as xml-file
*
* @author Andreas Grabs
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
* @package mod_evaluation
*/
require_once("../../config.php");
require_once("lib.php");
global $USER;
// get parameters
$id = required_param('id', PARAM_INT);
$action = optional_param('action', false, PARAM_ALPHA);
$url = new moodle_url('/mod/evaluation/export.php', array('id' => $id));
if ($action !== false) {
$url->param('action', $action);
}
$PAGE->set_url($url);
if (!$cm = get_coursemodule_from_id('evaluation', $id)) {
throw new moodle_exception('invalidcoursemodule');
}
if (!$course = $DB->get_record("course", array("id" => $cm->course))) {
throw new moodle_exception('coursemisconf');
}
if (!$evaluation = $DB->get_record("evaluation", array("id" => $cm->instance))) {
throw new moodle_exception('invalidcoursemodule');
}
$context = context_module::instance($cm->id);
require_login($course, true, $cm);
if ( !isset($_SESSION["privileged_users"][$USER->username])) {
require_capability('mod/evaluation:edititems', $context);
}
if ($action == 'exportfile') {
if (!$exportdata = evaluation_get_xml_data($evaluation->id)) {
throw new moodle_exception('nodata');
}
@evaluation_send_xml_data($exportdata, 'evaluation_' . $evaluation->id . '.xml');
exit;
}
redirect('view.php?id=' . $id);
exit;
function evaluation_get_xml_data($evaluationid) {
global $DB;
$space = ' ';
//get all items of the evaluation
if (!$items = $DB->get_records('evaluation_item', array('evaluation' => $evaluationid), 'position')) {
return false;
}
//writing the header of the xml file including the charset of the currrent used language
$data = '<?xml version="1.0" encoding="UTF-8" ?>' . "\n";
$data .= '<EVALUATION VERSION="200701" COMMENT="XML-Importfile for mod/evaluation">' . "\n";
$data .= $space . '<ITEMS>' . "\n";
//writing all the items
foreach ($items as $item) {
//start of item
$data .= $space . $space . '<ITEM TYPE="' . $item->typ . '" REQUIRED="' . $item->required . '">' . "\n";
//start of itemid
$data .= $space . $space . $space . '<ITEMID>' . "\n";
//start of CDATA
$data .= $space . $space . $space . $space . '<![CDATA[';
$data .= $item->id;
//end of CDATA
$data .= ']]>' . "\n";
//end of itemid
$data .= $space . $space . $space . '</ITEMID>' . "\n";
//start of itemtext
$data .= $space . $space . $space . '<ITEMTEXT>' . "\n";
//start of CDATA
$data .= $space . $space . $space . $space . '<![CDATA[';
$data .= $item->name;
//end of CDATA
$data .= ']]>' . "\n";
//end of itemtext
$data .= $space . $space . $space . '</ITEMTEXT>' . "\n";
//start of itemtext
$data .= $space . $space . $space . '<ITEMLABEL>' . "\n";
//start of CDATA
$data .= $space . $space . $space . $space . '<![CDATA[';
$data .= $item->label;
//end of CDATA
$data .= ']]>' . "\n";
//end of itemtext
$data .= $space . $space . $space . '</ITEMLABEL>' . "\n";
//start of presentation
$data .= $space . $space . $space . '<PRESENTATION>' . "\n";
//start of CDATA
$data .= $space . $space . $space . $space . '<![CDATA[';
$data .= $item->presentation;
//end of CDATA
$data .= ']]>' . "\n";
//end of presentation
$data .= $space . $space . $space . '</PRESENTATION>' . "\n";
//start of options
$data .= $space . $space . $space . '<OPTIONS>' . "\n";
//start of CDATA
$data .= $space . $space . $space . $space . '<![CDATA[';
$data .= $item->options;
//end of CDATA
$data .= ']]>' . "\n";
//end of options
$data .= $space . $space . $space . '</OPTIONS>' . "\n";
//start of dependitem
$data .= $space . $space . $space . '<DEPENDITEM>' . "\n";
//start of CDATA
$data .= $space . $space . $space . $space . '<![CDATA[';
$data .= $item->dependitem;
//end of CDATA
$data .= ']]>' . "\n";
//end of dependitem
$data .= $space . $space . $space . '</DEPENDITEM>' . "\n";
//start of dependvalue
$data .= $space . $space . $space . '<DEPENDVALUE>' . "\n";
//start of CDATA
$data .= $space . $space . $space . $space . '<![CDATA[';
$data .= $item->dependvalue;
//end of CDATA
$data .= ']]>' . "\n";
//end of dependvalue
$data .= $space . $space . $space . '</DEPENDVALUE>' . "\n";
//end of item
$data .= $space . $space . '</ITEM>' . "\n";
}
//writing the footer of the xml file
$data .= $space . '</ITEMS>' . "\n";
$data .= '</EVALUATION>' . "\n";
return $data;
}
function evaluation_send_xml_data($data, $filename) {
@header('Content-Type: application/xml; charset=UTF-8');
@header('Content-Disposition: attachment; filename="' . $filename . '"');
print($data);
}