<%@ page contentType="text/html; charset=GBK"%>
<%@ page import="java.sql.*,gbase.db.*,gbase.util.*" %>
<%@ include file="../checkLogin.jsp" %>
<SCRIPT language="JavaScript" src="../js/util.js"></SCRIPT>
<LINK href="../css/css.css" rel=stylesheet>
<SCRIPT language=JavaScript>
 function ceshi(Num){
    var content=document.form1.content.value;
    var huoqv="";
    if(Num==1)
      huoqv=document.form1.list_start_str.value;
    else if(Num==2)
      huoqv=document.form1.list_end_str.value;
    else if(Num==3)
      huoqv=document.form1.listpage_start_str.value;
    else if(Num==4)
      huoqv=document.form1.listpage_end_str.value;  
    else if(Num==5)
      huoqv=document.form1.href_start_str.value; 
    else if(Num==6)
      huoqv=document.form1.href_end_str.value;     
    if(Num!=5 && Num!=6){
    if(huoqv=="")
      alert("测试无效！代码为空！");
    else if(content.indexOf(huoqv)<0)
      alert("测试无效！网页没有这些代码。");
    else if(content.indexOf(huoqv)>0 && content.lastIndexOf(huoqv)>0 && content.indexOf(huoqv)!=content.lastIndexOf(huoqv))
      alert("测试失败！代码有重复,开始或结束至少有一处代码是唯一才有效！");
    else
      alert("测试成功！代码在页面是唯一的。");
    }
    else
    {
    if(huoqv=="")
      alert("测试无效！代码为空！");
    else if(content.indexOf(huoqv)<0)
      alert("测试无效！网页没有这些代码。");
    else
      alert("测试成功！代码在页面存在。");
    }  
   }     
 var openurl=0;
 function setFileFields(weburl){   
    if (openurl==0){
        str="<iframe id='IFrame1' marginwidth=0 marginheight=0 frameborder=0  width='785' height='400' src="+weburl+"></iframe>";
        objFiles.innerHTML=str;
        openurl=1
    }
 }
var tID=0;
function ShowTabs(ID){
  if(ID!=tID){
    TabTitle[tID].className='title5';
    TabTitle[ID].className='title6';
    Tabs[tID].style.display='none';
    Tabs[ID].style.display='';
    tID=ID;
  }
}
</SCRIPT>
<%
DBOperation theDBOperation = new DBOperation();

String id = request.getParameter("id") == null ? "" :request.getParameter("id");
String action = request.getParameter("action") == null ? "" :request.getParameter("action");
String listurl = "";
String web_encoding="GBK";
String list_start_str="";    
String list_end_str="";    
String href_start_str="";    
String href_end_str="";    
String hreftype="0";    
String rehrefurlstr="";    
String listpagetype="0";    
String listpage_start_str="";    
String listpage_end_str="";    
String listpage_param_url="";    
String listpage_start_id="0";    
String listpage_end_id="0";    
String listpage_url="";    
   
if(action.equals("update") || action.equals("view"))
{
String sql = "select * from web_collection  where id="+id+"";
System.out.println("sql====:"+sql);
ResultSet rs =theDBOperation.getResultSet(sql);
if(rs.next())
{
listurl=rs.getString("listurl")==null?"":rs.getString("listurl");
web_encoding=rs.getString("web_encoding")==null?"":rs.getString("web_encoding");
list_start_str=rs.getString("list_start_str")==null?"":rs.getString("list_start_str");
list_end_str=rs.getString("list_end_str")==null?"":rs.getString("list_end_str");  
href_start_str=rs.getString("href_start_str")==null?"":rs.getString("href_start_str");    
href_end_str=rs.getString("href_end_str")==null?"":rs.getString("href_end_str");    
hreftype=rs.getString("hreftype")==null?"0":rs.getString("hreftype");    
rehrefurlstr=rs.getString("rehrefurlstr")==null?"":rs.getString("rehrefurlstr");    
listpagetype=rs.getString("listpagetype")==null?"0":rs.getString("listpagetype");    
listpage_start_str=rs.getString("listpage_start_str")==null?"":rs.getString("listpage_start_str");    
listpage_end_str=rs.getString("listpage_end_str")==null?"":rs.getString("listpage_end_str");    
listpage_param_url=rs.getString("listpage_param_url")==null?"":rs.getString("listpage_param_url");    
listpage_start_id=rs.getString("listpage_start_id")==null?"0":rs.getString("listpage_start_id");    
listpage_end_id=rs.getString("listpage_end_id")==null?"0":rs.getString("listpage_end_id");    
listpage_url=rs.getString("listpage_url")==null?"":rs.getString("listpage_url");
}
}
CollectionManager theCollectionManager=new CollectionManager();
String content=theCollectionManager.getUrlContent(listurl,web_encoding);
%>
<html>
<head>
<title>
采编项目管理
</title>
</head>
<body leftmargin="0" topmargin="0">

