<!--#include file="connart.asp" -->
<%
Response.Buffer = true
Server.ScriptTimeOut=9999999
dim action : action = be("get","action")
headAdminCollect "文章采集入库管理"

select case action
	case "edit" : edit
	case "editsave" : editsave
	case "del" : del
	case "delpl" : delpl
	case "delall" : delAll
	case "delurl" : delurl
	case "IDInflow" : IDInflow
	case "AllInflow" : AllInflow
	case "noInflow" : noInflow
	case "editype" : editype
	case else : main
end select

sub editype
	dim m_typeid : m_typeid = be("post","m_typeid")
	if isN(m_typeid) then alert "请选择分类！"
	dim ids : ids=replace(be("post","m_id")," ","")
	cjdb.db "update tbl_art set m_typeid="&m_typeid&" where m_id in (" &ids&")","exe"
	redirect getReferer()
end sub

sub IDInflow
	dim ids,count,sql
	ids=replace(be("post","m_id")," ","")
	if not isN(ids) then
		count=cjdb.db("Select count(m_id) from tbl_art where m_id in ("&ids&") and m_typeid>0","exe")(0)
		sql="select * from tbl_art Where m_id in ("&ids&") and m_typeid>0"
		Call MovieInflow(sql,count)  
	else
		alert "请选择入库文章！"
	end if
end sub

sub AllInflow()
	dim count,sql
    count=cjdb.db("Select count(m_id) from tbl_art where m_typeid>0","exe")(0)
	sql="select * from tbl_art where m_typeid>0"
	Call MovieInflow(sql,count)
	cjdb.db "update tbl_art set m_zt=1 where m_typeid>0","exe"
end sub
sub noInflow()
	dim count,sql
    count=cjdb.db("Select count(m_id) from tbl_art where m_zt=0 and m_typeid>0","exe")(0)
	sql="select * from tbl_art where m_zt=0 and m_typeid>0"
	Call MovieInflow(sql,count)
	cjdb.db "update tbl_art set m_zt=1 where m_zt=0 and m_typeid>0","exe"
end sub

sub del 	
	cjdb.db "delete from tbl_art WHERE m_id ="&be("all","m_id"),"exe"
	redirect getReferer()
end sub

sub delpl
 dim ids:ids = be("all","m_id") : ids = replace(ids," ","")
 if not isN(ids) then
	 cjdb.db "delete from tbl_art WHERE m_id in("&be("all","m_id") &")","exe"
	  redirect getReferer()
 else
 	 alert "请选择相应数据！"
 end if
end sub

sub delall
	cjdb.db "delete from tbl_art","exe"
	redirect getReferer()
end sub

sub editsave
	dim m_id,m_title,m_type,m_typeid,m_author,m_content,m_addtime,m_zt,m_hits
	dim rs,sql,i
	m_id = be("post","m_id") : m_title = be("post","m_title")
	m_author = be("post","m_author") : m_addtime = be("post","m_addtime")
	m_zt = be("post","m_zt")  : m_hits = be("post","m_hits")
	m_typeid = be("post","m_typeid") : m_content = be("post","m_content")
	m_type = be("post","m_type")
	dim backurl : backurl = be("post","backurl")
	if isN(backurl) then backurl = "collect_art.asp"
	if isN(m_typeid) then errmsg "采集系统提示","文章分类不能为空,请选择配置!"
	if isN(m_hits) then m_hits = 0
	
	sql="select * from tbl_art where m_id="& m_id
	set rs=cjdb.db(sql,"rs3")
	rs("m_title")=m_title
	rs("m_type") =m_type
	rs("m_typeid")=m_typeid
	rs("m_author")=m_author
	rs("m_content")=m_content
	rs("m_addtime")=m_addtime
	rs("m_zt")=m_zt
	rs("m_hits")=m_hits
	rs("m_addtime")=now
	rs.Update
	cjdb.c(rs)
	
	showmsg "修改文章成功!",backurl
end sub

sub edit
	dim m_id,m_title,m_type,m_typeid,m_author,m_content,m_addtime,m_urltest,m_zt,m_hits
	dim rs,sql
	m_id = be("get","m_id")
	
	sql="select * from tbl_art where m_id="& m_id
	set rs=cjdb.db(sql,"rs1")
	m_title=rs("m_title")  
	m_type=rs("m_type")
	m_typeid=rs("m_typeid")
	m_author=rs("m_author")
	m_content=rs("m_content")
	m_urltest=rs("m_urltest")
	m_zt=rs("m_zt")
	m_addtime=rs("m_addtime")
	m_hits = rs("m_hits")
	cjdb.c(rs)
	
	dim backurl : backurl = request.ServerVariables("HTTP_REFERER")
