Completed
Push — master ( 871d94...af939e )
by Michael
03:14
created

add_dog.php ➔ sire()   F

Complexity

Conditions 38
Paths > 20000

Size

Total Lines 236
Code Lines 155

Duplication

Lines 66
Ratio 27.97 %

Importance

Changes 0
Metric Value
cc 38
eloc 155
nc 1520640
nop 0
dl 66
loc 236
rs 2
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 42 and the first side effect is on line 4.

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.

Loading history...
2
// -------------------------------------------------------------------------
3
4
require_once dirname(dirname(__DIR__)) . '/mainfile.php';
5
$moduleDirName = basename(__DIR__);
6
xoops_loadLanguage('main', $moduleDirName);
7
// Include any common code for this module.
8
require_once(XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->dirname() . '/include/common.php');
9
require_once(XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->dirname() . '/include/class_field.php');
10
11
$xoopsOption['template_main'] = 'pedigree_adddog.tpl';
12
13
include XOOPS_ROOT_PATH . '/header.php';
14
$xoopsTpl->assign('page_title', 'Pedigree database - Update details');
15
16
//check for access
17
$xoopsModule = XoopsModule::getByDirname('pedigree');
18
if (empty($xoopsUser)) {
19
    redirect_header('index.php', 3, _NOPERM . '<br />' . _MA_PEDIGREE_REGIST);
20
}
21
22
//create function variable from url
23
if (isset($_GET['f'])) {
24
    $f = $_GET['f'];
25
} else {
26
    $f = '';
27
    addDog();
28
}
29
if ($f === 'checkName') {
30
    checkName();
31
}
32
if ($f === 'sire') {
33
    sire();
34
}
35
if ($f === 'dam') {
36
    dam();
37
}
38
if ($f === 'check') {
39
    check();
40
}
41
42
function addDog()
43
{
44
    global $xoopsTpl, $xoopsUser, $xoopsDB;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
45
46
    //get module configuration
47
    $moduleHandler = xoops_getHandler('module');
48
    $module        = $moduleHandler->getByDirname('pedigree');
49
    $configHandler = xoops_getHandler('config');
50
    $moduleConfig  = $configHandler->getConfigsByCat(0, $module->getVar('mid'));
51
52
    //check for access
53
    if (empty($xoopsUser)) {
54
        redirect_header('javascript:history.go(-1)', 3, _NOPERM . '<br />' . _MA_PEDIGREE_REGIST);
55
    }
56
    if ($xoopsUser->getVar('uid') == 0) {
57
        redirect_header('javascript:history.go(-1)', 3, _NOPERM . '<br />' . _MA_PEDIGREE_REGIST);
58
    }
59
    //create form
60
    include XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
61
    $form = new XoopsThemeForm(strtr(_MA_PEDIGREE_ADD_DOG, array('[animalType]' => $moduleConfig['animalType'])), 'dogname', 'add_dog.php?f=checkName', 'POST');
62
    $form->addElement(new XoopsFormHiddenToken($name = 'XOOPS_TOKEN_REQUEST', $timeout = 360));
63
    //create random value
64
    $random = (mt_rand() % 10000);
65
    $form->addElement(new XoopsFormHidden('random', $random));
66
    //find userid
67
    $form->addElement(new XoopsFormHidden('user', $xoopsUser->getVar('uid')));
68
69
    //name
70
    $form->addElement(new XoopsFormText('<b>' . _MA_PEDIGREE_FLD_NAME . '</b>', 'NAAM', $size = 50, $maxsize = 255, $value = ''));
71
    $string = strtr(_MA_PEDIGREE_FLD_NAME_EX, array('[animalType]' => $moduleConfig['animalType']));
72
    $form->addElement(new XoopsFormLabel(_MA_PEDIGREE_EXPLAIN, $string));
73
74
    //submit button
75
    $form->addElement(new XoopsFormButton('', 'button_id', strtr(_MA_PEDIGREE_ADD_DATA, array('[animalType]' => $moduleConfig['animalType'])), 'submit'));
76
77
    //add data (form) to smarty template
78
    $xoopsTpl->assign('form', $form->render());
79
}
80
81
function checkName()
0 ignored issues
show
Coding Style introduced by
checkName uses the super-global variable $GLOBALS which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
Coding Style introduced by
checkName uses the super-global variable $_GET which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
Coding Style introduced by
checkName uses the super-global variable $_POST which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
82
{
83
    //configure global variables
84
    global $xoopsTpl, $xoopsDB, $xoopsUser;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
85
86
    //get module configuration
87
    $moduleHandler = xoops_getHandler('module');
88
    $module        = $moduleHandler->getByDirname('pedigree');
89
    $configHandler = xoops_getHandler('config');
90
    $moduleConfig  = $configHandler->getConfigsByCat(0, $module->getVar('mid'));
91
92
    //$name = $_POST['NAAM'];
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
93
    $name = XoopsRequest::getString('NAAM', '', 'post');
94
    //query
95
    //$queryString = 'SELECT * from ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . " WHERE NAAM LIKE'%" . $name . "%' ORDER BY NAAM";
0 ignored issues
show
Unused Code Comprehensibility introduced by
47% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
96
    $queryString = 'SELECT * from ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . " WHERE NAAM LIKE'%" . $GLOBALS['xoopsDB']->escape($name) . "%' ORDER BY NAAM";
97
    $result      = $GLOBALS['xoopsDB']->query($queryString);
98
    $numresults  = $GLOBALS['xoopsDB']->getRowsNum($result);
99
    if ($numresults >= 1 && !isset($_GET['r'])) {
100
        //create form
101
        include XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
102
        $form = new XoopsThemeForm(strtr(_MA_PEDIGREE_ADD_DOG, array('[animalType]' => $moduleConfig['animalType'])), 'dogname', 'add_dog.php?f=checkName&r=1', 'POST');
103
        //other elements
104
        $form->addElement(new XoopsFormHiddenToken($name = 'XOOPS_TOKEN_REQUEST', $timeout = 360));
105
        $form->addElement(new XoopsFormHidden('NAAM', $_POST['NAAM']));
106
        $form->addElement(new XoopsFormHidden('user', $xoopsUser->getVar('uid')));
107
        while ($row = $GLOBALS['xoopsDB']->fetchBoth($result)) {
108
            //name
109
            $form->addElement(new XoopsFormLabel('<b>' . _MA_PEDIGREE_FLD_NAME . '</b>', "<a href=\"dog.php?id=" . $row['Id'] . "\">" . stripslashes($row['NAAM']) . '</a>'));
110
        }
111
        $form->addElement(new XoopsFormLabel(_MA_PEDIGREE_EXPLAIN, strtr(_MA_PEDIGREE_ADD_KNOWN, array('[animalTypes]' => $moduleConfig['animalTypes']))));
112
        //submit button
113
        $form->addElement(new XoopsFormButton('', 'button_id', strtr(_MA_PEDIGREE_ADD_KNOWNOK, array('[animalType]' => $moduleConfig['animalType'])), 'submit'));
114
        //add data (form) to smarty template
115
        $xoopsTpl->assign('form', $form->render());
116
    } else {
117
        //create form
118
        include XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
119
        $form = new XoopsThemeForm(strtr(_MA_PEDIGREE_ADD_DOG, array('[animalType]' => $moduleConfig['animalType'])), 'dogname', 'add_dog.php?f=sire', 'POST');
120
        //added to handle upload
121
        $form->setExtra("enctype='multipart/form-data'");
122
        $form->addElement(new XoopsFormHiddenToken($name = 'XOOPS_TOKEN_REQUEST', $timeout = 360));
123
        //create random value
124
        $random = (mt_rand() % 10000);
125
        $form->addElement(new XoopsFormHidden('random', $random));
126
        $form->addElement(new XoopsFormHidden('NAAM', htmlspecialchars($_POST['NAAM'], ENT_QUOTES)));
127
        //find userid from previous form
128
        $form->addElement(new XoopsFormHidden('user', $_POST['user']));
129
130
        //name
131
        $form->addElement(new XoopsFormLabel('<b>' . _MA_PEDIGREE_FLD_NAME . '</b>', stripslashes($_POST['NAAM'])));
132
        //gender
133
        $gender_radio = new XoopsFormRadio('<b>' . _MA_PEDIGREE_FLD_GEND . '</b>', 'roft', $value = '0');
134
        $gender_radio->addOptionArray(array('0' => strtr(_MA_PEDIGREE_FLD_MALE, array('[male]' => $moduleConfig['male'])), '1' => strtr(_MA_PEDIGREE_FLD_FEMA, array('[female]' => $moduleConfig['female']))));
135
        $form->addElement($gender_radio);
136
        if ($moduleConfig['ownerbreeder'] == '1') {
137
            //breeder
138
            $breeder_select = new XoopsFormSelect('<b>' . _MA_PEDIGREE_FLD_BREE . '</b>', $name = 'id_breeder', $value = '0', $size = 1, $multiple = false);
139
            $queryfok       = 'SELECT ID, lastname, firstname from ' . $GLOBALS['xoopsDB']->prefix('pedigree_owner') . ' ORDER BY lastname';
140
            $resfok         = $GLOBALS['xoopsDB']->query($queryfok);
141
            $breeder_select->addOption('0', $name = _MA_PEDIGREE_UNKNOWN);
142
            while (false !== ($rowfok = $GLOBALS['xoopsDB']->fetchArray($resfok))) {
143
                $breeder_select->addOption($rowfok['Id'], $name = $rowfok['lastname'] . ', ' . $rowfok['firstname']);
144
            }
145
            $form->addElement($breeder_select);
146
            $form->addElement(new XoopsFormLabel(_MA_PEDIGREE_EXPLAIN, strtr(_MA_PEDIGREE_FLD_BREE_EX, array('[animalType]' => $moduleConfig['animalType']))));
147
148
            //owner
149
            $owner_select = new XoopsFormSelect('<b>' . _MA_PEDIGREE_FLD_OWNE . '</b>', $name = 'id_owner', $value = '0', $size = 1, $multiple = false);
150
            $queryfok     = 'SELECT ID, lastname, firstname from ' . $GLOBALS['xoopsDB']->prefix('pedigree_owner') . ' ORDER BY lastname';
151
            $resfok       = $GLOBALS['xoopsDB']->query($queryfok);
152
            $owner_select->addOption('0', $name = _MA_PEDIGREE_UNKNOWN);
153
            while (false !== ($rowfok = $GLOBALS['xoopsDB']->fetchArray($resfok))) {
154
                $owner_select->addOption($rowfok['Id'], $name = $rowfok['lastname'] . ', ' . $rowfok['firstname']);
155
            }
156
            $form->addElement($owner_select);
157
            $form->addElement(new XoopsFormLabel(_MA_PEDIGREE_EXPLAIN, strtr(_MA_PEDIGREE_FLD_OWNE_EX, array('[animalType]' => $moduleConfig['animalType']))));
158
        }
159
        //picture
160
        $max_imgsize = 1024000;
161
        $img_box     = new XoopsFormFile('Image', 'photo', $max_imgsize);
162
        $img_box->setExtra("size ='50'");
163
        $form->addElement($img_box);
164
165
        //create animal object
166
        $animal = new PedigreeAnimal();
167
        //test to find out how many user fields there are..
168
        $fields = $animal->getNumOfFields();
169
170
        for ($i = 0, $iMax = count($fields); $i < $iMax; ++$i) {
171
            $userField   = new Field($fields[$i], $animal->getConfig());
172
            $fieldType   = $userField->getSetting('FieldType');
173
            $fieldObject = new $fieldType($userField, $animal);
174
            if ($userField->isActive() && !$userField->isLocked()) {
175
                $newEntry = $fieldObject->newField();
176
                $form->addElement($newEntry);
177
            }
178
            unset($newEntry);
179
        }
180
181
        //submit button
182
        $form->addElement(new XoopsFormButton('', 'button_id', strtr(_MA_PEDIGREE_ADD_SIRE, array('[father]' => $moduleConfig['father'])), 'submit'));
183
184
        //add data (form) to smarty template
185
        $xoopsTpl->assign('form', $form->render());
186
    }
187
}
188
189
function sire()
0 ignored issues
show
Coding Style introduced by
sire uses the super-global variable $_POST which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
Coding Style introduced by
sire uses the super-global variable $_GET which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
Coding Style introduced by
sire uses the super-global variable $_FILES which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
Coding Style introduced by
sire uses the super-global variable $GLOBALS which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
190
{
191
    global $xoopsTpl, $xoopsUser, $xoopsDB;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
192
193
    //get module configuration
194
    $moduleHandler = xoops_getHandler('module');
195
    $module        = $moduleHandler->getByDirname('pedigree');
196
    $configHandler = xoops_getHandler('config');
197
    $moduleConfig  = $configHandler->getConfigsByCat(0, $module->getVar('mid'));
198
    $empty         = array(); // an empty array
199
200
    //check for access
201
    if (empty($xoopsUser)) {
202
        redirect_header('javascript:history.go(-1)', 3, _NOPERM . '<br />' . _MA_PEDIGREE_REGIST);
203
    }
204
    $user = isset($_POST['user']) ? $_POST['user'] : null;
205
    if (empty($random)) {
0 ignored issues
show
Bug introduced by
The variable $random seems only to be defined at a later point. As such the call to empty() seems to always evaluate to true.

This check marks calls to isset(...) or empty(...) that are found before the variable itself is defined. These will always have the same result.

This is likely the result of code being shifted around. Consider removing these calls.

Loading history...
206
        $random = isset($_POST['random']) ? $_POST['random'] : null;
207
    }
208
    if (isset($_GET['random'])) {
209
        $random = $_GET['random'];
210
    }
211
    if (empty($st)) {
0 ignored issues
show
Bug introduced by
The variable $st seems only to be defined at a later point. As such the call to empty() seems to always evaluate to true.

This check marks calls to isset(...) or empty(...) that are found before the variable itself is defined. These will always have the same result.

This is likely the result of code being shifted around. Consider removing these calls.

Loading history...
212
        $st = 0;
213
    }
214
    if (isset($_GET['st'])) {
215
        $st = $_GET['st'];
216
    }
217
    $name = isset($_POST['NAAM']) ? $_POST['NAAM'] : null;
218
    $roft = isset($_POST['roft']) ? $_POST['roft'] : null;
219
220
    $id_owner   = isset($_POST['id_owner']) ? $_POST['id_owner'] : null;
221
    $id_breeder = isset($_POST['id_breeder']) ? $_POST['id_breeder'] : null;
222
223
    $picturefield = isset($_FILES['photo']) ? $_FILES['photo']['name'] : null; // $_FILES['photo']['name'];
0 ignored issues
show
Unused Code Comprehensibility introduced by
89% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
224
    if (empty($picturefield) || $picturefield == '') {
225
        $foto = '';
226
    } else {
227
        $foto = PedigreeUtilities::uploadPicture(0);
228
    }
229
    $numpicturefield = 1;
230
231
    //make the redirect
232
    if (!isset($_GET['r'])) {
233
        if ($_POST['NAAM'] == '') {
234
            redirect_header('add_dog.php', 1, _MA_PEDIGREE_ADD_NAMEPLZ);
235
        }
236
        //create animal object
237
        $animal = new PedigreeAnimal();
238
        //test to find out how many user fields there are..
239
        $fields = $animal->getNumOfFields();
240
        sort($fields); //sort by ID not by order
241
        $usersql = '';
242
        for ($i = 0, $iMax = count($fields); $i < $iMax; ++$i) {
243
            $userField   = new Field($fields[$i], $animal->getConfig());
244
            $fieldType   = $userField->getSetting('FieldType');
245
            $fieldObject = new $fieldType($userField, $animal);
0 ignored issues
show
Unused Code introduced by
$fieldObject is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
246
            if ($userField->isActive()) {
247
                //check if _FILES variable exists for user picturefield
248
                $currentfield = 'user' . $fields[$i];
249
                $picturefield = $_FILES[$currentfield]['name'];
250
                if ($fieldType === 'Picture' && (!empty($picturefield) || $picturefield != '')) {
251
                    $userpicture = PedigreeUtilities::uploadPicture($numpicturefield);
252
                    $usersql .= ",'" . $userpicture . "'";
253
                    ++$numpicturefield;
254
                } elseif ($userField->isLocked()) {
255
                    //userfield is locked, substitute default value
256
                    $usersql .= ",'" . $userField->defaultvalue . "'";
0 ignored issues
show
Bug introduced by
The property defaultvalue does not seem to exist in Field.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
257
                } else {
258
                    //echo $fieldType.":".$i.":".$fields[$i]."<br />";
0 ignored issues
show
Unused Code Comprehensibility introduced by
65% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
259
                    $usersql .= ",'" . PedigreeUtilities::unHtmlEntities($_POST['user' . $fields[$i]]) . "'";
260
                }
261
            } else {
262
                $usersql .= ",''";
263
            }
264
            //echo $fields[$i]."<br/>";
0 ignored issues
show
Unused Code Comprehensibility introduced by
78% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
265
        }
266
267
        //insert into pedigree_temp
268
        //        $query = 'INSERT INTO ' . $GLOBALS['xoopsDB']->prefix('pedigree_temp') . " VALUES ('" . $random . "','" . PedigreeUtilities::unHtmlEntities($name) . "','" . $id_owner . "','" . $id_breeder . "','" . $user . "','" . $roft . "','','','" . $foto . "', ''" . $usersql . ')';
269
        $query = 'INSERT INTO ' . $GLOBALS['xoopsDB']->prefix('pedigree_temp') . " VALUES ('" . $GLOBALS['xoopsDB']->escape($random) . "','" . $GLOBALS['xoopsDB']->escape(unHtmlEntities($name)) . "','" . $GLOBALS['xoopsDB']->escape($id_owner) . "','" . $GLOBALS['xoopsDB']->escape($id_breeder) . "','" . $GLOBALS['xoopsDB']->escape($user) . "','" . $GLOBALS['xoopsDB']->escape($roft) . "','','','" . $GLOBALS['xoopsDB']->escape($foto) . "', ''" . $usersql . ')';
270
        //echo $query; die();
0 ignored issues
show
Unused Code Comprehensibility introduced by
78% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
271
        $GLOBALS['xoopsDB']->query($query);
272
        redirect_header('add_dog.php?f=sire&random=' . $random . '&st=' . $st . '&r=1&l=a', 1, strtr(_MA_PEDIGREE_ADD_SIREPLZ, array('[father]' => $moduleConfig['father'])));
273
    }
274
    //find letter on which to start else set to 'a'
275
    if (isset($_GET['l'])) {
276
        $l = $_GET['l'];
277
    } else {
278
        $l = 'a';
279
    }
280
    //assign sire to template
281
    $xoopsTpl->assign('sire', '1');
282
    //create list of males dog to select from
283
    $perp = $moduleConfig['perpage'];
284
    //count total number of dogs
285
    $numdog = 'SELECT count(ID) from ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . " WHERE roft='0' and NAAM LIKE '" . $l . "%'";
286
    $numres = $GLOBALS['xoopsDB']->query($numdog);
287
    //total number of dogs the query will find
288
    list($numresults) = $GLOBALS['xoopsDB']->fetchRow($numres);
289
    //total number of pages
290
    $numpages = floor($numresults / $perp) + 1;
291
    if (($numpages * $perp) == ($numresults + $perp)) {
292
        --$numpages ;
293
    }
294
    //find current page
295
    $cpage = floor($st / $perp) + 1;
296
    //create alphabet
297
    $pages = '';
298 View Code Duplication
    for ($i = 65; $i <= 90; ++$i) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
299
        if ($l == chr($i)) {
300
            $pages .= "<b><a href=\"add_dog.php?f=sire&r=1&random=" . $random . '&l=' . chr($i) . "\">" . chr($i) . '</a></b>&nbsp;';
301
        } else {
302
            $pages .= "<a href=\"add_dog.php?f=sire&r=1&random=" . $random . '&l=' . chr($i) . "\">" . chr($i) . '</a>&nbsp;';
303
        }
304
    }
