Passed
Branch master (48d769)
by Michael
02:30
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
2
// -------------------------------------------------------------------------
3
4
use Xmf\Request;
0 ignored issues
show
Bug introduced by
The type Xmf\Request was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
5
use XoopsModules\Pedigree;
6
7
//require_once  dirname(dirname(__DIR__)) . '/mainfile.php';
8
require_once __DIR__ . '/header.php';
9
//$moduleDirName = basename(__DIR__);
10
xoops_loadLanguage('main', $moduleDirName);
0 ignored issues
show
Bug introduced by
The function xoops_loadLanguage was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

10
/** @scrutinizer ignore-call */ 
11
xoops_loadLanguage('main', $moduleDirName);
Loading history...
11
// Include any common code for this module.
12
require_once XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->dirname() . '/include/common.php';
0 ignored issues
show
Bug introduced by
The constant XOOPS_ROOT_PATH was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
13
14
$GLOBALS['xoopsOption']['template_main'] = 'pedigree_adddog.tpl';
15
16
include XOOPS_ROOT_PATH . '/header.php';
17
$xoopsTpl->assign('page_title', 'Pedigree database - Update details');
18
19
//check for access
20
$xoopsModule = XoopsModule::getByDirname($moduleDirName);
21
if (empty($xoopsUser)) {
22
    redirect_header('index.php', 3, _NOPERM . '<br>' . _MA_PEDIGREE_REGIST);
0 ignored issues
show
Bug introduced by
The constant _NOPERM was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
Bug introduced by
The function redirect_header was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

22
    /** @scrutinizer ignore-call */ 
23
    redirect_header('index.php', 3, _NOPERM . '<br>' . _MA_PEDIGREE_REGIST);
Loading history...
23
}
24
25
//create function variable from url
26
//if (isset($_GET['f'])) {
27
//    $f = $_GET['f'];
28
//} else {
29
//    $f = '';
30
//    addDog();
31
//}
32
33
$f = Request::getString('f', '', 'GET');
34
35
//if ($f === 'checkName') {
36
//    checkName();
37
//}
38
//if ($f === 'sire') {
39
//    sire();
40
//}
41
//if ($f === 'dam') {
42
//    dam();
43
//}
44
//if ($f === 'check') {
45
//    check();
46
//}
47
48
if (empty($f)) {
49
    addDog();
50
} elseif ('checkName' === $f) {
51
    checkName();
52
} elseif ('sire' === $f) {
53
    sire();
54
} elseif ('dam' === $f) {
55
    dam();
56
} elseif ('check' === $f) {
57
    check();
58
}
59
60
function addDog()
61
{
62
    global $xoopsTpl, $xoopsUser, $xoopsDB;
63
    $moduleDirName = basename(__DIR__);
64
    //get module configuration
65
    /** @var XoopsModuleHandler $moduleHandler */
66
    $moduleHandler = xoops_getHandler('module');
0 ignored issues
show
Bug introduced by
The function xoops_getHandler was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

66
    $moduleHandler = /** @scrutinizer ignore-call */ xoops_getHandler('module');
Loading history...
67
    $module        = $moduleHandler->getByDirname($moduleDirName);
68
    $configHandler = xoops_getHandler('config');
69
    $moduleConfig  = $configHandler->getConfigsByCat(0, $module->getVar('mid'));
70
71
    //check for access
72
    if (empty($GLOBALS['xoopsUser']) || !($GLOBALS['xoopsUser'] instanceof \XoopsUser)) {
0 ignored issues
show
Bug introduced by
The type XoopsUser was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
73
        redirect_header('javascript:history.go(-1)', 3, _NOPERM . '<br>' . _MA_PEDIGREE_REGIST);
0 ignored issues
show
Bug introduced by
The function redirect_header was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

73
        /** @scrutinizer ignore-call */ 
74
        redirect_header('javascript:history.go(-1)', 3, _NOPERM . '<br>' . _MA_PEDIGREE_REGIST);
Loading history...
Bug introduced by
The constant _NOPERM was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
74
    }
75
    if (0 == $xoopsUser->getVar('uid')) {
76
        redirect_header('javascript:history.go(-1)', 3, _NOPERM . '<br>' . _MA_PEDIGREE_REGIST);
77
    }
78
    //create form
79
    include XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
0 ignored issues
show
Bug introduced by
The constant XOOPS_ROOT_PATH was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
80
    $form = new \XoopsThemeForm(strtr(_MA_PEDIGREE_ADD_DOG, ['[animalType]' => $moduleConfig['animalType']]), 'dogname', 'add_dog.php?f=checkName', 'post', true);
0 ignored issues
show
Bug introduced by
The type XoopsThemeForm was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
81
    $form->addElement(new \XoopsFormHiddenToken($name = 'XOOPS_TOKEN_REQUEST', $timeout = 360));
0 ignored issues
show
Bug introduced by
The type XoopsFormHiddenToken was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
82
    //create random value
83
    $random = (mt_rand() % 10000);
84
    $form->addElement(new \XoopsFormHidden('random', $random));
0 ignored issues
show
Bug introduced by
The type XoopsFormHidden was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
85
    //find userid
86
    $form->addElement(new \XoopsFormHidden('user', $xoopsUser->getVar('uid')));
87
88
    //name
89
    $form->addElement(new \XoopsFormText('<b>' . _MA_PEDIGREE_FLD_NAME . '</b>', 'naam', $size = 50, $maxsize = 255, $value = ''));
0 ignored issues
show
Bug introduced by
The type XoopsFormText was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
90
    $string = strtr(_MA_PEDIGREE_FLD_NAME_EX, ['[animalType]' => $moduleConfig['animalType']]);
91
    $form->addElement(new \XoopsFormLabel(_MA_PEDIGREE_EXPLAIN, $string));
0 ignored issues
show
Bug introduced by
The type XoopsFormLabel was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
92
93
    //submit button
94
    $form->addElement(new \XoopsFormButton('', 'button_id', strtr(_MA_PEDIGREE_ADD_DATA, ['[animalType]' => $moduleConfig['animalType']]), 'submit'));
0 ignored issues
show
Bug introduced by
The type XoopsFormButton was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
95
96
    //add data (form) to smarty template
97
    $xoopsTpl->assign('form', $form->render());
98
}
99
100
function checkName()
101
{
102
    //configure global variables
103
    global $xoopsTpl, $xoopsDB, $xoopsUser;
104
    $moduleDirName = basename(__DIR__);
105
    //get module configuration
106
    /** @var XoopsModuleHandler $moduleHandler */
107
    $moduleHandler = xoops_getHandler('module');
0 ignored issues
show
Bug introduced by
The function xoops_getHandler was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

107
    $moduleHandler = /** @scrutinizer ignore-call */ xoops_getHandler('module');
Loading history...
108
    $module        = $moduleHandler->getByDirname($moduleDirName);
109
    $configHandler = xoops_getHandler('config');
110
    $moduleConfig  = $configHandler->getConfigsByCat(0, $module->getVar('mid'));
111
112
    //$name = $_POST['naam'];
113
    $name = Request::getString('naam', '', 'POST');
114
    //query
115
    //$queryString = 'SELECT * FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . " WHERE naam LIKE'%" . $name . "%' ORDER BY naam";
116
    $queryString = 'SELECT * FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . " WHERE naam LIKE'%" . $GLOBALS['xoopsDB']->escape($name) . "%' ORDER BY naam";
117
    $result      = $GLOBALS['xoopsDB']->query($queryString);
118
    $numResults  = $GLOBALS['xoopsDB']->getRowsNum($result);
119
    if ($numResults >= 1 && !isset($_GET['r'])) {
120
        //create form
121
        include XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
0 ignored issues
show
Bug introduced by
The constant XOOPS_ROOT_PATH was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
122
        $form = new \XoopsThemeForm(strtr(_MA_PEDIGREE_ADD_DOG, ['[animalType]' => $moduleConfig['animalType']]), 'dogname', 'add_dog.php?f=checkName&r=1', 'post', true);
123
        //other elements
124
        $form->addElement(new \XoopsFormHiddenToken($name = 'XOOPS_TOKEN_REQUEST', $timeout = 360));
125
        $form->addElement(new \XoopsFormHidden('naam', $_POST['naam']));
126
        $form->addElement(new \XoopsFormHidden('user', $xoopsUser->getVar('uid')));
127
        while (false !== ($row = $GLOBALS['xoopsDB']->fetchBoth($result))) {
128
            //name
129
            $form->addElement(new \XoopsFormLabel('<b>' . _MA_PEDIGREE_FLD_NAME . '</b>', '<a href="dog.php?id=' . $row['id'] . '">' . stripslashes($row['naam']) . '</a>'));
130
        }
131
        $form->addElement(new \XoopsFormLabel(_MA_PEDIGREE_EXPLAIN, strtr(_MA_PEDIGREE_ADD_KNOWN, ['[animalTypes]' => $moduleConfig['animalTypes']])));
132
        //submit button
133
        $form->addElement(new \XoopsFormButton('', 'button_id', strtr(_MA_PEDIGREE_ADD_KNOWNOK, ['[animalType]' => $moduleConfig['animalType']]), 'submit'));
134
        //add data (form) to smarty template
135
        $xoopsTpl->assign('form', $form->render());
136
    } else {
137
        //create form
138
        include XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
139
        $form = new \XoopsThemeForm(strtr(_MA_PEDIGREE_ADD_DOG, ['[animalType]' => $moduleConfig['animalType']]), 'dogname', 'add_dog.php?f=sire', 'post', true);
140
        //added to handle upload
141
        $form->setExtra("enctype='multipart/form-data'");
142
        $form->addElement(new \XoopsFormHiddenToken($name = 'XOOPS_TOKEN_REQUEST', $timeout = 360));
143
        //create random value
144
        $random = (mt_rand() % 10000);
145
        $form->addElement(new \XoopsFormHidden('random', $random));
146
        $form->addElement(new \XoopsFormHidden('naam', htmlspecialchars($_POST['naam'], ENT_QUOTES)));
147
        //find userid from previous form
148
        $form->addElement(new \XoopsFormHidden('user', $_POST['user']));
149
150
        //name
151
        $form->addElement(new \XoopsFormLabel('<b>' . _MA_PEDIGREE_FLD_NAME . '</b>', stripslashes($_POST['naam'])));
152
        //gender
153
        $gender_radio = new \XoopsFormRadio('<b>' . _MA_PEDIGREE_FLD_GEND . '</b>', 'roft', $value = '0');
0 ignored issues
show
Bug introduced by
The type XoopsFormRadio was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
154
        $gender_radio->addOptionArray([
155
                                          '0' => strtr(_MA_PEDIGREE_FLD_MALE, ['[male]' => $moduleConfig['male']]),
156
                                          '1' => strtr(_MA_PEDIGREE_FLD_FEMA, ['[female]' => $moduleConfig['female']])
157
                                      ]);
158
        $form->addElement($gender_radio);
159
        if ('1' == $moduleConfig['ownerbreeder']) {
160
            //breeder
161
            $breeder_select = new \XoopsFormSelect('<b>' . _MA_PEDIGREE_FLD_BREE . '</b>', $name = 'id_breeder', $value = '0', $size = 1, $multiple = false);
0 ignored issues
show
Bug introduced by
The type XoopsFormSelect was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
162
            $queryfok       = 'SELECT id, lastname, firstname FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_owner') . ' ORDER BY lastname';
163
            $resfok         = $GLOBALS['xoopsDB']->query($queryfok);
164
            $breeder_select->addOption('0', $name = _MA_PEDIGREE_UNKNOWN);
165
            while (false !== ($rowfok = $GLOBALS['xoopsDB']->fetchArray($resfok))) {
166
                $breeder_select->addOption($rowfok['id'], $name = $rowfok['lastname'] . ', ' . $rowfok['firstname']);
167
            }
168
            $form->addElement($breeder_select);
169
            $form->addElement(new \XoopsFormLabel(_MA_PEDIGREE_EXPLAIN, strtr(_MA_PEDIGREE_FLD_BREE_EX, ['[animalType]' => $moduleConfig['animalType']])));
170
171
            //owner
172
            $owner_select = new \XoopsFormSelect('<b>' . _MA_PEDIGREE_FLD_OWNE . '</b>', $name = 'id_owner', $value = '0', $size = 1, $multiple = false);
173
            $queryfok     = 'SELECT id, lastname, firstname FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_owner') . ' ORDER BY lastname';
174
            $resfok       = $GLOBALS['xoopsDB']->query($queryfok);
175
            $owner_select->addOption('0', $name = _MA_PEDIGREE_UNKNOWN);
176
            while (false !== ($rowfok = $GLOBALS['xoopsDB']->fetchArray($resfok))) {
177
                $owner_select->addOption($rowfok['id'], $name = $rowfok['lastname'] . ', ' . $rowfok['firstname']);
178
            }
179
            $form->addElement($owner_select);
180
            $form->addElement(new \XoopsFormLabel(_MA_PEDIGREE_EXPLAIN, strtr(_MA_PEDIGREE_FLD_OWNE_EX, ['[animalType]' => $moduleConfig['animalType']])));
181
        }
