"MDL-12304, fix double text"
[moodle-linuxchix.git] / grade / export / txt / grade_export_txt.php
blob29dcdcc4e0c9330973be96ffd2d8fd830d987008
1 <?php
2 ///////////////////////////////////////////////////////////////////////////
3 // //
4 // NOTICE OF COPYRIGHT //
5 // //
6 // Moodle - Modular Object-Oriented Dynamic Learning Environment //
7 // http://moodle.com //
8 // //
9 // Copyright (C) 1999 onwards Martin Dougiamas http://moodle.com //
10 // //
11 // This program is free software; you can redistribute it and/or modify //
12 // it under the terms of the GNU General Public License as published by //
13 // the Free Software Foundation; either version 2 of the License, or //
14 // (at your option) any later version. //
15 // //
16 // This program is distributed in the hope that it will be useful, //
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of //
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
19 // GNU General Public License for more details: //
20 // //
21 // http://www.gnu.org/copyleft/gpl.html //
22 // //
23 ///////////////////////////////////////////////////////////////////////////
25 require_once($CFG->dirroot.'/grade/export/lib.php');
27 class grade_export_txt extends grade_export {
29 var $plugin = 'txt';
31 var $separator; // default separator
33 function grade_export_txt($course, $groupid=0, $itemlist='', $export_feedback=false, $updatedgradesonly = false, $displaytype = GRADE_DISPLAY_TYPE_REAL, $decimalpoints = 2, $separator='comma') {
34 $this->grade_export($course, $groupid, $itemlist, $export_feedback, $updatedgradesonly, $displaytype, $decimalpoints);
35 $this->separator = $separator;
38 function process_form($formdata) {
39 parent::process_form($formdata);
40 if (isset($formdata->separator)) {
41 $this->separator = $formdata->separator;
45 function get_export_params() {
46 $params = parent::get_export_params();
47 $params['separator'] = $this->separator;
48 return $params;
51 function print_grades() {
52 global $CFG;
54 $export_tracking = $this->track_exports();
56 $strgrades = get_string('grades');
58 switch ($this->separator) {
59 case 'comma':
60 $separator = ",";
61 break;
62 case 'tab':
63 default:
64 $separator = "\t";
67 /// Print header to force download
68 @header('Cache-Control: private, must-revalidate, pre-check=0, post-check=0, max-age=0');
69 @header('Expires: '. gmdate('D, d M Y H:i:s', 0) .' GMT');
70 @header('Pragma: no-cache');
71 header("Content-Type: application/download\n");
72 $downloadfilename = clean_filename("{$this->course->shortname} $strgrades");
73 header("Content-Disposition: attachment; filename=\"$downloadfilename.txt\"");
75 /// Print names of all the fields
76 echo get_string("firstname").$separator.
77 get_string("lastname").$separator.
78 get_string("idnumber").$separator.
79 get_string("institution").$separator.
80 get_string("department").$separator.
81 get_string("email");
83 foreach ($this->columns as $grade_item) {
84 echo $separator.$this->format_column_name($grade_item);
86 /// add a feedback column
87 if ($this->export_feedback) {
88 echo $separator.$this->format_column_name($grade_item, true);
91 echo "\n";
93 /// Print all the lines of data.
94 $geub = new grade_export_update_buffer();
95 $gui = new graded_users_iterator($this->course, $this->columns, $this->groupid);
96 $gui->init();
97 while ($userdata = $gui->next_user()) {
99 $user = $userdata->user;
101 echo $user->firstname.$separator.$user->lastname.$separator.$user->idnumber.$separator.$user->institution.$separator.$user->department.$separator.$user->email;
103 foreach ($userdata->grades as $itemid => $grade) {
104 if ($export_tracking) {
105 $status = $geub->track($grade);
108 echo $separator.$this->format_grade($grade);
110 if ($this->export_feedback) {
111 echo $separator.$this->format_feedback($userdata->feedbacks[$itemid]);
114 echo "\n";
116 $gui->close();
117 $geub->close();
119 exit;