305
    $pages .= '-&nbsp;';
306
    $pages .= "<a href=\"add_dog.php?f=sire&r=1&random=" . $random . "&l=Ã…\">Ã…</a>&nbsp;";
307
    $pages .= "<a href=\"add_dog.php?f=sire&r=1&random=" . $random . "&l=Ö\">Ö</a>&nbsp;";
308
    //create linebreak
309
    $pages .= '<br />';
310
    //create previous button
311
    if ($numpages > 1) {
312
        if ($cpage > 1) {
313
            $pages .= "<a href=\"add_dog.php?f=sire&r=1&l=" . $l . '&random=' . $random . '&st=' . ($st - $perp) . "\">" . _MA_PEDIGREE_PREVIOUS . '</a>&nbsp;&nbsp';
314
        }
315
    }
316
    //create numbers
317
    for ($x = 1; $x < ($numpages + 1); ++$x) {
318
        //create line break after 20 number
319
        if (($x % 20) == 0) {
320
            $pages .= '<br />';
321
        }
322
        if ($x != $cpage) {
323
            $pages .= "<a href=\"add_dog.php?f=sire&r=1&l=" . $l . '&random=' . $random . '&st=' . ($perp * ($x - 1)) . "\">" . $x . '</a>&nbsp;&nbsp;';
324
        } else {
325
            $pages .= $x . '&nbsp;&nbsp';
326
        }
327
    }
