. */ namespace Fisharebest\Webtrees; /** * Defined in session.php * * @global Tree $WT_TREE */ global $WT_TREE; use Fisharebest\Webtrees\Controller\PageController; define('WT_SCRIPT_NAME', 'admin_trees_places.php'); require './includes/session.php'; $search = Filter::post('search', null, Filter::get('search')); $replace = Filter::post('replace'); $confirm = Filter::post('confirm'); $changes = array(); if ($search && $replace) { $rows = Database::prepare( "SELECT i_id AS xref, i_gedcom AS gedcom" . " FROM `##individuals`" . " LEFT JOIN `##change` ON (i_id = xref AND i_file=gedcom_id AND status='pending')" . " WHERE i_file = ?" . " AND COALESCE(new_gedcom, i_gedcom) REGEXP CONCAT('\n2 PLAC ([^\n]*, )*', ?, '(\n|$)')" )->execute(array($WT_TREE->getTreeId(), preg_quote($search)))->fetchAll(); foreach ($rows as $row) { $record = Individual::getInstance($row->xref, $WT_TREE, $row->gedcom); foreach ($record->getFacts() as $fact) { $old_place = $fact->getAttribute('PLAC'); if (preg_match('/(^|, )' . preg_quote($search, '/') . '$/i', $old_place)) { $new_place = preg_replace('/(^|, )' . preg_quote($search, '/') . '$/i', '$1' . $replace, $old_place); $changes[$old_place] = $new_place; if ($confirm == 'update') { $gedcom = preg_replace('/(\n2 PLAC (?:.*, )*)' . preg_quote($search, '/') . '(\n|$)/i', '$1' . $replace . '$2', $fact->getGedcom()); $record->updateFact($fact->getFactId(), $gedcom, false); } } } } $rows = Database::prepare( "SELECT f_id AS xref, f_gedcom AS gedcom" . " FROM `##families`" . " LEFT JOIN `##change` ON (f_id = xref AND f_file=gedcom_id AND status='pending')" . " WHERE f_file = ?" . " AND COALESCE(new_gedcom, f_gedcom) REGEXP CONCAT('\n2 PLAC ([^\n]*, )*', ?, '(\n|$)')" )->execute(array($WT_TREE->getTreeId(), preg_quote($search)))->fetchAll(); foreach ($rows as $row) { $record = Family::getInstance($row->xref, $WT_TREE, $row->gedcom); foreach ($record->getFacts() as $fact) { $old_place = $fact->getAttribute('PLAC'); if (preg_match('/(^|, )' . preg_quote($search, '/') . '$/i', $old_place)) { $new_place = preg_replace('/(^|, )' . preg_quote($search, '/') . '$/i', '$1' . $replace, $old_place); $changes[$old_place] = $new_place; if ($confirm == 'update') { $gedcom = preg_replace('/(\n2 PLAC (?:.*, )*)' . preg_quote($search, '/') . '(\n|$)/i', '$1' . $replace . '$2', $fact->getGedcom()); $record->updateFact($fact->getFactId(), $gedcom, false); } } } } } $controller = new PageController; $controller ->restrictAccess(Auth::isManager($WT_TREE)) ->setPageTitle(I18N::translate('Update all the place names in a family tree') . ' — ' . $WT_TREE->getTitleHtml()) ->addInlineJavascript('autocomplete();') ->pageHeader(); ?>

getPageTitle(); ?>