<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Dance extends CI_Controller {

	function __construct(){
		    parent::__construct();
        	$this->load->helper('url');
        	$this->load->helper('form');
            $this->load->library('session'); //加载session
		    $this->load->model('CsdjDB');
		    $this->load->model('CsdjSkins');
		    $this->load->model('CsdjDance');
		    $this->load->model('CsdjCache');
	}

        //歌曲主页
	public function index()
	{
            //判断运行模式
            $cscms=$this->input->get('cs', TRUE);
	        if(Web_Mode==3 && $cscms!="html"){ 
                    header("Location: ".str_replace('//','/',Web_Path.Html_Dindex).""); 
                    exit;
            }

	        $cache_id ="dance_index";
	        if(!($this->CsdjCache->start($cache_id))){
                echo $this->CsdjDance->index();
		        $this->CsdjCache->end();
			}
	}

    //分类列表
	public function lists()
	{
            $fid = $this->uri->segment(3);   //方式
            $id = intval($this->uri->segment(4));   //ID
            $page  = intval($this->uri->segment(5));   //页数
            if($page==0) $page=1;
                
            if($id==0){
                exit($this->CsdjSkins->Msg_url('出错了，ID不能为空！',Web_Path));
            }

            //判断运行模式
            $cscms=$this->security->xss_clean($this->input->get('cs', TRUE));
	        if(Web_Mode==3 && $cscms!="html"){ 
                    $Htmllink=$this->CsdjSkins->LinkUrl('lists','dance',$fid,$id,$page);
                    header("Location: ".$Htmllink.""); 
                    exit;
            }

            $aliasname="";
		    $row=$this->CsdjDB->get_select ('class','CS_ID','*',''.$id.'');
		    if(!$row){
                    $aliasname=$id;
                    $row=$this->CsdjDB->get_select ('class','CS_AliasName','*',''.$id.'');
                    if(!$row){
                           exit($this->CsdjSkins->Msg_url('出错了，该分类不存在！',Web_Path));
                    }
			}
            if($row[0]->CS_SID>1){
                     exit($this->CsdjSkins->Msg_url('出错了，该分类不存在！',Web_Path));
            }

	        $cache_id ="dance_list_".$fid."_".$id."_".$page;
	        if(!($this->CsdjCache->start($cache_id))){
                echo $this->CsdjDance->lists($fid,$id,$page,$row,$aliasname);
			    $this->CsdjCache->end();
			}
	}

    //搜索列表
	public function so()
	{

            $data='';$data_content='';
            $fid = $this->uri->segment(3);   //方式
            $key = $this->input->get_post('key');   //关键字
            $page  = intval($this->input->get('p', TRUE));   //页数
            if($page==0) $page=1;
            if($fid=='zm' && empty($key)){
                 $key=$this->uri->segment(4); 
            }

	        $key = $this->CsdjSkins->safe_replace(trim($key));
	        $key = htmlspecialchars(strip_tags($key));
	        $key = str_replace('%', '', $key);	//过滤'%'，用户全文搜索
            $key=$this->CsdjSkins->rurlencode($key);

	        $cache_id ="dance_so_".$fid."_".$key."_".$page;
	        if(!($this->CsdjCache->start($cache_id))){


                $CS_Template='so-dance-'.$fid.'.html';

                $this->load->get_templates();
		        $template=$this->load->view($CS_Template,$data,true);

		        $Mark_Text=$this->CsdjSkins->TopandBottom($template);
		        $Mark_Text=str_replace("{cscms:sokey}",$key,$Mark_Text);
                if($fid=='zm'){
		             $Mark_Text=str_replace("{cscms:title}","搜索字母".$key." - ".Web_Name,$Mark_Text);
                }elseif($fid=='tags'){
		             $Mark_Text=str_replace("{cscms:title}","搜索标签".$key." - ".Web_Name,$Mark_Text);
                }else{
		             $Mark_Text=str_replace("{cscms:title}","搜索关键词".$key." - ".Web_Name,$Mark_Text);
                }
		        $Mark_Text=str_replace("{cscms:keywords}",$key,$Mark_Text);
		        $Mark_Text=str_replace("{cscms:description}",stripslashes(html_entity_decode(Web_Description)),$Mark_Text);

		        //预先除了分页
		        $pagenum=$this->CsdjSkins->GetPageNum($Mark_Text);
		        preg_match_all('/{cscms:dance(.*?pagesize=([\S]+).*?)}([\s\S]+?){\/cscms:dance}/',$Mark_Text,$page_arr);//判断是否有分页标识
		        if(!empty($page_arr) && !empty($page_arr[2])){

			        $zimu_arr=array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z');
			        $zimu_arr1=array(-20319,-20283,-19775,-19218,-18710,-18526,-18239,-17922,-1,-17417,-16474,-16212,-15640,-15165,-14922,-14914,-14630,-14149,-14090,-13318,-1,-1,-12838,-12556,-11847,-11055);
			        $zimu_arr2=array(-20284,-19776,-19219,-18711  ,-18527,-18240,-17923,-17418,-1,-16475,-16213,-15641,-15166,-14923,-14915,-14631,-14150,-14091,-13319,-12839,-1,-1,-12557,-11848,-11056,-2050);
                
		           if($fid=='zm' && in_array(strtoupper($key),$zimu_arr)){  //按字母搜索
			        $posarr=array_keys($zimu_arr,strtoupper($key));
			        $pos=$posarr[0];
			        $sqlstr="SELECT * FROM ".CS_SqlPrefix."dance where CS_HID=0 and CS_YID=0 and (((ord( substring( CS_Name, 1, 1 ) ) -65536>=".($zimu_arr1[$pos])." and  ord( substring( CS_Name, 1, 1 ) ) -65536<=".($zimu_arr2[$pos]).")) or UPPER(substring( CS_Name, 1, 1 ))='".$zimu_arr[$pos]."')";
		           }elseif($fid=='tags'){
                        $sqlstr="select * from ".CS_SqlPrefix."dance where CS_HID=0 and CS_YID=0 and CS_Tags like '%".$key."%'  order by CS_AddTime desc";
		           }else{
                        $sqlstr="select * from ".CS_SqlPrefix."dance where CS_HID=0 and CS_YID=0 and (CS_Tags like '%".$key."%' or CS_Name like '%".$key."%' or CS_Singer like '%".$key."%' or CS_Year like '%".$key."%')  order by CS_AddTime desc";
                   }

			       $Arr=$this->CsdjSkins->SpanPage($sqlstr,$page_arr[2][0],$pagenum,'so','dance',$fid,urlencode($key),1,$page);//sql,每页显示条数
			       $result=$this->CsdjDB->db->query($Arr[2]);
			       $recount=$result->num_rows();
			       if($recount==0){
				       $data_content.="<div align=center><a href=http://www.27meng.com/gbook target='so'><strong>对不起,《<font color=#FF0000>".$key."</font>》标签下没有数据,去求歌留言吧!</strong></a></div>";
			       }else{
				       if($result){
					       $sorti=1;
					       foreach ($result->result() as $row2) {
						       $datatmp=$this->CsdjSkins->DataDance($page_arr[0][0],$page_arr[3][0],$row2,$sorti);
						       $sorti=$sorti+1;
						       $data_content.=$datatmp;
					       }
				       }
			       }// end if recount
			       $Mark_Text=$this->CsdjSkins->Page_Mark($Mark_Text,$Arr);	
			       $Mark_Text=str_replace($page_arr[0][0],$data_content,$Mark_Text);
			       unset($Arr);
                }
		        unset($page_arr);
		        $this->CsdjSkins->skins($Mark_Text,$data);
		        $this->CsdjCache->end();
			}
	}

    //单曲播放页面
	public function play()
	{
            $fid = $this->uri->segment(3);   //方式
            $id = intval($this->uri->segment(4));   //ID
                
            if($id==0){
                exit($this->CsdjSkins->Msg_url('出错了，ID不能为空！',Web_Path));
            }

            //判断运行模式
            $cscms=$this->security->xss_clean($this->input->get('cs', TRUE));
	        if(Web_Mode==3 && $cscms!="html"){
                    $Htmllink=$this->CsdjSkins->LinkUrl('play','dance',$fid,$id,$id);
                    header("Location: ".$Htmllink.""); 
                    exit;
            }

		    $row=$this->CsdjDB->get_select ('dance','CS_ID','*',''.$id.'');
		    if(!$row){
                exit($this->CsdjSkins->Msg_url('抱歉，该歌曲本站还没有收录！',Web_Path));
		    }
            if($row[0]->CS_YID==1 && $cscms!="html"){
                exit($this->CsdjSkins->Msg_url('抱歉，该歌曲版权问题已经下线！',Web_Path));
            }

	        $cache_id ="play_".$id;
	        if(!($this->CsdjCache->start($cache_id))){
                echo $this->CsdjDance->play($fid,$id,$row);
			    $this->CsdjCache->end();
			}
	}

    //歌曲联播页面
	public function playsong()
	{
            $ids=$this->input->get('id',true);

            if(empty($ids)){
                $sqlstr="select CS_ID from ".CS_SqlPrefix."dance where CS_YID=0 and CS_HID=0 order by rand() desc LIMIT 0,30";
		        $result=$this->CsdjDB->db->query($sqlstr);
		        $recount=$result->num_rows();
                if($recount>0){
			            foreach ($result->result() as $row) {
                            $ids.=$row->CS_ID.",";
                        }
                }
            }
            if(substr($ids,-1)==",") $ids=substr($ids,0,-1);
            $this->load->get_templates();
		    $template=$this->load->view('dance-playsong.html','',true);
		    $Mark_Text=str_replace("{cscms:title}","歌曲联播 - ".Web_Name,$template);
		    $Mark_Text=str_replace("{cscms:keywords}",stripslashes(html_entity_decode(Web_Keywords)),$Mark_Text);
		    $Mark_Text=str_replace("{cscms:description}",stripslashes(html_entity_decode(Web_Description)),$Mark_Text);
		    $Mark_Text=str_replace("{cscms:lbid}",$ids,$Mark_Text);
		    $Mark_Text=str_replace("{cscms:lbjsurl}",site_url('dance/song_url').'?id='.$ids,$Mark_Text);
		    $this->CsdjSkins->skins($Mark_Text,'');
	}

    //单曲下载页面
	public function down()
	{
            $data='';$data_content='';
            $fid = $this->uri->segment(3);   //方式
            $id = intval($this->uri->segment(4));   //ID
                
            if($id==0){
                exit($this->CsdjSkins->Msg_url('出错了，ID不能为空！',Web_Path));
            }

	        $cache_id ="down_".$id;
	        if(!($this->CsdjCache->start($cache_id))){

		        $row=$this->CsdjDB->get_select ('dance','CS_ID','*',''.$id.'');
		        if(!$row){
                	$this->load->get_templates();
			        $this->load->view('cs-404.html',$data);
                    exit;
		        }
                if($row[0]->CS_YID==1){
                    exit($this->CsdjSkins->Msg_url('抱歉，该歌曲版权问题已经下线！',Web_Path));
                }

                $CS_Template='dance-down.html';
                $this->load->get_templates();
		        $template=$this->load->view($CS_Template,$data,true);

        	    //SEO标题
        	    if (empty($row[0]->CS_Title)){
               		$seo_title=$row[0]->CS_Name."下载 - ".Web_Name;
        	    }else{
               		$seo_title=$row[0]->CS_Title;
        	    }
        	    //SEO关键词
        	    if (empty($row[0]->CS_Keywords)){
               		$seo_keywords=$row[0]->CS_Name."试听,下载";
        	    }else{
              		$seo_keywords=$row[0]->CS_Keywords;
        	    }
        	    //SEO描述
        	    if (empty($row[0]->CS_Description)){
               		$seo_description=$row[0]->CS_Name." 是由".Web_Name."提供试听和下载。";
        	    }else{
               		$seo_description=$row[0]->CS_Description;
        	    }

		        $Mark_Text=str_replace("{cscms:title}",$seo_title,$template);
		        $Mark_Text=str_replace("{cscms:keywords}",$seo_keywords,$Mark_Text);
		        $Mark_Text=str_replace("{cscms:description}",$seo_description,$Mark_Text);
                if(Web_Mode==2){
		            $Mark_Text=str_replace("[dance:plink]",Web_Path."dance/download/p/1/".$id,$Mark_Text);
		            $Mark_Text=str_replace("[dance:pxlink]",Web_Path."dance/download/p/2/".$id,$Mark_Text);
		            $Mark_Text=str_replace("[dance:dlink]",Web_Path."dance/download/d/1/".$id,$Mark_Text);
		            $Mark_Text=str_replace("[dance:dxlink]",Web_Path."dance/download/d/2/".$id,$Mark_Text);
                }else{
		            $Mark_Text=str_replace("[dance:plink]",site_url("dance/download/p/1/".$id),$Mark_Text);
		            $Mark_Text=str_replace("[dance:pxlink]",site_url("dance/download/p/2/".$id),$Mark_Text);
		            $Mark_Text=str_replace("[dance:dlink]",site_url("dance/download/d/1/".$id),$Mark_Text);
		            $Mark_Text=str_replace("[dance:dxlink]",site_url("dance/download/d/2/".$id),$Mark_Text);
                }
		        $Mark_Text=$this->CsdjSkins->Common_Mark($Mark_Text,$id);
		        $Mark_Text=$this->CsdjSkins->DataDance($Mark_Text,$Mark_Text,$row[0],'1'); //全部解析
		        $this->CsdjSkins->skins($Mark_Text,$data);
		        $this->CsdjCache->end();
			}
	}

    //数据下载页面
	public function download()
	{
            header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); 
            header("Cache-Control: no-cache, must-revalidate"); 
            header("Pragma: no-cache");
		    $this->load->model('CsdjUser');

            $sid = $this->uri->segment(3);   //方式,试听，下载
            $type = intval($this->uri->segment(4));   //类型，普通，讯雷
            $id = intval($this->uri->segment(5));   //ID

            if(empty($sid)) $sid=='d';
            if(empty($type)) $type==1;

            if($id==0){
                exit($this->CsdjSkins->Msg_url('出错了，ID不能为空！',Web_Path));
            }

		    if($this->session->userdata('cs_id')){
                 $uid=$this->session->userdata('cs_id');
            }else{
                 $uid=0;
            }
		    if($this->session->userdata('cs_name')){
                 $user=$this->session->userdata('cs_name');
            }else{
                 $user='';
            }

		    if(!$this->CsdjUser->User_Login(1)){
                 exit($this->CsdjSkins->Msg_url('出错了，请先登入后在下载！',site_url("user/login")));
            }else{
		         $rowu=$this->CsdjDB->get_select('user','CS_ID','CS_Vip,CS_Cion',$uid);
                 $vip=$rowu[0]->CS_Vip;
                 $cion=$rowu[0]->CS_Cion;
            }

		    $row=$this->CsdjDB->get_select('dance','CS_ID','*',''.$id.'');
		    if(!$row){
                exit($this->CsdjSkins->Msg_url('抱歉，该歌曲本站还没有收录！',Web_Path));
		    }
            if($row[0]->CS_YID==1){
                exit($this->CsdjSkins->Msg_url('抱歉，该歌曲版权问题已经下线！',Web_Path));
            }

            $name=$row[0]->CS_Name;
            $cid=$row[0]->CS_CID;
            $djuser=$row[0]->CS_User;
            $scion=$row[0]->CS_Scion;
            $purl=$row[0]->CS_PlayUrl;
            $durl=$durls=$row[0]->CS_DownUrl1;
            $durl2=$durl2s=$row[0]->CS_DownUrl2;
            $fid=$row[0]->CS_FID;
            $dancehz=substr($durl,-4);

            if(FTP_Fun==1 && $row[0]->CS_FID==0){  //远程附件
                    $purl=FTP_Url.$row[0]->CS_PlayUrl;
                    $durl=FTP_Url.$row[0]->CS_DownUrl1;
            }else{
                    $purl=$this->CsdjSkins->playqurl($row[0]->CS_PlayUrl,$row[0]->CS_FID,1);
                    $durl=$this->CsdjSkins->playqurl($row[0]->CS_DownUrl1,$row[0]->CS_FID,2);
            }

	        $rowd=$this->db->query("SELECT CS_ID FROM ".CS_SqlPrefix."down where cs_did='".$id."' and cs_user='".$user."'")->row(); 

            //判断下载时间、低音质不判断
		    if(($sid=='d' && $row[0]->CS_Cion>0) || $row[0]->CS_Vip>0){ 
 
                    //判断级别
                    if($row[0]->CS_Vip>$vip){
                          exit($this->CsdjSkins->Msg_url('抱歉，您的级别不够下载该首歌曲，请先升级！',site_url("user/pay/vip/")));
                    }

                    //判断级别权限
                    if($vip>0){
                        $sqlz="SELECT * FROM ".CS_SqlPrefix."userzu where cs_id=".$vip."";
		                $rowz=$this->CsdjDB->get_all($sqlz);
		                if(!$rowz){
                             exit($this->CsdjSkins->Msg_url('出错了，该会员组不存在！',site_url("user/pay/vip")));
                        }else{
                             if($this->CsdjSkins->Getqx('dance_'.$cid,$rowz[0]->CS_Quanx)!='ok'){
                                  exit($this->CsdjSkins->Msg_url('抱歉，您所在的会员组不能下载该分类歌曲！',site_url("user/pay/vip")));
                             }
                        }
                    }

                    //扣除点数,VIP会员跳过
                    if($vip==0){
                        $downtime=3600*User_Downtime+strtotime($rowd->CS_AddTime);
		                if(!$rowd || $downtime<time()){
                           //判断点数
                           if($row[0]->CS_Cion>$cion){
                                 exit($this->CsdjSkins->Msg_url('抱歉，您的点数不够下载该首歌曲，请先充值！',site_url("user/pay/")));
                           }
		                   $us['CS_Cion'] = $cion-$row[0]->CS_Cion;
                           $this->CsdjDB->get_update ('user',$uid,$us);
		                   $downsj['down_'.$id.'_time']=date("Y-m-d H:i:s");
                           $this->session->set_userdata($downsj);
						}
                    }

                    //判断是否分成
                    if(User_DownFun==1 && $vip==0){
                         if($scion==0){
                             $fcbl=User_Downcion/100;
                             $scion=intval($row[0]->CS_Cion*$fcbl);
                         }
                         //分成点数
		                 $djuid    = $this->CsdjSkins->getuser('id','',$djuser);	
		                 $fc['CS_Cion']    = $this->CsdjSkins->getuser('cion','',$djuser)+$scion;
                         $this->CsdjDB->get_update('user',$djuid,$fc); 
                    }
			}

		    if($user && !$rowd){ //没有此歌曲记录
                    if(empty($row[0]->CS_Cion)) $row[0]->CS_Cion=0;
                    //写入下载记录
		            $down['CS_User']    = $user;
		            $down['CS_CID']     = $cid;	
		            $down['CS_DID']     = $id;
		            $down['CS_Ip']      = $this->CsdjSkins->GetIP();
                    if($vip==0){
		                $down['CS_Cion']    = $row[0]->CS_Cion;
                    }
		            $down['CS_Name']    = $name;
		            $down['CS_AddTime'] = date('Y-m-d H:i:s');
		            $this->CsdjDB->get_insert ('down',$down);

                    //写入动态
                    $dt['CS_CID']=7;
                    $dt['CS_DID']=$id;
                    $dt['CS_YID']=0;
                    $dt['CS_User']=$this->session->userdata('cs_name');
                    $dt['CS_Title']=$name;
                    $dt['CS_AddTime']=date('Y-m-d H:i:s');
                    $this->CsdjDB->get_insert('dt',$dt);
			}

            //增加下载次数	
		    $dance['CS_Xhits']    = $row[0]->CS_Xhits+21;
            $this->CsdjDB->get_update ('dance',$id,$dance);

            if(empty($durl)){
			    $durl=$durl2;  //当下载地址为空时，启用备用下载地址
			    $durls=$durl2s;
	        }
            if($sid=='p') $durl=$purl;  //下载低音质

            if($type==2){     //讯雷下载
                    //讯雷下载开始
                    if(substr($durl,0,7)!="http://") $durl="http://".Web_Url.Web_Path.$durl;
                    $DownUrl=base64_encode("AA".$durl."ZZ");
                    $thunderUrl="thunder://".$DownUrl;
                    $thunderID=User_thunderID;  //这个是讯雷联盟ID号

                    echo "<script src='http://pstatic.xunlei.com/js/webThunderDetect.js'></script>";
                    echo "<script>OnDownloadClick('".$thunderUrl."','',location.href,'".$thunderID."',false)</script>";
                    exit();

			}

		    $durl=str_replace("\\","",$durl);
            //判断开启物理路径
            if(User_DirFun==1){
                    if (!file_exists(User_Dirpath.$durls)){
                         header("Location: ".$durl); //连接下载
                         exit();
                    }else{

                         $this->load->helper('download');
                         $data = file_get_contents(User_Dirpath.$durls); // 读文件内容
                         force_download($name.$dancehz, $data);  //下载

                     }

			}else{
                    header("Location: ".$durl);
                    die();
			}
	}

    //增加人气
	public function hits()
	{
           $ac = $this->uri->segment(3);   //方式

           if($ac=='id'){
                $id = intval($this->uri->segment(4));   //ID
		        $row=$this->CsdjDB->get_select ('dance','CS_ID','CS_Rhits,CS_Zhits,CS_Yhits,CS_Hits,CS_PlayTime',''.$id.'');
		        if(!$row){
			        show_404();
		        }
                //增加舞曲播放人气
                $daytime =$this->CsdjSkins->DateBj("d",$row[0]->CS_PlayTime,date('Y-m-d H:i:s'));
	            if($daytime==0){
	                 $updata['CS_Rhits']=$row[0]->CS_Rhits+113;
	            }else{
	                 $updata['CS_Rhits']=1;
	            }
	            if($daytime < 7){
	                 $updata['CS_Zhits']=$row[0]->CS_Zhits+113;
	            }else{
	                 $updata['CS_Zhits']=1;
	            }
	            if($daytime <31){
	                 $updata['CS_Yhits']=$row[0]->CS_Yhits+113;
	            }else{
	                 $updata['CS_Yhits']=1;
	            }
	            $updata['CS_Hits']=$row[0]->CS_Hits+113;
	            $updata['CS_PlayTime']=date('Y-m-d H:i:s');
                $this->CsdjDB->get_update ('dance',$id,$updata);

           }elseif($ac=='dt'){   //静态模式、动态人气

                $op = $this->uri->segment(4);   //类型
                $id = intval($this->uri->segment(5));   //ID
		        $row=$this->CsdjDB->get_select ('dance','CS_ID','CS_Xhits,CS_Shits,CS_Dhits,CS_Chits,CS_Rhits,CS_Zhits,CS_Yhits,CS_Hits',''.$id.'');
		        if(!$row){
			         show_404();
		        }

                if($op=='yhits'){
                      echo "document.write('".$row[0]->CS_Yhits."');";
                }elseif($op=='zhits'){
                      echo "document.write('".$row[0]->CS_Zhits."');";
                }elseif($op=='rhits'){
                      echo "document.write('".$row[0]->CS_Rhits."');";
                }elseif($op=='dhits'){
                      echo "document.write('".$row[0]->CS_Dhits."');";
                }elseif($op=='chits'){
                      echo "document.write('".$row[0]->CS_Chits."');";
                }elseif($op=='shits'){
                      echo "document.write('".$row[0]->CS_Shits."');";
                }elseif($op=='xhits'){
                      echo "document.write('".$row[0]->CS_Xhits."');";
                }else{
                      echo "document.write('".$row[0]->CS_Hits."');";
                }
           }
	}

    //播放器
	public function player()
	{
            @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');}

            $id = intval($this->uri->segment(3));   //ID
		    $row=$this->CsdjDB->get_select ('dance','CS_ID','CS_FID,CS_PID,CS_PlayUrl',$id);
		    if(!$row){
			    show_404();
		    }
            $pid=$row[0]->CS_PID;
			if(substr($row[0]->CS_PlayUrl,0,7)=='http://'){
                    $purl=$row[0]->CS_PlayUrl;
            }elseif(FTP_Fun==1 && $row[0]->CS_FID==0){  //远程附件
                    $purl=FTP_Url.$row[0]->CS_PlayUrl;
            }else{
                    $purl=$this->CsdjSkins->playqurl($row[0]->CS_PlayUrl,$row[0]->CS_FID);
            }
            if($pid==2){  //WMA播放器
                     echo '
	                   document.writeln("<object id=\"MediaPlayer\" width=\"'.CS_Play_w.'\" height=\"'.CS_Play_h.'\" classid=\"clsid:6BF52A52-394A-11d3-B153-00C04F79FAA6\" type=\"application/x-ms-wmp\">");
	                   document.writeln("<param name=\"AutoStart\" value=\"1\" />");
	                   document.writeln("<param name=\"PlayCount\" value=\"1\" />");
	                   document.writeln("<param name=\"EnableContextMenu\" value=\"1\" />");
	                   document.writeln("<param name=\"Volume\" value=\"100\" />");
	                   document.writeln("<param name=\"url\" value=\"'.$purl.'\">");
	                   document.writeln("<embed src=\"'.$purl.'\" name=\"MediaPlayer\" type=\"video/x-ms-wmv\" width=\"'.CS_Play_w.'\" height=\"'.CS_Play_h.'\" autostart=\"1\" showcontrols=\"1\" allowscan=\"1\" playcount=\"1\" enablecontextmenu=\"0\"></embed>");
	                   document.writeln("</object>");';
			}elseif($pid==1){  //Flash MP3 MP4等所有音频
                     echo 'jwplayer("mediaplayer").setup({
                                     width: "'.CS_Play_w.'",
                                     height: "'.CS_Play_h.'",
                                     file: "'.$purl.'",
                                     flashplayer: "'.Web_Path.'csdj/player/jwplayer/player.swf",
                                     autostart: "true",
			                         repeat:"always",
			                         showdownload:false,
			                         showicons:false,
			                         controlbar: "bottom"
                           });';
			}else{    //CMP
                     echo 'document.writeln("<object id=\"cmp_BSTbSL\" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" width=\"'.CS_Play_w.'\" height=\"'.CS_Play_h.'\">");
	                 document.writeln("<param name=\"movie\" value=\"'.Web_Path.'csdj/player/cmp/cmp.swf?lists='.Web_Path.'index.php/dance/cmpurl?id='.$id.'&amp;bgcolor=ffffff&amp;context_menu=0&amp;skin_id=1&amp;skins=cscms.jpg&amp;auto_play=1&amp;play_mode=1&amp;play_id=1\" />");
	                 document.writeln("<param name=\"allowScriptAccess\" value=\"always\" />");
	                 document.writeln("<param name=\"allowFullScreen\" value=\"true\" />");
	                 document.writeln("<param name=\"wmode\" value=\"opaque\">");
	                 document.writeln("<embed wmode=\"opaque\" name=\"cmp_gz4V55\" type=\"application/x-shockwave-flash\" width=\"'.CS_Play_w.'\" height=\"'.CS_Play_h.'\" src=\"'.Web_Path.'csdj/player/cmp/cmp.swf?lists='.Web_Path.'index.php/dance/cmpurl?id='.$id.'&amp;bgcolor=ffffff&amp;context_menu=0&amp;skin_id=1&amp;skins=cscms.jpg&amp;auto_play=1&amp;play_mode=1\" allowScriptAccess=\"always\" allowfullscreen=\"true\"></embed>");
	                 document.writeln("<\/object>");';
			}
            echo 'SetCookie("open_player", "Y", null, "/", DomainUrl,false);';
	}

    //联播
	public function song_url()
	{
                @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');}
                $ids=$this->input->get('id',TRUE);
                $Arr=explode(',',$ids);
                $mp3list=$mp3url='';
                for($j=0;$j<count($Arr);$j++){
	               $row=$this->db->query("SELECT CS_Name,CS_FID,CS_PlayUrl FROM ".CS_SqlPrefix."dance where cs_hid=0 and cs_yid=0 and cs_id='".intval($Arr[$j])."'")->row();
                       if($row){
			                if(substr($row->CS_PlayUrl,0,7)=='http://'){
                                $purl=$row->CS_PlayUrl;
                            }elseif(FTP_Fun==1 && $row->CS_FID==0){  //远程附件
                                $purl=FTP_Url.$row->CS_PlayUrl;
                            }else{
                                $purl=$this->CsdjSkins->playqurl($row->CS_PlayUrl,$row->CS_FID);
                            }
                            $mp3url.='mp3list['.$j.']={file:"'.$purl.'",title:"'.$row->CS_Name.'",id:"'.$j.'"};
                                     ';
                            $mp3list.='<li id="list_'.$j.'"><a href="javascript:;" onclick="playsong('.$j.');">'.($j+1).'.'.$row->CS_Name.'</a><span><a href="'.site_url("user/fav/add/".$Arr[$j]).'" target="fav" title="收藏">收藏</a></span><span><a href="'.site_url("dance/down/id/".$Arr[$j]).'" target="fav" title="下载">下载</a></span></li>';
                       }
                }
                echo '
                       document.getElementById("play_list").innerHTML=\''.$mp3list.'\';
                                   var is=0;
		                   var mp3list=new Array();
                                   '.$mp3url.'
                                   jwplayer("mediaplayer").setup({
                                                        width: "100%",
                                                        height: "24",
                                                        //file:mp3list[is].file,
			                                playlist:mp3list,
                                                        flashplayer: "'.Web_Path.'csdj/player/jwplayer/player.swf",
                                                        autostart: "true",
			                                repeat:"always",
			                                showdownload:false,
			                                showicons:false,
			                                controlbar: "bottom",
			                                events:{
				                                onPlaylistItem:function(event){
                                                                        var list=jwplayer().getPlaylistItem();
                                                                        document.getElementById("list_"+is).className="";
                                                                        is=list.id;
                                                                        document.getElementById("list_"+is).className="on";
					                                document.getElementById("ptitle").innerHTML="正在播放："+list.title;
				                                },
				                                onBuffer:function(event){
                                                                        var list=jwplayer().getPlaylistItem();
                                                                        document.getElementById("list_"+is).className="";
                                                                        is=list.id;
                                                                        document.getElementById("list_"+is).className="on";
                                                                        document.getElementById("ptitle").innerHTML="正在缓冲："+list.title;
				                                },
				                                onPlay:function(event){
                                                                        var list=jwplayer().getPlaylistItem();
                                                                        is=list.id;
                                                                        document.getElementById("list_"+is).className="on";
                                                                        document.getElementById("ptitle").innerHTML="正在播放："+list.title;
				                                },
				                                onPause:function(event){
                                                                        var list=jwplayer().getPlaylistItem();
                                                                        is=list.id;
                                                                        document.getElementById("list_"+is).className="on";
                                                                        document.getElementById("ptitle").innerHTML="正在暂停："+list.title;
				                                },
				                                onComplete:function(){ //播放完毕
                                                                        var list=jwplayer().getPlaylistItem();
                                                                        is=list.id;
                                                                        document.getElementById("list_"+is).className="no";
                                                                        document.getElementById("ptitle").innerHTML="正在播放："+list.title;
				                                }
			                                }
                                   });
	                    function playsong(id){
                                       document.getElementById("list_"+is).className="";
                                       is=id;
                                       document.getElementById("list_"+id).className="on";
			               mp3list[0]=mp3list[id];
			               jwplayer("mediaplayer").load(mp3list);
                            }
                ';
	}

    //主页播放器歌曲
	public function real()
	{
            @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');}
	        $sql_string = "SELECT CS_ID,CS_Name,CS_FID,CS_PlayUrl FROM ".CS_SqlPrefix."dance where cs_yid=0 and cs_reco=5 order by CS_AddTime desc limit 100";
	        $query = $this->db->query($sql_string); 
            foreach ($query->result() as $row) { 
                    if(substr($row->CS_PlayUrl,0,7)=='http://'){
                            $Playurl=$row->CS_PlayUrl;
                    }elseif(FTP_Fun==1 && $row->CS_FID==0){  //远程附件
                            $Playurl=FTP_Url.$row->CS_PlayUrl;
                    }else{
                            $Playurl=$this->CsdjSkins->playqurl($row->CS_PlayUrl,$row->CS_FID);
                    }
                    echo 'DATA("'.$row->CS_Name.'", "'.$Playurl.'","'.$row->CS_ID.'");';
			}
	}

    //CMPURL
	public function cmpurl()
	{
            @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');}
            $id = intval($this->input->get('id',TRUE));   //方式
                
            if($id==0){
                exit();
            }
            $sql="SELECT CS_FID,CS_PlayUrl,CS_Name FROM ".CS_SqlPrefix."dance where cs_id='".$id."' and cs_hid=0 and cs_yid=0";
	        $row=$this->db->query($sql)->row();
	        if($row){
			        if(substr($row->CS_PlayUrl,0,7)=='http://'){
                            $Playurl=$row->CS_PlayUrl;
                    }elseif(FTP_Fun==1 && $row->CS_FID==0){  //远程附件
                            $Playurl=FTP_Url.$row->CS_PlayUrl;
                    }else{
                            $Playurl=$this->CsdjSkins->playqurl($row->CS_PlayUrl,$row->CS_FID);
                    }
                    echo '<list><m type="" src="'.$Playurl.'" lrc="" label="'.$row->CS_Name.'" opened="1"></m></list>';
            }
	}
}