return;
}
-// if reported recently, skip reporting
-if(skipReporting($link, $macAddress, $gatewayName, $reportInterval)){
- mysqli_close($link);
- return;
-}
-
// close database
mysqli_close($link);
}
/***
-To avoid to send too many mails,
- skip if there are recent logs having same macaddress and same gateway.
-If you want to change the report period, $reportPeriod is defined at the top of this file.
-***/
-function skipReporting($link, $macAddress, $gatewayName, $reportInterval){
-
- // query
- $result = mysqli_query($link, 'SELECT count(*) FROM sessionmd '
- .'WHERE EXISTS (SELECT * FROM sessionmd '
- .'WHERE macAddress="'.$macAddress.'" '
- .'AND gatewayName LIKE "'.$gatewayName.'.%" '
- .'AND openTime > NOW() - INTERVAL '.$reportInterval.' '
- .'AND openTime < NOW() - INTERVAL 1 MINUTE '
- .')'
- );
-
- if (!$result){
- syslog(LOG_INFO, 'ERR: Fail query '.mysqli_error());
- return TRUE;
- }
-
- // get data
- if($row = mysqli_fetch_row($result)) $count = $row[0];
- else $count = 0;
-
- // if recent logs exist, skip is true
- if($count>0)return TRUE;
- else return FALSE;
-}
-
-/***
send mail to the user mail address
***/
function sendMailToUser($mailSender, $mailAddress, $device, $gatewayName,