328
    //create next button
329
    if ($numpages > 1) {
330
        if ($cpage < $numpages) {
331
            $pages .= "<a href=\"add_dog.php?f=sire&r=1&l=" . $l . '&random=' . $random . '&st=' . ($st + $perp) . "\">" . _MA_PEDIGREE_NEXT . '</a>&nbsp;&nbsp';
332
        }
333
    }
334
335
    //query
336
    $queryString = 'SELECT * from ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . " WHERE roft = '0' and NAAM like '" . $l . "%'ORDER BY NAAM LIMIT " . $st . ', ' . $perp;
337
    $result      = $GLOBALS['xoopsDB']->query($queryString);
338
339
    $animal = new PedigreeAnimal();
340
    //test to find out how many user fields there are...
341
    $fields       = $animal->getNumOfFields();
342
    $numofcolumns = 1;
343
    $columns[]    = array('columnname' => 'Name');
0 ignored issues
show
Coding Style Comprehensibility introduced by
$columns was never initialized. Although not strictly required by PHP, it is generally a good practice to add $columns = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
344 View Code Duplication
    for ($i = 0, $iMax = count($fields); $i < $iMax; ++$i) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
345
        $userField   = new Field($fields[$i], $animal->getConfig());
346
        $fieldType   = $userField->getSetting('FieldType');
