Issues (807)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  Header Injection
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

add_dog.php (4 issues)

1
<?php
2
/*
3
 You may not change or alter any portion of this comment or credits of
4
 supporting developers from this source code or any supporting source code
5
 which is considered copyrighted (c) material of the original comment or credit
6
 authors.
7
8
 This program is distributed in the hope that it will be useful, but
9
 WITHOUT ANY WARRANTY; without even the implied warranty of
10
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11
 */
12
13
/**
14
 * Module: Pedigree
15
 *
16
 * @package   XoopsModules\Pedigree
17
 * @author    XOOPS Module Development Team
18
 * @copyright Copyright (c) 2001-2019 {@link https://xoops.org XOOPS Project}
19
 * @license   https://www.gnu.org/licenses/gpl-2.0.html GNU Public License
20
 */
21
22
use Xmf\Request;
23
use XoopsModules\Pedigree;
24
use XoopsModules\Pedigree\Constants;
25
26
require_once __DIR__ . '/header.php';
27
/** @var \XoopsModules\Pedigree\Helper $helper */
28
$helper->loadLanguage('main');
29
30
$GLOBALS['xoopsOption']['template_main'] = 'pedigree_adddog.tpl';
31
require XOOPS_ROOT_PATH . '/header.php';
32
$GLOBALS['xoopsTpl']->assign('page_title', _MA_PEDIGREE_UPDATE);
33
34
//check for access
35
$xoopsModule = XoopsModule::getByDirname($moduleDirName);
36
if (empty($GLOBALS['xoopsUser']) || !$GLOBALS['xoopsUser'] instanceof \XoopsUser || $GLOBALS['xoopsUser']->isGuest()) {
37
    $helper->redirect('', Constants::REDIRECT_DELAY_MEDIUM, _NOPERM . '<br>' . _MA_PEDIGREE_REGIST);
38
}
39
40
//create function variable from url
41
//if (isset($_GET['f'])) {
42
//    $f = $_GET['f'];
43
//} else {
44
//    $f = '';
45
//    addDog();
46
//}
47
48
$f      = Request::getString('f', '', 'GET');
49
$random = '';
50
51
switch ($f) {
52
    case 'checkName':
53
        $name        = Request::getString('pname', '', 'POST');
54
        $sql = 'SELECT * FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_registry') . " WHERE pname LIKE'%" . $GLOBALS['xoopsDB']->escape($name) . "%' ORDER BY pname";
55
        $result      = $GLOBALS['xoopsDB']->query($sql);
56
        $numResults  = $GLOBALS['xoopsDB']->getRowsNum($result);
