<?php
//ini_set('display_errors', 'on');

date_default_timezone_set('Asia/Tehran');


//$con = pg_connect('host=192.168.10.132 port=5432 dbname=netrise user=rss password=R$s123^&') or die('DB Connection Error!');
$con =pg_connect('host=192.168.10.132 port=5432 dbname=netrise user=rss_airport password=r$$AirporT1397') or die('DB Connection Error!');

//pg_query('SET NAMES "UTF8"');


header("Content-Type: text/xml");
header("Pragma: no-cache");

$host = $_SERVER['HTTP_HOST'];
if (empty($host)) {
	$host = 'www.airport.ir';
}

echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>
<rss version=\"2.0\">
<channel>
	<title>آخرین اخبار</title>
	<description>شرکت مادر تخصصی فرودگاه‌های کشور</description>
	<link>http://www.airport.ir</link>
	<language>fa</language>
	<generator>Airport.ir</generator>";

$entries = pg_query('SELECT Tbl.id, Tbl.titr, Tbl.lead, Tbl.news_date, Tbl.news_time FROM airport_site.news Tbl INNER JOIN airport_site.news_levels ON Tbl.id = news_levels.news_id WHERE Tbl.news_status = 3 AND (Tbl.news_type = 1 OR Tbl.news_type = 2) AND Tbl.language = 1 AND news_levels.portals_id = 1 AND Tbl.news_date <= \''. date('Y-m-d') .'\' ORDER BY Tbl.news_date DESC, Tbl.news_time DESC LIMIT 15');

while ($entry = pg_fetch_assoc($entries)) {

	$content = $entry['lead'];
	$content = str_replace("&#39;", "'", $content);
	$title = str_replace("&#39;", "'", $entry['titr']);
  	
  	$content = strip_tags($content);
  	$title = strip_tags($title);

	//$content = htmlspecialchars($content);
	//$title = htmlspecialchars($title);

	$title_for_url = str_replace(' ', '-', $entry['titr']);

	$link = "http://$host/shownews?public_news=".$entry['id'].'&amp;title='.$title_for_url;

	$pub_date = date("r", strtotime($entry['news_date'].' '.$entry['news_time']));

	//$thumb = htmlspecialchars("http://www.new.airport.ir/home?p_p_id=NetFormGetFile_WAR_NetForm&p_p_lifecycle=2&p_p_resource_id=getFile&_NetFormGetFile_WAR_NetForm_t=9119&_NetFormGetFile_WAR_NetForm_recordId=50221&_NetFormGetFile_WAR_NetForm_fieldId=36345&_NetFormGetFile_WAR_NetForm_fileName=upload_771_00005159.jpg&_NetFormGetFile_WAR_NetForm_extDir=10201/4606");

	echo "
		<item>
			<title>$title</title>
			<description>$content</description>
			<link>$link</link>
			<pubDate>$pub_date</pubDate>
		</item>";
}

echo "
</channel>
</rss>";

pg_free_result($entries);

pg_close($con);

?>
