2014-01-13 10:05:19 +00:00
< ? php
2020-09-21 14:54:51 +02:00
$init_modules = [ 'web' , 'auth' ];
2016-11-21 14:12:59 -06:00
require realpath ( __DIR__ . '/..' ) . '/includes/init.php' ;
2015-07-13 20:10:26 +02:00
2020-09-21 14:54:51 +02:00
if ( ! Auth :: check ()) {
exit ( 'Unauthorized' );
2015-07-13 20:10:26 +02:00
}
2014-01-13 10:05:19 +00:00
2019-04-11 23:26:42 -05:00
set_debug ( $_REQUEST [ 'debug' ]);
2020-09-21 14:54:51 +02:00
$device = [];
$ports = [];
$bgp = [];
$limit = ( int ) \LibreNMS\Config :: get ( 'webui.global_search_result_limit' );
2015-07-13 20:10:26 +02:00
if ( isset ( $_REQUEST [ 'search' ])) {
$search = mres ( $_REQUEST [ 'search' ]);
2016-02-04 18:16:36 -08:00
header ( 'Content-type: application/json' );
2015-07-13 20:10:26 +02:00
if ( strlen ( $search ) > 0 ) {
$found = 0 ;
2020-09-21 14:54:51 +02:00
if ( ! Auth :: user () -> hasGlobalRead ()) {
2019-12-30 12:11:26 +01:00
$device_ids = Permissions :: devicesForUser () -> toArray () ? : [ 0 ];
2020-10-21 23:15:47 +02:00
$perms_sql = '`D`.`device_id` IN ' . dbGenPlaceholders ( count ( $device_ids )) . ' AND ' ;
2019-12-30 12:11:26 +01:00
} else {
$device_ids = [];
2020-10-21 23:15:47 +02:00
$perms_sql = '' ;
2019-12-30 12:11:26 +01:00
}
2015-07-13 20:10:26 +02:00
if ( $_REQUEST [ 'type' ] == 'group' ) {
2020-09-21 15:59:34 +02:00
foreach ( dbFetchRows ( 'SELECT id,name FROM device_groups WHERE name LIKE ?' , [ " % $search % " ]) as $group ) {
2015-07-13 20:10:26 +02:00
if ( $_REQUEST [ 'map' ]) {
2020-09-21 14:54:51 +02:00
$results [] = [
'name' => 'g:' . $group [ 'name' ],
2015-07-13 20:10:26 +02:00
'group_id' => $group [ 'id' ],
2020-09-21 14:54:51 +02:00
];
2016-08-18 20:28:22 -05:00
} else {
2020-09-21 14:54:51 +02:00
$results [] = [ 'name' => $group [ 'name' ]];
2015-07-13 20:10:26 +02:00
}
}
2020-09-21 14:54:51 +02:00
exit ( json_encode ( $results ));
2016-08-18 20:28:22 -05:00
} elseif ( $_REQUEST [ 'type' ] == 'alert-rules' ) {
2020-09-21 15:59:34 +02:00
foreach ( dbFetchRows ( 'SELECT name FROM alert_rules WHERE name LIKE ?' , [ " % $search % " ]) as $rules ) {
2020-09-21 14:54:51 +02:00
$results [] = [ 'name' => $rules [ 'name' ]];
2015-07-13 20:10:26 +02:00
}
2014-03-18 22:36:22 +00:00
2020-09-21 14:54:51 +02:00
exit ( json_encode ( $results ));
2016-08-18 20:28:22 -05:00
} elseif ( $_REQUEST [ 'type' ] == 'device' ) {
2015-07-13 20:10:26 +02:00
// Device search
2020-03-11 14:54:11 +01:00
2020-09-21 15:59:34 +02:00
$query = ' SELECT * , `D` . `device_id` AS `device_id` FROM `devices` as `D`
LEFT JOIN `locations` AS `L` ON `L` . `id` = `D` . `location_id` ' ;
2020-03-11 14:54:11 +01:00
// user depending limitation
if ( ! Auth :: user () -> hasGlobalRead ()) {
$query_args_list = $device_ids ;
$query_filter = $perms_sql ;
2016-08-18 20:28:22 -05:00
} else {
2020-03-11 14:54:11 +01:00
$query_args_list = [];
$query_filter = '' ;
}
// search filter
2020-10-21 23:15:47 +02:00
$query_filter .= ' ( `D` . `hostname` LIKE ?
2020-03-11 14:54:11 +01:00
OR `L` . `location` LIKE ?
OR `D` . `sysName` LIKE ?
OR `D` . `purpose` LIKE ?
2020-09-21 15:59:34 +02:00
OR `D` . `notes` LIKE ? ' ;
2020-03-11 14:54:11 +01:00
$query_args_list = array_merge ( $query_args_list , [ " % $search % " , " % $search % " , " % $search % " ,
2020-09-21 14:54:51 +02:00
" % $search % " , " % $search % " , ]);
2020-03-11 14:54:11 +01:00
if ( \LibreNMS\Util\IPv4 :: isValid ( $search , false )) {
2020-09-21 15:59:34 +02:00
$query .= ' LEFT JOIN `ports` AS `P` ON `P` . `device_id` = `D` . `device_id`
LEFT JOIN `ipv4_addresses` AS `V4` ON `V4` . `port_id` = `P` . `port_id` ' ;
$query_filter .= ' OR `V4` . `ipv4_address` LIKE ?
2020-03-11 14:54:11 +01:00
OR `D` . `overwrite_ip` LIKE ?
2020-09-21 15:59:34 +02:00
OR `D` . `ip` = ? ' ;
2020-09-21 14:54:51 +02:00
$query_args_list = array_merge ( $query_args_list , [ " % $search % " , " % $search % " , inet_pton ( $search )]);
2020-03-11 14:54:11 +01:00
} elseif ( \LibreNMS\Util\IPv6 :: isValid ( $search , false )) {
2020-09-21 15:59:34 +02:00
$query .= ' LEFT JOIN `ports` AS `P` ON `P` . `device_id` = `D` . `device_id`
LEFT JOIN `ipv6_addresses` AS `V6` ON `V6` . `port_id` = `P` . `port_id` ' ;
$query_filter .= ' OR `V6` . `ipv6_address` LIKE ?
2020-03-11 14:54:11 +01:00
OR `D` . `overwrite_ip` LIKE ?
2020-09-21 15:59:34 +02:00
OR `D` . `ip` = ? ' ;
2020-09-21 14:54:51 +02:00
$query_args_list = array_merge ( $query_args_list , [ " % $search % " , " % $search % " , inet_pton ( $search )]);
2020-04-19 07:33:17 +02:00
} elseif ( ctype_xdigit ( $mac_search = str_replace ([ ':' , '-' , '.' ], '' , $search ))) {
2020-09-21 15:59:34 +02:00
$query .= ' LEFT JOIN `ports` as `M` on `M`.`device_id` = `D`.`device_id`' ;
$query_filter .= ' OR `M`.`ifPhysAddress` LIKE ? ' ;
2020-09-21 14:54:51 +02:00
$query_args_list [] = " % $mac_search % " ;
2015-07-13 20:10:26 +02:00
}
2020-10-21 23:15:47 +02:00
$query_filter .= ')' ;
2020-03-11 14:54:11 +01:00
// result limitation
$query_args_list [] = $limit ;
$results = dbFetchRows ( $query .
2020-09-21 15:59:34 +02:00
' WHERE ' . $query_filter .
' GROUP BY `D` . `hostname`
ORDER BY `D` . `hostname` LIMIT ? ' , $query_args_list );
2020-03-11 14:54:11 +01:00
2015-07-13 20:10:26 +02:00
if ( count ( $results )) {
2020-09-21 14:54:51 +02:00
$found = 1 ;
2015-07-13 20:10:26 +02:00
$devices = count ( $results );
foreach ( $results as $result ) {
$name = $result [ 'hostname' ];
2020-09-21 14:54:51 +02:00
if ( $_REQUEST [ 'map' ] != 1 && $result [ 'sysName' ] != $name && ! empty ( $result [ 'sysName' ])) {
$name .= ' (' . $result [ 'sysName' ] . ') ' ;
2016-07-09 22:24:30 +01:00
}
2015-07-13 20:10:26 +02:00
if ( $result [ 'disabled' ] == 1 ) {
$highlight_colour = '#808080' ;
2016-08-18 20:28:22 -05:00
} elseif ( $result [ 'ignored' ] == 1 && $result [ 'disabled' ] == 0 ) {
2015-07-13 20:10:26 +02:00
$highlight_colour = '#000000' ;
2016-08-18 20:28:22 -05:00
} elseif ( $result [ 'status' ] == 0 && $result [ 'ignore' ] == 0 && $result [ 'disabled' ] == 0 ) {
2015-07-13 20:10:26 +02:00
$highlight_colour = '#ff0000' ;
2016-08-18 20:28:22 -05:00
} elseif ( $result [ 'status' ] == 1 && $result [ 'ignore' ] == 0 && $result [ 'disabled' ] == 0 ) {
2015-07-13 20:10:26 +02:00
$highlight_colour = '#008000' ;
}
2020-10-21 23:15:47 +02:00
$num_ports = dbFetchCell ( 'SELECT COUNT(*) FROM `ports` AS `I`, `devices` AS `D` WHERE ' . $perms_sql . ' `I`.`device_id` = `D`.`device_id` AND `I`.`ignore` = 0 AND `I`.`deleted` = 0 AND `D`.`device_id` = ?' , array_merge ( $device_ids , [ $result [ 'device_id' ]]));
2019-12-30 12:11:26 +01:00
2020-09-21 14:54:51 +02:00
$device [] = [
2015-07-13 20:10:26 +02:00
'name' => $name ,
'device_id' => $result [ 'device_id' ],
'url' => generate_device_url ( $result ),
'colours' => $highlight_colour ,
'device_ports' => $num_ports ,
2017-01-24 16:16:01 -06:00
'device_image' => getIcon ( $result ),
2015-07-13 20:10:26 +02:00
'device_hardware' => $result [ 'hardware' ],
2020-02-19 12:35:55 -06:00
'device_os' => \LibreNMS\Config :: getOsSetting ( $result [ 'os' ], 'text' ),
2015-07-13 20:10:26 +02:00
'version' => $result [ 'version' ],
'location' => $result [ 'location' ],
2020-09-21 14:54:51 +02:00
];
2015-07-13 20:10:26 +02:00
} //end foreach
} //end if
$json = json_encode ( $device );
2020-09-21 14:54:51 +02:00
exit ( $json );
2016-08-18 20:28:22 -05:00
} elseif ( $_REQUEST [ 'type' ] == 'ports' ) {
2015-07-13 20:10:26 +02:00
// Search ports
2019-08-05 14:16:05 -05:00
if ( Auth :: user () -> hasGlobalRead ()) {
2019-04-11 09:39:25 -05:00
$results = dbFetchRows (
2020-09-21 15:59:34 +02:00
'SELECT `ports`.*,`devices`.* FROM `ports` LEFT JOIN `devices` ON `ports`.`device_id` = `devices`.`device_id` WHERE `ifAlias` LIKE ? OR `ifDescr` LIKE ? OR `ifName` LIKE ? ORDER BY ifDescr LIMIT ?' ,
2019-12-30 12:11:26 +01:00
[ " % $search % " , " % $search % " , " % $search % " , $limit ]
2019-04-11 09:39:25 -05:00
);
2016-08-18 20:28:22 -05:00
} else {
2019-04-11 09:39:25 -05:00
$results = dbFetchRows (
2020-10-21 23:15:47 +02:00
" SELECT DISTINCT(`I`.`port_id`), `I`.*, `D`.`hostname` FROM `ports` AS `I`, `devices` AS `D` WHERE $perms_sql `D`.`device_id` = `I`.`device_id` AND (`ifAlias` LIKE ? OR `ifDescr` LIKE ? OR `ifName` LIKE ?) ORDER BY ifDescr LIMIT ? " ,
2019-12-30 12:11:26 +01:00
array_merge ( $device_ids , [ " % $search % " , " % $search % " , " % $search % " , $limit ])
2019-04-11 09:39:25 -05:00
);
2015-07-13 20:10:26 +02:00
}
if ( count ( $results )) {
$found = 1 ;
foreach ( $results as $result ) {
2020-09-21 14:54:51 +02:00
$name = $result [ 'ifDescr' ] == $result [ 'ifAlias' ] ? $result [ 'ifName' ] : $result [ 'ifDescr' ];
2016-12-12 14:25:48 +00:00
$description = display ( $result [ 'ifAlias' ]);
2015-07-13 20:10:26 +02:00
if ( $result [ 'deleted' ] == 0 && ( $result [ 'ignore' ] == 0 || $result [ 'ignore' ] == 0 ) && ( $result [ 'ifInErrors_delta' ] > 0 || $result [ 'ifOutErrors_delta' ] > 0 )) {
// Errored ports
$port_colour = '#ffa500' ;
2016-08-18 20:28:22 -05:00
} elseif ( $result [ 'deleted' ] == 0 && ( $result [ 'ignore' ] == 1 || $result [ 'ignore' ] == 1 )) {
2015-07-13 20:10:26 +02:00
// Ignored ports
$port_colour = '#000000' ;
2016-08-18 20:28:22 -05:00
} elseif ( $result [ 'deleted' ] == 0 && $result [ 'ifAdminStatus' ] == 'down' && $result [ 'ignore' ] == 0 && $result [ 'ignore' ] == 0 ) {
2015-07-13 20:10:26 +02:00
// Shutdown ports
$port_colour = '#808080' ;
2016-08-18 20:28:22 -05:00
} elseif ( $result [ 'deleted' ] == 0 && $result [ 'ifOperStatus' ] == 'down' && $result [ 'ifAdminStatus' ] == 'up' && $result [ 'ignore' ] == 0 && $result [ 'ignore' ] == 0 ) {
2015-07-13 20:10:26 +02:00
// Down ports
$port_colour = '#ff0000' ;
2016-08-18 20:28:22 -05:00
} elseif ( $result [ 'deleted' ] == 0 && $result [ 'ifOperStatus' ] == 'up' && $result [ 'ignore' ] == 0 && $result [ 'ignore' ] == 0 ) {
2015-07-13 20:10:26 +02:00
// Up ports
$port_colour = '#008000' ;
} //end if
2020-09-21 14:54:51 +02:00
$ports [] = [
2015-07-13 20:10:26 +02:00
'count' => count ( $results ),
'url' => generate_port_url ( $result ),
'name' => $name ,
'description' => $description ,
2019-04-11 09:39:25 -05:00
'colours' => $port_colour ,
2019-12-20 21:21:31 +01:00
'hostname' => format_hostname ( $result ),
2015-09-07 19:29:30 +01:00
'port_id' => $result [ 'port_id' ],
2020-09-21 14:54:51 +02:00
];
2015-07-13 20:10:26 +02:00
} //end foreach
} //end if
$json = json_encode ( $ports );
2020-09-21 14:54:51 +02:00
exit ( $json );
2016-08-18 20:28:22 -05:00
} elseif ( $_REQUEST [ 'type' ] == 'bgp' ) {
2015-07-13 20:10:26 +02:00
// Search bgp peers
2019-12-30 12:11:26 +01:00
$results = dbFetchRows (
2020-10-21 23:15:47 +02:00
" SELECT `bgpPeers`.*,`D`.* FROM `bgpPeers`, `devices` AS `D` WHERE $perms_sql `bgpPeers`.`device_id`=`D`.`device_id` AND (`astext` LIKE ? OR `bgpPeerIdentifier` LIKE ? OR `bgpPeerRemoteAs` LIKE ?) ORDER BY `astext` LIMIT ? " ,
2019-12-30 12:11:26 +01:00
array_merge ( $device_ids , [ " % $search % " , " % $search % " , " % $search % " , $limit ])
);
2015-07-13 20:10:26 +02:00
if ( count ( $results )) {
$found = 1 ;
foreach ( $results as $result ) {
2020-09-21 14:54:51 +02:00
$name = $result [ 'bgpPeerIdentifier' ];
2015-07-13 20:10:26 +02:00
$description = $result [ 'astext' ];
2020-09-21 14:54:51 +02:00
$remoteas = $result [ 'bgpPeerRemoteAs' ];
$localas = $result [ 'bgpLocalAs' ];
2015-07-13 20:10:26 +02:00
if ( $result [ 'bgpPeerAdminStatus' ] == 'start' && $result [ 'bgpPeerState' ] != 'established' ) {
// Session active but errored
$port_colour = '#ffa500' ;
2016-08-18 20:28:22 -05:00
} elseif ( $result [ 'bgpPeerAdminStatus' ] != 'start' ) {
2015-07-13 20:10:26 +02:00
// Session inactive
$port_colour = '#000000' ;
2016-08-18 20:28:22 -05:00
} elseif ( $result [ 'bgpPeerAdminStatus' ] == 'start' && $result [ 'bgpPeerState' ] == 'established' ) {
2015-07-13 20:10:26 +02:00
// Session Up
$port_colour = '#008000' ;
}
if ( $result [ 'bgpPeerRemoteAs' ] == $result [ 'bgpLocalAs' ]) {
2019-12-11 17:58:58 +01:00
$bgp_image = 'fa fa-square fa-lg icon-theme' ;
2016-08-18 20:28:22 -05:00
} else {
2019-12-11 17:58:58 +01:00
$bgp_image = 'fa fa-external-link-square fa-lg icon-theme' ;
2015-07-13 20:10:26 +02:00
}
2020-09-21 14:54:51 +02:00
$bgp [] = [
2015-07-13 20:10:26 +02:00
'count' => count ( $results ),
'url' => generate_peer_url ( $result ),
'name' => $name ,
'description' => $description ,
'localas' => $localas ,
'bgp_image' => $bgp_image ,
'remoteas' => $remoteas ,
'colours' => $port_colour ,
2019-12-20 21:21:31 +01:00
'hostname' => format_hostname ( $result ),
2020-09-21 14:54:51 +02:00
];
2015-07-13 20:10:26 +02:00
} //end foreach
} //end if
$json = json_encode ( $bgp );
2020-09-21 14:54:51 +02:00
exit ( $json );
2016-08-18 20:28:22 -05:00
} elseif ( $_REQUEST [ 'type' ] == 'applications' ) {
2015-09-07 19:29:30 +01:00
// Device search
2019-12-30 12:11:26 +01:00
$results = dbFetchRows (
2020-10-21 23:15:47 +02:00
" SELECT * FROM `applications` INNER JOIN `devices` AS `D` ON `D`.`device_id` = `applications`.`device_id` WHERE $perms_sql (`app_type` LIKE ? OR `hostname` LIKE ?) ORDER BY hostname LIMIT ? " ,
2019-12-30 12:11:26 +01:00
array_merge ( $device_ids , [ " % $search % " , " % $search % " , $limit ])
);
2015-09-07 19:29:30 +01:00
if ( count ( $results )) {
2020-09-21 14:54:51 +02:00
$found = 1 ;
2015-09-07 19:29:30 +01:00
$devices = count ( $results );
foreach ( $results as $result ) {
$name = $result [ 'app_type' ];
if ( $result [ 'disabled' ] == 1 ) {
$highlight_colour = '#808080' ;
2016-08-18 20:28:22 -05:00
} elseif ( $result [ 'ignored' ] == 1 && $result [ 'disabled' ] == 0 ) {
2015-09-07 19:29:30 +01:00
$highlight_colour = '#000000' ;
2016-08-18 20:28:22 -05:00
} elseif ( $result [ 'status' ] == 0 && $result [ 'ignore' ] == 0 && $result [ 'disabled' ] == 0 ) {
2015-09-07 19:29:30 +01:00
$highlight_colour = '#ff0000' ;
2016-08-18 20:28:22 -05:00
} elseif ( $result [ 'status' ] == 1 && $result [ 'ignore' ] == 0 && $result [ 'disabled' ] == 0 ) {
2015-09-07 19:29:30 +01:00
$highlight_colour = '#008000' ;
}
2020-09-21 14:54:51 +02:00
$device [] = [
2015-09-07 19:29:30 +01:00
'name' => $name ,
2019-12-20 21:21:31 +01:00
'hostname' => format_hostname ( $result ),
2015-09-07 19:29:30 +01:00
'app_id' => $result [ 'app_id' ],
'device_id' => $result [ 'device_id' ],
'colours' => $highlight_colour ,
2017-01-24 16:16:01 -06:00
'device_image' => getIcon ( $result ),
2015-09-07 19:29:30 +01:00
'device_hardware' => $result [ 'hardware' ],
2019-06-23 00:29:12 -05:00
'device_os' => \LibreNMS\Config :: getOsSetting ( $result [ 'os' ], 'text' ),
2015-09-07 19:29:30 +01:00
'version' => $result [ 'version' ],
'location' => $result [ 'location' ],
2020-09-21 14:54:51 +02:00
];
2015-09-07 19:29:30 +01:00
} //end foreach
} //end if
$json = json_encode ( $device );
2020-09-21 14:54:51 +02:00
exit ( $json );
2016-08-18 20:28:22 -05:00
} elseif ( $_REQUEST [ 'type' ] == 'munin' ) {
2015-09-07 19:29:30 +01:00
// Device search
2019-12-30 12:11:26 +01:00
$results = dbFetchRows (
2020-10-21 23:15:47 +02:00
" SELECT * FROM `munin_plugins` INNER JOIN `devices` AS `D` ON `D`.`device_id` = `munin_plugins`.`device_id` WHERE $perms_sql (`mplug_type` LIKE ? OR `mplug_title` LIKE ? OR `hostname` LIKE ?) ORDER BY hostname LIMIT ? " ,
2019-12-30 12:11:26 +01:00
array_merge ( $device_ids , [ " % $search % " , " % $search % " , " % $search % " , $limit ])
);
2015-09-07 19:29:30 +01:00
if ( count ( $results )) {
2020-09-21 14:54:51 +02:00
$found = 1 ;
2015-09-07 19:29:30 +01:00
$devices = count ( $results );
foreach ( $results as $result ) {
$name = $result [ 'mplug_title' ];
if ( $result [ 'disabled' ] == 1 ) {
$highlight_colour = '#808080' ;
2016-08-18 20:28:22 -05:00
} elseif ( $result [ 'ignored' ] == 1 && $result [ 'disabled' ] == 0 ) {
2015-09-07 19:29:30 +01:00
$highlight_colour = '#000000' ;
2016-08-18 20:28:22 -05:00
} elseif ( $result [ 'status' ] == 0 && $result [ 'ignore' ] == 0 && $result [ 'disabled' ] == 0 ) {
2015-09-07 19:29:30 +01:00
$highlight_colour = '#ff0000' ;
2016-08-18 20:28:22 -05:00
} elseif ( $result [ 'status' ] == 1 && $result [ 'ignore' ] == 0 && $result [ 'disabled' ] == 0 ) {
2015-09-07 19:29:30 +01:00
$highlight_colour = '#008000' ;
}
2020-09-21 14:54:51 +02:00
$device [] = [
2015-09-07 19:29:30 +01:00
'name' => $name ,
2019-12-20 21:21:31 +01:00
'hostname' => format_hostname ( $result ),
2015-09-07 19:29:30 +01:00
'device_id' => $result [ 'device_id' ],
'colours' => $highlight_colour ,
2017-01-24 16:16:01 -06:00
'device_image' => getIcon ( $result ),
2015-09-07 19:29:30 +01:00
'device_hardware' => $result [ 'hardware' ],
2019-06-23 00:29:12 -05:00
'device_os' => \LibreNMS\Config :: getOsSetting ( $result [ 'os' ], 'text' ),
2015-09-07 19:29:30 +01:00
'version' => $result [ 'version' ],
'location' => $result [ 'location' ],
'plugin' => $result [ 'mplug_type' ],
2020-09-21 14:54:51 +02:00
];
2015-09-07 19:29:30 +01:00
} //end foreach
} //end if
2015-09-20 10:13:56 +01:00
$json = json_encode ( $device );
2020-09-21 14:54:51 +02:00
exit ( $json );
2016-08-18 20:28:22 -05:00
} elseif ( $_REQUEST [ 'type' ] == 'iftype' ) {
2015-09-20 10:13:56 +01:00
// Device search
2019-12-30 12:11:26 +01:00
$results = dbFetchRows (
2020-10-21 23:15:47 +02:00
" SELECT `ports`.ifType FROM `ports` WHERE $perms_sql `ifType` LIKE ? GROUP BY ifType ORDER BY ifType LIMIT ? " ,
2019-12-30 12:11:26 +01:00
array_merge ( $device_ids , [ " % $search % " , $limit ])
);
2015-09-20 10:13:56 +01:00
if ( count ( $results )) {
2020-09-21 14:54:51 +02:00
$found = 1 ;
2015-09-20 10:13:56 +01:00
$devices = count ( $results );
foreach ( $results as $result ) {
2020-09-21 14:54:51 +02:00
$device [] = [
2015-09-20 10:13:56 +01:00
'filter' => $result [ 'ifType' ],
2020-09-21 14:54:51 +02:00
];
2015-09-20 10:13:56 +01:00
} //end foreach
} //end if
2015-09-07 19:29:30 +01:00
$json = json_encode ( $device );
2020-09-21 14:54:51 +02:00
exit ( $json );
2016-08-18 20:28:22 -05:00
} elseif ( $_REQUEST [ 'type' ] == 'bill' ) {
2015-09-30 20:11:18 +00:00
// Device search
2019-08-05 14:16:05 -05:00
if ( Auth :: user () -> hasGlobalRead ()) {
2019-04-11 09:39:25 -05:00
$results = dbFetchRows (
2020-09-21 15:59:34 +02:00
'SELECT `bills`.bill_id, `bills`.bill_name FROM `bills` WHERE `bill_name` LIKE ? OR `bill_notes` LIKE ? LIMIT ?' ,
2019-12-30 12:11:26 +01:00
[ " % $search % " , " % $search % " , $limit ]
2019-04-11 09:39:25 -05:00
);
2016-08-18 20:28:22 -05:00
} else {
2019-04-11 09:39:25 -05:00
$results = dbFetchRows (
2020-09-21 15:59:34 +02:00
'SELECT `bills`.bill_id, `bills`.bill_name FROM `bills` INNER JOIN `bill_perms` ON `bills`.bill_id = `bill_perms`.bill_id WHERE `bill_perms`.user_id = ? AND (`bill_name` LIKE ? OR `bill_notes` LIKE ?) LIMIT ?' ,
2019-12-30 12:11:26 +01:00
[ Auth :: id (), " % $search % " , " % $search % " , $limit ]
2019-04-11 09:39:25 -05:00
);
2015-09-30 20:11:18 +00:00
}
$json = json_encode ( $results );
2020-09-21 14:54:51 +02:00
exit ( $json );
2015-07-13 20:10:26 +02:00
} //end if
} //end if
} //end if