xref: /webtrees/resources/views/edit/new-individual.phtml (revision 5d7ac01841c200d265671e82d6c805b85db90364)
1820b62dfSGreg Roach<?php
2820b62dfSGreg Roach
3820b62dfSGreg Roachuse Fisharebest\Webtrees\Auth;
4820b62dfSGreg Roachuse Fisharebest\Webtrees\Fact;
5*5d7ac018SGreg Roachuse Fisharebest\Webtrees\Family;
6820b62dfSGreg Roachuse Fisharebest\Webtrees\Functions\FunctionsEdit;
7820b62dfSGreg Roachuse Fisharebest\Webtrees\Gedcom;
8820b62dfSGreg Roachuse Fisharebest\Webtrees\GedcomTag;
97c7d1e03SGreg Roachuse Fisharebest\Webtrees\Http\RequestHandlers\AddChildToFamilyAction;
107c7d1e03SGreg Roachuse Fisharebest\Webtrees\Http\RequestHandlers\AddChildToIndividualAction;
117c7d1e03SGreg Roachuse Fisharebest\Webtrees\Http\RequestHandlers\AddParentToIndividualAction;
127c7d1e03SGreg Roachuse Fisharebest\Webtrees\Http\RequestHandlers\AddSpouseToFamilyAction;
137c7d1e03SGreg Roachuse Fisharebest\Webtrees\Http\RequestHandlers\AddSpouseToIndividualAction;
147c7d1e03SGreg Roachuse Fisharebest\Webtrees\Http\RequestHandlers\AddUnlinkedAction;
153b3db8adSGreg Roachuse Fisharebest\Webtrees\Http\RequestHandlers\EditRawFactPage;
1655749c76SGreg Roachuse Fisharebest\Webtrees\Http\RequestHandlers\EditFactAction;
176fd01894SGreg Roachuse Fisharebest\Webtrees\Http\RequestHandlers\ManageTrees;
18820b62dfSGreg Roachuse Fisharebest\Webtrees\I18N;
19820b62dfSGreg Roachuse Fisharebest\Webtrees\Individual;
20820b62dfSGreg Roachuse Fisharebest\Webtrees\SurnameTradition;
21820b62dfSGreg Roachuse Fisharebest\Webtrees\View;
22ae71f733SGreg Roachuse Illuminate\Support\Collection;
23820b62dfSGreg Roach
24820b62dfSGreg Roach/**
25*5d7ac018SGreg Roach * @var Family|null     $family
26*5d7ac018SGreg Roach * @var string          $famtag
27*5d7ac018SGreg Roach * @var string          $gender
28820b62dfSGreg Roach * @var Individual|null $individual
29820b62dfSGreg Roach * @var Fact|null       $name_fact
30*5d7ac018SGreg Roach * @var string          $next_action
31*5d7ac018SGreg Roach * @var string          $title
32820b62dfSGreg Roach */
33820b62dfSGreg Roach
34820b62dfSGreg Roach?>
35dd6b2bfcSGreg Roach
36dd6b2bfcSGreg Roach<?php
37820b62dfSGreg Roachif ($individual instanceof Individual) {
38c0935879SGreg Roach    $xref       = $individual->xref();
39dd6b2bfcSGreg Roach    $cancel_url = $individual->url();
40dd6b2bfcSGreg Roach} elseif ($family !== null) {
41c0935879SGreg Roach    $xref       = $family->xref();
42dd6b2bfcSGreg Roach    $cancel_url = $family->url();
43dd6b2bfcSGreg Roach} else {
446fd01894SGreg Roach    $cancel_url = route(ManageTrees::class, ['tree' => $tree->name()]);
45dd6b2bfcSGreg Roach    $xref       = 'new';
46dd6b2bfcSGreg Roach}
47dd6b2bfcSGreg Roach
48dd6b2bfcSGreg Roach// Different cultures do surnames differently
49dd6b2bfcSGreg Roach$surname_tradition = SurnameTradition::create($tree->getPreference('SURNAME_TRADITION'));
50dd6b2bfcSGreg Roach
51820b62dfSGreg Roachif ($name_fact instanceof Fact) {
52dd6b2bfcSGreg Roach    // Editing an existing name
53905ab80aSGreg Roach    $name_fact_id = $name_fact->id();
54138ca96cSGreg Roach    $namerec      = $name_fact->gedcom();
55dd6b2bfcSGreg Roach    $name_fields  = [
5684586c02SGreg Roach        'NAME' => $name_fact->value(),
573425616eSGreg Roach        'TYPE' => $name_fact->attribute('TYPE'),
583425616eSGreg Roach        'NPFX' => $name_fact->attribute('NPFX'),
593425616eSGreg Roach        'GIVN' => $name_fact->attribute('GIVN'),
603425616eSGreg Roach        'NICK' => $name_fact->attribute('NICK'),
613425616eSGreg Roach        'SPFX' => $name_fact->attribute('SPFX'),
623425616eSGreg Roach        'SURN' => $name_fact->attribute('SURN'),
633425616eSGreg Roach        'NSFX' => $name_fact->attribute('NSFX'),
64dd6b2bfcSGreg Roach    ];
65dd6b2bfcSGreg Roach} else {
66dd6b2bfcSGreg Roach    // Creating a new name
67dd6b2bfcSGreg Roach    $name_fact_id = '';
68dd6b2bfcSGreg Roach    $namerec      = '';
69dd6b2bfcSGreg Roach    $name_fields  = [
70dd6b2bfcSGreg Roach        'NAME' => '',
71dd6b2bfcSGreg Roach        'TYPE' => '',
72dd6b2bfcSGreg Roach        'NPFX' => '',
73dd6b2bfcSGreg Roach        'GIVN' => '',
74dd6b2bfcSGreg Roach        'NICK' => '',
75dd6b2bfcSGreg Roach        'SPFX' => '',
76dd6b2bfcSGreg Roach        'SURN' => '',
77dd6b2bfcSGreg Roach        'NSFX' => '',
78dd6b2bfcSGreg Roach    ];
79dd6b2bfcSGreg Roach
80dd6b2bfcSGreg Roach    // Inherit surname from parents, spouse or child
81dd6b2bfcSGreg Roach    if ($family) {
8239ca88baSGreg Roach        $father = $family->husband();
83820b62dfSGreg Roach        if ($father instanceof Individual && $father->facts(['NAME'])->isNotEmpty()) {
84820b62dfSGreg Roach            $father_name = $father->facts(['NAME'])->first()->value();
85dd6b2bfcSGreg Roach        } else {
86dd6b2bfcSGreg Roach            $father_name = '';
87dd6b2bfcSGreg Roach        }
8839ca88baSGreg Roach        $mother = $family->wife();
89820b62dfSGreg Roach        if ($mother instanceof Individual && $mother->facts(['NAME'])->isNotEmpty()) {
90820b62dfSGreg Roach            $mother_name = $mother->facts(['NAME'])->first()->value();
91dd6b2bfcSGreg Roach        } else {
92dd6b2bfcSGreg Roach            $mother_name = '';
93dd6b2bfcSGreg Roach        }
94dd6b2bfcSGreg Roach    } else {
95dd6b2bfcSGreg Roach        $father      = null;
96dd6b2bfcSGreg Roach        $mother      = null;
97dd6b2bfcSGreg Roach        $father_name = '';
98dd6b2bfcSGreg Roach        $mother_name = '';
99dd6b2bfcSGreg Roach    }
100820b62dfSGreg Roach    if ($individual && $individual->facts(['NAME'])->isNotEmpty()) {
101820b62dfSGreg Roach        $indi_name = $individual->facts(['NAME'])->first()->value();
102dd6b2bfcSGreg Roach    } else {
103dd6b2bfcSGreg Roach        $indi_name = '';
104dd6b2bfcSGreg Roach    }
105dd6b2bfcSGreg Roach
10683615acfSGreg Roach    switch ($next_action) {
1077c7d1e03SGreg Roach        case AddChildToFamilyAction::class:
108dd6b2bfcSGreg Roach            $name_fields = array_merge($name_fields, $surname_tradition->newChildNames($father_name, $mother_name, $gender));
109dd6b2bfcSGreg Roach            break;
1107c7d1e03SGreg Roach        case AddChildToIndividualAction::class:
11139ca88baSGreg Roach            if ($individual->sex() === 'F') {
112dd6b2bfcSGreg Roach                $name_fields = array_merge($name_fields, $surname_tradition->newChildNames('', $indi_name, $gender));
113dd6b2bfcSGreg Roach            } else {
114dd6b2bfcSGreg Roach                $name_fields = array_merge($name_fields, $surname_tradition->newChildNames($indi_name, '', $gender));
115dd6b2bfcSGreg Roach            }
116dd6b2bfcSGreg Roach            break;
1177c7d1e03SGreg Roach        case AddParentToIndividualAction::class:
118dd6b2bfcSGreg Roach            $name_fields = array_merge($name_fields, $surname_tradition->newParentNames($indi_name, $gender));
119dd6b2bfcSGreg Roach            break;
1207c7d1e03SGreg Roach        case AddSpouseToFamilyAction::class:
121dd6b2bfcSGreg Roach            if ($father) {
122dd6b2bfcSGreg Roach                $name_fields = array_merge($name_fields, $surname_tradition->newSpouseNames($father_name, $gender));
123dd6b2bfcSGreg Roach            } else {
124dd6b2bfcSGreg Roach                $name_fields = array_merge($name_fields, $surname_tradition->newSpouseNames($mother_name, $gender));
125dd6b2bfcSGreg Roach            }
126dd6b2bfcSGreg Roach            break;
1277c7d1e03SGreg Roach        case AddSpouseToIndividualAction::class:
128dd6b2bfcSGreg Roach            $name_fields = array_merge($name_fields, $surname_tradition->newSpouseNames($indi_name, $gender));
129dd6b2bfcSGreg Roach            break;
1307c7d1e03SGreg Roach        case AddUnlinkedAction::class:
13155749c76SGreg Roach        case EditFactAction::class:
132dd6b2bfcSGreg Roach            if ($surname_tradition->hasSurnames()) {
133dd6b2bfcSGreg Roach                $name_fields['NAME'] = '//';
134dd6b2bfcSGreg Roach            }
135dd6b2bfcSGreg Roach            break;
136dd6b2bfcSGreg Roach    }
137dd6b2bfcSGreg Roach}
138dd6b2bfcSGreg Roach
139dd6b2bfcSGreg Roach$bdm = ''; // used to copy '1 SOUR' to '2 SOUR' for BIRT DEAT MARR
140dd6b2bfcSGreg Roach
141dd6b2bfcSGreg Roach?>
142dd6b2bfcSGreg Roach<h2 class="wt-page-title"><?= $title ?></h2>
143dd6b2bfcSGreg Roach
14448d3aca6SGreg Roach<form method="post" action="<?= e(route($next_action, ['tree' => $tree->name(), 'xref' => $xref, 'fact_id' => $name_fact ? $name_fact->id() : null])) ?>" onsubmit="return checkform();">
145dd6b2bfcSGreg Roach    <input type="hidden" name="fact_id" value="<?= e($name_fact_id) ?>">
146dd6b2bfcSGreg Roach    <input type="hidden" name="famtag" value="<?= e($famtag) ?>">
147dd6b2bfcSGreg Roach    <input type="hidden" name="gender" value="<?= $gender ?>">
148dd6b2bfcSGreg Roach    <?= csrf_field() ?>
149dd6b2bfcSGreg Roach
1507c7d1e03SGreg Roach    <?php if ($next_action === AddChildToFamilyAction::class || $next_action === AddChildToIndividualAction::class) : ?>
151dd6b2bfcSGreg Roach        <?= FunctionsEdit::addSimpleTag($tree, '0 PEDI') ?>
152dd6b2bfcSGreg Roach    <?php endif ?>
153dd6b2bfcSGreg Roach
154dd6b2bfcSGreg Roach    <?php
1555eca9df6SGreg Roach    // If we are adding a new individual, choose the sex.
15655749c76SGreg Roach    if ($next_action !== EditFactAction::class) {
1575eca9df6SGreg Roach        if ($famtag === 'HUSB' || $gender === 'M') {
1585eca9df6SGreg Roach            echo FunctionsEdit::addSimpleTag($tree, '0 SEX M');
1595eca9df6SGreg Roach        } elseif ($famtag === 'WIFE' || $gender === 'F') {
1605eca9df6SGreg Roach            echo FunctionsEdit::addSimpleTag($tree, '0 SEX F');
1615eca9df6SGreg Roach        } else {
1627728b506SGreg Roach            echo FunctionsEdit::addSimpleTag($tree, '0 SEX');
1635eca9df6SGreg Roach        }
1645eca9df6SGreg Roach    }
1655eca9df6SGreg Roach    ?>
1665eca9df6SGreg Roach
1675eca9df6SGreg Roach    <?php
168dd6b2bfcSGreg Roach    // First - standard name fields
169dd6b2bfcSGreg Roach    foreach ($name_fields as $tag => $value) {
170dd6b2bfcSGreg Roach        if (substr_compare($tag, '_', 0, 1) !== 0) {
171809fcb31SGreg Roach            echo FunctionsEdit::addSimpleTag($tree, '0 ' . $tag . ' ' . $value, '', '');
172dd6b2bfcSGreg Roach        }
173dd6b2bfcSGreg Roach    }
174dd6b2bfcSGreg Roach
175dd6b2bfcSGreg Roach    // Second - advanced name fields
176dd6b2bfcSGreg Roach    if ($surname_tradition->hasMarriedNames() || preg_match('/\n2 _MARNM /', $namerec)) {
177dd6b2bfcSGreg Roach        $adv_name_fields = ['_MARNM' => ''];
178dd6b2bfcSGreg Roach    } else {
179dd6b2bfcSGreg Roach        $adv_name_fields = [];
180dd6b2bfcSGreg Roach    }
1818d0ebef0SGreg Roach    if (preg_match_all('/(' . Gedcom::REGEX_TAG . ')/', $tree->getPreference('ADVANCED_NAME_FACTS'), $match)) {
182dd6b2bfcSGreg Roach        foreach ($match[1] as $tag) {
183dd6b2bfcSGreg Roach            // Ignore advanced facts that duplicate standard facts
184dd6b2bfcSGreg Roach            if (!in_array($tag, ['TYPE', 'NPFX', 'GIVN', 'NICK', 'SPFX', 'SURN', 'NSFX'])) {
185dd6b2bfcSGreg Roach                $adv_name_fields[$tag] = '';
186dd6b2bfcSGreg Roach            }
187dd6b2bfcSGreg Roach        }
188dd6b2bfcSGreg Roach    }
189dd6b2bfcSGreg Roach
190dd6b2bfcSGreg Roach    foreach (array_keys($adv_name_fields) as $tag) {
191dd6b2bfcSGreg Roach        // Edit existing tags, grouped together
192dd6b2bfcSGreg Roach        if (preg_match_all('/2 ' . $tag . ' (.+)/', $namerec, $match)) {
193dd6b2bfcSGreg Roach            foreach ($match[1] as $value) {
19443e7e97aSGreg Roach                echo FunctionsEdit::addSimpleTag($tree, '2 ' . $tag . ' ' . $value, '', GedcomTag::getLabel('NAME:' . $tag));
195dd6b2bfcSGreg Roach                if ($tag === '_MARNM') {
196dd6b2bfcSGreg Roach                    preg_match_all('/\/([^\/]*)\//', $value, $matches);
197dd6b2bfcSGreg Roach                    echo FunctionsEdit::addSimpleTag($tree, '2 _MARNM_SURN ' . implode(',', $matches[1]));
198dd6b2bfcSGreg Roach                }
199dd6b2bfcSGreg Roach            }
200dd6b2bfcSGreg Roach        }
201dd6b2bfcSGreg Roach        // Allow a new tag to be entered
202dd6b2bfcSGreg Roach        if (!array_key_exists($tag, $name_fields)) {
20343e7e97aSGreg Roach            echo FunctionsEdit::addSimpleTag($tree, '0 ' . $tag, '', GedcomTag::getLabel('NAME:' . $tag));
204dd6b2bfcSGreg Roach            if ($tag === '_MARNM') {
205dd6b2bfcSGreg Roach                echo FunctionsEdit::addSimpleTag($tree, '0 _MARNM_SURN');
206dd6b2bfcSGreg Roach            }
207dd6b2bfcSGreg Roach        }
208dd6b2bfcSGreg Roach    }
209dd6b2bfcSGreg Roach
210dd6b2bfcSGreg Roach    // Third - new/existing custom name fields
211dd6b2bfcSGreg Roach    foreach ($name_fields as $tag => $value) {
212dd6b2bfcSGreg Roach        if (substr_compare($tag, '_', 0, 1) === 0) {
213dd6b2bfcSGreg Roach            echo FunctionsEdit::addSimpleTag($tree, '0 ' . $tag . ' ' . $value);
214dd6b2bfcSGreg Roach            if ($tag === '_MARNM') {
215dd6b2bfcSGreg Roach                preg_match_all('/\/([^\/]*)\//', $value, $matches);
216dd6b2bfcSGreg Roach                echo FunctionsEdit::addSimpleTag($tree, '2 _MARNM_SURN ' . implode(',', $matches[1]));
217dd6b2bfcSGreg Roach            }
218dd6b2bfcSGreg Roach        }
219dd6b2bfcSGreg Roach    }
220dd6b2bfcSGreg Roach
221dd6b2bfcSGreg Roach    // Fourth - SOUR, NOTE, _CUSTOM, etc.
222dd6b2bfcSGreg Roach    if ($namerec !== '') {
223dd6b2bfcSGreg Roach        $gedlines = explode("\n", $namerec); // -- find the number of lines in the record
224dd6b2bfcSGreg Roach        $fields   = explode(' ', $gedlines[0]);
225dd6b2bfcSGreg Roach        $glevel   = $fields[0];
226dd6b2bfcSGreg Roach        $level    = $glevel;
227dd6b2bfcSGreg Roach        $type     = $fields[1];
228dd6b2bfcSGreg Roach        $tags     = [];
229dd6b2bfcSGreg Roach        $i        = 0;
230dd6b2bfcSGreg Roach        do {
231dd6b2bfcSGreg Roach            if ($type !== 'TYPE' && !array_key_exists($type, $name_fields) && !array_key_exists($type, $adv_name_fields)) {
232dd6b2bfcSGreg Roach                $text = '';
233dd6b2bfcSGreg Roach                for ($j = 2; $j < count($fields); $j++) {
234dd6b2bfcSGreg Roach                    if ($j > 2) {
235dd6b2bfcSGreg Roach                        $text .= ' ';
236dd6b2bfcSGreg Roach                    }
237dd6b2bfcSGreg Roach                    $text .= $fields[$j];
238dd6b2bfcSGreg Roach                }
239dd6b2bfcSGreg Roach                while (($i + 1 < count($gedlines)) && (preg_match('/' . ($level + 1) . ' CONT ?(.*)/', $gedlines[$i + 1], $cmatch) > 0)) {
240dd6b2bfcSGreg Roach                    $text .= "\n" . $cmatch[1];
241dd6b2bfcSGreg Roach                    $i++;
242dd6b2bfcSGreg Roach                }
243dd6b2bfcSGreg Roach                echo FunctionsEdit::addSimpleTag($tree, $level . ' ' . $type . ' ' . $text);
244dd6b2bfcSGreg Roach            }
245dd6b2bfcSGreg Roach            $tags[] = $type;
246dd6b2bfcSGreg Roach            $i++;
247dd6b2bfcSGreg Roach            if (isset($gedlines[$i])) {
248dd6b2bfcSGreg Roach                $fields = explode(' ', $gedlines[$i]);
249dd6b2bfcSGreg Roach                $level  = $fields[0];
250dd6b2bfcSGreg Roach                if (isset($fields[1])) {
251dd6b2bfcSGreg Roach                    $type = $fields[1];
252dd6b2bfcSGreg Roach                }
253dd6b2bfcSGreg Roach            }
254dd6b2bfcSGreg Roach        } while (($level > $glevel) && ($i < count($gedlines)));
255dd6b2bfcSGreg Roach    }
256dd6b2bfcSGreg Roach
257dd6b2bfcSGreg Roach    // If we are adding a new individual, add the basic details
25855749c76SGreg Roach    if ($next_action !== EditFactAction::class) {
259dd6b2bfcSGreg Roach        $bdm = 'BD';
260ae71f733SGreg Roach        $tags = new Collection();
261ae71f733SGreg Roach        preg_match_all('/(' . Gedcom::REGEX_TAG . ')/', $tree->getPreference('QUICK_REQUIRED_FACTS'), $matches);
262ae71f733SGreg Roach        $tags = $tags->merge($matches[1]);
263ae71f733SGreg Roach
264ae71f733SGreg Roach        // If adding a spouse add the option to add a marriage fact to the new family
2657c7d1e03SGreg Roach        if ($next_action === AddSpouseToIndividualAction::class || $next_action === AddSpouseToFamilyAction::class) {
266dd6b2bfcSGreg Roach            $bdm .= 'M';
267ae71f733SGreg Roach            preg_match_all('/(' . Gedcom::REGEX_TAG . ')/', $tree->getPreference('QUICK_REQUIRED_FAMFACTS'), $matches);
268ae71f733SGreg Roach            $tags = $tags->merge($matches[1]);
269dd6b2bfcSGreg Roach        }
270ae71f733SGreg Roach
271ae71f733SGreg Roach        foreach (Fact::sortFactTags($tags) as $tag) {
27296a50d32SGreg Roach            echo view('cards/add-fact', [
27396a50d32SGreg Roach                'tag' => $tag,
27496a50d32SGreg Roach                'tree'  => $tree,
27596a50d32SGreg Roach            ]);
276dd6b2bfcSGreg Roach        }
277dd6b2bfcSGreg Roach    }
278dd6b2bfcSGreg Roach
27955749c76SGreg Roach    if ($next_action === EditFactAction::class ) {
280dd6b2bfcSGreg Roach        // GEDCOM 5.5.1 spec says NAME doesn’t get a OBJE
281dd6b2bfcSGreg Roach        echo view('cards/add-source-citation', [
282dd6b2bfcSGreg Roach            'level'          => 2,
283dd6b2bfcSGreg Roach            'full_citations' => $tree->getPreference('FULL_SOURCES'),
284dd6b2bfcSGreg Roach            'tree'           => $tree,
285dd6b2bfcSGreg Roach        ]);
286dd6b2bfcSGreg Roach        echo view('cards/add-note', [
287dd6b2bfcSGreg Roach            'level' => 2,
288dd6b2bfcSGreg Roach            'tree'  => $tree,
289dd6b2bfcSGreg Roach        ]);
290dd6b2bfcSGreg Roach        echo view('cards/add-shared-note', [
291dd6b2bfcSGreg Roach            'level' => 2,
292dd6b2bfcSGreg Roach            'tree'  => $tree,
293dd6b2bfcSGreg Roach        ]);
294dd6b2bfcSGreg Roach        echo view('cards/add-restriction', [
295dd6b2bfcSGreg Roach            'level' => 2,
296dd6b2bfcSGreg Roach            'tree'  => $tree,
297dd6b2bfcSGreg Roach        ]);
298dd6b2bfcSGreg Roach    } else {
299dd6b2bfcSGreg Roach        echo view('cards/add-source-citation', [
300dd6b2bfcSGreg Roach            'bdm'                     => $bdm,
301dd6b2bfcSGreg Roach            'level'                   => 1,
302dd6b2bfcSGreg Roach            'full_citations'          => $tree->getPreference('FULL_SOURCES'),
303dd6b2bfcSGreg Roach            'prefer_level2_sources'   => $tree->getPreference('PREFER_LEVEL2_SOURCES'),
304dd6b2bfcSGreg Roach            'quick_required_facts'    => $tree->getPreference('QUICK_REQUIRED_FACTS'),
305dd6b2bfcSGreg Roach            'quick_required_famfacts' => $tree->getPreference('QUICK_REQUIRED_FAMFACTS'),
306dd6b2bfcSGreg Roach            'tree'                    => $tree,
307dd6b2bfcSGreg Roach        ]);
308dd6b2bfcSGreg Roach        echo view('cards/add-note', [
309dd6b2bfcSGreg Roach            'level' => 1,
310dd6b2bfcSGreg Roach            'tree'  => $tree,
311dd6b2bfcSGreg Roach        ]);
312dd6b2bfcSGreg Roach        echo view('cards/add-shared-note', [
313dd6b2bfcSGreg Roach            'level' => 1,
314dd6b2bfcSGreg Roach            'tree'  => $tree,
315dd6b2bfcSGreg Roach        ]);
316dd6b2bfcSGreg Roach        echo view('cards/add-restriction', [
317dd6b2bfcSGreg Roach            'level' => 1,
318dd6b2bfcSGreg Roach            'tree'  => $tree,
319dd6b2bfcSGreg Roach        ]);
320dd6b2bfcSGreg Roach    }
321dd6b2bfcSGreg Roach
322dd6b2bfcSGreg Roach    ?>
323dd6b2bfcSGreg Roach    <div class="row form-group">
324dd6b2bfcSGreg Roach        <div class="col-sm-9 offset-sm-3">
325dd6b2bfcSGreg Roach            <button class="btn btn-primary" type="submit">
326d993d560SGreg Roach                <?= view('icons/save') ?>
327dd6b2bfcSGreg Roach                <?= /* I18N: A button label. */
328dd6b2bfcSGreg Roach                I18N::translate('save') ?>
329dd6b2bfcSGreg Roach            </button>
330bee967faSGreg Roach            <?php if ($next_action !== EditFactAction::class) : ?>
331dc21071fSGreg Roach                <button class="btn btn-primary" type="submit" name="goto" value="new">
332d993d560SGreg Roach                    <?= view('icons/save') ?>
333dd6b2bfcSGreg Roach                    <?= /* I18N: A button label. */
334dd6b2bfcSGreg Roach                    I18N::translate('go to new individual') ?>
335dd6b2bfcSGreg Roach                </button>
336dd6b2bfcSGreg Roach            <?php endif ?>
337dd6b2bfcSGreg Roach            <a class="btn btn-secondary" href="<?= e($cancel_url) ?>">
338d993d560SGreg Roach                <?= view('icons/cancel') ?>
339dd6b2bfcSGreg Roach                <?= /* I18N: A button label. */
340dd6b2bfcSGreg Roach                I18N::translate('cancel') ?>
341dd6b2bfcSGreg Roach            </a>
342dd6b2bfcSGreg Roach
343dd6b2bfcSGreg Roach            <?php if ($name_fact instanceof Fact && (Auth::isAdmin() || $tree->getPreference('SHOW_GEDCOM_RECORD'))) : ?>
3443b3db8adSGreg Roach                <a class="btn btn-link" href="<?= e(route(EditRawFactPage::class, ['xref' => $xref, 'fact_id' => $name_fact->id(), 'tree' => $tree->name()])) ?>">
345dd6b2bfcSGreg Roach                    <?= I18N::translate('Edit the raw GEDCOM') ?>
346dd6b2bfcSGreg Roach                </a>
347dd6b2bfcSGreg Roach            <?php endif ?>
348dd6b2bfcSGreg Roach        </div>
349dd6b2bfcSGreg Roach    </div>
350dd6b2bfcSGreg Roach</form>
351dd6b2bfcSGreg Roach
352dd6b2bfcSGreg Roach<?= view('modals/on-screen-keyboard') ?>
353dd6b2bfcSGreg Roach<?= view('modals/ajax') ?>
354dd6b2bfcSGreg Roach<?= view('edit/initialize-calendar-popup') ?>
355dd6b2bfcSGreg Roach
356dd6b2bfcSGreg Roach<?php View::push('javascript') ?>
357dd6b2bfcSGreg Roach<script>
358dd6b2bfcSGreg Roach    var SURNAME_TRADITION = <?= json_encode($tree->getPreference('SURNAME_TRADITION')) ?>;
359dd6b2bfcSGreg Roach
360dd6b2bfcSGreg Roach    var NAME = $("[name=NAME]");
361dd6b2bfcSGreg Roach
362dd6b2bfcSGreg Roach    // Generate a full name from the name components
363dd6b2bfcSGreg Roach    function generate_name() {
36459e18f0cSGreg Roach        var npfx      = document.querySelector("[name=NPFX]").value;
36559e18f0cSGreg Roach        var givn      = document.querySelector("[name=GIVN]").value;
36659e18f0cSGreg Roach        var spfx      = document.querySelector("[name=SPFX]").value;
36759e18f0cSGreg Roach        var surn      = document.querySelector("[name=SURN]").value;
36859e18f0cSGreg Roach        var nsfx      = document.querySelector("[name=NSFX]").value;
36959e18f0cSGreg Roach        var sex_input = document.querySelector("[name=SEX]:checked");
37059e18f0cSGreg Roach        var sex       = sex_input ? sex_input.value : "U";
371dd6b2bfcSGreg Roach
37259e18f0cSGreg Roach        return webtrees.buildNameFromParts(npfx, givn, spfx, surn, nsfx, sex);
373dd6b2bfcSGreg Roach    }
374dd6b2bfcSGreg Roach
375dd6b2bfcSGreg Roach    // Update the NAME and _MARNM fields from the name components
376dd6b2bfcSGreg Roach    // and also display the value in read-only "gedcom" format.
377dd6b2bfcSGreg Roach    function updatewholename() {
378dd6b2bfcSGreg Roach        // Don’t update the name if the user manually changed it
379dd6b2bfcSGreg Roach        if (manualChange) {
380dd6b2bfcSGreg Roach            return;
381dd6b2bfcSGreg Roach        }
382dd6b2bfcSGreg Roach
38359e18f0cSGreg Roach        var npfx = document.querySelector("[name=NPFX]").value;
38459e18f0cSGreg Roach        var givn = document.querySelector("[name=GIVN]").value;
38559e18f0cSGreg Roach        var spfx = document.querySelector("[name=SPFX]").value;
386cad15720SGreg Roach        var surn = document.querySelector("[name=SURN]").value;
38759e18f0cSGreg Roach        var nsfx = document.querySelector("[name=NSFX]").value;
388dd6b2bfcSGreg Roach        var name = generate_name();
389dd6b2bfcSGreg Roach
390820b62dfSGreg Roach        var display_id = NAME.attr("id") + "_display";
391dd6b2bfcSGreg Roach
392dd6b2bfcSGreg Roach        NAME.val(name);
393dd6b2bfcSGreg Roach        $("#" + display_id).text(name);
39459e18f0cSGreg Roach
395dd6b2bfcSGreg Roach        // Married names inherit some NSFX values, but not these
396dd6b2bfcSGreg Roach        nsfx = nsfx.replace(/^(I|II|III|IV|V|VI|Junior|Jr\.?|Senior|Sr\.?)$/i, "");
39759e18f0cSGreg Roach
398dd6b2bfcSGreg Roach        // Update _MARNM field from _MARNM_SURN field and display it
399dd6b2bfcSGreg Roach        var ip       = document.getElementsByTagName("input");
400dd6b2bfcSGreg Roach        var marnm_id = "";
401dd6b2bfcSGreg Roach        var romn     = "";
402dd6b2bfcSGreg Roach        var heb      = "";
403f6875112SGreg Roach        var i;
40459e18f0cSGreg Roach
405f6875112SGreg Roach        for (i = 0; i < ip.length; i++) {
40659e18f0cSGreg Roach            if (ip[i].id.indexOf("_HEB") === 0) {
40759e18f0cSGreg Roach                // Remember this field - we might need it later
408dd6b2bfcSGreg Roach                heb = val;
40959e18f0cSGreg Roach            }
41059e18f0cSGreg Roach            if (ip[i].id.indexOf("ROMN") === 0) {
41159e18f0cSGreg Roach                // Remember this field - we might need it later
412dd6b2bfcSGreg Roach                romn = val;
41359e18f0cSGreg Roach            }
414f6875112SGreg Roach        }
415f6875112SGreg Roach
416f6875112SGreg Roach        for (i = 0; i < ip.length; i++) {
417f6875112SGreg Roach            var val = ip[i].value;
418f6875112SGreg Roach
419dd6b2bfcSGreg Roach            if (ip[i].id.indexOf("_MARNM") === 0) {
420dd6b2bfcSGreg Roach                if (ip[i].id.indexOf("_MARNM_SURN") === 0) {
421dd6b2bfcSGreg Roach                    var msurn = "";
422dd6b2bfcSGreg Roach                    if (val !== "") {
423cad15720SGreg Roach                        if (surn === "" || webtrees.detectScript(val) === webtrees.detectScript(surn)) {
42459e18f0cSGreg Roach                            // Same script as NAME field?
425cad15720SGreg Roach                            msurn = name.replace(/\/.*\//, "/" + val + "/");
42659e18f0cSGreg Roach                        } else if (heb !== "" && webtrees.detectScript(val) === webtrees.detectScript(heb)) {
42759e18f0cSGreg Roach                            // Same script as _HEB field?
428dd6b2bfcSGreg Roach                            msurn = heb.replace(/\/.*\//, "/" + val + "/");
42959e18f0cSGreg Roach                        } else if (romn !== "" && webtrees.detectScript(val) === webtrees.detectScript(romn)) {
43059e18f0cSGreg Roach                            //. Same script as ROMN field
431dd6b2bfcSGreg Roach                            msurn = romn.replace(/\/.*\//, "/" + val + "/");
432dd6b2bfcSGreg Roach                        }
433b2091446SRico Sonntag                    }
434dd6b2bfcSGreg Roach                    document.getElementById(marnm_id).value                  = msurn;
435dd6b2bfcSGreg Roach                    document.getElementById(marnm_id + "_display").innerHTML = msurn;
436dd6b2bfcSGreg Roach                } else {
437dd6b2bfcSGreg Roach                    marnm_id = ip[i].id;
438dd6b2bfcSGreg Roach                }
439dd6b2bfcSGreg Roach            }
440dd6b2bfcSGreg Roach        }
441dd6b2bfcSGreg Roach    }
442dd6b2bfcSGreg Roach
443dd6b2bfcSGreg Roach    // Toggle the name editor fields between
444dd6b2bfcSGreg Roach    // <input type="hidden"> <span style="display:inline">
445dd6b2bfcSGreg Roach    // <input type="text">   <span style="display:none">
446dd6b2bfcSGreg Roach
447dd6b2bfcSGreg Roach    var oldName = "";
448dd6b2bfcSGreg Roach
449dd6b2bfcSGreg Roach    // Calls to generate_name() trigger an update - hence need to
450dd6b2bfcSGreg Roach    // set the manual change to true first. We are probably
451dd6b2bfcSGreg Roach    // listening to the wrong events on the input fields...
452dd6b2bfcSGreg Roach    var manualChange = generate_name() !== NAME.val();
453dd6b2bfcSGreg Roach
454dd6b2bfcSGreg Roach    function convertHidden(eid) {
455dd6b2bfcSGreg Roach        var input1 = $("#" + eid);
456dd6b2bfcSGreg Roach        var input2 = $("#" + eid + "_display");
45759e18f0cSGreg Roach
458dd6b2bfcSGreg Roach        if (input1.attr("type") === "hidden") {
45959e18f0cSGreg Roach            input1.attr("type", "text");
460dd6b2bfcSGreg Roach            input2.hide();
461dd6b2bfcSGreg Roach        } else {
46259e18f0cSGreg Roach            input1.attr("type", "hidden");
463dd6b2bfcSGreg Roach            input2.show();
464dd6b2bfcSGreg Roach        }
465dd6b2bfcSGreg Roach    }
466dd6b2bfcSGreg Roach
467dd6b2bfcSGreg Roach    /**
468dd6b2bfcSGreg Roach     * if the user manually changed the NAME field, then update the textual
469dd6b2bfcSGreg Roach     * HTML representation of it
470dd6b2bfcSGreg Roach     * If the value changed set manualChange to true so that changing
471dd6b2bfcSGreg Roach     * the other fields doesn’t change the NAME line
472dd6b2bfcSGreg Roach     */
473dd6b2bfcSGreg Roach    function updateTextName(eid) {
474dd6b2bfcSGreg Roach        var element = document.getElementById(eid);
475dd6b2bfcSGreg Roach        if (element) {
476dd6b2bfcSGreg Roach            if (element.value !== oldName) {
477dd6b2bfcSGreg Roach                manualChange = true;
478dd6b2bfcSGreg Roach            }
479dd6b2bfcSGreg Roach            var delement = document.getElementById(eid + "_display");
480dd6b2bfcSGreg Roach            if (delement) {
481dd6b2bfcSGreg Roach                delement.innerHTML = element.value;
482dd6b2bfcSGreg Roach            }
483dd6b2bfcSGreg Roach        }
484dd6b2bfcSGreg Roach    }
485dd6b2bfcSGreg Roach
486dd6b2bfcSGreg Roach    function checkform() {
487dd6b2bfcSGreg Roach        var ip = document.getElementsByTagName("input");
488dd6b2bfcSGreg Roach        for (var i = 0; i < ip.length; i++) {
489dd6b2bfcSGreg Roach            // ADD slashes to _HEB and _AKA names
490dd6b2bfcSGreg Roach            if (ip[i].id.indexOf("_AKA") === 0 || ip[i].id.indexOf("_HEB") === 0 || ip[i].id.indexOf("ROMN") === 0)
491dd6b2bfcSGreg Roach                if (ip[i].value.indexOf("/") < 0 && ip[i].value !== "")
492dd6b2bfcSGreg Roach                    ip[i].value = ip[i].value.replace(/([^\s]+)\s*$/, "/$1/");
493dd6b2bfcSGreg Roach            // Blank out temporary _MARNM_SURN
494dd6b2bfcSGreg Roach            if (ip[i].id.indexOf("_MARNM_SURN") === 0)
495dd6b2bfcSGreg Roach                ip[i].value = "";
496dd6b2bfcSGreg Roach            // Convert "xxx yyy" and "xxx y yyy" surnames to "xxx,yyy"
497dd6b2bfcSGreg Roach            if ((SURNAME_TRADITION === "spanish" || "SURNAME_TRADITION" === "portuguese") && ip[i].id.indexOf("SURN") === 0) {
498dd6b2bfcSGreg Roach                ip[i].value = document.forms[0].SURN.value.replace(/^\s*([^\s,]{2,})\s+([iIyY] +)?([^\s,]{2,})\s*$/, "$1,$3");
499dd6b2bfcSGreg Roach            }
500dd6b2bfcSGreg Roach        }
501dd6b2bfcSGreg Roach        return true;
502dd6b2bfcSGreg Roach    }
503dd6b2bfcSGreg Roach
504dd6b2bfcSGreg Roach    // If the name isnt initially formed from the components in a standard way,
505dd6b2bfcSGreg Roach    // then dont automatically update it.
506dd6b2bfcSGreg Roach    if (NAME.val() !== generate_name() && NAME.val() !== "//") {
507dd6b2bfcSGreg Roach        convertHidden(NAME.attr("id"));
508dd6b2bfcSGreg Roach    }
509dd6b2bfcSGreg Roach</script>
510dd6b2bfcSGreg Roach<?php View::endpush() ?>
511dd6b2bfcSGreg Roach
512