<?php
# Name: PHP版程氏音乐CMS管理系统 v3.0
# Author: 程氏<web@chshcms.com> [QQ:848769359]
# Homepage:http://www.chshcms.cn/
include_once("../lib/cs_conn.php");
include_once("../lib/cs_common.php");
if(CS_Ucmode==1){
 include_once("../lib/cs_config_uc.php");
 include_once("../lib/client/client.php");
}
if(CS_UserFun==1) exit(Msg_Error('抱歉,本站会员功能已经关闭!','/'));
ob_start();
//允许动作
$dos = array('reg', 'qqlogin', 'login', 'logout', 'music', 'topic', 'pic', 'edit', 'news', 'msg', 'fav');
//获取变量
$ac=CS_Request("ac");
$ac = (!empty($ac) && in_array($ac, $dos))?$ac:'tg';

switch ($ac){
	case 'login':LOGIN();break;
	case 'qqlogin':QQLOGIN();break;
	case 'reg':REG();break;
	case 'logout':LOGOUT();break;
	case 'music':MUSIC();break;
	case 'topic':TOPIC();break;
	case 'pic':PIC();break;
	case 'edit':EDIT();break;
	case 'news':NEWS();break;
	case 'msg':MSG();break;
	case 'fav':FAV();break;
	default:TG();break;
}

//推广
function TG(){
       echo "<script>window.location='".CS_WebPath."'</script>";
}

//用户注册
function REG(){
       $name=CS_Request("username");
       $pass=CS_Request("password");
       $nichen=CS_Request("nickname");
       $email=CS_Request("email");
	$loginip=$_SERVER['REMOTE_ADDR'];
       if(empty($name)||empty($pass)||empty($nichen)||empty($email))  exit(Msg_Error('抱歉,请把资料填写完整!','javascript:history.go(-1);'));
	$cs_pass=Md5($pass);

        $e_title=CS_WebName."-会员注册邮件";
	$e_content="<br>";
	$e_content.="   ".$name.",您好！欢迎您加入".CS_WebName."   以下是您的注册信息：<br>";
	$e_content.="用户名：".$name."   密码：".$pass."   请牢记你的密码！<br>";

	global $db;
	$userid=$db->getone("select cs_id from ".Getdbname('user')." where cs_name='".$name."'");
	if($userid) exit(Msg_Error("出错了，用户已存在不能重复申请。",$_SERVER['HTTP_REFERER']));
	$userEmail=$db->getone("select cs_id from ".Getdbname('user')." where cs_Email='".$email."'");
	if($userEmail) exit(Msg_Error("出错了，该Email已存在不能重复使用。",$_SERVER['HTTP_REFERER']));
        $uid="";
	//--------------------------- Ucenter ---------------------------
	if(CS_Ucmode==1){
	   $uid=uc_user_register($name,$pass,$email);
	   if($uid <= 0){
		if($uid == -1){
			exit(Msg_Error("出错了，UC用户名不合法。",$_SERVER['HTTP_REFERER']));
		}elseif($uid == -2){
			exit(Msg_Error("出错了，UC用户名包含要允许注册的词语。",$_SERVER['HTTP_REFERER']));
		}elseif($uid == -3){
			exit(Msg_Error("出错了，UC用户名已经存在。",$_SERVER['HTTP_REFERER']));
		}elseif($uid == -4){
			exit(Msg_Error("出错了，UCEmail 格式有误。",$_SERVER['HTTP_REFERER']));
		}elseif($uid == -5){
			exit(Msg_Error("出错了，UCmail 不允许注册。",$_SERVER['HTTP_REFERER']));
		}elseif($uid == -6){
			exit(Msg_Error("出错了，UC该 Email 已经被注册。",$_SERVER['HTTP_REFERER']));
		}else{
			exit(Msg_Error("出错了，UC该错误未定义。",$_SERVER['HTTP_REFERER']));
		}
	   }
        }
                $cs_uid=$uid;
		$sql="insert into ".Getdbname('user')." (CS_UID,CS_Name,CS_Pass,CS_Email,CS_Nichen,cs_addtime) values ('".$cs_uid."','".$name."','".$cs_pass."','".$email."','".$nichen."','".date('Y-m-d H:i:s')."')";
		if($db->query($sql)){
			//发消息通知
			$sql="insert into ".Getdbname('xiaoxi')." (cs_userb,cs_usera,cs_name,cs_neir,cs_addtime) values ('系统消息','".$name."','系统给您发送了一条消息','欢迎您加入".CS_WebName.",有您的加入我们会更加精彩!','".date('Y-m-d H:i:s')."')";
			$db->query($sql);
		  if(CS_Mailmode==1){	//判断是否发送邮件
                      $send=$smtp->sendmail($email,CS_Mailname,$e_title,$e_content,'HTML');
                      if($send==1){
                         exit(Msg_Error("恭喜您，注册成功了,注册信息已经发送直您的邮箱，现在引导您进入登录前页面。","index.php"));
		      }else{
		         exit(Msg_Error("恭喜您，注册成功了，现在引导您进入登录前页面。","index.php"));
		      }
		  }else{
		         exit(Msg_Error("恭喜您，注册成功了，现在引导您进入登录前页面。","index.php"));
		  }
		}else{
		         exit(Msg_Error("会员注册失败。",$_SERVER['HTTP_REFERER']));
		}
}

