1a6f13a4aSGreg Roach<?php 2a6f13a4aSGreg Roach/** 3a6f13a4aSGreg Roach * webtrees: online genealogy 41062a142SGreg Roach * Copyright (C) 2018 webtrees development team 5a6f13a4aSGreg Roach * This program is free software: you can redistribute it and/or modify 6a6f13a4aSGreg Roach * it under the terms of the GNU General Public License as published by 7a6f13a4aSGreg Roach * the Free Software Foundation, either version 3 of the License, or 8a6f13a4aSGreg Roach * (at your option) any later version. 9a6f13a4aSGreg Roach * This program is distributed in the hope that it will be useful, 10a6f13a4aSGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of 11a6f13a4aSGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12a6f13a4aSGreg Roach * GNU General Public License for more details. 13a6f13a4aSGreg Roach * You should have received a copy of the GNU General Public License 14a6f13a4aSGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>. 15a6f13a4aSGreg Roach */ 1676692c8bSGreg Roachnamespace Fisharebest\Webtrees\Report; 1776692c8bSGreg Roach 18a6f13a4aSGreg Roachuse Fisharebest\Webtrees\Auth; 19a6f13a4aSGreg Roachuse Fisharebest\Webtrees\Database; 20a6f13a4aSGreg Roachuse Fisharebest\Webtrees\Date; 21a6f13a4aSGreg Roachuse Fisharebest\Webtrees\Family; 22a4d703aeSGreg Roachuse Fisharebest\Webtrees\Filter; 233d7a8a4cSGreg Roachuse Fisharebest\Webtrees\Functions\Functions; 243d7a8a4cSGreg Roachuse Fisharebest\Webtrees\Functions\FunctionsDate; 25a6f13a4aSGreg Roachuse Fisharebest\Webtrees\GedcomRecord; 26a6f13a4aSGreg Roachuse Fisharebest\Webtrees\GedcomTag; 27a6f13a4aSGreg Roachuse Fisharebest\Webtrees\I18N; 28a6f13a4aSGreg Roachuse Fisharebest\Webtrees\Individual; 29d1286247SGreg Roachuse Fisharebest\Webtrees\Log; 30a6f13a4aSGreg Roachuse Fisharebest\Webtrees\Media; 31729ce104SGreg Roachuse Fisharebest\Webtrees\Note; 32a6f13a4aSGreg Roachuse Fisharebest\Webtrees\Place; 33299d100dSGreg Roachuse Fisharebest\Webtrees\Tree; 34a6f13a4aSGreg Roach 35a6f13a4aSGreg Roach/** 36a6f13a4aSGreg Roach * Class ReportParserGenerate - parse a report.xml file and generate the report. 37a6f13a4aSGreg Roach */ 38c1010edaSGreg Roachclass ReportParserGenerate extends ReportParserBase 39c1010edaSGreg Roach{ 40a6f13a4aSGreg Roach /** @var bool Are we collecting data from <Footnote> elements */ 41a6f13a4aSGreg Roach private $process_footnote = true; 42a6f13a4aSGreg Roach 43a6f13a4aSGreg Roach /** @var bool Are we currently outputing data? */ 44a6f13a4aSGreg Roach private $print_data = false; 45a6f13a4aSGreg Roach 46a6f13a4aSGreg Roach /** @var bool[] Push-down stack of $print_data */ 4713abd6f3SGreg Roach private $print_data_stack = []; 48a6f13a4aSGreg Roach 4976692c8bSGreg Roach /** @var int Are we processing GEDCOM data */ 50a6f13a4aSGreg Roach private $process_gedcoms = 0; 51a6f13a4aSGreg Roach 5276692c8bSGreg Roach /** @var int Are we processing conditionals */ 53a6f13a4aSGreg Roach private $process_ifs = 0; 54a6f13a4aSGreg Roach 5576692c8bSGreg Roach /** @var int Are we processing repeats */ 56a6f13a4aSGreg Roach private $process_repeats = 0; 57a6f13a4aSGreg Roach 58a6f13a4aSGreg Roach /** @var int Quantity of data to repeat during loops */ 59a6f13a4aSGreg Roach private $repeat_bytes = 0; 60a6f13a4aSGreg Roach 61*5b084b24SGreg Roach /** @var string[] Repeated data when iterating over loops */ 6213abd6f3SGreg Roach private $repeats = []; 63a6f13a4aSGreg Roach 64a6f13a4aSGreg Roach /** @var array[] Nested repeating data */ 6513abd6f3SGreg Roach private $repeats_stack = []; 66a6f13a4aSGreg Roach 67e8e7866bSGreg Roach /** @var ReportBase[] Nested repeating data */ 6813abd6f3SGreg Roach private $wt_report_stack = []; 69e8e7866bSGreg Roach 70e8e7866bSGreg Roach /** @var resource Nested repeating data */ 71e8e7866bSGreg Roach private $parser; 72e8e7866bSGreg Roach 73e8e7866bSGreg Roach /** @var resource[] Nested repeating data */ 7413abd6f3SGreg Roach private $parser_stack = []; 75e8e7866bSGreg Roach 76a6f13a4aSGreg Roach /** @var string The current GEDCOM record */ 77a6f13a4aSGreg Roach private $gedrec = ''; 78a6f13a4aSGreg Roach 79a6f13a4aSGreg Roach /** @var string[] Nested GEDCOM records */ 8013abd6f3SGreg Roach private $gedrec_stack = []; 81a6f13a4aSGreg Roach 82a6f13a4aSGreg Roach /** @var ReportBaseElement The currently processed element */ 83a6f13a4aSGreg Roach private $current_element; 84a6f13a4aSGreg Roach 85a6f13a4aSGreg Roach /** @var ReportBaseElement The currently processed element */ 86a6f13a4aSGreg Roach private $footnote_element; 87a6f13a4aSGreg Roach 88a6f13a4aSGreg Roach /** @var string The GEDCOM fact currently being processed */ 89a6f13a4aSGreg Roach private $fact = ''; 90a6f13a4aSGreg Roach 91a6f13a4aSGreg Roach /** @var string The GEDCOM value currently being processed */ 92a6f13a4aSGreg Roach private $desc = ''; 93a6f13a4aSGreg Roach 94a6f13a4aSGreg Roach /** @var string The GEDCOM type currently being processed */ 95a6f13a4aSGreg Roach private $type = ''; 96a6f13a4aSGreg Roach 97a6f13a4aSGreg Roach /** @var int The current generational level */ 98a6f13a4aSGreg Roach private $generation = 1; 99a6f13a4aSGreg Roach 100a6f13a4aSGreg Roach /** @var array Source data for processing lists */ 10113abd6f3SGreg Roach private $list = []; 102a6f13a4aSGreg Roach 103a6f13a4aSGreg Roach /** @var int Number of items in lists */ 104a6f13a4aSGreg Roach private $list_total = 0; 105a6f13a4aSGreg Roach 106a6f13a4aSGreg Roach /** @var int Number of items filtered from lists */ 107a6f13a4aSGreg Roach private $list_private = 0; 108a6f13a4aSGreg Roach 109299d100dSGreg Roach /** @var string The filename of the XML report */ 110299d100dSGreg Roach protected $report; 111299d100dSGreg Roach 112e8e7866bSGreg Roach /** @var ReportBase A factory for creating report elements */ 113e8e7866bSGreg Roach private $report_root; 114e8e7866bSGreg Roach 115*5b084b24SGreg Roach /** @var ReportBaseElement Nested report elements */ 116e8e7866bSGreg Roach private $wt_report; 117e8e7866bSGreg Roach 118d1286247SGreg Roach /** @var string[][] Variables defined in the report at run-time */ 1192118c0e3SGreg Roach private $vars; 120d1286247SGreg Roach 121299d100dSGreg Roach /** @var Tree The current tree */ 122299d100dSGreg Roach private $tree; 123299d100dSGreg Roach 12476692c8bSGreg Roach /** 12576692c8bSGreg Roach * Create a parser for a report 12676692c8bSGreg Roach * 12776692c8bSGreg Roach * @param string $report The XML filename 12876692c8bSGreg Roach * @param ReportBase $report_root 12976692c8bSGreg Roach * @param string[][] $vars 130299d100dSGreg Roach * @param Tree $tree 13176692c8bSGreg Roach */ 132c1010edaSGreg Roach public function __construct($report, ReportBase $report_root, array $vars, Tree $tree) 133c1010edaSGreg Roach { 134299d100dSGreg Roach $this->report = $report; 135e8e7866bSGreg Roach $this->report_root = $report_root; 136e8e7866bSGreg Roach $this->wt_report = $report_root; 137a6f13a4aSGreg Roach $this->current_element = new ReportBaseElement; 138d1286247SGreg Roach $this->vars = $vars; 139299d100dSGreg Roach $this->tree = $tree; 140299d100dSGreg Roach 141299d100dSGreg Roach parent::__construct($report, $report_root, $vars, $tree); 142a6f13a4aSGreg Roach } 143a6f13a4aSGreg Roach 144a6f13a4aSGreg Roach /** 145a6f13a4aSGreg Roach * XML start element handler 146a6f13a4aSGreg Roach * 147a6f13a4aSGreg Roach * This function is called whenever a starting element is reached 148a6f13a4aSGreg Roach * The element handler will be called if found, otherwise it must be HTML 149a6f13a4aSGreg Roach * 150a6f13a4aSGreg Roach * @param resource $parser the resource handler for the XML parser 151a6f13a4aSGreg Roach * @param string $name the name of the XML element parsed 152a6f13a4aSGreg Roach * @param array $attrs an array of key value pairs for the attributes 153a6f13a4aSGreg Roach */ 154c1010edaSGreg Roach protected function startElement($parser, $name, $attrs) 155c1010edaSGreg Roach { 15613abd6f3SGreg Roach $newattrs = []; 157a6f13a4aSGreg Roach 158a6f13a4aSGreg Roach foreach ($attrs as $key => $value) { 159a6f13a4aSGreg Roach if (preg_match("/^\\$(\w+)$/", $value, $match)) { 160d1286247SGreg Roach if ((isset($this->vars[$match[1]]['id'])) && (!isset($this->vars[$match[1]]['gedcom']))) { 161d1286247SGreg Roach $value = $this->vars[$match[1]]['id']; 162a6f13a4aSGreg Roach } 163a6f13a4aSGreg Roach } 164a6f13a4aSGreg Roach $newattrs[$key] = $value; 165a6f13a4aSGreg Roach } 166a6f13a4aSGreg Roach $attrs = $newattrs; 1677a6ee1acSGreg Roach if ($this->process_footnote && ($this->process_ifs === 0 || $name === 'if') && ($this->process_gedcoms === 0 || $name === 'Gedcom') && ($this->process_repeats === 0 || $name === 'Facts' || $name === 'RepeatTag')) { 168a6f13a4aSGreg Roach $start_method = $name . 'StartHandler'; 169a6f13a4aSGreg Roach $end_method = $name . 'EndHandler'; 170a6f13a4aSGreg Roach if (method_exists($this, $start_method)) { 171a6f13a4aSGreg Roach $this->$start_method($attrs); 172a6f13a4aSGreg Roach } elseif (!method_exists($this, $end_method)) { 173a6f13a4aSGreg Roach $this->htmlStartHandler($name, $attrs); 174a6f13a4aSGreg Roach } 175a6f13a4aSGreg Roach } 176a6f13a4aSGreg Roach } 177a6f13a4aSGreg Roach 178a6f13a4aSGreg Roach /** 179a6f13a4aSGreg Roach * XML end element handler 180a6f13a4aSGreg Roach * 181a6f13a4aSGreg Roach * This function is called whenever an ending element is reached 182a6f13a4aSGreg Roach * The element handler will be called if found, otherwise it must be HTML 183a6f13a4aSGreg Roach * 184a6f13a4aSGreg Roach * @param resource $parser the resource handler for the XML parser 185a6f13a4aSGreg Roach * @param string $name the name of the XML element parsed 186a6f13a4aSGreg Roach */ 187c1010edaSGreg Roach protected function endElement($parser, $name) 188c1010edaSGreg Roach { 1897a6ee1acSGreg Roach if (($this->process_footnote || $name === 'Footnote') && ($this->process_ifs === 0 || $name === 'if') && ($this->process_gedcoms === 0 || $name === 'Gedcom') && ($this->process_repeats === 0 || $name === 'Facts' || $name === 'RepeatTag' || $name === 'List' || $name === 'Relatives')) { 190a6f13a4aSGreg Roach $start_method = $name . 'StartHandler'; 191a6f13a4aSGreg Roach $end_method = $name . 'EndHandler'; 192a6f13a4aSGreg Roach if (method_exists($this, $end_method)) { 193a6f13a4aSGreg Roach $this->$end_method(); 194a6f13a4aSGreg Roach } elseif (!method_exists($this, $start_method)) { 195a6f13a4aSGreg Roach $this->htmlEndHandler($name); 196a6f13a4aSGreg Roach } 197a6f13a4aSGreg Roach } 198a6f13a4aSGreg Roach } 199a6f13a4aSGreg Roach 200a6f13a4aSGreg Roach /** 201a6f13a4aSGreg Roach * XML character data handler 202a6f13a4aSGreg Roach * 203a6f13a4aSGreg Roach * @param resource $parser the resource handler for the XML parser 204a6f13a4aSGreg Roach * @param string $data the name of the XML element parsed 205a6f13a4aSGreg Roach */ 206c1010edaSGreg Roach protected function characterData($parser, $data) 207c1010edaSGreg Roach { 208e8e7866bSGreg Roach if ($this->print_data && $this->process_gedcoms === 0 && $this->process_ifs === 0 && $this->process_repeats === 0) { 209a6f13a4aSGreg Roach $this->current_element->addText($data); 210a6f13a4aSGreg Roach } 211a6f13a4aSGreg Roach } 212a6f13a4aSGreg Roach 213a6f13a4aSGreg Roach /** 21476692c8bSGreg Roach * XML <style> 215a6f13a4aSGreg Roach * 216a6f13a4aSGreg Roach * @param array $attrs an array of key value pairs for the attributes 217a6f13a4aSGreg Roach */ 218c1010edaSGreg Roach private function styleStartHandler($attrs) 219c1010edaSGreg Roach { 220a6f13a4aSGreg Roach if (empty($attrs['name'])) { 221a6f13a4aSGreg Roach throw new \DomainException('REPORT ERROR Style: The "name" of the style is missing or not set in the XML file.'); 222a6f13a4aSGreg Roach } 223a6f13a4aSGreg Roach 224a6f13a4aSGreg Roach // array Style that will be passed on 22513abd6f3SGreg Roach $s = []; 226a6f13a4aSGreg Roach 227a6f13a4aSGreg Roach // string Name af the style 228a6f13a4aSGreg Roach $s['name'] = $attrs['name']; 229a6f13a4aSGreg Roach 230a6f13a4aSGreg Roach // string Name of the DEFAULT font 231e8e7866bSGreg Roach $s['font'] = $this->wt_report->defaultFont; 232a6f13a4aSGreg Roach if (!empty($attrs['font'])) { 233a6f13a4aSGreg Roach $s['font'] = $attrs['font']; 234a6f13a4aSGreg Roach } 235a6f13a4aSGreg Roach 236a6f13a4aSGreg Roach // int The size of the font in points 237e8e7866bSGreg Roach $s['size'] = $this->wt_report->defaultFontSize; 238a6f13a4aSGreg Roach if (!empty($attrs['size'])) { 239a6f13a4aSGreg Roach $s['size'] = (int)$attrs['size']; 240a6f13a4aSGreg Roach } // Get it as int to ignore all decimal points or text (if any text then int(0)) 241a6f13a4aSGreg Roach 242a6f13a4aSGreg Roach // string B: bold, I: italic, U: underline, D: line trough, The default value is regular. 2437a6ee1acSGreg Roach $s['style'] = ''; 244a6f13a4aSGreg Roach if (!empty($attrs['style'])) { 245a6f13a4aSGreg Roach $s['style'] = $attrs['style']; 246a6f13a4aSGreg Roach } 247a6f13a4aSGreg Roach 248e8e7866bSGreg Roach $this->wt_report->addStyle($s); 249a6f13a4aSGreg Roach } 250a6f13a4aSGreg Roach 251a6f13a4aSGreg Roach /** 25276692c8bSGreg Roach * XML <Doc> 253a6f13a4aSGreg Roach * 254a6f13a4aSGreg Roach * Sets up the basics of the document proparties 255a6f13a4aSGreg Roach * 256a6f13a4aSGreg Roach * @param array $attrs an array of key value pairs for the attributes 257a6f13a4aSGreg Roach */ 258c1010edaSGreg Roach private function docStartHandler($attrs) 259c1010edaSGreg Roach { 260e8e7866bSGreg Roach $this->parser = $this->xml_parser; 261a6f13a4aSGreg Roach 262a6f13a4aSGreg Roach // Custom page width 263a6f13a4aSGreg Roach if (!empty($attrs['customwidth'])) { 264e8e7866bSGreg Roach $this->wt_report->pagew = (int)$attrs['customwidth']; 265a6f13a4aSGreg Roach } // Get it as int to ignore all decimal points or text (if any text then int(0)) 266a6f13a4aSGreg Roach // Custom Page height 267a6f13a4aSGreg Roach if (!empty($attrs['customheight'])) { 268e8e7866bSGreg Roach $this->wt_report->pageh = (int)$attrs['customheight']; 269a6f13a4aSGreg Roach } // Get it as int to ignore all decimal points or text (if any text then int(0)) 270a6f13a4aSGreg Roach 271a6f13a4aSGreg Roach // Left Margin 272a6f13a4aSGreg Roach if (isset($attrs['leftmargin'])) { 2737a6ee1acSGreg Roach if ($attrs['leftmargin'] === '0') { 274e8e7866bSGreg Roach $this->wt_report->leftmargin = 0; 275a6f13a4aSGreg Roach } elseif (!empty($attrs['leftmargin'])) { 276e8e7866bSGreg Roach $this->wt_report->leftmargin = (int)$attrs['leftmargin']; // Get it as int to ignore all decimal points or text (if any text then int(0)) 277a6f13a4aSGreg Roach } 278a6f13a4aSGreg Roach } 279a6f13a4aSGreg Roach // Right Margin 280a6f13a4aSGreg Roach if (isset($attrs['rightmargin'])) { 2817a6ee1acSGreg Roach if ($attrs['rightmargin'] === '0') { 282e8e7866bSGreg Roach $this->wt_report->rightmargin = 0; 283a6f13a4aSGreg Roach } elseif (!empty($attrs['rightmargin'])) { 284e8e7866bSGreg Roach $this->wt_report->rightmargin = (int)$attrs['rightmargin']; // Get it as int to ignore all decimal points or text (if any text then int(0)) 285a6f13a4aSGreg Roach } 286a6f13a4aSGreg Roach } 287a6f13a4aSGreg Roach // Top Margin 288a6f13a4aSGreg Roach if (isset($attrs['topmargin'])) { 2897a6ee1acSGreg Roach if ($attrs['topmargin'] === '0') { 290e8e7866bSGreg Roach $this->wt_report->topmargin = 0; 291a6f13a4aSGreg Roach } elseif (!empty($attrs['topmargin'])) { 292e8e7866bSGreg Roach $this->wt_report->topmargin = (int)$attrs['topmargin']; // Get it as int to ignore all decimal points or text (if any text then int(0)) 293a6f13a4aSGreg Roach } 294a6f13a4aSGreg Roach } 295a6f13a4aSGreg Roach // Bottom Margin 296a6f13a4aSGreg Roach if (isset($attrs['bottommargin'])) { 2977a6ee1acSGreg Roach if ($attrs['bottommargin'] === '0') { 298e8e7866bSGreg Roach $this->wt_report->bottommargin = 0; 299a6f13a4aSGreg Roach } elseif (!empty($attrs['bottommargin'])) { 300e8e7866bSGreg Roach $this->wt_report->bottommargin = (int)$attrs['bottommargin']; // Get it as int to ignore all decimal points or text (if any text then int(0)) 301a6f13a4aSGreg Roach } 302a6f13a4aSGreg Roach } 303a6f13a4aSGreg Roach // Header Margin 304a6f13a4aSGreg Roach if (isset($attrs['headermargin'])) { 3057a6ee1acSGreg Roach if ($attrs['headermargin'] === '0') { 306e8e7866bSGreg Roach $this->wt_report->headermargin = 0; 307a6f13a4aSGreg Roach } elseif (!empty($attrs['headermargin'])) { 308e8e7866bSGreg Roach $this->wt_report->headermargin = (int)$attrs['headermargin']; // Get it as int to ignore all decimal points or text (if any text then int(0)) 309a6f13a4aSGreg Roach } 310a6f13a4aSGreg Roach } 311a6f13a4aSGreg Roach // Footer Margin 312a6f13a4aSGreg Roach if (isset($attrs['footermargin'])) { 3137a6ee1acSGreg Roach if ($attrs['footermargin'] === '0') { 314e8e7866bSGreg Roach $this->wt_report->footermargin = 0; 315a6f13a4aSGreg Roach } elseif (!empty($attrs['footermargin'])) { 316e8e7866bSGreg Roach $this->wt_report->footermargin = (int)$attrs['footermargin']; // Get it as int to ignore all decimal points or text (if any text then int(0)) 317a6f13a4aSGreg Roach } 318a6f13a4aSGreg Roach } 319a6f13a4aSGreg Roach 320a6f13a4aSGreg Roach // Page Orientation 321a6f13a4aSGreg Roach if (!empty($attrs['orientation'])) { 3227a6ee1acSGreg Roach if ($attrs['orientation'] == 'landscape') { 3237a6ee1acSGreg Roach $this->wt_report->orientation = 'landscape'; 3247a6ee1acSGreg Roach } elseif ($attrs['orientation'] == 'portrait') { 3257a6ee1acSGreg Roach $this->wt_report->orientation = 'portrait'; 326a6f13a4aSGreg Roach } 327a6f13a4aSGreg Roach } 328a6f13a4aSGreg Roach // Page Size 329a6f13a4aSGreg Roach if (!empty($attrs['pageSize'])) { 330e8e7866bSGreg Roach $this->wt_report->pageFormat = strtoupper($attrs['pageSize']); 331a6f13a4aSGreg Roach } 332a6f13a4aSGreg Roach 333a6f13a4aSGreg Roach // Show Generated By... 334a6f13a4aSGreg Roach if (isset($attrs['showGeneratedBy'])) { 3357a6ee1acSGreg Roach if ($attrs['showGeneratedBy'] === '0') { 336e8e7866bSGreg Roach $this->wt_report->showGenText = false; 3377a6ee1acSGreg Roach } elseif ($attrs['showGeneratedBy'] === '1') { 338e8e7866bSGreg Roach $this->wt_report->showGenText = true; 339a6f13a4aSGreg Roach } 340a6f13a4aSGreg Roach } 341a6f13a4aSGreg Roach 342e8e7866bSGreg Roach $this->wt_report->setup(); 343a6f13a4aSGreg Roach } 344a6f13a4aSGreg Roach 345a6f13a4aSGreg Roach /** 34676692c8bSGreg Roach * XML </Doc> 347a6f13a4aSGreg Roach */ 348c1010edaSGreg Roach private function docEndHandler() 349c1010edaSGreg Roach { 350e8e7866bSGreg Roach $this->wt_report->run(); 351a6f13a4aSGreg Roach } 352a6f13a4aSGreg Roach 353a6f13a4aSGreg Roach /** 35476692c8bSGreg Roach * XML <Header> 355a6f13a4aSGreg Roach */ 356c1010edaSGreg Roach private function headerStartHandler() 357c1010edaSGreg Roach { 358a6f13a4aSGreg Roach // Clear the Header before any new elements are added 359e8e7866bSGreg Roach $this->wt_report->clearHeader(); 3607a6ee1acSGreg Roach $this->wt_report->setProcessing('H'); 361a6f13a4aSGreg Roach } 362a6f13a4aSGreg Roach 363a6f13a4aSGreg Roach /** 36476692c8bSGreg Roach * XML <PageHeader> 365a6f13a4aSGreg Roach */ 366c1010edaSGreg Roach private function pageHeaderStartHandler() 367c1010edaSGreg Roach { 368a6f13a4aSGreg Roach array_push($this->print_data_stack, $this->print_data); 369a6f13a4aSGreg Roach $this->print_data = false; 370e8e7866bSGreg Roach array_push($this->wt_report_stack, $this->wt_report); 371e8e7866bSGreg Roach $this->wt_report = $this->report_root->createPageHeader(); 372a6f13a4aSGreg Roach } 373a6f13a4aSGreg Roach 374a6f13a4aSGreg Roach /** 37576692c8bSGreg Roach * XML <pageHeaderEndHandler> 376a6f13a4aSGreg Roach */ 377c1010edaSGreg Roach private function pageHeaderEndHandler() 378c1010edaSGreg Roach { 379a6f13a4aSGreg Roach $this->print_data = array_pop($this->print_data_stack); 380e8e7866bSGreg Roach $this->current_element = $this->wt_report; 381e8e7866bSGreg Roach $this->wt_report = array_pop($this->wt_report_stack); 382e8e7866bSGreg Roach $this->wt_report->addElement($this->current_element); 383a6f13a4aSGreg Roach } 384a6f13a4aSGreg Roach 385a6f13a4aSGreg Roach /** 38676692c8bSGreg Roach * XML <bodyStartHandler> 387a6f13a4aSGreg Roach */ 388c1010edaSGreg Roach private function bodyStartHandler() 389c1010edaSGreg Roach { 3907a6ee1acSGreg Roach $this->wt_report->setProcessing('B'); 391a6f13a4aSGreg Roach } 392a6f13a4aSGreg Roach 393a6f13a4aSGreg Roach /** 39476692c8bSGreg Roach * XML <footerStartHandler> 395a6f13a4aSGreg Roach */ 396c1010edaSGreg Roach private function footerStartHandler() 397c1010edaSGreg Roach { 3987a6ee1acSGreg Roach $this->wt_report->setProcessing('F'); 399a6f13a4aSGreg Roach } 400a6f13a4aSGreg Roach 401a6f13a4aSGreg Roach /** 40276692c8bSGreg Roach * XML <Cell> 403a6f13a4aSGreg Roach * 404a6f13a4aSGreg Roach * @param array $attrs an array of key value pairs for the attributes 405a6f13a4aSGreg Roach */ 406c1010edaSGreg Roach private function cellStartHandler($attrs) 407c1010edaSGreg Roach { 408a6f13a4aSGreg Roach // string The text alignment of the text in this box. 4097a6ee1acSGreg Roach $align = ''; 410a6f13a4aSGreg Roach if (!empty($attrs['align'])) { 411a6f13a4aSGreg Roach $align = $attrs['align']; 412a6f13a4aSGreg Roach // RTL supported left/right alignment 4137a6ee1acSGreg Roach if ($align == 'rightrtl') { 414e8e7866bSGreg Roach if ($this->wt_report->rtl) { 4157a6ee1acSGreg Roach $align = 'left'; 416a6f13a4aSGreg Roach } else { 4177a6ee1acSGreg Roach $align = 'right'; 418a6f13a4aSGreg Roach } 4197a6ee1acSGreg Roach } elseif ($align == 'leftrtl') { 420e8e7866bSGreg Roach if ($this->wt_report->rtl) { 4217a6ee1acSGreg Roach $align = 'right'; 422a6f13a4aSGreg Roach } else { 4237a6ee1acSGreg Roach $align = 'left'; 424a6f13a4aSGreg Roach } 425a6f13a4aSGreg Roach } 426a6f13a4aSGreg Roach } 427a6f13a4aSGreg Roach 428a6f13a4aSGreg Roach // string The color to fill the background of this cell 4297a6ee1acSGreg Roach $bgcolor = ''; 430a6f13a4aSGreg Roach if (!empty($attrs['bgcolor'])) { 431a6f13a4aSGreg Roach $bgcolor = $attrs['bgcolor']; 432a6f13a4aSGreg Roach } 433a6f13a4aSGreg Roach 434a6f13a4aSGreg Roach // int Whether or not the background should be painted 435a6f13a4aSGreg Roach $fill = 1; 436a6f13a4aSGreg Roach if (isset($attrs['fill'])) { 4377a6ee1acSGreg Roach if ($attrs['fill'] === '0') { 438a6f13a4aSGreg Roach $fill = 0; 4397a6ee1acSGreg Roach } elseif ($attrs['fill'] === '1') { 440a6f13a4aSGreg Roach $fill = 1; 441a6f13a4aSGreg Roach } 442a6f13a4aSGreg Roach } 443a6f13a4aSGreg Roach 444a6f13a4aSGreg Roach $reseth = true; 445a6f13a4aSGreg Roach // boolean if true reset the last cell height (default true) 446a6f13a4aSGreg Roach if (isset($attrs['reseth'])) { 4477a6ee1acSGreg Roach if ($attrs['reseth'] === '0') { 448a6f13a4aSGreg Roach $reseth = false; 4497a6ee1acSGreg Roach } elseif ($attrs['reseth'] === '1') { 450a6f13a4aSGreg Roach $reseth = true; 451a6f13a4aSGreg Roach } 452a6f13a4aSGreg Roach } 453a6f13a4aSGreg Roach 454a6f13a4aSGreg Roach // mixed Whether or not a border should be printed around this box 455a6f13a4aSGreg Roach $border = 0; 456a6f13a4aSGreg Roach if (!empty($attrs['border'])) { 457a6f13a4aSGreg Roach $border = $attrs['border']; 458a6f13a4aSGreg Roach } 459a6f13a4aSGreg Roach // string Border color in HTML code 4607a6ee1acSGreg Roach $bocolor = ''; 461a6f13a4aSGreg Roach if (!empty($attrs['bocolor'])) { 462a6f13a4aSGreg Roach $bocolor = $attrs['bocolor']; 463a6f13a4aSGreg Roach } 464a6f13a4aSGreg Roach 465a6f13a4aSGreg Roach // int Cell height (expressed in points) The starting height of this cell. If the text wraps the height will automatically be adjusted. 466a6f13a4aSGreg Roach $height = 0; 467a6f13a4aSGreg Roach if (!empty($attrs['height'])) { 468a6f13a4aSGreg Roach $height = (int)$attrs['height']; 469a6f13a4aSGreg Roach } 470a6f13a4aSGreg Roach // int Cell width (expressed in points) Setting the width to 0 will make it the width from the current location to the right margin. 471a6f13a4aSGreg Roach $width = 0; 472a6f13a4aSGreg Roach if (!empty($attrs['width'])) { 473a6f13a4aSGreg Roach $width = (int)$attrs['width']; 474a6f13a4aSGreg Roach } 475a6f13a4aSGreg Roach 476a6f13a4aSGreg Roach // int Stretch carachter mode 477a6f13a4aSGreg Roach $stretch = 0; 478a6f13a4aSGreg Roach if (!empty($attrs['stretch'])) { 479a6f13a4aSGreg Roach $stretch = (int)$attrs['stretch']; 480a6f13a4aSGreg Roach } 481a6f13a4aSGreg Roach 482a6f13a4aSGreg Roach // mixed Position the left corner of this box on the page. The default is the current position. 4837a6ee1acSGreg Roach $left = '.'; 484a6f13a4aSGreg Roach if (isset($attrs['left'])) { 4857a6ee1acSGreg Roach if ($attrs['left'] === '.') { 4867a6ee1acSGreg Roach $left = '.'; 487a6f13a4aSGreg Roach } elseif (!empty($attrs['left'])) { 488a6f13a4aSGreg Roach $left = (int)$attrs['left']; 4897a6ee1acSGreg Roach } elseif ($attrs['left'] === '0') { 490a6f13a4aSGreg Roach $left = 0; 491a6f13a4aSGreg Roach } 492a6f13a4aSGreg Roach } 493a6f13a4aSGreg Roach // mixed Position the top corner of this box on the page. the default is the current position 4947a6ee1acSGreg Roach $top = '.'; 495a6f13a4aSGreg Roach if (isset($attrs['top'])) { 4967a6ee1acSGreg Roach if ($attrs['top'] === '.') { 4977a6ee1acSGreg Roach $top = '.'; 498a6f13a4aSGreg Roach } elseif (!empty($attrs['top'])) { 499a6f13a4aSGreg Roach $top = (int)$attrs['top']; 5007a6ee1acSGreg Roach } elseif ($attrs['top'] === '0') { 501a6f13a4aSGreg Roach $top = 0; 502a6f13a4aSGreg Roach } 503a6f13a4aSGreg Roach } 504a6f13a4aSGreg Roach 505a6f13a4aSGreg Roach // string The name of the Style that should be used to render the text. 5067a6ee1acSGreg Roach $style = ''; 507a6f13a4aSGreg Roach if (!empty($attrs['style'])) { 508a6f13a4aSGreg Roach $style = $attrs['style']; 509a6f13a4aSGreg Roach } 510a6f13a4aSGreg Roach 511a6f13a4aSGreg Roach // string Text color in html code 5127a6ee1acSGreg Roach $tcolor = ''; 513a6f13a4aSGreg Roach if (!empty($attrs['tcolor'])) { 514a6f13a4aSGreg Roach $tcolor = $attrs['tcolor']; 515a6f13a4aSGreg Roach } 516a6f13a4aSGreg Roach 517a6f13a4aSGreg Roach // int Indicates where the current position should go after the call. 518a6f13a4aSGreg Roach $ln = 0; 519a6f13a4aSGreg Roach if (isset($attrs['newline'])) { 520a6f13a4aSGreg Roach if (!empty($attrs['newline'])) { 521a6f13a4aSGreg Roach $ln = (int)$attrs['newline']; 5227a6ee1acSGreg Roach } elseif ($attrs['newline'] === '0') { 523a6f13a4aSGreg Roach $ln = 0; 524a6f13a4aSGreg Roach } 525a6f13a4aSGreg Roach } 526a6f13a4aSGreg Roach 5277a6ee1acSGreg Roach if ($align == 'left') { 5287a6ee1acSGreg Roach $align = 'L'; 5297a6ee1acSGreg Roach } elseif ($align == 'right') { 5307a6ee1acSGreg Roach $align = 'R'; 5317a6ee1acSGreg Roach } elseif ($align == 'center') { 5327a6ee1acSGreg Roach $align = 'C'; 5337a6ee1acSGreg Roach } elseif ($align == 'justify') { 5347a6ee1acSGreg Roach $align = 'J'; 535a6f13a4aSGreg Roach } 536a6f13a4aSGreg Roach 537a6f13a4aSGreg Roach array_push($this->print_data_stack, $this->print_data); 538a6f13a4aSGreg Roach $this->print_data = true; 539a6f13a4aSGreg Roach 540e8e7866bSGreg Roach $this->current_element = $this->report_root->createCell( 541a6f13a4aSGreg Roach $width, 542a6f13a4aSGreg Roach $height, 543a6f13a4aSGreg Roach $border, 544a6f13a4aSGreg Roach $align, 545a6f13a4aSGreg Roach $bgcolor, 546a6f13a4aSGreg Roach $style, 547a6f13a4aSGreg Roach $ln, 548a6f13a4aSGreg Roach $top, 549a6f13a4aSGreg Roach $left, 550a6f13a4aSGreg Roach $fill, 551a6f13a4aSGreg Roach $stretch, 552a6f13a4aSGreg Roach $bocolor, 553a6f13a4aSGreg Roach $tcolor, 554a6f13a4aSGreg Roach $reseth 555a6f13a4aSGreg Roach ); 556a6f13a4aSGreg Roach } 557a6f13a4aSGreg Roach 558a6f13a4aSGreg Roach /** 55976692c8bSGreg Roach * XML </Cell> 560a6f13a4aSGreg Roach */ 561c1010edaSGreg Roach private function cellEndHandler() 562c1010edaSGreg Roach { 563a6f13a4aSGreg Roach $this->print_data = array_pop($this->print_data_stack); 564e8e7866bSGreg Roach $this->wt_report->addElement($this->current_element); 565a6f13a4aSGreg Roach } 566a6f13a4aSGreg Roach 567a6f13a4aSGreg Roach /** 568a6f13a4aSGreg Roach * XML <Now /> element handler 569a6f13a4aSGreg Roach */ 570c1010edaSGreg Roach private function nowStartHandler() 571c1010edaSGreg Roach { 5723d7a8a4cSGreg Roach $g = FunctionsDate::timestampToGedcomDate(WT_TIMESTAMP + WT_TIMESTAMP_OFFSET); 573a6f13a4aSGreg Roach $this->current_element->addText($g->display()); 574a6f13a4aSGreg Roach } 575a6f13a4aSGreg Roach 576a6f13a4aSGreg Roach /** 577a6f13a4aSGreg Roach * XML <PageNum /> element handler 578a6f13a4aSGreg Roach */ 579c1010edaSGreg Roach private function pageNumStartHandler() 580c1010edaSGreg Roach { 5817a6ee1acSGreg Roach $this->current_element->addText('#PAGENUM#'); 582a6f13a4aSGreg Roach } 583a6f13a4aSGreg Roach 584a6f13a4aSGreg Roach /** 585a6f13a4aSGreg Roach * XML <TotalPages /> element handler 586a6f13a4aSGreg Roach */ 587c1010edaSGreg Roach private function totalPagesStartHandler() 588c1010edaSGreg Roach { 5897a6ee1acSGreg Roach $this->current_element->addText('{{:ptp:}}'); 590a6f13a4aSGreg Roach } 591a6f13a4aSGreg Roach 592a6f13a4aSGreg Roach /** 593a6f13a4aSGreg Roach * Called at the start of an element. 594a6f13a4aSGreg Roach * 595a6f13a4aSGreg Roach * @param array $attrs an array of key value pairs for the attributes 596a6f13a4aSGreg Roach */ 597c1010edaSGreg Roach private function gedcomStartHandler($attrs) 598c1010edaSGreg Roach { 599a6f13a4aSGreg Roach if ($this->process_gedcoms > 0) { 600a6f13a4aSGreg Roach $this->process_gedcoms++; 601a6f13a4aSGreg Roach 602a6f13a4aSGreg Roach return; 603a6f13a4aSGreg Roach } 604a6f13a4aSGreg Roach 605a6f13a4aSGreg Roach $tag = $attrs['id']; 6067a6ee1acSGreg Roach $tag = str_replace('@fact', $this->fact, $tag); 6077a6ee1acSGreg Roach $tags = explode(':', $tag); 608a6f13a4aSGreg Roach $newgedrec = ''; 609a6f13a4aSGreg Roach if (count($tags) < 2) { 610299d100dSGreg Roach $tmp = GedcomRecord::getInstance($attrs['id'], $this->tree); 611299d100dSGreg Roach $newgedrec = $tmp ? $tmp->privatizeGedcom(Auth::accessLevel($this->tree)) : ''; 612a6f13a4aSGreg Roach } 613a6f13a4aSGreg Roach if (empty($newgedrec)) { 614a6f13a4aSGreg Roach $tgedrec = $this->gedrec; 615a6f13a4aSGreg Roach $newgedrec = ''; 616a6f13a4aSGreg Roach foreach ($tags as $tag) { 6177a6ee1acSGreg Roach if (preg_match('/\$(.+)/', $tag, $match)) { 618d1286247SGreg Roach if (isset($this->vars[$match[1]]['gedcom'])) { 619d1286247SGreg Roach $newgedrec = $this->vars[$match[1]]['gedcom']; 620a6f13a4aSGreg Roach } else { 621299d100dSGreg Roach $tmp = GedcomRecord::getInstance($match[1], $this->tree); 622299d100dSGreg Roach $newgedrec = $tmp ? $tmp->privatizeGedcom(Auth::accessLevel($this->tree)) : ''; 623a6f13a4aSGreg Roach } 624a6f13a4aSGreg Roach } else { 6257a6ee1acSGreg Roach if (preg_match('/@(.+)/', $tag, $match)) { 62613abd6f3SGreg Roach $gmatch = []; 627a6f13a4aSGreg Roach if (preg_match("/\d $match[1] @([^@]+)@/", $tgedrec, $gmatch)) { 628299d100dSGreg Roach $tmp = GedcomRecord::getInstance($gmatch[1], $this->tree); 629299d100dSGreg Roach $newgedrec = $tmp ? $tmp->privatizeGedcom(Auth::accessLevel($this->tree)) : ''; 630a6f13a4aSGreg Roach $tgedrec = $newgedrec; 631a6f13a4aSGreg Roach } else { 632a6f13a4aSGreg Roach $newgedrec = ''; 633a6f13a4aSGreg Roach break; 634a6f13a4aSGreg Roach } 635a6f13a4aSGreg Roach } else { 6367a6ee1acSGreg Roach $temp = explode(' ', trim($tgedrec)); 637a6f13a4aSGreg Roach $level = $temp[0] + 1; 6383d7a8a4cSGreg Roach $newgedrec = Functions::getSubRecord($level, "$level $tag", $tgedrec); 639a6f13a4aSGreg Roach $tgedrec = $newgedrec; 640a6f13a4aSGreg Roach } 641a6f13a4aSGreg Roach } 642a6f13a4aSGreg Roach } 643a6f13a4aSGreg Roach } 644a6f13a4aSGreg Roach if (!empty($newgedrec)) { 645c1010edaSGreg Roach array_push($this->gedrec_stack, [ 646c1010edaSGreg Roach $this->gedrec, 647c1010edaSGreg Roach $this->fact, 648c1010edaSGreg Roach $this->desc, 649c1010edaSGreg Roach ]); 650a6f13a4aSGreg Roach $this->gedrec = $newgedrec; 651a6f13a4aSGreg Roach if (preg_match("/(\d+) (_?[A-Z0-9]+) (.*)/", $this->gedrec, $match)) { 652a6f13a4aSGreg Roach $this->fact = $match[2]; 653a6f13a4aSGreg Roach $this->desc = trim($match[3]); 654a6f13a4aSGreg Roach } 655a6f13a4aSGreg Roach } else { 656a6f13a4aSGreg Roach $this->process_gedcoms++; 657a6f13a4aSGreg Roach } 658a6f13a4aSGreg Roach } 659a6f13a4aSGreg Roach 660a6f13a4aSGreg Roach /** 661a6f13a4aSGreg Roach * Called at the end of an element. 662a6f13a4aSGreg Roach */ 663c1010edaSGreg Roach private function gedcomEndHandler() 664c1010edaSGreg Roach { 665a6f13a4aSGreg Roach if ($this->process_gedcoms > 0) { 666a6f13a4aSGreg Roach $this->process_gedcoms--; 667a6f13a4aSGreg Roach } else { 668a6f13a4aSGreg Roach list($this->gedrec, $this->fact, $this->desc) = array_pop($this->gedrec_stack); 669a6f13a4aSGreg Roach } 670a6f13a4aSGreg Roach } 671a6f13a4aSGreg Roach 672a6f13a4aSGreg Roach /** 67376692c8bSGreg Roach * XML <textBoxStartHandler> 674a6f13a4aSGreg Roach * 675a6f13a4aSGreg Roach * @param array $attrs an array of key value pairs for the attributes 676a6f13a4aSGreg Roach */ 677c1010edaSGreg Roach private function textBoxStartHandler($attrs) 678c1010edaSGreg Roach { 679a6f13a4aSGreg Roach // string Background color code 6807a6ee1acSGreg Roach $bgcolor = ''; 681a6f13a4aSGreg Roach if (!empty($attrs['bgcolor'])) { 682a6f13a4aSGreg Roach $bgcolor = $attrs['bgcolor']; 683a6f13a4aSGreg Roach } 684a6f13a4aSGreg Roach 685a6f13a4aSGreg Roach // boolean Wether or not fill the background color 686a6f13a4aSGreg Roach $fill = true; 687a6f13a4aSGreg Roach if (isset($attrs['fill'])) { 6887a6ee1acSGreg Roach if ($attrs['fill'] === '0') { 689a6f13a4aSGreg Roach $fill = false; 6907a6ee1acSGreg Roach } elseif ($attrs['fill'] === '1') { 691a6f13a4aSGreg Roach $fill = true; 692a6f13a4aSGreg Roach } 693a6f13a4aSGreg Roach } 694a6f13a4aSGreg Roach 695a6f13a4aSGreg Roach // var boolean Whether or not a border should be printed around this box. 0 = no border, 1 = border. Default is 0 696a6f13a4aSGreg Roach $border = false; 697a6f13a4aSGreg Roach if (isset($attrs['border'])) { 6987a6ee1acSGreg Roach if ($attrs['border'] === '1') { 699a6f13a4aSGreg Roach $border = true; 7007a6ee1acSGreg Roach } elseif ($attrs['border'] === '0') { 701a6f13a4aSGreg Roach $border = false; 702a6f13a4aSGreg Roach } 703a6f13a4aSGreg Roach } 704a6f13a4aSGreg Roach 705a6f13a4aSGreg Roach // int The starting height of this cell. If the text wraps the height will automatically be adjusted 706a6f13a4aSGreg Roach $height = 0; 707a6f13a4aSGreg Roach if (!empty($attrs['height'])) { 708a6f13a4aSGreg Roach $height = (int)$attrs['height']; 709a6f13a4aSGreg Roach } 710a6f13a4aSGreg Roach // int Setting the width to 0 will make it the width from the current location to the margin 711a6f13a4aSGreg Roach $width = 0; 712a6f13a4aSGreg Roach if (!empty($attrs['width'])) { 713a6f13a4aSGreg Roach $width = (int)$attrs['width']; 714a6f13a4aSGreg Roach } 715a6f13a4aSGreg Roach 716a6f13a4aSGreg Roach // mixed Position the left corner of this box on the page. The default is the current position. 7177a6ee1acSGreg Roach $left = '.'; 718a6f13a4aSGreg Roach if (isset($attrs['left'])) { 7197a6ee1acSGreg Roach if ($attrs['left'] === '.') { 7207a6ee1acSGreg Roach $left = '.'; 721a6f13a4aSGreg Roach } elseif (!empty($attrs['left'])) { 722a6f13a4aSGreg Roach $left = (int)$attrs['left']; 7237a6ee1acSGreg Roach } elseif ($attrs['left'] === '0') { 724a6f13a4aSGreg Roach $left = 0; 725a6f13a4aSGreg Roach } 726a6f13a4aSGreg Roach } 727a6f13a4aSGreg Roach // mixed Position the top corner of this box on the page. the default is the current position 7287a6ee1acSGreg Roach $top = '.'; 729a6f13a4aSGreg Roach if (isset($attrs['top'])) { 7307a6ee1acSGreg Roach if ($attrs['top'] === '.') { 7317a6ee1acSGreg Roach $top = '.'; 732a6f13a4aSGreg Roach } elseif (!empty($attrs['top'])) { 733a6f13a4aSGreg Roach $top = (int)$attrs['top']; 7347a6ee1acSGreg Roach } elseif ($attrs['top'] === '0') { 735a6f13a4aSGreg Roach $top = 0; 736a6f13a4aSGreg Roach } 737a6f13a4aSGreg Roach } 738a6f13a4aSGreg Roach // boolean After this box is finished rendering, should the next section of text start immediately after the this box or should it start on a new line under this box. 0 = no new line, 1 = force new line. Default is 0 739a6f13a4aSGreg Roach $newline = false; 740a6f13a4aSGreg Roach if (isset($attrs['newline'])) { 7417a6ee1acSGreg Roach if ($attrs['newline'] === '1') { 742a6f13a4aSGreg Roach $newline = true; 7437a6ee1acSGreg Roach } elseif ($attrs['newline'] === '0') { 744a6f13a4aSGreg Roach $newline = false; 745a6f13a4aSGreg Roach } 746a6f13a4aSGreg Roach } 747a6f13a4aSGreg Roach // boolean 748a6f13a4aSGreg Roach $pagecheck = true; 749a6f13a4aSGreg Roach if (isset($attrs['pagecheck'])) { 7507a6ee1acSGreg Roach if ($attrs['pagecheck'] === '0') { 751a6f13a4aSGreg Roach $pagecheck = false; 7527a6ee1acSGreg Roach } elseif ($attrs['pagecheck'] === '1') { 753a6f13a4aSGreg Roach $pagecheck = true; 754a6f13a4aSGreg Roach } 755a6f13a4aSGreg Roach } 756a6f13a4aSGreg Roach // boolean Cell padding 757a6f13a4aSGreg Roach $padding = true; 758a6f13a4aSGreg Roach if (isset($attrs['padding'])) { 7597a6ee1acSGreg Roach if ($attrs['padding'] === '0') { 760a6f13a4aSGreg Roach $padding = false; 7617a6ee1acSGreg Roach } elseif ($attrs['padding'] === '1') { 762a6f13a4aSGreg Roach $padding = true; 763a6f13a4aSGreg Roach } 764a6f13a4aSGreg Roach } 765a6f13a4aSGreg Roach // boolean Reset this box Height 766a6f13a4aSGreg Roach $reseth = false; 767a6f13a4aSGreg Roach if (isset($attrs['reseth'])) { 7687a6ee1acSGreg Roach if ($attrs['reseth'] === '1') { 769a6f13a4aSGreg Roach $reseth = true; 7707a6ee1acSGreg Roach } elseif ($attrs['reseth'] === '0') { 771a6f13a4aSGreg Roach $reseth = false; 772a6f13a4aSGreg Roach } 773a6f13a4aSGreg Roach } 774a6f13a4aSGreg Roach 775a6f13a4aSGreg Roach // string Style of rendering 7767a6ee1acSGreg Roach $style = ''; 777a6f13a4aSGreg Roach 778a6f13a4aSGreg Roach array_push($this->print_data_stack, $this->print_data); 779a6f13a4aSGreg Roach $this->print_data = false; 780a6f13a4aSGreg Roach 781e8e7866bSGreg Roach array_push($this->wt_report_stack, $this->wt_report); 782e8e7866bSGreg Roach $this->wt_report = $this->report_root->createTextBox( 783a6f13a4aSGreg Roach $width, 784a6f13a4aSGreg Roach $height, 785a6f13a4aSGreg Roach $border, 786a6f13a4aSGreg Roach $bgcolor, 787a6f13a4aSGreg Roach $newline, 788a6f13a4aSGreg Roach $left, 789a6f13a4aSGreg Roach $top, 790a6f13a4aSGreg Roach $pagecheck, 791a6f13a4aSGreg Roach $style, 792a6f13a4aSGreg Roach $fill, 793a6f13a4aSGreg Roach $padding, 794a6f13a4aSGreg Roach $reseth 795a6f13a4aSGreg Roach ); 796a6f13a4aSGreg Roach } 797a6f13a4aSGreg Roach 798a6f13a4aSGreg Roach /** 79976692c8bSGreg Roach * XML <textBoxEndHandler> 800a6f13a4aSGreg Roach */ 801c1010edaSGreg Roach private function textBoxEndHandler() 802c1010edaSGreg Roach { 803a6f13a4aSGreg Roach $this->print_data = array_pop($this->print_data_stack); 804e8e7866bSGreg Roach $this->current_element = $this->wt_report; 805e8e7866bSGreg Roach $this->wt_report = array_pop($this->wt_report_stack); 806e8e7866bSGreg Roach $this->wt_report->addElement($this->current_element); 807a6f13a4aSGreg Roach } 808a6f13a4aSGreg Roach 809a6f13a4aSGreg Roach /** 81076692c8bSGreg Roach * XLM <Text>. 81176692c8bSGreg Roach * 812a6f13a4aSGreg Roach * @param array $attrs an array of key value pairs for the attributes 813a6f13a4aSGreg Roach */ 814c1010edaSGreg Roach private function textStartHandler($attrs) 815c1010edaSGreg Roach { 816a6f13a4aSGreg Roach array_push($this->print_data_stack, $this->print_data); 817a6f13a4aSGreg Roach $this->print_data = true; 818a6f13a4aSGreg Roach 819a6f13a4aSGreg Roach // string The name of the Style that should be used to render the text. 8207a6ee1acSGreg Roach $style = ''; 821a6f13a4aSGreg Roach if (!empty($attrs['style'])) { 822a6f13a4aSGreg Roach $style = $attrs['style']; 823a6f13a4aSGreg Roach } 824a6f13a4aSGreg Roach 825a6f13a4aSGreg Roach // string The color of the text - Keep the black color as default 8267a6ee1acSGreg Roach $color = ''; 827a6f13a4aSGreg Roach if (!empty($attrs['color'])) { 828a6f13a4aSGreg Roach $color = $attrs['color']; 829a6f13a4aSGreg Roach } 830a6f13a4aSGreg Roach 831e8e7866bSGreg Roach $this->current_element = $this->report_root->createText($style, $color); 832a6f13a4aSGreg Roach } 833a6f13a4aSGreg Roach 834a6f13a4aSGreg Roach /** 83576692c8bSGreg Roach * XML </Text> 836a6f13a4aSGreg Roach */ 837c1010edaSGreg Roach private function textEndHandler() 838c1010edaSGreg Roach { 839a6f13a4aSGreg Roach $this->print_data = array_pop($this->print_data_stack); 840e8e7866bSGreg Roach $this->wt_report->addElement($this->current_element); 841a6f13a4aSGreg Roach } 842a6f13a4aSGreg Roach 843a6f13a4aSGreg Roach /** 84476692c8bSGreg Roach * XML <GetPersonName/> 84576692c8bSGreg Roach * 846a6f13a4aSGreg Roach * Get the name 847a6f13a4aSGreg Roach * 1. id is empty - current GEDCOM record 848a6f13a4aSGreg Roach * 2. id is set with a record id 849a6f13a4aSGreg Roach * 850a6f13a4aSGreg Roach * @param array $attrs an array of key value pairs for the attributes 851a6f13a4aSGreg Roach */ 852c1010edaSGreg Roach private function getPersonNameStartHandler($attrs) 853c1010edaSGreg Roach { 8547a6ee1acSGreg Roach $id = ''; 85513abd6f3SGreg Roach $match = []; 856a6f13a4aSGreg Roach if (empty($attrs['id'])) { 8577a6ee1acSGreg Roach if (preg_match('/0 @(.+)@/', $this->gedrec, $match)) { 858a6f13a4aSGreg Roach $id = $match[1]; 859a6f13a4aSGreg Roach } 860a6f13a4aSGreg Roach } else { 8617a6ee1acSGreg Roach if (preg_match('/\$(.+)/', $attrs['id'], $match)) { 862d1286247SGreg Roach if (isset($this->vars[$match[1]]['id'])) { 863d1286247SGreg Roach $id = $this->vars[$match[1]]['id']; 864a6f13a4aSGreg Roach } 865a6f13a4aSGreg Roach } else { 8667a6ee1acSGreg Roach if (preg_match('/@(.+)/', $attrs['id'], $match)) { 86713abd6f3SGreg Roach $gmatch = []; 868a6f13a4aSGreg Roach if (preg_match("/\d $match[1] @([^@]+)@/", $this->gedrec, $gmatch)) { 869a6f13a4aSGreg Roach $id = $gmatch[1]; 870a6f13a4aSGreg Roach } 871a6f13a4aSGreg Roach } else { 872a6f13a4aSGreg Roach $id = $attrs['id']; 873a6f13a4aSGreg Roach } 874a6f13a4aSGreg Roach } 875a6f13a4aSGreg Roach } 876a6f13a4aSGreg Roach if (!empty($id)) { 877299d100dSGreg Roach $record = GedcomRecord::getInstance($id, $this->tree); 878a6f13a4aSGreg Roach if (is_null($record)) { 879a6f13a4aSGreg Roach return; 880a6f13a4aSGreg Roach } 881a6f13a4aSGreg Roach if (!$record->canShowName()) { 882a6f13a4aSGreg Roach $this->current_element->addText(I18N::translate('Private')); 883a6f13a4aSGreg Roach } else { 884a6f13a4aSGreg Roach $name = $record->getFullName(); 885a6f13a4aSGreg Roach $name = preg_replace( 886c1010edaSGreg Roach [ 887c1010edaSGreg Roach '/<span class="starredname">/', 888c1010edaSGreg Roach '/<\/span><\/span>/', 889c1010edaSGreg Roach '/<\/span>/', 890c1010edaSGreg Roach ], 891c1010edaSGreg Roach [ 892c1010edaSGreg Roach '«', 893c1010edaSGreg Roach '', 894c1010edaSGreg Roach '»', 895c1010edaSGreg Roach ], 896a6f13a4aSGreg Roach $name 897a6f13a4aSGreg Roach ); 898a6f13a4aSGreg Roach $name = strip_tags($name); 899a6f13a4aSGreg Roach if (!empty($attrs['truncate'])) { 900a6f13a4aSGreg Roach if (mb_strlen($name) > $attrs['truncate']) { 901a6f13a4aSGreg Roach $name = preg_replace("/\(.*\) ?/", '', $name); //removes () and text inbetween - what about ", [ and { etc? 902a6f13a4aSGreg Roach $words = preg_split('/[, -]+/', $name); // names separated with space, comma or hyphen - any others? 903a6f13a4aSGreg Roach $name = $words[count($words) - 1]; 904a6f13a4aSGreg Roach for ($i = count($words) - 2; $i >= 0; $i--) { 905a6f13a4aSGreg Roach $len = mb_strlen($name); 906a6f13a4aSGreg Roach for ($j = count($words) - 3; $j >= 0; $j--) { 907a6f13a4aSGreg Roach $len += mb_strlen($words[$j]); 908a6f13a4aSGreg Roach } 909a6f13a4aSGreg Roach if ($len > $attrs['truncate']) { 910a6f13a4aSGreg Roach $first_letter = mb_substr($words[$i], 0, 1); 911a6f13a4aSGreg Roach // Do not show " of nick-names 9127a6ee1acSGreg Roach if ($first_letter != '"') { 913a6f13a4aSGreg Roach $name = mb_substr($words[$i], 0, 1) . '. ' . $name; 914a6f13a4aSGreg Roach } 915a6f13a4aSGreg Roach } else { 916a6f13a4aSGreg Roach $name = $words[$i] . ' ' . $name; 917a6f13a4aSGreg Roach } 918a6f13a4aSGreg Roach } 919a6f13a4aSGreg Roach } 920a6f13a4aSGreg Roach } else { 921a6f13a4aSGreg Roach $addname = $record->getAddName(); 922a6f13a4aSGreg Roach $addname = preg_replace( 923c1010edaSGreg Roach [ 924c1010edaSGreg Roach '/<span class="starredname">/', 925c1010edaSGreg Roach '/<\/span><\/span>/', 926c1010edaSGreg Roach '/<\/span>/', 927c1010edaSGreg Roach ], 928c1010edaSGreg Roach [ 929c1010edaSGreg Roach '«', 930c1010edaSGreg Roach '', 931c1010edaSGreg Roach '»', 932c1010edaSGreg Roach ], 933a6f13a4aSGreg Roach $addname 934a6f13a4aSGreg Roach ); 935a6f13a4aSGreg Roach $addname = strip_tags($addname); 936a6f13a4aSGreg Roach if (!empty($addname)) { 9377a6ee1acSGreg Roach $name .= ' ' . $addname; 938a6f13a4aSGreg Roach } 939a6f13a4aSGreg Roach } 940a6f13a4aSGreg Roach $this->current_element->addText(trim($name)); 941a6f13a4aSGreg Roach } 942a6f13a4aSGreg Roach } 943a6f13a4aSGreg Roach } 944a6f13a4aSGreg Roach 945a6f13a4aSGreg Roach /** 94676692c8bSGreg Roach * XML <GedcomValue/> 947a6f13a4aSGreg Roach * 948a6f13a4aSGreg Roach * @param array $attrs an array of key value pairs for the attributes 949a6f13a4aSGreg Roach */ 950c1010edaSGreg Roach private function gedcomValueStartHandler($attrs) 951c1010edaSGreg Roach { 9527a6ee1acSGreg Roach $id = ''; 95313abd6f3SGreg Roach $match = []; 9547a6ee1acSGreg Roach if (preg_match('/0 @(.+)@/', $this->gedrec, $match)) { 955a6f13a4aSGreg Roach $id = $match[1]; 956a6f13a4aSGreg Roach } 957a6f13a4aSGreg Roach 9587a6ee1acSGreg Roach if (isset($attrs['newline']) && $attrs['newline'] == '1') { 9597a6ee1acSGreg Roach $useBreak = '1'; 960a6f13a4aSGreg Roach } else { 9617a6ee1acSGreg Roach $useBreak = '0'; 962a6f13a4aSGreg Roach } 963a6f13a4aSGreg Roach 964a6f13a4aSGreg Roach $tag = $attrs['tag']; 965a6f13a4aSGreg Roach if (!empty($tag)) { 9667a6ee1acSGreg Roach if ($tag == '@desc') { 967a6f13a4aSGreg Roach $value = $this->desc; 968a6f13a4aSGreg Roach $value = trim($value); 969a6f13a4aSGreg Roach $this->current_element->addText($value); 970a6f13a4aSGreg Roach } 9717a6ee1acSGreg Roach if ($tag == '@id') { 972a6f13a4aSGreg Roach $this->current_element->addText($id); 973a6f13a4aSGreg Roach } else { 9747a6ee1acSGreg Roach $tag = str_replace('@fact', $this->fact, $tag); 975a6f13a4aSGreg Roach if (empty($attrs['level'])) { 9767a6ee1acSGreg Roach $temp = explode(' ', trim($this->gedrec)); 977a6f13a4aSGreg Roach $level = $temp[0]; 978a6f13a4aSGreg Roach if ($level == 0) { 979a6f13a4aSGreg Roach $level++; 980a6f13a4aSGreg Roach } 981a6f13a4aSGreg Roach } else { 982a6f13a4aSGreg Roach $level = $attrs['level']; 983a6f13a4aSGreg Roach } 984a6f13a4aSGreg Roach $tags = preg_split('/[: ]/', $tag); 9853d7a8a4cSGreg Roach $value = $this->getGedcomValue($tag, $level, $this->gedrec); 986a6f13a4aSGreg Roach switch (end($tags)) { 987a6f13a4aSGreg Roach case 'DATE': 988a6f13a4aSGreg Roach $tmp = new Date($value); 989a6f13a4aSGreg Roach $value = $tmp->display(); 990a6f13a4aSGreg Roach break; 991a6f13a4aSGreg Roach case 'PLAC': 992299d100dSGreg Roach $tmp = new Place($value, $this->tree); 993a6f13a4aSGreg Roach $value = $tmp->getShortName(); 994a6f13a4aSGreg Roach break; 995a6f13a4aSGreg Roach } 9967a6ee1acSGreg Roach if ($useBreak == '1') { 997a6f13a4aSGreg Roach // Insert <br> when multiple dates exist. 998a6f13a4aSGreg Roach // This works around a TCPDF bug that incorrectly wraps RTL dates on LTR pages 999a6f13a4aSGreg Roach $value = str_replace('(', '<br>(', $value); 1000a6f13a4aSGreg Roach $value = str_replace('<span dir="ltr"><br>', '<br><span dir="ltr">', $value); 1001a6f13a4aSGreg Roach $value = str_replace('<span dir="rtl"><br>', '<br><span dir="rtl">', $value); 1002a6f13a4aSGreg Roach if (substr($value, 0, 6) == '<br>') { 1003a6f13a4aSGreg Roach $value = substr($value, 6); 1004a6f13a4aSGreg Roach } 1005a6f13a4aSGreg Roach } 1006d4d660b7SGreg Roach $tmp = explode(':', $tag); 1007c1010edaSGreg Roach if (in_array(end($tmp), [ 1008c1010edaSGreg Roach 'NOTE', 1009c1010edaSGreg Roach 'TEXT', 1010c1010edaSGreg Roach ])) { 1011299d100dSGreg Roach $value = Filter::formatText($value, $this->tree); // We'll strip HTML in addText() 1012a4d703aeSGreg Roach } 1013a6f13a4aSGreg Roach $this->current_element->addText($value); 1014a6f13a4aSGreg Roach } 1015a6f13a4aSGreg Roach } 1016a6f13a4aSGreg Roach } 1017a6f13a4aSGreg Roach 1018a6f13a4aSGreg Roach /** 101976692c8bSGreg Roach * XML <RepeatTag> 1020a6f13a4aSGreg Roach * 1021a6f13a4aSGreg Roach * @param array $attrs an array of key value pairs for the attributes 1022a6f13a4aSGreg Roach */ 1023c1010edaSGreg Roach private function repeatTagStartHandler($attrs) 1024c1010edaSGreg Roach { 1025a6f13a4aSGreg Roach $this->process_repeats++; 1026a6f13a4aSGreg Roach if ($this->process_repeats > 1) { 1027a6f13a4aSGreg Roach return; 1028a6f13a4aSGreg Roach } 1029a6f13a4aSGreg Roach 1030c1010edaSGreg Roach array_push($this->repeats_stack, [ 1031c1010edaSGreg Roach $this->repeats, 1032c1010edaSGreg Roach $this->repeat_bytes, 1033c1010edaSGreg Roach ]); 103413abd6f3SGreg Roach $this->repeats = []; 1035e8e7866bSGreg Roach $this->repeat_bytes = xml_get_current_line_number($this->parser); 1036a6f13a4aSGreg Roach 10377a6ee1acSGreg Roach $tag = ''; 1038a6f13a4aSGreg Roach if (isset($attrs['tag'])) { 1039a6f13a4aSGreg Roach $tag = $attrs['tag']; 1040a6f13a4aSGreg Roach } 1041a6f13a4aSGreg Roach if (!empty($tag)) { 10427a6ee1acSGreg Roach if ($tag == '@desc') { 1043a6f13a4aSGreg Roach $value = $this->desc; 1044a6f13a4aSGreg Roach $value = trim($value); 1045a6f13a4aSGreg Roach $this->current_element->addText($value); 1046a6f13a4aSGreg Roach } else { 10477a6ee1acSGreg Roach $tag = str_replace('@fact', $this->fact, $tag); 10487a6ee1acSGreg Roach $tags = explode(':', $tag); 10497a6ee1acSGreg Roach $temp = explode(' ', trim($this->gedrec)); 1050a6f13a4aSGreg Roach $level = $temp[0]; 1051a6f13a4aSGreg Roach if ($level == 0) { 1052a6f13a4aSGreg Roach $level++; 1053a6f13a4aSGreg Roach } 1054a6f13a4aSGreg Roach $subrec = $this->gedrec; 1055a6f13a4aSGreg Roach $t = $tag; 1056a6f13a4aSGreg Roach $count = count($tags); 1057a6f13a4aSGreg Roach $i = 0; 1058a6f13a4aSGreg Roach while ($i < $count) { 1059a6f13a4aSGreg Roach $t = $tags[$i]; 1060a6f13a4aSGreg Roach if (!empty($t)) { 1061a6f13a4aSGreg Roach if ($i < ($count - 1)) { 10623d7a8a4cSGreg Roach $subrec = Functions::getSubRecord($level, "$level $t", $subrec); 1063a6f13a4aSGreg Roach if (empty($subrec)) { 1064a6f13a4aSGreg Roach $level--; 10653d7a8a4cSGreg Roach $subrec = Functions::getSubRecord($level, "@ $t", $this->gedrec); 1066a6f13a4aSGreg Roach if (empty($subrec)) { 1067a6f13a4aSGreg Roach return; 1068a6f13a4aSGreg Roach } 1069a6f13a4aSGreg Roach } 1070a6f13a4aSGreg Roach } 1071a6f13a4aSGreg Roach $level++; 1072a6f13a4aSGreg Roach } 1073a6f13a4aSGreg Roach $i++; 1074a6f13a4aSGreg Roach } 1075a6f13a4aSGreg Roach $level--; 1076a6f13a4aSGreg Roach $count = preg_match_all("/$level $t(.*)/", $subrec, $match, PREG_SET_ORDER); 1077a6f13a4aSGreg Roach $i = 0; 1078a6f13a4aSGreg Roach while ($i < $count) { 1079a6f13a4aSGreg Roach $i++; 1080a9007102SGreg Roach // Privacy check - is this a link, and are we allowed to view the linked object? 1081a9007102SGreg Roach $subrecord = Functions::getSubRecord($level, "$level $t", $subrec, $i); 1082a9007102SGreg Roach if (preg_match('/^\d ' . WT_REGEX_TAG . ' @(' . WT_REGEX_XREF . ')@/', $subrecord, $xref_match)) { 1083299d100dSGreg Roach $linked_object = GedcomRecord::getInstance($xref_match[1], $this->tree); 1084a9007102SGreg Roach if ($linked_object && !$linked_object->canShow()) { 1085a9007102SGreg Roach continue; 1086a9007102SGreg Roach } 1087a9007102SGreg Roach } 1088a9007102SGreg Roach $this->repeats[] = $subrecord; 1089a6f13a4aSGreg Roach } 1090a6f13a4aSGreg Roach } 1091a6f13a4aSGreg Roach } 1092a6f13a4aSGreg Roach } 1093a6f13a4aSGreg Roach 1094a6f13a4aSGreg Roach /** 109576692c8bSGreg Roach * XML </ RepeatTag> 1096a6f13a4aSGreg Roach */ 1097c1010edaSGreg Roach private function repeatTagEndHandler() 1098c1010edaSGreg Roach { 1099a6f13a4aSGreg Roach $this->process_repeats--; 1100a6f13a4aSGreg Roach if ($this->process_repeats > 0) { 1101a6f13a4aSGreg Roach return; 1102a6f13a4aSGreg Roach } 1103a6f13a4aSGreg Roach 1104a6f13a4aSGreg Roach // Check if there is anything to repeat 1105a6f13a4aSGreg Roach if (count($this->repeats) > 0) { 1106a6f13a4aSGreg Roach // No need to load them if not used... 1107a6f13a4aSGreg Roach 1108a6f13a4aSGreg Roach $lineoffset = 0; 1109a6f13a4aSGreg Roach foreach ($this->repeats_stack as $rep) { 1110a6f13a4aSGreg Roach $lineoffset += $rep[1]; 1111a6f13a4aSGreg Roach } 1112a6f13a4aSGreg Roach //-- read the xml from the file 1113299d100dSGreg Roach $lines = file($this->report); 11147a6ee1acSGreg Roach while (strpos($lines[$lineoffset + $this->repeat_bytes], '<RepeatTag') === false) { 1115a6f13a4aSGreg Roach $lineoffset--; 1116a6f13a4aSGreg Roach } 1117a6f13a4aSGreg Roach $lineoffset++; 1118a6f13a4aSGreg Roach $reportxml = "<tempdoc>\n"; 1119a6f13a4aSGreg Roach $line_nr = $lineoffset + $this->repeat_bytes; 1120a6f13a4aSGreg Roach // RepeatTag Level counter 1121a6f13a4aSGreg Roach $count = 1; 1122a6f13a4aSGreg Roach while (0 < $count) { 11237a6ee1acSGreg Roach if (strstr($lines[$line_nr], '<RepeatTag') !== false) { 1124a6f13a4aSGreg Roach $count++; 11257a6ee1acSGreg Roach } elseif (strstr($lines[$line_nr], '</RepeatTag') !== false) { 1126a6f13a4aSGreg Roach $count--; 1127a6f13a4aSGreg Roach } 1128a6f13a4aSGreg Roach if (0 < $count) { 1129a6f13a4aSGreg Roach $reportxml .= $lines[$line_nr]; 1130a6f13a4aSGreg Roach } 1131a6f13a4aSGreg Roach $line_nr++; 1132a6f13a4aSGreg Roach } 1133a6f13a4aSGreg Roach // No need to drag this 1134a6f13a4aSGreg Roach unset($lines); 1135a6f13a4aSGreg Roach $reportxml .= "</tempdoc>\n"; 1136a6f13a4aSGreg Roach // Save original values 1137e8e7866bSGreg Roach array_push($this->parser_stack, $this->parser); 1138a6f13a4aSGreg Roach $oldgedrec = $this->gedrec; 1139a6f13a4aSGreg Roach foreach ($this->repeats as $gedrec) { 1140a6f13a4aSGreg Roach $this->gedrec = $gedrec; 1141a6f13a4aSGreg Roach $repeat_parser = xml_parser_create(); 1142e8e7866bSGreg Roach $this->parser = $repeat_parser; 1143a6f13a4aSGreg Roach xml_parser_set_option($repeat_parser, XML_OPTION_CASE_FOLDING, false); 1144c1010edaSGreg Roach xml_set_element_handler($repeat_parser, [ 1145c1010edaSGreg Roach $this, 1146c1010edaSGreg Roach 'startElement', 1147c1010edaSGreg Roach ], [ 1148c1010edaSGreg Roach $this, 1149c1010edaSGreg Roach 'endElement', 1150c1010edaSGreg Roach ]); 1151c1010edaSGreg Roach xml_set_character_data_handler($repeat_parser, [ 1152c1010edaSGreg Roach $this, 1153c1010edaSGreg Roach 'characterData', 1154c1010edaSGreg Roach ]); 1155a6f13a4aSGreg Roach if (!xml_parse($repeat_parser, $reportxml, true)) { 1156a6f13a4aSGreg Roach throw new \DomainException(sprintf( 1157a6f13a4aSGreg Roach 'RepeatTagEHandler XML error: %s at line %d', 1158a6f13a4aSGreg Roach xml_error_string(xml_get_error_code($repeat_parser)), 1159a6f13a4aSGreg Roach xml_get_current_line_number($repeat_parser) 1160a6f13a4aSGreg Roach )); 1161a6f13a4aSGreg Roach } 1162a6f13a4aSGreg Roach xml_parser_free($repeat_parser); 1163a6f13a4aSGreg Roach } 1164a6f13a4aSGreg Roach // Restore original values 1165a6f13a4aSGreg Roach $this->gedrec = $oldgedrec; 1166e8e7866bSGreg Roach $this->parser = array_pop($this->parser_stack); 1167a6f13a4aSGreg Roach } 1168a6f13a4aSGreg Roach list($this->repeats, $this->repeat_bytes) = array_pop($this->repeats_stack); 1169a6f13a4aSGreg Roach } 1170a6f13a4aSGreg Roach 1171a6f13a4aSGreg Roach /** 1172a6f13a4aSGreg Roach * Variable lookup 1173a6f13a4aSGreg Roach * 1174a6f13a4aSGreg Roach * Retrieve predefined variables : 1175a6f13a4aSGreg Roach * 1176a6f13a4aSGreg Roach * @ desc GEDCOM fact description, example: 1177a6f13a4aSGreg Roach * 1 EVEN This is a description 1178a6f13a4aSGreg Roach * @ fact GEDCOM fact tag, such as BIRT, DEAT etc. 1179a6f13a4aSGreg Roach * $ I18N::translate('....') 1180a6f13a4aSGreg Roach * $ language_settings[] 1181a6f13a4aSGreg Roach * 1182a6f13a4aSGreg Roach * @param array $attrs an array of key value pairs for the attributes 1183a6f13a4aSGreg Roach */ 1184c1010edaSGreg Roach private function varStartHandler($attrs) 1185c1010edaSGreg Roach { 1186a6f13a4aSGreg Roach if (empty($attrs['var'])) { 1187e8e7866bSGreg Roach throw new \DomainException('REPORT ERROR var: The attribute "var=" is missing or not set in the XML file on line: ' . xml_get_current_line_number($this->parser)); 1188a6f13a4aSGreg Roach } 1189a6f13a4aSGreg Roach 1190a6f13a4aSGreg Roach $var = $attrs['var']; 1191a6f13a4aSGreg Roach // SetVar element preset variables 1192d1286247SGreg Roach if (!empty($this->vars[$var]['id'])) { 1193d1286247SGreg Roach $var = $this->vars[$var]['id']; 1194a6f13a4aSGreg Roach } else { 1195a6f13a4aSGreg Roach $tfact = $this->fact; 11967a6ee1acSGreg Roach if (($this->fact === 'EVEN' || $this->fact === 'FACT') && $this->type !== ' ') { 1197a6f13a4aSGreg Roach // Use : 1198a6f13a4aSGreg Roach // n TYPE This text if string 1199a6f13a4aSGreg Roach $tfact = $this->type; 1200a6f13a4aSGreg Roach } 1201c1010edaSGreg Roach $var = str_replace([ 1202c1010edaSGreg Roach '@fact', 1203c1010edaSGreg Roach '@desc', 1204c1010edaSGreg Roach ], [ 1205c1010edaSGreg Roach GedcomTag::getLabel($tfact), 1206c1010edaSGreg Roach $this->desc, 1207c1010edaSGreg Roach ], $var); 1208a6f13a4aSGreg Roach if (preg_match('/^I18N::number\((.+)\)$/', $var, $match)) { 1209a6f13a4aSGreg Roach $var = I18N::number($match[1]); 1210a6f13a4aSGreg Roach } elseif (preg_match('/^I18N::translate\(\'(.+)\'\)$/', $var, $match)) { 1211a6f13a4aSGreg Roach $var = I18N::translate($match[1]); 1212a4956c0eSGreg Roach } elseif (preg_match('/^I18N::translateContext\(\'(.+)\', *\'(.+)\'\)$/', $var, $match)) { 1213a6f13a4aSGreg Roach $var = I18N::translateContext($match[1], $match[2]); 1214a6f13a4aSGreg Roach } 1215a6f13a4aSGreg Roach } 1216a6f13a4aSGreg Roach // Check if variable is set as a date and reformat the date 1217a6f13a4aSGreg Roach if (isset($attrs['date'])) { 12187a6ee1acSGreg Roach if ($attrs['date'] === '1') { 1219a6f13a4aSGreg Roach $g = new Date($var); 1220a6f13a4aSGreg Roach $var = $g->display(); 1221a6f13a4aSGreg Roach } 1222a6f13a4aSGreg Roach } 1223a6f13a4aSGreg Roach $this->current_element->addText($var); 12242836aa05SGreg Roach $this->text = $var; // Used for title/descriptio 1225a6f13a4aSGreg Roach } 1226a6f13a4aSGreg Roach 1227a6f13a4aSGreg Roach /** 122876692c8bSGreg Roach * XML <Facts> 122976692c8bSGreg Roach * 1230a6f13a4aSGreg Roach * @param array $attrs an array of key value pairs for the attributes 1231a6f13a4aSGreg Roach */ 1232c1010edaSGreg Roach private function factsStartHandler($attrs) 1233c1010edaSGreg Roach { 1234a6f13a4aSGreg Roach $this->process_repeats++; 1235a6f13a4aSGreg Roach if ($this->process_repeats > 1) { 1236a6f13a4aSGreg Roach return; 1237a6f13a4aSGreg Roach } 1238a6f13a4aSGreg Roach 1239c1010edaSGreg Roach array_push($this->repeats_stack, [ 1240c1010edaSGreg Roach $this->repeats, 1241c1010edaSGreg Roach $this->repeat_bytes, 1242c1010edaSGreg Roach ]); 124313abd6f3SGreg Roach $this->repeats = []; 1244e8e7866bSGreg Roach $this->repeat_bytes = xml_get_current_line_number($this->parser); 1245a6f13a4aSGreg Roach 12467a6ee1acSGreg Roach $id = ''; 124713abd6f3SGreg Roach $match = []; 12487a6ee1acSGreg Roach if (preg_match('/0 @(.+)@/', $this->gedrec, $match)) { 1249a6f13a4aSGreg Roach $id = $match[1]; 1250a6f13a4aSGreg Roach } 12517a6ee1acSGreg Roach $tag = ''; 1252a6f13a4aSGreg Roach if (isset($attrs['ignore'])) { 1253a6f13a4aSGreg Roach $tag .= $attrs['ignore']; 1254a6f13a4aSGreg Roach } 12557a6ee1acSGreg Roach if (preg_match('/\$(.+)/', $tag, $match)) { 1256d1286247SGreg Roach $tag = $this->vars[$match[1]]['id']; 1257a6f13a4aSGreg Roach } 1258a6f13a4aSGreg Roach 1259299d100dSGreg Roach $record = GedcomRecord::getInstance($id, $this->tree); 1260a6f13a4aSGreg Roach if (empty($attrs['diff']) && !empty($id)) { 1261a6f13a4aSGreg Roach $facts = $record->getFacts(); 12623d7a8a4cSGreg Roach Functions::sortFacts($facts); 126313abd6f3SGreg Roach $this->repeats = []; 1264a6f13a4aSGreg Roach $nonfacts = explode(',', $tag); 1265a6f13a4aSGreg Roach foreach ($facts as $event) { 1266a6f13a4aSGreg Roach if (!in_array($event->getTag(), $nonfacts)) { 1267a6f13a4aSGreg Roach $this->repeats[] = $event->getGedcom(); 1268a6f13a4aSGreg Roach } 1269a6f13a4aSGreg Roach } 1270a6f13a4aSGreg Roach } else { 1271a6f13a4aSGreg Roach foreach ($record->getFacts() as $fact) { 1272a6f13a4aSGreg Roach if ($fact->isPendingAddition() && $fact->getTag() !== 'CHAN') { 1273a6f13a4aSGreg Roach $this->repeats[] = $fact->getGedcom(); 1274a6f13a4aSGreg Roach } 1275a6f13a4aSGreg Roach } 1276a6f13a4aSGreg Roach } 1277a6f13a4aSGreg Roach } 1278a6f13a4aSGreg Roach 1279a6f13a4aSGreg Roach /** 128076692c8bSGreg Roach * XML </Facts> 1281a6f13a4aSGreg Roach */ 1282c1010edaSGreg Roach private function factsEndHandler() 1283c1010edaSGreg Roach { 1284a6f13a4aSGreg Roach $this->process_repeats--; 1285a6f13a4aSGreg Roach if ($this->process_repeats > 0) { 1286a6f13a4aSGreg Roach return; 1287a6f13a4aSGreg Roach } 1288a6f13a4aSGreg Roach 1289a6f13a4aSGreg Roach // Check if there is anything to repeat 1290a6f13a4aSGreg Roach if (count($this->repeats) > 0) { 1291e8e7866bSGreg Roach $line = xml_get_current_line_number($this->parser) - 1; 1292a6f13a4aSGreg Roach $lineoffset = 0; 1293a6f13a4aSGreg Roach foreach ($this->repeats_stack as $rep) { 1294a6f13a4aSGreg Roach $lineoffset += $rep[1]; 1295a6f13a4aSGreg Roach } 1296a6f13a4aSGreg Roach 1297a6f13a4aSGreg Roach //-- read the xml from the file 1298299d100dSGreg Roach $lines = file($this->report); 1299a6f13a4aSGreg Roach while ($lineoffset + $this->repeat_bytes > 0 && strpos($lines[$lineoffset + $this->repeat_bytes], '<Facts ') === false) { 1300a6f13a4aSGreg Roach $lineoffset--; 1301a6f13a4aSGreg Roach } 1302a6f13a4aSGreg Roach $lineoffset++; 1303a6f13a4aSGreg Roach $reportxml = "<tempdoc>\n"; 1304a6f13a4aSGreg Roach $i = $line + $lineoffset; 1305a6f13a4aSGreg Roach $line_nr = $this->repeat_bytes + $lineoffset; 1306a6f13a4aSGreg Roach while ($line_nr < $i) { 1307a6f13a4aSGreg Roach $reportxml .= $lines[$line_nr]; 1308a6f13a4aSGreg Roach $line_nr++; 1309a6f13a4aSGreg Roach } 1310a6f13a4aSGreg Roach // No need to drag this 1311a6f13a4aSGreg Roach unset($lines); 1312a6f13a4aSGreg Roach $reportxml .= "</tempdoc>\n"; 1313a6f13a4aSGreg Roach // Save original values 1314e8e7866bSGreg Roach array_push($this->parser_stack, $this->parser); 1315a6f13a4aSGreg Roach $oldgedrec = $this->gedrec; 1316a6f13a4aSGreg Roach $count = count($this->repeats); 1317a6f13a4aSGreg Roach $i = 0; 1318a6f13a4aSGreg Roach while ($i < $count) { 1319a6f13a4aSGreg Roach $this->gedrec = $this->repeats[$i]; 1320a6f13a4aSGreg Roach $this->fact = ''; 1321a6f13a4aSGreg Roach $this->desc = ''; 1322a6f13a4aSGreg Roach if (preg_match('/1 (\w+)(.*)/', $this->gedrec, $match)) { 1323a6f13a4aSGreg Roach $this->fact = $match[1]; 1324a6f13a4aSGreg Roach if ($this->fact === 'EVEN' || $this->fact === 'FACT') { 132513abd6f3SGreg Roach $tmatch = []; 1326a6f13a4aSGreg Roach if (preg_match('/2 TYPE (.+)/', $this->gedrec, $tmatch)) { 1327a6f13a4aSGreg Roach $this->type = trim($tmatch[1]); 1328a6f13a4aSGreg Roach } else { 1329a6f13a4aSGreg Roach $this->type = ' '; 1330a6f13a4aSGreg Roach } 1331a6f13a4aSGreg Roach } 1332a6f13a4aSGreg Roach $this->desc = trim($match[2]); 13333d7a8a4cSGreg Roach $this->desc .= Functions::getCont(2, $this->gedrec); 1334a6f13a4aSGreg Roach } 1335a6f13a4aSGreg Roach $repeat_parser = xml_parser_create(); 1336e8e7866bSGreg Roach $this->parser = $repeat_parser; 1337a6f13a4aSGreg Roach xml_parser_set_option($repeat_parser, XML_OPTION_CASE_FOLDING, false); 1338c1010edaSGreg Roach xml_set_element_handler($repeat_parser, [ 1339c1010edaSGreg Roach $this, 1340c1010edaSGreg Roach 'startElement', 1341c1010edaSGreg Roach ], [ 1342c1010edaSGreg Roach $this, 1343c1010edaSGreg Roach 'endElement', 1344c1010edaSGreg Roach ]); 1345c1010edaSGreg Roach xml_set_character_data_handler($repeat_parser, [ 1346c1010edaSGreg Roach $this, 1347c1010edaSGreg Roach 'characterData', 1348c1010edaSGreg Roach ]); 1349a6f13a4aSGreg Roach if (!xml_parse($repeat_parser, $reportxml, true)) { 1350a6f13a4aSGreg Roach throw new \DomainException(sprintf( 1351a6f13a4aSGreg Roach 'FactsEHandler XML error: %s at line %d', 1352a6f13a4aSGreg Roach xml_error_string(xml_get_error_code($repeat_parser)), 1353a6f13a4aSGreg Roach xml_get_current_line_number($repeat_parser) 1354a6f13a4aSGreg Roach )); 1355a6f13a4aSGreg Roach } 1356a6f13a4aSGreg Roach xml_parser_free($repeat_parser); 1357a6f13a4aSGreg Roach $i++; 1358a6f13a4aSGreg Roach } 1359a6f13a4aSGreg Roach // Restore original values 1360e8e7866bSGreg Roach $this->parser = array_pop($this->parser_stack); 1361a6f13a4aSGreg Roach $this->gedrec = $oldgedrec; 1362a6f13a4aSGreg Roach } 1363a6f13a4aSGreg Roach list($this->repeats, $this->repeat_bytes) = array_pop($this->repeats_stack); 1364a6f13a4aSGreg Roach } 1365a6f13a4aSGreg Roach 1366a6f13a4aSGreg Roach /** 1367a6f13a4aSGreg Roach * Setting upp or changing variables in the XML 1368d1286247SGreg Roach * The XML variable name and value is stored in $this->vars 1369a6f13a4aSGreg Roach * 1370a6f13a4aSGreg Roach * @param array $attrs an array of key value pairs for the attributes 1371a6f13a4aSGreg Roach */ 1372c1010edaSGreg Roach private function setVarStartHandler($attrs) 1373c1010edaSGreg Roach { 1374a6f13a4aSGreg Roach if (empty($attrs['name'])) { 1375a6f13a4aSGreg Roach throw new \DomainException('REPORT ERROR var: The attribute "name" is missing or not set in the XML file'); 1376a6f13a4aSGreg Roach } 1377a6f13a4aSGreg Roach 1378a6f13a4aSGreg Roach $name = $attrs['name']; 1379a6f13a4aSGreg Roach $value = $attrs['value']; 138013abd6f3SGreg Roach $match = []; 1381a6f13a4aSGreg Roach // Current GEDCOM record strings 13827a6ee1acSGreg Roach if ($value == '@ID') { 13837a6ee1acSGreg Roach if (preg_match('/0 @(.+)@/', $this->gedrec, $match)) { 1384a6f13a4aSGreg Roach $value = $match[1]; 1385a6f13a4aSGreg Roach } 13867a6ee1acSGreg Roach } elseif ($value == '@fact') { 1387a6f13a4aSGreg Roach $value = $this->fact; 13887a6ee1acSGreg Roach } elseif ($value == '@desc') { 1389a6f13a4aSGreg Roach $value = $this->desc; 13907a6ee1acSGreg Roach } elseif ($value == '@generation') { 1391a6f13a4aSGreg Roach $value = $this->generation; 1392a6f13a4aSGreg Roach } elseif (preg_match("/@(\w+)/", $value, $match)) { 139313abd6f3SGreg Roach $gmatch = []; 1394a6f13a4aSGreg Roach if (preg_match("/\d $match[1] (.+)/", $this->gedrec, $gmatch)) { 13957a6ee1acSGreg Roach $value = str_replace('@', '', trim($gmatch[1])); 1396a6f13a4aSGreg Roach } 1397a6f13a4aSGreg Roach } 1398a6f13a4aSGreg Roach if (preg_match("/\\$(\w+)/", $name, $match)) { 1399d1286247SGreg Roach $name = $this->vars["'" . $match[1] . "'"]['id']; 1400a6f13a4aSGreg Roach } 1401a6f13a4aSGreg Roach $count = preg_match_all("/\\$(\w+)/", $value, $match, PREG_SET_ORDER); 1402a6f13a4aSGreg Roach $i = 0; 1403a6f13a4aSGreg Roach while ($i < $count) { 1404d1286247SGreg Roach $t = $this->vars[$match[$i][1]]['id']; 14057a6ee1acSGreg Roach $value = preg_replace('/\$' . $match[$i][1] . '/', $t, $value, 1); 1406a6f13a4aSGreg Roach $i++; 1407a6f13a4aSGreg Roach } 1408a6f13a4aSGreg Roach if (preg_match('/^I18N::number\((.+)\)$/', $value, $match)) { 1409a6f13a4aSGreg Roach $value = I18N::number($match[1]); 1410a6f13a4aSGreg Roach } elseif (preg_match('/^I18N::translate\(\'(.+)\'\)$/', $value, $match)) { 1411a6f13a4aSGreg Roach $value = I18N::translate($match[1]); 1412a4956c0eSGreg Roach } elseif (preg_match('/^I18N::translateContext\(\'(.+)\', *\'(.+)\'\)$/', $value, $match)) { 1413a6f13a4aSGreg Roach $value = I18N::translateContext($match[1], $match[2]); 1414a6f13a4aSGreg Roach } 1415a6f13a4aSGreg Roach // Arithmetic functions 1416a6f13a4aSGreg Roach if (preg_match("/(\d+)\s*([\-\+\*\/])\s*(\d+)/", $value, $match)) { 1417a6f13a4aSGreg Roach switch ($match[2]) { 14187a6ee1acSGreg Roach case '+': 1419a6f13a4aSGreg Roach $t = $match[1] + $match[3]; 14207a6ee1acSGreg Roach $value = preg_replace('/' . $match[1] . "\s*([\-\+\*\/])\s*" . $match[3] . '/', $t, $value); 1421a6f13a4aSGreg Roach break; 14227a6ee1acSGreg Roach case '-': 1423a6f13a4aSGreg Roach $t = $match[1] - $match[3]; 14247a6ee1acSGreg Roach $value = preg_replace('/' . $match[1] . "\s*([\-\+\*\/])\s*" . $match[3] . '/', $t, $value); 1425a6f13a4aSGreg Roach break; 14267a6ee1acSGreg Roach case '*': 1427a6f13a4aSGreg Roach $t = $match[1] * $match[3]; 14287a6ee1acSGreg Roach $value = preg_replace('/' . $match[1] . "\s*([\-\+\*\/])\s*" . $match[3] . '/', $t, $value); 1429a6f13a4aSGreg Roach break; 14307a6ee1acSGreg Roach case '/': 1431a6f13a4aSGreg Roach $t = $match[1] / $match[3]; 14327a6ee1acSGreg Roach $value = preg_replace('/' . $match[1] . "\s*([\-\+\*\/])\s*" . $match[3] . '/', $t, $value); 1433a6f13a4aSGreg Roach break; 1434a6f13a4aSGreg Roach } 1435a6f13a4aSGreg Roach } 14367a6ee1acSGreg Roach if (strpos($value, '@') !== false) { 14377a6ee1acSGreg Roach $value = ''; 1438a6f13a4aSGreg Roach } 1439d1286247SGreg Roach $this->vars[$name]['id'] = $value; 1440a6f13a4aSGreg Roach } 1441a6f13a4aSGreg Roach 1442a6f13a4aSGreg Roach /** 1443a6f13a4aSGreg Roach * XML <if > start element 1444a6f13a4aSGreg Roach * 1445a6f13a4aSGreg Roach * @param array $attrs an array of key value pairs for the attributes 1446a6f13a4aSGreg Roach */ 1447c1010edaSGreg Roach private function ifStartHandler($attrs) 1448c1010edaSGreg Roach { 1449a6f13a4aSGreg Roach if ($this->process_ifs > 0) { 1450a6f13a4aSGreg Roach $this->process_ifs++; 1451a6f13a4aSGreg Roach 1452a6f13a4aSGreg Roach return; 1453a6f13a4aSGreg Roach } 1454a6f13a4aSGreg Roach 1455a6f13a4aSGreg Roach $condition = $attrs['condition']; 145682759250SGreg Roach $condition = $this->substituteVars($condition, true); 1457c1010edaSGreg Roach $condition = str_replace([ 1458c1010edaSGreg Roach ' LT ', 1459c1010edaSGreg Roach ' GT ', 1460c1010edaSGreg Roach ], [ 1461c1010edaSGreg Roach '<', 1462c1010edaSGreg Roach '>', 1463c1010edaSGreg Roach ], $condition); 1464a6f13a4aSGreg Roach // Replace the first accurance only once of @fact:DATE or in any other combinations to the current fact, such as BIRT 14657a6ee1acSGreg Roach $condition = str_replace('@fact:', $this->fact . ':', $condition); 146613abd6f3SGreg Roach $match = []; 1467a6f13a4aSGreg Roach $count = preg_match_all("/@([\w:\.]+)/", $condition, $match, PREG_SET_ORDER); 1468a6f13a4aSGreg Roach $i = 0; 1469a6f13a4aSGreg Roach while ($i < $count) { 1470a6f13a4aSGreg Roach $id = $match[$i][1]; 1471a6f13a4aSGreg Roach $value = '""'; 14727a6ee1acSGreg Roach if ($id == 'ID') { 14737a6ee1acSGreg Roach if (preg_match('/0 @(.+)@/', $this->gedrec, $match)) { 1474a6f13a4aSGreg Roach $value = "'" . $match[1] . "'"; 1475a6f13a4aSGreg Roach } 14767a6ee1acSGreg Roach } elseif ($id === 'fact') { 1477a6f13a4aSGreg Roach $value = '"' . $this->fact . '"'; 14787a6ee1acSGreg Roach } elseif ($id === 'desc') { 1479a6f13a4aSGreg Roach $value = '"' . addslashes($this->desc) . '"'; 14807a6ee1acSGreg Roach } elseif ($id === 'generation') { 1481a6f13a4aSGreg Roach $value = '"' . $this->generation . '"'; 1482a6f13a4aSGreg Roach } else { 14837a6ee1acSGreg Roach $temp = explode(' ', trim($this->gedrec)); 1484a6f13a4aSGreg Roach $level = $temp[0]; 1485a6f13a4aSGreg Roach if ($level == 0) { 1486a6f13a4aSGreg Roach $level++; 1487a6f13a4aSGreg Roach } 14883d7a8a4cSGreg Roach $value = $this->getGedcomValue($id, $level, $this->gedrec); 1489a6f13a4aSGreg Roach if (empty($value)) { 1490a6f13a4aSGreg Roach $level++; 14913d7a8a4cSGreg Roach $value = $this->getGedcomValue($id, $level, $this->gedrec); 1492a6f13a4aSGreg Roach } 14935e8c88c1SGreg Roach $value = preg_replace('/^@(' . WT_REGEX_XREF . ')@$/', '$1', $value); 14945e8c88c1SGreg Roach $value = '"' . addslashes($value) . '"'; 1495a6f13a4aSGreg Roach } 1496a6f13a4aSGreg Roach $condition = str_replace("@$id", $value, $condition); 1497a6f13a4aSGreg Roach $i++; 1498a6f13a4aSGreg Roach } 14995e8c88c1SGreg Roach $ret = eval("return (bool) ($condition);"); 1500a6f13a4aSGreg Roach if (!$ret) { 1501a6f13a4aSGreg Roach $this->process_ifs++; 1502a6f13a4aSGreg Roach } 1503a6f13a4aSGreg Roach } 1504a6f13a4aSGreg Roach 1505a6f13a4aSGreg Roach /** 1506a6f13a4aSGreg Roach * XML <if /> end element 1507a6f13a4aSGreg Roach */ 1508c1010edaSGreg Roach private function ifEndHandler() 1509c1010edaSGreg Roach { 1510a6f13a4aSGreg Roach if ($this->process_ifs > 0) { 1511a6f13a4aSGreg Roach $this->process_ifs--; 1512a6f13a4aSGreg Roach } 1513a6f13a4aSGreg Roach } 1514a6f13a4aSGreg Roach 1515a6f13a4aSGreg Roach /** 1516a6f13a4aSGreg Roach * XML <Footnote > start element 1517a6f13a4aSGreg Roach * Collect the Footnote links 1518a6f13a4aSGreg Roach * GEDCOM Records that are protected by Privacy setting will be ignore 1519a6f13a4aSGreg Roach * 1520a6f13a4aSGreg Roach * @param array $attrs an array of key value pairs for the attributes 1521a6f13a4aSGreg Roach */ 1522c1010edaSGreg Roach private function footnoteStartHandler($attrs) 1523c1010edaSGreg Roach { 15247a6ee1acSGreg Roach $id = ''; 15257a6ee1acSGreg Roach if (preg_match('/[0-9] (.+) @(.+)@/', $this->gedrec, $match)) { 1526a6f13a4aSGreg Roach $id = $match[2]; 1527a6f13a4aSGreg Roach } 1528299d100dSGreg Roach $record = GedcomRecord::getInstance($id, $this->tree); 1529a6f13a4aSGreg Roach if ($record && $record->canShow()) { 1530a6f13a4aSGreg Roach array_push($this->print_data_stack, $this->print_data); 1531a6f13a4aSGreg Roach $this->print_data = true; 15327a6ee1acSGreg Roach $style = ''; 1533a6f13a4aSGreg Roach if (!empty($attrs['style'])) { 1534a6f13a4aSGreg Roach $style = $attrs['style']; 1535a6f13a4aSGreg Roach } 1536a6f13a4aSGreg Roach $this->footnote_element = $this->current_element; 1537e8e7866bSGreg Roach $this->current_element = $this->report_root->createFootnote($style); 1538a6f13a4aSGreg Roach } else { 1539a6f13a4aSGreg Roach $this->print_data = false; 1540a6f13a4aSGreg Roach $this->process_footnote = false; 1541a6f13a4aSGreg Roach } 1542a6f13a4aSGreg Roach } 1543a6f13a4aSGreg Roach 1544a6f13a4aSGreg Roach /** 1545a6f13a4aSGreg Roach * XML <Footnote /> end element 1546a6f13a4aSGreg Roach * Print the collected Footnote data 1547a6f13a4aSGreg Roach */ 1548c1010edaSGreg Roach private function footnoteEndHandler() 1549c1010edaSGreg Roach { 1550a6f13a4aSGreg Roach if ($this->process_footnote) { 1551a6f13a4aSGreg Roach $this->print_data = array_pop($this->print_data_stack); 1552a6f13a4aSGreg Roach $temp = trim($this->current_element->getValue()); 1553a6f13a4aSGreg Roach if (strlen($temp) > 3) { 1554e8e7866bSGreg Roach $this->wt_report->addElement($this->current_element); 1555a6f13a4aSGreg Roach } 1556a6f13a4aSGreg Roach $this->current_element = $this->footnote_element; 1557a6f13a4aSGreg Roach } else { 1558a6f13a4aSGreg Roach $this->process_footnote = true; 1559a6f13a4aSGreg Roach } 1560a6f13a4aSGreg Roach } 1561a6f13a4aSGreg Roach 1562a6f13a4aSGreg Roach /** 1563a6f13a4aSGreg Roach * XML <FootnoteTexts /> element 1564a6f13a4aSGreg Roach */ 1565c1010edaSGreg Roach private function footnoteTextsStartHandler() 1566c1010edaSGreg Roach { 15677a6ee1acSGreg Roach $temp = 'footnotetexts'; 1568e8e7866bSGreg Roach $this->wt_report->addElement($temp); 1569a6f13a4aSGreg Roach } 1570a6f13a4aSGreg Roach 1571a6f13a4aSGreg Roach /** 1572a6f13a4aSGreg Roach * XML <AgeAtDeath /> element handler 1573a6f13a4aSGreg Roach */ 1574c1010edaSGreg Roach private function ageAtDeathStartHandler() 1575c1010edaSGreg Roach { 15763d7a8a4cSGreg Roach // This duplicates functionality in FunctionsPrint::format_fact_date() 1577299d100dSGreg Roach global $factrec; 1578a6f13a4aSGreg Roach 157913abd6f3SGreg Roach $match = []; 15807a6ee1acSGreg Roach if (preg_match('/0 @(.+)@/', $this->gedrec, $match)) { 1581299d100dSGreg Roach $person = Individual::getInstance($match[1], $this->tree); 1582a6f13a4aSGreg Roach // Recorded age 1583a6f13a4aSGreg Roach if (preg_match('/\n2 AGE (.+)/', $factrec, $match)) { 1584a6f13a4aSGreg Roach $fact_age = $match[1]; 1585a6f13a4aSGreg Roach } else { 1586a6f13a4aSGreg Roach $fact_age = ''; 1587a6f13a4aSGreg Roach } 1588a6f13a4aSGreg Roach if (preg_match('/\n2 HUSB\n3 AGE (.+)/', $factrec, $match)) { 1589a6f13a4aSGreg Roach $husb_age = $match[1]; 1590a6f13a4aSGreg Roach } else { 1591a6f13a4aSGreg Roach $husb_age = ''; 1592a6f13a4aSGreg Roach } 1593a6f13a4aSGreg Roach if (preg_match('/\n2 WIFE\n3 AGE (.+)/', $factrec, $match)) { 1594a6f13a4aSGreg Roach $wife_age = $match[1]; 1595a6f13a4aSGreg Roach } else { 1596a6f13a4aSGreg Roach $wife_age = ''; 1597a6f13a4aSGreg Roach } 1598a6f13a4aSGreg Roach 1599a6f13a4aSGreg Roach // Calculated age 1600a6f13a4aSGreg Roach $birth_date = $person->getBirthDate(); 1601a6f13a4aSGreg Roach // Can't use getDeathDate(), as this also gives BURI/CREM events, which 1602a6f13a4aSGreg Roach // wouldn't give the correct "days after death" result for people with 1603a6f13a4aSGreg Roach // no DEAT. 1604a6f13a4aSGreg Roach $death_event = $person->getFirstFact('DEAT'); 1605a6f13a4aSGreg Roach if ($death_event) { 1606a6f13a4aSGreg Roach $death_date = $death_event->getDate(); 1607a6f13a4aSGreg Roach } else { 1608a6f13a4aSGreg Roach $death_date = new Date(''); 1609a6f13a4aSGreg Roach } 1610a6f13a4aSGreg Roach $value = ''; 1611a6f13a4aSGreg Roach if (Date::compare($birth_date, $death_date) <= 0 || !$person->isDead()) { 1612a6f13a4aSGreg Roach $age = Date::getAgeGedcom($birth_date, $death_date); 1613a6f13a4aSGreg Roach // Only show calculated age if it differs from recorded age 16147a6ee1acSGreg Roach if ($age != '' && $age != '0d') { 1615a6f13a4aSGreg Roach if ($fact_age != '' && $fact_age != $age || $fact_age == '' && $husb_age == '' && $wife_age == '' || $husb_age != '' && $person->getSex() == 'M' && $husb_age != $age || $wife_age != '' && $person->getSex() == 'F' && $wife_age != $age 1616a6f13a4aSGreg Roach ) { 1617d6aa7ab2SGreg Roach $value = FunctionsDate::getAgeAtEvent($age); 1618a6f13a4aSGreg Roach $abbrev = substr($value, 0, strpos($value, ' ') + 5); 1619a6f13a4aSGreg Roach if ($value !== $abbrev) { 1620a6f13a4aSGreg Roach $value = $abbrev . '.'; 1621a6f13a4aSGreg Roach } 1622a6f13a4aSGreg Roach } 1623a6f13a4aSGreg Roach } 1624a6f13a4aSGreg Roach } 1625a6f13a4aSGreg Roach $this->current_element->addText($value); 1626a6f13a4aSGreg Roach } 1627a6f13a4aSGreg Roach } 1628a6f13a4aSGreg Roach 1629a6f13a4aSGreg Roach /** 1630a6f13a4aSGreg Roach * XML element Forced line break handler - HTML code 1631a6f13a4aSGreg Roach */ 1632c1010edaSGreg Roach private function brStartHandler() 1633c1010edaSGreg Roach { 1634a6f13a4aSGreg Roach if ($this->print_data && $this->process_gedcoms === 0) { 1635a6f13a4aSGreg Roach $this->current_element->addText('<br>'); 1636a6f13a4aSGreg Roach } 1637a6f13a4aSGreg Roach } 1638a6f13a4aSGreg Roach 1639a6f13a4aSGreg Roach /** 1640a6f13a4aSGreg Roach * XML <sp />element Forced space handler 1641a6f13a4aSGreg Roach */ 1642c1010edaSGreg Roach private function spStartHandler() 1643c1010edaSGreg Roach { 1644a6f13a4aSGreg Roach if ($this->print_data && $this->process_gedcoms === 0) { 1645a6f13a4aSGreg Roach $this->current_element->addText(' '); 1646a6f13a4aSGreg Roach } 1647a6f13a4aSGreg Roach } 1648a6f13a4aSGreg Roach 1649a6f13a4aSGreg Roach /** 165076692c8bSGreg Roach * XML <HighlightedImage/> 165176692c8bSGreg Roach * 1652a6f13a4aSGreg Roach * @param array $attrs an array of key value pairs for the attributes 1653a6f13a4aSGreg Roach */ 1654c1010edaSGreg Roach private function highlightedImageStartHandler($attrs) 1655c1010edaSGreg Roach { 1656a6f13a4aSGreg Roach $id = ''; 165713abd6f3SGreg Roach $match = []; 16587a6ee1acSGreg Roach if (preg_match('/0 @(.+)@/', $this->gedrec, $match)) { 1659a6f13a4aSGreg Roach $id = $match[1]; 1660a6f13a4aSGreg Roach } 1661a6f13a4aSGreg Roach 1662a6f13a4aSGreg Roach // mixed Position the top corner of this box on the page. the default is the current position 1663a6f13a4aSGreg Roach $top = '.'; 1664a6f13a4aSGreg Roach if (isset($attrs['top'])) { 1665a6f13a4aSGreg Roach if ($attrs['top'] === '0') { 1666a6f13a4aSGreg Roach $top = 0; 1667a6f13a4aSGreg Roach } elseif ($attrs['top'] === '.') { 1668a6f13a4aSGreg Roach $top = '.'; 1669a6f13a4aSGreg Roach } elseif (!empty($attrs['top'])) { 1670a6f13a4aSGreg Roach $top = (int)$attrs['top']; 1671a6f13a4aSGreg Roach } 1672a6f13a4aSGreg Roach } 1673a6f13a4aSGreg Roach 1674a6f13a4aSGreg Roach // mixed Position the left corner of this box on the page. the default is the current position 1675a6f13a4aSGreg Roach $left = '.'; 1676a6f13a4aSGreg Roach if (isset($attrs['left'])) { 1677a6f13a4aSGreg Roach if ($attrs['left'] === '0') { 1678a6f13a4aSGreg Roach $left = 0; 1679a6f13a4aSGreg Roach } elseif ($attrs['left'] === '.') { 1680a6f13a4aSGreg Roach $left = '.'; 1681a6f13a4aSGreg Roach } elseif (!empty($attrs['left'])) { 1682a6f13a4aSGreg Roach $left = (int)$attrs['left']; 1683a6f13a4aSGreg Roach } 1684a6f13a4aSGreg Roach } 1685a6f13a4aSGreg Roach 1686a6f13a4aSGreg Roach // string Align the image in left, center, right 1687a6f13a4aSGreg Roach $align = ''; 1688a6f13a4aSGreg Roach if (!empty($attrs['align'])) { 1689a6f13a4aSGreg Roach $align = $attrs['align']; 1690a6f13a4aSGreg Roach } 1691a6f13a4aSGreg Roach 1692a6f13a4aSGreg Roach // string Next Line should be T:next to the image, N:next line 1693a6f13a4aSGreg Roach $ln = ''; 1694a6f13a4aSGreg Roach if (!empty($attrs['ln'])) { 1695a6f13a4aSGreg Roach $ln = $attrs['ln']; 1696a6f13a4aSGreg Roach } 1697a6f13a4aSGreg Roach 1698a6f13a4aSGreg Roach $width = 0; 1699a6f13a4aSGreg Roach $height = 0; 1700a6f13a4aSGreg Roach if (!empty($attrs['width'])) { 1701a6f13a4aSGreg Roach $width = (int)$attrs['width']; 1702a6f13a4aSGreg Roach } 1703a6f13a4aSGreg Roach if (!empty($attrs['height'])) { 1704a6f13a4aSGreg Roach $height = (int)$attrs['height']; 1705a6f13a4aSGreg Roach } 1706a6f13a4aSGreg Roach 1707299d100dSGreg Roach $person = Individual::getInstance($id, $this->tree); 17084a9f750fSGreg Roach $media_file = $person->findHighlightedMediaFile(); 170986a63f51SGreg Roach 171086a63f51SGreg Roach if ($media_file !== null && $media_file->fileExists()) { 1711c1010edaSGreg Roach $attributes = getimagesize($media_file->getServerFilename()) ?: [ 1712c1010edaSGreg Roach 0, 1713c1010edaSGreg Roach 0, 1714c1010edaSGreg Roach ]; 1715a6f13a4aSGreg Roach if ($width > 0 && $height == 0) { 17163c3b90deSGreg Roach $perc = $width / $attributes[0]; 17173c3b90deSGreg Roach $height = round($attributes[1] * $perc); 1718a6f13a4aSGreg Roach } elseif ($height > 0 && $width == 0) { 17193c3b90deSGreg Roach $perc = $height / $attributes[1]; 17203c3b90deSGreg Roach $width = round($attributes[0] * $perc); 1721a6f13a4aSGreg Roach } else { 17223c3b90deSGreg Roach $width = $attributes[0]; 17233c3b90deSGreg Roach $height = $attributes[1]; 1724a6f13a4aSGreg Roach } 17254a9f750fSGreg Roach $image = $this->report_root->createImageFromObject($media_file, $left, $top, $width, $height, $align, $ln); 1726e8e7866bSGreg Roach $this->wt_report->addElement($image); 1727a6f13a4aSGreg Roach } 1728a6f13a4aSGreg Roach } 1729a6f13a4aSGreg Roach 1730a6f13a4aSGreg Roach /** 173176692c8bSGreg Roach * XML <Image/> 173276692c8bSGreg Roach * 1733a6f13a4aSGreg Roach * @param array $attrs an array of key value pairs for the attributes 1734a6f13a4aSGreg Roach */ 1735c1010edaSGreg Roach private function imageStartHandler($attrs) 1736c1010edaSGreg Roach { 1737a6f13a4aSGreg Roach // mixed Position the top corner of this box on the page. the default is the current position 1738a6f13a4aSGreg Roach $top = '.'; 1739a6f13a4aSGreg Roach if (isset($attrs['top'])) { 17407a6ee1acSGreg Roach if ($attrs['top'] === '0') { 1741a6f13a4aSGreg Roach $top = 0; 1742a6f13a4aSGreg Roach } elseif ($attrs['top'] === '.') { 1743a6f13a4aSGreg Roach $top = '.'; 1744a6f13a4aSGreg Roach } elseif (!empty($attrs['top'])) { 1745a6f13a4aSGreg Roach $top = (int)$attrs['top']; 1746a6f13a4aSGreg Roach } 1747a6f13a4aSGreg Roach } 1748a6f13a4aSGreg Roach 1749a6f13a4aSGreg Roach // mixed Position the left corner of this box on the page. the default is the current position 1750a6f13a4aSGreg Roach $left = '.'; 1751a6f13a4aSGreg Roach if (isset($attrs['left'])) { 1752a6f13a4aSGreg Roach if ($attrs['left'] === '0') { 1753a6f13a4aSGreg Roach $left = 0; 1754a6f13a4aSGreg Roach } elseif ($attrs['left'] === '.') { 1755a6f13a4aSGreg Roach $left = '.'; 1756a6f13a4aSGreg Roach } elseif (!empty($attrs['left'])) { 1757a6f13a4aSGreg Roach $left = (int)$attrs['left']; 1758a6f13a4aSGreg Roach } 1759a6f13a4aSGreg Roach } 1760a6f13a4aSGreg Roach 1761a6f13a4aSGreg Roach // string Align the image in left, center, right 1762a6f13a4aSGreg Roach $align = ''; 1763a6f13a4aSGreg Roach if (!empty($attrs['align'])) { 1764a6f13a4aSGreg Roach $align = $attrs['align']; 1765a6f13a4aSGreg Roach } 1766a6f13a4aSGreg Roach 1767a6f13a4aSGreg Roach // string Next Line should be T:next to the image, N:next line 1768a6f13a4aSGreg Roach $ln = 'T'; 1769a6f13a4aSGreg Roach if (!empty($attrs['ln'])) { 1770a6f13a4aSGreg Roach $ln = $attrs['ln']; 1771a6f13a4aSGreg Roach } 1772a6f13a4aSGreg Roach 1773a6f13a4aSGreg Roach $width = 0; 1774a6f13a4aSGreg Roach $height = 0; 1775a6f13a4aSGreg Roach if (!empty($attrs['width'])) { 1776a6f13a4aSGreg Roach $width = (int)$attrs['width']; 1777a6f13a4aSGreg Roach } 1778a6f13a4aSGreg Roach if (!empty($attrs['height'])) { 1779a6f13a4aSGreg Roach $height = (int)$attrs['height']; 1780a6f13a4aSGreg Roach } 1781a6f13a4aSGreg Roach 1782a6f13a4aSGreg Roach $file = ''; 1783a6f13a4aSGreg Roach if (!empty($attrs['file'])) { 1784a6f13a4aSGreg Roach $file = $attrs['file']; 1785a6f13a4aSGreg Roach } 17867a6ee1acSGreg Roach if ($file == '@FILE') { 178713abd6f3SGreg Roach $match = []; 1788a6f13a4aSGreg Roach if (preg_match("/\d OBJE @(.+)@/", $this->gedrec, $match)) { 1789299d100dSGreg Roach $mediaobject = Media::getInstance($match[1], $this->tree); 17904a9f750fSGreg Roach $media_file = $mediaobject->firstImageFile(); 1791cdf416fbSGreg Roach 17924a9f750fSGreg Roach if ($media_file !== null && $media_file->fileExists()) { 1793c1010edaSGreg Roach $attributes = getimagesize($media_file->getServerFilename()) ?: [ 1794c1010edaSGreg Roach 0, 1795c1010edaSGreg Roach 0, 1796c1010edaSGreg Roach ]; 1797a6f13a4aSGreg Roach if ($width > 0 && $height == 0) { 17983c3b90deSGreg Roach $perc = $width / $attributes[0]; 17993c3b90deSGreg Roach $height = round($attributes[1] * $perc); 1800a6f13a4aSGreg Roach } elseif ($height > 0 && $width == 0) { 18013c3b90deSGreg Roach $perc = $height / $attributes[1]; 18023c3b90deSGreg Roach $width = round($attributes[0] * $perc); 1803a6f13a4aSGreg Roach } else { 18043c3b90deSGreg Roach $width = $attributes[0]; 18053c3b90deSGreg Roach $height = $attributes[1]; 1806a6f13a4aSGreg Roach } 18074a9f750fSGreg Roach $image = $this->report_root->createImageFromObject($media_file, $left, $top, $width, $height, $align, $ln); 1808e8e7866bSGreg Roach $this->wt_report->addElement($image); 1809a6f13a4aSGreg Roach } 1810a6f13a4aSGreg Roach } 1811a6f13a4aSGreg Roach } else { 18127a6ee1acSGreg Roach if (file_exists($file) && preg_match('/(jpg|jpeg|png|gif)$/i', $file)) { 1813a6f13a4aSGreg Roach $size = getimagesize($file); 1814a6f13a4aSGreg Roach if ($width > 0 && $height == 0) { 1815a6f13a4aSGreg Roach $perc = $width / $size[0]; 1816a6f13a4aSGreg Roach $height = round($size[1] * $perc); 1817a6f13a4aSGreg Roach } elseif ($height > 0 && $width == 0) { 1818a6f13a4aSGreg Roach $perc = $height / $size[1]; 1819a6f13a4aSGreg Roach $width = round($size[0] * $perc); 1820a6f13a4aSGreg Roach } else { 1821a6f13a4aSGreg Roach $width = $size[0]; 1822a6f13a4aSGreg Roach $height = $size[1]; 1823a6f13a4aSGreg Roach } 1824e8e7866bSGreg Roach $image = $this->report_root->createImage($file, $left, $top, $width, $height, $align, $ln); 1825e8e7866bSGreg Roach $this->wt_report->addElement($image); 1826a6f13a4aSGreg Roach } 1827a6f13a4aSGreg Roach } 1828a6f13a4aSGreg Roach } 1829a6f13a4aSGreg Roach 1830a6f13a4aSGreg Roach /** 1831a6f13a4aSGreg Roach * XML <Line> element handler 1832a6f13a4aSGreg Roach * 1833a6f13a4aSGreg Roach * @param array $attrs an array of key value pairs for the attributes 1834a6f13a4aSGreg Roach */ 1835c1010edaSGreg Roach private function lineStartHandler($attrs) 1836c1010edaSGreg Roach { 1837a6f13a4aSGreg Roach // Start horizontal position, current position (default) 18387a6ee1acSGreg Roach $x1 = '.'; 1839a6f13a4aSGreg Roach if (isset($attrs['x1'])) { 18407a6ee1acSGreg Roach if ($attrs['x1'] === '0') { 1841a6f13a4aSGreg Roach $x1 = 0; 18427a6ee1acSGreg Roach } elseif ($attrs['x1'] === '.') { 18437a6ee1acSGreg Roach $x1 = '.'; 1844a6f13a4aSGreg Roach } elseif (!empty($attrs['x1'])) { 1845a6f13a4aSGreg Roach $x1 = (int)$attrs['x1']; 1846a6f13a4aSGreg Roach } 1847a6f13a4aSGreg Roach } 1848a6f13a4aSGreg Roach // Start vertical position, current position (default) 18497a6ee1acSGreg Roach $y1 = '.'; 1850a6f13a4aSGreg Roach if (isset($attrs['y1'])) { 18517a6ee1acSGreg Roach if ($attrs['y1'] === '0') { 1852a6f13a4aSGreg Roach $y1 = 0; 18537a6ee1acSGreg Roach } elseif ($attrs['y1'] === '.') { 18547a6ee1acSGreg Roach $y1 = '.'; 1855a6f13a4aSGreg Roach } elseif (!empty($attrs['y1'])) { 1856a6f13a4aSGreg Roach $y1 = (int)$attrs['y1']; 1857a6f13a4aSGreg Roach } 1858a6f13a4aSGreg Roach } 1859a6f13a4aSGreg Roach // End horizontal position, maximum width (default) 18607a6ee1acSGreg Roach $x2 = '.'; 1861a6f13a4aSGreg Roach if (isset($attrs['x2'])) { 18627a6ee1acSGreg Roach if ($attrs['x2'] === '0') { 1863a6f13a4aSGreg Roach $x2 = 0; 18647a6ee1acSGreg Roach } elseif ($attrs['x2'] === '.') { 18657a6ee1acSGreg Roach $x2 = '.'; 1866a6f13a4aSGreg Roach } elseif (!empty($attrs['x2'])) { 1867a6f13a4aSGreg Roach $x2 = (int)$attrs['x2']; 1868a6f13a4aSGreg Roach } 1869a6f13a4aSGreg Roach } 1870a6f13a4aSGreg Roach // End vertical position 18717a6ee1acSGreg Roach $y2 = '.'; 1872a6f13a4aSGreg Roach if (isset($attrs['y2'])) { 18737a6ee1acSGreg Roach if ($attrs['y2'] === '0') { 1874a6f13a4aSGreg Roach $y2 = 0; 18757a6ee1acSGreg Roach } elseif ($attrs['y2'] === '.') { 18767a6ee1acSGreg Roach $y2 = '.'; 1877a6f13a4aSGreg Roach } elseif (!empty($attrs['y2'])) { 1878a6f13a4aSGreg Roach $y2 = (int)$attrs['y2']; 1879a6f13a4aSGreg Roach } 1880a6f13a4aSGreg Roach } 1881a6f13a4aSGreg Roach 1882e8e7866bSGreg Roach $line = $this->report_root->createLine($x1, $y1, $x2, $y2); 1883e8e7866bSGreg Roach $this->wt_report->addElement($line); 1884a6f13a4aSGreg Roach } 1885a6f13a4aSGreg Roach 1886a6f13a4aSGreg Roach /** 188776692c8bSGreg Roach * XML <List> 1888a6f13a4aSGreg Roach * 1889a6f13a4aSGreg Roach * @param array $attrs an array of key value pairs for the attributes 1890a6f13a4aSGreg Roach */ 1891c1010edaSGreg Roach private function listStartHandler($attrs) 1892c1010edaSGreg Roach { 1893a6f13a4aSGreg Roach $this->process_repeats++; 1894a6f13a4aSGreg Roach if ($this->process_repeats > 1) { 1895a6f13a4aSGreg Roach return; 1896a6f13a4aSGreg Roach } 1897a6f13a4aSGreg Roach 189813abd6f3SGreg Roach $match = []; 1899a6f13a4aSGreg Roach if (isset($attrs['sortby'])) { 1900a6f13a4aSGreg Roach $sortby = $attrs['sortby']; 1901a6f13a4aSGreg Roach if (preg_match("/\\$(\w+)/", $sortby, $match)) { 1902d1286247SGreg Roach $sortby = $this->vars[$match[1]]['id']; 1903a6f13a4aSGreg Roach $sortby = trim($sortby); 1904a6f13a4aSGreg Roach } 1905a6f13a4aSGreg Roach } else { 19067a6ee1acSGreg Roach $sortby = 'NAME'; 1907a6f13a4aSGreg Roach } 1908a6f13a4aSGreg Roach 1909a6f13a4aSGreg Roach if (isset($attrs['list'])) { 1910a6f13a4aSGreg Roach $listname = $attrs['list']; 1911a6f13a4aSGreg Roach } else { 19127a6ee1acSGreg Roach $listname = 'individual'; 1913a6f13a4aSGreg Roach } 1914a6f13a4aSGreg Roach // Some filters/sorts can be applied using SQL, while others require PHP 1915a6f13a4aSGreg Roach switch ($listname) { 19167a6ee1acSGreg Roach case 'pending': 1917a6f13a4aSGreg Roach $rows = Database::prepare( 19185d0bc43dSGreg Roach "SELECT xref, CASE new_gedcom WHEN '' THEN old_gedcom ELSE new_gedcom END AS gedcom" . 19195d0bc43dSGreg Roach " FROM `##change`" . " WHERE (xref, change_id) IN (" . 19205d0bc43dSGreg Roach " SELECT xref, MAX(change_id)" . 19215d0bc43dSGreg Roach " FROM `##change`" . 19225d0bc43dSGreg Roach " WHERE status = 'pending' AND gedcom_id = :tree_id" . 19235d0bc43dSGreg Roach " GROUP BY xref" . 19245d0bc43dSGreg Roach " )" 192513abd6f3SGreg Roach )->execute([ 1926299d100dSGreg Roach 'tree_id' => $this->tree->getTreeId(), 192713abd6f3SGreg Roach ])->fetchAll(); 192813abd6f3SGreg Roach $this->list = []; 1929a6f13a4aSGreg Roach foreach ($rows as $row) { 1930299d100dSGreg Roach $this->list[] = GedcomRecord::getInstance($row->xref, $this->tree, $row->gedcom); 1931a6f13a4aSGreg Roach } 1932a6f13a4aSGreg Roach break; 1933a6f13a4aSGreg Roach case 'individual': 193476156db1SGreg Roach $sql_select = "SELECT i_id AS xref, i_gedcom AS gedcom FROM `##individuals` "; 1935a6f13a4aSGreg Roach $sql_join = ""; 1936825006d2SGreg Roach $sql_where = " WHERE i_file = :tree_id"; 1937a6f13a4aSGreg Roach $sql_order_by = ""; 1938299d100dSGreg Roach $sql_params = ['tree_id' => $this->tree->getTreeId()]; 1939a6f13a4aSGreg Roach foreach ($attrs as $attr => $value) { 1940a6f13a4aSGreg Roach if (strpos($attr, 'filter') === 0 && $value) { 194182759250SGreg Roach $value = $this->substituteVars($value, false); 1942a6f13a4aSGreg Roach // Convert the various filters into SQL 1943a6f13a4aSGreg Roach if (preg_match('/^(\w+):DATE (LTE|GTE) (.+)$/', $value, $match)) { 1944a6f13a4aSGreg Roach $sql_join .= " JOIN `##dates` AS {$attr} ON ({$attr}.d_file=i_file AND {$attr}.d_gid=i_id)"; 1945b0d2e743SGreg Roach $sql_where .= " AND {$attr}.d_fact = :{$attr}fact"; 19465d0bc43dSGreg Roach $sql_params[$attr . 'fact'] = $match[1]; 1947a6f13a4aSGreg Roach $date = new Date($match[3]); 19487a6ee1acSGreg Roach if ($match[2] == 'LTE') { 19495d0bc43dSGreg Roach $sql_where .= " AND {$attr}.d_julianday2 <= :{$attr}date"; 19505d0bc43dSGreg Roach $sql_params[$attr . 'date'] = $date->maximumJulianDay(); 1951a6f13a4aSGreg Roach } else { 19525d0bc43dSGreg Roach $sql_where .= " AND {$attr}.d_julianday1 >= :{$attr}date"; 19535d0bc43dSGreg Roach $sql_params[$attr . 'date'] = $date->minimumJulianDay(); 1954a6f13a4aSGreg Roach } 1955a6f13a4aSGreg Roach if ($sortby == $match[1]) { 1956a6f13a4aSGreg Roach $sortby = ""; 1957a6f13a4aSGreg Roach $sql_order_by .= ($sql_order_by ? ", " : " ORDER BY ") . "{$attr}.d_julianday1"; 1958a6f13a4aSGreg Roach } 1959a6f13a4aSGreg Roach unset($attrs[$attr]); // This filter has been fully processed 1960a6f13a4aSGreg Roach } elseif (preg_match('/^NAME CONTAINS (.*)$/', $value, $match)) { 1961a6f13a4aSGreg Roach // Do nothing, unless you have to 1962a6f13a4aSGreg Roach if ($match[1] != '' || $sortby == 'NAME') { 1963a6f13a4aSGreg Roach $sql_join .= " JOIN `##name` AS {$attr} ON (n_file=i_file AND n_id=i_id)"; 1964a6f13a4aSGreg Roach // Search the DB only if there is any name supplied 19657a6ee1acSGreg Roach if ($match[1] != '') { 19667a6ee1acSGreg Roach $names = explode(' ', $match[1]); 19675d0bc43dSGreg Roach foreach ($names as $n => $name) { 19685d0bc43dSGreg Roach $sql_where .= " AND {$attr}.n_full LIKE CONCAT('%', :{$attr}name{$n}, '%')"; 19695d0bc43dSGreg Roach $sql_params[$attr . 'name' . $n] = $name; 1970a6f13a4aSGreg Roach } 1971a6f13a4aSGreg Roach } 1972a6f13a4aSGreg Roach // Let the DB do the name sorting even when no name was entered 19737a6ee1acSGreg Roach if ($sortby == 'NAME') { 19747a6ee1acSGreg Roach $sortby = ''; 19757a6ee1acSGreg Roach $sql_order_by .= ($sql_order_by ? ', ' : ' ORDER BY ') . "{$attr}.n_sort"; 1976a6f13a4aSGreg Roach } 1977a6f13a4aSGreg Roach } 1978a6f13a4aSGreg Roach unset($attrs[$attr]); // This filter has been fully processed 1979a6f13a4aSGreg Roach } elseif (preg_match('/^REGEXP \/(.+)\//', $value, $match)) { 19805d0bc43dSGreg Roach $sql_where .= " AND i_gedcom REGEXP :{$attr}gedcom"; 1981b4e512fdSGreg Roach // PDO helpfully escapes backslashes for us, preventing us from matching "\n1 FACT" 1982b4e512fdSGreg Roach $sql_params[$attr . 'gedcom'] = str_replace('\n', "\n", $match[1]); 1983a6f13a4aSGreg Roach unset($attrs[$attr]); // This filter has been fully processed 1984a6f13a4aSGreg Roach } elseif (preg_match('/^(?:\w+):PLAC CONTAINS (.+)$/', $value, $match)) { 1985a6f13a4aSGreg Roach $sql_join .= " JOIN `##places` AS {$attr}a ON ({$attr}a.p_file = i_file)"; 1986a6f13a4aSGreg Roach $sql_join .= " JOIN `##placelinks` AS {$attr}b ON ({$attr}a.p_file = {$attr}b.pl_file AND {$attr}b.pl_p_id = {$attr}a.p_id AND {$attr}b.pl_gid = i_id)"; 19875d0bc43dSGreg Roach $sql_where .= " AND {$attr}a.p_place LIKE CONCAT('%', :{$attr}place, '%')"; 19885d0bc43dSGreg Roach $sql_params[$attr . 'place'] = $match[1]; 1989a6f13a4aSGreg Roach // Don't unset this filter. This is just initial filtering 1990a6f13a4aSGreg Roach } elseif (preg_match('/^(\w*):*(\w*) CONTAINS (.+)$/', $value, $match)) { 19915d0bc43dSGreg Roach $sql_where .= " AND i_gedcom LIKE CONCAT('%', :{$attr}contains1, '%', :{$attr}contains2, '%', :{$attr}contains3, '%')"; 19925d0bc43dSGreg Roach $sql_params[$attr . 'contains1'] = $match[1]; 19935d0bc43dSGreg Roach $sql_params[$attr . 'contains2'] = $match[2]; 19945d0bc43dSGreg Roach $sql_params[$attr . 'contains3'] = $match[3]; 1995a6f13a4aSGreg Roach // Don't unset this filter. This is just initial filtering 1996a6f13a4aSGreg Roach } 1997a6f13a4aSGreg Roach } 1998a6f13a4aSGreg Roach } 1999a6f13a4aSGreg Roach 200013abd6f3SGreg Roach $this->list = []; 2001a6f13a4aSGreg Roach $rows = Database::prepare( 2002a6f13a4aSGreg Roach $sql_select . $sql_join . $sql_where . $sql_order_by 20035d0bc43dSGreg Roach )->execute($sql_params)->fetchAll(); 2004a6f13a4aSGreg Roach 2005a6f13a4aSGreg Roach foreach ($rows as $row) { 2006299d100dSGreg Roach $this->list[$row->xref] = Individual::getInstance($row->xref, $this->tree, $row->gedcom); 2007a6f13a4aSGreg Roach } 2008a6f13a4aSGreg Roach break; 2009a6f13a4aSGreg Roach 2010a6f13a4aSGreg Roach case 'family': 201176156db1SGreg Roach $sql_select = "SELECT f_id AS xref, f_gedcom AS gedcom FROM `##families`"; 2012a6f13a4aSGreg Roach $sql_join = ""; 2013825006d2SGreg Roach $sql_where = " WHERE f_file = :tree_id"; 2014a6f13a4aSGreg Roach $sql_order_by = ""; 2015299d100dSGreg Roach $sql_params = ['tree_id' => $this->tree->getTreeId()]; 2016a6f13a4aSGreg Roach foreach ($attrs as $attr => $value) { 2017a6f13a4aSGreg Roach if (strpos($attr, 'filter') === 0 && $value) { 201882759250SGreg Roach $value = $this->substituteVars($value, false); 2019a6f13a4aSGreg Roach // Convert the various filters into SQL 2020a6f13a4aSGreg Roach if (preg_match('/^(\w+):DATE (LTE|GTE) (.+)$/', $value, $match)) { 2021a9eb55f8SGreg Roach $sql_join .= " JOIN `##dates` AS {$attr} ON ({$attr}.d_file=f_file AND {$attr}.d_gid=f_id)"; 2022b0d2e743SGreg Roach $sql_where .= " AND {$attr}.d_fact = :{$attr}fact"; 20235d0bc43dSGreg Roach $sql_params[$attr . 'fact'] = $match[1]; 2024a6f13a4aSGreg Roach $date = new Date($match[3]); 20257a6ee1acSGreg Roach if ($match[2] == 'LTE') { 20265d0bc43dSGreg Roach $sql_where .= " AND {$attr}.d_julianday2 <= :{$attr}date"; 20275d0bc43dSGreg Roach $sql_params[$attr . 'date'] = $date->maximumJulianDay(); 2028a6f13a4aSGreg Roach } else { 20295d0bc43dSGreg Roach $sql_where .= " AND {$attr}.d_julianday1 >= :{$attr}date"; 20305d0bc43dSGreg Roach $sql_params[$attr . 'date'] = $date->minimumJulianDay(); 2031a6f13a4aSGreg Roach } 2032a6f13a4aSGreg Roach if ($sortby == $match[1]) { 20337a6ee1acSGreg Roach $sortby = ''; 20347a6ee1acSGreg Roach $sql_order_by .= ($sql_order_by ? ', ' : ' ORDER BY ') . "{$attr}.d_julianday1"; 2035a6f13a4aSGreg Roach } 2036a6f13a4aSGreg Roach unset($attrs[$attr]); // This filter has been fully processed 2037a6f13a4aSGreg Roach } elseif (preg_match('/^REGEXP \/(.+)\//', $value, $match)) { 20385d0bc43dSGreg Roach $sql_where .= " AND f_gedcom REGEXP :{$attr}gedcom"; 2039b4e512fdSGreg Roach // PDO helpfully escapes backslashes for us, preventing us from matching "\n1 FACT" 2040b4e512fdSGreg Roach $sql_params[$attr . 'gedcom'] = str_replace('\n', "\n", $match[1]); 2041a6f13a4aSGreg Roach unset($attrs[$attr]); // This filter has been fully processed 2042a6f13a4aSGreg Roach } elseif (preg_match('/^NAME CONTAINS (.+)$/', $value, $match)) { 20435d0bc43dSGreg Roach // Do nothing, unless you have to 20445d0bc43dSGreg Roach if ($match[1] != '' || $sortby == 'NAME') { 20455d0bc43dSGreg Roach $sql_join .= " JOIN `##name` AS {$attr} ON n_file = f_file AND n_id IN (f_husb, f_wife)"; 20465d0bc43dSGreg Roach // Search the DB only if there is any name supplied 20477a6ee1acSGreg Roach if ($match[1] != '') { 20487a6ee1acSGreg Roach $names = explode(' ', $match[1]); 20495d0bc43dSGreg Roach foreach ($names as $n => $name) { 20505d0bc43dSGreg Roach $sql_where .= " AND {$attr}.n_full LIKE CONCAT('%', :{$attr}name{$n}, '%')"; 20515d0bc43dSGreg Roach $sql_params[$attr . 'name' . $n] = $name; 20525d0bc43dSGreg Roach } 20535d0bc43dSGreg Roach } 20545d0bc43dSGreg Roach // Let the DB do the name sorting even when no name was entered 20557a6ee1acSGreg Roach if ($sortby == 'NAME') { 20567a6ee1acSGreg Roach $sortby = ''; 20577a6ee1acSGreg Roach $sql_order_by .= ($sql_order_by ? ', ' : ' ORDER BY ') . "{$attr}.n_sort"; 2058a6f13a4aSGreg Roach } 20595d0bc43dSGreg Roach } 2060a6f13a4aSGreg Roach unset($attrs[$attr]); // This filter has been fully processed 2061a6f13a4aSGreg Roach } elseif (preg_match('/^(?:\w+):PLAC CONTAINS (.+)$/', $value, $match)) { 2062a6f13a4aSGreg Roach $sql_join .= " JOIN `##places` AS {$attr}a ON ({$attr}a.p_file=f_file)"; 2063a6f13a4aSGreg Roach $sql_join .= " JOIN `##placelinks` AS {$attr}b ON ({$attr}a.p_file={$attr}b.pl_file AND {$attr}b.pl_p_id={$attr}a.p_id AND {$attr}b.pl_gid=f_id)"; 20645d0bc43dSGreg Roach $sql_where .= " AND {$attr}a.p_place LIKE CONCAT('%', :{$attr}place, '%')"; 20655d0bc43dSGreg Roach $sql_params[$attr . 'place'] = $match[1]; 2066a6f13a4aSGreg Roach // Don't unset this filter. This is just initial filtering 2067a6f13a4aSGreg Roach } elseif (preg_match('/^(\w*):*(\w*) CONTAINS (.+)$/', $value, $match)) { 20685d0bc43dSGreg Roach $sql_where .= " AND f_gedcom LIKE CONCAT('%', :{$attr}contains1, '%', :{$attr}contains2, '%', :{$attr}contains3, '%')"; 20695d0bc43dSGreg Roach $sql_params[$attr . 'contains1'] = $match[1]; 20705d0bc43dSGreg Roach $sql_params[$attr . 'contains2'] = $match[2]; 20715d0bc43dSGreg Roach $sql_params[$attr . 'contains3'] = $match[3]; 2072a6f13a4aSGreg Roach // Don't unset this filter. This is just initial filtering 2073a6f13a4aSGreg Roach } 2074a6f13a4aSGreg Roach } 2075a6f13a4aSGreg Roach } 2076a6f13a4aSGreg Roach 207713abd6f3SGreg Roach $this->list = []; 2078a6f13a4aSGreg Roach $rows = Database::prepare( 2079a6f13a4aSGreg Roach $sql_select . $sql_join . $sql_where . $sql_order_by 20805d0bc43dSGreg Roach )->execute($sql_params)->fetchAll(); 2081a6f13a4aSGreg Roach 2082a6f13a4aSGreg Roach foreach ($rows as $row) { 2083299d100dSGreg Roach $this->list[$row->xref] = Family::getInstance($row->xref, $this->tree, $row->gedcom); 2084a6f13a4aSGreg Roach } 2085a6f13a4aSGreg Roach break; 2086a6f13a4aSGreg Roach 2087a6f13a4aSGreg Roach default: 2088a6f13a4aSGreg Roach throw new \DomainException('Invalid list name: ' . $listname); 2089a6f13a4aSGreg Roach } 2090a6f13a4aSGreg Roach 209113abd6f3SGreg Roach $filters = []; 209213abd6f3SGreg Roach $filters2 = []; 2093a6f13a4aSGreg Roach if (isset($attrs['filter1']) && count($this->list) > 0) { 2094a6f13a4aSGreg Roach foreach ($attrs as $key => $value) { 2095a6f13a4aSGreg Roach if (preg_match("/filter(\d)/", $key)) { 2096a6f13a4aSGreg Roach $condition = $value; 2097a6f13a4aSGreg Roach if (preg_match("/@(\w+)/", $condition, $match)) { 2098a6f13a4aSGreg Roach $id = $match[1]; 2099a6f13a4aSGreg Roach $value = "''"; 21007a6ee1acSGreg Roach if ($id == 'ID') { 21017a6ee1acSGreg Roach if (preg_match('/0 @(.+)@/', $this->gedrec, $match)) { 2102a6f13a4aSGreg Roach $value = "'" . $match[1] . "'"; 2103a6f13a4aSGreg Roach } 21047a6ee1acSGreg Roach } elseif ($id == 'fact') { 2105a6f13a4aSGreg Roach $value = "'" . $this->fact . "'"; 21067a6ee1acSGreg Roach } elseif ($id == 'desc') { 2107a6f13a4aSGreg Roach $value = "'" . $this->desc . "'"; 2108a6f13a4aSGreg Roach } else { 2109a6f13a4aSGreg Roach if (preg_match("/\d $id (.+)/", $this->gedrec, $match)) { 21107a6ee1acSGreg Roach $value = "'" . str_replace('@', '', trim($match[1])) . "'"; 2111a6f13a4aSGreg Roach } 2112a6f13a4aSGreg Roach } 2113a6f13a4aSGreg Roach $condition = preg_replace("/@$id/", $value, $condition); 2114a6f13a4aSGreg Roach } 2115a6f13a4aSGreg Roach //-- handle regular expressions 2116a6f13a4aSGreg Roach if (preg_match("/([A-Z:]+)\s*([^\s]+)\s*(.+)/", $condition, $match)) { 2117a6f13a4aSGreg Roach $tag = trim($match[1]); 2118a6f13a4aSGreg Roach $expr = trim($match[2]); 2119a6f13a4aSGreg Roach $val = trim($match[3]); 2120a6f13a4aSGreg Roach if (preg_match("/\\$(\w+)/", $val, $match)) { 2121d1286247SGreg Roach $val = $this->vars[$match[1]]['id']; 2122a6f13a4aSGreg Roach $val = trim($val); 2123a6f13a4aSGreg Roach } 2124a6f13a4aSGreg Roach if ($val) { 21257a6ee1acSGreg Roach $searchstr = ''; 21267a6ee1acSGreg Roach $tags = explode(':', $tag); 2127a6f13a4aSGreg Roach //-- only limit to a level number if we are specifically looking at a level 2128a6f13a4aSGreg Roach if (count($tags) > 1) { 2129a6f13a4aSGreg Roach $level = 1; 2130a6f13a4aSGreg Roach foreach ($tags as $t) { 2131a6f13a4aSGreg Roach if (!empty($searchstr)) { 2132a6f13a4aSGreg Roach $searchstr .= "[^\n]*(\n[2-9][^\n]*)*\n"; 2133a6f13a4aSGreg Roach } 2134a6f13a4aSGreg Roach //-- search for both EMAIL and _EMAIL... silly double gedcom standard 21357a6ee1acSGreg Roach if ($t == 'EMAIL' || $t == '_EMAIL') { 21367a6ee1acSGreg Roach $t = '_?EMAIL'; 2137a6f13a4aSGreg Roach } 21387a6ee1acSGreg Roach $searchstr .= $level . ' ' . $t; 2139a6f13a4aSGreg Roach $level++; 2140a6f13a4aSGreg Roach } 2141a6f13a4aSGreg Roach } else { 21427a6ee1acSGreg Roach if ($tag == 'EMAIL' || $tag == '_EMAIL') { 21437a6ee1acSGreg Roach $tag = '_?EMAIL'; 2144a6f13a4aSGreg Roach } 2145a6f13a4aSGreg Roach $t = $tag; 21467a6ee1acSGreg Roach $searchstr = '1 ' . $tag; 2147a6f13a4aSGreg Roach } 2148a6f13a4aSGreg Roach switch ($expr) { 21497a6ee1acSGreg Roach case 'CONTAINS': 21507a6ee1acSGreg Roach if ($t == 'PLAC') { 2151a6f13a4aSGreg Roach $searchstr .= "[^\n]*[, ]*" . $val; 2152a6f13a4aSGreg Roach } else { 2153a6f13a4aSGreg Roach $searchstr .= "[^\n]*" . $val; 2154a6f13a4aSGreg Roach } 2155a6f13a4aSGreg Roach $filters[] = $searchstr; 2156a6f13a4aSGreg Roach break; 2157a6f13a4aSGreg Roach default: 2158c1010edaSGreg Roach $filters2[] = [ 2159c1010edaSGreg Roach 'tag' => $tag, 2160c1010edaSGreg Roach 'expr' => $expr, 2161c1010edaSGreg Roach 'val' => $val, 2162c1010edaSGreg Roach ]; 2163a6f13a4aSGreg Roach break; 2164a6f13a4aSGreg Roach } 2165a6f13a4aSGreg Roach } 2166a6f13a4aSGreg Roach } 2167a6f13a4aSGreg Roach } 2168a6f13a4aSGreg Roach } 2169a6f13a4aSGreg Roach } 2170a6f13a4aSGreg Roach //-- apply other filters to the list that could not be added to the search string 2171a6f13a4aSGreg Roach if ($filters) { 2172a6f13a4aSGreg Roach foreach ($this->list as $key => $record) { 2173a6f13a4aSGreg Roach foreach ($filters as $filter) { 2174299d100dSGreg Roach if (!preg_match('/' . $filter . '/i', $record->privatizeGedcom(Auth::accessLevel($this->tree)))) { 2175a6f13a4aSGreg Roach unset($this->list[$key]); 2176a6f13a4aSGreg Roach break; 2177a6f13a4aSGreg Roach } 2178a6f13a4aSGreg Roach } 2179a6f13a4aSGreg Roach } 2180a6f13a4aSGreg Roach } 2181a6f13a4aSGreg Roach if ($filters2) { 218213abd6f3SGreg Roach $mylist = []; 2183a6f13a4aSGreg Roach foreach ($this->list as $indi) { 2184a6f13a4aSGreg Roach $key = $indi->getXref(); 2185299d100dSGreg Roach $grec = $indi->privatizeGedcom(Auth::accessLevel($this->tree)); 2186a6f13a4aSGreg Roach $keep = true; 2187a6f13a4aSGreg Roach foreach ($filters2 as $filter) { 2188a6f13a4aSGreg Roach if ($keep) { 2189a6f13a4aSGreg Roach $tag = $filter['tag']; 2190a6f13a4aSGreg Roach $expr = $filter['expr']; 2191a6f13a4aSGreg Roach $val = $filter['val']; 2192a6f13a4aSGreg Roach if ($val == "''") { 21937a6ee1acSGreg Roach $val = ''; 2194a6f13a4aSGreg Roach } 21957a6ee1acSGreg Roach $tags = explode(':', $tag); 2196a6f13a4aSGreg Roach $t = end($tags); 21973d7a8a4cSGreg Roach $v = $this->getGedcomValue($tag, 1, $grec); 2198a6f13a4aSGreg Roach //-- check for EMAIL and _EMAIL (silly double gedcom standard :P) 21997a6ee1acSGreg Roach if ($t == 'EMAIL' && empty($v)) { 22007a6ee1acSGreg Roach $tag = str_replace('EMAIL', '_EMAIL', $tag); 22017a6ee1acSGreg Roach $tags = explode(':', $tag); 2202a6f13a4aSGreg Roach $t = end($tags); 22033d7a8a4cSGreg Roach $v = Functions::getSubRecord(1, $tag, $grec); 2204a6f13a4aSGreg Roach } 2205a6f13a4aSGreg Roach 2206a6f13a4aSGreg Roach switch ($expr) { 22077a6ee1acSGreg Roach case 'GTE': 22087a6ee1acSGreg Roach if ($t == 'DATE') { 2209a6f13a4aSGreg Roach $date1 = new Date($v); 2210a6f13a4aSGreg Roach $date2 = new Date($val); 2211a6f13a4aSGreg Roach $keep = (Date::compare($date1, $date2) >= 0); 2212a6f13a4aSGreg Roach } elseif ($val >= $v) { 2213a6f13a4aSGreg Roach $keep = true; 2214a6f13a4aSGreg Roach } 2215a6f13a4aSGreg Roach break; 22167a6ee1acSGreg Roach case 'LTE': 22177a6ee1acSGreg Roach if ($t == 'DATE') { 2218a6f13a4aSGreg Roach $date1 = new Date($v); 2219a6f13a4aSGreg Roach $date2 = new Date($val); 2220a6f13a4aSGreg Roach $keep = (Date::compare($date1, $date2) <= 0); 2221a6f13a4aSGreg Roach } elseif ($val >= $v) { 2222a6f13a4aSGreg Roach $keep = true; 2223a6f13a4aSGreg Roach } 2224a6f13a4aSGreg Roach break; 2225a6f13a4aSGreg Roach default: 2226a6f13a4aSGreg Roach if ($v == $val) { 2227a6f13a4aSGreg Roach $keep = true; 2228a6f13a4aSGreg Roach } else { 2229a6f13a4aSGreg Roach $keep = false; 2230a6f13a4aSGreg Roach } 2231a6f13a4aSGreg Roach break; 2232a6f13a4aSGreg Roach } 2233a6f13a4aSGreg Roach } 2234a6f13a4aSGreg Roach } 2235a6f13a4aSGreg Roach if ($keep) { 2236a6f13a4aSGreg Roach $mylist[$key] = $indi; 2237a6f13a4aSGreg Roach } 2238a6f13a4aSGreg Roach } 2239a6f13a4aSGreg Roach $this->list = $mylist; 2240a6f13a4aSGreg Roach } 2241a6f13a4aSGreg Roach 2242a6f13a4aSGreg Roach switch ($sortby) { 2243a6f13a4aSGreg Roach case 'NAME': 2244a6f13a4aSGreg Roach uasort($this->list, '\Fisharebest\Webtrees\GedcomRecord::compare'); 2245a6f13a4aSGreg Roach break; 2246a6f13a4aSGreg Roach case 'CHAN': 2247a6f13a4aSGreg Roach uasort($this->list, function (GedcomRecord $x, GedcomRecord $y) { 2248a6f13a4aSGreg Roach return $y->lastChangeTimestamp(true) - $x->lastChangeTimestamp(true); 2249a6f13a4aSGreg Roach }); 2250a6f13a4aSGreg Roach break; 2251a6f13a4aSGreg Roach case 'BIRT:DATE': 2252a6f13a4aSGreg Roach uasort($this->list, '\Fisharebest\Webtrees\Individual::compareBirthDate'); 2253a6f13a4aSGreg Roach break; 2254a6f13a4aSGreg Roach case 'DEAT:DATE': 2255a6f13a4aSGreg Roach uasort($this->list, '\Fisharebest\Webtrees\Individual::compareDeathDate'); 2256a6f13a4aSGreg Roach break; 2257a6f13a4aSGreg Roach case 'MARR:DATE': 22585d0bc43dSGreg Roach uasort($this->list, '\Fisharebest\Webtrees\Family::compareMarrDate'); 2259a6f13a4aSGreg Roach break; 2260a6f13a4aSGreg Roach default: 2261a6f13a4aSGreg Roach // unsorted or already sorted by SQL 2262a6f13a4aSGreg Roach break; 2263a6f13a4aSGreg Roach } 2264a6f13a4aSGreg Roach 2265c1010edaSGreg Roach array_push($this->repeats_stack, [ 2266c1010edaSGreg Roach $this->repeats, 2267c1010edaSGreg Roach $this->repeat_bytes, 2268c1010edaSGreg Roach ]); 2269e8e7866bSGreg Roach $this->repeat_bytes = xml_get_current_line_number($this->parser) + 1; 2270a6f13a4aSGreg Roach } 2271a6f13a4aSGreg Roach 2272a6f13a4aSGreg Roach /** 227376692c8bSGreg Roach * XML <List> 2274a6f13a4aSGreg Roach */ 2275c1010edaSGreg Roach private function listEndHandler() 2276c1010edaSGreg Roach { 2277a6f13a4aSGreg Roach $this->process_repeats--; 2278a6f13a4aSGreg Roach if ($this->process_repeats > 0) { 2279a6f13a4aSGreg Roach return; 2280a6f13a4aSGreg Roach } 2281a6f13a4aSGreg Roach 2282a6f13a4aSGreg Roach // Check if there is any list 2283a6f13a4aSGreg Roach if (count($this->list) > 0) { 2284a6f13a4aSGreg Roach $lineoffset = 0; 2285a6f13a4aSGreg Roach foreach ($this->repeats_stack as $rep) { 2286a6f13a4aSGreg Roach $lineoffset += $rep[1]; 2287a6f13a4aSGreg Roach } 2288a6f13a4aSGreg Roach //-- read the xml from the file 2289299d100dSGreg Roach $lines = file($this->report); 22907a6ee1acSGreg Roach while ((strpos($lines[$lineoffset + $this->repeat_bytes], '<List') === false) && (($lineoffset + $this->repeat_bytes) > 0)) { 2291a6f13a4aSGreg Roach $lineoffset--; 2292a6f13a4aSGreg Roach } 2293a6f13a4aSGreg Roach $lineoffset++; 2294a6f13a4aSGreg Roach $reportxml = "<tempdoc>\n"; 2295a6f13a4aSGreg Roach $line_nr = $lineoffset + $this->repeat_bytes; 2296a6f13a4aSGreg Roach // List Level counter 2297a6f13a4aSGreg Roach $count = 1; 2298a6f13a4aSGreg Roach while (0 < $count) { 22997a6ee1acSGreg Roach if (strpos($lines[$line_nr], '<List') !== false) { 2300a6f13a4aSGreg Roach $count++; 23017a6ee1acSGreg Roach } elseif (strpos($lines[$line_nr], '</List') !== false) { 2302a6f13a4aSGreg Roach $count--; 2303a6f13a4aSGreg Roach } 2304a6f13a4aSGreg Roach if (0 < $count) { 2305a6f13a4aSGreg Roach $reportxml .= $lines[$line_nr]; 2306a6f13a4aSGreg Roach } 2307a6f13a4aSGreg Roach $line_nr++; 2308a6f13a4aSGreg Roach } 2309a6f13a4aSGreg Roach // No need to drag this 2310a6f13a4aSGreg Roach unset($lines); 23117a6ee1acSGreg Roach $reportxml .= '</tempdoc>'; 2312a6f13a4aSGreg Roach // Save original values 2313e8e7866bSGreg Roach array_push($this->parser_stack, $this->parser); 2314a6f13a4aSGreg Roach $oldgedrec = $this->gedrec; 2315a6f13a4aSGreg Roach 2316a6f13a4aSGreg Roach $this->list_total = count($this->list); 2317a6f13a4aSGreg Roach $this->list_private = 0; 2318a6f13a4aSGreg Roach foreach ($this->list as $record) { 2319a6f13a4aSGreg Roach if ($record->canShow()) { 2320a6f13a4aSGreg Roach $this->gedrec = $record->privatizeGedcom(Auth::accessLevel($record->getTree())); 2321a6f13a4aSGreg Roach //-- start the sax parser 2322a6f13a4aSGreg Roach $repeat_parser = xml_parser_create(); 2323e8e7866bSGreg Roach $this->parser = $repeat_parser; 2324a6f13a4aSGreg Roach xml_parser_set_option($repeat_parser, XML_OPTION_CASE_FOLDING, false); 2325c1010edaSGreg Roach xml_set_element_handler($repeat_parser, [ 2326c1010edaSGreg Roach $this, 2327c1010edaSGreg Roach 'startElement', 2328c1010edaSGreg Roach ], [ 2329c1010edaSGreg Roach $this, 2330c1010edaSGreg Roach 'endElement', 2331c1010edaSGreg Roach ]); 2332c1010edaSGreg Roach xml_set_character_data_handler($repeat_parser, [ 2333c1010edaSGreg Roach $this, 2334c1010edaSGreg Roach 'characterData', 2335c1010edaSGreg Roach ]); 2336a6f13a4aSGreg Roach if (!xml_parse($repeat_parser, $reportxml, true)) { 2337a6f13a4aSGreg Roach throw new \DomainException(sprintf( 2338a6f13a4aSGreg Roach 'ListEHandler XML error: %s at line %d', 2339a6f13a4aSGreg Roach xml_error_string(xml_get_error_code($repeat_parser)), 2340a6f13a4aSGreg Roach xml_get_current_line_number($repeat_parser) 2341a6f13a4aSGreg Roach )); 2342a6f13a4aSGreg Roach } 2343a6f13a4aSGreg Roach xml_parser_free($repeat_parser); 2344a6f13a4aSGreg Roach } else { 2345a6f13a4aSGreg Roach $this->list_private++; 2346a6f13a4aSGreg Roach } 2347a6f13a4aSGreg Roach } 234813abd6f3SGreg Roach $this->list = []; 2349e8e7866bSGreg Roach $this->parser = array_pop($this->parser_stack); 2350a6f13a4aSGreg Roach $this->gedrec = $oldgedrec; 2351a6f13a4aSGreg Roach } 2352a6f13a4aSGreg Roach list($this->repeats, $this->repeat_bytes) = array_pop($this->repeats_stack); 2353a6f13a4aSGreg Roach } 2354a6f13a4aSGreg Roach 2355a6f13a4aSGreg Roach /** 2356a6f13a4aSGreg Roach * XML <ListTotal> element handler 2357a6f13a4aSGreg Roach * 2358a6f13a4aSGreg Roach * Prints the total number of records in a list 2359a6f13a4aSGreg Roach * The total number is collected from 2360a6f13a4aSGreg Roach * List and Relatives 2361a6f13a4aSGreg Roach */ 2362c1010edaSGreg Roach private function listTotalStartHandler() 2363c1010edaSGreg Roach { 2364a6f13a4aSGreg Roach if ($this->list_private == 0) { 2365a6f13a4aSGreg Roach $this->current_element->addText($this->list_total); 2366a6f13a4aSGreg Roach } else { 23677a6ee1acSGreg Roach $this->current_element->addText(($this->list_total - $this->list_private) . ' / ' . $this->list_total); 2368a6f13a4aSGreg Roach } 2369a6f13a4aSGreg Roach } 2370a6f13a4aSGreg Roach 2371a6f13a4aSGreg Roach /** 237276692c8bSGreg Roach * XML <Relatives> 237376692c8bSGreg Roach * 2374a6f13a4aSGreg Roach * @param array $attrs an array of key value pairs for the attributes 2375a6f13a4aSGreg Roach */ 2376c1010edaSGreg Roach private function relativesStartHandler($attrs) 2377c1010edaSGreg Roach { 2378a6f13a4aSGreg Roach $this->process_repeats++; 2379a6f13a4aSGreg Roach if ($this->process_repeats > 1) { 2380a6f13a4aSGreg Roach return; 2381a6f13a4aSGreg Roach } 2382a6f13a4aSGreg Roach 23837a6ee1acSGreg Roach $sortby = 'NAME'; 2384a6f13a4aSGreg Roach if (isset($attrs['sortby'])) { 2385a6f13a4aSGreg Roach $sortby = $attrs['sortby']; 2386a6f13a4aSGreg Roach } 238713abd6f3SGreg Roach $match = []; 2388a6f13a4aSGreg Roach if (preg_match("/\\$(\w+)/", $sortby, $match)) { 2389d1286247SGreg Roach $sortby = $this->vars[$match[1]]['id']; 2390a6f13a4aSGreg Roach $sortby = trim($sortby); 2391a6f13a4aSGreg Roach } 2392a6f13a4aSGreg Roach 2393a6f13a4aSGreg Roach $maxgen = -1; 2394a6f13a4aSGreg Roach if (isset($attrs['maxgen'])) { 2395a6f13a4aSGreg Roach $maxgen = $attrs['maxgen']; 2396a6f13a4aSGreg Roach } 23977a6ee1acSGreg Roach if ($maxgen == '*') { 2398a6f13a4aSGreg Roach $maxgen = -1; 2399a6f13a4aSGreg Roach } 2400a6f13a4aSGreg Roach 24017a6ee1acSGreg Roach $group = 'child-family'; 2402a6f13a4aSGreg Roach if (isset($attrs['group'])) { 2403a6f13a4aSGreg Roach $group = $attrs['group']; 2404a6f13a4aSGreg Roach } 2405a6f13a4aSGreg Roach if (preg_match("/\\$(\w+)/", $group, $match)) { 2406d1286247SGreg Roach $group = $this->vars[$match[1]]['id']; 2407a6f13a4aSGreg Roach $group = trim($group); 2408a6f13a4aSGreg Roach } 2409a6f13a4aSGreg Roach 24107a6ee1acSGreg Roach $id = ''; 2411a6f13a4aSGreg Roach if (isset($attrs['id'])) { 2412a6f13a4aSGreg Roach $id = $attrs['id']; 2413a6f13a4aSGreg Roach } 2414a6f13a4aSGreg Roach if (preg_match("/\\$(\w+)/", $id, $match)) { 2415d1286247SGreg Roach $id = $this->vars[$match[1]]['id']; 2416a6f13a4aSGreg Roach $id = trim($id); 2417a6f13a4aSGreg Roach } 2418a6f13a4aSGreg Roach 241913abd6f3SGreg Roach $this->list = []; 2420299d100dSGreg Roach $person = Individual::getInstance($id, $this->tree); 2421a6f13a4aSGreg Roach if (!empty($person)) { 2422a6f13a4aSGreg Roach $this->list[$id] = $person; 2423a6f13a4aSGreg Roach switch ($group) { 24247a6ee1acSGreg Roach case 'child-family': 2425a6f13a4aSGreg Roach foreach ($person->getChildFamilies() as $family) { 2426a6f13a4aSGreg Roach $husband = $family->getHusband(); 2427a6f13a4aSGreg Roach $wife = $family->getWife(); 2428a6f13a4aSGreg Roach if (!empty($husband)) { 2429a6f13a4aSGreg Roach $this->list[$husband->getXref()] = $husband; 2430a6f13a4aSGreg Roach } 2431a6f13a4aSGreg Roach if (!empty($wife)) { 2432a6f13a4aSGreg Roach $this->list[$wife->getXref()] = $wife; 2433a6f13a4aSGreg Roach } 2434a6f13a4aSGreg Roach $children = $family->getChildren(); 2435a6f13a4aSGreg Roach foreach ($children as $child) { 2436a6f13a4aSGreg Roach if (!empty($child)) { 2437a6f13a4aSGreg Roach $this->list[$child->getXref()] = $child; 2438a6f13a4aSGreg Roach } 2439a6f13a4aSGreg Roach } 2440a6f13a4aSGreg Roach } 2441a6f13a4aSGreg Roach break; 24427a6ee1acSGreg Roach case 'spouse-family': 2443a6f13a4aSGreg Roach foreach ($person->getSpouseFamilies() as $family) { 2444a6f13a4aSGreg Roach $husband = $family->getHusband(); 2445a6f13a4aSGreg Roach $wife = $family->getWife(); 2446a6f13a4aSGreg Roach if (!empty($husband)) { 2447a6f13a4aSGreg Roach $this->list[$husband->getXref()] = $husband; 2448a6f13a4aSGreg Roach } 2449a6f13a4aSGreg Roach if (!empty($wife)) { 2450a6f13a4aSGreg Roach $this->list[$wife->getXref()] = $wife; 2451a6f13a4aSGreg Roach } 2452a6f13a4aSGreg Roach $children = $family->getChildren(); 2453a6f13a4aSGreg Roach foreach ($children as $child) { 2454a6f13a4aSGreg Roach if (!empty($child)) { 2455a6f13a4aSGreg Roach $this->list[$child->getXref()] = $child; 2456a6f13a4aSGreg Roach } 2457a6f13a4aSGreg Roach } 2458a6f13a4aSGreg Roach } 2459a6f13a4aSGreg Roach break; 24607a6ee1acSGreg Roach case 'direct-ancestors': 24613d7a8a4cSGreg Roach $this->addAncestors($this->list, $id, false, $maxgen); 2462a6f13a4aSGreg Roach break; 24637a6ee1acSGreg Roach case 'ancestors': 24643d7a8a4cSGreg Roach $this->addAncestors($this->list, $id, true, $maxgen); 2465a6f13a4aSGreg Roach break; 24667a6ee1acSGreg Roach case 'descendants': 2467a6f13a4aSGreg Roach $this->list[$id]->generation = 1; 24683d7a8a4cSGreg Roach $this->addDescendancy($this->list, $id, false, $maxgen); 2469a6f13a4aSGreg Roach break; 24707a6ee1acSGreg Roach case 'all': 24713d7a8a4cSGreg Roach $this->addAncestors($this->list, $id, true, $maxgen); 24723d7a8a4cSGreg Roach $this->addDescendancy($this->list, $id, true, $maxgen); 2473a6f13a4aSGreg Roach break; 2474a6f13a4aSGreg Roach } 2475a6f13a4aSGreg Roach } 2476a6f13a4aSGreg Roach 2477a6f13a4aSGreg Roach switch ($sortby) { 2478a6f13a4aSGreg Roach case 'NAME': 2479a6f13a4aSGreg Roach uasort($this->list, '\Fisharebest\Webtrees\GedcomRecord::compare'); 2480a6f13a4aSGreg Roach break; 2481a6f13a4aSGreg Roach case 'BIRT:DATE': 2482a6f13a4aSGreg Roach uasort($this->list, '\Fisharebest\Webtrees\Individual::compareBirthDate'); 2483a6f13a4aSGreg Roach break; 2484a6f13a4aSGreg Roach case 'DEAT:DATE': 2485a6f13a4aSGreg Roach uasort($this->list, '\Fisharebest\Webtrees\Individual::compareDeathDate'); 2486a6f13a4aSGreg Roach break; 2487a6f13a4aSGreg Roach case 'generation': 248813abd6f3SGreg Roach $newarray = []; 2489a6f13a4aSGreg Roach reset($this->list); 2490a6f13a4aSGreg Roach $genCounter = 1; 2491a6f13a4aSGreg Roach while (count($newarray) < count($this->list)) { 2492a6f13a4aSGreg Roach foreach ($this->list as $key => $value) { 2493a6f13a4aSGreg Roach $this->generation = $value->generation; 2494a6f13a4aSGreg Roach if ($this->generation == $genCounter) { 2495a6f13a4aSGreg Roach $newarray[$key] = new \stdClass; 2496a6f13a4aSGreg Roach $newarray[$key]->generation = $this->generation; 2497a6f13a4aSGreg Roach } 2498a6f13a4aSGreg Roach } 2499a6f13a4aSGreg Roach $genCounter++; 2500a6f13a4aSGreg Roach } 2501a6f13a4aSGreg Roach $this->list = $newarray; 2502a6f13a4aSGreg Roach break; 2503a6f13a4aSGreg Roach default: 2504a6f13a4aSGreg Roach // unsorted 2505a6f13a4aSGreg Roach break; 2506a6f13a4aSGreg Roach } 2507c1010edaSGreg Roach array_push($this->repeats_stack, [ 2508c1010edaSGreg Roach $this->repeats, 2509c1010edaSGreg Roach $this->repeat_bytes, 2510c1010edaSGreg Roach ]); 2511e8e7866bSGreg Roach $this->repeat_bytes = xml_get_current_line_number($this->parser) + 1; 2512a6f13a4aSGreg Roach } 2513a6f13a4aSGreg Roach 2514a6f13a4aSGreg Roach /** 251576692c8bSGreg Roach * XML </ Relatives> 2516a6f13a4aSGreg Roach */ 2517c1010edaSGreg Roach private function relativesEndHandler() 2518c1010edaSGreg Roach { 2519a6f13a4aSGreg Roach $this->process_repeats--; 2520a6f13a4aSGreg Roach if ($this->process_repeats > 0) { 2521a6f13a4aSGreg Roach return; 2522a6f13a4aSGreg Roach } 2523a6f13a4aSGreg Roach 2524a6f13a4aSGreg Roach // Check if there is any relatives 2525a6f13a4aSGreg Roach if (count($this->list) > 0) { 2526a6f13a4aSGreg Roach $lineoffset = 0; 2527a6f13a4aSGreg Roach foreach ($this->repeats_stack as $rep) { 2528a6f13a4aSGreg Roach $lineoffset += $rep[1]; 2529a6f13a4aSGreg Roach } 2530a6f13a4aSGreg Roach //-- read the xml from the file 2531299d100dSGreg Roach $lines = file($this->report); 25327a6ee1acSGreg Roach while ((strpos($lines[$lineoffset + $this->repeat_bytes], '<Relatives') === false) && (($lineoffset + $this->repeat_bytes) > 0)) { 2533a6f13a4aSGreg Roach $lineoffset--; 2534a6f13a4aSGreg Roach } 2535a6f13a4aSGreg Roach $lineoffset++; 2536a6f13a4aSGreg Roach $reportxml = "<tempdoc>\n"; 2537a6f13a4aSGreg Roach $line_nr = $lineoffset + $this->repeat_bytes; 2538a6f13a4aSGreg Roach // Relatives Level counter 2539a6f13a4aSGreg Roach $count = 1; 2540a6f13a4aSGreg Roach while (0 < $count) { 25417a6ee1acSGreg Roach if (strpos($lines[$line_nr], '<Relatives') !== false) { 2542a6f13a4aSGreg Roach $count++; 25437a6ee1acSGreg Roach } elseif (strpos($lines[$line_nr], '</Relatives') !== false) { 2544a6f13a4aSGreg Roach $count--; 2545a6f13a4aSGreg Roach } 2546a6f13a4aSGreg Roach if (0 < $count) { 2547a6f13a4aSGreg Roach $reportxml .= $lines[$line_nr]; 2548a6f13a4aSGreg Roach } 2549a6f13a4aSGreg Roach $line_nr++; 2550a6f13a4aSGreg Roach } 2551a6f13a4aSGreg Roach // No need to drag this 2552a6f13a4aSGreg Roach unset($lines); 2553a6f13a4aSGreg Roach $reportxml .= "</tempdoc>\n"; 2554a6f13a4aSGreg Roach // Save original values 2555e8e7866bSGreg Roach array_push($this->parser_stack, $this->parser); 2556a6f13a4aSGreg Roach $oldgedrec = $this->gedrec; 2557a6f13a4aSGreg Roach 2558a6f13a4aSGreg Roach $this->list_total = count($this->list); 2559a6f13a4aSGreg Roach $this->list_private = 0; 2560a6f13a4aSGreg Roach foreach ($this->list as $key => $value) { 2561a6f13a4aSGreg Roach if (isset($value->generation)) { 2562a6f13a4aSGreg Roach $this->generation = $value->generation; 2563a6f13a4aSGreg Roach } 2564299d100dSGreg Roach $tmp = GedcomRecord::getInstance($key, $this->tree); 2565299d100dSGreg Roach $this->gedrec = $tmp->privatizeGedcom(Auth::accessLevel($this->tree)); 2566a6f13a4aSGreg Roach 2567a6f13a4aSGreg Roach $repeat_parser = xml_parser_create(); 2568e8e7866bSGreg Roach $this->parser = $repeat_parser; 2569a6f13a4aSGreg Roach xml_parser_set_option($repeat_parser, XML_OPTION_CASE_FOLDING, false); 2570c1010edaSGreg Roach xml_set_element_handler($repeat_parser, [ 2571c1010edaSGreg Roach $this, 2572c1010edaSGreg Roach 'startElement', 2573c1010edaSGreg Roach ], [ 2574c1010edaSGreg Roach $this, 2575c1010edaSGreg Roach 'endElement', 2576c1010edaSGreg Roach ]); 2577c1010edaSGreg Roach xml_set_character_data_handler($repeat_parser, [ 2578c1010edaSGreg Roach $this, 2579c1010edaSGreg Roach 'characterData', 2580c1010edaSGreg Roach ]); 2581a6f13a4aSGreg Roach 2582a6f13a4aSGreg Roach if (!xml_parse($repeat_parser, $reportxml, true)) { 25837a6ee1acSGreg Roach throw new \DomainException(sprintf('RelativesEHandler XML error: %s at line %d', xml_error_string(xml_get_error_code($repeat_parser)), xml_get_current_line_number($repeat_parser))); 2584a6f13a4aSGreg Roach } 2585a6f13a4aSGreg Roach xml_parser_free($repeat_parser); 2586a6f13a4aSGreg Roach } 2587a6f13a4aSGreg Roach // Clean up the list array 258813abd6f3SGreg Roach $this->list = []; 2589e8e7866bSGreg Roach $this->parser = array_pop($this->parser_stack); 2590a6f13a4aSGreg Roach $this->gedrec = $oldgedrec; 2591a6f13a4aSGreg Roach } 2592a6f13a4aSGreg Roach list($this->repeats, $this->repeat_bytes) = array_pop($this->repeats_stack); 2593a6f13a4aSGreg Roach } 2594a6f13a4aSGreg Roach 2595a6f13a4aSGreg Roach /** 2596a6f13a4aSGreg Roach * XML <Generation /> element handler 2597a6f13a4aSGreg Roach * 2598a6f13a4aSGreg Roach * Prints the number of generations 2599a6f13a4aSGreg Roach */ 2600c1010edaSGreg Roach private function generationStartHandler() 2601c1010edaSGreg Roach { 2602a6f13a4aSGreg Roach $this->current_element->addText($this->generation); 2603a6f13a4aSGreg Roach } 2604a6f13a4aSGreg Roach 2605a6f13a4aSGreg Roach /** 2606a6f13a4aSGreg Roach * XML <NewPage /> element handler 2607a6f13a4aSGreg Roach * 2608a6f13a4aSGreg Roach * Has to be placed in an element (header, pageheader, body or footer) 2609a6f13a4aSGreg Roach */ 2610c1010edaSGreg Roach private function newPageStartHandler() 2611c1010edaSGreg Roach { 26127a6ee1acSGreg Roach $temp = 'addpage'; 2613e8e7866bSGreg Roach $this->wt_report->addElement($temp); 2614a6f13a4aSGreg Roach } 2615a6f13a4aSGreg Roach 2616a6f13a4aSGreg Roach /** 261776692c8bSGreg Roach * XML <html> 261876692c8bSGreg Roach * 2619a6f13a4aSGreg Roach * @param string $tag HTML tag name 262076692c8bSGreg Roach * @param array[] $attrs an array of key value pairs for the attributes 2621a6f13a4aSGreg Roach */ 2622c1010edaSGreg Roach private function htmlStartHandler($tag, $attrs) 2623c1010edaSGreg Roach { 26247a6ee1acSGreg Roach if ($tag === 'tempdoc') { 2625a6f13a4aSGreg Roach return; 2626a6f13a4aSGreg Roach } 2627e8e7866bSGreg Roach array_push($this->wt_report_stack, $this->wt_report); 2628e8e7866bSGreg Roach $this->wt_report = $this->report_root->createHTML($tag, $attrs); 2629e8e7866bSGreg Roach $this->current_element = $this->wt_report; 2630a6f13a4aSGreg Roach 2631a6f13a4aSGreg Roach array_push($this->print_data_stack, $this->print_data); 2632a6f13a4aSGreg Roach $this->print_data = true; 2633a6f13a4aSGreg Roach } 2634a6f13a4aSGreg Roach 2635a6f13a4aSGreg Roach /** 263676692c8bSGreg Roach * XML </html> 263776692c8bSGreg Roach * 2638a6f13a4aSGreg Roach * @param string $tag 2639a6f13a4aSGreg Roach */ 2640c1010edaSGreg Roach private function htmlEndHandler($tag) 2641c1010edaSGreg Roach { 26427a6ee1acSGreg Roach if ($tag === 'tempdoc') { 2643a6f13a4aSGreg Roach return; 2644a6f13a4aSGreg Roach } 2645a6f13a4aSGreg Roach 2646a6f13a4aSGreg Roach $this->print_data = array_pop($this->print_data_stack); 2647e8e7866bSGreg Roach $this->current_element = $this->wt_report; 2648e8e7866bSGreg Roach $this->wt_report = array_pop($this->wt_report_stack); 2649e8e7866bSGreg Roach if (!is_null($this->wt_report)) { 2650e8e7866bSGreg Roach $this->wt_report->addElement($this->current_element); 2651a6f13a4aSGreg Roach } else { 2652e8e7866bSGreg Roach $this->wt_report = $this->current_element; 2653a6f13a4aSGreg Roach } 2654a6f13a4aSGreg Roach } 2655a6f13a4aSGreg Roach 2656a6f13a4aSGreg Roach /** 2657a6f13a4aSGreg Roach * Handle <Input> 2658a6f13a4aSGreg Roach */ 2659c1010edaSGreg Roach private function inputStartHandler() 2660c1010edaSGreg Roach { 2661a6f13a4aSGreg Roach // Dummy function, to prevent the default HtmlStartHandler() being called 2662a6f13a4aSGreg Roach } 2663a6f13a4aSGreg Roach 2664a6f13a4aSGreg Roach /** 2665a6f13a4aSGreg Roach * Handle </Input> 2666a6f13a4aSGreg Roach */ 2667c1010edaSGreg Roach private function inputEndHandler() 2668c1010edaSGreg Roach { 2669a6f13a4aSGreg Roach // Dummy function, to prevent the default HtmlEndHandler() being called 2670a6f13a4aSGreg Roach } 2671a6f13a4aSGreg Roach 2672a6f13a4aSGreg Roach /** 2673a6f13a4aSGreg Roach * Handle <Report> 2674a6f13a4aSGreg Roach */ 2675c1010edaSGreg Roach private function reportStartHandler() 2676c1010edaSGreg Roach { 2677a6f13a4aSGreg Roach // Dummy function, to prevent the default HtmlStartHandler() being called 2678a6f13a4aSGreg Roach } 2679a6f13a4aSGreg Roach 2680a6f13a4aSGreg Roach /** 2681a6f13a4aSGreg Roach * Handle </Report> 2682a6f13a4aSGreg Roach */ 2683c1010edaSGreg Roach private function reportEndHandler() 2684c1010edaSGreg Roach { 2685a6f13a4aSGreg Roach // Dummy function, to prevent the default HtmlEndHandler() being called 2686a6f13a4aSGreg Roach } 2687a6f13a4aSGreg Roach 2688a6f13a4aSGreg Roach /** 268976692c8bSGreg Roach * XML </titleEndHandler> 2690a6f13a4aSGreg Roach */ 2691c1010edaSGreg Roach private function titleEndHandler() 2692c1010edaSGreg Roach { 26932836aa05SGreg Roach $this->report_root->addTitle($this->text); 2694a6f13a4aSGreg Roach } 2695a6f13a4aSGreg Roach 2696a6f13a4aSGreg Roach /** 269776692c8bSGreg Roach * XML </descriptionEndHandler> 2698a6f13a4aSGreg Roach */ 2699c1010edaSGreg Roach private function descriptionEndHandler() 2700c1010edaSGreg Roach { 27012836aa05SGreg Roach $this->report_root->addDescription($this->text); 2702a6f13a4aSGreg Roach } 2703729ce104SGreg Roach 2704729ce104SGreg Roach /** 270576692c8bSGreg Roach * Create a list of all descendants. 270676692c8bSGreg Roach * 2707729ce104SGreg Roach * @param string[] $list 2708729ce104SGreg Roach * @param string $pid 2709729ce104SGreg Roach * @param bool $parents 2710729ce104SGreg Roach * @param int $generations 2711729ce104SGreg Roach */ 2712c1010edaSGreg Roach private function addDescendancy(&$list, $pid, $parents = false, $generations = -1) 2713c1010edaSGreg Roach { 2714299d100dSGreg Roach $person = Individual::getInstance($pid, $this->tree); 2715729ce104SGreg Roach if ($person === null) { 2716729ce104SGreg Roach return; 2717729ce104SGreg Roach } 2718729ce104SGreg Roach if (!isset($list[$pid])) { 2719729ce104SGreg Roach $list[$pid] = $person; 2720729ce104SGreg Roach } 2721729ce104SGreg Roach if (!isset($list[$pid]->generation)) { 2722729ce104SGreg Roach $list[$pid]->generation = 0; 2723729ce104SGreg Roach } 2724729ce104SGreg Roach foreach ($person->getSpouseFamilies() as $family) { 2725729ce104SGreg Roach if ($parents) { 2726729ce104SGreg Roach $husband = $family->getHusband(); 2727729ce104SGreg Roach $wife = $family->getWife(); 2728729ce104SGreg Roach if ($husband) { 2729729ce104SGreg Roach $list[$husband->getXref()] = $husband; 2730729ce104SGreg Roach if (isset($list[$pid]->generation)) { 2731729ce104SGreg Roach $list[$husband->getXref()]->generation = $list[$pid]->generation - 1; 2732729ce104SGreg Roach } else { 2733729ce104SGreg Roach $list[$husband->getXref()]->generation = 1; 2734729ce104SGreg Roach } 2735729ce104SGreg Roach } 2736729ce104SGreg Roach if ($wife) { 2737729ce104SGreg Roach $list[$wife->getXref()] = $wife; 2738729ce104SGreg Roach if (isset($list[$pid]->generation)) { 2739729ce104SGreg Roach $list[$wife->getXref()]->generation = $list[$pid]->generation - 1; 2740729ce104SGreg Roach } else { 2741729ce104SGreg Roach $list[$wife->getXref()]->generation = 1; 2742729ce104SGreg Roach } 2743729ce104SGreg Roach } 2744729ce104SGreg Roach } 2745729ce104SGreg Roach $children = $family->getChildren(); 2746729ce104SGreg Roach foreach ($children as $child) { 2747729ce104SGreg Roach if ($child) { 2748729ce104SGreg Roach $list[$child->getXref()] = $child; 2749729ce104SGreg Roach if (isset($list[$pid]->generation)) { 2750729ce104SGreg Roach $list[$child->getXref()]->generation = $list[$pid]->generation + 1; 2751729ce104SGreg Roach } else { 2752729ce104SGreg Roach $list[$child->getXref()]->generation = 2; 2753729ce104SGreg Roach } 2754729ce104SGreg Roach } 2755729ce104SGreg Roach } 2756729ce104SGreg Roach if ($generations == -1 || $list[$pid]->generation + 1 < $generations) { 2757729ce104SGreg Roach foreach ($children as $child) { 27583d7a8a4cSGreg Roach $this->addDescendancy($list, $child->getXref(), $parents, $generations); // recurse on the childs family 2759729ce104SGreg Roach } 2760729ce104SGreg Roach } 2761729ce104SGreg Roach } 2762729ce104SGreg Roach } 2763729ce104SGreg Roach 2764729ce104SGreg Roach /** 276576692c8bSGreg Roach * Create a list of all ancestors. 276676692c8bSGreg Roach * 2767729ce104SGreg Roach * @param string[] $list 2768729ce104SGreg Roach * @param string $pid 2769729ce104SGreg Roach * @param bool $children 2770729ce104SGreg Roach * @param int $generations 2771729ce104SGreg Roach */ 2772c1010edaSGreg Roach private function addAncestors(&$list, $pid, $children = false, $generations = -1) 2773c1010edaSGreg Roach { 277413abd6f3SGreg Roach $genlist = [$pid]; 2775729ce104SGreg Roach $list[$pid]->generation = 1; 2776729ce104SGreg Roach while (count($genlist) > 0) { 2777729ce104SGreg Roach $id = array_shift($genlist); 2778729ce104SGreg Roach if (strpos($id, 'empty') === 0) { 2779729ce104SGreg Roach continue; // id can be something like “empty7” 2780729ce104SGreg Roach } 2781299d100dSGreg Roach $person = Individual::getInstance($id, $this->tree); 2782729ce104SGreg Roach foreach ($person->getChildFamilies() as $family) { 2783729ce104SGreg Roach $husband = $family->getHusband(); 2784729ce104SGreg Roach $wife = $family->getWife(); 2785729ce104SGreg Roach if ($husband) { 2786729ce104SGreg Roach $list[$husband->getXref()] = $husband; 2787729ce104SGreg Roach $list[$husband->getXref()]->generation = $list[$id]->generation + 1; 2788729ce104SGreg Roach } 2789729ce104SGreg Roach if ($wife) { 2790729ce104SGreg Roach $list[$wife->getXref()] = $wife; 2791729ce104SGreg Roach $list[$wife->getXref()]->generation = $list[$id]->generation + 1; 2792729ce104SGreg Roach } 2793729ce104SGreg Roach if ($generations == -1 || $list[$id]->generation + 1 < $generations) { 2794729ce104SGreg Roach if ($husband) { 2795729ce104SGreg Roach array_push($genlist, $husband->getXref()); 2796729ce104SGreg Roach } 2797729ce104SGreg Roach if ($wife) { 2798729ce104SGreg Roach array_push($genlist, $wife->getXref()); 2799729ce104SGreg Roach } 2800729ce104SGreg Roach } 2801729ce104SGreg Roach if ($children) { 2802729ce104SGreg Roach foreach ($family->getChildren() as $child) { 2803729ce104SGreg Roach $list[$child->getXref()] = $child; 2804729ce104SGreg Roach if (isset($list[$id]->generation)) { 2805729ce104SGreg Roach $list[$child->getXref()]->generation = $list[$id]->generation; 2806729ce104SGreg Roach } else { 2807729ce104SGreg Roach $list[$child->getXref()]->generation = 1; 2808729ce104SGreg Roach } 2809729ce104SGreg Roach } 2810729ce104SGreg Roach } 2811729ce104SGreg Roach } 2812729ce104SGreg Roach } 2813729ce104SGreg Roach } 2814729ce104SGreg Roach 2815729ce104SGreg Roach /** 2816729ce104SGreg Roach * get gedcom tag value 2817729ce104SGreg Roach * 2818729ce104SGreg Roach * @param string $tag The tag to find, use : to delineate subtags 2819729ce104SGreg Roach * @param int $level The gedcom line level of the first tag to find, setting level to 0 will cause it to use 1+ the level of the incoming record 2820729ce104SGreg Roach * @param string $gedrec The gedcom record to get the value from 2821729ce104SGreg Roach * 2822729ce104SGreg Roach * @return string the value of a gedcom tag from the given gedcom record 2823729ce104SGreg Roach */ 2824c1010edaSGreg Roach private function getGedcomValue($tag, $level, $gedrec) 2825c1010edaSGreg Roach { 2826729ce104SGreg Roach if (empty($gedrec)) { 2827729ce104SGreg Roach return ''; 2828729ce104SGreg Roach } 2829729ce104SGreg Roach $tags = explode(':', $tag); 2830729ce104SGreg Roach $origlevel = $level; 2831729ce104SGreg Roach if ($level == 0) { 28323c12f3e5SGreg Roach $level = $gedrec[0] + 1; 2833729ce104SGreg Roach } 2834729ce104SGreg Roach 2835729ce104SGreg Roach $subrec = $gedrec; 2836729ce104SGreg Roach foreach ($tags as $t) { 2837729ce104SGreg Roach $lastsubrec = $subrec; 28383d7a8a4cSGreg Roach $subrec = Functions::getSubRecord($level, "$level $t", $subrec); 2839729ce104SGreg Roach if (empty($subrec) && $origlevel == 0) { 2840729ce104SGreg Roach $level--; 28413d7a8a4cSGreg Roach $subrec = Functions::getSubRecord($level, "$level $t", $lastsubrec); 2842729ce104SGreg Roach } 2843729ce104SGreg Roach if (empty($subrec)) { 28447a6ee1acSGreg Roach if ($t == 'TITL') { 28453d7a8a4cSGreg Roach $subrec = Functions::getSubRecord($level, "$level ABBR", $lastsubrec); 2846729ce104SGreg Roach if (!empty($subrec)) { 28477a6ee1acSGreg Roach $t = 'ABBR'; 2848729ce104SGreg Roach } 2849729ce104SGreg Roach } 2850729ce104SGreg Roach if (empty($subrec)) { 2851729ce104SGreg Roach if ($level > 0) { 2852729ce104SGreg Roach $level--; 2853729ce104SGreg Roach } 28543d7a8a4cSGreg Roach $subrec = Functions::getSubRecord($level, "@ $t", $gedrec); 2855729ce104SGreg Roach if (empty($subrec)) { 2856729ce104SGreg Roach return ''; 2857729ce104SGreg Roach } 2858729ce104SGreg Roach } 2859729ce104SGreg Roach } 2860729ce104SGreg Roach $level++; 2861729ce104SGreg Roach } 2862729ce104SGreg Roach $level--; 2863729ce104SGreg Roach $ct = preg_match("/$level $t(.*)/", $subrec, $match); 2864729ce104SGreg Roach if ($ct == 0) { 2865729ce104SGreg Roach $ct = preg_match("/$level @.+@ (.+)/", $subrec, $match); 2866729ce104SGreg Roach } 2867729ce104SGreg Roach if ($ct == 0) { 2868729ce104SGreg Roach $ct = preg_match("/@ $t (.+)/", $subrec, $match); 2869729ce104SGreg Roach } 2870729ce104SGreg Roach if ($ct > 0) { 2871729ce104SGreg Roach $value = trim($match[1]); 2872729ce104SGreg Roach if ($t == 'NOTE' && preg_match('/^@(.+)@$/', $value, $match)) { 2873299d100dSGreg Roach $note = Note::getInstance($match[1], $this->tree); 2874729ce104SGreg Roach if ($note) { 2875729ce104SGreg Roach $value = $note->getNote(); 2876729ce104SGreg Roach } else { 2877729ce104SGreg Roach //-- set the value to the id without the @ 2878729ce104SGreg Roach $value = $match[1]; 2879729ce104SGreg Roach } 2880729ce104SGreg Roach } 28817a6ee1acSGreg Roach if ($level != 0 || $t != 'NOTE') { 28823d7a8a4cSGreg Roach $value .= Functions::getCont($level + 1, $subrec); 2883729ce104SGreg Roach } 2884729ce104SGreg Roach 2885729ce104SGreg Roach return $value; 2886729ce104SGreg Roach } 2887729ce104SGreg Roach 28887a6ee1acSGreg Roach return ''; 2889729ce104SGreg Roach } 2890d1286247SGreg Roach 2891d1286247SGreg Roach /** 2892d1286247SGreg Roach * Replace variable identifiers with their values. 2893d1286247SGreg Roach * 2894d1286247SGreg Roach * @param string $expression An expression such as "$foo == 123" 289582759250SGreg Roach * @param bool $quote Whether to add quotation marks 2896d1286247SGreg Roach * 2897d1286247SGreg Roach * @return string 2898d1286247SGreg Roach */ 2899c1010edaSGreg Roach private function substituteVars($expression, $quote) 2900c1010edaSGreg Roach { 2901d1286247SGreg Roach return preg_replace_callback( 2902d1286247SGreg Roach '/\$(\w+)/', 29032118c0e3SGreg Roach function ($matches) use ($quote) { 29042118c0e3SGreg Roach if (isset($this->vars[$matches[1]]['id'])) { 290582759250SGreg Roach if ($quote) { 29062118c0e3SGreg Roach return "'" . addcslashes($this->vars[$matches[1]]['id'], "'") . "'"; 290782759250SGreg Roach } else { 29082118c0e3SGreg Roach return $this->vars[$matches[1]]['id']; 290982759250SGreg Roach } 2910d1286247SGreg Roach } else { 2911d1286247SGreg Roach Log::addErrorLog(sprintf('Undefined variable $%s in report', $matches[1])); 29123d7a8a4cSGreg Roach 2913d1286247SGreg Roach return '$' . $matches[1]; 2914d1286247SGreg Roach } 2915d1286247SGreg Roach }, 2916d1286247SGreg Roach $expression 2917d1286247SGreg Roach ); 2918d1286247SGreg Roach } 2919a6f13a4aSGreg Roach} 2920