<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!--#include file="../../conn/conn.asp" -->
<!--#include file="../../Inc/Commoncode.asp" -->
<!--#include file="../checkvalid.asp"-->
<%
'************************************************************
'	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 Inc. All Rights Reserved.
'	版权所有 嘉挚科技 未经嘉挚公司授权不得用于任何商业用途
'
'	文件名称：Admin_TemplateProject.asp
'	作    用：模板方案管理
'	最后更新：Fine Sincere (Mr.Hou)
'	最后日期：2007-5-13
'************************************************************
If Not FRAdminLevel(401) Then
	Call ErrorMsg()
End If
Const strFileName="Admin_TemplateProject.asp"
%>
<!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" />
<meta content="noindex,nofollow" name="robots" />
<title>Finereason HRCMS 7.0 后台管理系统</title>
<link href="../css/style<%=sk%>.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="../inc/input.js"></script>
<script language="JavaScript" type="text/JavaScript">
function ConfirmDel(TemplateProjectID,TemplateProjectName)
{
   if(confirm("您确定要删除方案【"+TemplateProjectName+"】吗？\n\n警告：此操作将同时删除该方案的模板，标签，样式和广告，确定删除？！"))
     location.href="<%=strFileName%>?Action=Del&TemplateProjectID="+TemplateProjectID
}
function confirmX(num)
{
	if(num==1)
	{
		if(document.form1.TemplateProjectName.value.length<1)
		{
		alert("您必须输入新方案名称!")
		document.form1.TemplateProjectName.focus();
		return false;
		}
		if(document.form1.Intro.value.length<1)
		{
		alert("您必须输入新方案备注!")
		document.form1.Intro.focus();
		return false;
		}
		document.form1.action="Admin_TemplateProject.asp";
		document.form1.submit();		
	}
	return false;	
}
function CheckTpj()
{
	if(document.form2.TemplateProjectName.value=="")
	{
		alert("请输入新方案的名称");
		document.form2.TemplateProjectName.focus();
		return false;
	}
	if(document.form2.TemplateDir.value=="")
	{
		alert("请输入方案的文件夹");
		document.form2.TemplateDir.focus();
		return false;
	}
	if(document.form2.Intro.value=="")
	{
		alert("请输入新方案的备注信息");
		document.form2.Intro.focus();
		return false;
	}
}
</script>
</head>
<body>
<table width="100%" border="0" align="center" cellpadding="2" cellspacing="1" class="tableBorder">
  <tr class="topbg">
    <th height="22" align="center" class="tableHeaderText"><strong >模板方案管理</strong></th>
  </tr>
  <tr>
    <td height="22"><span class="bodytitle"><font color="ff6600"><b class="style1">　管理选项</b></font>：</span>&nbsp;<a href="<%=strFileName%>?Action=Add">添加模板方案</a> | <a href="<%=strFileName%>">管理模板方案</a> | <a href="Admin_TempDatabase.asp?Action=LeadOut">模板方案导出</a> | <a href="Admin_TempDatabase.asp?Action=LeadIn">模板方案导入</a> [<a href="javascript:location.reload()">刷新页面</a>]</td>
  </tr>
</table> 
<%
dim Action
Action=trim(Request("Action"))
Select Case Action
	Case "Add"
		Call ShowData()
	Case "Modify"
		Call ShowData()
	Case "SaveData"
		Call SaveData()
	Case "Default"
		Call Default()
	Case "Copy"
		Call Copy()
	Case "Del"
		Call Del()
	Case "Create"
		Call Create()
	Case "CopyDir"
		Call CopyDir()
	Case Else
		Call main()
End Select

if FoundErr=True then
	call Show_Err()
end if

Conn.Close
Set Conn=Nothing
%>
<%
sub main()
	Set rs= Server.CreateObject(FR_HR_RS)
	sql="select * from JOB_TemplateProject order by TemplateProjectID desc"
	rs.open sql,conn,1,1
	if rs.eof and rs.bof then
		FoundErr=True
		ErrMsg=ErrMsg & "<br><li>暂无任何方案，请添加后再进行管理！</li>"
		exit sub
	else
		Call MainInfo()
	end if
	rs.close
	set rs=nothing