<!--导航-->
    <table border="0" cellpadding="0" cellspacing="0" width="100%">
       <tr>
		<td width="100%" height="20"  bgcolor="#eeeeee" class="p2">您当前所在的位置>>采编项目管理</td>
	   </tr>
       <tr>
          <td width="100%" height="2"> <img border="0" src="../images/spacer.gif" width="1" height="3"></td>
       </tr>
    </table>
<!--标题-->
<BR>
&nbsp;&nbsp;采编项目设置步骤：
<A href="web_collection_content1.jsp?action=view&id=<%=id%>">基本设置</A>
<%if(action.equals("update")){%> 
&gt;&gt; <A href="web_collection_content2.jsp?action=update&id=<%=id%>"><FONT color=red>列表设置</FONT></A> 
&gt;&gt; <A href="web_collection_content3.jsp?action=update&id=<%=id%>">正文设置</A> 
&gt;&gt; 采样测试
<%} else {%>
&gt;&gt; <A href="web_collection_content2.jsp?action=view&id=<%=id%>"><FONT color=red>列表设置</FONT></A> 
&gt;&gt; 正文设置 
&gt;&gt; 采样测试
<%}%> 
&gt;&gt; 完成设置
<BR><BR>

<div align="center">
   <table border="0" width="100%" cellspacing="0" cellpadding="0" height="28">
	<tr align=middle height=24>
	        <td valign="bottom" align="right" width="7"></td>
		<TD class=title6 id=TabTitle onclick=ShowTabs(0) width="60">基本设置</TD>
                <TD class=title5 id=TabTitle onclick=ShowTabs(1)  width="60">分页设置</TD>
                <TD class=title5 id=TabTitle onclick=ShowTabs(2)  width="60">代码预览</TD>
                <TD class=title5 id=TabTitle onclick="ShowTabs(3);setFileFields('<%=listurl%>')"  width="60">网页预览</TD>
		<td valign="bottom" align="right"></td>
	</tr>
	<tr>
		<td bgcolor="#2C9CC4" colspan="7"><img border="0" src="../images/bline_3.gif" width="1" height="4"></td>
	</tr>
</table>
</div><br>

