<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!--#include file="../../conn/conn.asp" -->
<!--#include file="../checkvalid.asp"-->
<!--#include file="../../inc/commoncode.asp"-->
<%If Not FRAdminLevel(402) Then
	Call ErrorMsg()
End If
'#########################################################
'
' Software name: Finereason HRCMS 7.0
' 软件名称:嘉缘人才网站内容管理系统 V7.0
' Email: service@finereason.com . QQ:109530926
' Web: http://www.finereason.com  http://www.yjys.net
' Copyright (C) FineSincere Network All Rights Reserved.
' 版权所有 嘉挚科技 未经嘉挚公司授权不得用于任何商业用途
'
'#########################################################
TemplateID=request.QueryString("id")
action=request.QueryString("action")
tempname=request.form("tempname")
tempfa=request.form("tempfa")
temppd=request.form("temppd")
content=request.form("content")
typeid=request.form("typeid")
de=request.form("de")
if tempname<>"" and tempfa<>"0" and temppd<>"" and content<>"" then
'*********************查看方案是否默认*****************************
	set rsp=server.CreateObject("adodb.recordset")
	sql="select IsDefault,TemplateDir from JOB_TemplateProject where TemplateProjectName='"&tempfa&"'"
	rsp.open sql,conn,1,1
		IsDefaultInProject=rsp("IsDefault")
		TemplateDir=rsp("TemplateDir")
	rsp.close
	set rsp=nothing
'*********************更新模板状态*****************************
	if de then
		set rsc=server.CreateObject("adodb.recordset")
		sql="select IsDefault from JOB_Template where ProjectName='"&tempfa&"' and ChannelID="&temppd&" and typeid="&typeid
		rsc.open sql,conn,1,3
		if not rsc.eof then
		do while not rsc.eof
			rsc("IsDefault")=False
		rsc.movenext
		loop
		end if
		rsc.close
		set rsc=nothing
	end if
'*********************这是添加的**************************
	set rs=server.CreateObject ("adodb.recordset")
	if action<>"edit" and TemplateID="" then
		sql="select * from JOB_Template"
		rs.open sql,conn,1,3
		rs.addnew
	else
		sql="select * from JOB_Template where TemplateID="&TemplateID
		rs.open sql,conn,1,3
	end if
		rs("ChannelID")=temppd
		rs("TemplateName")=tempname
		rs("TemplateContent")=content
		'rs("TemplateContent")=server.HTMLEncode(content)
		rs("IsDefault")=de
		rs("ProjectName")=tempfa
		rs("IsDefaultInProject")=IsDefaultInProject
		rs("typeid")=typeid
		rs.update
		rs.close
	set rs=nothing
	if TemplateID="" then
		set rsp=server.CreateObject("adodb.recordset")
		sql="select TemplateID from JOB_Template where ProjectName='"&tempfa&"' and ChannelID="&temppd&" and typeid="&typeid&" and TemplateName='"&tempname&"'"
		rsp.open sql,conn,1,1
			TemplateID=rsp("TemplateID")
		rsp.close
		set rsp=nothing
	end if
CreateTempFile()
if de then
IsDefault=de
CreateTempFile()
end if
if FoundErr=True then
	call Show_Err()
	response.End()
end if
response.write "<script language=javascript>alert('操作成功');location.href='Admin_Template.asp?show=all';</script>"
Response.end()
end if
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<META http-equiv=Content-Type content="text/html; charset=gb2312">
<link href="../css/style<%=sk%>.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="../inc/input.js"></script><title>模板管理</title>
<script language="javascript" src="../Inc/Admin.js"></script><script language="javascript">
function check(){
	if(form1.tempname.value=="")
	{
		alert("对不起模板名称不能为空！");
		return false;
	}
	if(form1.tempfa.value==0)
	{
		alert("对不起请选择模板方案！");
		return false;
	}
	if(form1.temppd.value=="")
	{
		alert("对不起请选择模板频道！");
		return false;
	}
	if(form1.typeid.value==10000)
	{
		alert("对不起请选择模板类型！");
		return false;
	}

	if(form1.content.value=="")
	{
		alert("对不起模板内容不能为空！");
		return false;
	}

	return true;
}

</script></head>
<body>
<table width="100%" border="0" align="center" cellpadding="2" cellspacing="1" class="tableBorder">
  <tr>
    <th height="22" align="center" >模板管理</th>
  </tr>
  <tr>
    <td height="20"><span class="bodytitle"><font color="ff6600"><b class="style1">　管理选项</b></font>：</span><a href="Admin_AddTemp.asp">添加模板</a> | <a href="Admin_Template.asp?show=all">模板管理</a></td>
  </tr>
</table>
<%
	if action="edit" and TemplateID<>"" then
		set rs1=server.CreateObject("adodb.recordset")
		sql="select * from JOB_Template where TemplateID="&TemplateID&" and IsDefaultInProject="&FR_HR_True&""
		rs1.open sql,conn,1,1
		TemplateName=rs1("TemplateName")
		ProjectName=rs1("ProjectName")
		ChannelID=rs1("ChannelID")
		typeid=rs1("typeid")
		TemplateContent=rs1("TemplateContent")
		IsDefault=rs1("IsDefault")
		rs1.close
		set rs1=nothing
		
'		if IsDefault then
'			TemplateIDs=0
'		else
'		TemplateIDs=TemplateID
'		end if
'		TemplateContent=LoadTemplate(ChannelID,typeid,0)
		
	else
		IsDefault=True
	end if	
