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 ();
if ( $_SESSION [ 'userlevel' ] >= '5' ) {
$sql = " FROM entPhysical AS E, devices AS D WHERE $where AND D.device_id = E.device_id " ;
2015-07-13 20:10:26 +02:00
}
else {
$sql = " FROM entPhysical AS E, devices AS D, devices_perms AS P WHERE $where AND D.device_id = E.device_id AND P.device_id = D.device_id AND P.user_id = ? " ;
2015-04-02 18:05:24 +01:00
$param [] = $_SESSION [ 'user_id' ];
}
if ( isset ( $searchPhrase ) && ! empty ( $searchPhrase )) {
$sql .= " AND (`D`.`hostname` LIKE '% $searchPhrase %' OR `E`.`entPhysicalDescr` LIKE '% $searchPhrase %' OR `E`.`entPhysicalModelName` LIKE '% $searchPhrase %' OR `E`.`entPhysicalSerialNum` LIKE '% $searchPhrase %') " ;
}
if ( isset ( $_POST [ 'string' ]) && strlen ( $_POST [ 'string' ])) {
2015-07-13 20:10:26 +02:00
$sql .= ' AND E.entPhysicalDescr LIKE ?' ;
$param [] = '%' . $_POST [ 'string' ] . '%' ;
2015-04-02 18:05:24 +01:00
}
if ( isset ( $_POST [ 'device_string' ]) && strlen ( $_POST [ 'device_string' ])) {
2015-07-13 20:10:26 +02:00
$sql .= ' AND D.hostname LIKE ?' ;
$param [] = '%' . $_POST [ 'device_string' ] . '%' ;
2015-04-02 18:05:24 +01:00
}
if ( isset ( $_POST [ 'part' ]) && strlen ( $_POST [ 'part' ])) {
2015-07-13 20:10:26 +02:00
$sql .= ' AND E.entPhysicalModelName = ?' ;
$param [] = $_POST [ 'part' ];
2015-04-02 18:05:24 +01:00
}
if ( isset ( $_POST [ 'serial' ]) && strlen ( $_POST [ 'serial' ])) {
2015-07-13 20:10:26 +02:00
$sql .= ' AND E.entPhysicalSerialNum LIKE ?' ;
$param [] = '%' . $_POST [ 'serial' ] . '%' ;
2015-04-02 18:05:24 +01:00
}
if ( isset ( $_POST [ 'device' ]) && is_numeric ( $_POST [ 'device' ])) {
2015-07-13 20:10:26 +02:00
$sql .= ' AND D.device_id = ?' ;
$param [] = $_POST [ '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 " ;
}
$sql = " SELECT `D`.`device_id` AS `device_id`, `D`.`hostname` AS `hostname`,`entPhysicalDescr` AS `description`, `entPhysicalName` AS `name`, `entPhysicalModelName` AS `model`, `entPhysicalSerialNum` AS `serial` $sql " ;
foreach ( dbFetchRows ( $sql , $param ) as $invent ) {
2015-07-13 20:10:26 +02:00
$response [] = array (
'hostname' => generate_device_link ( $invent , shortHost ( $invent [ 'hostname' ])),
'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 );