End Sub
%>
<%Sub MainInfo()%>
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="1" class="tableBorder mt6">
<form name="form1" method="Post" action="<%=strFileName%>">
	  <tr><th colspan="6">模板方案列表</th></tr>
	  <tr align="center">
		<td width="6%" height="22" class=tableHeaderText><strong>编号</strong></td>
		<td width="20%" class=tableHeaderText><strong>方案名称</strong></td> 
		<td width="14%" class=tableHeaderText><strong>方案目录</strong></td>
		<td width="13%" class=tableHeaderText><strong>方案备注</strong></td>
		<td width="8%" class=tableHeaderText><strong>是否默认</strong></td>
		<td width="39%" class=tableHeaderText><strong>操作选项</strong></td>
	  </tr>
	<%
		do while not rs.eof
		TemplateProjectID=Rs("TemplateProjectID")
		TemplateProjectName=Rs("TemplateProjectName")
		TemplateDir=Rs("TemplateDir")
		Intro=Rs("Intro")
		IsDefault=Rs("IsDefault")
	%>
	  <tr onMouseOver="this.style.background='#FFFFCC'" onMouseOut="this.style.background='#EEF7FD'" align="center">
		<td><%=TemplateProjectID%></td>
		<td><%=TemplateProjectName%></td> 
		<td><%=TemplateDir%></td>
		<td><%=Intro%></td>
		<td><%if IsDefault = True then%>
		  √
            <%else%>
            ×
            <%end if%></td>
		<td><%if IsDefault = True then%><a href="?Action=Create&TemplateProjectID=<%=TemplateProjectID%>">生成</a> <%else%><font color="#999999">生成</font> <%end if%><a href="Admin_Template.asp?id=<%=rs("TemplateProjectID")%>">管理模板</a>
		  <%if IsDefault = True then%>
		  <font color="#999999">设为默认</font>
		  <%else%>
		  <a href="?Action=Default&TemplateProjectID=<%=TemplateProjectID%>">设置默认</a>
		  <%end if%><a href="?Action=Modify&TemplateProjectID=<%=TemplateProjectID%>">
修改方案</a> <a href="?Action=CopyDir&TemplateProjectID=<%=TemplateProjectID%>">复制</a>
<%if IsDefault = True then%>
<font color="#999999">删除</font>
<%else%>
<a href="javascript:ConfirmDel(<%=TemplateProjectID%>,'<%=TemplateProjectName%>');">删除</a>
<%end if%></td>
	  </tr>
	<%
		rs.movenext
		loop
	%>
</form>
</table>
<%End Sub%>
<%
Sub ShowData()
	TemplateProjectID=trim(request.QueryString("TemplateProjectID"))
	If TemplateProjectID<>"" Then
		If IsNumeric(TemplateProjectID)=False Then
			FoundErr=True
			ErrMsg=ErrMsg & "<br><li>参数错误！</li>"
			Exit Sub
		End If
		sql="select * from JOB_TemplateProject where TemplateProjectID=" & TemplateProjectID
		set rs=server.CreateObject (FR_HR_RS)
		rs.open sql,conn,1,1
		if rs.bof and rs.eof then
			FoundErr=True
			ErrMsg=ErrMsg & "<br><li>此方案不存在或者已经删除！</li>"
			Exit Sub
		else
			TemplateProjectName=Rs("TemplateProjectName")
			TemplateDirs=Rs("TemplateDir")
			Intro=Rs("Intro")
			IsDefault=Rs("IsDefault")
		end if
		rs.Close
		Set rs=Nothing
	End If
%>
<table width="100%" border="0" align="center" cellpadding="2" cellspacing="1" class="tableBorder mt6">
  <form name="form1" method="post" action="<%=strFileName%>">
    <tr class="title">
      <th height="22" colspan="4" align="center" ><strong><%If TemplateProjectID<>"" Then%>修 改<%Else%>添 加<%End If%>方 案</strong></th>
    </tr>
    <tr class="amrow">
      <td width="17%" height="40" align="right"><strong>方案名称：</strong></td>
      <td><input maxlength="100" size="30" name="TemplateProjectName" value="<%=TemplateProjectName%>" /></td>
    </tr>
    <tr class="amrow">
      <td width="17%" height="40" align="right"><strong>方案目录：</strong></td>
      <td><input maxlength="100" size="30" name="TemplateDir" value="<%=TemplateDirs%>" />
      该方案所有模板存放的文件目录</td>
    </tr>
    <tr class="amrow">
      <td width="17%" height="40" align="right"><strong>方案备注：</strong></td>
      <td><textarea name="Intro" cols="38" rows="5"><%=Intro%></textarea></td>
    </tr>
    <tr class="amrow">
      <td width="17%" height="40" align="right"><strong>是否默认：</strong></td>
      <td><input name="IsDefault" type="radio" class="checkbox" value="True" checked="checked"  />
        是&nbsp;
        <input name="IsDefault" type="radio" class="checkbox" value="False" <%If IsDefault = False Then%>checked="checked"<%End If%> />
      否</td></tr>
    <tr class="tdbg">
      <td height="40" colspan="2" align="center"><input name="TemplateProjectID" type="hidden" value="<%=TemplateProjectID%>" />
          <input name="Action" type="hidden" value="SaveData" />
          <input name="btnSave" type="submit" class="inputs" style="cursor:hand;" value="<%If TemplateProjectID<>"" Then%> 修 改 <%Else%> 添 加 <%End If%>" />
        &nbsp;
        <input name="btnCancel" type="button" class="inputs" style="cursor:hand;" onClick="window.location.href='<%=strFileName%>'" value=" 取 消 " />      </td>
    </tr>
  </form>
