xref(); $cancel_url = $individual->url(); } elseif ($family !== null) { $xref = $family->xref(); $cancel_url = $family->url(); } else { $cancel_url = route('admin-trees'); $xref = 'new'; } // Different cultures do surnames differently $surname_tradition = SurnameTradition::create($tree->getPreference('SURNAME_TRADITION')); if ($name_fact !== null) { // Editing an existing name $name_fact_id = $name_fact->id(); $namerec = $name_fact->gedcom(); $name_fields = [ 'NAME' => $name_fact->value(), 'TYPE' => $name_fact->attribute('TYPE'), 'NPFX' => $name_fact->attribute('NPFX'), 'GIVN' => $name_fact->attribute('GIVN'), 'NICK' => $name_fact->attribute('NICK'), 'SPFX' => $name_fact->attribute('SPFX'), 'SURN' => $name_fact->attribute('SURN'), 'NSFX' => $name_fact->attribute('NSFX'), ]; // Populate any missing subfields from the NAME field $npfx_accept = implode('|', Config::namePrefixes()); if (preg_match('/(((' . $npfx_accept . ')\.? +)*)([^\n\/"]*)("(.*)")? *\/(([a-z]{2,3} +)*)(.*)\/ *(.*)/i', $name_fields['NAME'], $name_bits)) { $name_fields['NPFX'] = $name_fields['NPFX'] ?: $name_bits[1]; $name_fields['GIVN'] = $name_fields['GIVN'] ?: $name_bits[4]; $name_fields['NICK'] = $name_fields['NICK'] ?: $name_bits[6]; $name_fields['SPFX'] = $name_fields['SPFX'] ?: trim($name_bits[7]); $name_fields['SURN'] = $name_fields['SURN'] ?: preg_replace('~/[^/]*/~', ',', $name_bits[9]); $name_fields['NSFX'] = $name_fields['NSFX'] ?: $name_bits[10]; } } else { // Creating a new name $name_fact_id = ''; $namerec = ''; $name_fields = [ 'NAME' => '', 'TYPE' => '', 'NPFX' => '', 'GIVN' => '', 'NICK' => '', 'SPFX' => '', 'SURN' => '', 'NSFX' => '', ]; // Inherit surname from parents, spouse or child if ($family) { $father = $family->getHusband(); if ($father && $father->getFirstFact('NAME')) { $father_name = $father->getFirstFact('NAME')->value(); } else { $father_name = ''; } $mother = $family->getWife(); if ($mother && $mother->getFirstFact('NAME')) { $mother_name = $mother->getFirstFact('NAME')->value(); } else { $mother_name = ''; } } else { $father = null; $mother = null; $father_name = ''; $mother_name = ''; } if ($individual && $individual->getFirstFact('NAME')) { $indi_name = $individual->getFirstFact('NAME')->value(); } else { $indi_name = ''; } switch ($nextaction) { case 'add_child_to_family_action': $name_fields = array_merge($name_fields, $surname_tradition->newChildNames($father_name, $mother_name, $gender)); break; case 'add_child_to_individual_action': if ($individual->getSex() === 'F') { $name_fields = array_merge($name_fields, $surname_tradition->newChildNames('', $indi_name, $gender)); } else { $name_fields = array_merge($name_fields, $surname_tradition->newChildNames($indi_name, '', $gender)); } break; case 'add_parent_to_individual_action': $name_fields = array_merge($name_fields, $surname_tradition->newParentNames($indi_name, $gender)); break; case 'add_spouse_to_family_action': if ($father) { $name_fields = array_merge($name_fields, $surname_tradition->newSpouseNames($father_name, $gender)); } else { $name_fields = array_merge($name_fields, $surname_tradition->newSpouseNames($mother_name, $gender)); } break; case 'add_spouse_to_individual_action': $name_fields = array_merge($name_fields, $surname_tradition->newSpouseNames($indi_name, $gender)); break; case 'add_unlinked_indi_action': case 'update': if ($surname_tradition->hasSurnames()) { $name_fields['NAME'] = '//'; } break; } } $bdm = ''; // used to copy '1 SOUR' to '2 SOUR' for BIRT DEAT MARR ?>

