Passed
Pull Request — master (#1270)
by Michael
05:36
created

XoUserHandler::getCount()   B

Complexity

Conditions 7
Paths 24

Size

Total Lines 25
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
eloc 16
nc 24
nop 2
dl 0
loc 25
rs 8.8333
c 0
b 0
f 0
1
<?php
2
/**
3
 * Find XOOPS users
4
 *
5
 * You may not change or alter any portion of this comment or credits
6
 * of supporting developers from this source code or any supporting source code
7
 * which is considered copyrighted (c) material of the original comment or credit authors.
8
 * This program is distributed in the hope that it will be useful,
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11
 *
12
 * @copyright       (c) 2000-2016 XOOPS Project (www.xoops.org)
13
 * @license             GNU GPL 2 (https://www.gnu.org/licenses/gpl-2.0.html)
14
 * @package             kernel
15
 * @since               2.3.0
16
 * @author              Taiwen Jiang <[email protected]>
17
 */
18
/* @var  XoopsUser $xoopsUser */
19
20
use Xmf\Request;
21
22
include_once dirname(__DIR__) . '/mainfile.php';
23
24
xoops_header(false);
25
26
$denied = true;
27
if (Request::hasVar('token')) {
28
    if ($GLOBALS['xoopsSecurity']->validateToken(Request::getString('token'), false)) {
29
        $denied = false;
30
    }
31
} elseif (is_object($xoopsUser) && $xoopsUser->isAdmin()) {
32
    $denied = false;
33
}
34
if ($denied) {
35
    xoops_error(_NOPERM);
36
    exit();
37
}
38
39
$token         = Request::getString('token', '');
40
$name_form     = 'memberslist';
41
$multiple = Request::getInt('multiple', 0);
42
$name_userid   = 'uid' . ((0 != $multiple) ? '[]' : '');
43
$name_username = 'uname' . ((0 != $multiple) ? '[]' : '');
44
45
xoops_loadLanguage('findusers');
46
47
/**
48
 * Enter description here...
49
 *
50
 */
51
class XoopsRank extends XoopsObject
52
{
53
    /**
54
     * Construct
55
     *
56
     */
57
    public function __construct()
58
    {
59
        parent::__construct();
60
        $this->initVar('rank_id', XOBJ_DTYPE_INT, null, false);
61
        $this->initVar('rank_title', XOBJ_DTYPE_TXTBOX, null, false);
62
        $this->initVar('rank_min', XOBJ_DTYPE_INT, 0);
63
        $this->initVar('rank_max', XOBJ_DTYPE_INT, 0);
64
        $this->initVar('rank_special', XOBJ_DTYPE_INT, 0);
65
        $this->initVar('rank_image', XOBJ_DTYPE_TXTBOX, '');
66
    }
67
}
68
69
/**
70
 * Xoops Rank Handler
71
 *
72
 */
73
class XoopsRankHandler extends XoopsObjectHandler
74
{
75
    /**
76
     * Constructor
77
     *
78
     * @param XoopsDatabase $db
79
     */
80
    public function __construct(XoopsDatabase $db)
81
    {
82
        parent::__construct($db);
83
    }
84
85
    /**
86
     * Create Object
87
     *
88
     * @param  bool $isNew
89
     * @return XoopsRank
90
     */
91
    public function create($isNew = true)
92
    {
93
        $obj = new XoopsRank();
94
        if ($isNew === true) {
95
            $obj->setNew();
96
        }
97
98
        return $obj;
99
    }
100
101
    /**
102
     * Get Object
103
     *
104
     * @param  int $id
105
     * @return object
106
     */
107
    public function get($id = 0)
108
    {
109
        $object = $this->create(false);
110
        $sql    = 'SELECT * FROM ' . $this->db->prefix('ranks') . ' WHERE rank_id = ' . $this->db->quoteString($id);
0 ignored issues
show
Bug introduced by
The method quoteString() does not exist on XoopsDatabase. Since it exists in all sub-types, consider adding an abstract or default implementation to XoopsDatabase. ( Ignorable by Annotation )

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

110
        $sql    = 'SELECT * FROM ' . $this->db->prefix('ranks') . ' WHERE rank_id = ' . $this->db->/** @scrutinizer ignore-call */ quoteString($id);
Loading history...
111
        $result = $this->db->query($sql);
0 ignored issues
show
Bug introduced by
The method query() does not exist on XoopsDatabase. Since it exists in all sub-types, consider adding an abstract or default implementation to XoopsDatabase. ( Ignorable by Annotation )

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

111
        /** @scrutinizer ignore-call */ 
112
        $result = $this->db->query($sql);
Loading history...
112
        if (!$this->db->isResultSet($result)) {
113
            \trigger_error("Query Failed! SQL: $sql- Error: " . $this->db->error(), E_USER_ERROR);
0 ignored issues
show
Bug introduced by
The method error() does not exist on XoopsDatabase. Since it exists in all sub-types, consider adding an abstract or default implementation to XoopsDatabase. ( Ignorable by Annotation )

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

113
            \trigger_error("Query Failed! SQL: $sql- Error: " . $this->db->/** @scrutinizer ignore-call */ error(), E_USER_ERROR);
Loading history...
114
        }
115
116
//        if (!$result) {
117
//            $ret = null;
118
//
119
//            return $ret;
120
//        }
121
        while (false !== ($row = $this->db->fetchArray($result))) {
0 ignored issues
show
Bug introduced by
The method fetchArray() does not exist on XoopsDatabase. Since it exists in all sub-types, consider adding an abstract or default implementation to XoopsDatabase. ( Ignorable by Annotation )

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

121
        while (false !== ($row = $this->db->/** @scrutinizer ignore-call */ fetchArray($result))) {
Loading history...
122
            $object->assignVars($row);
123
        }
124
125
        return $object;
126
    }
127
128
    /**
129
     * Get List
130
     *
131
     * @param  CriteriaElement $criteria
132
     * @param  int             $limit
133
     * @param  int             $start
134
     * @return array
135
     */
136
    public function getList(CriteriaElement $criteria = null, $limit = 0, $start = 0)
137
    {
138
        $ret = array();
139
        if ($criteria == null) {
140
            $criteria = new CriteriaCompo();
141
        }
142
143
        $sql = 'SELECT rank_id, rank_title FROM ' . $this->db->prefix('ranks');
144
        if (isset($criteria) && is_subclass_of($criteria, 'CriteriaElement')) {
145
            $sql .= ' ' . $criteria->renderWhere();
0 ignored issues
show
Bug introduced by
The method renderWhere() does not exist on CriteriaElement. Did you maybe mean render()? ( Ignorable by Annotation )

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

145
            $sql .= ' ' . $criteria->/** @scrutinizer ignore-call */ renderWhere();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
146
            if ($criteria->getSort() != '') {
147
                $sql .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder();
148
            }
149
            $limit = $criteria->getLimit();
150
            $start = $criteria->getStart();
151
        }
152
        $result = $this->db->query($sql, $limit, $start);
153
//        if (!$result) {
154
//            return $ret;
155
//        }
156
        if (!$this->db->isResultSet($result)) {
157
            \trigger_error("Query Failed! SQL: $sql- Error: " . $this->db->error(), E_USER_ERROR);
158
        }
159
        $myts = MyTextSanitizer::getInstance();
160
        while (false !== ($myrow = $this->db->fetchArray($result))) {
161
            $ret[$myrow['rank_id']] = $myts->htmlSpecialChars($myrow['rank_title']);
162
        }
163
164
        return $ret;
165
    }
166
}
167
168
/**
169
 * Xoops Users Extend Class
170
 *
171
 */
172
class XoUser extends XoopsUser
173
{
174
    /**
175
     * Enter Constructor
176
     *
177
     */
178
    public function __construct()
179
    {
180
        parent::__construct();
181
        $unsets = array(
182
            'actkey',
183
            'pass',
184
            'theme',
185
            'umode',
186
            'uorder',
187
            'notify_mode');
188
        foreach ($unsets as $var) {
189
            unset($this->vars[$var]);
190
        }
191
    }
192
}
193
194
/**
195
 * XoUser Handler
196
 *
197
 */
198
class XoUserHandler extends XoopsObjectHandler
199
{
200
    /**
201
     * Enter description here...
202
     *
203
     * @param XoopsDatabase $db
204
     */
205
    public function __construct(XoopsDatabase $db)
206
    {
207
        parent::__construct($db);
208
    }
209
210
    /**
211
     * Create
212
     *
213
     * @param  bool $isNew
214
     * @return XoUser
215
     */
216
    public function create($isNew = true)
217
    {
218
        $obj = new XoUser();
219
        if ($isNew === true) {
220
            $obj->setNew();
221
        }
222
223
        return $obj;
224
    }
225
226
    /**
227
     * Get Count
228
     *
229
     * @param  CriteriaElement $criteria
230
     * @param  array           $groups
231
     * @return int
232
     */
233
    public function getCount(CriteriaElement $criteria = null, $groups = array())
234
    {
235
        if (!is_array($groups)) {
0 ignored issues
show
introduced by
The condition is_array($groups) is always true.
Loading history...
236
            $groups = array(
237
                $groups);
238
        }
239
        $groups = array_filter($groups);
240
        if (empty($groups)) {
241
            $sql = '    SELECT COUNT(DISTINCT u.uid) FROM ' . $this->db->prefix('users') . ' AS u' . '    WHERE 1=1';
242
        } else {
243
            $sql = '    SELECT COUNT(DISTINCT u.uid) FROM ' . $this->db->prefix('users') . ' AS u' . '    LEFT JOIN ' . $this->db->prefix('groups_users_link') . ' AS g ON g.uid = u.uid' . '    WHERE g.groupid IN (' . implode(', ', array_map('intval', $groups)) . ')';
244
        }
245
        if (isset($criteria) && is_subclass_of($criteria, 'CriteriaElement')) {
246
            // Use the direct renderer, assuming no `uid` in criteria
247
            if ($render = $criteria->render()) {
248
                $sql .= ' AND ' . $render;
249
            }
250
        }
251
        $result = $this->db->query($sql);
252
        if (!$this->db->isResultSet($result)) {
253
            \trigger_error("Query Failed! SQL: $sql- Error: " . $this->db->error(), E_USER_ERROR);
254
        }
255
        list($count) = $this->db->fetchRow($result);
0 ignored issues
show
Bug introduced by
The method fetchRow() does not exist on XoopsDatabase. Since it exists in all sub-types, consider adding an abstract or default implementation to XoopsDatabase. ( Ignorable by Annotation )

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

255
        /** @scrutinizer ignore-call */ 
256
        list($count) = $this->db->fetchRow($result);
Loading history...
256
257
        return $count;
258
    }
259
260
    /**
261
     * GetAll
262
     *
263
     * @param  CriteriaElement $criteria
264
     * @param  array           $groups
265
     * @return array of matching objects
266
     */
267
    public function getAll(CriteriaElement $criteria = null, $groups = array())
268
    {
269
        if (!is_array($groups)) {
0 ignored issues
show
introduced by
The condition is_array($groups) is always true.
Loading history...
270
            $groups = array(
271
                $groups);
272
        }
273
        $groups = array_filter($groups);
274
        $limit  = null;
275
        $start  = null;
276
        if (empty($groups)) {
277
            $sql = '    SELECT u.* FROM ' . $this->db->prefix('users') . ' AS u' . '    WHERE 1=1';
278
        } else {
279
            $sql = '    SELECT u.* FROM ' . $this->db->prefix('users') . ' AS u' . '    LEFT JOIN ' . $this->db->prefix('groups_users_link') . ' AS g ON g.uid = u.uid' . '    WHERE g.groupid IN (' . implode(', ', array_map('intval', $groups)) . ')';
280
        }
281
        if (isset($criteria) && is_subclass_of($criteria, 'CriteriaElement')) {
282
            if ($render = $criteria->render()) {
283
                $sql .= ' AND ' . $render;
284
            }
285
            if ($sort = $criteria->getSort()) {
286
                $sql .= ' ORDER BY ' . $sort . ' ' . $criteria->getOrder();
287
                $orderSet = true;
288
            }
289
            $limit = $criteria->getLimit();
290
            $start = $criteria->getStart();
291
        }
292
        if (empty($orderSet)) {
293
            $sql .= ' ORDER BY u.uid ASC';
294
        }
295
        $result = $this->db->query($sql, $limit, $start);
296
        if (!$this->db->isResultSet($result)) {
297
            \trigger_error("Query Failed! SQL: $sql- Error: " . $this->db->error(), E_USER_ERROR);
298
        }
299
        $ret    = array();
300
        while (false !== ($myrow = $this->db->fetchArray($result))) {
301
            $object = $this->create(false);
302
            $object->assignVars($myrow);
303
            $ret[$myrow['uid']] = $object;
304
            unset($object);
305
        }
306
307
        return $ret;
308
    }
309
}
310
311
$rank_handler = new XoopsRankHandler($xoopsDB);
312
$user_handler = new XoUserHandler($xoopsDB);
313
314
$items_match = array(
315
    'uname'     => _MA_USER_UNAME,
316
    'name'      => _MA_USER_REALNAME,
317
    'email'     => _MA_USER_EMAIL,
318
//  'user_icq'  => _MA_USER_ICQ,
319
//  'user_aim'  => _MA_USER_AIM,
320
//  'user_yim'  => _MA_USER_YIM,
321
//  'user_msnm' => _MA_USER_MSNM,
322
);
323
324
$items_range = array(
325
    'user_regdate' => _MA_USER_RANGE_USER_REGDATE,
326
    'last_login'   => _MA_USER_RANGE_LAST_LOGIN,
327
    'posts'        => _MA_USER_RANGE_POSTS);
328
329
define('FINDUSERS_MODE_SIMPLE', 0);
330
define('FINDUSERS_MODE_ADVANCED', 1);
331
332
$modes = array(
333
    FINDUSERS_MODE_SIMPLE   => _MA_USER_MODE_SIMPLE,
334
    FINDUSERS_MODE_ADVANCED => _MA_USER_MODE_ADVANCED,
335
);
336
337
if (!Request::hasVar('user_submit', 'POST')) {
338
    include_once $GLOBALS['xoops']->path('class/xoopsformloader.php');
339
340
    $form = new XoopsThemeForm(_MA_USER_FINDUS, 'user_findform', 'findusers.php', 'post', true);
341
    $mode = Request::getInt('mode', 0);
342
    if (FINDUSERS_MODE_ADVANCED == $mode) {
343
        foreach ($items_match as $var => $title) {
344
            $text = new XoopsFormText('', $var, 30, 100, Request::getString($var, '', 'POST'));
345
            $match = new XoopsFormSelectMatchOption('', "{$var}_match", Request::getInt("{$var}_match", 0));
346
            $match_tray = new XoopsFormElementTray($title, '&nbsp;');
347
            $match_tray->addElement($match);
348
            $match_tray->addElement($text);
349
            $form->addElement($match_tray);
350
            unset($text, $match, $match_tray);
351
        }
352
353
        $url_text        = new XoopsFormText(_MA_USER_URLC, 'url', 30, 100, Request::getUrl('url', '', 'POST'));
354
        $location_text   = new XoopsFormText(_MA_USER_LOCATION, 'user_from', 30, 100, Request::getString('user_from', '', 'POST'));
355
        $occupation_text = new XoopsFormText(_MA_USER_OCCUPATION, 'user_occ', 30, 100, Request::getString('user_occ', '', 'POST'));
356
        $interest_text   = new XoopsFormText(_MA_USER_INTEREST, 'user_intrest', 30, 100, Request::getString('user_intrest', '', 'POST'));
357
        foreach ($items_range as $var => $title) {
358
            $more = new XoopsFormText('', "{$var}_more", 10, 5, Request::getString("{$var}_more", '', 'POST'));
359
            $less = new XoopsFormText('', "{$var}_less", 10, 5, Request::getString("{$var}_less", '', 'POST'));
360
            $range_tray = new XoopsFormElementTray($title, '&nbsp;-&nbsp;&nbsp;');
361
            $range_tray->addElement($less);
362
            $range_tray->addElement($more);
363
            $form->addElement($range_tray);
364
            unset($more, $less, $range_tray);
365
        }
366
367
        $mailok_radio = new XoopsFormRadio(_MA_USER_SHOWMAILOK, 'user_mailok',  Request::getString('user_mailok', 'both', 'POST'));
368
        $mailok_radio->addOptionArray(array(
369
            'mailok' => _MA_USER_MAILOK,
370
            'mailng' => _MA_USER_MAILNG,
371
            'both' => _MA_USER_BOTH
372
        ));
373
        $avatar_radio = new XoopsFormRadio(_MA_USER_HASAVATAR, 'user_avatar', Request::getString('user_avatar', 'both', 'POST'));
374
        $avatar_radio->addOptionArray(array(
375
            'y' => _YES,
376
            'n' => _NO,
377
            'both' => _MA_USER_BOTH
378
        ));
379
380
        $level_radio = new XoopsFormRadio(_MA_USER_LEVEL, 'level', @$_POST['level']);
381
        $levels      = array(
382
            0 => _ALL,
383
            1 => _MA_USER_LEVEL_ACTIVE,
384
            2 => _MA_USER_LEVEL_INACTIVE,
385
            3 => _MA_USER_LEVEL_DISABLED
386
        );
387
        $level_radio->addOptionArray($levels);
388
389
        /* @var XoopsMemberHandler $member_handler */
390
        $member_handler = xoops_getHandler('member');
391
        $groups         = $member_handler->getGroupList();
392
        $groups[0]      = _ALL;
393
        $group_select   = new XoopsFormSelect(_MA_USER_GROUP, 'groups', Request::getInt('groups', 0), 3, true);
394
        $group_select->addOptionArray($groups);
395
396
        $ranks       = $rank_handler->getList();
397
        $ranks[0]    = _ALL;
398
        $rank_select = new XoopsFormSelect(_MA_USER_RANK, 'rank', Request::getInt('rank', 0) );
399
        $rank_select->addOptionArray($ranks);
400
        $form->addElement($url_text);
401
        $form->addElement($location_text);
402
        $form->addElement($occupation_text);
403
        $form->addElement($interest_text);
404
        $form->addElement($mailok_radio);
405
        $form->addElement($avatar_radio);
406
        $form->addElement($level_radio);
407
        $form->addElement($group_select);
408
        $form->addElement($rank_select);
409
    } else {
410
        foreach (array('uname', 'email') as $var) {
411
            $title      = $items_match[$var];
412
            $text       = new XoopsFormText('', $var, 30, 100, Request::getString($var, '', 'POST'));
413
            $match      = new XoopsFormSelectMatchOption('', "{$var}_match", Request::getInt("{$var}_match", 0));
414
            $match_tray = new XoopsFormElementTray($title, '&nbsp;');
415
            $match_tray->addElement($match);
416
            $match_tray->addElement($text);
417
            $form->addElement($match_tray);
418
            unset($text, $match, $match_tray);
419
        }
420
    }
421
422
    $sort_select = new XoopsFormSelect(_MA_USER_SORT, 'user_sort', @$_POST['user_sort']);
423
    $sort_select->addOptionArray(array(
424
        'uname' => _MA_USER_UNAME,
425
        'last_login' => _MA_USER_LASTLOGIN,
426
        'user_regdate' => _MA_USER_REGDATE,
427
        'posts' => _MA_USER_POSTS
428
    ));
429
    $order_select = new XoopsFormSelect(_MA_USER_ORDER, 'user_order', @$_POST['user_order']);
430
    $order_select->addOptionArray(array(
431
        'ASC' => _MA_USER_ASC,
432
        'DESC' => _MA_USER_DESC
433
    ));
434
435
    $form->addElement($sort_select);
436
    $form->addElement($order_select);
437
438
    $form->addElement(new XoopsFormText(_MA_USER_LIMIT, 'limit', 6, 6, Request::getInt('limit', 50, 'POST')));
439
    $form->addElement(new XoopsFormHidden('mode', $mode));
440
    $form->addElement(new XoopsFormHidden('target', Request::getString('target', '', 'POST')));
441
    $form->addElement(new XoopsFormHidden('multiple', $multiple));
442
    $form->addElement(new XoopsFormHidden('token', $token));
443
    $form->addElement(new XoopsFormButton('', 'user_submit', _SUBMIT, 'submit'));
444
445
    $acttotal   = $user_handler->getCount(new Criteria('level', 0, '>'));
446
    $inacttotal = $user_handler->getCount(new Criteria('level', 0, '<='));
447
    echo '</html><body>';
448
    echo "<h2 style='text-align:left;'>" . _MA_USER_FINDUS . ' - ' . $modes[$mode] . '</h2>';
449
    $modes_switch = array();
450
    foreach ($modes as $_mode => $title) {
451
        if ($mode == $_mode) {
452
            continue;
453
        }
454
        $modes_switch[] = "<a href='findusers.php?target=" . htmlspecialchars(Request::getString('target', ''), ENT_QUOTES) . '&amp;multiple=' . (string)$multiple . '&amp;token=' . htmlspecialchars($token, ENT_QUOTES) . "&amp;mode={$_mode}'>{$title}</a>";
455
    }
456
    echo '<h4>' . implode(' | ', $modes_switch) . '</h4>';
457
    echo '(' . sprintf(_MA_USER_ACTUS, "<span style='color:#ff0000;'>$acttotal</span>") . ' ' . sprintf(_MA_USER_INACTUS, "<span style='color:#ff0000;'>$inacttotal</span>") . ')';
458
    $form->display();
459
} else {
460
    $myts  = MyTextSanitizer::getInstance();
461
    $limit = Request::getInt('limit', 50, 'POST');
462
    $start = Request::getInt('start', 0, 'POST');
463
    if (Request::hasVar('query', 'POST')) {
464
        unset($_POST['query']);
465
        $query = '';
466
    }
467
468
    $criteria = new CriteriaCompo();
469
    foreach (array_keys($items_match) as $var) {
470
        if (Request::hasVar($var, 'POST')) {
471
            $match = Request::getInt("{$var}_match", XOOPS_MATCH_START, 'POST');
472
            $value = $xoopsDB->escape(Request::getString($var, '', 'POST'));
473
            switch ($match) {
474
                case XOOPS_MATCH_START:
475
                    $criteria->add(new Criteria($var, $value . '%', 'LIKE'));
476
                    break;
477
                case XOOPS_MATCH_END:
478
                    $criteria->add(new Criteria($var, '%' . $value, 'LIKE'));
479
                    break;
480
                case XOOPS_MATCH_EQUAL:
481
                    $criteria->add(new Criteria($var, $value));
482
                    break;
483
                case XOOPS_MATCH_CONTAIN:
484
                    $criteria->add(new Criteria($var, '%' . $value . '%', 'LIKE'));
485
                    break;
486
            }
487
        }
488
    }
489
    if (Request::hasVar('url', 'POST')) {
490
        $url = formatURL(trim(Request::getUrl('url', '', 'POST')));
491
        $criteria->add(new Criteria('url', $url . '%', 'LIKE'));
492
    }
493
    if (Request::hasVar('user_from', 'POST')) {
494
        $criteria->add(new Criteria('user_from', '%' . $xoopsDB->escape(Request::getString('user_from', '', 'POST')) . '%', 'LIKE'));
495
    }
496
    if (Request::hasVar('user_intrest', 'POST')) {
497
        $criteria->add(new Criteria('user_intrest', '%' . $xoopsDB->escape(Request::getString('user_intrest', '', 'POST')) . '%', 'LIKE'));
498
    }
499
    if (Request::hasVar('user_occ', 'POST')) {
500
        $criteria->add(new Criteria('user_occ', '%' . $xoopsDB->escape(Request::getString('user_occ', '', 'POST')) . '%', 'LIKE'));
501
    }
502
    foreach (array('last_login', 'user_regdate') as $var) {
503
        if (Request::hasVar("{$var}_more", 'POST') && is_numeric($_POST["{$var}_more"])) {
504
            $time = time() - (60 * 60 * 24 *  Request::getInt("{$var}_more", 0, 'POST'));
505
            if ($time > 0) {
506
                $criteria->add(new Criteria($var, $time, '<='));
507
            }
508
        }
509
        if (Request::hasVar("{$var}_less", 'POST') && is_numeric($_POST["{$var}_less"])) {
510
            $time = time() - (60 * 60 * 24 *  Request::getInt("{$var}_less", 0, 'POST'));
511
            if ($time > 0) {
512
                $criteria->add(new Criteria($var, $time, '>='));
513
            }
514
        }
515
    }
516
    if (Request::hasVar('posts_more', 'POST') && is_numeric($_POST['posts_more'])) {
517
        $criteria->add(new Criteria('posts',  Request::getInt('posts_more', 0, 'POST'), '<='));
518
    }
519
    if (Request::hasVar('posts_less', 'POST') && is_numeric($_POST['posts_less'])) {
520
        $criteria->add(new Criteria('posts', Request::getInt('posts_less', 0, 'POST'), '>='));
521
    }
522
    if (Request::hasVar('user_mailok', 'POST')) {
523
        if (Request::getString('user_mailok', '', 'POST') === 'mailng') {
524
            $criteria->add(new Criteria('user_mailok', 0));
525
        } elseif (Request::getString('user_mailok', '', 'POST') === 'mailok') {
526
            $criteria->add(new Criteria('user_mailok', 1));
527
        }
528
    }
529
    if (Request::hasVar('user_avatar', 'POST')) {
530
        if (Request::getString('user_avatar', '', 'POST') === 'y') {
531
            $criteria->add(new Criteria('user_avatar', "('', 'blank.gif')", 'NOT IN'));
532
        } elseif (Request::getString('user_avatar', '', 'POST') === 'n') {
533
            $criteria->add(new Criteria('user_avatar', "('', 'blank.gif')", 'IN'));
534
        }
535
    }
536
    if (Request::hasVar('level', 'POST')) {
537
//        $level_value = array(
538
//            1 => 1,
539
//            2 => 0,
540
//            3 => -1
541
//        );
542
        $level       = Request::getInt('level', 0, 'POST');
543
        if ($level > 0) {
544
            $criteria->add(new Criteria('level', $level));
545
        }
546
    }
547
    if (Request::hasVar('rank', 'POST')) {
548
        $rank_obj = $rank_handler->get(Request::getInt('rank', 0, 'POST'));
549
        if ($rank_obj->getVar('rank_special')) {
550
            $criteria->add(new Criteria('rank', Request::getInt('rank', 0, 'POST')));
551
        } else {
552
            if ($rank_obj->getVar('rank_min')) {
553
                $criteria->add(new Criteria('posts', $rank_obj->getVar('rank_min'), '>='));
554
            }
555
            if ($rank_obj->getVar('rank_max')) {
556
                $criteria->add(new Criteria('posts', $rank_obj->getVar('rank_max'), '<='));
557
            }
558
        }
559
    }
560
    $total     = $user_handler->getCount($criteria, @$_POST['groups']);
561
    $validsort = array(
562
        'uname',
563
        'email',
564
        'last_login',
565
        'user_regdate',
566
        'posts'
567
    );
568
    $sort      = (!in_array(Request::getString('user_sort', '', 'POST'), $validsort)) ? 'uname' : Request::getString('user_sort', '', 'POST');
569
    $order     = 'ASC';
570
    if (Request::hasVar('user_order', 'POST') && Request::getString('user_order', '', 'POST')  === 'DESC') {
571
        $order = 'DESC';
572
    }
573
    $criteria->setSort($sort);
574
    $criteria->setOrder($order);
575
    $criteria->setLimit($limit);
576
    $criteria->setStart($start);
577
    $foundusers = $user_handler->getAll($criteria, Request::getArray('groups', array(), 'POST'));
578
579
    echo $js_adduser = '
580
        <script type="text/javascript">
581
        var multiple=' . (string) $multiple . ';
582
        function addusers()
583
        {
584
            var sel_str = "";
585
            var num = 0;
586
            var mForm = document.forms["' . $name_form . '"];
587
            for (var i=0;i!=mForm.elements.length;i++) {
588
                var id=mForm.elements[i];
589
                if ( ( (multiple > 0 && id.type == "checkbox") || (multiple == 0 && id.type == "radio") ) && (id.checked == true) && ( id.name == "' . $name_userid . '" ) ) {
590
                    var name = mForm.elements[++i];
591
                    var len = id.value.length + name.value.length;
592
                    sel_str += len + ":" + id.value + ":" + name.value;
593
                    num ++;
594
                }
595
            }
596
            if (num == 0) {
597
                alert("' . _MA_USER_NOUSERSELECTED . '");
598
                return false;
599
            }
600
            sel_str = num + ":" + sel_str;
601
            window.opener.addusers(sel_str);
602
            alert("' . _MA_USER_USERADDED . '");
603
            if (multiple == 0) {
604
                window.close();
605
                window.opener.focus();
606
            }
607
            return true;
608
        }
609
        </script>
610
    ';
611
612
    echo '</html><body>';
613
    echo "<a href='findusers.php?target=" . htmlspecialchars(Request::getString('target', '', 'POST'), ENT_QUOTES) . '&amp;multiple=' . (string)$multiple . '&amp;token=' . htmlspecialchars($token, ENT_QUOTES) . "'>" . _MA_USER_FINDUS . "</a>&nbsp;<span style='font-weight:bold;'>&raquo;</span>&nbsp;" . _MA_USER_RESULTS . '<br><br>';
614
    if (empty($start) && empty($foundusers)) {
615
        echo '<h4>' . _MA_USER_NOFOUND, '</h4>';
616
        $hiddenform = "<form name='findnext' action='findusers.php' method='post'>";
617
        foreach ($_POST as $k => $v) {
618
            if ($k === 'XOOPS_TOKEN_REQUEST') {
619
                // regenerate token value
620
                $hiddenform .= $GLOBALS['xoopsSecurity']->getTokenHTML() . "\n";
621
            } elseif (is_array($v)) {
622
                foreach ($v as $temp) {
623
                    $hiddenform .= "<input type='hidden' name='". htmlspecialchars($k, ENT_QUOTES)."' value='" . htmlspecialchars($temp, ENT_QUOTES) . "' />\n";
624
                }
625
            } else {
626
                $hiddenform .= "<input type='hidden' name='" . htmlspecialchars($k, ENT_QUOTES) . "' value='" . htmlspecialchars($v, ENT_QUOTES) . "' />\n";
627
            }
628
        }
629
        if (!Request::hasVar('limit', 'POST')) {
630
            $hiddenform .= "<input type='hidden' name='limit' value='{$limit}' />\n";
631
        }
632
        if (!Request::hasVar('start', 'POST')) {
633
            $hiddenform .= "<input type='hidden' name='start' value='{$start}' />\n";
634
        }
635
        $hiddenform .= "<input type='hidden' name='token' value='" . htmlspecialchars($token, ENT_QUOTES) . "' />\n";
636
        $hiddenform .= '</form>';
637
638
        echo '<div>' . $hiddenform;
639
        echo "<a href='#' onclick='document.findnext.start.value=0;document.findnext.user_submit.value=0;document.findnext.submit();'>" . _MA_USER_SEARCHAGAIN . "</a>\n";
640
        echo '</div>';
641
    } elseif ($start < $total) {
642
        if (!empty($total)) {
643
            echo sprintf(_MA_USER_USERSFOUND, $total) . '<br>';
644
        }
645
        if (!empty($foundusers)) {
646
            echo "<form action='findusers.php' method='post' name='{$name_form}' id='{$name_form}'>
647
            <table width='100%' border='0' cellspacing='1' cellpadding='4' class='outer'>
648
            <tr>
649
            <th align='center' width='5px'>";
650
            if ($multiple > 0 ) {
651
                echo "<input type='checkbox' name='memberslist_checkall' id='memberslist_checkall' onclick='xoopsCheckAll(\"{$name_form}\", \"memberslist_checkall\");' />";
652
            }
653
            echo "</th>
654
            <th align='center'>" . _MA_USER_UNAME . "</th>
655
            <th align='center'>" . _MA_USER_REALNAME . "</th>
656
            <th align='center'>" . _MA_USER_REGDATE . "</th>
657
            <th align='center'>" . _MA_USER_LASTLOGIN . "</th>
658
            <th align='center'>" . _MA_USER_POSTS . '</th>
659
            </tr>';
660
            $ucount = 0;
661
            foreach (array_keys($foundusers) as $j) {
662
                $class = 'odd';
663
                if ($ucount % 2 == 0) {
664
                    $class = 'even';
665
                }
666
                ++$ucount;
667
                $fuser_name = $foundusers[$j]->getVar('name') ?: '&nbsp;';
668
                echo "<tr class='$class'>
669
                    <td align='center'>";
670
                if ($multiple > 0) {
671
                    echo "<input type='checkbox' name='{$name_userid}' id='{$name_userid}' value='" . $foundusers[$j]->getVar('uid') . "' />";
672
                    echo "<input type='hidden' name='{$name_username}' id='{$name_username}' value='" . $foundusers[$j]->getVar('uname') . "' />";
673
                } else {
674
                    echo "<input type='radio' name='{$name_userid}' id='{$name_userid}' value='" . $foundusers[$j]->getVar('uid') . "' />";
675
                    echo "<input type='hidden' name='{$name_username}' id='{$name_username}' value='" . $foundusers[$j]->getVar('uname') . "' />";
676
                }
677
                echo "</td>
678
                    <td><a href='" . XOOPS_URL . '/userinfo.php?uid=' . $foundusers[$j]->getVar('uid') . "' target='_blank'>" . $foundusers[$j]->getVar('uname') . '</a></td>
679
                    <td>' . $fuser_name . "</td>
680
                    <td align='center'>" . ($foundusers[$j]->getVar('user_regdate') ? date('Y-m-d', $foundusers[$j]->getVar('user_regdate')) : '') . "</td>
681
                    <td align='center'>" . ($foundusers[$j]->getVar('last_login') ? date('Y-m-d H:i', $foundusers[$j]->getVar('last_login')) : '') . "</td>
682
                    <td align='center'>" . $foundusers[$j]->getVar('posts') . '</td>';
683
                echo "</tr>\n";
684
            }
685
            echo "<tr class='foot'><td colspan='6'>";
686
687
            // placeholder for external applications
688
            if (!Request::hasVar('target', 'POST')) {
689
                echo "<select name='fct'><option value='users'>" . _DELETE . "</option><option value='mailusers'>" . _MA_USER_SENDMAIL . '</option>';
690
                echo '</select>&nbsp;';
691
                echo $GLOBALS['xoopsSecurity']->getTokenHTML() . "<input type='submit' value='" . _SUBMIT . "' />";
692
693
                // Add selected users
694
            } else {
695
                echo "<input type='button' value='" . _MA_USER_ADD_SELECTED . "' onclick='addusers();' />";
696
            }
697
            echo "<input type='hidden' name='token' value='" . htmlspecialchars($token, ENT_QUOTES) . "' />\n";
698
            echo "</td></tr></table></form>\n";
699
        }
700
701
        $hiddenform = "<form name='findnext' action='findusers.php' method='post'>";
702
        foreach ($_POST as $k => $v) {
703
            if ($k === 'XOOPS_TOKEN_REQUEST') {
704
                // regenerate token value
705
                $hiddenform .= $GLOBALS['xoopsSecurity']->getTokenHTML() . "\n";
706
            } elseif (is_array($v)) {
707
                foreach ($v as $temp) {
708
                    $hiddenform .= "<input type='hidden' name='". htmlspecialchars($k, ENT_QUOTES)."' value='" . htmlspecialchars($temp, ENT_QUOTES) . "' />\n";
709
                }
710
            } else {
711
712
                $hiddenform .= "<input type='hidden' name='" . htmlspecialchars($k, ENT_QUOTES) . "' value='" . htmlspecialchars($myts->stripSlashesGPC($v), ENT_QUOTES) . "' />\n";
0 ignored issues
show
Deprecated Code introduced by
The function MyTextSanitizer::stripSlashesGPC() has been deprecated: as of XOOPS 2.5.11 and will be removed in next XOOPS version ( Ignorable by Annotation )

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

712
                $hiddenform .= "<input type='hidden' name='" . htmlspecialchars($k, ENT_QUOTES) . "' value='" . htmlspecialchars(/** @scrutinizer ignore-deprecated */ $myts->stripSlashesGPC($v), ENT_QUOTES) . "' />\n";

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
713
            }
714
        }
715
        if (!Request::hasVar('limit', 'POST')) {
716
            $hiddenform .= "<input type='hidden' name='limit' value='" . $limit . "' />\n";
717
        }
718
        if (!Request::hasVar('start', 'POST')) {
719
            $hiddenform .= "<input type='hidden' name='start' value='" . $start . "' />\n";
720
        }
721
        $hiddenform .= "<input type='hidden' name='token' value='" . htmlspecialchars($token, ENT_QUOTES) . "' />\n";
722
        if (!isset($total) || ($totalpages = ceil($total / $limit)) > 1) {
723
            $prev = $start - $limit;
724
            if ($start - $limit >= 0) {
725
                $hiddenform .= "<a href='#0' onclick='document.findnext.start.value=" . $prev . ";document.findnext.submit();'>" . _MA_USER_PREVIOUS . "</a>&nbsp;\n";
726
            }
727
            $counter     = 1;
728
            $currentpage = ($start + $limit) / $limit;
729
            if (!isset($total)) {
730
                while ($counter <= $currentpage) {
731
                    if ($counter == $currentpage) {
732
                        $hiddenform .= '<strong>' . $counter . '</strong> ';
733
                    } elseif (($counter > $currentpage - 4 && $counter < $currentpage + 4) || $counter == 1) {
734
                        $hiddenform .= "<a href='#" . $counter . "' onclick='document.findnext.start.value=" . ($counter - 1) * $limit . ";document.findnext.submit();'>" . $counter . '</a> ';
735
                        if ($counter == 1 && $currentpage > 5) {
736
                            $hiddenform .= '... ';
737
                        }
738
                    }
739
                    ++$counter;
740
                }
741
            } else {
742
                while ($counter <= $totalpages) {
743
                    if ($counter == $currentpage) {
744
                        $hiddenform .= '<strong>' . $counter . '</strong> ';
745
                    } elseif (($counter > $currentpage - 4 && $counter < $currentpage + 4) || $counter == 1 || $counter == $totalpages) {
746
                        if ($counter == $totalpages && $currentpage < $totalpages - 4) {
747
                            $hiddenform .= '... ';
748
                        }
749
                        $hiddenform .= "<a href='#" . $counter . "' onclick='document.findnext.start.value=" . ($counter - 1) * $limit . ";document.findnext.submit();'>" . $counter . '</a> ';
750
                        if ($counter == 1 && $currentpage > 5) {
751
                            $hiddenform .= '... ';
752
                        }
753
                    }
754
                    ++$counter;
755
                }
756
            }
757
758
            $next = $start + $limit;
759
            if ((isset($total) && $total > $next) || (!isset($total) && count($foundusers) >= $limit)) {
760
                $hiddenform .= "&nbsp;<a href='#" . $total . "' onclick='document.findnext.start.value=" . $next . ";document.findnext.submit();'>" . _MA_USER_NEXT . "</a>\n";
761
            }
762
        }
763
        $hiddenform .= '</form>';
764
765
        echo '<div>' . $hiddenform;
766
        if (isset($total)) {
767
            echo '<br>' . sprintf(_MA_USER_USERSFOUND, $total) . '&nbsp;';
768
        }
769
        echo "<a href='#' onclick='document.findnext.start.value=0;document.findnext.user_submit.value=0;document.findnext.submit();'>" . _MA_USER_SEARCHAGAIN . "</a>\n";
770
        echo '</div>';
771
    }
772
}
773
774
xoops_footer();
775