<%@page contentType="text/html;charset=GBK"%>
<%@page import="java.sql.*" errorPage="/public/error.jsp"%>
<%@ include file="/public/checkvalidadmin.jsp"%>
<%@ include file="/public/checkvalidadmin8.jsp"%>
<jsp:useBean id="conn" scope="page" class="test.ConnOracle"/>

<%!
ResultSet rs = null;

String username = "";
String truename = "";
String password = "";
String priv = "";
String oper = "";
String sql = "";

int result = 0;
%>

<html>

<head>
	<title>权限管理</title>
	<link rel="stylesheet" href="../public/style.css">
</head>

<Body class="ss">
<center>

<%
request.setCharacterEncoding("GBK");
username = request.getParameter("username");
truename = request.getParameter("truename");
password = request.getParameter("password");
priv     = request.getParameter("priv");
oper     = request.getParameter("oper");

// 避免用户直接在浏览器地址栏输入地址所产生的Exception
if(username==null || username.equals("")) {
    out.println("<center>");
	out.println("请进行合法操作！");
	out.println("</center>");
	return;
}
try{
	rs = conn.executeQuery("select * from test_admin where loginname='"+username+"'");
	if(!rs.next()) {
		out.println("<center>");
		out.println("数据库没有用户名为" + username + "的用户！<br>");
		out.println("单击这里<a href=javascript:history.back()>返回</a><br>");
		out.println("</center>");
	} else {
		if(oper.equals("修改")) {
			sql = "update test_admin set PRIVILEDGE=" + priv ;
			sql+= ",truename='"+ truename + "',";
			sql+= "password='" + password + "' ";
			sql+= "where loginname='" + username + "'";
        } else if(oper.equals("删除")){
		    sql = "delete from test_admin ";
			sql+= "where loginname='" + username + "'";
		}
		result = conn.executeUpdate( sql );
	}
}catch(Exception ee) {
	out.println("<center>");
	out.println("管理员账号信息更新失败！<br><br>");
	out.println("请将下列信息告知管理员<br><br>");
	out.println(ee.toString() + "<br><br>");
	out.println("单击这里<a href=javascript:history.back()>返回</a><br>");
	out.println("</center>");
}
%>
<jsp:forward page="accountmanager.jsp"/>
</center>
</Body>

</html>