1 | <?php |
||||
2 | |||||
3 | $where = '1'; |
||||
4 | $param = []; |
||||
5 | |||||
6 | if (! Auth::user()->hasGlobalRead()) { |
||||
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||
7 | $device_ids = Permissions::devicesForUser()->toArray() ?: [0]; |
||||
0 ignored issues
–
show
The method
devicesForUser() does not exist on App\Facades\Permissions . Since you implemented __callStatic , consider adding a @method annotation.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
8 | $where .= ' AND `D`.`device_id` IN ' . dbGenPlaceholders(count($device_ids)); |
||||
9 | $param = array_merge($param, $device_ids); |
||||
10 | } |
||||
11 | |||||
12 | $sql = " FROM entPhysical AS E, devices AS D WHERE $where AND D.device_id = E.device_id"; |
||||
13 | |||||
14 | if (isset($searchPhrase) && ! empty($searchPhrase)) { |
||||
15 | $sql .= ' AND (`D`.`hostname` LIKE ? OR `E`.`entPhysicalDescr` LIKE ? OR `E`.`entPhysicalModelName` LIKE ? OR `E`.`entPhysicalSerialNum` LIKE ?)'; |
||||
16 | $param[] = "%$searchPhrase%"; |
||||
17 | $param[] = "%$searchPhrase%"; |
||||
18 | $param[] = "%$searchPhrase%"; |
||||
19 | $param[] = "%$searchPhrase%"; |
||||
20 | } |
||||
21 | |||||
22 | if (isset($vars['string']) && strlen($vars['string'])) { |
||||
23 | $sql .= ' AND E.entPhysicalDescr LIKE ?'; |
||||
24 | $param[] = '%' . $vars['string'] . '%'; |
||||
25 | } |
||||
26 | |||||
27 | if (isset($vars['device_string']) && strlen($vars['device_string'])) { |
||||
28 | $sql .= ' AND D.hostname LIKE ?'; |
||||
29 | $param[] = '%' . $vars['device_string'] . '%'; |
||||
30 | } |
||||
31 | |||||
32 | if (isset($vars['part']) && strlen($vars['part'])) { |
||||
33 | $sql .= ' AND E.entPhysicalModelName = ?'; |
||||
34 | $param[] = $vars['part']; |
||||
35 | } |
||||
36 | |||||
37 | if (isset($vars['serial']) && strlen($vars['serial'])) { |
||||
38 | $sql .= ' AND E.entPhysicalSerialNum LIKE ?'; |
||||
39 | $param[] = '%' . $vars['serial'] . '%'; |
||||
40 | } |
||||
41 | |||||
42 | if (isset($vars['device']) && is_numeric($vars['device'])) { |
||||
43 | $sql .= ' AND D.device_id = ?'; |
||||
44 | $param[] = $vars['device']; |
||||
45 | } |
||||
46 | |||||
47 | $count_sql = "SELECT COUNT(`entPhysical_id`) $sql"; |
||||
48 | $total = dbFetchCell($count_sql, $param); |
||||
49 | if (empty($total)) { |
||||
50 | $total = 0; |
||||
51 | } |
||||
52 | |||||
53 | if (! isset($sort) || empty($sort)) { |
||||
54 | $sort = '`hostname` DESC'; |
||||
55 | } |
||||
56 | |||||
57 | $sql .= " ORDER BY $sort"; |
||||
58 | |||||
59 | if (isset($current)) { |
||||
60 | $limit_low = (($current * $rowCount) - ($rowCount)); |
||||
61 | $limit_high = $rowCount; |
||||
62 | } |
||||
63 | |||||
64 | if ($rowCount != -1) { |
||||
65 | $sql .= " LIMIT $limit_low,$limit_high"; |
||||
66 | } |
||||
67 | |||||
68 | $sql = "SELECT `D`.`device_id` AS `device_id`, `D`.`os` AS `os`, `D`.`hostname` AS `hostname`, `D`.`sysName` AS `sysName`,`entPhysicalDescr` AS `description`, `entPhysicalName` AS `name`, `entPhysicalModelName` AS `model`, `entPhysicalSerialNum` AS `serial` $sql"; |
||||
69 | |||||
70 | foreach (dbFetchRows($sql, $param) as $invent) { |
||||
71 | $response[] = [ |
||||
72 | 'hostname' => generate_device_link($invent), |
||||
73 | 'description' => $invent['description'], |
||||
74 | 'name' => $invent['name'], |
||||
75 | 'model' => $invent['model'], |
||||
76 | 'serial' => $invent['serial'], |
||||
77 | ]; |
||||
78 | } |
||||
79 | |||||
80 | $output = [ |
||||
81 | 'current' => $current, |
||||
82 | 'rowCount' => $rowCount, |
||||
83 | 'rows' => $response, |
||||
84 | 'total' => $total, |
||||
85 | ]; |
||||
86 | echo json_encode($output, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); |
||||
87 |