Passed
Push — 1.7 ( 4c1abf...23cbb7 )
by Greg
08:10
created

search.php (1 issue)

1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 21 and the first side effect is on line 22.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
/**
3
 * webtrees: online genealogy
4
 * Copyright (C) 2018 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
use Fisharebest\Webtrees\Controller\SearchController;
19
use Fisharebest\Webtrees\Functions\FunctionsPrint;
20
21
define('WT_SCRIPT_NAME', 'search.php');
22
require './includes/session.php';
23
24
$controller = new SearchController;
25
$controller
26
	->pageHeader()
27
	->addExternalJavascript(WT_AUTOCOMPLETE_JS_URL)
28
	->addInlineJavascript('autocomplete();');
29
30
?>
31
<script>
32
function checknames(frm) {
33
	action = "<?php echo $controller->action; ?>";
34
	if (action === "general") {
35
		if (frm.query.value.length<2) {
36
			alert("<?php echo I18N::translate('Please enter more than one character.'); ?>");
37
			frm.query.focus();
38
			return false;
39
		}
40
	} else if (action === "soundex") {
41
		year = frm.year.value;
42
		fname = frm.firstname.value;
43
		lname = frm.lastname.value;
44
		place = frm.place.value;
45
46
		if (year == "") {
47
			if (fname.length < 2 && lname.length < 2 && place.length < 2) {
48
				alert("<?php echo I18N::translate('Please enter more than one character.'); ?>");
49
				return false;
50
			}
51
		}
52
53
		if (year != "") {
54
			if (fname === "" && lname === "" && place === "") {
55
				alert("<?php echo I18N::translate('Please enter a given name, surname, or place in addition to the year'); ?>");
56
				frm.firstname.focus();
57
				return false;
58
			}
59
		}
60
		return true;
61
	}
62
	return true;
63
}
64
</script>
65
66
<div id="search-page">
67
<h2><?php echo $controller->getPageTitle(); ?></h2>
68
69
<?php if ($controller->action === 'general'): ?>
70
71
	<form name="searchform" onsubmit="return checknames(this);">
72
		<input type="hidden" name="action" value="general">
73
		<input type="hidden" name="isPostBack" value="true">
74
		<div id="search-page-table">
75
			<div class="label">
76
				<?php echo I18N::translate('Search for'); ?>
77
			</div>
78
			<div class="value">
79
				<input id="query" type="text" name="query" value="<?php echo Filter::escapeHtml($controller->query); ?>" size="40" autofocus>
80
				<?php echo FunctionsPrint::printSpecialCharacterLink('query'); ?>
81
			</div>
82
			<div class="label">
83
				<?php echo I18N::translate('Records'); ?>
84
			</div>
85
			<div class="value">
86
				<label>
87
					<input type="checkbox" <?php echo $controller->srindi; ?> value="checked" name="srindi">
88
					<?php echo I18N::translate('Individuals'); ?>
89
				</label>
90
				<br>
91
				<label>
92
					<input type="checkbox" <?php echo $controller->srfams; ?> value="checked" name="srfams">
93
					<?php echo I18N::translate('Families'); ?>
94
				</label>
95
				<br>
96
				<label>
97
					<input type="checkbox" <?php echo $controller->srsour; ?> value="checked" name="srsour">
98
					<?php echo I18N::translate('Sources'); ?>
99
				</label>
100
				<br>
101
				<label>
102
					<input type="checkbox" <?php echo $controller->srnote; ?> value="checked" name="srnote">
103
					<?php echo I18N::translate('Shared notes'); ?>
104
				</label>
105
			</div>
106
			<div class="label">
107
				<?php echo I18N::translate('Associates'); ?>
108
			</div>
109
			<div class="value">
110
				<input type="checkbox" id="showasso" name="showasso" value="on" <?php echo $controller->showasso === 'on' ? 'checked' : ''; ?>>
111
				<label for="showasso">
112
					<?php echo I18N::translate('Show related individuals/families'); ?>
113
				</label>
114
			</div>
115
			<?php if (count(Tree::getAll()) > 1 && Site::getPreference('ALLOW_CHANGE_GEDCOM')): ?>
116
			<?php if (count(Tree::getAll()) > 3): ?>
117
			<div class="label"></div>
118
			<div class="value">
119
				<input type="button" value="<?php echo /* I18N: select all (of the family trees) */ I18N::translate('select all'); ?>" onclick="jQuery('#search_trees :checkbox').each(function(){jQuery(this).attr('checked', true);});return false;">
120
				<input type="button" value="<?php echo /* I18N: select none (of the family trees) */ I18N::translate('select none'); ?>" onclick="jQuery('#search_trees :checkbox').each(function(){jQuery(this).attr('checked', false);});return false;">