</table>
<%End Sub%>
<%Sub CopyDir()
TemplateProjectID=trim(request("TemplateProjectID"))
if TemplateProjectID<>"" and Isnumeric(TemplateProjectID) then
	sql="select * from JOB_TemplateProject where TemplateProjectID="&TemplateProjectID&""
	set rs=Server.CreateObject(FR_HR_RS)
	rs.open sql,conn,1,1
	if not rs.eof then
		TemplateProjectName=rs("TemplateProjectName")&"副本"
		Intro=rs("Intro")		
	end if
	rs.close
	set rs=nothing
end if
%>
<table width="100%" border="0" align="center" cellpadding="2" cellspacing="1" class="tableBorder mt6">
  <form name="form2" method="post" action="<%=strFileName%>?Action=Copy&TemplateProjectID=<%=TemplateProjectID%>" onSubmit="return CheckTpj();">
    <tr>
      <th height="22" colspan="4" align="center" ><strong>复制方案</strong></th>
    </tr>
	<tr>
      <td colspan="2">&nbsp;<span class="800000">操作提示:</span>输入新方案的名称，目录，备注等信息后，点复制。该操作将同时复制原来方案的模板，样式，标签，广告等。</td>
    </tr>
    <tr>
      <td width="17%" height="40" align="right"><strong>方案名称：</strong></td>
      <td><input maxlength="100" size="30" name="TemplateProjectName" value="<%=TemplateProjectName%>" /></td>
    </tr>
    <tr>
      <td width="17%" height="40" align="right"><strong>方案目录：</strong></td>
      <td><input maxlength="100" size="30" name="TemplateDir" />
      该方案所有模板存放的文件目录</td>
    </tr>
    <tr>
      <td width="17%" height="40" align="right"><strong>方案备注：</strong></td>
      <td><textarea name="Intro" cols="38" rows="5"><%=Intro%></textarea></td>
    </tr>
    <tr>
      <td height="40" colspan="2" align="center"><input name="btnSave" type="submit" class="inputs" value="复制" />&nbsp;<input name="btnCancel" type="button" class="inputs" value=" 取 消 " /></td>
    </tr>
  </form>
</table>
<%End Sub%>
<!--#include file="../inc/copy.asp" -->
<%
Sub Default()
	TemplateProjectID=trim(request("TemplateProjectID"))
	if TemplateProjectID<>"" then
	conn.execute("update JOB_TemplateProject set IsDefault = "&FR_HR_False&" where IsDefault = "&FR_HR_True&"")
	conn.execute("update JOB_TemplateProject set IsDefault = "&FR_HR_True&" where TemplateProjectID="&TemplateProjectID&"")
	sql="select * from JOB_TemplateProject where TemplateProjectID="&TemplateProjectID
	set rs1=conn.execute(sql)
	de=rs1("TemplateProjectName")
	rs1.close
	set rs1=nothing
	conn.execute("update JOB_Template set IsDefaultInProject="&FR_HR_False&"")
	conn.execute("update JOB_Template set IsDefaultInProject="&FR_HR_True&" where ProjectName='"&de&"'")
	conn.execute("update JOB_Skin set IsDefaultInProject="&FR_HR_False&",IsDefault="&FR_HR_False&"")
	conn.execute("update JOB_Skin set IsDefaultInProject="&FR_HR_True&",IsDefault="&FR_HR_True&" where ProjectName='"&de&"'")
	end if
	Call main()
