search.inc.php ➔ equipment_search()   B
last analyzed

Complexity

Conditions 6
Paths 8

Size

Total Lines 31
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
eloc 20
nc 8
nop 5
dl 0
loc 31
rs 8.439
c 0
b 0
f 0
1
<?php
2
3
/*
4
 You may not change or alter any portion of this comment or credits
5
 of supporting developers from this source code or any supporting source code
6
 which is considered copyrighted (c) material of the original comment or credit authors.
7
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
/**
13
 * Module: Equipment
14
 *
15
 * @category        Module
16
 * @package         equipment
17
 * @author          XOOPS Development Team <[email protected]> - <http://xoops.org>
18
 * @copyright       {@link https://xoops.org/ XOOPS Project}
19
 * @license         GPL 2.0 or later
20
 * @link            https://xoops.org/
21
 * @since           1.0.0
22
 */
23
/**
24
 *  equipment_search
25
 *
26
 * @param $queryarray
27
 * @param $andor
28
 * @param $limit
29
 * @param $offset
30
 * @param $userid
31
 * @return array|bool
32
 */
33
function equipment_search($queryarray, $andor, $limit, $offset, $userid)
34
{
35
    $sql = 'SELECT id, last FROM ' . $GLOBALS['xoopsDB']->prefix('equipment_customer') . ' WHERE _online = 1';
36
37
    if ($userid !== 0) {
38
        $sql .= ' AND _submitter=' . (int)$userid;
39
    }
40
41
    if (is_array($queryarray) && $count = count($queryarray)) {
42
        $sql .= ' AND ((address LIKE ' % $queryarray[0] % ' OR city LIKE ' % $queryarray[0] % ' OR country LIKE ' % $queryarray[0] % ')';
43
44
        for ($i = 1; $i < $count; ++$i) {
45
            $sql .= " $andor ";
46
            $sql .= '(address LIKE ' % $queryarray[$i] % ' OR city LIKE ' % $queryarray[$i] % ' OR country LIKE ' % $queryarray[0] % ')';
47
        }
48
        $sql .= ')';
49
    }
50
51
    $sql    .= ' ORDER BY id DESC';
52
    $result = $GLOBALS['xoopsDB']->query($sql, $limit, $offset);
53
    $ret    = array();
54
    $i      = 0;
55
    while (false !== ($myrow = $GLOBALS['xoopsDB']->fetchArray($result))) {
56
        $ret[$i]['image'] = 'assets/images/icons/32/_search.png';
57
        $ret[$i]['link']  = 'customer.php?id=' . $myrow['id'];
58
        $ret[$i]['title'] = $myrow['last'];
59
        ++$i;
60
    }
61
62
    return $ret;
63
}
64