Passed
Push — master ( 48d769...5ccf6e )
by Michael
07:14
created

mpedigree.php (1 issue)

Labels
Severity
1
<?php
2
// -------------------------------------------------------------------------
3
4
use Xmf\Request;
5
use XoopsModules\Pedigree;
6
7
//require_once  dirname(dirname(__DIR__)) . '/mainfile.php';
8
require_once __DIR__ . '/header.php';
9
10
/** @var Pedigree\Helper $helper */
11
$helper = Pedigree\Helper::getInstance();
12
13
$moduleDirName = basename(__DIR__);
14
$helper->loadLanguage('main');
15
16
// Include any common code for this module.
17
require_once XOOPS_ROOT_PATH . '/modules/' . $moduleDirName . '/include/common.php';
18
19
$GLOBALS['xoopsOption']['template_main'] = 'pedigree_mpedigree.tpl';
20
21
include $GLOBALS['xoops']->path('/header.php');
22
23
//get module configuration
24
/** @var \XoopsModuleHandler $moduleHandler */
25
$moduleHandler = xoops_getHandler('module');
26
$module        = $moduleHandler->getByDirname($moduleDirName);
27
$configHandler = xoops_getHandler('config');
28
$moduleConfig  = $configHandler->getConfigsByCat(0, $module->getVar('mid'));
0 ignored issues
show
The method getConfigsByCat() does not exist on XoopsObjectHandler. It seems like you code against a sub-type of XoopsObjectHandler such as XoopsPersistableObjectHandler. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

28
$moduleConfig  = $configHandler->/** @scrutinizer ignore-call */ getConfigsByCat(0, $module->getVar('mid'));
Loading history...
29
30
//always start with Anika
31
$pedId = Request::getInt('pedid', 0, 'GET');
32
//$pedId = $_GET['pedid'];
33
//draw pedigree
34
35
$queryString = '
36
SELECT d.id as d_id,
37
d.naam as d_naam,
38
d.roft as d_roft,
39
f.id as f_id,
40
f.naam as f_naam,
41
m.id as m_id,
42
m.naam as m_naam,
43
ff.id as ff_id,
44
ff.naam as ff_naam,
45
mf.id as mf_id,
46
mf.naam as mf_naam,
47
fm.id as fm_id,
48
fm.naam as fm_naam,
49
mm.id as mm_id,
50
mm.naam as mm_naam,
51
fff.id as fff_id,
52
fff.naam as fff_naam,
53
ffm.id as ffm_id,
54
ffm.naam as ffm_naam,
55
fmf.id as fmf_id,
56
fmf.naam as fmf_naam,
57
fmm.id as fmm_id,
58
fmm.naam as fmm_naam,
59
mmf.id as mmf_id,
60
mmf.naam as mmf_naam,
61
mff.id as mff_id,
62
mff.naam as mff_naam,
63
mfm.id as mfm_id,
64
mfm.naam as mfm_naam,
65
mmm.id as mmm_id,
66
mmm.naam as mmm_naam,
67
ffff.id as ffff_id,
68
ffff.naam as ffff_naam,
69
ffmf.id as ffmf_id,
70
ffmf.naam as ffmf_naam,
71
fmff.id as fmff_id,
72
fmff.naam as fmff_naam,
73
fmmf.id as fmmf_id,
74
fmmf.naam as fmmf_naam,
75
mmff.id as mmff_id,
76
mmff.naam as mmff_naam,
77
mfff.id as mfff_id,
78
mfff.naam as mfff_naam,
79
mfmf.id as mfmf_id,
80
mfmf.naam as mfmf_naam,
81
mmmf.id as mmmf_id,
82
mmmf.naam as mmmf_naam,
83
fffm.id as fffm_id,
84
fffm.naam as fffm_naam,
85
ffmm.id as ffmm_id,
86
ffmm.naam as ffmm_naam,
87
fmfm.id as fmfm_id,
88
fmfm.naam as fmfm_naam,
89
fmmm.id as fmmm_id,
90
fmmm.naam as fmmm_naam,
91
mmfm.id as mmfm_id,
92
mmfm.naam as mmfm_naam,
93
mffm.id as mffm_id,
94
mffm.naam as mffm_naam,
95
mfmm.id as mfmm_id,
96
mfmm.naam as mfmm_naam,
97
mmmm.id as mmmm_id,
98
mmmm.naam as mmmm_naam
99
    FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' d
