MDL-21845 user profile: Fixed missing multilang support
[moodle.git] / mod / feedback / export.php
CommitLineData
84973212 1<?php
2
c70ad9f7 3/**
84973212 4 * prints the form to export the items as xml-file
5 *
6 * @author Andreas Grabs
7 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
8 * @package feedback
9 */
10
11require_once("../../config.php");
12require_once("lib.php");
13
14// get parameters
1adbd2c3 15$id = required_param('id', PARAM_INT);
84973212 16$action = optional_param('action', false, PARAM_ALPHA);
17
a6855934 18$url = new moodle_url('/mod/feedback/export.php', array('id'=>$id));
84973212 19if ($action !== false) {
20 $url->param('action', $action);
21}
22$PAGE->set_url($url);
23
24if ($id) {
25 if (! $cm = get_coursemodule_from_id('feedback', $id)) {
26 print_error('invalidcoursemodule');
c70ad9f7 27 }
c70ad9f7 28
84973212 29 if (! $course = $DB->get_record("course", array("id"=>$cm->course))) {
30 print_error('coursemisconf');
c70ad9f7 31 }
84973212 32
33 if (! $feedback = $DB->get_record("feedback", array("id"=>$cm->instance))) {
34 print_error('invalidcoursemodule');
c70ad9f7 35 }
84973212 36}
37$capabilities = feedback_load_capabilities($cm->id);
38
39require_login($course->id, true, $cm);
40
41if(!$capabilities->edititems){
42 print_error('invalidaction');
43}
c70ad9f7 44
84973212 45if ($action == 'exportfile') {
46 if(!$exportdata = feedback_get_xml_data($feedback->id)) {
47 print_error('nodata');
48 }
49 @feedback_send_xml_data($exportdata, 'feedback_'.$feedback->id.'.xml');
c70ad9f7 50 exit;
84973212 51}
52
53redirect('view.php?id='.$id);
54exit;
55
56function feedback_get_xml_data($feedbackid) {
57 global $DB;
58
59 $space = ' ';
60 //get all items of the feedback
61 if(!$items = $DB->get_records('feedback_item', array('feedback'=>$feedbackid), 'position')) {
62 return false;
c70ad9f7 63 }
84973212 64
65 //writing the header of the xml file including the charset of the currrent used language
66 $data = '<?xml version="1.0" encoding="UTF-8" ?>'."\n";
67 $data .= '<FEEDBACK VERSION="200701" COMMENT="XML-Importfile for mod/feedback">'."\n";
68 $data .= $space.'<ITEMS>'."\n";
69
70 //writing all the items
71 foreach($items as $item) {
72 //start of item
73 $data .= $space.$space.'<ITEM TYPE="'.$item->typ.'" REQUIRED="'.$item->required.'">'."\n";
74
75 //start of itemtext
76 $data .= $space.$space.$space.'<ITEMTEXT>'."\n";
77 //start of CDATA
78 $data .= $space.$space.$space.$space.'<![CDATA[';
79 $data .= $item->name;
80 //end of CDATA
81 $data .= ']]>'."\n";
82 //end of itemtext
83 $data .= $space.$space.$space.'</ITEMTEXT>'."\n";
84
85 //start of presentation
86 $data .= $space.$space.$space.'<PRESENTATION>'."\n";
87 //start of CDATA
88 $data .= $space.$space.$space.$space.'<![CDATA[';
89 $data .= $item->presentation;
90 //end of CDATA
91 $data .= ']]>'."\n";
92 //end of presentation
93 $data .= $space.$space.$space.'</PRESENTATION>'."\n";
94
95 //end of item
96 $data .= $space.$space.'</ITEM>'."\n";
c70ad9f7 97 }
84973212 98
99 //writing the footer of the xml file
100 $data .= $space.'</ITEMS>'."\n";
101 $data .= '</FEEDBACK>'."\n";
102
103 return $data;
104}
105
106function feedback_send_xml_data($data, $filename) {
107 $charset = get_string('thischarset');
108 @header('Content-Type: application/xml; charset=UTF-8');
109 @header('Content-Disposition: attachment; filename='.$filename);
110 print($data);
111}