<?php
error_reporting(0);
include "../include/cctvai.conn.php";
include "../include/cctvai.inc.php";
header("Content-type: text/html; charset=gb2312");
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");
if(!eregi($_SERVER['SERVER_NAME'], $_SERVER['HTTP_REFERER'])) {exit();}
$ac=SafeRequest("action", "get");
if($ac=="doHits") { //提交数据
	global $db;
	$CD_ID=SafeRequest("id", "get");
	$dowhat=SafeRequest("dowhat", "get");
	$CD_type=SafeRequest("type", "get");
	if(!IsNumID($CD_ID)) {
		exit('up_004');
	}
	if($CD_type=="video") {
		if($dowhat=="good") {
			$sql="update " . tname('video') . " set CD_uHits=CD_uHits+1,CD_LastHitTime='" . date('Y-m-d H:i:s') . "' where CD_ID=" . $CD_ID . "";
			$up_tips='up_001';
		} else {
			$sql="update " . tname('video') . " set CD_dHits=CD_dHits+1 where CD_ID=" . $CD_ID . "";
			$up_tips='up_002';
		}
		$cookies="doHits_video_$CD_ID";
	} elseif($CD_type=="dj") {
		if($dowhat=="good") {
			$sql="update " . tname('dj') . " set CD_uHits=CD_uHits+1,CD_LastHitTime='" . date('Y-m-d H:i:s') . "' where CD_ID=" . $CD_ID . "";
			$up_tips='up_001';
		} else {
			$sql="update " . tname('dj') . " set CD_dHits=CD_dHits+1 where CD_ID=" . $CD_ID . "";
			$up_tips='up_002';
		}
		$cookies="doHits_dj_$CD_ID";
	}
	if($_COOKIE[$cookies]=="yes") {
		exit('up_003');
	} else {
		setcookie($cookies, "yes", time()+86400);
		if($db->query($sql)) {
			exit($up_tips);
		}
	}
} elseif($ac=="dofav") { //提交收藏
	global $db;
	$CD_ID=SafeRequest("id", "get");
	$CD_type=SafeRequest("type", "get");
	if(!IsNumID($CD_ID)) {
		exit('upfav_005');
	}
	if(!$userlogined) {
		exit("upfav_002");
	}
	if($CD_type=="video") {
		$sql="select * from " . tname('video') . " where CD_ID='" . $CD_ID . "'";
		if($row=$db->getrow($sql)) {
			$cd_ids=$db->getone("select cd_id from " . tname('fav') . " where cd_type='video' and cd_uid=" . $CcTvAi_com_userid . " and cd_musicid='" . $CD_ID . "'");
			if($cd_ids) {
				exit('upfav_004');
			} else {
				$db->query("update " . tname('video') . " set CD_FavHits=CD_FavHits+1 where CD_ID='" . $CD_ID . "'");
				$setarr=array(
					'cd_uid'=>$CcTvAi_com_userid,
					'cd_uname'=>$CcTvAi_com_username,
					'cd_musicid'=>$row['CD_ID'],
					'cd_musicname'=>$row['CD_Name'],
					'cd_classid'=>$row['CD_ClassID'],
					'cd_type'=>'video',
					'cd_addtime'=>time()
				);
				inserttable('fav', $setarr, 1);
				$setarrs=array(
					'cd_uid'=>$CcTvAi_com_userid,
					'cd_uname'=>$CcTvAi_com_username,
					'cd_icon'=>'favorites',
					'cd_title'=>'收藏了视频',
					'cd_data'=>'收藏了《' . $row['CD_Name'] . '》<a href="' . LinkUrl("video", $row['CD_ClassID'], 1, $row['CD_ID']) . '" target="_blank">观看</a>',
					'cd_image'=>'',
					'cd_imagelink'=>'',
					'cd_dataid'=>$row['CD_ID'],
					'cd_addtime'=>date('Y-m-d H:i:s')
				);
				inserttable('feed', $setarrs, 1);
				exit('upfav_001');
			}
		}else{
		exit('upfav_003');	
		}
	}
	if($CD_type=="dj") {
		$sql="select * from " . tname('dj') . " where CD_ID='" . $CD_ID . "'";
		if($row=$db->getrow($sql)) {
			$cd_ids=$db->getone("select cd_id from " . tname('fav') . " where cd_type='dj' and cd_uid=" . $CcTvAi_com_userid . " and cd_musicid='" . $CD_ID . "'");
			if($cd_ids) {
				exit('upfav_004');
			} else {
				$db->query("update " . tname('dj') . " set CD_FavHits=CD_FavHits+1 where CD_ID='" . $CD_ID . "'");
				$setarr=array(
					'cd_uid'=>$CcTvAi_com_userid,
					'cd_uname'=>$CcTvAi_com_username,
					'cd_musicid'=>$row['CD_ID'],
					'cd_musicname'=>$row['CD_Name'],
					'cd_classid'=>$row['CD_ClassID'],
					'cd_type'=>'dj',
					'cd_addtime'=>time()
				);
				inserttable('fav', $setarr, 1);
				$setarrs=array(
					'cd_uid'=>$CcTvAi_com_userid,
					'cd_uname'=>$CcTvAi_com_username,
					'cd_icon'=>'favorites',
					'cd_title'=>'收藏了音乐',
					'cd_data'=>'收藏了《' . $row['CD_Name'] . '》<a href="' . LinkUrl("dj", $row['CD_ClassID'], 1, $row['CD_ID']) . '" target="_blank">试听</a>',
					'cd_image'=>'',
					'cd_imagelink'=>'',
					'cd_dataid'=>$row['CD_ID'],
					'cd_addtime'=>date('Y-m-d H:i:s')
				);
				inserttable('feed', $setarrs, 1);
				exit('upfav_001');
			}
		}else{
		exit('upfav_003');	
		}
	}
}
?>