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

if (empty($mode)) $mode = "";
if ($mode == "gb_audit") {
	$gb_audit = ($gb_audit != "")?$gb_audit:"Y";
	db_query("UPDATE $sql_tbl[guestbook] SET ifshow='$gb_audit' WHERE id='$gb_id'");
	ng_header_location("ng_gb.php?sortby=$sortby&sortorder=$orderby&page=$page");
}

if ($REQUEST_METHOD == "POST") {
#
# Process the POST request
#
	if ($mode == "delete") {
	#
	# Delete reviews
	#
		if ($to_delete) {
			$deleted = false;
			foreach ($to_delete as $key=>$value) {
				db_query ("DELETE FROM $sql_tbl[guestbook] WHERE id='$key'");
				$deleted = true;
			}
		}
	}
	
	if ($mode == "update") {
	
		if ($gb_reply) {
			foreach ($gb_reply as $key=>$value)
			{
				db_query ("UPDATE $sql_tbl[guestbook] SET reply='$value' WHERE id='$key'");
			}
		}
		if ($gb_content) {
			foreach ($gb_content as $key=>$value)
			{
				db_query ("UPDATE $sql_tbl[guestbook] SET content='$value' WHERE id='$key'");
			}
		}
	}
	showmsg("更新成功","ng_gb.php?sortby=$sortby&sortorder=$orderby&page=$page");

} # /if ($REQUEST_METHOD == "POST")

# sortorder & sortby
if ($sortorder == 0) {
	$_sortorder = " DESC ";
} else {
	$sortorder = 1;
	$_sortorder = " ASC ";
}

if ($sortby == 'ifshow')
	$_sortby = " $sql_tbl[guestbook].ifshow ";
elseif ($sortby == 'login')
	$_sortby = " $sql_tbl[guestbook].login ";
else {
	$sortby = 'id';
	$_sortby = " $sql_tbl[guestbook].id ";
}
	
# prodcut reviews
$count_guest_book = ng_query_first_cell("SELECT COUNT(id) FROM $sql_tbl[guestbook]");

if($count_guest_book > 0){
				
	$objects_per_page = 30;
	$total_items = $count_guest_book;
	$total_nav_pages = ceil($total_items/$objects_per_page);
	if($page > $total_nav_pages)
		$page = $total_nav_pages;
	$pageurl = "ng_gb.php?sortby=$sortby&orderby=$orderby&page=$page&";
	include_once ng_dir."/include/navigation.php";
	$guest_book = ng_query ("SELECT $sql_tbl[guestbook].* FROM $sql_tbl[guestbook] ORDER BY $sortby $_sortorder LIMIT $first_page, $objects_per_page");
	
	$invsortorder = !$sortorder;
	$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('ng_gb');
require_once "./footer.php";

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