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