<?php

header("Content-type: application/rss+xml; charset=\"utf-8\""); 

  include("$DOCUMENT_ROOT/functions/format.inc");
	include("$DOCUMENT_ROOT/functions/userfunc.inc");
  include("$DOCUMENT_ROOT/objects/widgets/table.inc");
  include("$DOCUMENT_ROOT/objects/user.inc");
  include("$DOCUMENT_ROOT/objects/session.inc");
  include("$DOCUMENT_ROOT/objects/review.inc");
  require("$DOCUMENT_ROOT/objects/comment.inc");
 

// Connect to the database.
require("$DOCUMENT_ROOT/db/db_setup.inc");
dbConnect();

// The header info



echo "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n";
echo "<rss version=\"2.0\">\n";
echo "<channel>\n";
echo "<title>Atlanta's TheaterReview.com</title>\n";
echo "<link>http://www.theaterreview.com</link>\n";
echo "<description>Reviews of Atlanta's Theater works from the unwashed masses.</description>\n";

// pull the data
// want to be able to optionally choose show opening info, review info or both.

// we'll start with review info for last 10 reviews
// and expand from there.
if ($rev="yes")
{
	$strQuery = "SELECT rv.*, pr.*, rt.rating, us.display_name " .
				 "FROM production pr, prod_review rv, prod_rating rt, user us " .
				 "WHERE rt.rating_id = rv.rating_id " .
				 "AND pr.prod_id = rv.prod_id " .
				 "AND us.user_id = rv.user_id " .
				 "AND pr.allowreview = 1 " .
				 "ORDER BY rv.timestamp DESC " . 
				 "LIMIT 3";
		 if (!($revresult = mysql_query($strQuery, $db)))
		 {
			 $error = mysql_error();
			 echo ("REVIEW ERROR : $error");
		 }
		 while ($myreview = mysql_fetch_array($revresult))
		 {
				$coQuery =  "SELECT co.* " .
							"FROM company co, complink cl " .
							"WHERE cl.prod_id = " .  $myreview[prod_id] . " " .
							"AND co.comp_id = cl.comp_id ";
				//echo $coQuery."<br>";
				 if (!($coresult = mysql_query($coQuery, $db)))
				 {
					 $error = mysql_error();
					 echo ("COMPANY ERROR : $error");
				 }
				
				echo "<item>\n";
				echo "<title>" . utf8_encode(htmlentities($myreview[text_header])) . "</title>\n";
				echo "<link>".utf8_encode(htmlentities( "http://www.theaterreview.com/index.php3?productionurl=".$myreview[prod_id]."&maindata=proddetail"))."</link>\n";
				
				echo "<pubDate>";
				$unixtimestamp = sql_to_unix_time2($myreview[timestamp]);
			  $review_date = date("r", $unixtimestamp);
			  echo "$review_date";
				echo "</pubDate>\n";
				echo "<description>";
				echo utf8_encode(htmlentities("Review of <b>".$myreview[title]."</b><br>"));
				While ($mycompany = mysql_fetch_array($coresult))
				{
					echo utf8_encode(htmlentities("Produced by <b>".$mycompany[name]."</b><br>"));
				}
				echo utf8_encode(htmlentities("Review by <b>".$myreview[display_name]."</b><br>"));
				echo utf8_encode(htmlentities("<p>".$myreview[text]."</p>"));
				echo "</description>\n";
				echo "<comments>".utf8_encode(htmlentities( "http://www.theaterreview.com/index.php3?productionurl=".$myreview[prod_id]."&maindata=proddetail"))."</comments>\n";
				echo "<guid isPermaLink=\"false\">".$myreview[text_header]."</guid>\n";
				echo "</item>\n";
		 }
}
else
{
	echo "No data selected for RSS feed.  (&rev=yes for reviews.)<br>\n";
}

//Ending stuff

?>
 </channel>
</rss>
<?php
?>