<%
Response.Buffer = True 
Server.ScriptTimeOut=999999
Response.Expires = -1
Response.ExpiresAbsolute = Now() - 1 
Response.Expires = 0 
Response.CacheControl = "no-cache"
%>
<!--#include file="../inc/config.asp"-->
<!--#include file="../inc/conn.asp"-->
<!-- #include file="inc/Session.asp" -->
<!-- #include file="inc/checkrole.asp" -->
<%
'''''''''''''''''''''''''''''''''''''''''''''''
call checkPrevilege(Session("Name"),"p05")
'''''''''''''''''''''''''''''''''''''''''''''''
dim actype,starts,id,sendSql,countSql,percentNum,queryStr
if not isempty(request("actype")) then
	actype=trim(request("actype"))
else
	response.Write("请选择要发布的类型")
	response.End()
end if
queryStr="actype="&actype
if not isempty(request("id")) then
	id=Clng(request("id"))
else
	id=1
end if

if not isempty(request("start")) then
	starts=Clng(request("start"))
else
	starts=0
end if
if(application("TOT_Reset_Robot")="") then
	application.Lock()
	application("TOT_Reset_Robot")=0
	application.UnLock()
end if
if(application("TOT_Reset_Total")="") then
	application.Lock()
	application("TOT_Reset_Total")=0
	application.UnLock()
end if
if(starts=1) then
	application.Lock()
	application("TOT_Reset_Robot")=0
	application.UnLock()
end if
sendSql="select top 1 id from news where id>"&id
countSql="select count(*) from news where 1=1"
Select Case LCase(actype)
	Case "bydate"
		dim fromdate,enddate
		if not isempty(request("FromDate")) then
			fromdate=trim(request("FromDate"))
		else
			response.Write("请选择起始日期")
			response.End()
		end if
		if not isempty(request("EndDate")) then
			enddate=trim(request("EndDate"))
		else
			response.Write("请选择起始日期")
			response.End()
		end if
		sendSql=sendSql&" and moditime >= #"&fromdate&"# And moditime<= #"&enddate&"#"
		countSql=countSql&" and moditime >= #"&fromdate&"# And moditime<= #"&enddate&"#"
		application.Lock()
		application("TOT_Reset_Total")=conn.execute(countSql)(0)
		application.UnLock()
		queryStr=queryStr&"&FromDate="&fromdate&"&EndDate="&enddate
	Case "bytopn"
		dim bytopn
		if not isempty(request("topN")) then
			bytopn=Clng(trim(request("topN")))
		else
			response.Write("请选择新闻条数")
			response.End()
		end if
		if(Clng(application("TOT_Reset_Robot"))>bytopn) then
			response.Write("成功发布前"&bytopn&"条新闻记录")
			response.Write("<p><a href=""send_news.asp"">继续发布</a></p>")
			response.End()
		end if
		application("TOT_Reset_Total")=bytopn
		queryStr=queryStr&"&topN="&bytopn
	Case "byid"
		dim startId,endId
		startId=Clng(request("startId"))
		endId=Clng(request("endId"))
		sendSql=sendSql&" and id>="&startId&" and id<="&endId
		countSql=countSql&" and id>="&startId&" and id<="&endId
		queryStr=queryStr&"&startId="&startId&"&endId="&endId
		application.Lock()
		application("TOT_Reset_Total")=conn.execute(countSql)(0)
		application.UnLock()
		if(id>endId) then
			response.Write("成功发布"&application("TOT_Reset_Total")&"条新闻记录,id从"&startId&"到"&endId&"")
			response.Write("<p><a href=""send_news.asp"">继续发布</a></p>")
			response.End()
		end if
	Case "byall"
		application.Lock()
		application("TOT_Reset_Total")=conn.execute(countSql)(0)
		application.UnLock()
	Case "bycatalog"
		dim catalogId,catalogtopN,tempNum
		if not isempty(request("catalogId")) then
			catalogId=Clng(trim(request("catalogId")))
		else
			response.Write("请选择栏目")
			response.End()
		end if
		if not isempty(request("topN")) then
			catalogtopN=Clng(trim(request("topN")))
		else
			response.Write("请选择新闻个数")
			response.End()
		end if
		if(Clng(application("TOT_Reset_Robot"))>catalogtopN) then
			response.Write("成功发布前"&bytopn&"条新闻记录")
			response.Write("<p><a href=""send_news.asp"">继续发布</a></p>")
			response.End()
		end if
		sendSql=sendSql&" and classid="&catalogId
		countSql=countSql&" and classid="&catalogId
		tempNum=Clng(conn.execute(countSql)(0))
		if(tempNum<catalogtopN) then
		
		else
			tempNum=catalogtopN
		end if
		application.Lock()
		application("TOT_Reset_Total")=tempNum
		application.UnLock()
		queryStr=queryStr&"&catalogId="&catalogId&"&topN="&catalogtopN