57
        if ($numResults >= 1 && !isset($_GET['r'])) {
58
            //create form
59
            require XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
60
            $form = new \XoopsThemeForm(strtr(_MA_PEDIGREE_ADD_DOG, ['[animalType]' => $helper->getConfig('animalType')]), 'dogname', 'add_dog.php?f=checkName&r=1', 'post');
61
            $form->addElement(new \XoopsFormHiddenToken($name = 'XOOPS_TOKEN_REQUEST', $timeout = Constants::TOKEN_TIMEOUT));
62
            $form->addElement(new \XoopsFormHidden('pname', $name));
63
            $form->addElement(new \XoopsFormHidden('user', $GLOBALS['xoopsUser']->getVar('uid')));
64
            while (false !== ($row = $GLOBALS['xoopsDB']->fetchBoth($result))) {
65
                $form->addElement(new \XoopsFormLabel('<b>' . _MA_PEDIGREE_FLD_NAME . '</b>', '<a href="' . $helper->url('dog.php?id=' . $row['id']) . '">' . stripslashes($row['pname']) . '</a>'));
66
            }
67
            $form->addElement(new \XoopsFormLabel(_MA_PEDIGREE_EXPLAIN, strtr(_MA_PEDIGREE_ADD_KNOWN, ['[animalTypes]' => $helper->getConfig('animalTypes')])));
68
            //submit button
69
            $form->addElement(new \XoopsFormButton('', 'button_id', strtr(_MA_PEDIGREE_ADD_KNOWNOK, ['[animalType]' => $helper->getConfig('animalType')]), 'submit'));
70
            //add data (form) to smarty template
71
            $GLOBALS['xoopsTpl']->assign('form', $form->render());
72
        } else {
73
            //create form
74
            require XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
75
            $form = new \XoopsThemeForm(strtr(_MA_PEDIGREE_ADD_DOG, ['[animalType]' => $helper->getConfig('animalType')]), 'dogname', 'add_dog.php?f=sire', 'post');
76
            //added to handle upload
77
            $form->setExtra("enctype='multipart/form-data'");
78
            $form->addElement(new \XoopsFormHiddenToken($name = 'XOOPS_TOKEN_REQUEST', $timeout = Constants::TOKEN_TIMEOUT));
79
            //create random value
80
            $random = (mt_rand() % 10000);
81
            $form->addElement(new \XoopsFormHidden('random', $random));
82
            $form->addElement(new \XoopsFormHidden('pname', htmlspecialchars($name, ENT_QUOTES)));
83
            //find userid from previous form
84
            $form->addElement(new \XoopsFormHidden('user', $GLOBALS['xoopsUser']->getVar('uid')));
85
86
            //name
87
            $form->addElement(new \XoopsFormLabel('<b>' . _MA_PEDIGREE_FLD_NAME . '</b>', stripslashes($name)));
88
            //gender
89
            $gender_radio = new \XoopsFormRadio('<b>' . _MA_PEDIGREE_FLD_GEND . '</b>', 'roft', $value = '0');
90
            $gender_radio->addOptionArray([
91
                                              '0' => strtr(_MA_PEDIGREE_FLD_MALE, ['[male]' => $helper->getConfig('male')]),
92
                                              '1' => strtr(_MA_PEDIGREE_FLD_FEMA, ['[female]' => $helper->getConfig('female')]),
93
                                          ]);
94
            $form->addElement($gender_radio);
95
            if ('1' == $helper->getConfig('ownerbreeder')) {
96
                //breeder
97
                $breeder_select = new \XoopsFormSelect('<b>' . _MA_PEDIGREE_FLD_BREE . '</b>', $name = 'id_breeder', $value = '0', $size = 1, $multiple = false);
98
                $queryfok       = 'SELECT id, lastname, firstname FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_owner') . ' ORDER BY lastname';
99
                $resfok         = $GLOBALS['xoopsDB']->query($queryfok);
100
                $breeder_select->addOption('0', $name = _MA_PEDIGREE_UNKNOWN);
101
                while (false !== ($rowfok = $GLOBALS['xoopsDB']->fetchArray($resfok))) {
102
                    $breeder_select->addOption($rowfok['id'], $name = $rowfok['lastname'] . ', ' . $rowfok['firstname']);
103
                }
104
                $form->addElement($breeder_select);
105
                $form->addElement(new \XoopsFormLabel(_MA_PEDIGREE_EXPLAIN, strtr(_MA_PEDIGREE_FLD_BREE_EX, ['[animalType]' => $helper->getConfig('animalType')])));
106
107
                //owner
108
                $owner_select = new \XoopsFormSelect('<b>' . _MA_PEDIGREE_FLD_OWNE . '</b>', $name = 'id_owner', $value = '0', $size = 1, $multiple = false);
109
                $queryfok     = 'SELECT id, lastname, firstname FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_owner') . ' ORDER BY lastname';
110
                $resfok       = $GLOBALS['xoopsDB']->query($queryfok);
111
                $owner_select->addOption('0', $name = _MA_PEDIGREE_UNKNOWN);
112
                while (false !== ($rowfok = $GLOBALS['xoopsDB']->fetchArray($resfok))) {
113
                    $owner_select->addOption($rowfok['id'], $name = $rowfok['lastname'] . ', ' . $rowfok['firstname']);
114
                }
115
                $form->addElement($owner_select);
116
                $form->addElement(new \XoopsFormLabel(_MA_PEDIGREE_EXPLAIN, strtr(_MA_PEDIGREE_FLD_OWNE_EX, ['[animalType]' => $helper->getConfig('animalType')])));
117
            }
118
            //picture
119
            $max_imgsize = 1024000;
120
            $img_box     = new \XoopsFormFile('Image', 'photo', $max_imgsize);
121
            $img_box->setExtra("size ='50'");
122
            $form->addElement($img_box);
123
124
            //create animal object
125
            $animal = new Pedigree\Animal();
126
            //test to find out how many user fields there are..
127
            $fields = $animal->getNumOfFields();
128
129
            foreach ($fields as $i => $iValue) {
130
                $userField   = new Pedigree\Field($fields[$i], $animal->getConfig());
131
                $fieldType   = $userField->getSetting('fieldtype');
132
                $fieldObject = new $fieldType($userField, $animal);
133
                if ($userField->isActive() && !$userField->isLocked()) {
134
                    $newEntry = $fieldObject->newField();
135
                    $form->addElement($newEntry);
136
                }
137
                unset($newEntry);
138
            }
139
140
            //submit button
141
            $form->addElement(new \XoopsFormButton('', 'button_id', strtr(_MA_PEDIGREE_ADD_SIRE, ['[father]' => $helper->getConfig('father', '')]), 'submit'));
142
143
            //add data (form) to smarty template
144
            $GLOBALS['xoopsTpl']->assign('form', $form->render());
145
        }
146
        break;
147
    case 'sire':
148
        $empty  = []; // an empty array
149
        $user   = Request::getInt('user', null, 'POST');
150
        $random = Request::getString('random', $random, 'GET');
151
        //@todo is $st suppose to be POST?
152
        $st              = Request::getInt('st', 0, 'GET');
153
        $name            = Request::getString('pname', null, 'POST');
154
        $roft            = Request::getString('roft', null, 'POST');
