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
213
214
215
216
|
<?php
// Report Header Parser
// used by the SAX parser to generate PDF reports from the XML report file.
//
// webtrees: Web based Family History software
// Copyright (C) 2014 webtrees development team.
//
// Derived from PhpGedView
// Copyright (C) 2002 to 2009 PGV Development Team.
//
// 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
if (!defined('WT_WEBTREES')) {
header('HTTP/1.0 403 Forbidden');
exit;
}
/**
* element handlers array
*
* An array of element handler functions
* @global array $elementHandler
*/
$elementHandler = array();
$elementHandler["Report"]["start"] = "reportStartHandler";
$elementHandler["var"]["start"] = "varStartHandler";
$elementHandler["Title"]["start"] = "titleStartHandler";
$elementHandler["Title"]["end"] = "titleEndHandler";
$elementHandler["Description"]["end"] = "descriptionEndHandler";
$elementHandler["Input"]["start"] = "inputStartHandler";
$elementHandler["Input"]["end"] = "inputEndHandler";
$text = "";
$report_array = array();
/**
* xml start element handler
*
* this function is called whenever a starting element is reached
*
* @param resource $parser the resource handler for the xml parser
* @param string $name the name of the xml element parsed
* @param string[] $attrs an array of key value pairs for the attributes
*/
function startElement($parser, $name, $attrs) {
global $elementHandler, $processIfs;
if (($processIfs == 0) || ($name == "if")) {
if (isset($elementHandler[$name]["start"])) {
call_user_func($elementHandler[$name]["start"], $attrs);
}
}
}
/**
* xml end element handler
*
* this function is called whenever an ending element is reached
* @param resource $parser the resource handler for the xml parser
* @param string $name the name of the xml element parsed
*/
function endElement($parser, $name) {
global $elementHandler, $processIfs;
if (($processIfs == 0) || ($name == "if")) {
if (isset($elementHandler[$name]["end"])) {
call_user_func($elementHandler[$name]["end"]);
}
}
}
/**
* xml character data handler
*
* this function is called whenever raw character data is reached
* just print it to the screen
* @param resource $parser the resource handler for the xml parser
* @param string $data the name of the xml element parsed
*/
function characterData($parser, $data) {
global $text;
$text .= $data;
}
/**
* @param string[] $attrs
*/
function reportStartHandler($attrs) {
global $report_array;
$access = WT_PRIV_PUBLIC;
if (isset($attrs["access"])) {
if (isset($$attrs["access"])) {
$access = $$attrs["access"];
}
}
$report_array["access"] = $access;
if (isset($attrs["icon"])) {
$report_array["icon"] = $attrs["icon"];
} else {
$report_array["icon"] = "";
}
}
/**
* @param string[] $attrs
*/
function varStartHandler($attrs) {
global $text, $fact, $desc, $type;
$var = $attrs["var"];
if (!empty($var)) {
$tfact = $fact;
if ($fact == "EVEN") {
$tfact = $type;
}
$var = str_replace(array("@fact", "@desc"), array($tfact, $desc), $var);
if (preg_match('/^WT_I18N::number\((.+)\)$/', $var, $match)) {
$var = WT_I18N::number($match[1]);
} elseif (preg_match('/^WT_I18N::translate\(\'(.+)\'\)$/', $var, $match)) {
$var = WT_I18N::translate($match[1]);
} elseif (preg_match('/^WT_I18N::translate_c\(\'(.+)\', *\'(.+)\'\)$/', $var, $match)) {
$var = WT_I18N::translate_c($match[1], $match[2]);
}
$text .= $var;
}
}
function titleStartHandler() {
global $text;
$text = "";
}
function titleEndHandler() {
global $report_array, $text;
$report_array["title"] = $text;
$text = "";
}
function descriptionEndHandler() {
global $report_array, $text;
$report_array["description"] = $text;
$text = "";
}
/**
* @param string[] $attrs
*/
function inputStartHandler($attrs) {
global $input, $text;
$text = "";
$input = array();
$input["name"] = "";
$input["type"] = "";
$input["lookup"] = "";
$input["default"] = "";
$input["value"] = "";
$input["options"] = "";
if (isset($attrs["name"])) {
$input["name"] = $attrs["name"];
}
if (isset($attrs["type"])) {
$input["type"] = $attrs["type"];
}
if (isset($attrs["lookup"])) {
$input["lookup"] = $attrs["lookup"];
}
if (isset($attrs["default"])) {
if ($attrs["default"] == "NOW") {
$input["default"] = date("d M Y");
} else {
$match = array();
if (preg_match("/NOW\s*([+\-])\s*(\d+)/", $attrs['default'], $match) > 0) {
$plus = 1;
if ($match[1] == "-") {
$plus = -1;
}
$input["default"] = date("d M Y", WT_TIMESTAMP + $plus * 60 * 60 * 24 * $match[2]);
} else {
$input["default"] = $attrs["default"];
}
}
}
if (isset($attrs["options"])) {
$input["options"] = $attrs["options"];
}
}
function inputEndHandler() {
global $report_array, $text, $input;
$input["value"] = $text;
if (!isset($report_array["inputs"])) {
$report_array["inputs"] = array();
}
$report_array["inputs"][] = $input;
$text = "";
}
|