Passed
Branch master (465698)
by Michael
05:38
created

add_dog.php ➔ dam()   F

Complexity

Conditions 24
Paths > 20000

Size

Total Lines 186
Code Lines 128

Duplication

Lines 74
Ratio 39.78 %

Importance

Changes 0
Metric Value
cc 24
eloc 128
nc 60480
nop 0
dl 74
loc 186
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
require_once dirname(dirname(__DIR__)) . '/mainfile.php';
5
xoops_load('XoopsRequest');
6
$moduleDirName = basename(__DIR__);
7
xoops_loadLanguage('main', $moduleDirName);
8
// Include any common code for this module.
9
require_once XOOPS_ROOT_PATH . "/modules/{$moduleDirName}/include/common.php";
10
//require_once(XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->dirname() . '/class/field.php');
11
if (!class_exists('PedigreeField')) {
12
    require_once XOOPS_ROOT_PATH . "/modules/{$moduleDirName}/class/field.php";
13
}
14
15
$xoopsOption['template_main'] = 'pedigree_adddog.tpl';
16
17
include XOOPS_ROOT_PATH . '/header.php';
18
$xoopsTpl->assign('page_title', 'Pedigree database - Update details');
19
20
//check for access
21
$xoopsModule = XoopsModule::getByDirname('pedigree');
22
if (empty($xoopsUser)) {
23
    redirect_header('index.php', 3, _NOPERM . '<br />' . _MA_PEDIGREE_REGIST);
24
}
25
26
//create function variable from url
27
$f = XoopsRequest::getCmd('f', 'add', 'GET');
28
switch ($f) {
29
    case 'checkName':
30
        checkName();
31
        break;
32
    case 'sire':
33
        sire();
34
        break;
35
    case 'dam':
36
        dam();
37
        break;
38
    case 'check':
39
        check();
40
        break;
41
    default:
42
        addDog();
43
        break;
44
}
45
46
function addDog() {
47
48
    global $xoopsTpl, $xoopsUser, $xoopsDB, $pedigree;
49
/*
50
    //get module configuration
51
    $moduleHandler = xoops_getHandler('module');
52
    $module        = $moduleHandler->getByDirname('pedigree');
53
    $configHandler = xoops_getHandler('config');
54
    $moduleConfig  = $configHandler->getConfigsByCat(0, $module->getVar('mid'));
55
*/
56
    //check for access
57
    if (empty($xoopsUser)) {
58
        redirect_header('javascript:history.go(-1)', 3, _NOPERM . '<br />' . _MA_PEDIGREE_REGIST);
59
    }
60
    if ($xoopsUser->getVar('uid') == 0) {
61
        redirect_header('javascript:history.go(-1)', 3, _NOPERM . '<br />' . _MA_PEDIGREE_REGIST);
62
    }
63
    //create form
64
    include XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
65
    $form = new XoopsThemeForm(strtr(_MA_PEDIGREE_ADD_DOG, array('[animalType]' => $pedigree->getConfig('animalType'))), 'dogname', 'add_dog.php?f=checkName', 'POST');
66
    $form->addElement(new XoopsFormHiddenToken($name = 'XOOPS_TOKEN_REQUEST', $timeout = 360));
67
    //create random value
68
    $random = (mt_rand() % 10000);
69
    $form->addElement(new XoopsFormHidden('random', $random));
70
    //find userid
71
    $form->addElement(new XoopsFormHidden('user', $xoopsUser->getVar('uid')));
72
73
    //name
74
    $form->addElement(new XoopsFormText('<b>' . _MA_PEDIGREE_FLD_NAME . '</b>', 'NAAM', $size = 50, $maxsize = 255, $value = ''));
75
    $string = strtr(_MA_PEDIGREE_FLD_NAME_EX, array('[animalType]' => $pedigree->getConfig('animalType')));
76
    $form->addElement(new XoopsFormLabel(_MA_PEDIGREE_EXPLAIN, $string));
77
78
    //submit button
79
    $form->addElement(new XoopsFormButton('', 'button_id', strtr(_MA_PEDIGREE_ADD_DATA, array('[animalType]' => $pedigree->getConfig('animalType'))), 'submit'));
80
81
    //add data (form) to smarty template
82
    $xoopsTpl->assign('form', $form->render());
83
}
84
85
function checkName()
86
{
87
    //configure global variables
88
    global $xoopsTpl, $xoopsDB, $xoopsUser, $pedigree;
89
/*
90
    //get module configuration
91
    $moduleHandler = xoops_getHandler('module');
92
    $module        = $moduleHandler->getByDirname('pedigree');
93
    $configHandler = xoops_getHandler('config');
94
    $moduleConfig  = $configHandler->getConfigsByCat(0, $module->getVar('mid'));
95
*/
96
    $name = XoopsRequest::getString('NAAM', '', 'POST');
97
    //query
98
    //$queryString = 'SELECT * from ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . " WHERE NAAM LIKE'%" . $name . "%' ORDER BY NAAM";
99
    $queryString = 'SELECT * FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . " WHERE NAAM LIKE'%" . $GLOBALS['xoopsDB']->escape($name) . "%' ORDER BY NAAM";
100
    $result      = $GLOBALS['xoopsDB']->query($queryString);
101
    $numresults  = $GLOBALS['xoopsDB']->getRowsNum($result);
102
    if ($numresults >= 1 && !isset($_GET['r'])) {
103
        //create form
104
        include XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
105
        $form = new XoopsThemeForm(strtr(_MA_PEDIGREE_ADD_DOG, array('[animalType]' => $pedigree->getConfig('animalType'))), 'dogname', 'add_dog.php?f=checkName&r=1', 'POST');
106
        //other elements
107
        $form->addElement(new XoopsFormHiddenToken($name = 'XOOPS_TOKEN_REQUEST', $timeout = 360));
108
        $form->addElement(new XoopsFormHidden('NAAM', $_POST['NAAM']));
109
        $form->addElement(new XoopsFormHidden('user', $xoopsUser->getVar('uid')));
110
        while ($row = $GLOBALS['xoopsDB']->fetchBoth($result)) {
111
            //name
112
            $form->addElement(new XoopsFormLabel('<b>' . _MA_PEDIGREE_FLD_NAME . '</b>', "<a href=\"dog.php?Id=" . $row['Id'] . "\">" . stripslashes($row['NAAM']) . '</a>'));
113
        }
114
        $form->addElement(new XoopsFormLabel(_MA_PEDIGREE_EXPLAIN, strtr(_MA_PEDIGREE_ADD_KNOWN, array('[animalTypes]' => $pedigree->getConfig('animalTypes')))));
115
        //submit button
116
        $form->addElement(new XoopsFormButton('', 'button_id', strtr(_MA_PEDIGREE_ADD_KNOWNOK, array('[animalType]' => $pedigree->getConfig('animalType'))), 'submit'));
117
        //add data (form) to smarty template
118
        $xoopsTpl->assign('form', $form->render());
119
    } else {
120
        //create form
121
        include XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
122
        $form = new XoopsThemeForm(strtr(_MA_PEDIGREE_ADD_DOG, array('[animalType]' => $pedigree->getConfig('animalType'))), 'dogname', 'add_dog.php?f=sire', 'POST');
123
        //added to handle upload
124
        $form->setExtra("enctype='multipart/form-data'");
125
        $form->addElement(new XoopsFormHiddenToken($name = 'XOOPS_TOKEN_REQUEST', $timeout = 360));
126
        //create random value
127
        $random = (mt_rand() % 10000);
128
        $form->addElement(new XoopsFormHidden('random', $random));
129
        $form->addElement(new XoopsFormHidden('NAAM', htmlspecialchars($_POST['NAAM'], ENT_QUOTES)));
130
        //find userid from previous form
131
        $form->addElement(new XoopsFormHidden('user', $_POST['user']));
132
133
        //name
134
        $form->addElement(new XoopsFormLabel('<b>' . _MA_PEDIGREE_FLD_NAME . '</b>', stripslashes($_POST['NAAM'])));
135
        //gender
136
        $gender_radio = new XoopsFormRadio('<b>' . _MA_PEDIGREE_FLD_GEND . '</b>', 'roft', $value = '0');
137
        $gender_radio->addOptionArray(array('0' => strtr(_MA_PEDIGREE_FLD_MALE, array('[male]' => $pedigree->getConfig('male'))), '1' => strtr(_MA_PEDIGREE_FLD_FEMA, array('[female]' => $pedigree->getConfig('female')))));
138
        $form->addElement($gender_radio);
139
        if ('1' == $pedigree->getConfig('ownerbreeder')) {
140
            //breeder
141
            $breeder_select = new XoopsFormSelect('<b>' . _MA_PEDIGREE_FLD_BREE . '</b>', $name = 'id_breeder', $value = '0', $size = 1, $multiple = false);
142
            $queryfok       = 'SELECT Id, lastname, firstname from ' . $GLOBALS['xoopsDB']->prefix('pedigree_owner') . ' ORDER BY lastname';
143
            $resfok         = $GLOBALS['xoopsDB']->query($queryfok);
144
            $breeder_select->addOption('0', $name = _MA_PEDIGREE_UNKNOWN);
145
            while (false !== ($rowfok = $GLOBALS['xoopsDB']->fetchArray($resfok))) {
146
                $breeder_select->addOption($rowfok['Id'], $name = $rowfok['lastname'] . ', ' . $rowfok['firstname']);
147
            }
148
            $form->addElement($breeder_select);
149
            $form->addElement(new XoopsFormLabel(_MA_PEDIGREE_EXPLAIN, strtr(_MA_PEDIGREE_FLD_BREE_EX, array('[animalType]' => $pedigree->getConfig('animalType')))));
150
151
            //owner
152
            $owner_select = new XoopsFormSelect('<b>' . _MA_PEDIGREE_FLD_OWNE . '</b>', $name = 'id_owner', $value = '0', $size = 1, $multiple = false);
153
            $queryfok     = 'SELECT Id, lastname, firstname from ' . $GLOBALS['xoopsDB']->prefix('pedigree_owner') . ' ORDER BY lastname';
154
            $resfok       = $GLOBALS['xoopsDB']->query($queryfok);
155
            $owner_select->addOption('0', $name = _MA_PEDIGREE_UNKNOWN);
156
            while (false !== ($rowfok = $GLOBALS['xoopsDB']->fetchArray($resfok))) {
157
                $owner_select->addOption($rowfok['Id'], $name = $rowfok['lastname'] . ', ' . $rowfok['firstname']);
158
            }
159
            $form->addElement($owner_select);
160
            $form->addElement(new XoopsFormLabel(_MA_PEDIGREE_EXPLAIN, strtr(_MA_PEDIGREE_FLD_OWNE_EX, array('[animalType]' => $pedigree->getConfig('animalType')))));
161
        }
162
        //picture
163
        $max_imgsize = 1024000;
164
        $img_box     = new XoopsFormFile('Image', 'photo', $max_imgsize);
165
        $img_box->setExtra("size ='50'");
166
        $form->addElement($img_box);
167
168
        //create animal object
169
        $animal = new PedigreeAnimal();
170
        //test to find out how many user fields there are..
171
        $fields = $animal->getNumOfFields();
172
173
        for ($i = 0, $iMax = count($fields); $i < $iMax; ++$i) {
174
            $userField   = new PedigreeField($fields[$i], $animal->getConfig());
175
            $fieldType   = $userField->getSetting('fieldtype');
176
            $fieldObject = new $fieldType($userField, $animal);
177
            if ($userField->isActive() && !$userField->isLocked()) {
178
                $newEntry = $fieldObject->newField();
179
                $form->addElement($newEntry);
180
            }
181
            unset($newEntry);
182
        }
183
184
        //submit button
185
        $form->addElement(new XoopsFormButton('', 'button_id', strtr(_MA_PEDIGREE_ADD_SIRE, array('[father]' => $pedigree->getConfig('father'))), 'submit'));
186
187
        //add data (form) to smarty template
188
        $xoopsTpl->assign('form', $form->render());
189
    }
190
}
191
192
function sire() {
193
    global $xoopsTpl, $xoopsUser, $xoopsDB, $pedigree;
194
/*
195
    //get module configuration
196
    $moduleHandler = xoops_getHandler('module');
197
    $module        = $moduleHandler->getByDirname('pedigree');
198
    $configHandler = xoops_getHandler('config');
199
    $moduleConfig  = $configHandler->getConfigsByCat(0, $module->getVar('mid'));
200
    $empty         = array(); // an empty array
201
*/
202
    //check for access
203
    if (!$xoopsUser instanceof XoopsUser) {
204
        redirect_header('javascript:history.go(-1)', 3, _NOPERM . '<br />' . _MA_PEDIGREE_REGIST);
205
    }
206
//    $user       = isset($_POST['user']) ? $_POST['user'] : null;
207
    $user       = XoopsRequest::getString('user', null, 'POST');
208
    $random     = (empty($random)) ? XoopsRequest::getString('random', null) : $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...
209
    $st         = (empty($st)) ? XoopsRequest::getInt('st', 0) : $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...
210
    $name       = XoopsRequest::getString('NAAM', '', 'POST');
211
    $roft       = XoopsRequest::getString('roft', '');
212
    $id_owner   = XoopsRequest::getInt('id_owner', 0);
213
    $id_breeder = XoopsRequest::getInt('id_breeder', 0);
214
/*
215
    if (empty($random)) {
216
        $random = isset($_POST['random']) ? $_POST['random'] : null;
217
    }
218
    if (isset($_GET['random'])) {
219
        $random = $_GET['random'];
220
    }
221
222
    if (empty($st)) {
223
        $st = 0;
224
    }
225
    if (isset($_GET['st'])) {
226
        $st = $_GET['st'];
227
    }
228
229
    $name = isset($_POST['NAAM']) ? $_POST['NAAM'] : null;
230
    $roft = isset($_POST['roft']) ? $_POST['roft'] : null;
231
232
    $id_owner   = isset($_POST['id_owner']) ? $_POST['id_owner'] : null;
233
    $id_breeder = isset($_POST['id_breeder']) ? $_POST['id_breeder'] : null;
234
*/
235
    $picturefield = isset($_FILES['photo']) ? $_FILES['photo']['name'] : null; // $_FILES['photo']['name'];
236
    $foto = (empty($picturefield) || $picturefield == '') ? '' : PedigreeUtilities::uploadPicture(0);
237
238
    $numpicturefield = 1;
239
240
    //make the redirect
241
    if (!isset($_GET['r'])) {
242
        if ('' == $name) {
243
            redirect_header('add_dog.php', 1, _MA_PEDIGREE_ADD_NAMEPLZ);
244
        }
245
        //create animal object
246
        $animal = new PedigreeAnimal();
247
        //test to find out how many user fields there are..
248
        $fields = $animal->getNumOfFields();
249
        sort($fields); //sort by Id not by order
250
        $usersql = '';
251
        for ($i = 0, $iMax = count($fields); $i < $iMax; ++$i) {
252
            $userField   = new PedigreeField($fields[$i], $animal->getConfig());
253
            $fieldType   = $userField->getSetting('fieldtype');
254
            $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...
255
            if ($userField->isActive()) {
256
                //check if _FILES variable exists for user picturefield
257
                $currentfield = 'user' . $fields[$i];
258
                $picturefield = $_FILES[$currentfield]['name'];
259
                if ($fieldType === 'Picture' && (!empty($picturefield) || $picturefield != '')) {
260
                    $userpicture = PedigreeUtilities::uploadPicture($numpicturefield);
261
                    $usersql .= ",'" . $userpicture . "'";
262
                    ++$numpicturefield;
263
                } elseif ($userField->isLocked()) {
264
                    //userfield is locked, substitute default value
265
                    $usersql .= ",'" . $userField->defaultvalue . "'";
266
                } else {
267
                    //echo $fieldType.":".$i.":".$fields[$i]."<br />";
268
                    $usersql .= ",'" . PedigreeUtilities::unHtmlEntities($_POST['user' . $fields[$i]]) . "'";
269
                }
270
            } else {
271
                $usersql .= ",''";
272
            }
273
            //echo $fields[$i]."<br/>";
274
        }
275
276
        //insert into pedigree_temp
277
        //        $query = 'INSERT INTO ' . $GLOBALS['xoopsDB']->prefix('pedigree_temp') . " VALUES ('" . $random . "','" . PedigreeUtilities::unHtmlEntities($name) . "','" . $id_owner . "','" . $id_breeder . "','" . $user . "','" . $roft . "','','','" . $foto . "', ''" . $usersql . ')';
278
        $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 . ')';
0 ignored issues
show
Bug introduced by
The function unHtmlEntities 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

278
        $query = 'INSERT INTO ' . $GLOBALS['xoopsDB']->prefix('pedigree_temp') . " VALUES ('" . $GLOBALS['xoopsDB']->escape($random) . "','" . $GLOBALS['xoopsDB']->escape(/** @scrutinizer ignore-call */ 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 . ')';
Loading history...
279
        //echo $query; die();
280
        $GLOBALS['xoopsDB']->query($query);
281
        redirect_header('add_dog.php?f=sire&random=' . $random . '&st=' . $st . '&r=1&l=a', 1, strtr(_MA_PEDIGREE_ADD_SIREPLZ, array('[father]' => $pedigree->getConfig('father'))));
282
    }
283
    //find letter on which to start else set to 'a'
284
    $l = XoopsRequest::getCmd('l', 'a', 'GET');
285
    //assign sire to template
286
    $xoopsTpl->assign('sire', '1');
287
    //create list of males dog to select from
288
    $perp = $pedigree->getConfig('perpage');
289
    //count total number of dogs
290
    $numdog = 'SELECT COUNT(Id) FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . " WHERE roft='0' AND NAAM LIKE '" . $l . "%'";
291
    $numres = $GLOBALS['xoopsDB']->query($numdog);
292
    //total number of dogs the query will find
293
    list($numresults) = $GLOBALS['xoopsDB']->fetchRow($numres);
294
    //total number of pages
295
    $numpages = floor($numresults / $perp) + 1;
296
    if (($numpages * $perp) == ($numresults + $perp)) {
297
        --$numpages ;
298
    }
299
    //find current page
300
    $cpage = floor($st / $perp) + 1;
301
    //create alphabet
302
    $pages = '';
303
    for ($i = 65; $i <= 90; ++$i) {
304
        if ($l == chr($i)) {
305
            $pages .= "<b><a href=\"add_dog.php?f=sire&r=1&random=" . $random . '&l=' . chr($i) . "\">" . chr($i) . '</a></b>&nbsp;';
306
        } else {
307
            $pages .= "<a href=\"add_dog.php?f=sire&r=1&random=" . $random . '&l=' . chr($i) . "\">" . chr($i) . '</a>&nbsp;';
308
        }
309
    }
310
    $pages .= '-&nbsp;';
311
    $pages .= "<a href=\"add_dog.php?f=sire&r=1&random=" . $random . "&l=Ã…\">Ã…</a>&nbsp;";
312
    $pages .= "<a href=\"add_dog.php?f=sire&r=1&random=" . $random . "&l=Ö\">Ö</a>&nbsp;";
313
    //create linebreak
314
    $pages .= '<br />';
315
    //create previous button
316
    if ($numpages > 1) {
317
        if ($cpage > 1) {
318
            $pages .= "<a href=\"add_dog.php?f=sire&r=1&l=" . $l . '&random=' . $random . '&st=' . ($st - $perp) . "\">" . _MA_PEDIGREE_PREVIOUS . '</a>&nbsp;&nbsp';
319
        }
320
    }
321
    //create numbers
322
    for ($x = 1; $x < ($numpages + 1); ++$x) {
323
        //create line break after 20 number
324
        if (($x % 20) == 0) {
325
            $pages .= '<br />';
326
        }
327
        if ($x != $cpage) {
328
            $pages .= "<a href=\"add_dog.php?f=sire&r=1&l=" . $l . '&random=' . $random . '&st=' . ($perp * ($x - 1)) . "\">" . $x . '</a>&nbsp;&nbsp;';
329
        } else {
330
            $pages .= $x . '&nbsp;&nbsp';
331
        }
332
    }
333
    //create next button
334
    if ($numpages > 1) {
335
        if ($cpage < $numpages) {
336
            $pages .= "<a href=\"add_dog.php?f=sire&r=1&l=" . $l . '&random=' . $random . '&st=' . ($st + $perp) . "\">" . _MA_PEDIGREE_NEXT . '</a>&nbsp;&nbsp';
337
        }
338
    }
339
340
    //query
341
    $queryString = 'SELECT * from ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . " WHERE roft = '0' and NAAM like '" . $l . "%'ORDER BY NAAM LIMIT " . $st . ', ' . $perp;
342
    $result      = $GLOBALS['xoopsDB']->query($queryString);
343
344
    $animal = new PedigreeAnimal();
345
    //test to find out how many user fields there are...
346
    $fields       = $animal->getNumOfFields();
347
    $numofcolumns = 1;
348
    $columns[]    = array('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...
349
    for ($i = 0, $iMax = count($fields); $i < $iMax; ++$i) {
350
        $userField   = new PedigreeField($fields[$i], $animal->getConfig());
351
        $fieldType   = $userField->getSetting('fieldtype');
352
        $fieldObject = new $fieldType($userField, $animal);
353
        //create empty string
354
        $lookupvalues = '';
355
        if ($userField->isActive() && $userField->inList()) {
356
            if ($userField->hasLookup()) {
357
                $lookupvalues = $userField->lookupField($fields[$i]);
358
                //debug information
359
                //print_r($lookupvalues);
360
            }
361
            $columns[] = array('columnname' => $fieldObject->fieldname, 'columnnumber' => $userField->getId(), 'lookupval' => $lookupvalues);
362
            ++$numofcolumns;
363
            unset($lookupvalues);
364
        }
365
    }
366
367
    for ($i = 1; $i < $numofcolumns; ++$i) {
368
        $empty[] = array('value' => '');
369
    }
370
    $dogs [] = array(
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...
371
        'id'          => '0',
372
        'name'        => '',
373
        'gender'      => '',
374
        'link'        => "<a href=\"add_dog.php?f=dam&random=" . $random . "&selsire=0\">" . strtr(_MA_PEDIGREE_ADD_SIREUNKNOWN, array('[father]' => $pedigree->getConfig('father'))) . '</a>',
375
        'colour'      => '',
376
        'number'      => '',
377
        'usercolumns' => $empty
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $empty does not seem to be defined for all execution paths leading up to this point.
Loading history...
378
    );
379
380
    while (false !== ($row = $GLOBALS['xoopsDB']->fetchArray($result))) {
381
        //create picture information
382
        if ($row['foto'] != '') {
383
            $camera = " <img src=\"assets/images/camera.png\">";
384
        } else {
385
            $camera = '';
386
        }
387
        $name = stripslashes($row['NAAM']) . $camera;
388
        //empty array
389
        unset($columnvalue);
390
        //fill array
391
        for ($i = 1; $i < $numofcolumns; ++$i) {
392
            $x = $columns[$i]['columnnumber'];
393
            if (is_array($columns[$i]['lookupval'])) {
394
                foreach ($columns[$i]['lookupval'] as $key => $keyvalue) {
395
                    if ($key == $row['user' . $x]) {
396
                        $value = $keyvalue['value'];
397
                    }
398
                }
399
                //debug information
400
                ///echo $columns[$i]['columnname']."is an array !";
401
            } //format value - cant use object because of query count
402
            elseif (0 === strpos($row['user' . $x], 'http://')) {
403
                $value = "<a href=\"" . $row['user' . $x] . "\">" . $row['user' . $x] . '</a>';
404
            } else {
405
                $value = $row['user' . $x];
406
            }
407
            $columnvalue[] = array('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...
408
        }
409
        $dogs[] = array(
410
            'id'          => $row['Id'],
411
            'name'        => $name,
412
            'gender'      => '<img src="assets/images/male.gif">',
413
            'link'        => "<a href=\"add_dog.php?f=dam&random=" . $random . '&selsire=' . $row['Id'] . "\">" . $name . '</a>',
414
            'colour'      => '',
415
            'number'      => '',
416
            '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...
417
        );
418
    }
419
420
    //add data to smarty template
421
    //assign dog
422
    $xoopsTpl->assign('dogs', $dogs);
423
    $xoopsTpl->assign('columns', $columns);
424
    $xoopsTpl->assign('numofcolumns', $numofcolumns);
425
    $xoopsTpl->assign('tsarray', PedigreeUtilities::sortTable($numofcolumns));
426
    //assign links
427
    $xoopsTpl->assign('nummatch', strtr(_MA_PEDIGREE_ADD_SELSIRE, array('[father]' => $pedigree->getConfig('father'))));
428
    $xoopsTpl->assign('pages', $pages);
429
}
430
431
function dam()
432
{
433
    global $xoopsTpl, $xoopsUser, $xoopsDB, $pedigree;
434
435
    //get module configuration
436
    $moduleHandler = xoops_getHandler('module');
437
    $module        = $moduleHandler->getByDirname('pedigree');
0 ignored issues
show
Bug introduced by
The method getByDirname() does not exist on XoopsObjectHandler. It seems like you code against a sub-type of XoopsObjectHandler such as XoopsModuleHandler or XoopsPersistableObjectHandler. ( Ignorable by Annotation )

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

437
    /** @scrutinizer ignore-call */ 
438
    $module        = $moduleHandler->getByDirname('pedigree');
Loading history...
438
    $configHandler = xoops_getHandler('config');
439
    $moduleConfig  = $configHandler->getConfigsByCat(0, $module->getVar('mid'));
0 ignored issues
show
Unused Code introduced by
The assignment to $moduleConfig is dead and can be removed.
Loading history...
Bug introduced by
The method getConfigsByCat() does not exist on XoopsObjectHandler. It seems like you code against a sub-type of XoopsObjectHandler such as XoopsPersistableObjectHandler. ( Ignorable by Annotation )

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

439
    /** @scrutinizer ignore-call */ 
440
    $moduleConfig  = $configHandler->getConfigsByCat(0, $module->getVar('mid'));
Loading history...
440
    $empty         = array(); // an empty array
441
442
    //check for access
443
    $xoopsModule = XoopsModule::getByDirname('pedigree');
0 ignored issues
show
Unused Code introduced by
The assignment to $xoopsModule is dead and can be removed.
Loading history...
444
    if (empty($xoopsUser)) {
445
        redirect_header('javascript:history.go(-1)', 3, _NOPERM . '<br />' . _MA_PEDIGREE_REGIST);
446
    }
447
    //    if (empty($random)) {
448
    //$random = isset($_POST['random']) ? $_POST['random'] : null;
449
    //}
450
    //if (isset($_GET['random'])) {
451
    //$random = $_GET['random'];
452
    //}
453
    //if (empty($st)) {
454
    //$st = 0;
455
    //}
456
    //if (isset($_GET['st'])) {
457
    //$st = $_GET['st'];
458
    //}
459
    $random = XoopsRequest::getInt('random', 0);
460
    $st     = XoopsRequest::getInt('st', 0, 'get');
461
    //find letter on which to start else set to 'a'
462
    //    if (isset($_GET['l'])) {
463
    //        $l = $_GET['l'];
464
    //    } else {
465
    //        $l = 'a';
466
    //    }
467
    $l = XoopsRequest::getString('l', 'a', 'get');
468
    //make the redirect
469
    if (!isset($_GET['r'])) {
470
        //insert into pedigree_temp
471
        //        $query = 'UPDATE ' . $GLOBALS['xoopsDB']->prefix('pedigree_temp') . ' SET father =' . $_GET['selsire'] . ' WHERE ID=' . $random;
472
        //        $GLOBALS['xoopsDB']->queryF($query);
473
        $query = 'UPDATE ' . $GLOBALS['xoopsDB']->prefix('pedigree_temp') . ' SET father =' . XoopsRequest::getInt('selsire', 0, 'get') . ' WHERE Id=' . $random;
474
        $GLOBALS['xoopsDB']->queryF($query);
475
        redirect_header('add_dog.php?f=dam&random=' . $random . '&st=' . $st . '&r=1&l=a', 1, strtr(_MA_PEDIGREE_ADD_SIREOK, array('[mother]' => $pedigree->getConfig('mother'))));
476
    }
477
478
    $xoopsTpl->assign('sire', '1');
479
    //create list of males dog to select from
480
    $perp = $pedigree->getConfig('perpage');
481
    //count total number of dogs
482
    $numdog = 'SELECT COUNT(Id) FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . " WHERE roft='1' AND NAAM LIKE '" . $l . "%'";
483
    $numres = $GLOBALS['xoopsDB']->query($numdog);
484
    list($numresults) = $GLOBALS['xoopsDB']->fetchRow($numres);
485
    $numpages = floor($numresults / $perp) + 1;
486
    if (($numpages * $perp) == ($numresults + $perp)) {
487
        --$numpages;
488
    }
489
    $cpage = floor($st / $perp) + 1;
490
    //create alphabet
491
    $pages = '';
492
    for ($i = 65; $i <= 90; ++$i) {
493
        if ($l == chr($i)) {
494
            $pages .= "<b><a href=\"add_dog.php?f=dam&r=1&random=" . $random . '&l=' . chr($i) . "\">" . chr($i) . '</a></b>&nbsp;';
495
        } else {
496
            $pages .= "<a href=\"add_dog.php?f=dam&r=1&random=" . $random . '&l=' . chr($i) . "\">" . chr($i) . '</a>&nbsp;';
497
        }
498
    }
499
    $pages .= '-&nbsp;';
500
    $pages .= "<a href=\"add_dog.php?f=dam&r=1&random=" . $random . "&l=Ã…\">Ã…</a>&nbsp;";
501
    $pages .= "<a href=\"add_dog.php?f=dam&r=1&random=" . $random . "&l=Ö\">Ö</a>&nbsp;";
502
    $pages .= '<br />';
503
    //create previous button
504
    if ($numpages > 1) {
505
        if ($cpage > 1) {
506
            $pages .= "<a href=\"add_dog.php?f=dam&r=1&l=" . $l . '&random=' . $random . '&st=' . ($st - $perp) . "\">" . _MA_PEDIGREE_PREVIOUS . '</a>&nbsp;&nbsp';
507
        }
508
    }
509
    //create numbers
510
    for ($x = 1; $x < ($numpages + 1); ++$x) {
511
        //create line break after 20 number
512
        if (($x % 20) == 0) {
513
            $pages .= '<br />';
514
        }
515
        if ($x != $cpage) {
516
            $pages .= "<a href=\"add_dog.php?f=dam&r=1&l=" . $l . '&random=' . $random . '&st=' . ($perp * ($x - 1)) . "\">" . $x . '</a>&nbsp;&nbsp;';
517
        } else {
518
            $pages .= $x . '&nbsp;&nbsp';
519
        }
520
    }
521
    //create next button
522
    if ($numpages > 1) {
523
        if ($cpage < $numpages) {
524
            $pages .= "<a href=\"add_dog.php?f=dam&l=" . $l . '&r=1&random=' . $random . '&st=' . ($st + $perp) . "\">" . _MA_PEDIGREE_NEXT . '</a>&nbsp;&nbsp;';
525
        }
526
    }
527
528
    //query
529
    $queryString = 'SELECT * from ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . " WHERE roft = '1' and NAAM LIKE '" . $l . "%' ORDER BY NAAM LIMIT " . $st . ', ' . $perp;
530
    $result      = $GLOBALS['xoopsDB']->query($queryString);
531
532
    $animal = new PedigreeAnimal();
533
    //test to find out how many user fields there are...
534
    $fields       = $animal->getNumOfFields();
535
    $numofcolumns = 1;
536
    $columns[]    = array('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...
537
    for ($i = 0, $iMax = count($fields); $i < $iMax; ++$i) {
538
        $userField   = new PedigreeField($fields[$i], $animal->getConfig());
539
        $fieldType   = $userField->getSetting('fieldtype');
540
        $fieldObject = new $fieldType($userField, $animal);
541
        //create empty string
542
        $lookupvalues = '';
543
        if ($userField->isActive() && $userField->inList()) {
544
            if ($userField->hasLookup()) {
545
                $lookupvalues = $userField->lookupField($fields[$i]);
546
                //debug information
547
                //print_r($lookupvalues);
548
            }
549
            $columns[] = array('columnname' => $fieldObject->fieldname, 'columnnumber' => $userField->getId(), 'lookupval' => $lookupvalues);
550
            ++$numofcolumns;
551
            unset($lookupvalues);
552
        }
553
    }
554
555
    for ($i = 1; $i < $numofcolumns; ++$i) {
556
        $empty[] = array('value' => '');
557
    }
558
    $dogs [] = array(
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...
559
        'id'          => '0',
560
        'name'        => '',
561
        'gender'      => '',
562
        'link'        => "<a href=\"add_dog.php?f=check&random=" . $random . "&seldam=0\">" . strtr(_MA_PEDIGREE_ADD_DAMUNKNOWN, array('[mother]' => $pedigree->getConfig('mother'))) . '</a>',
563
        'colour'      => '',
564
        'number'      => '',
565
        'usercolumns' => $empty
566
    );
567
568
    while (false !== ($row = $GLOBALS['xoopsDB']->fetchArray($result))) {
569
        //create picture information
570
        if ($row['foto'] != '') {
571
            $camera = " <img src=\"assets/images/camera.png\">";
572
        } else {
573
            $camera = '';
574
        }
575
        $name = stripslashes($row['NAAM']) . $camera;
576
        //empty array
577
        unset($columnvalue);
578
        //fill array
579
        for ($i = 1; $i < $numofcolumns; ++$i) {
580
            $x = $columns[$i]['columnnumber'];
581
            if (is_array($columns[$i]['lookupval'])) {
582
                foreach ($columns[$i]['lookupval'] as $key => $keyvalue) {
583
                    if ($key == $row['user' . $x]) {
584
                        $value = $keyvalue['value'];
585
                    }
586
                }
587
                //debug information
588
                ///echo $columns[$i]['columnname']."is an array !";
589
            } //format value - cant use object because of query count
590
            elseif (0 === strpos($row['user' . $x], 'http://')) {
591
                $value = "<a href=\"" . $row['user' . $x] . "\">" . $row['user' . $x] . '</a>';
592
            } else {
593
                $value = $row['user' . $x];
594
            }
595
            $columnvalue[] = array('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...
596
        }
597
        $dogs[] = array(
598
            'id'          => $row['Id'],
599
            'name'        => $name,
600
            'gender'      => '<img src="assets/images/female.gif">',
601
            'link'        => "<a href=\"add_dog.php?f=check&random=" . $random . '&seldam=' . $row['Id'] . "\">" . $name . '</a>',
602
            'colour'      => '',
603
            'number'      => '',
604
            '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...
605
        );
606
    }
607
608
    //add data to smarty template
609
    //assign dog
610
    $xoopsTpl->assign('dogs', $dogs);
611
    $xoopsTpl->assign('columns', $columns);
612
    $xoopsTpl->assign('numofcolumns', $numofcolumns);
613
    $xoopsTpl->assign('tsarray', PedigreeUtilities::sortTable($numofcolumns));
614
    $xoopsTpl->assign('nummatch', strtr(_MA_PEDIGREE_ADD_SELDAM, array('[mother]' => $pedigree->getConfig('mother'))));
615
    $xoopsTpl->assign('pages', $pages);
616
}
617
618
function check()
619
{
620
    global $xoopsTpl, $xoopsUser, $xoopsDB, $pedigree;
621
622
    //get module configuration
623
    $moduleHandler = xoops_getHandler('module');
624
    $module        = $moduleHandler->getByDirname('pedigree');
625
    $configHandler = xoops_getHandler('config');
626
    $moduleConfig  = $configHandler->getConfigsByCat(0, $module->getVar('mid'));
0 ignored issues
show
Unused Code introduced by
The assignment to $moduleConfig is dead and can be removed.
Loading history...
627
628
    //check for access
629
    $xoopsModule = XoopsModule::getByDirname('pedigree');
0 ignored issues
show
Unused Code introduced by
The assignment to $xoopsModule is dead and can be removed.
Loading history...
630
    if (empty($xoopsUser)) {
631
        redirect_header('index.php', 3, _NOPERM . '<br />' . _MA_PEDIGREE_REGIST);
632
    }
633
    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...
634
        $random = $_POST['random'];
635
    }
636
    if (isset($_GET['random'])) {
637
        $random = $_GET['random'];
638
    }
639
640
    //query
641
    $queryString = 'SELECT * FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_temp') . ' WHERE Id = ' . $random;
642
    $result      = $GLOBALS['xoopsDB']->query($queryString);
643
    while (false !== ($row = $GLOBALS['xoopsDB']->fetchArray($result))) {
644
        //create animal object
645
        $animal = new PedigreeAnimal();
646
        //test to find out how many user fields there are..
647
        $fields = $animal->getNumOfFields();
648
        sort($fields);
649
        $usersql = '';
650
        for ($i = 0, $iMax = count($fields); $i < $iMax; ++$i) {
651
            $userField   = new PedigreeField($fields[$i], $animal->getConfig());
652
            $fieldType   = $userField->getSetting('fieldtype');
653
            $fieldObject = new $fieldType($userField, $animal);
654
            if ($userField->isActive()) {
655
                $usersql .= ",'" . addslashes($row['user' . $fields[$i]]) . "'";
656
            } else {
657
                $usersql .= ",'" . $fieldObject->defaultvalue . "'";
658
            }
659
            //echo $fields[$i]."<br/>";
660
        }
661
        //insert into pedigree
662
        //$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 . ')';
663
        $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 . ')';
664
        $GLOBALS['xoopsDB']->queryF($query);
665
        //echo $query; die();
666
    }
667
    $sqlquery = 'DELETE FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_temp') . " WHERE Id='" . $random . "'";
668
    $GLOBALS['xoopsDB']->queryF($sqlquery);
669
    redirect_header('latest.php', 1, strtr(_MA_PEDIGREE_ADD_OK, array('[animalType]' => $pedigree->getConfig('animalType'))));
670
}
671
672
//footer
673
include XOOPS_ROOT_PATH . '/footer.php';
674