<% 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 DownLoadID,RsDownModAddrObj,RequestNameArrays,RequestUrlArrays,RsDownAddrObj,RsDASql,RequestNumberArray
DownLoadID = Request("DownLoadID")
If Request.Form("action")="add" then
	AddressNum = Request.Form("AddressNum")
	for i = 1 to AddressNum
		RequestNameArrays = RequestNameArrays & "," & Request.Form("AddressName" & i)
		RequestUrlArrays = RequestUrlArrays & "," & Request.Form("Url" & i)
		RequestNumberArray = RequestNumberArray & "," & Request.Form("Number" & i)
	next
else
	RequestNameArrays = ""
	RequestUrlArrays = ""
	RequestNumberArray = ""
	Set RsDownModAddrObj = Conn.Execute("Select * from DownLoad where DownLoadID='"&DownLoadID&"'")
	If RsDownModAddrObj.eof then
	   Response.Write("<script>alert(""参数传递错误"");dialogArguments.location.reload();window.close();</script>")
	   Response.End
	End If
	Set RsDownAddrObj = Server.CreateObject("Adodb.RecordSet")
	RsDASql = "Select * from DownLoadAddress where DownLoadID='"&DownLoadID&"' order by Number asc"
	RsDownAddrObj.Open RsDASql,Conn,3,3
	AddressNum = RsDownAddrObj.RecordCount
	for i = 0 to RsDownAddrObj.RecordCount-1
			RequestNameArrays = RequestNameArrays & "," & RsDownAddrObj("AddressName")
			RequestUrlArrays = RequestUrlArrays & "," & RsDownAddrObj("Url")
			RequestNumberArray = RequestNumberArray & "," & RsDownAddrObj("Number")
		RsDownAddrObj.MoveNext
	next
	RsDownAddrObj.Close
	Set RsDownAddrObj = Nothing
end if
Dim DirectoryRoot
DirectoryRoot=confimsn("domain")
%>
<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 src="../JS/PublicJS.js" language="JavaScript"></script>
<body topmargin="0" leftmargin="0">
<form name="VoteForm" action="" method="post">
  <table width="100%" border="0" cellspacing="5" cellpadding="0">
    <tr> 
      <td height="5" colspan="2"></td>
    </tr>
    <tr> 
      <td width="11%" height="5"></td>
      <td width="89%">下载地址数量&nbsp;
        <input name="AddressNum" type="text" id="AddressNum" value="<%=AddressNum%>" size="8">
        <input type="button" name="Submit3" value=" 设 置 " onClick="ChooseOption();SetOptionsValue()">
      </td>
    </tr>
    <tr> 
      <td colspan="2" id="Options">&nbsp;</td>
    </tr>
    <tr> 
      <td colspan="2"><div align="center"> 
          <input type="submit" name="Submit" value=" 确 定 ">
          <input name="action" type="hidden" id="action2" value="add">
          &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
          <input type="button" name="Submit2" value=" 取 消 " onclick="window.close();">
        </div></td>
    </tr>
  </table>
