<?php
require_once("feedcreator.class.php"); 
require_once("../safehouse/FoalnetInc/db.inc");

$rss = new UniversalFeedCreator(); 
$rss->title = "Foalcam Alerts"; 
$rss->description = "Alerts about foaling mares from Foalcam.com";

$rss->link = "http://www.foalcam.com"; 
$rss->syndicationURL = "http://www.foalcam.com/".$_SERVER["PHP_SELF"]; 

/*
$image = new FeedImage(); 
$image->title = "Foalcam.com Logo"; 
$image->url = "http://www.foalcam.com/images/logo.gif"; 
$image->link = "http://www.foalcam.com"; 
$image->description = "Feed provided by Foalcam.com. Click to visit."; 
*/

$rss->image = $image; 

//Get any triggered
$alertsT = "SELECT a.level, a.time, a.status, s.url, s.site_name, s.camera_url, s.id FROM fn_alerts_new a, fn_sites s WHERE a.status!=2 AND a.site_id = s.id AND time>UNIX_TIMESTAMP()-24*60*60 ORDER BY time DESC";
$alertsQ = mysql_query($alertsT);

while ($alert = mysql_fetch_object($alertsQ))
{
/*
$alert->camera_url = "www.google.com";
$alert->level = 2;
$alert->site_name = "Saddlebrook Appaloosas";
$alert->time = time();
*/

	$url = ($alert->camera_url == "") ? $alert->url : $alert->camera_url;
	if (substr($url, 0, 4) != "http") $url = "http://".$url;

	$item = new FeedItem(); 
	$item->title = ($alert->level == 1 ? "Low" : "High")." Alert for $alert->site_name!";
	$item->link = $url;
	$item->description = "<h3>A ".($alert->level == 1 ? "Low" : "High")." alert has been posted for $alert->site_name at " . date("m/d/Y g:i a", $alert->time)."</h3><br />Now you can get these alerts even faster on your cell phone at <a href='http://www.foalcall.com'>FoalCall.com</a> or by viewing our real-time <a href='http://www.foalcam.com/gateway.html'>alert monitor</a> at <a href='http://www.foalcam.com'>FoalCam.com</a>.";
	
	//$item->date = date("H:i:s m/d/Y");
	//$item->source = "http://www.foalcam.com".date("H:i:s m/d/Y");
	 
	$rss->addItem($item); 
} 

// valid format strings are: RSS0.91, RSS1.0, RSS2.0, PIE0.1 (deprecated),
// MBOX, OPML, ATOM, ATOM0.3, HTML, JS
echo $rss->createFeed("RSS2.0");

?>
