<!--#include file="../inc/config.asp"-->
<!--#include file="../inc/conn.asp"-->
<!-- #include file="inc/Session.asp" -->
<!--#include file="inc/collectfunc.asp"-->
<!-- #include file="inc/checkrole.asp" -->
<%
Server.ScriptTimeout = 999999
'''''''''''''''''''''''''''''''''''''''''''''''
call checkPrevilege(Session("Name"),"p09")
'''''''''''''''''''''''''''''''''''''''''''''''
BeginTime=Timer
'获得参数==============================
dim taskid
if not isempty(request("taskid")) then 
	taskid=Cint(request("taskid"))
else
	taskid=0
end if
dim taskname,taskdes,collecturl,encode,catalogid,IfLogin,LoginUrl,LoginActUrl,PostData,LoginFailMsg
taskname=trim(request.Form("taskname"))
if(taskname="" or len(taskname)<1) then
	response.Write("错误!任务名称不能为空!")
	response.Write("&nbsp;&nbsp;<a href=""#"" onClick=""javascript:history.back();""><==返回</a>")
	response.End()
end if
taskdes=trim(request.Form("taskdes"))
if(taskdes="" or len(taskdes)<1) then
	response.Write("错误!任务描述不能为空!")
	response.Write("&nbsp;&nbsp;<a href=""#"" onClick=""javascript:history.back();""><==返回</a>")
	response.End()
end if
collecturl=trim(request.Form("collecturl"))
if(collecturl="" or len(collecturl)<1) then
	response.Write("错误!采集地址不能为空!")
	response.Write("&nbsp;&nbsp;<a href=""#"" onClick=""javascript:history.back();""><==返回</a>")
	response.End()
end if
encode=trim(request.Form("encode"))
if(encode="" or len(encode)<1) then
	response.Write("错误!编码不能为空!")
	response.Write("&nbsp;&nbsp;<a href=""#"" onClick=""javascript:history.back();""><==返回</a>")
	response.End()
end if
catalogid=request.Form("catalogid")
if catalogid<>"" and isnumeric(catalogid) then
	catalogid=Cint(catalogid)
else
	response.Write("请选择要采集到的栏目!")
	response.Write("&nbsp;&nbsp;<a href=""#"" onClick=""javascript:history.back();""><==返回</a>")
	response.End()
end if
IfLogin=Cint(request.Form("IfLogin"))

'登录
if(IfLogin=1) then
	LoginUrl=trim(request.Form("LoginUrl"))
	if(LoginUrl="" or len(LoginUrl)<1) then
		response.Write("错误!登录地址不能为空!")
		response.Write("&nbsp;&nbsp;<a href=""#"" onClick=""javascript:history.back();""><==返回</a>")
		response.End()
	end if
	LoginActUrl=trim(request.Form("LoginActUrl"))
	if(LoginActUrl="" or len(LoginActUrl)<1) then
		response.Write("错误!登录提交地址不能为空!")
		response.Write("&nbsp;&nbsp;<a href=""#"" onClick=""javascript:history.back();""><==返回</a>")
		response.End()
	end if
	PostData=trim(request.Form("PostData"))
	if(PostData="" or len(PostData)<1) then
		response.Write("错误!发送数据不能为空!")
		response.Write("&nbsp;&nbsp;<a href=""#"" onClick=""javascript:history.back();""><==返回</a>")
		response.End()
	end if
	LoginFailMsg=trim(request.Form("LoginFailMsg"))
	if(LoginFailMsg="" or len(LoginFailMsg)<1) then
		response.Write("错误!登录失败信息不能为空!")
		response.Write("&nbsp;&nbsp;<a href=""#"" onClick=""javascript:history.back();""><==返回</a>")
		response.End()
	end if
	loginback=PostHttpPage(LoginUrl,LoginActUrl,PostData) 
	if(instr(loginback,LoginFailMsg)>0) then
		response.Write("登录失败，请重新设置登录参数！")
		response.Write("&nbsp;&nbsp;<a href=""#"" onClick=""javascript:history.back();""><==返回</a>")
		response.End()
	else
		response.Write("登录成功，系统继续执行.....")
	end if
end if

