xref: /webtrees/resources/views/modules/sources_tab/tab.phtml (revision 4991f2057a6647447a648c5d6743dab00378e98e)
1<?php
2
3use Fisharebest\Webtrees\Fact;
4use Fisharebest\Webtrees\Http\RequestHandlers\AddNewFact;
5use Fisharebest\Webtrees\I18N;
6use Fisharebest\Webtrees\Individual;
7use Illuminate\Support\Collection;
8
9/**
10 * @var bool                 $can_edit
11 * @var Collection<int,Fact> $clipboard_facts
12 * @var Collection<int,Fact> $facts
13 * @var Individual           $individual
14 */
15
16?>
17
18<div class="wt-tab-sources py-4">
19    <table class="table wt-facts-table">
20        <tr>
21            <td colspan="2">
22                <label>
23                    <input id="show-level-2-sources" type="checkbox" data-bs-toggle="collapse" data-bs-target=".wt-level-two-source" data-wt-persist="level-two-sources" autocomplete="off">
24                    <?= I18N::translate('Show all sources') ?>
25                </label>
26            </td>
27        </tr>
28
29        <?php foreach ($facts as $fact) : ?>
30            <?php if (str_ends_with($fact->tag(), ':SOUR')) : ?>
31                <?= view('fact', ['fact' => $fact, 'record' => $individual]) ?>
32            <?php else : ?>
33                <?php
34                    if ($fact->isPendingAddition()) {
35                        $styleadd = 'wt-new ';
36                    } elseif ($fact->isPendingDeletion()) {
37                        $styleadd = 'wt-old ';
38                    } else {
39                        $styleadd = '';
40                    }
41                ?>
42
43                <tr class="wt-level-two-source collapse">
44                    <th scope="row" class="rela <?= $styleadd ?>">
45                        <?= $fact->label() ?>
46                        <?= view('fact-edit-links', ['fact' => $fact, 'url' => $fact->record()->url() . '#tab-sources']) ?>
47                    </th>
48
49                    <td class="<?= $styleadd ?>">
50                        <?php if (preg_match_all('/\n(2 SOUR\b.*(?:\n[^2].*)*)/', $fact->gedcom(), $matches, PREG_SET_ORDER) > 0) : ?>
51                            <?php foreach($matches as $match) : ?>
52                                <?= view('fact-gedcom-fields', ['gedcom' => $match[1], 'parent' => $fact->tag(), 'tree' => $fact->record()->tree()]) ?>
53                            <?php endforeach ?>
54                        <?php endif ?>
55                    </td>
56                </tr>
57            <?php endif ?>
58        <?php endforeach ?>
59
60        <?php if ($facts->isEmpty()) : ?>
61            <tr>
62                <td colspan="2">
63                    <?= I18N::translate('There are no source citations for this individual.') ?>
64                </td>
65            </tr>
66        <?php endif ?>
67
68        <?php if ($can_edit) : ?>
69            <tr>
70                <th scope="row">
71                    <?= I18N::translate('Source') ?>
72                </th>
73                <td>
74                    <a href="<?= e(route(AddNewFact::class, ['tree' => $individual->tree()->name(), 'xref' => $individual->xref(), 'fact' => 'SOUR'])) ?>">
75                        <?= I18N::translate('Add a source citation') ?>
76                    </a>
77                </td>
78            </tr>
79        <?php endif ?>
80    </table>
81</div>
82