This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
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; |
||||
0 ignored issues
–
show
|
|||||
23 | use XoopsModules\Pedigree; |
||||
24 | use XoopsModules\Pedigree\Constants; |
||||
25 | |||||
26 | //require_once \dirname(__DIR__, 2) . '/mainfile.php'; |
||||
27 | require_once __DIR__ . '/header.php'; |
||||
28 | $helper->loadLanguage('main'); |
||||
29 | |||||
30 | // Include any common code for this module. |
||||
31 | require_once $helper->path('include/common.php'); |
||||
32 | |||||
33 | $GLOBALS['xoopsOption']['template_main'] = 'pedigree_addlitter.tpl'; |
||||
34 | require XOOPS_ROOT_PATH . '/header.php'; |
||||
35 | $GLOBALS['xoopsTpl']->assign('page_title', _MA_PEDIGREE_ADD_LITTER_PAGETITLE); |
||||
36 | |||||
37 | //check for access |
||||
38 | if (empty($GLOBALS['xoopsUser']) || !($GLOBALS['xoopsUser'] instanceof \XoopsUser) || $GLOBALS['xoopsUser']->isGuest()) { |
||||
39 | redirect_header('javascript:history.go(-1)', 3, _NOPERM . '<br>' . _MA_PEDIGREE_REGIST); |
||||
40 | } |
||||
41 | |||||
42 | $f = Request::getCmd('f', 'addlitter', 'GET'); |
||||
43 | switch ($f) { |
||||
44 | case 'addlitter': |
||||
45 | default: |
||||
46 | //create xoopsform |
||||
47 | require XOOPS_ROOT_PATH . '/class/xoopsformloader.php'; |
||||
48 | $searchform = new \XoopsThemeForm(strtr(_MA_PEDIGREE_ADD_LITTER, ['[litter]' => $helper->getConfig('litter')]), 'searchform', $helper->url('add_litter.php?f=sire'), 'post'); |
||||
49 | $searchform->addElement(new \XoopsFormHiddenToken($name = 'XOOPS_TOKEN_REQUEST', $timeout = Constants::TOKEN_TIMEOUT)); |
||||
50 | //create random value |
||||
51 | $random = (mt_rand() % 10000); |
||||
52 | $searchform->addElement(new \XoopsFormHidden('random', $random)); |
||||
53 | $searchform->addElement(new \XoopsFormHidden('userid', $GLOBALS['xoopsUser']->getVar('uid'))); //get user's ID |
||||
54 | $animal = new Pedigree\Animal(); //create animal object |
||||
55 | $fields = $animal->getNumOfFields();//test to find out how many user fields there are... |
||||
56 | |||||
57 | //create form contents |
||||
58 | for ($count = 1; $count < 11; ++$count) { |
||||
59 | //name |
||||
60 | $searchform->addElement(new \XoopsFormLabel($count . '.', strtr(_MA_PEDIGREE_KITT_NAME . $count . '.', ['[animalType]' => $helper->getConfig('animalType')]))); |
||||
61 | $textbox[$count] = new \XoopsFormText('<b>' . _MA_PEDIGREE_FLD_NAME . '</b>', 'name' . $count, $size = 50, $maxsize = 50, ''); |
||||
62 | $searchform->addElement($textbox[$count]); |
||||
63 | //gender |
||||
64 | $gender_radio[$count] = new \XoopsFormRadio('<b>' . _MA_PEDIGREE_FLD_GEND . '</b>', 'roft' . $count, $value = '0'); |
||||
65 | $gender_radio[$count]->addOptionArray([ |
||||
66 | Constants::MALE => strtr(_MA_PEDIGREE_FLD_MALE, ['[male]' => $helper->getConfig('male')]), |
||||
67 | Constants::FEMALE => strtr(_MA_PEDIGREE_FLD_FEMA, ['[female]' => $helper->getConfig('female')]), |
||||
68 | ]); |
||||
69 | $searchform->addElement($gender_radio[$count]); |
||||
70 | //add userfields |
||||
71 | $fieldCount = count($fields); |
||||
72 | for ($i = 0; $i < $fieldCount; ++$i) { |
||||
73 | $userField = new Pedigree\Field($fields[$i], $animal->getConfig()); |
||||
74 | $fieldType = $userField->getSetting('fieldtype'); |
||||
75 | $fieldObject = new $fieldType($userField, $animal); |
||||
76 | if ($userField->isActive() && '1' == $userField->getSetting('Litter') && !$userField->isLocked()) { |
||||
77 | $newEntry[$count][$i] = $fieldObject->newField($count); |
||||
78 | $searchform->addElement($newEntry[$count][$i]); |
||||
79 | } |
||||
80 | } |
||||
81 | //add empty place holder as divider |
||||
82 | $searchform->addElement(new \XoopsFormLabel(' ', '')); |
||||
83 | } |
||||
84 | |||||
85 | $searchform->addElement(new \XoopsFormLabel(_MA_PEDIGREE_ADD_DATA, _MA_PEDIGREE_DATA_INFO . $helper->getConfig('litter') . '.</h2>')); |
||||
86 | //add userfields that are not shown in the litter |
||||
87 | $fieldCount = count($fields); |
||||
88 | for ($i = 0, $fieldCount; $i < $fieldCount; ++$i) { |
||||
89 | $userField = new Pedigree\Field($fields[$i], $animal->getConfig()); |
||||
90 | $fieldType = $userField->getSetting('fieldtype'); |
||||
91 | $fieldObject = new $fieldType($userField, $animal); |
||||
92 | if ($userField->isActive() && $userField->generalLitter() && !$userField->isLocked()) { |
||||
93 | //add the "-" character to the beginning of the fieldname !!! |
||||
94 | $newEntry[$i] = $fieldObject->newField('-'); |
||||
95 | $searchform->addElement($newEntry[$i]); |
||||
96 | } |
||||
97 | } |
||||
98 | //add the breeder to the list for the entire litter |
||||
99 | //no need to add the owner here because they will be different for each animal in the litter. |
||||
100 | if ('1' == $helper->getConfig('ownerbreeder')) { |
||||
101 | //breeder |
||||
102 | $ownerHandler = $helper->getHandler('Owner'); |
||||
103 | $criteria = new \Criteria(); |
||||
0 ignored issues
–
show
The call to
Criteria::__construct() has too few arguments starting with column .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue. If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above. ![]() |
|||||
104 | $criteria->setSort('lastname, firstname'); |
||||
105 | $ownerObjArray = $ownerHandler->getAll($criteria); |
||||
106 | $breeder = new \XoopsFormSelect(_MA_PEDIGREE_FLD_BREE, 'id_breeder', $value = '', $size = 1, $multiple = false); |
||||
107 | $breeder->addOption(0, $name = _MA_PEDIGREE_UNKNOWN); |
||||
108 | foreach ($ownerObjArray as $oObj) { |
||||
109 | $breeder->addOption($oObj->getVar('id'), $name = $oObj->getVar('lastname') . ', ' . $oObj->getVar('firstname')); |
||||
110 | } |
||||
111 | /* |
||||
112 | $queryfok = 'SELECT id, firstname, lastname FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_owner') . ' ORDER BY `lastname`; |
||||
113 | $resfok = $GLOBALS['xoopsDB']->query($queryfok); |
||||
114 | $breeder->addOption(0, $name = _MA_PEDIGREE_UNKNOWN); |
||||
115 | while (false !== ($rowfok = $GLOBALS['xoopsDB']->fetchArray($resfok))) { |
||||
116 | $breeder->addOption($rowfok['id'], $name = $rowfok['lastname'] . ', ' . $rowfok['firstname']); |
||||
117 | } |
||||
118 | */ |
||||
119 | $searchform->addElement($breeder); |
||||
120 | } |
||||
121 | |||||
122 | //submit button |
||||
123 | $searchform->addElement(new \XoopsFormButton('', 'submit', strtr(_MA_PEDIGREE_ADD_SIRE, ['[father]' => $helper->getConfig('father', '')]), 'submit')); |
||||
124 | //send to template |
||||
125 | $searchform->assign($GLOBALS['xoopsTpl']); |
||||
126 | break; |
||||
127 | case 'sire': |
||||
128 | //debug option ! |
||||
129 | //print_r($_POST); die(); |
||||
130 | // $userid = $_POST['userid']; |
||||
131 | // if (empty($random)) { |
||||
132 | // $random = $_POST['random']; |
||||
133 | // } |
||||
134 | // if (isset($_GET['random'])) { |
||||
135 | // $random = $_GET['random']; |
||||
136 | // } |
||||
137 | // if (empty($st)) { |
||||
138 | // $st = 0; |
||||
139 | // } |
||||
140 | // if (isset($_GET['st'])) { |
||||
141 | // $st = $_GET['st']; |
||||
142 | // } |
||||
143 | $userid = Request::getInt('userid', 0, 'POST'); |
||||
144 | $random = Request::getInt('random', 0); |
||||
145 | $st = Request::getInt('st', 0); |
||||
146 | $userfields = ''; |
||||
147 | $name = ''; |
||||
148 | $roft = ''; |
||||
149 | for ($count = 1; $count < 11; ++$count) { |
||||
150 | $namelitter = 'name' . $count; |
||||
151 | $roftlitter = 'roft' . $count; |
||||
152 | //check for an empty name |
||||
153 | if ('' !== $_POST[$namelitter]) { |
||||
154 | $name .= ':' . Request::getString('namelitter', '', 'POST'); |
||||
155 | $roft .= ':' . Request::getString('roftlitter', '', 'POST'); |
||||
156 | } else { |
||||
157 | if (1 == $count) { |
||||
158 | $helper->redirect('add_litter.php', 3, _MA_PEDIGREE_ADD_NAMEPLZ); |
||||
159 | } |
||||
160 | } |
||||
161 | } |
||||
162 | |||||
163 | $id_breeder = Request::getInt('id_breeder', 0, 'POST'); |
||||
164 | |||||
165 | //make the redirect |
||||
166 | if (!isset($_GET['r'])) { |
||||
167 | $animal = new Pedigree\Animal(); |
||||
168 | $fields = $animal->getNumOfFields(); |
||||
169 | sort($fields); |
||||
170 | foreach ($fields as $i => $iValue) { |
||||
171 | $userField = new Pedigree\Field($fields[$i], $animal->getConfig()); |
||||
172 | $fieldType = $userField->getSetting('fieldtype'); |
||||
173 | $fieldObject = new $fieldType($userField, $animal); |
||||
174 | $defvalue = $fieldObject->defaultvalue; |
||||
175 | //empty string to house the different values for this userfield |
||||
176 | $withinfield = ''; |
||||
177 | for ($count = 1; $count < 11; ++$count) { |
||||
178 | if ('' !== $_POST['name' . $count]) { |
||||
179 | //@todo need to sanitize these $_POST values |
||||
180 | if (isset($_POST[$count . 'user' . $iValue])) { |
||||
181 | //debug option |
||||
182 | //echo $count.'user'.$fields[$i]."=".$_POST[$count.'user'.$fields[$i]]."<br>"; |
||||
183 | $withinfield .= ':' . $_POST[$count . 'user' . $iValue]; |
||||
184 | } else { |
||||
185 | if ($userField->isActive() && $userField->generalLitter() && !$userField->isLocked()) { |
||||
186 | //use $_POST value if this is a general litter field |
||||
187 | $withinfield .= ':' . $_POST['-user' . $iValue]; |
||||
188 | } else { |
||||
189 | //create $withinfield for fields not added to the litter |
||||
190 | $withinfield .= ':' . $defvalue; |
||||
191 | } |
||||
192 | } |
||||
193 | } |
||||
194 | } |
||||
195 | //debug option |
||||
196 | //echo "user".$fields[$i]." - ".$withinfield."<br>"; |
||||
197 | $user{$fields[$i]} = $withinfield; |
||||
198 | } |
||||
199 | //insert into pedigree_temp |
||||
200 | // $query = 'INSERT INTO ' . $GLOBALS['xoopsDB']->prefix('pedigree_temp') . " VALUES ('" . $random . "','" . Pedigree\Utility::unHtmlEntities($name) . "','0','" . $id_breeder . "','" . $userid . "','" . $roft . "','','','', ''"; |
||||
201 | $query = 'INSERT INTO ' . $GLOBALS['xoopsDB']->prefix('pedigree_temp') . " VALUES ('" . $random . "','" . Pedigree\Utility::unHtmlEntities($name) . "','0','" . Request::getInt('id_breeder', 0, 'POST') . "','" . $userid . "','" . $roft . "','','','', ''"; |
||||
202 | foreach ($fields as $i => $iValue) { |
||||
203 | $userField = new Pedigree\Field($fields[$i], $animal->getConfig()); |
||||
204 | $fieldType = $userField->getSetting('fieldtype'); |
||||
205 | $fieldObject = new $fieldType($userField, $animal); |
||||
206 | //do we only need to create a query for active fields ? |
||||
207 | $query .= ",'" . $user{$fields[$i]} . "'"; |
||||
208 | } |
||||
209 | $query .= ')'; |
||||
210 | //debug options |
||||
211 | //echo $query."<br>"; die(); |
||||
212 | $GLOBALS['xoopsDB']->query($query); |
||||
213 | $helper->redirect('add_litter.php?f=sire&random=' . $random . '&st=' . $st . '&r=1&l=a', 1, strtr(_MA_PEDIGREE_ADD_SIREPLZ, ['[father]' => $helper->getConfig('father', '')])); |
||||
214 | } |
||||
215 | //@todo refactor to allow for language other than english |
||||
216 | //find letter on which to start else set to 'a' |
||||
217 | $l = Request::getWord('l', 'A', 'GET'); |
||||
218 | |||||
219 | //assign 'sire' to the template |
||||
220 | $GLOBALS['xoopsTpl']->assign('sire', '1'); |
||||
221 | |||||
222 | //create list of males dog to select from |
||||
223 | $perPage = $helper->getConfig('perpage', Constants::DEFAULT_PER_PAGE); |
||||
224 | $perPage = (int)$perPage > 0 ? (int)$perPage : Constants::DEFAULT_PER_PAGE; // default if invalid number in module param |
||||
225 | //count total number of dogs |
||||
226 | $numDog = 'SELECT id FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_registry') . " WHERE roft='0' AND pname LIKE '" . $l . "%'"; |
||||
227 | $numRes = $GLOBALS['xoopsDB']->query($numDog); |
||||
228 | //total number of dogs the query will find |
||||
229 | $numResults = $GLOBALS['xoopsDB']->getRowsNum($numRes); |
||||
230 | //total number of pages |
||||
231 | $numPages = floor($numResults / $perPage) + 1; |
||||
232 | if (($numPages * $perPage) == ($numResults + $perPage)) { |
||||
233 | --$numPages; |
||||
234 | } |
||||
235 | //find current page |
||||
236 | $currentPage = floor($st / $perPage) + 1; |
||||
237 | //create alphabet |
||||
238 | $pages = ''; |
||||
239 | //@todo need to rework this as it's only valid for English |
||||
240 | for ($i = 65; $i <= 90; ++$i) { |
||||
241 | if ($l == chr($i)) { |
||||
242 | $pages .= '<b><a href="' . $helper->url('add_litter.php?f=sire&r=1&r=1&random=' . $random . '&l=' . chr($i)) . '">' . chr($i) . '</a></b> '; |
||||
243 | } else { |
||||
244 | $pages .= '<a href="' . $helper->url('add_litter.php?f=sire&r=1&r=1&random=' . $random . '&l=' . chr($i)) . '">' . chr($i) . '</a> '; |
||||
245 | } |
||||
246 | } |
||||
247 | $pages .= '- '; |
||||
248 | $pages .= '<a href="' . $helper->url('add_litter.php?f=sire&r=1&random=' . $random . '&l=Ã…') . '">Ã…</a> '; |
||||
249 | $pages .= '<a href="' . $helper->url('add_litter.php?f=sire&r=1&random=' . $random . '&l=Ö') . '">Ö</a> '; |
||||
250 | //create linebreak |
||||
251 | $pages .= '<br>'; |
||||
252 | //create previous button |
||||
253 | if ($numPages > 1) { |
||||
254 | if ($currentPage > 1) { |
||||
255 | $pages .= '<a href="' . $helper->url('add_litter.php?f=sire&r=1&l=' . $l . '&random=' . $random . '&st=' . ($st - $perPage)) . '">' . _MA_PEDIGREE_PREVIOUS . '</a>  '; |
||||
256 | } |
||||
257 | } |
||||
258 | //create numbers |
||||
259 | for ($x = 1; $x < ($numPages + 1); ++$x) { |
||||
260 | //create line break after 20 number |
||||
261 | if (0 == ($x % 20)) { |
||||
262 | $pages .= '<br>'; |
||||
263 | } |
||||
264 | if ($x != $currentPage) { |
||||
265 | $pages .= '<a href="' . $helper->url('add_litter.php?f=sire&r=1&l=' . $l . '&random=' . $random . '&st=' . ($perPage * ($x - 1))) . '">' . $x . '</a> '; |
||||
266 | } else { |
||||
267 | $pages .= $x . '  '; |
||||
268 | } |
||||
269 | } |
||||
270 | //create next button |
||||
271 | if ($numPages > 1) { |
||||
272 | if ($currentPage < $numPages) { |
||||
273 | $pages .= '<a href="' . $helper->url('add_litter.php?f=sire&r=1&l=' . $l . '&random=' . $random . '&st=' . ($st + $perPage)) . '">' . _MA_PEDIGREE_NEXT . '</a>  '; |
||||
274 | } |
||||
275 | } |
||||
276 | //query |
||||
277 | $sql = 'SELECT * FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_registry') . " WHERE roft = '0' AND pname LIKE '" . $l . "%' ORDER BY pname LIMIT " . $st . ', ' . $perPage; |
||||
278 | $result = $GLOBALS['xoopsDB']->query($sql); |
||||
279 | |||||
280 | $animal = new Pedigree\Animal(); |
||||
281 | //test to find out how many user fields there are... |
||||
282 | $fields = $animal->getNumOfFields(); |
||||
283 | $numOfColumns = 1; |
||||
284 | $columns[] = ['columnname' => 'Name']; |
||||
285 | foreach ($fields as $i => $iValue) { |
||||
286 | $userField = new Pedigree\Field($fields[$i], $animal->getConfig()); |
||||
287 | $fieldType = $userField->getSetting('fieldtype'); |
||||
288 | $fieldObject = new $fieldType($userField, $animal); |
||||
289 | //create empty string |
||||
290 | $lookupValues = ''; |
||||
291 | if ($userField->isActive() && $userField->inList()) { |
||||
292 | if ($userField->hasLookup()) { |
||||
293 | $lookupValues = $userField->lookupField($fields[$i]); |
||||
294 | //debug information |
||||
295 | //print_r($lookupValues); |
||||
296 | } |
||||
297 | $columns[] = [ |
||||
298 | 'columnname' => $fieldObject->fieldname, |
||||
299 | 'columnnumber' => $userField->getId(), |
||||
300 | 'lookupval' => $lookupValues, |
||||
301 | ]; |
||||
302 | ++$numOfColumns; |
||||
303 | unset($lookupValues); |
||||
304 | } |
||||
305 | } |
||||
306 | |||||
307 | $empty = array_fill(0, $numOfColumns - 1, ['value' => '']); |
||||
308 | /* |
||||
309 | $empty = []; //initialize the array |
||||
310 | for ($i = 1; $i < $numOfColumns; ++$i) { |
||||
311 | $empty[] = ['value' => '']; |
||||
312 | } |
||||
313 | */ |
||||
314 | $dogs [] = [ |
||||
315 | 'id' => '0', |
||||
316 | 'name' => '', |
||||
317 | 'gender' => '', |
||||
318 | 'link' => '<a href="add_litter.php?f=dam&random=' . $random . '&selsire=0">' . strtr(_MA_PEDIGREE_ADD_SIREUNKNOWN, ['[father]' => $helper->getConfig('father', '')]) . '</a>', |
||||
319 | 'colour' => '', |
||||
320 | 'number' => '', |
||||
321 | 'usercolumns' => $empty, |
||||
322 | ]; |
||||
323 | |||||
324 | while (false !== ($row = $GLOBALS['xoopsDB']->fetchArray($result))) { |
||||
325 | //create picture information |
||||
326 | $camera = ('' != $row['foto']) ? " <img src=\"" . PEDIGREE_IMAGE_URL . "/camera.png\">" : ''; |
||||
0 ignored issues
–
show
|
|||||
327 | $name = stripslashes($row['pname']) . $camera; |
||||
328 | //empty array |
||||
329 | $columnvalue = []; // initialize columnvalue to empty array |
||||
330 | //fill array |
||||
331 | for ($i = 1; $i < $numOfColumns; ++$i) { |
||||
332 | $x = $columns[$i]['columnnumber']; |
||||
333 | if (is_array($columns[$i]['lookupval'])) { |
||||
334 | foreach ($columns[$i]['lookupval'] as $key => $keyValue) { |
||||
335 | if ($key == $row['user' . $x]) { |
||||
336 | $value = $keyValue['value']; |
||||
337 | } |
||||
338 | } |
||||
339 | //debug information |
||||
340 | ///echo $columns[$i]['columnname']."is an array !"; |
||||
341 | } //format value - cant use object because of query count |
||||
342 | elseif (0 === strncmp($row['user' . $x], 'http://', 7)) { |
||||
343 | $value = '<a href="' . $row['user' . $x] . '">' . $row['user' . $x] . '</a>'; |
||||
344 | } else { |
||||
345 | $value = $row['user' . $x]; |
||||
346 | } |
||||
347 | $columnvalue[] = ['value' => $value]; |
||||
348 | } |
||||
349 | $dogs[] = [ |
||||
350 | 'id' => $row['id'], |
||||
351 | 'name' => $name, |
||||
352 | 'gender' => "<img src=\"" . PEDIGREE_IMAGE_URL . "/male.gif\">", |
||||
353 | 'link' => '<a href="add_litter.php?f=dam&random=' . $random . '&selsire=' . $row['id'] . '">' . $name . '</a>', |
||||
354 | 'colour' => '', |
||||
355 | 'number' => '', |
||||
356 | 'usercolumns' => $columnvalue, |
||||
357 | ]; |
||||
358 | } |
||||
359 | |||||
360 | //add data to smarty template |
||||
361 | //assign dog |
||||
362 | $GLOBALS['xoopsTpl']->assign([ |
||||
363 | 'dogs' => $dogs, |
||||
364 | 'columns' => $columns, |
||||
365 | 'numofcolumns' => $numOfColumns, |
||||
366 | 'tsarray' => Pedigree\Utility::sortTable($numOfColumns), |
||||
367 | 'nummatch' => strtr(_MA_PEDIGREE_ADD_SELSIRE, ['[father]' => $helper->getConfig('father', '')]), |
||||
368 | 'pages' => $pages, |
||||
369 | ]); |
||||
370 | break; |
||||
371 | |||||
372 | case 'dam': |
||||
373 | if (empty($random)) { |
||||
374 | $random = Request::getInt('random', 0); |
||||
375 | } |
||||
376 | $st = Request::getInt('st', 0, 'GET'); |
||||
377 | //make the redirect |
||||
378 | if (!isset($_GET['r'])) { |
||||
379 | //insert into pedigree_temp |
||||
380 | // $query = 'UPDATE ' . $GLOBALS['xoopsDB']->prefix('pedigree_temp') . ' SET father =' . $_GET['selsire'] . ' WHERE id=' . $random; |
||||
381 | $query = 'UPDATE ' . $GLOBALS['xoopsDB']->prefix('pedigree_temp') . ' SET father =' . Request::getInt('selsire', 0, 'GET') . ' WHERE id=' . $random; |
||||
382 | //@todo figure out what's suppose to happen here. Query results don't go anywhere... |
||||
383 | $GLOBALS['xoopsDB']->queryF($query); |
||||
384 | $helper->redirect('add_litter.php?f=dam&random=' . $random . '&st=' . $st . '&r=1', Constants::REDIRECT_DELAY_SHORT, strtr(_MA_PEDIGREE_ADD_SIREOK, ['[mother]' => $helper->getConfig('mother', '')])); |
||||
385 | } |
||||
386 | //find letter on which to start else set to 'a' |
||||
387 | $l = Request::getString('l', 'a', 'GET'); |
||||
388 | //assign sire to the template |
||||
389 | |||||
390 | $GLOBALS['xoopsTpl']->assign('sire', '1'); |
||||
391 | //create list of males dog to select from |
||||
392 | $perPage = (int)$helper->getConfig('perpage', Constants::DEFAULT_PER_PAGE); |
||||
393 | $perPage = (int)$perPage > 0 ? (int)$perPage : Constants::DEFAULT_PER_PAGE; //set default number of pages if invalid value in module preferences |
||||
394 | //count total number of dogs |
||||
395 | $numDog = 'SELECT id FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_registry') . " WHERE roft='1' AND pname LIKE '" . $GLOBALS['xoopsDB']->escape($l) . "%'"; |
||||
396 | $numRes = $GLOBALS['xoopsDB']->query($numDog); |
||||
397 | //total number of dogs the query will find |
||||
398 | $numResults = $GLOBALS['xoopsDB']->getRowsNum($numRes); |
||||
399 | //total number of pages |
||||
400 | $numPages = floor($numResults / $perPage) + 1; |
||||
401 | if (($numPages * $perPage) == ($numResults + $perPage)) { |
||||
402 | --$numPages; |
||||
403 | } |
||||
404 | //find current page |
||||
405 | $currentPage = floor($st / $perPage) + 1; |
||||
406 | //create alphabet |
||||
407 | $pages = ''; |
||||
408 | //@todo need to rework this as it's only valid for English |
||||
409 | for ($i = 65; $i <= 90; ++$i) { |
||||
410 | if ($l == chr($i)) { |
||||
411 | $pages .= '<b><a href="' . $helper->url('add_litter.php?f=dam&r=1&random=' . $random . '&l=' . chr($i)) . '">' . chr($i) . '</a></b> '; |
||||
412 | } else { |
||||
413 | $pages .= '<a href="' . $helper->url('add_litter.php?f=dam&r=1&random=' . $random . '&l=' . chr($i)) . '">' . chr($i) . '</a> '; |
||||
414 | } |
||||
415 | } |
||||
416 | $pages .= '- '; |
||||
417 | $pages .= '<a href="' . $helper->url('add_litter.php?f=dam&r=1&random=' . $random . '&l=Ã…') . '">Ã…</a> '; |
||||
418 | $pages .= '<a href="' . $helper->url('add_litter.php?f=dam&r=1&random=' . $random . '&l=Ö') . '">Ö</a> '; |
||||
419 | //create linebreak |
||||
420 | $pages .= '<br>'; |
||||
421 | //create previous button |
||||
422 | if ($numPages > 1) { |
||||
423 | if ($currentPage > 1) { |
||||
424 | $pages .= '<a href="' . $helper->url('add_litter.php?f=dam&r=1&l=' . $l . '&random=' . $random . '&st=' . ($st - $perPage)) . '">' . _MA_PEDIGREE_PREVIOUS . '</a>  '; |
||||
425 | } |
||||
426 | } |
||||
427 | //create numbers |
||||
428 | for ($x = 1; $x < ($numPages + 1); ++$x) { |
||||
429 | //create line break after 20 number |
||||
430 | if (0 == ($x % 20)) { |
||||
431 | $pages .= '<br>'; |
||||
432 | } |
||||
433 | if ($x != $currentPage) { |
||||
434 | $pages .= '<a href="' . $helper->url('add_litter.php?f=dam&r=1&l=' . $l . '&random=' . $random . '&st=' . ($perPage * ($x - 1))) . '">' . $x . '</a> '; |
||||
435 | } else { |
||||
436 | $pages .= $x . '  '; |
||||
437 | } |
||||
438 | } |
||||
439 | //create next button |
||||
440 | if ($numPages > 1) { |
||||
441 | if ($currentPage < $numPages) { |
||||
442 | $pages .= '<a href="' . $helper->url('add_litter.php?f=dam&r=1&l=' . $l . '&random=' . $random . '&st=' . ($st + $perPage)) . '">' . _MA_PEDIGREE_NEXT . '</a>  '; |
||||
443 | } |
||||
444 | } |
||||
445 | //query |
||||
446 | $sql = 'SELECT * FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_registry') . " WHERE roft = '1' AND pname LIKE '" . $l . "%' ORDER BY pname LIMIT " . $st . ', ' . $perPage; |
||||
447 | $result = $GLOBALS['xoopsDB']->query($sql); |
||||
448 | |||||
449 | $animal = new Pedigree\Animal(); |
||||
450 | //test to find out how many user fields there are... |
||||
451 | $fields = $animal->getNumOfFields(); |
||||
452 | $numOfColumns = 1; |
||||
453 | $columns[] = ['columnname' => 'Name']; |
||||
454 | foreach ($fields as $i => $iValue) { |
||||
455 | $userField = new Pedigree\Field($fields[$i], $animal->getConfig()); |
||||
456 | $fieldType = $userField->getSetting('fieldtype'); |
||||
457 | $fieldObject = new $fieldType($userField, $animal); |
||||
458 | //create empty string |
||||
459 | $lookupValues = ''; |
||||
460 | if ($userField->isActive() && $userField->inList()) { |
||||
461 | if ($userField->hasLookup()) { |
||||
462 | $lookupValues = $userField->lookupField($fields[$i]); |
||||
463 | //debug information |
||||
464 | //print_r($lookupValues); |
||||
465 | } |
||||
466 | $columns[] = [ |
||||
467 | 'columnname' => $fieldObject->fieldname, |
||||
468 | 'columnnumber' => $userField->getId(), |
||||
469 | 'lookupval' => $lookupValues, |
||||
470 | ]; |
||||
471 | ++$numOfColumns; |
||||
472 | unset($lookupValues); |
||||
473 | } |
||||
474 | } |
||||
475 | |||||
476 | $empty = array_fill(0, $numOfColumns - 1, ['value' => '']); |
||||
477 | /* |
||||
478 | $empty = []; //initialize the array |
||||
479 | for ($i = 1; $i < $numOfColumns; ++$i) { |
||||
480 | $empty[] = ['value' => '']; |
||||
481 | } |
||||
482 | */ |
||||
483 | $dogs [] = [ |
||||
484 | 'id' => '0', |
||||
485 | 'name' => '', |
||||
486 | 'gender' => '', |
||||
487 | 'link' => '<a href="add_litter.php?f=check&random=' . $random . '&seldam=0">' . strtr(_MA_PEDIGREE_ADD_DAMUNKNOWN, ['[mother]' => $helper->getConfig('mother', '')]) . '</a>', |
||||
488 | 'colour' => '', |
||||
489 | 'number' => '', |
||||
490 | 'usercolumns' => $empty, |
||||
491 | ]; |
||||
492 | |||||
493 | while (false !== ($row = $GLOBALS['xoopsDB']->fetchArray($result))) { |
||||
494 | //create picture information |
||||
495 | $camera = ('' != $row['foto']) ? " <img src=\"" . PEDIGREE_IMAGE_URL . "/camera.png\">" : ''; |
||||
496 | $name = stripslashes($row['pname']) . $camera; |
||||
497 | //empty array |
||||
498 | unset($columnvalue); |
||||
499 | //fill array |
||||
500 | for ($i = 1; $i < $numOfColumns; ++$i) { |
||||
501 | $x = $columns[$i]['columnnumber']; |
||||
502 | if (is_array($columns[$i]['lookupval'])) { |
||||
503 | foreach ($columns[$i]['lookupval'] as $key => $keyValue) { |
||||
504 | if ($key == $row['user' . $x]) { |
||||
505 | $value = $keyValue['value']; |
||||
506 | } |
||||
507 | } |
||||
508 | //debug information |
||||
509 | ///echo $columns[$i]['columnname']."is an array !"; |
||||
510 | } //format value - cant use object because of query count |
||||
511 | elseif (0 === strncmp($row['user' . $x], 'http://', 7)) { |
||||
512 | $value = '<a href="' . $row['user' . $x] . '">' . $row['user' . $x] . '</a>'; |
||||
513 | } else { |
||||
514 | $value = $row['user' . $x]; |
||||
515 | } |
||||
516 | $columnvalue[] = ['value' => $value]; |
||||
517 | } |
||||
518 | $dogs[] = [ |
||||
519 | 'id' => $row['id'], |
||||
520 | 'name' => $name, |
||||
521 | 'gender' => "<img src=\"" . PEDIGREE_IMAGE_URL . "/female.gif\">", |
||||
522 | 'link' => '<a href="add_litter.php?f=check&random=' . $random . '&seldam=' . $row['id'] . '">' . $name . '</a>', |
||||
523 | 'colour' => '', |
||||
524 | 'number' => '', |
||||
525 | 'usercolumns' => $columnvalue, |
||||
526 | ]; |
||||
527 | } |
||||
528 | |||||
529 | //add data to smarty template |
||||
530 | //assign dog |
||||
531 | $GLOBALS['xoopsTpl']->assign([ |
||||
532 | 'dogs' => $dogs, |
||||
533 | 'columns' => $columns, |
||||
534 | 'numofcolumns' => $numOfColumns, |
||||
535 | 'tsarray' => Pedigree\Utility::sortTable($numOfColumns), |
||||
536 | 'nummatch' => strtr(_MA_PEDIGREE_ADD_SELDAM, ['[mother]' => $helper->getConfig('mother', '')]), |
||||
537 | 'pages' => $pages, |
||||
538 | ]); |
||||
539 | break; |
||||
540 | case 'check': |
||||
541 | if (empty($random)) { |
||||
542 | $random = Request::getInt('random', 0); |
||||
543 | } |
||||
544 | //query |
||||
545 | $sql = 'SELECT * FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_temp') . ' WHERE id = ' . $random; |
||||
546 | $result = $GLOBALS['xoopsDB']->query($sql); |
||||
547 | $seldam = Request::getInt('seldam', 0, 'GET'); |
||||
548 | while (false !== ($row = $GLOBALS['xoopsDB']->fetchArray($result))) { |
||||
549 | //pull data apart. |
||||
550 | if ('' !== $row['pname']) { |
||||
551 | $genders = explode(':', $row['roft']); |
||||
552 | $names = explode(':', $row['pname']); |
||||
553 | $namesCount = count($names); |
||||
554 | for ($c = 1; $c < $namesCount; ++$c) { |
||||
555 | //$query = 'INSERT INTO ' . $GLOBALS['xoopsDB']->prefix('pedigree_registry') . " VALUES ('','" . addslashes($names[$c]) . "','0','" . $row['id_breeder'] . "','" . $row['user'] . "','" . $genders[$c] . "','" . $_GET['seldam'] . "','" . $row['father'] . "','',''"; |
||||
556 | $query = 'INSERT INTO ' |
||||
557 | . $GLOBALS['xoopsDB']->prefix('pedigree_registry') |
||||
558 | . " VALUES ('','" |
||||
559 | . $GLOBALS['xoopsDB']->escape($names[$c]) |
||||
560 | . "','0','" |
||||
561 | . $GLOBALS['xoopsDB']->escape($row['id_breeder']) |
||||
562 | . "','" |
||||
563 | . $GLOBALS['xoopsDB']->escape($row['user']) |
||||
564 | . "','" |
||||
565 | . $GLOBALS['xoopsDB']->escape($genders[$c]) |
||||
566 | . "','" |
||||
567 | . $GLOBALS['xoopsDB']->escape($seldam) |
||||
568 | . "','" |
||||
569 | . $GLOBALS['xoopsDB']->escape($row['father']) |
||||
570 | . "','',''"; |
||||
571 | //create animal object |
||||
572 | $animal = new Pedigree\Animal(); |
||||
573 | //test to find out how many user fields there are.. |
||||
574 | $fields = $animal->getNumOfFields(); |
||||
575 | sort($fields); |
||||
576 | foreach ($fields as $i => $iValue) { |
||||
577 | $userfields{$fields[$i]} = explode(':', $row['user' . $iValue]); |
||||
578 | $query .= ",'" . $userfields{$fields[$i]} |
||||
579 | [$c] . "'"; |
||||
580 | } |
||||
581 | //insert into pedigree |
||||
582 | $query .= ');'; |
||||
583 | $GLOBALS['xoopsDB']->queryF($query); |
||||
584 | } |
||||
585 | } |
||||
586 | $sqlQuery = 'DELETE FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_temp') . " WHERE id='" . $random . "'"; |
||||
587 | } |
||||
588 | $helper->redirect('latest.php', 1, strtr(_MA_PEDIGREE_ADD_LIT_OK, ['[animalTypes]' => $helper->getConfig('animalTypes')])); |
||||
589 | break; |
||||
590 | } |
||||
591 | |||||
592 | //footer |
||||
593 | require XOOPS_ROOT_PATH . '/footer.php'; |
||||
594 |
Let?s assume that you have a directory layout like this:
and let?s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as
OtherDir/Foo.php
does not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php
, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: