/adei/ui

To get this branch, use:
bzr branch http://darksoft.org/webbzr/adei/ui

« back to all changes in this revision

Viewing changes to classes/handlers/csv.php

  • Committer: Suren A. Chilingaryan
  • Date: 2008-04-02 10:23:22 UTC
  • Revision ID: csa@dside.dyndns.org-20080402102322-okib92sicg2dx3o3
Initial import

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
 
 
3
class CSVHandler extends DATAHandler {
 
4
 var $separator;
 
5
 
 
6
 var $date_format;
 
7
 
 
8
 function __construct(&$opts = NULL, STREAMHandler $h  = NULL) {
 
9
    global $CSV_SEPARATOR;
 
10
    global $CSV_DATE_FORMAT;
 
11
 
 
12
    $this->content_type = "text/csv";
 
13
    $this->extension = "csv"; 
 
14
 
 
15
    parent::__construct($opts, $h);
 
16
    
 
17
    if ($opts) {
 
18
        $this->separator = $opts['separator'];
 
19
        $this->date_format = $opts['date_format'];
 
20
    }
 
21
    
 
22
    if (!$this->separator) $this->separator = $CSV_SEPARATOR;
 
23
    if (!$this->date_format) $this->date_format = $CSV_DATE_FORMAT;
 
24
 }
 
25
 
 
26
 function TimeHeader($flags = 0) {
 
27
    $this->h->Write("Date/Time");
 
28
 }
 
29
 
 
30
 function DataHeader(&$header, $i, $flags = 0) {
 
31
    $this->h->Write($this->separator . " " . preg_replace("/" . $this->separator . "/", " ", $header));
 
32
 }
 
33
 
 
34
 function HeaderEnd($flags = 0) {
 
35
    $this->h->Write("\r\n");
 
36
 }
 
37
 
 
38
 function VectorEnd($flags = 0) {
 
39
    $this->h->Write("\r\n");
 
40
 }
 
41
 
 
42
 function TimeValue(&$time, $flags = 0) {
 
43
        if ($this->subseconds) {
 
44
/*
 
45
            if (is_float($unix_time)) $subsec = strchr(sprintf("%F", $unix_time), '.');
 
46
            else $subsec = strchr($unix_time, '.');
 
47
*/
 
48
            $subsec = strchr(sprintf("%.6F", $time), '.');
 
49
            $this->h->Write(date($this->date_format, $time) . $subsec);
 
50
        } else 
 
51
            $this->h->Write(date($this->date_format, $time));
 
52
 }
 
53
 
 
54
 function DataValue(&$value, $i, $flags = 0) {
 
55
    $this->h->Write($this->separator . " " . $value);
 
56
 }
 
57
}
 
58
 
 
59
?>
 
 
b'\\ No newline at end of file'