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
|
<?php
// List branches by surname
//
// webtrees: Web based Family History software
// Copyright (C) 2013 webtrees development team.
//
// Derived from PhpGedView
// Copyright (C) 2002 to 2009 PGV Development Team. All rights reserved.
//
// 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 2 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, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// $Id$
define('WT_SCRIPT_NAME', 'branches.php');
require './includes/session.php';
//-- args
$surn = safe_GET('surname', '[^<>&%{};]*');
$soundex_std = safe_GET_bool('soundex_std');
$soundex_dm = safe_GET_bool('soundex_dm');
$ged = safe_GET('ged');
if (empty($ged)) {
$ged = $GEDCOM;
}
$user_ancestors=array();
if (WT_USER_GEDCOM_ID) {
load_ancestors_array(WT_Individual::getInstance(WT_USER_GEDCOM_ID), 1);
}
$controller=new WT_Controller_Page();
if ($surn) {
$controller->setPageTitle(/* I18N: %s is a surname */ WT_I18N::translate('Branches of the %s family', htmlspecialchars($surn)));
} else {
$controller->setPageTitle(WT_I18N::translate('Branches'));
}
$controller
->pageHeader()
->addExternalJavascript(WT_STATIC_URL.'js/autocomplete.js');
?>
<div id="branches-page">
<form name="surnlist" id="surnlist" action="?">
<table class="facts_table width50">
<tr>
<td class="descriptionbox">
<?php echo WT_Gedcom_Tag::getLabel('SURN'); ?></td>
<td class="optionbox">
<input type="text" name="surname" id="SURN" value="<?php echo htmlspecialchars($surn); ?>" dir="auto">
<input type="hidden" name="ged" id="ged" value="<?php echo $ged; ?>">
<input type="submit" value="<?php echo WT_I18N::translate('View'); ?>">
<p><?php echo WT_I18N::translate('Phonetic search'); ?></p>
<p>
<input type="checkbox" name="soundex_std" id="soundex_std" value="1" <?php if ($soundex_std) echo ' checked="checked"'; ?>>
<label for="soundex_std"><?php echo WT_I18N::translate('Russell'); ?></label>
<input type="checkbox" name="soundex_dm" id="soundex_dm" value="1" <?php if ($soundex_dm) echo ' checked="checked"'; ?>>
<label for="soundex_dm"><?php echo WT_I18N::translate('Daitch-Mokotoff'); ?></label>
</p>
</td>
</tr>
</table>
</form>
<?php
//-- results
if ($surn) {
echo '<fieldset><legend><i class="icon-patriarch"></i> ', $surn, '</legend>';
$indis = indis_array($surn, $soundex_std, $soundex_dm);
usort($indis, array('WT_Individual', 'CompareBirtDate'));
echo '<ol>';
foreach ($indis as $person) {
$famc = $person->getPrimaryChildFamily();
// Don't show INDIs with parents in the list, as they will be shown twice.
if ($famc) {
foreach ($famc->getSpouses() as $parent) {
if (in_array($parent, $indis, true)) {
continue 2;
}
}
}
print_fams($person);
}
echo '</ol>';
echo '</fieldset>';
}
echo '</div>'; // close branches-page
if (false) {
// These messages were added (briefly) and translated.
// Keep them in the translation template, as we will want them in the future
WT_I18N::translate('Collapse all');
WT_I18N::translate('Expand all');
}
function print_fams(WT_Individual $person, WT_Family $family=null) {
global $surn, $soundex_std, $soundex_dm, $user_ancestors;
// select person name according to searched surname
$person_name = "";
foreach ($person->getAllNames() as $n=>$name) {
list($surn1) = explode(",", $name['sort']);
if (
// one name is a substring of the other
stripos($surn1, $surn)!==false ||
stripos($surn, $surn1)!==false ||
// one name sounds like the other
$soundex_std && WT_Soundex::compare(WT_Soundex::soundex_std($surn1), WT_Soundex::soundex_std($surn)) ||
$soundex_dm && WT_Soundex::compare(WT_Soundex::soundex_dm ($surn1), WT_Soundex::soundex_dm ($surn))
) {
$person_name = $name['full'];
break;
}
}
if (empty($person_name)) {
echo '<li title="', strip_tags($person->getFullName()), '">', $person->getSexImage(), '…</li>';
return;
}
// current indi
echo '<li>';
$class = '';
$sosa = array_search($person->getXref(), $user_ancestors);
if ($sosa) {
$class = 'search_hit';
$sosa = '<a target="_blank" dir="ltr" class="details1 '.$person->getBoxStyle().'" title="'.WT_I18N::translate('Sosa').'" href="relationship.php?pid2='.WT_USER_ROOT_ID.'&pid1='.$person->getXref().'"> '.$sosa.' </a>'.sosa_gen($sosa);
}
$current = $person->getSexImage().
'<a target="_blank" class="'.$class.'" href="'.$person->getHtmlUrl().'">'.$person_name.'</a> '.
$person->getLifeSpan().' '.$sosa;
if ($family) {
foreach ($person->getFacts('FAMC') as $fact) {
if ($fact->getTarget() === $family) {
$pedi = $fact->getAttribute('PEDI');
break;
}
}
if ($pedi && $pedi!='birth') {
$label = WT_Gedcom_Code_Pedi::getValue($pedi, $person);
$current = '<span class="red">'.$label.'</span> '.$current;
}
}
// spouses and children
if (count($person->getSpouseFamilies())<1) {
echo $current;
}
foreach ($person->getSpouseFamilies() as $family) {
$txt = $current;
$spouse = $family->getSpouse($person);
if ($spouse) {
$class = '';
$sosa2 = array_search($spouse->getXref(), $user_ancestors);
if ($sosa2) {
$class = 'search_hit';
$sosa2 = '<a target="_blank" dir="ltr" class="details1 '.$spouse->getBoxStyle().'" title="'.WT_I18N::translate('Sosa').'" href="relationship.php?pid2='.WT_USER_ROOT_ID.'&pid1='.$spouse->getXref().'"> '.$sosa2.' </a>'.sosa_gen($sosa2);
}
$marriage_year=$family->getMarriageYear();
if ($marriage_year) {
$txt .= ' <a href="'.$family->getHtmlUrl().'">';
$txt .= '<span class="details1" title="'.strip_tags($family->getMarriageDate()->Display()).'"><i class="icon-rings"></i>'.$marriage_year.'</span></a>';
}
else if ($family->getMarriage()) {
$txt .= ' <a href="'.$family->getHtmlUrl().'">';
$txt .= '<span class="details1" title="'.WT_I18N::translate('yes').'"><i class="icon-rings"></i></span></a>';
}
$txt .=
$spouse->getSexImage().
' <a class="'.$class.'" href="'.$spouse->getHtmlUrl().'">'.$spouse->getFullName().'</a> '.$spouse->getLifeSpan().' '.$sosa2;
}
echo $txt;
echo '<ol>';
foreach ($family->getChildren() as $child) {
print_fams($child, $family);
}
echo '</ol>';
}
echo '</li>';
}
function load_ancestors_array($person, $sosa=1) {
global $user_ancestors;
if ($person) {
$user_ancestors[$sosa]=$person->getXref();
foreach ($person->getChildFamilies() as $family) {
foreach ($family->getSpouses() as $parent) {
load_ancestors_array($parent, $sosa*2+($parent->getSex()=='F'));
}
}
}
}
function indis_array($surn, $soundex_std, $soundex_dm) {
$sql=
"SELECT DISTINCT i_id AS xref, i_file AS gedcom_id, i_gedcom AS gedcom".
" FROM `##individuals`".
" JOIN `##name` ON (i_id=n_id AND i_file=n_file)".
" WHERE n_file=?".
" AND n_type!=?".
" AND (n_surn=? OR n_surname=?";
$args=array(WT_GED_ID, '_MARNM', $surn, $surn);
if ($soundex_std) {
foreach (explode(':', WT_Soundex::soundex_std($surn)) as $value) {
$sql .= " OR n_soundex_surn_std LIKE CONCAT('%', ?, '%')";
$args[]=$value;
}
}
if ($soundex_dm) {
foreach (explode(':', WT_Soundex::soundex_dm($surn)) as $value) {
$sql .= " OR n_soundex_surn_dm LIKE CONCAT('%', ?, '%')";
$args[]=$value;
}
}
$sql .= ')';
$rows=
WT_DB::prepare($sql)
->execute($args)
->fetchAll();
$data=array();
foreach ($rows as $row) {
$data[]=WT_Individual::getInstance($row->xref, $row->gedcom_id, $row->gedcom);
}
return $data;
}
function sosa_gen($sosa) {
$gen = (int)log($sosa, 2)+1;
return '<sup title="'.WT_I18N::translate('Generation').'">'.$gen.'</sup>';
}
|