182
        //picture
183
        $max_imgsize = 1024000;
184
        $img_box     = new \XoopsFormFile('Image', 'photo', $max_imgsize);
0 ignored issues
show
Bug introduced by
The type XoopsFormFile was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
185
        $img_box->setExtra("size ='50'");
186
        $form->addElement($img_box);
187
188
        //create animal object
189
        $animal = new Pedigree\Animal();
190
        //test to find out how many user fields there are..
191
        $fields = $animal->getNumOfFields();
192
193
        for ($i = 0, $iMax = count($fields); $i < $iMax; ++$i) {
194
            $userField   = new Pedigree\Field($fields[$i], $animal->getConfig());
195
            $fieldType   = $userField->getSetting('FieldType');
196
            $fieldObject = new $fieldType($userField, $animal);
197
            if ($userField->isActive() && !$userField->isLocked()) {
198
                $newEntry = $fieldObject->newField();
199
                $form->addElement($newEntry);
200
            }
201
            unset($newEntry);
202
        }
203
204
        //submit button
205
        $form->addElement(new \XoopsFormButton('', 'button_id', strtr(_MA_PEDIGREE_ADD_SIRE, ['[father]' => $moduleConfig['father']]), 'submit'));
206
207
        //add data (form) to smarty template
208
        $xoopsTpl->assign('form', $form->render());