155
        $id_owner        = Request::getInt('id_owner', null, 'POST');
156
        $id_breeder      = Request::getInt('id_breeder', null, 'POST');
157
        $pictureField    = isset($_FILES['photo']) ? $_FILES['photo']['name'] : null; // $_FILES['photo']['name'];
158
        $foto            = (empty($pictureField)) ? '' : Pedigree\Utility::uploadPicture(0);
159
        $numPictureField = 1;
160
161
        //make the redirect
162
        if (!isset($_GET['r'])) {
163
            if (empty($name)) {
164
                $helper->redirect('add_dog.php', 1, _MA_PEDIGREE_ADD_NAMEPLZ);
165
            }
166
            //create animal object
167
            $animal = new Pedigree\Animal();
168
            $fields = $animal->getNumOfFields(); //test to find out how many user fields there are..
169
            sort($fields); //sort by ID not by order
170
            $usersql = '';
171
            foreach ($fields as $i => $iValue) {
172
                $userField   = new Pedigree\Field($fields[$i], $animal->getConfig());
173
                $fieldType   = $userField->getSetting('fieldtype');
174
                $fieldObject = new $fieldType($userField, $animal);
175
                if ($userField->isActive()) {
176
                    //check if _FILES variable exists for user picturefield
177
                    $currentfield = 'user' . $iValue;
178
                    $pictureField = $_FILES[$currentfield]['name'];
179
                    if ('Picture' === $fieldType && (!empty($pictureField) || '' != $pictureField)) {
180
                        $userpicture = Pedigree\Utility::uploadPicture($numPictureField);
181
                        $usersql     .= ",'" . $userpicture . "'";
182
                        ++$numPictureField;
183
                    } elseif ($userField->isLocked()) {
184
                        //userfield is locked, substitute default value
185
                        $usersql .= ",'" . $userField->defaultvalue . "'";
0 ignored issues
show
The property defaultvalue does not seem to exist on XoopsModules\Pedigree\Field.
Loading history...
186
                    } else {
187
                        //echo $fieldType.":".$i.":".$fields[$i]."<br>";
188
                        $usersql .= ",'" . Pedigree\Utility::unHtmlEntities($_POST['user' . $iValue]) . "'";
189
                    }
190
                } else {
191
                    $usersql .= ",''";
192
                }
193
                //echo $fields[$i]."<br>";
194
            }
195
196
            //insert into pedigree_temp
197
            //        $query = 'INSERT INTO ' . $GLOBALS['xoopsDB']->prefix('pedigree_temp') . " VALUES ('" . $random . "','" . Pedigree\Utility::unHtmlEntities($name) . "','" . $id_owner . "','" . $id_breeder . "','" . $user . "','" . $roft . "','','','" . $foto . "', ''" . $usersql . ')';
198
            $query = 'INSERT INTO '
199
                     . $GLOBALS['xoopsDB']->prefix('pedigree_temp')
200
                     . " VALUES ('"
201
                     . $GLOBALS['xoopsDB']->escape($random)
202
                     . "','"
203
                     . $GLOBALS['xoopsDB']->escape(Pedigree\Utility::unHtmlEntities($name))
204
                     . "','"
205
                     . $GLOBALS['xoopsDB']->escape($id_owner)
206
                     . "','"
207
                     . $GLOBALS['xoopsDB']->escape($id_breeder)
208
                     . "','"
209
                     . $GLOBALS['xoopsDB']->escape($user)
210
                     . "','"
211
                     . $GLOBALS['xoopsDB']->escape($roft)
212
                     . "','0','0','"
213
                     . $GLOBALS['xoopsDB']->escape($foto)
214
                     . "', ''"
215
                     . $usersql
216
                     . ')';
217
            //echo $query; die();
218
            $GLOBALS['xoopsDB']->queryF($query);
219
            $helper->redirect('add_dog.php?f=sire&random=' . $random . '&st=' . $st . '&r=1&l=a', 1, strtr(_MA_PEDIGREE_ADD_SIREPLZ, ['[father]' => $helper->getConfig('father', '')]));
220
        }
221
        //find letter on which to start else set to 'a'
222
        $l = Request::getString('l', 'a', 'GET');
223
        $GLOBALS['xoopsTpl']->assign('sire', '1');
224
225
        //create list of males dog to select from
226
        $perPage = $helper->getConfig('perpage', Constants::DEFAULT_PER_PAGE);
227
        $perPage = (int)$perPage > 0 ? (int)$perPage : Constants::DEFAULT_PER_PAGE; // default if invalid number in module param
228
        //count total number of dogs
229
        $numDog = 'SELECT COUNT(id) FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_registry') . " WHERE roft='0' AND pname LIKE '" . $l . "%'";
230
        $numRes = $GLOBALS['xoopsDB']->query($numDog);
231
        //total number of dogs the query will find
232
        [$numResults] = $GLOBALS['xoopsDB']->fetchRow($numRes);
233
        //total number of pages
234
        $numPages = floor($numResults / $perPage) + 1;
