XoUser::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 13
rs 9.9332
c 0
b 0
f 0
cc 2
nc 2
nop 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-2025 XOOPS Project (https://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;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, Request. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
21
22
include_once dirname(__DIR__) . '/mainfile.php';
23
24
xoops_header(false);
25
26
$denied = true;
27
if (Request::hasVar('token') && is_object($xoopsUser)) {
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
35
if ($denied) {
36
    xoops_error(_NOPERM);
37
    exit();
38
}
39
40
$token         = Request::getString('token', '');
41
$name_form     = 'memberslist';
42
$multiple = Request::getInt('multiple', 0);
43
$name_userid   = 'uid' . ((0 != $multiple) ? '[]' : '');
44
$name_username = 'uname' . ((0 != $multiple) ? '[]' : '');
45
46
xoops_loadLanguage('findusers');
47
48
/**
49
 * Enter description here...
50
 *
51
 */
52
class XoopsRank extends XoopsObject
53
{
54
    //PHP 8.2 Dynamic properties deprecated
55
    public $rank_id;
56
    public $rank_title;
57
    public $rank_min;
58
    public $rank_max;
59
    public $rank_special;
60
    public $rank_image;
61
62
    /**
63
     * Construct
64
     *
65
     */
66
    public function __construct()
67
    {
68
        parent::__construct();
69
        $this->initVar('rank_id', XOBJ_DTYPE_INT, null, false);
70
        $this->initVar('rank_title', XOBJ_DTYPE_TXTBOX, null, false);
71
        $this->initVar('rank_min', XOBJ_DTYPE_INT, 0);
72
        $this->initVar('rank_max', XOBJ_DTYPE_INT, 0);
73
        $this->initVar('rank_special', XOBJ_DTYPE_INT, 0);
74
        $this->initVar('rank_image', XOBJ_DTYPE_TXTBOX, '');
75
    }
76
}
77
78
/**
79
 * Xoops Rank Handler
80
 *
81
 */
82
class XoopsRankHandler extends XoopsObjectHandler
83
{
84
    /**
85
     * Constructor
86
     *
87
     * @param XoopsDatabase $db
88
     */
89
    public function __construct(XoopsDatabase $db)
90
    {
91
        parent::__construct($db);
92
    }
93
94
    /**
95
     * Create Object
96
     *
97
     * @param  bool $isNew
98
     * @return XoopsRank
99
     */
100
    public function create($isNew = true)
101
    {
102
        $obj = new XoopsRank();
103
        if ($isNew === true) {
104
            $obj->setNew();
105
        }
106
107
        return $obj;
108
    }
109
110
    /**
111
     * Get Object
112
     *
113
     * @param  int $id
114
     * @return object
115
     */
116
    public function get($id = 0)
117
    {
118
        $object = $this->create(false);
119
        $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

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

120
        /** @scrutinizer ignore-call */ 
121
        $result = $this->db->query($sql);
Loading history...
121
        if (!$this->db->isResultSet($result)) {
122
            $ret = null;
123
124
            return $ret;
125
        }
126
127
        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

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

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

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