Passed
Push — master ( 05faca...9c86bf )
by Richard
08:39 queued 13s
created

XoUserHandler::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 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
            $ret = null;
122
123
            return $ret;
124
        }
125
126
        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

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

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

256
                \sprintf(_DB_QUERY_ERROR, $sql) . $this->db->/** @scrutinizer ignore-call */ error(), E_USER_ERROR
Loading history...
257
            );
258
        }
259
        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

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

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