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

<%@ page contentType="text/html; charset=GB2312" language="java" import="java.sql.*" %>
<%@ include file = "func/parameter.jsp" %>
<%@ page import="java.io.*" %> 
<%@ page import="java.util.*" %>
<jsp:useBean id="TypeBean" 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'/>

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

boolean isedit = false; 	//是否在编辑状态
int type_id;
String sql;
ResultSet rs;
int intPageCount,intPageSize,intCurrentPage,intRowCount,i;
intPageSize = param[2];
i=0;


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

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

    
TypeBean.openConnection();

//************************************修改用户**************************************
if("modify".equalsIgnoreCase(request.getParameter("action")))
{
	String type_name=request.getParameter("type_name").trim();
	String type_describ=request.getParameter("type_describ").trim();
	if(type_name.length()>=2)
	{
	sql = "update "+type_table+" set type_name = '"+type_name+"',type_describ = '"+type_describ+"' where type_id = "+type_id;
	TypeBean.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(),'modify type name to: "+type_name+" type_id: "+type_id+"')";
	TypeBean.executeUpdate(sql_in);
	}
}


if("pass".equals(request.getParameter("action")))
{
	String type_audit=request.getParameter("type_audit").trim();
	sql = "update "+type_table+" set type_audit="+Integer.parseInt(type_audit)+" where type_id="+type_id;
	TypeBean.executeQuery(sql);
	if("0".equals(type_audit)) {
	sql = "update "+board_table+" set board_audit="+Integer.parseInt(type_audit)+" where type_id="+type_id;
	TypeBean.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 type status to "+type_audit+",type_id: "+type_id+"')";
	TypeBean.executeUpdate(sql_in);
}

//************************************添加用户**************************************
if("add".equalsIgnoreCase(request.getParameter("action")))
{
	String type_name=request.getParameter("type_name").trim();
	String type_describ=request.getParameter("type_describ").trim();
	String news_audit=request.getParameter("type_audit").trim();
	if(type_name.length()>=2)
	{
	sql = "insert into "+type_table+" values('','"+type_name+"',"+Integer.parseInt(news_audit)+",'"+type_describ+"')";
	TypeBean.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 type name: "+type_name+"')";
	TypeBean.executeUpdate(sql_in);
	}
}


//************************************删除版块**************************************
if("delete".equalsIgnoreCase(request.getParameter("action")))
{
	sql = "delete from "+type_table+" where type_id = "+type_id+"";
	TypeBean.executeQuery(sql);	
	
	sql = "delete from "+board_table+" where type_id = "+type_id+"";
	TypeBean.executeQuery(sql);

	sql = "delete from "+news_table+" where type_id = "+type_id+"";
	TypeBean.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 type id: "+type_id+"')";
	TypeBean.executeUpdate(sql_in);
}
%>


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

<body>
<div align=center>
版面管理
<br>
<table width="80%"  border="1" cellspacing="0" cellpadding="0"  bordercolor="#00CC66"  borderColorDark="#FFFFFF" borderColorLight="#00CC66">
      <tr> 
    <td width="15%"> 
      <div align="center">版面名称</div>
    </td>
    <td width="25%"> 
      <div align="center">版面描述</div>
    </td>
    <td width="30%"> 
      <div align="center">版面描述</div>
    </td>
    <td width="30%"> 
      <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 "+type_table;
	rs = TypeBean.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="15%"> 
      <div align="center"><%=rs.getString("type_id")%></div>
    </td>
    <td width="25%"> 
      <div align="center"><%=rs.getString("type_name")%></div>
    </td>
    <td width="30%"> 
      <div align="center"><%=rs.getString("type_describ")%></div>
    </td>
    <td width="30%"> 
      <div align="center">
      <a href="type_man.jsp?action=pass&type_id=<%=rs.getString("type_id")%>&type_audit=<% if(Integer.parseInt(rs.getString("type_audit"))==1) out.print("0"); else out.print("1"); %>&page=<%=intCurrentPage%>"><% if(Integer.parseInt(rs.getString("type_audit"))==1) { %>取消审核 <% } else { %>通过审核 <% } %></a>&nbsp;
      <a href="type_man.jsp?action=edit&type_id=<%=rs.getString("type_id")%>&page=<%=intCurrentPage%>">编辑</a>&nbsp;
      <a href="type_man.jsp?action=delete&type_id=<%=rs.getString("type_id")%>&page=<%=intCurrentPage%>">删除</a></div>
    </td>
   </tr>
<%	
	i++;
	}
	while(rs.next()&&i<intPageSize);
	}
%>
</table>
<br>
<%
	if(intCurrentPage == 1) { 
		%> 首页 前页 <% }
	else
		out.println("<a href='type_man.jsp?page=1'>首页</a> <a href='type_man.jsp?page="+(intCurrentPage-1)+"'>前页</a> ");
	
	if(intCurrentPage==intPageCount) {
		%>后页 末页<% }
	else
		out.println("<a href='type_man.jsp?page="+(intCurrentPage+1)+"'>后页</a> <a href='type_man.jsp?page="+intPageCount+"'>末页</a> ");

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

<%
if(isedit==true)
	{
	       sql = "select * from "+type_table+" where type_id="+type_id;
	       rs = TypeBean.executeQuery(sql);
	       rs.next();
	}
%>

<form action="type_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="type_id" value="<%=type_id%>">
<%
	}
%>

    <table width="50%"  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="type_name" type="text"  class=input size="12" maxlength=13  value="<% if(isedit==true) out.print(rs.getString("type_name")); %>"></div></td>
	</tr>
	<tr> 
        	<td><div align="right">版面描述</div></td>
        	<td><div align="left"><input name="type_describ" type="text"  class=input size="12" maxlength=13  value="<% if(isedit==true) out.print(rs.getString("type_describ")); %>"></div></td>
	</tr>
	<tr> 
        	<td><div align="right">版面状态</div></td>
        	<td><div align="left">
        		<input type="radio" name="type_audit" value=1 checked>已审核&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        		<input type="radio" name="type_audit" value=0>未审核  
        	</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.type_name.value=="")
            	{
            		alert("请输入版面名称!");
			document.form1.type_name.focus();
			return false;
		}     

         }
</SCRIPT>


<%
TypeBean.close();
%>
<%@ include file = "func/footer.jsp" %>