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