<!--
whilvydy 新闻发布系统
-->

<%@ page contentType="text/html; charset=GB2312" language="java" import="java.sql.*" errorPage="" %>
<%@ include file = "func/parameter.jsp" %>
<%@ page import="java.io.*" %> 
<%@ page import="java.util.*" %>
<jsp:useBean id="UserBean" scope="page" class="net.jspcn.db.DbConnect" />
<jsp:useBean id='oMD5' scope='page' class='net.jspcn.tool.MD5'/>
<jsp:useBean id='StrTool' scope='page' class='net.jspcn.tool.StringProcess'/>

<%

if (Integer.parseInt((String) session.getValue("user_power"))<9999)
response.sendRedirect("login.jsp");


boolean isedit = false; 	//是否在编辑状态
int color = 0;		//表格颜色
int user_id;
String sql;
ResultSet rs,rs1;
int intPageCount,intPageSize,intCurrentPage,intRowCount,i;
intPageSize = param[1];
i=0;

//out.println(request.getParameter("action"));

if("edit".equalsIgnoreCase(request.getParameter("action")))
    isedit=true;

if(request.getParameter("user_id")==null)
	user_id = 1;
else
	user_id = Integer.parseInt(request.getParameter("user_id").trim());

    
UserBean.openConnection();

//************************************修改用户**************************************
if("modify".equalsIgnoreCase(request.getParameter("action")))
{
	String user_account=request.getParameter("user_account").trim();
	String user_name=request.getParameter("user_name").trim();
	String user_password=oMD5.getMD5ofStr(request.getParameter("user_password").trim());
	String user_email=request.getParameter("user_email").trim();
	String user_mobile=request.getParameter("user_mobile").trim();
	String user_qq=request.getParameter("user_qq").trim();
	int user_power=Integer.parseInt(request.getParameter("user_power").trim());	
	if(user_account.length()>=2&&user_name.length()>=2)
	{
	sql = "update "+user_table+" set user_account = '"+user_account+"',user_name = '"+user_name+"',user_password='"+user_password+"',user_email='"+user_email+"',user_mobile='"+user_mobile+"',user_qq='"+user_qq+"',user_power="+user_power+" where user_id = "+user_id;
	UserBean.executeQuery(sql);
	//log process	
	String sql_in = "insert into "+logrecord_table+" (logrecord_id,user_name,operation_time,logrecord_operation) values('','"+session.getValue("user_name")+"',now(),'change user name: "+user_name+",user_id: "+user_id+"')";
	UserBean.executeUpdate(sql_in);
	}
}


//************************************添加用户**************************************
if("add".equalsIgnoreCase(request.getParameter("action")))
{
	//out.println("hello");
	String user_account=request.getParameter("user_account").trim();
	String user_name=request.getParameter("user_name").trim();
	String user_password=oMD5.getMD5ofStr(request.getParameter("user_password").trim());
	String user_email=request.getParameter("user_email").trim();
	String user_mobile=request.getParameter("user_mobile").trim();
	String user_qq=request.getParameter("user_qq").trim();
	int user_power=Integer.parseInt(request.getParameter("user_power").trim());	
	if(user_account.length()>=2&&user_name.length()>=2)
	{
	sql = "insert into "+user_table+" (user_account,user_name,user_password,user_email,user_mobile,user_qq,user_power) values('"+user_account+"','"+user_name+"','"+user_password+"','"+user_email+"','"+user_mobile+"','"+user_qq+"',"+user_power+")";
	UserBean.executeQuery(sql);
	//log process	
	String sql_in = "insert into "+logrecord_table+" (logrecord_id,user_name,operation_time,logrecord_operation) values('','"+session.getValue("user_name")+"',now(),'add user name: "+user_name+"')";
	UserBean.executeUpdate(sql_in);
	}
}


