Passed
Branch master (465698)
by Michael
05:38
created

PedigreeUtilities::formatErrors()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 1
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Created by PhpStorm.
5
 * User: Mamba
6
 * Date: 2014-11-19
7
 * Time: 3:05
8
 */
9
10
$moduleDirName = basename(dirname(__DIR__));
11
//require_once $GLOBALS['xoops']->path("modules/{$moduleDirName}/class/field.php");
12
require_once $GLOBALS['xoops']->path("modules/{$moduleDirName}/include/config.php");
13
if (!class_exists('PedigreeAnimal')) {
14
    require_once $GLOBALS['xoops']->path("modules/{$moduleDirName}/class/animal.php");
15
}
16
if (!class_exists('PedigreeField')) {
17
    $GLOBALS['xoops']->path("modules/{$moduleDirName}/class/field.php");
18
}
19
/*
20
//get module configuration
21
$moduleHandler = xoops_getHandler('module');
22
$module        = $moduleHandler->getByDirname($moduleDirName);
23
$configHandler = xoops_getHandler('config');
24
$moduleConfig  = $configHandler->getConfigsByCat(0, $module->getVar('mid'));
25
*/
26
/**
27
 * Class PedigreeUtilities
28
 */
29
class PedigreeUtilities
30
{
31
32
    /**
33
     * Function responsible for checking if a directory exists, we can also write in and create an index.html file
34
     *
35
     * @param string $folder The full path of the directory to check
36
     *
37
     * @return void
38
     */
39
    public static function prepareFolder($folder)
40
    {
41
        //        $filteredFolder = XoopsFilterInput::clean($folder, 'PATH');
42
        if (!is_dir($folder)) {
43
            mkdir($folder);
44
            file_put_contents($folder . '/index.html', '<script>history.go(-1);</script>');
45
        }
46
        //        chmod($filteredFolder, 0777);
47
    }
48
49
    /**
50
     * @param $columncount
51
     *
52
     * @return string
53
     */
54
    public static function sortTable($columncount)
55
    {
56
        $ttemp = '';
57
        if ($columncount > 1) {
58
            for ($t = 1; $t < $columncount; ++$t) {
59
                $ttemp .= "'S',";
60
            }
61
            $tsarray = "initSortTable('Result', Array({$ttemp}'S'));";
62
        } else {
63
            $tsarray = "initSortTable('Result',Array('S'));";
64
        }
65
66
        return $tsarray;
67
    }
68
69
    /**
70
     * @param $num
71
     *
72
     * @return string
73
     */
74
    public static function uploadPicture($num)
75
    {
76
        $max_imgsize       = $GLOBALS['xoopsModuleConfig']['maxfilesize']; //1024000;
77
        $max_imgwidth      = $GLOBALS['xoopsModuleConfig']['maximgwidth']; //1500;
78
        $max_imgheight     = $GLOBALS['xoopsModuleConfig']['maximgheight']; //1000;
79
        $allowed_mimetypes = array('image/gif', 'image/jpeg', 'image/pjpeg', 'image/x-png', 'image/png');
80
        //    $img_dir = XOOPS_ROOT_PATH . "/modules/" . $GLOBALS['xoopsModule']->dirname() . "/images" ;
81
        $img_dir = $GLOBALS['xoopsModuleConfig']['uploaddir'] . '/images';
82
        include_once $GLOBALS['xoops']->path('class/uploader.php');
83
        $field = $_POST['xoops_upload_file'][$num];
84
        if (!empty($field) || $field != '') {
85
            $uploader = new XoopsMediaUploader($img_dir, $allowed_mimetypes, $max_imgsize, $max_imgwidth, $max_imgheight);
86
            $uploader->setPrefix('img');
87
            if ($uploader->fetchMedia($field) && $uploader->upload()) {
88
                $photo = $uploader->getSavedFileName();
89
            } else {
90
                echo $uploader->getErrors();
91
            }
92
            createThumbs($photo);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $photo does not seem to be defined for all execution paths leading up to this point.
Loading history...
Bug introduced by
The function createThumbs was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

92
            /** @scrutinizer ignore-call */ 
93
            createThumbs($photo);
Loading history...
93
94
            return $photo;
95
        }
96
    }
97
98
    /**
99
     * @param $filename
100
     *
101
     * @return bool
102
     */
103
    public static function createThumbs($filename)
104
    {/*
105
    require_once('phpthumb/phpthumb.class.php');
106
    $thumbnail_widths = array(150, 400);
107
    foreach ($thumbnail_widths as $thumbnail_width) {
108
        $phpThumb = new phpThumb();
109
        // set data
110
        $phpThumb->setSourceFilename('images/' . $filename);
111
        $phpThumb->w                    = $thumbnail_width;
112
        $phpThumb->config_output_format = 'jpeg';
113
        // generate & output thumbnail
114
        $output_filename = 'images/thumbnails/' . basename($filename) . '_' . $thumbnail_width . '.' . $phpThumb->config_output_format;
115
        if ($phpThumb->GenerateThumbnail()) { // this line is VERY important, do not remove it!
116
            if ($output_filename) {
117
                if ($phpThumb->RenderToFile($output_filename)) {
118
                    // do something on success
119
                    //echo 'Successfully rendered:<br><img src="'.$output_filename.'">';
120
                } else {
121
                    echo 'Failed (size=' . $thumbnail_width . '):<pre>' . implode("\n\n", $phpThumb->debugmessages) . '</pre>';
122
                }
123
            }
124
        } else {
125
            echo 'Failed (size=' . $thumbnail_width . '):<pre>' . implode("\n\n", $phpThumb->debugmessages) . '</pre>';
126
        }
127
        unset($phpThumb);
128
    }
129
130
    return true;
131
132
    */
133
134
        // load the image
135
        require_once $GLOBALS['xoops']->path('modules/' . $GLOBALS['xoopsModule']->dirname() . '/library/Zebra_Image.php');
136
        $thumbnail_widths = array(150, 400);
137
138
        // indicate a target image
139
        // note that there's no extra property to set in order to specify the target
140
        // image's type -simply by writing '.jpg' as extension will instruct the script
141
        // to create a 'jpg' file
142
        $config_output_format = 'jpeg';
143
144
        // create a new instance of the class
145
        $image = new Zebra_Image();
0 ignored issues
show
Bug introduced by
The type Zebra_Image was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
146
        // indicate a source image (a GIF, PNG or JPEG file)
147
        $image->source_path = PEDIGREE_UPLOAD_PATH . "/images/{$filename}";
148
149
        foreach ($thumbnail_widths as $thumbnail_width) {
150
151
            // generate & output thumbnail
152
            $output_filename    = PEDIGREE_UPLOAD_PATH . '/images/thumbnails/' . basename($filename) . "_{$thumbnail_width}.{$config_output_format}";
153
            $image->target_path = $output_filename;
154
            // since in this example we're going to have a jpeg file, let's set the output
155
            // image's quality
156
            $image->jpeg_quality = 100;
157
            // some additional properties that can be set
158
            // read about them in the documentation
159
            $image->preserve_aspect_ratio  = true;
160
            $image->enlarge_smaller_images = true;
161
            $image->preserve_time          = true;
162
163
            // resize the image to exactly 100x100 pixels by using the "crop from center" method
164
            // (read more in the overview section or in the documentation)
165
            //  and if there is an error, check what the error is about
166
            if (!$image->resize($thumbnail_width, 0)) {
167
                // if there was an error, let's see what the error is about
168
                switch ($image->error) {
169
170
                    case 1:
171
                        echo 'Source file could not be found!';
172
                        break;
173
                    case 2:
174
                        echo 'Source file is not readable!';
175
                        break;
176
                    case 3:
177
                        echo 'Could not write target file!';
178
                        break;
179
                    case 4:
180
                        echo 'Unsupported source file format!';
181
                        break;
182
                    case 5:
183
                        echo 'Unsupported target file format!';
184
                        break;
185
                    case 6:
186
                        echo 'GD library version does not support target file format!';
187
                        break;
188
                    case 7:
189
                        echo 'GD library is not installed!';
190
                        break;
191
                    case 8:
192
                        echo '"chmod" command is disabled via configuration!';
193
                        break;
194
                }
195
196
                // if no errors
197
            } else {
198
                echo 'Success!';
199
            }
200
201
            /*
202
                    if ($phpThumb->GenerateThumbnail()) { // this line is VERY important, do not remove it!
203
                        if ($output_filename) {
204
                            if ($phpThumb->RenderToFile($output_filename)) {
205
                                // do something on success
206
                                //echo 'Successfully rendered:<br><img src="'.$output_filename.'">';
207
                            } else {
208
                                echo 'Failed (size='.$thumbnail_width.'):<pre>'.implode("\n\n", $phpThumb->debugmessages).'</pre>';
209
                            }
210
                        }
211
                    } else {
212
                        echo 'Failed (size='.$thumbnail_width.'):<pre>'.implode("\n\n", $phpThumb->debugmessages).'</pre>';
213
                    }
214
     */
215
        }
216
217
        unset($image);
218
    }
219
220
    /**
221
     * @param $string
222
     *
223
     * @return string
224
     */
225
    public static function unHtmlEntities($string)
226
    {
227
        $trans_tbl = get_html_translation_table(HTML_ENTITIES);
228
        $trans_tbl = array_flip($trans_tbl);
229
230
        return strtr($string, $trans_tbl);
231
    }
232
233
    /**
234
     * @param $oid
235
     * @param $gender
236
     *
237
     * @return null
238
     */
239
    public static function pups($oid, $gender)
240
    {
241
        global $numofcolumns, $nummatch, $pages, $columns, $dogs;
242
        $content = '';
0 ignored issues
show
Unused Code introduced by
The assignment to $content is dead and can be removed.
Loading history...
243
        if ($gender == 0) {
244
            $sqlquery = 'SELECT d.Id AS d_id, d.NAAM AS d_naam, d.roft AS d_roft, d.* FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' d LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' f ON d.father = f.Id LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' m ON d.mother = m.Id WHERE d.father=' . $oid . ' ORDER BY d.NAAM';
245
        } else {
246
            $sqlquery = 'SELECT d.Id AS d_id, d.NAAM AS d_naam, d.roft AS d_roft, d.* FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' d LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' f ON d.father = f.Id LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' m ON d.mother = m.Id WHERE d.mother=' . $oid . ' ORDER BY d.NAAM';
247
        }
248
        $queryresult = $GLOBALS['xoopsDB']->query($sqlquery);
249
        $nummatch    = $GLOBALS['xoopsDB']->getRowsNum($queryresult);
250
251
        $animal = new PedigreeAnimal();
252
        //test to find out how many user fields there are...
253
        $fields       = $animal->getNumOfFields();
254
        $numofcolumns = 1;
255
        $columns[]    = array('columnname' => 'Name');
256
        for ($i = 0, $iMax = count($fields); $i < $iMax; ++$i) {
257
            $userField   = new PedigreeField($fields[$i], $animal->getConfig());
258
            $fieldType   = $userField->getSetting('fieldtype');
259
            $fieldObject = new $fieldType($userField, $animal);
260
            //create empty string
261
            $lookupvalues = '';
262
            if ($userField->isActive() && $userField->inList()) {
263
                if ($userField->hasLookup()) {
264
                    $lookupvalues = $userField->lookupField($fields[$i]);
265
                    //debug information
266
                    //print_r($lookupvalues);
267
                }
268
                $columns[] = array('columnname' => $fieldObject->fieldname, 'columnnumber' => $userField->getId(), 'lookupval' => $lookupvalues);
269
                ++$numofcolumns;
270
                unset($lookupvalues);
271
            }
272
        }
273
274
        while (false !== ($rowres = $GLOBALS['xoopsDB']->fetchArray($queryresult))) {
275
            if ($rowres['d_roft'] == '0') {
276
                $gender = "<img src=\"assets/images/male.gif\">";
277
            } else {
278
                $gender = "<img src=\"assets/images/female.gif\">";
279
            }
280
            $name = stripslashes($rowres['d_naam']);
281
            //empty array
282
            unset($columnvalue);
283
            //fill array
284
            for ($i = 1; $i < $numofcolumns; ++$i) {
285
                $x = $columns[$i]['columnnumber'];
286
                if (is_array($columns[$i]['lookupval'])) {
287
                    foreach ($columns[$i]['lookupval'] as $key => $keyvalue) {
288
                        if ($keyvalue['id'] == $rowres['user' . $x]) {
289
                            $value = $keyvalue['value'];
290
                        }
291
                    }
292
                    //debug information
293
                    ///echo $columns[$i]['columnname']."is an array !";
294
                } //format value - cant use object because of query count
295
                elseif (0 === strpos($rowres['user' . $x], 'http://')) {
296
                    $value = "<a href=\"" . $rowres['user' . $x] . "\">" . $rowres['user' . $x] . '</a>';
297
                } else {
298
                    $value = $rowres['user' . $x];
299
                }
300
                $columnvalue[] = array('value' => $value);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $value does not seem to be defined for all execution paths leading up to this point.
Loading history...
301
            }
302
            $dogs[] = array(
303
                'id'          => $rowres['d_id'],
304
                'name'        => $name,
305
                'gender'      => $gender,
306
                'link'        => "<a href=\"dog.php?Id=" . $rowres['d_id'] . "\">" . $name . '</a>',
307
                'colour'      => '',
308
                'number'      => '',
309
                'usercolumns' => $columnvalue
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $columnvalue does not seem to be defined for all execution paths leading up to this point.
Loading history...
310
            );
311
        }
312
313
        return null;
314
    }
315
316
    /**
317
     * @param $oid
318
     * @param $pa
319
     * @param $ma
320
     *
321
     * @return null
322
     */
323
    public static function bas($oid, $pa, $ma)
324
    {
325
        global $numofcolumns1, $nummatch1, $pages1, $columns1, $dogs1;
326
        if ($pa == '0' && $ma == '0') {
327
            $sqlquery = 'SELECT * FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' where father = ' . $pa . ' and mother = ' . $ma . ' and Id != ' . $oid . " and father != '0' and mother !='0' order by NAAM";
328
        } else {
329
            $sqlquery = 'SELECT * FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' where father = ' . $pa . ' and mother = ' . $ma . ' and Id != ' . $oid . ' order by NAAM';
330
        }
331
        $queryresult = $GLOBALS['xoopsDB']->query($sqlquery);
332
        $nummatch1   = $GLOBALS['xoopsDB']->getRowsNum($queryresult);
333
334
        $animal = new PedigreeAnimal();
335
        //test to find out how many user fields there are...
336
        $fields        = $animal->getNumOfFields();
337
        $numofcolumns1 = 1;
338
        $columns1[]    = array('columnname' => 'Name');
339
        for ($i = 0, $iMax = count($fields); $i < $iMax; ++$i) {
340
            $userField   = new PedigreeField($fields[$i], $animal->getConfig());
341
            $fieldType   = $userField->getSetting('fieldtype');
342
            $fieldObject = new $fieldType($userField, $animal);
343
            //create empty string
344
            $lookupvalues = '';
345
            if ($userField->isActive() && $userField->inList()) {
346
                if ($userField->hasLookup()) {
347
                    $lookupvalues = $userField->lookupField($fields[$i]);
348
                    //debug information
349
                    //print_r($lookupvalues);
350
                }
351
                $columns1[] = array('columnname' => $fieldObject->fieldname, 'columnnumber' => $userField->getId(), 'lookupval' => $lookupvalues);
352
                ++$numofcolumns1;
353
                unset($lookupvalues);
354
            }
355
        }
356
357
        while (false !== ($rowres = $GLOBALS['xoopsDB']->fetchArray($queryresult))) {
358
            if (0 == $rowres['roft']) {
359
                $gender = "<img src='assets/images/male.gif'>";
360
            } else {
361
                $gender = "<img src='assets/images/female.gif'>";
362
            }
363
            $name = stripslashes($rowres['NAAM']);
364
            //empty array
365
            //        unset($columnvalue1);
366
            $columnvalue1 = array();
367
            //fill array
368
            for ($i = 1; $i < $numofcolumns1; ++$i) {
369
                $x = $columns1[$i]['columnnumber'];
370
                if (is_array($columns1[$i]['lookupval'])) {
371
                    foreach ($columns1[$i]['lookupval'] as $key => $keyvalue) {
372
                        if ($keyvalue['id'] == $rowres['user' . $x]) {
373
                            $value = $keyvalue['value'];
374
                        }
375
                    }
376
                    //debug information
377
                    ///echo $columns[$i]['columnname']."is an array !";
378
                } //format value - cant use object because of query count
379
                elseif (0 === strpos($rowres['user' . $x], 'http://')) {
380
                    $value = "<a href=\"" . $rowres['user' . $x] . "\">" . $rowres['user' . $x] . '</a>';
381
                } else {
382
                    $value = $rowres['user' . $x];
383
                }
384
                $columnvalue1[] = array('value' => $value);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $value does not seem to be defined for all execution paths leading up to this point.
Loading history...
385
            }
386
            $dogs1[] = array(
387
                'id'          => $rowres['Id'],
388
                'name'        => $name,
389
                'gender'      => $gender,
390
                'link'        => "<a href=\"dog.php?Id=" . $rowres['Id'] . "\">" . $name . '</a>',
391
                'colour'      => '',
392
                'number'      => '',
393
                'usercolumns' => $columnvalue1
394
            );
395
        }
396
397
        return null;
398
    }
399
400
    /**
401
     * @param $oid
402
     * @param $breeder
403
     *
404
     * @return string
405
     */
406
    public static function breederof($oid, $breeder)
407
    {
408
        $content = '';
409
410
        if (0 == $breeder) {
411
            $sqlquery = 'SELECT Id, NAAM, roft from ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . " WHERE id_owner = '" . $oid . "' order by NAAM";
412
        } else {
413
            $sqlquery = 'SELECT Id, NAAM, roft from ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . " WHERE id_breeder = '" . $oid . "' order by NAAM";
414
        }
415
        $queryresult = $GLOBALS['xoopsDB']->query($sqlquery);
416
        while (false !== ($rowres = $GLOBALS['xoopsDB']->fetchArray($queryresult))) {
417
            if ($rowres['roft'] == '0') {
418
                $gender = "<img src=\"assets/images/male.gif\">";
419
            } else {
420
                $gender = "<img src=\"assets/images/female.gif\">";
421
            }
422
            $link = "<a href=\"dog.php?Id=" . $rowres['Id'] . "\">" . stripslashes($rowres['NAAM']) . '</a>';
423
            $content .= $gender . ' ' . $link . '<br />';
424
        }
425
426
        return $content;
427
    }
428
429
    /**
430
     * @param $oid
431
     *
432
     * @return string
433
     */
434
    public static function getName($oid)
435
    {
436
        $oid         = (int)$oid;
437
        $sqlquery    = 'SELECT NAAM FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . " WHERE Id = '{$oid}'";
438
        $queryresult = $GLOBALS['xoopsDB']->query($sqlquery);
439
        while (false !== ($rowres = $GLOBALS['xoopsDB']->fetchArray($queryresult))) {
440
            $an = stripslashes($rowres['NAAM']);
441
        }
442
443
        return $an;
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $an does not seem to be defined for all execution paths leading up to this point.
Loading history...
444
    }
445
446
    /**
447
     * @param $PA
448
     */
449
    public static function showParent($PA)
450
    {
451
        $sqlquery    = 'SELECT NAAM FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . " WHERE Id='" . $PA . "'";
452
        $queryresult = $GLOBALS['xoopsDB']->query($sqlquery);
453
        while (false !== ($rowres = $GLOBALS['xoopsDB']->fetchArray($queryresult))) {
454
            $result = $rowres['NAAM'];
455
        }
456
        if (isset($result)) {
457
            return $result;
458
        } else {
459
            return;
460
        }
461
    }
462
463
    /**
464
     * @param $naam_hond
465
     *
466
     * @return mixed
467
     */
468
    public static function findId($naam_hond)
469
    {
470
        $sqlquery    = 'SELECT Id FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . " WHERE NAAM= '$naam_hond'";
471
        $queryresult = $GLOBALS['xoopsDB']->query($sqlquery);
472
        while (false !== ($rowres = $GLOBALS['xoopsDB']->fetchArray($queryresult))) {
473
            $result = $rowres['Id'];
474
        }
475
476
        return $result;
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $result does not seem to be defined for all execution paths leading up to this point.
Loading history...
477
    }
478
479
    /**
480
     * @param $result
481
     * @param $prefix
482
     * @param $link
483
     * @param $element
484
     */
485
    public static function createList($result, $prefix, $link, $element)
486
    {
487
        global $xoopsTpl;
488
        $animal = new PedigreeAnimal();
489
        //test to find out how many user fields there are...
490
        $fields       = $animal->getNumOfFields();
491
        $numofcolumns = 1;
492
        $columns[]    = array('columnname' => 'Name');
0 ignored issues
show
Comprehensibility Best Practice introduced by
$columns was never initialized. Although not strictly required by PHP, it is generally a good practice to add $columns = array(); before regardless.
Loading history...
493
        for ($i = 0, $iMax = count($fields); $i < $iMax; ++$i) {
494
            $userField   = new PedigreeField($fields[$i], $animal->getConfig());
495
            $fieldType   = $userField->getSetting('fieldtype');
496
            $fieldObject = new $fieldType($userField, $animal);
497
            if ($userField->isActive() && $userField->inList()) {
498
                if ($userField->hasLookup()) {
499
                    $id = $userField->getId();
500
                    $q  = $userField->lookupField($id);
501
                } else {
502
                    $q = '';
503
                }
504
                $columns[] = array('columnname' => $fieldObject->fieldname, 'columnnumber' => $userField->getId(), 'lookuparray' => $q);
505
                ++$numofcolumns;
506
            }
507
        }
508
509
        //add preliminary row to array if passed
510
        if (is_array($prefix)) {
511
            $dogs[] = $prefix;
0 ignored issues
show
Comprehensibility Best Practice introduced by
$dogs was never initialized. Although not strictly required by PHP, it is generally a good practice to add $dogs = array(); before regardless.
Loading history...
512
        }
513
514
        while (false !== ($row = $GLOBALS['xoopsDB']->fetchArray($result))) {
515
            //reset $gender
516
            $gender = '';
517
            if ((!empty($GLOBALS['xoopsUser']) && $GLOBALS['xoopsUser'] instanceof XoopsUser) && ($row['user'] == $GLOBALS['xoopsUser']->getVar('uid') || true === $modadmin)) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $modadmin seems to be never defined.
Loading history...
518
                $gender = "<a href='dog.php?Id={$row['Id']}'><img src='images/edit.gif' alt='" . _EDIT . "'></a>
519
                     . <a href='delete.php?Id={$row['Id']}'><img src='images/delete.gif' alt='" . _DELETE . "'></a>";
520
            }
521
522
            $genImg = (0 == $row['roft']) ? 'male.gif' : 'female.gif';
523
            $gender .= "<img src='assets/images/{$genImg}'>";
524
525
            if ('' != $row['foto']) {
526
                $camera = " <img src=\"assets/images/dog-icon25.png\">";
527
            } else {
528
                $camera = '';
529
            }
530
            $name = stripslashes($row['NAAM']) . $camera;
531
            unset($columnvalue);
532
533
            //fill array
534
            for ($i = 1; $i < $numofcolumns; ++$i) {
535
                $x           = $columns[$i]['columnnumber'];
536
                $lookuparray = $columns[$i]['lookuparray'];
537
                if (is_array($lookuparray)) {
538
                    for ($index = 0, $indexMax = count($lookuparray); $index < $indexMax; ++$index) {
539
                        if ($lookuparray[$index]['id'] == $row['user' . $x]) {
540
                            //echo "<h1>".$lookuparray[$index]['id']."</h1>";
541
                            $value = $lookuparray[$index]['value'];
542
                        }
543
                    }
544
                } //format value - cant use object because of query count
545
                elseif (0 === strpos($row['user' . $x], 'http://')) {
546
                    $value = "<a href=\"" . $row['user' . $x] . "\">" . $row['user' . $x] . '</a>';
547
                } else {
548
                    $value = $row['user' . $x];
549
                }
550
                $columnvalue[] = array('value' => $value);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $value does not seem to be defined for all execution paths leading up to this point.
Loading history...
551
                unset($value);
552
            }
553
554
            $linkto = "<a href=\"" . $link . $row[$element] . "\">" . $name . '</a>';
555
            //create array
556
            $dogs[] = array('id' => $row['Id'], 'name' => $name, 'gender' => $gender, 'link' => $linkto, 'colour' => '', 'number' => '', 'usercolumns' => $columnvalue);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $columnvalue does not seem to be defined for all execution paths leading up to this point.
Loading history...
557
        }
558
559
        //add data to smarty template
560
        //assign dog
561
        $xoopsTpl->assign('dogs', $dogs);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $dogs does not seem to be defined for all execution paths leading up to this point.
Loading history...
562
        $xoopsTpl->assign('columns', $columns);
563
        $xoopsTpl->assign('numofcolumns', $numofcolumns);
564
        $xoopsTpl->assign('tsarray', PedigreeUtilities::sortTable($numofcolumns));
565
    }
