<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%> 
<!--#include file="../../conn/conn.asp" -->
<!--#include file="../../Inc/Commoncode.asp" -->
<!--#include file="../checkvalid.asp" -->
<%
dim wid
wid=request("wid")
if wid="" or not Isnumeric(wid) then wid=10
If Not FRAdminLevel(307&wid) Then
	Call ErrorMsg()
End If
Dim action
Dim typeid
typeid=request.QueryString("typeid")
action=request.QueryString("action")
select case action
	case "del"
		call del()
	case "typeadd"
		call typesave()
end select
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>HR资讯类别管理</title>
<link href="../css/style<%=sk%>.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="../inc/input.js"></script>
</head>
<script type="text/javascript">
function check()
{
if (document.form2.typenames.value=="")
{
	alert("请输入类别名称！");
	document.form2.typenames.focus();
	return false;
}
if (document.form2.typeorder.value=="")
{
	alert("请输入类别排序！");
	document.form2.typeorder.focus();
	return false;
}
var objv = document.form2.typeorder.value;
var pattern = /^([0-9])+$/;
flag = pattern.test(objv);
if(!flag)
{
	alert("类别排序只能为数字!");
	document.form2.typeorder.focus();
	return false; 
} 
}
</script>
<body>
<table width="98%" border="0" cellspacing="1" cellpadding="2" align=center class="tableBorder"> 
  <tr> 
     <th height=25><%=ChannelNametitle(wid)%>管理</th> 
  </tr> 
  <tr>
    <td height=25><span class="bodytitle"><font color="ff6600"><b class="style1">　管理选项</b></font></span>： <a href="newsadd.asp?wid=<%=wid%>">添加<%=ChannelNametitle(wid)%></a> | <a href="index.asp?wid=<%=wid%>">管理<%=ChannelNametitle(wid)%></a> | <a href="newssort.asp?wid=<%=wid%>#type">添加信息类别</a> | <a href="newssort.asp?wid=<%=wid%>">管理信息类别</a> | [<a href="javascript:location.reload()">刷新页面</a>] </td>
  </tr>
</table>

<table width="98%" border="0" cellspacing="1" cellpadding="2" align=center class="tableBorder mt6"> 
  <tr>
  <th colspan="5"><%=ChannelNametitle(wid)%>类别管理</td>  </tr>
  <tr align="center">
    <td width="8%"><b>编号</b></td>
    <td width="25%"><b>类别名称</b></td>
    <td width="17%"><b>显示顺序</b></td>
    <td width="33%"><b>添加时间</b></td>
    <td width="17%"><b>操作</b></td>
  </tr>
<%
sql="select * from JOB_NewsSort where S_cid="&wid&" order by S_order asc,S_id desc"
set rs=Server.CreateObject("ADODB.RecordSet")
rs.open sql,conn,1,1
if not rs.eof then
for i=1 to rs.recordcount
%>
  <tr>
    <td align="center" bgcolor="#FFFFFF"><%=rs("S_id")%></td>
    <td bgcolor="#FFFFFF">&nbsp;&nbsp; &nbsp;<img src="../images/-.gif" width="15" height="15" /><%=rs("S_name")%></td>
    <td align="center" bgcolor="#FFFFFF"><%=rs("S_order")%></td>
    <td align="center" bgcolor="#FFFFFF"><%=rs("S_addtime")%></td>
    <td align="center" bgcolor="#FFFFFF">&nbsp; <a href="newssort.asp?wid=<%=wid%>&typeid=<%=rs("S_id")%>" title="修改类别">修改</a>┆<a href='javascript:if(confirm("确定要删除吗?删除将同时删除该类别的所有文章!!!"))location.href="newssort.asp?action=del&wid=<%=wid%>&typeid=<%=rs("S_id")%>"' title="删除类别">删除</a></td>
  </tr>
<%
rs.movenext
next
else
%>
<tr>
  <td colspan="6" align="center">还没有添加类别  </tr>
