xref: /webtrees/resources/views/edit/new-individual.phtml (revision 820b62df142779302ed642942aa3676dd58f5906)
1*820b62dfSGreg Roach<?php
2*820b62dfSGreg Roach
3*820b62dfSGreg Roachuse Fisharebest\Webtrees\Auth;
4*820b62dfSGreg Roachuse Fisharebest\Webtrees\Config;
5*820b62dfSGreg Roachuse Fisharebest\Webtrees\Fact;
6*820b62dfSGreg Roachuse Fisharebest\Webtrees\Functions\FunctionsEdit;
7*820b62dfSGreg Roachuse Fisharebest\Webtrees\Gedcom;
8*820b62dfSGreg Roachuse Fisharebest\Webtrees\GedcomTag;
9*820b62dfSGreg Roachuse Fisharebest\Webtrees\I18N;
10*820b62dfSGreg Roachuse Fisharebest\Webtrees\Individual;
11*820b62dfSGreg Roachuse Fisharebest\Webtrees\SurnameTradition;
12*820b62dfSGreg Roachuse Fisharebest\Webtrees\View;
13*820b62dfSGreg Roach
14*820b62dfSGreg Roach/**
15*820b62dfSGreg Roach * @var Individual|null $individual
16*820b62dfSGreg Roach * @var Fact|null       $name_fact
17*820b62dfSGreg Roach */
18*820b62dfSGreg Roach
19*820b62dfSGreg Roach?>
20dd6b2bfcSGreg Roach
21dd6b2bfcSGreg Roach<?php
22*820b62dfSGreg Roachif ($individual instanceof Individual) {
23c0935879SGreg Roach    $xref       = $individual->xref();
24dd6b2bfcSGreg Roach    $cancel_url = $individual->url();
25dd6b2bfcSGreg Roach} elseif ($family !== null) {
26c0935879SGreg Roach    $xref       = $family->xref();
27dd6b2bfcSGreg Roach    $cancel_url = $family->url();
28dd6b2bfcSGreg Roach} else {
29dd6b2bfcSGreg Roach    $cancel_url = route('admin-trees');
30dd6b2bfcSGreg Roach    $xref       = 'new';
31dd6b2bfcSGreg Roach}
32dd6b2bfcSGreg Roach
33dd6b2bfcSGreg Roach// Different cultures do surnames differently
34dd6b2bfcSGreg Roach$surname_tradition = SurnameTradition::create($tree->getPreference('SURNAME_TRADITION'));
35dd6b2bfcSGreg Roach
36*820b62dfSGreg Roachif ($name_fact instanceof Fact) {
37dd6b2bfcSGreg Roach    // Editing an existing name
38905ab80aSGreg Roach    $name_fact_id = $name_fact->id();
39138ca96cSGreg Roach    $namerec      = $name_fact->gedcom();
40dd6b2bfcSGreg Roach    $name_fields  = [
4184586c02SGreg Roach        'NAME' => $name_fact->value(),
423425616eSGreg Roach        'TYPE' => $name_fact->attribute('TYPE'),
433425616eSGreg Roach        'NPFX' => $name_fact->attribute('NPFX'),
443425616eSGreg Roach        'GIVN' => $name_fact->attribute('GIVN'),
453425616eSGreg Roach        'NICK' => $name_fact->attribute('NICK'),
463425616eSGreg Roach        'SPFX' => $name_fact->attribute('SPFX'),
473425616eSGreg Roach        'SURN' => $name_fact->attribute('SURN'),
483425616eSGreg Roach        'NSFX' => $name_fact->attribute('NSFX'),
49dd6b2bfcSGreg Roach    ];
50dd6b2bfcSGreg Roach
51dd6b2bfcSGreg Roach    // Populate any missing subfields from the NAME field
52dd6b2bfcSGreg Roach    $npfx_accept = implode('|', Config::namePrefixes());
53dd6b2bfcSGreg Roach    if (preg_match('/(((' . $npfx_accept . ')\.? +)*)([^\n\/"]*)("(.*)")? *\/(([a-z]{2,3} +)*)(.*)\/ *(.*)/i', $name_fields['NAME'], $name_bits)) {
54dd6b2bfcSGreg Roach        $name_fields['NPFX'] = $name_fields['NPFX'] ?: $name_bits[1];
55dd6b2bfcSGreg Roach        $name_fields['GIVN'] = $name_fields['GIVN'] ?: $name_bits[4];
56dd6b2bfcSGreg Roach        $name_fields['NICK'] = $name_fields['NICK'] ?: $name_bits[6];
57dd6b2bfcSGreg Roach        $name_fields['SPFX'] = $name_fields['SPFX'] ?: trim($name_bits[7]);
58dd6b2bfcSGreg Roach        $name_fields['SURN'] = $name_fields['SURN'] ?: preg_replace('~/[^/]*/~', ',', $name_bits[9]);
59dd6b2bfcSGreg Roach        $name_fields['NSFX'] = $name_fields['NSFX'] ?: $name_bits[10];
60dd6b2bfcSGreg Roach    }
61dd6b2bfcSGreg Roach} else {
62dd6b2bfcSGreg Roach    // Creating a new name
63dd6b2bfcSGreg Roach    $name_fact_id = '';
64dd6b2bfcSGreg Roach    $namerec      = '';
65dd6b2bfcSGreg Roach    $name_fields  = [
66dd6b2bfcSGreg Roach        'NAME' => '',
67dd6b2bfcSGreg Roach        'TYPE' => '',
68dd6b2bfcSGreg Roach        'NPFX' => '',
69dd6b2bfcSGreg Roach        'GIVN' => '',
70dd6b2bfcSGreg Roach        'NICK' => '',
71dd6b2bfcSGreg Roach        'SPFX' => '',
72dd6b2bfcSGreg Roach        'SURN' => '',
73dd6b2bfcSGreg Roach        'NSFX' => '',
74dd6b2bfcSGreg Roach    ];
75dd6b2bfcSGreg Roach
76dd6b2bfcSGreg Roach    // Inherit surname from parents, spouse or child
77dd6b2bfcSGreg Roach    if ($family) {
7839ca88baSGreg Roach        $father = $family->husband();
79*820b62dfSGreg Roach        if ($father instanceof Individual && $father->facts(['NAME'])->isNotEmpty()) {
80*820b62dfSGreg Roach            $father_name = $father->facts(['NAME'])->first()->value();
81dd6b2bfcSGreg Roach        } else {
82dd6b2bfcSGreg Roach            $father_name = '';
83dd6b2bfcSGreg Roach        }
8439ca88baSGreg Roach        $mother = $family->wife();
85*820b62dfSGreg Roach        if ($mother instanceof Individual && $mother->facts(['NAME'])->isNotEmpty()) {
86*820b62dfSGreg Roach            $mother_name = $mother->facts(['NAME'])->first()->value();
87dd6b2bfcSGreg Roach        } else {
88dd6b2bfcSGreg Roach            $mother_name = '';
89dd6b2bfcSGreg Roach        }
90dd6b2bfcSGreg Roach    } else {
91dd6b2bfcSGreg Roach        $father      = null;
92dd6b2bfcSGreg Roach        $mother      = null;
93dd6b2bfcSGreg Roach        $father_name = '';
94dd6b2bfcSGreg Roach        $mother_name = '';
95dd6b2bfcSGreg Roach    }
96*820b62dfSGreg Roach    if ($individual && $individual->facts(['NAME'])->isNotEmpty()) {
97*820b62dfSGreg Roach        $indi_name = $individual->facts(['NAME'])->first()->value();
98dd6b2bfcSGreg Roach    } else {
99dd6b2bfcSGreg Roach        $indi_name = '';
100dd6b2bfcSGreg Roach    }
101dd6b2bfcSGreg Roach
102dd6b2bfcSGreg Roach    switch ($nextaction) {
103dd6b2bfcSGreg Roach        case 'add_child_to_family_action':
104dd6b2bfcSGreg Roach            $name_fields = array_merge($name_fields, $surname_tradition->newChildNames($father_name, $mother_name, $gender));
105dd6b2bfcSGreg Roach            break;
106dd6b2bfcSGreg Roach        case 'add_child_to_individual_action':
10739ca88baSGreg Roach            if ($individual->sex() === 'F') {
108dd6b2bfcSGreg Roach                $name_fields = array_merge($name_fields, $surname_tradition->newChildNames('', $indi_name, $gender));
109dd6b2bfcSGreg Roach            } else {
110dd6b2bfcSGreg Roach                $name_fields = array_merge($name_fields, $surname_tradition->newChildNames($indi_name, '', $gender));
111dd6b2bfcSGreg Roach            }
112dd6b2bfcSGreg Roach            break;
113dd6b2bfcSGreg Roach        case 'add_parent_to_individual_action':
114dd6b2bfcSGreg Roach            $name_fields = array_merge($name_fields, $surname_tradition->newParentNames($indi_name, $gender));
115dd6b2bfcSGreg Roach            break;
116dd6b2bfcSGreg Roach        case 'add_spouse_to_family_action':
117dd6b2bfcSGreg Roach            if ($father) {
118dd6b2bfcSGreg Roach                $name_fields = array_merge($name_fields, $surname_tradition->newSpouseNames($father_name, $gender));
119dd6b2bfcSGreg Roach            } else {
120dd6b2bfcSGreg Roach                $name_fields = array_merge($name_fields, $surname_tradition->newSpouseNames($mother_name, $gender));
121dd6b2bfcSGreg Roach            }
122dd6b2bfcSGreg Roach            break;
123dd6b2bfcSGreg Roach        case 'add_spouse_to_individual_action':
124dd6b2bfcSGreg Roach            $name_fields = array_merge($name_fields, $surname_tradition->newSpouseNames($indi_name, $gender));
125dd6b2bfcSGreg Roach            break;
126dd6b2bfcSGreg Roach        case 'add_unlinked_indi_action':
127dd6b2bfcSGreg Roach        case 'update':
128dd6b2bfcSGreg Roach            if ($surname_tradition->hasSurnames()) {
129dd6b2bfcSGreg Roach                $name_fields['NAME'] = '//';
130dd6b2bfcSGreg Roach            }
131dd6b2bfcSGreg Roach            break;
132dd6b2bfcSGreg Roach    }
133dd6b2bfcSGreg Roach}
134dd6b2bfcSGreg Roach
135dd6b2bfcSGreg Roach$bdm = ''; // used to copy '1 SOUR' to '2 SOUR' for BIRT DEAT MARR
136dd6b2bfcSGreg Roach
137dd6b2bfcSGreg Roach?>
138dd6b2bfcSGreg Roach<h2 class="wt-page-title"><?= $title ?></h2>
139dd6b2bfcSGreg Roach
140dd6b2bfcSGreg Roach<form method="post" onsubmit="return checkform();">
141aa6f03bbSGreg Roach    <input type="hidden" name="ged" value="<?= e($tree->name()) ?>">
142dd6b2bfcSGreg Roach    <input type="hidden" name="action" value="<?= e($nextaction) ?>">
143dd6b2bfcSGreg Roach    <input type="hidden" name="fact_id" value="<?= e($name_fact_id) ?>">
144dd6b2bfcSGreg Roach    <input type="hidden" name="xref" value="<?= e($xref) ?>">
145dd6b2bfcSGreg Roach    <input type="hidden" name="famtag" value="<?= e($famtag) ?>">
146dd6b2bfcSGreg Roach    <input type="hidden" name="gender" value="<?= $gender ?>">
147dd6b2bfcSGreg Roach    <?= csrf_field() ?>
148dd6b2bfcSGreg Roach
149dd6b2bfcSGreg Roach    <?php if ($nextaction === 'add_child_to_family_action' || $nextaction === 'add_child_to_individual_action') : ?>
150dd6b2bfcSGreg Roach        <?= FunctionsEdit::addSimpleTag($tree, '0 PEDI') ?>
151dd6b2bfcSGreg Roach    <?php endif ?>
152dd6b2bfcSGreg Roach
153dd6b2bfcSGreg Roach    <?php
154dd6b2bfcSGreg Roach    // First - standard name fields
155dd6b2bfcSGreg Roach    foreach ($name_fields as $tag => $value) {
156dd6b2bfcSGreg Roach        if (substr_compare($tag, '_', 0, 1) !== 0) {
157809fcb31SGreg Roach            echo FunctionsEdit::addSimpleTag($tree, '0 ' . $tag . ' ' . $value, '', '');
158dd6b2bfcSGreg Roach        }
159dd6b2bfcSGreg Roach    }
160dd6b2bfcSGreg Roach
161dd6b2bfcSGreg Roach    // Second - advanced name fields
162dd6b2bfcSGreg Roach    if ($surname_tradition->hasMarriedNames() || preg_match('/\n2 _MARNM /', $namerec)) {
163dd6b2bfcSGreg Roach        $adv_name_fields = ['_MARNM' => ''];
164dd6b2bfcSGreg Roach    } else {
165dd6b2bfcSGreg Roach        $adv_name_fields = [];
166dd6b2bfcSGreg Roach    }
1678d0ebef0SGreg Roach    if (preg_match_all('/(' . Gedcom::REGEX_TAG . ')/', $tree->getPreference('ADVANCED_NAME_FACTS'), $match)) {
168dd6b2bfcSGreg Roach        foreach ($match[1] as $tag) {
169dd6b2bfcSGreg Roach            // Ignore advanced facts that duplicate standard facts
170dd6b2bfcSGreg Roach            if (!in_array($tag, ['TYPE', 'NPFX', 'GIVN', 'NICK', 'SPFX', 'SURN', 'NSFX'])) {
171dd6b2bfcSGreg Roach                $adv_name_fields[$tag] = '';
172dd6b2bfcSGreg Roach            }
173dd6b2bfcSGreg Roach        }
174dd6b2bfcSGreg Roach    }
175dd6b2bfcSGreg Roach
176dd6b2bfcSGreg Roach    foreach (array_keys($adv_name_fields) as $tag) {
177dd6b2bfcSGreg Roach        // Edit existing tags, grouped together
178dd6b2bfcSGreg Roach        if (preg_match_all('/2 ' . $tag . ' (.+)/', $namerec, $match)) {
179dd6b2bfcSGreg Roach            foreach ($match[1] as $value) {
180dd6b2bfcSGreg Roach                echo FunctionsEdit::addSimpleTag($tree, '2 ' . $tag . ' ' . $value, '', GedcomTag::getLabel('NAME:' . $tag, $individual));
181dd6b2bfcSGreg Roach                if ($tag === '_MARNM') {
182dd6b2bfcSGreg Roach                    preg_match_all('/\/([^\/]*)\//', $value, $matches);
183dd6b2bfcSGreg Roach                    echo FunctionsEdit::addSimpleTag($tree, '2 _MARNM_SURN ' . implode(',', $matches[1]));
184dd6b2bfcSGreg Roach                }
185dd6b2bfcSGreg Roach            }
186dd6b2bfcSGreg Roach        }
187dd6b2bfcSGreg Roach        // Allow a new tag to be entered
188dd6b2bfcSGreg Roach        if (!array_key_exists($tag, $name_fields)) {
189dd6b2bfcSGreg Roach            echo FunctionsEdit::addSimpleTag($tree, '0 ' . $tag, '', GedcomTag::getLabel('NAME:' . $tag, $individual));
190dd6b2bfcSGreg Roach            if ($tag === '_MARNM') {
191dd6b2bfcSGreg Roach                echo FunctionsEdit::addSimpleTag($tree, '0 _MARNM_SURN');
192dd6b2bfcSGreg Roach            }
193dd6b2bfcSGreg Roach        }
194dd6b2bfcSGreg Roach    }
195dd6b2bfcSGreg Roach
196dd6b2bfcSGreg Roach    // Third - new/existing custom name fields
197dd6b2bfcSGreg Roach    foreach ($name_fields as $tag => $value) {
198dd6b2bfcSGreg Roach        if (substr_compare($tag, '_', 0, 1) === 0) {
199dd6b2bfcSGreg Roach            echo FunctionsEdit::addSimpleTag($tree, '0 ' . $tag . ' ' . $value);
200dd6b2bfcSGreg Roach            if ($tag === '_MARNM') {
201dd6b2bfcSGreg Roach                preg_match_all('/\/([^\/]*)\//', $value, $matches);
202dd6b2bfcSGreg Roach                echo FunctionsEdit::addSimpleTag($tree, '2 _MARNM_SURN ' . implode(',', $matches[1]));
203dd6b2bfcSGreg Roach            }
204dd6b2bfcSGreg Roach        }
205dd6b2bfcSGreg Roach    }
206dd6b2bfcSGreg Roach
207dd6b2bfcSGreg Roach    // Fourth - SOUR, NOTE, _CUSTOM, etc.
208dd6b2bfcSGreg Roach    if ($namerec !== '') {
209dd6b2bfcSGreg Roach        $gedlines = explode("\n", $namerec); // -- find the number of lines in the record
210dd6b2bfcSGreg Roach        $fields   = explode(' ', $gedlines[0]);
211dd6b2bfcSGreg Roach        $glevel   = $fields[0];
212dd6b2bfcSGreg Roach        $level    = $glevel;
213dd6b2bfcSGreg Roach        $type     = $fields[1];
214dd6b2bfcSGreg Roach        $tags     = [];
215dd6b2bfcSGreg Roach        $i        = 0;
216dd6b2bfcSGreg Roach        do {
217dd6b2bfcSGreg Roach            if ($type !== 'TYPE' && !array_key_exists($type, $name_fields) && !array_key_exists($type, $adv_name_fields)) {
218dd6b2bfcSGreg Roach                $text = '';
219dd6b2bfcSGreg Roach                for ($j = 2; $j < count($fields); $j++) {
220dd6b2bfcSGreg Roach                    if ($j > 2) {
221dd6b2bfcSGreg Roach                        $text .= ' ';
222dd6b2bfcSGreg Roach                    }
223dd6b2bfcSGreg Roach                    $text .= $fields[$j];
224dd6b2bfcSGreg Roach                }
225dd6b2bfcSGreg Roach                while (($i + 1 < count($gedlines)) && (preg_match('/' . ($level + 1) . ' CONT ?(.*)/', $gedlines[$i + 1], $cmatch) > 0)) {
226dd6b2bfcSGreg Roach                    $text .= "\n" . $cmatch[1];
227dd6b2bfcSGreg Roach                    $i++;
228dd6b2bfcSGreg Roach                }
229dd6b2bfcSGreg Roach                echo FunctionsEdit::addSimpleTag($tree, $level . ' ' . $type . ' ' . $text);
230dd6b2bfcSGreg Roach            }
231dd6b2bfcSGreg Roach            $tags[] = $type;
232dd6b2bfcSGreg Roach            $i++;
233dd6b2bfcSGreg Roach            if (isset($gedlines[$i])) {
234dd6b2bfcSGreg Roach                $fields = explode(' ', $gedlines[$i]);
235dd6b2bfcSGreg Roach                $level  = $fields[0];
236dd6b2bfcSGreg Roach                if (isset($fields[1])) {
237dd6b2bfcSGreg Roach                    $type = $fields[1];
238dd6b2bfcSGreg Roach                }
239dd6b2bfcSGreg Roach            }
240dd6b2bfcSGreg Roach        } while (($level > $glevel) && ($i < count($gedlines)));
241dd6b2bfcSGreg Roach    }
242dd6b2bfcSGreg Roach
243dd6b2bfcSGreg Roach    // If we are adding a new individual, add the basic details
244dd6b2bfcSGreg Roach    if ($nextaction !== 'update') {
245dd6b2bfcSGreg Roach        echo '</table><br><table class="table wt-facts-table">';
246dd6b2bfcSGreg Roach        // 1 SEX
247dd6b2bfcSGreg Roach        if ($famtag === 'HUSB' || $gender === 'M') {
248dd6b2bfcSGreg Roach            echo FunctionsEdit::addSimpleTag($tree, '0 SEX M');
249dd6b2bfcSGreg Roach        } elseif ($famtag === 'WIFE' || $gender === 'F') {
250dd6b2bfcSGreg Roach            echo FunctionsEdit::addSimpleTag($tree, '0 SEX F');
251dd6b2bfcSGreg Roach        } else {
252dd6b2bfcSGreg Roach            echo FunctionsEdit::addSimpleTag($tree, '0 SEX U');
253dd6b2bfcSGreg Roach        }
254dd6b2bfcSGreg Roach        $bdm = 'BD';
2558d0ebef0SGreg Roach        if (preg_match_all('/(' . Gedcom::REGEX_TAG . ')/', $tree->getPreference('QUICK_REQUIRED_FACTS'), $matches)) {
256dd6b2bfcSGreg Roach            foreach ($matches[1] as $match) {
2578d0ebef0SGreg Roach                if (!in_array($match, Gedcom::DEATH_EVENTS)) {
258dd6b2bfcSGreg Roach                    FunctionsEdit::addSimpleTags($tree, $match);
259dd6b2bfcSGreg Roach                }
260dd6b2bfcSGreg Roach            }
261dd6b2bfcSGreg Roach        }
262dd6b2bfcSGreg Roach        //-- if adding a spouse add the option to add a marriage fact to the new family
263dd6b2bfcSGreg Roach        if ($nextaction === 'add_spouse_to_individual_action' || $nextaction === 'add_spouse_to_family_action') {
264dd6b2bfcSGreg Roach            $bdm .= 'M';
2658d0ebef0SGreg Roach            if (preg_match_all('/(' . Gedcom::REGEX_TAG . ')/', $tree->getPreference('QUICK_REQUIRED_FAMFACTS'), $matches)) {
266dd6b2bfcSGreg Roach                foreach ($matches[1] as $match) {
267dd6b2bfcSGreg Roach                    FunctionsEdit::addSimpleTags($tree, $match);
268dd6b2bfcSGreg Roach                }
269dd6b2bfcSGreg Roach            }
270dd6b2bfcSGreg Roach        }
2718d0ebef0SGreg Roach        if (preg_match_all('/(' . Gedcom::REGEX_TAG . ')/', $tree->getPreference('QUICK_REQUIRED_FACTS'), $matches)) {
272dd6b2bfcSGreg Roach            foreach ($matches[1] as $match) {
2738d0ebef0SGreg Roach                if (in_array($match, Gedcom::DEATH_EVENTS)) {
274dd6b2bfcSGreg Roach                    FunctionsEdit::addSimpleTags($tree, $match);
275dd6b2bfcSGreg Roach                }
276dd6b2bfcSGreg Roach            }
277dd6b2bfcSGreg Roach        }
278dd6b2bfcSGreg Roach    }
279dd6b2bfcSGreg Roach
280dd6b2bfcSGreg Roach    echo '</table>';
281dd6b2bfcSGreg Roach    if ($nextaction === 'update') {
282dd6b2bfcSGreg Roach        // GEDCOM 5.5.1 spec says NAME doesn’t get a OBJE
283dd6b2bfcSGreg Roach        echo view('cards/add-source-citation', [
284dd6b2bfcSGreg Roach            'level'          => 2,
285dd6b2bfcSGreg Roach            'full_citations' => $tree->getPreference('FULL_SOURCES'),
286dd6b2bfcSGreg Roach            'tree'           => $tree,
287dd6b2bfcSGreg Roach        ]);
288dd6b2bfcSGreg Roach        echo view('cards/add-note', [
289dd6b2bfcSGreg Roach            'level' => 2,
290dd6b2bfcSGreg Roach            'tree'  => $tree,
291dd6b2bfcSGreg Roach        ]);
292dd6b2bfcSGreg Roach        echo view('cards/add-shared-note', [
293dd6b2bfcSGreg Roach            'level' => 2,
294dd6b2bfcSGreg Roach            'tree'  => $tree,
295dd6b2bfcSGreg Roach        ]);
296dd6b2bfcSGreg Roach        echo view('cards/add-restriction', [
297dd6b2bfcSGreg Roach            'level' => 2,
298dd6b2bfcSGreg Roach            'tree'  => $tree,
299dd6b2bfcSGreg Roach        ]);
300dd6b2bfcSGreg Roach    } else {
301dd6b2bfcSGreg Roach        echo view('cards/add-source-citation', [
302dd6b2bfcSGreg Roach            'bdm'                     => $bdm,
303dd6b2bfcSGreg Roach            'level'                   => 1,
304dd6b2bfcSGreg Roach            'full_citations'          => $tree->getPreference('FULL_SOURCES'),
305dd6b2bfcSGreg Roach            'prefer_level2_sources'   => $tree->getPreference('PREFER_LEVEL2_SOURCES'),
306dd6b2bfcSGreg Roach            'quick_required_facts'    => $tree->getPreference('QUICK_REQUIRED_FACTS'),
307dd6b2bfcSGreg Roach            'quick_required_famfacts' => $tree->getPreference('QUICK_REQUIRED_FAMFACTS'),
308dd6b2bfcSGreg Roach            'tree'                    => $tree,
309dd6b2bfcSGreg Roach        ]);
310dd6b2bfcSGreg Roach        echo view('cards/add-note', [
311dd6b2bfcSGreg Roach            'level' => 1,
312dd6b2bfcSGreg Roach            'tree'  => $tree,
313dd6b2bfcSGreg Roach        ]);
314dd6b2bfcSGreg Roach        echo view('cards/add-shared-note', [
315dd6b2bfcSGreg Roach            'level' => 1,
316dd6b2bfcSGreg Roach            'tree'  => $tree,
317dd6b2bfcSGreg Roach        ]);
318dd6b2bfcSGreg Roach        echo view('cards/add-restriction', [
319dd6b2bfcSGreg Roach            'level' => 1,
320dd6b2bfcSGreg Roach            'tree'  => $tree,
321dd6b2bfcSGreg Roach        ]);
322dd6b2bfcSGreg Roach    }
323dd6b2bfcSGreg Roach
324dd6b2bfcSGreg Roach    ?>
325dd6b2bfcSGreg Roach    <div class="row form-group">
326dd6b2bfcSGreg Roach        <div class="col-sm-9 offset-sm-3">
327dd6b2bfcSGreg Roach            <button class="btn btn-primary" type="submit">
328d993d560SGreg Roach                <?= view('icons/save') ?>
329dd6b2bfcSGreg Roach                <?= /* I18N: A button label. */
330dd6b2bfcSGreg Roach                I18N::translate('save') ?>
331dd6b2bfcSGreg Roach            </button>
332dd6b2bfcSGreg Roach            <?php if (preg_match('/^add_(child|spouse|parent|unlinked_indi)/', $nextaction)) : ?>
333dd6b2bfcSGreg Roach                <button class="btn btn-primary" type="submit" name="goto" value="<?= $xref ?>">
334d993d560SGreg Roach                    <?= view('icons/save') ?>
335dd6b2bfcSGreg Roach                    <?= /* I18N: A button label. */
336dd6b2bfcSGreg Roach                    I18N::translate('go to new individual') ?>
337dd6b2bfcSGreg Roach                </button>
338dd6b2bfcSGreg Roach            <?php endif ?>
339dd6b2bfcSGreg Roach            <a class="btn btn-secondary" href="<?= e($cancel_url) ?>">
340d993d560SGreg Roach                <?= view('icons/cancel') ?>
341dd6b2bfcSGreg Roach                <?= /* I18N: A button label. */
342dd6b2bfcSGreg Roach                I18N::translate('cancel') ?>
343dd6b2bfcSGreg Roach            </a>
344dd6b2bfcSGreg Roach
345dd6b2bfcSGreg Roach            <?php if ($name_fact instanceof Fact && (Auth::isAdmin() || $tree->getPreference('SHOW_GEDCOM_RECORD'))) : ?>
346aa6f03bbSGreg Roach                <a class="btn btn-link" href="<?= e(route('edit-raw-fact', ['xref' => $xref, 'fact_id' => $name_fact->id(), 'ged' => $tree->name()])) ?>">
347dd6b2bfcSGreg Roach                    <?= I18N::translate('Edit the raw GEDCOM') ?>
348dd6b2bfcSGreg Roach                </a>
349dd6b2bfcSGreg Roach            <?php endif ?>
350dd6b2bfcSGreg Roach        </div>
351dd6b2bfcSGreg Roach    </div>
352dd6b2bfcSGreg Roach</form>
353dd6b2bfcSGreg Roach
354dd6b2bfcSGreg Roach<?= view('modals/on-screen-keyboard') ?>
355dd6b2bfcSGreg Roach<?= view('modals/ajax') ?>
356dd6b2bfcSGreg Roach<?= view('edit/initialize-calendar-popup') ?>
357dd6b2bfcSGreg Roach
358dd6b2bfcSGreg Roach<?php View::push('javascript') ?>
359dd6b2bfcSGreg Roach<script>
360dd6b2bfcSGreg Roach    var SURNAME_TRADITION = <?= json_encode($tree->getPreference('SURNAME_TRADITION')) ?>;
361dd6b2bfcSGreg Roach    var gender            = <?= json_encode($gender) ?>;
362dd6b2bfcSGreg Roach    var famtag            = <?= json_encode($famtag) ?>;
363dd6b2bfcSGreg Roach
364dd6b2bfcSGreg Roach    var NAME = $("[name=NAME]");
365dd6b2bfcSGreg Roach
366dd6b2bfcSGreg Roach    function trim(str) {
367dd6b2bfcSGreg Roach        str = str.replace(/\s\s+/g, " ");
368dd6b2bfcSGreg Roach        return str.replace(/(^\s+)|(\s+$)/g, "");
369dd6b2bfcSGreg Roach    }
370dd6b2bfcSGreg Roach
371dd6b2bfcSGreg Roach    function lang_class(str) {
372dd6b2bfcSGreg Roach        if (str.match(/[\u0370-\u03FF]/)) return "greek";
373dd6b2bfcSGreg Roach        if (str.match(/[\u0400-\u04FF]/)) return "cyrillic";
374dd6b2bfcSGreg Roach        if (str.match(/[\u0590-\u05FF]/)) return "hebrew";
375dd6b2bfcSGreg Roach        if (str.match(/[\u0600-\u06FF]/)) return "arabic";
376dd6b2bfcSGreg Roach        return "latin"; // No matched text implies latin :-)
377dd6b2bfcSGreg Roach    }
378dd6b2bfcSGreg Roach
379dd6b2bfcSGreg Roach    // Generate a full name from the name components
380dd6b2bfcSGreg Roach    function generate_name() {
381dd6b2bfcSGreg Roach        var npfx = $("[name=NPFX]").val();
382dd6b2bfcSGreg Roach        var givn = $("[name=GIVN]").val();
383dd6b2bfcSGreg Roach        var spfx = $("[name=SPFX]").val();
384dd6b2bfcSGreg Roach        var surn = $("[name=SURN]").val();
385dd6b2bfcSGreg Roach        var nsfx = $("[name=NSFX]").val();
386dd6b2bfcSGreg Roach
387dd6b2bfcSGreg Roach        if (SURNAME_TRADITION === "polish" && (gender === "F" || famtag === "WIFE")) {
388dd6b2bfcSGreg Roach            surn = surn.replace(/ski$/, "ska");
389dd6b2bfcSGreg Roach            surn = surn.replace(/cki$/, "cka");
390dd6b2bfcSGreg Roach            surn = surn.replace(/dzki$/, "dzka");
391dd6b2bfcSGreg Roach            surn = surn.replace(/żki$/, "żka");
392dd6b2bfcSGreg Roach        }
393dd6b2bfcSGreg Roach
394dd6b2bfcSGreg Roach        // Commas are used in the GIVN and SURN field to separate lists of surnames.
395dd6b2bfcSGreg Roach        // For example, to differentiate the two Spanish surnames from an English
396dd6b2bfcSGreg Roach        // double-barred name.
397dd6b2bfcSGreg Roach        // Commas *may* be used in other fields, and will form part of the NAME.
398dd6b2bfcSGreg Roach        var locale = document.documentElement.lang;
399dd6b2bfcSGreg Roach        if (locale === "vi" || locale === "hu") {
400dd6b2bfcSGreg Roach            // Default format: /SURN/ GIVN
401dd6b2bfcSGreg Roach            return trim(npfx + " /" + trim(spfx + " " + surn).replace(/ *, */g, " ") + "/ " + givn.replace(/ *, */g, " ") + " " + nsfx);
402dd6b2bfcSGreg Roach        } else if (locale === "zh-Hans" || locale === "zh-Hant") {
403dd6b2bfcSGreg Roach            // Default format: /SURN/GIVN
404dd6b2bfcSGreg Roach            return npfx + "/" + spfx + surn + "/" + givn + nsfx;
405dd6b2bfcSGreg Roach        } else {
406dd6b2bfcSGreg Roach            // Default format: GIVN /SURN/
407dd6b2bfcSGreg Roach            return trim(npfx + " " + givn.replace(/ *, */g, " ") + " /" + trim(spfx + " " + surn).replace(/ *, */g, " ") + "/ " + nsfx);
408dd6b2bfcSGreg Roach        }
409dd6b2bfcSGreg Roach    }
410dd6b2bfcSGreg Roach
411dd6b2bfcSGreg Roach    // Update the NAME and _MARNM fields from the name components
412dd6b2bfcSGreg Roach    // and also display the value in read-only "gedcom" format.
413dd6b2bfcSGreg Roach    function updatewholename() {
414dd6b2bfcSGreg Roach        // Don’t update the name if the user manually changed it
415dd6b2bfcSGreg Roach        if (manualChange) {
416dd6b2bfcSGreg Roach            return;
417dd6b2bfcSGreg Roach        }
418dd6b2bfcSGreg Roach
419dd6b2bfcSGreg Roach        var npfx = $("[name=NPFX]").val();
420dd6b2bfcSGreg Roach        var givn = $("[name=GIVN]").val();
421dd6b2bfcSGreg Roach        var spfx = $("[name=SPFX]").val();
422dd6b2bfcSGreg Roach        var surn = $("[name=SURN]").val();
423dd6b2bfcSGreg Roach        var nsfx = $("[name=NSFX]").val();
424dd6b2bfcSGreg Roach        var name = generate_name();
425dd6b2bfcSGreg Roach
426*820b62dfSGreg Roach        var display_id = NAME.attr("id") + "_display";
427dd6b2bfcSGreg Roach
428dd6b2bfcSGreg Roach        NAME.val(name);
429dd6b2bfcSGreg Roach        $("#" + display_id).text(name);
430dd6b2bfcSGreg Roach        // Married names inherit some NSFX values, but not these
431dd6b2bfcSGreg Roach        nsfx = nsfx.replace(/^(I|II|III|IV|V|VI|Junior|Jr\.?|Senior|Sr\.?)$/i, "");
432dd6b2bfcSGreg Roach        // Update _MARNM field from _MARNM_SURN field and display it
433dd6b2bfcSGreg Roach        // Be careful of mixing latin/hebrew/etc. character sets.
434dd6b2bfcSGreg Roach        var ip       = document.getElementsByTagName("input");
435dd6b2bfcSGreg Roach        var marnm_id = "";
436dd6b2bfcSGreg Roach        var romn     = "";
437dd6b2bfcSGreg Roach        var heb      = "";
438dd6b2bfcSGreg Roach        for (var i = 0; i < ip.length; i++) {
439dd6b2bfcSGreg Roach            var val = trim(ip[i].value);
440dd6b2bfcSGreg Roach            if (ip[i].id.indexOf("_HEB") === 0)
441dd6b2bfcSGreg Roach                heb = val;
442dd6b2bfcSGreg Roach            if (ip[i].id.indexOf("ROMN") === 0)
443dd6b2bfcSGreg Roach                romn = val;
444dd6b2bfcSGreg Roach            if (ip[i].id.indexOf("_MARNM") === 0) {
445dd6b2bfcSGreg Roach                if (ip[i].id.indexOf("_MARNM_SURN") === 0) {
446dd6b2bfcSGreg Roach                    var msurn = "";
447dd6b2bfcSGreg Roach                    if (val !== "") {
448dd6b2bfcSGreg Roach                        var lc = lang_class(document.getElementById(ip[i].id).value);
449dd6b2bfcSGreg Roach                        if (lang_class(name) === lc)
450dd6b2bfcSGreg Roach                            msurn = trim(npfx + " " + givn + " /" + val + "/ " + nsfx);
451dd6b2bfcSGreg Roach                        else if (lc === "hebrew")
452dd6b2bfcSGreg Roach                            msurn = heb.replace(/\/.*\//, "/" + val + "/");
453dd6b2bfcSGreg Roach                        else if (lang_class(romn) === lc)
454dd6b2bfcSGreg Roach                            msurn = romn.replace(/\/.*\//, "/" + val + "/");
455dd6b2bfcSGreg Roach                    }
456dd6b2bfcSGreg Roach                    document.getElementById(marnm_id).value                  = msurn;
457dd6b2bfcSGreg Roach                    document.getElementById(marnm_id + "_display").innerHTML = msurn;
458dd6b2bfcSGreg Roach                } else {
459dd6b2bfcSGreg Roach                    marnm_id = ip[i].id;
460dd6b2bfcSGreg Roach                }
461dd6b2bfcSGreg Roach            }
462dd6b2bfcSGreg Roach        }
463dd6b2bfcSGreg Roach    }
464dd6b2bfcSGreg Roach
465dd6b2bfcSGreg Roach    // Toggle the name editor fields between
466dd6b2bfcSGreg Roach    // <input type="hidden"> <span style="display:inline">
467dd6b2bfcSGreg Roach    // <input type="text">   <span style="display:none">
468dd6b2bfcSGreg Roach
469dd6b2bfcSGreg Roach    var oldName = "";
470dd6b2bfcSGreg Roach
471dd6b2bfcSGreg Roach    // Calls to generate_name() trigger an update - hence need to
472dd6b2bfcSGreg Roach    // set the manual change to true first. We are probably
473dd6b2bfcSGreg Roach    // listening to the wrong events on the input fields...
474dd6b2bfcSGreg Roach    var manualChange = generate_name() !== NAME.val();
475dd6b2bfcSGreg Roach
476dd6b2bfcSGreg Roach    function convertHidden(eid) {
477dd6b2bfcSGreg Roach        var input1 = $("#" + eid);
478dd6b2bfcSGreg Roach        var input2 = $("#" + eid + "_display");
479dd6b2bfcSGreg Roach        // Note that IE does not allow us to change the type of an input, so we must create a new one.
480dd6b2bfcSGreg Roach        if (input1.attr("type") === "hidden") {
481dd6b2bfcSGreg Roach            input1.replaceWith(input1.clone().attr("type", "text"));
482dd6b2bfcSGreg Roach            input2.hide();
483dd6b2bfcSGreg Roach        } else {
484dd6b2bfcSGreg Roach            input1.replaceWith(input1.clone().attr("type", "hidden"));
485dd6b2bfcSGreg Roach            input2.show();
486dd6b2bfcSGreg Roach        }
487dd6b2bfcSGreg Roach    }
488dd6b2bfcSGreg Roach
489dd6b2bfcSGreg Roach    /**
490dd6b2bfcSGreg Roach     * if the user manually changed the NAME field, then update the textual
491dd6b2bfcSGreg Roach     * HTML representation of it
492dd6b2bfcSGreg Roach     * If the value changed set manualChange to true so that changing
493dd6b2bfcSGreg Roach     * the other fields doesn’t change the NAME line
494dd6b2bfcSGreg Roach     */
495dd6b2bfcSGreg Roach    function updateTextName(eid) {
496dd6b2bfcSGreg Roach        var element = document.getElementById(eid);
497dd6b2bfcSGreg Roach        if (element) {
498dd6b2bfcSGreg Roach            if (element.value !== oldName) {
499dd6b2bfcSGreg Roach                manualChange = true;
500dd6b2bfcSGreg Roach            }
501dd6b2bfcSGreg Roach            var delement = document.getElementById(eid + "_display");
502dd6b2bfcSGreg Roach            if (delement) {
503dd6b2bfcSGreg Roach                delement.innerHTML = element.value;
504dd6b2bfcSGreg Roach            }
505dd6b2bfcSGreg Roach        }
506dd6b2bfcSGreg Roach    }
507dd6b2bfcSGreg Roach
508dd6b2bfcSGreg Roach    function checkform() {
509dd6b2bfcSGreg Roach        var ip = document.getElementsByTagName("input");
510dd6b2bfcSGreg Roach        for (var i = 0; i < ip.length; i++) {
511dd6b2bfcSGreg Roach            // ADD slashes to _HEB and _AKA names
512dd6b2bfcSGreg Roach            if (ip[i].id.indexOf("_AKA") === 0 || ip[i].id.indexOf("_HEB") === 0 || ip[i].id.indexOf("ROMN") === 0)
513dd6b2bfcSGreg Roach                if (ip[i].value.indexOf("/") < 0 && ip[i].value !== "")
514dd6b2bfcSGreg Roach                    ip[i].value = ip[i].value.replace(/([^\s]+)\s*$/, "/$1/");
515dd6b2bfcSGreg Roach            // Blank out temporary _MARNM_SURN
516dd6b2bfcSGreg Roach            if (ip[i].id.indexOf("_MARNM_SURN") === 0)
517dd6b2bfcSGreg Roach                ip[i].value = "";
518dd6b2bfcSGreg Roach            // Convert "xxx yyy" and "xxx y yyy" surnames to "xxx,yyy"
519dd6b2bfcSGreg Roach            if ((SURNAME_TRADITION === "spanish" || "SURNAME_TRADITION" === "portuguese") && ip[i].id.indexOf("SURN") === 0) {
520dd6b2bfcSGreg Roach                ip[i].value = document.forms[0].SURN.value.replace(/^\s*([^\s,]{2,})\s+([iIyY] +)?([^\s,]{2,})\s*$/, "$1,$3");
521dd6b2bfcSGreg Roach            }
522dd6b2bfcSGreg Roach        }
523dd6b2bfcSGreg Roach        return true;
524dd6b2bfcSGreg Roach    }
525dd6b2bfcSGreg Roach
526dd6b2bfcSGreg Roach    // If the name isnt initially formed from the components in a standard way,
527dd6b2bfcSGreg Roach    // then dont automatically update it.
528dd6b2bfcSGreg Roach    if (NAME.val() !== generate_name() && NAME.val() !== "//") {
529dd6b2bfcSGreg Roach        convertHidden(NAME.attr("id"));
530dd6b2bfcSGreg Roach    }
531dd6b2bfcSGreg Roach</script>
532dd6b2bfcSGreg Roach<?php View::endpush() ?>
533dd6b2bfcSGreg Roach
534