Passed
Pull Request — master (#25)
by
unknown
03:26
created
Severity
1
<?php
2
3
/**
4
 * Xoops Members Module
5
 *
6
 * You may not change or alter any portion of this comment or credits
7
 * of supporting developers from this source code or any supporting source code
8
 * which is considered copyrighted (c) material of the original comment or credit authors.
9
 * This program is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
 *
13
 * @copyright XOOPS Project (https://xoops.org)
14
 * @license   http://www.fsf.org/copyleft/gpl.html GNU public license
15
 * @package   Xoops Members
16
 * @since     2.3.0
17
 * @author    onokazu
18
 * @author    John Neill
19
 */
20
21
$xoopsOption['template_main'] = 'xoopsmembers_index.tpl'; 
22
require_once __DIR__ . '/header.php';
23
 
24
//global $pathIcon16;
25
26
global $xoopsModule;
27
if ('datatables' == $xoopsModuleConfig['indextemplate']) {
28
	$xoTheme->addStylesheet(XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/assets/css/jquery.dataTables.css');
29
	$xoTheme->addScript(XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/assets/js/jquery.dataTables.js');
30
}
31
32
/** @var \XoopsMemberHandler $memberHandler */
33
$memberHandler = xoops_getHandler('member');
34
$total         = $memberHandler->getUserCount(new \Criteria('level', 0, '>'));
35
36
$iamadmin = $xoopsUserIsAdmin;
37
$myts     = \MyTextSanitizer::getInstance();
38
$criteria = new \CriteriaCompo();
39
40
$criteria->add(new \Criteria('level', 0, '>'));
41
$validsort = ['uname', 'name', 'last_login', 'user_regdate', 'posts'];
42
//$sort      = (!in_array($helper->getModule()->getInfo('sortmembers'), $validsort)) ? 'uname' : $helper->getModule()->getInfo('sortmembers');
43
//temp solution
44
$sort = (!in_array($xoopsModuleConfig['sortmembers'], $validsort ) ) ? 'uname' : $xoopsModuleConfig['sortmembers'];
45
    
46
$order = 'ASC';
47
//$temp  = $helper->getModule()->getInfo('membersorder');
48
//temp solution
49
if ( isset($xoopsModuleConfig['membersorder']) && $xoopsModuleConfig['membersorder'] == 'DESC' ) {
50
//if (isset($temp) && 'DESC' == $temp) {
51
    $order = 'DESC';
52
}
53
54
if ('normal' == $xoopsModuleConfig['indextemplate']) {
55
//temp solution
56
$limit = (!empty($xoopsModuleConfig['membersperpage'])) ? intval($xoopsModuleConfig['membersperpage']) : 20;
57
//$limit = \Xmf\Request::getInt('limit', 20, 'POST');
58
if (0 == $limit || $limit > 50) {
59
    $limit = 50;
60
}
61
}
62
$start = \Xmf\Request::getInt('start', 0, 'POST');
63
$total = $memberHandler->getUserCount($criteria);
64
$xoopsTpl->assign('totalmember', $total);
65
66
//Show last member
67
$result = $GLOBALS['xoopsDB']->query('SELECT uid, uname FROM ' . $GLOBALS['xoopsDB']->prefix('users') . ' WHERE level > 0 ORDER BY uid DESC', 1, 0);
68
list($latestuid, $latestuser) = $GLOBALS['xoopsDB']->fetchRow($result);
69
$xoopsTpl->assign('latestmember', " <a href='" . XOOPS_URL . '/userinfo.php?uid=' . $latestuid . "'>" . $latestuser . '</a>');
70
$xoopsTpl->assign('welcomemessage', $xoopsModuleConfig['welcomemessage']);
71
72
if (0 == $total) {
73
} elseif ($start < $total) {
74
    if ($iamadmin) {
75
        $xoopsTpl->assign('is_admin', true);
76
    }
77
    $criteria->setSort($sort);
78
    $criteria->setOrder($order);
79
    $criteria->setStart($start);
80
    if ('normal' == $xoopsModuleConfig['indextemplate']) {
81
    $criteria->setLimit($limit); }
82
    $foundusers = $memberHandler->getUsers($criteria, true);
83
    foreach (array_keys($foundusers) as $j) {
84
        $userdata['avatar']   = $foundusers[$j]->getVar('user_avatar');
85
        $userdata['realname'] = $foundusers[$j]->getVar('name');
86
        $userdata['name']     = $foundusers[$j]->getVar('uname');
87
        $userdata['id']       = $foundusers[$j]->getVar('uid');
88
        if (1 == $foundusers[$j]->getVar('user_viewemail') || $iamadmin) {
89
            $userdata['email'] = '<a href="mailto:' . $foundusers[$j]->getVar('email') . '"><img src="' . XOOPS_URL . '/images/icons/email.gif" border="0" alt="' . sprintf(_SENDEMAILTO, $foundusers[$j]->getVar('uname', 'e')) . '"></a>';
90
        }
91
        if ($xoopsUser) {
92
            $userdata['pmlink'] = '<a href="javascript:openWithSelfMain(\'' . XOOPS_URL . '/pmlite.php?send2=1&amp;to_userid=' . $foundusers[$j]->getVar('uid') . '\',\'pmlite\',450,370);"><img src="' . XOOPS_URL . '/images/icons/pm.gif" border="0" alt="' . sprintf(_SENDPMTO, $foundusers[$j]->getVar('uname', 'e')) . '"></a>';
93
        } 
94
        if ('' != $foundusers[$j]->getVar('url', 'e')) {
95
            $userdata['website'] = '<a href="' . $foundusers[$j]->getVar('url', 'e') . '" target="_blank"><img src="' . XOOPS_URL . '/images/icons/www.gif" border="0" alt="' . _VISITWEBSITE . '"></a>';
96
        }
97
        $userdata['registerdate'] = formatTimestamp($foundusers[$j]->getVar('user_regdate'), 's');
98
        if (0 != $foundusers[$j]->getVar('last_login')) {
99
            $userdata['lastlogin'] = formatTimestamp($foundusers[$j]->getVar('last_login'), 'm');
100
        } else {
101
            $userdata['lastlogin'] = _MD_XOOPSMEMBERS_NEVERLOGIN;
102
        }
103
        $userdata['posts'] = $foundusers[$j]->getVar('posts');
104
        if ($iamadmin) {
105
            $userdata['adminlink'] = '<a href="' . XOOPS_URL . '/modules/system/admin.php?fct=users&amp;uid=' . $foundusers[$j]->getVar('uid') . '&amp;op=users_edit">' . '<img src=' . $pathIcon16 . '/edit.png' . " alt='" . _EDIT . "' title='" . _EDIT . "'>"
106
107
                                     . '</a> <a href="' . XOOPS_URL . '/modules/system/admin.php?fct=users&amp;op=users_delete&amp;uid=' . $foundusers[$j]->getVar('uid') . '">' . '<img src=' . $pathIcon16 . '/delete.png' . " alt='" . _DELETE . "' title='" . _DELETE . "'>" . '</a>';
108
        }
109
		
110
		$userdata['location']       = $foundusers[$j]->getVar('user_from');
111
		$userdata['occupation']     = $foundusers[$j]->getVar('user_occ');
112
		$userdata['interest']       = $foundusers[$j]->getVar('user_intrest');
113
        $xoopsTpl->append('users', $userdata);
114
    }
115
  if ('normal' == $xoopsModuleConfig['indextemplate']) {
116
    $totalpages = ceil($total / $limit);
117
    if ($totalpages > 1) {
118
        $hiddenform = '<form name="findnext" action="index.php" method="post">';
119
        foreach ($_POST as $k => $v) {
120
            $hiddenform .= '<input type="hidden" name="' . $myts->htmlSpecialChars($k) . '" value="' . $myts->previewTarea($v) . '">';
121
        }
122
        if (!isset($_POST['limit'])) {
123
            $hiddenform .= '<input type="hidden" name="limit" value="' . $limit . '">';
124
        }
125
        if (!isset($_POST['start'])) {
126
            $hiddenform .= '<input type="hidden" name="start" value="' . $start . '">';
127
        }
128
        $prev = $start - $limit;
129
        if ($start - $limit >= 0) {
130
            $hiddenform .= '<a href="#0" onclick="javascript:document.findnext.start.value=' . $prev . ';document.findnext.submit();">' . _MD_XOOPSMEMBERS_PREVIOUS . '</a>&nbsp;';
131
        }
132
        $counter     = 1;
133
        $currentpage = ($start + $limit) / $limit;
134
        while ($counter <= $totalpages) {
135
            if ($counter == $currentpage) {
136
                $hiddenform .= '<b>' . $counter . '</b> ';
137
            } elseif (($counter > $currentpage - 4 && $counter < $currentpage + 4) || 1 == $counter || $counter == $totalpages) {
138
                if ($counter == $totalpages && $currentpage < $totalpages - 4) {
139
                    $hiddenform .= '... ';
140
                }
141
                $hiddenform .= '<a href="#' . $counter . '" onclick="javascript:document.findnext.start.value=' . ($counter - 1) * $limit . ';document.findnext.submit();">' . $counter . '</a> ';
142
                if (1 == $counter && $currentpage > 5) {
143
                    $hiddenform .= '... ';
144
                }
145
            }
146
            $counter++;
147
        }
148
        $next = $start + $limit;
149
        if ($total > $next) {
150
            $hiddenform .= '&nbsp;<a href="#' . $total . '" onclick="javascript:document.findnext.start.value=' . $next . ';document.findnext.submit();">' . _MD_XOOPSMEMBERS_NEXT . '</a>';
151
        }
152
        $hiddenform .= '</form>';
153
        $xoopsTpl->assign('pagenav', $hiddenform);
154
        $xoopsTpl->assign('lang_numfound', sprintf(_MD_XOOPSMEMBERS_USERSFOUND, $total));
155
    }
156
  }
157
}
158
159
require __DIR__ . '/footer.php';
160
require_once XOOPS_ROOT_PATH . '/footer.php';
161
exit();
162
163
/**
164
 * xoops_Criteria()
165
 *
166
 * @param \CriteriaCompo       $criteria
167
 * @param string $name
168
 * @param string $ret
169
 * @param string $match
170
 * @return void
171
 */
172
function xoops_Criteria(&$criteria, $name = '', $ret = '', $match = '')
0 ignored issues
show
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

172
function xoops_Criteria(/** @scrutinizer ignore-unused */ &$criteria, $name = '', $ret = '', $match = '')

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...
173
{
174
    global $criteria;
175
176
    switch ($match) {
177
        case XOOPS_MATCH_START:
178
            $criteria->add(new \Criteria($name, $ret . '%', 'LIKE'));
179
            break;
180
        case XOOPS_MATCH_END:
181
            $criteria->add(new \Criteria($name, '%' . $ret . '%', 'LIKE'));
182
            break;
183
        case XOOPS_MATCH_EQUAL:
184
            $criteria->add(new \Criteria($name, $ret));
185
            break;
186
        case XOOPS_MATCH_CONTAIN:
187
            $criteria->add(new \Criteria($name, '%' . $ret . '%', 'LIKE'));
188
            break;
189
    }
190
}
191