forked from reportico-web/reportico
-
Notifications
You must be signed in to change notification settings - Fork 0
/
reportico_report_xml.php
164 lines (135 loc) · 4.58 KB
/
reportico_report_xml.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
<?php
/*
Reportico - PHP Reporting Tool
Copyright (C) 2010-2014 Peter Deed
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* File: reportico_report_xml.php
*
* Base class for all report output formats.
* Defines base functionality for handling report
* page headers, footers, group headers, group trailers
* data lines
*
* @link http://www.reportico.org/
* @copyright 2010-2014 Peter Deed
* @author Peter Deed <[email protected]>
* @package Reportico
* @license - http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
* @version $Id: swoutput.php,v 1.33 2014/05/17 15:12:31 peter Exp $
*/
require_once("reportico_report.php");
class reportico_report_xml extends reportico_report
{
var $record_template;
var $results = array();
var $line_ct = 0;
function __construct ()
{
$this->page_width = 595;
$this->page_height = 842;
$this->column_spacing = "2%";
}
function start ()
{
reportico_report::start();
$title = $this->reporttitle;
$this->results=array(
"title" => $title,
"timestamp" => date("Y-m-d\TH:i:s\Z", time()),
"displaylike" => array(),
"data" => array()
);
$ct=0;
}
function finish ()
{
reportico_report::finish();
$xmlroot = preg_replace("/\.xml$/", "", $this->query->xmloutfile);
$xml = $this->arrayToXML($this->results, new SimpleXMLElement('<'.$xmlroot.'/>'))->asXml();
$len = strlen($xml);
if ( ob_get_length() > 0 )
ob_end_clean();
header('Cache-Control: no-cache, must-revalidate');
header('Content-Type: text/xml');
header("Content-Length: $len");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header('Content-Disposition: inline; filename=reportico.xml');
echo $xml;
die;
}
function arrayToXML1($root_element_name,$ar)
{
$xml = new SimpleXMLElement("<?xml version=\"1.0\"?><".$root_element_name."></".$root_element_name.">");
$f = create_function('$f,$c,$a','
foreach($a as $k=>$v) {
if(is_array($v)) {
$ch=$c->addChild($k);
$f($f,$ch,$v);
} else {
$c->addChild($k,$v);
}
}');
$f($f,$xml,$ar);
return $xml->asXML();
}
function arrayToXml(array $arr, SimpleXMLElement $xml)
{
foreach ($arr as $k => $v) {
if ( is_array ($v) && count($v) == 0 )
continue;
if ( preg_match("/^dataline_/", $k ) ) $k = "dataline";
is_array($v) ? $this->arrayToXml($v, $xml->addChild($k)) : $xml->addChild($k, $v);
}
return $xml;
}
function format_column(& $column_item)
{
if ( !$this->show_column_header($column_item) )
return;
$k =& $column_item->column_value;
$padstring = str_pad($k,20);
}
function each_line($val)
{
reportico_report::each_line($val);
// Set the values for the fields in the record
$linekey = "dataline_".($this->line_ct + 1);
$this->results["data"][$linekey] = array();
if ( $this->line_ct == 0 )
{
$qn = get_query_column("golap", $this->columns ) ;
if ( $qn )
{
$arr = explode ( ",", $qn->column_value );
foreach ( $arr as $k => $v )
{
$arr1 = explode ( "=", $v );
$this->results["displaylike"][$arr1[0]] = $arr1[1];
}
}
}
foreach ( $this->query->display_order_set["column"] as $col )
{
$qn = get_query_column($col->query_name, $this->columns ) ;
$coltitle = $col->derive_attribute( "column_title", $col->query_name);
$coltitle = str_replace("_", " ", $coltitle);
$coltitle = ucwords(strtolower($coltitle));
$coltitle = sw_translate($coltitle);
$disp = $col->derive_attribute( "column_display", "show" );
if ( $disp == "hide" ) continue;
$this->results["data"][$linekey][preg_replace("/ /", "", $coltitle)] = $qn->column_value;
}
$this->line_ct++;
}
}
?>