forked from kiwi3685/kiwitrees
-
Notifications
You must be signed in to change notification settings - Fork 0
/
admin_trees_duplicates.php
330 lines (317 loc) · 11.6 KB
/
admin_trees_duplicates.php
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
<?php
/**
* Kiwitrees: Web based Family History software
* Copyright (C) 2012 to 2017 kiwitrees.net
*
* Derived from webtrees (www.webtrees.net)
* Copyright (C) 2010 to 2012 webtrees development team
*
* Derived from PhpGedView (phpgedview.sourceforge.net)
* Copyright (C) 2002 to 2010 PGV Development Team
*
* Kiwitrees 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 Kiwitrees. If not, see <http://www.gnu.org/licenses/>.
*/
define('KT_SCRIPT_NAME', 'admin_trees_duplicates.php');
require './includes/session.php';
require KT_ROOT.'includes/functions/functions_edit.php';
$controller = new KT_Controller_Page();
$controller
->requireManagerLogin()
->setPageTitle(KT_I18N::translate('Find duplicate individuals'))
->pageHeader()
->addExternalJavascript(KT_AUTOCOMPLETE_JS_URL)
->addInlineJavascript('
autocomplete();
// prevent more than two boxes from being checked
var checked = 0;
function addCheck(box) {
// allow checked box to be unchecked
if(!box.checked) return true;
// get ref to collection
var boxes = document.getElementsByName(box.name);
// count checked
var cb, count=0, k=0;
while(cb=boxes[k++])
if(cb.checked && ++count>2){
alert("Sorry, you can only merge 2 at a time");
return false;
}
return true;
}
// loop through all checkboxes with class "check" and create input string for form
function checkbox_test() {
var counter = 0, i = 0, myvar = new Array();
form = document.createElement("form");
form.setAttribute("method", "POST");
form.setAttribute("action", "admin_trees_merge.php");
form.setAttribute("target", "_blank");
// get a collection of objects with the specified class "check"
input_obj = document.getElementsByClassName("check"); // this might fail on some old browsers (see http://caniuse.com/getelementsbyclassname)
// loop through all collected objects
for (i = 0; i < input_obj.length; i++) {
// if input object is checked then ...
if (input_obj[i].checked === true) {
// ... increase counter and concatenate checkbox value to the input string
myvar[i] = document.createElement("input");
myvar[i].setAttribute("name", "gid" + (counter + 1));
myvar[i].setAttribute("type", "hidden");
myvar[i].setAttribute("value", input_obj[i].value);
form.appendChild(myvar[i]);
counter++;
}
}
// display send form or display message if there is only 1 or no checked checkboxes
if (counter > 0) {
if (counter == 1) {
alert("Select TWO items to merge");
return false;
}
// send checkbox values
document.body.appendChild(form);
form.submit();
} else {
alert("There is nothing selected");
}
}
');
$action = safe_get('action','go', '');
$gedcom_id = safe_get('gedcom_id', array_keys(KT_Tree::getAll()), KT_GED_ID);
$surn = KT_Filter::get('surname', '[^<>&%{};]*');
$givn = KT_Filter::get('given', '[^<>&%{};]*');
$exact_givn = safe_GET_bool('exact_givn');
$exact_surn = safe_GET_bool('exact_surn');
$married = safe_GET_bool('married');
$gender = safe_GET('gender');
// the sql query used to identify duplicates
$sql = '
SELECT n_id, n_full, n_surn, n_givn, n_type, n_sort
FROM `##name` ';
if ($exact_surn) {
$sql .= 'WHERE n_surn = "' . $surn . '" ';
} else {
$sql .= 'WHERE n_surn LIKE "%' . $surn . '%"';
}
if ($exact_givn) {
$sql .= 'AND n_givn = "' . $givn . '" ';
} else {
$sql .= 'AND n_givn LIKE "%' . $givn . '%"';
}
if (!$married) {
$sql .= 'AND n_type NOT LIKE "_MARNM" ';
}
$sql .= 'AND n_file = '. $gedcom_id. ' ';
$sql .= 'AND n_full IN (
SELECT n_full
FROM `##name`
GROUP BY n_full
HAVING count(n_full) > 1
)
ORDER BY n_sort ASC';
$SHOW_EST_LIST_DATES=get_gedcom_setting(KT_GED_ID, 'SHOW_EST_LIST_DATES');
echo '<div id="admin_dup">
<h2>' .$controller->getPageTitle(). '</h2>
<form method="get" name="duplicates_form" action="', KT_SCRIPT_NAME, '">
<div class="gm_check">
<div id="famtree">
<label>', KT_I18N::translate('Family tree'), '</label>
<select name="ged">';
foreach (KT_Tree::getAll() as $tree) {
echo '<option value="', $tree->tree_name_html, '"';
if (empty($ged) && $tree->tree_id == KT_GED_ID || !empty($ged) && $ged == $tree->tree_name) {
echo ' selected="selected"';
}
echo ' dir="auto">', $tree->tree_title_html, '</option>';
}
echo '</select>
</div>
<div id="surnm">
<label for="SURN">', KT_I18N::translate('Surname'), '</label>
<div class="exact" title="', KT_I18N::translate('Match exactly'), '">
<input data-autocomplete-type="SURN" type="text" name="surname" id="SURN" value="', htmlspecialchars($surn), '" dir="auto">
<input type="checkbox" name="exact_surn" value="1"';
if ($exact_surn) {
echo ' checked="checked"';
}
echo '>',
KT_I18N::translate('Tick for exact match'), '
</div>
</div>
<div id="givnm">
<label for="GIVN">', KT_I18N::translate('Given name'), '</label>
<div class="exact" title="', KT_I18N::translate('Match exactly'), '">
<input data-autocomplete-type="GIVN" type="text" name="given" id="GIVN" value="', htmlspecialchars($givn), '" dir="auto">
<input type="checkbox" name="exact_givn" value="1" title="', KT_I18N::translate('Match exactly'), '"';
if ($exact_givn) {
echo ' checked="checked"';
}
echo '>',
KT_I18N::translate('Tick for exact match'), '
</div>
</div>
<div id="gender">
<label>', KT_I18N::translate('Gender'), '</label>
<select name="gender">
<option value="A"';
if ($gender == 'A' || empty($gender)) echo ' selected="selected"';
echo '>', KT_I18N::translate('Any'), '
</option>
<option value="M"';
if ($gender == 'M') echo ' selected="selected"';
echo '>', KT_I18N::translate('Male'), '
</option>
<option value="F"';
if ($gender == 'F') echo ' selected="selected"';
echo '>', KT_I18N::translate('Female'), '
</option>
<option value="U"';
if ($gender == 'U') echo ' selected="selected"';
echo '>', KT_I18N::translate_c('unknown gender', 'Unknown'), '
</option>
</select>
</div>
<div id="marname">
<label>', KT_I18N::translate('Include married names: '), '</label>
<input type="checkbox" name="married" value="1"';
if ($married) {
echo ' checked="checked"';
}
echo '>
</div>
<button type="submit" class="btn btn-primary">
<i class="fa fa-eye"></i>' ,
KT_I18N::translate('show'), '
</button>
</div>
</form>';
// START OUTPUT
if ($surn) {
$rows=KT_DB::prepare($sql)->fetchAll(PDO::FETCH_ASSOC);
if ($rows) {
$name1 = '';
$name2 = '';
echo '<div class="scrollableContainer">
<div class="scrollingArea">
<table id="duplicates_table">
<thead>
<tr>
<th rowspan="2"><div class="col1">',KT_I18N::translate('Name'),'</div></th>
<th colspan="2">',KT_I18N::translate('Birth'),'</th>
<th colspan="2">',KT_I18N::translate('Death'),'</th>
<th rowspan="2">
<div class="col6">
<input type="button" value="',KT_I18N::translate('Merge selected'),'" onclick="return checkbox_test();">
</div>
</th>
</tr>
<tr>
<th><div class="col2">',KT_I18N::translate('Date'),'</div></th>
<th><div class="col3">',KT_I18N::translate('Place'),'</div></th>
<th><div class="col4">',KT_I18N::translate('Date'),'</div></th>
<th><div class="col5">',KT_I18N::translate('Place'),'</div></th>
</tr>
</thead>
<tbody>';
$i = 0;
foreach ($rows as $row) {
$i++;
$bdate = '';
$bplace = '';
$ddate = '';
$dplace = '';
$name1 = $row['n_full'];
if ($row['n_type'] == '_MARNM') {
$marr = '<span style="font-style:italic;font-size:80%;">('.KT_I18N::translate('Married name').')</span>';
} else {
$marr = '';
}
$id = $row['n_id'];
$person = KT_Person::getInstance($id);
if ($person->getSex() == $gender || $gender == 'A') {
// find birth/death dates
if ($birth_dates=$person->getAllBirthDates()) {
foreach ($birth_dates as $num=>$birth_date) {
if ($num) {$bdate .= '<br>';}
$bdate .= $birth_date->Display();
}
} else {
$birth_date = $person->getEstimatedBirthDate();
$birth_jd = $birth_date->JD();
if ($SHOW_EST_LIST_DATES) {
$bdate .= $birth_date->Display();
} else {
$bdate .= ' ';
}
$birth_dates[0] = new KT_Date('');
}
//find birth places
foreach ($person->getAllBirthPlaces() as $n=>$birth_place) {
$tmp = new KT_Place($birth_place, KT_GED_ID);
if ($n) {$bplace .= '<br>';}
$bplace .= $tmp->getShortName();
}
// find death dates
if ($death_dates = $person->getAllDeathDates()) {
foreach ($death_dates as $num=>$death_date) {
if ($num) {$ddate .= '<br>';}
$ddate .= $death_date->Display();
}
} else {
$death_date = $person->getEstimatedDeathDate();
$death_jd = $death_date->JD();
if ($SHOW_EST_LIST_DATES) {
$ddate .= $death_date->Display();
} else if ($person->isDead()) {
$ddate .= KT_I18N::translate('yes');
} else {
$ddate .= ' ';
}
$death_dates[0]=new KT_Date('');
}
// find death places
foreach ($person->getAllDeathPlaces() as $n=>$death_place) {
$tmp=new KT_Place($death_place, KT_GED_ID);
if ($n) {$dplace .= '<br>';}
$dplace .= $tmp->getShortName();
}
//output result rows, grouping exact matches (on full name)
if ($name2 == $name1) {
echo '<tr>
<td><div class="col1"><a href="'. $person->getHtmlUrl(). '" target="_blank" rel="noopener noreferrer">'. $name1. ' '. $marr. '</a></td>
<td><div class="col2">' . $bdate . '</div></td>
<td><div class="col3">'. $bplace. '</div></td>
<td><div class="col4">' . $ddate . '</div></td>
<td><div class="col5">'. $dplace. '</div></td>
<td><div class="col6"><input type="checkbox" name="gid[]" onclick="return addCheck(this);" class="check" value="'.$id.'"></div></td>
</tr>';
} else {
$name2 = $row['n_full'];
echo '<tr><td colspan="5" style="border:0;"> </td></tr>
<tr>
<td><div class="col1"><a href="'. $person->getHtmlUrl(). '" target="_blank" rel="noopener noreferrer">'. $name2. ' '. $marr. '</a></div></td>
<td><div class="col2">' . $bdate . '</div></td>
<td><div class="col3">'. $bplace. '</div></td>
<td><div class="col4">' . $ddate . '</div></td>
<td><div class="col5">'. $dplace. '</div></td>
<td><div class="col6"><input type="checkbox" name="gid[]" onclick="return addCheck(this);" class="check" value="'.$id.'"></div></td>
</tr>';
}
}
}
echo '</tbody>
</table>
</div>
</div>';
} else {
echo '<h4>', KT_I18N::translate('No duplicates to display'), '</h4>';
}
}
echo '</div>';