", i18n::translate('Access Denied
You do not have access to this resource.'), ""; print_footer(); exit; } if ($action!="choose") { if ($gid1==$gid2 && $GEDCOM==$ged2) { $action="choose"; echo "", i18n::translate('You entered the same IDs. You cannot merge the same records.'), "\n"; } 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 Person($gedrec1); $gid1=$tmp->getXref(); $tmp=new Person($gedrec2); $gid2=$tmp->getXref(); if (empty($gedrec1)) { echo '', i18n::translate('Unable to find record with ID'), ': ', $gid1, ', ', $ged; $action="choose"; } elseif (empty($gedrec2)) { echo '', 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 "", i18n::translate('Records are not the same type. Cannot merge records that are not the same type.'), "\n"; $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 "

", i18n::translate('Merge Step 2 of 3'), "

\n"; echo "
\n"; echo i18n::translate('The following facts were exactly the same in both records and will be merged automatically.'), "
\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; $equal_count=0; $skip1 = array(); $skip2 = array(); echo "\n"; foreach ($facts1 as $i=>$fact1) { foreach ($facts2 as $j=>$fact2) { if (utf8_strtoupper($fact1["subrec"])==utf8_strtoupper($fact2["subrec"])) { $skip1[] = $i; $skip2[] = $j; $equal_count++; echo "\n\n"; } } } if ($equal_count==0) { echo "\n"; } echo "
", i18n::translate($fact1['fact']); echo "", nl2br($fact1["subrec"]), "
", i18n::translate('No matching facts found'), "


\n"; echo i18n::translate('The following facts did not match. Select the information you would like to keep.'), "
\n"; echo "\n"; echo "\n"; echo ""; echo "
", i18n::translate('Record'), " ", $gid1, "", i18n::translate('Record'), " ", $gid2, "
\n"; echo "\n"; foreach ($facts1 as $i=>$fact1) { if (($fact1["fact"]!="CHAN")&&(!in_array($i, $skip1))) { echo ""; echo "\n"; } } echo "
", nl2br($fact1["subrec"]), "
\n"; echo "
\n"; echo "\n"; foreach ($facts2 as $j=>$fact2) { if (($fact2["fact"]!="CHAN")&&(!in_array($j, $skip2))) { echo ""; echo "\n"; } } echo "
", nl2br($fact2["subrec"]), "
"; echo "
\n"; echo "\n"; echo "
\n"; } elseif ($action=="merge") { $manual_save = true; echo "

", i18n::translate('Merge Step 3 of 3'), "

\n"; if ($GEDCOM==$ged2) { $success = delete_gedrec($gid2, WT_GED_ID); if ($success) { echo "
", i18n::translate('GEDCOM record successfully deleted.'), "
\n"; } //-- replace all the records that linked to gid2 $ids=fetch_all_links($gid2, WT_GED_ID); foreach ($ids as $id) { $record=find_gedcom_record($id, WT_GED_ID, true); echo i18n::translate('Updating linked record'), " {$id}
\n"; $newrec=str_replace("@$gid2@", "@$gid1@", $record); $newrec=preg_replace( '/(\n1.*@.+@.*(?:(?:\n[2-9].*)*))((?:\n1.*(?:\n[2-9].*)*)*\1)/', '$2', $newrec ); replace_gedrec($id, WT_GED_ID, $newrec); } // Update any linked user-accounts WT_DB::prepare( "UPDATE `##user_gedcom_setting`". " SET setting_value=?". " WHERE gedcom_id=? AND setting_name='gedcomid' AND setting_value=?" )->execute(array($gid2, WT_GED_ID, $gid1)); // Merge hit counters $hits=WT_DB::prepare( "SELECT page_name, SUM(page_count)". " FROM `##hit_counter`". " WHERE gedcom_id=? AND page_parameter IN (?, ?)". " GROUP BY page_name" )->execute(array(WT_GED_ID, $gid1, $gid2))->fetchAssoc(); foreach ($hits as $page_name=>$page_count) { WT_DB::prepare( "UPDATE `##hit_counter` SET page_count=?". " WHERE gedcom_id=? AND page_name=? AND page_parameter=?" )->execute(array($page_count, WT_GED_ID, $page_name, $gid1)); } WT_DB::prepare( "DELETE FROM `##hit_counter`". " WHERE gedcom_id=? AND page_parameter=?" )->execute(array(WT_GED_ID, $gid2)); } $newgedrec = "0 @$gid1@ $type1\n"; for ($i=0; ($i\n"; } } if (isset($facts2[$i])) { if (in_array($i, $keep2)) { $newgedrec .= $facts2[$i]["subrec"]."\n"; echo i18n::translate('Adding'), " ", $facts2[$i]["fact"], " ", i18n::translate('from'), " ", $gid2, "
\n"; } } } replace_gedrec($gid1, WT_GED_ID, $newgedrec); $rec=GedcomRecord::getInstance($gid1); echo '
', i18n::translate('Record %s successfully updated.', $rec->getXrefLink()), '
'; $fav_count=update_favorites($gid2, $gid1); if ($fav_count > 0) { echo '
', $fav_count, ' ', i18n::translate('favorites updated.'), '
'; } echo "
", i18n::translate('Merge more records.'), "
\n"; echo "


\n"; } } } } } if ($action=="choose") { ?>

'; echo "

", i18n::translate('Merge Step 1 of 3'), "

\n"; echo "
\n"; echo "\n"; echo i18n::translate('Select two GEDCOM records to merge. The records must be of the same type.'), "
\n"; echo "\n\t\t\n\t\t"; echo "
 "; echo i18n::translate('Merge To ID:'); echo " "; echo " "; echo ''; echo "\n"; echo " ", i18n::translate('Find individual ID'), " |"; echo " ", i18n::translate('Find Family ID'), " |"; echo " ", i18n::translate('Find Source ID'), ""; echo "
 "; echo i18n::translate('Merge From ID:'); echo " "; echo " "; echo "\n"; echo " ", i18n::translate('Find individual ID'), " |"; echo " ", i18n::translate('Find Family ID'), " |"; echo " ", i18n::translate('Find Source ID'), ""; echo "
"; echo "\n"; echo "
"; echo "
\n"; } print_footer();