<?php
error_reporting(0);
/*
'**************************************************************************************************
' 程序名称: CCTVAI开源音乐管理系统
' 官方网站: http://www.cctvai.com
' 联系 Q Q: 1542367792
' QQ交流群：136687984
' 版本：(终结版)
' 备注：未经书面授权，不得向任何第三方提供本软件系统！
' 功能，模板，插件，扩展，定制请联系QQ：1542367792
'**************************************************************************************************
*/
if(!eregi($_SERVER['SERVER_NAME'], $_SERVER['HTTP_REFERER'])) {exit('');}
include "../../include/cctvai.conn.php";
if(cd_mobile=="no"){header("Location:".cd_webpath."");exit();}
if(cd_mobilepc=="no"){if (!isMobile()){header("Location:".cd_webpath."");exit();}}
include "../../include/cctvai.inc.php";
include "source/function_common.php";
ob_start();
$ac=SafeRequest("ac", "get");
$op=SafeRequest("op", "get");
$id=SafeRequest("id", "get");
$uid=SafeRequest("uid", "get");
if(!IsNumID($id)) {exit();}
if(!IsNumID($uid)) {exit();}
if(!IsNul($ac)) {$ac="home";}
include_once('source/space_header.php');
?>
<?php
if($ac=="login") {//登陆
	$cd_username=SafeRequest("username", "post");
	$cd_password=SafeRequest("password", "post");
	if(cd_userlogin == "no") {showmessage("系统禁止登录", "login.php", 0);}
	if($cd_username=="") {showmessage("请输入登录帐号", "login.php", 0);}
	if($cd_password=="") {showmessage("请输入登录密码", "login.php", 0);}
	$cd_password=substr(md5($cd_password), 8, 16);
	$cd_logintime=date('Y-m-d H:i:s');
	$cd_loginip=getonlineip();
	$cookietime=cd_userlogintime;
	global $db;
	$sql="select cd_id from " . tname('user') . " where cd_name='" . $cd_username . "' and cd_password='" . $cd_password . "'";
	$cd_id=$db->Getone($sql);
	if(!IsNumID($cd_id)) {showmessage("参数错误", "login.php", 0);}
	if($cd_id) {
		$row=$db->Getrow("select cd_id,cd_lock,cd_name,cd_password,cd_vipgrade from " . tname('user') . " where cd_id='" . $cd_id . "'");
		if($row["cd_lock"]==1) {
			showmessage("帐号已被锁定", "login.php", 0);
		} elseif($row["cd_lock"]==2) {
			showmessage("帐号未通过审核", "login.php", 0);
		} else {
			$cd_ids=$db->Getone("select cd_id from " . tname('session') . " where cd_uid='" . $cd_id . "'");
			if($cd_ids) {
				updatetable('session', array(
					'cd_logintime'=>time()
				), array(
					'cd_id'=>$cd_ids
				));
			} else {
				$setarr=array(
					'cd_uid'=>$cd_id,
					'cd_uname'=>$cd_username,
					'cd_uip'=>$cd_loginip,
					'cd_logintime'=>time()
				);
				inserttable('session', $setarr, 1);
			}
			if($db->getone("select cd_id from " . tname('user') . " where DateDiff(DATE(cd_logintime),'" . date('Y-m-d') . "')=0 and cd_id='" . $cd_id . "'")) {
				$db->query("update " . tname('user') . " set cd_loginnum=cd_loginnum+'1',cd_loginip='" . $cd_loginip . "',cd_logintime='" . $cd_logintime . "' where cd_id=cd_id='" . $cd_id . "'");
			} else {
				if(cd_userloginpoints>=1) {
					$setarr=array(
						'cd_type'=>1,
						'cd_uid'=>$cd_id,
						'cd_uname'=>$cd_username,
						'cd_icon'=>'app',
						'cd_title'=>'每日登录',
						'cd_points'=>cd_userloginpoints,
						'cd_state'=>0,
						'cd_addtime'=>date('Y-m-d H:i:s'),
						'cd_endtime'=>getendtime()
					);
					inserttable('bill', $setarr, 1);
				}
				if($row["cd_vipgrade"]==1) {
					$cd_speed=5;
				} elseif($row["cd_vipgrade"]==2) {
					$cd_speed=10;
				} else {
					$cd_speed=0;
				}
				$db->query("update " . tname('user') . " set cd_points=cd_points+'" . cd_userloginpoints . "',cd_rank=cd_rank+'" . cd_userloginrank . "',cd_viprank=cd_viprank+'" . $cd_speed . "',cd_loginnum=cd_loginnum+'1',cd_loginip='" . $cd_loginip . "',cd_logintime='" . $cd_logintime . "' where cd_id='" . $cd_id . "'");
			}
			setcookie("cd_id", $row["cd_id"], time()+$cookietime, cd_cookiepath);
			setcookie("cd_name", $row["cd_name"], time()+$cookietime, cd_cookiepath);
			setcookie("cd_password", $row["cd_password"], time()+$cookietime, cd_cookiepath);
			showmessage("登录成功,正在转跳中....", "index.php", 0);
		}
	} else {
		showmessage("帐号或密码错误", "login.php", 0);
	}
} elseif($ac=="logout") {
	global $db;
	$db->query("delete from " . tname('session') . " where cd_uid=$CcTvAi_com_userid");
	setcookie("cd_id", "", time() - 1, cd_cookiepath);
	setcookie("cd_name", "", time() - 1, cd_cookiepath);
	setcookie("cd_password", "", time() - 1, cd_cookiepath);
	showmessage("已安全退出", "login.php", 0);

} elseif($ac=="reg") {//用户注册
	global $db;
	if(cd_userreg == "no") {showmessage("本站暂不开放新会员注册", "login.php", 0);}
	$email=SafeRequest("email", "post");
	$password=SafeRequest("password", "post");
	$lemail=SafeRequest("lemail", "post");
	$nicheng=SafeRequest("nicheng", "post");
	$seccode=SafeRequest("seccode", "post");
	$cd_loginip=getonlineip();
	$cookietime=cd_userlogintime;
	if(check_email($email)==""){showmessage("请输入正确的登录邮箱帐号", "reg.php", 0);}
	if(check_email($lemail)==""){showmessage("请输入正确的联系邮箱帐号", "reg.php", 0);}
	if($email=="") {showmessage("请输入登录邮箱帐号", "reg.php", 0);}
	if($password=="") {showmessage("请输入登录密码", "reg.php", 0);}
	if($lemail=="") {showmessage("请输入联系邮箱帐号", "reg.php", 0);}
	if($nicheng=="") {showmessage("请输入用户昵称", "reg.php", 0);}
	if($seccode=="") {showmessage("请输入4位验证码", "reg.php", 0);}
	if($seccode != $_SESSION["codes"]) {showmessage("验证码错误", "reg.php", 0);}
	
    $cemail=$db->getone("select cd_id from " . tname('user') . " where cd_name='" . $email . "'");
    $cnicheng=$db->getone("select cd_id from " . tname('user') . " where cd_nicheng='" . $nicheng . "'");
    $clemail=$db->getone("select cd_id from " . tname('user') . " where cd_email='" . $lemail . "'");
	if($cemail) {showmessage("登录邮箱已存在", "reg.php", 0);}
	if($cnicheng) {showmessage("用户昵称已存在", "reg.php", 0);}
	if($clemail) {showmessage("联系邮箱已存在", "reg.php", 0);}

        $setarr=array(
            'cd_name'=>$email,
            'cd_nicheng'=>$nicheng,
            'cd_password'=>substr(md5($password), 8, 16),
            'cd_question'=>'',
            'cd_answer'=>'',
            'cd_email'=>$lemail,
            'cd_sex'=>'靓女',
            'cd_regdate'=>date('Y-m-d H:i:s'),
            'cd_loginip'=>$cd_loginip,
            'cd_loginnum'=>0,
            'cd_qq'=>'',
            'cd_logintime'=>date('Y-m-d H:i:s'),
            'cd_grade'=>0,
            'cd_lock'=>0,
            'cd_points'=>cd_userpoints,
            'cd_photo'=>'',
            'cd_sign'=>'',
            'cd_hidden'=>0,
            'cd_birthprovince'=>'',
            'cd_birthcity'=>'',
            'cd_resideprovince'=>'',
            'cd_residecity'=>'',
            'cd_birthday'=>'',
            'cd_vipindate'=>"0000-00-00 00:00:00",
            'cd_vipenddate'=>"0000-00-00 00:00:00",
            'cd_vipgrade'=>0,
            'cd_viprank'=>0,
            'cd_verified'=>0,
            'cd_djmub'=>0,
            'cd_ufav'=>0,
            'cd_ufans'=>0,
            'cd_hits'=>0,
            'cd_isbest'=>0,
            'cd_money'=>0,
            'cd_weblock'=>0,
            'cd_signd'=>0,
            'cd_signdcumu'=>0,
            'cd_signdtime'=>"0000-00-00 00:00:00",
            'cd_skin'=>0,
            'cd_friendnum'=>0,
            'cd_creditname'=>0,
            'cd_rank'=>cd_userrank,
            'cd_credit'=>0,
            'cd_qqopenid'=>'',
            'cd_checkmm'=>0,
            'cd_checkmusic'=>0,
            'cd_groupnum'=>0,
            'cd_level'=>0,
        );
        inserttable('user', $setarr, 1);
        //增加数据统计
        $tongji='select * from ' . tname('system') . '';
        $tj=$db->getrow($tongji);
        $sj=date('Ymd');
        if($tj['cd_userdaytime'] == $sj) {
            $db->query('update ' . tname('system') . " set cd_usermub=cd_usermub+1,cd_userdaymub=cd_userdaymub+1");
        } else {
            $db->query('update ' . tname('system') . " set cd_usermub=cd_usermub+1,cd_userdaymub='1',cd_djdaytime='" . $sj . "'");
        }
        //发送站内短消息
        if(cd_userlocalpm == "yes") {
            $rowlast=$db->getrow("select cd_id from " . tname('user') . " where cd_name='" . $email . "' order by cd_id desc");
            $cd_lastid=$rowlast['cd_id'];
            $setarrs=array(
                'cd_uid'=>0,
                'cd_uname'=>'系统消息',
                'cd_uids'=>$cd_lastid,
                'cd_unames'=>$email,
                'cd_dataid'=>0,
                'cd_readid'=>1,
                'cd_content'=>cd_userlocalpmtxt,
                'cd_addtime'=>date('Y-m-d H:i:s')
            );
            inserttable('message', $setarrs, 1);
        }
        //直接登录
        $sql="select cd_id from " . tname('user') . " where cd_name='" . $email . "' and cd_password='" . substr(md5($password), 8, 16) . "'";
        $cd_id=$db->getone($sql);
        if(!IsNumID($cd_id)) {showmessage("系统出错", "reg.php", 0);}
        if($cd_id) {
            $db->query("update " . tname('user') . " set cd_loginnum=cd_loginnum+'1',cd_loginip='" . $cd_loginip . "',cd_logintime='" . date('Y-m-d H:i:s') . "',cd_weblock='1' where cd_id='" . $cd_id . "'");
            $db->query("delete from " . tname('session') . " where cd_uid='" . $cd_id . "'");
            $db->query("Insert " . tname('session') . " (cd_uid,cd_uname,cd_uip,cd_logintime) values ('" . $cd_id . "','" . $email . "','" . $cd_loginip . "','" . time() . "')");
            setcookie("cd_id", $cd_id, time()+$cookietime, cd_cookiepath);
            setcookie("cd_name", $email, time()+$cookietime, cd_cookiepath);
            setcookie("cd_password", substr(md5($password), 8, 16), time()+$cookietime, cd_cookiepath);
            $_SESSION["codes"]=substr(md5(date('' . rand(1, 9) . 'msds' . rand(1, 9) . 'Hs' . rand(1, 9) . 's')), 8, 16);
            //奖励账单
            if($points >= 1) {
                $setarr=array(
                    'cd_type'=>1,
                    'cd_uid'=>$cd_id,
                    'cd_uname'=>$email,
                    'cd_icon'=>'logon',
                    'cd_title'=>'新用户注册',
                    'cd_points'=>$points,
                    'cd_state'=>0,
                    'cd_addtime'=>date('Y-m-d H:i:s'),
                    'cd_endtime'=>$cd_loginip
                );
                inserttable('bill', $setarr, 1);
            }
            if(cd_userloginpoints >= 1) {
                $setarr=array(
                    'cd_type'=>1,
                    'cd_uid'=>$cd_id,
                    'cd_uname'=>$email,
                    'cd_icon'=>'app',
                    'cd_title'=>'每日登录',
                    'cd_points'=>cd_userloginpoints,
                    'cd_state'=>0,
                    'cd_addtime'=>date('Y-m-d H:i:s'),
                    'cd_endtime'=>$cd_loginip
                );
                inserttable('bill', $setarr, 1);
            }
            $db->query("update " . tname('user') . " set cd_points=cd_points+'" . cd_userloginpoints . "',cd_rank=cd_rank+'" . cd_userloginrank . "' where cd_id='" . $cd_id . "'");
        }
		showmessage("注册成功,正在进入会员中心...", "index.php", 0);

} elseif($ac=="lostpasswd") {//取回密码
	$cd_username=SafeRequest("username", "post");
	$cd_question=SafeRequest("question", "post");
	$cd_answer=SafeRequest("answer", "post");
	$cd_password=SafeRequest("password", "post");
	if($cd_username=="") {
		showmessage("出错了，登陆帐号不能为空。", "lostpasswd.php", 0);
	} elseif($cd_question=="") {
		showmessage("出错了，密保问题不能为空。", "lostpasswd.php", 0);
	} elseif($cd_answer=="") {
		showmessage("出错了，密保答案不能为空。", "lostpasswd.php", 0);
	} elseif($cd_password=="") {
		showmessage("出错了，新设密码不能为空。", "lostpasswd.php", 0);
	} else {
		$cd_answers=substr(md5($cd_answer), 8, 16);
		$cd_passwords=substr(md5($cd_password), 8, 16);
		global $db;
		$sql="select cd_id from " . tname('user') . " where cd_name='" . $cd_username . "'";
		$cd_id=$db->Getone($sql);
		if($cd_id) {
			$row=$db->Getrow("select * from " . tname('user') . " where cd_id='" . $cd_id . "'");
			if($cd_answers<>$row["cd_answer"]) {
				showmessage("密保答案错误", "lostpasswd.php", 0);
			} elseif($cd_question<>$row["cd_question"]) {
				showmessage("密保问题错误", "lostpasswd.php", 0);
			} else {
				$db->query("update " . tname('user') . " set cd_password='" . $cd_passwords . "' where cd_id='" . $cd_id . "'");
				showmessage("密码已修改,正在转跳登录....", "login.php", 1);
			}
		} else {
			showmessage("登陆帐号不存在", "lostpasswd.php", 0);
		}
	}
} elseif($ac=="delgddjfav") {//删除歌单收藏
if(!$userlogined==true){showmessage("请先登录后操作", "login.php", 0);}
$row=$db->getrow("Select cd_uname,cd_id from " . tname('fav') . " where cd_type='dj' and cd_id='" . $id . "'");
if ($row['cd_uname']==$CcTvAi_com_username) {
	$db->query("delete from " . tname('fav') . " where cd_type='dj' and cd_uid='" . $CcTvAi_com_userid . "' and cd_id = '" . $id . "'");
	showmessage("收藏的音乐已删除", $_SERVER['HTTP_REFERER'], 0);
	} else {
		showmessage("您没有权限删除别人的数据", $_SERVER['HTTP_REFERER'], 0);
		}
} elseif($ac=="delgddjdown") {//删除歌单下载
if(!$userlogined==true){showmessage("请先登录后操作", "login.php", 0);}
$row=$db->getrow("Select cd_uname,cd_id from " . tname('down') . " where cd_type='dj' and cd_id='" . $id . "'");
if ($row['cd_uname']==$CcTvAi_com_username) {
	$db->query("delete from " . tname('down') . " where cd_type='dj' and cd_uid='" . $CcTvAi_com_userid . "' and cd_id = '" . $id . "'");
	showmessage("下载的音乐已删除", $_SERVER['HTTP_REFERER'], 0);
	} else {
		showmessage("您没有权限删除别人的数据", $_SERVER['HTTP_REFERER'], 0);
		}
} elseif($ac=="delgdvideofav") {//删除视频收藏
if(!$userlogined==true){showmessage("请先登录后操作", "login.php", 0);}
$row=$db->getrow("Select cd_uname,cd_id from " . tname('fav') . " where cd_type='video' and cd_id='" . $id . "'");
if ($row['cd_uname']==$CcTvAi_com_username) {
	$db->query("delete from " . tname('fav') . " where cd_type='video' and cd_uid='" . $CcTvAi_com_userid . "' and cd_id = '" . $id . "'");
	showmessage("收藏的视频已删除", $_SERVER['HTTP_REFERER'], 0);
	} else {
		showmessage("您没有权限删除别人的数据", $_SERVER['HTTP_REFERER'], 0);
		}
} elseif($ac=="delgdvideodown") {//删除视频下载
if(!$userlogined==true){showmessage("请先登录后操作", "login.php", 0);}
$row=$db->getrow("Select cd_uname,cd_id from " . tname('down') . " where cd_type='video' and cd_id='" . $id . "'");
if ($row['cd_uname']==$CcTvAi_com_username) {
	$db->query("delete from " . tname('down') . " where cd_type='video' and cd_uid='" . $CcTvAi_com_userid . "' and cd_id = '" . $id . "'");
	showmessage("下载的视频已删除", $_SERVER['HTTP_REFERER'], 0);
	} else {
		showmessage("您没有权限删除别人的数据", $_SERVER['HTTP_REFERER'], 0);
		}
} elseif($ac=="delmessage") {//删除系统消息
if(!$userlogined==true){showmessage("请先登录后操作", "login.php", 0);}
if($id==0){
		$sql="select * from " . tname('message') . " where cd_uids='" . $CcTvAi_com_userid . "'";
		if ($row=$db->getrow($sql)) {
			$db->query("delete from " . tname('message') . " where cd_uids='" . $CcTvAi_com_userid . "'");
			showmessage("私信对话已清空", "index.php?ac=pm", 0);
		} else {
			showmessage("没有您的私信", "index.php?ac=pm", 0);
		}
}else{
$row=$db->getrow("select cd_uids from " . tname('message') . " where cd_id='" . $id . "'");
if ($row['cd_uids']==$CcTvAi_com_userid) {
	$db->query("delete from " . tname('message') . " where cd_id='" . $id . "'");
	showmessage("私信对话已删除", "index.php?ac=pm", 0);
	} else {
		showmessage("您没有权限删除别人的数据", "index.php?ac=pm", 0);
		}
}	
} elseif($ac=="delmessagedt") {//删除对话单条消息
$iid=SafeRequest("iid", "get");
if(!IsNumID($iid)) {showmessage("参数错误", "index.php?ac=pm", 0);}
if(!$userlogined==true){showmessage("请先登录后操作", "login.php", 0);}
$row=$db->getrow("select cd_uids from " . tname('message') . " where cd_id='" . $id . "'");
$sql="select * from " . tname('message') . " where cd_id='$id'";
if ($row=$db->getrow($sql)) {
	if ($iid==$CcTvAi_com_userid) {
		$db->query("delete from " . tname('message') . " where cd_id='" . $row['cd_id'] . "'");
		$result=$db->query("select * from " . tname('message') . " where cd_dataid='" . $row['cd_dataid'] . "' order by cd_id asc");
		$num=$db->num_rows($result);
		if ($num) {
			showmessage("私信对话已删除", $_SERVER['HTTP_REFERER'], 0);
		}else{
			$db->query("delete from " . tname('message') . " where cd_id='" . $row['cd_dataid'] . "'");
			showmessage("私信对话已删除", "index.php?ac=pm", 0);
		}
		
	}else{
		showmessage("您没有权限删除别人的数据", $_SERVER['HTTP_REFERER'], 0);
	}
}else{
	showmessage("用户不存在", $_SERVER['HTTP_REFERER'], 0);
}
} elseif($ac=="messageadd") {//回复对话消息
if(!$userlogined==true){showmessage("请先登录后操作", "login.php", 0);}
$cd_uid=SafeRequest("uid", "post");
$cd_note=SafeRequest("note", "post");
if(!IsNumID($CcTvAi_com_userid | $cd_uid)) {showmessage("参数错误", "index.php?ac=pm", 0);}
if ($cd_uid==$CcTvAi_com_userid) {showmessage("参数错误", "index.php?ac=pm", 0);}
if(preg_match("/".cd_messagereplace."/i",$cd_note)){showmessage("请不要输入违规词汇", $_SERVER['HTTP_REFERER'], 0);}
if($_COOKIE["messageadd"]){
setcookie("messageadd", 'add', time()+10);
showmessage("请稍等10秒后回复！", $_SERVER['HTTP_REFERER'], 0);
}else{
setcookie("messageadd", 'add', time()+10);
}
$user=$db->getrow("select cd_id,cd_name from " . tname('user') . " where cd_id='$cd_uid'");
	if ($user) {
		$cd_uids=$user['cd_id'];
		$cd_unames=$user['cd_name'];
		$query="select cd_id from " . tname('message') . " where cd_uids='$CcTvAi_com_userid' and cd_uid='$cd_uid' and cd_dataid=0";
		if ($rows=$db->getrow($query)) {
			$rsa=$db->getrow("select cd_id from " . tname('message') . " where cd_uid='$CcTvAi_com_userid' and cd_uids='$cd_uid' and cd_dataid=0 order by cd_id desc");
			$setarr=array(
				'cd_uid' => $CcTvAi_com_userid,
				'cd_uname' => $CcTvAi_com_username,
				'cd_uids' => $cd_uids,
				'cd_unames' => $cd_unames,
				'cd_dataid' => $rsa['cd_id'],
				'cd_readid' => 1,
				'cd_content' => $cd_note,
				'cd_addtime' => date('Y-m-d H:i:s')
			);
			inserttable('message', $setarr, 1);
			$rsb=$db->getrow("select cd_id from " . tname('message') . " where cd_uids='$CcTvAi_com_userid' and cd_uid='$cd_uid' and cd_dataid=0 order by cd_id desc");
			$setarr=array(
				'cd_uid' => $CcTvAi_com_userid,
				'cd_uname' => $CcTvAi_com_username,
				'cd_uids' => $cd_uids,
				'cd_unames' => $cd_unames,
				'cd_dataid' => $rsb['cd_id'],
				'cd_readid' => 1,
				'cd_content' => $cd_note,
				'cd_addtime' => date('Y-m-d H:i:s')
			);
			inserttable('message', $setarr, 1);
		} else {
			$setarr=array(
				'cd_uid' => $CcTvAi_com_userid,
				'cd_uname' => $CcTvAi_com_username,
				'cd_uids' => $cd_uids,
				'cd_unames' => $cd_unames,
				'cd_dataid' => 0,
				'cd_readid' => 1,
				'cd_content' => $cd_note,
				'cd_addtime' => date('Y-m-d H:i:s')
			);
			inserttable('message', $setarr, 1);
			$setarr=array(
				'cd_uid' => $cd_uids,
				'cd_uname' => $cd_unames,
				'cd_uids' => $CcTvAi_com_userid,
				'cd_unames' => $CcTvAi_com_username,
				'cd_dataid' => 0,
				'cd_readid' => 1,
				'cd_content' => $cd_note,
				'cd_addtime' => date('Y-m-d H:i:s')
			);
			inserttable('message', $setarr, 1);
			$rsa=$db->getrow("select cd_id from " . tname('message') . " where cd_uid='$CcTvAi_com_userid' and cd_uids='$cd_uid' and cd_dataid=0 order by cd_id desc");
			$setarr=array(
				'cd_uid' => $CcTvAi_com_userid,
				'cd_uname' => $CcTvAi_com_username,
				'cd_uids' => $cd_uids,
				'cd_unames' => $cd_unames,
				'cd_dataid' => $rsa['cd_id'],
				'cd_readid' => 1,
				'cd_content' => $cd_note,
				'cd_addtime' => date('Y-m-d H:i:s')
			);
			inserttable('message', $setarr, 1);
			$rsb=$db->getrow("select cd_id from " . tname('message') . " where cd_uids='$CcTvAi_com_userid' and cd_uid='$cd_uid' and cd_dataid=0 order by cd_id desc");
			$setarr=array(
				'cd_uid' => $CcTvAi_com_userid,
				'cd_uname' => $CcTvAi_com_username,
				'cd_uids' => $cd_uids,
				'cd_unames' => $cd_unames,
				'cd_dataid' => $rsb['cd_id'],
				'cd_readid' => 1,
				'cd_content' => $cd_note,
				'cd_addtime' => date('Y-m-d H:i:s')
			);
			inserttable('message', $setarr, 1);
		}
		$rsc=$db->getrow("select cd_id from " . tname('message') . " where cd_uid='$CcTvAi_com_userid' and cd_uids='$cd_uid' and cd_dataid=0 order by cd_id desc");
		//更新通知
		$setarr=array(
			'cd_uid' => $CcTvAi_com_userid,
			'cd_uname' => $CcTvAi_com_username,
			'cd_uids' => $cd_uids,
			'cd_unames' => $cd_unames,
			'cd_icon' => 'message',
			'cd_data' => '给您发了一个私信&nbsp;<a href="' . cd_webpath . 'user/space.php?do=pm&view=msgDetail&day=' . $rsc['cd_id'] . '" target="_blank">查看</a>',
			'cd_dataid' => 0,
			'cd_state' => 1,
			'cd_addtime' => date('Y-m-d H:i:s')
		);
		inserttable('notice', $setarr, 1);
		$db->query("update " . tname('message') . " set cd_addtime='".date('Y-m-d H:i:s')."' where cd_id='".$rsc['cd_id']."'");
		showmessage("回复成功", $_SERVER['HTTP_REFERER'], 0);
	} else {
		showmessage("用户不存在", "index.php?ac=pm", 0);
	}
} elseif($ac=="delnotice") {//清空通知
if(!$userlogined==true){showmessage("请先登录后操作", "login.php", 0);}
if ($CcTvAi_com_userid==$id) {
	$db->query("delete from " . tname('notice') . " where cd_uids='" . $CcTvAi_com_userid . "'");
	showmessage("通知已全部删除", $_SERVER['HTTP_REFERER'], 0);
}else{
	showmessage("您没有权限删除别人的数据", $_SERVER['HTTP_REFERER'], 0);
}

} elseif($ac=="delpic") {//删除个人照片	
if(!$userlogined==true){showmessage("请先登录后操作", "login.php", 0);}
if (strstr($CcTvAi_com_points, "-")) {showmessage("您的金币余额不足以支付删除", $_SERVER['HTTP_REFERER'], 0);}
$row=$db->getrow("Select cd_uid from " . tname('pic') . " where cd_id='".$id."'");
	if ($row['cd_uid']==$CcTvAi_com_userid) {
		$query=$db->query("select cd_id,cd_uid,cd_uname,cd_url from " . tname('pic') . " where cd_id in(" . $id . ")");
		while ($row=$db->fetch_array($query)) {
			//删除图片
			$db->query("delete from " . tname('pic') . " where cd_uid='" . $row['cd_uid'] . "' and cd_id='" . $row['cd_id'] . "'");
			//删除评论
			$db->query("delete from " . tname('comment') . " where cd_channel=7 and cd_dataid='" . $row['cd_id'] . "'");
			//惩罚经验
			if (cd_userdeletepicpoints>=1) { //大于1才记录
				//记录账单
				$setarr=array(
					'cd_type' => 0, //1为加,0为减
					'cd_uid' => $row['cd_uid'],
					'cd_uname' => $row['cd_uname'],
					'cd_icon' => 'album',
					'cd_title' => '照片被删除',
					'cd_points' => cd_userdeletepicpoints,
					'cd_addtime' => date('Y-m-d H:i:s')
				);
				inserttable('bill', $setarr, 1);
			}
			$db->query('update ' . tname('user') . " set cd_points=cd_points-'" . cd_userdeletepicpoints . "',cd_rank=cd_rank-'" . cd_userdeletepicrank . "' where cd_id='" . $CcTvAi_com_userid . "'");
			if (delunlink($row['cd_url'])==true) {
				@unlink("../../upload/album/" . $row['cd_url'] . ".thumb." . fileext($row['cd_url']));
				@unlink("../../upload/album/" . $row['cd_url'] . ".thumb_180x180." . fileext($row['cd_url']));
				@unlink("../../upload/album/" . $row['cd_url']);
			}
		}
		showmessage("照片已删除", "../singer/index.php?ac=album&id=".$uid."", 0);
	} else {
		showmessage("您没有权限删除别人的数据", $_SERVER['HTTP_REFERER'], 0);
	}
} elseif($ac=="vippoints") {//月VIP	
if(!$userlogined==true){showmessage("请先登录后操作", "login.php", 0);}
if(cd_vipoff == "no") {showmessage("系统已关闭申请", "index.php?ac=assets&view=vip", 0);}
    if($CcTvAi_com_points >= cd_vippoints) {
    if($CcTvAi_com_grade == 1) {
        $cd_vippoints=cd_vippoints;
        $cd_viptime=cd_viptime;
        $cd_vipenddate=date("Y-m-d", strtotime("+".$cd_viptime." day", strtotime($CcTvAi_com_vipenddate)));
        $db->query("update " . tname('user') . " set cd_points=cd_points-$cd_vippoints,cd_vipenddate='$cd_vipenddate' where cd_id='$CcTvAi_com_userid'");
        //记录账单
        $setarr=array(
            'cd_type'=>0, //1为加,0为减
            'cd_uid'=>$CcTvAi_com_userid,
            'cd_uname'=>$CcTvAi_com_username,
            'cd_icon'=>'payvip',
            'cd_title'=>'续费'.cd_viptime.'天VIP会员',
            'cd_points'=>cd_vippoints,
            'cd_addtime'=>date('Y-m-d H:i:s')
        );
        inserttable('bill', $setarr, 1);
        //发送通知
        $setarr=array(
            'cd_uid'=>0,
            'cd_uname'=>'系统提示',
            'cd_uids'=>$CcTvAi_com_userid,
            'cd_unames'=>$CcTvAi_com_username,
            'cd_icon'=>'payvip',
            'cd_data'=>cd_vipxtxt,
            'cd_dataid'=>0,
            'cd_state'=>1,
            'cd_addtime'=>date('Y-m-d H:i:s')
        );
        inserttable('notice', $setarr, 1);
         showmessage("恭喜您，已成功续费1个月VIP会员", "index.php?ac=assets&view=vip", 0);
    }else{
        $cd_vippoints=cd_vippoints;
        $cd_viptime=cd_viptime;
        $cd_vipindate=date('Y-m-d H:i:s');
        $tomorrow=mktime(date("H"), date("i"), date("s"), date("m"), date("d")+$cd_viptime, date("Y"));
        $cd_vipenddate=date("Y-m-d H:i:s", $tomorrow);
        $db->query("update " . tname('user') . " set cd_points=cd_points-$cd_vippoints,cd_vipgrade=1,cd_grade=1,cd_vipindate='$cd_vipindate',cd_vipenddate='$cd_vipenddate' where cd_id='$CcTvAi_com_userid'");
        //记录账单
        $setarr=array(
            'cd_type'=>0, //1为加,0为减
            'cd_uid'=>$CcTvAi_com_userid,
            'cd_uname'=>$CcTvAi_com_username,
            'cd_icon'=>'payvip',
            'cd_title'=>'充值'.cd_viptime.'天VIP会员',
            'cd_points'=>cd_vippoints,
            'cd_addtime'=>date('Y-m-d H:i:s')
        );
        inserttable('bill', $setarr, 1);
        //发送通知
        $setarr=array(
            'cd_uid'=>0,
            'cd_uname'=>'系统提示',
            'cd_uids'=>$CcTvAi_com_userid,
            'cd_unames'=>$CcTvAi_com_username,
            'cd_icon'=>'payvip',
            'cd_data'=>cd_vipktxt,
            'cd_dataid'=>0,
            'cd_state'=>1,
            'cd_addtime'=>date('Y-m-d H:i:s')
        );
        inserttable('notice', $setarr, 1);
        showmessage("恭喜您，已成功申请1个月VIP会员", "index.php?ac=assets&view=vip", 0);
	}
    } else {
        showmessage("您的账户金币不足", "index.php?ac=assets", 0);
    }

} elseif($ac=="vipyearspoints") {//年VIP	
if(!$userlogined==true){showmessage("请先登录后操作", "login.php", 0);}
if(cd_vipoff == "no") {showmessage("系统已关闭申请", "index.php?ac=assets&view=vip", 0);}
    if($CcTvAi_com_points >= cd_vipyearspointsa) {
    if($CcTvAi_com_grade == 1) {
        $cd_vippoints=cd_vipyearspointsa;
        $cd_viptime=cd_vipyearstime;
        $cd_vipenddate=date("Y-m-d", strtotime("+".$cd_viptime." day", strtotime($CcTvAi_com_vipenddate)));
        $db->query("update " . tname('user') . " set cd_points=cd_points-$cd_vippoints,cd_vipgrade=2,cd_grade=1,cd_vipenddate='$cd_vipenddate' where cd_id='$CcTvAi_com_userid'");
        //记录账单
        $setarr=array(
            'cd_type'=>0, //1为加,0为减
            'cd_uid'=>$CcTvAi_com_userid,
            'cd_uname'=>$CcTvAi_com_username,
            'cd_icon'=>'payvip',
            'cd_title'=>'续费'.cd_vipyearstime.'天VIP会员',
            'cd_points'=>cd_vipyearspointsa,
            'cd_addtime'=>date('Y-m-d H:i:s')
        );
        inserttable('bill', $setarr, 1);
        //发送通知
        $setarr=array(
            'cd_uid'=>0,
            'cd_uname'=>'系统提示',
            'cd_uids'=>$CcTvAi_com_userid,
            'cd_unames'=>$CcTvAi_com_username,
            'cd_icon'=>'payvip',
            'cd_data'=>cd_vipxtxt,
            'cd_dataid'=>0,
            'cd_state'=>1,
            'cd_addtime'=>date('Y-m-d H:i:s')
        );
        inserttable('notice', $setarr, 1);
        showmessage("恭喜您，已成功续费1年VIP会员", "index.php?ac=assets&view=vip", 0);
    }else{
        $cd_vippoints=cd_vipyearspointsa;
        $cd_viptime=cd_vipyearstime;
        $cd_vipindate=date('Y-m-d H:i:s');
        $tomorrow=mktime(date("H"), date("i"), date("s"), date("m"), date("d")+$cd_viptime, date("Y"));
        $cd_vipenddate=date("Y-m-d H:i:s", $tomorrow);
        $db->query("update " . tname('user') . " set cd_points=cd_points-$cd_vippoints,cd_vipgrade=2,cd_grade=1,cd_vipindate='$cd_vipindate',cd_vipenddate='$cd_vipenddate' where cd_id='$CcTvAi_com_userid'");
        //记录账单
        $setarr=array(
            'cd_type'=>0, //1为加,0为减
            'cd_uid'=>$CcTvAi_com_userid,
            'cd_uname'=>$CcTvAi_com_username,
            'cd_icon'=>'payvip',
            'cd_title'=>'充值'.cd_vipyearstime.'天VIP会员',
            'cd_points'=>cd_vipyearspointsa,
            'cd_addtime'=>date('Y-m-d H:i:s')
        );
        inserttable('bill', $setarr, 1);
        //发送通知
        $setarr=array(
            'cd_uid'=>0,
            'cd_uname'=>'系统提示',
            'cd_uids'=>$CcTvAi_com_userid,
            'cd_unames'=>$CcTvAi_com_username,
            'cd_icon'=>'payvip',
            'cd_data'=>cd_vipktxt,
            'cd_dataid'=>0,
            'cd_state'=>1,
            'cd_addtime'=>date('Y-m-d H:i:s')
        );
        inserttable('notice', $setarr, 1);
        showmessage("恭喜您，已成功申请1年VIP会员", "index.php?ac=assets&view=vip", 0);
	}
    } else {
        showmessage("您的账户金币不足", "index.php?ac=assets", 0);
    }
} elseif($ac=="profile") {//修改基本资料
if(!$userlogined==true){showmessage("请先登录后操作", "login.php", 0);}
$cd_sex=SafeRequest("cd_sex", "post");
$b_year=SafeRequest("b_year", "post");
$b_month=SafeRequest("b_month", "post");
$b_day=SafeRequest("b_day", "post");
$birthcity=SafeRequest("birthprovince", "post");
$cd_qq=SafeRequest("cd_qq", "post");
$cd_sign=SafeRequest("cd_sign", "post");
$rqq=SafeRequest("rqq", "post");
$cd_birthday=$b_year . "-" . $b_month . "-" . $b_day;
if ($cd_sex=="1") {$sexs="帅哥";} elseif ($cd_sex=="0") {$sexs="靓女";} else {$sexs="靓女";}
$db->query("update " . tname('user') . " set cd_sex='" . $sexs . "',cd_birthday='" . $cd_birthday . "',cd_birthcity='" . $birthcity . "',cd_qq='" . $cd_qq . "',cd_hidden='" . $rqq . "',cd_sign='" . $cd_sign . "' where cd_id='" . $CcTvAi_com_userid . "'");
showmessage("个人资料已更新", "index.php?ac=profile", 0);

} elseif($ac=="profilepassword") {//修改密码
if(!$userlogined==true){showmessage("请先登录后操作", "login.php", 0);}
$cd_oldPassword=SafeRequest("roldpassword", "post");
$cd_password=SafeRequest("rpassword", "post");
$cd_password2=SafeRequest("rpassword2", "post");
if ($cd_password!=$cd_password2) {showmessage("两次输入密码不相同", "index.php?ac=profile&view=password", 0);}
	$sql="select cd_id from " . tname('user') . " where cd_name='" . $CcTvAi_com_username . "' and cd_password='" . substr(md5($cd_oldPassword), 8, 16) . "'";
	$cd_id=$db->getone($sql);
	if ($cd_id) {
		$db->query("update " . tname('user') . " set cd_password='" . substr(md5($cd_password2), 8, 16) . "' where cd_id='" . $CcTvAi_com_userid . "'");
		setcookie("cd_id", $cd_id, time()+86400, cd_cookiepath);
		setcookie("cd_name", $CcTvAi_com_username, time()+86400, cd_cookiepath);
		setcookie("cd_password", substr(md5($cd_password2), 8, 16), time()+86400, cd_cookiepath);
		showmessage("密码已修改", "login.php", 0);
	} else {
		showmessage("旧密码错误", "index.php?ac=profile&view=password", 0);
	}
} elseif($ac=="profileemail") {//修改邮箱
if(!$userlogined==true){showmessage("请先登录后操作", "login.php", 0);}
$cd_email=SafeRequest("email", "post");
if(check_email($cd_email)==""){showmessage("请输入正确的联系邮箱帐号", $_SERVER['HTTP_REFERER'], 0);}
	$email=$db->getone("select cd_id from " . tname('user') . " where cd_id<>'$CcTvAi_com_userid' and cd_email='" . $cd_email . "'");
	if ($email) {
		showmessage("联系邮箱已存在,请更换一个", $_SERVER['HTTP_REFERER'], 0);
	} else {
		$db->query("update " . tname('user') . " set cd_email='" . $cd_email . "' where cd_id='" . $CcTvAi_com_userid . "'");
		showmessage("联系邮箱已修改", $_SERVER['HTTP_REFERER'], 0);
	}
} elseif($ac=="profilenickname") {//修改昵称
if(!$userlogined==true){showmessage("请先登录后操作", "login.php", 0);}
$cd_nickname=SafeRequest("nicheng", "post");
	$nicheng=$db->getone("select cd_id from " . tname('user') . " where cd_id<>'" . $CcTvAi_com_userid . "' and cd_nicheng='" . $cd_nickname . "'");
	if ($nicheng) {
		showmessage("昵称已存在,请更换一个", $_SERVER['HTTP_REFERER'], 0);
	} else {
		$db->query("update " . tname('user') . " set cd_nicheng='" . $cd_nickname . "' where cd_id='" . $CcTvAi_com_userid . "'");
		showmessage("昵称已修改", $_SERVER['HTTP_REFERER'], 0);
	}
} elseif($ac=="profileprotectio") {//修改密保
if(!$userlogined==true){showmessage("请先登录后操作", "login.php", 0);}
$cd_password=SafeRequest("rpasswords", "post");
$cd_question=SafeRequest("rquestion", "post");
$cd_answer=SafeRequest("ranswer", "post");
if ($cd_question==$cd_answer) {showmessage("问题和答案不能相同", "index.php?ac=profile&view=protectio", 0);}
$sql="select cd_id from " . tname('user') . " where cd_name='" . $CcTvAi_com_username . "' and cd_password='" . substr(md5($cd_password), 8, 16) . "'";
$cd_id=$db->getone($sql);
if ($cd_id) {
	$db->query("update " . tname('user') . " set cd_question='" . $cd_question . "',cd_answer='" . substr(md5($cd_answer), 8, 16) . "' where cd_id='" . $CcTvAi_com_userid . "'");
	showmessage("密保已修改", "index.php?ac=profile&view=protectio", 0);
	} else {
		showmessage("登录密码不正确", "index.php?ac=profile&view=protectio", 0);
		}
} elseif($ac=="danceadd") {//发布音乐
if(!$userlogined==true){showmessage("请先登录后操作", "login.php", 0);}
if(cd_uploadentrance=="no") {showmessage("已关闭作品提交", $_SERVER['HTTP_REFERER'], 0);}
if(cd_userupload=="0"){showmessage("已关闭本地上传服务", "index.php?ac=music", 0);}

	//******提交参数********//
	$seccode=SafeRequest("seccode", "post");
	$CD_Name=unescape(SafeRequest("CD_Name", "post"));
	$CD_Singer=SafeRequest("CD_Singer", "post");
	$CD_ClassID=SafeRequest("CD_ClassID", "post");
	$CD_Pic=SafeRequest("CD_Pic", "post");
	$CD_Url=SafeRequest("CD_Url", "post");
	$CD_DownUrl=$CD_Url;
	$CD_Siz=SafeRequest("CD_Siz", "post");
	$CD_Md5=SafeRequest("CD_Md5", "post");
	$CD_From=SafeRequest("CD_From", "post");
	$CD_Uid=SafeRequest("CD_Uid", "post");
	$CD_Playtime=SafeRequest("CD_Playtime", "post");
	$CD_Bitkbps=SafeRequest("CD_Bitkbps", "post");
	$CD_SpecialID=0;
	$CD_User=$CcTvAi_com_username;
	$CD_Tag=SafeRequest("CD_Tag", "post");
	$CD_Word=SafeRequest("CD_Word", "post");
	$CD_Lrc=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");
	$posturl="index.php?ac=music&view=upload&editor=2&cd_pic=$CD_Pic&cd_url=$CD_Url&rServer=$CD_Server&cd_name=$CD_Name&cd_singer=$CD_Singer&cd_tag=$CD_Tag&cd_points=$CD_Points&cd_word=$CD_Word&rsiz=$CD_Siz&rmd5=$CD_Md5";//返回url地址
	
	
	//******判断V过滤********//
	if ($seccode!=$_SESSION["codes"]) {showmessage("验证码不正确", $posturl, 0);}
	$_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 . "'")) {showmessage("音乐名称已存在，请修改", $posturl, 0);}
	if (cd_attachmentpoints>$CD_Points) {} else {showmessage("金币售价太高", $posturl, 0);}
	if (empty($CD_Name) || empty($CD_Singer) || empty($CD_ClassID) || empty($CD_Url)) {showmessage("请完善信息", $posturl, 0);}
	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 . "'");
}
if(cd_upmusicpassed=="1"){showmessage("发布成功，请等待审核。", "index.php?ac=music&view=passed", 0);}else{showmessage("发布成功", "index.php?ac=music", 0);}

} elseif($ac=="videoadd") {//发布视频
if(!$userlogined==true){showmessage("请先登录后操作", "login.php", 0);}
if(cd_uploadentrance=="no") {showmessage("已关闭作品提交", $_SERVER['HTTP_REFERER'], 0);}
if(cd_userupload=="0"){showmessage("已关闭本地上传服务", "index.php?ac=video", 0);}

	//******提交参数********//
	$seccode=SafeRequest("seccode", "post");
	$CD_Name=unescape(SafeRequest("CD_Name", "post"));
	$CD_Singer=SafeRequest("CD_Singer", "post");
	$CD_ClassID=SafeRequest("CD_ClassID", "post");
	$CD_Pic=SafeRequest("CD_Pic", "post");
	$CD_Url=SafeRequest("CD_Url", "post");
	$CD_DownUrl=$CD_Url;
	$CD_Siz=SafeRequest("CD_Siz", "post");
	$CD_Md5=SafeRequest("CD_Md5", "post");
	$CD_From=SafeRequest("CD_From", "post");
	$CD_Uid=SafeRequest("CD_Uid", "post");
	$CD_Playtime=SafeRequest("CD_Playtime", "post");
	$CD_Bitkbps=SafeRequest("CD_Bitkbps", "post");
	$CD_SpecialID=0;
	$CD_User=$CcTvAi_com_username;
	$CD_Tag=SafeRequest("CD_Tag", "post");
	$CD_Word=SafeRequest("CD_Word", "post");
	$CD_Lrc=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='video.html';
	$CD_Server=SafeRequest("CD_Server", "post");
	$posturl="index.php?ac=video&view=upload&editor=2&cd_pic=$CD_Pic&cd_url=$CD_Url&rServer=$CD_Server&cd_name=$CD_Name&cd_singer=$CD_Singer&cd_tag=$CD_Tag&cd_points=$CD_Points&cd_word=$CD_Word&rsiz=$CD_Siz&rmd5=$CD_Md5";//返回url地址
	
	
	//******判断V过滤********//
	if ($seccode!=$_SESSION["codes"]) {showmessage("验证码不正确", $posturl, 0);}
	$_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('video') . " where CD_Name='" . $CD_Name . "'")) {showmessage("视频名称已存在，请修改", $posturl, 0);}
	if (cd_attachmentpoints>$CD_Points) {} else {showmessage("金币售价太高", $posturl, 0);}
	if (empty($CD_Name) || empty($CD_Singer) || empty($CD_ClassID) || empty($CD_Url)) {showmessage("请完善信息", $posturl, 0);}
	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('video') . " (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('video') . " 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' => 'video',
	'cd_title' => '发布了视频',
	'cd_data' => '发布了《' . $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);