</form>
</body>
</html>
<script>
var AddressCount=0;
var RequestNameArray=new Array();
var RequestColorArray=new Array();
var TempRequestNameArray,TempRequestColorArray,TempRequestNumberArray;
TempRequestNameArray='<% = RequestNameArrays %>';
TempRequestColorArray='<% = RequestUrlArrays %>';
TempRequestNumberArray='<% = RequestNumberArray %>';
RequestNameArray = TempRequestNameArray.split(",");
RequestColorArray = TempRequestColorArray.split(",");
RequestNumberArray = TempRequestNumberArray.split(",");
AddressCount=RequestNumberArray.length;
window.setTimeout('SetOptionsValue();',100);
function SetOptionsValue()
{
		//alert(AddressCount);
	if ((RequestNameArray.length==0)||(RequestColorArray.length==0)||(RequestNumberArray.length==0)) return;
	var AddressNum=document.VoteForm.AddressNum.value;
	for (i=1;i<=AddressNum;i++)
	{
		if (i>=AddressCount) 
		{
			document.all('AddressName'+i).value='';
			document.all('Url'+i).value='';
			document.all('Number'+i).value='';
		}
		else
		{
			document.all('AddressName'+i).value=RequestNameArray[i];
			document.all('Url'+i).value=RequestColorArray[i];
			document.all('Number'+i).value=RequestNumberArray[i];
		}
	}
}
function ChooseOption()
 {
	var AddressNum = document.VoteForm.AddressNum.value;
	var i,Optionstr;
	Optionstr = '<table width="100%" border="0" cellspacing="5" cellpadding="0">';
	for (i=1;i<=AddressNum;i++)
	{
	   Optionstr = Optionstr+'<tr><td><div align="center">地址名称'+i+'&nbsp;<input type="text" size="20" name="AddressName'+i+'" value="">&nbsp;</div></td><td><div align="center">链接地址&nbsp;<input type="text" size="30" name="Url'+i+'" value="">&nbsp;</div></td><td><div align="center"><input type="button" name="Submit4" onClick="SetFilePath(document.VoteForm.Url'+i+');" value="选择文件"></div></td><td><div align="center">地址排序&nbsp;<input type="text" name="Number'+i+'" value="'+i+'" size="3"></div></td></tr>';
	}
	Optionstr = Optionstr+'</table>';  
	document.all.Options.innerHTML = Optionstr;
  }
function SetFilePath(Obj)
{
	var ReturnValue=OpenWindow('../inc/SelectPic.asp?CurrPath=/<% = UpFiles %>',550,300);
	if (ReturnValue!='') Obj.value=ReturnValue;
}
ChooseOption();
</script>
<%
  If Request.Form("action")="add" then
     Dim RsVoteObj,RsVoteSql,VoteName,AddressNum,RsDownAddrAddObj,RsVoteOptionSql,i
	 For i=1 to Request.Form("AddressNum")
	     if Request.Form("AddressName"&i)="" or isnull(Request.Form("AddressName"&i&"")) then
		    Response.Write("<script>alert(""地址名称"&i&"不能为空"");</script>")
			Response.End
		 end if
		 If Request.Form("Url"&i)="" or isnull(Request.Form("Url"&i)) then
		    Response.Write("<script>alert(""链接地址"&i&"不能为空"");</script>")
			Response.End
		 End If
	 Next
	 Conn.Execute("Delete from DownLoadAddress where DownLoadID='"&DownLoadID&"'")
			 For i = 1 to Request.Form("AddressNum")
				 Set RsDownAddrAddObj = Server.CreateObject("Adodb.RecordSet")
				 RsVoteOptionSql = "Select * from DownLoadAddress where 1=0"
				 RsDownAddrAddObj.Open RsVoteOptionSql,Conn,3,3
				 RsDownAddrAddObj.AddNew
			 	 RsDownAddrAddObj("ID") = GetRandomID18()
			 	 RsDownAddrAddObj("DownLoadID") = Cstr(DownLoadID)
			 	 RsDownAddrAddObj("AddressName") = Replace(Request.Form("AddressName"&i),"'","")
				 RsDownAddrAddObj("Url") = Request.Form("Url"&i)
				 If isnumeric(Request.Form("Number"&i)) then
					 RsDownAddrAddObj("Number") = Cint(Request.Form("Number"&i))
				 Else
					 RsDownAddrAddObj("Number") = i
				 End If
				 RsDownAddrAddObj.Update
				 RsDownAddrAddObj.Close
			 Next
			 Set RsDownAddrAddObj = Nothing
			 '生成文件
			  Dim CreatePageObj
			  Set CreatePageObj = Conn.Execute("Select * from DownLoad where DownLoadID='"&DownLoadID&"'")
				If Not CreatePageObj.eof then
					RefreshDownLoad CreatePageObj
				End If	
				CreatePageObj.Close
				Set CreatePageObj = Nothing  
		 Response.Write("<script>alert(""链接地址设置成功"");dialogArguments.location.reload();window.close();</script>")
		 Response.End
  End if
  Set Conn = Nothing
%>