//登入
function LOGIN(){
       $name=CS_Request("username");
       $pass=CS_Request("password");
       $cookietime=CS_Request("cookietime");
       if(empty($cookietime)) $cookietime=86400;
       $logintime=date('Y-m-d H:i:s');
       $loginip=$_SERVER['REMOTE_ADDR'];
       if(empty($name)) exit(Msg_Error('抱歉,用户名不能为空，请重新登录!','javascript:history.go(-1);'));
       if(empty($pass)) exit(Msg_Error('抱歉,密码不能为空，请重新登录!','javascript:history.go(-1);'));
		$pass=Md5($pass);
		global $db;
		$sqlj= "select cs_id from ".Getdbname('user')." where cs_name='".$name."'";
        	$cs_id= $db->Getone($sqlj);
		if($cs_id==""){
	                //--------------------------- Ucenter ---------------------------
			if(CS_Ucmode==1){
			//从UC中获得UC用户ID
			  $ucid = uc_get_user($name);
			  // 获得后激活帐号
			  if($ucid[0]>0) {

		                  $sql="insert into ".Getdbname('user')." (CS_UID,CS_Name,CS_Pass,CS_Email,cs_addtime) values ('".$ucid[0]."','".$ucid[1]."','".md5($pass)."','".$ucid[2]."','".date('Y-m-d H:i:s')."')";
		                  if($db->query($sql)){
			                   //发消息通知
			                   $sql="insert into ".Getdbname('xiaoxi')." (cs_userb,cs_usera,cs_name,cs_neir,cs_addtime) values ('系统消息','".$ucid[1]."','系统给您发送了一条消息','欢迎您加入".CS_WebName.",有您的加入我们会更加精彩!','".date('Y-m-d H:i:s')."')";
			                   $db->query($sql);
                                           //登入
                                           $row=$db ->Getrow("select cs_id,cs_name,cs_pass,cs_sid,cs_email from ".Getdbname('user')." where cs_name='".$ucid[1]."'");
				           setcookie("cs_id",$row["cs_id"],time()+$cookietime,'/',Host_User());
				           setcookie("cs_name",$row["cs_name"],time()+$cookietime,'/',Host_User());
				           exit(Msg_Error('登录成功了，现在引导您进入会员中心!','space.php?ac=home'));
		                   }
			  }
                        }
	                //--------------------------- Ucenter ---------------------------
                }
		$sql= "select cs_id from ".Getdbname('user')." where cs_name='".$name."' and cs_pass='".$pass."'";
        	$cs_id= $db->Getone($sql);
		if($cs_id){
			$db->query("update ".Getdbname('user')." set CS_LogNum=CS_LogNum+1,CS_LogIP ='".$loginip."',CS_LogTime='".$logintime."' where cs_id='".$cs_id."'");
			$row=$db ->Getrow("select cs_id,cs_name,cs_pass,cs_sid,cs_email from ".Getdbname('user')." where cs_id=".$cs_id."");
			if($row["cs_sid"]==1){
                                exit(Msg_Error('对不起，此账号已被锁定，请和管理员联系!',$_SERVER['HTTP_REFERER']));
			}else{
			  if(CS_LogFun==0){
			    $tishi="b";
			    if(isset($_COOKIE["CS_LoginIP"])){
			        $CS_LoginIP=$_COOKIE["CS_LoginIP"];
			        if($loginip==$CS_LoginIP){
                                         $tishi="a";
                                }else{
                                       setcookie("CS_LoginIP","",time()-1);
                                }
			    }else{
				setcookie("CS_LoginIP",$loginip,time()+3600);	
			    }
			    if($tishi=="b"){
					setcookie("CS_LoginIP",$loginip,time()+3600);
					$db->query("update ".Getdbname('user')." set CS_Coin=CS_Coin+".CS_LogDs." where Cs_id=".$cs_id."");
                                  $tishiname="每天登入一次系统给你增加".CS_DjDs."点";
			    }
                          }

	             //--------------------------- Ucenter ---------------------------
			if(CS_Ucmode==1){
			//从UC中获得UC用户ID
			$ucid = uc_get_user($row["cs_name"]);
			// 获得后同步登陆
			if($ucid[0]>0) {
				echo uc_user_synlogin($ucid[0]);
			}
			}
	             //--------------------------- Ucenter ---------------------------
				setcookie("cs_id",$row["cs_id"],time()+$cookietime,'/',Host_User());
				setcookie("cs_name",$row["cs_name"],time()+$cookietime,'/',Host_User());
				exit(Msg_Error('登录成功了，现在引导您进入会员中心!'.$tishiname.'','space.php?ac=home'));
			}
		}else{
                        exit(Msg_Error('对不起，用户名或密码错误，请重新登录!',$_SERVER['HTTP_REFERER']));
		}
}