End Sub
%>
<%
'复制模板方案
'复制方案的同时复制该方案的模板，标签，样式，广告，只修改该内容的模板方案编号
Sub Copy()
	TemplateProjectID=trim(request("TemplateProjectID"))	
	if TemplateProjectID<>"" And IsNumeric(TemplateProjectID)=False then
		FoundErr=True
		ErrMsg=ErrMsg & "<br><li>参数错误！</li>"
		Exit Sub
		TemplateProjectID=CLng(TemplateProjectID)
	end if
	TemplateProjectName=Trim(Request.Form("TemplateProjectName"))
	TemplateDirs=Trim(Request.Form("TemplateDir"))
	Intro=Request.Form("Intro")
	IsDefault=FR_HR_False
	If TemplateProjectName="" Then
		ErrMsg=ErrMsg &"<br><li>新方案名称不能为空！</li>"
		FoundErr=True
	End If
	If TemplateDirs="" Then
		ErrMsg=ErrMsg &"<br><li>新方案目录不能为空！</li>"
		FoundErr=True
	End If
	If Intro="" Then
		ErrMsg=ErrMsg &"<br><li>新方案备注不能为空！</li>"
		FoundErr=True
	End If
	
	'判断复制新方案的名称填写是否有重复
	set rs=Server.CreateObject(FR_HR_RS)
	sql="select * from JOB_TemplateProject Where TemplateProjectName='"&TemplateProjectName&"'"
	rs.open sql,conn,1,1
	if not rs.eof then
		ErrMsg=ErrMsg &"<br><li>新方案名称已经存在,请重新填写！</li>"
		FoundErr=True
	end if
	rs.close
	set rs=nothing
	
	If FoundErr=True Then
		Exit Sub
	End If
	
	'把新方案的相关信息写到方案表
	set rs=Server.CreateObject(FR_HR_RS)
	sql="select * from JOB_TemplateProject"
	rs.open sql,conn,1,3
	rs.AddNew
	rs("TemplateProjectName")=TemplateProjectName
	rs("TemplateDir")=TemplateDirs
	rs("Intro")=Intro
	rs("IsDefault")=IsDefault
	rs.update
	rs.close
	set rs=nothing
	
	'读取新复制的模板方案的编号
	set rs=Server.CreateObject(FR_HR_RS)
	sql="select TemplateProjectID,TemplateProjectName from JOB_TemplateProject where TemplateProjectName='"&TemplateProjectName&"'"
	rs.open sql,conn,1,1
	if not rs.eof then
		'新方案的编号
		NewTemplateProjectID=rs("TemplateProjectID")
		NewTemplateProjectName=rs("TemplateProjectName")
	end if
	rs.close
	set rs=nothing
	
	'读取复制的模板方案的名称和存贮文件目录
	set rs=Server.CreateObject(FR_HR_RS)
	sql="select TemplateProjectName,TemplateDir from JOB_TemplateProject where TemplateProjectID="&TemplateProjectID&""
	rs.open sql,conn,1,1
	if not rs.eof then
		ProjectName=rs("TemplateProjectName")
		'旧方案的存贮目录
		TemplateDirss=rs("TemplateDir")
	end if
	rs.close
	set rs=nothing
	
	'复制要复制的方案的模板
	set rs=Server.CreateObject(FR_HR_RS)
	sql="select * from JOB_Template where ProjectName='"&ProjectName&"'"
	rs.open sql,conn,1,1
	if not rs.eof then
		'复制模板
		for i=1 to rs.recordcount
			set rs1=Server.CreateObject(FR_HR_RS)
			sql1="select * from JOB_Template"
			rs1.open sql1,conn,1,3
			rs1.addnew
			rs1("ChannelID")=rs("ChannelID")
			rs1("TemplateName")=rs("TemplateName")
			rs1("TemplateContent")=rs("TemplateContent")
			rs1("IsDefault")=rs("IsDefault")
			rs1("ProjectName")=NewTemplateProjectName
			rs1("IsDefaultInProject")=IsDefault
			rs1("Deleted")=rs("Deleted")
			rs1("typeid")=rs("typeid")
			rs1.update
			rs1.close
			set rs1=nothing
		rs.movenext
		next
	end if
	rs.close
	set rs=nothing
	
	'复制要复制的方案的样式
	set rs=Server.CreateObject(FR_HR_RS)
	sql="select * from JOB_Skin where ProjectName='"&ProjectName&"'"
	rs.open sql,conn,1,1
	if not rs.eof then
		for i=1 to rs.recordcount
			set rs1=Server.CreateObject(FR_HR_RS)
			sql1="select * from JOB_Skin"
			rs1.open sql1,conn,1,3
			rs1.addnew
			rs1("SkinName")=rs("SkinName")
			rs1("Skin_CSS")=rs("Skin_CSS")
			rs1("filename")=rs("filename")&"Copy"
			rs1("IsDefault")=rs("IsDefault")
			rs1("ProjectName")=NewTemplateProjectName
			rs1("IsDefaultInProject")=IsDefault
			if rs("imgpath")<>"" then
				rs1("imgpath")=split(rs("imgpath"),"/")(0)&"Copy/"
			end if			
			rs1.update
			rs1.close
			set rs1=nothing
		rs.movenext
		next
	end if
	rs.close
	set rs=nothing
	
	'复制要复制的方案的标签
	set rs=Server.CreateObject(FR_HR_RS)
	sql="select * from JOB_Label where projectid="&TemplateProjectID&" and LabelType>4"
	rs.open sql,conn,1,1
	if not rs.eof then
		for i=1 to rs.recordcount
			set rs1=Server.CreateObject(FR_HR_RS)
			sql1="select * from JOB_Label"
			rs1.open sql1,conn,1,3
			rs1.addnew
			rs1("LabelName")=rs("LabelName")
			rs1("LabelType")=rs("LabelType")
			rs1("LabelIntro")=rs("LabelIntro")
			rs1("LabelContent")=rs("LabelContent")
			rs1("projectid")=NewTemplateProjectID
			rs1("Labeladddate")=rs("Labeladddate")
			rs1("Labeleditdate")=rs("Labeleditdate")
			rs1("Labelorder")=rs("Labelorder")
			rs1.update
			rs1.close
			set rs1=nothing
		rs.movenext
		next
	end if
	rs.close
	set rs=nothing
	
	'复制要复制的方案的广告种类
	set rs=Server.CreateObject(FR_HR_RS)
	sql="select * from JOB_Adplace where projectid="&TemplateProjectID&""
	rs.open sql,conn,1,1
	if not rs.eof then
		for i=1 to rs.recordcount
			'读出要复制的广告种类的id
			oldadplaceid=rs("adplace_id")
			oldadplacename=rs("adplace_name")
			Set Rs1=server.createobject("adodb.recordset")         
			Sql1="select * from JOB_Adplace"         
			Rs1.open Sql1,Conn,1,3
			Rs1.AddNew								
			Rs1("adplace_name")=rs("adplace_name")
			Rs1("projectid")=NewTemplateProjectID								
			Rs1.Update
			Rs1.Close
			Set Rs1=Nothing
			
			'读出新添加的广告位种类的新编号
			Set Rsadplacenew=Server.CreateObject("ADODB.RecordSet")
			Sqladplacenew="Select adplace_id from JOB_Adplace where adplace_name='"&oldadplacename&"' and projectid="&NewTemplateProjectID&""
			Rsadplacenew.open Sqladplacenew,conn,1,1
			if not (Rsadplacenew.eof and Rsadplacenew.bof) then
				newadplaceid=Rsadplacenew("adplace_id")
			else
			Response.Write("复制模板方案失败!")
			Response.End()
			end if
			
			'读出该广告种类下的广告位
			Set Rs2=server.createobject("adodb.recordset")     
			Sql2="select * from JOB_Adsplace where projectid="&TemplateProjectID&" and Adsplace_placeid="&oldadplaceid&" order by adsplace_id desc"
			Rs2.open Sql2,Conn,1,1
			If Not Rs2.Eof then
				Do while Not Rs2.Eof
					'读出原来保存的广告位的自动编号以便导入时关联
					oldadsplaceid=Rs2("adsplace_id")
					oldadsplacename=Rs2("Adsplace_name")
					Set Rs3=server.createobject("adodb.recordset")         
					Sql3="select * from JOB_Adsplace"         
					Rs3.open Sql3,Conn,1,3
					Rs3.AddNew								
					Rs3("Adsplace_name")=Rs2("Adsplace_name")
					Rs3("Adsplace_placeid")=newadplaceid	
					Rs3("Adsplace_priceid")=Rs2("Adsplace_priceid")
					Rs3("Adsplace_price")=Rs2("Adsplace_price")
					Rs3("Adsplace_unit")=Rs2("Adsplace_unit")
					Rs3("Adsplace_row")=Rs2("Adsplace_row")
					Rs3("Adsplace_width")=Rs2("Adsplace_width")
					Rs3("projectid")=NewTemplateProjectID																
					Rs3.Update
					Rs3.Close
					Set Rs3=Nothing
					
					'读出新广告位的编号	
					Set Rsadsplacenew=Server.CreateObject("ADODB.RecordSet")
					Sqladsplacenew="Select Adsplace_id from JOB_Adsplace where adsplace_name='"&oldadsplacename&"' and projectid="&NewTemplateProjectID&" and Adsplace_placeid="&newadplaceid&""
					Rsadsplacenew.open Sqladsplacenew,conn,1,1
					if not(Rsadsplacenew.eof and Rsadsplacenew.bof) then
						newadsplaceid=Rsadsplacenew("adsplace_id")
					else
					Response.Write("复制模板方案失败")
					Response.End()
					end if
					
					'添加该广告位种类和广告位的广告导进系统									
					Set Rs4=server.createobject("adodb.recordset")     
					Sql4="select * from JOB_Ad where projectid="&TemplateProjectID&" and Ad_placeid="&oldadplaceid&" and Ad_priceid="&oldadsplaceid&" order by Ad_id desc"
					Rs4.open Sql4,Conn,1,1
					If Not Rs4.Eof then
						Do while Not Rs4.Eof										
							Set Rs5=server.createobject("adodb.recordset")         
							Sql5="select * from JOB_Ad"         
							Rs5.open Sql5,Conn,1,3
							Rs5.AddNew								
							Rs5("Ad_sitename")=Rs4("Ad_sitename")
							Rs5("Ad_siteurl")=Rs4("Ad_siteurl")
							Rs5("Ad_contactman")=Rs4("Ad_contactman")
							Rs5("Ad_tel")=Rs4("Ad_tel")
							Rs5("Ad_width")=Rs4("Ad_width")
							Rs5("Ad_pic")=Rs4("Ad_pic")
							Rs5("Ad_target")=Rs4("Ad_target")
							Rs5("Ad_type")=Rs4("Ad_type")
							Rs5("Ad_act")=Rs4("Ad_act")
							Rs5("Ad_click")=Rs4("Ad_click")
							Rs5("Ad_show")=Rs4("Ad_show")
							Rs5("Ad_enddate")=Rs4("Ad_enddate")
							Rs5("Ad_clicks")=Rs4("Ad_clicks")
							Rs5("Ad_shows")=Rs4("Ad_shows")											
							Rs5("Ad_stop")=Rs4("Ad_stop")
							Rs5("Ad_other")=Rs4("Ad_other")
							Rs5("Ad_addtime")=Rs4("Ad_addtime")
							Rs5("Ad_showtime")=Rs4("Ad_showtime")
							Rs5("Ad_lose")=Rs4("Ad_lose")											
							Rs5("Ad_placeid")=newadplaceid	
							Rs5("Ad_priceid")=newadsplaceid
							Rs5("projectid")=NewTemplateProjectID															
							Rs5.Update
							Rs5.Close
							Set Rs5=Nothing																		
						Rs4.MoveNext
						Loop
					End If
					Rs4.Close
					Set Rs4=Nothing														
				Rs2.MoveNext
				Loop
			End If
			Rs2.Close
			Set Rs2=Nothing		
								
		rs.MoveNext
		next
	end if
	rs.close
	set rs=nothing
	
	'创建新方案文件夹
	Set fso = CreateObject("Scripting.FileSystemObject")
	fso.CreateFolder (server.MapPath(InstallDir&"templates/"&TemplateDirs))
	Set fso = nothing
	
	'复制原来方案的广告图片
	Call CopyMyFolder(TemplateDirss,TemplateDirs)
		
    response.redirect strFileName
	response.End()
