summaryrefslogtreecommitdiff
path: root/search_advanced.php
blob: 1c655a7814ca01cf9be37ed19dd773d19642703a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
<?php
/**
 * webtrees: online genealogy
 * Copyright (C) 2017 webtrees development team
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */
namespace Fisharebest\Webtrees;

use Fisharebest\Webtrees\Controller\AdvancedSearchController;

require 'includes/session.php';

$controller = new AdvancedSearchController;
$controller->pageHeader();

?>
<script>
	function checknames(frm) {
		action = "<?= $controller->action ?>";

		return true;
	}

	var numfields = <?= count($controller->fields) ?>;

	/**
	 * add a row to the table of fields
	 */
	function addFields() {
		var tbl         = document.getElementById('div-holder');
		var trow        = document.createElement('div');
		trow.className	= 'row form-group';
		var label       = document.createElement('div');
		label.className = 'col-sm-3 wt-page-options-label py-1';
		var sel         = document.createElement('select');
		sel.className	= 'form-control form-control-sm';
		sel.name        = 'fields[' + numfields + ']';
		sel.rownum      = numfields;
		sel.onchange    = function () {
			showDate(this, this.rownum);
		};

		// all of the field options
		<?php foreach ($controller->getOtherFields() as $field => $label) { ?>
		opt       = document.createElement('option');
		opt.value = <?= json_encode($field) ?>;
		opt.text  = <?= json_encode($label) ?>;
		sel.options.add(opt);
		<?php } ?>
		label.appendChild(sel);
		trow.appendChild(label);
		// create the new value cell
		var val			= document.createElement('div');
		val.id			= 'vcell' + numfields;
		val.className	= 'col-sm-9 wt-page-options-value form-row py-1';

		var inp			= document.createElement('input');
		inp.name		= 'values[' + numfields + ']';
		inp.className	= 'form-control form-control-sm col-9';
		inp.type		= 'text';
		inp.id			= 'value' + numfields;
		inp.tabindex	= numfields + 1;
		val.appendChild(inp);
		trow.appendChild(val);
		var lastRow = tbl.lastChild.previousSibling;

		tbl.insertBefore(trow, lastRow.nextSibling);
		numfields++;
	}

	/**
	 * add the date options selection
	 */
	function showDate(sel, row) {
		var type = sel.options[sel.selectedIndex].value;
		var pm   = document.getElementById('plusminus' + row);
		if (!type.match("DATE$")) {
			// if it is not a date do not show the date
			if (pm) pm.parentNode.removeChild(pm);
			return;
		}
		// if it is a date and the plusminus is already show, then leave
		if (pm) return;
		var elm			= document.getElementById('vcell' + row);
		var sel			= document.createElement('select');
		sel.id			= 'plusminus' + row;
		sel.name		= 'plusminus[' + row + ']';
		sel.className	= 'form-control form-control-sm col-3';
		var opt			= document.createElement('option');
		opt.value		= '';
		opt.text		= '<?= I18N::translate('Exact date') ?>';
		sel.appendChild(opt);
		opt				= document.createElement('option');
		opt.value		= '';
		opt.text		= '<?= I18N::plural('±%s year', '±%s years', 2, I18N::number(2)) ?>';
		sel.appendChild(opt);
		opt				= document.createElement('option');
		opt.value		= '5';
		opt.text		= '<?= I18N::plural('±%s year', '±%s years', 5, I18N::number(5)) ?>';
		sel.appendChild(opt);
		opt				= document.createElement('option');
		opt.value		= '10';
		opt.text		= '<?= I18N::plural('±%s year', '±%s years', 10, I18N::number(10)) ?>';
		sel.appendChild(opt);
		var spc = document.createTextNode(' ');
		elm.appendChild(spc);
		elm.appendChild(sel);
	}
</script>

