Passed
Push — master ( 39c203...ca1205 )
by Michael
02:01
created

searchmembers.php (3 issues)

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 The XOOPS Project http://sourceforge.net/projects/xoops/
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
require_once  __DIR__ . '/header.php';
22
23
global $xoopsModule;
24
$pathIcon16 = $xoopsModule->getInfo('icons16');
25
26
$op = (isset($_POST['op']) && 'submit' == $_POST['op']) ? 'submit' : 'form';
27
28
if ('form' == $op) {
29
    $xoopsOption['template_main'] = 'xoopsmembers_searchform.tpl';
30
    include XOOPS_ROOT_PATH . '/header.php';
31
32
    /** @var \XoopsMemberHandler $memberHandler */
33
    $memberHandler = xoops_getHandler('member');
34
    $total          = $memberHandler->getUserCount(new Criteria('level', 0, '>'));
35
36
    include_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
37
38
    $form        = new XoopsThemeForm('', 'searchform', 'searchmembers.php');
39
    $uname_text  = new XoopsFormText('', 'user_uname', 30, 60);
40
    $uname_match = new XoopsFormSelectMatchOption('', 'user_uname_match');
41
    $uname_tray  = new XoopsFormElementTray(_MD_XOOPSMEMBERS_UNAME, '&nbsp;');
42
    $uname_tray->addElement($uname_match);
43
    $uname_tray->addElement($uname_text);
44
    $form->addElement($uname_tray);
45
46
    if (1 == $xoopsModuleConfig['displayrealname']){
47
    $name_text  = new XoopsFormText('', 'user_name', 30, 60);
48
    $name_match = new XoopsFormSelectMatchOption('', 'user_name_match');
49
    $name_tray  = new XoopsFormElementTray(_MD_XOOPSMEMBERS_REALNAME, '&nbsp;');
50
    $name_tray->addElement($name_match);
51
    $name_tray->addElement($name_text);
52
    $form->addElement($name_tray);
53
    }
54
55
	if (1 == $xoopsModuleConfig['displayemail']){
56
    $email_text  = new XoopsFormText('', 'user_email', 30, 60);
57
    $email_match = new XoopsFormSelectMatchOption('', 'user_email_match');
58
    $email_tray  = new XoopsFormElementTray(_MD_XOOPSMEMBERS_EMAIL, '&nbsp;');
59
    $email_tray->addElement($email_match);
60
    $email_tray->addElement($email_text);
61
    $form->addElement($email_tray);
62
    }
63
64
	if (1 == $xoopsModuleConfig['displayurl']){
65
    $form->addElement(new XoopsFormText(_MD_XOOPSMEMBERS_URLC, 'user_url', 30, 100));
66
    }
67
	if (1 == $xoopsModuleConfig['displayfrom']){
68
    $form->addElement(new XoopsFormText(_MD_XOOPSMEMBERS_LOCATION, 'user_from', 30, 100));
69
	}
70
	if (1 == $xoopsModuleConfig['displayoccupation']){
71
    $form->addElement(new XoopsFormText(_MD_XOOPSMEMBERS_OCCUPATION, 'user_occ', 30, 100));
72
	}
73
	if (1 == $xoopsModuleConfig['displayinterest']){
74
    $form->addElement(new XoopsFormText(_MD_XOOPSMEMBERS_INTEREST, 'user_intrest', 30, 100));
75
	}
76
	if (1 == $xoopsModuleConfig['displaylastlogin']){
77
    $form->addElement(new XoopsFormText(_MD_XOOPSMEMBERS_LASTLOGMORE, 'user_lastlog_more', 10, 5));
78
    $form->addElement(new XoopsFormText(_MD_XOOPSMEMBERS_LASTLOGLESS, 'user_lastlog_less', 10, 5));
79
	}
80
	if (1 == $xoopsModuleConfig['displayregdate']){
81
    $form->addElement(new XoopsFormText(_MD_XOOPSMEMBERS_REGMORE, 'user_reg_more', 10, 5));
82
    $form->addElement(new XoopsFormText(_MD_XOOPSMEMBERS_REGLESS, 'user_reg_less', 10, 5));
83
	}
84
	if (1 == $xoopsModuleConfig['displayposts']){
85
    $form->addElement(new XoopsFormText(_MD_XOOPSMEMBERS_POSTSMORE, 'user_posts_more', 10, 5));
86
    $form->addElement(new XoopsFormText(_MD_XOOPSMEMBERS_POSTSLESS, 'user_posts_less', 10, 5));
87
	}
88
89
    $sort_select = new XoopsFormSelect(_MD_XOOPSMEMBERS_SORT, 'user_sort');
90
    $sort_select->addOptionArray(['uname' => _MD_XOOPSMEMBERS_UNAME, 'name' => _MD_XOOPSMEMBERS_REALNAME, 'last_login' => _MD_XOOPSMEMBERS_LASTLOGIN, 'user_regdate' => _MD_XOOPSMEMBERS_REGDATE, 'posts' => _MD_XOOPSMEMBERS_POSTS]);
91
    $form->addElement($sort_select);
92
93
    $order_select = new XoopsFormSelect(_MD_XOOPSMEMBERS_ORDER, 'user_order');
94
    $order_select->addOptionArray(['ASC' => _MD_XOOPSMEMBERS_ASC, 'DESC' => _MD_XOOPSMEMBERS_DESC]);
95
    $form->addElement($order_select);
96
97
    $form->addElement(new XoopsFormText(_MD_XOOPSMEMBERS_LIMIT, 'limit', 6, 2));
98
    $form->addElement(new XoopsFormHidden('op', 'submit'));
99
    $form->addElement(new XoopsFormButton('', 'user_submit', _SUBMIT, 'submit'));
100
    $form->assign($xoopsTpl);
101
    $xoopsTpl->assign('totalmember', $total);
102
}
103
104
if ('submit' == $op) {
105
    $xoopsOption['template_main'] = 'xoopsmembers_searchresults.tpl';
106
    include XOOPS_ROOT_PATH . '/header.php';
107
108
    $iamadmin = $xoopsUserIsAdmin;
109
    $myts     = MyTextSanitizer::getInstance();
110
    $criteria = new CriteriaCompo();
111
112
    if (!empty($_POST['user_uname'])) {
113
        $match = (!empty($_POST['user_uname_match'])) ? (int)$_POST['user_uname_match'] : XOOPS_MATCH_START;
114
        $ret   = $myts->addSlashes(trim($_POST['user_uname']));
115
        xoops_Criteria($criteria, 'uname', $ret, $match);
116
    }
117
118
    if (!empty($_POST['user_name'])) {
119
        $match = (!empty($_POST['user_name_match'])) ? (int)$_POST['user_name_match'] : XOOPS_MATCH_START;
120
        $ret   = $myts->addSlashes(trim($_POST['user_uname']));
121
        xoops_Criteria($criteria, 'name', $ret, $match);
122
    }
123
124
    if (!empty($_POST['user_email'])) {
125
        $match = (!empty($_POST['user_email_match'])) ? (int)$_POST['user_email_match'] : XOOPS_MATCH_START;
126
        $ret   = $myts->addSlashes(trim($_POST['user_email']));
127
        xoops_Criteria($criteria, 'name', $ret, $match);
128
        if (!$iamadmin) {
129
            $criteria->add(new Criteria('user_viewemail', 1));
130
        }
131
    }
132
133
    if (!empty($_POST['user_url'])) {
134
        $url = formatURL(trim($_POST['user_url']));
135
        $criteria->add(new Criteria('url', $myts->addSlashes($url) . '%', 'LIKE'));
136
    }
137
138
    if (!empty($_POST['user_from'])) {
139
        $criteria->add(new Criteria('user_from', '%' . $myts->addSlashes(trim($_POST['user_from'])) . '%', 'LIKE'));
140
    }
141
142
    if (!empty($_POST['user_intrest'])) {
143
        $criteria->add(new Criteria('user_intrest', '%' . $myts->addSlashes(trim($_POST['user_intrest'])) . '%', 'LIKE'));
144
    }
145
146
    if (!empty($_POST['user_occ'])) {
147
        $criteria->add(new Criteria('user_occ', '%' . $myts->addSlashes(trim($_POST['user_occ'])) . '%', 'LIKE'));
148
    }
149
150
    if (!empty($_POST['user_lastlog_more']) && is_numeric($_POST['user_lastlog_more'])) {
151
        $f_user_lastlog_more = (int)trim($_POST['user_lastlog_more']);
152
        $time                = time() - (60 * 60 * 24 * $f_user_lastlog_more);
153
        if ($time > 0) {
154
            $criteria->add(new Criteria('last_login', $time, '<'));
155
        }
156
    }
157
158
    if (!empty($_POST['user_lastlog_less']) && is_numeric($_POST['user_lastlog_less'])) {
159
        $f_user_lastlog_less = (int)trim($_POST['user_lastlog_less']);
160
        $time                = time() - (60 * 60 * 24 * $f_user_lastlog_less);
161
        if ($time > 0) {
162
            $criteria->add(new Criteria('last_login', $time, '>'));
163
        }
164
    }
165
166
    if (!empty($_POST['user_reg_more']) && is_numeric($_POST['user_reg_more'])) {
167
        $f_user_reg_more = (int)trim($_POST['user_reg_more']);
168
        $time            = time() - (60 * 60 * 24 * $f_user_reg_more);
169
        if ($time > 0) {
170
            $criteria->add(new Criteria('user_regdate', $time, '<'));
171
        }
172
    }
173
174
    if (!empty($_POST['user_reg_less']) && is_numeric($_POST['user_reg_less'])) {
175
        $f_user_reg_less = (int)$_POST['user_reg_less'];
176
        $time            = time() - (60 * 60 * 24 * $f_user_reg_less);
177
        if ($time > 0) {
178
            $criteria->add(new Criteria('user_regdate', $time, '>'));
179
        }
180
    }
181
182
    if (isset($_POST['user_posts_more']) && is_numeric($_POST['user_posts_more'])) {
183
        $criteria->add(new Criteria('posts', (int)$_POST['user_posts_more'], '>'));
184
    }
185
186
    if (!empty($_POST['user_posts_less']) && is_numeric($_POST['user_posts_less'])) {
187
        $criteria->add(new Criteria('posts', (int)$_POST['user_posts_less'], '<'));
188
    }
189
190
    $criteria->add(new Criteria('level', 0, '>'));
191
    $validsort = ['uname', 'email', 'last_login', 'user_regdate', 'posts'];
192
    $sort      = (!in_array($_POST['user_sort'], $validsort)) ? 'uname' : $_POST['user_sort'];
193
    $order     = 'ASC';
194
    if (isset($_POST['user_order']) && 'DESC' == $_POST['user_order']) {
195
        $order = 'DESC';
196
    }
197
    $limit = (!empty($_POST['limit'])) ? (int)$_POST['limit'] : 20;
198
    if (0 == $limit || $limit > 50) {
199
        $limit = 50;
200
    }
201
202
    $start          = (!empty($_POST['start'])) ? (int)$_POST['start'] : 0;
203
    $memberHandler = xoops_getHandler('member');
204
    $total          = $memberHandler->getUserCount($criteria);
0 ignored issues
show
The method getUserCount() 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

204
    /** @scrutinizer ignore-call */ 
205
    $total          = $memberHandler->getUserCount($criteria);
Loading history...
205
    $xoopsTpl->assign('total_found', $total);
206
207
    if (0 == $total) {
208
    } elseif ($start < $total) {
209
        if ($iamadmin) {
210
            $xoopsTpl->assign('is_admin', true);
211
        }
212
        $criteria->setSort($sort);
213
        $criteria->setOrder($order);
214
        $criteria->setStart($start);
215
        $criteria->setLimit($limit);
216
        $foundusers = $memberHandler->getUsers($criteria, true);
0 ignored issues
show
The method getUsers() 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

216
        /** @scrutinizer ignore-call */ 
217
        $foundusers = $memberHandler->getUsers($criteria, true);
Loading history...
217
        foreach (array_keys($foundusers) as $j) {
218
            $userdata['avatar']   = $foundusers[$j]->getVar('user_avatar') ? '<img src="' . XOOPS_UPLOAD_URL . '/' . $foundusers[$j]->getVar('user_avatar') . '" alt="" />' : '&nbsp;';
219
            $userdata['realname'] = $foundusers[$j]->getVar('name') ?: '&nbsp;';
220
            $userdata['name']     = $foundusers[$j]->getVar('uname');
221
            $userdata['id']       = $foundusers[$j]->getVar('uid');
222
            if (1 == $foundusers[$j]->getVar('user_viewemail') || $iamadmin) {
223
                $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>';
224
            } else {
225
                $userdata['email'] = '&nbsp;';
226
            }
227
            if ($xoopsUser) {
228
                $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>';
229
            } else {
230
                $userdata['pmlink'] = '&nbsp;';
231
            }
232
            if ('' != $foundusers[$j]->getVar('url', 'e')) {
233
                $userdata['website'] = '<a href="' . $foundusers[$j]->getVar('url', 'e') . '" target="_blank"><img src="' . XOOPS_URL . '/images/icons/www.gif" border="0" alt="' . _VISITWEBSITE . '" /></a>';
234
            } else {
235
                $userdata['website'] = '&nbsp;';
236
            }
237
            $userdata['registerdate'] = formatTimestamp($foundusers[$j]->getVar('user_regdate'), 's');
238
            if (0 != $foundusers[$j]->getVar('last_login')) {
239
                $userdata['lastlogin'] = formatTimestamp($foundusers[$j]->getVar('last_login'), 'm');
240
            } else {
241
                $userdata['lastlogin'] = '&nbsp;';
242
            }
243
            $userdata['posts'] = $foundusers[$j]->getVar('posts');
244
            if ($iamadmin) {
245
                $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 . "' />"
246
247
                                         . '</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>';
248
            }
249
            $xoopsTpl->append('users', $userdata);
250
        }
251
252
        $totalpages = ceil($total / $limit);
253
        if ($totalpages > 1) {
254
            $hiddenform = '<form name="findnext" action="searchmembers.php" method="post">';
255
            foreach ($_POST as $k => $v) {
256
                $hiddenform .= '<input type="hidden" name="' . $myts->htmlSpecialChars($k) . '" value="' . $myts->previewTarea($v) . '" />';
257
            }
258
            if (!isset($_POST['limit'])) {
259
                $hiddenform .= '<input type="hidden" name="limit" value="' . $limit . '" />';
260
            }
261
            if (!isset($_POST['start'])) {
262
                $hiddenform .= '<input type="hidden" name="start" value="' . $start . '" />';
263
            }
264
            $prev = $start - $limit;
265
            if ($start - $limit >= 0) {
266
                $hiddenform .= '<a href="#0" onclick="javascript:document.findnext.start.value=' . $prev . ';document.findnext.submit();">' . _MD_XOOPSMEMBERS_PREVIOUS . '</a>&nbsp;';
267
            }
268
            $counter     = 1;
269
            $currentpage = ($start + $limit) / $limit;
270
            while ($counter <= $totalpages) {
271
                if ($counter == $currentpage) {
272
                    $hiddenform .= '<b>' . $counter . '</b> ';
273
                } elseif (($counter > $currentpage - 4 && $counter < $currentpage + 4) || 1 == $counter || $counter == $totalpages) {
274
                    if ($counter == $totalpages && $currentpage < $totalpages - 4) {
275
                        $hiddenform .= '... ';
276
                    }
277
                    $hiddenform .= '<a href="#' . $counter . '" onclick="javascript:document.findnext.start.value=' . ($counter - 1) * $limit . ';document.findnext.submit();">' . $counter . '</a> ';
278
                    if (1 == $counter && $currentpage > 5) {
279
                        $hiddenform .= '... ';
280
                    }
281
                }
282
                $counter++;
283
            }
284
            $next = $start + $limit;
285
            if ($total > $next) {
286
                $hiddenform .= '&nbsp;<a href="#' . $total . '" onclick="javascript:document.findnext.start.value=' . $next . ';document.findnext.submit();">' . _MD_XOOPSMEMBERS_NEXT . '</a>';
287
            }
288
            $hiddenform .= '</form>';
289
            $xoopsTpl->assign('pagenav', $hiddenform);
290
            $xoopsTpl->assign('lang_numfound', sprintf(_MD_XOOPSMEMBERS_USERSFOUND, $total));
291
        }
292
    }
293
}
294
295
include 'footer.php';
296
include_once XOOPS_ROOT_PATH . '/footer.php';
297
exit();
298
299
/**
300
 * xoops_Criteria()
301
 *
302
 * @param        $criteria
303
 * @param string $name
304
 * @param string $ret
305
 * @param string $match
306
 * @return void
307
 */
308
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

308
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...
309
{
310
    global $criteria;
311
312
    switch ($match) {
313
        case XOOPS_MATCH_START:
314
            $criteria->add(new Criteria($name, $ret . '%', 'LIKE'));
315
            break;
316
        case XOOPS_MATCH_END:
317
            $criteria->add(new Criteria($name, '%' . $ret . '%', 'LIKE'));
318
            break;
319
        case XOOPS_MATCH_EQUAL:
320
            $criteria->add(new Criteria($name, $ret));
321
            break;
322
        case XOOPS_MATCH_CONTAIN:
323
            $criteria->add(new Criteria($name, '%' . $ret . '%', 'LIKE'));
324
            break;
325
    }
326
}
327