End Sub

sub SaveData()
	TemplateProjectID=trim(request("TemplateProjectID"))
	if TemplateProjectID<>"" And IsNumeric(TemplateProjectID)=False then
		FoundErr=True
		ErrMsg=ErrMsg & "<br><li>参数错误！</li>"
		Exit Sub
		TemplateProjectID=CLng(TemplateProjectID)
	end if
	TemplateProjectName=Trim(Request.Form("TemplateProjectName"))
	TemplateDirs=Trim(Request.Form("TemplateDir"))
	Intro=Request.Form("Intro")
	IsDefault=Request.Form("IsDefault")
	If TemplateProjectName="" Then
		ErrMsg=ErrMsg &"<br><li>方案名称不能为空！</li>"
		FoundErr=True
	End If
	If TemplateDirs="" Then
		ErrMsg=ErrMsg &"<br><li>方案目录不能为空！</li>"
		FoundErr=True
	End If
	If Intro="" Then
		ErrMsg=ErrMsg &"<br><li>方案备注不能为空！</li>"
		FoundErr=True
	End If
	If IsDefault="" Then
		ErrMsg=ErrMsg &"<br><li>请选择是否默认！</li>"
		FoundErr=True
	End If
	
	If FoundErr=True Then
		Exit Sub
	End If

	set rs=Server.CreateObject(FR_HR_RS)
	If TemplateProjectID<>"" Then
		sql="select * from JOB_TemplateProject Where TemplateProjectID="&TemplateProjectID
	Else
		sql="select * from JOB_TemplateProject"
	End If
	rs.open sql,conn,1,3
	If TemplateProjectID="" Then
		rs.AddNew
	End If
	TemplateProjectNameOld=rs("TemplateProjectName")
	conn.execute("update JOB_Template set ProjectName='"&TemplateProjectName&"' where ProjectName='"&TemplateProjectNameOld&"'")
	conn.execute("update JOB_Skin set ProjectName='"&TemplateProjectName&"' where ProjectName='"&TemplateProjectNameOld&"'")
	rs("TemplateProjectName")=TemplateProjectName
	rs("Intro")=Intro
	if IsDefault="True" then
	If TemplateProjectID<>"" Then
	conn.execute("update JOB_TemplateProject set IsDefault = "&FR_HR_False&" where IsDefault = "&FR_HR_True&" and TemplateProjectID<>"&TemplateProjectID&"")
	Else
	conn.execute("update JOB_TemplateProject set IsDefault = "&FR_HR_False&" where IsDefault = "&FR_HR_True&"")
	End If
	end if
	rs("IsDefault")=IsDefault 
	rs("TemplateDir")=TemplateDirs
	rs.update
	rs.close
	set rs=nothing
	If TemplateProjectID="" Then
		Set fso = CreateObject("Scripting.FileSystemObject")
		if fso.FolderExists(server.MapPath(InstallDir&"Templates/"&TemplateDirs)) Then    '判断文件夹是否存在
			response.Write("<script>alert(""系统错误提示：["&TemplateDir&"]目录已经存在！""),history.go(-1);</script>")
			response.End()
		else
			fso.CreateFolder (server.MapPath(InstallDir&"templates/"&TemplateDirs))
		end if
		if not fso.FolderExists(server.MapPath(InstallDir&"Adpic/"&TemplateDirs)) Then    '判断文件夹是否存在
			fso.CreateFolder (server.MapPath(InstallDir&"Adpic/"&TemplateDirs))
		end if
		Set fso = nothing
	end if	
    response.redirect strFileName
	response.End()