//QQ登入
function QQLOGIN(){
       $name=CS_Request("username");
       $pass=CS_Request("password");
       $cookietime=CS_Request("cookietime");
       if(empty($cookietime)) $cookietime=86400;
       $logintime=date('Y-m-d H:i:s');
       $loginip=$_SERVER['REMOTE_ADDR'];
       if(empty($_SESSION["openid"])) exit(Msg_Error('抱歉,QQ登入出错，获取布不到openid。','index.php'));

		global $db;
		$sqlj= "select cs_id from ".Getdbname('user')." where cs_qqid='".$_SESSION["openid"]."'";
        	$cs_id= $db->Getone($sqlj);
		if($cs_id==""){  //没有绑定
                        if(CS_RegFun==1) exit(Web_Error('抱歉,本站会员注册已经关闭!','/'));
	                //--------------------------- Ucenter ---------------------------
			if(CS_Ucmode==1){
			//从UC中获得UC用户ID
			  $ucid = uc_get_user($name);
			  // 获得后激活帐号
			  if($ucid[0]>0) {
			  $_SESSION["uid"]=$ucid[0];
			  $_SESSION["username"]=$ucid[1];
			  $_SESSION["email"]=$ucid[2];
			  $_SESSION["password"]=$s_password;
                             exit(Msg_Error('对不起，该用户未在本站激活,请先激活帐号!','jihuo.php'));
			  }
                        }
	                //--------------------------- Ucenter ---------------------------
                        $name="QQ".rand(10000, 99999);
		        $sql="insert into ".Getdbname('user')." (CS_UID,CS_Name,CS_Pass,CS_Email,CS_Nichen,cs_qqid,cs_addtime) values ('','".$name."','".md5($name)."','','".$name."','".$_SESSION["openid"]."','".date('Y-m-d H:i:s')."')";
		        if($db->query($sql)){
			        //发消息通知
			        $sql="insert into ".Getdbname('xiaoxi')." (cs_userb,cs_usera,cs_name,cs_neir,cs_addtime) values ('系统消息','".$name."','系统给您发送了一条消息','欢迎您加入".CS_WebName.",有您的加入我们会更加精彩!','".date('Y-m-d H:i:s')."')";
			        $db->query($sql);
                                //登入
                                $row=$db ->Getrow("select cs_id,cs_name,cs_pass,cs_sid,cs_email from ".Getdbname('user')." where cs_qqid='".$_SESSION["openid"]."'");
				setcookie("cs_id",$row["cs_id"],time()+$cookietime,'/',Host_User());
				setcookie("cs_name",$row["cs_name"],time()+$cookietime,'/',Host_User());
				exit(Msg_Error('登录成功了，现在去完成资料!'.$tishiname.'','space.php?ac=edit&op=zl'));
		        }else{
		                 exit(Msg_Error("会员注册失败。",$_SERVER['HTTP_REFERER']));
		        }

                }else{ //已经存在侧登入
			$db->query("update ".Getdbname('user')." set CS_LogNum=CS_LogNum+1,CS_LogIP ='".$loginip."',CS_LogTime='".$logintime."' where cs_qqid='".$_SESSION["openid"]."'");
			$row=$db ->Getrow("select cs_id,cs_name,cs_pass,cs_sid,cs_email from ".Getdbname('user')." where cs_qqid='".$_SESSION["openid"]."'");
			if($row["cs_sid"]==1){
                                exit(Msg_Error('对不起，此账号已被锁定，请和管理员联系!',$_SERVER['HTTP_REFERER']));
			}else{
			  if(CS_LogFun==0){
			    $tishi="b";
			    if(isset($_COOKIE["CS_LoginIP"])){
			        $CS_LoginIP=$_COOKIE["CS_LoginIP"];
			        if($loginip==$CS_LoginIP){
                                         $tishi="a";
                                }else{
                                       setcookie("CS_LoginIP","",time()-1);
                                }
			    }else{
				setcookie("CS_LoginIP",$loginip,time()+3600);	
			    }
			    if($tishi=="b"){
					setcookie("CS_LoginIP",$loginip,time()+3600);
					$db->query("update ".Getdbname('user')." set CS_Coin=CS_Coin+".CS_LogDs." where Cs_id=".$cs_id."");
                                  $tishiname="每天登入一次系统给你增加".CS_DjDs."点";
			    }
                          }

	             //--------------------------- Ucenter ---------------------------
			if(CS_Ucmode==1){
			//从UC中获得UC用户ID
			$ucid = uc_get_user($row["cs_name"]);
			// 获得后同步登陆
			if($ucid[0]>0) {
				echo uc_user_synlogin($ucid[0]);
			}
			}
	             //--------------------------- Ucenter ---------------------------
				setcookie("cs_id",$row["cs_id"],time()+$cookietime,'/',Host_User());
				setcookie("cs_name",$row["cs_name"],time()+$cookietime,'/',Host_User());
				exit(Msg_Error('登录成功了，现在引导您进入会员中心!'.$tishiname.'','space.php?ac=home'));
			}
		}
}

