<% Option Explicit %>
<!--#include file="../../Inc/Const.asp" -->
<!--#include file="../../Inc/Cls_DB.asp" -->
<!--#include file="../../Inc/Function.asp" -->
<!--#include file="../Refresh/Function.asp" -->
<!--#include file="../Refresh/RefreshFunction.asp" -->
<!--#include file="../Refresh/SelectFunction.asp" -->
<%
Dim DBC,Conn
Set DBC = New DataBaseClass
Set Conn = DBC.OpenConnection()
Set DBC = Nothing
'==============================================================================
'软件名称：风讯网站信息管理系统
'当前版本：Foosun Content Manager System 2.0 
'最新更新：2004.12
'==============================================================================
'商业注册联系：028-85098980-601,602 技术支持：028-85098980-606、607,客户支持：608
'产品咨询QQ：159410,655071,66252421
'技术支持:所有程序使用问题，请提问到bbs.foosun.net我们将及时回答您
'程序开发：风讯开发组 & 风讯插件开发组
'论坛支持：风讯在线论坛(http://bbs.foosun.net)
'官方网站：www.Foosun.net  演示站点：test.cooin.com    
'网站建设专区：www.cooin.com
'==============================================================================
'免费版本请在新闻首页保留版权信息，并做上本站LOGO友情连接
'==============================================================================
%>
<!--#include file="../../Inc/Session.asp" -->
<!--#include file="../../Inc/CheckPopedom.asp" -->
<%
if Not JudgePopedomTF(Session("Name"),"P139") then Call ReturnError()
    Dim TempClassID,OldClassObj,OldClassEName
	If Request("ClassID")<>"" then
	   TempClassID = Cstr(Request("ClassID"))
	 else
	   Response.Write("<script>alert(""参数传递错误"");dialogArguments.location.reload();window.close();</script>")
	   Response.End
	End If
	
    set OldClassObj = Conn.Execute("select ClassID,ClassEName from NewsClass where ClassID='"&TempClassID&"'")
	if Not OldClassObj.Eof then
		OldClassEName = OldClassObj("ClassEName")
	end if
	OldClassObj.Close
	Set OldClassObj = Nothing
	
dim TempClassListStr
TempClassListStr = ClassList
Function ClassList()
	Dim ClassListObj,SelectStr
	Set ClassListObj = Conn.Execute("select * from newsclass where ParentID = '0'")
	do while Not ClassListObj.Eof
		if OldClassEName = ClassListObj("ClassEName") then
			SelectStr = "selected"
		else
			SelectStr = ""
		end if
		ClassList = ClassList & "<option " & SelectStr & " value="&ClassListObj("ClassID")&"" & ">" & ClassListObj("ClassCName") & "</option><br>"
		ClassList = ClassList & ChildClassList(ClassListObj("ClassID"),"")
		ClassListObj.MoveNext	
	loop
	ClassListObj.Close
	Set ClassListObj = Nothing
End Function

Function ChildClassList(ClassID,Temp)
	Dim TempRs,TempStr,SelectStr
	Set TempRs = Conn.Execute("Select * from NewsClass where ParentID = '" & ClassID & "'")
	TempStr = Temp & " - "
	do while Not TempRs.Eof
		if OldClassEName = TempRs("ClassEName") then
			SelectStr = "selected"
		else
			SelectStr = ""
		end if
		if TempRs("ChildNum") = 0 then
			ChildClassList = ChildClassList & "<option " & SelectStr & " value="&TempRs("ClassID")&"" & ">" & TempStr & TempRs("ClassCName") & "</option><br>"
		else
			ChildClassList = ChildClassList & "<option " & SelectStr & " value="&TempRs("ClassID")&"" & ">" & TempStr & TempRs("ClassCName") & "</option><br>"
		end if
		ChildClassList = ChildClassList & ChildClassList(TempRs("ClassID"),TempStr)
		TempRs.MoveNext
	loop
	TempRs.Close
	Set TempRs = Nothing
