1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* You may not change or alter any portion of this comment or credits |
4
|
|
|
* of supporting developers from this source code or any supporting source code |
5
|
|
|
* which is considered copyrighted (c) material of the original comment or credit authors. |
6
|
|
|
* |
7
|
|
|
* This program is distributed in the hope that it will be useful, |
8
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
9
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* @package XoopsModules\Pedigree |
14
|
|
|
* @copyright {@link https://xoops.org/ XOOPS Project} |
15
|
|
|
* @license {@link https://www.gnu.org/licenses/gpl-2.0.html GNU GPL 2 or later} |
16
|
|
|
* @since |
17
|
|
|
* @author Tobias Liegl (aka CHAPI) |
18
|
|
|
* @author XOOPS Development Team |
19
|
|
|
* @link http://www.chapi.de |
20
|
|
|
*/ |
21
|
|
|
|
22
|
|
|
use XoopsModules\Pedigree\{ |
23
|
|
|
Constants, |
24
|
|
|
Helper |
25
|
|
|
}; |
26
|
|
|
|
27
|
|
|
|
28
|
|
|
xoops_load('Pedigree\Animal', $moduleDirName); |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @param $columncount |
32
|
|
|
* |
33
|
|
|
* @return string |
34
|
|
|
*/ |
35
|
|
|
function sortTable($columncount) |
36
|
|
|
{ |
37
|
|
|
$ttemp = ''; |
38
|
|
|
if ($columncount > 1) { |
39
|
|
|
for ($t = 1; $t < $columncount; ++$t) { |
40
|
|
|
$ttemp .= "'S',"; |
41
|
|
|
} |
42
|
|
|
$tsarray = "initSortTable('Result', Array({$ttemp}'S'));"; |
43
|
|
|
} else { |
44
|
|
|
$tsarray = "initSortTable('Result',Array('S'));"; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
return $tsarray; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @param $num |
52
|
|
|
* |
53
|
|
|
* @return string |
54
|
|
|
*/ |
55
|
|
|
function uploadPicture($num) |
56
|
|
|
{ |
57
|
|
|
$max_imgsize = $GLOBALS['xoopsModuleConfig']['maxfilesize']; //1024000; |
58
|
|
|
$max_imgwidth = $GLOBALS['xoopsModuleConfig']['maximgwidth']; //1500; |
59
|
|
|
$max_imgheight = $GLOBALS['xoopsModuleConfig']['maximgheight']; //1000; |
60
|
|
|
$allowed_mimetypes = ['image/gif', 'image/jpeg', 'image/pjpeg', 'image/x-png', 'image/png']; |
61
|
|
|
// $img_dir = XOOPS_ROOT_PATH . "/modules/" . $GLOBALS['xoopsModule']->dirname() . "/images" ; |
62
|
|
|
$img_dir = $GLOBALS['xoopsModuleConfig']['uploaddir'] . '/images'; |
63
|
|
|
require_once $GLOBALS['xoops']->path('class/uploader.php'); |
64
|
|
|
$field = $_POST['xoops_upload_file'][$num]; |
65
|
|
|
if (!empty($field) || '' != $field) { |
66
|
|
|
$uploader = new \XoopsMediaUploader($img_dir, $allowed_mimetypes, $max_imgsize, $max_imgwidth, $max_imgheight); |
67
|
|
|
$uploader->setPrefix('img'); |
68
|
|
|
if ($uploader->fetchMedia($field) && $uploader->upload()) { |
69
|
|
|
$photo = $uploader->getSavedFileName(); |
70
|
|
|
} else { |
71
|
|
|
echo $uploader->getErrors(); |
72
|
|
|
} |
73
|
|
|
createThumbs($photo); |
|
|
|
|
74
|
|
|
|
75
|
|
|
return $photo; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
return ''; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @param $filename |
83
|
|
|
*/ |
84
|
|
|
function createThumbs($filename) |
85
|
|
|
{ |
86
|
|
|
/* |
87
|
|
|
require_once __DIR__ . '/phpthumb/phpthumb.class.php'; |
88
|
|
|
$thumbnail_widths = array(150, 400); |
89
|
|
|
foreach ($thumbnail_widths as $thumbnail_width) { |
90
|
|
|
$phpThumb = new phpThumb(); |
91
|
|
|
// set data |
92
|
|
|
$phpThumb->setSourceFilename('images/' . $filename); |
93
|
|
|
$phpThumb->w = $thumbnail_width; |
94
|
|
|
$phpThumb->config_output_format = 'jpeg'; |
95
|
|
|
// generate & output thumbnail |
96
|
|
|
$output_filename = 'images/thumbnails/' . basename($filename) . '_' . $thumbnail_width . '.' . $phpThumb->config_output_format; |
97
|
|
|
if ($phpThumb->GenerateThumbnail()) { // this line is VERY important, do not remove it! |
98
|
|
|
if ($output_filename) { |
99
|
|
|
if ($phpThumb->RenderToFile($output_filename)) { |
100
|
|
|
// do something on success |
101
|
|
|
//echo 'Successfully rendered:<br><img src="'.$output_filename.'">'; |
102
|
|
|
} else { |
103
|
|
|
echo 'Failed (size=' . $thumbnail_width . '):<pre>' . implode("\n\n", $phpThumb->debugmessages) . '</pre>'; |
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
} else { |
107
|
|
|
echo 'Failed (size=' . $thumbnail_width . '):<pre>' . implode("\n\n", $phpThumb->debugmessages) . '</pre>'; |
108
|
|
|
} |
109
|
|
|
unset($phpThumb); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
return true; |
113
|
|
|
|
114
|
|
|
*/ |
115
|
|
|
|
116
|
|
|
// load the image |
117
|
|
|
require_once $GLOBALS['xoops']->path('modules/' . $GLOBALS['xoopsModule']->dirname() . '/library/Zebra_Image.php'); |
118
|
|
|
$thumbnail_widths = [150, 400]; |
119
|
|
|
|
120
|
|
|
// indicate a target image |
121
|
|
|
// note that there's no extra property to set in order to specify the target |
122
|
|
|
// image's type -simply by writing '.jpg' as extension will instruct the script |
123
|
|
|
// to create a 'jpg' file |
124
|
|
|
$config_output_format = 'jpeg'; |
125
|
|
|
|
126
|
|
|
// create a new instance of the class |
127
|
|
|
$image = new Zebra_Image(); |
128
|
|
|
// indicate a source image (a GIF, PNG or JPEG file) |
129
|
|
|
$image->source_path = PEDIGREE_UPLOAD_PATH . "/images/{$filename}"; |
|
|
|
|
130
|
|
|
|
131
|
|
|
foreach ($thumbnail_widths as $thumbnail_width) { |
132
|
|
|
// generate & output thumbnail |
133
|
|
|
$output_filename = PEDIGREE_UPLOAD_PATH . '/images/thumbnails/' . basename($filename) . "_{$thumbnail_width}.{$config_output_format}"; |
134
|
|
|
$image->target_path = $output_filename; |
135
|
|
|
// since in this example we're going to have a jpeg file, let's set the output |
136
|
|
|
// image's quality |
137
|
|
|
$image->jpeg_quality = 100; |
138
|
|
|
// some additional properties that can be set |
139
|
|
|
// read about them in the documentation |
140
|
|
|
$image->preserve_aspect_ratio = true; |
141
|
|
|
$image->enlarge_smaller_images = true; |
142
|
|
|
$image->preserve_time = true; |
143
|
|
|
|
144
|
|
|
// resize the image to exactly 100x100 pixels by using the "crop from center" method |
145
|
|
|
// (read more in the overview section or in the documentation) |
146
|
|
|
// and if there is an error, check what the error is about |
147
|
|
|
if (!$image->resize($thumbnail_width, 0)) { |
148
|
|
|
// if there was an error, let's see what the error is about |
149
|
|
|
switch ($image->error) { |
150
|
|
|
case 1: |
151
|
|
|
echo 'Source file could not be found!'; |
152
|
|
|
break; |
153
|
|
|
case 2: |
154
|
|
|
echo 'Source file is not readable!'; |
155
|
|
|
break; |
156
|
|
|
case 3: |
157
|
|
|
echo 'Could not write target file!'; |
158
|
|
|
break; |
159
|
|
|
case 4: |
160
|
|
|
echo 'Unsupported source file format!'; |
161
|
|
|
break; |
162
|
|
|
case 5: |
163
|
|
|
echo 'Unsupported target file format!'; |
164
|
|
|
break; |
165
|
|
|
case 6: |
166
|
|
|
echo 'GD library version does not support target file format!'; |
167
|
|
|
break; |
168
|
|
|
case 7: |
169
|
|
|
echo 'GD library is not installed!'; |
170
|
|
|
break; |
171
|
|
|
case 8: |
172
|
|
|
echo '"chmod" command is disabled via configuration!'; |
173
|
|
|
break; |
174
|
|
|
} |
175
|
|
|
// if no errors |
176
|
|
|
} else { |
177
|
|
|
echo 'Success!'; |
178
|
|
|
} |
179
|
|
|
/* |
180
|
|
|
if ($phpThumb->GenerateThumbnail()) { // this line is VERY important, do not remove it! |
181
|
|
|
if ($output_filename) { |
182
|
|
|
if ($phpThumb->RenderToFile($output_filename)) { |
183
|
|
|
// do something on success |
184
|
|
|
//echo 'Successfully rendered:<br><img src="'.$output_filename.'">'; |
185
|
|
|
} else { |
186
|
|
|
echo 'Failed (size='.$thumbnail_width.'):<pre>'.implode("\n\n", $phpThumb->debugmessages).'</pre>'; |
187
|
|
|
} |
188
|
|
|
} |
189
|
|
|
} else { |
190
|
|
|
echo 'Failed (size='.$thumbnail_width.'):<pre>'.implode("\n\n", $phpThumb->debugmessages).'</pre>'; |
191
|
|
|
} |
192
|
|
|
*/ |
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
unset($image); |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
/** |
199
|
|
|
* @param $string |
200
|
|
|
* |
201
|
|
|
* @return string |
202
|
|
|
*/ |
203
|
|
|
function unHtmlEntities($string) |
204
|
|
|
{ |
205
|
|
|
$trans_tbl = array_flip(get_html_translation_table(HTML_ENTITIES)); |
206
|
|
|
|
207
|
|
|
return strtr($string, $trans_tbl); |
208
|
|
|
} |
209
|
|
|
|
210
|
|
|
/** |
211
|
|
|
* @param $oid |
212
|
|
|
* @param $gender |
213
|
|
|
*/ |
214
|
|
|
function pups($oid, $gender) |
215
|
|
|
{ |
216
|
|
|
global $numofcolumns, $numMatch, $pages, $columns, $dogs; |
217
|
|
|
$content = ''; |
|
|
|
|
218
|
|
|
if (0 == $gender) { |
219
|
|
|
$sqlQuery = 'SELECT d.id AS d_id, d.pname AS d_pname, d.roft AS d_roft, d.* FROM ' |
220
|
|
|
. $GLOBALS['xoopsDB']->prefix('pedigree_registry') |
221
|
|
|
. ' d LEFT JOIN ' |
222
|
|
|
. $GLOBALS['xoopsDB']->prefix('pedigree_registry') |
223
|
|
|
. ' f ON d.father = f.id LEFT JOIN ' |
224
|
|
|
. $GLOBALS['xoopsDB']->prefix('pedigree_registry') |
225
|
|
|
. ' m ON d.mother = m.id WHERE d.father=' |
226
|
|
|
. $oid |
227
|
|
|
. ' ORDER BY d.pname'; |
228
|
|
|
} else { //@todo - what's suppose to happen for females? this is the same as for male above |
229
|
|
|
$sqlQuery = 'SELECT d.id AS d_id, d.pname AS d_pname, d.roft AS d_roft, d.* FROM ' |
230
|
|
|
. $GLOBALS['xoopsDB']->prefix('pedigree_registry') |
231
|
|
|
. ' d LEFT JOIN ' |
232
|
|
|
. $GLOBALS['xoopsDB']->prefix('pedigree_registry') |
233
|
|
|
. ' f ON d.father = f.id LEFT JOIN ' |
234
|
|
|
. $GLOBALS['xoopsDB']->prefix('pedigree_registry') |
235
|
|
|
. ' m ON d.mother = m.id WHERE d.mother=' |
236
|
|
|
. $oid |
237
|
|
|
. ' ORDER BY d.pname'; |
238
|
|
|
} |
239
|
|
|
$queryResult = $GLOBALS['xoopsDB']->query($sqlQuery); |
240
|
|
|
$numMatch = $GLOBALS['xoopsDB']->getRowsNum($queryResult); |
241
|
|
|
|
242
|
|
|
$animal = new Pedigree\Animal(); |
|
|
|
|
243
|
|
|
//test to find out how many user fields there are... |
244
|
|
|
$fields = $animal->getNumOfFields(); |
245
|
|
|
$numofcolumns = 1; |
246
|
|
|
$columns[] = ['columnname' => 'Name']; |
247
|
|
|
foreach ($fields as $i => $iValue) { |
248
|
|
|
$userField = new Pedigree\Field($fields[$i], $animal->getConfig()); |
|
|
|
|
249
|
|
|
$fieldType = $userField->getSetting('fieldtype'); |
250
|
|
|
$fieldObject = new $fieldType($userField, $animal); |
251
|
|
|
//create empty string |
252
|
|
|
$lookupValues = ''; |
253
|
|
|
if ($userField->isActive() && $userField->inList()) { |
254
|
|
|
if ($userField->hasLookup()) { |
255
|
|
|
$lookupValues = $userField->lookupField($fields[$i]); |
256
|
|
|
//debug information |
257
|
|
|
//print_r($lookupValues); |
258
|
|
|
} |
259
|
|
|
$columns[] = [ |
260
|
|
|
'columnname' => $fieldObject->fieldname, |
261
|
|
|
'columnnumber' => $userField->getId(), |
262
|
|
|
'lookupval' => $lookupValues, |
263
|
|
|
]; |
264
|
|
|
++$numofcolumns; |
265
|
|
|
unset($lookupValues); |
266
|
|
|
} |
267
|
|
|
} |
268
|
|
|
|
269
|
|
|
while (false !== ($rowResult = $GLOBALS['xoopsDB']->fetchArray($queryResult))) { |
270
|
|
|
if ('0' == $rowResult['d_roft']) { |
271
|
|
|
$gender = '<img src="assets/images/male.gif">'; |
272
|
|
|
} else { |
273
|
|
|
$gender = '<img src="assets/images/female.gif">'; |
274
|
|
|
} |
275
|
|
|
$name = stripslashes($rowResult['d_pname']); |
276
|
|
|
//empty array |
277
|
|
|
unset($columnvalue); |
278
|
|
|
//fill array |
279
|
|
|
for ($i = 1; $i < $numofcolumns; ++$i) { |
280
|
|
|
$x = $columns[$i]['columnnumber']; |
281
|
|
|
if (is_array($columns[$i]['lookupval'])) { |
282
|
|
|
foreach ($columns[$i]['lookupval'] as $key => $keyValue) { |
283
|
|
|
if ($keyValue['id'] == $rowResult['user' . $x]) { |
284
|
|
|
$value = $keyValue['value']; |
285
|
|
|
} |
286
|
|
|
} |
287
|
|
|
//debug information |
288
|
|
|
///echo $columns[$i]['columnname']."is an array !"; |
289
|
|
|
} //format value - cant use object because of query count |
290
|
|
|
elseif (0 === strncmp($rowResult['user' . $x], 'http://', 7)) { |
291
|
|
|
$value = '<a href="' . $rowResult['user' . $x] . '">' . $rowResult['user' . $x] . '</a>'; |
292
|
|
|
} else { |
293
|
|
|
$value = $rowResult['user' . $x]; |
294
|
|
|
} |
295
|
|
|
$columnvalue[] = ['value' => $value]; |
|
|
|
|
296
|
|
|
} |
297
|
|
|
$dogs[] = [ |
298
|
|
|
'id' => $rowResult['d_id'], |
299
|
|
|
'name' => $name, |
300
|
|
|
'gender' => $gender, |
301
|
|
|
'link' => '<a href="dog.php?id=' . $rowResult['d_id'] . '">' . $name . '</a>', |
302
|
|
|
'colour' => '', |
303
|
|
|
'number' => '', |
304
|
|
|
'usercolumns' => $columnvalue, |
|
|
|
|
305
|
|
|
]; |
306
|
|
|
} |
307
|
|
|
|
308
|
|
|
return null; |
309
|
|
|
} |
310
|
|
|
|
311
|
|
|
/** |
312
|
|
|
* @param $oid |
313
|
|
|
* @param $pa |
314
|
|
|
* @param $ma |
315
|
|
|
*/ |
316
|
|
|
function bas($oid, $pa, $ma) |
317
|
|
|
{ |
318
|
|
|
global $numofcolumns1, $nummatch1, $pages1, $columns1, $dogs1; |
319
|
|
|
if ('0' == $pa && '0' == $ma) { |
320
|
|
|
$sqlQuery = 'SELECT * FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_registry') . ' WHERE father = ' . $pa . ' AND mother = ' . $ma . ' AND id != ' . $oid . " AND father != '0' AND mother !='0' ORDER BY pname"; |
321
|
|
|
} else { |
322
|
|
|
$sqlQuery = 'SELECT * FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_registry') . ' WHERE father = ' . $pa . ' AND mother = ' . $ma . ' AND id != ' . $oid . ' ORDER BY pname'; |
323
|
|
|
} |
324
|
|
|
$queryResult = $GLOBALS['xoopsDB']->query($sqlQuery); |
325
|
|
|
$nummatch1 = $GLOBALS['xoopsDB']->getRowsNum($queryResult); |
326
|
|
|
|
327
|
|
|
$animal = new Pedigree\Animal(); |
328
|
|
|
//test to find out how many user fields there are... |
329
|
|
|
$fields = $animal->getNumOfFields(); |
330
|
|
|
$numofcolumns1 = 1; |
331
|
|
|
$columns1[] = ['columnname' => 'Name']; |
332
|
|
|
foreach ($fields as $i => $iValue) { |
333
|
|
|
$userField = new Pedigree\Field($fields[$i], $animal->getConfig()); |
334
|
|
|
$fieldType = $userField->getSetting('fieldtype'); |
335
|
|
|
$fieldObject = new $fieldType($userField, $animal); |
336
|
|
|
//create empty string |
337
|
|
|
$lookupValues = ''; |
338
|
|
|
if ($userField->isActive() && $userField->inList()) { |
339
|
|
|
if ($userField->hasLookup()) { |
340
|
|
|
$lookupValues = $userField->lookupField($fields[$i]); |
341
|
|
|
//debug information |
342
|
|
|
//print_r($lookupValues); |
343
|
|
|
} |
344
|
|
|
$columns1[] = [ |
345
|
|
|
'columnname' => $fieldObject->fieldname, |
346
|
|
|
'columnnumber' => $userField->getId(), |
347
|
|
|
'lookupval' => $lookupValues, |
348
|
|
|
]; |
349
|
|
|
++$numofcolumns1; |
350
|
|
|
unset($lookupValues); |
351
|
|
|
} |
352
|
|
|
} |
353
|
|
|
|
354
|
|
|
while (false !== ($rowResult = $GLOBALS['xoopsDB']->fetchArray($queryResult))) { |
355
|
|
|
if (0 == $rowResult['roft']) { |
356
|
|
|
$gender = "<img src='assets/images/male.gif'>"; |
357
|
|
|
} else { |
358
|
|
|
$gender = "<img src='assets/images/female.gif'>"; |
359
|
|
|
} |
360
|
|
|
$name = stripslashes($rowResult['pname']); |
361
|
|
|
//empty array |
362
|
|
|
// unset($columnvalue1); |
363
|
|
|
$columnvalue1 = []; |
364
|
|
|
//fill array |
365
|
|
|
for ($i = 1; $i < $numofcolumns1; ++$i) { |
366
|
|
|
$x = $columns1[$i]['columnnumber']; |
367
|
|
|
if (is_array($columns1[$i]['lookupval'])) { |
368
|
|
|
foreach ($columns1[$i]['lookupval'] as $key => $keyValue) { |
369
|
|
|
if ($keyValue['id'] == $rowResult['user' . $x]) { |
370
|
|
|
$value = $keyValue['value']; |
371
|
|
|
} |
372
|
|
|
} |
373
|
|
|
//debug information |
374
|
|
|
///echo $columns[$i]['columnname']."is an array !"; |
375
|
|
|
} //format value - cant use object because of query count |
376
|
|
|
elseif (0 === strncmp($rowResult['user' . $x], 'http://', 7)) { |
377
|
|
|
$value = '<a href="' . $rowResult['user' . $x] . '">' . $rowResult['user' . $x] . '</a>'; |
378
|
|
|
} else { |
379
|
|
|
$value = $rowResult['user' . $x]; |
380
|
|
|
} |
381
|
|
|
$columnvalue1[] = ['value' => $value]; |
|
|
|
|
382
|
|
|
} |
383
|
|
|
$dogs1[] = [ |
384
|
|
|
'id' => $rowResult['id'], |
385
|
|
|
'name' => $name, |
386
|
|
|
'gender' => $gender, |
387
|
|
|
'link' => '<a href="dog.php?id=' . $rowResult['id'] . '">' . $name . '</a>', |
388
|
|
|
'colour' => '', |
389
|
|
|
'number' => '', |
390
|
|
|
'usercolumns' => $columnvalue1, |
391
|
|
|
]; |
392
|
|
|
} |
393
|
|
|
|
394
|
|
|
return null; |
395
|
|
|
} |
396
|
|
|
|
397
|
|
|
/** |
398
|
|
|
* @param $oid |
399
|
|
|
* @param $breeder |
400
|
|
|
* |
401
|
|
|
* @return string |
402
|
|
|
*/ |
403
|
|
|
function breederof($oid, $breeder) |
404
|
|
|
{ |
405
|
|
|
$content = ''; |
406
|
|
|
|
407
|
|
|
if (0 == $breeder) { |
408
|
|
|
$sqlQuery = 'SELECT id, pname, roft FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_registry') . " WHERE id_owner = '" . $oid . "' ORDER BY pname"; |
409
|
|
|
} else { |
410
|
|
|
$sqlQuery = 'SELECT id, pname, roft FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_registry') . " WHERE id_breeder = '" . $oid . "' ORDER BY pname"; |
411
|
|
|
} |
412
|
|
|
$queryResult = $GLOBALS['xoopsDB']->query($sqlQuery); |
413
|
|
|
while (false !== ($rowResult = $GLOBALS['xoopsDB']->fetchArray($queryResult))) { |
414
|
|
|
if ('0' == $rowResult['roft']) { |
415
|
|
|
$gender = '<img src="assets/images/male.gif">'; |
416
|
|
|
} else { |
417
|
|
|
$gender = '<img src="assets/images/female.gif">'; |
418
|
|
|
} |
419
|
|
|
$link = '<a href="dog.php?id=' . $rowResult['id'] . '">' . stripslashes($rowResult['pname']) . '</a>'; |
420
|
|
|
$content .= $gender . ' ' . $link . '<br>'; |
421
|
|
|
} |
422
|
|
|
|
423
|
|
|
return $content; |
424
|
|
|
} |
425
|
|
|
|
426
|
|
|
/** |
427
|
|
|
* @param $oid |
428
|
|
|
* |
429
|
|
|
* @return string |
430
|
|
|
*/ |
431
|
|
|
function getName($oid) |
432
|
|
|
{ |
433
|
|
|
$oid = (int)$oid; |
434
|
|
|
$sqlQuery = 'SELECT pname FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_registry') . " WHERE id = '{$oid}'"; |
435
|
|
|
$queryResult = $GLOBALS['xoopsDB']->query($sqlQuery); |
436
|
|
|
while (false !== ($rowResult = $GLOBALS['xoopsDB']->fetchArray($queryResult))) { |
437
|
|
|
$an = stripslashes($rowResult['pname']); |
438
|
|
|
} |
439
|
|
|
|
440
|
|
|
return $an; |
|
|
|
|
441
|
|
|
} |
442
|
|
|
|
443
|
|
|
/** |
444
|
|
|
* @param $PA |
445
|
|
|
* @return string |
446
|
|
|
*/ |
447
|
|
|
function showParent($PA) |
448
|
|
|
{ |
449
|
|
|
$sqlQuery = 'SELECT pname FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_registry') . " WHERE id='" . $PA . "'"; |
450
|
|
|
$queryResult = $GLOBALS['xoopsDB']->query($sqlQuery); |
451
|
|
|
while (false !== ($rowResult = $GLOBALS['xoopsDB']->fetchArray($queryResult))) { |
452
|
|
|
$result = $rowResult['pname']; |
453
|
|
|
} |
454
|
|
|
if (isset($result)) { |
455
|
|
|
return $result; |
456
|
|
|
} |
457
|
|
|
|
458
|
|
|
return ''; |
459
|
|
|
} |
460
|
|
|
|
461
|
|
|
/** |
462
|
|
|
* @param $pname_hond |
463
|
|
|
* |
464
|
|
|
* @return mixed |
465
|
|
|
*/ |
466
|
|
|
function findId($pname_hond) |
467
|
|
|
{ |
468
|
|
|
$sqlQuery = 'SELECT id FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_registry') . " where pname= '$pname_hond'"; |
469
|
|
|
$queryResult = $GLOBALS['xoopsDB']->query($sqlQuery); |
470
|
|
|
while (false !== ($rowResult = $GLOBALS['xoopsDB']->fetchArray($queryResult))) { |
471
|
|
|
$result = $rowResult['id']; |
472
|
|
|
} |
473
|
|
|
|
474
|
|
|
return $result; |
|
|
|
|
475
|
|
|
} |
476
|
|
|
|
477
|
|
|
/** |
478
|
|
|
* @param $result |
479
|
|
|
* @param $prefix |
480
|
|
|
* @param $link |
481
|
|
|
* @param $element |
482
|
|
|
*/ |
483
|
|
|
function createList($result, $prefix, $link, $element) |
484
|
|
|
{ |
485
|
|
|
global $xoopsTpl; |
486
|
|
|
$animal = new Pedigree\Animal(); |
487
|
|
|
//test to find out how many user fields there are... |
488
|
|
|
$fields = $animal->getNumOfFields(); |
489
|
|
|
$numofcolumns = 1; |
490
|
|
|
$columns[] = ['columnname' => 'Name']; |
|
|
|
|
491
|
|
|
foreach ($fields as $i => $iValue) { |
492
|
|
|
$userField = new Pedigree\Field($fields[$i], $animal->getConfig()); |
493
|
|
|
$fieldType = $userField->getSetting('fieldtype'); |
494
|
|
|
$fieldObject = new $fieldType($userField, $animal); |
495
|
|
|
if ($userField->isActive() && $userField->inList()) { |
496
|
|
|
if ($userField->hasLookup()) { |
497
|
|
|
$id = $userField->getId(); |
498
|
|
|
$q = $userField->lookupField($id); |
499
|
|
|
} else { |
500
|
|
|
$q = ''; |
501
|
|
|
} |
502
|
|
|
$columns[] = [ |
503
|
|
|
'columnname' => $fieldObject->fieldname, |
504
|
|
|
'columnnumber' => $userField->getId(), |
505
|
|
|
'lookuparray' => $q, |
506
|
|
|
]; |
507
|
|
|
++$numofcolumns; |
508
|
|
|
} |
509
|
|
|
} |
510
|
|
|
|
511
|
|
|
//add preliminary row to array if passed |
512
|
|
|
if (is_array($prefix)) { |
513
|
|
|
$dogs[] = $prefix; |
|
|
|
|
514
|
|
|
} |
515
|
|
|
|
516
|
|
|
$helper = XoopsModules\Pedigree\Helper::getInstance(); |
517
|
|
|
require_once $helper->path('include/common.php'); |
518
|
|
|
|
519
|
|
|
while (false !== ($row = $GLOBALS['xoopsDB']->fetchArray($result))) { |
520
|
|
|
//reset $gender |
521
|
|
|
$gender = ''; |
522
|
|
|
if ((!empty($GLOBALS['xoopsUser']) && $GLOBALS['xoopsUser'] instanceof \XoopsUser) |
523
|
|
|
&& ($row['user'] == $GLOBALS['xoopsUser']->getVar('uid') || true === $modadmin)) { |
|
|
|
|
524
|
|
|
$gender = "<a href=\"dog.php?id={$row['id']}\">{$icons['edit']}</a> |
525
|
|
|
. <a href=\"'delete.php?id={$row['id']}\">{$icons['delete']}</a>"; |
526
|
|
|
} |
527
|
|
|
|
528
|
|
|
$genImg = (Constants::MALE == $row['roft']) ? 'male.gif' : 'female.gif'; |
529
|
|
|
$gender .= "<img src=\"" . PEDIGREE_IMAGE_PATH . "/{$genImg}'>"; |
530
|
|
|
|
531
|
|
|
if ('' != $row['foto']) { |
532
|
|
|
$camera = ' <img src="' . PEDIGREE_UPLOAD_URL . '/images/dog-icon25.png">'; |
|
|
|
|
533
|
|
|
} else { |
534
|
|
|
$camera = ''; |
535
|
|
|
} |
536
|
|
|
$name = stripslashes($row['pname']) . $camera; |
537
|
|
|
unset($columnvalue); |
538
|
|
|
|
539
|
|
|
//fill array |
540
|
|
|
for ($i = 1; $i < $numofcolumns; ++$i) { |
541
|
|
|
$x = $columns[$i]['columnnumber']; |
542
|
|
|
$lookuparray = $columns[$i]['lookuparray']; |
543
|
|
|
if (is_array($lookuparray)) { |
544
|
|
|
foreach ($lookuparray as $index => $indexValue) { |
545
|
|
|
if ($lookuparray[$index]['id'] == $row['user' . $x]) { |
546
|
|
|
//echo "<h1>".$lookuparray[$index]['id']."</h1>"; |
547
|
|
|
$value = $lookuparray[$index]['value']; |
548
|
|
|
} |
549
|
|
|
} |
550
|
|
|
} //format value - cant use object because of query count |
551
|
|
|
elseif (0 === strncmp($row['user' . $x], 'http://', 7)) { |
552
|
|
|
$value = '<a href="' . $row['user' . $x] . '">' . $row['user' . $x] . '</a>'; |
553
|
|
|
} else { |
554
|
|
|
$value = $row['user' . $x]; |
555
|
|
|
} |
556
|
|
|
$columnvalue[] = ['value' => $value]; |
|
|
|
|
557
|
|
|
unset($value); |
558
|
|
|
} |
559
|
|
|
|
560
|
|
|
$linkto = '<a href="' . $link . $row[$element] . '">' . $name . '</a>'; |
561
|
|
|
//create array |
562
|
|
|
$dogs[] = [ |
563
|
|
|
'id' => $row['id'], |
564
|
|
|
'name' => $name, |
565
|
|
|
'gender' => $gender, |
566
|
|
|
'link' => $linkto, |
567
|
|
|
'colour' => '', |
568
|
|
|
'number' => '', |
569
|
|
|
'usercolumns' => $columnvalue, |
|
|
|
|
570
|
|
|
]; |
571
|
|
|
} |
572
|
|
|
|
573
|
|
|
//add data to smarty template |
574
|
|
|
//assign dog |
575
|
|
|
$xoopsTpl->assign('dogs', $dogs); |
|
|
|
|
576
|
|
|
$xoopsTpl->assign('columns', $columns); |
577
|
|
|
$xoopsTpl->assign('numofcolumns', $numofcolumns); |
578
|
|
|
$xoopsTpl->assign('tsarray', Pedigree\Utility::sortTable($numofcolumns)); |
|
|
|
|
579
|
|
|
} |
580
|
|
|
|
581
|
|
|
/***************Blocks************** |
582
|
|
|
* |
583
|
|
|
* @param $cats |
584
|
|
|
* |
585
|
|
|
* @return string |
586
|
|
|
* @deprecated - NOT USED |
587
|
|
|
*/ |
588
|
|
|
function animal_block_addCatSelect($cats) |
589
|
|
|
{ |
590
|
|
|
if (is_array($cats)) { |
591
|
|
|
$cat_sql = '(' . current($cats); |
592
|
|
|
array_shift($cats); |
593
|
|
|
foreach ($cats as $cat) { |
594
|
|
|
$cat_sql .= ',' . $cat; |
595
|
|
|
} |
596
|
|
|
$cat_sql .= ')'; |
597
|
|
|
} |
598
|
|
|
|
599
|
|
|
return $cat_sql; |
|
|
|
|
600
|
|
|
} |
601
|
|
|
|
602
|
|
|
/** |
603
|
|
|
* @param $global |
604
|
|
|
* @param $key |
605
|
|
|
* @param string $default |
606
|
|
|
* @param string $type |
607
|
|
|
* |
608
|
|
|
* @return mixed|string |
609
|
|
|
* @deprecated |
610
|
|
|
*/ |
611
|
|
|
function animal_CleanVars(&$global, $key, $default = '', $type = 'int') |
612
|
|
|
{ |
613
|
|
|
switch ($type) { |
614
|
|
|
case 'string': |
615
|
|
|
$ret = isset($global[$key]) ? filter_var($global[$key], FILTER_SANITIZE_MAGIC_QUOTES) : $default; |
|
|
|
|
616
|
|
|
break; |
617
|
|
|
case 'int': |
618
|
|
|
default: |
619
|
|
|
$ret = isset($global[$key]) ? filter_var($global[$key], FILTER_SANITIZE_NUMBER_INT) : $default; |
620
|
|
|
break; |
621
|
|
|
} |
622
|
|
|
if (false === $ret) { |
623
|
|
|
return $default; |
624
|
|
|
} |
625
|
|
|
|
626
|
|
|
return $ret; |
627
|
|
|
} |
628
|
|
|
|
629
|
|
|
/** |
630
|
|
|
* @param $content |
631
|
|
|
* @deprecated - NOT USED |
632
|
|
|
*/ |
633
|
|
|
function animal_meta_keywords($content) |
634
|
|
|
{ |
635
|
|
|
global $xoopsTpl, $xoTheme; |
636
|
|
|
$myts = \MyTextSanitizer::getInstance(); |
637
|
|
|
$content = $myts->undoHtmlSpecialChars($myts->displayTarea($content)); |
638
|
|
|
if (isset($xoTheme) && is_object($xoTheme)) { |
639
|
|
|
$xoTheme->addMeta('meta', 'keywords', strip_tags($content)); |
640
|
|
|
} else { // Compatibility for old Xoops versions |
641
|
|
|
$xoopsTpl->assign('xoops_meta_keywords', strip_tags($content)); |
642
|
|
|
} |
643
|
|
|
} |
644
|
|
|
|
645
|
|
|
/** |
646
|
|
|
* @param $content |
647
|
|
|
* @deprecated - NOT USED |
648
|
|
|
*/ |
649
|
|
|
function animal_meta_description($content) |
650
|
|
|
{ |
651
|
|
|
global $xoopsTpl, $xoTheme; |
652
|
|
|
$myts = \MyTextSanitizer::getInstance(); |
653
|
|
|
$content = $myts->undoHtmlSpecialChars($myts->displayTarea($content)); |
654
|
|
|
if (isset($xoTheme) && is_object($xoTheme)) { |
655
|
|
|
$xoTheme->addMeta('meta', 'description', strip_tags($content)); |
656
|
|
|
} else { // Compatibility for old Xoops versions |
657
|
|
|
$xoopsTpl->assign('xoops_meta_description', strip_tags($content)); |
658
|
|
|
} |
659
|
|
|
} |
660
|
|
|
|
661
|
|
|
/** |
662
|
|
|
* Verify that a mysql table exists |
663
|
|
|
* |
664
|
|
|
* @package pedigree |
665
|
|
|
* @author Hervé Thouzard (http://www.herve-thouzard.com) |
666
|
|
|
* @copyright (c) Hervé Thouzard |
667
|
|
|
*/ |
668
|
|
|
//function tableExists($tablename) |
669
|
|
|
//{ |
670
|
|
|
// |
671
|
|
|
// $result=$GLOBALS['xoopsDB']->queryF("SHOW TABLES LIKE '$tablename'"); |
672
|
|
|
// return($GLOBALS['xoopsDB']->getRowsNum($result) > 0); |
673
|
|
|
//} |
674
|
|
|
|
675
|
|
|
/** |
676
|
|
|
* Create download by letter choice bar/menu |
677
|
|
|
* updated starting from this idea https://xoops.org/modules/news/article.php?storyid=6497 |
678
|
|
|
* |
679
|
|
|
* @return string html |
680
|
|
|
* |
681
|
|
|
* @deprecated |
682
|
|
|
* @access public |
683
|
|
|
* @author luciorota |
684
|
|
|
*/ |
685
|
|
|
function lettersChoice() |
686
|
|
|
{ |
687
|
|
|
$helper = Helper::getInstance(); |
688
|
|
|
$helper->loadLanguage('main'); |
689
|
|
|
xoops_load('XoopsLocal'); |
690
|
|
|
|
691
|
|
|
$criteria = $helper->getHandler('Tree')->getActiveCriteria(); |
692
|
|
|
$criteria->setGroupby('UPPER(LEFT(pname,1))'); |
693
|
|
|
$countsByLetters = $helper->getHandler('Tree')->getCounts($criteria); |
694
|
|
|
// Fill alphabet array |
695
|
|
|
// $alphabet = XoopsLocal::getAlphabet(); |
696
|
|
|
// $xLocale = new \XoopsLocal; |
697
|
|
|
// $alphabet = $xLocale->getAlphabet(); |
698
|
|
|
$alphabet = explode(',', _MA_PEDIGREE_LTRCHARS); |
699
|
|
|
//$alphabet = pedigreeGetAlphabet(); |
700
|
|
|
$alphabet_array = []; |
701
|
|
|
foreach ($alphabet as $letter) { |
702
|
|
|
$letter_array = []; |
703
|
|
|
if (isset($countsByLetters[$letter])) { |
704
|
|
|
$letter_array['letter'] = $letter; |
705
|
|
|
$letter_array['count'] = $countsByLetters[$letter]; |
706
|
|
|
// $letter_array['url'] = "" . XOOPS_URL . "/modules/" . $helper->getModule()->dirname() . "/viewcat.php?list={$letter}"; |
707
|
|
|
$letter_array['url'] = '' . XOOPS_URL . '/modules/' . $helper->getModule()->dirname() . "/result.php?f=pname&l=1&w={$letter}%25&o=pname"; |
708
|
|
|
} else { |
709
|
|
|
$letter_array['letter'] = $letter; |
710
|
|
|
$letter_array['count'] = 0; |
711
|
|
|
$letter_array['url'] = ''; |
712
|
|
|
} |
713
|
|
|
$alphabet_array[$letter] = $letter_array; |
714
|
|
|
unset($letter_array); |
715
|
|
|
} |
716
|
|
|
// Render output |
717
|
|
|
if (!isset($GLOBALS['xoTheme']) || !is_object($GLOBALS['xoTheme'])) { |
718
|
|
|
require_once $GLOBALS['xoops']->path('class/theme.php'); |
719
|
|
|
$GLOBALS['xoTheme'] = new \xos_opal_Theme(); |
720
|
|
|
} |
721
|
|
|
require_once $GLOBALS['xoops']->path('class/template.php'); |
722
|
|
|
$letterschoiceTpl = new \XoopsTpl(); |
723
|
|
|
$letterschoiceTpl->caching = false; // Disable cache |
|
|
|
|
724
|
|
|
$letterschoiceTpl->assign('alphabet', $alphabet_array); |
725
|
|
|
$html = $letterschoiceTpl->fetch('db:' . $helper->getDirname() . '_common_letterschoice.tpl'); |
726
|
|
|
unset($letterschoiceTpl); |
727
|
|
|
|
728
|
|
|
return $html; |
729
|
|
|
} |
730
|
|
|
|
731
|
|
|
/** |
732
|
|
|
* Detemines if a table exists in the current db |
733
|
|
|
* |
734
|
|
|
* @param string $table the table name (without XOOPS prefix) |
735
|
|
|
* |
736
|
|
|
* @return bool True if table exists, false if not |
737
|
|
|
* |
738
|
|
|
* @access public |
739
|
|
|
* @author xhelp development team |
740
|
|
|
*/ |
741
|
|
|
function hasTable($table) |
742
|
|
|
{ |
743
|
|
|
$bRetVal = false; |
744
|
|
|
//Verifies that a MySQL table exists |
745
|
|
|
$GLOBALS['xoopsDB'] = \XoopsDatabaseFactory::getDatabaseConnection(); |
746
|
|
|
$realName = $GLOBALS['xoopsDB']->prefix($table); |
747
|
|
|
|
748
|
|
|
$sql = 'SHOW TABLES FROM ' . XOOPS_DB_NAME; |
749
|
|
|
$ret = $GLOBALS['xoopsDB']->queryF($sql); |
750
|
|
|
|
751
|
|
|
while (false !== (list($m_table) = $GLOBALS['xoopsDB']->fetchRow($ret))) { |
752
|
|
|
if ($m_table == $realName) { |
753
|
|
|
$bRetVal = true; |
754
|
|
|
break; |
755
|
|
|
} |
756
|
|
|
} |
757
|
|
|
$GLOBALS['xoopsDB']->freeRecordSet($ret); |
758
|
|
|
|
759
|
|
|
return $bRetVal; |
760
|
|
|
} |
761
|
|
|
|
762
|
|
|
/** |
763
|
|
|
* Gets a value from a key in the xhelp_meta table |
764
|
|
|
* |
765
|
|
|
* @param string $key |
766
|
|
|
* |
767
|
|
|
* @return string $value |
768
|
|
|
* |
769
|
|
|
* @access public |
770
|
|
|
* @author xhelp development team |
771
|
|
|
*/ |
772
|
|
|
function getMeta($key) |
773
|
|
|
{ |
774
|
|
|
$GLOBALS['xoopsDB'] = \XoopsDatabaseFactory::getDatabaseConnection(); |
775
|
|
|
$sql = sprintf('SELECT metavalue FROM `%s` WHERE metakey= `%s` ', $GLOBALS['xoopsDB']->prefix('pedigree_meta'), $GLOBALS['xoopsDB']->quoteString($key)); |
776
|
|
|
$ret = $GLOBALS['xoopsDB']->query($sql); |
777
|
|
|
if (!$ret) { |
778
|
|
|
$value = false; |
779
|
|
|
} else { |
780
|
|
|
[$value] = $GLOBALS['xoopsDB']->fetchRow($ret); |
781
|
|
|
} |
782
|
|
|
|
783
|
|
|
return $value; |
784
|
|
|
} |
785
|
|
|
|
786
|
|
|
/** |
787
|
|
|
* Sets a value for a key in the xhelp_meta table |
788
|
|
|
* |
789
|
|
|
* @param string $key |
790
|
|
|
* @param string $value |
791
|
|
|
* |
792
|
|
|
* @return bool true if success, false if failure |
793
|
|
|
* |
794
|
|
|
* @access public |
795
|
|
|
* @author xhelp development team |
796
|
|
|
*/ |
797
|
|
|
function setMeta($key, $value) |
798
|
|
|
{ |
799
|
|
|
$GLOBALS['xoopsDB'] = \XoopsDatabaseFactory::getDatabaseConnection(); |
800
|
|
|
if (false !== ($ret = Pedigree\Utility::getMeta($key))) { |
|
|
|
|
801
|
|
|
$sql = sprintf('UPDATE `%s` SET metavalue = `%s` WHERE metakey = `%s` ', $GLOBALS['xoopsDB']->prefix('pedigree_meta'), $GLOBALS['xoopsDB']->quoteString($value), $GLOBALS['xoopsDB']->quoteString($key)); |
802
|
|
|
} else { |
803
|
|
|
$sql = sprintf('INSERT INTO `%s` (metakey, metavalue) VALUES (`%s`, `%s`)', $GLOBALS['xoopsDB']->prefix('pedigree_meta'), $GLOBALS['xoopsDB']->quoteString($key), $GLOBALS['xoopsDB']->quoteString($value)); |
804
|
|
|
} |
805
|
|
|
$ret = $GLOBALS['xoopsDB']->queryF($sql); |
806
|
|
|
if (!$ret) { |
807
|
|
|
return false; |
808
|
|
|
} |
809
|
|
|
|
810
|
|
|
return true; |
811
|
|
|
} |
812
|
|
|
|
813
|
|
|
/** |
814
|
|
|
* @param $name |
815
|
|
|
* @param $value |
816
|
|
|
* @param int $time |
817
|
|
|
*/ |
818
|
|
|
function setCookieVar($name, $value, $time = 0) |
819
|
|
|
{ |
820
|
|
|
if (0 == $time) { |
821
|
|
|
$time = time() + 3600 * 24 * 365; |
822
|
|
|
} |
823
|
|
|
setcookie($name, $value, $time, '/', ini_get('session.cookie_domain'), ini_get('session.cookie_secure'), ini_get('session.cookie_httponly')); |
|
|
|
|
824
|
|
|
} |
825
|
|
|
|
826
|
|
|
/** |
827
|
|
|
* @param $name |
828
|
|
|
* @param string $default |
829
|
|
|
* |
830
|
|
|
* @return string |
831
|
|
|
*/ |
832
|
|
|
function getCookieVar($name, $default = '') |
833
|
|
|
{ |
834
|
|
|
if (isset($_COOKIE[$name]) && ($_COOKIE[$name] > '')) { |
835
|
|
|
return $_COOKIE[$name]; |
836
|
|
|
} |
837
|
|
|
|
838
|
|
|
return $default; |
839
|
|
|
} |
840
|
|
|
|
841
|
|
|
/** |
842
|
|
|
* @return array |
843
|
|
|
*/ |
844
|
|
|
function getCurrentUrls() |
845
|
|
|
{ |
846
|
|
|
$http = (false === mb_strpos(XOOPS_URL, 'https://')) ? 'http://' : 'https://'; |
847
|
|
|
$phpSelf = $_SERVER['SCRIPT_NAME']; |
848
|
|
|
$httpHost = $_SERVER['HTTP_HOST']; |
849
|
|
|
$sql = $_SERVER['QUERY_STRING']; |
850
|
|
|
|
851
|
|
|
if ('' != $sql) { |
852
|
|
|
$sql = '?' . $sql; |
853
|
|
|
} |
854
|
|
|
|
855
|
|
|
$currentURL = $http . $httpHost . $phpSelf . $sql; |
856
|
|
|
|
857
|
|
|
$urls = []; |
858
|
|
|
$urls['http'] = $http; |
859
|
|
|
$urls['httphost'] = $httpHost; |
860
|
|
|
$urls['phpself'] = $phpSelf; |
861
|
|
|
$urls['querystring'] = $sql; |
862
|
|
|
$urls['full'] = $currentURL; |
863
|
|
|
|
864
|
|
|
return $urls; |
865
|
|
|
} |
866
|
|
|
|
867
|
|
|
/** |
868
|
|
|
* @return mixed |
869
|
|
|
*/ |
870
|
|
|
function getCurrentPage() |
871
|
|
|
{ |
872
|
|
|
$urls = Pedigree\Utility::getCurrentUrls(); |
873
|
|
|
|
874
|
|
|
return $urls['full']; |
875
|
|
|
} |
876
|
|
|
|
877
|
|
|
/** |
878
|
|
|
* @param array $errors |
879
|
|
|
* |
880
|
|
|
* @return string |
881
|
|
|
*/ |
882
|
|
|
function formatErrors($errors = []) |
883
|
|
|
{ |
884
|
|
|
$ret = ''; |
885
|
|
|
foreach ($errors as $key => $value) { |
886
|
|
|
$ret .= "<br> - {$value}"; |
887
|
|
|
} |
888
|
|
|
|
889
|
|
|
return $ret; |
890
|
|
|
} |
891
|
|
|
|