<?php
require('../../class/connect.php');
require('../../class/db_sql.php');
require("../../data/dbcache/class.php");
$link=db_connect();
$empire=new mysqlquery();

$time=time();
$td=mktime(0,0,0,date('m',$time),date('d',$time),date('Y',$time));
$ytd=$td-86400;
$td=(int)$td;
$ytd=(int)$ytd;

//更新记录 ok
function intop($id,$classid){
	global $empire,$dbtbpre;
	$time=time();
	$td=mktime(0,0,0,date('m',$time),date('d',$time),date('Y',$time));
	$f=$empire->fetch1("select no from {$dbtbpre}dongpo_top where id='$id' and classid='$classid' and time>'$td'"); 
	if($f[no]){
		$empire->query("update {$dbtbpre}dongpo_top set hit=hit+1, time=$time where no=$f[no]");
	}
	else{
		$empire->query("insert into {$dbtbpre}dongpo_top(time,classid,id,hit) values('$time','$classid','$id','1');");
	}
	exit();
}

//获取参数
$id=(int)$_GET['id'];
$classid=(int)$_GET['classid'];

//栏目页退出
if(empty($id)||empty($classid)){exit();}

//验证栏目
$cr=$empire->fetch1("select classid from {$dbtbpre}enewsclass where classid=$classid limit 1");
if($cr['classid'] != $classid){exit();}

//验证信息
$ar=$empire->fetch1("select id,classid from {$dbtbpre}ecms_".$class_r[$classid][tbname]." where id='$id' limit 1");
if(!$ar[id]||$classid!=$ar[classid]){exit();}

//删除前天的记录
$empire->query("delete from {$dbtbpre}dongpo_top where time<$ytd");

//更新记录
intop($id,$classid);


db_close();
$empire=null;
?>