-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathmpedigree.php
More file actions
399 lines (378 loc) · 15.5 KB
/
mpedigree.php
File metadata and controls
399 lines (378 loc) · 15.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
<?php
/*
You may not change or alter any portion of this comment or credits of
supporting developers from this source code or any supporting source code
which is considered copyrighted (c) material of the original comment or credit
authors.
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.
*/
/**
* Module: Pedigree
*
* @package XoopsModules\Pedigree
* @author XOOPS Module Development Team
* @copyright Copyright (c) 2001-2019 {@link https://xoops.org XOOPS Project}
* @license https://www.gnu.org/licenses/gpl-2.0.html GNU Public License
*/
use Xmf\Request;
use XoopsModules\Pedigree\{
Helper
};
/** @var Helper $helper */
//require_once \dirname(__DIR__, 2) . '/mainfile.php';
require_once __DIR__ . '/header.php';
$helper = Helper::getInstance();
$moduleDirName = basename(__DIR__);
$helper->loadLanguage('main');
// Include any common code for this module.
require_once XOOPS_ROOT_PATH . '/modules/' . $moduleDirName . '/include/common.php';
$GLOBALS['xoopsOption']['template_main'] = 'pedigree_mpedigree.tpl';
require $GLOBALS['xoops']->path('/header.php');
//get module configuration
/** @var \XoopsModuleHandler $moduleHandler */
$moduleHandler = xoops_getHandler('module');
$module = $moduleHandler->getByDirname($moduleDirName);
/** @var \XoopsConfigHandler $configHandler */
$configHandler = xoops_getHandler('config');
$moduleConfig = $configHandler->getConfigsByCat(0, $module->getVar('mid'));
//always start with Anika
$pedId = Request::getInt('pedid', 0, 'GET');
//$pedId = $_GET['pedid'];
//draw pedigree
$sql = '
SELECT d.id as d_id,
d.pname as d_pname,
d.roft as d_roft,
f.id as f_id,
f.pname as f_pname,
m.id as m_id,
m.pname as m_pname,
ff.id as ff_id,
ff.pname as ff_pname,
mf.id as mf_id,
mf.pname as mf_pname,
fm.id as fm_id,
fm.pname as fm_pname,
mm.id as mm_id,
mm.pname as mm_pname,
fff.id as fff_id,
fff.pname as fff_pname,
ffm.id as ffm_id,
ffm.pname as ffm_pname,
fmf.id as fmf_id,
fmf.pname as fmf_pname,
fmm.id as fmm_id,
fmm.pname as fmm_pname,
mmf.id as mmf_id,
mmf.pname as mmf_pname,
mff.id as mff_id,
mff.pname as mff_pname,
mfm.id as mfm_id,
mfm.pname as mfm_pname,
mmm.id as mmm_id,
mmm.pname as mmm_pname,
ffff.id as ffff_id,
ffff.pname as ffff_pname,
ffmf.id as ffmf_id,
ffmf.pname as ffmf_pname,
fmff.id as fmff_id,
fmff.pname as fmff_pname,
fmmf.id as fmmf_id,
fmmf.pname as fmmf_pname,
mmff.id as mmff_id,
mmff.pname as mmff_pname,
mfff.id as mfff_id,
mfff.pname as mfff_pname,
mfmf.id as mfmf_id,
mfmf.pname as mfmf_pname,
mmmf.id as mmmf_id,
mmmf.pname as mmmf_pname,
fffm.id as fffm_id,
fffm.pname as fffm_pname,
ffmm.id as ffmm_id,
ffmm.pname as ffmm_pname,
fmfm.id as fmfm_id,
fmfm.pname as fmfm_pname,
fmmm.id as fmmm_id,
fmmm.pname as fmmm_pname,
mmfm.id as mmfm_id,
mmfm.pname as mmfm_pname,
mffm.id as mffm_id,
mffm.pname as mffm_pname,
mfmm.id as mfmm_id,
mfmm.pname as mfmm_pname,
mmmm.id as mmmm_id,
mmmm.pname as mmmm_pname
FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_registry') . ' d
LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_registry') . ' f ON d.father = f.id
LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_registry') . ' m ON d.mother = m.id
LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_registry') . ' ff ON f.father = ff.id
LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_registry') . ' fff ON ff.father = fff.id
LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_registry') . ' ffm ON ff.mother = ffm.id
LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_registry') . ' mf ON m.father = mf.id
LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_registry') . ' mff ON mf.father = mff.id
LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_registry') . ' mfm ON mf.mother = mfm.id
LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_registry') . ' fm ON f.mother = fm.id
LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_registry') . ' fmf ON fm.father = fmf.id
LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_registry') . ' fmm ON fm.mother = fmm.id
LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_registry') . ' mm ON m.mother = mm.id
LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_registry') . ' mmf ON mm.father = mmf.id
LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_registry') . ' mmm ON mm.mother = mmm.id
LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_registry') . ' ffff ON fff.father = ffff.id
LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_registry') . ' ffmf ON ffm.father = ffmf.id
LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_registry') . ' fmff ON fmf.father = fmff.id
LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_registry') . ' fmmf ON fmm.father = fmmf.id
LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_registry') . ' mmff ON mmf.father = mmff.id
LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_registry') . ' mfff ON mff.father = mfff.id
LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_registry') . ' mfmf ON mfm.father = mfmf.id
LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_registry') . ' mmmf ON mmm.father = mmmf.id
LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_registry') . ' fffm ON fff.mother = fffm.id
LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_registry') . ' ffmm ON ffm.mother = ffmm.id
LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_registry') . ' fmfm ON fmf.mother = fmfm.id
LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_registry') . ' fmmm ON fmm.mother = fmmm.id
LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_registry') . ' mmfm ON mmf.mother = mmfm.id
LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_registry') . ' mffm ON mff.mother = mffm.id
LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_registry') . ' mfmm ON mfm.mother = mfmm.id
LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_registry') . ' mmmm ON mmm.mother = mmmm.id
WHERE d.id=' . $pedId;
$result = $GLOBALS['xoopsDB']->query($sql);
while (false !== ($row = $GLOBALS['xoopsDB']->fetchArray($result))) {
//crete array to count frequency (to select colour)
count_item($freq, $row['d_id']);
count_item($freq, $row['f_id']);
count_item($freq, $row['m_id']);
count_item($freq, $row['ff_id']);
count_item($freq, $row['fm_id']);
count_item($freq, $row['mf_id']);
count_item($freq, $row['mm_id']);
count_item($freq, $row['fff_id']);
count_item($freq, $row['ffm_id']);
count_item($freq, $row['fmf_id']);
count_item($freq, $row['fmm_id']);
count_item($freq, $row['mff_id']);
count_item($freq, $row['mfm_id']);
count_item($freq, $row['mmf_id']);
count_item($freq, $row['mmm_id']);
count_item($freq, $row['ffff_id']);
count_item($freq, $row['ffmf_id']);
count_item($freq, $row['fmff_id']);
count_item($freq, $row['fmmf_id']);
count_item($freq, $row['mfff_id']);
count_item($freq, $row['mfmf_id']);
count_item($freq, $row['mmff_id']);
count_item($freq, $row['mmmf_id']);
count_item($freq, $row['fffm_id']);
count_item($freq, $row['ffmm_id']);
count_item($freq, $row['fmfm_id']);
count_item($freq, $row['fmmm_id']);
count_item($freq, $row['mffm_id']);
count_item($freq, $row['mfmm_id']);
count_item($freq, $row['mmfm_id']);
count_item($freq, $row['mmmm_id']);
//create array for dog (and all parents)
//selected dog
$d['d']['name'] = stripslashes($row['d_pname']);
$d['d']['id'] = $row['d_id'];
$d['d']['roft'] = $row['d_roft'];
$d['d']['col'] = 'transparant';
//father
$d['f']['name'] = stripslashes($row['f_pname']);
$d['f']['id'] = $row['f_id'];
$d['f']['col'] = crcolour('f', $freq[$row['f_id']]);
//mother
$d['m']['name'] = stripslashes($row['m_pname']);
$d['m']['id'] = $row['m_id'];
$d['m']['col'] = crcolour('m', $freq[$row['m_id']]);
//grandparents
//father father
$d['ff']['name'] = stripslashes($row['ff_pname']);
$d['ff']['id'] = $row['ff_id'];
$d['ff']['col'] = crcolour('f', $freq[$row['ff_id']]);
//father mother
$d['fm']['name'] = stripslashes($row['fm_pname']);
$d['fm']['id'] = $row['fm_id'];
$d['fm']['col'] = crcolour('m', $freq[$row['fm_id']]);
//mother father
$d['mf']['name'] = stripslashes($row['mf_pname']);
$d['mf']['id'] = $row['mf_id'];
$d['mf']['col'] = crcolour('f', $freq[$row['mf_id']]);
//mother mother
$d['mm']['name'] = stripslashes($row['mm_pname']);
$d['mm']['id'] = $row['mm_id'];
$d['mm']['col'] = crcolour('m', $freq[$row['mm_id']]);
//great-grandparents
//father father father
$d['fff']['name'] = stripslashes($row['fff_pname']);
$d['fff']['id'] = $row['fff_id'];
$d['fff']['col'] = crcolour('f', $freq[$row['fff_id']]);
//father father mother
$d['ffm']['name'] = stripslashes($row['ffm_pname']);
$d['ffm']['id'] = $row['ffm_id'];
$d['ffm']['col'] = crcolour('m', $freq[$row['ffm_id']]);
//father mother father
$d['fmf']['name'] = stripslashes($row['fmf_pname']);
$d['fmf']['id'] = $row['fmf_id'];
$d['fmf']['col'] = crcolour('f', $freq[$row['fmf_id']]);
//father mother mother
$d['fmm']['name'] = stripslashes($row['fmm_pname']);
$d['fmm']['id'] = $row['fmm_id'];
$d['fmm']['col'] = crcolour('m', $freq[$row['fmm_id']]);
//mother father father
$d['mff']['name'] = stripslashes($row['mff_pname']);
$d['mff']['id'] = $row['mff_id'];
$d['mff']['col'] = crcolour('f', $freq[$row['mff_id']]);
//mother father mother
$d['mfm']['name'] = stripslashes($row['mfm_pname']);
$d['mfm']['id'] = $row['mfm_id'];
$d['mfm']['col'] = crcolour('m', $freq[$row['mfm_id']]);
//mother mother father
$d['mmf']['name'] = stripslashes($row['mmf_pname']);
$d['mmf']['id'] = $row['mmf_id'];
$d['mmf']['col'] = crcolour('f', $freq[$row['mmf_id']]);
//mother mother mother
$d['mmm']['name'] = stripslashes($row['mmm_pname']);
$d['mmm']['id'] = $row['mmm_id'];
$d['mmm']['col'] = crcolour('m', $freq[$row['mmm_id']]);
//great-great-grandparents (fathers)
//father father father
$d['ffff']['name'] = stripslashes($row['ffff_pname']);
$d['ffff']['id'] = $row['ffff_id'];
$d['ffff']['col'] = crcolour('f', $freq[$row['ffff_id']]);
//father father mother
$d['ffmf']['name'] = stripslashes($row['ffmf_pname']);
$d['ffmf']['id'] = $row['ffmf_id'];
$d['ffmf']['col'] = crcolour('f', $freq[$row['ffmf_id']]);
//father mother father
$d['fmff']['name'] = stripslashes($row['fmff_pname']);
$d['fmff']['id'] = $row['fmff_id'];
$d['fmff']['col'] = crcolour('f', $freq[$row['fmff_id']]);
//father mother mother
$d['fmmf']['name'] = stripslashes($row['fmmf_pname']);
$d['fmmf']['id'] = $row['fmmf_id'];
$d['fmmf']['col'] = crcolour('f', $freq[$row['fmmf_id']]);
//mother father father
$d['mfff']['name'] = stripslashes($row['mfff_pname']);
$d['mfff']['id'] = $row['mfff_id'];
$d['mfff']['col'] = crcolour('f', $freq[$row['mfff_id']]);
//mother father mother
$d['mfmf']['name'] = stripslashes($row['mfmf_pname']);
$d['mfmf']['id'] = $row['mfmf_id'];
$d['mfmf']['col'] = crcolour('f', $freq[$row['mfmf_id']]);
//mother mother father
$d['mmff']['name'] = stripslashes($row['mmff_pname']);
$d['mmff']['id'] = $row['mmff_id'];
$d['mmff']['col'] = crcolour('f', $freq[$row['mmff_id']]);
//mother mother mother
$d['mmmf']['name'] = stripslashes($row['mmmf_pname']);
$d['mmmf']['id'] = $row['mmmf_id'];
$d['mmmf']['col'] = crcolour('f', $freq[$row['mmmf_id']]);
//great-great-grandparents (mothers)
//father father father
$d['fffm']['name'] = stripslashes($row['fffm_pname']);
$d['fffm']['id'] = $row['fffm_id'];
$d['fffm']['col'] = crcolour('m', $freq[$row['fffm_id']]);
//father father mother
$d['ffmm']['name'] = stripslashes($row['ffmm_pname']);
$d['ffmm']['id'] = $row['ffmm_id'];
$d['ffmm']['col'] = crcolour('m', $freq[$row['ffmm_id']]);
//father mother father
$d['fmfm']['name'] = stripslashes($row['fmfm_pname']);
$d['fmfm']['id'] = $row['fmfm_id'];
$d['fmfm']['col'] = crcolour('m', $freq[$row['fmfm_id']]);
//father mother mother
$d['fmmm']['name'] = stripslashes($row['fmmm_pname']);
$d['fmmm']['id'] = $row['fmmm_id'];
$d['fmmm']['col'] = crcolour('m', $freq[$row['fmmm_id']]);
//mother father father
$d['mffm']['name'] = stripslashes($row['mffm_pname']);
$d['mffm']['id'] = $row['mffm_id'];
$d['mffm']['col'] = crcolour('m', $freq[$row['mffm_id']]);
//mother father mother
$d['mfmm']['name'] = stripslashes($row['mfmm_pname']);
$d['mfmm']['id'] = $row['mfmm_id'];
$d['mfmm']['col'] = crcolour('m', $freq[$row['mfmm_id']]);
//mother mother father
$d['mmfm']['name'] = stripslashes($row['mmfm_pname']);
$d['mmfm']['id'] = $row['mmfm_id'];
$d['mmfm']['col'] = crcolour('m', $freq[$row['mmfm_id']]);
//mother mother mother
$d['mmmm']['name'] = stripslashes($row['mmmm_pname']);
$d['mmmm']['id'] = $row['mmmm_id'];
$d['mmmm']['col'] = crcolour('m', $freq[$row['mmmm_id']]);
}
//add data to smarty template
$GLOBALS['xoopsTpl']->assign('xoops_pagetitle', $d['d']['name'] . ' -- mega pedigree');
//assign dog(s)
$GLOBALS['xoopsTpl']->assign('d', $d);
$GLOBALS['xoopsTpl']->assign('male', "<img src=\"" . PEDIGREE_IMAGE_URL . "/male.gif\">");
$GLOBALS['xoopsTpl']->assign('female', "<img src=\"" . PEDIGREE_IMAGE_URL . "/female.gif\">");
//assign extra display options
$GLOBALS['xoopsTpl']->assign('unknown', 'Unknown');
$GLOBALS['xoopsTpl']->assign('f2', strtr(_MA_PEDIGREE_MPED_F2, ['[animalType]' => $helper->getConfig('animalType')]));
$GLOBALS['xoopsTpl']->assign('f3', strtr(_MA_PEDIGREE_MPED_F3, ['[animalType]' => $helper->getConfig('animalType')]));
$GLOBALS['xoopsTpl']->assign('f4', strtr(_MA_PEDIGREE_MPED_F4, ['[animalType]' => $helper->getConfig('animalType')]));
$GLOBALS['xoopsTpl']->assign('m2', strtr(_MA_PEDIGREE_MPED_M2, ['[animalType]' => $helper->getConfig('animalType')]));
$GLOBALS['xoopsTpl']->assign('m3', strtr(_MA_PEDIGREE_MPED_M3, ['[animalType]' => $helper->getConfig('animalType')]));
$GLOBALS['xoopsTpl']->assign('m4', strtr(_MA_PEDIGREE_MPED_M4, ['[animalType]' => $helper->getConfig('animalType')]));
/**
* @param string $gender m|f
* @param int $item
*
* @return string
* @todo move this to ./include directory
*/
function crcolour($gender, $item)
{
switch ($item) {
case '1':
default:
$col = 'transparent';
break;
case '2':
$col = ('f' === $gender) ? '#C8C8FF' : '#FFC8C8';
break;
case '3':
$col = ('f' === $gender) ? '#6464FF' : '#FF6464';
break;
case '4':
$col = ('f' === $gender) ? '#0000FF' : '#FF0000';
break;
}
/*
if ('1' == $item) {
$col = 'transparant';
} elseif ('2' == $item && 'f' === $sex) {
$col = '#C8C8FF';
} elseif (3 == $item && 'f' === $sex) {
$col = '#6464FF';
} elseif ('4' == $item && 'f' === $sex) {
$col = '#0000FF';
} elseif ('2' == $item && 'm' === $sex) {
$col = '#FFC8C8';
} elseif ('3' == $item && 'm' === $sex) {
$col = '#FF6464';
} elseif ('4' == $item && 'm' === $sex) {
$col = '#FF0000';
} else {
$col = 'transparant';
}
*/
return $col;
}
/**
* @param $freq
* @param $item
* @param int $inc
*
* @return bool
*/
function count_item(&$freq, $item, $inc = 1)
{
if (!is_array($freq)) {
$freq = [];
}
$freq[$item] = (isset($freq[$item]) ? ($freq[$item] += $inc) : $inc);
return true;
}