//退出登陆
function LOGOUT(){
	$name=$_COOKIE["cs_name"];

	//--------------------------- Ucenter ---------------------------
			if(CS_Ucmode==1){
			   //从UC中获得UC用户ID
			   $ucid = uc_get_user($name);
			   // 获得后同步退出登陆
			   if($ucid[0]>0) {
				echo uc_user_synlogout($ucid[0]);
			   }
			}
	//--------------------------- Ucenter ---------------------------
	setcookie("cs_id","",time()-1,'/',Host_User());
	setcookie("cs_name","",time()-1,'/',Host_User());
	exit(Msg_Error('你已安全退出了!','index.php'));
}

//分享音乐
function MUSIC(){
        if(isset($_COOKIE["cs_name"])){
	   $cscms_name=$_COOKIE["cs_name"];
	}else{
	   exit(Msg_Error('你还没有登入或者登入已经超时!','login.php'));
	}
	$CS_Name=CS_Request("CS_Name");
	$CS_CID=CS_Request("CS_CID");
	$CS_FID=CS_Request("CS_FID");
	$CS_Tags=trim($_POST["CS_Tags"]);
	$CS_TID=CS_Request("CS_TID");
	$CS_PlayUrl=CS_Request("CS_PlayUrl");
	$CS_DownUrl1=CS_Request("CS_DownUrl1");
	$CS_Dx=CS_Request("CS_Dx");
	$CS_Content=CS_Request("CS_Content");
        if($CS_FID!=0) $CS_CID=$CS_FID;
        if(CS_DjFun==0){ $CS_YID=1;$title1=",请等待管理员审核!";}else{ $CS_YID=0;$title1="";}
 
        global $db;
        if(empty($CS_Name)||empty($CS_CID)||empty($CS_Tags)||empty($CS_PlayUrl)) exit(Msg_Error('抱歉,请把资料填写完整!','javascript:history.go(-1);'));
        //入库
	$sql="insert into ".Getdbname('dance')." (cs_user,cs_yid,cs_name,cs_cid,cs_tid,cs_tags,cs_playurl,cs_downurl1,cs_dx,CS_Content,cs_addtime) values ('".$cscms_name."',".$CS_YID.",'".$CS_Name."',".$CS_CID.",".$CS_TID.",'".$CS_Tags."','".$CS_PlayUrl."','".$CS_DownUrl1."','".$CS_Dx."','".$CS_Content."','".date('Y-m-d H:i:s')."')";
	if($db->query($sql)){
	   $row=$db->getrow("Select * from ".Getdbname('dance')." where CS_Name='".$CS_Name."'");

            if($CS_YID==0 && CS_DjaddFun==0){ //发布加点
		$db->query("update ".Getdbname('user')." set CS_Coin=CS_Coin+".CS_DjDs." where cs_name='".$cscms_name."'");
            }

           //*********分享到腾讯微薄********//
             require_once("open/qq/common.php");
             $linkurl="http://".CS_WebUrl.LinkUrl('play','dance','id',$row['CS_CID'],$row['CS_ID']);
             $title="我刚刚在“".CS_WebName."”发布了音乐[ ".$CS_Name." ]非常好听哦！ 感谢支持！";
             $ret = add_share($title,$linkurl,CS_WebName,CS_WebName);

            //产生动态
		$sqldt="insert into ".Getdbname('dt')." (cs_user,cs_cid,cs_did,cs_title,cs_addtime) values ('".$cscms_name."',3,".$row['CS_ID'].",'".$CS_Name."','".date('Y-m-d H:i:s')."')";
		$db->query($sqldt);

	    exit(Msg_Error('恭喜您，音乐添加成功了'.$title1.'!','space.php?ac=music'));

        }else{
	    exit(Msg_Error('抱歉，音乐添加失败!','javascript:history.go(-1);'));
        }
}