209
    }
210
}
211
212
function sire()
213
{
214
    global $xoopsTpl, $xoopsUser, $xoopsDB;
215
    $moduleDirName = basename(__DIR__);
216
    //get module configuration
217
    /** @var XoopsModuleHandler $moduleHandler */
218
    $moduleHandler = xoops_getHandler('module');
0 ignored issues
show
Bug introduced by
The function xoops_getHandler was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

218
    $moduleHandler = /** @scrutinizer ignore-call */ xoops_getHandler('module');
Loading history...
219
    $module        = $moduleHandler->getByDirname($moduleDirName);
220
    $configHandler = xoops_getHandler('config');
221
    $moduleConfig  = $configHandler->getConfigsByCat(0, $module->getVar('mid'));
222
    $empty         = []; // an empty array
223
224
    //check for access
225
    if (empty($GLOBALS['xoopsUser']) || !($GLOBALS['xoopsUser'] instanceof \XoopsUser)) {
226
        redirect_header('javascript:history.go(-1)', 3, _NOPERM . '<br>' . _MA_PEDIGREE_REGIST);
0 ignored issues
show
Bug introduced by
The function redirect_header was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

226
        /** @scrutinizer ignore-call */ 
227
        redirect_header('javascript:history.go(-1)', 3, _NOPERM . '<br>' . _MA_PEDIGREE_REGIST);
Loading history...
Bug introduced by
The constant _NOPERM was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
227
    }
228
    $user = isset($_POST['user']) ? $_POST['user'] : null;
229
    if (empty($random)) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $random seems to never exist and therefore empty should always be true.
Loading history...
230
        //        $random = isset($_POST['random']) ? $_POST['random'] : null;
231
        $random = Request::getString('random', null, 'POST');
232
    }
233
    //    if (isset($_GET['random'])) {
234
    //        $random = $_GET['random'];
235
    //    }
236
237
    $random = Request::getString('random', $random, 'GET');
238
239
    if (empty($st)) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $st seems to never exist and therefore empty should always be true.
Loading history...
240
        $st = 0;
241
    }
242
    if (isset($_GET['st'])) {
243
        $st = $_GET['st'];
244
    }
245
    $name = isset($_POST['naam']) ? $_POST['naam'] : null;
246
    $roft = isset($_POST['roft']) ? $_POST['roft'] : null;
247
248
    $id_owner   = isset($_POST['id_owner']) ? $_POST['id_owner'] : null;
249
    $id_breeder = isset($_POST['id_breeder']) ? $_POST['id_breeder'] : null;
250
251
    $pictureField = isset($_FILES['photo']) ? $_FILES['photo']['name'] : null; // $_FILES['photo']['name'];
252
    if (empty($pictureField) || '' == $pictureField) {
253
        $foto = '';
254
    } else {
255
        $foto = Pedigree\Utility::uploadPicture(0);
256
    }
257
    $numPictureField = 1;
258
259
    //make the redirect
