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