<?php header("Content-type: text/xml");
echo "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>"; ?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
    >
<channel> 
    <title>Latest ESO telbib papers</title>
    <atom:link href="http://www.eso.org/sci/libraries/rss.php" rel="self" type="application/rss+xml" />
    <link>http://www.eso.org/sci/libraries/latest-eso-papers.php</link>
    <description>The Telescope Bibliography (telbib) is ESO's database of refereed papers that use ESO data (public interface: http://www.eso.org/libraries/telbib.html). Developed, maintained, and further enhanced by the ESO Library, telbib is used to generate statistics and reports on a regular basis as well as on request (see for instance Basic ESO Statistics, http://www.eso.org/sci/libraries/edocs/ESO/ESOstats.pdf). For questions and suggestions, please contact the ESO Librarians at library@eso.org</description>
    <language>en-en</language>
    <docs>http://www.eso.org/sci/libraries/rss/rss.php</docs>
    <generator>Rss Feed Engine</generator>
    <managingEditor>library@eso.org</managingEditor>
    <webMaster>library@eso.org</webMaster>

<?php
include("inc/functions.php");

    $res_p = sybase_query("SELECT DISTINCT TOP 100 PaperID FROM bibPapers WHERE (PaperStatus = 1 OR PaperStatus = 2) AND Refereed = 1 AND MadePublicDate < current_date() ORDER BY MadePublicDate DESC") or die("SELECT DISTINCT TOP 100 PaperID FROM bibPapers WHERE (PaperStatus = 1 OR PaperStatus = 2) AND Refereed = 1 AND MadePublicDate < current_date() ORDER BY MadePublicDate DESC");
    
    while ($rp = sybase_fetch_array($res_p)) {
		
        $res_itemb = sybase_query("SELECT FirstAuthor, Title, BibCode, Abstract FROM bibPapers WHERE PaperID=".$rp["PaperID"]) or die("SELECT FirstAuthor, Title, BibCode, Abstract FROM bibPapers WHERE PaperID=".$rp["PaperID"]);
        
        while ($itemb = sybase_fetch_array($res_itemb)) {
    
?>
        <item>
        <title><?php echo htmlspecialchars($itemb["Title"], ENT_QUOTES, "UTF-8"); ?></title>    
        <link>
        <?php echo "http://telbib.eso.org/detail.php?id=".$rp["PaperID"]; ?>
        </link>    
        <description><![CDATA[
        <?php  
        	echo "First Author: ".$itemb["FirstAuthor"]."<br>";
            
            $res_itemi = sybase_query("SELECT Instrument FROM bibInstrumentUsage, bibInstruments WHERE bibInstruments.InstrumentID = bibInstrumentUsage.InstrumentID AND PaperID=".$rp["PaperID"]) or die("SELECT Instrument FROM bibInstrumentUsage, bibInstruments WHERE bibInstruments.InstrumentID = bibInstrumentUsage.InstrumentID AND PaperID=".$rp["PaperID"]);
            
            while ($itemi = sybase_fetch_array($res_itemi)) {       
        		$instrument[] = $itemi['Instrument'];
            }
            $instrument = array_unique($instrument);
            sort($instrument);
            $instrument = removeEmptyValues($instrument); 
            $instrument = implode(", ", $instrument);  
            echo "Instruments: ".$instrument."<br>";        
            unset($instrument);
            
            $res_itemp = sybase_query("SELECT ProgramID FROM bibPrograms WHERE PaperID=".$rp["PaperID"]) or die("SELECT ProgramID FROM bibPrograms WHERE PaperID=".$rp["PaperID"]);
            
            while ($itemp = sybase_fetch_array($res_itemp)) {       
        		$program[] = $itemp['ProgramID'];
            }
            $program = array_unique($program);
            //sort($program);
            $program = removeEmptyValues($program);
            $program = implode(", ", $program);  
            echo "ProgramIDs: ".$program."<br>";
            unset($program);
            echo "BibCode: ".htmlentities($itemb["BibCode"])."<br><br>";
            echo $itemb["Abstract"];
            //echo htmlspecialchars($rp["Abstract"], ENT_QUOTES, "UTF-8");
        ?>
        ]]>
        </description>
        <guid isPermaLink="false">http://telbib.eso.org/detail.php?id=<?php echo $rp["PaperID"]; ?></guid>
        </item>
<?php
		}
   }
?>

</channel>
</rss> 
