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

if (empty($uid) or empty($userinfo)) {
	$strmess = urlencode("请先登录");
	ng_header_location("login.php?strmess=$strmess");
}

$metawords = $netgou["meta_keywords"];
$metaintro = $netgou["meta_descr"];
$titlename = $netgou["web_name"];

$txturl = "";
$txtsou = "";

if($mode == "update" && $REQUEST_METHOD == "POST"){

	$hxname = addslashes($_POST["hxname"]);
	$hxsex = addslashes($_POST["hxsex"]);
	$hxage = addslashes($_POST["hxage"]);
	$hxaddress = addslashes($_POST["hxaddress"]);
	$hxgd = addslashes($_POST["hxgd"]);
	$msnqq = addslashes($_POST["msnqq"]);
	$email = addslashes($_POST["email"]);
	
	if($hxname == ''){
		echo "<script language=\"JavaScript\">\r\n"; 
		echo " alert(\"施主名字不能为空，请填写施主名字！\");\r\n"; 
		echo " history.go(-1);\r\n";echo "</script>"; 
		exit; 
		
	}elseif($hxage == ''){
		echo "<script language=\"JavaScript\">\r\n"; 
		echo " alert(\"施主年龄不能为空，请填写施主年龄！\");\r\n"; 
		echo " history.go(-1);\r\n";echo "</script>"; 
		exit; 
		
	}elseif($hxaddress == ''){
		echo "<script language=\"JavaScript\">\r\n"; 
		echo " alert(\"施主地址不能为空，请填写施主地址！\");\r\n"; 
		echo " history.go(-1);\r\n";echo "</script>"; 
		exit; 
	}
	
	if($passwd1 <> ''){
		
		if($passwd1 != $passwd2){
			echo "<script language=\"JavaScript\">\r\n"; 
			echo " alert(\"两次输入的密码不一致，请重新输入！\");\r\n"; 
			echo " history.go(-1);\r\n";echo "</script>"; 
			exit; 
		}elseif(md5($oldpass) != $userinfo["password"]){
			echo "<script language=\"JavaScript\">\r\n"; 
			echo " alert(\"旧密码错误,请正确输入！\");\r\n"; 
			echo " history.go(-1);\r\n";echo "</script>"; 
			exit; 
		}else{
			$newpass = md5($passwd1);
			$strpass = ",password = '$newpass'";
			$ispass = "Y";
			
		}		
	}
	
	db_query("UPDATE $sql_tbl[users] SET hxname='$hxname', hxsex = '$hxsex', hxage = '$hxage', hxaddress = '$hxaddress', hxgd = '$hxgd', msnqq = '$msnqq', email = '$email' $strpass WHERE uid='$uid'");
	
	if($ispass == "Y"){
	
		$uid = '';
		$username = '';
		setcookie("uid", "", 0,"/",""); 
		setcookie("username", "", 0,"/",""); 
		setcookie("ngpassword", "", 0,"/",""); 
		$strmess = urlencode("密码更新成功，请用新密码重新登录");
		ng_header_location("login.php?strmess=$strmess");
		
	}else{
	
		$strmess = urlencode("更新成功");
		ng_header_location("users.php?strmess=$strmess");
	}
			
}elseif ($mode == "yichao"){
	
	$uid && $txtsou .= " WHERE $sql_tbl[jwchao].uid='$uid'";
	$total_items = ng_query_first_cell("SELECT COUNT($sql_tbl[jwchao].jcid) FROM $sql_tbl[jwchao] $txtsou");
	
	if ($total_items > 0) {
		
		$pageurl = "users.php?mode=yichao&uid=$uid".$txturl;
		$objects_per_page = 20;
			
		$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";
	
		$yichao = ng_query("SELECT $sql_tbl[jwchao].jcid, $sql_tbl[jwchao].jwid, $sql_tbl[jwchao].jwname, $sql_tbl[jwchao].jcshijian FROM $sql_tbl[jwchao] $txtsou ORDER BY $sql_tbl[jwchao].jcid DESC LIMIT $first_page, $objects_per_page");
			
		$first_item = $first_page+1;
		$last_item =  min($first_page+$objects_per_page, $total_items);
	}
	

}elseif ($mode == "gongde"){

	$userzl = ng_query_first("select $sql_tbl[users].* from $sql_tbl[users] where uid = '$uid' AND status = 'Y'");
	
	$uid && $txtsou .= " WHERE $sql_tbl[gongde].uid='$uid'";
	$total_items = ng_query_first_cell("SELECT COUNT($sql_tbl[gongde].gdid) FROM $sql_tbl[gongde] $txtsou");
	
	if ($total_items > 0) {
		
		$pageurl = "users.php?mode=gongde&uid=$uid".$txturl;
		$objects_per_page = 20;
			
		$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";
	
		$gongde = ng_query("SELECT $sql_tbl[gongde].gdid, $sql_tbl[gongde].uid, $sql_tbl[gongde].username, $sql_tbl[gongde].modetype, $sql_tbl[gongde].oldgd, $sql_tbl[gongde].gdnum, $sql_tbl[gongde].newgd, $sql_tbl[gongde].gddtm FROM $sql_tbl[gongde] $txtsou ORDER BY $sql_tbl[gongde].gdid DESC LIMIT $first_page, $objects_per_page");
	
		$first_item = $first_page+1;
		$last_item =  min($first_page+$objects_per_page, $total_items);
	}
	
}else{

	$userzl = ng_query_first("select $sql_tbl[users].* from $sql_tbl[users] where uid = '$uid' AND status = 'Y'");

}


$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('users');
require_once PrintTemp('footer');
$output=str_replace(array('<!--<!--<!---->','<!--<!---->','<!---->'),array('','',''),ob_get_contents());
ob_end_clean();
echo $output;
flush;
exit;
break;
?>