Passed
Push — master ( b847d6...d6d54c )
by Michael
09:34 queued 05:00
created

pedigree.php (4 issues)

1
<?php
2
/*
3
 You may not change or alter any portion of this comment or credits
4
 of supporting developers from this source code or any supporting source code
5
 which is considered copyrighted (c) material of the original comment or credit authors.
6
7
 This program is distributed in the hope that it will be useful,
8
 but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10
*/
11
12
/**
13
 * animal module for xoops
14
 *
15
 * @copyright       {@link http://sourceforge.net/projects/thmod/ The TXMod XOOPS Project}
16
 * @copyright       {@link http://sourceforge.net/projects/xoops/ The XOOPS Project}
17
 * @license         GPL 2.0 or later
18
 * @package         pedigree
19
 * @author          XOOPS Mod Development Team
20
 */
21
22
use Xmf\Request;
23
use XoopsModules\Pedigree;
0 ignored issues
show
This use statement conflicts with another class in this namespace, Pedigree. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
24
25
26
$rootPath      = dirname(dirname(__DIR__));
27
$moduleDirName = basename(__DIR__);
28
$mydirpath     = dirname(__DIR__);
29
30
require_once  dirname(dirname(__DIR__)) . '/mainfile.php';
31
require_once __DIR__ . '/header.php';
32
//require_once $rootPath . '/include/cp_functions.php';
33
//require_once $rootPath . '/include/cp_header.php';
34
//require_once $rootPath . '/class/xoopsformloader.php';
35
36
//require_once dirname(dirname(__DIR__)) . '/mainfile.php';
37
//xoops_cp_header();
38
39
xoops_loadLanguage('main', $moduleDirName);
40
41
//require_once __DIR__ . '/header.php';
42
43
// Include any common code for this module.
44
require_once XOOPS_ROOT_PATH . '/modules/' . $moduleDirName . '/include/common.php';
45
//require_once(XOOPS_ROOT_PATH ."/modules/" . $xoopsModule->dirname() . "/include/css.php");
46
47
// Get all HTTP post or get parameters into global variables that are prefixed with "param_"
48
//import_request_variables("gp", "param_");
49
//extract($_GET, EXTR_PREFIX_ALL, "param");
50
//extract($_POST, EXTR_PREFIX_ALL, "param");
51
52
// This page uses smarty templates. Set "$xoopsOption['template_main']" before including header
53
$GLOBALS['xoopsOption']['template_main'] = 'pedigree_pedigree.tpl';
54
55
include $GLOBALS['xoops']->path('/header.php');
56
57
$GLOBALS['xoTheme']->addScript('browse.php?Frameworks/jquery/jquery.js');
58
$GLOBALS['xoTheme']->addScript("browse.php?modules/{$moduleDirName}/assets/js/jquery.magnific-popup.min.js");
59
$GLOBALS['xoTheme']->addStylesheet("browse.php?modules/{$moduleDirName}/assets/css/style.css");
60
$GLOBALS['xoTheme']->addStylesheet("browse.php?modules/{$moduleDirName}/assets/css/magnific-popup.css");
61
62
require_once $GLOBALS['xoops']->path('class/xoopsformloader.php');
63
64
//get module configuration
65
/** @var XoopsModuleHandler $moduleHandler */
66
$moduleHandler = xoops_getHandler('module');
67
$module        = $moduleHandler->getByDirname($moduleDirName);
68
$configHandler = xoops_getHandler('config');
69
$moduleConfig  = $configHandler->getConfigsByCat(0, $module->getVar('mid'));
70
71
//draw pedigree
72
//$id = Request::getInt('pedid',0,'GET');
73
pedigree_main();
74
75
//include XOOPS_ROOT_PATH . "/footer.php";
76
include __DIR__ . '/footer.php';
77
78
//
79
// Displays the "Main" tab of the module
80
//
81
/**
82
 */
