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