<?php
/*
'**************************************************************************************************
' 软件名称: 搜一次 Content Management System
' 版本编号: Version 1.X
' 官方网站: http://www.syccms.com
' 官方论坛：http://bbs.syccms.com
' 版权所有: 搜一次运营团队
' 法律顾问: 杭州市元茂律师事务所 严飞律师
' 郑重声明:
'    1、任何个人或组织不得在未经授权的情况下删除、修改、拷贝本软件及其他副本上一切关于版权的信息；
'    2、搜一次网络事业部保留此软件的法律追究权利
'**************************************************************************************************
*/
include "../admin_loginstate.php";
include "../../include/label.php";

if(S_Webmode==1){die("<font color=red>当前网站为动态模式,不能生成!!</font>");}
$Sel=SafeRequest("sel","get");
if($Sel=="single"){
	$ID=SafeRequest("id","get");
	$ClassID=SafeRequest("cid","get");
	$Mark_Text=SpanArticleShow($ID);
	$spanurl=LinkUrl("s_article",$ClassID,1,$ID);
	$spanurl=substr($spanurl,strlen(S_SitePath));
	spandir($spanurl);
	fwrite(fopen("../../".$spanurl,"wb"),$Mark_Text);
	die("ok");	
	}
if($Sel=="today" or $Sel=="sday"){
	if(file_exists("../../".S_Templateurl."artshow.html")){	
		if($Sel=="sday"){
			$sday=SafeRequest("sdaya","auto");
			$s_title=$sday."天前文章";
			$sql="select * from s_article where S_IsHide=0 and S_ClassID<>0 and DATEDIFF(DATE(S_AddTime),'".date('Y-m-d')."')>=-$sday order by S_ID desc";
			}
		else{
			$sday=1;
			$s_title="当天文章";
			$sql="select * from s_article where S_IsHide=0 and S_ClassID<>0 and DATEDIFF(DATE(S_AddTime),'".date('Y-m-d')."')=0 order by S_ID desc";
			}		
		$Arr=spanpage($sql,S_Createpre);		
		echo("<div style=' width:100%; background: #F9FBFD; border-top:4px solid #DEEFFA; border-bottom:1px solid #DEEFFA;color:#008EBD; font-size:10pt; height:30px; line-height:40px;font-weight:bold; margin:0 auto;'>&nbsp;正在开始生成".$s_title."第<font style='color:red; font-size:16px; font-style:italic'>".$Arr[5]."</font>页数据，共<font style='color:red; font-size:16px; font-style:italic'>".$Arr[6]."</font>页</div>");
		$result=$db->query($Arr[2]);
		if($result){
			while($row=$db->fetch_array($result)){
			$Mark_Text=SpanArticleShow($row['S_ID']);
			$Mark_Text.="<script type='text/javascript' language='javascript' src='".S_SitePath."users/userded.php?id=".$row['S_ID']."&art=1'></script>";
			$spanurl=LinkUrl("s_article",$row['S_ClassID'],1,$row['S_ID']);
			$spanurl=substr($spanurl,strlen(S_SitePath));
			spandir($spanurl);
		 	fwrite(fopen("../../".$spanurl,"wb"),$Mark_Text);
	 	    echo "&nbsp;<font style=font-size:10pt;>生成新闻:<font color=red>".$row['S_Name']."</font>成功:<a href=../../".$spanurl." target=_blank>".$spanurl."</a></font><br/>";				
			}
			if($Arr[5]<$Arr[6]){
			echo "<br/>&nbsp;<font style=font-size:10pt;><b>暂停".S_StopTime."秒后继续生成．．．</b></font><script language='javascript'>setTimeout('ReadGo();',".(S_StopTime*1000).");function ReadGo(){location.href='?sel=".$Sel."&sdaya=".$sday."&pages=".($Arr[5]+1)."';}</script>";
				}
			else{
				echo "&nbsp;<font style=font-size:10pt;><b>恭喜你！".$s_title."全部新闻内容生成完毕．．．</b></font>";
				}
		}
	}
	else{
		die("出错了，模板文件不存在！");
	}	
	die();
	}
