<?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";

@set_time_limit(0);
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=SpanVideoShow($ID);
	$spanurl=LinkUrl("s_video",$ClassID,1,$ID);
	$spanurl=substr($spanurl,strlen(S_SitePath));
	spandir($spanurl);
	fwrite(fopen("../../".$spanurl,"wb"),$Mark_Text);
	//判断是否生成静态播放页
	if(S_Webmode==0 && S_IsStaticPlay==0){
		$sql="select * from s_video where S_ID=$ID";
		$row=$db->getrow($sql);
		SpanStaticPlay($row,$Sel);
		}
	die("ok");
	}
if($Sel=="today" or $Sel=="sday"){
	if(file_exists(_SYC_ROOT_.S_Templateurl."vodshow.html")){	
		if($Sel=="sday"){
			$sday=SafeRequest("sdayv","auto");
			$s_title=$sday."天前视频";
			$sql="select * from s_video 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_video 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:30px;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=SpanVideoShow($row['S_ID']);
			$spanurl=LinkUrl("s_video",$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(S_Webmode==0 && S_IsStaticPlay==0){
				SpanStaticPlay($row,$Sel);
				}			
			}
			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."&sdayv=".$sday."&pages=".($Arr[5]+1)."';}</script>";
				}
			else{
				echo "&nbsp;<font style=font-size:10pt;><b>恭喜你！".$s_title."全部视频内容全部生成完毕．．．</b></font>";
				}
		}
	}
	else{
		die("出错了，模板文件不存在！");
	}	
	die();
	}
//生成当天视频结束	
$ClassID=SafeRequest("ClassIDs","post");
if($ClassID==""){
$ClassID=SafeRequest("ClassIDs","get");
}
if(!IsNum($ClassID)){die("参数错误!");}
if($ClassID=='0'){
	if(file_exists(_SYC_ROOT_.S_Templateurl."vodshow.html")){		
		$sql="select * from s_video 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:30px;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=SpanVideoShow($row['S_ID']);
			$spanurl=LinkUrl("s_video",$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(S_Webmode==0 && S_IsStaticPlay==0){
				SpanStaticPlay($row,$Sel);
				}
			}
			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='?ClassIDs=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."vodshow.html")){
		$sqlstr="select S_Name from s_class where S_ID=".$ClassID."";
		$res=$db->getrow($sqlstr);
		
		$sql="select * from s_video 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:30px;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=SpanVideoShow($row['S_ID']);
			$spanurl=LinkUrl("s_video",$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(S_Webmode==0 && S_IsStaticPlay==0){
				SpanStaticPlay($row,$Sel);
				}			
			}
			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='?ClassIDs=".$ClassID."&pages=".($Arr[5]+1)."';}</script>";
				}
			else{
				echo "&nbsp;<font style=font-size:10pt;><b>恭喜你!全部影片生成完毕．．．</b></font>";
				}
		}
	}
	else{
		die("出错了，模板文件不存在！");
		}	
	}
	