566
567
    /***************Blocks**************
568
     *
569
     * @param array|string $cats
570
     *
571
     * @return string (cat1, cat2, cat3, etc) for SQL statement
572
     */
573
    public static function animal_block_addCatSelect($cats)
574
    {
575
        $cat_sql = '';
576
        if (is_array($cats)) {
577
            $cats = array_map('intval', $cats); // make sure all cats are numbers
578
            $cat_sql = "(" . implode(',', $cats) . ")";
579
/*
580
            $cat_sql = '(' . current($cats);
581
            array_shift($cats);
582
            foreach ($cats as $cat) {
583
                $cat_sql .= ',' . $cat;
584
            }
585
            $cat_sql .= ')';
586
*/
587
        } else {
588
            $cat_sql = "(" . (int)$cats . ")"; // not efficient but at least creates valid SQL statement
589
        }
590
591
        return $cat_sql;
592
    }
593
594
    /**
595
     * @deprecated
596
     * @param        $global
597
     * @param        $key
598
     * @param string $default
599
     * @param string $type
600
     *
601
     * @return mixed|string
602
     */
603
    public static function animal_CleanVars(&$global, $key, $default = '', $type = 'int')
604
    {
605
        switch ($type) {
606
            case 'string':
607
                $ret = isset($global[$key]) ? filter_var($global[$key], FILTER_SANITIZE_MAGIC_QUOTES) : $default;
608
                break;
609
            case 'int':
610
            default:
611
                $ret = isset($global[$key]) ? filter_var($global[$key], FILTER_SANITIZE_NUMBER_INT) : $default;
612
                break;
613
        }
614
        if ($ret === false) {
615
            return $default;
616
        }
617
618
        return $ret;
619
    }
