requireManagerLogin() ->setPageTitle(WT_I18N::translate('Merge records')) ->pageHeader(); require_once WT_ROOT.'includes/functions/functions_edit.php'; require_once WT_ROOT.'includes/functions/functions_import.php'; $ged=$GEDCOM; $gid1=safe_POST_xref('gid1'); $gid2=safe_POST_xref('gid2'); $action=safe_POST('action', WT_REGEX_ALPHA, 'choose'); $ged2=safe_POST('ged2', WT_REGEX_NOSCRIPT, $GEDCOM); $keep1=safe_POST('keep1', WT_REGEX_UNSAFE); $keep2=safe_POST('keep2', WT_REGEX_UNSAFE); if (empty($keep1)) $keep1=array(); if (empty($keep2)) $keep2=array(); if (count(WT_Tree::getAll())==1) { //Removed becasue it doesn't work here for multiple GEDCOMs. Can be reinstated when fixed (https://bugs.launchpad.net/webtrees/+bug/613235) $controller->addExternalJavascript(WT_STATIC_URL.'js/autocomplete.js'); } if ($action!='choose') { if ($gid1==$gid2 && $GEDCOM==$ged2) { $action='choose'; echo '', WT_I18N::translate('You entered the same IDs. You cannot merge the same records.'), ''; } else { $gedrec1 = find_gedcom_record($gid1, WT_GED_ID, true); $gedrec2 = find_gedcom_record($gid2, get_id_from_gedcom($ged2), true); // Fetch the original XREF - may differ in case from the supplied value $tmp=new WT_Person($gedrec1); $gid1=$tmp->getXref(); $tmp=new WT_Person($gedrec2); $gid2=$tmp->getXref(); if (empty($gedrec1)) { echo '', WT_I18N::translate('Unable to find record with ID'), ': ', $gid1, ', ', $ged; $action='choose'; } elseif (empty($gedrec2)) { echo '', WT_I18N::translate('Unable to find record with ID'), ': ', $gid2, ', ', $ged2; $action='choose'; } else { $type1 = ''; $ct = preg_match("/0 @$gid1@ (.*)/", $gedrec1, $match); if ($ct>0) { $type1 = trim($match[1]); } $type2 = ""; $ct = preg_match("/0 @$gid2@ (.*)/", $gedrec2, $match); if ($ct>0) $type2 = trim($match[1]); if (!empty($type1) && ($type1!=$type2)) { echo '', WT_I18N::translate('Records are not the same type. Cannot merge records that are not the same type.'), ''; $action='choose'; } else { $facts1 = array(); $facts2 = array(); $prev_tags = array(); $ct = preg_match_all('/\n1 (\w+)/', $gedrec1, $match, PREG_SET_ORDER); for ($i=0; $i<$ct; $i++) { $fact = trim($match[$i][1]); if (isset($prev_tags[$fact])) { $prev_tags[$fact]++; } else { $prev_tags[$fact] = 1; } $subrec = get_sub_record(1, "1 $fact", $gedrec1, $prev_tags[$fact]); $facts1[] = array('fact'=>$fact, 'subrec'=>trim($subrec)); } $prev_tags = array(); $ct = preg_match_all('/\n1 (\w+)/', $gedrec2, $match, PREG_SET_ORDER); for ($i=0; $i<$ct; $i++) { $fact = trim($match[$i][1]); if (isset($prev_tags[$fact])) { $prev_tags[$fact]++; } else { $prev_tags[$fact] = 1; } $subrec = get_sub_record(1, "1 $fact", $gedrec2, $prev_tags[$fact]); $facts2[] = array('fact'=>$fact, 'subrec'=>trim($subrec)); } if ($action=='select') { echo '