347
        $fieldObject = new $fieldType($userField, $animal);
348
        //create empty string
349
        $lookupvalues = '';
350
        if ($userField->isActive() && $userField->inList()) {
351
            if ($userField->hasLookup()) {
352
                $lookupvalues = $userField->lookupField($fields[$i]);
353
                //debug information
354
                //print_r($lookupvalues);
355
            }
356
            $columns[] = array('columnname' => $fieldObject->fieldname, 'columnnumber' => $userField->getId(), 'lookupval' => $lookupvalues);
357
            ++$numofcolumns;
358
            unset($lookupvalues);
359
        }
360
    }
361
362 View Code Duplication
    for ($i = 1; $i < $numofcolumns; ++$i) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
363
        $empty[] = array('value' => '');
364
    }
365
    $dogs [] = array(
0 ignored issues
show
Coding Style Comprehensibility introduced by
$dogs was never initialized. Although not strictly required by PHP, it is generally a good practice to add $dogs = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
366
        'id'          => '0',
367
        'name'        => '',
368
        'gender'      => '',
369
        'link'        => "<a href=\"add_dog.php?f=dam&random=" . $random . "&selsire=0\">" . strtr(_MA_PEDIGREE_ADD_SIREUNKNOWN, array('[father]' => $moduleConfig['father'])) . '</a>',
370
        'colour'      => '',
371
        'number'      => '',
372
        'usercolumns' => $empty
373
    );
