Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/mod/feedback/export.php
Go to the documentation of this file.
00001 <?php
00002 // This file is part of Moodle - http://moodle.org/
00003 //
00004 // Moodle is free software: you can redistribute it and/or modify
00005 // it under the terms of the GNU General Public License as published by
00006 // the Free Software Foundation, either version 3 of the License, or
00007 // (at your option) any later version.
00008 //
00009 // Moodle is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 // GNU General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU General Public License
00015 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
00016 
00025 require_once("../../config.php");
00026 require_once("lib.php");
00027 
00028 // get parameters
00029 $id = required_param('id', PARAM_INT);
00030 $action = optional_param('action', false, PARAM_ALPHA);
00031 
00032 $url = new moodle_url('/mod/feedback/export.php', array('id'=>$id));
00033 if ($action !== false) {
00034     $url->param('action', $action);
00035 }
00036 $PAGE->set_url($url);
00037 
00038 if (! $cm = get_coursemodule_from_id('feedback', $id)) {
00039     print_error('invalidcoursemodule');
00040 }
00041 
00042 if (! $course = $DB->get_record("course", array("id"=>$cm->course))) {
00043     print_error('coursemisconf');
00044 }
00045 
00046 if (! $feedback = $DB->get_record("feedback", array("id"=>$cm->instance))) {
00047     print_error('invalidcoursemodule');
00048 }
00049 
00050 if (!$context = get_context_instance(CONTEXT_MODULE, $cm->id)) {
00051         print_error('badcontext');
00052 }
00053 
00054 require_login($course->id, true, $cm);
00055 
00056 require_capability('mod/feedback:edititems', $context);
00057 
00058 if ($action == 'exportfile') {
00059     if (!$exportdata = feedback_get_xml_data($feedback->id)) {
00060         print_error('nodata');
00061     }
00062     @feedback_send_xml_data($exportdata, 'feedback_'.$feedback->id.'.xml');
00063     exit;
00064 }
00065 
00066 redirect('view.php?id='.$id);
00067 exit;
00068 
00069 function feedback_get_xml_data($feedbackid) {
00070     global $DB;
00071 
00072     $space = '     ';
00073     //get all items of the feedback
00074     if (!$items = $DB->get_records('feedback_item', array('feedback'=>$feedbackid), 'position')) {
00075         return false;
00076     }
00077 
00078     //writing the header of the xml file including the charset of the currrent used language
00079     $data = '<?xml version="1.0" encoding="UTF-8" ?>'."\n";
00080     $data .= '<FEEDBACK VERSION="200701" COMMENT="XML-Importfile for mod/feedback">'."\n";
00081     $data .= $space.'<ITEMS>'."\n";
00082 
00083     //writing all the items
00084     foreach ($items as $item) {
00085         //start of item
00086         $data .= $space.$space.'<ITEM TYPE="'.$item->typ.'" REQUIRED="'.$item->required.'">'."\n";
00087 
00088         //start of itemid
00089         $data .= $space.$space.$space.'<ITEMID>'."\n";
00090         //start of CDATA
00091         $data .= $space.$space.$space.$space.'<![CDATA[';
00092         $data .= $item->id;
00093         //end of CDATA
00094         $data .= ']]>'."\n";
00095         //end of itemid
00096         $data .= $space.$space.$space.'</ITEMID>'."\n";
00097 
00098         //start of itemtext
00099         $data .= $space.$space.$space.'<ITEMTEXT>'."\n";
00100         //start of CDATA
00101         $data .= $space.$space.$space.$space.'<![CDATA[';
00102         $data .= $item->name;
00103         //end of CDATA
00104         $data .= ']]>'."\n";
00105         //end of itemtext
00106         $data .= $space.$space.$space.'</ITEMTEXT>'."\n";
00107 
00108         //start of itemtext
00109         $data .= $space.$space.$space.'<ITEMLABEL>'."\n";
00110         //start of CDATA
00111         $data .= $space.$space.$space.$space.'<![CDATA[';
00112         $data .= $item->label;
00113         //end of CDATA
00114         $data .= ']]>'."\n";
00115         //end of itemtext
00116         $data .= $space.$space.$space.'</ITEMLABEL>'."\n";
00117 
00118         //start of presentation
00119         $data .= $space.$space.$space.'<PRESENTATION>'."\n";
00120         //start of CDATA
00121         $data .= $space.$space.$space.$space.'<![CDATA[';
00122         $data .= $item->presentation;
00123         //end of CDATA
00124         $data .= ']]>'."\n";
00125         //end of presentation
00126         $data .= $space.$space.$space.'</PRESENTATION>'."\n";
00127 
00128         //start of options
00129         $data .= $space.$space.$space.'<OPTIONS>'."\n";
00130         //start of CDATA
00131         $data .= $space.$space.$space.$space.'<![CDATA[';
00132         $data .= $item->options;
00133         //end of CDATA
00134         $data .= ']]>'."\n";
00135         //end of options
00136         $data .= $space.$space.$space.'</OPTIONS>'."\n";
00137 
00138         //start of dependitem
00139         $data .= $space.$space.$space.'<DEPENDITEM>'."\n";
00140         //start of CDATA
00141         $data .= $space.$space.$space.$space.'<![CDATA[';
00142         $data .= $item->dependitem;
00143         //end of CDATA
00144         $data .= ']]>'."\n";
00145         //end of dependitem
00146         $data .= $space.$space.$space.'</DEPENDITEM>'."\n";
00147 
00148         //start of dependvalue
00149         $data .= $space.$space.$space.'<DEPENDVALUE>'."\n";
00150         //start of CDATA
00151         $data .= $space.$space.$space.$space.'<![CDATA[';
00152         $data .= $item->dependvalue;
00153         //end of CDATA
00154         $data .= ']]>'."\n";
00155         //end of dependvalue
00156         $data .= $space.$space.$space.'</DEPENDVALUE>'."\n";
00157 
00158         //end of item
00159         $data .= $space.$space.'</ITEM>'."\n";
00160     }
00161 
00162     //writing the footer of the xml file
00163     $data .= $space.'</ITEMS>'."\n";
00164     $data .= '</FEEDBACK>'."\n";
00165 
00166     return $data;
00167 }
00168 
00169 function feedback_send_xml_data($data, $filename) {
00170     @header('Content-Type: application/xml; charset=UTF-8');
00171     @header('Content-Disposition: attachment; filename='.$filename);
00172     print($data);
00173 }
 All Data Structures Namespaces Files Functions Variables Enumerations