if(taskid>=1) then
'======================================
'修改任务到库
'======================================
	set rs=server.CreateObject("adodb.recordset") 
	rs.open "select top 1 * from collect where id="&taskid,conn,3,3
	if not rs.eof then
		rs("TaskName")=taskname
		rs("Taskdes")=taskdes
		rs("CollectUrl")=collecturl
		rs("Encode")=encode
		rs("IfLogin")=IfLogin
		rs("LoginUrl")=LoginUrl
		rs("LoginActUrl")=LoginActUrl
		rs("PostData")=PostData
		rs("LoginFailMsg")=LoginFailMsg
		rs("CatalogId")=catalogid
		rs("Moditime")=now
		rs.update	
		rs.close
		set rs=nothing
	else
		response.Write("没有找到ID为"&taskid&"的任务")
		response.End()
	end if
else
'======================================
'添加新任务到库
'======================================
	set rs=server.CreateObject("adodb.recordset") 
	rs.open "select top 1 * from collect where TaskName='"&taskname&"'",conn,3,3
	if not rs.eof then
		response.Write("此任务名称己经存在!请另起一个名字!")
		response.End()
	else
		rs.addnew
		rs("TaskName")=taskname
		rs("Taskdes")=taskdes
		rs("CollectUrl")=collecturl
		rs("Encode")=encode
		rs("IfLogin")=IfLogin
		rs("LoginUrl")=LoginUrl
		rs("LoginActUrl")=LoginActUrl
		rs("PostData")=PostData
		rs("LoginFailMsg")=LoginFailMsg
		rs("CatalogId")=catalogid
		rs("Moditime")=now
		rs.update	
		rs.close
		set rs=nothing
	end if