374
375 View Code Duplication
    while (false !== ($row = $GLOBALS['xoopsDB']->fetchArray($result))) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
376
        //create picture information
377
        if ($row['foto'] != '') {
378
            $camera = " <img src=\"assets/images/camera.png\">";
379
        } else {
380
            $camera = '';
381
        }
382
        $name = stripslashes($row['NAAM']) . $camera;
383
        //empty array
384
        unset($columnvalue);
385
        //fill array
386
        for ($i = 1; $i < $numofcolumns; ++$i) {
387
            $x = $columns[$i]['columnnumber'];
388
            if (is_array($columns[$i]['lookupval'])) {
389
                foreach ($columns[$i]['lookupval'] as $key => $keyvalue) {
390
                    if ($key == $row['user' . $x]) {
391
                        $value = $keyvalue['value'];
392
                    }
393
                }
394
                //debug information
395
                ///echo $columns[$i]['columnname']."is an array !";
0 ignored issues
show
Unused Code Comprehensibility introduced by
77% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
396
            } //format value - cant use object because of query count
397
            elseif (0 === strpos($row['user' . $x], 'http://')) {
398
                $value = "<a href=\"" . $row['user' . $x] . "\">" . $row['user' . $x] . '</a>';
399
            } else {
400
                $value = $row['user' . $x];
401
            }
402
            $columnvalue[] = array('value' => $value);
0 ignored issues
show
Coding Style Comprehensibility introduced by
$columnvalue was never initialized. Although not strictly required by PHP, it is generally a good practice to add $columnvalue = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
Bug introduced by
The variable $value does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
403
        }
404
        $dogs[] = array(
405
            'id'          => $row['Id'],
406
            'name'        => $name,
407
            'gender'      => '<img src="assets/images/male.gif">',
408
            'link'        => "<a href=\"add_dog.php?f=dam&random=" . $random . '&selsire=' . $row['Id'] . "\">" . $name . '</a>',
409
            'colour'      => '',
410
            'number'      => '',
411
            'usercolumns' => $columnvalue
0 ignored issues
show
Bug introduced by
The variable $columnvalue does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
412
        );
413
    }
414
415
    //add data to smarty template
416
    //assign dog
417
    $xoopsTpl->assign('dogs', $dogs);
418
    $xoopsTpl->assign('columns', $columns);
419
    $xoopsTpl->assign('numofcolumns', $numofcolumns);
420
    $xoopsTpl->assign('tsarray', PedigreeUtilities::sortTable($numofcolumns));
421
    //assign links
422
    $xoopsTpl->assign('nummatch', strtr(_MA_PEDIGREE_ADD_SELSIRE, array('[father]' => $moduleConfig['father'])));
423
    $xoopsTpl->assign('pages', $pages);
