<?php
require("../../class/connect.php");
$link=db_connect();
$empire=new mysqlquery();
eCheckCloseMods('viewnum');//關閉模塊
$id=(int)$_GET['id'];
$classid=(int)$_GET['classid'];
//變量
$onclick=(int)$_GET['onclick'];
$down=(int)$_GET['down'];
$plnum=(int)$_GET['plnum'];
$pfen=(int)$_GET['pfen'];
$pfennum=(int)$_GET['pfennum'];
$diggtop=(int)$_GET['diggtop'];
$diggdown=(int)$_GET['diggdown'];
$classf='tid,tbname';
if($plnum)
{
	$classf.=',checkpl';
}
$cr=$empire->fetch1("select ".$classf." from {$dbtbpre}enewsclass where classid='$classid'".do_dblimit_one());
if(empty($cr['tbname'])||InfoIsInTable($cr['tbname']))
{
	exit();
}
$selectf='';
$f=array();
$divname=array();
$dh='';
if($onclick)//瀏覽數
{
	$selectf.=$dh.'onclick';
	$dh=',';
	$f[]='onclick';
	$divname[]='onclick';
}
if($down)//下載數
{
	$selectf.=$dh.'totaldown';
	$dh=',';
	$f[]='totaldown';
	$divname[]='down';
}
$pl=0;
if($plnum)//評論數
{
	if($cr['checkpl'])
	{
		$selectf.=$dh.'restb';
	}
	else
	{
		$selectf.=$dh.'plnum';
	}
	$dh=',';
	$f[]='plnum';
	$divname[]='plnum';
}
if($pfen)//評分數
{
	$selectf.=$dh.'infopfen,infopfennum';
	$dh=',';
	$f[]='avepfen';
	$divname[]='pfen';
}
if($pfennum)//評分人數
{
	if(!$pfen)
	{
		$selectf.=$dh.'infopfennum';
		$dh=',';
	}
	$f[]='infopfennum';
	$divname[]='pfennum';
}
if($diggtop)//digg頂數
{
	$selectf.=$dh.'diggtop';
	$dh=',';
	$f[]='diggtop';
	$divname[]='diggtop';
}
if($diggdown)//digg踩數
{
	$selectf.=$dh.'diggdown';
	$dh=',';
	$f[]='diggdown';
	$divname[]='diggdown';
}
if(empty($selectf))
{
	exit();
}
//年月日統計
$ymdtotaleo='';
$ymdtid=(int)$cr['tid'];
if($_GET['addclick']==1&&strstr($emod_pubr['tbidseo'],','.$ymdtid.','))
{
	$r=$empire->fetch1("select * from {$dbtbpre}ecms_".$cr['tbname']." where id='$id'".do_dblimit_one());
	$ymdtotaleo=eReturnYmdTotalf($r,0);
}
else
{
	$r=$empire->fetch1("select ".$selectf." from {$dbtbpre}ecms_".$cr['tbname']." where id='$id'".do_dblimit_one());
}
//統計瀏覽次數
if($_GET['addclick']==1)
{
	$empire->query("update {$dbtbpre}ecms_".$cr['tbname']." set onclick=onclick+1".$ymdtotaleo." where id='$id'".do_dblimit_upone());
}
$r['onclick']=$r['onclick']+1;
if($cr['checkpl'])
{
	$pubid=ReturnInfoPubid(0,$id,$cr['tid']);
	$pl=$empire->gettotal("select count(*) as total from {$dbtbpre}enewspl_".$r['restb']." where pubid='$pubid' and checked=0");
	$r['plnum']=$pl;
}
if($pfen)
{
	$r['avepfen']=$r['infopfennum']?round($r['infopfen']/$r['infopfennum']):0;
}
db_close();
$empire=null;
$count=count($divname);
for($i=0;$i<$count;$i++)
{
	$fname=$f[$i];
	echo 'document.getElementById("'.$divname[$i].'showdiv").innerHTML="'.$r[$fname].'";';
}
?>