1<?php
2/**
3 * webtrees: online genealogy
4 * Copyright (C) 2019 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 */
16namespace Fisharebest\Webtrees;
17
18/**
19 * Defined in session.php
20 *
21 * @global Tree $WT_TREE
22 */
23global $WT_TREE;
24
25use Fisharebest\Webtrees\Controller\GedcomRecordController;
26use Fisharebest\Webtrees\Functions\FunctionsPrint;
27use Fisharebest\Webtrees\Functions\FunctionsPrintFacts;
28use Fisharebest\Webtrees\Functions\FunctionsPrintLists;
29
30define('WT_SCRIPT_NAME', 'gedrecord.php');
31require './includes/session.php';
32
33$record = GedcomRecord::getInstance(Filter::get('pid', WT_REGEX_XREF), $WT_TREE);
34if (
35    $record instanceof Individual ||
36    $record instanceof Family ||
37    $record instanceof Source ||
38    $record instanceof Repository ||
39    $record instanceof Note ||
40    $record instanceof Media
41) {
42    header('Location: ' . WT_BASE_URL . $record->getRawUrl());
43
44    return;
45}
46$controller = new GedcomRecordController($record);
47
48if ($controller->record && $controller->record->canShow()) {
49    if ($controller->record->isPendingDeletion()) {
50        if (Auth::isModerator($controller->record->getTree())) {
51            FlashMessages::addMessage(/* I18N: %1$s is “accept”, %2$s is “reject”. These are links. */ I18N::translate(
52                'This record has been deleted. You should review the deletion and then %1$s or %2$s it.',
53                '<a href="#" onclick="accept_changes(\'' . $controller->record->getXref() . '\');">' . I18N::translateContext('You should review the deletion and then accept or reject it.', 'accept') . '</a>',
54                '<a href="#" onclick="reject_changes(\'' . $controller->record->getXref() . '\');">' . I18N::translateContext('You should review the deletion and then accept or reject it.', 'reject') . '</a>'
55            ) . ' ' . FunctionsPrint::helpLink('pending_changes'), 'warning');
56        } elseif (Auth::isEditor($controller->record->getTree())) {
57            FlashMessages::addMessage(I18N::translate('This record has been deleted. The deletion will need to be reviewed by a moderator.') . ' ' . FunctionsPrint::helpLink('pending_changes'), 'warning');
58        }
59    } elseif ($controller->record->isPendingAddtion()) {
60        if (Auth::isModerator($controller->record->getTree())) {
61            FlashMessages::addMessage(/* I18N: %1$s is “accept”, %2$s is “reject”. These are links. */ I18N::translate(
62                'This record has been edited. You should review the changes and then %1$s or %2$s them.',
63                '<a href="#" onclick="accept_changes(\'' . $controller->record->getXref() . '\');">' . I18N::translateContext('You should review the changes and then accept or reject them.', 'accept') . '</a>',
64                '<a href="#" onclick="reject_changes(\'' . $controller->record->getXref() . '\');">' . I18N::translateContext('You should review the changes and then accept or reject them.', 'reject') . '</a>'
65            ) . ' ' . FunctionsPrint::helpLink('pending_changes'), 'warning');
66        } elseif (Auth::isEditor($controller->record->getTree())) {
67            FlashMessages::addMessage(I18N::translate('This record has been edited. The changes need to be reviewed by a moderator.') . ' ' . FunctionsPrint::helpLink('pending_changes'), 'warning');
68        }
69    }
70    $controller->pageHeader();
71} else {
72    FlashMessages::addMessage(I18N::translate('This record does not exist or you do not have permission to view it.'), 'danger');
73    http_response_code(404);
74    $controller->pageHeader();
75
76    return;
77}
78
79$controller->addInlineJavascript('
80	jQuery("#record-tabs")
81		.tabs({
82			create: function(e, ui){
83				jQuery(e.target).css("visibility", "visible");  // prevent FOUC
84			}
85		});
86');
87
88$linked_indi = $controller->record->linkedIndividuals('SUBM');
89$linked_fam  = $controller->record->linkedFamilies('SUBM');
90$linked_obje = $controller->record->linkedMedia('SUBM');
91$linked_sour = $controller->record->linkedSources('SUBM');
92$linked_note = $controller->record->linkedNotes('SUBM');
93
94$facts = $controller->record->getFacts();
95
96?>
97<div id="record-details">
98    <h2>
99        <?php echo $controller->record->getFullName() ?>
100    </h2>
101    <div id="record-tabs">
102        <ul>
103            <li>
104                <a href="#record-edit">
105                    <?php echo I18N::translate('Details') ?>
106                </a>
107            </li>
108            <?php if ($linked_indi): ?>
109            <li>
110                <a href="#linked-individuals">
111                    <?php echo I18N::translate('Individuals') ?>
112                </a>
113            </li>
114            <?php endif; ?>
115            <?php if ($linked_fam): ?>
116            <li>
117                <a href="#linked-families">
118                    <?php echo I18N::translate('Families') ?>
119                </a>
120            </li>
121            <?php endif; ?>
122            <?php if ($linked_obje): ?>
123            <li>
124                <a href="#linked-media">
125                    <?php echo I18N::translate('Media objects') ?>
126                </a>
127            </li>
128            <?php endif; ?>
129            <?php if ($linked_sour): ?>
130            <li>
131                <a href="#linked-sources"><?php echo I18N::translate('Sources') ?></a>
132            </li>
133            <?php endif; ?>
134            <?php if ($linked_note): ?>
135            <li>
136                <a href="#linked-notes"><?php echo I18N::translate('Notes') ?></a>
137            </li>
138            <?php endif; ?>
139        </ul>
140
141        <div id="record-edit">
142            <table class="facts_table">
143                <?php
144                foreach ($facts as $fact) {
145                    FunctionsPrintFacts::printFact($fact, $controller->record);
146                }
147                ?>
148            </table>
149        </div>
150
151        <?php if ($linked_indi): ?>
152            <div id="linked-individuals">
153                <?php echo FunctionsPrintLists::individualTable($linked_indi) ?>
154            </div>
155        <?php endif; ?>
156
157        <?php if ($linked_fam): ?>
158            <div id="linked-families">
159                <?php echo FunctionsPrintLists::familyTable($linked_fam) ?>
160            </div>
161        <?php endif; ?>
162
163        <?php if ($linked_obje): ?>
164            <div id="linked-media">
165                <?php echo FunctionsPrintLists::mediaTable($linked_obje) ?>
166            </div>
167        <?php endif; ?>
168
169        <?php if ($linked_sour): ?>
170            <div id="linked-sources">
171                <?php echo FunctionsPrintLists::sourceTable($linked_sour) ?>
172            </div>
173        <?php endif; ?>
174
175        <?php if ($linked_note): ?>
176            <div id="linked-notes">
177                <?php echo FunctionsPrintLists::noteTable($linked_note) ?>
178            </div>
179        <?php endif; ?>
180    </div>
181</div>
182