260
    if (!isset($_GET['r'])) {
261
        if ('' == $_POST['naam']) {
262
            redirect_header('add_dog.php', 1, _MA_PEDIGREE_ADD_NAMEPLZ);
263
        }
264
        //create animal object
265
        $animal = new Pedigree\Animal();
266
        //test to find out how many user fields there are..
267
        $fields = $animal->getNumOfFields();
268
        sort($fields); //sort by ID not by order
269
        $usersql = '';
270
        for ($i = 0, $iMax = count($fields); $i < $iMax; ++$i) {
271
            $userField   = new Pedigree\Field($fields[$i], $animal->getConfig());
272
            $fieldType   = $userField->getSetting('FieldType');
273
            $fieldObject = new $fieldType($userField, $animal);
0 ignored issues
show
Unused Code introduced by
The assignment to $fieldObject is dead and can be removed.
Loading history...
274
            if ($userField->isActive()) {
275
                //check if _FILES variable exists for user picturefield
276
                $currentfield = 'user' . $fields[$i];
277
                $pictureField = $_FILES[$currentfield]['name'];
278
                if ('Picture' === $fieldType && (!empty($pictureField) || '' != $pictureField)) {
279
                    $userpicture = Pedigree\Utility::uploadPicture($numPictureField);
280
                    $usersql .= ",'" . $userpicture . "'";
281
                    ++$numPictureField;
282
                } elseif ($userField->isLocked()) {
283
                    //userfield is locked, substitute default value
284
                    $usersql .= ",'" . $userField->defaultvalue . "'";
285
                } else {
286
                    //echo $fieldType.":".$i.":".$fields[$i]."<br>";
287
                    $usersql .= ",'" . Pedigree\Utility::unHtmlEntities($_POST['user' . $fields[$i]]) . "'";
288
                }
289
            } else {
290
                $usersql .= ",''";
291
            }
292
            //echo $fields[$i]."<br>";
293
        }
294
295
        //insert into pedigree_temp
296
        //        $query = 'INSERT INTO ' . $GLOBALS['xoopsDB']->prefix('pedigree_temp') . " VALUES ('" . $random . "','" . Pedigree\Utility::unHtmlEntities($name) . "','" . $id_owner . "','" . $id_breeder . "','" . $user . "','" . $roft . "','','','" . $foto . "', ''" . $usersql . ')';
297
        $query = 'INSERT INTO '
298
                 . $GLOBALS['xoopsDB']->prefix('pedigree_temp')
299
                 . " VALUES ('"
300
                 . $GLOBALS['xoopsDB']->escape($random)
301
                 . "','"
302
                 . $GLOBALS['xoopsDB']->escape(Pedigree\Utility::unHtmlEntities($name))
303
                 . "','"
304
                 . $GLOBALS['xoopsDB']->escape($id_owner)
305
                 . "','"
306
                 . $GLOBALS['xoopsDB']->escape($id_breeder)
307
                 . "','"
308
                 . $GLOBALS['xoopsDB']->escape($user)
309
                 . "','"
310
                 . $GLOBALS['xoopsDB']->escape($roft)
311
                 . "','0','0','"
312
                 . $GLOBALS['xoopsDB']->escape($foto)
313
                 . "', ''"
314
                 . $usersql
315
                 . ')';
316
        //echo $query; die();
317
        $GLOBALS['xoopsDB']->queryF($query);
318
        redirect_header('add_dog.php?f=sire&random=' . $random . '&st=' . $st . '&r=1&l=a', 1, strtr(_MA_PEDIGREE_ADD_SIREPLZ, ['[father]' => $moduleConfig['father']]));
319
    }
320
    //find letter on which to start else set to 'a'
321
    $l = Request::getString('l', 'A', 'GET');
322
    //    if (isset($_GET['l'])) {
323
    //        $l = $_GET['l'];
324
    //    } else {
325
    //        $l = 'a';
326
    //    }
327
    //assign sire to template
328
    $xoopsTpl->assign('sire', '1');
329
    //create list of males dog to select from
330
    $perPage = $moduleConfig['perpage'];
331
    //count total number of dogs
332
    $numDog = 'SELECT count(id) FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . " WHERE roft='0' AND naam LIKE '" . $l . "%'";
333
    $numRes = $GLOBALS['xoopsDB']->query($numDog);
334
    //total number of dogs the query will find
335
    list($numResults) = $GLOBALS['xoopsDB']->fetchRow($numRes);
336
    //total number of pages
337
    $numPages = floor($numResults / $perPage) + 1;
338
    if (($numPages * $perPage) == ($numResults + $perPage)) {
339
        --$numPages;
340
    }
341
    //find current page
342
    $currentPage = floor($st / $perPage) + 1;
343
    //create alphabet
344
    $pages = '';
345
    for ($i = 65; $i <= 90; ++$i) {
346
        if ($l == chr($i)) {
347
            $pages .= '<b><a href="add_dog.php?f=sire&r=1&random=' . $random . '&l=' . chr($i) . '">' . chr($i) . '</a></b>&nbsp;';
348
        } else {
349
            $pages .= '<a href="add_dog.php?f=sire&r=1&random=' . $random . '&l=' . chr($i) . '">' . chr($i) . '</a>&nbsp;';
350
        }
351
    }
352
    $pages .= '-&nbsp;';
353
    $pages .= '<a href="add_dog.php?f=sire&r=1&random=' . $random . '&l=Ã…">Ã…</a>&nbsp;';
354
    $pages .= '<a href="add_dog.php?f=sire&r=1&random=' . $random . '&l=Ö">Ö</a>&nbsp;';
355
    //create linebreak
356
    $pages .= '<br>';
357
    //create previous button
358
    if ($numPages > 1) {
359
        if ($currentPage > 1) {
360
            $pages .= '<a href="add_dog.php?f=sire&r=1&l=' . $l . '&random=' . $random . '&st=' . ($st - $perPage) . '">' . _MA_PEDIGREE_PREVIOUS . '</a>&nbsp;&nbsp';
361
        }
362
    }
363
    //create numbers
364
    for ($x = 1; $x < ($numPages + 1); ++$x) {
365
        //create line break after 20 numbers
366
        if (0 == ($x % 20)) {
367
            $pages .= '<br>';
368
        }
369
        if ($x != $currentPage) {
370
            $pages .= '<a href="add_dog.php?f=sire&r=1&l=' . $l . '&random=' . $random . '&st=' . ($perPage * ($x - 1)) . '">' . $x . '</a>&nbsp;&nbsp;';
371
        } else {
372
            $pages .= $x . '&nbsp;&nbsp';
373
        }
374
    }
