. */ namespace Fisharebest\Webtrees; use Fisharebest\Webtrees\Controller\PageController; use Fisharebest\Webtrees\Functions\FunctionsPrint; use Fisharebest\Webtrees\Report\ReportHtml; use Fisharebest\Webtrees\Report\ReportParserGenerate; use Fisharebest\Webtrees\Report\ReportParserSetup; use Fisharebest\Webtrees\Report\ReportPdf; /** * Defined in session.php * * @global Tree $WT_TREE */ global $WT_TREE; define('WT_SCRIPT_NAME', 'reportengine.php'); require './includes/session.php'; $controller = new PageController; $famid = Filter::get('famid', WT_REGEX_XREF); $pid = Filter::get('pid', WT_REGEX_XREF); $action = Filter::get('action', 'choose|setup|run', 'choose'); $report = Filter::get('report'); $output = Filter::get('output', 'HTML|PDF', 'PDF'); $vars = Filter::get('vars'); $varnames = Filter::get('varnames'); $type = Filter::get('type'); if (!is_array($vars)) { $vars = array(); } if (!is_array($varnames)) { $varnames = array(); } if (!is_array($type)) { $type = array(); } //-- setup the arrays $newvars = array(); foreach ($vars as $name => $var) { $newvars[$name]['id'] = $var; if (!empty($type[$name])) { switch ($type[$name]) { case 'INDI': $record = Individual::getInstance($var, $WT_TREE); if ($record && $record->canShowName()) { $newvars[$name]['gedcom'] = $record->privatizeGedcom(Auth::accessLevel($WT_TREE)); } else { $action = 'setup'; } break; case 'FAM': $record = Family::getInstance($var, $WT_TREE); if ($record && $record->canShowName()) { $newvars[$name]['gedcom'] = $record->privatizeGedcom(Auth::accessLevel($WT_TREE)); } else { $action = 'setup'; } break; case 'SOUR': $record = Source::getInstance($var, $WT_TREE); if ($record && $record->canShowName()) { $newvars[$name]['gedcom'] = $record->privatizeGedcom(Auth::accessLevel($WT_TREE)); } else { $action = 'setup'; } break; default: break; } } } $vars = $newvars; foreach ($varnames as $name) { if (!isset($vars[$name])) { $vars[$name]['id'] = ''; } } $reports = array(); foreach (Module::getActiveReports($WT_TREE) as $rep) { $menu = $rep->getReportMenu(); if (preg_match('/report=(' . preg_quote(WT_MODULES_DIR, '/') . '[a-z0-9_]+\/[a-z0-9_]+\.xml)/', $menu->getLink(), $match)) { $reports[$match[1]] = $menu->getLabel(); } } if (!empty($report)) { if (!array_key_exists($report, $reports)) { $action = 'choose'; } } //-- choose a report to run switch ($action) { case 'choose': $controller ->setPageTitle(I18N::translate('Choose a report to run')) ->pageHeader(); echo '

', I18N::translate('Choose a report to run'), '

', I18N::translate('Report'), '
'; break; case 'setup': $report_setup = new ReportParserSetup($report); $report_array = $report_setup->reportProperties(); $controller ->setPageTitle($report_array['title']) ->pageHeader() ->addExternalJavascript(WT_AUTOCOMPLETE_JS_URL) ->addInlineJavascript('autocomplete();'); FunctionsPrint::initializeCalendarPopup(); echo '

', $report_array['title'], '

'; if (!isset($report_array['inputs'])) { $report_array['inputs'] = array(); } foreach ($report_array['inputs'] as $input) { echo ''; } echo '
', I18N::translate('Report'), '', $report_array['description'], '
'; echo ''; echo I18N::translate($input['value']), ''; if (!isset($input['type'])) { $input['type'] = 'text'; } if (!isset($input['default'])) { $input['default'] = ''; } if (!isset($input['lookup'])) { $input['lookup'] = ''; } if ($input['type'] == 'text') { echo 'getSignificantIndividual()->getXref(); } break; case 'FAM': echo ' data-autocomplete-type="FAM"'; if (!empty($famid)) { $input['default'] = $famid; } else { $input['default'] = $controller->getSignificantFamily()->getXref(); } break; case 'SOUR': echo ' data-autocomplete-type="SOUR"'; if (!empty($sid)) { $input['default'] = $sid; } break; case 'DATE': if (isset($input['default'])) { $input['default'] = strtoupper($input['default']); } break; } echo ' type="text" name="vars[', Filter::escapeHtml($input['name']), ']" id="', Filter::escapeHtml($input['name']), '" value="', Filter::escapeHtml($input['default']), '" style="direction: ltr;">'; } if ($input['type'] == 'checkbox') { echo ''; } if ($input['type'] == 'select') { echo ''; } if (isset($input['lookup'])) { echo ''; if ($input['lookup'] == 'INDI') { echo FunctionsPrint::printFindIndividualLink('pid'); } elseif ($input['lookup'] == 'PLAC') { echo FunctionsPrint::printFindPlaceLink($input['name']); } elseif ($input['lookup'] == 'FAM') { echo FunctionsPrint::printFindFamilyLink('famid'); } elseif ($input['lookup'] == 'SOUR') { echo FunctionsPrint::printFindSourceLink($input['name']); } elseif ($input['lookup'] == 'DATE') { echo ' '; echo ''; } } echo '

'; break; case 'run': if (strstr($report, 'report_singlepage.xml') !== false) { // This is a custom module? new \ReportPedigree; break; } switch ($output) { case 'HTML': header('Content-type: text/html; charset=UTF-8'); new ReportParserGenerate($report, new ReportHtml, $vars); break; case 'PDF': new ReportParserGenerate($report, new ReportPdf, $vars); break; } }