2015-03-24 16:27:28 +00:00
< ? php
$pdf -> AddPage ( 'L' );
2015-07-13 20:10:26 +02:00
$where = '1' ;
2015-03-24 16:27:28 +00:00
2015-07-13 20:10:26 +02:00
if ( is_numeric ( $_GET [ 'device_id' ])) {
$where .= ' AND E.device_id = ?' ;
$param [] = $_GET [ 'device_id' ];
}
2015-03-24 16:27:28 +00:00
2015-07-13 20:10:26 +02:00
if ( $_GET [ 'string' ]) {
$where .= ' AND R.rule LIKE ?' ;
$param [] = '%' . $_GET [ 'string' ] . '%' ;
}
2015-03-24 16:27:28 +00:00
2015-07-13 20:10:26 +02:00
if ( $_SESSION [ 'userlevel' ] >= '5' ) {
$query = " FROM `alert_log` AS E LEFT JOIN devices AS D ON E.device_id=D.device_id RIGHT JOIN alert_rules AS R ON E.rule_id=R.id WHERE $where ORDER BY `humandate` DESC " ;
}
else {
$query = " FROM `alert_log` AS E LEFT JOIN devices AS D ON E.device_id=D.device_id RIGHT JOIN alert_rules AS R ON E.rule_id=R.id RIGHT JOIN devices_perms AS P ON E.device_id = P.device_id WHERE $where AND P.user_id = ? ORDER BY `humandate` DESC " ;
$param [] = $_SESSION [ 'user_id' ];
}
2015-03-24 16:27:28 +00:00
2015-07-13 20:10:26 +02:00
if ( isset ( $_GET [ 'start' ]) && is_numeric ( $_GET [ 'start' ])) {
$start = mres ( $_GET [ 'start' ]);
}
else {
$start = 0 ;
}
2015-03-24 16:27:28 +00:00
2015-07-13 20:10:26 +02:00
if ( isset ( $_GET [ 'results' ]) && is_numeric ( $_GET [ 'results' ])) {
$numresults = mres ( $_GET [ 'results' ]);
}
else {
$numresults = 250 ;
}
$full_query = " SELECT D.device_id,name,state,time_logged,DATE_FORMAT(time_logged, ' " . $config [ 'dateformat' ][ 'mysql' ][ 'compact' ] . " ') as humandate $query LIMIT $start , $numresults " ;
foreach ( dbFetchRows ( $full_query , $param ) as $alert_entry ) {
$hostname = gethostbyid ( mres ( $alert_entry [ 'device_id' ]));
$alert_state = $alert_entry [ 'state' ];
2015-03-24 16:27:28 +00:00
2015-07-13 20:10:26 +02:00
if ( $alert_state != '' ) {
if ( $alert_state == '0' ) {
$glyph_color = 'green' ;
$text = 'Ok' ;
2015-03-24 16:27:28 +00:00
}
2015-07-13 20:10:26 +02:00
else if ( $alert_state == '1' ) {
$glyph_color = 'red' ;
$text = 'Alert' ;
}
else if ( $alert_state == '2' ) {
$glyph_color = 'lightgrey' ;
$text = 'Ack' ;
}
else if ( $alert_state == '3' ) {
$glyph_color = 'orange' ;
$text = 'Worse' ;
}
else if ( $alert_state == '4' ) {
$glyph_color = 'khaki' ;
$text = 'Better' ;
}
$data [] = array (
$alert_entry [ 'time_logged' ],
$hostname ,
2016-02-10 15:40:50 +00:00
$alert_entry [ 'name' ],
2015-07-13 20:10:26 +02:00
$text ,
);
} //end if
} //end foreach
2015-03-24 16:27:28 +00:00
2015-07-13 20:10:26 +02:00
$header = array (
'Datetime' ,
'Device' ,
'Log' ,
'Status' ,
);
2015-03-24 16:27:28 +00:00
$table = <<< EOD
< table border = " 1 " cellpadding = " 0 " cellspacing = " 0 " align = " center " >
< tr nobr = " true " bgcolor = " #92b7d3 " >
< th > Datetime </ th >
< th > Device </ th >
< th > Log </ th >
< th > Status </ th >
</ tr >
EOD ;
foreach ( $data as $log ) {
if ( $log [ 3 ] == 'Alert' ) {
$tr_col = '#d39392' ;
2015-07-13 20:10:26 +02:00
}
else {
2015-03-24 16:27:28 +00:00
$tr_col = '#bbd392' ;
}
2015-07-13 20:10:26 +02:00
2015-03-24 16:27:28 +00:00
$table .= '
2015-07-13 20:10:26 +02:00
< tr nobr = " true " bgcolor = " '. $tr_col .' " >
2015-03-24 16:27:28 +00:00
< td > '.$log[0].' </ td >
< td > '.$log[1].' </ td >
< td > '.$log[2].' </ td >
< td > '.$log[3].' </ td >
2015-07-13 20:10:26 +02:00
</ tr >
' ;
2015-03-24 16:27:28 +00:00
}
$table .= <<< EOD
</ table >
EOD ;
$pdf -> writeHTML ( $table , true , false , false , false , '' );