620
621
    /**
622
     * @param $content
623
     */
624
    public static function animal_meta_keywords($content)
625
    {
626
        global $xoopsTpl, $xoTheme;
627
        $myts    = MyTextSanitizer::getInstance();
628
        $content = $myts->undoHtmlSpecialChars($myts->sanitizeForDisplay($content));
629
        if (isset($xoTheme) && is_object($xoTheme)) {
630
            $xoTheme->addMeta('meta', 'keywords', strip_tags($content));
631
        } else {    // Compatibility for old Xoops versions
632
            $xoopsTpl->assign('xoops_meta_keywords', strip_tags($content));
633
        }
634
    }
635
636
    /**
637
     * @param $content
638
     */
639
    public static function animal_meta_description($content)
640
    {
641
        global $xoopsTpl, $xoTheme;
642
        $myts    = MyTextSanitizer::getInstance();
643
        $content = $myts->undoHtmlSpecialChars($myts->displayTarea($content));
644
        if (isset($xoTheme) && is_object($xoTheme)) {
645
            $xoTheme->addMeta('meta', 'description', strip_tags($content));
646
        } else {    // Compatibility for old Xoops versions
647
            $xoopsTpl->assign('xoops_meta_description', strip_tags($content));
648
        }
649
    }
650
651
    /**
652
     * Verify that a mysql table exists
653
     *
654
     * @package       pedigree
655
     * @author        Hervé Thouzard (http://www.herve-thouzard.com)
656
     * @copyright (c) Hervé Thouzard
657
     */
