2015-04-02 18:05:24 +01:00
< ? php
2015-07-13 20:10:26 +02:00
$where = '1' ;
2015-04-02 18:05:24 +01:00
$param = array ();
2019-12-30 12:11:26 +01:00
if ( ! Auth :: user () -> hasGlobalRead ()) {
$device_ids = Permissions :: devicesForUser () -> toArray () ? : [ 0 ];
$where .= " AND `D`.`device_id` IN " . dbGenPlaceholders ( count ( $device_ids ));
$param = array_merge ( $param , $device_ids );
2015-04-02 18:05:24 +01:00
}
2019-12-30 12:11:26 +01:00
$sql = " FROM entPhysical AS E, devices AS D WHERE $where AND D.device_id = E.device_id " ;
2015-04-02 18:05:24 +01:00
if ( isset ( $searchPhrase ) && ! empty ( $searchPhrase )) {
2020-07-10 16:17:09 +02:00
$sql .= " AND (`D`.`hostname` LIKE ? OR `E`.`entPhysicalDescr` LIKE ? OR `E`.`entPhysicalModelName` LIKE ? OR `E`.`entPhysicalSerialNum` LIKE ?) " ;
$param [] = " % $searchPhrase % " ;
$param [] = " % $searchPhrase % " ;
$param [] = " % $searchPhrase % " ;
$param [] = " % $searchPhrase % " ;
2015-04-02 18:05:24 +01:00
}
2018-03-25 22:50:09 +02:00
if ( isset ( $vars [ 'string' ]) && strlen ( $vars [ 'string' ])) {
2015-07-13 20:10:26 +02:00
$sql .= ' AND E.entPhysicalDescr LIKE ?' ;
2018-03-25 22:50:09 +02:00
$param [] = '%' . $vars [ 'string' ] . '%' ;
2015-04-02 18:05:24 +01:00
}
2018-03-25 22:50:09 +02:00
if ( isset ( $vars [ 'device_string' ]) && strlen ( $vars [ 'device_string' ])) {
2015-07-13 20:10:26 +02:00
$sql .= ' AND D.hostname LIKE ?' ;
2018-03-25 22:50:09 +02:00
$param [] = '%' . $vars [ 'device_string' ] . '%' ;
2015-04-02 18:05:24 +01:00
}
2018-03-25 22:50:09 +02:00
if ( isset ( $vars [ 'part' ]) && strlen ( $vars [ 'part' ])) {
2015-07-13 20:10:26 +02:00
$sql .= ' AND E.entPhysicalModelName = ?' ;
2018-03-25 22:50:09 +02:00
$param [] = $vars [ 'part' ];
2015-04-02 18:05:24 +01:00
}
2018-03-25 22:50:09 +02:00
if ( isset ( $vars [ 'serial' ]) && strlen ( $vars [ 'serial' ])) {
2015-07-13 20:10:26 +02:00
$sql .= ' AND E.entPhysicalSerialNum LIKE ?' ;
2018-03-25 22:50:09 +02:00
$param [] = '%' . $vars [ 'serial' ] . '%' ;
2015-04-02 18:05:24 +01:00
}
2018-03-25 22:50:09 +02:00
if ( isset ( $vars [ 'device' ]) && is_numeric ( $vars [ 'device' ])) {
2015-07-13 20:10:26 +02:00
$sql .= ' AND D.device_id = ?' ;
2018-03-25 22:50:09 +02:00
$param [] = $vars [ 'device' ];
2015-04-02 18:05:24 +01:00
}
$count_sql = " SELECT COUNT(`entPhysical_id`) $sql " ;
2015-07-13 20:10:26 +02:00
$total = dbFetchCell ( $count_sql , $param );
2015-04-12 11:47:21 +01:00
if ( empty ( $total )) {
$total = 0 ;
}
2015-04-02 18:05:24 +01:00
if ( ! isset ( $sort ) || empty ( $sort )) {
$sort = '`hostname` DESC' ;
}
$sql .= " ORDER BY $sort " ;
if ( isset ( $current )) {
2015-07-13 20:10:26 +02:00
$limit_low = (( $current * $rowCount ) - ( $rowCount ));
2015-04-02 18:05:24 +01:00
$limit_high = $rowCount ;
}
if ( $rowCount != - 1 ) {
$sql .= " LIMIT $limit_low , $limit_high " ;
}
2020-05-05 01:59:44 +02:00
$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 " ;
2015-04-02 18:05:24 +01:00
foreach ( dbFetchRows ( $sql , $param ) as $invent ) {
2015-07-13 20:10:26 +02:00
$response [] = array (
2020-02-10 12:07:27 +01:00
'hostname' => generate_device_link ( $invent ),
2015-07-13 20:10:26 +02:00
'description' => $invent [ 'description' ],
'name' => $invent [ 'name' ],
'model' => $invent [ 'model' ],
'serial' => $invent [ 'serial' ],
);
2015-04-02 18:05:24 +01:00
}
2015-07-13 20:10:26 +02:00
$output = array (
'current' => $current ,
'rowCount' => $rowCount ,
'rows' => $response ,
'total' => $total ,
);
2015-04-02 18:05:24 +01:00
echo _json_encode ( $output );