//专集制作
function TOPIC(){
        if(isset($_COOKIE["cs_name"])){
	   $cscms_name=$_COOKIE["cs_name"];
	}else{
	   exit(Msg_Error('你还没有登入或者登入已经超时!','login.php'));
	}
	$op=CS_Request("op");
	$id=CS_Request("id");
	$CS_Name=CS_Request("CS_Name");
	$CS_CID=CS_Request("CS_CID");
	$CS_FID=CS_Request("CS_FID");
	$CS_YID=CS_Request("CS_YID");
	$CS_Pic=CS_Request("CS_Pic");
	$CS_Tags=trim($_POST["CS_Tags"]);
	$CS_AliasName=CS_Request("CS_AliasName");
	$CS_Fxgs=CS_Request("CS_Fxgs");
	$CS_Diqu=CS_Request("CS_Diqu");
	$CS_Yuyan=CS_Request("CS_Yuyan");
	$CS_Year=CS_Request("CS_Year");
	$CS_Content=CS_Request("CS_Content");
        if($CS_FID!=0) $CS_CID=$CS_FID;
        global $db;

        if($op=='add'){ //新增
             if(empty($CS_Name)||empty($CS_CID)||empty($CS_Tags)||empty($CS_Pic)||empty($CS_AliasName)) exit(Msg_Error('抱歉,请把资料填写完整!','javascript:history.go(-1);'));
             //入库
	     $sql="insert into ".Getdbname('topic')." (cs_user,cs_yid,cs_name,cs_cid,cs_pic,cs_tags,cs_aliasname,cs_fxgs,cs_diqu,cs_yuyan,cs_year,cs_content,cs_addtime) values ('".$cscms_name."',1,'".$CS_Name."',".$CS_CID.",'".$CS_Pic."','".$CS_Tags."','".$CS_AliasName."','".$CS_Fxgs."','".$CS_Diqu."','".$CS_Yuyan."','".$CS_Year."','".$CS_Content."','".date('Y-m-d H:i:s')."')";
	     if($db->query($sql)){
	        $row=$db->getrow("Select * from ".Getdbname('topic')." where CS_Name='".$CS_Name."'");
                //*********分享到腾讯微薄********//
                  require_once("open/qq/common.php");
                  $linkurl="http://".CS_WebUrl.LinkUrl('show','zj','id',$row['CS_CID'],$row['CS_ID']);
                  $title="我刚刚在“".CS_WebName."”制作了专集[ ".$CS_Name." ]非常好听哦！ 感谢支持！";
                  $ret = add_share($title,$linkurl,CS_WebName,CS_WebName);

                 //产生动态
		     $sqldt="insert into ".Getdbname('dt')." (cs_user,cs_cid,cs_did,cs_title,cs_addtime) values ('".$cscms_name."',4,".$row['CS_ID'].",'".$CS_Name."','".date('Y-m-d H:i:s')."')";
		     $db->query($sqldt);

	         exit(Msg_Error('恭喜您，专集成功了，请等待管理员审核!','space.php?ac=topic'));

             }else{
	         exit(Msg_Error('抱歉，专集添加失败!','javascript:history.go(-1);'));
             }

        }elseif($op=='edit'){ //修改
              $sql="update ".Getdbname('topic')." set cs_name='".$CS_Name."',cs_cid=".$CS_CID.",cs_pic='".$CS_Pic."',cs_tags='".$CS_Tags."',cs_fxgs='".$CS_Fxgs."',cs_diqu='".$CS_Diqu."',cs_yuyan='".$CS_Yuyan."',cs_year='".$CS_Year."',cs_content='".$CS_Content."',cs_addtime='".date('Y-m-d H:i:s')."' where cs_id=".$id." and cs_user='".$cscms_name."'";
              if($db->query($sql)){
	         exit(Msg_Error('恭喜您，专集修改成功了!','space.php?ac=topic'));
              }else{
	         exit(Msg_Error('抱歉，专集修改失败!','javascript:history.go(-1);'));
              }

        }elseif($op=='zjadd'){
	    $tid=CS_Request("tid");
	    $id=trim($_GET["id"]);
               if($db->query("update ".Getdbname('dance')." set CS_TID=".$tid." where cs_user='".$cscms_name."' and CS_ID in (".$id.")")){
	            exit(Msg_Error('恭喜您，加入成功了!','javascript:history.go(-1);'));
               }else{
	            exit(Msg_Error('抱歉，加入失败了!','javascript:history.go(-1);'));
               }

        }elseif($op=='zjdel'){
	    $tid=CS_Request("tid");
	    $id=trim($_GET["id"]);
               if($db->query("update ".Getdbname('dance')." set CS_TID=0 where cs_user='".$cscms_name."' and CS_ID in (".$id.")")){
	            exit(Msg_Error('恭喜您，移除成功了!','javascript:history.go(-1);'));
               }else{
	            exit(Msg_Error('抱歉，移除失败了!','javascript:history.go(-1);'));
               }
        }
}