658
    //function tableExists($tablename)
659
    //{
660
    //
661
    //  $result=$GLOBALS['xoopsDB']->queryF("SHOW TABLES LIKE '$tablename'");
662
    //  return($GLOBALS['xoopsDB']->getRowsNum($result) > 0);
663
    //}
664
665
    /**
666
     * Create download by letter choice bar/menu
667
     * updated starting from this idea http://xoops.org/modules/news/article.php?storyid=6497
668
     *
669
     * @param PedigreePedigree $myObject
670
     * @param $activeObject
671
     * @param $criteria
672
     * @param $name
673
     * @param $file
674
     * @param $file2
675
     * @return string html
676
     *
677
     * @access  public
678
     * @author  luciorota
679
     */
680
    public static function lettersChoice(PedigreePedigree $myObject, $activeObject, $criteria, $name, $file, $file2)
0 ignored issues
show
Unused Code introduced by
The parameter $file is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

680
    public static function lettersChoice(PedigreePedigree $myObject, $activeObject, $criteria, $name, /** @scrutinizer ignore-unused */ $file, $file2)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $criteria is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

680
    public static function lettersChoice(PedigreePedigree $myObject, $activeObject, /** @scrutinizer ignore-unused */ $criteria, $name, $file, $file2)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
681
    {
682
        /*
683
        $pedigree = PedigreePedigree::getInstance();
684
        xoops_load('XoopsLocal');
685
686
        $criteria = $pedigree->getHandler('tree')->getActiveCriteria();
687
        $criteria->setGroupby('UPPER(LEFT(NAAM,1))');
688
        $countsByLetters = $pedigree->getHandler('tree')->getCounts($criteria);
689
        // Fill alphabet array
690
        $alphabet       = XoopsLocal::getAlphabet();
691
        $alphabet_array = array();
692
        foreach ($alphabet as $letter) {
693
            $letter_array = array();
694
            if (isset($countsByLetters[$letter])) {
695
                $letter_array['letter'] = $letter;
696
                $letter_array['count']  = $countsByLetters[$letter];
697
                //            $letter_array['url']    = "" . XOOPS_URL . "/modules/" . $pedigree->getModule()->dirname() . "/viewcat.php?list={$letter}";
698
                $letter_array['url'] = '' . XOOPS_URL . '/modules/' . $pedigree->getModule()->dirname() . "/result.php?f=NAAM&amp;l=1&amp;w={$letter}%25&amp;o=NAAM";
699
            } else {
700
                $letter_array['letter'] = $letter;
701
                $letter_array['count']  = 0;
702
                $letter_array['url']    = '';
703
            }
704
            $alphabet_array[$letter] = $letter_array;
705
            unset($letter_array);
706
        }
707
        // Render output
708
        if (!isset($GLOBALS['xoTheme']) || !is_object($GLOBALS['xoTheme'])) {
709
            include_once $GLOBALS['xoops']->path('class/theme.php');
710
            $GLOBALS['xoTheme'] = new xos_opal_Theme();
711
        }
712
        require_once $GLOBALS['xoops']->path('class/template.php');
713
        $letterschoiceTpl          = new XoopsTpl();
714
        $letterschoiceTpl->caching = false; // Disable cache
715
        $letterschoiceTpl->assign('alphabet', $alphabet_array);
716
        $html = $letterschoiceTpl->fetch('db:' . $pedigree->getModule()->dirname() . '_common_letterschoice.tpl');
717
        unset($letterschoiceTpl);
718
        return $html;
719
*/
720
721
        //        $pedigree = PedigreePedigree::getInstance();
722
        xoops_load('XoopsLocal');
723
724
        $criteria = $myObject->getHandler($activeObject)->getActiveCriteria();
725
        $criteria->setGroupby('UPPER(LEFT(' . $name . ',1))');
726
        $countsByLetters = $myObject->getHandler($activeObject)->getCounts($criteria);
727
        // Fill alphabet array
728
        //@todo getAlphabet method doesn't exist anywhere
729
        //$alphabet       = XoopsLocal::getAlphabet();
730
731
        $alphabet_array = array();
732
//        foreach ($alphabet as $letter) {
733
        foreach (range ('A', 'Z') as $letter) {
734
            $letter_array = array();
735
            if (isset($countsByLetters[$letter])) {
736
                $letter_array['letter'] = $letter;
737
                $letter_array['count']  = $countsByLetters[$letter];
738
                //            $letter_array['url']    = "" . XOOPS_URL . "/modules/" . $pedigree->getModule()->dirname() . "/viewcat.php?list={$letter}";
739
                //                $letter_array['url'] = '' . XOOPS_URL . '/modules/' . $myObject->getModule()->dirname() . '/'.$file.'?f='.$name."&amp;l=1&amp;w={$letter}%25&amp;o=".$name;
740
                $letter_array['url'] = '' . XOOPS_URL . '/modules/' . $myObject->getModule()->dirname() . '/' . $file2;
741
            } else {
742
                $letter_array['letter'] = $letter;
743
                $letter_array['count']  = 0;
744
                $letter_array['url']    = '';
745
            }
746
            $alphabet_array[$letter] = $letter_array;
747
            unset($letter_array);
748
        }
749
        // Render output
750
        if (!isset($GLOBALS['xoTheme']) || !is_object($GLOBALS['xoTheme'])) {
751
            include_once $GLOBALS['xoops']->path('class/theme.php');
752
            $GLOBALS['xoTheme'] = new xos_opal_Theme();
753
        }
754
        require_once $GLOBALS['xoops']->path('class/template.php');
755
        $letterschoiceTpl          = new XoopsTpl();
756
        $letterschoiceTpl->caching = false; // Disable cache
0 ignored issues
show
Documentation Bug introduced by
The property $caching was declared of type integer, but false is of type false. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
757
        $letterschoiceTpl->assign('alphabet', $alphabet_array);
758
        $html = $letterschoiceTpl->fetch('db:' . $myObject->getModule()->dirname() . '_common_letterschoice.tpl');
759
        unset($letterschoiceTpl);
760
        return $html;
761
    }