375
    //create next button
376
    if ($numPages > 1) {
377
        if ($currentPage < $numPages) {
378
            $pages .= '<a href="add_dog.php?f=sire&r=1&l=' . $l . '&random=' . $random . '&st=' . ($st + $perPage) . '">' . _MA_PEDIGREE_NEXT . '</a>&nbsp;&nbsp';
379
        }
380
    }
381
382
    //query
383
    $queryString = 'SELECT * FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . " WHERE roft = '0' AND naam LIKE '" . $l . "%'ORDER BY naam LIMIT " . $st . ', ' . $perPage;
384
    $result      = $GLOBALS['xoopsDB']->query($queryString);
385
386
    $animal = new Pedigree\Animal();
387
    //test to find out how many user fields there are...
388
    $fields       = $animal->getNumOfFields();
389
    $numofcolumns = 1;
390
    $columns[]    = ['columnname' => 'Name'];
0 ignored issues
show
Comprehensibility Best Practice introduced by
$columns was never initialized. Although not strictly required by PHP, it is generally a good practice to add $columns = array(); before regardless.
Loading history...
391
    for ($i = 0, $iMax = count($fields); $i < $iMax; ++$i) {
392
        $userField   = new Pedigree\Field($fields[$i], $animal->getConfig());
393
        $fieldType   = $userField->getSetting('FieldType');
394
        $fieldObject = new $fieldType($userField, $animal);
395
        //create empty string
396
        $lookupValues = '';
397
        if ($userField->isActive() && $userField->inList()) {
398
            if ($userField->hasLookup()) {
399
                $lookupValues = $userField->lookupField($fields[$i]);
400
                //debug information
401
                //print_r($lookupValues);
402
            }
403
            $columns[] = [
404
                'columnname'   => $fieldObject->fieldname,
405
                'columnnumber' => $userField->getId(),
406
                'lookupval'    => $lookupValues
407
            ];
408
            ++$numofcolumns;
409
            unset($lookupValues);
410
        }
411
    }
412
413
    for ($i = 1; $i < $numofcolumns; ++$i) {
414
        $empty[] = ['value' => ''];
415
    }
416
    $dogs [] = [
0 ignored issues
show
Comprehensibility Best Practice introduced by
$dogs was never initialized. Although not strictly required by PHP, it is generally a good practice to add $dogs = array(); before regardless.
Loading history...
417
        'id'          => '0',
418
        'name'        => '',
419
        'gender'      => '',
420
        'link'        => '<a href="add_dog.php?f=dam&random=' . $random . '&selsire=0">' . strtr(_MA_PEDIGREE_ADD_SIREUNKNOWN, ['[father]' => $moduleConfig['father']]) . '</a>',
421
        'colour'      => '',
422
        'number'      => '',
423
        'usercolumns' => $empty
424
    ];
425
426
    while (false !== ($row = $GLOBALS['xoopsDB']->fetchArray($result))) {
427
        //create picture information
428
        if ('' != $row['foto']) {
429
            $camera = ' <img src="assets/images/camera.png">';
430
        } else {
431
            $camera = '';
432
        }
433
        $name = stripslashes($row['naam']) . $camera;
434
        //empty array
435
        unset($columnvalue);
436
        //fill array
437
        for ($i = 1; $i < $numofcolumns; ++$i) {
438
            $x = $columns[$i]['columnnumber'];
439
            if (is_array($columns[$i]['lookupval'])) {
440
                foreach ($columns[$i]['lookupval'] as $key => $keyValue) {
441
                    if ($key == $row['user' . $x]) {
442
                        $value = $keyValue['value'];
443
                    }
444
                }
445
                //debug information
446
                ///echo $columns[$i]['columnname']."is an array !";
447
            } //format value - cant use object because of query count
448
            elseif (0 === strncmp($row['user' . $x], 'http://', 7)) {
449
                $value = '<a href="' . $row['user' . $x] . '">' . $row['user' . $x] . '</a>';
450
            } else {
451
                $value = $row['user' . $x];
452
            }
453
            $columnvalue[] = ['value' => $value];
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $value does not seem to be defined for all execution paths leading up to this point.
Loading history...
454
        }
455
        $dogs[] = [
456
            'id'          => $row['id'],
457
            'name'        => $name,
458
            'gender'      => '<img src="assets/images/male.gif">',
459
            'link'        => '<a href="add_dog.php?f=dam&random=' . $random . '&selsire=' . $row['id'] . '">' . $name . '</a>',
460
            'colour'      => '',
461
            'number'      => '',
462
            'usercolumns' => $columnvalue
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $columnvalue does not seem to be defined for all execution paths leading up to this point.
Loading history...
463
        ];
464
    }
465
466
    //add data to smarty template
467
    //assign dog
468
    $xoopsTpl->assign('dogs', $dogs);
469
    $xoopsTpl->assign('columns', $columns);
470
    $xoopsTpl->assign('numofcolumns', $numofcolumns);
471
    $xoopsTpl->assign('tsarray', Pedigree\Utility::sortTable($numofcolumns));
472
    //assign links
473
    $xoopsTpl->assign('nummatch', strtr(_MA_PEDIGREE_ADD_SELSIRE, ['[father]' => $moduleConfig['father']]));
474
    $xoopsTpl->assign('pages', $pages);
475
476
    //mb =========== FATHER LETTERS =============================
477
    $myObject = Pedigree\Helper::getInstance();
478
    $roft     = 0;
479
    //    $criteria     = $myObject->getHandler('Tree')->getActiveCriteria($roft);
480
    $activeObject = 'Tree';
481
    $name         = 'naam';
482
    $number1      = '1';
0 ignored issues
show
Unused Code introduced by
The assignment to $number1 is dead and can be removed.
Loading history...
483
    $number2      = '0';
0 ignored issues
show
Unused Code introduced by
The assignment to $number2 is dead and can be removed.
Loading history...
484
    //    $link         = "virtual.php?r={$number1}&st={$number2}&l=";
