<?php
$id_content_category_main=23;

if($id_content_category_main<>""){
require_once dirname(__FILE__) . '/rss2writer.php';
// convert from MySQL's datetime to a timestamp
//$timestamp = strtotime('2006-02-06 20:26:23');
 include_once( '../includes/adodbinfo.php' );

		 //print $components_record;
		 // id_content_category_main=51 and
$recordSet = $db->Execute("Select content_management_main.topic_en,content_management_main.topic_th,content_management_main.pic_firstpage,content_management_main.description_th,content_management_main.description_en,content_management_main.text_firstpage_en,content_management_main.text_firstpage_th,content_management_main.id_content_management_main,content_management_main.id_content_topic_main,content_topic_main.id_content_category_main,content_management_main.event_date,content_category_main.topic_th AS cat_topic_th  From  content_management_main LEFT JOIN content_topic_main ON content_management_main.id_content_topic_main=content_topic_main.id_content_topic_main LEFT JOIN  content_category_main ON content_topic_main.id_content_category_main=content_category_main.id_content_category_main  where  content_category_main.id_content_category_main=$id_content_category_main and  content_management_main.firstpage_status=0 and content_management_main.active_status=0 $member_access_check Order by content_management_main.event_date  Desc");
		 $sum_row=$recordSet->RecordCount();
		$cat_topic_th=$recordSet->fields["cat_topic_th"];
		$cat_topic_th=iconv("UTF-8","TIS-620",$cat_topic_th);
		$cat_topic_th="Kriengsak.com - ".$cat_topic_th;


$rss = new RSS2Writer('http://www.kriengsak.com/', "$cat_topic_th", 'www.kriengsak.com ' , array(

 'copyright' => 'www.kriengsak.com',

 'generator' => 'webmaster@www.kriengsak.com',

 'language' => 'th-TH'

 ));


		 
		
			$rss_show_record=10; 
		 if($sum_row<$rss_show_record){
		 	$show_recore=$sum_row;
		 }else{
		 $show_recore=$rss_show_record;
		 }
		 


		



$i=0;
while ($i< $show_recore){	

	$topic_th= $recordSet->fields["topic_th"];
	$text_firstpage_th=$recordSet->fields["text_firstpage_th"];
	//print $topic_th;
	if($topic_th==""){
		$topic_th= $recordSet->fields["topic_en"];
		$text_firstpage_th=$recordSet->fields["text_firstpage_en"];	
	}
	
	
	
	
	$topic_th=str_replace('“','"',$topic_th);
	$topic_th=str_replace('”','"',$topic_th);
	$topic_th=iconv("UTF-8","TIS-620",$topic_th);
	$text_firstpage_th=iconv("UTF-8","TIS-620",$text_firstpage_th);
	$id_content_category_main=$recordSet->fields["id_content_category_main"];
	$id_content_topic_main=$recordSet->fields["id_content_topic_main"];
	$id_content_management_main=$recordSet->fields["id_content_management_main"];
	$link_article="http://www.kriengsak.com/index.php?components=content&id_content_category_main=$id_content_category_main&id_content_topic_main=$id_content_topic_main&id_content_management_main=$id_content_management_main";
//print $topic_th;
//print "<br>";

$rss->addItem(
 "$link_article",
 "$topic_th",
  "$text_firstpage_th"
);


	$recordSet->MoveNext(); 
		$i++;
	}
$recordSet->Close(); # optional$conn->Close(); # optional
		


$rss->output('windows-874');

} 
?>