424
}
425
426
function dam()
0 ignored issues
show
Coding Style introduced by
dam uses the super-global variable $_GET which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
Coding Style introduced by
dam uses the super-global variable $GLOBALS which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
427
{
428
    global $xoopsTpl, $xoopsUser, $xoopsDB;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
429
430
    //get module configuration
431
    $moduleHandler = xoops_getHandler('module');
432
    $module        = $moduleHandler->getByDirname('pedigree');
433
    $configHandler = xoops_getHandler('config');
434
    $moduleConfig  = $configHandler->getConfigsByCat(0, $module->getVar('mid'));
435
    $empty         = array(); // an empty array
436
437
    //check for access
438
    $xoopsModule = XoopsModule::getByDirname('pedigree');
0 ignored issues
show
Unused Code introduced by
$xoopsModule is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
439
    if (empty($xoopsUser)) {
440
        redirect_header('javascript:history.go(-1)', 3, _NOPERM . '<br />' . _MA_PEDIGREE_REGIST);
441
    }
442
    //    if (empty($random)) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
73% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
443
    //$random = isset($_POST['random']) ? $_POST['random'] : null;
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
444
    //}
445
    //if (isset($_GET['random'])) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
85% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
446
    //$random = $_GET['random'];
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
447
    //}
448
    //if (empty($st)) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
80% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
449
    //$st = 0;
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
450
    //}
451
    //if (isset($_GET['st'])) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
85% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
452
    //$st = $_GET['st'];
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
453
    //}
454
    $random = XoopsRequest::getInt('random', 0);
455
    $st     = XoopsRequest::getInt('st', 0, 'get');
456
    //find letter on which to start else set to 'a'
457
    //    if (isset($_GET['l'])) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
79% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
458
    //        $l = $_GET['l'];
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
459
    //    } else {
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
460
    //        $l = 'a';
0 ignored issues
show
Unused Code Comprehensibility introduced by
43% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
461
    //    }
462
    $l = XoopsRequest::getString('l', 'a', 'get');
463
    //make the redirect
464 View Code Duplication
    if (!isset($_GET['r'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
465
        //insert into pedigree_temp
466
        //        $query = 'UPDATE ' . $GLOBALS['xoopsDB']->prefix('pedigree_temp') . ' SET father =' . $_GET['selsire'] . ' WHERE ID=' . $random;
0 ignored issues
show
Unused Code Comprehensibility introduced by
48% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
467
        //        $GLOBALS['xoopsDB']->queryF($query);
0 ignored issues
show
Unused Code Comprehensibility introduced by
82% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
468
        $query = 'UPDATE ' . $GLOBALS['xoopsDB']->prefix('pedigree_temp') . ' SET father =' . XoopsRequest::getInt('selsire', 0, 'get') . ' WHERE ID=' . $random;
469
        $GLOBALS['xoopsDB']->queryF($query);
470
        redirect_header('add_dog.php?f=dam&random=' . $random . '&st=' . $st . '&r=1&l=a', 1, strtr(_MA_PEDIGREE_ADD_SIREOK, array('[mother]' => $moduleConfig['mother'])));
471
    }
472
473
    $xoopsTpl->assign('sire', '1');
474
    //create list of males dog to select from
475
    $perp = $moduleConfig['perpage'];
476
    //count total number of dogs
477
    $numdog = 'SELECT count(ID) from ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . " WHERE roft='1' and NAAM LIKE '" . $l . "%'";
478
    $numres = $GLOBALS['xoopsDB']->query($numdog);
479
    list($numresults) = $GLOBALS['xoopsDB']->fetchRow($numres);
480
    $numpages = floor($numresults / $perp) + 1;
481
    if (($numpages * $perp) == ($numresults + $perp)) {
482
        --$numpages;
483
    }
484
    $cpage = floor($st / $perp) + 1;
485
    //create alphabet
486
    $pages = '';
487 View Code Duplication
    for ($i = 65; $i <= 90; ++$i) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
488
        if ($l == chr($i)) {
489
            $pages .= "<b><a href=\"add_dog.php?f=dam&r=1&random=" . $random . '&l=' . chr($i) . "\">" . chr($i) . '</a></b>&nbsp;';
490
        } else {
491
            $pages .= "<a href=\"add_dog.php?f=dam&r=1&random=" . $random . '&l=' . chr($i) . "\">" . chr($i) . '</a>&nbsp;';
492
        }
493
    }
494
    $pages .= '-&nbsp;';
495
    $pages .= "<a href=\"add_dog.php?f=dam&r=1&random=" . $random . "&l=Ã…\">Ã…</a>&nbsp;";
496
    $pages .= "<a href=\"add_dog.php?f=dam&r=1&random=" . $random . "&l=Ö\">Ö</a>&nbsp;";
497
    $pages .= '<br />';
498
    //create previous button
499
    if ($numpages > 1) {
500
        if ($cpage > 1) {
501
            $pages .= "<a href=\"add_dog.php?f=dam&r=1&l=" . $l . '&random=' . $random . '&st=' . ($st - $perp) . "\">" . _MA_PEDIGREE_PREVIOUS . '</a>&nbsp;&nbsp';
502
        }
503
    }
504
    //create numbers
505
    for ($x = 1; $x < ($numpages + 1); ++$x) {
506
        //create line break after 20 number
507
        if (($x % 20) == 0) {
508
            $pages .= '<br />';
509
        }
510
        if ($x != $cpage) {
511
            $pages .= "<a href=\"add_dog.php?f=dam&r=1&l=" . $l . '&random=' . $random . '&st=' . ($perp * ($x - 1)) . "\">" . $x . '</a>&nbsp;&nbsp;';
512
        } else {
513
            $pages .= $x . '&nbsp;&nbsp';
514
        }
515
    }
516
    //create next button
517
    if ($numpages > 1) {
518
        if ($cpage < $numpages) {
519
            $pages .= "<a href=\"add_dog.php?f=dam&l=" . $l . '&r=1&random=' . $random . '&st=' . ($st + $perp) . "\">" . _MA_PEDIGREE_NEXT . '</a>&nbsp;&nbsp;';
520
        }
521
    }
522
523
    //query
524
    $queryString = 'SELECT * from ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . " WHERE roft = '1' and NAAM LIKE '" . $l . "%' ORDER BY NAAM LIMIT " . $st . ', ' . $perp;
525
    $result      = $GLOBALS['xoopsDB']->query($queryString);
526
527
    $animal = new PedigreeAnimal();
528
    //test to find out how many user fields there are...
529
    $fields       = $animal->getNumOfFields();
530
    $numofcolumns = 1;
531
    $columns[]    = array('columnname' => 'Name');
0 ignored issues
show
Coding Style Comprehensibility introduced by
$columns was never initialized. Although not strictly required by PHP, it is generally a good practice to add $columns = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
532 View Code Duplication
    for ($i = 0, $iMax = count($fields); $i < $iMax; ++$i) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
533
        $userField   = new Field($fields[$i], $animal->getConfig());
534
        $fieldType   = $userField->getSetting('FieldType');
535
        $fieldObject = new $fieldType($userField, $animal);
536
        //create empty string
537
        $lookupvalues = '';
538
        if ($userField->isActive() && $userField->inList()) {
539
            if ($userField->hasLookup()) {
540
                $lookupvalues = $userField->lookupField($fields[$i]);
541
                //debug information
542
                //print_r($lookupvalues);
543
            }
544
            $columns[] = array('columnname' => $fieldObject->fieldname, 'columnnumber' => $userField->getId(), 'lookupval' => $lookupvalues);
545
            ++$numofcolumns;
546
            unset($lookupvalues);
547
        }
548
    }
549
550 View Code Duplication
    for ($i = 1; $i < $numofcolumns; ++$i) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
551
        $empty[] = array('value' => '');
552
    }
