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