Passed
Push — 1.7 ( 6276c0...29b678 )
by
unknown
07:11
created

source.php (12 issues)

1
<?php
2
/**
3
 * webtrees: online genealogy
4
 * Copyright (C) 2017 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
 */
16
namespace Fisharebest\Webtrees;
17
18
/**
19
 * Defined in session.php
20
 *
21
 * @global Tree $WT_TREE
22
 */
23
global $WT_TREE;
24
25
use Fisharebest\Webtrees\Controller\SourceController;
26
use Fisharebest\Webtrees\Functions\FunctionsPrint;
27
use Fisharebest\Webtrees\Functions\FunctionsPrintFacts;
28
use Fisharebest\Webtrees\Functions\FunctionsPrintLists;
29
30
define('WT_SCRIPT_NAME', 'source.php');
31
require './includes/session.php';
32
33
$record     = Source::getInstance(Filter::get('sid', WT_REGEX_XREF), $WT_TREE);
34
$controller = new SourceController($record);
35
36
if ($controller->record && $controller->record->canShow()) {
37
	if ($controller->record->isPendingDeletion()) {
38
		if (Auth::isModerator($controller->record->getTree())) {
39
			FlashMessages::addMessage(/* I18N: %1$s is “accept”, %2$s is “reject”. These are links. */ I18N::translate(
40
				'This source has been deleted. You should review the deletion and then %1$s or %2$s it.',
41
				'<a href="#" onclick="accept_changes(\'' . $controller->record->getXref() . '\');">' . I18N::translateContext('You should review the deletion and then accept or reject it.', 'accept') . '</a>',
42
				'<a href="#" onclick="reject_changes(\'' . $controller->record->getXref() . '\');">' . I18N::translateContext('You should review the deletion and then accept or reject it.', 'reject') . '</a>'
43
			) . ' ' . FunctionsPrint::helpLink('pending_changes'), 'warning');
44
		} elseif (Auth::isEditor($controller->record->getTree())) {
45
			FlashMessages::addMessage(I18N::translate('This source has been deleted. The deletion will need to be reviewed by a moderator.') . ' ' . FunctionsPrint::helpLink('pending_changes'), 'warning');
46
		}
47
	} elseif ($controller->record->isPendingAddtion()) {
48
		if (Auth::isModerator($controller->record->getTree())) {
49
			FlashMessages::addMessage(/* I18N: %1$s is “accept”, %2$s is “reject”. These are links. */ I18N::translate(
50
				'This source has been edited. You should review the changes and then %1$s or %2$s them.',
51
				'<a href="#" onclick="accept_changes(\'' . $controller->record->getXref() . '\');">' . I18N::translateContext('You should review the changes and then accept or reject them.', 'accept') . '</a>',
52
				'<a href="#" onclick="reject_changes(\'' . $controller->record->getXref() . '\');">' . I18N::translateContext('You should review the changes and then accept or reject them.', 'reject') . '</a>'
53
			) . ' ' . FunctionsPrint::helpLink('pending_changes'), 'warning');
54
		} elseif (Auth::isEditor($controller->record->getTree())) {
55
			FlashMessages::addMessage(I18N::translate('This source has been edited. The changes need to be reviewed by a moderator.') . ' ' . FunctionsPrint::helpLink('pending_changes'), 'warning');
56
		}
57
	}
58
	$controller->pageHeader();
59
} else {
60
	FlashMessages::addMessage(I18N::translate('This source does not exist or you do not have permission to view it.'), 'danger');
61
	http_response_code(404);
62
	$controller->pageHeader();
63
64
	return;
65
}
66
67
$controller->addInlineJavascript('
68
	jQuery("#source-tabs")
69
		.tabs({
70
			create: function(e, ui){
71
				jQuery(e.target).css("visibility", "visible");  // prevent FOUC
72
			}
73
		});
74
');
75
76
$linked_fam  = $controller->record->linkedFamilies('SOUR');
77
$linked_indi = $controller->record->linkedIndividuals('SOUR');
78
$linked_note = $controller->record->linkedNotes('SOUR');
79
$linked_obje = $controller->record->linkedMedia('SOUR');
80
$linked_sour = array();
81
82
$facts = $controller->record->getFacts();
83
84
usort(
85
	$facts,
86
	function (Fact $x, Fact $y) {
87
		static $order = array(
88
			'TITL' => 0,
89
			'ABBR' => 1,
90
			'AUTH' => 2,
91
			'DATA' => 3,
92
			'PUBL' => 4,
93
			'TEXT' => 5,
94
			'NOTE' => 6,
95
			'OBJE' => 7,
96
			'REFN' => 8,
97
			'RIN'  => 9,
98
			'_UID' => 10,
99
			'CHAN' => 11,
100
		);
101
102
		return
103
			(array_key_exists($x->getTag(), $order) ? $order[$x->getTag()] : PHP_INT_MAX)
104
			-
105
			(array_key_exists($y->getTag(), $order) ? $order[$y->getTag()] : PHP_INT_MAX);
106
	}
107
);
108
109
?>
110
<div id="source-details">
111
	<h2>
112
		<?php echo $controller->record->getFullName() ?>
113
	</h2>
114
	<div id="source-tabs">
115
		<ul>
116
			<li>
117
				<a href="#source-edit">
118
					<?php echo I18N::translate('Details') ?>
119
				</a>
120
			</li>
121
			<?php if ($linked_indi): ?>
0 ignored issues
show
Bug Best Practice introduced by
The expression $linked_indi of type Fisharebest\Webtrees\Individual[] is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
122
			<li>
123
				<a href="#linked-individuals">
124
					<?php echo I18N::translate('Individuals') ?>
125
				</a>
126
			</li>
127
			<?php endif; ?>
128
			<?php if ($linked_fam): ?>
0 ignored issues
show
Bug Best Practice introduced by
The expression $linked_fam of type Fisharebest\Webtrees\Family[] is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
129
			<li>
130
				<a href="#linked-families">
131
					<?php echo I18N::translate('Families') ?>
132
				</a>
133
			</li>
134
			<?php endif; ?>
135
			<?php if ($linked_obje): ?>
0 ignored issues
show
Bug Best Practice introduced by
The expression $linked_obje of type Fisharebest\Webtrees\Media[] is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
136
			<li>
137
				<a href="#linked-media">
138
					<?php echo I18N::translate('Media objects') ?>
139
				</a>
140
			</li>
141
			<?php endif; ?>
142
			<?php if ($linked_sour): ?>
0 ignored issues
show
Bug Best Practice introduced by
The expression $linked_sour of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
$linked_sour is an empty array, thus is always false.
Loading history...
143
			<li>
144
				<a href="#linked-sources"><?php echo I18N::translate('Sources') ?></a>
145
			</li>
146
			<?php endif; ?>
147
			<?php if ($linked_note): ?>
0 ignored issues
show
Bug Best Practice introduced by
The expression $linked_note of type Fisharebest\Webtrees\Note[] is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
148
			<li>
149
				<a href="#linked-notes"><?php echo I18N::translate('Notes') ?></a>
150
			</li>
151
			<?php endif; ?>
152
		</ul>
153
154
		<div id="source-edit">
155
			<table class="facts_table">
156
				<?php
157
				foreach ($facts as $fact) {
158
					FunctionsPrintFacts::printFact($fact, $controller->record);
159
				}
160
161
				if ($controller->record->canEdit()) {
162
					FunctionsPrint::printAddNewFact($controller->record->getXref(), $facts, 'SOUR');
163
					// new media
164
					if ($controller->record->getTree()->getPreference('MEDIA_UPLOAD') >= Auth::accessLevel($WT_TREE)) {
165
						echo '<tr><td class="descriptionbox">';
166
						echo GedcomTag::getLabel('OBJE');
167
						echo '</td><td class="optionbox">';
168
						echo '<a href="#" onclick="window.open(\'addmedia.php?action=showmediaform&amp;linktoid=', $controller->record->getXref(), '\', \'_blank\', edit_window_specs); return false;">', I18N::translate('Add a media object'), '</a>';
169
						echo FunctionsPrint::helpLink('OBJE');
170
						echo '<br>';
171
						echo '<a href="#" onclick="window.open(\'inverselink.php?linktoid=', $controller->record->getXref(), '&amp;linkto=source\', \'_blank\', find_window_specs); return false;">', I18N::translate('Link to an existing media object'), '</a>';
172
						echo '</td></tr>';
173
					}
174
				}
175
				?>
176
			</table>
177
		</div>
178
179
		<?php if ($linked_indi): ?>
0 ignored issues
show
Bug Best Practice introduced by
The expression $linked_indi of type Fisharebest\Webtrees\Individual[] is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
180
			<div id="linked-individuals">
181
				<?php echo FunctionsPrintLists::individualTable($linked_indi) ?>
182
			</div>
183
		<?php endif; ?>
184
185
		<?php if ($linked_fam): ?>
0 ignored issues
show
Bug Best Practice introduced by
The expression $linked_fam of type Fisharebest\Webtrees\Family[] is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
186
			<div id="linked-families">
187
				<?php echo FunctionsPrintLists::familyTable($linked_fam) ?>
188
			</div>
189
		<?php endif; ?>
190
191
		<?php if ($linked_obje): ?>
0 ignored issues
show
Bug Best Practice introduced by
The expression $linked_obje of type Fisharebest\Webtrees\Media[] is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
192
			<div id="linked-media">
193
				<?php echo FunctionsPrintLists::mediaTable($linked_obje) ?>
194
			</div>
195
		<?php endif; ?>
196
197
		<?php if ($linked_sour): ?>
0 ignored issues
show
Bug Best Practice introduced by
The expression $linked_sour of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
$linked_sour is an empty array, thus is always false.
Loading history...
198
			<div id="linked-sources">
199
				<?php echo FunctionsPrintLists::sourceTable($linked_sour) ?>
200
			</div>
201
		<?php endif; ?>
202
203
		<?php if ($linked_note): ?>
0 ignored issues
show
Bug Best Practice introduced by
The expression $linked_note of type Fisharebest\Webtrees\Note[] is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
204
			<div id="linked-notes">
205
				<?php echo FunctionsPrintLists::noteTable($linked_note) ?>
206
			</div>
207
		<?php endif; ?>
208
	</div>
209
</div>
210