<FORM name=form1 action="web_collection_save2.jsp" method=post>
<input name="action" type="hidden" value="<%=action%>">
<input name="id" type="hidden" value="<%=id%>">
<table width="90%" class="p1" border="0" cellSpacing="1" cellPadding="3" align="center" bgColor="#cccccc">
        <TBODY id=Tabs>
        <TR>
          <TD bgColor=#e9f0f4 align=right width=120>列表开始代码：</TD>
          <TD onmouseover='vbscript:me.bgcolor="#F5F5F5"' onmouseout='vbscript:me.bgcolor="#FFFFFF"' bgColor=#ffffff>
            <TEXTAREA  name=list_start_str rows=4 cols=70><%=list_start_str%></TEXTAREA>&nbsp;<FONT  color=red>*</FONT><INPUT onclick=ceshi(1) type=button value=测试代码></TD></TR>
        <TR>
          <TD bgColor=#e9f0f4 align=right width=120>列表结束代码：</TD>
          <TD onmouseover='vbscript:me.bgcolor="#F5F5F5"' onmouseout='vbscript:me.bgcolor="#FFFFFF"' bgColor=#ffffff>
          <TEXTAREA  name=list_end_str rows=4 cols=70><%=list_end_str%></TEXTAREA>&nbsp;<FONT color=red>*</FONT><INPUT onclick=ceshi(2) type=button value=测试代码></TD></TR>
        <TR>
          <TD bgColor=#e9f0f4 align=right width=120>链接开始代码：</TD>
          <TD onmouseover='vbscript:me.bgcolor="#F5F5F5"' onmouseout='vbscript:me.bgcolor="#FFFFFF"' bgColor=#ffffff>
          <TEXTAREA  name=href_start_str rows=4 cols=70><%=href_start_str%></TEXTAREA>&nbsp;<FONT  color=red>*</FONT><INPUT onclick=ceshi(5) type=button value=测试代码></TD></TR>
        <TR>
          <TD bgColor=#e9f0f4 align=right width=120>链接结束代码：</TD>
          <TD onmouseover='vbscript:me.bgcolor="#F5F5F5"'	onmouseout='vbscript:me.bgcolor="#FFFFFF"' bgColor=#ffffff>
          <TEXTAREA  name=href_end_str rows=4 cols=70><%=href_end_str%></TEXTAREA>&nbsp;<FONT color=red>*</FONT><INPUT onclick=ceshi(6) type=button value=测试代码></TD></TR>
        <TR>
          <TD bgColor=#e9f0f4 align=right width=120></TD>
          <TD onmouseover='vbscript:me.bgcolor="#F5F5F5"' onmouseout='vbscript:me.bgcolor="#FFFFFF"' bgColor=#ffffff>
          <FONT color=#0099ff>例如：列表中的链接代码形如：&lt;a href='Article/Class1/1358.html'  target='_blank'&gt;<BR>则链接开始代码应该设置为：</FONT><FONT color=red>&lt;a  href='</FONT><FONT color=#0099ff>，链接结束代码设置为：</FONT><FONT color=red>' target='_blank'&gt;</FONT> </TD></TR>
        <TR>
          <TD bgColor=#e9f0f4 align=right width=120>特殊处理：</TD>
          <TD onmouseover='vbscript:me.bgcolor="#F5F5F5"' onmouseout='vbscript:me.bgcolor="#FFFFFF"' bgColor=#ffffff>
           <INPUT onclick="javascript:HttpUrl1.style.display='none'" type=radio CHECKED value=0 name=hreftype>关闭&nbsp; 
           <INPUT onclick="javascript:HttpUrl1.style.display=''" type=radio value=1 name=hreftype>启用 </TD></TR>
        <TR class=tdbg id=HttpUrl1 style="DISPLAY: none">
          <TD bgColor=#e9f0f4 vAlign=top align=right width=120>重定向URL：</TD>
          <TD onmouseover='vbscript:me.bgcolor="#F5F5F5"' onmouseout='vbscript:me.bgcolor="#FFFFFF"' bgColor=#ffffff>
            <INPUT maxLength=200 size=49 name=rehrefurlstr value="<%=rehrefurlstr%>"> 
            <BR><FONT 
            color=#0099ff>当链接代码是一些非常特殊的JS函数调用代码时，请设置此选项。<BR>例如：列表中的链接代码形如：&lt;a 
            href='#' 
            onclick='opennews(137)'&gt;，对应的opennews(id)函数的代码为：<BR>window.open('http://www.xxxx.com/xxx/news.asp?id='+id,'','****')。<BR>则链接开始代码设置为：</FONT><FONT 
            color=red> &lt;a href='#' onclick='opennews(</FONT><FONT 
            color=#0099ff>，链接结束代码为：<FONT color=red>)'&gt;</FONT><FONT 
            color=#0099ff>，<BR>此处“重定向URL”设置为：</FONT><FONT 
            color=red>http://www.xxxx.com/xxx/news.asp?id={$ID}</FONT><FONT 
            color=#0099ff>（{$ID}是系统规定的标签）</FONT> </FONT></TD></TR></TBODY>
        <TBODY id=Tabs style="DISPLAY: none">
        <TR>
          <TD bgColor=#e9f0f4 align=right width=120>选择分页类型：</TD>
          <TD onmouseover='vbscript:me.bgcolor="#F5F5F5"' onmouseout='vbscript:me.bgcolor="#FFFFFF"' bgColor=#ffffff>
            <INPUT onclick="javascript:ListPaing1.style.display='none';ListPaing2.style.display='none';ListPaing3.style.display='none'"  type=radio CHECKED value=0 name=listpagetype>不采集列表分页&nbsp; 
            <INPUT onclick="javascript:ListPaing1.style.display='';ListPaing2.style.display='none';ListPaing3.style.display='none'" type=radio value=1 name=listpagetype>从源代码中获取下一页的URL&nbsp; 
            <INPUT onclick="javascript:ListPaing1.style.display='none';ListPaing2.style.display='';ListPaing3.style.display='none'" type=radio value=2 name=listpagetype>批量指定分页URL代码&nbsp; 
            <INPUT onclick="javascript:ListPaing1.style.display='none';ListPaing2.style.display='none';ListPaing3.style.display=''" type=radio value=3 name=listpagetype>手动添加分页URL代码 </TD></TR>
        <TR id=ListPaing1 style="DISPLAY: none">
          <TD bgColor=#e9f0f4 align=right width=120>“下一页”<BR>URL开始代码：<BR><BR><BR>“下一页”<BR>URL结束代码：</FONT> 
          </TD>
          <TD onmouseover='vbscript:me.bgcolor="#F5F5F5"' onmouseout='vbscript:me.bgcolor="#FFFFFF"' bgColor=#ffffff>
            <TEXTAREA name=listpage_start_str  rows=4 cols=70><%=listpage_start_str%></TEXTAREA>&nbsp;
            <INPUT onclick=ceshi(3) type=button value=测试代码><BR>
            <TEXTAREA  name=listpage_end_str  rows=4 cols=70><%=listpage_end_str%></TEXTAREA>&nbsp;
            <INPUT onclick=ceshi(4) type=button value=测试代码> 
          </TD></TR>
        <TR id=ListPaing2 style="DISPLAY: none">
          <TD bgColor=#e9f0f4 align=right width=120>URL字符串：<BR><BR><BR>ID范围：</TD>
          <TD onmouseover='vbscript:me.bgcolor="#F5F5F5"' onmouseout='vbscript:me.bgcolor="#FFFFFF"' bgColor=#ffffff>
          <INPUT maxLength=200 size=80  name=listpage_param_url value="<%=listpage_param_url%>"><BR>
          <FONT  color=#0099ff>例：http://www.xxxxx.com/news/index_{$ID}.html&nbsp;&nbsp;&nbsp;&nbsp;{$ID}代表分页数</FONT>
          <BR><BR><INPUT maxLength=200 size=8 value=0 name=listpage_start_id  value="<%=listpage_start_id%>"><SPAN lang=en-us> To </SPAN>
          <INPUT maxLength=200 size=8 value=0 name=listpage_end_id   value="<%=listpage_end_id%>"> 
          <FONT  color=#0099ff>例： 1 ~ 9 或 9 ~ 1 升序或倒序采集</FONT><BR></TD></TR>
        <TR id=ListPaing3 style="DISPLAY: none">
          <TD bgColor=#e9f0f4 align=right width=120>URL列表：&nbsp;</TD>
          <TD onmouseover='vbscript:me.bgcolor="#F5F5F5"' onmouseout='vbscript:me.bgcolor="#FFFFFF"' bgColor=#ffffff>
          <TEXTAREA  name=listpage_url  rows=10 cols=70><%=listpage_url%></TEXTAREA><BR><FONT color=#0099ff>注：一行写一个网页地址</FONT> </TD></TR></TBODY>
        <TBODY id=Tabs style="DISPLAY: none">
        <TR>
          <TD bgColor=#ffffff>
          <TEXTAREA style="WIDTH: 785px; HEIGHT: 400px" name=content value="<%=content%>"></TEXTAREA> 
          </TD></TR></TBODY>
        <TBODY id=Tabs style="DISPLAY: none">
        <TR>
          <TD id=objFiles align=middle></TD></TR>
        </TBODY>
  
  </TABLE><BR>
