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

$search_condition = " 1=1 ";
$messages = "";
$txturl = '';

$listid && $txturl .= "&listid=$listid";
$substring && $txturl .= "&substring=$substring";

$listid && $search_condition .= " AND listid = $listid";
$substring && $search_condition .= " AND subject LIKE '%".$substring."%'";

if ($mode == "up_avail") {
	$avail = ($avail != "")?$avail:"Y";
	db_query("UPDATE $sql_tbl[newsletter] SET avail='$avail' WHERE newsid='$newsid'");
	showmsg("操作成功","news.php?listid=$listid&substring=$substring&page=$page");
	
}elseif($mode == "delete" and !empty($to_delete)){
	
	if(is_array($to_delete)){
		foreach($to_delete as $k=>$v){
			db_query("DELETE FROM $sql_tbl[newsletter] WHERE newsid = '$k'");
		}
	}
	showmsg("操作成功","news.php?listid=$listid&substring=$substring&page=$page");
}
	
$total_items = ng_query_first_cell("SELECT COUNT(newsid) FROM $sql_tbl[newsletter] WHERE ".$search_condition."");
	
if ($total_items > 0) {
			
	$objects_per_page = 50;
	$total_nav_pages = ceil($total_items/$objects_per_page);
	if($page > $total_nav_pages)
		$page = $total_nav_pages;
	$pageurl = "news.php?listid=$listid&substring=$substring&";
	include_once ng_dir."/include/navigation.php";
			
	$messages = ng_query("SELECT * FROM $sql_tbl[newsletter] WHERE ".$search_condition." 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('news');
require_once "./footer.php";

$output=str_replace(array('<!--<!--<!---->','<!--<!---->','<!---->'),array('','',''),ob_get_contents());
ob_end_clean();
echo $output;
flush;
exit;
?>