Passed
Pull Request — master (#1270)
by Michael
05:10
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);
114
            $ret = null;
115
116
            return $ret;
117
        }
118
119
        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

119
        while (false !== ($row = $this->db->/** @scrutinizer ignore-call */ fetchArray($result))) {
Loading history...
120
            $object->assignVars($row);
121
        }
122
123
        return $object;
124
    }
125
126
    /**
127
     * Get List
128
     *
129
     * @param  CriteriaElement $criteria
130
     * @param  int             $limit
131
     * @param  int             $start
132
     * @return array
133
     */
134
    public function getList(CriteriaElement $criteria = null, $limit = 0, $start = 0)
135
    {
136
        $ret = array();
137
        if ($criteria == null) {
138
            $criteria = new CriteriaCompo();
139
        }
140
141
        $sql = 'SELECT rank_id, rank_title FROM ' . $this->db->prefix('ranks');
142
        if (isset($criteria) && is_subclass_of($criteria, 'CriteriaElement')) {
143
            $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

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

249
            \trigger_error("Query Failed! SQL: $sql- Error: " . $this->db->/** @scrutinizer ignore-call */ error(), E_USER_ERROR);
Loading history...
250
        }
251
        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

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

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