Passed
Pull Request — master (#1301)
by Michael
05:46
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
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
eloc 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
            //    \trigger_error("Query Failed! SQL: $sql- Error: " . $this->db->error(), E_USER_ERROR);
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 = array();
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) && is_subclass_of($criteria, 'CriteriaElement')) {
151
            $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

151
            $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...
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
            //   \trigger_error("Query Failed! SQL: $sql- Error: " . $this->db->error(), E_USER_ERROR);
161
            return $ret;
162
        }
163
        $myts = \MyTextSanitizer::getInstance();
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 = array(
186
            'actkey',
187
            'pass',
188
            'theme',
189
            'umode',
190
            'uorder',
191
            'notify_mode');
192
        foreach ($unsets as $var) {
193
            unset($this->vars[$var]);
194
        }
195
    }
196
}
197
198
/**
199
 * XoUser Handler
200
 *
201
 */
202
class XoUserHandler extends XoopsObjectHandler
203
{
204
    /**
205
     * Enter description here...
206
     *
207
     * @param XoopsDatabase $db
208
     */
209
    public function __construct(XoopsDatabase $db)
210
    {
211
        parent::__construct($db);
212
    }
213
214
    /**
215
     * Create
216
     *
217
     * @param  bool $isNew
218
     * @return XoUser
219
     */
220
    public function create($isNew = true)
221
    {
222
        $obj = new XoUser();
223
        if ($isNew === true) {
224
            $obj->setNew();
225
        }
226
227
        return $obj;
228
    }
229
230
    /**
231
     * Get Count
232
     *
233
     * @param  CriteriaElement $criteria
234
     * @param  array           $groups
235
     * @return int
236
     */
237
    public function getCount(CriteriaElement $criteria = null, $groups = array())
238
    {
239
        if (!is_array($groups)) {
0 ignored issues
show
introduced by
The condition is_array($groups) is always true.
Loading history...
240
            $groups = array(
241
                $groups);
242
        }
243
        $groups = array_filter($groups);
244
        if (empty($groups)) {
245
            $sql = '    SELECT COUNT(DISTINCT u.uid) FROM ' . $this->db->prefix('users') . ' AS u' . '    WHERE 1=1';
246
        } else {
247
            $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)) . ')';
248
        }
249
        if (isset($criteria) && is_subclass_of($criteria, 'CriteriaElement')) {
250
            // Use the direct renderer, assuming no `uid` in criteria
251
            if ($render = $criteria->render()) {
252
                $sql .= ' AND ' . $render;
253
            }
254
        }
255
        $result = $this->db->query($sql);
256
        if (!$this->db->isResultSet($result)) {
257
            \trigger_error("Query Failed! SQL: $sql- Error: " . $this->db->error(), E_USER_ERROR);
0 ignored issues
show
Bug introduced by
The method error() does not exist on XoopsDatabase. Since it exists in all sub-types, consider adding an abstract or default implementation to XoopsDatabase. ( Ignorable by Annotation )

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

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

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