<?php
error_reporting(0);
global $db, $CcTvAi_com_userid;
close_browse();
if(!eregi($_SERVER['SERVER_NAME'], $_SERVER['HTTP_REFERER'])) {
	exit();
}
if(cd_uploadentrance=="no") {exit('1004');}
if(cd_ykuploadmusic=="no") {if($userlogined==false) {exit('1004');}}
	//******提交参数********//
	$seccode=SafeRequest("seccode", "post");
	$CD_Name=unescape(SafeRequest("CD_Name", "post"));
	$CD_Singer=unescape(SafeRequest("CD_Singer", "post"));
	$CD_ClassID=SafeRequest("CD_ClassID", "post");
	$CD_Pic=unescape(SafeRequest("CD_Pic", "post"));
	$CD_Url=unescape(SafeRequest("CD_Url", "post"));
	$CD_DownUrl=$CD_Url;
	$CD_Siz=unescape(SafeRequest("CD_siz", "post"));
	$CD_Md5=unescape(SafeRequest("CD_md5", "post"));
	$CD_From=unescape(SafeRequest("CD_from", "post"));
	$CD_Uid=unescape(SafeRequest("CD_uid", "post"));
	$CD_Playtime=unescape(SafeRequest("CD_Playtime", "post"));
	$CD_Bitkbps=unescape(SafeRequest("CD_Bitkbps", "post"));
	$CD_SpecialID=SafeRequest("CD_SpecialID", "post");
	$CD_User=$CcTvAi_com_username;
	$CD_Tag=unescape(SafeRequest("CD_Tag", "post"));
	$CD_Word=unescape(SafeRequest("CD_Word", "post"));
	$CD_Lrc=unescape(SafeRequest("CD_Lrc", "post"));
	$CD_Hits=0;
	$CD_DownHits=0;
	$CD_FavHits=0;
	$CD_uHits=0;
	$CD_dHits=0;
	$CD_DayHits=0;
	$CD_WeekHits=0;
	$CD_MonthHits=0;
	$CD_AddTime=date('Y-m-d H:i:s');
	$CD_LastHitTime=date('Y-m-d H:i:s');
	$CD_Deleted=0;
	$CD_IsBest=0;
	$CD_Error=0;
	$CD_Passed=cd_upmusicpassed;
	$CD_Points=SafeRequest("CD_Points", "post");
	$CD_Grade=SafeRequest("CD_Grade", "post");
	$CD_Color="";
	$CD_Skin='play.html';
	$CD_Server=SafeRequest("CD_Server", "post");

	//******判断V过滤********//
	if ($seccode!=$_SESSION["codes"]) {exit('1001');}
	$_SESSION["codes"]=substr(md5(date('' . rand(1, 9) . 'msds' . rand(1, 9) . 'Hs' . rand(1, 9) . 's')), 8, 16);
	if (strpos($CD_Url, ".")===false){exit('1007');}
	if($db->getone("select CD_Name from " . tname('dj') . " where CD_Name='" . $CD_Name . "'")) {exit('音乐名称已存在，请修改！');}
	if (cd_attachmentpoints>$CD_Points) {} else {exit('1002');}
	if (empty($CD_Name) || empty($CD_Singer) || empty($CD_ClassID) || empty($CD_Url)) {exit('1003');}
	if ($CD_Server=="") {$CD_Server='2';}
	$CD_Name=str_replace("'", '', $CD_Name);
	$CD_Name=str_replace("\"", '', $CD_Name);
	$CD_Lrc=preg_replace("/<a[^>]+>(.+?)<\/a>/i", "", $CD_Lrc);
	$CD_Word=preg_replace("/<a[^>]+>(.+?)<\/a>/i", "", $CD_Word);
	$CD_Lrc = str_replace("<br>", '
', $CD_Lrc);
	
if($CD_Singer) {
	//检测歌手$singername['CD_ID']
	$singername=$db->getrow("select CD_ID from " . tname('singer') . " where CD_Name='" . $CD_Singer . "'");
	if($singername=="") {
		$setarr=array(
			'CD_ClassID'=>4,
			'CD_Name'=>$CD_Singer,
			'CD_Sex'=>'',
			'CD_Bieming'=>'',
			'CD_Guoji'=>'',
			'CD_Yuan'=>'',
			'CD_Birth'=>'',
			'CD_Birthday'=>'',
			'CD_Sign'=>'',
			'CD_Height'=>'',
			'CD_Kg'=>'',
			'CD_User'=>$CcTvAi_com_username,
			'CD_Pic'=>'',
			'CD_Intro'=>'',
			'CD_Hits'=>0,
			'CD_IsBest'=>1,
			'CD_Passed'=>1,
			'CD_AddTime'=>date('Y-m-d H:i:s')
		);
		inserttable('singer', $setarr, 1);
		$singername=$db->getrow("select CD_ID from " . tname('singer') . " where CD_User='" . $CcTvAi_com_username . "' and CD_Name='" . $CD_Singer . "'  order by CD_ID desc");
	}
}
if($singername['CD_ID']=="") {
	$singername['CD_ID']=0;
}

global $db;
$sql="Insert " . tname('dj') . " (CD_ClassID,CD_SpecialID,CD_Name,CD_Singer,CD_User,CD_Pic,CD_From,CD_Siz,CD_Uid,CD_Md5,CD_Playtime,CD_Bitkbps,CD_Tag,CD_Url,CD_DownUrl,CD_Word,CD_Lrc,CD_Hits,CD_DownHits,CD_FavHits,CD_uHits,CD_dHits,CD_DayHits,CD_WeekHits,CD_MonthHits,CD_AddTime,CD_LastHitTime,CD_Server,CD_Deleted,CD_IsBest,CD_Error,CD_Passed,CD_Points,CD_Grade,CD_Color,CD_Skin) values ('" . $CD_ClassID . "','" . $CD_SpecialID . "','" . $CD_Name . "','" . $singername['CD_ID'] . "','" . $CD_User . "','" . $CD_Pic . "','" . $CD_From . "','" . $CD_Siz . "','" . $CD_Uid . "','" . $CD_Md5 . "','" . $CD_Playtime . "','" . $CD_Bitkbps . "','" . $CD_Tag . "','" . $CD_Url . "','" . $CD_DownUrl . "','" . $CD_Word . "','" . $CD_Lrc . "','" . $CD_Hits . "','" . $CD_DownHits . "','" . $CD_FavHits . "','" . $CD_uHits . "','" . $CD_dHits . "','" . $CD_DayHits . "','" . $CD_WeekHits . "','" . $CD_MonthHits . "','" . $CD_AddTime . "','" . $CD_LastHitTime . "','" . $CD_Server . "','" . $CD_Deleted . "','" . $CD_IsBest . "','" . $CD_Error . "','" . $CD_Passed . "','" . $CD_Points . "','" . $CD_Grade . "','" . $CD_Color . "','" . $CD_Skin . "')";
$db->query($sql);


$row=$db->getrow("select * from " . tname('dj') . " where CD_User='" . $CcTvAi_com_username . "' and CD_Name='" . $CD_Name . "' and CD_Url='" . $CD_Url . "' order by CD_ID desc");
$setarrs=array(
	'cd_uid'=>$CcTvAi_com_userid,
	'cd_uname'=>$CcTvAi_com_username,
	'cd_icon'=>'dance',
	'cd_title'=>'分享了音乐',
	'cd_data'=>'分享了《' . $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);
$db->query('update ' . tname('user') . " set cd_points=cd_points+'" . cd_userupmusicpoints . "',cd_rank=cd_rank+'" . cd_userupmusicrank . "',cd_djmub=cd_djmub+'1' where cd_name='" . $CcTvAi_com_username . "'");
$tongji='select * from ' . tname('system') . '';
$tj=$db->getrow($tongji);
$sj=date('Ymd');
if($tj['cd_djdaytime']==$sj) {
	$db->query('update ' . tname('system') . " set cd_djdaymub=cd_djdaymub+'1',cd_djmub=cd_djmub+'1'");
} else {
	$db->query('update ' . tname('system') . " set cd_djdaymub='1',cd_djmub=cd_djmub+'1',cd_djdaytime='" . $sj . "'");
}

//百度链接提交工具
include "../plug/baidu_linksubmit/conf.inc.php";
if(baidu_linksubmit_open=="yes"){
$baidu_link="http://".$_SERVER['HTTP_HOST'].LinkUrl("dj", $row['CD_ClassID'], 1, $row['CD_ID'])."";
$urls = array($baidu_link);
$api = baidu_linksubmit_url;
$ch = curl_init();
$options =  array(
    CURLOPT_URL => $api,
    CURLOPT_POST => true,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_POSTFIELDS => implode("\n", $urls),
    CURLOPT_HTTPHEADER => array('Content-Type: text/plain'),
);
curl_setopt_array($ch, $options);
$result = curl_exec($ch);
}

if(cd_upmusicpassed=="1") {
	exit('1005');
} else {
	exit('1006');
}
?>