762
763
    /**
764
     * @return bool
765
     */
766
    public static function userIsAdmin()
767
    {
768
        $pedigree = PedigreePedigree::getInstance();
769
770
        static $pedigree_isAdmin;
771
772
        if (isset($pedigree_isAdmin)) {
773
            return $pedigree_isAdmin;
774
        }
775
776
        if (!$GLOBALS['xoopsUser']) {
777
            $pedigree_isAdmin = false;
778
        } else {
779
            $pedigree_isAdmin = $GLOBALS['xoopsUser']->isAdmin($pedigree->getModule()->getVar('mid'));
780
        }
781
782
        return $pedigree_isAdmin;
783
    }
784
785
    public static function getXoopsCpHeader()
786
    {
787
        xoops_cp_header();
788
    }
789
790
    /**
791
     * @deprecated
792
     * @param bool $withLink
793
     *
794
     * @return string
795
     */
796
    public static function getModuleName($withLink = true)
797
    {
798
        $pedigree = PedigreePedigree::getInstance();
799
800
        $pedigreeModuleName = $pedigree->getModule()->getVar('name');
801
        if (!$withLink) {
802
            return $pedigreeModuleName;
803
        } else {
804
            return '<a href="' . PEDIGREE_URL . '/">{$pedigreeModuleName}</a>';
805
        }
806
    }