//************************************添加用户**************************************
if("delete".equalsIgnoreCase(request.getParameter("action")))
{
	sql = "delete from "+user_table+" where user_id = "+user_id+"";
	UserBean.executeQuery(sql);

	//log process	
	String sql_in = "insert into "+logrecord_table+" (logrecord_id,user_name,operation_time,logrecord_operation) values('','"+session.getValue("user_name")+"',now(),'delete user id: "+user_id+"')";
	UserBean.executeUpdate(sql_in);
}
%>


<%@ include file = "func/header.jsp" %>

<body>
<div align=center>
用户管理
<br>
<table width="90%"  border="1" cellspacing="0" cellpadding="0"  bordercolor="#00CC66"  borderColorDark="#FFFFFF" borderColorLight="#00CC66">
      <tr> 
    <td width="9%"> 
      <div align="center">用户编号</div>
    </td>
    <td width="13%"> 
      <div align="center">用户帐号</div>
    </td>
    <td width="13%"> 
      <div align="center">真实姓名</div>
    </td>
    <td width="13%"> 
      <div align="center">用户EMAIL</div>
    </td>
    <td width="13%"> 
      <div align="center">用户手机</div>
    </td>
    <td width="13%"> 
      <div align="center">用户QQ</div>
    </td>
    <td width="13%"> 
      <div align="center">用户权限</div>
    </td>
    <td width="13%"> 
      <div align="center">操    作</div>
    </td>
   </tr>
<%
	if(request.getParameter("page")==null)
		intCurrentPage = 1;
	else
	{
		intCurrentPage = Integer.parseInt(request.getParameter("page"));
		if(intCurrentPage<1) intCurrentPage = 1;
	}									//得到当前页数
	
	sql = "select * from "+user_table+" where user_id!=1";
	//sql = "select * from user";
	rs = UserBean.executeQuery(sql);
	rs.last();
	intRowCount = rs.getRow();
	intPageCount = (intRowCount+intPageSize-1)/intPageSize;
	//out.print("intPageCount"+intPageCount);
	if(intCurrentPage>intPageCount) intCurrentPage=intPageCount;		//对当前页数的控制
		
	if(intPageCount>0)
	{	
	rs.absolute((intCurrentPage-1)*intPageSize+1);	
	//for(color=0,i=0;i<intPageSize&&!rs.isAfterLast();color++,i++)

	do {
%>
  <tr> 
    <td width="9%"> 
      <div align="center"><%=rs.getString("user_id")%></div>
    </td>
    <td width="13%"> 
      <div align="center"><%=rs.getString("user_account")%></div>
    </td>
    <td width="13%"> 
      <div align="center"><%=rs.getString("user_name")%></div>
    </td>
    <td width="13%"> 
      <div align="center"><%=rs.getString("user_email")%>&nbsp;</div>
    </td>
    <td width="13%"> 
      <div align="center"><%=rs.getString("user_mobile")%>&nbsp;</div>
    </td>
    <td width="13%"> 
      <div align="center"><%=rs.getString("user_qq")%>&nbsp;</div>
    </td>
    <td width="13%"> 
      <div align="center"><%=rs.getString("user_power")%></div>
    </td>
    <td width="13%"> 
      <div align="center"><a href="user_man.jsp?action=edit&user_id=<%=rs.getString("user_id")%>">编辑</a>&nbsp;<a href="user_man.jsp?action=delete&user_id=<%=rs.getString("user_id")%>">删除</a></div>
    </td>
   </tr>
<%	
	color++;
	i++;
	}
	while(rs.next()&&i<intPageSize);
	}
%>
</table>
<br>
<%
	if(intCurrentPage == 1) { 
		%> 首页 前页 <% }
	else
		out.println("<a href='user_man.jsp?page=1'>首页</a> <a href='user_man.jsp?page="+(intCurrentPage-1)+"'>前页</a> ");
	
	if(intCurrentPage==intPageCount) {
		%>后页 末页<% }
	else
		out.println("<a href='user_man.jsp?page="+(intCurrentPage+1)+"'>后页</a> <a href='user_man.jsp?page="+intPageCount+"'>末页</a> ");

%>
<hr size=0 width=100%>

