Passed
Pull Request — master (#1301)
by Michael
05:44
created

XoUserHandler   A

Complexity

Total Complexity 20

Size/Duplication

Total Lines 114
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 54
dl 0
loc 114
rs 10
c 0
b 0
f 0
wmc 20

4 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 8 2
B getCount() 0 27 7
B getAll() 0 43 10
A __construct() 0 3 1
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
    //PHP 8.2 Dynamic properties deprecated
54
    public $rank_id;
55
    public $rank_title;
56
    public $rank_min;
57
    public $rank_max;
58
    public $rank_special;
59
    public $rank_image;
60
    
61
    /**
62
     * Construct
63
     *
64
     */
65
    public function __construct()
66
    {
67
        parent::__construct();
68
        $this->initVar('rank_id', XOBJ_DTYPE_INT, null, false);
69
        $this->initVar('rank_title', XOBJ_DTYPE_TXTBOX, null, false);
70
        $this->initVar('rank_min', XOBJ_DTYPE_INT, 0);
71
        $this->initVar('rank_max', XOBJ_DTYPE_INT, 0);
72
        $this->initVar('rank_special', XOBJ_DTYPE_INT, 0);
73
        $this->initVar('rank_image', XOBJ_DTYPE_TXTBOX, '');
74
    }
75
}
76
77
/**
78
 * Xoops Rank Handler
79
 *
80
 */
81
class XoopsRankHandler extends XoopsObjectHandler
82
{
83
    /**
84
     * Constructor
85
     *
86
     * @param XoopsDatabase $db
87
     */
88
    public function __construct(XoopsDatabase $db)
89
    {
90
        parent::__construct($db);
91
    }
92
93
    /**
94
     * Create Object
95
     *
96
     * @param  bool $isNew
97
     * @return XoopsRank
98
     */
99
    public function create($isNew = true)
100
    {
101
        $obj = new XoopsRank();
102
        if ($isNew === true) {
103
            $obj->setNew();
104
        }
105
106
        return $obj;
107
    }
108
109
    /**
110
     * Get Object
111
     *
112
     * @param  int $id
113
     * @return object
114
     */
115
    public function get($id = 0)
116
    {
117
        $object = $this->create(false);
118
        $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

118
        $sql    = 'SELECT * FROM ' . $this->db->prefix('ranks') . ' WHERE rank_id = ' . $this->db->/** @scrutinizer ignore-call */ quoteString($id);
Loading history...
119
        $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

119
        /** @scrutinizer ignore-call */ 
120
        $result = $this->db->query($sql);
Loading history...
120
        if (!$this->db->isResultSet($result)) {
121
            //       // throw new \RuntimeException(
122
            //       \sprintf(_DB_QUERY_ERROR, $sql) . $this->db->error(), E_USER_ERROR
123
            // );
124
            $ret = null;
125
126
            return $ret;
127
        }
128
129
        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

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

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

262
                \sprintf(_DB_QUERY_ERROR, $sql) . $this->db->/** @scrutinizer ignore-call */ error(), E_USER_ERROR
Loading history...
263
            );
264
        }
265
        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

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

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