MDL-73912 templates: Proper type value for back to user menu button
[moodle.git] / mod / feedback / export.php
blob6f6672817ec3cb07ce6211e082fb08c7c1dbf02f
1 <?php
2 // This file is part of Moodle - http://moodle.org/
3 //
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.
8 //
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/>.
17 /**
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");
28 // get parameters
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);
36 $PAGE->set_url($url);
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');
61 exit;
64 redirect('view.php?id='.$id);
65 exit;
67 function feedback_get_xml_data($feedbackid) {
68 global $DB;
70 $space = ' ';
71 //get all items of the feedback
72 if (!$items = $DB->get_records('feedback_item', array('feedback'=>$feedbackid), 'position')) {
73 return false;
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) {
83 //start of item
84 $data .= $space.$space.'<ITEM TYPE="'.$item->typ.'" REQUIRED="'.$item->required.'">'."\n";
86 //start of itemid
87 $data .= $space.$space.$space.'<ITEMID>'."\n";
88 //start of CDATA
89 $data .= $space.$space.$space.$space.'<![CDATA[';
90 $data .= $item->id;
91 //end of CDATA
92 $data .= ']]>'."\n";
93 //end of itemid
94 $data .= $space.$space.$space.'</ITEMID>'."\n";
96 //start of itemtext
97 $data .= $space.$space.$space.'<ITEMTEXT>'."\n";
98 //start of CDATA
99 $data .= $space.$space.$space.$space.'<![CDATA[';
100 $data .= $item->name;
101 //end of CDATA
102 $data .= ']]>'."\n";
103 //end of itemtext
104 $data .= $space.$space.$space.'</ITEMTEXT>'."\n";
106 //start of itemtext
107 $data .= $space.$space.$space.'<ITEMLABEL>'."\n";
108 //start of CDATA
109 $data .= $space.$space.$space.$space.'<![CDATA[';
110 $data .= $item->label;
111 //end of CDATA
112 $data .= ']]>'."\n";
113 //end of itemtext
114 $data .= $space.$space.$space.'</ITEMLABEL>'."\n";
116 //start of presentation
117 $data .= $space.$space.$space.'<PRESENTATION>'."\n";
118 //start of CDATA
119 $data .= $space.$space.$space.$space.'<![CDATA[';
120 $data .= $item->presentation;
121 //end of CDATA
122 $data .= ']]>'."\n";
123 //end of presentation
124 $data .= $space.$space.$space.'</PRESENTATION>'."\n";
126 //start of options
127 $data .= $space.$space.$space.'<OPTIONS>'."\n";
128 //start of CDATA
129 $data .= $space.$space.$space.$space.'<![CDATA[';
130 $data .= $item->options;
131 //end of CDATA
132 $data .= ']]>'."\n";
133 //end of options
134 $data .= $space.$space.$space.'</OPTIONS>'."\n";
136 //start of dependitem
137 $data .= $space.$space.$space.'<DEPENDITEM>'."\n";
138 //start of CDATA
139 $data .= $space.$space.$space.$space.'<![CDATA[';
140 $data .= $item->dependitem;
141 //end of CDATA
142 $data .= ']]>'."\n";
143 //end of dependitem
144 $data .= $space.$space.$space.'</DEPENDITEM>'."\n";
146 //start of dependvalue
147 $data .= $space.$space.$space.'<DEPENDVALUE>'."\n";
148 //start of CDATA
149 $data .= $space.$space.$space.$space.'<![CDATA[';
150 $data .= $item->dependvalue;
151 //end of CDATA
152 $data .= ']]>'."\n";
153 //end of dependvalue
154 $data .= $space.$space.$space.'</DEPENDVALUE>'."\n";
156 //end of item
157 $data .= $space.$space.'</ITEM>'."\n";
160 //writing the footer of the xml file
161 $data .= $space.'</ITEMS>'."\n";
162 $data .= '</FEEDBACK>'."\n";
164 return $data;
167 function feedback_send_xml_data($data, $filename) {
168 @header('Content-Type: application/xml; charset=UTF-8');
169 @header('Content-Disposition: attachment; filename="'.$filename.'"');
170 print($data);