<%
if(isedit==true)
	{
	       sql = "select * from "+user_table+" where user_id="+user_id;
	       rs = UserBean.executeQuery(sql);
	       rs.next();
	}
%>

<form action="user_man.jsp" method=post name=form1 onsubmit="return formCheck()">
    <input type="Hidden" name="action" value="<%if(isedit==true) out.print("modify"); else out.print("add"); %>">
<%if(isedit==true)
     { 
%>
    <input type="Hidden" name="user_id" value="<%=user_id%>">
<%
	}
%>

    <table width="80%"  border="1" cellspacing="0" cellpadding="2"  bordercolor="#00CC66"  borderColorDark="#FFFFFF" borderColorLight="#00CC66">
	<tr> 
        	<td><div align="right">用户账号</div></td>
        	<td><div align="left"><input name="user_account" type="text"  class=input size="12" maxlength=50  value="<% if(isedit==true) out.print(rs.getString("user_account")); %>"></div></td>
        	<td><div align="right">真实姓名</div></td>
        	<td><div align="left"><input name="user_name" type="text"  class=input size="12" maxlength=50  value="<% if(isedit==true) out.print(rs.getString("user_name")); %>"></div></td>
	</tr>
	<tr> 
        	<td><div align="right">用户密码</div></td>
        	<td><div align="left"><input name="user_password" type="password"  class=input size="12" maxlength=50  value="123456"></div></td>
        	<td><div align="right">用户EMAIL</div></td>
        	<td><div align="left"><input name="user_email" type="text"  class=input size="12" maxlength=80  value="<% if(isedit==true) out.print(rs.getString("user_email")); %>">&nbsp;</div></td>
	</tr>
	<tr> 
        	<td><div align="right">用户手机</div></td>
        	<td><div align="left"><input name="user_mobile" type="text"  class=input size="12" maxlength=13  value="<% if(isedit==true) out.print(rs.getString("user_mobile")); %>">&nbsp;</div></td>
        	<td><div align="right">用户OICQ</div></td>
        	<td><div align="left"><input name="user_qq" type="text"  class=input size="12" maxlength=13  value="<% if(isedit==true) out.print(rs.getString("user_qq")); %>">&nbsp;</div></td>
	</tr>
	<tr> 
        	<td><div align="right">用户权限</div></td>
        	<td><div align="left">
        	<select name="user_power" class=input>
        	<option value="9999">系统管理员</option>
        	<option value="999">系统审核员</option>
        	<%
        	String sql1 = "select * from "+type_table;
        	rs1 = UserBean.executeQuery(sql1);
		for(i=0;rs1.next();i++)
        	{        	
        	%>
        	<option value="<%=rs1.getString("type_id")%>"><%=rs1.getString("type_name")%>审核员</option>
        	<option value="<% out.print(Integer.parseInt(rs1.getString("type_id"))+1000);%>"><%=rs1.getString("type_name")%>管理员</option>
        	<%
        	}
        	//while(rs1.next());
        	%>
        	</div></td>
        	<td><div align="right">&nbsp;</div></td>
        	<td><div align="left">&nbsp;</div></td>
	</tr>
  </table>
  <br>
  <input type=submit value="确 定" class=button>&nbsp;&nbsp;&nbsp;&nbsp;<input type=reset value="重 置" class=button>
 </div>
</form>

<SCRIPT language=JavaScript>
         function formCheck()
	{
		if(document.form1.user_account.value=="")
            	{
            		alert("请输入您的帐号!");
			document.form1.user_account.focus();
			return false;
		}     
		
		if(document.form1.user_name.value=="")
		{
			alert("请输入您的姓名!");
			document.form1.user_name.focus();
			return false;
		}
		
		if(document.form1.user_password.value=="")
		{
			alert("请输入您的用户密码!");
			document.form1.user_password.focus();
			return false;
		}
		
		if(document.form1.user_email.value=="")
		{
			alert("请输入您的用户EMAIL!");
			document.form1.user_email.focus();
			return false;
		}
         }
</SCRIPT>

<%@ include file = "func/footer.jsp" %>