$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_videodaytime']==$sj) {
	$db->query('update ' . tname('system') . " set cd_videodaymub=cd_videodaymub+'1',cd_videomub=cd_videomub+'1'");
} else {
	$db->query('update ' . tname('system') . " set cd_videodaymub='1',cd_videomub=cd_videomub+'1',cd_videodaytime='" . $sj . "'");
}
if(cd_upmusicpassed=="1"){showmessage("发布成功，请等待审核。", "index.php?ac=video&view=passed", 0);}else{showmessage("发布成功", "index.php?ac=video", 0);}
	
} elseif($ac=="malbumadd") {//发布音乐专辑
if(!$userlogined==true){showmessage("请先登录后操作", "login.php", 0);}
$CD_Name=SafeRequest("SpecialName", "post");
$CD_Singer=SafeRequest("SingerID", "post");
$CD_GongSi=SafeRequest("GongSi", "post");
$CD_ClassID=SafeRequest("CD_ClassID", "post");
$CD_YuYan=SafeRequest("YuYan", "post");
$CD_Pic=SafeRequest("Pic", "post");
$CD_Intro=SafeRequest("Intro", "post");
$posturl="index.php?ac=malbum&view=upload&editor=1&cd_pic=$CD_Pic&SpecialName=$CD_Name&SingerID=$CD_Singer&GongSi=$CD_GongSi&Intro=$CD_Intro";//返回url地址
if ($db->getone("select CD_Name from " . tname('malbum') . " where CD_Name='" . $CD_Name . "'")) {showmessage("专辑名称已存在，请修改", $posturl, 0);}
if (strpos($CD_Pic, ".")===false) {showmessage("请上传封面图片", 'index.php?ac=malbum&view=upload', 0);}
if (empty($CD_Name) || empty($CD_Singer) || empty($CD_ClassID)) {showmessage("请完善信息", $posturl, 0);}
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;
}
	$setarr=array(
		'CD_ClassID' => $CD_ClassID,
		'CD_Name' => $CD_Name,
		'CD_User' => $CcTvAi_com_username,
		'CD_Pic' => $CD_Pic,
		'CD_Singer' => $singername['CD_ID'],
		'CD_GongSi' => $CD_GongSi,
		'CD_YuYan' => $CD_YuYan,
		'CD_Song' => '',
		'CD_Intro' => $CD_Intro,
		'CD_Hits' => 0,
		'CD_IsBest' => 1,
		'CD_Passed' => 1,
		'CD_AddTime' => date('Y-m-d H:i:s')
	);
	inserttable('malbum', $setarr, 1);
	$row=$db->getrow("select * from " . tname('malbum') . " where CD_User='" . $CcTvAi_com_username . "' and CD_Name='" . $CD_Name . "' and CD_Singer='" . $singername['CD_ID'] . "' order by CD_ID desc");
	$setarrs=array(
		'cd_uid' => $CcTvAi_com_userid,
		'cd_uname' => $CcTvAi_com_username,
		'cd_icon' => 'malbum',
		'cd_title' => '制作了音乐专辑',
		'cd_data' => '制作了《' . $CD_Name . '》<a href="' . LinkUrl("malbum", $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);
showmessage("发布成功，请等待审核。", "index.php?ac=malbum&view=passed", 0);
} elseif($ac=="malbumsong") {//添加音乐专辑
$malbumid=SafeRequest("malbumid", "get");
$songid=SafeRequest("songid", "get");
$db->query("update " . tname('dj') . " set CD_SpecialID='" . $malbumid . "' where CD_ID in ($songid)");
showmessage("已添加到专辑中", $_SERVER['HTTP_REFERER'], 0);
} elseif($ac=="malbumsongdel") {//移除音乐专辑
$malbumid=SafeRequest("malbumid", "get");
$songid=SafeRequest("songid", "get");
$db->query("update " . tname('dj') . " set CD_SpecialID=0 where CD_ID in ($songid)");
showmessage("已从专辑中移除", $_SERVER['HTTP_REFERER'], 0);

} elseif($ac=="valbumadd") {//发布视频专辑
if(!$userlogined==true){showmessage("请先登录后操作", "login.php", 0);}
$CD_Name=SafeRequest("SpecialName", "post");
$CD_Singer=SafeRequest("SingerID", "post");
$CD_GongSi=SafeRequest("GongSi", "post");
$CD_ClassID=SafeRequest("CD_ClassID", "post");
$CD_YuYan=SafeRequest("YuYan", "post");
$CD_Pic=SafeRequest("Pic", "post");
$CD_Intro=SafeRequest("Intro", "post");
$posturl="index.php?ac=valbum&view=upload&editor=1&cd_pic=$CD_Pic&SpecialName=$CD_Name&SingerID=$CD_Singer&GongSi=$CD_GongSi&Intro=$CD_Intro";//返回url地址
if ($db->getone("select CD_Name from " . tname('valbum') . " where CD_Name='" . $CD_Name . "'")) {showmessage("专辑名称已存在，请修改", $posturl, 0);}
if (strpos($CD_Pic, ".")===false) {showmessage("请上传封面图片", 'index.php?ac=valbum&view=upload', 0);}
if (empty($CD_Name) || empty($CD_Singer) || empty($CD_ClassID)) {showmessage("请完善信息", $posturl, 0);}
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;
}
	$setarr=array(
		'CD_ClassID' => $CD_ClassID,
		'CD_Name' => $CD_Name,
		'CD_User' => $CcTvAi_com_username,
		'CD_Pic' => $CD_Pic,
		'CD_Singer' => $singername['CD_ID'],
		'CD_GongSi' => $CD_GongSi,
		'CD_YuYan' => $CD_YuYan,
		'CD_Song' => '',
		'CD_Intro' => $CD_Intro,
		'CD_Hits' => 0,
		'CD_IsBest' => 1,
		'CD_Passed' => 1,
		'CD_AddTime' => date('Y-m-d H:i:s')
	);
	inserttable('valbum', $setarr, 1);
	$row=$db->getrow("select * from " . tname('valbum') . " where CD_User='" . $CcTvAi_com_username . "' and CD_Name='" . $CD_Name . "' and CD_Pic='" . $CD_Pic . "' order by CD_ID desc");
	$setarrs=array(
		'cd_uid' => $CcTvAi_com_userid,
		'cd_uname' => $CcTvAi_com_username,
		'cd_icon' => 'malbum',
		'cd_title' => '制作了视频专辑',
		'cd_data' => '制作了《' . $CD_Name . '》<a href="' . LinkUrl("valbum", $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);
showmessage("发布成功，请等待审核。", "index.php?ac=valbum&view=passed", 0);
} elseif($ac=="valbumsong") {//添加视频专辑
$valbumid=SafeRequest("valbumid", "get");
$songid=SafeRequest("songid", "get");
$db->query("update " . tname('video') . " set CD_SpecialID='" . $valbumid . "' where CD_ID in ($songid)");
showmessage("已添加到专辑中", $_SERVER['HTTP_REFERER'], 0);
} elseif($ac=="valbumsongdel") {//移除视频专辑
$valbumid=SafeRequest("valbumid", "get");
$songid=SafeRequest("songid", "get");
$db->query("update " . tname('video') . " set CD_SpecialID=0 where CD_ID in ($songid)");
showmessage("已从专辑中移除", $_SERVER['HTTP_REFERER'], 0);

} 
?>