pg_query("\n            BEGIN\n        ");
 // transfer all "events" from source to target
 pg_query("\n            UPDATE participants\n            SET person_fk = {$target}\n            WHERE person_fk = {$source}\n        ");
 pg_query("\n            UPDATE participant_notes\n            SET person_fk = {$target}\n            WHERE person_fk = {$source}\n        ");
 // merge parental relations according to discovery process above
 if ($merge_fathers) {
     // delete 'source' father relationship, transfer citation(s)
     $relid_s = get_relation_id($source, 1);
     $relid_t = get_relation_id($target, 1);
     pg_query("\n                UPDATE relation_citations\n                SET relation_fk = {$relid_t}\n                WHERE relation_fk = {$relid_s}\n            ");
     pg_query("\n                DELETE FROM relations\n                WHERE relation_id = {$relid_s}\n            ");
 }
 if ($merge_mothers) {
     // delete 'source' mother relationship, transfer citation(s)
     $relid_s = get_relation_id($source, 2);
     $relid_t = get_relation_id($target, 2);
     pg_query("\n                UPDATE relation_citations\n                SET relation_fk = {$relid_t}\n                WHERE relation_fk = {$relid_s}\n            ");
     pg_query("\n                DELETE FROM relations\n                WHERE relation_id = {$relid_s}\n            ");
 }
 // transfer remaining relations
 pg_query("\n            UPDATE relations\n            SET child_fk = {$target}\n            WHERE child_fk = {$source}\n        ");
 pg_query("\n            UPDATE relations\n            SET parent_fk = {$target}\n            WHERE parent_fk = {$source}\n        ");
 // update source_linkage
 pg_query("\n            UPDATE source_linkage\n            SET person_fk = {$target}\n            WHERE person_fk = {$source}\n        ");
 // insert "event" for source person with a link to target person
 $event_note = " [p={$target}|ID #{$target}]";
 $event = fetch_val("\n            INSERT INTO events (\n                tag_fk,\n                place_fk,\n                event_date,\n                sort_date,\n                event_note\n            )\n            VALUES (\n                1040,\n                1,\n                '000000003000000001',\n                '00010101',\n                '{$event_note}'\n            )\n            RETURNING event_id\n        ");
 add_participant($source, $event);
 pg_query("\n            INSERT INTO merged (old_person_fk,new_person_fk)\n            VALUES ({$source}, {$target})\n        ");
 set_last_edit($source);
 set_last_edit($target);
function show_parent($person, $gender)
{
    // print names and lifespans of parents.
    // valid $gender values are 1=father, 2=mother
    global $language, $_Add, $_Insert, $_edit, $_delete, $_Father, $_father, $_Mother, $_mother, $_toolhelp_edit_parent, $_toolhelp_add_parent, $_toolhelp_insert_parent, $_toolhelp_delete_parent;
    $parent_id = fetch_val("SELECT get_parent({$person}, {$gender})");
    $surety = fetch_val("\n        SELECT get_lsurety((\n            SELECT surety_fk\n            FROM relations\n            WHERE parent_fk = {$parent_id}\n            AND child_fk = {$person}\n        ), '{$language}')\n    ");
    if ($gender == 1) {
        $Parent = $_Father;
        $parent = $_father;
        $para = '<p>';
        $newline = '<br />';
    } else {
        // $gender == 2
        $Parent = $_Mother;
        $parent = $_mother;
        $para = '';
        $newline = '</p>';
    }
    echo $para . conc(bold($Parent) . ':') . conc(get_name_and_dates('', $parent_id));
    if ($parent_id) {
        echo conc(curly_brace($surety)) . conc(span_type(paren(to_url('./forms/relation_edit.php', array('person' => $person, 'parent' => $parent_id), $_edit, sprintf($_toolhelp_edit_parent, $parent)) . ' / ' . to_url('./forms/relation_delete.php', array('person' => $person, 'parent' => $parent_id), $_delete, sprintf($_toolhelp_delete_parent, $parent))), "hotlink")) . cite(get_relation_id($person, $gender), 'relation', $person);
    } else {
        echo conc(span_type(paren(to_url('./forms/person_insert.php', array('person' => $person, 'addparent' => 'true', 'gender' => $gender), "{$_Add} {$parent}", sprintf($_toolhelp_add_parent, $parent)) . ' / ' . to_url('./forms/relation_edit.php', array('person' => $person, 'gender' => $gender), "{$_Insert} {$parent}", sprintf($_toolhelp_insert_parent, $parent))), "hotlink"));
    }
    echo "{$newline}\n";
}