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