1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
|
<?php
namespace Fisharebest\Webtrees\Module;
/**
* webtrees: online genealogy
* Copyright (C) 2015 webtrees development team
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
use Fisharebest\Webtrees\Auth;
use Fisharebest\Webtrees\Date;
use Fisharebest\Webtrees\Family;
use Fisharebest\Webtrees\Functions\Functions;
use Fisharebest\Webtrees\GedcomTag;
use Fisharebest\Webtrees\I18N;
use Fisharebest\Webtrees\Individual;
use Fisharebest\Webtrees\Theme;
/**
* Class RelativesTabModule
*/
class RelativesTabModule extends AbstractModule implements ModuleTabInterface {
/** {@inheritdoc} */
public function getTitle() {
return /* I18N: Name of a module */ I18N::translate('Families');
}
/** {@inheritdoc} */
public function getDescription() {
return /* I18N: Description of the “Families” module */ I18N::translate('A tab showing the close relatives of an individual.');
}
/** {@inheritdoc} */
public function defaultTabOrder() {
return 20;
}
/**
* @param Date $prev
* @param Date $next
* @param int $child_number
*
* @return string
*/
private static function ageDifference(Date $prev, Date $next, $child_number = 0) {
if ($prev->isOK() && $next->isOK()) {
$days = $next->maximumJulianDay() - $prev->minimumJulianDay();
if ($days < 0) {
// Show warning triangle if dates in reverse order
$diff = '<i class="icon-warning"></i> ';
} elseif ($child_number > 1 && $days > 1 && $days < 240) {
// Show warning triangle if children born too close together
$diff = '<i class="icon-warning"></i> ';
} else {
$diff = '';
}
$months = round($days * 12 / 365.25); // Approximate - we do not know the calendar
if (abs($months) == 12 || abs($months) >= 24) {
$diff .= I18N::plural('%s year', '%s years', round($months / 12), I18N::number(round($months / 12)));
} elseif ($months != 0) {
$diff .= I18N::plural('%s month', '%s months', $months, I18N::number($months));
}
return '<div class="elderdate age">' . $diff . '</div>';
} else {
return '';
}
}
/**
* @param Family $family
* @param string $type
* @param string $label
*/
private function printFamily(Family $family, $type, $label) {
global $controller;
if ($family->getTree()->getPreference('SHOW_PRIVATE_RELATIONSHIPS')) {
$access_level = Auth::PRIV_HIDE;
} else {
$access_level = Auth::accessLevel($family->getTree());
}
?>
<table>
<tr>
<td>
<i class="icon-cfamily"></i>
</td>
<td>
<span class="subheaders"> <?php echo $label; ?> </span> -
<a href="<?php echo $family->getHtmlUrl(); ?>"><?php echo I18N::translate('View family'); ?></a>
</td>
</tr>
</table>
<table class="facts_table">
<?php
///// HUSB /////
$found = false;
foreach ($family->getFacts('HUSB', false, $access_level) as $fact) {
$found |= !$fact->isPendingDeletion();
$person = $fact->getTarget();
if ($person instanceof Individual) {
if ($fact->isPendingAddition()) {
$class = 'facts_label new';
} elseif ($fact->isPendingDeletion()) {
$class = 'facts_label old';
} else {
$class = 'facts_label';
}
?>
<tr>
<td class="<?php echo $class; ?>">
<?php echo Functions::getCloseRelationshipName($controller->record, $person); ?>
</td>
<td class="<?php echo $controller->getPersonStyle($person); ?>">
<?php echo Theme::theme()->individualBoxLarge($person); ?>
</td>
</tr>
<?php
}
}
if (!$found && $family->canEdit()) {
?>
<tr>
<td class="facts_label"></td>
<td class="facts_value"><a href="#" onclick="return add_spouse_to_family('<?php echo $family->getXref(); ?>', 'HUSB');"><?php echo I18N::translate('Add a husband to this family'); ?></a></td>
</tr>
<?php
}
///// WIFE /////
$found = false;
foreach ($family->getFacts('WIFE', false, $access_level) as $fact) {
$person = $fact->getTarget();
if ($person instanceof Individual) {
$found |= !$fact->isPendingDeletion();
if ($fact->isPendingAddition()) {
$class = 'facts_label new';
} elseif ($fact->isPendingDeletion()) {
$class = 'facts_label old';
} else {
$class = 'facts_label';
}
?>
<tr>
<td class="<?php echo $class; ?>">
<?php echo Functions::getCloseRelationshipName($controller->record, $person); ?>
</td>
<td class="<?php echo $controller->getPersonStyle($person); ?>">
<?php echo Theme::theme()->individualBoxLarge($person); ?>
</td>
</tr>
<?php
}
}
if (!$found && $family->canEdit()) {
?>
<tr>
<td class="facts_label"></td>
<td class="facts_value"><a href="#" onclick="return add_spouse_to_family('<?php echo $family->getXref(); ?>', 'WIFE');"><?php echo I18N::translate('Add a wife to this family'); ?></a></td>
</tr>
<?php
}
///// MARR /////
$found = false;
$prev = new Date('');
foreach ($family->getFacts(WT_EVENTS_MARR) as $fact) {
$found |= !$fact->isPendingDeletion();
if ($fact->isPendingAddition()) {
$class = ' new';
} elseif ($fact->isPendingDeletion()) {
$class = ' old';
} else {
$class = '';
}
?>
<tr>
<td class="facts_label">
</td>
<td class="facts_value<?php echo $class; ?>">
<?php echo GedcomTag::getLabelValue($fact->getTag(), $fact->getDate()->display() . ' — ' . $fact->getPlace()->getFullName()); ?>
</td>
</tr>
<?php
if (!$prev->isOK() && $fact->getDate()->isOK()) {
$prev = $fact->getDate();
}
}
if (!$found && $family->canShow() && $family->canEdit()) {
// Add a new marriage
?>
<tr>
<td class="facts_label">
</td>
<td class="facts_value">
<a href="#" onclick="return add_new_record('<?php echo $family->getXref(); ?>', 'MARR');">
<?php echo I18N::translate('Add marriage details'); ?>
</a>
</td>
</tr>
<?php
}
///// CHIL /////
$child_number = 0;
foreach ($family->getFacts('CHIL', false, $access_level) as $fact) {
$person = $fact->getTarget();
if ($person instanceof Individual) {
if ($fact->isPendingAddition()) {
$child_number++;
$class = 'facts_label new';
} elseif ($fact->isPendingDeletion()) {
$class = 'facts_label old';
} else {
$child_number++;
$class = 'facts_label';
}
$next = new Date('');
foreach ($person->getFacts(WT_EVENTS_BIRT) as $bfact) {
if ($bfact->getDate()->isOK()) {
$next = $bfact->getDate();
break;
}
}
?>
<tr>
<td class="<?php echo $class; ?>">
<?php echo self::ageDifference($prev, $next, $child_number); ?>
<?php echo Functions::getCloseRelationshipName($controller->record, $person); ?>
</td>
<td class="<?php echo $controller->getPersonStyle($person); ?>">
<?php echo Theme::theme()->individualBoxLarge($person); ?>
</td>
</tr>
<?php
$prev = $next;
}
}
// Re-order children / add a new child
if ($family->canEdit()) {
if ($type == 'FAMS') {
$add_child_text = I18N::translate('Add a new son or daughter');
} else {
$add_child_text = I18N::translate('Add a new brother or sister');
}
?>
<tr>
<td class="facts_label">
<?php if (count($family->getChildren()) > 1) { ?>
<a href="#" onclick="reorder_children('<?php echo $family->getXref(); ?>');tabswitch(5);"><i class="icon-media-shuffle"></i> <?php echo I18N::translate('Re-order children'); ?></a>
<?php } ?>
</td>
<td class="facts_value">
<a href="#" onclick="return add_child_to_family('<?php echo $family->getXref(); ?>');"><?php echo $add_child_text; ?></a>
<span style='white-space:nowrap;'>
<a href="#" class="icon-sex_m_15x15" onclick="return add_child_to_family('<?php echo $family->getXref(); ?>','M');"></a>
<a href="#" class="icon-sex_f_15x15" onclick="return add_child_to_family('<?php echo $family->getXref(); ?>','F');"></a>
</span>
</td>
</tr>
<?php
}
echo '</table>';
return;
}
/** {@inheritdoc} */
public function getTabContent() {
global $WT_TREE, $show_full, $controller;
if (isset($show_full)) {
$saved_show_full = $show_full;
}
// We always want to see full details here
$show_full = 1;
ob_start();
?>
<table class="facts_table"><tr><td class="descriptionbox rela">
<input id="checkbox_elder" type="checkbox" onclick="jQuery('div.elderdate').toggle();" <?php echo $WT_TREE->getPreference('SHOW_AGE_DIFF') ? 'checked' : ''; ?>>
<label for="checkbox_elder"><?php echo I18N::translate('Show date differences'); ?></label>
</td></tr></table>
<?php
$families = $controller->record->getChildFamilies();
if (!$families && $controller->record->canEdit()) {
?>
<table class="facts_table">
<tr>
<td class="facts_value"><a href="#" onclick="return add_parent_to_individual('<?php echo $controller->record->getXref(); ?>', 'M');"><?php echo I18N::translate('Add a new father'); ?></td>
</tr>
<tr>
<td class="facts_value"><a href="#" onclick="return add_parent_to_individual('<?php echo $controller->record->getXref(); ?>', 'F');"><?php echo I18N::translate('Add a new mother'); ?></a></td>
</tr>
</table>
<?php
}
// parents
foreach ($families as $family) {
$this->printFamily($family, 'FAMC', $controller->record->getChildFamilyLabel($family));
}
// step-parents
foreach ($controller->record->getChildStepFamilies() as $family) {
$this->printFamily($family, 'FAMC', $controller->record->getStepFamilyLabel($family));
}
// spouses
$families = $controller->record->getSpouseFamilies();
foreach ($families as $family) {
$this->printFamily($family, 'FAMS', $controller->getSpouseFamilyLabel($family, $controller->record));
}
// step-children
foreach ($controller->record->getSpouseStepFamilies() as $family) {
$this->printFamily($family, 'FAMS', $family->getFullName());
}
if (!$WT_TREE->getPreference('SHOW_AGE_DIFF')) {
echo '<script>jQuery("DIV.elderdate").toggle();</script>';
}
if ($controller->record->canEdit()) {
?>
<br><table class="facts_table">
<?php
if (count($families) > 1) { ?>
<tr>
<td class="facts_value">
<a href="#" onclick="return reorder_families('<?php echo $controller->record->getXref(); ?>');"><?php echo I18N::translate('Re-order families'); ?></a>
</td>
</tr>
<?php } ?>
<tr>
<td class="facts_value">
<a href="#" onclick="return add_famc('<?php echo $controller->record->getXref(); ?>');"><?php echo I18N::translate('Link this individual to an existing family as a child'); ?></a>
</td>
</tr>
<?php if ($controller->record->getSex() != "F") { ?>
<tr>
<td class="facts_value">
<a href="#" onclick="return add_spouse_to_individual('<?php echo $controller->record->getXref(); ?>','WIFE');"><?php echo I18N::translate('Add a new wife'); ?></a>
</td>
</tr>
<tr>
<td class="facts_value">
<a href="#" onclick="return linkspouse('<?php echo $controller->record->getXref(); ?>','WIFE');"><?php echo I18N::translate('Add a wife using an existing individual'); ?></a>
</td>
</tr>
<?php }
if ($controller->record->getSex() != "M") { ?>
<tr>
<td class="facts_value">
<a href="#" onclick="return add_spouse_to_individual('<?php echo $controller->record->getXref(); ?>','HUSB');"><?php echo I18N::translate('Add a new husband'); ?></a>
</td>
</tr>
<tr>
<td class="facts_value">
<a href="#" onclick="return linkspouse('<?php echo $controller->record->getXref(); ?>','HUSB');"><?php echo I18N::translate('Add a husband using an existing individual'); ?></a>
</td>
</tr>
<?php } ?>
<tr>
<td class="facts_value">
<a href="#" onclick="return add_child_to_individual('<?php echo $controller->record->getXref(); ?>','U');"><?php echo I18N::translate('Add a child to create a one-parent family'); ?></a>
</td>
</tr>
</table>
<?php } ?>
<br>
<?php
unset($show_full);
if (isset($saved_show_full)) {
$show_full = $saved_show_full;
}
return '<div id="' . $this->getName() . '_content">' . ob_get_clean() . '</div>';
}
/** {@inheritdoc} */
public function hasTabContent() {
return true;
}
/** {@inheritdoc} */
public function isGrayedOut() {
return false;
}
/** {@inheritdoc} */
public function canLoadAjax() {
return !Auth::isSearchEngine(); // Search engines cannot use AJAX
}
/** {@inheritdoc} */
public function getPreLoadContent() {
return '';
}
}
|