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
|
<?php
// Classes and libraries for module system
//
// webtrees: Web based Family History software
// Copyright (C) 2013 webtrees development team.
//
// Derived from PhpGedView
// Copyright (C) 2010 John Finlay
//
// 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$
if (!defined('WT_WEBTREES')) {
header('HTTP/1.0 403 Forbidden');
exit;
}
class descendancy_WT_Module extends WT_Module implements WT_Module_Sidebar {
// Extend WT_Module
public function getTitle() {
return /* I18N: Name of a module/sidebar */ WT_I18N::translate('Descendants');
}
// Extend WT_Module
public function getDescription() {
return /* I18N: Description of the “Descendants” module */ WT_I18N::translate('A sidebar showing the descendants of an individual.');
}
// Implement WT_Module
public function modAction($modAction) {
switch ($modAction) {
case 'ajax':
Zend_Session::writeClose();
header('Content-Type: text/html; charset=UTF-8');
echo $this->getSidebarAjaxContent();
break;
default:
header('HTTP/1.0 404 Not Found');
break;
}
exit;
}
// Implement WT_Module_Sidebar
public function defaultSidebarOrder() {
return 30;
}
// Implement WT_Module_Sidebar
public function hasSidebarContent() {
return true;
}
// Implement WT_Module_Sidebar
public function getSidebarAjaxContent() {
$search=safe_GET('search');
$pid =safe_GET('pid', WT_REGEX_XREF);
$famid =safe_GET('famid', WT_REGEX_XREF);
$individual = WT_Individual::getInstance($pid);
$family = WT_Family::getInstance($famid);
if ($search) {
return $this->search($search);
} elseif ($individual) {
return $this->loadSpouses($individual, 1);
} elseif ($family) {
return $this->loadChildren($family, 1);
} else {
return '';
}
}
// Implement WT_Module_Sidebar
public function getSidebarContent() {
global $controller;
$controller->addInlineJavascript('
var dloadedNames = new Array();
function dsearchQ() {
var query = jQuery("#sb_desc_name").val();
if (query.length>1) {
jQuery("#sb_desc_content").load("module.php?mod='.$this->getName().'&mod_action=ajax&sb_action=descendancy&search="+query);
}
}
jQuery("#sb_desc_name").focus(function(){this.select();});
jQuery("#sb_desc_name").blur(function(){if (this.value=="") this.value="'.WT_I18N::translate('Search').'";});
var dtimerid = null;
jQuery("#sb_desc_name").keyup(function(e) {
if (dtimerid) window.clearTimeout(dtimerid);
dtimerid = window.setTimeout("dsearchQ()", 500);
});
jQuery("#sb_desc_content").on("click", ".sb_desc_indi", function() {
var pid=this.title;
if (!dloadedNames[pid]) {
jQuery("#sb_desc_"+pid+" div").load(this.href);
jQuery("#sb_desc_"+pid+" div").show("fast");
jQuery("#sb_desc_"+pid+" .plusminus").removeClass("icon-plus").addClass("icon-minus");
dloadedNames[pid]=2;
} else if (dloadedNames[pid]==1) {
dloadedNames[pid]=2;
jQuery("#sb_desc_"+pid+" div").show("fast");
jQuery("#sb_desc_"+pid+" .plusminus").removeClass("icon-plus").addClass("icon-minus");
} else {
dloadedNames[pid]=1;
jQuery("#sb_desc_"+pid+" div").hide("fast");
jQuery("#sb_desc_"+pid+" .plusminus").removeClass("icon-minus").addClass("icon-plus");
}
return false;
});
');
return
'<form method="post" action="module.php?mod='.$this->getName().'&mod_action=ajax" onsubmit="return false;">'.
'<input type="search" name="sb_desc_name" id="sb_desc_name" placeholder="'.WT_I18N::translate('Search').'">'.
'</form>'.
'<div id="sb_desc_content">'.
'<ul>'.$this->getPersonLi($controller->record, 1).'</ul>'.
'</div>';
}
public function getPersonLi(WT_Individual $person, $generations=0) {
$out = '<li id="sb_desc_'.$person->getXref().'" class="sb_desc_indi_li"><a href="module.php?mod='.$this->getName().'&mod_action=ajax&sb_action=descendancy&pid='.$person->getXref().'" title="'.$person->getXref().'" class="sb_desc_indi">';
if ($generations>0) {
$out .= '<i class="icon-minus plusminus"></i>';
} else {
$out .= '<i class="icon-plus plusminus"></i>';
}
$out .= $person->getSexImage().' '.$person->getFullName().' ';
if ($person->canShow()) {
$out .= ' ('.$person->getLifeSpan().')';
}
$out .= '</a> <a href="'.$person->getHtmlUrl().'" class="icon-button_indi"></a>';
if ($generations>0) {
$out .= '<div class="desc_tree_div_visible">';
$out .= $this->loadSpouses($person, 0);
$out .= '</div>';
$base_controller = new WT_Controller_Base();
$base_controller->addInlineJavascript('dloadedNames["'.$person->getXref().'"]=2;');
} else {
$out .= '<div class="desc_tree_div">';
$out .= '</div>';
}
$out .= '</li>';
return $out;
}
public function getFamilyLi(WT_Family $family, WT_Individual $person, $generations=0) {
$out = '<li id="sb_desc_'.$family->getXref().'" class="sb_desc_indi_li"><a href="module.php?mod='.$this->getName().'&mod_action=ajax&sb_action=descendancy&famid='.$family->getXref().'" title="'.$family->getXref().'" class="sb_desc_indi">';
$out .= '<i class="icon-minus plusminus"></i>';
$out .= $person->getSexImage().$person->getFullName();
$marryear = $family->getMarriageYear();
if ($marryear) {
$out .= ' ('.WT_Gedcom_Tag::getLabel('MARR').' '.$marryear.')';
}
$out .= '</a> <a href="'.$person->getHtmlUrl().'" class="icon-button_indi"></a>';
$out .= '<a href="'.$family->getHtmlUrl().'" class="icon-button_family"></a>';
$out .= '<div class="desc_tree_div_visible">';
$out .= $this->loadChildren($family, $generations);
$out .= '</div>';
$base_controller=new WT_Controller_Base();
$base_controller->addInlineJavascript('dloadedNames["'.$family->getXref().'"]=2;');
$out .= '</li>';
return $out;
}
public function search($query) {
if (strlen($query)<2) return '';
$rows = WT_DB::prepare(
"SELECT i_id AS xref".
" FROM `##individuals`, `##name`".
" WHERE (i_id LIKE ? OR n_sort LIKE ?)".
" AND i_id=n_id AND i_file=n_file AND i_file=?".
" ORDER BY n_sort"
)
->execute(array("%{$query}%", "%{$query}%", WT_GED_ID))
->fetchAll();
$out = '';
foreach ($rows as $row) {
$person = WT_Individual::getInstance($row->xref);
if ($person->canShowName()) {
$out .= $this->getPersonLi($person);
}
}
if ($out) {
return '<ul>' . $out . '</ul>';
} else {
return '';
}
}
public function loadSpouses(WT_Individual $person, $generations) {
$out = '';
if ($person && $person->canShow()) {
foreach($person->getSpouseFamilies() as $family) {
$out .= $this->getFamilyLi($family, $family->getSpouse($person), $generations-1);
}
}
if ($out) {
return '<ul>' . $out . '</ul>';
} else {
return '';
}
}
public function loadChildren(WT_Family $family, $generations) {
$out = '';
if ($family->canShow()) {
$children = $family->getChildren();
if ($children) {
foreach ($children as $child) {
$out .= $this->getPersonLi($child, $generations-1);
}
} else {
$out .= '<li>'.WT_I18N::translate('No children').'</li>';
}
}
if ($out) {
return '<ul>' . $out . '</ul>';
} else {
return '';
}
}
}
|