xref: /webtrees/resources/views/modules/notes/tab.phtml (revision bd29d468ac3a5ed7a23d7dd8f300504dda83fc72)
12917771cSGreg Roach<?php
22917771cSGreg Roach
3b315f3e1SGreg Roachuse Fisharebest\Webtrees\Elements\SubmitterText;
47c2c99faSGreg Roachuse Fisharebest\Webtrees\Fact;
5b315f3e1SGreg Roachuse Fisharebest\Webtrees\Gedcom;
62917771cSGreg Roachuse Fisharebest\Webtrees\Http\RequestHandlers\AddNewFact;
72917771cSGreg Roachuse Fisharebest\Webtrees\I18N;
87c2c99faSGreg Roachuse Fisharebest\Webtrees\Individual;
9b315f3e1SGreg Roachuse Fisharebest\Webtrees\Note;
10b315f3e1SGreg Roachuse Fisharebest\Webtrees\Registry;
117c2c99faSGreg Roachuse Illuminate\Support\Collection;
127c2c99faSGreg Roach
137c2c99faSGreg Roach/**
147c2c99faSGreg Roach * @var bool                 $can_edit
1536779af1SGreg Roach * @var Collection<int,Fact> $clipboard_facts
1636779af1SGreg Roach * @var Collection<int,Fact> $facts
177c2c99faSGreg Roach * @var Individual           $individual
187c2c99faSGreg Roach */
192917771cSGreg Roach
202917771cSGreg Roach?>
21dd6b2bfcSGreg Roach
224a2590a5SGreg Roach<div class="wt-tan-notes py-4">
23dd6b2bfcSGreg Roach    <table class="table wt-facts-table">
24dd6b2bfcSGreg Roach        <tr>
25dd6b2bfcSGreg Roach            <td colspan="2">
26dd6b2bfcSGreg Roach                <label>
270363a7fdSDavid Drury                    <input id="show-level-2-notes" type="checkbox" data-bs-toggle="collapse" data-bs-target=".wt-level-two-note" data-wt-persist="level-two-notes" autocomplete="off">
28dd6b2bfcSGreg Roach                    <?= I18N::translate('Show all notes') ?>
29dd6b2bfcSGreg Roach                </label>
30dd6b2bfcSGreg Roach            </td>
31dd6b2bfcSGreg Roach        </tr>
32dd6b2bfcSGreg Roach
33dd6b2bfcSGreg Roach        <?php foreach ($facts as $fact) : ?>
34b315f3e1SGreg Roach            <?php if ($fact->tag() === 'INDI:NOTE' || $fact->tag() === 'FAM:NOTE') : ?>
35b315f3e1SGreg Roach                <?= view('fact', ['fact' => $fact, 'record' => $individual]) ?>
36b315f3e1SGreg Roach            <?php else : ?>
37b315f3e1SGreg Roach                <?php
38b315f3e1SGreg Roach                if ($fact->isPendingAddition()) {
39b315f3e1SGreg Roach                    $styleadd = 'wt-new ';
40b315f3e1SGreg Roach                } elseif ($fact->isPendingDeletion()) {
41b315f3e1SGreg Roach                    $styleadd = 'wt-old ';
42b315f3e1SGreg Roach                } else {
43b315f3e1SGreg Roach                    $styleadd = '';
44b315f3e1SGreg Roach                }
45b315f3e1SGreg Roach                ?>
46b315f3e1SGreg Roach
47b315f3e1SGreg Roach                <tr class="wt-level-two-note collapse">
48b315f3e1SGreg Roach                    <th scope="row" class="rela <?= $styleadd ?>">
49b315f3e1SGreg Roach                        <?= $fact->label() ?>
50b315f3e1SGreg Roach                        <?= view('fact-edit-links', ['fact' => $fact, 'url' => $fact->record()->url() . '#tab-notes']) ?>
51b315f3e1SGreg Roach                    </th>
52b315f3e1SGreg Roach
53b315f3e1SGreg Roach                    <td class="<?= $styleadd ?>">
54b315f3e1SGreg Roach                        <?php preg_match_all("/\n[1-9] NOTE ?(.*(?:\n\d CONT.*)*)/", $fact->gedcom(), $matches, PREG_SET_ORDER) ?>
55b315f3e1SGreg Roach                        <?php foreach ($matches as $match) : ?>
56b315f3e1SGreg Roach                            <div class="mb-2">
57b315f3e1SGreg Roach                                <?php $text = preg_replace('/\n\d CONT ?/', "\n", $match[1]) ?>
58*bd29d468SGreg Roach                                <?php if (preg_match('/^@' . Gedcom::REGEX_XREF . '@$/', $text) === 1) : ?>
59b315f3e1SGreg Roach                                    <?php $note = Registry::noteFactory()->make(trim($text, '@'), $individual->tree()) ?>
60b315f3e1SGreg Roach                                    <?php if ($note instanceof Note) : ?>
61b315f3e1SGreg Roach                                        <?php if ($note->canShow()) : ?>
62b315f3e1SGreg Roach                                            <a href="<?= e($note->url()) ?>">
63b315f3e1SGreg Roach                                                <?= I18N::translate('Shared note') ?>
64b315f3e1SGreg Roach                                                <?= view('icons/note') ?>
65b315f3e1SGreg Roach                                            </a>
66b315f3e1SGreg Roach                                            <?= (new SubmitterText(''))->value($note->getNote(), $individual->tree()) ?>
67b315f3e1SGreg Roach                                        <?php endif ?>
68b315f3e1SGreg Roach                                    <?php else : ?>
69b315f3e1SGreg Roach                                        <span class="error"><?= e($text) ?></span>
70b315f3e1SGreg Roach                                    <?php endif ?>
71b315f3e1SGreg Roach                                <?php else : ?>
72b315f3e1SGreg Roach                                    <?= (new SubmitterText(''))->value($text, $individual->tree()) ?>
73b315f3e1SGreg Roach                                <?php endif ?>
74b315f3e1SGreg Roach                            </div>
75dd6b2bfcSGreg Roach                        <?php endforeach ?>
76b315f3e1SGreg Roach                    </td>
77b315f3e1SGreg Roach                </tr>
78*bd29d468SGreg Roach            <?php endif ?>
79*bd29d468SGreg Roach        <?php endforeach ?>
80dd6b2bfcSGreg Roach
81075d1a05SGreg Roach        <?php if ($facts->isEmpty()) : ?>
82dd6b2bfcSGreg Roach            <tr>
83dd6b2bfcSGreg Roach                <td colspan="2">
84dd6b2bfcSGreg Roach                    <?= I18N::translate('There are no notes for this individual.') ?>
85dd6b2bfcSGreg Roach                </td>
86dd6b2bfcSGreg Roach            </tr>
87dd6b2bfcSGreg Roach        <?php endif ?>
88dd6b2bfcSGreg Roach
89dd6b2bfcSGreg Roach        <?php if ($can_edit) : ?>
90dd6b2bfcSGreg Roach            <tr>
91dd6b2bfcSGreg Roach                <th scope="row">
92dd6b2bfcSGreg Roach                    <?= I18N::translate('Note') ?>
93dd6b2bfcSGreg Roach                </th>
94dd6b2bfcSGreg Roach                <td>
952917771cSGreg Roach                    <a href="<?= e(route(AddNewFact::class, ['tree' => $individual->tree()->name(), 'xref' => $individual->xref(), 'fact' => 'NOTE'])) ?>">
96dd6b2bfcSGreg Roach                        <?= I18N::translate('Add a note') ?>
97dd6b2bfcSGreg Roach                    </a>
98dd6b2bfcSGreg Roach                </td>
99dd6b2bfcSGreg Roach            </tr>
100dd6b2bfcSGreg Roach        <?php endif ?>
101dd6b2bfcSGreg Roach    </table>
102dd6b2bfcSGreg Roach</div>
103