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

if($action == "del"){

	if($is_admin["admintype"] != 'Y'){
		echo "<script language=\"JavaScript\">\r\n"; 
		echo " alert(\"你无权执行此操作!\");\r\n"; 
		echo " history.go(-1);\r\n";echo "</script>"; 
		exit; 
	}
	
	$existing_admin = ng_query_first_cell("select count(aid) from $sql_tbl[admins] where admintype='Y'");
	if($existing_admin <= 1){
	
		echo "<script language=\"JavaScript\">\r\n"; 
		echo " alert(\"这是网站的最后一个管理员,不能删除!\");\r\n"; 
		echo " history.go(-1);\r\n";echo "</script>"; 
		exit; 
		
	}else{
		
		db_query("DELETE FROM $sql_tbl[admins] WHERE aid='$adminid'");
		showmsg("操作成功","ng_admin.php");
	}	
}
	
if ($REQUEST_METHOD == "POST") {

	if($is_admin["admintype"] != 'Y'){
		echo "<script language=\"JavaScript\">\r\n"; 
		echo " alert(\"你无权执行此操作!\");\r\n"; 
		echo " history.go(-1);\r\n";echo "</script>"; 
		exit; 
	}
		
	if(empty($nglogin)){
		echo "<script language=\"JavaScript\">\r\n"; 
		echo " alert(\"管理员帐号为空,请填写帐号!\");\r\n"; 
		echo " history.go(-1);\r\n";echo "</script>"; 
		exit; 
	}
	
	$adminsion = $qx1.','.$qx11.','.$qx12.','.$qx13.','.$qx14.','.$qx15.','.$qx16.','.$qx17.','.$qx18.','.
	$qx21.','.$qx22.','.$qx23.','.$qx24.','.$qx25.','.$qx26.','.$qx27.','.$qx28.','.
	$qx31.','.$qx32.','.$qx33.','.$qx34.','.$qx35.','.$qx36.','.$qx37.','.$qx38.','.
	$qx51.','.$qx52.','.$qx53.','.$qx54.','.$qx55.','.$qx56.','.$qx57.','.$qx58.','.
	$qx61.','.$qx62.','.$qx63.','.$qx64.','.$qx65.','.$qx66.','.$qx67.','.$qx68.','.
	$qx81.','.$qx82.','.$qx83.','.$qx84.','.$qx85.','.$qx86.','.$qx87.','.$qx88.','.
	$qx91.','.$qx92.','.$qx93.','.$qx94.','.$qx95.','.$qx96.','.$qx97.','.$qx98;


	if($action == "add"){
	
		$existing_user = ng_query_first_cell("select count(aid) from $sql_tbl[admins] where ngadmin=$nglogin ");
		if($existing_user){
			echo "<script language=\"JavaScript\">\r\n"; 
			echo " alert(\"输入的会员名已被使用,请选择其他的会员名\");\r\n"; 
			echo " history.go(-1);\r\n";echo "</script>"; 
			exit; 
		}
	
		if(empty($passwd1)){
			echo "<script language=\"JavaScript\">\r\n"; 
			echo " alert(\"密码为空,请填写密码\");\r\n"; 
			echo " history.go(-1);\r\n";echo "</script>"; 
			exit; 
		}
		if(empty($passwd2)){
			echo "<script language=\"JavaScript\">\r\n"; 
			echo " alert(\"确认密码为空,请填写确认密码\");\r\n"; 
			echo " history.go(-1);\r\n";echo "</script>"; 
			exit; 
		}
		if($passwd1 != $passwd2){
			echo "<script language=\"JavaScript\">\r\n"; 
			echo " alert(\"两次输入的密码不一致,请正确填写\");\r\n"; 
			echo " history.go(-1);\r\n";echo "</script>"; 
			exit; 
		}
		$crypted = md5($passwd1);
		db_query("INSERT INTO $sql_tbl[admins] (ngadmin,admintype,password,email,first_login,last_login,status, realname, phone, cellphone, msnqq, referer, adminsion, admintxt) VALUES ('$nglogin','$admintype','$crypted','$email','".time()."','".time()."','Y','$realname','$phone','$cellphone','$msnqq','".$_COOKIE['ngadmin']."','$adminsion','$admintxt')");

		db_query("INSERT INTO $sql_tbl[admins] (ngadmin,admintype,password,email,first_login,last_login,status, realname, phone, cellphone, msnqq, referer, adminsion, admintxt) VALUES ('$nglogin','$admintype','$crypted','$email','".time()."','".time()."','Y','$realname','$phone','$cellphone','$msnqq','".$_COOKIE['ngadmin']."','$adminsion','$admintxt')");
		
		showmsg("添加成功","ng_admin.php");
	
	}elseif($action == "update"){
		$crypted = md5($passwd1);
		if($passwd1 != '' && $passwd2 != ''){
		
			if ($passwd1 != $passwd2){
				echo "<script language=\"JavaScript\">\r\n"; 
				echo " alert(\"两次输入的密码不一直，请正确操作\");\r\n"; 
				echo " history.go(-1);\r\n";echo "</script>"; 
				exit; 
			}else{
				$changpass = "password = '$crypted', ";
			}
		
		}else{
			$changpass = '';
		}
		db_query("UPDATE $sql_tbl[admins] SET $changpass ngadmin = '$nglogin', admintype = '$admintype', email = '$email', status = '$status', realname = '$realname', phone = '$phone', cellphone = '$cellphone', msnqq = '$msnqq', adminsion = '$adminsion', admintxt = '$admintxt' WHERE aid='$adminid'");
		
		showmsg("修改成功","ng_admin.php?adminid=$adminid&mode=update");
	}
}
$edit_admin = '';
$adminpermission = array();
$admins = ng_query("SELECT * FROM $sql_tbl[admins] order by aid desc");
if($_GET['adminid']){
	$edit_admin = ng_query_first("SELECT * FROM $sql_tbl[admins] WHERE aid = '$adminid'");
}

$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_admin');
require_once "./footer.php";

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