235
        if (($numPages * $perPage) == ($numResults + $perPage)) {
236
            --$numPages;
237
        }
238
        //@todo replace following code with {@see \XoopsPageNav}
239
        //find current page
240
        $currentPage = floor($st / $perPage) + 1;
241
        //create alphabet
242
        $pages = '';
243
        for ($i = 65; $i <= 90; ++$i) {
244
            if ($l == chr($i)) {
245
                $pages .= '<b><a href="' . $helper->url('add_dog.php?f=sire&r=1&random=' . $random . '&l=' . chr($i)) . '">' . chr($i) . '</a></b>&nbsp;';
246
            } else {
247
                $pages .= '<a href="' . $helper->url('add_dog.php?f=sire&r=1&random=' . $random . '&l=' . chr($i)) . '">' . chr($i) . '</a>&nbsp;';
248
            }
249
        }
250
        $pages .= '-&nbsp;';
251
        $pages .= '<a href="' . $helper->url('add_dog.php?f=sire&r=1&random=' . $random . '&l=Ã…') . '">Ã…</a>&nbsp;';
252
        $pages .= '<a href="' . $helper->url('add_dog.php?f=sire&r=1&random=' . $random . '&l=Ö') . '">Ö</a>&nbsp;';
253
        //create linebreak
254
        $pages .= '<br>';
255
        //create previous button
256
        if ($numPages > 1) {
257
            if ($currentPage > 1) {
258
                $pages .= '<a href="' . $helper->url('add_dog.php?f=sire&r=1&l=' . $l . '&random=' . $random . '&st=' . ($st - $perPage)) . '">' . _MA_PEDIGREE_PREVIOUS . '</a>&nbsp;&nbsp';
259
            }
260
        }
261
        //create numbers
262
        $numCount = $numPages + 1;
263
        for ($x = 1; $x < $numCount; ++$x) {
264
            //create line break after 20 numbers
265
            if (0 == ($x % 20)) {
266
                $pages .= '<br>';
267
            }
268
            if ($x != $currentPage) {
269
                $pages .= '<a href="' . $helper->url('add_dog.php?f=sire&r=1&l=' . $l . '&random=' . $random . '&st=' . ($perPage * ($x - 1))) . '">' . $x . '</a>&nbsp;&nbsp;';
270
            } else {
271
                $pages .= $x . '&nbsp;&nbsp';
272
            }
273
        }
274
        //create next button
275
        if ($numPages > 1) {
276
            if ($currentPage < $numPages) {
277
                $pages .= '<a href="' . $helper->url('add_dog.php?f=sire&r=1&l=' . $l . '&random=' . $random . '&st=' . ($st + $perPage)) . '">' . _MA_PEDIGREE_NEXT . '</a>&nbsp;&nbsp';
278
            }
279
        }
280
281
        //query
282
        $sql = 'SELECT * FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_registry') . " WHERE roft = '0' AND pname LIKE '" . $l . "%'ORDER BY pname LIMIT " . $st . ', ' . $perPage;
283
        $result      = $GLOBALS['xoopsDB']->query($sql);
284
285
        $animal = new Pedigree\Animal();
286
        //test to find out how many user fields there are...
287
        $fields       = $animal->getNumOfFields();
288
        $numofcolumns = 1;
289
        $columns[]    = ['columnname' => 'Name'];
290
        foreach ($fields as $i => $iValue) {
291
            $userField   = new Pedigree\Field($fields[$i], $animal->getConfig());
292
            $fieldType   = $userField->getSetting('fieldtype');
293
            $fieldObject = new $fieldType($userField, $animal);
294
            //create empty string
295
            $lookupValues = '';
296
            if ($userField->isActive() && $userField->inList()) {
297
                if ($userField->hasLookup()) {
298
                    $lookupValues = $userField->lookupField($fields[$i]);
299
                    //debug information
300
                    //print_r($lookupValues);
301
                }
302
                $columns[] = [
303
                    'columnname'   => $fieldObject->fieldname,
304
                    'columnnumber' => $userField->getId(),
305
                    'lookupval'    => $lookupValues,
306
                ];
307
                ++$numofcolumns;
308
                unset($lookupValues);
309
            }
310
        }
311
312
        for ($i = 1; $i < $numofcolumns; ++$i) {
313
            $empty[] = ['value' => ''];
314
        }
315
        $dogs[] = [
316
            'id'          => '0',
317
            'name'        => '',
318
            'gender'      => '',
319
            'link'        => '<a href="' . $helper->url('add_dog.php?f=dam&random=' . $random . '&selsire=0') . '">' . strtr(_MA_PEDIGREE_ADD_SIREUNKNOWN, ['[father]' => $helper->getConfig('father', '')]) . '</a>',
320
            'colour'      => '',
321
            'number'      => '',
322
            'usercolumns' => $empty,
323
        ];