End Select
sendSql=sendSql&" order by id asc"
'response.Write(sendSql&"<br>")
'response.Write(countSql)
set rs=server.createobject("adodb.recordset")
rs.open sendSql,conn,3,1
if not rs.eof then
	id=rs("id")	
	application.Lock()
	application("TOT_Reset_Robot")=application("TOT_Reset_Robot")+1
	application.UnLock()
else
	response.Write("发布完成！共发布"&application("TOT_Reset_Total")&"条新闻记录")
	response.Write("<p><a href=""send_news.asp"">继续发布</a></p>")
	application.Contents.removeall
	response.End()
end if
rs.close
set rs=nothing
call connclose()
percentNum=Cint((application("TOT_Reset_Robot")*100)/application("TOT_Reset_Total"))
%>
<style type="text/css">
<!--
.style1 {color: #000000}
body{font-size:12px;}
-->
</style>
<div align="center"><table width="400" height="20" border="1" cellpadding="0" cellspacing="0" bordercolor="#D4D0C8" bgcolor="#FFFFFF">
  <tr>
    <td>
      <table id="stat_w" width="1%"  border="0" align="left" cellpadding="0" cellspacing="0" bgcolor="#003399">
      <tr>
        <td>&nbsp;</td>
      </tr>
    </table>
      <span class="style1" id="P_num"></span></td>
  </tr>
</table>
<Br>正在发布新闻，共<%=application("TOT_Reset_Total")%>条&nbsp;&nbsp;第<%=application("TOT_Reset_Robot")%>条</div>
<script type="text/javascript" language="javascript">
var HTTP;
function CallServer(Url)
{
	HTTP = new ActiveXObject("Microsoft.XMLHTTP");
	HTTP.onreadystatechange = doAction;
	var ReturnValue=HTTP.open("POST", Url, false);
	HTTP.send("");
	return HTTP.responseText;
}
function doAction() {		
        if (HTTP.readyState == 4) // 收到完整的服务器响应
		{
			if (HTTP.status == 500) {//服务器错误				
				document.write("服务器出现内部错误。");				

            }
            else if (HTTP.status == 200) {//HTTP服务器响应的值OK
				//document.write(HTTP.responseText);//将服务器返回的字符串写到页面中ID为message的区域
				document.write("id:"+<%=id%>+"<br>");
				document.write('<meta http-equiv="refresh" content="0;URL=reset.asp?<%=queryStr%>&id=<%=id%>">');
				document.getElementById('stat_w').width ="<%=percentNum%>%";
				document.getElementById('P_num').innerHTML ="<%=percentNum%>%";
            } 
			else {
                alert(HTTP.status);
            }
        }
}
function resetHtml()
{
	var ReturnValue;	
	ReturnValue=CallServer('reset_htm.asp?id=<%=id%>');
	document.write(ReturnValue);
}
resetHtml();
</script>
<p align="center"><a href="#">系统运行中...</a></p>
