Passed
Pull Request — master (#3)
by Michael
05:20
created

topstud.php (1 issue)

Labels
Severity
1
<?php
2
// -------------------------------------------------------------------------
3
4
use Xmf\Request;
5
use XoopsModules\Pedigree;
0 ignored issues
show
This use statement conflicts with another class in this namespace, Pedigree. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
6
7
//require_once  dirname(dirname(__DIR__)) . '/mainfile.php';
8
require_once __DIR__ . '/header.php';
9
10
$moduleDirName = basename(__DIR__);
11
xoops_loadLanguage('main', $moduleDirName);
12
13
// Include any common code for this module.
14
require_once XOOPS_ROOT_PATH . '/modules/' . $moduleDirName . '/include/common.php';
15
16
/*
17
// Get all HTTP post or get parameters into global variables that are prefixed with "param_"
18
//import_request_variables("gp", "param_");
19
extract($_GET, EXTR_PREFIX_ALL, "param");
20
extract($_POST, EXTR_PREFIX_ALL, "param");
21
*/
22
$GLOBALS['xoopsOption']['template_main'] = 'pedigree_result.tpl';
23
24
include $GLOBALS['xoops']->path('/header.php');
25
26
//get module configuration
27
/** @var XoopsModuleHandler $moduleHandler */
28
$moduleHandler = xoops_getHandler('module');
29
$module        = $moduleHandler->getByDirname($moduleDirName);
30
$configHandler = xoops_getHandler('config');
31
$moduleConfig  = $configHandler->getConfigsByCat(0, $module->getVar('mid'));
32
33
$perPage = $moduleConfig['perpage'];
34
35
$st  = Request::getInt('st', 0, 'GET');
36
$com = Request::getString('com', 'father', 'GET');
37
/*
38
$st = isset($_GET['st']) ? $_GET['st'] : null;
39
if (!$st) {
40
    $st = 0;
41
}
42
$com = $_GET['com'];
43
if (!$com) {
44
    $com = "father";
45
}
46
*/
47
48
$dogs         = []; // an empty array
49
$numofcolumns = 0;
50
$pages        = '';
51
52
//count total number of dogs
53
$numDog = "SELECT COUNT( {$com} ) AS X, {$com} FROM " . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . " WHERE {$com} !=0 GROUP BY {$com}";
54
$numRes = $GLOBALS['xoopsDB']->query($numDog);
55
//total number of dogs the query will find
56
$numResults = $GLOBALS['xoopsDB']->getRowsNum($numRes);
57
//total number of pages
58
$numPages = floor($numResults / $perPage) + 1;
59
if (($numPages * $perPage) == ($numResults + $perPage)) {
60
    --$numpage;
61
}
62
//find current page
63
$currentPage = floor($st / $perPage) + 1;
64
//create previous button
65
if ($numPages > 1) {
66
    if ($currentPage > 1) {
67
        $pages .= '<a href="topstud.php?com=' . $com . '&st=' . ($st - $perPage) . '">' . _MA_PEDIGREE_PREVIOUS . '</a>&nbsp;&nbsp;';
68
    }
69
}
70
//create numbers
71
for ($x = 1; $x < ($numPages + 1); ++$x) {
72
    //create line break after 20 number
73
    if (0 == ($x % 20)) {
74
        $pages .= '<br>';
75
    }
76
    if ($x != $currentPage) {
77
        $pages .= '<a href="topstud.php?com=' . $com . '&st=' . ($perPage * ($x - 1)) . '">' . $x . '</a>&nbsp;&nbsp;';
78
    } else {
79
        $pages .= $x . '&nbsp;&nbsp';
80
    }
81
}
82
//create next button
83
if ($numPages > 1) {
84
    if ($currentPage < $numPages) {
85
        $pages .= '<a href="topstud.php?com=' . $com . '&st=' . ($st + $perPage) . '">' . _MA_PEDIGREE_NEXT . '</a>&nbsp;&nbsp;';
86
    }
87
}
88
//query
89
$queryString = 'SELECT count( d.'
90
               . $com
91
               . ' ) AS X, d.'
92
               . $com
93
               . ', p.naam as p_NAAM, p.father as p_father, p.mother as p_mother, p.coi as p_coi, p.foto as p_foto FROM '
94
               . $GLOBALS['xoopsDB']->prefix('pedigree_tree')
95
               . ' d LEFT JOIN '
96
               . $GLOBALS['xoopsDB']->prefix('pedigree_tree')
97
               . ' p ON d.'
98
               . $com
99
               . ' = p.id WHERE d.'
100
               . $com
101
               . ' !=0 GROUP BY d.'
102
               . $com
103
               . ' ORDER BY X DESC LIMIT '
104
               . $st
105
               . ', '
106
               . $perPage;
107
$result      = $GLOBALS['xoopsDB']->query($queryString);
108
109
while (false !== ($row = $GLOBALS['xoopsDB']->fetchArray($result))) {
110
    $numofcolumns = 2;
111
    if ('father' === $com) {
112
        $gender = '<img src="assets/images/male.gif">';
113
    } else {
114
        $gender = '<img src="assets/images/female.gif">';
115
    }
116
    //read coi% information if exists or create link if not
117
    if ('' == $row['p_coi'] || '0' == $row['p_coi']) {
118
        $coi = '<a href="coi.php?s=' . $row['p_father'] . '&d=' . $row['p_mother'] . '&dogid=' . $row[$com] . '&detail=1">' . _MA_PEDIGREE_UNKNOWN . '</a>';
119
    } else {
120
        $coi = $row['p_coi'] . ' %';
121
    }
122
    //number of pups
123
    $dob = $row['X'];
124
    //create array for dogs
125
    if ('' != $row['p_foto']) {
126
        $camera = ' <img src="' . PEDIGREE_UPLOAD_URL . '/images/dog-icon25.png">';
127
    } else {
128
        $camera = '';
129
    }
130
    $name = stripslashes($row['p_NAAM']) . $camera;
131
    for ($i = 1; $i < $numofcolumns; ++$i) {
132
        $columnvalue[] = ['value' => $coi];
133
        $columnvalue[] = ['value' => $row['X']];
134
    }
135
    $dogs[] = [
136
        'id'          => $row[$com],
137
        'name'        => $name,
138
        'gender'      => $gender,
139
        'link'        => '<a href="pedigree.php?pedid=' . $row[$com] . '">' . $name . '</a>',
140
        'colour'      => '',
141
        'number'      => '',
142
        'usercolumns' => $columnvalue
143
    ];
144
    unset($columnvalue);
145
}
146
$columns[] = ['columnname' => 'Name', 'columnnumber' => 1];
147
$columns[] = ['columnname' => 'COI%', 'columnnumber' => 2];
148
$columns[] = ['columnname' => 'Offspring', 'columnnumber' => 3];
149
150
//add data to smarty template
151
//assign dog
152
$GLOBALS['xoopsTpl']->assign('dogs', $dogs);
153
$GLOBALS['xoopsTpl']->assign('columns', $columns);
154
$GLOBALS['xoopsTpl']->assign('numofcolumns', $numofcolumns);
155
$GLOBALS['xoopsTpl']->assign('tsarray', Pedigree\Utility::sortTable($numofcolumns));
156
//find last shown number
157
if (($st + $perPage) > $numResults) {
158
    $lastshown = $numResults;
159
} else {
160
    $lastshown = $st + $perPage;
161
}
162
//create string
163
$matches     = _MA_PEDIGREE_MATCHES;
164
$nummatchstr = $numResults . $matches . ($st + 1) . '-' . $lastshown . ' (' . $numPages . ' pages)';
165
$GLOBALS['xoopsTpl']->assign('nummatch', strtr($nummatchstr, ['[animalTypes]' => $moduleConfig['animalTypes']]));
166
$GLOBALS['xoopsTpl']->assign('pages', $pages);
167
168
//comments and footer
169
include $GLOBALS['xoops']->path('/footer.php');
170