1 <?php
3 class csvExporter
4 {
5 var $result;
7 function csvExporter($header, $entries, $columns= array()) {
8 // If no preset, render all columns
9 if (!count($columns)) {
10 foreach ($header as $index => $dummy) {
11 $columns[]= $index;
12 }
13 }
15 // Generate header
16 $this->result= "#";
17 foreach ($columns as $index) {
18 if (isset($header[$index])){
19 $this->result.= $header[$index].";";
20 } else {
21 $this->result.= ";";
22 }
23 }
24 $this->result= preg_replace('/;$/', '', $this->result)."\n";
26 // Append entries
27 foreach ($entries as $row) {
28 foreach ($columns as $index) {
29 if (isset($row["_sort$index"])){
30 $this->result.= $row["_sort$index"].";";
31 } else {
32 $this->result.= ";";
33 }
34 }
35 $this->result= preg_replace('/;$/', '', $this->result)."\n";
36 }
37 }
40 function query()
41 {
42 return $this->result;
43 }
46 static function getInfo()
47 {
48 return array("exportCVS" => array( "label" => _("CSV"), "image" => "plugins/lists/exportCSV.png", "class"=> "csvExporter", "mime" => "text/x-csv", "filename" => "export.csv" ));
49 }
51 }
53 ?>