xref(); $cancel_url = $individual->url(); } elseif ($family !== null) { $xref = $family->xref(); $cancel_url = $family->url(); } else { $cancel_url = route('manage-trees', ['tree' => $tree->name()]); $xref = 'new'; } // Different cultures do surnames differently $surname_tradition = SurnameTradition::create($tree->getPreference('SURNAME_TRADITION')); if ($name_fact instanceof Fact) { // 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'), ]; } 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->husband(); if ($father instanceof Individual && $father->facts(['NAME'])->isNotEmpty()) { $father_name = $father->facts(['NAME'])->first()->value(); } else { $father_name = ''; } $mother = $family->wife(); if ($mother instanceof Individual && $mother->facts(['NAME'])->isNotEmpty()) { $mother_name = $mother->facts(['NAME'])->first()->value(); } else { $mother_name = ''; } } else { $father = null; $mother = null; $father_name = ''; $mother_name = ''; } if ($individual && $individual->facts(['NAME'])->isNotEmpty()) { $indi_name = $individual->facts(['NAME'])->first()->value(); } else { $indi_name = ''; } switch ($next_action) { 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->sex() === '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-individual-action': case 'add-name-action': case 'edit-name-action': 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, '', ''); } } // 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)); 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)); 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 ($next_action !== 'add-name-action' && $next_action !== 'edit-name-action') { $bdm = 'BD'; $tags = new Collection(); preg_match_all('/(' . Gedcom::REGEX_TAG . ')/', $tree->getPreference('QUICK_REQUIRED_FACTS'), $matches); $tags = $tags->merge($matches[1]); // If adding a spouse add the option to add a marriage fact to the new family if ($next_action === 'add-spouse-to-individual-action' || $next_action === 'add-spouse-to-family-action') { $bdm .= 'M'; preg_match_all('/(' . Gedcom::REGEX_TAG . ')/', $tree->getPreference('QUICK_REQUIRED_FAMFACTS'), $matches); $tags = $tags->merge($matches[1]); } foreach (Fact::sortFactTags($tags) as $tag) { echo view('cards/add-fact', [ 'tag' => $tag, 'tree' => $tree, ]); } } if ($next_action === 'edit-name-action' || $next_action === 'add-name-action') { // 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'))) : ?>