//生成当天新闻结束	
$ClassID=SafeRequest("NewsClassIDs","post");
if($ClassID==""){
$ClassID=SafeRequest("NewsClassIDs","get");
}
if(!IsNum($ClassID)){die("参数错误!");}
if($ClassID=='0'){
	if(file_exists(_SYC_ROOT_.S_Templateurl."artshow.html")){		
		$sql="select * from s_article where S_IsHide=0 and S_ClassID<>0";
		$Arr=spanpage($sql,S_Createpre);		
		echo("<div style=' width:100%; background: #F9FBFD; border-top:4px solid #DEEFFA; border-bottom:1px solid #DEEFFA;color:#008EBD; font-size:10pt; height:30px; line-height:40px;font-weight:bold; margin:0 auto;'>&nbsp;正在开始生成第<font style='color:red; font-size:16px; font-style:italic'>".$Arr[5]."</font>页数据，共<font style='color:red; font-size:16px; font-style:italic'>".$Arr[6]."</font>页</div>");
		$result=$db->query($Arr[2]);
		if($result){
			while($row=$db->fetch_array($result)){
			$Mark_Text=SpanArticleShow($row['S_ID']);
			$Mark_Text.="<script type='text/javascript' language='javascript' src='".S_SitePath."users/userded.php?id=".$row['S_ID']."&art=1'></script>";
			$spanurl=LinkUrl("s_article",$row['S_ClassID'],1,$row['S_ID']);
			$spanurl=substr($spanurl,strlen(S_SitePath));
			spandir($spanurl);
		 	fwrite(fopen("../../".$spanurl,"wb"),$Mark_Text);
	 	    echo "&nbsp;<font style=font-size:10pt;>生成新闻:<font color=red>".$row['S_Name']."</font>成功:<a href=../../".$spanurl." target=_blank>".$spanurl."</a></font><br/>";				
			}
			if($Arr[5]<$Arr[6]){
			echo "<br/>&nbsp;<font style=font-size:10pt;><b>暂停".S_StopTime."秒后继续生成．．．</b></font><script language='javascript'>setTimeout('ReadGo();',".(S_StopTime*1000).");function ReadGo(){location.href='?NewsClassIDs=0&pages=".($Arr[5]+1)."';}</script>";
				}
			else{
				echo "&nbsp;<font style=font-size:10pt;><b>恭喜你!全部新闻内容生成完毕．．．</b></font>";
				}
		}
	}
	else{
		die("出错了，模板文件不存在！");
		}	
	
	}
else{
	if(file_exists(_SYC_ROOT_.S_Templateurl."artshow.html")){
		$sqlstr="select S_Name from s_class where S_ID=".$ClassID."";
		$res=$db->getrow($sqlstr);
		
		$sql="select * from s_article where S_IsHide=0 and S_ClassID=".$ClassID."";
		$Arr=spanpage($sql,S_Createpre);		
		echo("<div style=' width:100%; background: #F9FBFD; border-top:4px solid #DEEFFA; border-bottom:1px solid #DEEFFA;color:#008EBD; font-size:10pt; height:30px; line-height:40px;font-weight:bold; margin:0 auto;'>&nbsp;正在开始生成<font style='color:red; font-size:16px; font-style:italic'>".$res['S_Name']."</font>分类的第<font style='color:red; font-size:16px; font-style:italic'>".$Arr[5]."</font>页数据，共<font style='color:red; font-size:16px; font-style:italic'>".$Arr[6]."</font>页</div>");
		$result=$db->query($Arr[2]);
		if($result){
			while($row=$db->fetch_array($result)){
			$Mark_Text=SpanArticleShow($row['S_ID']);
			$Mark_Text.="<script type='text/javascript' language='javascript' src='".S_SitePath."users/userded.php?id=".$row['S_ID']."&art=1'></script>";
			$spanurl=LinkUrl("s_article",$row['S_ClassID'],1,$row['S_ID']);
			$spanurl=substr($spanurl,strlen(S_SitePath));
			spandir($spanurl);
		 	fwrite(fopen("../../".$spanurl,"wb"),$Mark_Text);
	 	    echo "&nbsp;<font style=font-size:10pt;>生成新闻:<font color=red>".$row['S_Name']."</font>成功:<a href=../../".$spanurl." target=_blank>".$spanurl."</a></font><br/>";				
			}
			if($Arr[5]<$Arr[6]){
			echo "<br/>&nbsp;<font style=font-size:10pt;>暂停".S_StopTime."秒后继续生成．．．</font><script language='javascript'>setTimeout('ReadGo();',".(S_StopTime*1000).");function ReadGo(){location.href='?NewsClassIDs=".$ClassID."&pages=".($Arr[5]+1)."';}</script>";
				}
			else{
				echo "&nbsp;<font style=font-size:10pt;><b>恭喜你！全部新闻内容全部生成完毕．．．</b></font>";
				}
		}
	}
	else{
		die("出错了，模板文件不存在！");
		}	
	}
?>