<?php
require('top.php');
require(R_P.'require/groupid.php');
InitGP(array('action','type','id',));
if ($action == 'admin') {
	$_SESSION['admin_groupid'] != 1 &&  Showmsg('authority');
	if ($type == 'del') {
		$sql = "select groupid FROM ".$db_tablepre."admin WHERE a_id='".$id."'";
		$authority_chk = sql_return($sql,3);
		$authority_chk['groupid'] <= $_SESSION['admin_groupid'] && Showmsg('authority');
		$sql = "DELETE FROM ".$db_tablepre."admin WHERE a_id='".$id."' and groupid>".$_SESSION['admin_groupid'];
		sql_return($sql) &&  Showmsg('post_Success');
	}else{
		$sql = "select * from ".$db_tablepre."admin inner join ".$db_tablepre."user on ".$db_tablepre."admin.u_id=".$db_tablepre."user.u_id ";
		//$sql .= WHERE ".$db_tablepre."user.u_name='".$name."'";
		$adminset = sql_return($sql);
	}


}

//添加管理
elseif ($action == 'addadmin'){
	$_SESSION['admin_groupid'] != 1 &&  Showmsg('authority');
	if ($type == 'up') {

		InitGP(array('admin_id','group_select'));
		empty_chk(array($admin_id,$group_select));

		$sql = "select * from ".$db_tablepre."admin where u_id='".$admin_id."'";
		sql_return($sql,3) && Showmsg('upadmin_err_1');

		$sql = "select * from ".$db_tablepre."user where u_id='".$admin_id."'";
		sql_return($sql,3) || Showmsg('upadmin_err_2');

		$sql = "INSERT INTO ".$db_tablepre."admin (u_id,groupid) VALUES ('".$admin_id."','".$group_select."')";
		sql_return($sql)  && Showmsg('post_Success');

	}
}
elseif ($action == 'up_admin'){
	$_SESSION['admin_groupid'] != 1 &&  Showmsg('authority');

	InitGP(array('admin_id','group_select','uid'));
	empty_chk(array($admin_id,$group_select));

	$sql = "select * from ".$db_tablepre."user WHERE u_id='".$uid."'";
	sql_return($sql,3) || Showmsg('upadmin_err_2');

	$sql_1 .= "u_id = '".$admin_id."'";
	$sql_1 .= "groupid = '".$group_select."'";

	$sql = "UPDATE ".$db_tablepre."admin  SET groupid='".$group_select."'  WHERE a_id='".$admin_id."'";
	sql_return($sql)  && Showmsg('post_Success');


}

elseif ($action == 'user'){

	$_SESSION['admin_groupid'] > 2 &&  Showmsg('authority');
	if ($type == 'del') {
		$sql = "select groupid FROM ".$db_tablepre."admin WHERE a_id='".$id."'";
		$authority_chk = sql_return($sql,3);
		$authority_chk['groupid'] <= $_SESSION['admin_groupid'] && Showmsg('authority');
		$sql = "DELETE FROM ".$db_tablepre."admin WHERE a_id='".$id."' and groupid>".$_SESSION['admin_groupid'];
		sql_return($sql) &&  Showmsg('post_Success');
	}else{
		$sql = "select * from ".$db_tablepre."user   ";
		//$sql .= WHERE ".$db_tablepre."user.u_name='".$name."'";
		$adminset = sql_return($sql);
	}
}


require PrintEot($self_template,'A');
echo footer();
?>