|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* webtrees: online genealogy |
|
4
|
|
|
* Copyright (C) 2018 webtrees development team |
|
5
|
|
|
* This program is free software: you can redistribute it and/or modify |
|
6
|
|
|
* it under the terms of the GNU General Public License as published by |
|
7
|
|
|
* the Free Software Foundation, either version 3 of the License, or |
|
8
|
|
|
* (at your option) any later version. |
|
9
|
|
|
* This program is distributed in the hope that it will be useful, |
|
10
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12
|
|
|
* GNU General Public License for more details. |
|
13
|
|
|
* You should have received a copy of the GNU General Public License |
|
14
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
15
|
|
|
*/ |
|
16
|
|
|
namespace Fisharebest\Webtrees\Controller; |
|
17
|
|
|
|
|
18
|
|
|
use Fisharebest\Webtrees\Auth; |
|
19
|
|
|
use Fisharebest\Webtrees\Fact; |
|
20
|
|
|
use Fisharebest\Webtrees\Family; |
|
21
|
|
|
use Fisharebest\Webtrees\Filter; |
|
22
|
|
|
use Fisharebest\Webtrees\FontAwesome; |
|
23
|
|
|
use Fisharebest\Webtrees\Functions\FunctionsPrint; |
|
24
|
|
|
use Fisharebest\Webtrees\Functions\FunctionsPrintFacts; |
|
25
|
|
|
use Fisharebest\Webtrees\GedcomCode\GedcomCodeName; |
|
26
|
|
|
use Fisharebest\Webtrees\GedcomTag; |
|
27
|
|
|
use Fisharebest\Webtrees\I18N; |
|
28
|
|
|
use Fisharebest\Webtrees\Individual; |
|
29
|
|
|
use Fisharebest\Webtrees\Menu; |
|
30
|
|
|
use Fisharebest\Webtrees\Module; |
|
31
|
|
|
use Fisharebest\Webtrees\Module\ModuleTabInterface; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* Controller for the individual page |
|
35
|
|
|
*/ |
|
36
|
|
|
class IndividualController extends GedcomRecordController { |
|
37
|
|
|
/** @var int Count of names */ |
|
38
|
|
|
public $name_count = 0; |
|
39
|
|
|
|
|
40
|
|
|
/** @var int Count of names. */ |
|
41
|
|
|
public $total_names = 0; |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* Startup activity |
|
45
|
|
|
* |
|
46
|
|
|
* @param Individual|null $record |
|
47
|
|
|
*/ |
|
48
|
|
|
public function __construct($record) { |
|
49
|
|
|
parent::__construct($record); |
|
50
|
|
|
|
|
51
|
|
|
// If we can display the details, add them to the page header |
|
52
|
|
|
if ($this->record && $this->record->canShow()) { |
|
53
|
|
|
$this->setPageTitle($this->record->getFullName() . ' ' . $this->record->getLifeSpan()); |
|
|
|
|
|
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* Get significant information from this page, to allow other pages such as |
|
59
|
|
|
* charts and reports to initialise with the same records |
|
60
|
|
|
* |
|
61
|
|
|
* @return Individual |
|
62
|
|
|
*/ |
|
63
|
|
|
public function getSignificantIndividual() { |
|
64
|
|
|
if ($this->record) { |
|
65
|
|
|
return $this->record; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
return parent::getSignificantIndividual(); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* Get significant information from this page, to allow other pages such as |
|
73
|
|
|
* charts and reports to initialise with the same records |
|
74
|
|
|
* |
|
75
|
|
|
* @return Family |
|
76
|
|
|
*/ |
|
77
|
|
|
public function getSignificantFamily() { |
|
78
|
|
|
if ($this->record) { |
|
79
|
|
|
foreach ($this->record->getChildFamilies() as $family) { |
|
|
|
|
|
|
80
|
|
|
return $family; |
|
81
|
|
|
} |
|
82
|
|
|
foreach ($this->record->getSpouseFamilies() as $family) { |
|
|
|
|
|
|
83
|
|
|
return $family; |
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
return parent::getSignificantFamily(); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* Which tabs should we show on this individual's page. |
|
92
|
|
|
* We don't show empty tabs. |
|
93
|
|
|
* |
|
94
|
|
|
* @param Individual $individual |
|
95
|
|
|
* |
|
96
|
|
|
* @return ModuleTabInterface[] |
|
97
|
|
|
*/ |
|
98
|
|
|
public function getTabs(Individual $individual) { |
|
99
|
|
|
$active_tabs = Module::getActiveTabs($individual->getTree()); |
|
100
|
|
|
|
|
101
|
|
|
return array_filter($active_tabs, function (ModuleTabInterface $tab) use ($individual) { |
|
102
|
|
|
return $tab->hasTabContent($individual); |
|
103
|
|
|
}); |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
* Handle AJAX requests - to generate the tab content |
|
108
|
|
|
* |
|
109
|
|
|
* @param Individual $individual |
|
110
|
|
|
*/ |
|
111
|
|
|
public function ajaxRequest(Individual $individual) { |
|
112
|
|
|
header('Content-Type: text/html; charset=UTF-8'); |
|
113
|
|
|
|
|
114
|
|
|
$tab = Filter::get('module'); |
|
115
|
|
|
$tabs = $this->getTabs($individual); |
|
116
|
|
|
|
|
117
|
|
|
if (!array_key_exists($tab, $tabs)) { |
|
118
|
|
|
http_response_code(404); |
|
119
|
|
|
} else { |
|
120
|
|
|
echo $tabs[$tab]->getTabContent($individual); |
|
121
|
|
|
} |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
/** |
|
125
|
|
|
* Format a name record |
|
126
|
|
|
* |
|
127
|
|
|
* @param int $n |
|
128
|
|
|
* @param Fact $fact |
|
129
|
|
|
* |
|
130
|
|
|
* @return string |
|
131
|
|
|
*/ |
|
132
|
|
|
public function formatNameRecord($n, Fact $fact) { |
|
133
|
|
|
$individual = $fact->getParent(); |
|
134
|
|
|
|
|
135
|
|
|
// Create a dummy record, so we can extract the formatted NAME value from it. |
|
136
|
|
|
$dummy = new Individual( |
|
137
|
|
|
'xref', |
|
138
|
|
|
"0 @xref@ INDI\n1 DEAT Y\n" . $fact->getGedcom(), |
|
139
|
|
|
null, |
|
140
|
|
|
$individual->getTree() |
|
141
|
|
|
); |
|
142
|
|
|
$dummy->setPrimaryName(0); // Make sure we use the name from "1 NAME" |
|
143
|
|
|
|
|
144
|
|
|
$container_class = 'card'; |
|
145
|
|
|
$content_class = 'collapse'; |
|
146
|
|
|
$aria = 'false'; |
|
147
|
|
|
|
|
148
|
|
|
if ($n === 0) { |
|
149
|
|
|
$content_class = 'collapse show'; |
|
150
|
|
|
$aria = 'true'; |
|
151
|
|
|
} |
|
152
|
|
|
if ($fact->isPendingDeletion()) { |
|
153
|
|
|
$container_class .= ' old'; |
|
154
|
|
|
} elseif ($fact->isPendingAddition()) { |
|
155
|
|
|
$container_class .= ' new'; |
|
156
|
|
|
} |
|
157
|
|
|
|
|
158
|
|
|
ob_start(); |
|
159
|
|
|
echo '<dl><dt class="label">', I18N::translate('Name'), '</dt>'; |
|
160
|
|
|
echo '<dd class="field">', $dummy->getFullName(), '</dd>'; |
|
161
|
|
|
$ct = preg_match_all('/\n2 (\w+) (.*)/', $fact->getGedcom(), $nmatch, PREG_SET_ORDER); |
|
162
|
|
|
for ($i = 0; $i < $ct; $i++) { |
|
163
|
|
|
$tag = $nmatch[$i][1]; |
|
164
|
|
|
if ($tag != 'SOUR' && $tag != 'NOTE' && $tag != 'SPFX') { |
|
165
|
|
|
echo '<dt class="label">', GedcomTag::getLabel($tag, $this->record), '</dt>'; |
|
166
|
|
|
echo '<dd class="field">'; // Before using dir="auto" on this field, note that Gecko treats this as an inline element but WebKit treats it as a block element |
|
167
|
|
|
if (isset($nmatch[$i][2])) { |
|
168
|
|
|
$name = e($nmatch[$i][2]); |
|
169
|
|
|
$name = str_replace('/', '', $name); |
|
170
|
|
|
$name = preg_replace('/(\S*)\*/', '<span class="starredname">\\1</span>', $name); |
|
171
|
|
|
switch ($tag) { |
|
172
|
|
|
case 'TYPE': |
|
173
|
|
|
echo GedcomCodeName::getValue($name, $this->record); |
|
174
|
|
|
break; |
|
175
|
|
|
case 'SURN': |
|
176
|
|
|
// The SURN field is not necessarily the surname. |
|
177
|
|
|
// Where it is not a substring of the real surname, show it after the real surname. |
|
178
|
|
|
$surname = e($dummy->getAllNames()[0]['surname']); |
|
179
|
|
|
$surns = preg_replace('/, */', ' ', $nmatch[$i][2]); |
|
180
|
|
|
if (strpos($dummy->getAllNames()[0]['surname'], $surns) !== false) { |
|
181
|
|
|
echo '<span dir="auto">' . $surname . '</span>'; |
|
182
|
|
|
} else { |
|
183
|
|
|
echo I18N::translate('%1$s (%2$s)', '<span dir="auto">' . $surname . '</span>', '<span dir="auto">' . $name . '</span>'); |
|
184
|
|
|
} |
|
185
|
|
|
break; |
|
186
|
|
|
default: |
|
187
|
|
|
echo '<span dir="auto">' . $name . '</span>'; |
|
188
|
|
|
break; |
|
189
|
|
|
} |
|
190
|
|
|
} |
|
191
|
|
|
echo '</dd>'; |
|
192
|
|
|
echo '</dl>'; |
|
193
|
|
|
} |
|
194
|
|
|
} |
|
195
|
|
|
if (preg_match("/\n2 SOUR/", $fact->getGedcom())) { |
|
196
|
|
|
echo '<div id="indi_sour" class="clearfloat">', FunctionsPrintFacts::printFactSources($fact->getGedcom(), 2), '</div>'; |
|
197
|
|
|
} |
|
198
|
|
|
if (preg_match("/\n2 NOTE/", $fact->getGedcom())) { |
|
199
|
|
|
echo '<div id="indi_note" class="clearfloat">', FunctionsPrint::printFactNotes($fact->getGedcom(), 2), '</div>'; |
|
200
|
|
|
} |
|
201
|
|
|
$content = ob_get_clean(); |
|
202
|
|
|
|
|
203
|
|
|
if ($this->record->canEdit() && !$fact->isPendingDeletion()) { |
|
204
|
|
|
$edit_links = |
|
205
|
|
|
FontAwesome::linkIcon('delete', I18N::translate('Delete this name'), ['class' => 'btn btn-link', 'href' => '#', 'onclick' => 'return delete_fact("' . I18N::translate('Are you sure you want to delete this fact?') . '", "' . $this->record->getXref() . '", "' . $fact->getFactId() . '");']) . |
|
206
|
|
|
FontAwesome::linkIcon('edit', I18N::translate('Edit the name'), ['class' => 'btn btn-link', 'href' => 'edit_interface.php?action=editname&xref=' . $this->record->getXref() . '&fact_id=' . $fact->getFactId() . '&ged=' . $this->record->getTree()->getNameHtml()]); |
|
207
|
|
|
} else { |
|
208
|
|
|
$edit_links = ''; |
|
209
|
|
|
} |
|
210
|
|
|
|
|
211
|
|
|
return ' |
|
212
|
|
|
<div class="' . $container_class . '"> |
|
213
|
|
|
<div class="card-header" role="tab" id="name-header-' . $n . '"> |
|
214
|
|
|
<a data-toggle="collapse" data-parent="#individual-names" href="#name-content-' . $n . '" aria-expanded="' . $aria . '" aria-controls="name-content-' . $n . '">' . $dummy->getFullName() . '</a> |
|
215
|
|
|
' . $edit_links . ' |
|
216
|
|
|
</div> |
|
217
|
|
|
<div id="name-content-' . $n . '" class="' . $content_class . '" role="tabpanel" aria-labelledby="name-header-' . $n . '"> |
|
218
|
|
|
<div class="card-body">' . $content . '</div> |
|
219
|
|
|
</div> |
|
220
|
|
|
</div>'; |
|
221
|
|
|
} |
|
222
|
|
|
|
|
223
|
|
|
/** |
|
224
|
|
|
* print information for a sex record |
|
225
|
|
|
* |
|
226
|
|
|
* @param Fact $fact |
|
227
|
|
|
* |
|
228
|
|
|
* @return string |
|
229
|
|
|
*/ |
|
230
|
|
|
public function formatSexRecord(Fact $fact) { |
|
231
|
|
|
$individual = $fact->getParent(); |
|
232
|
|
|
|
|
233
|
|
|
switch ($fact->getValue()) { |
|
234
|
|
|
case 'M': |
|
235
|
|
|
$sex = I18N::translate('Male'); |
|
236
|
|
|
break; |
|
237
|
|
|
case 'F': |
|
238
|
|
|
$sex = I18N::translate('Female'); |
|
239
|
|
|
break; |
|
240
|
|
|
default: |
|
241
|
|
|
$sex = I18N::translateContext('unknown gender', 'Unknown'); |
|
242
|
|
|
break; |
|
243
|
|
|
} |
|
244
|
|
|
|
|
245
|
|
|
$container_class = 'card'; |
|
246
|
|
|
if ($fact->isPendingDeletion()) { |
|
247
|
|
|
$container_class .= ' old'; |
|
248
|
|
|
} elseif ($fact->isPendingAddition()) { |
|
249
|
|
|
$container_class .= ' new'; |
|
250
|
|
|
} |
|
251
|
|
|
|
|
252
|
|
|
if ($individual->canEdit() && !$fact->isPendingDeletion()) { |
|
253
|
|
|
$edit_links = FontAwesome::linkIcon('edit', I18N::translate('Edit the gender'), ['class' => 'btn btn-link', 'href' => 'edit_interface.php?action=edit&xref=' . $individual->getXref() . '&fact_id=' . $fact->getFactId() . '&ged=' . $individual->getTree()->getNameHtml()]); |
|
254
|
|
|
} else { |
|
255
|
|
|
$edit_links = ''; |
|
256
|
|
|
} |
|
257
|
|
|
|
|
258
|
|
|
return ' |
|
259
|
|
|
<div class="' . $container_class . '"> |
|
260
|
|
|
<div class="card-header" role="tab" id="name-header-add"> |
|
261
|
|
|
<div class="card-title mb-0"> |
|
262
|
|
|
<b>' . I18N::translate('Gender') . '</b> ' . $sex . $edit_links . ' |
|
263
|
|
|
</div> |
|
264
|
|
|
</div> |
|
265
|
|
|
</div>'; |
|
266
|
|
|
} |
|
267
|
|
|
|
|
268
|
|
|
/** |
|
269
|
|
|
* get edit menu |
|
270
|
|
|
*/ |
|
271
|
|
|
public function getEditMenu() { |
|
272
|
|
|
if (!$this->record || $this->record->isPendingDeletion()) { |
|
273
|
|
|
return null; |
|
274
|
|
|
} |
|
275
|
|
|
// edit menu |
|
276
|
|
|
$menu = new Menu(I18N::translate('Edit'), '#', 'menu-indi'); |
|
277
|
|
|
|
|
278
|
|
|
if (Auth::isEditor($this->record->getTree())) { |
|
279
|
|
|
// delete |
|
280
|
|
|
$menu->addSubmenu(new Menu(I18N::translate('Delete'), '#', 'menu-indi-del', [ |
|
281
|
|
|
'onclick' => 'return delete_record("' . I18N::translate('Are you sure you want to delete “%s”?', strip_tags($this->record->getFullName())) . '", "' . $this->record->getXref() . '");', |
|
282
|
|
|
])); |
|
283
|
|
|
} |
|
284
|
|
|
|
|
285
|
|
|
// edit raw |
|
286
|
|
|
if (Auth::isAdmin() || Auth::isEditor($this->record->getTree()) && $this->record->getTree()->getPreference('SHOW_GEDCOM_RECORD')) { |
|
287
|
|
|
$menu->addSubmenu(new Menu(I18N::translate('Edit the raw GEDCOM'), 'edit_interface.php?action=editraw&ged=' . $this->record->getTree()->getNameHtml() . '&xref=' . $this->record->getXref(), 'menu-indi-editraw')); |
|
288
|
|
|
} |
|
289
|
|
|
|
|
290
|
|
|
return $menu; |
|
291
|
|
|
} |
|
292
|
|
|
|
|
293
|
|
|
/** |
|
294
|
|
|
* get the person box stylesheet class for the given person |
|
295
|
|
|
* |
|
296
|
|
|
* @param Individual $person |
|
297
|
|
|
* |
|
298
|
|
|
* @return string returns 'person_box', 'person_boxF', or 'person_boxNN' |
|
299
|
|
|
*/ |
|
300
|
|
|
public function getPersonStyle($person) { |
|
301
|
|
|
switch ($person->getSex()) { |
|
302
|
|
|
case 'M': |
|
303
|
|
|
$class = 'person_box'; |
|
304
|
|
|
break; |
|
305
|
|
|
case 'F': |
|
306
|
|
|
$class = 'person_boxF'; |
|
307
|
|
|
break; |
|
308
|
|
|
default: |
|
309
|
|
|
$class = 'person_boxNN'; |
|
310
|
|
|
break; |
|
311
|
|
|
} |
|
312
|
|
|
if ($person->isPendingDeletion()) { |
|
313
|
|
|
$class .= ' old'; |
|
314
|
|
|
} elseif ($person->isPendingAddition()) { |
|
315
|
|
|
$class .= ' new'; |
|
316
|
|
|
} |
|
317
|
|
|
|
|
318
|
|
|
return $class; |
|
319
|
|
|
} |
|
320
|
|
|
|
|
321
|
|
|
/** |
|
322
|
|
|
* Get significant information from this page, to allow other pages such as |
|
323
|
|
|
* charts and reports to initialise with the same records |
|
324
|
|
|
* |
|
325
|
|
|
* @return string |
|
326
|
|
|
*/ |
|
327
|
|
|
public function getSignificantSurname() { |
|
328
|
|
|
if ($this->record) { |
|
329
|
|
|
list($surn) = explode(',', $this->record->getSortName()); |
|
330
|
|
|
|
|
331
|
|
|
return $surn; |
|
332
|
|
|
} else { |
|
333
|
|
|
return ''; |
|
334
|
|
|
} |
|
335
|
|
|
} |
|
336
|
|
|
|
|
337
|
|
|
/** |
|
338
|
|
|
* Get the contents of sidebar. |
|
339
|
|
|
* |
|
340
|
|
|
* @return string |
|
341
|
|
|
*/ |
|
342
|
|
|
public function getSideBarContent() { |
|
343
|
|
|
$html = ''; |
|
344
|
|
|
foreach (Module::getActiveSidebars($this->record->getTree()) as $module) { |
|
345
|
|
|
if ($module->hasSidebarContent($this->record)) { |
|
|
|
|
|
|
346
|
|
|
$class = $module->getName() === 'family_nav' ? 'collapse show' : 'collapse'; |
|
|
|
|
|
|
347
|
|
|
$aria = $module->getName() === 'family_nav' ? 'true' : 'false'; |
|
348
|
|
|
$html .= ' |
|
349
|
|
|
<div class="card"> |
|
350
|
|
|
<div class="card-header" role="tab" id="sidebar-header-' . $module->getName() . '"> |
|
351
|
|
|
<div class="card-title mb-0"> |
|
352
|
|
|
<a data-toggle="collapse" data-parent="#sidebar" href="#sidebar-content-' . $module->getName() . '" aria-expanded="' . $aria . '" aria-controls="sidebar-content-' . $module->getName() . '">' . $module->getTitle() . '</a> |
|
|
|
|
|
|
353
|
|
|
</div> |
|
354
|
|
|
</div> |
|
355
|
|
|
<div id="sidebar-content-' . $module->getName() . '" class="' . $class . '" role="tabpanel" aria-labelledby="sidebar-header-' . $module->getName() . '"> |
|
356
|
|
|
<div class="card-body">' . $module->getSidebarContent() . '</div> |
|
|
|
|
|
|
357
|
|
|
</div> |
|
358
|
|
|
</div>'; |
|
359
|
|
|
} |
|
360
|
|
|
} |
|
361
|
|
|
|
|
362
|
|
|
if ($html) { |
|
363
|
|
|
return '<div id="sidebar" role="tablist">' . $html . '</div>'; |
|
364
|
|
|
} else { |
|
365
|
|
|
return ''; |
|
366
|
|
|
} |
|
367
|
|
|
} |
|
368
|
|
|
} |
|
369
|
|
|
|