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