<?php
/*************************************************************\
+-------------------------------------------------------------+
| 通灵佛教网在线烧香程序 System                                 |
| Copyright (c) 2003-2010 Alfred China                        |
| All rights reserved.                                        |
+-------------------------------------------------------------+
\*************************************************************/
require_once('chk.php');

$nid = intval($nid);
$lid = intval($lid);

$txturl = "";
$txtsou = "$sql_tbl[newsletter].avail = 'Y'";

$lid && $txturl .= "&lid=$lid";
$lid && $txtsou .= " AND $sql_tbl[newsletter].listid='$lid'";

$substring && $txturl .= "&substring=$substring";
$substring && $txtsou .= " AND subject LIKE '%".$substring."%'";

if($nid <> ""){

	$news = ng_query_first("SELECT * FROM $sql_tbl[newsletter] WHERE $sql_tbl[newsletter].avail = 'Y' AND newsid = '$nid'");
	
	$metawords = $news["subject"];
	$metaintro = msubstr(ltrim(strip_tags($news["body"])),0,100);
	$titlename =  $news["subject"];
	
}else{

if($lid <> ""){

	$lstname = ng_query_first_cell("SELECT name FROM $sql_tbl[newslists] WHERE listid = '$lid'");
	$metawords = $netgou["meta_keywords"];
	$metaintro = $netgou["meta_descr"];
	$titlename = $netgou["web_name"];

}else{
	
	$lstname ="全部新闻";
	$metawords = $netgou["meta_keywords"];
	$metaintro = $netgou["meta_descr"];
	$titlename = $netgou["web_name"];
}

$total_items = ng_query_first_cell("SELECT COUNT($sql_tbl[newsletter].newsid) FROM $sql_tbl[newsletter] WHERE $txtsou");

if ($total_items > 0) {
	
	$pageurl = "news.php?".$txturl;
	$objects_per_page = 50;
		
	$total_nav_pages = ceil($total_items/$objects_per_page);
	if($page > $total_nav_pages)
		$page = $total_nav_pages;
	$netgou["max_nav_pages"] = 10;
	include_once ng_dir."/include/navigation.php";

	$newsletter = ng_query("SELECT $sql_tbl[newsletter].newsid, $sql_tbl[newsletter].subject, $sql_tbl[newsletter].titleb, $sql_tbl[newsletter].titlecolor FROM $sql_tbl[newsletter] WHERE $txtsou order by newsid desc LIMIT $first_page, $objects_per_page");
			
	$first_item = $first_page+1;
	$last_item =  min($first_page+$objects_per_page, $total_items);
}

}

$ng_obstart && function_exists('ob_gzhandler') ? ob_start('ob_gzhandler') : ob_start();
$ng_obstart ? $ng_gzip="Gzip enabled":$ng_gzip="Gzip disabled";
require_once PrintTemp('header');
require_once PrintTemp('news');
require_once PrintTemp('footer');
$output=str_replace(array('<!--<!--<!---->','<!--<!---->','<!---->'),array('','',''),ob_get_contents());
ob_end_clean();
echo $output;
flush;
exit;
break;
?>