//相册制作
function PIC(){
        if(isset($_COOKIE["cs_name"])){
	   $cscms_name=$_COOKIE["cs_name"];
	}else{
	   exit(Msg_Error('你还没有登入或者登入已经超时!','login.php'));
	}
	$op=CS_Request("op");
	$id=CS_Request("id");
	$CS_Name=CS_Request("CS_Name");
	$CS_Pic=CS_Request("CS_Pic");
	$CS_Content=CS_Request("CS_Content");
        global $db;

        if($op=='add'){ //新增
             if(empty($CS_Name)||empty($CS_Pic)) exit(Msg_Error('抱歉,请把资料填写完整!','javascript:history.go(-1);'));
             //入库
	     $sql="insert into ".Getdbname('pic')." (cs_user,cs_name,cs_pic,cs_content,cs_addtime) values ('".$cscms_name."','".$CS_Name."','".$CS_Pic."','".$CS_Content."','".date('Y-m-d H:i:s')."')";
	     if($db->query($sql)){
	        $row=$db->getrow("Select * from ".Getdbname('topic')." where CS_Name='".$CS_Name."'");
                //*********分享到腾讯微薄********//
                  require_once("open/qq/common.php");
                  $linkurl="http://".CS_WebUrl.userlink('pic',$_COOKIE["cs_id"],$row['CS_ID']);
                  $title="我刚刚在“".CS_WebName."”制作了相册[ ".$CS_Name." ]去看看吧！ 感谢支持！";
                  $ret = add_share($title,$linkurl,CS_WebName,CS_WebName);
	         exit(Msg_Error('恭喜您，相册制作成功了!','space.php?ac=pic'));

             }else{
	         exit(Msg_Error('抱歉，相册制作失败!','javascript:history.go(-1);'));
             }

        }elseif($op=='edit'){ //修改
              $sql="update ".Getdbname('pic')." set cs_name='".$CS_Name."',cs_pic='".$CS_Pic."',cs_content='".$CS_Content."',cs_addtime='".date('Y-m-d H:i:s')."' where cs_id=".$id." and cs_user='".$cscms_name."'";
              if($db->query($sql)){
	         exit(Msg_Error('恭喜您，相册修改成功了!','space.php?ac=pic'));
              }else{
	         exit(Msg_Error('抱歉，相册修改失败!','javascript:history.go(-1);'));
              }

        }elseif($op=='zypic'){ //移动相片
	    $cid=CS_Request("cid");
	    $id=trim($_GET["id"]);
               if($db->query("update ".Getdbname('photo')." set CS_CID=".$cid." where CS_User='".$cscms_name."' and CS_ID in (".$id.")")){
	            exit(Msg_Error('恭喜您，转移成功了!','javascript:history.go(-1);'));
               }else{
	            exit(Msg_Error('抱歉，转移失败了!','javascript:history.go(-1);'));
               }
        }elseif($op=='delpic'){ //删除相片
	    $id=trim($_GET["id"]);
	    $Arr=explode(',',$id);
            for($i=0;$i<count($Arr);$i++){
                 $row=$db->getrow("Select * from ".Getdbname('photo')." where cs_id=".$Arr[$i]."");
                 //删除图片
	         $fileurl="../annex/pic/".$row['CS_Url'];
	         if(file_exists($fileurl)){
	           @unlink($fileurl);
	         }
                 $db->query("delete from ".Getdbname('photo')." where CS_ID=".$Arr[$i]." and CS_User='".$cscms_name."'");
            }
	       exit(Msg_Error('恭喜您，删除成功了!','javascript:history.go(-1);'));
        }
}