end sub
sub Del()
	TemplateProjectID=trim(Request("TemplateProjectID"))
	if TemplateProjectID="" then
		FoundErr=True
		ErrMsg=ErrMsg & "<br><li>参数不足！</li>"
		exit sub
	end if
	'读出要删除方案的方案名称
	
	sql="select TemplateProjectID,TemplateProjectName,TemplateDir from JOB_TemplateProject where TemplateProjectID="&TemplateProjectID
    set rs=server.CreateObject("Adodb.recordset")
	rs.open sql,conn,1,1
	if rs.bof and rs.eof then
		FoundErr=True
		ErrMsg=ErrMsg & "<br><li>方案不存在或者已被删除！</li>"
		exit sub
	else
		TemplateProjectID=rs("TemplateProjectID")
		TemplateProjectName=rs("TemplateProjectName")
		TemplateDirs=rs("TemplateDir")
		
		'删除方案
		conn.execute("delete from JOB_TemplateProject where TemplateProjectID="&TemplateProjectID&"")
		'删除该方案的模板
		conn.execute("delete from JOB_Template where ProjectName='"&TemplateProjectName&"'")
		'删除该方案的标签（不包括系统标签）
		conn.execute("delete from JOB_Label where LabelType>4 and projectid="&TemplateProjectID&"")
		'删除该方案的样式		
		'查方案的图片包文件和css文件的名称，删除
		sqlskin="select filename,imgpath from JOB_Skin where ProjectName='"&TemplateProjectName&"'"
		set rsskin=Server.CreateObject("ADODB.RecordSet")
		rsskin.open sqlskin,conn,1,1
		if not rsskin.eof then
			'删除样式文件
			Set fso = CreateObject("Scripting.FileSystemObject")
			myfile=server.mappath(InstallDir&"Css/"&rsskin("filename")&".css")
			If fso.FileExists(myfile) Then 
				fso.DeleteFile(myfile)
			end if			
			'删除样式图片包
			if fso.FolderExists(server.MapPath(InstallDir&"Skin/"&split(rsskin("imgpath"),"/")(0))) Then    '判断文件夹是否存在
				fso.DeleteFolder(server.MapPath(InstallDir&"Skin/"&split(rsskin("imgpath"),"/")(0)))
			end if
			set fso=nothing
		end if
		rsskin.close
		set rsskin=nothing
		
		conn.execute("delete from JOB_Skin where ProjectName='"&TemplateProjectName&"'")
		'删除该方案的广告种类
		conn.execute("delete from JOB_Adplace where projectid="&TemplateProjectID&"")
		'删除该方案的广告位
		conn.execute("delete from JOB_Adsplace where projectid="&TemplateProjectID&"")
		'删除该方案的广告
		conn.execute("delete from JOB_Ad where projectid="&TemplateProjectID&"")
	end if
	rs.close
	set rs=nothing
	'删除方案文件夹
	Set fso = CreateObject("Scripting.FileSystemObject")
	if fso.FolderExists(server.MapPath(InstallDir&"Templates/"&TemplateDirs)) Then    '判断文件夹是否存在
		fso.DeleteFolder(server.MapPath(InstallDir&"Templates/"&TemplateDirs)) 
	end if
	'删除广告文件夹
	if fso.FolderExists(server.MapPath(InstallDir&"Adpic/"&TemplateDirs)) Then    '判断文件夹是否存在
		fso.DeleteFolder(server.MapPath(InstallDir&"Adpic/"&TemplateDirs)) 
	end if
	set fso=nothing
	
    response.redirect strFileName
	response.End()
