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