<?php 
include "../admin_loginstate.php";
include "../../include/conn.php";
include "../admin_version.php";

if(isset($_GET['num'])){
	$classid = $_GET['classid'];
	$time = $_GET['time'];
	$num = $_GET['num'];
	$pagesize = $_GET['pagesize'];
	$pagecount = $_GET['pagecount'];
	$pagenow = $_GET['pagenow'];
	if($pagenow>$pagecount){
		echo 'SUCCESS';exit;
	}
	echo '"admin_ko.php?num='.$num.'&pagecount='.$pagecount.'&pagesize='.$pagesize.'&pagenow='.($pagenow+1).'&classid='.$classid.'&time='.$time.'"';
	
	$con = "WHERE S_ClassID = '".$classid."' ";
	switch($time){
		case '1':
			$con.="AND TO_DAYS(s_addtime)=TO_DAYS(NOW())";
		break;
		case '2':
			$con.="AND TO_DAYS(NOW())-TO_DAYS(s_addtime)<3";
		break;
		case '3':
			$con.="AND TO_DAYS(NOW())-TO_DAYS(s_addtime)<7";
		break;
		case '4':
			$con.='';
		break;
	}
	$sql="SELECT S_ID,S_VData FROM s_video ".$con." limit ".($pagenow-1).",".$pagesize;
	$result = mysql_query($sql) or die('#4#');
	while($row = mysql_fetch_assoc($result)){
		$array = array();
		$array = explode('#',$row['S_VData']);
		$arrcount = count($array);
		@mysql_query("UPDATE s_video SET S_Remark = '".$arrcount."' WHERE S_ID='".$row['S_ID']."'");
	}
	
	echo '<script type="text/javascript">window.location.href="admin_ko.php?num='.$num.'&pagecount='.$pagecount.'&pagesize='.$pagesize.'&pagenow='.($pagenow+1).'&classid='.$classid.'&time='.$time.'";</script>';

	exit;
}

if(empty($_POST)){
	//读取分类数据
	$sql="SELECT S_ID as id,S_Name as name FROM s_class WHERE S_SystemID='1'";
	$result = mysql_query($sql) or die('#4#');
	while($row=mysql_fetch_assoc($result)){
		$classArr[$row['id']] = $row['name'];
	}
}else{
	$classid = $_POST['class'];
	$time = $_POST['time'];
	$con = "WHERE S_ClassID = '".$classid."' ";
	switch($time){
		case '1':
			$con.="AND TO_DAYS(s_addtime)=TO_DAYS(NOW())";
		break;
		case '2':
			$con.="AND TO_DAYS(NOW())-TO_DAYS(s_addtime)<3";
		break;
		case '3':
			$con.="AND TO_DAYS(NOW())-TO_DAYS(s_addtime)<7";
		break;
		case '4':
			$con.='';
		break;
	}
	$sql="SELECT count(S_ID) as num FROM s_video ".$con;
	$result = mysql_query($sql) or die('#4#');
	$row=mysql_fetch_assoc($result);
	$num = $row['num'];//总共要处理的条数
	$pagesize = 100; //每页要处理的数据量
	$pagecount = ceil($num/$pagesize);//总页面数
	echo '<script type="text/javascript">window.location.href="admin_ko.php?num='.$num.'&pagecount='.$pagecount.'&pagesize='.$pagesize.'&pagenow=1&classid='.$classid.'&time='.$time.'";</script>';
	
}
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>快播自动添加网址</title>
</head>

<body>
<?php if(empty($_POST)){?>
<form action="" method="post">
选择分类
<select name="class">
	<?php foreach($classArr as $k=>$v){?>
	<option value="<?php echo $k; ?>"><?php echo $v; ?></option>
	<?php }?>
</select>
选择时间
<select name="time">
	<option value="1">当天</option>
	<option value="2">三天</option>
	<option value="3">七天</option>
	<option value="4">全部</option>
</select>
<button type="submit">提交</button>
</form>
<?php }?>
</body>
</html>