Passed
Push — master ( 48d769...5ccf6e )
by Michael
07:14
created

latest.php (1 issue)

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