324
325
        while (false !== ($row = $GLOBALS['xoopsDB']->fetchArray($result))) {
326
            //create picture information
327
            $camera = ('' != $row['foto']) ? " <img src=\"" . PEDIGREE_IMAGE_URL . "/camera.png\">" : '';
0 ignored issues
show
The constant PEDIGREE_IMAGE_URL was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
328
            $name   = stripslashes($row['pname']) . $camera;
329
            //empty array
330
            unset($columnvalue);
331
            //fill array
332
            for ($i = 1; $i < $numofcolumns; ++$i) {
333
                $x = $columns[$i]['columnnumber'];
334
                if (is_array($columns[$i]['lookupval'])) {
335
                    foreach ($columns[$i]['lookupval'] as $key => $keyValue) {
336
                        if ($key == $row['user' . $x]) {
337
                            $value = $keyValue['value'];
338
                        }
339
                    }
340
                    //debug information
341
                    ///echo $columns[$i]['columnname']."is an array !";
342
                } //format value - cant use object because of query count
343
                elseif (0 === strncmp($row['user' . $x], 'http://', 7)) { //@todo need to update for https
344
                    $value = '<a href="' . $row['user' . $x] . '">' . $row['user' . $x] . '</a>';
345
                } else {
346
                    $value = $row['user' . $x];
347
                }
348
                $columnvalue[] = ['value' => $value];
349
            }
350
            $dogs[] = [
351
                'id'          => $row['id'],
352
                'name'        => $name,
353
                'gender'      => "<img src=\"" . PEDIGREE_IMAGE_URL . "/male.gif\">",
354
                'link'        => '<a href="' . $helper->url('add_dog.php?f=dam&random=' . $random . '&selsire=' . $row['id']) . '">' . $name . '</a>',
355
                'colour'      => '',
356
                'number'      => '',
357
                'usercolumns' => $columnvalue,
358
            ];
359
        }
360
361
        //add data to smarty template
362
        //assign dog
363
        $GLOBALS['xoopsTpl']->assign([
364
                                         'dogs'         => $dogs,
365
                                         'columns'      => $columns,
366
                                         'numofcolumns' => $numofcolumns,
367
                                         'tsarray'      => Pedigree\Utility::sortTable($numofcolumns),
368
                                         'nummatch'     => strtr(_MA_PEDIGREE_ADD_SELSIRE, ['[father]' => $helper->getConfig('father', '')]),
369
                                         'pages'        => $pages,
370
                                     ]);
371
372
        //mb =========== FATHER LETTERS =============================
373
        $roft = Constants::MALE;
374
        //    $criteria     = $helper->getHandler('Tree')->getActiveCriteria($roft);
375
        $activeObject = 'Tree';
376
        $name         = 'pname';
377
        /*
378
        $number1 = '1';
379
        $number2 = '0';
380
            $link         = "virtual.php?r={$number1}&st={$number2}&l=";
381
        */
382
        $link = "add_dog.php?f=sire&r={$roft}&random={$random}&l=";
383
384
        //    http://localhost/257belgi/modules/pedigree/virtual.php?f=dam&selsire=35277
385
386
        $link2 = '';
387
388
        $criteria = $helper->getHandler('Tree')->getActiveCriteria($roft);
389
        //    $criteria->setGroupby('UPPER(LEFT(' . $name . ',1))');
390
391
        $fatherArray['letters'] = Pedigree\Utility::lettersChoice($helper, $activeObject, $criteria, $name, $link, $link2);
392
        //$catarray['toolbar']    = pedigree_toolbar();
393
        $GLOBALS['xoopsTpl']->assign('fatherArray', $fatherArray);
394
        break;
395
    case 'dam':
396
        $empty = []; // an empty array
397
        if (empty($random)) {
0 ignored issues
show
The condition empty($random) is always true.
Loading history...
398
            $random = Request::getInt('random', 0);
399
        }
400
        $st = Request::getInt('st', 0, 'GET');
401
        $l  = Request::getString('l', 'A', 'GET');
402
        //make the redirect
403
        if (!isset($_GET['r'])) {
404
            //insert into pedigree_temp
405
            //        $query = 'UPDATE ' . $GLOBALS['xoopsDB']->prefix('pedigree_temp') . ' SET father =' . $_GET['selsire'] . ' WHERE id=' . $random;
406
            //        $GLOBALS['xoopsDB']->queryF($query);
407
            $query = 'UPDATE ' . $GLOBALS['xoopsDB']->prefix('pedigree_temp') . ' SET father =' . Request::getInt('selsire', 0, 'GET') . ' WHERE id=' . $random;
408
            $GLOBALS['xoopsDB']->queryF($query);
409
            $helper->redirect('add_dog.php?f=dam&random=' . $random . '&st=' . $st . '&r=' . Constants::FEMALE . '&l=A', 1, strtr(_MA_PEDIGREE_ADD_SIREOK, ['[mother]' => $helper->getConfig('mother', '')]));
410
        }
411
412
        $GLOBALS['xoopsTpl']->assign('sire', '1');
