2015-03-27 16:28:09 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								< ? php  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-08-06 18:36:26 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								$sql  =  ' FROM `devices` AS D ' ;  
						 
					
						
							
								
									
										
										
										
											2015-03-27 16:28:09 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								if  ( is_admin ()  ===  false )  {  
						 
					
						
							
								
									
										
										
										
											2015-08-06 18:36:26 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    $sql  .=  " , devices_perms AS P  " ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								$sql  .=  "  LEFT JOIN `poller_groups` ON `D`.`poller_group`=`poller_groups`.`id` " ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								if  ( is_admin ()  ===  false )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    $sql  .=  "  WHERE D.device_id = P.device_id AND P.user_id = ' " . $_SESSION [ 'user_id' ] . " ' AND D.ignore = '0' " ; 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								else  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    $sql  .=  ' WHERE 1' ; 
							 
						 
					
						
							
								
									
										
										
										
											2015-03-27 16:28:09 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								if  ( isset ( $searchPhrase )  &&  ! empty ( $searchPhrase ))  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    $sql  .=  "  AND (hostname LIKE '% $searchPhrase %' OR last_polled LIKE '% $searchPhrase %' OR last_polled_timetaken LIKE '% $searchPhrase %') " ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								if  ( ! isset ( $sort )  ||  empty ( $sort ))  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    $sort  =  'last_polled_timetaken DESC' ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-05-25 21:54:57 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								$sql  .=  "  AND D.status ='1' AND D.ignore='0' AND D.disabled='0' ORDER BY  $sort " ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-03-27 16:47:26 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								$count_sql  =  " SELECT COUNT(`D`.`device_id`)  $sql " ;  
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								$total      =  dbFetchCell ( $count_sql );  
						 
					
						
							
								
									
										
										
										
											2015-04-12 11:47:21 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								if  ( empty ( $total ))  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    $total  =  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
									
										
										
										
											2015-03-27 16:28:09 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								if  ( isset ( $current ))  {  
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    $limit_low   =  (( $current  *  $rowCount )  -  ( $rowCount )); 
							 
						 
					
						
							
								
									
										
										
										
											2015-03-27 16:28:09 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    $limit_high  =  $rowCount ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								if  ( $rowCount  !=  - 1 )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    $sql  .=  "  LIMIT  $limit_low , $limit_high " ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-08-06 18:36:26 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								$sql  =  " SELECT D.device_id,D.hostname AS `hostname`, D.last_polled AS `last_polled`, `group_name`, D.last_polled_timetaken AS `last_polled_timetaken`  $sql " ;  
						 
					
						
							
								
									
										
										
										
											2015-03-27 16:47:26 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-09-30 15:20:06 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								foreach  ( dbFetchRows ( $sql , array (), true )  as  $device )  {  
						 
					
						
							
								
									
										
										
										
											2015-08-06 18:36:26 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    if  ( empty ( $device [ 'group_name' ]))  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        $device [ 'group_name' ]  =  'General' ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    $response []  =  array ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        'hostname'               =>  " <a class='list-device' href=' " . generate_device_url ( $device ,  array ( 'tab'  =>  'graphs' ,  'group'  =>  'poller' )) . " '> " . $device [ 'hostname' ] . '</a>' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        'last_polled'            =>  $device [ 'last_polled' ], 
							 
						 
					
						
							
								
									
										
										
										
											2015-08-06 18:36:26 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        'poller_group'           =>  $device [ 'group_name' ], 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        'last_polled_timetaken'  =>  $device [ 'last_polled_timetaken' ], 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ); 
							 
						 
					
						
							
								
									
										
										
										
											2015-03-27 16:28:09 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								$output  =  array (  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    'current'   =>  $current , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    'rowCount'  =>  $rowCount , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    'rows'      =>  $response , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    'total'     =>  $total , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								);  
						 
					
						
							
								
									
										
										
										
											2015-03-27 16:28:09 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								echo  _json_encode ( $output );