807
808
    /**
809
     * Detemines if a table exists in the current db
810
     *
811
     * @param string $table the table name (without XOOPS prefix)
812
     *
813
     * @return bool True if table exists, false if not
814
     *
815
     * @access public
816
     * @author xhelp development team
817
     */
818
    public static function hasTable($table)
819
    {
820
        $bRetVal = false;
821
        //Verifies that a MySQL table exists
822
        $GLOBALS['xoopsDB'] = XoopsDatabaseFactory::getDatabaseConnection();
823
        $realName           = $GLOBALS['xoopsDB']->prefix($table);
824
825
        $sql = 'SHOW TABLES FROM ' . XOOPS_DB_NAME;
826
        $ret = $GLOBALS['xoopsDB']->queryF($sql);
827
828
        while (false !== (list($m_table) = $GLOBALS['xoopsDB']->fetchRow($ret))) {
829
            if ($m_table == $realName) {
830
                $bRetVal = true;
831
                break;
832
            }
833
        }
834
        $GLOBALS['xoopsDB']->freeRecordSet($ret);
835
836
        return $bRetVal;
837
    }
838
839
    /**
840
     * Gets a value from a key in the xhelp_meta table
841
     *
842
     * @param string $key
843
     *
844
     * @return string $value
845
     *
846
     * @access public
847
     * @author xhelp development team
848
     */