413
        //create list of males dog to select from
414
        $perPage = $helper->getConfig('perpage', Constants::DEFAULT_PER_PAGE);
415
        $perPage = (int)$perPage > 0 ? (int)$perPage : Constants::DEFAULT_PER_PAGE; // default if invalid number in module param
416
        //count total number of dogs
417
        //@todo replace SQL with \TreeHandler & \Criteria class methods
418
        $numDog = 'SELECT COUNT(id) FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_registry') . " WHERE roft='1' AND pname LIKE '" . $l . "%'";
419
        $numRes = $GLOBALS['xoopsDB']->query($numDog);
420
        [$numResults] = $GLOBALS['xoopsDB']->fetchRow($numRes);
421
        $numPages = floor($numResults / $perPage) + 1;
422
        if (($numPages * $perPage) == ($numResults + $perPage)) {
423
            --$numPages;
424
        }
425
        $currentPage = floor($st / $perPage) + 1;
426
        //create alphabet
427
        $pages = '';
428
        for ($i = 65; $i <= 90; ++$i) {
429
            if ($l == chr($i)) {
430
                $pages .= '<b><a href="' . $helper->url('add_dog.php?f=dam&r=1&random=' . $random . '&l=' . chr($i)) . '">' . chr($i) . '</a></b>&nbsp;';
431
            } else {
432
                $pages .= '<a href="' . $helper->url('add_dog.php?f=dam&r=1&random=' . $random . '&l=' . chr($i)) . '">' . chr($i) . '</a>&nbsp;';
433
            }
434
        }
435
        $pages .= '-&nbsp;';
436
        $pages .= '<a href="' . $helper->url('add_dog.php?f=dam&r=1&random=' . $random . '&l=Ã…') . '">Ã…</a>&nbsp;';
437
        $pages .= '<a href="' . $helper->url('add_dog.php?f=dam&r=1&random=' . $random . '&l=Ö') . '">Ö</a>&nbsp;';
438
        $pages .= '<br>';
439
        //create previous button
440
        if ($numPages > 1) {
441
            if ($currentPage > 1) {
442
                $pages .= '<a href="' . $helper->url('add_dog.php?f=dam&r=1&l=' . $l . '&random=' . $random . '&st=' . ($st - $perPage)) . '">' . _MA_PEDIGREE_PREVIOUS . '</a>&nbsp;&nbsp';
443
            }
444
        }
445
        //create numbers
446
        for ($x = 1; $x < ($numPages + 1); ++$x) {
447
            //create line break after 20 number
448
            if (0 == ($x % 20)) {
449
                $pages .= '<br>';
450
            }
451
            if ($x != $currentPage) {
452
                $pages .= '<a href="' . $helper->url('add_dog.php?f=dam&r=1&l=' . $l . '&random=' . $random . '&st=' . ($perPage * ($x - 1))) . '">' . $x . '</a>&nbsp;&nbsp;';
453
            } else {
454
                $pages .= $x . '&nbsp;&nbsp';
455
            }
456
        }
457
        //create next button
458
        if ($numPages > 1) {
459
            if ($currentPage < $numPages) {
460
                $pages .= '<a href="' . $helper->url('add_dog.php?f=dam&l=' . $l . '&r=1&random=' . $random . '&st=' . ($st + $perPage)) . '">' . _MA_PEDIGREE_NEXT . '</a>&nbsp;&nbsp;';
461
            }
462
        }
463
464
        //query
465
        $sql = 'SELECT * FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_registry') . " WHERE roft = '1' AND pname LIKE '" . $l . "%' ORDER BY pname LIMIT " . $st . ', ' . $perPage;
466
        $result      = $GLOBALS['xoopsDB']->query($sql);
467
468
        $animal = new Pedigree\Animal();
469
        //test to find out how many user fields there are...
470
        $fields       = $animal->getNumOfFields();
471
        $numofcolumns = 1;
472
        $columns[]    = ['columnname' => 'Name'];
473
        foreach ($fields as $i => $iValue) {
474
            $userField   = new Pedigree\Field($fields[$i], $animal->getConfig());
475
            $fieldType   = $userField->getSetting('fieldtype');
476
            $fieldObject = new $fieldType($userField, $animal);
477
            //create empty string
478
            $lookupValues = '';
479
            if ($userField->isActive() && $userField->inList()) {
480
                if ($userField->hasLookup()) {
481
                    $lookupValues = $userField->lookupField($fields[$i]);
482
                    //debug information
483
                    //print_r($lookupValues);
484
                }
485
                $columns[] = [
486
                    'columnname'   => $fieldObject->fieldname,
487
                    'columnnumber' => $userField->getId(),
488
                    'lookupval'    => $lookupValues,
489
                ];
490
                ++$numofcolumns;
491
                unset($lookupValues);
492
            }
493
        }
494
495
        for ($i = 1; $i < $numofcolumns; ++$i) {
496
            $empty[] = ['value' => ''];
497
        }
