-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathbit_reportengine.php
More file actions
212 lines (191 loc) · 7.15 KB
/
bit_reportengine.php
File metadata and controls
212 lines (191 loc) · 7.15 KB
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
<?php
/**
* Report Engine
*
* Processes PGV XML Reports and generates a report
*
* phpGedView: Genealogy Viewer
* Copyright (C) 2002 to 2005 John Finlay and Others
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* @package PhpGedView
* @subpackage Reports
* @version $Id$
*/
/**
* Initialization
*/
require_once( '../kernel/setup_inc.php' );
// Is package installed and enabled
$gBitSystem->verifyPackage( 'phpgedview' );
include_once( PHPGEDVIEW_PKG_PATH.'BitGEDCOM.php' );
$gGedcom = new BitGEDCOM();
require_once("includes/functions_charts.php");
require(PHPGEDVIEW_PKG_PATH."languages/lang.en.php");
//if (file_exists($factsfile[$LANGUAGE])) require($factsfile[$LANGUAGE]);
//-- try to increase the time limit because reports can take a long time
@set_time_limit($TIME_LIMIT*2);
/**
* function to get the values for the given tag
*/
function get_tag_values($tag) {
global $tags, $values;
$indexes = $tags[$tag];
$vals = array();
foreach($indexes as $indexval => $i) {
$vals[] = $values[$i];
}
return $vals;
}
if (!isset($_REQUEST['action'])) $action = "choose";
else $action = $_REQUEST['action'];
if (!isset($_REQUEST['report'])) $report = "";
else $report = $_REQUEST['report'];
if (!isset($output)) $output = "PDF";
if (!isset($_REQUEST['vars'])) $vars = array();
else $vars = $_REQUEST['vars'];
if (!isset($_REQUEST['varnames'])) $varnames = array();
else $varnames = $_REQUEST['varnames'];
if (!isset($_REQUEST['$type'])) $type = array();
else $type = $_REQUEST['type'];
//-- setup the arrays
$newvars = array();
foreach($vars as $name=>$var) {
$var = clean_input($var);
$newvars[$name]["id"] = $var;
if (!empty($type[$name]) && (($type[$name]=="INDI")||($type[$name]=="FAM")||($type[$name]=="SOUR"))) {
$gedcom = find_gedcom_record($var);
if (empty($gedcom)) $action="setup";
if ($type[$name]=="FAM") {
if (preg_match("/0 @.*@ INDI/", $gedcom)>0) {
$fams = find_sfamily_ids($var);
if (!empty($fams[0])) {
$gedcom = find_family_record($fams[0]);
if (!empty($gedcom)) $vars[$name] = $fams[0];
else $action="setup";
}
}
}
$newvars[$name]["gedcom"] = $gedcom;
}
}
$vars = $newvars;
foreach($varnames as $indexval => $name) {
if (!isset($vars[$name])) {
$vars[$name]["id"] = "";
}
}
if ($report == "" && $action!="run" ) {
$reports = get_report_list();
}
if (!empty($report)) {
$r = basename($report);
// if (!isset($reports[$r]["access"])) $action = "choose";
// else if ($reports[$r]["access"]<getUserAccessLevel(getUserName())) $action = "choose";
}
//-- choose a report to run
//-- setup report to run
if ($action=="setup") {
//-- make sure the report exists
if (!file_exists(PHPGEDVIEW_PKG_PATH.$report)) {
$gBitSmarty->assign('errors', 'The specified report cannot be found' );
$action = 'choose';
}
else {
require_once("includes/reportheader.php");
$report_array = array();
//-- start the sax parser
$xml_parser = xml_parser_create();
//-- make sure everything is case sensitive
xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, false);
//-- set the main element handler functions
xml_set_element_handler($xml_parser, "startElement", "endElement");
//-- set the character data handler
xml_set_character_data_handler($xml_parser, "characterData");
//-- open the file
if (!($fp = fopen(PHPGEDVIEW_PKG_PATH.$report, "r"))) {
die("could not open XML input");
}
//-- read the file and parse it 4kb at a time
while ($data = fread($fp, 4096)) {
if (!xml_parse($xml_parser, $data, feof($fp))) {
die(sprintf($data."\nXML error: %s at line %d", xml_error_string(xml_get_error_code($xml_parser)), xml_get_current_line_number($xml_parser)));
}
}
xml_parser_free($xml_parser);
foreach($report_array["inputs"] as $indexval => $input) {
if (!isset($input["type"])) $report_array["inputs"][$indexval]["type"] = "text";
if ($input["type"]=="select") {
$report_array["inputs"][$indexval]['select'] = preg_split("/[, ]+/", $input["options"]);
}
if (isset($input["lookup"])) {
if ($input["lookup"]=="INDI") {
if (isset($_REQUEST['pid'])) $report_array["inputs"][$indexval]["default"] = clean_input($_REQUEST['pid']);
else $report_array["inputs"][$indexval]["default"] = check_rootid($input["default"]);
}
if ($input["lookup"]=="FAM") {
if (isset($_REQUEST['famid'])) $report_array["inputs"][$indexval]["default"] = clean_input($_REQUEST['famid']);
}
if ($input["lookup"]=="SOUR") {
if (isset($_REQUEST['sid'])) $report_array["inputs"][$indexval]["default"] = clean_input($_REQUEST['sid']);
}
if ($input["lookup"]=="DATE") {
$report_array["calendar"] = true;
if (!isset($input["default"]) || $input["default"] == "" ) $report_array["inputs"][$indexval]["default"] = "2007-06-01";
}
else
if (!isset($input["default"])) $report_array["inputs"][$indexval]["default"] = "";
}
}
$report_array['name'] = strtoupper(basename($report));
$gBitSmarty->assign( "pagetitle", tra( 'Report options selection' ) );
$gBitSmarty->assign( "report", $report );
$gBitSmarty->assign_by_ref( "report_array", $report_array );
$gBitSystem->display( 'bitpackage:phpgedview/report_setup.tpl', tra( 'Report options selection' ) , array( 'display_mode' => 'display' ));
}
}
//-- run the report
else if ($action=="run") {
//-- load the report generator
if ($output=="HTML") require("includes/reporthtml.php");
else if ($output=="PDF") require("includes/reportpdf.php");
//-- start the sax parser
$xml_parser = xml_parser_create();
//-- make sure everything is case sensitive
xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, false);
//-- set the main element handler functions
xml_set_element_handler($xml_parser, "startElement", "endElement");
//-- set the character data handler
xml_set_character_data_handler($xml_parser, "characterData");
//-- open the file
if (!($fp = fopen(PHPGEDVIEW_PKG_PATH.$report, "r"))) {
die("could not open XML input");
}
//-- read the file and parse it 4kb at a time
while ($data = fread($fp, 4096)) {
if (!xml_parse($xml_parser, $data, feof($fp))) {
die(sprintf($data."\nXML error: %s at line %d", xml_error_string(xml_get_error_code($xml_parser)), xml_get_current_line_number($xml_parser)));
}
}
xml_parser_free($xml_parser);
}
if ($action=="choose" ) {
$reports = get_report_list(true);
$gBitSmarty->assign( "pagetitle", tra( 'Report selection' ) );
$gBitSmarty->assign_by_ref( "reports", $reports );
$gBitSystem->display( 'bitpackage:phpgedview/report_menu.tpl', tra( 'Report selection' ) , array( 'display_mode' => 'display' ));
}
?>