<?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 Ajax extends CI_Controller {

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

	public function uicon()
	{
		    $str1='<img src="'.Web_Path.'skins/index/hanmai/images/uvip.gif" title="VIP会员">';
		    $str2='<img src="'.Web_Path.'skins/index/hanmai/images/urealname.gif" title="认证会员">';
		    $str3='<img src="'.Web_Path.'skins/index/hanmai/images/umusician.gif" title="音乐人">';
		    $str4='<img src="'.Web_Path.'skins/index/hanmai/images/urecommend.gif" title="推荐歌手">';
		    $str5='<img src="'.Web_Path.'skins/index/hanmai/images/ustar.gif" title="明星会员">';
            $id = intval($this->uri->segment(3));   //UID    
		    $row=$this->db->query("SELECT CS_ID,CS_Vip,CS_Name,CS_RZID,CS_TID,CS_Hits FROM ".CS_SqlPrefix."user where cs_id='$id'")->row();
		    if($row){
				 if($row->CS_Vip>0){
		                $str1='<img src="'.Web_Path.'skins/index/hanmai/images/vip.gif" title="VIP会员">';
				 }
				 if($row->CS_RZID>0){
		                $str2='<img src="'.Web_Path.'skins/index/hanmai/images/realname.gif" title="认证会员">';
				 }
				 if($this->CsdjSkins->getusercount($row->CS_Name,'dance')>100){
		                $str3='<img src="'.Web_Path.'skins/index/hanmai/images/musician.gif" title="音乐人">';
				 }
				 if($row->CS_TID>0){
		                $str4='<img src="'.Web_Path.'skins/index/hanmai/images/recommend.gif" title="推荐歌手">';
				 }
				 if($row->CS_Hits>1000){
		                $str4='<img src="'.Web_Path.'skins/index/hanmai/images/star.gif" title="明星会员">';
				 }
			}
			echo $str1.$str2.$str3.$str4.$str5;
	}

	public function real()
	{
	            $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 10";
	            $query = $this->db->query($sql_string); 
				$mp3list='';
                foreach ($query->result() as $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);
                    }
                    $row->CS_Name=str_replace('"','',$row->CS_Name);
                    $mp3list.='{"title":"'.$row->CS_Name.'","mp3":"'.$purl.'","sid":"'.$row->CS_ID.'"},';
                }
                $mp3list=substr($mp3list,0,-1);
                echo 'var Music = ['.$mp3list.'];';
    }

	public function playsong()
	{
                $id=intval($this->input->get_post('id'));
                if($id==0) exit();
                $row=$this->db->query("select CS_ID,CS_Reco,CS_Name,CS_User,CS_Hits,CS_Shits,CS_Dhits,CS_Xhits,CS_AddTime,CS_FID,CS_PlayUrl from ".CS_SqlPrefix."dance where cs_id='{$id}'")->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);
                    }
					$rowu=$this->db->query("select CS_Logo,CS_Nichen from ".CS_SqlPrefix."user where cs_name='".$row->CS_User."'")->row();
					$upic=$this->CsdjSkins->piclink('logo',$rowu->CS_Logo);
					$unichen=(empty($rowu->CS_Nichen))?$row->CS_User:$rowu->CS_Nichen;
					$ulink=$this->CsdjSkins->userlink('index','',$row->CS_User);
                    echo '{"xhits":"'.$row->CS_Xhits.'","shits":"'.$row->CS_Shits.'","dhits":"'.$row->CS_Dhits.'","xing":"'.$row->CS_Reco.'","name":"'.sub_str($row->CS_Name,20).'","uname":"'.$row->CS_User.'","upic":"'.$upic.'","unichen":"'.$unichen.'","ulink":"'.$ulink.'","url":"'.$purl.'","hits":"'.$row->CS_Hits.'","addtime":"'.$this->CsdjSkins->datetime($row->CS_AddTime).'","id":"'.$id.'"}';
                }
	}
}