498
        $dogs[] = [
499
            'id'          => '0',
500
            'name'        => '',
501
            'gender'      => '',
502
            'link'        => '<a href="' . $helper->url('add_dog.php?f=check&random=' . $random . '&seldam=0') . '">' . strtr(_MA_PEDIGREE_ADD_DAMUNKNOWN, ['[mother]' => $helper->getConfig('mother', '')]) . '</a>',
503
            'colour'      => '',
504
            'number'      => '',
505
            'usercolumns' => $empty,
506
        ];
507
508
        while (false !== ($row = $GLOBALS['xoopsDB']->fetchArray($result))) {
509
            //create picture information
510
            $camera = ('' != $row['foto']) ? " <img src=\"" . PEDIGREE_IMAGE_URL . "/camera.png\">" : '';
511
            $name   = stripslashes($row['pname']) . $camera;
512
            //empty array
513
            unset($columnvalue);
514
            //fill array
515
            for ($i = 1; $i < $numofcolumns; ++$i) {
516
                $x = $columns[$i]['columnnumber'];
517
                if (is_array($columns[$i]['lookupval'])) {
518
                    foreach ($columns[$i]['lookupval'] as $key => $keyValue) {
519
                        if ($key == $row['user' . $x]) {
520
                            $value = $keyValue['value'];
521
                        }
522
                    }
523
                    //debug information
524
                    ///echo $columns[$i]['columnname']."is an array !";
525
                } //format value - cant use object because of query count
526
                elseif (0 === strncmp($row['user' . $x], 'http://', 7)) {
527
                    $value = '<a href="' . $row['user' . $x] . '">' . $row['user' . $x] . '</a>';
528
                } else {
529
                    $value = $row['user' . $x];
530
                }
531
                $columnvalue[] = ['value' => $value];
532
            }
533
            $dogs[] = [
534
                'id'          => $row['id'],
535
                'name'        => $name,
536
                'gender'      => "<img src=\"" . PEDIGREE_IMAGE_URL . "/female.gif\">",
537
                'link'        => '<a href="' . $helper->url('add_dog.php?f=check&random=' . $random . '&seldam=' . $row['id']) . '">' . $name . '</a>',
538
                'colour'      => '',
539
                'number'      => '',
540
                'usercolumns' => $columnvalue,
541
            ];
542
        }
543
544
        //add data to smarty template
545
        //assign dog
546
        $GLOBALS['xoopsTpl']->assign([
547
                                         'dogs'         => $dogs,
548
                                         'columns'      => $columns,
549
                                         'numofcolumns' => $numofcolumns,
550
                                         'tsarray'      => Pedigree\Utility::sortTable($numofcolumns),
551
                                         'nummatch'     => strtr(_MA_PEDIGREE_ADD_SELDAM, ['[mother]' => $helper->getConfig('mother', '')]),
552
                                         'pages'        => $pages,
553
                                     ]);
554
555
        //mb ========= MOTHER LETTERS===============================
556
        $roft = Constants::FEMALE;
557
        //    $criteria     = $helper->getHandler('Tree')->getActiveCriteria($roft);
558
        $activeObject = 'Tree';
559
        $name         = 'pname';
560
        $link         = "add_dog.php?f=dam&r={$roft}&random={$random}&l=";
561
        $link2        = '';
562
563
        $criteria = $helper->getHandler('Tree')->getActiveCriteria($roft);
564
        //    $criteria->setGroupby('UPPER(LEFT(' . $name . ', 1))');
565
566
        $motherArray['letters'] = Pedigree\Utility::lettersChoice($helper, $activeObject, $criteria, $name, $link, $link2);
567
        //$catarray['toolbar']    = pedigree_toolbar();
568
        $GLOBALS['xoopsTpl']->assign('motherArray', $motherArray);
569
        break;
570
    case 'check':
571
        if (empty($random)) {
0 ignored issues
show
The condition empty($random) is always true.
Loading history...
572
            $random = Request::getInt('random', null);
573
        }
574
575
        /**
576
         * @var XoopsModules\Pedigree\TreeHandler $treeHandler
577
         * @var XoopsModules\Pedigree\TempHandler $tempHandler
578
         */
579
        /*
580
         * @todo replace code below with this refactored code using class methods
581
         * after we figure out how to handle user values and insert them into the DB
582
        $treeHandler = $helper->getHandler('Tree');
583
        $tempHandler = $helper->getHandler('Temp');
584
        $criteria = new \Criteria('id', $random);
585
        $tempObj = $tempHandler->get($id);
586
        if (!$tempObj instanceof Pedigree\Temp || $tempObj->isNew()) {
587
            $helper->redirect('add_dog.php', Constants::REDIRECT_DELAY_MEDIUM, _MA_PEDIGREE_ERR_INVALID);
588
        }
589
        $tempVals = $tempObj->getValues();
590
        $treeObj = $treeHandler->create();
591
592
        $treeObj->setVar([
593
            'pname' => $tempVals['pname'],
594
            'id_owner' => $tempVals['id_owner'],
595
            'id_breeder' => $tempVals['id_breeder'],
596
            'user' => $tempVals['user'],
597
            'roft' => $tempVals['roft'],
598
            'mother' => $tempVals['mother'],
599
            'father' => $tempVals['father'],
600
            'foto' => $tempVals['foto']
601
        ]);
602
        $treeHandler->insert($treeObj);
603
        */