<CENTER>
<INPUT id=ItemID type=hidden value=2 name=ItemID> 
<INPUT id=NeedSave type=hidden value=True name=NeedSave> 
<INPUT id=Action type=hidden value=Step2 name=Action>
<INPUT type=button value="上一步" name=prebutton onclick="window.location.href='web_collection_content1.jsp?action=view&id=<%=id%>'"></TD>&nbsp;&nbsp; 
<input type="button" value="重  填" onclick = "document.form1.reset();">&nbsp;&nbsp; 
<INPUT type=button   value="下一步" name=next1 onclick = "javascript: if(check_validate(this.form)){this.form.submit();}"></TD> 
</CENTER>
</FORM>
</body>
<Script Language="javaScript">
    function  check_validate(theForm) {
        if (isSpace(theForm.list_start_str.value)) {
            alert("列表开始代码不能为空！");
            theForm.list_start_str.focus();
            return false;
        }
        if (isSpace(theForm.list_end_str.value)) {
            alert("列表结束代码不能为空！");
            theForm.list_end_str.focus();
            return false;
        }
        if (isSpace(theForm.href_start_str.value)) {
            alert("链接开始代码不能为空！");
            theForm.href_start_str.focus();
            return false;
        }
        if (isSpace(theForm.href_end_str.value)) {
            alert("链接结束代码不能为空！");
            theForm.href_end_str.focus();
            return false;
        }
        if(getRadioValue('hreftype')=='1')
        {
          if (isSpace(theForm.rehrefurlstr.value)) {
            alert("重定向URL不能为空！");
            theForm.rehrefurlstr.focus();
            return false;
          }
        }
        if(getRadioValue('listpagetype')=='1')
        {
          if (isSpace(theForm.listpage_start_str.value)) {
            alert("选择分页类型为'从源代码中获取下一页的URL'时，下一页URL开始代码不能为空！");
            theForm.listpage_start_str.focus();
            return false;
          }
          if (isSpace(theForm.listpage_end_str.value)) {
            alert("选择分页类型为'从源代码中获取下一页的URL'时，下一页URL结束代码不能为空！");
            theForm.listpage_end_str.focus();
            return false;
          }
        }
        if(getRadioValue('listpagetype')=='2')
        {
          if (isSpace(theForm.listpage_param_url.value)) {
            alert("选择分页类型为'批量指定分页URL代码'时，URL字符串不能为空！");
            theForm.listpage_param_url.focus();
            return false;
          }
          if (isSpace(theForm.listpage_start_id.value) || (!isNum(theForm.listpage_start_id.value))) {
            alert("选择分页类型为'批量指定分页URL代码'时，ID范围开始数不能为空并且必须为整数！");
            theForm.listpage_start_id.focus();
            return false;
          }
          if (isSpace(theForm.listpage_end_id.value) || (!isNum(theForm.listpage_end_id.value))) {
            alert("选择分页类型为'批量指定分页URL代码'时，ID范围结束数不能为空并且必须为整数！");
            theForm.listpage_end_id.focus();
            return false;
          }
        }
        if(getRadioValue('listpagetype')=='3')
        {
          if (isSpace(theForm.listpage_url.value)) {
            alert("选择分页类型为'手动添加分页URL代码'时，URL列表不能为空！");
            theForm.listpage_url.focus();
            return false;
          }
        }
        return true;
    }
    function  onChange_hreftype(hreftype_value)
    { if(hreftype_value=='0')
      {
      HttpUrl1.style.display='none';
      }
      else
      {
      HttpUrl1.style.display='';
      }
    }
    function  onChange_hreftype(hreftype_value)
    { if(hreftype_value=='0')
      {
      HttpUrl1.style.display='none';
      }
      else
      {
      HttpUrl1.style.display='';
      }
    }
    function  onChange_listpagetype(listpagetype_value)
    { if(listpagetype_value=='0')
      {
      ListPaing1.style.display='none';
      ListPaing2.style.display='none';
      ListPaing3.style.display='none';
      }
      else if(listpagetype_value=='1')
      {
      ListPaing1.style.display='';
      ListPaing2.style.display='none';
      ListPaing3.style.display='none';
      }
      else if(listpagetype_value=='2')
      {
      ListPaing1.style.display='none';
      ListPaing2.style.display='';
      ListPaing3.style.display='none';
      }
      else if(listpagetype_value=='3')
      {
      ListPaing1.style.display='none';
      ListPaing2.style.display='none';
      ListPaing3.style.display='';
      }
    }
    function  modify_init(hreftype,listpagetype)
    { 
        RadioChecked('hreftype',hreftype);  
        RadioChecked('listpagetype',listpagetype);  
        onChange_hreftype(hreftype);
        onChange_listpagetype(listpagetype);
    }      
    modify_init('<%=hreftype%>','<%=listpagetype%>');
</Script>
</html>