%>
<script>
$(document).ready(function(){
	$("#form1").validate({
		rules:{
			m_title:{
				required:true,
				maxlength:255
			},
			m_author:{
				required:true,
				maxlength:255
			}
			m_hits:{
				number:true
			},
			m_typeid:{
				required:true
			}
		}
	});
});
</script>
<form name="form" action="?action=editsave" method="post">
<input id="backurl" name="backurl" type="hidden" value="<%=backurl%>">
<table class=tb >
    <tr>
      <td>文章标题：</td>
      <td><input id="m_title" name="m_title" type="text" value="<%=m_title%>" size="100"> </td>
    </tr>
    <tr>
      <td>文章作者：</td>
      <td><input id="m_author" name="m_author" type="text" value="<%=m_author%>" size="40"> </td>
    </tr>
    <tr>
      <td>发布日期：</td>
      <td><input id="m_addtime" name="m_addtime" type="text" value="<%=m_addtime%>" size="40">
      文章人气：<input id="m_hits" name="m_hits" type="text" value="<%=m_hits%>" size="40">
      </td>
    </tr>
    <tr>
      <td>入库状态：</td>
      <td>
      <input type="radio" name="m_zt" value="0" <%IF m_zt=0 Then writeA"checked"%>> 未入库
	  <input type="radio" name="m_zt" value="1" <%IF m_zt=1 Then writeA"checked"%>> 已入库
      </td>
    </tr>
    <tr>
      <td>分类：</td>
      <td>
        <select name="m_typeid" id="m_typeid"  >
        <option value="">请选择数据分类</option>
            <%=makeSelectAll("{pre}art_type","t_id","t_name","t_pid","t_sort",0,"","&nbsp;|&nbsp;&nbsp;",m_typeid)%>
        </select>
      </td>
    </tr>
    <tr>
      <td>文章内容：</td>
      <td>
		<textarea id="m_content" name="m_content" style="width:750px;height:150px;"><%=m_content%></textarea>
      </td>
    </tr>
 	<tr>
	<td colspan="2" >
	<input type="hidden" id="m_id" name="m_id" value="<%=m_id%>">
	<input type="submit" class="btn" name="Submit" value="修 改">
	<input  type="button" class="btn" name="button" value="返 回" onClick="window.location.href='javascript:history.go(-1)'">	
	</td>
	</tr>
</table>
</form>
<%	
end sub

sub main
	Dim pagenum : pagenum = be("all","page")
	if isN(pagenum) or not isNum(pagenum) then pagenum = 1
	if pagenum < 1 then pagenum = 1
	pagenum = clng(pagenum)
	dim keyword : keyword = be("all","keyword")
	dim project : project = be("all","project")
	
	dim sql,rs,zt,rsproject
	zt = be("all","zt") 
	
	Sql="Select a.*,b.P_Name as P_Name from tbl_art a,tbl_art_Project b where a.m_pid=b.P_ID"
	if zt <> "" then
		sql = sql & " and m_zt = " & zt 
	end if
	if keyword <> "" then
		if keyword = "[" then keyword = "[[]"
		if instr(keyword,"[") > 0 and instr(keyword,"]") <= 0 then keyword =replace(keyword,"[","[[]")
		sql = sql & " and m_title like '%" & keyword & "%' "
	end if
	if project<> "" then
		sql = sql & " and a.m_pid = " & project
	end if
	sql = sql & " order by m_zt asc,m_addtime desc" 
	set rs=cjdb.db(sql,"rs1")