604
        //query
605
        $sql = 'SELECT * FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_temp') . ' WHERE id = ' . $random;
606
        $result      = $GLOBALS['xoopsDB']->query($sql);
607
        while (false !== ($row = $GLOBALS['xoopsDB']->fetchArray($result))) {
608
            //create animal object
609
            $animal = new Pedigree\Animal();
610
            $fields = $animal->getNumOfFields(); //test to find out how many user fields there are..
611
            sort($fields);
612
            $usersql = '';
613
            foreach ($fields as $i => $iValue) {
614
                $userField   = new Pedigree\Field($fields[$i], $animal->getConfig());
615
                $fieldType   = $userField->getSetting('fieldtype');
616
                $fieldObject = new $fieldType($userField, $animal);
617
                if ($userField->isActive()) {
618
                    $usersql .= ",'" . addslashes($row['user' . $iValue]) . "'";
619
                } else {
620
                    $usersql .= ",'" . $fieldObject->defaultvalue . "'";
621
                }
622
                //echo $fields[$i]."<br>";
623
            }
624
            //insert into pedigree
625
            //$query = 'INSERT INTO ' . $GLOBALS['xoopsDB']->prefix('pedigree_registry') . " VALUES ('','" . addslashes($row['pname']) . "','" . $row['id_owner'] . "','" . $row['id_breeder'] . "','" . $row['user'] . "','" . $row['roft'] . "','" . $_GET['seldam'] . "','" . $row['father'] . "','" . addslashes($row['foto']) . "',''" . $usersql . ')';
626
            $sql = 'INSERT INTO ' . $GLOBALS['xoopsDB']->prefix('pedigree_registry') . " VALUES (0,'" . $GLOBALS['xoopsDB']->escape($row['pname']) . "','" . $GLOBALS['xoopsDB']->escape($row['id_owner']) . "','" . $GLOBALS['xoopsDB']->escape($row['id_breeder']) . "','" . $GLOBALS['xoopsDB']->escape(
627
                    $row['user']
628
                ) . "','" . $GLOBALS['xoopsDB']->escape($row['roft']) . "','" . $GLOBALS['xoopsDB']->escape($_GET['seldam']) . "','" . $GLOBALS['xoopsDB']->escape($row['father']) . "','" . $GLOBALS['xoopsDB']->escape($row['foto']) . "',''" . $usersql . ')';
629
            $GLOBALS['xoopsDB']->queryF($sql);
630
            //echo $query; die();
631
            break;
632
        }
633
        $sqlQuery = 'DELETE FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_temp') . " WHERE id='" . $random . "'";
634
        $GLOBALS['xoopsDB']->queryF($sqlQuery);
635
        $helper->redirect('latest.php', 1, strtr(_MA_PEDIGREE_ADD_OK, ['[animalType]' => $helper->getConfig('animalType')]));
636
        break;
637
    default: //add a dog
638
        require XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
639
        $form = new \XoopsThemeForm(strtr(_MA_PEDIGREE_ADD_DOG, ['[animalType]' => $helper->getConfig('animalType')]), 'dogname', 'add_dog.php?f=checkName', 'post');
640
        $form->addElement(new \XoopsFormHiddenToken($name = 'XOOPS_TOKEN_REQUEST', $timeout = Constants::TOKEN_TIMEOUT));
641
        //create random value
642
        $random = (mt_rand() % 10000);
643
        $form->addElement(new \XoopsFormHidden('random', $random));
644
        //find userid
645
        $form->addElement(new \XoopsFormHidden('user', $GLOBALS['xoopsUser']->getVar('uid')));
646
647
        //name
648
        $form->addElement(new \XoopsFormText('<b>' . _MA_PEDIGREE_FLD_NAME . '</b>', 'pname', $size = 50, $maxsize = 255, $value = ''), true); // name required
649
        $string = strtr(_MA_PEDIGREE_FLD_NAME_EX, ['[animalType]' => $helper->getConfig('animalType')]);
650
        $form->addElement(new \XoopsFormLabel(_MA_PEDIGREE_EXPLAIN, $string));
651
652
        //submit button
653
        $form->addElement(new \XoopsFormButton('', 'button_id', strtr(_MA_PEDIGREE_ADD_DATA, ['[animalType]' => $helper->getConfig('animalType')]), 'submit'));
654
655
        //add data (form) to smarty template
656
        $GLOBALS['xoopsTpl']->assign('form', $form->render());
657
        break;
658
}
659
660
//footer
661
require XOOPS_ROOT_PATH . '/footer.php';
662