485
    $link = "add_dog.php?f=sire&r=1&random={$random}&l=";
486
487
    //    http://localhost/257belgi/modules/pedigree/virtual.php?f=dam&selsire=35277
488
489
    $link2 = '';
490
491
    $criteria = $myObject->getHandler('Tree')->getActiveCriteria($roft);
492
    //    $criteria->setGroupby('UPPER(LEFT(' . $name . ',1))');
493
494
    $fatherArray['letters'] = Pedigree\Utility::lettersChoice($myObject, $activeObject, $criteria, $name, $link, $link2);
0 ignored issues
show
Comprehensibility Best Practice introduced by
$fatherArray was never initialized. Although not strictly required by PHP, it is generally a good practice to add $fatherArray = array(); before regardless.
Loading history...
495
    //$catarray['toolbar']          = pedigree_toolbar();
496
    $xoopsTpl->assign('fatherArray', $fatherArray);
497
498
    //mb ========================================
499
}
500
501
function dam()
502
{
503
    global $xoopsTpl, $xoopsUser, $xoopsDB;
504
    $moduleDirName = basename(__DIR__);
505
    //get module configuration
506
    /** @var XoopsModuleHandler $moduleHandler */
507
    $moduleHandler = xoops_getHandler('module');
0 ignored issues
show
Bug introduced by
The function xoops_getHandler was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

507
    $moduleHandler = /** @scrutinizer ignore-call */ xoops_getHandler('module');
Loading history...
508
    $module        = $moduleHandler->getByDirname($moduleDirName);
509
    $configHandler = xoops_getHandler('config');
510
    $moduleConfig  = $configHandler->getConfigsByCat(0, $module->getVar('mid'));
511
    $empty         = []; // an empty array
512
513
    //check for access
514
    $xoopsModule = XoopsModule::getByDirname($moduleDirName);
0 ignored issues
show
Unused Code introduced by
The assignment to $xoopsModule is dead and can be removed.
Loading history...
515
    if (empty($GLOBALS['xoopsUser']) || !($GLOBALS['xoopsUser'] instanceof \XoopsUser)) {
516
        redirect_header('javascript:history.go(-1)', 3, _NOPERM . '<br>' . _MA_PEDIGREE_REGIST);
0 ignored issues
show
Bug introduced by
The function redirect_header was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

516
        /** @scrutinizer ignore-call */ 
517
        redirect_header('javascript:history.go(-1)', 3, _NOPERM . '<br>' . _MA_PEDIGREE_REGIST);
Loading history...
Bug introduced by
The constant _NOPERM was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
517
    }
518
    //    if (empty($random)) {
519
    //$random = isset($_POST['random']) ? $_POST['random'] : null;
520
    //}
521
    //if (isset($_GET['random'])) {
522
    //$random = $_GET['random'];
523
    //}
524
    //if (empty($st)) {
525
    //$st = 0;
526
    //}
527
    //if (isset($_GET['st'])) {
528
    //$st = $_GET['st'];
529
    //}
530
    $random = Request::getInt('random', 0);
531
    $st     = Request::getInt('st', 0, 'GET');
532
    //find letter on which to start else set to 'a'
533
    //    if (isset($_GET['l'])) {
534
    //        $l = $_GET['l'];
535
    //    } else {
536
    //        $l = 'a';
537
    //    }
538
    $l = Request::getString('l', 'a', 'GET');
539
    //make the redirect
540
    if (!isset($_GET['r'])) {
541
        //insert into pedigree_temp
542
        //        $query = 'UPDATE ' . $GLOBALS['xoopsDB']->prefix('pedigree_temp') . ' SET father =' . $_GET['selsire'] . ' WHERE id=' . $random;
543
        //        $GLOBALS['xoopsDB']->queryF($query);
544
        $query = 'UPDATE ' . $GLOBALS['xoopsDB']->prefix('pedigree_temp') . ' SET father =' . Request::getInt('selsire', 0, 'GET') . ' WHERE id=' . $random;
545
        $GLOBALS['xoopsDB']->queryF($query);
546
        redirect_header('add_dog.php?f=dam&random=' . $random . '&st=' . $st . '&r=1&l=a', 1, strtr(_MA_PEDIGREE_ADD_SIREOK, ['[mother]' => $moduleConfig['mother']]));
547
    }
548
549
    $xoopsTpl->assign('sire', '1');
550
    //create list of males dog to select from
551
    $perPage = $moduleConfig['perpage'];
552
    //count total number of dogs
553
    $numDog = 'SELECT count(id) FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . " WHERE roft='1' AND naam LIKE '" . $l . "%'";
554
    $numRes = $GLOBALS['xoopsDB']->query($numDog);
555
    list($numResults) = $GLOBALS['xoopsDB']->fetchRow($numRes);
556
    $numPages = floor($numResults / $perPage) + 1;
557
    if (($numPages * $perPage) == ($numResults + $perPage)) {
558
        --$numPages;
559
    }
560
    $currentPage = floor($st / $perPage) + 1;
561
    //create alphabet
562
    $pages = '';
563
    for ($i = 65; $i <= 90; ++$i) {
564
        if ($l == chr($i)) {
565
            $pages .= '<b><a href="add_dog.php?f=dam&r=1&random=' . $random . '&l=' . chr($i) . '">' . chr($i) . '</a></b>&nbsp;';
566
        } else {
567
            $pages .= '<a href="add_dog.php?f=dam&r=1&random=' . $random . '&l=' . chr($i) . '">' . chr($i) . '</a>&nbsp;';
568
        }
569
    }
570
    $pages .= '-&nbsp;';
571
    $pages .= '<a href="add_dog.php?f=dam&r=1&random=' . $random . '&l=Ã…">Ã…</a>&nbsp;';
572
    $pages .= '<a href="add_dog.php?f=dam&r=1&random=' . $random . '&l=Ö">Ö</a>&nbsp;';
573
    $pages .= '<br>';
574
    //create previous button
575
    if ($numPages > 1) {
576
        if ($currentPage > 1) {
577
            $pages .= '<a href="add_dog.php?f=dam&r=1&l=' . $l . '&random=' . $random . '&st=' . ($st - $perPage) . '">' . _MA_PEDIGREE_PREVIOUS . '</a>&nbsp;&nbsp';
578
        }
579
    }
580
    //create numbers
581
    for ($x = 1; $x < ($numPages + 1); ++$x) {
582
        //create line break after 20 number
583
        if (0 == ($x % 20)) {
584
            $pages .= '<br>';
585
        }
586
        if ($x != $currentPage) {
587
            $pages .= '<a href="add_dog.php?f=dam&r=1&l=' . $l . '&random=' . $random . '&st=' . ($perPage * ($x - 1)) . '">' . $x . '</a>&nbsp;&nbsp;';
588
        } else {
589
            $pages .= $x . '&nbsp;&nbsp';
590
        }
591
    }
592
    //create next button
593
    if ($numPages > 1) {
594
        if ($currentPage < $numPages) {
595
            $pages .= '<a href="add_dog.php?f=dam&l=' . $l . '&r=1&random=' . $random . '&st=' . ($st + $perPage) . '">' . _MA_PEDIGREE_NEXT . '</a>&nbsp;&nbsp;';
596
        }
597
    }
598
599
    //query
600
    $queryString = 'SELECT * FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . " WHERE roft = '1' AND naam LIKE '" . $l . "%' ORDER BY naam LIMIT " . $st . ', ' . $perPage;
601
    $result      = $GLOBALS['xoopsDB']->query($queryString);
602
603
    $animal = new Pedigree\Animal();
604
    //test to find out how many user fields there are...
605
    $fields       = $animal->getNumOfFields();
606
    $numofcolumns = 1;
607
    $columns[]    = ['columnname' => 'Name'];
0 ignored issues
show
Comprehensibility Best Practice introduced by
$columns was never initialized. Although not strictly required by PHP, it is generally a good practice to add $columns = array(); before regardless.
Loading history...
608
    for ($i = 0, $iMax = count($fields); $i < $iMax; ++$i) {
609
        $userField   = new Pedigree\Field($fields[$i], $animal->getConfig());
610
        $fieldType   = $userField->getSetting('FieldType');
611
        $fieldObject = new $fieldType($userField, $animal);
612
        //create empty string
613
        $lookupValues = '';
614
        if ($userField->isActive() && $userField->inList()) {
615
            if ($userField->hasLookup()) {
616
                $lookupValues = $userField->lookupField($fields[$i]);
617
                //debug information
618
                //print_r($lookupValues);
619
            }
620
            $columns[] = [
621
                'columnname'   => $fieldObject->fieldname,
622
                'columnnumber' => $userField->getId(),
623
                'lookupval'    => $lookupValues
624
            ];
625
            ++$numofcolumns;
626
            unset($lookupValues);
627
        }
628
    }
629
630
    for ($i = 1; $i < $numofcolumns; ++$i) {
631
        $empty[] = ['value' => ''];
632
    }
633
    $dogs [] = [
0 ignored issues
show
Comprehensibility Best Practice introduced by
$dogs was never initialized. Although not strictly required by PHP, it is generally a good practice to add $dogs = array(); before regardless.
Loading history...
634
        'id'          => '0',
635
        'name'        => '',
636
        'gender'      => '',
637
        'link'        => '<a href="add_dog.php?f=check&random=' . $random . '&seldam=0">' . strtr(_MA_PEDIGREE_ADD_DAMUNKNOWN, ['[mother]' => $moduleConfig['mother']]) . '</a>',
638
        'colour'      => '',
639
        'number'      => '',
640
        'usercolumns' => $empty
641
    ];
642
643
    while (false !== ($row = $GLOBALS['xoopsDB']->fetchArray($result))) {
644
        //create picture information
645
        if ('' != $row['foto']) {
646
            $camera = ' <img src="assets/images/camera.png">';
647
        } else {
648
            $camera = '';
649
        }
650
        $name = stripslashes($row['naam']) . $camera;
651
        //empty array
652
        unset($columnvalue);
653
        //fill array
654
        for ($i = 1; $i < $numofcolumns; ++$i) {
655
            $x = $columns[$i]['columnnumber'];
656
            if (is_array($columns[$i]['lookupval'])) {
657
                foreach ($columns[$i]['lookupval'] as $key => $keyValue) {
658
                    if ($key == $row['user' . $x]) {
659
                        $value = $keyValue['value'];
660
                    }
661
                }
662
                //debug information
663
                ///echo $columns[$i]['columnname']."is an array !";
664
            } //format value - cant use object because of query count
665
            elseif (0 === strncmp($row['user' . $x], 'http://', 7)) {
666
                $value = '<a href="' . $row['user' . $x] . '">' . $row['user' . $x] . '</a>';
667
            } else {
668
                $value = $row['user' . $x];
669
            }
670
            $columnvalue[] = ['value' => $value];
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $value does not seem to be defined for all execution paths leading up to this point.
Loading history...
671
        }
672
        $dogs[] = [
673
            'id'          => $row['id'],
674
            'name'        => $name,
675
            'gender'      => '<img src="assets/images/female.gif">',
676
            'link'        => '<a href="add_dog.php?f=check&random=' . $random . '&seldam=' . $row['id'] . '">' . $name . '</a>',
677
            'colour'      => '',
678
            'number'      => '',
679
            'usercolumns' => $columnvalue
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $columnvalue does not seem to be defined for all execution paths leading up to this point.
Loading history...
680
        ];
681
    }
682
683
    //add data to smarty template
684
    //assign dog
685
    $xoopsTpl->assign('dogs', $dogs);
686
    $xoopsTpl->assign('columns', $columns);
687
    $xoopsTpl->assign('numofcolumns', $numofcolumns);
688
    $xoopsTpl->assign('tsarray', Pedigree\Utility::sortTable($numofcolumns));
689
    $xoopsTpl->assign('nummatch', strtr(_MA_PEDIGREE_ADD_SELDAM, ['[mother]' => $moduleConfig['mother']]));
690
    $xoopsTpl->assign('pages', $pages);
691
692
    //mb ========= MOTHER LETTERS===============================
693
    $myObject = Pedigree\Helper::getInstance();
694
    $roft     = 1;
695
    //    $criteria     = $myObject->getHandler('Tree')->getActiveCriteria($roft);
696
    $activeObject = 'Tree';
697
    $name         = 'naam';
698
    $number1      = '1';
0 ignored issues
show
Unused Code introduced by
The assignment to $number1 is dead and can be removed.
Loading history...
699
    $number2      = '0';
0 ignored issues
show
Unused Code introduced by
The assignment to $number2 is dead and can be removed.
Loading history...
700
    $link         = "add_dog.php?f=dam&r=1&random={$random}&l=";
701
    $link2        = '';
702
703
    $criteria = $myObject->getHandler('Tree')->getActiveCriteria($roft);
704
    //    $criteria->setGroupby('UPPER(LEFT(' . $name . ',1))');
705
706
    $motherArray['letters'] = Pedigree\Utility::lettersChoice($myObject, $activeObject, $criteria, $name, $link, $link2);
0 ignored issues
show
Comprehensibility Best Practice introduced by
$motherArray was never initialized. Although not strictly required by PHP, it is generally a good practice to add $motherArray = array(); before regardless.
Loading history...
707
    //$catarray['toolbar']          = pedigree_toolbar();
708
    $xoopsTpl->assign('motherArray', $motherArray);
709
710
    //mb ========================================
711
}
712
713
function check()
714
{
715
    global $xoopsTpl, $xoopsUser, $xoopsDB;
716
    $moduleDirName = basename(__DIR__);
717
    //get module configuration
718
    /** @var XoopsModuleHandler $moduleHandler */
719
    $moduleHandler = xoops_getHandler('module');
0 ignored issues
show
Bug introduced by
The function xoops_getHandler was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

719
    $moduleHandler = /** @scrutinizer ignore-call */ xoops_getHandler('module');
Loading history...
720
    $module        = $moduleHandler->getByDirname($moduleDirName);
721
    $configHandler = xoops_getHandler('config');
722
    $moduleConfig  = $configHandler->getConfigsByCat(0, $module->getVar('mid'));
723
724
    //check for access
725
    $xoopsModule = XoopsModule::getByDirname($moduleDirName);
0 ignored issues
show
Unused Code introduced by
The assignment to $xoopsModule is dead and can be removed.
Loading history...
726
    if (empty($xoopsUser)) {
727
        redirect_header('index.php', 3, _NOPERM . '<br>' . _MA_PEDIGREE_REGIST);
0 ignored issues
show
Bug introduced by
The function redirect_header was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

727
        /** @scrutinizer ignore-call */ 
728
        redirect_header('index.php', 3, _NOPERM . '<br>' . _MA_PEDIGREE_REGIST);
Loading history...
Bug introduced by
The constant _NOPERM was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
728
    }
729
    if (empty($random)) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $random seems to never exist and therefore empty should always be true.
Loading history...
730
        $random = $_POST['random'];
731
    }