%>
<script language="javascript">
$(document).ready(function(){
	$("#btnDel").click(function(){
		if(confirm('确定要删除吗')){
			$("#form1").attr("action","?action=delpl");
			$("#form1").submit();
		}
	});
	$("#btnDelall").click(function(){
		if(confirm('确定要删除吗')){
			$("#form1").attr("action","?action=delall");
			$("#form1").submit();
		}
	});
	$("#btnSelin").click(function(){
		if(confirm('确定入库您所选择的数据吗')){
			$("#form1").attr("action","?action=IDInflow");
			$("#form1").submit();
		}
	});
	$("#btnAllin").click(function(){
		if(confirm('全部入库你所采集的数据吗')){
			$("#form1").attr("action","?action=AllInflow");
			$("#form1").submit();
		}
	});
	$("#btnNoin").click(function(){
		if(confirm('确定入库所有未入库的数据吗')){
			$("#form1").attr("action","?action=noInflow");
			$("#form1").submit();
		}
	});
	 $("#btnType").click(function(){
		if(confirm('确定入库所有未入库的数据吗')){
			$("#form1").attr("action","?action=editype");
			$("#form1").submit();
		}
	});
});
</script>
<table width="96%" border=0 align=center cellpadding=0 cellSpacing=0 class=tbtitle >
    <tr>
      <td>
		<form action="collect_art.asp" method="get"> 
		<strong>搜索文章：</strong>
		<input id=KeyWord size=40 name=keyword>
		<INPUT class=inputbut type=submit value=搜索 name=Submit>
		&nbsp; 按项目查看：
		<select onchange=javascript:window.location.href=this.options[this.selectedIndex].value>
        <option value="collect_art.asp">全部采集项目</option>
		<%
		sql = "select p_id,p_name from tbl_art_project"
		set rsproject=cjdb.db(sql,"rs1")
		do while not rsproject.eof
		%>
		<option value="collect_art.asp?project=<%=rsproject("P_ID")%>" <%if trim(project)=trim(rsproject("P_ID")) then %>selected<%end if%>><%=rsproject("P_Name")%></option>
		<%
		rsproject.movenext
		loop
		cjdb.c(rsproject)
		%>
		</select>	
		<font color="#FF0000">(没有找到对应栏目,不能入库)</font>
		</form>
        </td>
    </tr>
</table>

<form action="" method="post" name="form1" id="form1">
<table  class=tb >
	<tr>
	<td width="4%">&nbsp;</td>
	<td>文章名称</td>
	<td width="7%">状态</td>
	<td width="15%">栏目分类</td>
	<td width="15%">采集项目名称</td> 
	<td width="13%">添加时间</td>
	<td width="8%">操作</td>
	</tr>
	<%
		if rs.eof then
	 %>
    <tr><td align="center" colspan="9" >没有任何记录!</td></tr>
    <%
		else
		Dim i,typearr
		rs.PageSize = app_pagenum
	    rs.AbsolutePage = pagenum
	  	for i = 1 to rs.PageSize
	  	if rs.eof then exit for
	%>
    <tr>
	  <td><input name="m_id" type="checkbox" id="m_id" value="<%=rs("m_id")%>" /></td>
      <td><%=rs("m_title")%></td>
      <td ><%IF rs("m_zt")=1 Then writeA"<font color=""#FF0000"">已入库</font>" Else writeA"未入库"%></td>
      <td>
	  <%
	   if rs("m_typeid")=0 then 
	   	   %>
           <font color="#FF0000">没找到对应分类请配置</font>
           <%
	  	else
			typearr = getValueByArray(cachearttype, rs("m_typeid"))
	  		if isarray(typearr) then
	  			writeA typearr(1)
	  		end if
		end if
	  %>
      </td>
      <td><%=rs("P_Name")%></td>
      <td><%=getColorDay(rs("m_addtime"))%></td>
      <td><A href="?action=edit&m_id=<%=rs("m_id")%>">修改</A>｜<A href="?action=del&m_id=<%=rs("m_id")%>">删除</A></td>
    </tr>
	<%
	rs.MoveNext
	next 
	end if
	%>
<tr>
	<td  colspan="9">
    全选<input name="chkall" type="checkbox" id="chkall" value="1" onClick="checkAll(this.checked,'m_id');"/>&nbsp;
    &nbsp;<input type="button" id="btnDel" value="批量删除" class="btn"  />
	&nbsp;<input type="button" id="btnDelall" value="删除所有" class="btn"  />
	&nbsp;<input type="button" id="btnSelin" class="btn" name="Submit" value="入库所选" >
	&nbsp;<input type="button" id="btnAllin" class="btn" name="Submit" value="全部入库" >
    &nbsp;<input type="button" id="btnNoin" class="btn" name="Submit" value="入库未入库" >
    &nbsp;<select name="m_typeid" id="m_typeid"  >
        <option value="">请选择数据分类</option>
            <%=makeSelectAll("{pre}art_type","t_id","t_name","t_pid","t_sort",0,"","&nbsp;|&nbsp;&nbsp;","")%>
        </select>
        <input type="button" id="btnType" class="btn" name="Submit" value="批量分类"><font color="#FF0000">&nbsp; </font></td>
</tr>
<tr>
	<td colspan="9" >同名处理：
	<input type="checkbox" name="CCTV1" value="1">覆盖作者:
	<input type="checkbox" name="CCTV2" value="2">覆盖内容:
	</td>
</tr>
<tr align="center">
      <td colspan="8">
      <%=pagelist_manage(rs.PageCount,pagenum,rs.RecordCount,app_pagenum,"collect_art.asp?page={p}&project="&project)%>
      </td>
</tr>
</table>
</form>
<%
rs.close
set rs=nothing
end sub

