//check the log file for the last time an email was sent
$logfile = "/home/www-data/berkeley.edu-cnmat.www/htdocs/var/log/checkout-notifications.log";
$filetime = filemtime($logfile);
$diff = time() - $filetime;
//echo $diff;
echo " ";
$recipients = '';

//get the view with the checkouts
$view = views_get_view('checkouts_pastdue');
//gets the items in the view
$items = views_build_view('items', $view, null, false, 0, 0, 0, $filters);
$res = $items['items'];//results
//go through each result and get the node of the checkout and from there find and email the user
foreach($res as $r){
//print_r( $r);
$nd = node_load( $r->nid);
//print_r($nd);
$usr = user_load(array('name' => check_plain($nd->name)));

$email = $usr->mail; //here is the user's email address.
$recipients[]=$email;
$fieldval = $nd->field_notifications[0]['value'];

//the email body

}
//
$body = "Your equipment checkout on the CNMAT website has ended. Please return the items or update your checkout information.

www.cnmat.berkeley.edu/checkouts ";

$recipients = array_unique($recipients);

foreach($recipients as $person){
echo $person;
echo '
';
}
?>