849
    public static function getMeta($key)
850
    {
851
        $GLOBALS['xoopsDB'] = XoopsDatabaseFactory::getDatabaseConnection();
852
        $sql                = sprintf('SELECT metavalue FROM %s WHERE metakey=%s', $GLOBALS['xoopsDB']->prefix('pedigree_meta'), $GLOBALS['xoopsDB']->quoteString($key));
853
        $ret                = $GLOBALS['xoopsDB']->query($sql);
854
        if (!$ret) {
855
            $value = false;
856
        } else {
857
            list($value) = $GLOBALS['xoopsDB']->fetchRow($ret);
858
        }
859
860
        return $value;
861
    }
862
863
    /**
864
     * Sets a value for a key in the xhelp_meta table
865
     *
866
     * @param string $key
867
     * @param string $value
868
     *
869
     * @return bool true if success, false if failure
870
     *
871
     * @access public
872
     * @author xhelp development team
873
     */
874
    public static function setMeta($key, $value)
875
    {
876
        $GLOBALS['xoopsDB'] = XoopsDatabaseFactory::getDatabaseConnection();
877
        if (false !== ($ret = PedigreeUtilities::getMeta($key))) {
0 ignored issues
show
Unused Code introduced by
The assignment to $ret is dead and can be removed.
Loading history...
introduced by
The condition false !== $ret = PedigreeUtilities::getMeta($key) is always true.
Loading history...
878
            $sql = sprintf('UPDATE %s SET metavalue = %s WHERE metakey = %s', $GLOBALS['xoopsDB']->prefix('pedigree_meta'), $GLOBALS['xoopsDB']->quoteString($value), $GLOBALS['xoopsDB']->quoteString($key));
879
        } else {
880
            $sql = sprintf('INSERT INTO %s (metakey, metavalue) VALUES (%s, %s)', $GLOBALS['xoopsDB']->prefix('pedigree_meta'), $GLOBALS['xoopsDB']->quoteString($key), $GLOBALS['xoopsDB']->quoteString($value));
881
        }
882
        $ret = $GLOBALS['xoopsDB']->queryF($sql);
883
        if (!$ret) {
884
            return false;
885
        }
886
887
        return true;
888
    }
