Passed
Push — codex/explain-codebase-structu... ( a4c6f1...5ea8d4 )
by Michael
08:21
created

topstud.php (1 issue)

Labels
Severity
1
<?php
2
/*
3
 You may not change or alter any portion of this comment or credits of
4
 supporting developers from this source code or any supporting source code
5
 which is considered copyrighted (c) material of the original comment or credit
6
 authors.
7
8
 This program is distributed in the hope that it will be useful, but
9
 WITHOUT ANY WARRANTY; without even the implied warranty of
10
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11
 */
12
13
/**
14
 * Module: Pedigree
15
 *
16
 * @package   XoopsModules\Pedigree
17
 * @author    XOOPS Module Development Team
18
 * @copyright Copyright (c) 2001-2019 {@link https://xoops.org XOOPS Project}
19
 * @license   https://www.gnu.org/licenses/gpl-2.0.html GNU Public License
20
 */
21
22
use Xmf\Request;
23
use XoopsModules\Pedigree\{
24
    Constants,
25
    Helper,
26
    Utility
27
};
28
29
/** @var Helper $helper */
30
31
require_once __DIR__ . '/header.php';
32
33
34
$helper->loadLanguage('main');
35
36
// Include any common code for this module.
37
require_once $helper->path('include/common.php');
38
39
/*
40
// Get all HTTP post or get parameters into global variables that are prefixed with "param_"
41
//import_request_variables("gp", "param_");
42
extract($_GET, EXTR_PREFIX_ALL, "param");
43
extract($_POST, EXTR_PREFIX_ALL, "param");
44
*/
45
$GLOBALS['xoopsOption']['template_main'] = 'pedigree_result.tpl';
46
require $GLOBALS['xoops']->path('/header.php');
47
48
//get module configuration
49
/** @var XoopsModuleHandler $moduleHandler */
50
$moduleHandler = xoops_getHandler('module');
51
$module        = $moduleHandler->getByDirname($moduleDirName);
52
$configHandler = xoops_getHandler('config');
53
$moduleConfig  = $configHandler->getConfigsByCat(0, $module->getVar('mid'));
0 ignored issues
show
The method getConfigsByCat() does not exist on XoopsObjectHandler. It seems like you code against a sub-type of XoopsObjectHandler such as XoopsPersistableObjectHandler. ( Ignorable by Annotation )

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

53
$moduleConfig  = $configHandler->/** @scrutinizer ignore-call */ getConfigsByCat(0, $module->getVar('mid'));
Loading history...
54
55
$perPage = $helper->getConfig('perpage', Constants::DEFAULT_PER_PAGE);
56
$perPage = (int)$perPage > 0 ? (int)$perPage : Constants::DEFAULT_PER_PAGE; // default if invalid number in module param
57
58
$st  = Request::getInt('st', 0, 'GET');
59
$com = Request::getString('com', 'father', 'GET');
60
/*
61
$st = isset($_GET['st']) ? $_GET['st'] : null;
62
if (!$st) {
63
    $st = 0;
64
}
65
$com = $_GET['com'];
66
if (!$com) {
67
    $com = "father";
68
}
69
*/
70
71
$dogs         = []; // an empty array
72
$numofcolumns = 0;
73
$pages        = '';
74
75
//count total number of dogs
76
$numDog = "SELECT COUNT( {$com} ) AS X, {$com} FROM " . $GLOBALS['xoopsDB']->prefix('pedigree_registry') . " WHERE {$com} !=0 GROUP BY {$com}";
77
$numRes = $GLOBALS['xoopsDB']->query($numDog);
78
//total number of dogs the query will find
79
$numResults = $GLOBALS['xoopsDB']->getRowsNum($numRes);
80
//total number of pages
81
$numPages = floor($numResults / $perPage) + 1;
82
if (($numPages * $perPage) == ($numResults + $perPage)) {
83
    --$numpage;
84
}
85
//find current page
86
$currentPage = floor($st / $perPage) + 1;
87
//create previous button
88
if ($numPages > 1) {
89
    if ($currentPage > 1) {
90
        $pages .= '<a href="topstud.php?com=' . $com . '&st=' . ($st - $perPage) . '">' . _MA_PEDIGREE_PREVIOUS . '</a>&nbsp;&nbsp;';
91
    }
92
}
93
//create numbers
94
for ($x = 1; $x < ($numPages + 1); ++$x) {
95
    //create line break after 20 number
96
    if (0 == ($x % 20)) {
97
        $pages .= '<br>';
98
    }
99
    if ($x != $currentPage) {
100
        $pages .= '<a href="topstud.php?com=' . $com . '&st=' . ($perPage * ($x - 1)) . '">' . $x . '</a>&nbsp;&nbsp;';
101
    } else {
102
        $pages .= $x . '&nbsp;&nbsp';
103
    }
104
}
105
//create next button
106
if ($numPages > 1) {
107
    if ($currentPage < $numPages) {
108
        $pages .= '<a href="topstud.php?com=' . $com . '&st=' . ($st + $perPage) . '">' . _MA_PEDIGREE_NEXT . '</a>&nbsp;&nbsp;';
109
    }
110
}
111
//query
112
$sql    = 'SELECT count( d.'
113
               . $com