<div id="advanced-search-page">
	<h2 class="wt-page-title"><?= $controller->getPageTitle() ?></h2>
	<form class="wt-page-options wt-page-options-search-advanced hidden-print" name="searchform" onsubmit="return checknames(this);">
		<input type="hidden" name="action" value="<?= $controller->action ?>">
		<input type="hidden" name="isPostBack" value="true">
		<div id="div-holder">
			<?php
			$fct = count($controller->fields);
			for ($i = 0; $i < $fct; $i++):
				if (strpos($controller->getField($i), 'FAMC:HUSB:NAME') === 0) {
					continue;
				}
				if (strpos($controller->getField($i), 'FAMC:WIFE:NAME') === 0) {
					continue;
				}
				?>
				<div class="row form-group">
					<label class="col-sm-3 col-form-label wt-page-options-label">
					<?= $controller->getLabel($controller->getField($i)) ?>
					</label>
					<?php
					$currentFieldSearch = $controller->getField($i); // Get this field’s name and the search criterion
					$currentField       = substr($currentFieldSearch, 0, strrpos($currentFieldSearch, ':')); // Get the actual field name
					?>
					<div class="col-sm-9 wt-page-options-value form-row mx-0">
						<input class="form-control form-control-sm col-9" type="text" id="value<?= $i ?>" name="values[<?= $i ?>]"
					value="<?= Html::escape($controller->getValue($i)) ?>">
						<?php if (preg_match('/^NAME:/', $currentFieldSearch) > 0): ?>
							<select class="form-control form-control-sm col-3" name="fields[<?= $i ?>]">
								<option value="<?= $currentField ?>:EXACT" <?php if (preg_match('/:EXACT$/', $currentFieldSearch) > 0) echo 'selected' ?>>
									<?= I18N::translate('Exact') ?>
								</option>
								<option value="<?= $currentField ?>:BEGINS" <?php if (preg_match('/:BEGINS$/', $currentFieldSearch) > 0) echo 'selected' ?>>
									<?= I18N::translate('Begins with') ?>
								</option>
								<option value="<?= $currentField ?>:CONTAINS" <?php if (preg_match('/:CONTAINS$/', $currentFieldSearch) > 0) echo 'selected' ?>>
									<?= I18N::translate('Contains') ?>
								</option>
								<option value="<?= $currentField ?>:SDX" <?php if (preg_match('/:SDX$/', $currentFieldSearch) > 0) echo 'selected' ?>><?= I18N::translate('Sounds like') ?>
								</option>
							</select>
						<?php else: ?>
							<input type="hidden" name="fields[<?= $i ?>]" value="<?= $controller->getField($i) ?>">
						<?php endif;
						if (preg_match('/:DATE$/', $currentFieldSearch) > 0) {
							?>
							<select class="form-control form-control-sm col-3" name="plusminus[<?= $i ?>]">
								<option value="">
									<?= I18N::translate('Exact date') ?>
								</option>
								<option value="2" <?php if (!empty($controller->plusminus[$i]) && $controller->plusminus[$i] == 2) echo 'selected' ?>>
									<?= I18N::plural('±%s year', '±%s years', 2, I18N::number(2)) ?>
								</option>
								<option value="5" <?php if (!empty($controller->plusminus[$i]) && $controller->plusminus[$i] == 5) echo 'selected' ?>>
									<?= I18N::plural('±%s year', '±%s years', 5, I18N::number(5)) ?>
								</option>
								<option value="10" <?php if (!empty($controller->plusminus[$i]) && $controller->plusminus[$i] == 10) echo 'selected' ?>>
									<?= I18N::plural('±%s year', '±%s years', 10, I18N::number(10)) ?>
								</option>
							</select>
						<?php } ?>
					</div>
					<?php
					//-- relative fields
					if ($i == 0 && $fct > 4) {
						$j = $fct;
						// Get the current options for Father’s and Mother’s name searches
						$fatherGivnOption = 'SDX';
						$fatherSurnOption = 'SDX';
						$motherGivnOption = 'SDX';
						$motherSurnOption = 'SDX';
						for ($k = 0; $k < $fct; $k++) {
							$searchField  = $controller->getField($k);
							$searchOption = substr($searchField, 20); // Assume we have something like "FAMC:HUSB:NAME:GIVN:foo"
							switch (substr($searchField, 0, 20)) {
							case 'FAMC:HUSB:NAME:GIVN:':
								$fatherGivnOption = $searchOption;
								break;
							case 'FAMC:HUSB:NAME:SURN:':
								$fatherSurnOption = $searchOption;
								break;
							case 'FAMC:WIFE:NAME:GIVN:':
								$motherGivnOption = $searchOption;
								break;
							case 'FAMC:WIFE:NAME:SURN:':
								$motherSurnOption = $searchOption;
								break;
							}
						}
					}
					?>
				</div>
			<?php endfor; ?>
			<!--  father -->
			<div class="row form-group wt-page-options-label">
				<div class="form-row mx-auto">
					<?= I18N::translate('Father') ?>
				</div>
			</div>
			<div class="row form-group">
				<label class="col-sm-3 col-form-label wt-page-options-label">
					<?= I18N::translate('Given names') ?>
				</label>
				<div class="col-sm-9 wt-page-options-value form-row mx-0">
					<input class="form-control form-control-sm col-9" type="text" name="values[<?= $j ?>]" value="<?= $controller->getValue($controller->getIndex('FAMC:HUSB:NAME:GIVN:' . $fatherGivnOption)) ?>">
					<select class="form-control form-control-sm col-3" name="fields[<?= $j ?>]">
						<option value="FAMC:HUSB:NAME:GIVN:EXACT" <?php if ($fatherGivnOption == 'EXACT') echo 'selected' ?>>
							<?= I18N::translate('Exact') ?>
						</option>
						<option value="FAMC:HUSB:NAME:GIVN:BEGINS" <?php if ($fatherGivnOption == 'BEGINS') echo 'selected' ?>>
							<?= I18N::translate('Begins with') ?>
						</option>
						<option value="FAMC:HUSB:NAME:GIVN:CONTAINS" <?php if ($fatherGivnOption == 'CONTAINS') echo 'selected' ?>>
							<?= I18N::translate('Contains') ?>
						</option>
						<option value="FAMC:HUSB:NAME:GIVN:SDX" <?php if ($fatherGivnOption == 'SDX') echo 'selected' ?>>
							<?= I18N::translate('Sounds like') ?>
						</option>
					</select>
				</div>
			</div>
			<?php $j++ ?>
			<div class="row form-group">
				<label class="col-sm-3 col-form-label wt-page-options-label">
					<?= I18N::translate('Surname') ?>
				</label>
				<div class="col-sm-9 wt-page-options-value form-row mx-0">
					<input class="form-control form-control-sm col-9" type="text" name="values[<?= $j ?>]" value="<?= $controller->getValue($controller->getIndex('FAMC:HUSB:NAME:SURN:' . $fatherSurnOption)) ?>">
					<select class="form-control form-control-sm col-3" name="fields[<?= $j ?>]">
						<option value="FAMC:HUSB:NAME:SURN:EXACT" <?php if ($fatherSurnOption == 'EXACT') echo 'selected' ?>>
							<?= I18N::translate('Exact') ?>
						</option>
						<option value="FAMC:HUSB:NAME:SURN:BEGINS" <?php if ($fatherSurnOption == 'BEGINS') echo 'selected' ?>>
							<?= I18N::translate('Begins with') ?>
						</option>
						<option value="FAMC:HUSB:NAME:SURN:CONTAINS" <?php if ($fatherSurnOption == 'CONTAINS') echo 'selected' ?>>
							<?= I18N::translate('Contains') ?>
						</option>
						<option value="FAMC:HUSB:NAME:SURN:SDX" <?php if ($fatherSurnOption == 'SDX') echo 'selected' ?>>
							<?= I18N::translate('Sounds like') ?>
						</option>
					</select>
				</div>
			</div>
			<!--  mother -->
			<?php $j++ ?>
			<div class="row form-group wt-page-options-label">
				<div class="form-row mx-auto">
					<?= I18N::translate('Mother') ?>
				</div>
			</div>
			<div class="row form-group">
				<label class="col-sm-3 col-form-label wt-page-options-label">
					<?= I18N::translate('Given names') ?>
				</label>
				<div class="col-sm-9 wt-page-options-value form-row mx-0">
					<input class="form-control form-control-sm col-9" type="text" name="values[<?= $j ?>]" value="<?= $controller->getValue($controller->getIndex('FAMC:WIFE:NAME:GIVN:' . $motherGivnOption)) ?>">
					<select class="form-control form-control-sm col-3" name="fields[<?= $j ?>]">
						<option value="FAMC:WIFE:NAME:GIVN:EXACT" <?php if ($motherGivnOption == 'EXACT') echo 'selected' ?>>
							<?= I18N::translate('Exact') ?>
						</option>
						<option value="FAMC:WIFE:NAME:GIVN:BEGINS" <?php if ($motherGivnOption == 'BEGINS') echo 'selected' ?>>
							<?= I18N::translate('Begins with') ?>
						</option>
						<option value="FAMC:WIFE:NAME:GIVN:CONTAINS" <?php if ($motherGivnOption == 'CONTAINS') echo 'selected' ?>>
							<?= I18N::translate('Contains') ?>
						</option>
						<option value="FAMC:WIFE:NAME:GIVN:SDX" <?php if ($motherGivnOption == 'SDX') echo 'selected' ?>>
							<?= I18N::translate('Sounds like') ?>
						</option>
					</select>
				</div>
			</div>
			<?php $j++ ?>
			<div class="row form-group">
				<label class="col-sm-3 col-form-label wt-page-options-label">
					<?= I18N::translate('Surname') ?>
				</label>
				<div class="col-sm-9 wt-page-options-value form-row mx-0">
					<input class="form-control form-control-sm col-9" type="text" name="values[<?= $j ?>]" value="<?= $controller->getValue($controller->getIndex('FAMC:WIFE:NAME:GIVN:' . $motherGivnOption)) ?>">
					<select class="form-control form-control-sm col-3" name="fields[<?= $j ?>]">
						<option value="FAMC:WIFE:NAME:GIVN:EXACT" <?php if ($motherGivnOption == 'EXACT') echo 'selected' ?>>
							<?= I18N::translate('Exact') ?>
						</option>
						<option value="FAMC:WIFE:NAME:GIVN:BEGINS" <?php if ($motherGivnOption == 'BEGINS') echo 'selected' ?>>
							<?= I18N::translate('Begins with') ?>
						</option>
						<option value="FAMC:WIFE:NAME:GIVN:CONTAINS" <?php if ($motherGivnOption == 'CONTAINS') echo 'selected' ?>>
							<?= I18N::translate('Contains') ?>
						</option>
						<option value="FAMC:WIFE:NAME:GIVN:SDX" <?php if ($motherGivnOption == 'SDX') echo 'selected' ?>>
							<?= I18N::translate('Sounds like') ?>
						</option>
					</select>
				</div>
			</div>
			<?php $j++ ?>
			<div class="row form-group my-3">
				<div class="form-row mx-auto">
					<a href="#" onclick="addFields();return false;"><?= I18N::translate('Add more fields') ?></a>
				</div>
			</div>
		</div> <!-- Close of div-holder -->
		<?php $j++ ?>
		<div class="row form-group my-3">
			<div class="form-row mx-auto">
				<input type="submit" class="btn btn-primary" value="<?=  /* I18N: A button label. */ I18N::translate('search') ?>">
			</div>
		</div>
	</form>
	<?php $controller->printResults() ?>
</div>