//修改资料
function EDIT(){
       if(isset($_COOKIE["cs_name"])){
	   $cscms_name=$_COOKIE["cs_name"];
       }else{
	   exit(Msg_Error('你还没有登入或者登入已经超时!','login.php'));
       }
       $op=CS_Request("op");
       $CS_Pass=CS_Request("CS_Pass");
       $CS_Pass2=CS_Request("CS_Pass2");
       $CS_Nichen=CS_Request("CS_Nichen");
       $CS_Sex=CS_Request("CS_Sex");
       $CS_City=CS_Request("CS_City");
       $CS_QQ=CS_Request("CS_QQ");
       $CS_Email=CS_Request("CS_Email");
       $CS_Qianm=CS_Request("CS_Qianm");
        global $db;

        if($op=='zl'){ //资料
             if(empty($CS_QQ)||empty($CS_Nichen)||empty($CS_City)||empty($CS_Email)) exit(Msg_Error('抱歉,请把资料填写完整!','javascript:history.go(-1);'));
             $sql="update ".Getdbname('user')." set CS_Nichen='".$CS_Nichen."',CS_Email='".$CS_Email."',CS_Sex=".$CS_Sex.",CS_City='".$CS_City."',CS_QQ='".$CS_QQ."',CS_Qianm='".$CS_Qianm."' where CS_Name='".$cscms_name."'";
             if($db->query($sql)){
	          exit(Msg_Error('恭喜您，修改成功了!','javascript:history.go(-1);'));
             }else{
	          exit(Msg_Error('抱歉，修改失败了!','javascript:history.go(-1);'));
             }
        }elseif($op=='pass'){ //密码
             $row=$db->getrow("Select * from ".Getdbname('user')." where CS_Name='".$cscms_name."' and cs_pass='".md5($CS_Pass)."'");
             if($row){
                  $db->query("update ".Getdbname('user')." set CS_Pass='".md5($CS_Pass2)."' where CS_Name='".$cscms_name."'");
	          exit(Msg_Error('恭喜您，修改成功了!','javascript:history.go(-1);'));
             }else{
	          exit(Msg_Error('抱歉，您的原密码错误!','javascript:history.go(-1);'));
             }
        }elseif($op=='bo'){ //播放器
           $CS_Bname=CS_Request("CS_Bname");
           $CS_Btop=CS_Request("CS_Btop");
           $CS_Bleft=CS_Request("CS_Bleft");
           if(empty($CS_Bname)||empty($CS_Btop)||empty($CS_Bleft)) exit(Msg_Error('抱歉,请把资料填写完整!','javascript:history.go(-1);'));

             $row=$db->getrow("Select * from ".Getdbname('dance')." where CS_User='".$cscms_name."' and  CS_Name like '%".$CS_Bname."%'");
             if($row){
                 $server=$db->getrow("select * from ".Getdbname('fwqip')." where CS_ID=".$row['CS_FID']."");
                 if(substr($row['CS_PlayUrl'],0,5)=="csdj_"){
                      $str=explode("_",$row['CS_PlayUrl']);
                      $Playurl="http://csdj.so/qq.php/".$str[1]."/".substr($str[2],0,-4).".mp3";
                 }else{
                      $Playurl=$server['CS_Playip'].$row['CS_PlayUrl'];
                 }
                 if(substr($Playurl,0,7)!="http://") $Playurl="http://".CS_WebUrl.$Playurl;
                 $CS_Mp3=$CS_Btop."@@@".$CS_Bleft."@@@".$row['CS_Name']."@@@".$Playurl;
                 $db->query("update ".Getdbname('user')." set CS_Mp3='".$CS_Mp3."' where CS_Name='".$cscms_name."'");
	          exit(Msg_Error('恭喜您，修改成功!','javascript:history.go(-1);'));
             }else{
	          exit(Msg_Error('抱歉，没有找到你要的歌曲!','javascript:history.go(-1);'));
             }
        }
}


//分享文章
function NEWS(){
        if(isset($_COOKIE["cs_name"])){
	   $cscms_name=$_COOKIE["cs_name"];
	}else{
	   exit(Msg_Error('你还没有登入或者登入已经超时!','login.php'));
	}
	$op=CS_Request("op");
	$id=CS_Request("id");
	$CS_Name=CS_Request("CS_Name");
	$CS_CID=CS_Request("CS_CID");
	$CS_Content=CS_Request("CS_Content");
        if(CS_NewsFun==0){ $CS_YID=1;$title1=",请等待管理员审核!";}else{ $CS_YID=0;$title1="";}
 
        global $db;
        if(empty($CS_Name)||empty($CS_CID)||empty($CS_Content)) exit(Msg_Error('抱歉,请把资料填写完整!','javascript:history.go(-1);'));
        
        if($op=='add'){
           //入库
	   $sql="insert into ".Getdbname('news')." (cs_user,cs_yid,cs_name,cs_cid,CS_Content,cs_addtime) values ('".$cscms_name."',".$CS_YID.",'".$CS_Name."',".$CS_CID.",'".$CS_Content."','".date('Y-m-d H:i:s')."')";
	   if($db->query($sql)){
	        $row=$db->getrow("Select * from ".Getdbname('news')." where CS_Name='".$CS_Name."'");

               //*********分享到腾讯微薄********//
                 require_once("open/qq/common.php");
                 $linkurl="http://".CS_WebUrl.LinkUrl('show','news','id',$row['CS_CID'],$row['CS_ID']);
                 $title="我刚刚在“".CS_WebName."”发表了文章[ ".$CS_Name." ], 去看看吧,感谢支持！";
                 $ret = add_share($title,$linkurl,CS_WebName,CS_WebName);

                //产生动态
		    $sqldt="insert into ".Getdbname('dt')." (cs_user,cs_cid,cs_did,cs_title,cs_addtime) values ('".$cscms_name."',5,".$row['CS_ID'].",'".$CS_Name."','".date('Y-m-d H:i:s')."')";
		    $db->query($sqldt);

	        exit(Msg_Error('恭喜您，文章发表成功了'.$title1.'!','space.php?ac=news'));

           }else{
	        exit(Msg_Error('抱歉，文章发表失败!','javascript:history.go(-1);'));
           }

        }elseif($op=='edit'){ //修改
              $sql="update ".Getdbname('news')." set cs_name='".$CS_Name."',cs_cid=".$CS_CID.",cs_content='".$CS_Content."',cs_addtime='".date('Y-m-d H:i:s')."' where cs_id=".$id." and cs_user='".$cscms_name."'";
              if($db->query($sql)){
	         exit(Msg_Error('恭喜您，文章修改成功了!','space.php?ac=news'));
              }else{
	         exit(Msg_Error('抱歉，文章修改失败!','javascript:history.go(-1);'));
              }
        }
}