end sub
Sub Create()
	On error resume Next
	TemplateProjectID=trim(Request("TemplateProjectID"))
	if TemplateProjectID="" then
		FoundErr=True
		ErrMsg=ErrMsg & "<br><li>参数不足！</li>"
		exit sub
	end if
	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
	sql="select TemplateDir,TemplateID,TemplateName,ProjectName,ChannelID,TemplateContent,JOB_Template.IsDefault,typeid from JOB_TemplateProject,JOB_Template where TemplateProjectName=ProjectName and TemplateProjectID="& TemplateProjectID &""
    set rs=server.CreateObject ("Adodb.recordset")
	rs.open sql,conn,1,3
	if rs.bof and rs.eof then
		FoundErr=True
		ErrMsg=ErrMsg & "<br><li>方案不存在或者已被删除！</li>"
		exit sub
	else
		TemplateDirs=rs("TemplateDir")
		'如果方案文件夹不存在则创建
		if not fso.FolderExists(server.MapPath(InstallDir&"Templates/"&TemplateDirs)) Then    '判断文件夹是否存在
			fso.CreateFolder (server.MapPath(InstallDir&"templates/"&TemplateDirs))
		end if
		
		Do While Not(rs.Eof)		
		TemplateID=rs("TemplateID")
		TemplateName=rs("TemplateName")
		ProjectName=rs("ProjectName")
		ChannelID=rs("ChannelID")
		TemplateContent=rs("TemplateContent")
		IsDefault=rs("IsDefault")
		typeid=rs("typeid")
				
		Fso.CreateTextFile(Server.MapPath("../../Templates/"&TemplateDirs&"/T_"&ChannelID&"_"&typeid&"_"&TemplateID&".html")).WriteLine(TemplateContent)
		if IsDefault then
			Fso.CreateTextFile(Server.MapPath("../../Templates/"&TemplateDirs&"/T_"&ChannelID&"_"&typeid&"_0.html")).WriteLine(TemplateContent)
		end if
		rs.MoveNext
		Loop
	end if
	rs.close
	set rs=nothing
	Set Fso=Nothing
	response.Write("<script>alert(""生成成功，确定返回列表...！"");window.location='"&strFileName&"';</script>")
	response.End() 