889
890
    /**
891
     * @param     $name
892
     * @param     $value
893
     * @param int $time
894
     */
895
    public static function setCookieVar($name, $value, $time = 0)
896
    {
897
        if ($time == 0) {
898
            $time = time() + 3600 * 24 * 365;
899
            //$time = '';
900
        }
901
        setcookie($name, $value, $time, '/');
902
    }
903
904
    /**
905
     * @param        $name
906
     * @param string $default
907
     *
908
     * @return string
909
     */
910
    public static function getCookieVar($name, $default = '')
911
    {
912
        if (isset($_COOKIE[$name]) && ($_COOKIE[$name] > '')) {
913
            return $_COOKIE[$name];
914
        } else {
915
            return $default;
916
        }
917
    }
918
919
    /**
920
     * @return array
921
     */
922
    public static function getCurrentUrls()
923
    {
924
        $http        = (strpos(XOOPS_URL, 'https://') === false) ? 'http://' : 'https://';
925
        $phpSelf     = $_SERVER['PHP_SELF'];
926
        $httpHost    = $_SERVER['HTTP_HOST'];
927
        $queryString = $_SERVER['QUERY_STRING'];
928
929
        if ($queryString != '') {
930
            $queryString = '?' . $queryString;
931
        }
932
933
        $currentURL = $http . $httpHost . $phpSelf . $queryString;
934
935
        $urls                = array();
936
        $urls['http']        = $http;
937
        $urls['httphost']    = $httpHost;
938
        $urls['phpself']     = $phpSelf;
939
        $urls['querystring'] = $queryString;
940
        $urls['full']        = $currentURL;
941
942
        return $urls;
943
    }
944
945
    /**
946
     * @return mixed
947
     */
948
    public static function getCurrentPage()
949
    {
950
        $urls = PedigreeUtilities::getCurrentUrls();
951
952
        return $urls['full'];
953
    }
954
955
    /**
956
     * @param array $errors
957
     *
958
     * @return string
959
     */
960
    public static function formatErrors($errors = array())
961
    {
962
        $ret = '';
963
        foreach ($errors as $key => $value) {
964
            $ret .= "<br /> - {$value}";
965
        }
966
967
        return $ret;
968
    }
969
970
}
971