<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
@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');}
class Url 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');
	}

        //单页
	public function play()
	{
            $id = $this->security->xss_clean($this->uri->segment(3));   //方式
                
            if(empty($id)){
                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(FTP_Fun==0){  //远程附件
                            $Playurl=FTP_Url.$row->CS_PlayUrl;
                    }else{
                            $Playurl=$this->CsdjSkins->playqurl($row->CS_PlayUrl,$row->CS_FID);
                    }
                    if(strtolower(substr($Playurl,-3))=='m4a'){
                           $type='m4a';
                    }else{
                           $type='mp3';
                    }
                    echo '
                         var firstplay="'.$Playurl.'";
                         var psid=document.getElementById("psid").value;
                         $(document).ready(function(){
	                         $("#c6Player").jPlayer({
		                         ready:function (event){
			                         $(this).jPlayer("setMedia",{"'.$type.'":firstplay}).jPlayer("play");
		                         },
		                         supplied: "m4a,mp3",
		                         swfPath: "/skins/js/jp",
		                         wmode: "window",
		                         volume: 1,
		                         ended: function() {
                                              if(psid==2 && nextlink){
                                                 window.location.href = nextlink;
                                              }else{
                                                 $(this).jPlayer("play"); 
                                              }
                                         }
	                         });
                         });

                    ';
            }
	}

        //联播
	public function playsong()
	{
            $id = $this->security->xss_clean($this->input->get('id', TRUE));   //方式
                
            if(empty($id)){
                exit();
            }
            $str='';
            $ids=explode(",",$id);
	    for($j=0;$j<count($ids);$j++){

                    $sql="SELECT CS_ID,CS_CID,CS_FID,CS_PlayUrl,CS_Name FROM ".CS_SqlPrefix."dance where cs_id='".$ids[$j]."' and cs_hid=0 and cs_yid=0";
	            $row=$this->db->query($sql)->row();
	            if($row){
                            if(FTP_Fun==0){  //远程附件
                                    $Playurl=FTP_Url.$row->CS_PlayUrl;
                            }else{
                                    $Playurl=$this->CsdjSkins->playqurl($row->CS_PlayUrl,$row->CS_FID);
                            }
                            $str.='{name:"'.$row->CS_Name.'",us:"'.$Playurl.'","id":"'.$ids[$j].'","clink":"'.$this->CsdjSkins->LinkUrl('play','dance','id',$row->CS_CID,$row->CS_ID).'","cname":"'.$this->CsdjSkins->getclass($row->CS_CID).'"},';
	            }
            }
	    $str=$str.']';
	    $str=str_replace(",]","",$str);
            echo 'var myPlayList = ['.$str.'];';
	}

        //下载过的会员
	public function downlist()
	{
            $id = $this->security->xss_clean($this->input->get('id', TRUE));   //方式
                
            if(empty($id)){
                exit();
            }

            $sql="SELECT CS_User FROM ".CS_SqlPrefix."down where cs_did='".$id."' order by CS_ID desc limit 8";
	    $result=$this->db->query($sql);
	    foreach ($result->result() as $row) {
                    echo "<li><div class='avatar'><a href='".$this->CsdjSkins->userlink('index',$this->CsdjSkins->getuser('id','',$row->CS_User),$row->CS_User)."' target='_blank'><img width='52' height='52' src='".$this->CsdjSkins->getuser('logo','',$row->CS_User)."'><em></em></a><a href='".$this->CsdjSkins->userlink('index',$this->CsdjSkins->getuser('id','',$row->CS_User),$row->CS_User)."' class='name'>".$this->CsdjSkins->getuser('nichen','',$row->CS_User)."</a></div></li>";
	    }
	}
}

