<?php
error_reporting(0);
global $db, $CcTvAi_com_userid;
close_browse();
if (!eregi($_SERVER['SERVER_NAME'], $_SERVER['HTTP_REFERER'])) {exit();}
if ($CcTvAi_com_userid) {
	$cd_id=SafeRequest("did", "get");
	if(!IsNumID($cd_id)) {exit();}
	if(!IsNumID($CcTvAi_com_userid)) {exit();}
	$callback=SafeRequest("callback", "get");
	if (strstr($CcTvAi_com_points, "-")) {exit($callback . '({"error":002})');}
	$row=$db->getrow("Select cd_name,CD_User,CD_Pic,CD_Url from " . tname('dj') . " where cd_id='" . $cd_id . "'");
	if ($row['CD_User']==$CcTvAi_com_username) {
		$db->query('update ' . tname('user') . " set cd_points=cd_points-'" . cd_userdeletemusicpoints . "',cd_rank=cd_rank-'" . cd_userdeletemusicrank . "',cd_djmub=cd_djmub-'1' where cd_name='" . $row['CD_User'] . "'");
		updatetable('dj', array('CD_User' => '游客','CD_Deleted' => '1'), array('cd_id' => $cd_id));
		if (cd_userdeletemusicpoints>=1) { //大于1才记录
			//记录账单
			$setarr=array(
				'cd_type' => 0, //1为加,0为减
				'cd_uid' => $CcTvAi_com_userid,
				'cd_uname' => $CcTvAi_com_username,
				'cd_icon' => 'dance',
				'cd_title' => '音乐被删除',
				'cd_points' => cd_userdeletemusicpoints,
				'cd_addtime' => date('Y-m-d H:i:s')
			);
			inserttable('bill', $setarr, 1);
		}
		if (delunlink($row['CD_Pic'])==true) {@unlink(_cctvai_root_ . $row['CD_Pic']);}
		if (delunlink($row['CD_Url'])==true) {@unlink(_cctvai_root_ . $row['CD_Url']);}
		exit($callback . '({"error":004})');
	} else {
		exit($callback . '({"error":003})');
	}
} else {
	exit($callback . '({"error":001})');
}
?>