%>
<table width="100%" border="0" align="center" cellpadding="2" cellspacing="1" class="tableBorder mt6">
  <form id="form1" name="form1" method="post" action="" onSubmit="return check();">
    <tr>
      <th height="22" colspan="5" align="center" >添加模板 </th>
    </tr>
    <tr>
      <td width="100" height="20" align="right">模板名称： </td>
      <td height="20" colspan="2"><label>
        <input name="tempname" type="text" id="tempname" value="<%=TemplateName%>" />
      </label></td>
    </tr>
    <tr>
      <td height="20" align="right">选择方案：</td>
      <td height="20" colspan="2">
        <select name="tempfa" id="tempfa">
          <option value="0">请选择方案</option>
		  <%
				Set rs= Server.CreateObject(FR_HR_RS)
				sql="select * from JOB_TemplateProject order by TemplateProjectID desc"
				rs.open sql,conn,1,1
				do while not rs.eof
				if  ProjectName = rs("TemplateProjectName") then
					response.write "<option value="&rs("TemplateProjectName")&" selected>"&rs("TemplateProjectName")&"</option>"
				else
					response.write "<option value="&rs("TemplateProjectName")&">"&rs("TemplateProjectName")&"</option>"
				end if
				rs.movenext
				loop
				rs.close
				set rs=nothing

		  %>
        </select>
     </td>
    </tr>
    <tr>
      <td height="20" align="right">选择频道： </td>
      <td height="20" colspan="2"><select name="temppd" id="temppd">
        <option value="">请选择频道</option>
		<option value="0" <%if ChannelID=0 then response.write "selected"%>>网站首页</option>
		<%
			set rs=conn.execute("select * from JOB_Channel where Disabled="&FR_HR_False&" order by orderid asc")
			if not rs.eof then
			do while not rs.eof
			if ChannelID=rs("ChannelID") then
					response.write "<option value="&rs("ChannelID")&" selected>"&rs("ChannelName")&"</option>"
			else
					response.write "<option value="&rs("ChannelID")&">"&rs("ChannelName")&"</option>"
			end if
			rs.movenext
			loop
			end if
			rs.close
			set rs=nothing

		%>
		<option value="9999" <%if ChannelID=9999 then response.write "selected"%>>通用频道</option>
      </select></td>
    </tr>
	    <tr>
      <td height="20" align="right">选择类型： </td>
      <td height="20" colspan="2"><select name="typeid" id="typeid">
        <option value="10000" selected>请选择模板类型</option>
		<%
			typeid=10000'如果不给初始值，那么typeid将是0.
			if TemplateID<>"" then
			sql="select * from JOB_Template where TemplateID="&TemplateID
			set rs=conn.execute(sql)
			if not rs.eof then
				typeid=rs("typeid")
			end if
			rs.close
			set rs=nothing
			end if	
			for i=0 to ubound(myarray)
			if i=typeid then
					response.write "<option value="&i&" selected>"&myarray(i)&"</option>"
			else
					response.write "<option value="&i&">"&myarray(i)&"</option>"
			end if
			next
		%>
      </select></td>
    </tr>

    <tr>
      <td height="20" align="right">模板内容：</td>
      <td width="762" height="20" colspan="-3">
	  <textarea name="content" rows=24 id=t1 style="width:100%;"><%=TemplateContent%></textarea>	  </td>
      <td width="60"><span class="td2"><A href="javascript:admin_Size(-5,'t1')"><IMG 
      src="../Images/minus.gif" width="20" height="20" border=0 unselectable="on"></A> <A 
      href="javascript:admin_Size(5,'t1')"><IMG src="../Images/plus.gif" width="20" height="20" 
      border=0 unselectable="on"></A><IMG 
      src="../Images/viewpic.gif" width="45" height="19" onclick=runscript(t1)></span></td>
    </tr>
    <tr class="amrow">
      <td height="20" align="right">是否默认：</td>
      <td height="20" colspan="2"><input name="de" type="radio" class="checkbox" value="True" checked="checked" />是<input name="de" type="radio" class="checkbox" value="False" <%if IsDefault=False then%>checked="checked"<% end if %>/>否</td>
    </tr>
    <tr>
      <td height="20" colspan="3" align="center" bgcolor="#F0F0F0"><label>
        <input name="Submit" type="submit" class="inputs" value="<%
		if action="edit" then
		response.write "修改"
		else
		response.write "提交"
		end if
 %>" />
        &nbsp;
        <input name="Submit2" type="reset" class="inputs" value="重置" />
      </label></td>
    </tr>
  </form>
</table>
<!--#include file="../inc/copy.asp" -->
</body>
</html>
<%
Sub CreateTempFile()
	On error resume Next
	Dim Fso,FileName,Template_Con
	Set FSO=Server.CreateObject(FR_HR_fso)
	If  Err Then
		FoundErr=True
		ErrMsg=ErrMsg & "<br><li>您的服务器不支持写文件,模板文件写入失败！</li>"
		Exit Sub
	end If
	if IsDefault then TemplateID=0
	Template_Con=content
	Fso.CreateTextFile(Server.MapPath("../../Templates/"&TemplateDir&"/T_"&temppd&"_"&typeid&"_"&TemplateID&".html")).WriteLine(Template_Con)
	If  Err Then
		FoundErr=True
		ErrMsg=ErrMsg & "<br><li>您的服务器不支持写文件,模板文件写入失败！</li>"
		Exit Sub
	End If
	Set FSO=Nothing  
End Sub
%>