End Sub
%>
<% 
Function CopyMyFolder(FolderName,FolderPath) 
	sFolder=server.mappath(InstallDir&"Adpic/"&FolderName) 
	oFolder=server.mappath(InstallDir&"Adpic/"&FolderPath) 
	set fso=server.createobject("scripting.filesystemobject") 
	if fso.folderexists(server.mappath(InstallDir&"Adpic/"&FolderName)) Then'检查原文件夹是否存在 
	if fso.folderexists(server.mappath(InstallDir&"Adpic/"&FolderPath)) Then'检查目标文件夹是否存在 
		fso.copyfolder sFolder,oFolder 
	Else '目标文件夹如果不存在就创建 
		CreateNewFolder = Server.Mappath(InstallDir&"Adpic/"&FolderPath) 
		fso.CreateFolder(CreateNewFolder) 
		fso.copyfolder sFolder,oFolder 
	End if 
	'CopyMyFolder="复制文件夹["&server.mappath(FolderName)&"]到["&server.mappath(FolderPath)&"]成功!" 
	'Else 
	'CopyMyFolder="错误,原文件夹["&sFolde&"]不存在!" 
	End If 
	set fso=nothing 
End Function 
	'FolderName="2006" '原文件夹 
	'FolderPath="2008" '目标文件夹 
	'response.write""&CopyMyFolder(FolderName,FolderPath)&"" '复制文件夹2006下的所有内容到2008文件夹下并返回结果 
%>