553
    $dogs [] = array(
0 ignored issues
show
Coding Style Comprehensibility introduced by
$dogs was never initialized. Although not strictly required by PHP, it is generally a good practice to add $dogs = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
554
        'id'          => '0',
555
        'name'        => '',
556
        'gender'      => '',
557
        'link'        => "<a href=\"add_dog.php?f=check&random=" . $random . "&seldam=0\">" . strtr(_MA_PEDIGREE_ADD_DAMUNKNOWN, array('[mother]' => $moduleConfig['mother'])) . '</a>',
558
        'colour'      => '',
559
        'number'      => '',
560
        'usercolumns' => $empty
561
    );
562
563 View Code Duplication
    while (false !== ($row = $GLOBALS['xoopsDB']->fetchArray($result))) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
564
        //create picture information
565
        if ($row['foto'] != '') {
566
            $camera = " <img src=\"assets/images/camera.png\">";
567
        } else {
568
            $camera = '';
569
        }
570
        $name = stripslashes($row['NAAM']) . $camera;
571
        //empty array
572
        unset($columnvalue);
573
        //fill array
574
        for ($i = 1; $i < $numofcolumns; ++$i) {
575
            $x = $columns[$i]['columnnumber'];
576
            if (is_array($columns[$i]['lookupval'])) {
577
                foreach ($columns[$i]['lookupval'] as $key => $keyvalue) {
578
                    if ($key == $row['user' . $x]) {
579
                        $value = $keyvalue['value'];
580
                    }
581
                }
582
                //debug information
583
                ///echo $columns[$i]['columnname']."is an array !";
0 ignored issues
show
Unused Code Comprehensibility introduced by
77% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
584
            } //format value - cant use object because of query count
585
            elseif (0 === strpos($row['user' . $x], 'http://')) {
586
                $value = "<a href=\"" . $row['user' . $x] . "\">" . $row['user' . $x] . '</a>';
587
            } else {
588
                $value = $row['user' . $x];
589
            }
590
            $columnvalue[] = array('value' => $value);
0 ignored issues
show
Coding Style Comprehensibility introduced by
$columnvalue was never initialized. Although not strictly required by PHP, it is generally a good practice to add $columnvalue = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
Bug introduced by
The variable $value does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
591
        }
592
        $dogs[] = array(
593
            'id'          => $row['Id'],
594
            'name'        => $name,
595
            'gender'      => '<img src="assets/images/female.gif">',
596
            'link'        => "<a href=\"add_dog.php?f=check&random=" . $random . '&seldam=' . $row['Id'] . "\">" . $name . '</a>',
597
            'colour'      => '',
598
            'number'      => '',
599
            'usercolumns' => $columnvalue
0 ignored issues
show
Bug introduced by
The variable $columnvalue does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
600
        );
601
    }
602
603
    //add data to smarty template
604
    //assign dog
605
    $xoopsTpl->assign('dogs', $dogs);
606
    $xoopsTpl->assign('columns', $columns);
607
    $xoopsTpl->assign('numofcolumns', $numofcolumns);