function SpanStaticPlay($video,$Sel){
	global $db;
	$playadd=playadd(2);
	if(file_exists(_SYC_ROOT_.S_Templateurl."vodplay.html")){
	$Data_Arr=explode('$$$',$video['S_VData']);
	$Source_Arr=explode('$$',$video['S_Source']);
	
	for($i=0;$i<count($Source_Arr);$i++){
		$DataValue=explode('#',$Data_Arr[$i]);
		for($j=0;$j<count($DataValue);$j++){
			$Mark_Text=@file_get_contents(_SYC_ROOT_.S_Templateurl."vodplay.html");
			$Mark_Text=topandbottom($Mark_Text);
			$Mark_Text= Span_Playlist($Mark_Text,$video['S_ID'],$video['S_Source'],$video['S_VData'],2,$j,$i);
			$Mark_Text=Common_Mark($Mark_Text,$video['S_ClassID']);
			$Mark_Text=datavideo($Mark_Text,$Mark_Text,$video,'1');
			$Server_Arr=explode('$',$video['S_AddPath']);
			if(count($Server_Arr)!=count($Source_Arr)){
				$AddPath=0;
			}
			else{
				$AddPath=$Server_Arr[$i];
			}	
			$Source=$Source_Arr[$i];
			$Data=$DataValue[$j];
			if($j<(count($DataValue)-1)){
				$DataNext=$DataValue[($j+1)];
				$DataNextArr=explode('$',$DataNext);
				if(count($DataNextArr)==2) $DataNext=$DataNextArr[1];				
				$urlnext=PlayLink($video['S_ID'],$i,($j+1));
				}
			else{
				$DataNext=$DataValue[$j];
				$DataNextArr=explode('$',$DataNext);
				if(count($DataNextArr)==2) $DataNext=$DataNextArr[1];				
				$urlnext=PlayLink($video['S_ID'],$i,$j);
				}
			if($j==0){
				$urllast=PlayLink($video['S_ID'],$i,0);
				}
			else{
				$urllast=PlayLink($video['S_ID'],$i,($j-1));
				}	
			//获取当前集数
			$nowji=explode('$',$Data);
			if(count($nowji)==1){
				$playnum="第".($j+1)."集";
				}
			else{
				$playnum=$nowji[0];
				}
		if(stristr($video['S_Pic'],"http://")==false){
				if($video['S_Pic']==""){
					$video['S_Pic']=S_SitePath."images/nopic.gif";
					}
				else{
					$video['S_Pic']=S_SitePath."images/".S_Vimgfolder."/".$video['S_Pic'];
					}							
			}					
			$Mark_Text=ReplaceStr($Mark_Text,"[video:playname]",$playnum);
			$Mark_Text=ReplaceStr($Mark_Text,"[video:player]",PlayFormSel($Source,$Data,$AddPath,$DataNext));
	   		$Mark_Text=ReplaceStr($Mark_Text,"[video:urlnext]",$urlnext);
			$Mark_Text=ReplaceStr($Mark_Text,"[video:urllast]",$urllast);
			$Mark_Text.="<script type='text/javascript' language='javascript' src='".S_SitePath."users/userded.php?id=".$video["S_ID"]."&art=0'></script>";
			$spanurl=PlayLink($video['S_ID'],$i,$j);
			$spanurl=substr($spanurl,strlen(S_SitePath));
			spandir($spanurl);
		 	fwrite(fopen("../../".$spanurl,"wb"),$Mark_Text);
			if($Sel!="single"){
				echo "&nbsp;<font style=font-size:9pt;color:red;>--生成第".($i+1)."组播放器：<a href=../../$spanurl target=_blank>$spanurl</a></font><br/>";
				}
			}
		}
		
		}
	}	

function PlayFormSel($PlayForm,$Volume,$AddPath,$DataNext){
	$VolumeArr=explode('$',$Volume);
	if(count($VolumeArr)==2){
		$Volume=$VolumeArr[1];
		}
	if($AddPath!=0 && $AddPath!=""){
		$server=trim(GetAddPath($AddPath));
		}	
	$Mark_Text=@file_get_contents("../../js/player/play.html");
	if(file_exists("../../js/player/".$PlayForm.".html")){
		$Mark_Text=ReplaceStr($Mark_Text,'$playshow$',"<script src=".S_SitePath."js/base64.js></script>".file_get_contents("../../js/player/".$PlayForm.".html"));
		}
	else{
		$Mark_Text=ReplaceStr($Mark_Text,'$playshow$',"未知的播放来源！");
		}	
	$Mark_Text=ReplaceStr($Mark_Text,'$s_adloadtime$',S_AdLoadTime);
	$Mark_Text=ReplaceStr($Mark_Text,'$width$',S_PlayWidth);
	$Mark_Text=ReplaceStr($Mark_Text,'$height$',S_PlayHeight);
	$Mark_Text=ReplaceStr($Mark_Text,'$uid$',S_UID);
	$Mark_Text=ReplaceStr($Mark_Text,'{syccms:path}',S_SitePath);
	$Mark_Text=ReplaceStr($Mark_Text,'{syccms:webname}',S_SiteName);
	$Mark_Text=ReplaceStr($Mark_Text,'$url$',$Volume);
	$Mark_Text=ReplaceStr($Mark_Text,'$server$',"");
	$Mark_Text=ReplaceStr($Mark_Text,'$urlnext$',$DataNext);
	
	return $Mark_Text;
	}	
?>