Passed
Push — master ( 41940e...005d4f )
by Michael
36s queued 18s
created

latest.php (1 issue)

Labels
Severity
1
<?php
2
// -------------------------------------------------------------------------
3
4
use Xmf\Request;
5
6
//require_once  dirname(dirname(__DIR__)) . '/mainfile.php';
7
require_once __DIR__ . '/header.php';
8
9
$moduleDirName = basename(__DIR__);
10
xoops_loadLanguage('main', $moduleDirName);
11
12
// Include any common code for this module.
13
require_once XOOPS_ROOT_PATH . '/modules/' . $moduleDirName . '/include/common.php';
14
//path taken
15
16
$GLOBALS['xoopsOption']['template_main'] = 'pedigree_latest.tpl';
17
18
include $GLOBALS['xoops']->path('/header.php');
19
20
//get module configuration
21
/** @var XoopsModuleHandler $moduleHandler */
22
$moduleHandler = xoops_getHandler('module');
23
$module = $moduleHandler->getByDirname($moduleDirName);
24
$configHandler = xoops_getHandler('config');
25
$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

25
$moduleConfig = $configHandler->/** @scrutinizer ignore-call */ getConfigsByCat(0, $module->getVar('mid'));
Loading history...
26
27
$st = Request::getInt('st', 0, 'GET');
28
29
$perPage = $moduleConfig['perpage'];
30
global $xoopsTpl, $xoopsModuleConfig;
31
32
//iscurrent user a module admin ?
33
$modadmin = false;
34
$xoopsModule = XoopsModule::getByDirname($moduleDirName);
35
if (!empty($GLOBALS['xoopsUser'])) {
36
    if ($GLOBALS['xoopsUser']->isAdmin($xoopsModule->mid())) {
37
        $modadmin = true;
38
    }
39
}
40
41
//count total number of animals
42
$numanimal = 'SELECT id FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' NOLIMIT';
43
$numRes = $GLOBALS['xoopsDB']->query($numanimal);
44
//total number of animals the query will find
45
$numResults = $GLOBALS['xoopsDB']->getRowsNum($numRes);
46
//total number of pages
47
$numPages = floor($numResults / $perPage) + 1;
48
if (($numPages * $perPage) == ($numResults + $perPage)) {
49
    --$numPages;
50
}
51
//find current page
52
$currentPage = floor($st / $perPage) + 1;
53
54
//create numbers
55
for ($x = 1; $x < ($numPages + 1); ++$x) {
56
    $pages = $x . '&nbsp;&nbsp';
57
}
58
59
//query
60
$queryString = 'SELECT d.id AS d_id, d.naam AS d_naam, d.roft AS d_roft, d.mother AS d_mother, d.father AS d_father, d.foto AS d_foto, d.user AS d_user, f.id AS f_id, f.naam AS f_naam, m.id AS m_id, m.naam AS m_naam, u.uname AS u_uname FROM '
61
               . $GLOBALS['xoopsDB']->prefix('pedigree_tree')
62
               . ' d LEFT JOIN '
63
               . $GLOBALS['xoopsDB']->prefix('pedigree_tree')
64
               . ' f ON d.father = f.id LEFT JOIN '
65
               . $GLOBALS['xoopsDB']->prefix('pedigree_tree')
66
               . ' m ON d.mother = m.id LEFT JOIN '
67
               . $GLOBALS['xoopsDB']->prefix('users')
68
               . ' u ON d.user = u.uid ORDER BY d.id DESC LIMIT '
69
               . $st
70
               . ', '
71
               . $perPage;
72
$result = $GLOBALS['xoopsDB']->query($queryString);
73
$pathIcon16 = \Xmf\Module\Admin::iconUrl('', 16);
74
75
while (false !== ($row = $GLOBALS['xoopsDB']->fetchArray($result))) {
76
    //reset $gender
77
    $gender = '';
78
    if (!empty($GLOBALS['xoopsUser'])) {
79
        if ($row['d_user'] == $GLOBALS['xoopsUser']->getVar('uid') || true === $modadmin) {
80
            $gender = '<a href="dog.php?id=' . $row['d_id'] . '"><img src=' . $pathIcon16 . '/edit.png alt=' . _EDIT . '></a><a href="delete.php?id=' . $row['d_id'] . '"><img src=' . $pathIcon16 . '/delete.png alt=' . _DELETE . '></a>';
81
        } else {
82
            $gender = '';
83
        }
84
    }
85
86
    if ('' != $row['d_foto']) {
87
        $camera = ' <img src="assets/images/camera.png">';
88
    } else {
89
        $camera = '';
90
    }
91
92
    if (0 == $row['d_roft']) {
93
        $gender .= '<img src="assets/images/male.gif">';
94
    } else {
95
        $gender .= '<img src="assets/images/female.gif">';
96
    }
97
    //create string for parents
98
    if ('' == $row['f_naam']) {
99
        $dad = _MA_PEDIGREE_UNKNOWN;
100
    } else {
101
        $dad = '<a href="pedigree.php?pedid=' . $row['f_id'] . '">' . stripslashes($row['f_naam']) . '</a>';
102
    }
103
    if ('' == $row['m_naam']) {
104
        $mom = _MA_PEDIGREE_UNKNOWN;
105
    } else {
106
        $mom = '<a href="pedigree.php?pedid=' . $row['m_id'] . '">' . stripslashes($row['m_naam']) . '</a>';
107
    }
108
    $parents = $dad . ' x ' . $mom;
109
    //create array for animals
110
    $animals[] = [
111
        'id' => $row['d_id'],
112
        'name' => stripslashes($row['d_naam']) . $camera,
113
        'gender' => $gender,
114
        'parents' => $parents,
115
        'addedby' => '<a href="../../userinfo.php?uid=' . $row['d_user'] . '">' . $row['u_uname'] . '</a>',
116
    ];
117
    //reset rights ready for the next dog
118
    $editdel = '0';
119
}
120
121
//add data to smarty template
122
//assign dog
123
if (isset($animals)) {
124
    $xoopsTpl->assign('dogs', $animals);
125
}
126
127
//find last shown number
128
if (($st + $perPage) > $numResults) {
129
    $lastshown = $numResults;
130
} else {
131
    $lastshown = $st + $perPage;
132
}
133
//create string
134
$matches = strtr(_MA_PEDIGREE_MATCHES, ['[animalTypes]' => $moduleConfig['animalTypes']]);
135
$nummatchstr = $numResults . $matches . ($st + 1) . '-' . $lastshown . ' (' . $numPages . ' pages)';
136
$xoopsTpl->assign('nummatch', $nummatchstr);
137
if (isset($pages)) {
138
    $xoopsTpl->assign('pages', $pages);
139
}
140
$xoopsTpl->assign('name', _MA_PEDIGREE_FLD_NAME);
141
$xoopsTpl->assign('parents', _MA_PEDIGREE_PA);
142
$xoopsTpl->assign('addedby', _MA_PEDIGREE_FLD_DBUS);
143
//comments and footer
144
include XOOPS_ROOT_PATH . '/footer.php';
145