2 // This file is part of Moodle - http://moodle.org/
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
18 * prints the form to export the items as xml-file
20 * @author Andreas Grabs
21 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
22 * @package mod_feedback
25 require_once("../../config.php");
26 require_once("lib.php");
29 $id = required_param('id', PARAM_INT
);
30 $action = optional_param('action', false, PARAM_ALPHA
);
32 $url = new moodle_url('/mod/feedback/export.php', array('id'=>$id));
33 if ($action !== false) {
34 $url->param('action', $action);
38 if (! $cm = get_coursemodule_from_id('feedback', $id)) {
39 print_error('invalidcoursemodule');
42 if (! $course = $DB->get_record("course", array("id"=>$cm->course
))) {
43 print_error('coursemisconf');
46 if (! $feedback = $DB->get_record("feedback", array("id"=>$cm->instance
))) {
47 print_error('invalidcoursemodule');
50 $context = context_module
::instance($cm->id
);
52 require_login($course, true, $cm);
54 require_capability('mod/feedback:edititems', $context);
56 if ($action == 'exportfile') {
57 if (!$exportdata = feedback_get_xml_data($feedback->id
)) {
58 print_error('nodata');
60 @feedback_send_xml_data
($exportdata, 'feedback_'.$feedback->id
.'.xml');
64 redirect('view.php?id='.$id);
67 function feedback_get_xml_data($feedbackid) {
71 //get all items of the feedback
72 if (!$items = $DB->get_records('feedback_item', array('feedback'=>$feedbackid), 'position')) {
76 //writing the header of the xml file including the charset of the currrent used language
77 $data = '<?xml version="1.0" encoding="UTF-8" ?>'."\n";
78 $data .= '<FEEDBACK VERSION="200701" COMMENT="XML-Importfile for mod/feedback">'."\n";
79 $data .= $space.'<ITEMS>'."\n";
81 //writing all the items
82 foreach ($items as $item) {
84 $data .= $space.$space.'<ITEM TYPE="'.$item->typ
.'" REQUIRED="'.$item->required
.'">'."\n";
87 $data .= $space.$space.$space.'<ITEMID>'."\n";
89 $data .= $space.$space.$space.$space.'<![CDATA[';
94 $data .= $space.$space.$space.'</ITEMID>'."\n";
97 $data .= $space.$space.$space.'<ITEMTEXT>'."\n";
99 $data .= $space.$space.$space.$space.'<![CDATA[';
100 $data .= $item->name
;
104 $data .= $space.$space.$space.'</ITEMTEXT>'."\n";
107 $data .= $space.$space.$space.'<ITEMLABEL>'."\n";
109 $data .= $space.$space.$space.$space.'<![CDATA[';
110 $data .= $item->label
;
114 $data .= $space.$space.$space.'</ITEMLABEL>'."\n";
116 //start of presentation
117 $data .= $space.$space.$space.'<PRESENTATION>'."\n";
119 $data .= $space.$space.$space.$space.'<![CDATA[';
120 $data .= $item->presentation
;
123 //end of presentation
124 $data .= $space.$space.$space.'</PRESENTATION>'."\n";
127 $data .= $space.$space.$space.'<OPTIONS>'."\n";
129 $data .= $space.$space.$space.$space.'<![CDATA[';
130 $data .= $item->options
;
134 $data .= $space.$space.$space.'</OPTIONS>'."\n";
136 //start of dependitem
137 $data .= $space.$space.$space.'<DEPENDITEM>'."\n";
139 $data .= $space.$space.$space.$space.'<![CDATA[';
140 $data .= $item->dependitem
;
144 $data .= $space.$space.$space.'</DEPENDITEM>'."\n";
146 //start of dependvalue
147 $data .= $space.$space.$space.'<DEPENDVALUE>'."\n";
149 $data .= $space.$space.$space.$space.'<![CDATA[';
150 $data .= $item->dependvalue
;
154 $data .= $space.$space.$space.'</DEPENDVALUE>'."\n";
157 $data .= $space.$space.'</ITEM>'."\n";
160 //writing the footer of the xml file
161 $data .= $space.'</ITEMS>'."\n";
162 $data .= '</FEEDBACK>'."\n";
167 function feedback_send_xml_data($data, $filename) {
168 @header
('Content-Type: application/xml; charset=UTF-8');
169 @header
('Content-Disposition: attachment; filename="'.$filename.'"');