sub MovieInflow(Sql_Collect,MovieNumW)
%>
<table class=tb>
	<tr>
		<td  colspan="2" align="center"> 入 库 状 态</td>
	</tr>
	<tr>
		<td  colspan="2" align="center"> 
		<div class="xingmu" id="refreshlentext" style="background:#006600"></div>
		</td>
  	</tr>
  	<tr>
		<td  colspan="2" align="center"><span id="storagetext">正 在 入 库...</span></td>
  	</tr>
</table>
<%
	dim iscover,rs_Collect,flag,rs_MOVIE,sql_MOVIE,area,rs,MovieID,MovieInflowNum
	dim title,entitle,sql,rscount,letter
	
	iscover=request.Form("iscover")
	rscount = 10
	
	set rs_Collect=cjdb.db(Sql_Collect,"rs1")
	if rs_Collect.recordcount > 10000 then 
		rscount = 1000
	elseif rs_Collect.recordcount > 5000 then 
		rscount = 500
	elseif rs_Collect.recordcount > 1000 then 
		rscount = 100
	else
		rscount = 10
	end if
	
	do while not rs_Collect.eof
		flag=false
		title = rs_Collect("m_Title")
		title = replaceStr(title,"'"," ''")
		
		sql_MOVIE = "SELECT * FROM {pre}art WHERE a_title = '"&title&"'"
	    set rs_MOVIE = objdb.db(sql_MOVIE,"rs3")
		
		 '插入新数据开始
		If rs_MOVIE.EOF or  rs_MOVIE.EOF Then
			rs_MOVIE.addnew
			flag=true
			rs_MOVIE("a_author")=rs_Collect("m_author")
			rs_MOVIE("a_hits") = 0
			if not isN( rs_Collect("m_addtime") ) then
				rs_MOVIE("a_addtime")= rs_Collect("m_addtime")
				rs_MOVIE("a_time")= rs_Collect("m_addtime")
			else
				rs_MOVIE("a_addtime")= Now()
				rs_MOVIE("a_time")= Now()
			end if
			rs_MOVIE("a_content")=rs_Collect("m_content")
			rs_MOVIE("a_hits")=rs_Collect("m_hits")
		end if
		'插入新数据结束
		
		'自动判断分类
		if rs_Collect("m_typeid") > 0 then 
			rs_MOVIE("a_type") = rs_Collect("m_typeid")
		else
			if not isN(rs_Collect("m_type")) then
				sql = "select * from tbl_art_type where t_name like '%" & rs_Collect("m_type") &"%'"
				Set rs = objdb.db(sql,"rs1")
				if not rs.eof then 
					rs_MOVIE("a_type") = rs("t_id")
				end if
				objdb.c(rs)
			end if
		end if
			
		rs_MOVIE("a_title")= replace(rs_Collect("m_Title"),"'","")
		entitle = Hanzi2Pinyin(title)
		rs_MOVIE("a_entitle")= entitle
		if not isN(entitle) then letter = UCase(left(entitle,1))
		rs_MOVIE("a_letter")= letter
		
		if request("CCTV1")="1"  Then rs_MOVIE("a_author")=rs_Collect("m_author")
		if request("CCTV2")="2" then rs_MOVIE("a_content")=rs_Collect("m_content")
		rs_MOVIE("a_time")= Now()
		rs_MOVIE.Update
		objdb.c(rs_MOVIE)
		
		CJDB.DB "update tbl_art set m_zt=1 Where m_id ="&rs_Collect("m_id"),"exe"
		MovieInflowNum=MovieInflowNum+1
		if MovieInflowNum >= MovieNumW then
			writeA "<script type=""text/javascript"" language=""javascript"">"
			writeA "document.getElementById(""refreshlentext"").style.width = ""100%"";"
			writeA "document.getElementById(""refreshlentext"").innerHTML = ""100%"";"
			writeA "document.getElementById(""storagetext"").innerHTML = ""入库完毕 <a href='collect_art.asp'>返回</a>"";"
			writeA "alert('入库完毕'); location.href='collect_art.asp';"
			writeF "</script>"
		elseif (MovieInflowNum mod rscount) = 0 then
			writeA "<script type=""text/javascript"" language=""javascript"">"
			writeA "document.getElementById(""refreshlentext"").style.width = """&(MovieInflowNum/MovieNumW*100)&"%"";"
			writeA "document.getElementById(""refreshlentext"").innerHTML = """&(MovieInflowNum/MovieNumW*100)&"%"";"
			writeA "document.getElementById(""storagetext"").innerHTML = ""正在入库......"";"
			writeF "</script>"
		end if
rs_Collect.movenext
loop

cjdb.C(rs_Collect)
end sub
%>