83
function pedigree_main()
84
{
85
    $moduleDirName = basename(__DIR__);
0 ignored issues
show
The assignment to $moduleDirName is dead and can be removed.
Loading history...
86
    $id     = Request::getInt('pedid', 1, 'GET');
87
    $animal = new Pedigree\Animal($id);
88
    //test to find out how many user fields there are.
89
    $fields      = $animal->getNumOfFields();
90
    $fieldsCount = count($fields);
0 ignored issues
show
The assignment to $fieldsCount is dead and can be removed.
Loading history...
91
92
    $qarray = ['d', 'f', 'm', 'ff', 'mf', 'fm', 'mm', 'fff', 'ffm', 'fmf', 'fmm', 'mmf', 'mff', 'mfm', 'mmm'];
93
94
    $querystring = 'SELECT ';
95
96
    foreach ($qarray as $key) {
97
        $querystring .= $key . '.id as ' . $key . '_id, ';
98
        $querystring .= $key . '.naam as ' . $key . '_naam, ';
99
        $querystring .= $key . '.mother as ' . $key . '_mother, ';
100
        $querystring .= $key . '.father as ' . $key . '_father, ';
101
        $querystring .= $key . '.roft as ' . $key . '_roft, ';
102
        $querystring .= $key . '.foto as ' . $key . '_foto, ';
103
    }
104
105
    $querystring .= 'mmm.coi as mmm_coi FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' d
106
                 LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' f ON d.father = f.id
107
                 LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' m ON d.mother = m.id
108
                 LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' ff ON f.father = ff.id
109
                 LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' fff ON ff.father = fff.id
110
                 LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' ffm ON ff.mother = ffm.id
111
                 LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' mf ON m.father = mf.id
112
                 LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' mff ON mf.father = mff.id
113
                 LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' mfm ON mf.mother = mfm.id
114
                 LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' fm ON f.mother = fm.id
115
                 LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' fmf ON fm.father = fmf.id
116
                 LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' fmm ON fm.mother = fmm.id
117
                 LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' mm ON m.mother = mm.id
118
                 LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' mmf ON mm.father = mmf.id
119
                 LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . " mmm ON mm.mother = mmm.id
120
                 WHERE d.id={$id}";
121
122
    $result = $GLOBALS['xoopsDB']->query($querystring);
123
    global $moduleConfig;
124
125
    while (false !== ($row = $GLOBALS['xoopsDB']->fetchArray($result))) {
126
        //create array for animal (and all parents)
127
        foreach ($qarray as $key) {
128
            $d[$key] = [
129
                'id'     => $row[$key . '_id'],
130
                'name'   => stripslashes($row[$key . '_naam']),
131
                'mother' => $row[$key . '_mother'],
132
                'father' => $row[$key . '_father'],
133
                'roft'   => $row[$key . '_roft'],
134
                'nhsb'   => ''
135
            ];
136
            if ((3 != strlen($key) || (0 != $moduleConfig['lastimage'])) && ('' !== $row[$key . '_foto'])) {
137
                //show image in last row of pedigree if image exists
138
                $d[$key]['photo']    = PEDIGREE_UPLOAD_URL . '/images/thumbnails/' . $row[$key . '_foto'] . '_150.jpeg';
139
                $d[$key]['photoBig'] = PEDIGREE_UPLOAD_URL . '/images/' . $row[$key . '_foto'] . '.jpeg';
140
            }
141
142
            $d[$key]['overig'] = '';
143
            // $pedidata to hold viewable data to be shown in pedigree
144
            $pedidata = '';
145
146
            if ('' == !$d[$key]['id']) {
147
                //if exists create animal object
148
                $animal = new Pedigree\Animal($d[$key]['id']);
149
                $fields = $animal->getNumOfFields();
150
            }
151
            foreach ($fields as $i => $iValue) {
152
                $userField = new Pedigree\Field($fields[$i], $animal->getConfig());
153
                if ($userField->isActive() && $userField->inPedigree()) {
154
                    $fieldType = $userField->getSetting('FieldType');
155
                    $fieldObj  = new $fieldType($userField, $animal);
156
                    $pedidata  .= $fieldObj->showField() . '<br>';
157
                }
158
                $d[$key]['hd'] = $pedidata;
159
            }
160
        }
161
    }
162
163
    //add data to smarty template
164
    $GLOBALS['xoopsTpl']->assign([
165
                                     'page_title' => stripslashes($row['d_naam']),
166
                                     'd'          => $d,  //assign dog
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $d does not seem to be defined for all execution paths leading up to this point.
Loading history...
167
                                     //assign config options
168
                                     'male'       => "<img src='assets/images/male.gif'>",
169
                                     'female'     => "<img src='assets/images/female.gif'>",
170
                                     //assign extra display options
171
                                     'unknown'    => 'Unknown',
172
                                     'SD'         => _MA_PEDIGREE_SD,
173
                                     'PA'         => _MA_PEDIGREE_PA,
174
                                     'GP'         => _MA_PEDIGREE_GP,
175
                                     'GGP'        => _MA_PEDIGREE_GGP
176
                                 ]);
177
178
    //    include __DIR__ . '/footer.php';
179
}
180