100
LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' f ON d.father = f.id
101
LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' m ON d.mother = m.id
102
LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' ff ON f.father = ff.id
103
LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' fff ON ff.father = fff.id
104
LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' ffm ON ff.mother = ffm.id
105
LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' mf ON m.father = mf.id
106
LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' mff ON mf.father = mff.id
107
LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' mfm ON mf.mother = mfm.id
108
LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' fm ON f.mother = fm.id
109
LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' fmf ON fm.father = fmf.id
110
LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' fmm ON fm.mother = fmm.id
111
LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' mm ON m.mother = mm.id
112
LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' mmf ON mm.father = mmf.id
113
LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' mmm ON mm.mother = mmm.id
114
LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' ffff ON fff.father = ffff.id
115
LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' ffmf ON ffm.father = ffmf.id
116
LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' fmff ON fmf.father = fmff.id
117
LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' fmmf ON fmm.father = fmmf.id
118
LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' mmff ON mmf.father = mmff.id
119
LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' mfff ON mff.father = mfff.id
120
LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' mfmf ON mfm.father = mfmf.id
121
LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' mmmf ON mmm.father = mmmf.id
122
LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' fffm ON fff.mother = fffm.id
123
LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' ffmm ON ffm.mother = ffmm.id
124
LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' fmfm ON fmf.mother = fmfm.id
125
LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' fmmm ON fmm.mother = fmmm.id
126
LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' mmfm ON mmf.mother = mmfm.id
127
LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' mffm ON mff.mother = mffm.id
128
LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' mfmm ON mfm.mother = mfmm.id
129
LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' mmmm ON mmm.mother = mmmm.id
130
WHERE d.id=' . $pedId;
131
132
$result = $GLOBALS['xoopsDB']->query($queryString);
133
134
while (false !== ($row = $GLOBALS['xoopsDB']->fetchArray($result))) {
135
    //crete array to count frequency (to select colour)
136
    count_item($freq, $row['d_id']);
137
    count_item($freq, $row['f_id']);
138
    count_item($freq, $row['m_id']);
139
    count_item($freq, $row['ff_id']);
140
    count_item($freq, $row['fm_id']);
141
    count_item($freq, $row['mf_id']);
142
    count_item($freq, $row['mm_id']);
143
    count_item($freq, $row['fff_id']);
144
    count_item($freq, $row['ffm_id']);
145
    count_item($freq, $row['fmf_id']);
146
    count_item($freq, $row['fmm_id']);
147
    count_item($freq, $row['mff_id']);
148
    count_item($freq, $row['mfm_id']);
149
    count_item($freq, $row['mmf_id']);
150
    count_item($freq, $row['mmm_id']);
151
    count_item($freq, $row['ffff_id']);
152
    count_item($freq, $row['ffmf_id']);
153
    count_item($freq, $row['fmff_id']);
154
    count_item($freq, $row['fmmf_id']);
155
    count_item($freq, $row['mfff_id']);
156
    count_item($freq, $row['mfmf_id']);
157
    count_item($freq, $row['mmff_id']);
158
    count_item($freq, $row['mmmf_id']);
159
    count_item($freq, $row['fffm_id']);
160
    count_item($freq, $row['ffmm_id']);
161
    count_item($freq, $row['fmfm_id']);
162
    count_item($freq, $row['fmmm_id']);
163
    count_item($freq, $row['mffm_id']);
164
    count_item($freq, $row['mfmm_id']);
165
    count_item($freq, $row['mmfm_id']);
166
    count_item($freq, $row['mmmm_id']);
167
168
    //create array for dog (and all parents)
169
    //selected dog
170
    $d['d']['name'] = stripslashes($row['d_naam']);
171
    $d['d']['id']   = $row['d_id'];
172
    $d['d']['roft'] = $row['d_roft'];
173
    $d['d']['col']  = 'transparant';
174
    //father
175
    $d['f']['name'] = stripslashes($row['f_naam']);
176
    $d['f']['id']   = $row['f_id'];
177
    $d['f']['col']  = crcolour('f', $freq[$row['f_id']]);
178
    //mother
179
    $d['m']['name'] = stripslashes($row['m_naam']);
180
    $d['m']['id']   = $row['m_id'];
181
    $d['m']['col']  = crcolour('m', $freq[$row['m_id']]);
182
    //grandparents
183
    //father father
184
    $d['ff']['name'] = stripslashes($row['ff_naam']);
185
    $d['ff']['id']   = $row['ff_id'];
186
    $d['ff']['col']  = crcolour('f', $freq[$row['ff_id']]);
187
    //father mother
188
    $d['fm']['name'] = stripslashes($row['fm_naam']);
189
    $d['fm']['id']   = $row['fm_id'];
190
    $d['fm']['col']  = crcolour('m', $freq[$row['fm_id']]);
191
    //mother father
192
    $d['mf']['name'] = stripslashes($row['mf_naam']);
193
    $d['mf']['id']   = $row['mf_id'];
194
    $d['mf']['col']  = crcolour('f', $freq[$row['mf_id']]);
195
    //mother mother
196
    $d['mm']['name'] = stripslashes($row['mm_naam']);
197
    $d['mm']['id']   = $row['mm_id'];
198
    $d['mm']['col']  = crcolour('m', $freq[$row['mm_id']]);
199
    //great-grandparents
200
    //father father father
201
    $d['fff']['name'] = stripslashes($row['fff_naam']);
202
    $d['fff']['id']   = $row['fff_id'];
203
    $d['fff']['col']  = crcolour('f', $freq[$row['fff_id']]);
204
    //father father mother
205
    $d['ffm']['name'] = stripslashes($row['ffm_naam']);
206
    $d['ffm']['id']   = $row['ffm_id'];
207
    $d['ffm']['col']  = crcolour('m', $freq[$row['ffm_id']]);
208
    //father mother father
209
    $d['fmf']['name'] = stripslashes($row['fmf_naam']);
210
    $d['fmf']['id']   = $row['fmf_id'];
211
    $d['fmf']['col']  = crcolour('f', $freq[$row['fmf_id']]);
212
    //father mother mother
213
    $d['fmm']['name'] = stripslashes($row['fmm_naam']);
214
    $d['fmm']['id']   = $row['fmm_id'];
215
    $d['fmm']['col']  = crcolour('m', $freq[$row['fmm_id']]);
216
    //mother father father
217
    $d['mff']['name'] = stripslashes($row['mff_naam']);
218
    $d['mff']['id']   = $row['mff_id'];
219
    $d['mff']['col']  = crcolour('f', $freq[$row['mff_id']]);
220
    //mother father mother
221
    $d['mfm']['name'] = stripslashes($row['mfm_naam']);
222
    $d['mfm']['id']   = $row['mfm_id'];
223
    $d['mfm']['col']  = crcolour('m', $freq[$row['mfm_id']]);
224
    //mother mother father
225
    $d['mmf']['name'] = stripslashes($row['mmf_naam']);
226
    $d['mmf']['id']   = $row['mmf_id'];
227
    $d['mmf']['col']  = crcolour('f', $freq[$row['mmf_id']]);
228
    //mother mother mother
229
    $d['mmm']['name'] = stripslashes($row['mmm_naam']);
230
    $d['mmm']['id']   = $row['mmm_id'];
231
    $d['mmm']['col']  = crcolour('m', $freq[$row['mmm_id']]);
232
    //great-great-grandparents (fathers)
233
    //father father father
234
    $d['ffff']['name'] = stripslashes($row['ffff_naam']);
235
    $d['ffff']['id']   = $row['ffff_id'];
236
    $d['ffff']['col']  = crcolour('f', $freq[$row['ffff_id']]);
237
    //father father mother
238
    $d['ffmf']['name'] = stripslashes($row['ffmf_naam']);
239
    $d['ffmf']['id']   = $row['ffmf_id'];
240
    $d['ffmf']['col']  = crcolour('f', $freq[$row['ffmf_id']]);
241
    //father mother father
242
    $d['fmff']['name'] = stripslashes($row['fmff_naam']);
243
    $d['fmff']['id']   = $row['fmff_id'];
244
    $d['fmff']['col']  = crcolour('f', $freq[$row['fmff_id']]);
245
    //father mother mother
246
    $d['fmmf']['name'] = stripslashes($row['fmmf_naam']);
247
    $d['fmmf']['id']   = $row['fmmf_id'];
248
    $d['fmmf']['col']  = crcolour('f', $freq[$row['fmmf_id']]);
249
    //mother father father
250
    $d['mfff']['name'] = stripslashes($row['mfff_naam']);
251
    $d['mfff']['id']   = $row['mfff_id'];
252
    $d['mfff']['col']  = crcolour('f', $freq[$row['mfff_id']]);
253
    //mother father mother
254
    $d['mfmf']['name'] = stripslashes($row['mfmf_naam']);
255
    $d['mfmf']['id']   = $row['mfmf_id'];
256
    $d['mfmf']['col']  = crcolour('f', $freq[$row['mfmf_id']]);
257
    //mother mother father
258
    $d['mmff']['name'] = stripslashes($row['mmff_naam']);
259
    $d['mmff']['id']   = $row['mmff_id'];
260
    $d['mmff']['col']  = crcolour('f', $freq[$row['mmff_id']]);
261
    //mother mother mother
262
    $d['mmmf']['name'] = stripslashes($row['mmmf_naam']);
263
    $d['mmmf']['id']   = $row['mmmf_id'];
264
    $d['mmmf']['col']  = crcolour('f', $freq[$row['mmmf_id']]);
265
    //great-great-grandparents (mothers)
266
    //father father father
267
    $d['fffm']['name'] = stripslashes($row['fffm_naam']);
268
    $d['fffm']['id']   = $row['fffm_id'];
269
    $d['fffm']['col']  = crcolour('m', $freq[$row['fffm_id']]);
270
    //father father mother
271
    $d['ffmm']['name'] = stripslashes($row['ffmm_naam']);
272
    $d['ffmm']['id']   = $row['ffmm_id'];
273
    $d['ffmm']['col']  = crcolour('m', $freq[$row['ffmm_id']]);
274
    //father mother father
275
    $d['fmfm']['name'] = stripslashes($row['fmfm_naam']);
276
    $d['fmfm']['id']   = $row['fmfm_id'];
277
    $d['fmfm']['col']  = crcolour('m', $freq[$row['fmfm_id']]);
278
    //father mother mother
279
    $d['fmmm']['name'] = stripslashes($row['fmmm_naam']);
280
    $d['fmmm']['id']   = $row['fmmm_id'];
281
    $d['fmmm']['col']  = crcolour('m', $freq[$row['fmmm_id']]);
282
    //mother father father
283
    $d['mffm']['name'] = stripslashes($row['mffm_naam']);
284
    $d['mffm']['id']   = $row['mffm_id'];
285
    $d['mffm']['col']  = crcolour('m', $freq[$row['mffm_id']]);
286
    //mother father mother
287
    $d['mfmm']['name'] = stripslashes($row['mfmm_naam']);
288
    $d['mfmm']['id']   = $row['mfmm_id'];
289
    $d['mfmm']['col']  = crcolour('m', $freq[$row['mfmm_id']]);
290
    //mother mother father
291
    $d['mmfm']['name'] = stripslashes($row['mmfm_naam']);
292
    $d['mmfm']['id']   = $row['mmfm_id'];
293
    $d['mmfm']['col']  = crcolour('m', $freq[$row['mmfm_id']]);
294
    //mother mother mother
295
    $d['mmmm']['name'] = stripslashes($row['mmmm_naam']);
296
    $d['mmmm']['id']   = $row['mmmm_id'];
297
    $d['mmmm']['col']  = crcolour('m', $freq[$row['mmmm_id']]);
298
}
299
300
//add data to smarty template
301
$GLOBALS['xoopsTpl']->assign('xoops_pagetitle', $d['d']['name'] . ' -- mega pedigree');
302
//assign dog(s)
303
$GLOBALS['xoopsTpl']->assign('d', $d);
304
$GLOBALS['xoopsTpl']->assign('male', '<img src="assets/images/male.gif">');
305
$GLOBALS['xoopsTpl']->assign('female', '<img src="assets/images/female.gif">');
306
//assign extra display options
307
$GLOBALS['xoopsTpl']->assign('unknown', 'Unknown');
308
$GLOBALS['xoopsTpl']->assign('f2', strtr(_MA_PEDIGREE_MPED_F2, ['[animalType]' => $helper->getConfig('animalType')]));
309
$GLOBALS['xoopsTpl']->assign('f3', strtr(_MA_PEDIGREE_MPED_F3, ['[animalType]' => $helper->getConfig('animalType')]));
310
$GLOBALS['xoopsTpl']->assign('f4', strtr(_MA_PEDIGREE_MPED_F4, ['[animalType]' => $helper->getConfig('animalType')]));
311
$GLOBALS['xoopsTpl']->assign('m2', strtr(_MA_PEDIGREE_MPED_M2, ['[animalType]' => $helper->getConfig('animalType')]));
312
$GLOBALS['xoopsTpl']->assign('m3', strtr(_MA_PEDIGREE_MPED_M3, ['[animalType]' => $helper->getConfig('animalType')]));
313
$GLOBALS['xoopsTpl']->assign('m4', strtr(_MA_PEDIGREE_MPED_M4, ['[animalType]' => $helper->getConfig('animalType')]));
314
315
/**
316
 * @param $sex
317
 * @param $item
318
 *
319
 * @return string
320
 * @todo move this to ./include directory
321
 */
322
function crcolour($sex, $item)
323
{
324
    if ('1' == $item) {
325
        $col = 'transparant';
326
    } elseif ('2' == $item && 'f' === $sex) {
327
        $col = '#C8C8FF';
328
    } elseif (3 == $item && 'f' === $sex) {
329
        $col = '#6464FF';
330
    } elseif ('4' == $item && 'f' === $sex) {
331
        $col = '#0000FF';
332
    } elseif ('2' == $item && 'm' === $sex) {
333
        $col = '#FFC8C8';
334
    } elseif ('3' == $item && 'm' === $sex) {
335
        $col = '#FF6464';
336
    } elseif ('4' == $item && 'm' === $sex) {
337
        $col = '#FF0000';
338
    } else {
339
        $col = 'transparant';
340
    }
341
342
    return $col;
343
}
344
345
/**
346
 * @param     $freq
347
 * @param     $item
348
 * @param int $inc
349
 *
350
 * @return bool
351
 */
352
function count_item(&$freq, $item, $inc = 1)
353
{
354
    if (!is_array($freq)) {
355
        $freq = [];
356
    }
357
    $freq[$item] = (isset($freq[$item]) ? ($freq[$item] += $inc) : $inc);
358
359
    return true;
360
}
361