732
    if (isset($_GET['random'])) {
733
        $random = $_GET['random'];
734
    }
735
736
    //query
737
    $queryString = 'SELECT * FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_temp') . ' WHERE id = ' . $random;
738
    $result      = $GLOBALS['xoopsDB']->query($queryString);
739
    while (false !== ($row = $GLOBALS['xoopsDB']->fetchArray($result))) {
740
        //create animal object
741
        $animal = new Pedigree\Animal();
742
        //test to find out how many user fields there are..
743
        $fields = $animal->getNumOfFields();
744
        sort($fields);
745
        $usersql = '';
746
        for ($i = 0, $iMax = count($fields); $i < $iMax; ++$i) {
747
            $userField   = new Pedigree\Field($fields[$i], $animal->getConfig());
748
            $fieldType   = $userField->getSetting('FieldType');
749
            $fieldObject = new $fieldType($userField, $animal);
750
            if ($userField->isActive()) {
751
                $usersql .= ",'" . addslashes($row['user' . $fields[$i]]) . "'";
752
            } else {
753
                $usersql .= ",'" . $fieldObject->defaultvalue . "'";
754
            }
755
            //echo $fields[$i]."<br>";
756
        }
757
        //insert into pedigree
758
        //$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 . ')';
759
        $sql = 'INSERT INTO '
760
               . $GLOBALS['xoopsDB']->prefix('pedigree_tree')
761
               . " VALUES (0,'"
762
               . $GLOBALS['xoopsDB']->escape($row['naam'])
763
               . "','"
764
               . $GLOBALS['xoopsDB']->escape($row['id_owner'])
765
               . "','"
766
               . $GLOBALS['xoopsDB']->escape($row['id_breeder'])
767
               . "','"
768
               . $GLOBALS['xoopsDB']->escape($row['user'])
769
               . "','"
770
               . $GLOBALS['xoopsDB']->escape($row['roft'])
771
               . "','"
772
               . $GLOBALS['xoopsDB']->escape($_GET['seldam'])
773
               . "','"
774
               . $GLOBALS['xoopsDB']->escape($row['father'])
775
               . "','"
776
               . $GLOBALS['xoopsDB']->escape($row['foto'])
777
               . "',''"
778
               . $usersql
779
               . ')';
780
        $GLOBALS['xoopsDB']->queryF($sql);
781
        //echo $query; die();
782
    }
783
    $sqlQuery = 'DELETE FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_temp') . " WHERE id='" . $random . "'";
784
    $GLOBALS['xoopsDB']->queryF($sqlQuery);
785
    redirect_header('latest.php', 1, strtr(_MA_PEDIGREE_ADD_OK, ['[animalType]' => $moduleConfig['animalType']]));
786
}
787
788
//footer
789
include XOOPS_ROOT_PATH . '/footer.php';
790