End Function
Dim Description
Description = Replace(Replace(Request("Description"),"""","%22"),"'","%27")
%>
<html>
<head>
<link href="../Inc/ModeWindow.css" rel="stylesheet" type="text/css">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>添加下载</title>
</head>
<script language="JavaScript" src="../JS/PublicJS.js"></script>
<body>
<table width="100%" border="0" cellspacing="1" cellpadding="0">
  <form action="" name="DownForm" method="post">
    <tr> 
      <td width="12%"><div align="center">下载名称</div></td>
      <td width="37%"><input name="Name" type="text" id="Title2" style="width:90%" value="<%=Request("Name")%>"> 
      </td>
      <td><div align="center">推荐下载 </div></td>
      <td><select name="RecTF" id="RecTF" style="width:90%">
          <option value="1" <%If Request("RecTF")=1 then Response.Write("selected")%>>是</option>
          <option value="0" <%If Request("RecTF")=0 then Response.Write("selected")%>>否</option>
        </select></td>
    </tr>
    <tr> 
      <td><div align="center">所属栏目</div></td>
      <td><select name="ClassID" id="select7" style="width:90%">
          <% = TempClassListStr %>
        </select></td>
      <td width="10%"><div align="center">是否审核</div></td>
      <td width="41%"><select name="AuditTF" id="AuditTF" style="width:90%">
          <option value="0" <%If Request("AuditTF")=0 then Response.Write("selected")%>>需要审核</option>
          <option value="1" <%If Request("AuditTF")=1 then Response.Write("selected")%>>不用审核</option>
        </select></td>
    </tr>
    <tr> 
      <td><div align="center">下载性质</div></td>
      <td><select name="Property" id="Property" style="width:90%">
          <option value="1" <%If Request("Property")=1 then Response.Write("selected")%>>图片</option>
          <option value="2" <%If Request("Property")=2 then Response.Write("selected")%>>文件</option>
          <option value="3" <%If Request("Property")=3 then Response.Write("selected")%>>程序</option>
          <option value="4" <%If Request("Property")=4 then Response.Write("selected")%>>Flash</option>
          <option value="5" <%If Request("Property")=5 then Response.Write("selected")%>>音乐</option>
          <option value="6" <%If Request("Property")=6 then Response.Write("selected")%>>其它</option>
        </select></td>
      <td><div align="center">下载权限</div></td>
      <td><select name="BrowPop" id="select11" style="width:90%" onChange="ChooseExeName();">
          <option value="" <%if Request("BrowPop")="" then Response.Write("selected")%>> 
          </option>
          <%
		Dim BrowPopObj
		set BrowPopObj = Conn.Execute("Select Name,PopLevel from MemGroup order by PopLevel asc")
		while not BrowPopObj.eof
		%>
          <option value="<%=BrowPopObj("PopLevel")%>" <%if Request("BrowPop")<>"" and isnull(Request("BrowPop"))=false then if Cint(Request("BrowPop")) = Cint(BrowPopObj("PopLevel")) then Response.Write("selected") end if end if%>><%=BrowPopObj("Name")%></option>
          <%
		BrowPopObj.Movenext
		Wend
		BrowPopObj.Close
		Set BrowPopObj = Nothing
		%>
        </select></td>
    </tr>
    <tr> 
      <td><div align="center">下载类型</div></td>
      <td><select name="Types" id="Types" style="width:90%">
          <option value="1" <%If Request("Types")=1 then Response.Write("selected")%>>图片</option>
          <option value="2" <%If Request("Types")=2 then Response.Write("selected")%>>文件</option>
          <option value="3" <%If Request("Types")=3 then Response.Write("selected")%>>程序</option>
          <option value="4" <%If Request("Types")=4 then Response.Write("selected")%>>Flash</option>
          <option value="5" <%If Request("Types")=5 then Response.Write("selected")%>>音乐</option>
          <option value="6" <%If Request("Types")=6 then Response.Write("selected")%>>影视</option>
          <option value="7" <%If Request("Types")=7 then Response.Write("selected")%>>其它</option>
        </select></td>
      <td><div align="center">下载次数</div></td>
      <td><input name="ClickNum" type="text" id="ClickNum3" style="width:90%" value="<%if Request("ClickNum")="" then Response.Write("0") else Response.Write(Request("ClickNum")) end if %>"> 
      </td>
    </tr>
    <tr> 
      <td><div align="center">程序语言</div></td>
      <td><select name="Language" id="Language" style="width:90%">
          <option value="1" <%If Request("Language")=1 then Response.Write("selected")%>>简体中文</option>
          <option value="2" <%If Request("Language")=2 then Response.Write("selected")%>>繁体中文</option>
          <option value="3" <%If Request("Language")=3 then Response.Write("selected")%>>英文</option>
          <option value="4" <%If Request("Language")=4 then Response.Write("selected")%>>法文</option>
          <option value="5" <%If Request("Language")=5 then Response.Write("selected")%>>日文</option>
          <option value="6" <%If Request("Language")=6 then Response.Write("selected")%>>德文</option>
        </select></td>
      <td><div align="center">版本名称</div></td>
      <td><input name="Version" type="text" id="Version2" style="width:90%" value="<%=Request("Version")%>"></td>
    </tr>
    <tr> 
      <td><div align="center">文件大小</div></td>
      <td><input name="FileSize" type="text" id="FileSize" style="width:90%" value="<%=Request("FileSize")%>"></td>
      <td><div align="center">程序授权</div></td>
      <td><select name="Accredit" id="Accredit" style="width:90%">
          <option value="1" <%If Request("Accredit")=1 then Response.Write("selected")%>>免费</option>
          <option value="2" <%If Request("Accredit")=2 then Response.Write("selected")%>>共享</option>
          <option value="3" <%If Request("Accredit")=3 then Response.Write("selected")%>>试用</option>
          <option value="4" <%If Request("Accredit")=4 then Response.Write("selected")%>>演示</option>
          <option value="5" <%If Request("Accredit")=5 then Response.Write("selected")%>>注册</option>
          <option value="6" <%If Request("Accredit")=6 then Response.Write("selected")%>>破解</option>
          <option value="7" <%If Request("Accredit")=7 then Response.Write("selected")%>>零售</option>
          <option value="8" <%If Request("Accredit")=8 then Response.Write("selected")%>>其它</option>
        </select></td>
    </tr>
    <tr> 
      <td><div align="center">系统平台</div></td>
      <td><input name="SystemType" type="text" id="SystemType" style="width:63%" value="<%=Request("SystemType")%>"> 
        <select name="SystemChoose" id="SystemChoose" style="width:25%" onChange=ChooseSystem(this.options[this.selectedIndex].value)>
          <option value="Clean" style="color:red">清空</option>
          <option value="Win95">Win95</option>
          <option value="Win98">Win98</option>
          <option value="WinMe">WinMe</option>
          <option value="WinNT">WinNT</option>
          <option value="Win2000">Win2000</option>
          <option value="WinXP" selected>WinXP</option>
          <option value="Win2003">Win2003</option>
          <option value="Linux">Linux</option>
        </select></td>
      <td><div align="center">星级评价</div></td>
      <td><select name="Appraise" id="Appraise" style="width:90%">
          <option value="1" <%If Request("Appraise")=1 then Response.Write("selected")%>>★</option>
          <option value="2" <%If Request("Appraise")=2 then Response.Write("selected")%>>★★</option>
          <option value="3" <%If Request("Appraise")=3 then Response.Write("selected")%>>★★★</option>
          <option value="4" <%If Request("Appraise")=4 then Response.Write("selected")%>>★★★★</option>
          <option value="5" <%If Request("Appraise")=5 then Response.Write("selected")%>>★★★★★</option>
          <option value="6" <%If Request("Appraise")=6 then Response.Write("selected")%>>★★★★★★</option>
        </select></td>
    </tr>
    <tr> 
      <td><div align="center">开 发 商</div></td>
      <td><input name="Provider" type="text" id="Provider" style="width:90%" value="<%=Request("Provider")%>"></td>
      <td><div align="center">E_Mail</div></td>
      <td><input name="EMail" type="text" id="EMail2" style="width:90%" value="<%=Request("EMail")%>"></td>
    </tr>
    <tr> 
      <td><div align="center">开发商Url</div></td>
      <td><input name="ProviderUrl" type="text" id="ProviderUrl" style="width:90%" value="<%=Request("ProviderUrl")%>"></td>
      <td><div align="center">显示图片</div></td>
      <td><input name="Pic" type="text" id="Pic" style="width:60% " value="<%=Request("Pic")%>" > 
        <input type="button" name="Submit4" value="选择图片" onClick="OpenWindowAndSetValue('../inc/SelectPic.asp?CurrPath=/<% = UpFiles %>',550,290,window,document.DownForm.Pic);"></td>
    </tr>
    <tr> 
      <td><div align="center">解压密码</div></td>
      <td><input name="PassWord" type="text" id="PassWord" style="width:90%" value="<%=Request("PassWord")%>"></td>
      <td><div align="center">页面模板</div></td>
      <td><input name="NewsTemplet" type="text" id="NewsTemplet" style="width:60% " readonly value="<%If Request("NewsTemplet")="" then Response.Write("/"&RemoveVirtualPath(TempletDir)&"/NewsClass/DownPage.htm") else Response.Write(Request("NewsTemplet"))%>" > 
        <input type="button" name="Submit" value="选择模板" onClick="OpenWindowAndSetValue('../Inc/SelectFileFrame.asp?CurrPath=/<% = TempletDir %>',400,300,window,document.DownForm.NewsTemplet);document.DownForm.NewsTemplet.focus();"></td>
    </tr>
    <tr> 
      <td><div align="center">扩 展 名</div></td>
      <td> <select name="FileExtName" id="FileExtName" style="width:90%">
          <option value="htm" <%If Request("FileExtName")="htm" then Response.Write("selected")%>>htm</option>
          <option value="html" <%If Request("FileExtName")="html" then Response.Write("selected")%>>html</option>
          <option value="shtm" <%If Request("FileExtName")="shtm" then Response.Write("selected")%>>shtm</option>
          <option value="shtml" <%If Request("FileExtName")="shtml" then Response.Write("selected")%>>shtml</option>
          <option value="asp" <%If Request("FileExtName")="asp" then Response.Write("selected")%>>asp</option>
        </select></td>
      <td><div align="center">添加日期</div></td>
      <td> <input name="AddTime" readonly type="text" id="AddTime" style="width:60% " value="<% if Request("AddTime")="" then Response.Write(now()) else Response.Write(Request("AddTime")) end if%>"> 
        <input type="button" name="Submit42" value="选择日期" onClick="OpenWindowAndSetValue('../Inc/SelectDate.asp',280,110,window,document.DownForm.AddTime);document.DownForm.AddTime.focus();"></td>
    </tr>
    <tr> 
      <td height="21"><div align="center">下载简介</div></td>
      <td height="21" colspan="3"><iframe id='NewsContent' src='../Editer/DownLoadEditer.asp' frameborder=0 scrolling=no width='93%' height='360'></iframe></td>
    </tr>
    <tr> 
      <td height="21" colspan="4"> <div align="center"> 
          <input type="button" name="Submit2" value=" 添 加 " onClick="SubmitData();">
          <input name="action" type="hidden" id="action" value="add">
          <input type="button" name="Submit3" value=" 取 消 " onClick="window.close();">
          <input type="hidden" name="Description" value="<%= Description %>">
		</div></td>
    </tr>
  </form>
</table>
</body>
</html>
<script language="javascript">
function ChooseExeName()
{
  if (document.DownForm.BrowPop.value!='') document.DownForm.FileExtName.disabled=true;
  else document.DownForm.FileExtName.disabled=false;
 }
function SubmitData()
{
	document.DownForm.Description.value=frames["NewsContent"].EditArea.document.body.innerHTML;
	document.DownForm.submit();
}
ChooseExeName();
</script>
<%
  if Request.Form("action")="add" then
  	Dim IDownObj,IClassID,INewsID
	If Replace(Replace(Replace(Replace(Request.Form("Name"),"/",""),"\",""),"'","")," ","") = "" then
		Response.Write("<script>alert(""下载名称为空或是含有非法字符"");</script>")
		Response.End 
	End If
	If Request.Form("ClassID") = "" then
		Response.Write("<script>alert(""请选择栏目"");</script>")
		Response.End 
	Else
		IClassID = Request.Form("ClassID")
	End If
	If Isdate(Request.Form("AddTime")) = false then
		Response.Write("<script>alert(""添加时间格式不正确"");</script>")
		Response.End 
	End If
	If Isnumeric(Request.Form("ClickNum")) = false then
		Response.Write("<script>alert(""下载次数必须为数字类型"");</script>")
		Response.End 
	End If
	If Request.Form("NewsTemplet") = "" then
		Response.Write("<script>alert(""文件模板名称不能为空"");</script>")
		Response.End 
	End If
	INewsID = GetRandomID18()
	Dim NewsFileNames,RsNewsConfigObj,INewsAddSql
		Set RsNewsConfigObj = Conn.Execute("Select DoMain,NewsFileName from Config")
		NewsFileNames = NewsFileName(RsNewsConfigObj("NewsFileName"),IClassID,INewsID)

	  set IDownObj=server.createobject("adodb.recordset")
	  INewsAddSql="select * from DownLoad where 1=0"
	  IDownObj.open INewsAddSql,Conn,3,3
	  IDownObj.addnew
	  IDownObj("DownLoadID") = INewsID
	  IDownObj("Name") = Replace(Replace(Replace(Replace(Request.Form("Name"),"/",""),"\",""),"'","")," ","")
	  IDownObj("ClassID") = IClassID
	  if Request.Form("Version")<>"" then
		  IDownObj("Version") = Replace(Replace(Request.Form("Version"),"""",""),"'","")
	  end if
	  IDownObj("Types") = Cint(Request.Form("Types"))
	  IDownObj("Property") = Cint(Request.Form("Property"))
	  IDownObj("Language") = Cint(Request.Form("Language"))
	  if Request.Form("Accredit") <> "" then 
		  IDownObj("Accredit") = Cint(Request.Form("Accredit"))
	  end if
	  If Request.Form("FileSize") <> "" then
		  IDownObj("FileSize") = Replace(Replace(Request.Form("FileSize"),"""",""),"'","")
	  End If
	  If Isnumeric(Request.Form("Appraise")) then
		  IDownObj("Appraise") = Cint(Request.Form("Appraise"))
	  End If
	  If Request.Form("SystemType") <> "" then
		  IDownObj("SystemType") = Replace(Replace(Request.Form("SystemType"),"""",""),"'","")
	  End If
	  If Request.Form("EMail") <> "" then
		  IDownObj("EMail") = Replace(Replace(Request.Form("EMail"),"""",""),"'","")
	  End If
	  If Request.Form("Provider") <> "" then
		  IDownObj("Provider") = Request.Form("Provider")
	  End If
	  If Request.Form("ProviderUrl") <> "" then
		  IDownObj("ProviderUrl") = Request.Form("ProviderUrl")
	  End If
	  if Request.Form("Pic") <> "" then
		  IDownObj("Pic") = Replace(Request.Form("Pic"),"'","")
	  end if
	  if Request.Form("BrowPop") <> "" then
		  IDownObj("BrowPop") = Cint(Request.Form("BrowPop"))
	  end if
	  if Request.Form("Description") <> "" then
		  IDownObj("Description") = Request.Form("Description")
	  end if
	  IDownObj("PassWord") = Request.Form("PassWord")
	  IDownObj("AddTime") = Formatdatetime(Request.Form("AddTime"))
	  IDownObj("RecTF") = Cint(Request.Form("RecTF"))
	  IDownObj("AuditTF") = Cint(Request.Form("AuditTF"))
	  IDownObj("FileName") = NewsFileNames
	  If Request.Form("BrowPop") <> "" then
		  IDownObj("FileExtName") = "asp"
	  Else
		  IDownObj("FileExtName") = Request.Form("FileExtName")
	  End If
	  IDownObj("ClickNum") = Clng(Request.Form("ClickNum"))
	 IDownObj("NewsTemplet") = Cstr(Request.Form("NewsTemplet"))
	  IDownObj.Update
	  IDownObj.Close
	  Set IDownObj = Nothing
	  '生成文件
	  if Cint(Request.Form("AuditTF")) = 1 then
		  Dim CreatePageObj
		  Set CreatePageObj = Conn.Execute("Select * from DownLoad where DownLoadID='"&INewsID&"'")
			If Not CreatePageObj.eof then
				RefreshDownLoad CreatePageObj
			Else
			  Response.Write("<script>if (confirm(""下载添加成功,但未能成功生成新闻文件,是否继续添加?"")==false) {dialogArguments.location.reload();window.close();} else {window.location=""?ClassID="&IClassID&""";}</script>")
			  Response.End
			End If	
			CreatePageObj.Close
			Set CreatePageObj = Nothing
	 end if  
	  Response.Write("<script>if (confirm(""下载添加成功,是否继续添加?"")==false) {dialogArguments.location.reload();window.close();} else {window.location=""?ClassID="&IClassID&""";} </script>")
	  Response.End
  end if
%>