$value) { if (substr_compare($tag, '_', 0, 1) !== 0) { echo FunctionsEdit::addSimpleTag($tree, '0 ' . $tag . ' ' . $value, '', '', $individual); } } // Second - advanced name fields if ($surname_tradition->hasMarriedNames() || preg_match('/\n2 _MARNM /', $namerec)) { $adv_name_fields = ['_MARNM' => '']; } else { $adv_name_fields = []; } if (preg_match_all('/(' . Gedcom::REGEX_TAG . ')/', $tree->getPreference('ADVANCED_NAME_FACTS'), $match)) { foreach ($match[1] as $tag) { // Ignore advanced facts that duplicate standard facts if (!in_array($tag, ['TYPE', 'NPFX', 'GIVN', 'NICK', 'SPFX', 'SURN', 'NSFX'])) { $adv_name_fields[$tag] = ''; } } } foreach (array_keys($adv_name_fields) as $tag) { // Edit existing tags, grouped together if (preg_match_all('/2 ' . $tag . ' (.+)/', $namerec, $match)) { foreach ($match[1] as $value) { echo FunctionsEdit::addSimpleTag($tree, '2 ' . $tag . ' ' . $value, '', GedcomTag::getLabel('NAME:' . $tag, $individual)); if ($tag === '_MARNM') { preg_match_all('/\/([^\/]*)\//', $value, $matches); echo FunctionsEdit::addSimpleTag($tree, '2 _MARNM_SURN ' . implode(',', $matches[1])); } } } // Allow a new tag to be entered if (!array_key_exists($tag, $name_fields)) { echo FunctionsEdit::addSimpleTag($tree, '0 ' . $tag, '', GedcomTag::getLabel('NAME:' . $tag, $individual)); if ($tag === '_MARNM') { echo FunctionsEdit::addSimpleTag($tree, '0 _MARNM_SURN'); } } } // Third - new/existing custom name fields foreach ($name_fields as $tag => $value) { if (substr_compare($tag, '_', 0, 1) === 0) { echo FunctionsEdit::addSimpleTag($tree, '0 ' . $tag . ' ' . $value); if ($tag === '_MARNM') { preg_match_all('/\/([^\/]*)\//', $value, $matches); echo FunctionsEdit::addSimpleTag($tree, '2 _MARNM_SURN ' . implode(',', $matches[1])); } } } // Fourth - SOUR, NOTE, _CUSTOM, etc. if ($namerec !== '') { $gedlines = explode("\n", $namerec); // -- find the number of lines in the record $fields = explode(' ', $gedlines[0]); $glevel = $fields[0]; $level = $glevel; $type = $fields[1]; $tags = []; $i = 0; do { if ($type !== 'TYPE' && !array_key_exists($type, $name_fields) && !array_key_exists($type, $adv_name_fields)) { $text = ''; for ($j = 2; $j < count($fields); $j++) { if ($j > 2) { $text .= ' '; } $text .= $fields[$j]; } while (($i + 1 < count($gedlines)) && (preg_match('/' . ($level + 1) . ' CONT ?(.*)/', $gedlines[$i + 1], $cmatch) > 0)) { $text .= "\n" . $cmatch[1]; $i++; } echo FunctionsEdit::addSimpleTag($tree, $level . ' ' . $type . ' ' . $text); } $tags[] = $type; $i++; if (isset($gedlines[$i])) { $fields = explode(' ', $gedlines[$i]); $level = $fields[0]; if (isset($fields[1])) { $type = $fields[1]; } } } while (($level > $glevel) && ($i < count($gedlines))); } // If we are adding a new individual, add the basic details if ($nextaction !== 'update') { echo '
'; // 1 SEX if ($famtag === 'HUSB' || $gender === 'M') { echo FunctionsEdit::addSimpleTag($tree, '0 SEX M'); } elseif ($famtag === 'WIFE' || $gender === 'F') { echo FunctionsEdit::addSimpleTag($tree, '0 SEX F'); } else { echo FunctionsEdit::addSimpleTag($tree, '0 SEX U'); } $bdm = 'BD'; if (preg_match_all('/(' . Gedcom::REGEX_TAG . ')/', $tree->getPreference('QUICK_REQUIRED_FACTS'), $matches)) { foreach ($matches[1] as $match) { if (!in_array($match, Gedcom::DEATH_EVENTS)) { FunctionsEdit::addSimpleTags($tree, $match); } } } //-- if adding a spouse add the option to add a marriage fact to the new family if ($nextaction === 'add_spouse_to_individual_action' || $nextaction === 'add_spouse_to_family_action') { $bdm .= 'M'; if (preg_match_all('/(' . Gedcom::REGEX_TAG . ')/', $tree->getPreference('QUICK_REQUIRED_FAMFACTS'), $matches)) { foreach ($matches[1] as $match) { FunctionsEdit::addSimpleTags($tree, $match); } } } if (preg_match_all('/(' . Gedcom::REGEX_TAG . ')/', $tree->getPreference('QUICK_REQUIRED_FACTS'), $matches)) { foreach ($matches[1] as $match) { if (in_array($match, Gedcom::DEATH_EVENTS)) { FunctionsEdit::addSimpleTags($tree, $match); } } } } echo '
'; if ($nextaction === 'update') { // GEDCOM 5.5.1 spec says NAME doesn’t get a OBJE echo view('cards/add-source-citation', [ 'level' => 2, 'full_citations' => $tree->getPreference('FULL_SOURCES'), 'tree' => $tree, ]); echo view('cards/add-note', [ 'level' => 2, 'tree' => $tree, ]); echo view('cards/add-shared-note', [ 'level' => 2, 'tree' => $tree, ]); echo view('cards/add-restriction', [ 'level' => 2, 'tree' => $tree, ]); } else { echo view('cards/add-source-citation', [ 'bdm' => $bdm, 'level' => 1, 'full_citations' => $tree->getPreference('FULL_SOURCES'), 'prefer_level2_sources' => $tree->getPreference('PREFER_LEVEL2_SOURCES'), 'quick_required_facts' => $tree->getPreference('QUICK_REQUIRED_FACTS'), 'quick_required_famfacts' => $tree->getPreference('QUICK_REQUIRED_FAMFACTS'), 'tree' => $tree, ]); echo view('cards/add-note', [ 'level' => 1, 'tree' => $tree, ]); echo view('cards/add-shared-note', [ 'level' => 1, 'tree' => $tree, ]); echo view('cards/add-restriction', [ 'level' => 1, 'tree' => $tree, ]); } ?>
getPreference('SHOW_GEDCOM_RECORD'))) : ?>