1
|
|
|
<?php |
|
|
|
|
2
|
|
|
ini_set('memory_limit', '32M'); |
3
|
|
|
|
4
|
|
|
require_once dirname(dirname(__DIR__)) . '/mainfile.php'; |
5
|
|
|
$moduleDirName = basename(__DIR__); |
6
|
|
|
xoops_loadLanguage('main', $moduleDirName); |
7
|
|
|
require_once(XOOPS_ROOT_PATH . '/modules/' . $moduleDirName . '/include/common.php'); |
8
|
|
|
|
9
|
|
|
$xoopsOption['template_main'] = 'pedigree_coi.tpl'; |
10
|
|
|
include XOOPS_ROOT_PATH . '/header.php'; |
11
|
|
|
|
12
|
|
|
//get module configuration |
13
|
|
|
$moduleHandler = xoops_getHandler('module'); |
14
|
|
|
$module = $moduleHandler->getByDirname('pedigree'); |
15
|
|
|
$configHandler = xoops_getHandler('config'); |
16
|
|
|
$moduleConfig = $configHandler->getConfigsByCat(0, $module->getVar('mid')); |
17
|
|
|
|
18
|
|
|
global $xoopsTpl, $xoopsDB, $moduleConfig; |
|
|
|
|
19
|
|
|
|
20
|
|
|
//start kinship.php code -- help !! |
21
|
|
|
/* ************************************************************************************* */ |
22
|
|
|
/* |
23
|
|
|
This program calculates the coefficient of inbreeding (IC, or COI, or F) |
24
|
|
|
for the offspring of a couple of animals, given by their IDs (s=sire_ID&d=dam_ID), |
25
|
|
|
or for a given animal given by its ID (a=animal_ID). |
26
|
|
|
|
27
|
|
|
By default, all known ascendants are used. |
28
|
|
|
However, maximum count of distinct ascendants is limited to $nb_maxi (default=600) |
29
|
|
|
[higher values for $nb_maxi could lead to calculations ending in timeout], |
30
|
|
|
or depth of tree can be limited to $nb_gen generations (default = 8). |
31
|
|
|
*/ |
32
|
|
|
/* ************************************************************************************* */ |
33
|
|
|
|
34
|
|
|
if (!isset($verbose)) { |
35
|
|
|
$verbose = 0; |
36
|
|
|
} // don't display different steps of ICs calculation |
37
|
|
|
if (!isset($detail)) { |
38
|
|
|
$detail = 1; |
39
|
|
|
} // don't display detail results [faster] |
40
|
|
|
if (!isset($nb_maxi)) { |
41
|
|
|
$nb_maxi = 600; |
42
|
|
|
} // maximum count of distinct ascendants |
43
|
|
|
if (!isset($nb_gen)) { |
44
|
|
|
$nb_gen = 8; |
45
|
|
|
} // maximum count of generations of ascendants |
46
|
|
|
if (!isset($pedigree)) { |
47
|
|
|
$pedigree = 0; |
48
|
|
|
} // dont't display sketch pedigree [faster] |
49
|
|
|
if (!isset($max_dist)) { // maximum length of implex loops |
50
|
|
|
if ($nb_gen > 9) { |
51
|
|
|
$max_dist = 14; |
52
|
|
|
} else { |
53
|
|
|
if ($nb_gen == 9) { |
54
|
|
|
$max_dist = 17; |
55
|
|
|
} else { |
56
|
|
|
if ($nb_gen == 8) { |
57
|
|
|
$max_dist = 18; |
58
|
|
|
} else { |
59
|
|
|
$max_dist = 99; |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
$empty = array(); // an empty array |
66
|
|
|
$sql1 = 'select ID, father, mother, roft from ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' where ID '; |
67
|
|
|
|
68
|
|
|
// input data arrays: |
69
|
|
|
$IDs = $empty; |
70
|
|
|
$fathers = $empty; |
71
|
|
|
$mothers = $empty; |
72
|
|
|
|
73
|
|
|
// working arrays: |
74
|
|
|
$inds = $empty; |
75
|
|
|
$marked = $empty; |
76
|
|
|
$ICknown = $empty; |
77
|
|
|
$deltaf = $empty; |
78
|
|
|
$pater = $empty; |
79
|
|
|
$mater = $empty; |
80
|
|
|
$chrono = $empty; |
81
|
|
|
|
82
|
|
|
// Coefficients of Inbreeding array (result): |
83
|
|
|
$COIs = $empty; |
84
|
|
|
|
85
|
|
|
/* ****************************** FUNCTIONS ********************************* */ |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @return int |
|
|
|
|
89
|
|
|
*/ |
90
|
|
|
function chrono_sort() |
91
|
|
|
{ |
92
|
|
|
global $IDs, $inds, $fathers, $mothers, $chrono, $nl, $detail; |
|
|
|
|
93
|
|
|
$impr = 0; |
94
|
|
|
$modif = 1; |
95
|
|
|
$nloop = 0; |
96
|
|
|
$nba = count($IDs); |
97
|
|
|
// print_r ($IDs) ; |
|
|
|
|
98
|
|
|
// echo "<b>231 : $IDs[231] $fathers[231] $mothers[231] $chrono[231] $inds[231] </b><br />\n" ; |
|
|
|
|
99
|
|
|
foreach ($IDs as $i => $v) { |
100
|
|
|
$chrono[$i] = 1; |
101
|
|
|
} // initialize all chronological ranks to 1 |
102
|
|
|
$chrono[0] = 0; // except animal #0 (at 0 rank). |
103
|
|
|
while ($modif && $nloop < 40) { |
104
|
|
|
$modif = 0; |
105
|
|
|
++$nloop; |
106
|
|
|
for ($i = 1; $i < $nba; ++$i) { |
107
|
|
|
$s = $fathers[$i]; |
108
|
|
|
if ($s) { |
109
|
|
|
$s = $inds[$s]; |
110
|
|
|
} |
111
|
|
|
$d = $mothers[$i]; |
112
|
|
|
if ($d) { |
113
|
|
|
$d = $inds[$d]; |
114
|
|
|
} |
115
|
|
View Code Duplication |
if ($s && $chrono[$s] <= $chrono[$i]) { |
|
|
|
|
116
|
|
|
$chrono[$s] = $chrono[$i] + 1; |
117
|
|
|
$modif = 1; |
118
|
|
|
} |
119
|
|
View Code Duplication |
if ($d && $chrono[$d] <= $chrono[$i]) { |
|
|
|
|
120
|
|
|
$chrono[$d] = $chrono[$i] + 1; |
121
|
|
|
$modif = 1; |
122
|
|
|
} |
123
|
|
|
} |
124
|
|
|
} |
125
|
|
|
if ($nloop == 40) { |
126
|
|
|
die('Endless loop detected. Stopped.'); |
|
|
|
|
127
|
|
|
} |
128
|
|
|
array_multisort($chrono, $IDs, $fathers, $mothers); |
129
|
|
|
$depth = $chrono[$nba - 1]; |
|
|
|
|
130
|
|
|
//commentes out by JC |
131
|
|
|
//if ($detail) echo "<br />Chronological ranking done : Pedigree stretched over <b>$depth</b> generations.<br />$nl" ; |
|
|
|
|
132
|
|
|
if ($impr) { |
133
|
|
|
echo "</center><pre>$nl $nl"; |
134
|
|
|
foreach ($chrono as $i => $val) { |
135
|
|
|
echo "<b>$i</b> : $val $IDs[$i] $fathers[$i] $mothers[$i] $nl"; |
136
|
|
|
} |
137
|
|
|
echo "</pre>$nl"; |
138
|
|
|
die('</html>'); |
|
|
|
|
139
|
|
|
} |
140
|
|
|
$inds = array_flip($IDs); |
141
|
|
|
|
142
|
|
|
return 0; |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
/** |
146
|
|
|
* @param $s |
147
|
|
|
* |
148
|
|
|
* @return array |
149
|
|
|
*/ |
150
|
|
|
function fetch_record($s) |
|
|
|
|
151
|
|
|
{ |
152
|
|
|
global $database; |
|
|
|
|
153
|
|
|
$r = mysqli_db_query($database, $s); |
154
|
|
|
$n = 0; |
155
|
|
|
if ($r) { |
156
|
|
|
$n = mysqli_num_rows($r); |
157
|
|
|
} |
158
|
|
|
if ($n == 0) { |
159
|
|
|
$record = array('0'); |
160
|
|
|
} else { |
161
|
|
|
$record = $GLOBALS['xoopsDB']->fetchBoth($r); |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
return $record; |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
/** |
168
|
|
|
* @param $ind |
169
|
|
|
* @param $gen |
170
|
|
|
* |
171
|
|
|
* @return int |
172
|
|
|
*/ |
173
|
|
|
function count_all($ind, $gen) |
174
|
|
|
{ |
175
|
|
|
global $inds, $nb_gen, $nb_all, $fathers, $mothers; |
|
|
|
|
176
|
|
|
if ($ind) { |
177
|
|
|
++$nb_all; |
178
|
|
|
} |
179
|
|
|
$s = $fathers[$ind]; |
180
|
|
|
$d = $mothers[$ind]; |
181
|
|
|
if ($s && $gen < $nb_gen) { |
182
|
|
|
count_all($s, $gen + 1); |
183
|
|
|
} |
184
|
|
|
if ($d && $gen < $nb_gen) { |
185
|
|
|
count_all($d, $gen + 1); |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
return 0; |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
/** |
192
|
|
|
* @param $ch |
193
|
|
|
* @param $niv |
194
|
|
|
* |
195
|
|
|
* @return int |
196
|
|
|
*/ |
197
|
|
|
function add_multi($ch, $niv) |
198
|
|
|
{ |
199
|
|
|
global $implx, $couls, $nl; |
|
|
|
|
200
|
|
|
reset($implx); |
201
|
|
|
$first = 1; |
202
|
|
|
foreach ($implx as $im => $impl) { |
203
|
|
|
if ($impl[0] == $ch || $impl[1] == $ch) { |
204
|
|
|
if ($niv > 1 && $first) { |
205
|
|
|
echo "<br />$nl"; |
206
|
|
|
} else { |
207
|
|
|
echo ' '; |
208
|
|
|
} |
209
|
|
|
$i = $im + 1; |
210
|
|
|
$j = min($im, 6); |
211
|
|
|
$c = $couls[$j]; |
212
|
|
|
$first = 0; |
213
|
|
|
echo '<font color=' . $c . ' size="+2"><b>*' . $i . '*</b></font>'; |
214
|
|
|
} |
215
|
|
|
} |
216
|
|
|
|
217
|
|
|
return 0; |
218
|
|
|
} |
219
|
|
|
|
220
|
|
|
/** |
221
|
|
|
* @param $ind |
222
|
|
|
* @param $gen |
223
|
|
|
* @param $class |
224
|
|
|
* |
225
|
|
|
* @return int |
226
|
|
|
*/ |
227
|
|
|
function output_animal($ind, $gen, $class) |
228
|
|
|
{ |
229
|
|
|
global $depth, $IDs, $fathers, $mothers, $nl; |
|
|
|
|
230
|
|
|
if ($gen > $depth) { |
231
|
|
|
return 0; |
232
|
|
|
} |
233
|
|
|
$cell_content = 'Ø'; |
234
|
|
|
if ($ind || $gen == 0) { |
235
|
|
|
$ID = $IDs[$ind]; |
236
|
|
|
$ani = set_name($ID); |
237
|
|
|
$name = $ani[1]; |
|
|
|
|
238
|
|
|
$name = $ID; |
239
|
|
|
$cell_content = showParent($name) . $nl; |
240
|
|
|
} |
241
|
|
|
$rowspan = 1 << ($depth - $gen); |
242
|
|
|
echo '<td rowspan=' . $rowspan . ' align="center" class="' . $class . '">' . $cell_content . "</td>$nl"; |
243
|
|
|
if ($gen < $depth) { |
244
|
|
|
$sire = 0; |
245
|
|
|
if ($ind || $gen == 0) { |
246
|
|
|
$sire = $fathers[$ind]; |
247
|
|
|
} |
248
|
|
|
output_animal($sire, $gen + 1, '0'); |
249
|
|
|
$dam = 0; |
250
|
|
|
if ($ind || $gen == 0) { |
251
|
|
|
$dam = $mothers[$ind]; |
252
|
|
|
} |
253
|
|
|
output_animal($dam, $gen + 1, '1'); |
254
|
|
|
} else { |
255
|
|
|
echo "</tr><tr>$nl"; |
256
|
|
|
} |
257
|
|
|
|
258
|
|
|
return 0; |
259
|
|
|
} |
260
|
|
|
|
261
|
|
|
/** |
262
|
|
|
* @return int |
263
|
|
|
*/ |
264
|
|
|
function SKETCH_PEDIGREE() |
265
|
|
|
{ |
266
|
|
|
global $nl, $detail, $depth, $IDs; |
|
|
|
|
267
|
|
|
// print_r ($IDs) ; |
|
|
|
|
268
|
|
|
echo $nl . '<br />' . $nl . '<table border="3" cellpadding="4" width="85%"" cellpadding="0" cellspacing="0">' . $nl . '<tr><th colspan="10" align="center">SKETCH PEDIGREE OF COMMON PROGENY</th></tr>' . $nl . '<tr align="center" valign="middle"><th>Progeny</th><th>' . _('Sire / Dam') . '</th>'; |
269
|
|
|
if ($depth >= 2) { |
270
|
|
|
echo '<th>' . _('Grandparents') . '</th>' . $nl; |
271
|
|
|
} |
272
|
|
|
if ($depth >= 3) { |
273
|
|
|
echo '<th>' . _('Great-Grandparents') . '</th>' . $nl; |
274
|
|
|
} |
275
|
|
|
if ($depth >= 4) { |
276
|
|
|
echo '<th>3xGr. P.</th>' . $nl; |
277
|
|
|
} |
278
|
|
|
if ($depth >= 5) { |
279
|
|
|
echo '<th>4xGr. P.</th>' . $nl; |
280
|
|
|
} |
281
|
|
|
if ($depth >= 6) { |
282
|
|
|
echo '<th>5xGr. P.</th>' . $nl; |
283
|
|
|
} |
284
|
|
|
if ($depth >= 7) { |
285
|
|
|
echo '<th>6xGr. P.</th>' . $nl; |
286
|
|
|
} |
287
|
|
|
echo '</tr><tr>'; |
288
|
|
|
output_animal(0, 0, '0'); /* output the sketch pedigree */ |
289
|
|
|
echo $nl . '</tr></table>' . $nl . '<p />' . $nl; |
290
|
|
|
|
291
|
|
|
return 0; |
292
|
|
|
} |
293
|
|
|
|
294
|
|
|
/** |
295
|
|
|
* @return int |
296
|
|
|
*/ |
297
|
|
|
function GENEALOGY() |
|
|
|
|
298
|
|
|
{ |
299
|
|
|
global $IDs, $fathers, $mothers, $inds, $nb_gen, $nb_maxi, $nbani, $nl, $sql1; |
|
|
|
|
300
|
|
|
$impr = 0; |
301
|
|
|
$fathers[0] = $IDs[1]; |
302
|
|
|
$mothers[0] = $IDs[2]; |
303
|
|
|
$fathers[1] = 0; |
304
|
|
|
$mothers[1] = 0; |
305
|
|
|
$fathers[2] = 0; |
306
|
|
|
$mothers[2] = 0; |
307
|
|
|
$last = 2; |
308
|
|
|
if ($impr) { |
309
|
|
|
echo "<!-- genealogy 'de cujus' (gener. 0) : $IDs[0] = $IDs[1] x $IDs[2] -->$nl"; |
310
|
|
|
} |
311
|
|
|
$generation = array($IDs[1], $IDs[2]); // starting with first generation (sire and dam) |
312
|
|
|
$nbtot = 0; // count of total known ascendants within $nb_gen generations |
313
|
|
|
for ($nloop = 1, $tot = 2; $last <= $nb_maxi && $nloop <= $nb_gen; ++$nloop) { |
314
|
|
|
$nbtot += $tot; // count of total known ascendants within $nb_gen generations |
315
|
|
|
$nbani = $last; // count of distinct ascendants within $nb_gen generations |
316
|
|
|
$list = implode(',', array_unique($generation)); |
317
|
|
|
$generation = array(); |
318
|
|
|
$tot = 0; |
319
|
|
|
if ($impr) { |
320
|
|
|
echo " [$list]$nl"; |
321
|
|
|
} |
322
|
|
|
|
323
|
|
|
// HERE IS FETCHED EACH TRIPLET [ID, sire_ID, dam_ID] : |
324
|
|
|
$r = $GLOBALS['xoopsDB']->query("$sql1 IN ($list)"); |
325
|
|
|
while (false !== ($rec = $GLOBALS['xoopsDB']->fetchBoth($r))) { |
326
|
|
|
$a = $rec[0] + 0; |
327
|
|
|
$s = $rec[1] + 0; |
328
|
|
|
$d = $rec[2] + 0; |
329
|
|
|
if (!$a) { |
330
|
|
|
echo "ERROR : $a = $s x $d for list = '$list'<br />\n"; |
331
|
|
|
} |
332
|
|
|
if ($s) { |
333
|
|
|
++$tot; |
334
|
|
|
} |
335
|
|
|
if ($d) { |
336
|
|
|
++$tot; |
337
|
|
|
} |
338
|
|
|
$j = array_keys($IDs, $a); |
339
|
|
|
$j = $j[0]; |
340
|
|
|
$fathers[$j] = $s; |
341
|
|
|
$mothers[$j] = $d; |
342
|
|
View Code Duplication |
if ($s && !in_array($s, $IDs)) { |
|
|
|
|
343
|
|
|
$i = ++$last; |
344
|
|
|
$IDs[$i] = $s; |
345
|
|
|
$fathers[$i] = 0; |
346
|
|
|
$mothers[$i] = 0; |
347
|
|
|
if ($s) { |
348
|
|
|
$generation[] = $s; |
349
|
|
|
} |
350
|
|
|
} |
351
|
|
View Code Duplication |
if ($d && !in_array($d, $IDs)) { |
|
|
|
|
352
|
|
|
$i = ++$last; |
353
|
|
|
$IDs[$i] = $d; |
354
|
|
|
$fathers[$i] = 0; |
355
|
|
|
$mothers[$i] = 0; |
356
|
|
|
if ($s) { |
357
|
|
|
$generation[] = $d; |
358
|
|
|
} |
359
|
|
|
} |
360
|
|
|
if ($impr) { |
361
|
|
|
echo "<pre>genealogy ascendant (gener. $nloop) : $a = $s x $d [tot = $tot]$nl</pre>"; |
362
|
|
|
} |
363
|
|
|
} |
364
|
|
|
if (!count($generation)) { |
365
|
|
|
break; |
366
|
|
|
} |
367
|
|
|
} |
368
|
|
|
|
369
|
|
|
if ($nloop <= $nb_gen) { |
370
|
|
|
$nb_gen = $nloop; |
371
|
|
|
} // tree cut by $nb_maxi ! |
372
|
|
|
|
373
|
|
|
reset($IDs); |
374
|
|
|
$inds = array_flip($IDs); |
375
|
|
|
|
376
|
|
|
chrono_sort(); |
377
|
|
|
|
378
|
|
|
return $nbtot; |
379
|
|
|
} |
380
|
|
|
|
381
|
|
|
/** |
382
|
|
|
* @param $p |
383
|
|
|
* |
384
|
|
|
* @return int |
385
|
|
|
*/ |
386
|
|
View Code Duplication |
function dist_p($p) |
|
|
|
|
387
|
|
|
{ |
388
|
|
|
global $IDs, $fathers, $mothers, $pater, $nb_gen, $detail, $nl; |
|
|
|
|
389
|
|
|
// Anim #P is the sire |
390
|
|
|
$listall = array($p); |
391
|
|
|
$listnew = array($p); |
392
|
|
|
$pater = array(); |
393
|
|
|
$pater[$p] = 1; |
394
|
|
|
for ($nloop = 2; $nloop < ($nb_gen + 1); ++$nloop) { |
395
|
|
|
$liste = array(); |
396
|
|
|
foreach ($listnew as $i) { |
397
|
|
|
$s = $fathers[$i]; |
398
|
|
|
$d = $mothers[$i]; |
399
|
|
|
if ($s && !$pater[$s]) { |
400
|
|
|
$pater[$s] = $nloop; |
401
|
|
|
} // least distance from $s to sire's progeny |
402
|
|
|
if ($d && !$pater[$d]) { |
403
|
|
|
$pater[$d] = $nloop; |
404
|
|
|
} // least distance from $d to sire's progeny |
405
|
|
|
if ($s) { |
406
|
|
|
$liste[] = $s; |
407
|
|
|
} |
408
|
|
|
if ($d) { |
409
|
|
|
$liste[] = $d; |
410
|
|
|
} |
411
|
|
|
} |
412
|
|
|
if (!count($liste)) { |
413
|
|
|
break; |
414
|
|
|
} |
415
|
|
|
//commented pout by jc |
416
|
|
|
//if (in_array ($IDs[2], $liste) && !$detail) |
|
|
|
|
417
|
|
|
//{ echo "<p>DAM is an ascendant (at $nloop generations) of SIRE. Stopped." ; |
|
|
|
|
418
|
|
|
// die ("</body></html>$nl") ; } |
|
|
|
|
419
|
|
|
$listnew = array_diff(array_unique($liste), $listall); |
420
|
|
|
/* $list1 = join (' ', $listall) ; $list2 = join ('+', $listnew) ; |
|
|
|
|
421
|
|
|
echo "<!-- P ($nloop) $list1/$list2 -->$nl" ; */ |
422
|
|
|
$listall = array_merge($listall, $listnew); |
423
|
|
|
} |
424
|
|
|
// Here $pater array contains list of all distinct ascendants of #P (including P himself) |
425
|
|
|
// Values of $pater are minimum distances to #P (in generations) +1 |
426
|
|
|
return 0; |
427
|
|
|
} |
428
|
|
|
|
429
|
|
|
/** |
430
|
|
|
* @param $m |
431
|
|
|
* |
432
|
|
|
* @return int |
433
|
|
|
*/ |
434
|
|
View Code Duplication |
function dist_m($m) |
|
|
|
|
435
|
|
|
{ |
436
|
|
|
global $IDs, $fathers, $mothers, $mater, $nb_gen, $detail, $nl; |
|
|
|
|
437
|
|
|
// Anim #M is the dam |
438
|
|
|
$listall = array($m); |
439
|
|
|
$listnew = array($m); |
440
|
|
|
$mater = array(); |
441
|
|
|
$mater[$m] = 1; |
442
|
|
|
for ($nloop = 2; $nloop <= ($nb_gen + 1); ++$nloop) { |
443
|
|
|
$liste = array(); |
444
|
|
|
foreach ($listnew as $i) { |
445
|
|
|
$s = $fathers[$i]; |
446
|
|
|
$d = $mothers[$i]; |
447
|
|
|
if ($s && !$mater[$s]) { |
448
|
|
|
$mater[$s] = $nloop; |
449
|
|
|
} // least distance from $s to dam's progeny |
450
|
|
|
if ($d && !$mater[$d]) { |
451
|
|
|
$mater[$d] = $nloop; |
452
|
|
|
} // least distance from $d to dam's progeny |
453
|
|
|
// echo "I=" . $i . " MATER(I)=" . $mater[$i] . " NLOOP=" . $nloop . "<br />$nl" ; |
|
|
|
|
454
|
|
|
if ($s) { |
455
|
|
|
$liste[] = $s; |
456
|
|
|
} |
457
|
|
|
if ($d) { |
458
|
|
|
$liste[] = $d; |
459
|
|
|
} |
460
|
|
|
} |
461
|
|
|
if (!count($liste)) { |
462
|
|
|
break; |
463
|
|
|
} |
464
|
|
|
//commented out by jc |
465
|
|
|
//if (in_array ($IDs[1], $liste) && !$detail) |
|
|
|
|
466
|
|
|
// { echo "<p>SIRE is an ascendant (at $nloop generations) of DAM. Stopped." ; |
|
|
|
|
467
|
|
|
// die ("</body></html>$nl") ; } |
|
|
|
|
468
|
|
|
$listnew = array_diff(array_unique($liste), $listall); |
469
|
|
|
// $list1 = join (' ', $listall) ; $list2 = join ('+', $listnew) ; echo "M ($nloop) $list1/$list2 $nl" ; |
|
|
|
|
470
|
|
|
$listall = array_merge($listall, $listnew); |
471
|
|
|
} |
472
|
|
|
// Here $mater array contains list of all distinct ascendants of #M (including M herself) |
473
|
|
|
// Values of $mater are minimum distances to #M (in generations) +1 |
474
|
|
|
return 0; |
475
|
|
|
} |
476
|
|
|
|
477
|
|
|
/** |
478
|
|
|
* @return array |
479
|
|
|
*/ |
480
|
|
|
function calc_dist() /* Common Ascendants and their distances */ |
481
|
|
|
{ |
482
|
|
|
global $IDs, $fathers, $mothers, $nbanims, $pater, $mater, $empty, $nb_gen, $nl; |
|
|
|
|
483
|
|
|
global $dmax, $detail, $nb_gen; |
|
|
|
|
484
|
|
|
$distan = array(); |
485
|
|
|
// dist_m (2) ; has already been called |
486
|
|
|
dist_p($fathers[0]); |
487
|
|
|
$dmax = 0; |
488
|
|
|
$impr = 0; |
489
|
|
|
$dmx = 7; |
490
|
|
|
if ($detail) { |
491
|
|
|
$dmx += 2; |
492
|
|
|
} |
493
|
|
|
// ksort ($pater) ; print_r ($pater) ; echo "<br />$nl" ; ksort ($mater) ; print_r ($mater) ; echo "<br />$nl" ; |
|
|
|
|
494
|
|
|
foreach ($pater as $i => $p) { |
495
|
|
|
if ($p) { |
496
|
|
|
$m = $mater[$i]; |
497
|
|
|
if ($m) { |
498
|
|
|
$di = $p + $m; |
499
|
|
|
if ($impr) { |
500
|
|
|
echo " $i : $p + $m = $di <br />$nl"; |
501
|
|
|
} |
502
|
|
|
if (!$dmax) { |
503
|
|
|
$dmax = $dmx + $di - ceil($di / 2.); |
504
|
|
|
} |
505
|
|
|
if ($di > ($dmax + 2)) { |
506
|
|
|
continue; |
507
|
|
|
} |
508
|
|
|
$distan[$i] = $di; |
509
|
|
|
} |
510
|
|
|
} |
511
|
|
|
} |
512
|
|
|
if (!$dmax) { |
513
|
|
|
$dmax = 2 * $nb_gen - 2; |
514
|
|
|
} |
515
|
|
|
|
516
|
|
|
return $distan; |
517
|
|
|
} |
518
|
|
|
|
519
|
|
|
/** |
520
|
|
|
* @param $p |
521
|
|
|
* @param $m |
522
|
|
|
* @param $a |
523
|
|
|
* @param $ndist |
524
|
|
|
* |
525
|
|
|
* @return int |
526
|
|
|
*/ |
527
|
|
|
function mater_side($p, $m, $a, $ndist) |
528
|
|
|
{ |
529
|
|
|
global $fathers, $mothers, $marked, $COIs, $deltaf, $ICknown, $verbose, $nl, $chrono, $paternal_rank, $max_dist; |
|
|
|
|
530
|
|
|
if (!$m || $ndist > $max_dist) { |
531
|
|
|
return 0; |
532
|
|
|
} |
533
|
|
|
if ($p == $m) { |
534
|
|
|
/* IMPLEX FOUND (node of consanguinity) { for Anim #A */ |
535
|
|
|
$already_known = $ICknown[$p]; |
536
|
|
|
} |
537
|
|
|
if (!$already_known) { |
|
|
|
|
538
|
|
|
CONSANG($p); |
539
|
|
|
} // MAIN RECURSION: |
540
|
|
|
$ICp = $COIs[$p]; // we need to know the IC of Parent for Wright's formula |
541
|
|
|
if ($verbose && !$already_known && $ICp > 0.001 * $verbose) { |
542
|
|
|
echo "IC of Animal $p is $ICp$nl"; |
543
|
|
|
} |
544
|
|
|
$incr = 1.0 / (1 << $ndist) * (1. + $ICp); // ******** applying WRIGHT's formula ******** |
545
|
|
|
|
546
|
|
|
// [Note: 1 << $ndist is equal to 2 power $ndist] |
547
|
|
|
$COIs[$a] += $incr; // incrementing the IC of AnimC |
548
|
|
|
if ($a == 0) { |
549
|
|
|
$deltaf[$p] += $incr; |
550
|
|
|
} |
551
|
|
|
/* contribution of Anim #P to IC of Anim #0 */ |
552
|
|
|
// if ($verbose && $a == 0 && $incr > 0.0001*$verbose) |
|
|
|
|
553
|
|
|
// echo "Animal $p is contributing for " . substr ($deltaf[$p], 0, 10) . " to the IC of Animal $a$nl" ;} |
|
|
|
|
554
|
|
|
else { |
555
|
|
|
if (!$marked[$m] && $chrono[$m] < $paternal_rank) { |
556
|
|
|
mater_side($p, $fathers[$m], $a, $ndist + 1); |
557
|
|
|
} |
558
|
|
|
mater_side($p, $mothers[$m], $a, $ndist + 1); |
559
|
|
|
} |
560
|
|
|
|
561
|
|
|
return 0; |
562
|
|
|
} |
563
|
|
|
|
564
|
|
|
/** |
565
|
|
|
* @param $p |
566
|
|
|
* @param $m |
567
|
|
|
* @param $a |
568
|
|
|
* @param $pdist |
569
|
|
|
* |
570
|
|
|
* @return int |
571
|
|
|
*/ |
572
|
|
|
function pater_side($p, $m, $a, $pdist) |
573
|
|
|
{ |
574
|
|
|
global $mater, $fathers, $mothers, $marked, $chrono, $paternal_rank; |
|
|
|
|
575
|
|
|
if (!$p) { |
576
|
|
|
return 0; |
577
|
|
|
} |
578
|
|
|
$paternal_rank = $chrono[$p]; |
579
|
|
|
$marked[$p] = 1; /* cut paternal side */ |
580
|
|
|
if ($mater[$p] || $a) { |
581
|
|
|
mater_side($p, $m, $a, $pdist); |
582
|
|
|
} |
583
|
|
|
pater_side($fathers[$p], $m, $a, $pdist + 1); |
584
|
|
|
pater_side($mothers[$p], $m, $a, $pdist + 1); |
585
|
|
|
$marked[$p] = 0; /* free paternal side */ |
586
|
|
|
|
587
|
|
|
return 0; |
588
|
|
|
} |
589
|
|
|
|
590
|
|
|
/** |
591
|
|
|
* @param $a |
592
|
|
|
* |
593
|
|
|
* @return int |
594
|
|
|
*/ |
595
|
|
|
function CONSANG($a) |
596
|
|
|
{ |
597
|
|
|
global $fathers, $mothers, $ICknown, $COIs, $nl; |
|
|
|
|
598
|
|
|
if (!$a || $ICknown[$a]) { |
599
|
|
|
return 0; |
600
|
|
|
} |
601
|
|
|
if ($a == -1) { |
602
|
|
|
$a = 0; |
603
|
|
|
} // particular case : a= -1 means Anim #0 (to bypass above test) |
604
|
|
|
$IC_if_deadend = 0.0; // 0.0 means taht deadends are deemed to be total outcrosses... |
605
|
|
|
// if IC was already stored in the database for Aminal #A, it should be used here instead of 0.0 |
606
|
|
|
$p = $fathers[$a]; |
607
|
|
|
$m = $mothers[$a]; |
608
|
|
|
if (!$p || !$m) { |
609
|
|
|
$COIs[$a] = $IC_if_deadend; |
610
|
|
|
$ICknown[$a] = 2; |
611
|
|
|
|
612
|
|
|
return 0; |
613
|
|
|
} |
614
|
|
|
|
615
|
|
|
if ($verbose) { |
|
|
|
|
616
|
|
|
echo "</center><pre>$nl"; |
617
|
|
|
} |
618
|
|
|
pater_side($p, $m, $a, 1); // launch tree exploration |
619
|
|
|
if ($verbose) { |
620
|
|
|
echo "</pre><center>$nl"; |
621
|
|
|
} |
622
|
|
|
|
623
|
|
|
$ICknown[$a] = 1; |
624
|
|
|
$p = $fathers[$a]; |
625
|
|
|
$m = $mothers[$a]; |
626
|
|
|
foreach ($fathers as $i => $pere) {/* siblings share the same COI value */ |
627
|
|
|
if ($i <> $a && $pere == $p && $mothers[$i] == $m) { |
628
|
|
|
$COIs[$i] = $COIs[$a]; |
629
|
|
|
$ICknown[$i] = 1; |
630
|
|
|
} |
631
|
|
|
} |
632
|
|
|
// echo "<!-- COI($a) = $COIs[$a] $IDs[$a] ($fathers[$a] x $mothers[$a])-->$nl" ; |
|
|
|
|
633
|
|
|
return 0; |
634
|
|
|
} |
635
|
|
|
|
636
|
|
|
/** |
637
|
|
|
* @param $nb_gen |
638
|
|
|
* @param $nloop |
639
|
|
|
* |
640
|
|
|
* @return int |
641
|
|
|
*/ |
642
|
|
|
function boucle($nb_gen, $nloop) |
643
|
|
|
{ |
644
|
|
|
global $fathers, $mothers, $nbanims, $listing, $nl, $IDs; |
|
|
|
|
645
|
|
|
$nbtot = 0; |
646
|
|
|
$listing = ''; |
647
|
|
|
if ($nloop < ($nb_gen + 20)) { |
648
|
|
|
$nloop = $nb_gen + 20; |
649
|
|
|
} |
650
|
|
|
$list = array(0 => 1); /* initialize list with Anim0 (rank = 1) */ |
651
|
|
|
for ($j = 1; $j < $nloop; ++$j) { |
652
|
|
|
$new = 0; |
653
|
|
|
foreach ($list as $i => $rank) { |
654
|
|
View Code Duplication |
if (false !== ($s = $fathers[$i])) { |
|
|
|
|
655
|
|
|
if (!$list[$s]) { |
656
|
|
|
$new = 1; |
657
|
|
|
if ($j < $nb_gen) { |
658
|
|
|
++$nbtot; |
659
|
|
|
} |
660
|
|
|
} |
661
|
|
|
$list[$s] = $rank + 1; |
662
|
|
|
if ($j < $nb_gen) { |
663
|
|
|
++$nbtot; |
664
|
|
|
} |
665
|
|
|
if ($j > $nloop - 10) { |
666
|
|
|
$listing .= "Loop $j: Animal #$s " . $IDs[$s] . $nl; |
667
|
|
|
} |
668
|
|
|
} |
669
|
|
View Code Duplication |
if (false !== ($d = $mothers[$i])) { |
|
|
|
|
670
|
|
|
if (!$list[$d]) { |
671
|
|
|
$new = 1; |
672
|
|
|
if ($j < $nb_gen) { |
673
|
|
|
++$nbtot; |
674
|
|
|
} |
675
|
|
|
} |
676
|
|
|
$list[$d] = $rank + 1; |
677
|
|
|
if ($j < $nb_gen) { |
678
|
|
|
++$nbtot; |
679
|
|
|
} |
680
|
|
|
if ($j > $nloop - 10) { |
681
|
|
|
$listing .= "Loop $j: Animal #$d " . $IDs[$d] . $nl; |
682
|
|
|
} |
683
|
|
|
} |
684
|
|
|
} |
685
|
|
|
if (!$new) { |
686
|
|
|
break; |
687
|
|
|
} |
688
|
|
|
} |
689
|
|
|
if ($new) { |
|
|
|
|
690
|
|
|
$nbtot = 0; |
691
|
|
|
} /* Endless loop detected (see listing) */ |
692
|
|
|
|
693
|
|
|
return $nbtot; |
694
|
|
|
} |
695
|
|
|
|
696
|
|
|
if (!function_exists('html_accents')) { |
697
|
|
|
/** |
698
|
|
|
* @param $string |
699
|
|
|
* @return mixed |
700
|
|
|
*/ |
701
|
|
|
function html_accents($string) |
702
|
|
|
{ |
703
|
|
|
return $string; |
704
|
|
|
} |
705
|
|
|
} |
706
|
|
|
|
707
|
|
|
/** |
708
|
|
|
* @param $ID |
709
|
|
|
* |
710
|
|
|
* @return array |
711
|
|
|
*/ |
712
|
|
|
function set_name($ID) |
|
|
|
|
713
|
|
|
{ |
714
|
|
|
global $sql2, $sql2bis, $xoopsDB; |
|
|
|
|
715
|
|
|
$name = ' '; |
|
|
|
|
716
|
|
|
$ani = array(); |
717
|
|
|
if ($ID) { |
718
|
|
|
$sqlquery = 'SELECT ID, NAAM, roft from ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . " where ID = '$ID'"; |
719
|
|
|
$queryresult = $GLOBALS['xoopsDB']->query($sqlquery); |
720
|
|
|
$ani = $GLOBALS['xoopsDB']->fetchBoth($queryresult); |
721
|
|
|
$name = $ani[1]; |
722
|
|
|
if ($sql2bis) { // true for E.R.o'S. only |
723
|
|
|
$name = html_accents($name); |
724
|
|
|
//$affx = $ani[5] ; // affix-ID |
|
|
|
|
725
|
|
|
if ($affx) { |
726
|
|
|
$affix = fetch_record("$sql2bis '$affx'"); |
|
|
|
|
727
|
|
|
$type = $affix[1]; |
728
|
|
|
$affixe = html_accents($affix[0]); |
729
|
|
|
if ($type[0] === 'P') { |
730
|
|
|
$name = '<i>' . $affixe . '</i> ' . $name; |
731
|
|
|
} |
732
|
|
|
if ($type[0] === 'S') { |
733
|
|
|
$name = $name . ' <i>' . $affixe . '</i>'; |
734
|
|
|
} |
735
|
|
|
} |
736
|
|
|
$ani[1] = $name; |
737
|
|
|
} |
738
|
|
|
} |
739
|
|
|
|
740
|
|
|
return $ani; |
741
|
|
|
} |
742
|
|
|
|
743
|
|
|
/** |
744
|
|
|
* @param $ems |
745
|
|
|
* |
746
|
|
|
* @return string |
747
|
|
|
*/ |
748
|
|
|
function Ems_($ems) |
749
|
|
|
{ |
750
|
|
|
if (function_exists('Ems')) { |
751
|
|
|
return Ems($ems); |
752
|
|
|
} |
753
|
|
|
if (!$ems) { |
754
|
|
|
return ' '; |
755
|
|
|
} |
756
|
|
|
$e = str_replace(' ', '+', $ems); |
757
|
|
|
$res = '<a href="#" style="text-decoration:none;" onClick="' . "window.open('http://www.somali.asso.fr/eros/decode_ems.php?$e'," . "'', 'resizable=no,width=570,height=370')" . '"' . "><b>$ems</b></a>"; |
758
|
|
|
|
759
|
|
|
return $res; |
760
|
|
|
} |
761
|
|
|
|
762
|
|
|
/** |
763
|
|
|
* @param $ID |
764
|
|
|
* |
765
|
|
|
* @return string |
766
|
|
|
*/ |
767
|
|
|
function one_animal($ID) |
|
|
|
|
768
|
|
|
{ |
769
|
|
|
global $xoopsDB; |
|
|
|
|
770
|
|
|
global $sex, $val, $sosa, $detail, $sql3; |
|
|
|
|
771
|
|
|
$sosa = 12; |
772
|
|
|
// echo '<div style="position:relative;float:right;width=2.0em;color=white;">' . $sosa . '</div>' ; |
|
|
|
|
773
|
|
|
$animal = set_name($ID); |
774
|
|
|
list($ID, $name, $sex, $hd, $ems) = $animal; |
|
|
|
|
775
|
|
|
$sqlquery = 'select SQL_CACHE count(ID) from ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . " where father = '$ID' or mother = '$ID'"; |
776
|
|
|
$queryresult = $GLOBALS['xoopsDB']->query($sqlquery); |
777
|
|
|
$nb = $GLOBALS['xoopsDB']->fetchBoth($queryresult); |
778
|
|
|
$nb_children = $nb[0]; |
779
|
|
|
if ($nb_children == 0) { |
780
|
|
|
$nb_children = _MA_PEDIGREE_COI_NO; |
781
|
|
|
} |
782
|
|
|
//$dogid = $animal[0]; |
|
|
|
|
783
|
|
|
$content .= "<tr><td><a href=\"dog.php?id=" . $ID . "\">" . stripslashes($name) . '</a>'; |
|
|
|
|
784
|
|
|
// if ($nb_enf == 0) echo ' ø' ; |
|
|
|
|
785
|
|
|
if ($val) { |
786
|
|
|
$content .= $val; |
787
|
|
|
} |
788
|
|
|
if ($sex == 1) { |
789
|
|
|
$geslacht = "<img src=\"assets/images/female.gif\">"; |
790
|
|
|
} |
791
|
|
|
if ($sex == 0) { |
792
|
|
|
$geslacht = "<img src=\"assets/images/male.gif\">"; |
793
|
|
|
} |
794
|
|
|
$content .= '</td><td>' . $geslacht . '</td><td>' . $nb_children . _MA_PEDIGREE_COI_OFF . '</td></tr>'; |
|
|
|
|
795
|
|
|
|
796
|
|
|
return $content; |
797
|
|
|
} |
798
|
|
|
|
799
|
|
|
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% MAIN %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% */ |
800
|
|
|
|
801
|
|
|
$nl = "\n"; // the newline character |
802
|
|
|
|
803
|
|
|
//edit by jc |
|
|
|
|
804
|
|
|
//$link = @mysqli_pconnect ($host, $database, $password) |
805
|
|
|
// or die ("<html><body>Connection to database failed.</body></html>") ; |
806
|
|
|
$s = $_GET['s']; |
807
|
|
|
$d = $_GET['d']; |
808
|
|
|
$detail = $_GET['detail']; |
809
|
|
|
|
810
|
|
|
if (isset($si)) { |
811
|
|
|
$s = findId($si); |
812
|
|
|
} |
813
|
|
|
if (isset($da)) { |
814
|
|
|
$d = findId($da); |
815
|
|
|
} |
816
|
|
|
//test for variables |
|
|
|
|
817
|
|
|
//echo "si=".$si." da=".$da." s=".$s." d=".$d; |
818
|
|
|
$utils = $GLOBALS['xoopsDB']->query("select user(), date_format(now(),'%d-%b-%Y')"); |
819
|
|
|
list($who, $jourj) = $GLOBALS['xoopsDB']->fetchBoth($utils); |
820
|
|
|
|
821
|
|
|
if (isset($IC)) { |
822
|
|
|
$detail = -1; |
823
|
|
|
$a = $IC; |
824
|
|
|
} |
825
|
|
|
|
826
|
|
|
if (!isset($detail)) { |
827
|
|
|
$detail = 0; |
828
|
|
|
} |
829
|
|
|
|
830
|
|
|
if (!isset($a)) { |
831
|
|
|
if ($s && !isset($d)) { |
832
|
|
|
$a = $s; |
833
|
|
|
$s = ''; |
834
|
|
|
} |
835
|
|
|
if ($d && !isset($s)) { |
836
|
|
|
$a = $d; |
837
|
|
|
$d = ''; |
838
|
|
|
} |
839
|
|
|
} |
840
|
|
|
|
841
|
|
|
if (isset($a)) { |
842
|
|
|
$sqlquery = 'select ID, father, mother, roft from ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . " where ID = '$a'"; |
843
|
|
|
$queryresult = $GLOBALS['xoopsDB']->query($sqlquery); |
844
|
|
|
$rowhond = $GLOBALS['xoopsDB']->fetchBoth($queryresult); |
845
|
|
|
$a = $rowhond['Id']; |
846
|
|
|
$s = $rowhond['father']; |
847
|
|
|
$d = $rowhond['mother']; |
848
|
|
|
} |
849
|
|
|
$a += 0; |
850
|
|
|
$s += 0; |
851
|
|
|
$d += 0; // [IDs are numbers] |
852
|
|
|
|
853
|
|
|
$xoopsTpl->assign('ptitle', _MA_PEDIGREE_COI_CKRI); |
854
|
|
|
$xoopsTpl->assign('pcontent', strtr(_MA_PEDIGREE_COI_CKRI_CT, array('[animalType]' => $moduleConfig['animalType']))); |
855
|
|
|
|
856
|
|
|
if (!$s && !$d) { |
857
|
|
|
$error = _MA_PEDIGREE_COI_SPANF1 . $a . _MA_PEDIGREE_COI_SPANF2; |
858
|
|
|
$xoopsTpl->assign('COIerror', $error); |
859
|
|
|
} |
860
|
|
|
|
861
|
|
|
$maxn_ = 1000; |
862
|
|
|
$maxr_ = 9; |
863
|
|
|
|
864
|
|
|
$maxn = $maxn_; |
865
|
|
|
$maxr = $maxr_; |
866
|
|
|
$cinnamon = 0; |
867
|
|
|
$chocolat = 0; |
868
|
|
|
$dilution = 0; |
869
|
|
|
$sexlred = 0; |
870
|
|
|
|
871
|
|
|
$nivomin = -$maxr; /* Maximal depth of recursion (-10) */ |
872
|
|
|
$codec = 0; |
873
|
|
|
$gens = 4; /* 4 gens. for both pedigrees of couple */ |
874
|
|
|
$litter = 0; |
875
|
|
|
|
876
|
|
|
// echo "s:".$s."<br />"; |
|
|
|
|
877
|
|
|
// echo "d:".$d."<br />"; |
878
|
|
|
|
879
|
|
|
$codec1 = $d; |
880
|
|
|
$codec2 = $s; |
881
|
|
|
$val = ''; |
882
|
|
|
|
883
|
|
|
if (!$s && $d) { |
884
|
|
|
$codec1 = $d; |
885
|
|
|
$codec2 = 0; |
886
|
|
|
} |
887
|
|
|
if ($codec1 == $codec2) { |
888
|
|
|
$codec2 = 0; |
889
|
|
|
} |
890
|
|
|
|
891
|
|
|
$sqlquery = 'select father, mother, roft from ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . " where ID = '$codec1'"; |
892
|
|
|
$queryresult = $GLOBALS['xoopsDB']->query($sqlquery); |
893
|
|
|
$rowhond = $GLOBALS['xoopsDB']->fetchBoth($queryresult); |
894
|
|
|
$a1 = $rowhond['Id']; |
895
|
|
|
$s1 = $rowhond['father']; |
896
|
|
|
$d1 = $rowhond['mother']; |
897
|
|
|
$sex1 = $rowhond['roft']; |
898
|
|
|
|
899
|
|
|
// echo "sqlquery:".$sqlquery."<br />"; |
|
|
|
|
900
|
|
|
|
901
|
|
|
$sqlquery = 'select father, mother, roft from ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . " where ID = '$codec2'"; |
902
|
|
|
$queryresult = $GLOBALS['xoopsDB']->query($sqlquery); |
903
|
|
|
$rowhond = $GLOBALS['xoopsDB']->fetchBoth($queryresult); |
904
|
|
|
$a2 = $rowhond['Id']; |
905
|
|
|
$s2 = $rowhond['father']; |
906
|
|
|
$d2 = $rowhond['mother']; |
907
|
|
|
$sex2 = $rowhond['roft']; |
908
|
|
|
|
909
|
|
|
// echo "sqlquery:".$sqlquery."<br />"; |
|
|
|
|
910
|
|
|
|
911
|
|
|
//if ($sex1 == '0' && $sex2 == '1') { $a3 = $a1 ; $a1 = $a2 ; $a2 = $a3 ; } /* permute dam and sire */ |
|
|
|
|
912
|
|
|
$codec1 = $a1; |
913
|
|
|
$codec2 = $a2; |
914
|
|
|
if (!isset($s1) || !isset($d1) || !isset($s2) || !isset($d2)) { |
915
|
|
|
$xoopsTpl->assign('COIerror', _MA_PEDIGREE_COI_SGPU); |
916
|
|
|
} |
917
|
|
|
|
918
|
|
|
$title = strtr(_MA_PEDIGREE_FLD_FATH, array('[father]' => $moduleConfig['father'])) . ' (' . stripslashes(showParent($codec2)) . ')' . _MA_PEDIGREE_COI_AND . strtr(_MA_PEDIGREE_FLD_MOTH, array('[mother]' => $moduleConfig['mother'])) . ' (' . stripslashes(showParent($codec1)) . ')'; |
919
|
|
|
$content = stripslashes(one_animal($codec2)); |
920
|
|
|
$content .= stripslashes(one_animal($codec1)); |
921
|
|
|
$val = ''; |
922
|
|
|
$xoopsTpl->assign('SADtitle', $title); |
923
|
|
|
$xoopsTpl->assign('SADcontent', $content); |
924
|
|
|
$xoopsTpl->assign('SADexplain', strtr(_MA_PEDIGREE_COI_SDEX, array('[animalType]' => $moduleConfig['animalType'], '[animalTypes]' => $moduleConfig['animalTypes'], '[children]' => $moduleConfig['children']))); |
925
|
|
|
|
926
|
|
|
$de_cujus = 0; |
927
|
|
|
$sire_ID = $_GET['s']; |
928
|
|
|
$dam_ID = $_GET['d']; |
929
|
|
|
$rec = 'select ID from ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . " WHERE father = '" . $sire_ID . "' and mother = '" . $dam_ID . "' order by NAAM"; |
930
|
|
|
$result = $GLOBALS['xoopsDB']->query($rec); |
931
|
|
|
$content = ''; |
932
|
|
|
while (false !== ($row = $GLOBALS['xoopsDB']->fetchArray($result))) { |
933
|
|
|
$content .= one_animal($row['Id']); |
934
|
|
|
} |
935
|
|
|
|
936
|
|
|
$xoopsTpl->assign('COMtitle', strtr(_MA_PEDIGREE_COI_COMTIT, array('[father]' => $moduleConfig['father'], '[mother]' => $moduleConfig['mother']))); |
937
|
|
|
$xoopsTpl->assign('COMexplain', strtr(_MA_PEDIGREE_COI_COMEX, array('[animalType]' => $moduleConfig['animalType'], '[children]' => $moduleConfig['children']))); |
938
|
|
|
$xoopsTpl->assign('COMcontent', $content); |
939
|
|
|
|
940
|
|
|
if (!isset($nb_gen)) { |
941
|
|
|
$nb_gen = 7; |
942
|
|
|
if ($detail) { |
943
|
|
|
$nb_gen = 9; |
944
|
|
|
} |
945
|
|
|
} elseif ($nb_gen < $pedigree) { |
946
|
|
|
$nb_gen = $pedigree; |
947
|
|
|
} |
948
|
|
|
|
949
|
|
|
$IDs = array($de_cujus + 0, $codec1 + 0, $codec2 + 0); /* Structuring animal IDs into memory */ |
950
|
|
|
|
951
|
|
|
$nbanims = GENEALOGY(); // ************************************************************* // |
952
|
|
|
|
953
|
|
|
for ($i = 0; $i <= $nbanims; ++$i) { |
954
|
|
|
$empty[$i] = 0; |
955
|
|
|
} |
956
|
|
|
|
957
|
|
|
foreach ($fathers as $i => $a) { |
958
|
|
|
if ($a) { |
959
|
|
|
$fathers[$i] = $inds[$a]; |
960
|
|
|
} |
961
|
|
|
} /* Replace parents codes */ |
962
|
|
|
foreach ($mothers as $i => $a) { |
963
|
|
|
if ($a) { |
964
|
|
|
$mothers[$i] = $inds[$a]; |
965
|
|
|
} |
966
|
|
|
} /* by their indices */ |
967
|
|
|
|
968
|
|
|
dist_m($mothers[0]); // set "$mater" array (list of all maternal ascendants), for Anim #0 |
969
|
|
|
|
970
|
|
|
/* Calculating CONSANGUINITY by dual (paternal & maternal) path method */ |
971
|
|
|
$f = $empty; |
972
|
|
|
$ICknown = $empty; |
973
|
|
|
$deltaf = $empty; |
974
|
|
|
$marked = $empty; |
975
|
|
|
|
976
|
|
|
/****************** LAUNCHING ALL RECURSIONS ********************/ |
977
|
|
|
/* */ |
978
|
|
|
CONSANG(-1); /* [-1 is standing for de_cujus] |
979
|
|
|
/* */ |
980
|
|
|
/******************************************************************/ |
981
|
|
|
|
982
|
|
|
$nf = ceil(100 * $COIs[0]); |
983
|
|
|
if ($nf >= 55) { |
984
|
|
|
$w = _MA_PEDIGREE_COI_HUGE; |
985
|
|
|
} else { |
986
|
|
|
if ($nf >= 35) { |
987
|
|
|
$w = _MA_PEDIGREE_COI_VHIG; |
988
|
|
|
} else { |
989
|
|
|
if ($nf >= 20) { |
990
|
|
|
$w = _MA_PEDIGREE_COI_HIGH; |
991
|
|
|
} else { |
992
|
|
|
if ($nf >= 10) { |
993
|
|
|
$w = _MA_PEDIGREE_COI_MEDI; |
994
|
|
|
} else { |
995
|
|
|
if ($nf >= 05) { |
996
|
|
|
$w = _MA_PEDIGREE_COI_LOW; |
997
|
|
|
} else { |
998
|
|
|
if ($nf >= 02) { |
999
|
|
|
$w = _MA_PEDIGREE_COI_VLOW; |
1000
|
|
|
} else { |
1001
|
|
|
if ($nf >= 01) { |
1002
|
|
|
$w = _MA_PEDIGREE_COI_VVLO; |
1003
|
|
|
} else { |
1004
|
|
|
$w = _MA_PEDIGREE_COI_TLTB; |
1005
|
|
|
} |
1006
|
|
|
} |
1007
|
|
|
} |
1008
|
|
|
} |
1009
|
|
|
} |
1010
|
|
|
} |
1011
|
|
|
} |
1012
|
|
|
$w = _MA_PEDIGREE_COI_TVI . ' ' . $w; |
1013
|
|
|
|
1014
|
|
|
$nb_all = 0; |
1015
|
|
|
count_all(0, 0); // count all ascendants in flat tree |
1016
|
|
|
|
1017
|
|
|
$nbmax = (2 << $nb_gen) - 2; |
1018
|
|
|
$asctc = _MA_PEDIGREE_COI_ASTC . $nb_gen . _MA_PEDIGREE_COI_ASTCGEN . $nbmax . ')'; |
1019
|
|
|
$ascuni = _MA_PEDIGREE_COI_ASDKA . $nb_gen . _MA_PEDIGREE_COI_ASGEN; |
1020
|
|
|
$xoopsTpl->assign('ASCtitle', _MA_PEDIGREE_COI_ACTIT); |
1021
|
|
|
$xoopsTpl->assign('ASCtc', $asctc); |
1022
|
|
|
$xoopsTpl->assign('ASCuni', $ascuni); |
1023
|
|
|
$xoopsTpl->assign('ASCall', $nb_all); |
1024
|
|
|
$xoopsTpl->assign('ASCani', $nbani); |
1025
|
|
|
$xoopsTpl->assign('ASCexplain', _MA_PEDIGREE_COI_ACEX); |
1026
|
|
|
|
1027
|
|
|
$f0 = substr($COIs[0], 0, 8); |
1028
|
|
|
if (!$f0) { |
1029
|
|
|
$f0 = 'n.a.'; |
1030
|
|
|
} |
1031
|
|
|
$f1 = 100 * $f0; |
1032
|
|
|
|
1033
|
|
|
$xoopsTpl->assign('COItitle', strtr(_MA_PEDIGREE_COI_COITIT, array('[father]' => $moduleConfig['father'], '[mother]' => $moduleConfig['mother']))); |
1034
|
|
|
$xoopsTpl->assign('COIperc', $w); |
1035
|
|
|
$xoopsTpl->assign('COIval', $f1); |
1036
|
|
|
$xoopsTpl->assign('COIexplain', strtr(_MA_PEDIGREE_COI_COIEX, array('[animalType]' => $moduleConfig['animalType'], '[animalTypes]' => $moduleConfig['animalTypes'], '[children]' => $moduleConfig['children']))); |
1037
|
|
|
$xoopsTpl->assign('COIcoi', _MA_PEDIGREE_COI_COI); |
1038
|
|
|
$dogid = XoopsRequest::getInt('dogid', 0, 'get'); |
1039
|
|
|
$query = 'UPDATE ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' SET coi=' . $f1 . ' WHERE ID = ' . $dogid; |
1040
|
|
|
$GLOBALS['xoopsDB']->queryF($query); |
1041
|
|
|
arsort($deltaf); |
1042
|
|
|
$j = 1; |
1043
|
|
|
foreach ($deltaf as $i => $v) { |
1044
|
|
|
if ($j > 12) { |
1045
|
|
|
break; |
1046
|
|
|
} |
1047
|
|
|
++$j; |
1048
|
|
|
$code = $IDs[$i]; |
1049
|
|
|
$v = substr($v, 0, 7); |
1050
|
|
|
$animal = set_name($IDs[$i]); |
1051
|
|
|
$name = $animal[1]; |
1052
|
|
|
if (!$name) { |
1053
|
|
|
$name = $i . ' [' . $IDs[$i] . ']'; |
1054
|
|
|
} |
1055
|
|
|
if ($v > 0.0001 && $v < 1.0) { |
1056
|
|
|
$dogs[] = array('id' => $code, 'name' => stripslashes($name), 'coi' => 100 * $v); |
1057
|
|
|
} |
1058
|
|
|
} |
1059
|
|
|
|
1060
|
|
|
$xoopsTpl->assign('TCAtitle', _MA_PEDIGREE_COI_TCATIT); |
1061
|
|
|
$xoopsTpl->assign('TCApib', _MA_PEDIGREE_COI_TCApib); |
1062
|
|
|
$xoopsTpl->assign('dogs', $dogs); |
1063
|
|
|
$xoopsTpl->assign('TCAexplain', strtr(_MA_PEDIGREE_COI_TCAEX, array( |
1064
|
|
|
'[animalType]' => $moduleConfig['animalType'], |
1065
|
|
|
'[animalTypes]' => $moduleConfig['animalTypes'], |
1066
|
|
|
'[children]' => $moduleConfig['children'], |
1067
|
|
|
'[mother]' => $moduleConfig['mother'], |
1068
|
|
|
'[father]' => $moduleConfig['father'] |
1069
|
|
|
))); |
1070
|
|
|
|
1071
|
|
|
if ($detail) { |
1072
|
|
|
if ($verbose) { |
1073
|
|
|
$verbose = 0; |
1074
|
|
|
} |
1075
|
|
|
if (count($COIs) > 1) { |
1076
|
|
|
$ICs = $COIs; |
1077
|
|
|
arsort($ICs); |
1078
|
|
|
$j = 1; |
1079
|
|
|
foreach ($ICs as $i => $ic) { |
1080
|
|
|
if ($j > 12) { |
1081
|
|
|
break; |
1082
|
|
|
} |
1083
|
|
|
++$j; |
1084
|
|
|
$ID = $IDs[$i]; |
1085
|
|
|
$ani = set_name($ID); |
1086
|
|
|
$name = $ani[1]; |
1087
|
|
|
$ic = substr($ic, 0, 6); |
1088
|
|
|
if ($ic > 0.125 && $i) { |
1089
|
|
|
$mia[] = array('id' => $ID, 'name' => stripslashes($name), 'coi' => 100 * $ic); |
1090
|
|
|
} |
1091
|
|
|
} |
1092
|
|
|
} |
1093
|
|
|
$xoopsTpl->assign('MIAtitle', _MA_PEDIGREE_COI_MIATIT); |
1094
|
|
|
$xoopsTpl->assign('mia', $mia); |
1095
|
|
|
$xoopsTpl->assign('MIAexplain', strtr(_MA_PEDIGREE_COI_MIAEX, array('[animalType]' => $moduleConfig['animalType']))); |
1096
|
|
|
|
1097
|
|
|
if (!$ICknown[1]) { |
1098
|
|
|
$marked = $empty; |
1099
|
|
|
CONSANG(1); |
1100
|
|
|
} // Sire |
1101
|
|
|
if (!$ICknown[2]) { |
1102
|
|
|
$marked = $empty; |
1103
|
|
|
CONSANG(2); |
1104
|
|
|
} // Dam |
1105
|
|
|
$COR = 2.0 * $COIs[0] / sqrt((1. + $COIs[1]) * (1. + $COIs[2])); |
1106
|
|
|
$COR = substr($COR, 0, 8); |
1107
|
|
|
if (!$COR) { |
1108
|
|
|
$COR = 'n.a.'; |
1109
|
|
|
} |
1110
|
|
|
$f1 = substr($COIs[1], 0, 8); |
1111
|
|
|
$f2 = substr($COIs[2], 0, 8); |
1112
|
|
|
if (!$f1) { |
1113
|
|
|
$f1 = 'n.a.'; |
1114
|
|
|
} |
1115
|
|
|
if (!$f2) { |
1116
|
|
|
$f2 = 'n.a.'; |
1117
|
|
|
} |
1118
|
|
|
$SSDcor = (100 * $COR); |
1119
|
|
|
$SSDsire = (100 * $f2); |
1120
|
|
|
$SSDdam = (100 * $f1); |
1121
|
|
|
} |
1122
|
|
|
|
1123
|
|
|
$xoopsTpl->assign('SSDtitle', strtr(_MA_PEDIGREE_COI_SSDTIT, array('[father]' => $moduleConfig['father'], '[mother]' => $moduleConfig['mother']))); |
1124
|
|
|
$xoopsTpl->assign('SSDcortit', _MA_PEDIGREE_COI_SSDcor); |
1125
|
|
|
$xoopsTpl->assign('SSDbsd', strtr(_MA_PEDIGREE_COI_SDDbsd, array('[father]' => $moduleConfig['father'], '[mother]' => $moduleConfig['mother']))); |
1126
|
|
|
$xoopsTpl->assign('SSDcor', $SSDcor); |
1127
|
|
|
|
1128
|
|
|
$xoopsTpl->assign('SSDS', _MA_PEDIGREE_COI_COI . _MA_PEDIGREE_FROM . strtr(_MA_PEDIGREE_FLD_FATH, array('[father]' => $moduleConfig['father']))); |
1129
|
|
|
$xoopsTpl->assign('SSDsire', $SSDsire); |
1130
|
|
|
$xoopsTpl->assign('SSDM', _MA_PEDIGREE_COI_COI . _MA_PEDIGREE_FROM . strtr(_MA_PEDIGREE_FLD_MOTH, array('[mother]' => $moduleConfig['mother']))); |
1131
|
|
|
$xoopsTpl->assign('SSDdam', $SSDdam); |
1132
|
|
|
|
1133
|
|
|
// echo "SSDsire : ".$SSDsire."<br />"; |
|
|
|
|
1134
|
|
|
// echo "SSDdam : ".$SSDdam."<br />"; |
1135
|
|
|
// print_r($COIs); |
1136
|
|
|
|
1137
|
|
|
$xoopsTpl->assign('SSDexplain', strtr(_MA_PEDIGREE_COI_SSDEX, array('[father]' => $moduleConfig['father'], '[mother]' => $moduleConfig['mother'], '[animalType]' => $moduleConfig['animalTypes']))); |
1138
|
|
|
$xoopsTpl->assign('TNXtitle', _MA_PEDIGREE_COI_TNXTIT); |
1139
|
|
|
$xoopsTpl->assign('TNXcontent', _MA_PEDIGREE_COI_TNXCON); |
1140
|
|
|
$xoopsTpl->assign('Name', _MA_PEDIGREE_FLD_NAME); |
1141
|
|
|
$xoopsTpl->assign('Gender', _MA_PEDIGREE_FLD_GEND); |
1142
|
|
|
$xoopsTpl->assign('Children', strtr(_MA_PEDIGREE_FLD_PUPS, array('[children]' => $moduleConfig['children']))); |
1143
|
|
|
|
1144
|
|
|
//add data to smarty template |
1145
|
|
|
$xoopsTpl->assign('explain', _MA_PEDIGREE_EXPLAIN); |
1146
|
|
|
|
1147
|
|
|
//comments and footer |
1148
|
|
|
include XOOPS_ROOT_PATH . '/footer.php'; |
1149
|
|
|
|
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.