xref: /webtrees/resources/views/modules/notes/tab.phtml (revision 10e0649788c8d7d4974d81c048ca2b225df8f22e)
12917771cSGreg Roach<?php
22917771cSGreg Roach
3*10e06497SGreg Roachdeclare(strict_types=1);
4*10e06497SGreg Roach
5b315f3e1SGreg Roachuse Fisharebest\Webtrees\Elements\SubmitterText;
67c2c99faSGreg Roachuse Fisharebest\Webtrees\Fact;
7b315f3e1SGreg Roachuse Fisharebest\Webtrees\Gedcom;
82917771cSGreg Roachuse Fisharebest\Webtrees\Http\RequestHandlers\AddNewFact;
92917771cSGreg Roachuse Fisharebest\Webtrees\I18N;
107c2c99faSGreg Roachuse Fisharebest\Webtrees\Individual;
11b315f3e1SGreg Roachuse Fisharebest\Webtrees\Note;
12b315f3e1SGreg Roachuse Fisharebest\Webtrees\Registry;
137c2c99faSGreg Roachuse Illuminate\Support\Collection;
147c2c99faSGreg Roach
157c2c99faSGreg Roach/**
167c2c99faSGreg Roach * @var bool                 $can_edit
1736779af1SGreg Roach * @var Collection<int,Fact> $clipboard_facts
1836779af1SGreg Roach * @var Collection<int,Fact> $facts
197c2c99faSGreg Roach * @var Individual           $individual
207c2c99faSGreg Roach */
212917771cSGreg Roach
222917771cSGreg Roach?>
23dd6b2bfcSGreg Roach
244a2590a5SGreg Roach<div class="wt-tan-notes py-4">
25dd6b2bfcSGreg Roach    <table class="table wt-facts-table">
26dd6b2bfcSGreg Roach        <tr>
27dd6b2bfcSGreg Roach            <td colspan="2">
28dd6b2bfcSGreg Roach                <label>
290363a7fdSDavid 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">
30dd6b2bfcSGreg Roach                    <?= I18N::translate('Show all notes') ?>
31dd6b2bfcSGreg Roach                </label>
32dd6b2bfcSGreg Roach            </td>
33dd6b2bfcSGreg Roach        </tr>
34dd6b2bfcSGreg Roach
35dd6b2bfcSGreg Roach        <?php foreach ($facts as $fact) : ?>
36b315f3e1SGreg Roach            <?php if ($fact->tag() === 'INDI:NOTE' || $fact->tag() === 'FAM:NOTE') : ?>
37b315f3e1SGreg Roach                <?= view('fact', ['fact' => $fact, 'record' => $individual]) ?>
38b315f3e1SGreg Roach            <?php else : ?>
39b315f3e1SGreg Roach                <?php
40b315f3e1SGreg Roach                if ($fact->isPendingAddition()) {
41b315f3e1SGreg Roach                    $styleadd = 'wt-new ';
42b315f3e1SGreg Roach                } elseif ($fact->isPendingDeletion()) {
43b315f3e1SGreg Roach                    $styleadd = 'wt-old ';
44b315f3e1SGreg Roach                } else {
45b315f3e1SGreg Roach                    $styleadd = '';
46b315f3e1SGreg Roach                }
47b315f3e1SGreg Roach                ?>
48b315f3e1SGreg Roach
49b315f3e1SGreg Roach                <tr class="wt-level-two-note collapse">
50b315f3e1SGreg Roach                    <th scope="row" class="rela <?= $styleadd ?>">
51b315f3e1SGreg Roach                        <?= $fact->label() ?>
52b315f3e1SGreg Roach                        <?= view('fact-edit-links', ['fact' => $fact, 'url' => $fact->record()->url() . '#tab-notes']) ?>
53b315f3e1SGreg Roach                    </th>
54b315f3e1SGreg Roach
55b315f3e1SGreg Roach                    <td class="<?= $styleadd ?>">
56b315f3e1SGreg Roach                        <?php preg_match_all("/\n[1-9] NOTE ?(.*(?:\n\d CONT.*)*)/", $fact->gedcom(), $matches, PREG_SET_ORDER) ?>
57b315f3e1SGreg Roach                        <?php foreach ($matches as $match) : ?>
58b315f3e1SGreg Roach                            <div class="mb-2">
59b315f3e1SGreg Roach                                <?php $text = preg_replace('/\n\d CONT ?/', "\n", $match[1]) ?>
60bd29d468SGreg Roach                                <?php if (preg_match('/^@' . Gedcom::REGEX_XREF . '@$/', $text) === 1) : ?>
61b315f3e1SGreg Roach                                    <?php $note = Registry::noteFactory()->make(trim($text, '@'), $individual->tree()) ?>
62b315f3e1SGreg Roach                                    <?php if ($note instanceof Note) : ?>
63b315f3e1SGreg Roach                                        <?php if ($note->canShow()) : ?>
64b315f3e1SGreg Roach                                            <a href="<?= e($note->url()) ?>">
65b315f3e1SGreg Roach                                                <?= I18N::translate('Shared note') ?>
66b315f3e1SGreg Roach                                                <?= view('icons/note') ?>
67b315f3e1SGreg Roach                                            </a>
68b315f3e1SGreg Roach                                            <?= (new SubmitterText(''))->value($note->getNote(), $individual->tree()) ?>
69b315f3e1SGreg Roach                                        <?php endif ?>
70b315f3e1SGreg Roach                                    <?php else : ?>
71b315f3e1SGreg Roach                                        <span class="error"><?= e($text) ?></span>
72b315f3e1SGreg Roach                                    <?php endif ?>
73b315f3e1SGreg Roach                                <?php else : ?>
74b315f3e1SGreg Roach                                    <?= (new SubmitterText(''))->value($text, $individual->tree()) ?>
75b315f3e1SGreg Roach                                <?php endif ?>
76b315f3e1SGreg Roach                            </div>
77dd6b2bfcSGreg Roach                        <?php endforeach ?>
78b315f3e1SGreg Roach                    </td>
79b315f3e1SGreg Roach                </tr>
80bd29d468SGreg Roach            <?php endif ?>
81bd29d468SGreg Roach        <?php endforeach ?>
82dd6b2bfcSGreg Roach
83075d1a05SGreg Roach        <?php if ($facts->isEmpty()) : ?>
84dd6b2bfcSGreg Roach            <tr>
85dd6b2bfcSGreg Roach                <td colspan="2">
86dd6b2bfcSGreg Roach                    <?= I18N::translate('There are no notes for this individual.') ?>
87dd6b2bfcSGreg Roach                </td>
88dd6b2bfcSGreg Roach            </tr>
89dd6b2bfcSGreg Roach        <?php endif ?>
90dd6b2bfcSGreg Roach
91dd6b2bfcSGreg Roach        <?php if ($can_edit) : ?>
92dd6b2bfcSGreg Roach            <tr>
93dd6b2bfcSGreg Roach                <th scope="row">
94dd6b2bfcSGreg Roach                    <?= I18N::translate('Note') ?>
95dd6b2bfcSGreg Roach                </th>
96dd6b2bfcSGreg Roach                <td>
972917771cSGreg Roach                    <a href="<?= e(route(AddNewFact::class, ['tree' => $individual->tree()->name(), 'xref' => $individual->xref(), 'fact' => 'NOTE'])) ?>">
98dd6b2bfcSGreg Roach                        <?= I18N::translate('Add a note') ?>
99dd6b2bfcSGreg Roach                    </a>
100dd6b2bfcSGreg Roach                </td>
101dd6b2bfcSGreg Roach            </tr>
102dd6b2bfcSGreg Roach        <?php endif ?>
103dd6b2bfcSGreg Roach    </table>
104dd6b2bfcSGreg Roach</div>
105