608
    $xoopsTpl->assign('tsarray', PedigreeUtilities::sortTable($numofcolumns));
609
    $xoopsTpl->assign('nummatch', strtr(_MA_PEDIGREE_ADD_SELDAM, array('[mother]' => $moduleConfig['mother'])));
610
    $xoopsTpl->assign('pages', $pages);
611
}
612
613
function check()
0 ignored issues
show
Best Practice introduced by
The function check() has been defined more than once; this definition is ignored, only the first definition in add_breeder.php (L27-47) is considered.

This check looks for functions that have already been defined in other files.

Some Codebases, like WordPress, make a practice of defining functions multiple times. This may lead to problems with the detection of function parameters and types. If you really need to do this, you can mark the duplicate definition with the @ignore annotation.

/**
 * @ignore
 */
function getUser() {

}

function getUser($id, $realm) {

}

See also the PhpDoc documentation for @ignore.

Loading history...
Coding Style introduced by
check uses the super-global variable $_POST which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
Coding Style introduced by
check uses the super-global variable $_GET which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
Coding Style introduced by
check uses the super-global variable $GLOBALS which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
614
{
615
    global $xoopsTpl, $xoopsUser, $xoopsDB;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
616
617
    //get module configuration
618
    $moduleHandler = xoops_getHandler('module');
619
    $module        = $moduleHandler->getByDirname('pedigree');
620
    $configHandler = xoops_getHandler('config');
621
    $moduleConfig  = $configHandler->getConfigsByCat(0, $module->getVar('mid'));
622
623
    //check for access
624
    $xoopsModule = XoopsModule::getByDirname('pedigree');
0 ignored issues
show
Unused Code introduced by
$xoopsModule is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
625
    if (empty($xoopsUser)) {
626
        redirect_header('index.php', 3, _NOPERM . '<br />' . _MA_PEDIGREE_REGIST);
627
    }
628
    if (empty($random)) {
0 ignored issues
show
Bug introduced by
The variable $random seems only to be defined at a later point. As such the call to empty() seems to always evaluate to true.

This check marks calls to isset(...) or empty(...) that are found before the variable itself is defined. These will always have the same result.

This is likely the result of code being shifted around. Consider removing these calls.

Loading history...
629
        $random = $_POST['random'];
630
    }
631
    if (isset($_GET['random'])) {
632
        $random = $_GET['random'];
633
    }
634
635
    //query
636
    $queryString = 'SELECT * from ' . $GLOBALS['xoopsDB']->prefix('pedigree_temp') . ' WHERE ID = ' . $random;
637
    $result      = $GLOBALS['xoopsDB']->query($queryString);
638
    while (false !== ($row = $GLOBALS['xoopsDB']->fetchArray($result))) {
639
        //create animal object
640
        $animal = new PedigreeAnimal();
641
        //test to find out how many user fields there are..
642
        $fields = $animal->getNumOfFields();
643
        sort($fields);
644
        $usersql = '';
645
        for ($i = 0, $iMax = count($fields); $i < $iMax; ++$i) {
646
            $userField   = new Field($fields[$i], $animal->getConfig());
647
            $fieldType   = $userField->getSetting('FieldType');
648
            $fieldObject = new $fieldType($userField, $animal);
649
            if ($userField->isActive()) {
650
                $usersql .= ",'" . addslashes($row['user' . $fields[$i]]) . "'";
651
            } else {
652
                $usersql .= ",'" . $fieldObject->defaultvalue . "'";
653
            }
654
            //echo $fields[$i]."<br/>";
0 ignored issues
show
Unused Code Comprehensibility introduced by
78% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
655
        }
656
        //insert into pedigree
657
        //$query = 'INSERT INTO ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . " VALUES ('','" . addslashes($row['NAAM']) . "','" . $row['id_owner'] . "','" . $row['id_breeder'] . "','" . $row['user'] . "','" . $row['roft'] . "','" . $_GET['seldam'] . "','" . $row['father'] . "','" . addslashes($row['foto']) . "',''" . $usersql . ')';
0 ignored issues
show
Unused Code Comprehensibility introduced by
47% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
658
        $query = 'INSERT INTO ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . " VALUES ('','" . $GLOBALS['xoopsDB']->escape($row['NAAM']) . "','" . $GLOBALS['xoopsDB']->escape($row['id_owner']) . "','" . $GLOBALS['xoopsDB']->escape($row['id_breeder']) . "','" . $GLOBALS['xoopsDB']->escape($row['user']) . "','" . $GLOBALS['xoopsDB']->escape($row['roft']) . "','" . $GLOBALS['xoopsDB']->escape($_GET['seldam']) . "','" . $GLOBALS['xoopsDB']->escape($row['father']) . "','" . $GLOBALS['xoopsDB']->escape($row['foto']) . "',''" . $usersql . ')';
659
        $GLOBALS['xoopsDB']->queryF($query);
660
        //echo $query; die();
0 ignored issues
show
Unused Code Comprehensibility introduced by
78% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
661
    }
662
    $sqlquery = 'DELETE from ' . $GLOBALS['xoopsDB']->prefix('pedigree_temp') . " where ID='" . $random . "'";
663
    $GLOBALS['xoopsDB']->queryF($sqlquery);
664
    redirect_header('latest.php', 1, strtr(_MA_PEDIGREE_ADD_OK, array('[animalType]' => $moduleConfig['animalType'])));
665
}
666
667
//footer
668
include XOOPS_ROOT_PATH . '/footer.php';
669