121
				<?php if (count(Tree::getAll()) > 10): ?>
122
				<input type="button" value="<?php echo I18N::translate('invert selection'); ?>" onclick="jQuery('#search_trees :checkbox').each(function(){jQuery(this).attr('checked', !jQuery(this).attr('checked'));});return false;">
123
				<?php endif; ?>
124
				</div>
125
			<?php endif; ?>
126
			<div class="label">
127
				<?php echo I18N::translate('Family trees'); ?>
128
			</div>
129
			<div id="search_trees" class="value">
130
				<?php foreach (Tree::getAll() as $tree): ?>
131
				<p>
132
					<input type="checkbox" <?php echo in_array($tree, $controller->search_trees) ? 'checked' : ''; ?> value="yes" id="tree_<?php echo $tree->getTreeId(); ?>" name="tree_<?php echo $tree->getTreeId(); ?>">
133
					<label for="tree_'<?php echo $tree->getTreeId(); ?>">
134
						<?php echo $tree->getTitleHtml(); ?>
135
					</label>
136
				</p>
137
				<?php endforeach; ?>
138
			</div>
139
			<?php endif; ?>
140
141
			<div class="label"></div>
142
			<div class="value">
143
				<input type="submit" value="<?php echo /* I18N: A button label. */ I18N::translate('search'); ?>">
144
			</div>
145
		</div>
146
	</form>
147
148
<?php endif; ?>
149
<?php if ($controller->action === 'replace'): ?>
150
151
	<form method="post" name="searchform" onsubmit="return checknames(this);">
152
		<input type="hidden" name="action" value="replace">
153
		<input type="hidden" name="isPostBack" value="true">
154
		<div id="search-page-table">
155
			<div class="label">
156
				<?php echo I18N::translate('Search for'); ?>
157
			</div>
158
			<div class="value">
159
				<input name="query" value="<?php echo Filter::escapeHtml($controller->query); ?>" type="text" autofocus>
160
			</div>
161
			<div class="label">
162
				<?php echo I18N::translate('Replace with'); ?>
163
			</div>
164
			<div class="value">
165
				<input name="replace" value="<?php echo Filter::escapeHtml($controller->replace); ?>" type="text">
166
			</div>
167
			<script>
168
				function checkAll(box) {
169
					if (box.checked) {
170
						box.form.replaceNames.disabled = true;
171
						box.form.replacePlaces.disabled = true;
172
						box.form.replacePlacesWord.disabled = true;
173
						box.form.replaceNames.checked = false;
174
						box.form.replacePlaces.checked = false;
175
						box.form.replacePlacesWord.checked = false;
176
					} else {
177
						box.form.replaceNames.disabled = false;
178
						box.form.replacePlaces.disabled = false;
179
						box.form.replacePlacesWord.disabled = false;
180
						box.form.replaceNames.checked = true;
181
					}
182
				}
183
			</script>
184
			<div class="label">
185
				<?php echo /* I18N: A button label. */ I18N::translate('search'); ?>
186
			</div>
187
			<div class="value">
188
				<p>
189
					<label>
190
					<input <?php echo $controller->replaceAll; ?> onclick="checkAll(this);" value="checked" name="replaceAll" type="checkbox">
191
						<?php echo I18N::translate('Entire record'); ?>
192
					</label>
193
					<hr>
194
				</p>
195
				<p>
196
					<label>
197
						<input <?php echo $controller->replaceNames; ?> <?php echo $controller->replaceAll ? 'disabled' : ''; ?> value="checked" name="replaceNames" type="checkbox">
198
						<?php echo I18N::translate('Names'); ?>
199
					</label>
200
				</p>
201
				<p>
202
					<label>
203
						<input <?php echo $controller->replacePlaces; ?> <?php echo $controller->replaceAll ? 'disabled' : ''; ?> value="checked" name="replacePlaces" type="checkbox">
204
						<?php echo I18N::translate('Places'); ?>
205
					</label>
206
				</p>
207
				<p>
208
					<label>
209
					<input <?php echo $controller->replacePlacesWord; ?> <?php echo $controller->replaceAll ? 'disabled' : ''; ?> value="checked" name="replacePlacesWord" type="checkbox">
210
						<?php echo I18N::translate('Whole words only'); ?>
211
					</label>
212
				</p>
213
			</div>
214
215
			<div class="label"></div>
216
			<div class="value">
217
				<input type="submit" value="<?php echo /* I18N: A button label. */ I18N::translate('replace'); ?>">
218
			</div>
219
		</div>
220
	</form>