//发送消息
function MSG(){
        if(isset($_COOKIE["cs_name"])){
	   $cscms_name=$_COOKIE["cs_name"];
	}else{
	   exit(Msg_Error('你还没有登入或者登入已经超时!','login.php'));
	}
	$CS_Usera=CS_Request("CS_Usera");
	$CS_Neir=CS_Request("CS_Neir");
	$CS_Name=CS_Request("CS_Name");

        global $db;
        if(empty($CS_Usera)||empty($CS_Neir)) exit(Msg_Error('抱歉,请把资料填写完整!','javascript:history.go(-1);'));
        if($CS_Usera==$cscms_name) exit(Msg_Error('抱歉,请不要给自己发消息!','javascript:history.go(-1);'));

	$userid=$db->getone("select cs_id from ".Getdbname('user')." where cs_name='".$CS_Usera."'");
	if(!$userid) exit(Msg_Error("出错了，该接收会员不存在。",$_SERVER['HTTP_REFERER']));

           //入库
	   $sql="insert into ".Getdbname('xiaoxi')." (cs_usera,cs_userb,cs_name,cs_neir,cs_addtime) values ('".$CS_Usera."','".$cscms_name."','".$CS_Name."','".$CS_Neir."','".date('Y-m-d H:i:s')."')";
	   if($db->query($sql)){
	        exit(Msg_Error('恭喜您，消息发送成功了'.$title1.'!','space.php?ac=msg'));
           }else{
	        exit(Msg_Error('抱歉，消息发送失败!','javascript:history.go(-1);'));
           }

}

//收藏
function FAV(){
	$id=CS_Request("id");
        if(isset($_COOKIE["cs_name"])){
	   $cscms_name=$_COOKIE["cs_name"];
	}else{
	   exit(Msg_Error('你还没有登入或者登入已经超时!','login.php'));
	}
	global $db;
	if(empty($id)) exit(Msg_Error('出错了，请不要提交非法参数。','window.close();'));
                //检测数据是否存在
		$row=$db->getrow("select * from ".Getdbname('dance')." where CS_ID=".$id."");
                if($row){
	            $favid=$db->getone("select cs_id from ".Getdbname('fav')." where cs_user='".$cscms_name."' and cs_did=".$id."");
	            if($favid) exit(Msg_Error('出错了，您已经收藏了该歌曲。','window.close();'));

				$db->query("update ".Getdbname('dance')." set CS_Shits=CS_Shits+1 where CS_ID=".$id."");
				//入库
				$sqlhya="insert into ".Getdbname('fav')." (CS_Name,CS_DID,CS_CID,CS_User,CS_Addtime) values ('".$row['CS_Name']."',".$id.",".$row['CS_CID'].",'".$cscms_name."','".date('Y-m-d H:i:s')."')";
				if($db->query($sqlhya)){

           //*********分享到腾讯微薄********//
             require_once("open/qq/common.php");
             $linkurl="http://".CS_WebUrl.LinkUrl('play','dance','id',$row['CS_CID'],$row['CS_ID']);
             $title="我刚刚在“".CS_WebName."”收藏了音乐[ ".$CS_Name." ]非常好听哦！ 感谢支持！";
             $ret = add_share($title,$linkurl,CS_WebName,CS_WebName);

				    //产生动态
				     $sqldt="insert into ".Getdbname('dt')." (CS_Title,CS_Did,CS_Cid,CS_User,CS_Addtime) values ('".$row['CS_Name']."',".$id.",2,'".$cscms_name."','".date('Y-m-d H:i:s')."')";
				     $db->query($sqldt);
				         exit(Msg_Error('恭喜您，收藏歌曲《<font color="red">'.$row['CS_Name'].'</font>》成功。','window.close();'));
				}else{
				         exit(Msg_Error('抱歉，收藏歌曲《<font color="red">'.$row['CS_Name'].'</font>》失败。','window.close();'));
				}
		}else{
                         exit(Msg_Error('出错了，你收藏的数据不存在。','window.close();'));
		}
}