end if
%>
<html>
<head>
<title>信息采集</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<style type="text/css">
<!--
body {
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
	background-color: #D4D0C8;
}
input{ font-size:12px;}
form{margin:0;}
-->
</style>
<link href="style/global.css" rel="stylesheet" type="text/css">
<style type="text/css">
body{font-size:12px;}
<!--
.style1 {color: #FF0000}
.style2 {color: #CCCCCC}
.style3 {color: #FFFFFF;
	font-weight: bold;
}
-->
</style>
</head>
<body>
<table width="100%"  border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td><iframe src="right_top.htm" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" height="30" width="100%"></iframe></td>
  </tr>
</table>
<table width="100%"  border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#999999">
  <tr bgcolor="#FF9900">
    <td width="100%" height="22"><div align="center"><span class="style3">◆ 信息采集 ◆</span></div></td>
  </tr>
</table>
<!--开始采集规则-->
<fieldset style="margin:5px 50px 5px 50px; border-top:1px solid #ffffff; border-right:1px solid #000000;border-bottom:1px solid #000000;border-left:1px solid #ffffff;">
<%
if(taskid>=1) then
	set rs=server.CreateObject("adodb.recordset") 
	rs.open "select top 1 * from collect where id="&taskid,conn,3,3
	if not rs.eof then
%>
<form name="form1" method="post" action="collect3.asp">
	  <legend>第二步设置采集规则</legend>
	<table width="100%"  border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td width="28%"><div align="right">起始地址：</div></td>
    <td width="72%"><div align="left">
      
        <input name="StartUrl" type="text" id="StartUrl" size="30" value="<%=rs("StartUrl")%>">
    </div></td>
    </tr>
  <tr>
    <td><div align="right">列表起始标记：</div></td>
    <td><textarea name="ListStartTag" cols="50" rows="6" id="ListStartTag"><%=rs("ListStartTag")%></textarea></td>
  </tr>
  <tr>
    <td><div align="right">列表结束标记：</div></td>
    <td><textarea name="ListEndTag" cols="50" rows="6" id="ListEndTag"><%=rs("ListEndTag")%></textarea></td>
  </tr>
  <tr>
    <td><div align="right">列表中链接设置：</div></td>
    <td height="50"><input name="LinkSet" type="radio" onClick="LinkAbs.style.display='none'" value="0" <%if(rs("LinkSet")=0) then response.Write("checked")%>>
      系统自动
      <input name="LinkSet" type="radio" value="1" onClick="LinkAbs.style.display=''" <%if(rs("LinkSet")=1) then response.Write("checked")%>>
      相对地址转绝对地址<br>
	  <div id="LinkAbs" <%if(rs("LinkSet")=0) then response.Write("style=""display:none; """)%>>
      将相对链接中的
      <input name="LinkFrom" type="text" size="10" value="<%=rs("LinkFrom")%>">
      替换为绝对地址
      <input name="LinkTo" type="text" size="20" value="<%=rs("LinkTo")%>">
	  </div>	  </td>
  </tr>
  <tr>
    <td><div align="right">过滤字符：</div></td>
    <td><textarea name="removelinkstr" cols="50" rows="6" id="removelinkstr"><%=rs("removelinkstr")%></textarea></td>
  </tr>
  <tr>
    <td><div align="right">分页设置：</div></td>
    <td><div align="left">
      <input name="PageSplitTag" type="text" id="PageSplitTag" size="60" value="<%=rs("PageSplitTag")%>">
    <br>(例：http://www.**.com/index.asp?id=$NUM$)</div></td>
  </tr>
  <tr>
    <td><div align="right">采集页数范围：</div></td>
    <td><div align="left">
      <input name="StartPageNum" type="text" id="StartPageNum" size="5" value="<%=rs("StartPageNum")%>">
      到
      <input name="EndPageNum" type="text" id="EndPageNum" size="5" value="<%=rs("EndPageNum")%>">
    </div></td>
  </tr>
  <tr>
    <td><div align="right"></div></td>
    <td height="50"><div align="left">
	<input type="hidden" name="taskid" value="<%=taskid%>">
	<input type="hidden" name="catalogid" value="<%=catalogid%>">
	<input type="hidden" name="encode" value="<%=encode%>">
	<input type="hidden" name="taskname" value="<%=taskname%>">
      <input type="submit" name="Submit3" value="下一步">
      <input type="button" name="btn" value="返  回" onClick="javascript:history.go(-1);">
</div></td>
  </tr>
</table>
</form>
<%
	end if
	rs.close
	set rs=nothing
else
%>
<form name="form1" method="post" action="collect3.asp">
	  <legend>第二步设置采集规则</legend>
	<table width="100%"  border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td width="36%"><div align="right">起始地址：</div></td>
    <td width="64%"><div align="left">
      
        <input name="StartUrl" type="text" id="StartUrl" size="30">
    </div></td>
    </tr>
  <tr>
    <td><div align="right">列表起始标记：</div></td>
    <td><textarea name="ListStartTag" cols="50" rows="6" id="ListStartTag"></textarea></td>
  </tr>
  <tr>
    <td><div align="right">列表结束标记：</div></td>
    <td><textarea name="ListEndTag" cols="50" rows="6" id="ListEndTag"></textarea></td>
  </tr>
  <tr>
    <td><div align="right">列表中链接设置：</div></td>
    <td height="50"><input name="LinkSet" type="radio" onClick="LinkAbs.style.display='none'" value="0" checked>
      系统自动
      <input name="LinkSet" type="radio" value="1" onClick="LinkAbs.style.display=''">
      相对地址转绝对地址<br>
	  <div id="LinkAbs" style="display:none; ">
      将相对链接中的
      <input name="LinkFrom" type="text" size="10">
      替换为绝对地址
      <input name="LinkTo" type="text" size="20">
	  </div>	  </td>
  </tr>
  <tr>
    <td><div align="right">过滤字符：</div></td>
    <td><textarea name="removelinkstr" cols="50" rows="6" id="removelinkstr"></textarea></td>
  </tr>
  <tr>
    <td><div align="right">分页设置：</div></td>
    <td><div align="left">
      <input name="PageSplitTag" type="text" id="PageSplitTag" size="30">
      <br>
    (例：http://www.**.com/index.asp?id=$NUM$)</div></td>
  </tr>
  <tr>
    <td><div align="right">采集页数范围：</div></td>
    <td><div align="left">
      <input name="StartPageNum" type="text" id="StartPageNum" size="5">
      到
      <input name="EndPageNum" type="text" id="EndPageNum" size="5">
    </div></td>
  </tr>
  <tr>
    <td><div align="right"></div></td>
    <td height="50"><div align="left">
	<input type="hidden" name="catalogid" value="<%=catalogid%>">
	<input type="hidden" name="encode" value="<%=encode%>">
	<input type="hidden" name="taskname" value="<%=taskname%>">
      <input type="submit" name="Submit3" value="下一步">
      <input type="button" name="btn" value="返  回" onClick="javascript:history.go(-1);">
</div></td>
  </tr>
</table>
</form>
<%end if%>
	
</fieldset>
<!--以下是采集地址的内容-->
<fieldset style="margin:5px 50px 5px 50px; border-top:1px solid #ffffff; border-right:1px solid #000000;border-bottom:1px solid #000000;border-left:1px solid #ffffff;">
<legend>以下是采集地址的内容</legend>
<%'=RemoveBlank(RemoveHTML(ReadXml(collecturl,encode,"","")))%>
<%=ReadXml(collecturl,encode,"","")%>
</fieldset>
<p align="center"><%=CStr(FormatNumber((Timer-BeginTime)*1000,2))& "毫秒"%></p>
</body>
</html>
<%call connclose()%>