<?php
# Name: PHP版程氏音乐CMS管理系统 v3.0
# Author: 程氏<web@chshcms.com> [QQ:848769359]
# Homepage:http://www.chshcms.cn/
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('QQ:848769359');}
include_once("../lib/cs_conn.php");
include_once("../lib/cs_common.php");
$ac=CS_Request('ac');
$op=CS_Request('op');
$id=CS_Request('id');
	$showstr="";
	global $db;

if($ac=="dt"){
     if(!isset($_COOKIE["cs_name"])) exit();
     if($id==1){
	$sql="select * from ".Getdbname('dt')." order by cs_id desc";
     }else{
	$sql="select * from ".Getdbname('dt')." where cs_user='".$_COOKIE["cs_name"]."' order by cs_id desc";
     }
	$rs=$db->query($sql);
	$num=$db->num_rows($rs);
	if($num==0) echo "<li>没有相关动态。</li>";
	$nums=30;
	if($num<$nums){
		$j=$num;
	}else{
		$j=$nums;
	}
	for($i=0;$i<$j;$i++){
		$row=$db->fetch_array($rs);
	     $showstr.='
                      <li>
                        <div class="avatar"><a href="'.userlink('index',getuser('uid',$row['CS_User'])).'" target="_blank"><img class="avatar-58" src="'.getuser('pic',$row['CS_User']).'"/></a></div>
                        <div class="feedContent">';
          if($row['CS_CID']==0){   
	     $showstr.='<!--微博动态-->
                          <div class="feedName"><img class="feedIcon" src="images/feed_miniblog.gif"> <a href="'.userlink('index',getuser('uid',$row['CS_User'])).'" target="_blank">'.getuser('nichen',$row['CS_User']).'</a> 更新了微博  (<a href="'.userlink('index',getuser('uid',$row['CS_User'])).'" target="_blank">查看</a>)</div>
                          <div class="line">
                          <div class="detail">
				'.$row['CS_User'].'说：'.facehtml(stripslashes(html_entity_decode($row['CS_Title']))).'  <span class="createTime">'.datetime($row['CS_AddTime']).'</span> (<a href="'.userlink('index',getuser('uid',$row['CS_User'])).'" target="_blank">评论</a>)
			  </div>
                          </div>
                          <!--微博动态结束-->';  
          }elseif($row['CS_CID']==1){
             $xc=$db->getrow("Select * from ".Getdbname('pic')." where CS_ID=".$row['CS_DID']."");
	     $showstr.='<!--相册动态-->
                          <div class="feedName"><img class="feedIcon" src="images/feed_album.gif"> <a href="'.userlink('index',getuser('uid',$row['CS_User'])).'" target="_blank">'.getuser('nichen',$row['CS_User']).'</a> 更新了相册  (<a href="'.userlink('pic',getuser('uid',$row['CS_User'])).'" target="_blank">'.$row['CS_Title'].'</a>)</div>
                                 <a href="'.userlink('pick',getuser('uid',$row['CS_User']),$row['CS_DID']).'" target="_blank"><img src="'.piclink('pic',$xc['CS_Pic']).'" title="'.$row['CS_Title'].'" class="summaryimg"></a>
                          <!--相册动态结束-->';
          }elseif($row['CS_CID']==2){
             $music=$db->getrow("Select * from ".Getdbname('dance')." where CS_ID=".$row['CS_DID']."");
	     $showstr.='<!--收藏动态-->
                          <div class="feedName"><img align="absmiddle" src="images/feed_favorites.gif"><a href="'.userlink('index',getuser('uid',$row['CS_User'])).'" target="_blank">'.getuser('nichen',$row['CS_User']).'</a>  收藏了歌曲 (<a href="'.LinkUrl('play','dance','id',$music['CS_CID'],$row['CS_DID']).'" target="_blank">'.$row['CS_Title'].'</a>)</div>
                          <div class="line">
                          <div class="detail">
				收藏了《'.$row['CS_Title'].'》 (<a href="'.LinkUrl('play','dance','id',$music['CS_CID'],$row['CS_DID']).'" target="p">试听</a>)  <span class="createTime">'.datetime($row['CS_AddTime']).'</span>
			  </div>
                          </div>
                          <!--收藏动态结束-->';
          }elseif($row['CS_CID']==3){
             $music=$db->getrow("Select * from ".Getdbname('dance')." where CS_ID=".$row['CS_DID']."");
	     $showstr.='<!--分享动态-->
                          <div class="feedName"><img align="absmiddle" src="images/feed_dance.gif"><a href="'.userlink('index',getuser('uid',$row['CS_User'])).'" target="_blank">'.getuser('nichen',$row['CS_User']).'</a>  分享了歌曲 (<a href="'.LinkUrl('play','dance','id',$music['CS_CID'],$row['CS_DID']).'" target="_blank">'.$row['CS_Title'].'</a>)</div>
                          <div class="line">
                          <div class="detail">
				分享了《'.$row['CS_Title'].'》 (<a href="'.LinkUrl('play','dance','id',$music['CS_CID'],$row['CS_DID']).'" target="p">试听</a>)  <span class="createTime">'.datetime($row['CS_AddTime']).'</span>
			  </div>
                          </div>
                          <!--分享动态结束-->';
          }elseif($row['CS_CID']==4){
             $topic=$db->getrow("Select * from ".Getdbname('topic')." where CS_ID=".$row['CS_DID']."");
	     $showstr.='<!--专集动态-->
                          <div class="feedName"><img align="absmiddle" src="images/feed_topic.gif"><a href="'.userlink('index',getuser('uid',$row['CS_User'])).'" target="_blank">'.getuser('nichen',$row['CS_User']).'</a>  制作了专集 (<a href="'.LinkUrl('show','zj','id',$topic['CS_CID'],$row['CS_DID']).'" target="_blank">'.$row['CS_Title'].'</a>)</div>
                          <div class="line">
                          <div class="detail">
				制作了专集《'.$row['CS_Title'].'》 (<a href="'.LinkUrl('show','zj','id',$topic['CS_CID'],$row['CS_DID']).'" target="p">查看</a>)  <span class="createTime">'.datetime($row['CS_AddTime']).'</span>
			  </div>
                          </div>
                          <!--专集动态结束-->';
          }elseif($row['CS_CID']==5){
             $topic=$db->getrow("Select * from ".Getdbname('news')." where CS_ID=".$row['CS_DID']."");
	     $showstr.='<!--文章动态-->
                          <div class="feedName"><img align="absmiddle" src="images/feed_news.gif"><a href="'.userlink('index',getuser('uid',$row['CS_User'])).'" target="_blank">'.getuser('nichen',$row['CS_User']).'</a>  发表了文章 (<a href="'.LinkUrl('show','news','id',$row['CS_CID'],$row['CS_ID']).'" target="_blank">'.$row['CS_Title'].'</a>)</div>
                          <div class="line">
                          <div class="detail">
				发表了文章《'.$row['CS_Title'].'》 (<a href="'.LinkUrl('show','news','id',$row['CS_CID'],$row['CS_ID']).'" target="p">查看</a>)  <span class="createTime">'.datetime($row['CS_AddTime']).'</span>
			  </div>
                          </div>
                          <!--文章动态结束-->';
          }elseif($row['CS_CID']==6){
             $topic=$db->getrow("Select * from ".Getdbname('dance')." where CS_ID=".$row['CS_DID']."");
	     $showstr.='<!--下载动态-->
                          <div class="feedName"><img align="absmiddle" src="images/feed_down.gif"><a href="'.userlink('index',getuser('uid',$row['CS_User'])).'" target="_blank">'.getuser('nichen',$row['CS_User']).'</a>  下载了歌曲 (<a href="'.LinkUrl('play','dance','id',$music['CS_CID'],$row['CS_DID']).'" target="_blank">'.$row['CS_Title'].'</a>)</div>
                          <div class="line">
                          <div class="detail">
				下载了歌曲《'.$row['CS_Title'].'》 (<a href="'.LinkUrl('play','dance','id',$music['CS_CID'],$row['CS_DID']).'" target="p">视听</a>)  <span class="createTime">'.datetime($row['CS_AddTime']).'</span>
			  </div>
                          </div>
                          <!--下载动态结束-->';
          }
	     $showstr.='<div class="more"><a href="'.userlink('index',getuser('uid',$row['CS_User'])).'" target="_blank">查看【'.$row['CS_User'].'】更多动态>></a></div>
                        </div>
                      </li>
	     ';
	}
  echo escape($showstr);

}elseif($ac=="weibo"){
     if(!isset($_COOKIE["cs_name"])) exit();
     $neir=CS_Request('neir');
     if(empty($neir)) exit('Err_100');
     if(strlen($neir)<5 || strlen($neir)>200) exit('Err_101');
     if(DateDiff($_SESSION['weibotime'],date("Y-m-d H:i:s"))<16) exit('Err_104');

	$sql="insert into ".Getdbname('blog')." (CS_User,CS_Neir,CS_AddTime) values ('".$_COOKIE["cs_name"]."','".$neir."','".date('Y-m-d H:i:s')."')";
	if($db->query($sql)){
                $_SESSION['weibotime']=date("Y-m-d H:i:s");
		//产生动态
		$sql="insert into ".Getdbname('dt')." (cs_user,cs_cid,cs_title,cs_addtime) values ('".$_COOKIE["cs_name"]."',0,'".$neir."','".date('Y-m-d H:i:s')."')";
		$db->query($sql);
             exit('Err_102');
        }else{
             exit('Err_103');
        }

}elseif($ac=="favdel"){
     if(!isset($_COOKIE["cs_name"])) exit('Err_101');
     if(empty($id)) exit('Err_101');
     if($db->query("delete from ".Getdbname('fav')." where cs_id=".$id." and cs_user='".$_COOKIE["cs_name"]."'")){
         $db->query("delete from ".Getdbname('dt')." where CS_did=".$id." and cs_cid=2 and cs_user='".$_COOKIE["cs_name"]."'");
         echo 'Err_100';
     }else{
         echo 'Err_101';
     }

}elseif($ac=="topicdel"){
     if(!isset($_COOKIE["cs_name"])) exit('Err_101');
     if(empty($id)) exit('Err_101');
     $musicnum=$db->getRow("select count(CS_ID) as rc from ".Getdbname('dance')." where CS_TID=".$id."");
     if($musicnum['rc']>0) exit('Err_102');
     $row=$db->getrow("Select * from ".Getdbname('topic')." where cs_id=".$id."");
     if($db->query("delete from ".Getdbname('topic')." where cs_id=".$id." and cs_user='".$_COOKIE["cs_name"]."'")){
         //删除专集图片
	 $fileurl="../annex/topic/".$row['CS_Pic'];
	 if(file_exists($fileurl)){
	   @unlink($fileurl);
	 }
         $db->query("delete from ".Getdbname('dt')." where CS_did=".$id." and cs_cid=4 and cs_user='".$_COOKIE["cs_name"]."'");
         echo 'Err_100';
     }else{
         echo 'Err_101';
     }

}elseif($ac=="picdel"){
     if(!isset($_COOKIE["cs_name"])) exit('Err_101');
     if(empty($id)) exit('Err_101');
     $picnum=$db->getRow("select count(CS_ID) as rc from ".Getdbname('photo')." where CS_CID=".$id."");
     if($picnum['rc']>0) exit('Err_102');
     $row=$db->getrow("Select * from ".Getdbname('pic')." where cs_id=".$id."");
     if($db->query("delete from ".Getdbname('pic')." where cs_id=".$id." and cs_user='".$_COOKIE["cs_name"]."'")){
        $db->query("delete from ".Getdbname('dt')." where CS_did=".$id." and and cs_cid=1 cs_user='".$_COOKIE["cs_name"]."'");
        //删除封面图片
	$fileurl="../annex/pic/".$row['CS_Pic'];
	if(file_exists($fileurl)){
	  @unlink($fileurl);
	}
         echo 'Err_100';
     }else{
         echo 'Err_101';
     }
}elseif($ac=="usermb"){
     if(!isset($_COOKIE["cs_name"])) exit('Err_101');
     if(empty($id)) exit('Err_101');
     if($db->query("update ".Getdbname('user')." set CS_Mbid='".$id."' where CS_Name='".$_COOKIE["cs_name"]."'")){
         echo 'Err_100';
     }else{
         echo 'Err_101';
     }
}elseif($ac=="delmsg"){
     if(!isset($_COOKIE["cs_name"])) exit('Err_101');
     if($db->query("delete from ".Getdbname('xiaoxi')." where cs_usera='".$_COOKIE["cs_name"]."'")){
         echo 'Err_100';
     }else{
         echo 'Err_101';
     }
}elseif($ac=="dumsg"){
     if(!isset($_COOKIE["cs_name"])) exit('Err_101');
     if($db->query("update ".Getdbname('xiaoxi')." set CS_DID=1 where CS_Usera='".$_COOKIE["cs_name"]."'")){
         echo 'Err_100';
     }else{
         echo 'Err_101';
     }
}elseif($ac=="gbook"){
     $neir=CS_Request('neir');
     if(!isset($_COOKIE["cs_name"])) exit('Err_101');
     if($op=="delhf"){
        if($db->query("delete from ".Getdbname('gbook')." where cs_id=".$id."")){
             echo 'Err_100';
        }else{
             echo 'Err_101';
        }
     }elseif($op=="del"){
        if($db->query("delete from ".Getdbname('gbook')." where cs_id=".$id." or cs_fid=".$id."")){
             echo 'Err_100';
        }else{
             echo 'Err_101';
        }
     }elseif($op=="hf"){
           $row=$db->getrow("Select * from ".Getdbname('gbook')." where cs_id=".$id."");
	   $sql="insert into ".Getdbname('gbook')." (cs_usera,cs_userb,cs_fid,cs_hfneir,cs_addtime) values ('".$row["CS_Userb"]."','".$row["CS_Usera"]."',".$row["CS_ID"].",'".$neir."','".date('Y-m-d H:i:s')."')";
	   if($db->query($sql)){
                echo 'Err_100';
           }else{
                echo 'Err_101';
           }
     }
}elseif($ac=="delfriend"){
     if(!isset($_COOKIE["cs_name"])) exit('Err_101');
     if($op=='hy'){
         $sql="delete from ".Getdbname('friend')." where cs_id=".$id."";
     }else{
         $sql="delete from ".Getdbname('fans')." where cs_id=".$id."";
     }
     if($db->query($sql)){
         echo 'Err_100';
     }else{
         echo 'Err_101';
     }
}elseif($ac=="delnews"){
     if(!isset($_COOKIE["cs_name"])) exit('Err_101');
     $sql="delete from ".Getdbname('news')." where cs_id=".$id." and CS_User='".$_COOKIE["cs_name"]."'";
     if($db->query($sql)){
        $db->query("delete from ".Getdbname('dt')." where CS_did=".$id." and cs_cid=5 and cs_user='".$_COOKIE["cs_name"]."'");
         echo 'Err_100';
     }else{
         echo 'Err_101';
     }
}elseif($ac=="delpay"){
     if(!isset($_COOKIE["cs_name"])) exit('Err_101');
     $sql="delete from ".Getdbname('pay')." where cs_id=".$id." and CS_User='".$_COOKIE["cs_name"]."'";
     if($db->query($sql)){
         echo 'Err_100';
     }else{
         echo 'Err_101';
     }
}