114
               . ' ) AS X, d.'
115
               . $com
116
          . ', p.pname as p_pname, p.father as p_father, p.mother as p_mother, p.coi as p_coi, p.foto as p_foto FROM '
117
               . $GLOBALS['xoopsDB']->prefix('pedigree_registry')
118
               . ' d LEFT JOIN '
119
               . $GLOBALS['xoopsDB']->prefix('pedigree_registry')
120
               . ' p ON d.'
121
               . $com
122
               . ' = p.id WHERE d.'
123
               . $com
124
               . ' !=0 GROUP BY d.'
125
               . $com
126
               . ' ORDER BY X DESC LIMIT '
127
               . $st
128
               . ', '
129
               . $perPage;
130
$result = $GLOBALS['xoopsDB']->query($sql);
131
132
while (false !== ($row = $GLOBALS['xoopsDB']->fetchArray($result))) {
133
    $numofcolumns = 2;
134
    $gender       = ('father' === $com) ? "<img src=\"" . PEDIGREE_IMAGE_URL . "/male.gif\">" : "<img src=\"" . PEDIGREE_IMAGE_URL . "/female.gif\">";
135
136
    //read coi% information if exists or create link if not
137
    if ('' == $row['p_coi'] || '0' == $row['p_coi']) {
138
        $coi = '<a href="coi.php?s=' . $row['p_father'] . '&d=' . $row['p_mother'] . '&dogid=' . $row[$com] . '&detail=1">' . _MA_PEDIGREE_UNKNOWN . '</a>';
139
    } else {
140
        $coi = $row['p_coi'] . ' %';
141
    }
142
    //number of pups
143
    $dob = $row['X'];
144
    //create array for dogs
145
    if ('' != $row['p_foto']) {
146
        //@todo figure out what this file is and where it should be placed
147
        $camera = ' <img src="' . PEDIGREE_IMAGE_URL . '/images/camera.png">';
148
    } else {
149
        $camera = '';
150
    }
151
    $name = stripslashes($row['p_pname']) . $camera;
152
    for ($i = 1; $i < $numofcolumns; ++$i) {
153
        $columnvalue[] = ['value' => $coi];
154
        $columnvalue[] = ['value' => $row['X']];
155
    }
156
    $dogs[] = [
157
        'id'          => $row[$com],
158
        'name'        => $name,
159
        'gender'      => $gender,
160
        'link'        => '<a href="pedigree.php?pedid=' . $row[$com] . '">' . $name . '</a>',
161
        'colour'      => '',
162
        'number'      => '',
163
        'usercolumns' => $columnvalue,
164
    ];
165
    unset($columnvalue);
166
}
167
$columns[] = ['columnname' => 'Name', 'columnnumber' => 1];
168
$columns[] = ['columnname' => 'COI%', 'columnnumber' => 2];
169
$columns[] = ['columnname' => 'Offspring', 'columnnumber' => 3];
170
171
//add data to smarty template
172
//assign dog
173
$GLOBALS['xoopsTpl']->assign('dogs', $dogs);
174
$GLOBALS['xoopsTpl']->assign('columns', $columns);
175
$GLOBALS['xoopsTpl']->assign('numofcolumns', $numofcolumns);
176
$GLOBALS['xoopsTpl']->assign('tsarray', Utility::sortTable($numofcolumns));
177
//find last shown number
178
if (($st + $perPage) > $numResults) {
179
    $lastshown = $numResults;
180
} else {
181
    $lastshown = $st + $perPage;
182
}
183
//create string
184
$matches     = _MA_PEDIGREE_MATCHES;
185
$nummatchstr = $numResults . $matches . ($st + 1) . '-' . $lastshown . ' (' . $numPages . ' pages)';
186
$GLOBALS['xoopsTpl']->assign('nummatch', strtr($nummatchstr, ['[animalTypes]' => $helper->getConfig('animalTypes')]));
187
$GLOBALS['xoopsTpl']->assign('pages', $pages);
188
189
//comments and footer
190
require $GLOBALS['xoops']->path('/footer.php');
191