<!--#include file="../../Inc/Const.asp" -->
<!--#include file="../../Inc/Cls_DB.asp" -->
<%
Dim Conn,DownLoadConfig,DBC,SQLStr,IPList,Lock,IPType
Set DBC = New DataBaseClass
Set Conn = DBC.OpenConnection
Set DBC = Nothing
%>
<!--#include file="../../Inc/Session.asp" -->
<!--#include file="../../Inc/CheckPopedom.asp" -->
<%
if Not JudgePopedomTF(Session("Name"),"P0607") then Call ReturnError1()
SQLStr="Select * from DownLoadConfig"
Set DownLoadConfig = Server.CreateObject("ADODB.RecordSet")
DownLoadConfig.Open SQLStr,Conn,1,3
if Not DownLoadConfig.Eof then
	IPList = DownLoadConfig("IPList")
	Lock = DownLoadConfig("Lock")
	IPType = DownLoadConfig("IPType")
else
	IPList = ""
	Lock = ""
	IPType = ""
end if
if Request.Form("Operation") = "Modify" then
	On Error Resume Next
	IPList = Request.Form("IPList")
	Lock = Request.Form("Lock")
	IPType = Request.Form("IPType")
	DownLoadConfig("IPList")=Replace(Replace(IPList,"'",""),"""","")
	if Lock = "1" then
		DownLoadConfig("Lock") = 1
	else
		DownLoadConfig("Lock") = 0
	end if
	DownLoadConfig("IPType")=Replace(Replace(IPType,"'",""),"""","")
	DownLoadConfig.update
	if Err.Mumber = 0 then
%>
<script language="javascript">
alert('修改成功');window.location='DownLoadParameter.asp';
</script>
<%
	else
%>
<script language="javascript">
alert('有错误发生，请刷新后再试');window.location='DownLoadParameter.asp';
</script>
<%
		Response.Redirect("DownLoadParameter.asp")  
	end if
	Response.End
end if 
%>
<html>
<title>下载参数基本参数设置</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<style type="text/css">
<!--
.SysParaButtonStyle {
	border-top-width: 1px;
	border-right-width: 1px;
	border-bottom-width: 1px;
	border-left-width: 1px;
	border-right-style: solid;
	border-bottom-style: solid;
	border-left-style: solid;
	border-right-color: #999999;
	border-bottom-color: #999999;
	border-left-color: #FFFFFF;
	background-color: #E6E6E6;
}
-->
</style>
</head>
<link href="../../CSS/css.css" rel="stylesheet">
<body bgcolor="#FFFFFF" topmargin="0" leftmargin="0" scroll=yes>
<table width="100%"  border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td height="23" class="SysParaButtonStyle"> 
      <div align="center"><strong>下载基本参数设置</strong></div></td>
  </tr>
</table>
 <tr><td height="50">&nbsp;</td>
 </tr>
  <tr><td>
<table width="677" border="1" align="center" cellpadding="2" cellspacing="1"  bordercolor="e6e6e6">
      <form name="Form" method=post action="" >
        <tr valign="middle"> 
          <td width="120" height="30"> <div align="left"> 是否加防盗链：</div></td>
          <td width="469" height="30"><input <% if Lock=1 then Response.Write("Checked") %>  name="Lock" type="checkbox" id="Lock" value="1">
            <input name="Operation" type="hidden" id="Operation" value="Modify">
            <input name="IPList" type="hidden" id="IPList"></td>
        </tr>
        <tr valign="middle" > 
          <td width="120" rowspan="2"> <div align="left"> 
              <p> 
                <input name="IPType" <% if IPType=1 then Response.Write("Checked") %> type="radio" value="1" checked>
                锁定IP段：</p>
              <p> 
                <input type="radio" <% if IPType=0 then Response.Write("Checked") %>  name="IPType" value="0">
                针对IP段：</p>
            </div></td>
          <td height="30">
		  <select name="IPSelectList" size="10" multiple id="IPSelectList" style="width:100%;">
              <%
		  Dim TempArray,i
		  if Not IsNull(IPList) then
			  TempArray = Split(IPList,"$")
			  for i=LBound(TempArray) to UBound(TempArray)
			  %>
			  <option value="<% = TempArray(i) %>"><% = TempArray(i) %></option>
			  <%
			  Next
		  end if
		  %>
           </select>
		  </td>
        </tr>
        <tr valign="middle" > 
          <td height="30" width="469"><input name="BeginIP" type="text" id="BeginIP">
            --- 
            <input name="EndIP" type="text" id="EndIP"> <input type="button" onClick="AddIPList();" name="Submit3" value=" 添 加 "> 
            <input type="button" onClick="DelIPList();" name="Submit4" value=" 删 除 "> </td>
        </tr>
        <tr valign="middle" > 
          <td height="30" colspan="2"> <div align="center"> 
              <input type="submit" name="Submit" onClick="SetIPList();" value=" 确 定 ">
              <input type="reset" name="Submit2" value=" 还 原 ">
            </div></td>
        </tr>
      </form>
    </table>
</body>
</html>
<%
DownLoadConfig.close
Set DownLoadConfig =nothing
Set Conn=nothing
%>
<script language="JavaScript">
function AddIPList()
{
	var BeginIPStr=document.Form.BeginIP.value,EndIPStr=document.Form.EndIP.value;
	if (CheckIP(BeginIPStr))
	{
		if (CheckIP(EndIPStr))
		{
			if (CheckBeginAndEndIP(BeginIPStr,EndIPStr))
			{
				var TempStr=BeginIPStr+'-'+EndIPStr;
				AddList(document.Form.IPSelectList,TempStr,TempStr);
				document.Form.BeginIP.value='';
				document.Form.EndIP.value='';
			}
		}
		else
		{
			alert('结束IP地址不对');
			document.Form.EndIP.focus();
			document.Form.EndIP.select();
		}
	}
	else
	{
		alert('开始IP地址不对');
		document.Form.BeginIP.focus();
		document.Form.BeginIP.select();
	}
}
function DelIPList()
{
	DelList(document.Form.IPSelectList);
}
function SetIPList()
{
	var TempStr='',Obj=document.Form.IPSelectList;
	for(var i=0;i<Obj.length;i++)
	{
		if (TempStr=='') TempStr=Obj.options(i).value;
		else TempStr=TempStr+'$'+Obj.options(i).value;
	}
	document.Form.IPList.value=TempStr;
}
function CheckBeginAndEndIP(BeginIPStr,EndIPStr)
{
	return true;
}
function CheckIP(IPAddress)
{
	var TempArray=null,TempInt=0;
	TempArray=IPAddress.split('.');
	if (TempArray.length!=4) return false;
	for (var i=0;i<TempArray.length;i++)
	{
		if (TempArray[i]!='')
		{
			TempInt=parseInt(TempArray[i]);
			if ((TempInt<0)||(TempInt>255)) return false;
		}
		else return false;
	}
	return true;
}
function AddList(SelectObj,Lable,LableContent)
{
	var i=0,AddOption;
	if (!SearchOptionExists(SelectObj,Lable))
	{
		AddOption = document.createElement("OPTION");
		AddOption.text=Lable;
		AddOption.value=LableContent;
		SelectObj.add(AddOption);
		//SelectObj.options(SelectObj.length-1).selected=true;
	}
}
function SearchOptionExists(Obj,SearchText)
{
	var i;
	for(i=0;i<Obj.length;i++)
	{
		if (Obj.options(i).text==SearchText)
		{
			Obj.options(i).selected=true;
			return true;
		}
	}
	return false;
}
function DelList(SelectObj)
{
	var OptionLength=SelectObj.length;
	for(var i=0;i<OptionLength;i++)
	{
		if (SelectObj.options(SelectObj.length-1).selected==true) SelectObj.options.remove(SelectObj.length-1);
		//OptionLength=SelectObj.length;
	}
}
</script>