221
222
<?php endif; ?>
223
<?php if ($controller->action == "soundex"): ?>
224
225
	<form name="searchform" onsubmit="return checknames(this);">
226
		<input type="hidden" name="action" value="soundex">
227
		<input type="hidden" name="isPostBack" value="true">
228
		<div id="search-page-table">
229
			<div class="label">
230
				<?php echo I18N::translate('Given name'); ?>
231
			</div>
232
			<div class="value">
233
				<input type="text" data-autocomplete-type="GIVN" name="firstname" value="<?php echo Filter::escapeHtml($controller->firstname); ?>" autofocus>
234
			</div>
235
			<div class="label">
236
				<?php echo I18N::translate('Surname'); ?>
237
			</div>
238
			<div class="value">
239
				<input type="text" data-autocomplete-type="SURN" name="lastname" value="<?php echo Filter::escapeHtml($controller->lastname); ?>">
240
			</div>
241
			<div class="label">
242
				<?php echo I18N::translate('Place'); ?>
243
			</div>
244
			<div class="value">
245
				<input type="text"  data-autocomplete-type="PLAC2" name="place" value="<?php echo Filter::escapeHtml($controller->place); ?>">
246
			</div>
247
			<div class="label">
248
				<?php echo I18N::translate('Year'); ?>
249
			</div>
250
			<div class="value"><input type="text" name="year" value="<?php echo Filter::escapeHtml($controller->year); ?>">
251
			</div>
252
			<div class="label">
253
				<?php echo I18N::translate('Phonetic algorithm'); ?>
254
			</div>
255
			<div class="value">
256
				<p>
257
					<input type="radio" name="soundex" value="Russell" <?php echo $controller->soundex === 'Russell' ? 'checked' : ''; ?>>
258
					<?php echo I18N::translate('Russell'); ?>
259
				</p>
260
				<p>
261
					<input type="radio" name="soundex" value="DaitchM" <?php echo $controller->soundex === 'DaitchM' || $controller->soundex === '' ? 'checked' : ''; ?>>
262
					<?php echo I18N::translate('Daitch-Mokotoff'); ?>
263
				</p>
264
			</div>
265
			<div class="label">
266
				<?php echo I18N::translate('Associates'); ?>
267
			</div>
268
			<div class="value">
269
				<input type="checkbox" name="showasso" value="on" <?php echo $controller->showasso === 'on' ? 'checked' : ''; ?>>
270
				<?php echo I18N::translate('Show related individuals/families'); ?>
271
			</div>
272
			<?php if (count(Tree::getAll()) > 1 && Site::getPreference('ALLOW_CHANGE_GEDCOM')): ?>
273
				<?php if (count(Tree::getAll()) > 3): ?>
274
					<div class="label"></div>
275
					<div class="value">
276
						<input type="button" value="<?php echo /* I18N: select all (of the family trees) */ I18N::translate('select all'); ?>" onclick="jQuery('#search_trees :checkbox').each(function(){jQuery(this).attr('checked', true);});return false;">
277
						<input type="button" value="<?php echo /* I18N: select none (of the family trees) */ I18N::translate('select none'); ?>" onclick="jQuery('#search_trees :checkbox').each(function(){jQuery(this).attr('checked', false);});return false;">
278
						<?php if (count(Tree::getAll()) > 10): ?>
279
							<input type="button" value="<?php echo I18N::translate('invert selection'); ?>" onclick="jQuery('#search_trees :checkbox').each(function(){jQuery(this).attr('checked', !jQuery(this).attr('checked'));});return false;">
280
						<?php endif; ?>
281
					</div>
282
				<?php endif; ?>
283
				<div class="label">
284
					<?php echo I18N::translate('Family trees'); ?>
285
				</div>
286
				<div id="search_trees" class="value">
287
					<?php foreach (Tree::getAll() as $tree): ?>
288
						<p>
289
							<input type="checkbox" <?php echo in_array($tree, $controller->search_trees) ? 'checked' : ''; ?> value="yes" id="tree_<?php echo $tree->getTreeId(); ?>" name="tree_<?php echo $tree->getTreeId(); ?>">
290
							<label for="tree_'<?php echo $tree->getTreeId(); ?>">
291
								<?php echo $tree->getTitleHtml(); ?>
292
							</label>
293
						</p>
294
					<?php endforeach; ?>
295
				</div>
296
			<?php endif; ?>
297
298
			<div class="label"></div>
299
			<div class="value">
300
				<input type="submit" value="<?php echo  /* I18N: A button label. */ I18N::translate('search'); ?>">
301
			</div>
302
		</div>
303
	</form>
304
305
<?php endif; ?>
306
307
<?php $controller->printResults(); ?>
308
309
</div>
310