<%
end if
rs.close
set rs=nothing
%>
</table>
<%
typeid=request.QueryString("typeid")
if typeid<>"" and Isnumeric(typeid)=true then
	sql="select * from JOB_NewsSort where S_id="&typeid&" and S_cid="&wid&""
	set rs=Server.CreateObject("ADODB.RecordSet")
	rs.open sql,conn,1,1
	if not rs.eof then
		typenames=rs("S_name")
		typeorder=rs("S_order")
	end if
	rs.close
	set rs=nothing
else
	'查类别的最后一个排序序号
	sql="select top 1 S_order from JOB_NewsSort where S_cid="&wid&" order by S_order desc"
	set rs=Server.CreateObject("ADODB.RecordSet")
	rs.open sql,conn,1,1
	if not rs.eof then
		typeorder=rs("S_order")+1
	else
		typeorder=0
	end if
	rs.close
	set rs=nothing	
end if
%>
<a name="type" id="type"></a><table width="98%" border="0" cellspacing="1" cellpadding="2" align=center class="tableBorder mt6">
  <tr>
    <th colspan="2"><%=ChannelNametitle(wid)%>类别<%if typeid="" then%>添加<%else%>修改<%end if%></th>
  </tr>
<form name="form2" action="newssort.asp?wid=<%=wid%>&action=typeadd&typeid=<%=typeid%>" method="post" onsubmit="return check();">
  <tr>
    <td align="right" width="18%"><b>类别名称：</b></td>
    <td>&nbsp;<input name="typenames" type="text" id="typenames" value="<%=typenames%>" /></td>
  </tr>
  <tr>
    <td align="right"><b>显示顺序：</b></td>
    <td>&nbsp;<input name="typeorder" type="text" id="typeorder" value="<%=typeorder%>" size="10" /> *请填写数字（数字越小排在越前面）</td>
  </tr>
  <tr>
  	<td align="right">&nbsp;</td>
    <td>&nbsp;<%if typeid="" then%><input type="submit" name="Submit3" value="新增类别" class="inputs" /><%else%><input type="submit" name="Submit3" value="修改类别" class="inputs" /><%end if%></td>
    </tr>
</form>
</table>
<!--#include file="../inc/copy.asp" -->
</body>
</html>
<%
'保存类别数据
Sub typesave()
	typenames=trim(request.Form("typenames"))
	typeorder=trim(request.Form("typeorder"))
	'频道类别名称是否已经存在
	if typeid="" then
		sql="select S_id from JOB_NewsSort where S_name='"&typenames&"' and S_cid="&wid&""
	else
		sql="select S_id from JOB_NewsSort where S_name='"&typenames&"' and S_cid="&wid&" and S_id<>"&typeid&""
	end if
	set rs=Server.CreateObject("ADODB.RecordSet")
	rs.open sql,conn,1,1
	if not rs.eof then
		response.Write("<script>alert(""类别名称["&typenames&"]已经存在!""),history.go(-1);</script>")
		response.End()
	end if
	rs.close
	set rs=nothing
	
	if typeid="" then
		sql="Insert into JOB_NewsSort(S_name,S_cid,S_addtime,S_order) values('"&typenames&"','"&wid&"','"&now()&"','"&typeorder&"')"
	else
		sql="update JOB_NewsSort set S_name='"&typenames&"',S_cid='"&wid&"',S_addtime='"&now()&"',S_order='"&typeorder&"' where S_id="&typeid
	end if
	conn.execute(sql)
	if typeid="" then
		response.Write("<script>alert(""新增类别完成！""),location.href(""newssort.asp?wid="&wid&""");</script>")
	else
		response.Write("<script>alert(""修改类别完成！""),location.href(""newssort.asp?wid="&wid&""");</script>")
	end if
	response.End()
End Sub

Sub Del()
	if typeid<>"" and Isnumeric(typeid) then
		'删除更该类别的文章
		conn.execute("Delete From JOB_News where N_sid="&typeid&" and N_cid="&wid&"")
		'删除该类别
		conn.execute("Delete From JOB_NewsSort where S_id="&typeid&" and S_cid="&wid&"")
	end if
	response.Redirect("newssort.asp?wid="&wid&"")
	response.End()
End Sub
%>