<?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('CsdjUser');
	}

    //推荐舞曲
	public function fav()
	{
		        $this->CsdjUser->User_Login();
                $data='';
                $cid = intval($this->input->get('cid', TRUE));   //cid
                $page = intval($this->input->get('page', TRUE));   //page
                if($page==0) $page=1;

                $this->load->get_user_templates();
		        $template=$this->load->view('fav-list.html',$data,true);
		        $template=$this->CsdjSkins->TopandBottom($template,'user');

		        $Mark_Text=str_replace("{cscms:title}","我推荐的歌曲 - 会员管理中心",$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("[fav:cid]",$cid,$Mark_Text); //CID
				$Mark_Text=str_replace("[user:op]","song",$Mark_Text);

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

                        $sqlstr="select * from ".CS_SqlPrefix."fav where CS_User='".$this->session->userdata('cs_name')."'";
                        if($cid>0){
							$cids=$this->CsdjSkins->getChild($cid);
                            $sqlstr.=" and cs_cid in(".$cids.")";
                        }
                        $sqlstr.=" order by CS_AddTime desc";
                        $data_content='';
			            $Arr=$this->CsdjSkins->SpanUsersPage($sqlstr,$page_arr[2][0],$pagenum,'user/dance/fav?cid='.$cid,$page);//sql,每页显示条数
			            $result=$this->CsdjDB->db->query($Arr[2]);
			            if($result){
					            $sorti=1;
					            foreach ($result->result() as $row2) {
						            $datatmp=$this->CsdjSkins->DataFav($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);
	            $row=$this->CsdjDB->get_select ('user','CS_ID','*',''.$this->session->userdata('cs_id').'');
		        $Mark_Text=$this->CsdjUser->getuser($Mark_Text,$row);
		        $Mark_Text=$this->CsdjSkins->Common_Mark($Mark_Text,$this->session->userdata('cs_name'));
                $this->CsdjSkins->skins($Mark_Text,$data);
	}

    //喜欢舞曲
	public function like()
	{
		        $this->CsdjUser->User_Login();
                $data='';
                $cid = intval($this->input->get('cid', TRUE));   //cid
                $page = intval($this->input->get('page', TRUE));   //page
                if($page==0) $page=1;

                $this->load->get_user_templates();
		        $template=$this->load->view('like-list.html',$data,true);
		        $template=$this->CsdjSkins->TopandBottom($template,'user');

		        $Mark_Text=str_replace("{cscms:title}","我喜欢的歌曲 - 会员管理中心",$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("[like:cid]",$cid,$Mark_Text); //CID
				$Mark_Text=str_replace("[user:op]","song",$Mark_Text);


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

                        $sqlstr="select * from ".CS_SqlPrefix."like where CS_User='".$this->session->userdata('cs_name')."'";
                        if($cid>0){
							$cids=$this->CsdjSkins->getChild($cid);
                            $sqlstr.=" and cs_cid in(".$cids.")";
                        }
                        $sqlstr.=" order by CS_AddTime desc";
                        $data_content='';
			            $Arr=$this->CsdjSkins->SpanUsersPage($sqlstr,$page_arr[2][0],$pagenum,'user/dance/like?cid='.$cid,$page);//sql,每页显示条数
			            $result=$this->CsdjDB->db->query($Arr[2]);
			            if($result){
					            $sorti=1;
					            foreach ($result->result() as $row2) {
						            $datatmp=$this->CsdjSkins->DataLike($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);
	            $row=$this->CsdjDB->get_select ('user','CS_ID','*',''.$this->session->userdata('cs_id').'');
		        $Mark_Text=$this->CsdjUser->getuser($Mark_Text,$row);
		        $Mark_Text=$this->CsdjSkins->Common_Mark($Mark_Text,$this->session->userdata('cs_name'));
                $this->CsdjSkins->skins($Mark_Text,$data);
	}

    //下载舞曲
	public function down()
	{
		        $this->CsdjUser->User_Login();
                $data='';
                $cid = intval($this->input->get('cid', TRUE));   //cid
                $page = intval($this->input->get('page', TRUE));   //page
                if($page==0) $page=1;

                $this->load->get_user_templates();
		        $template=$this->load->view('down-list.html',$data,true);
		        $template=$this->CsdjSkins->TopandBottom($template,'user');

		        $Mark_Text=str_replace("{cscms:title}","我下载的歌曲 - 会员管理中心",$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("[down:cid]",$cid,$Mark_Text); //CID
				$Mark_Text=str_replace("[user:op]","song",$Mark_Text);


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

                        $sqlstr="select * from ".CS_SqlPrefix."down where CS_User='".$this->session->userdata('cs_name')."'";
                        if($cid>0){
							$cids=$this->CsdjSkins->getChild($cid);
                            $sqlstr.=" and cs_cids in(".$cids.")";
                        }
                        $sqlstr.=" order by CS_AddTime desc";
                        $data_content='';
			            $Arr=$this->CsdjSkins->SpanUsersPage($sqlstr,$page_arr[2][0],$pagenum,'user/dance/down?cid='.$cid,$page);//sql,每页显示条数
			            $result=$this->CsdjDB->db->query($Arr[2]);
			            if($result){
					            $sorti=1;
					            foreach ($result->result() as $row2) {
						            $datatmp=$this->CsdjSkins->DataDown($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);
	            $row=$this->CsdjDB->get_select ('user','CS_ID','*',''.$this->session->userdata('cs_id').'');
		        $Mark_Text=$this->CsdjUser->getuser($Mark_Text,$row);
		        $Mark_Text=$this->CsdjSkins->Common_Mark($Mark_Text,$this->session->userdata('cs_name'));
                $this->CsdjSkins->skins($Mark_Text,$data);
	}

    //听过舞曲
	public function listen()
	{
		        $this->CsdjUser->User_Login();
                $data='';
                $cid = intval($this->input->get('cid', TRUE));   //cid
                $page = intval($this->input->get('page', TRUE));   //page
                if($page==0) $page=1;

                $this->load->get_user_templates();
		        $template=$this->load->view('listen-list.html',$data,true);
		        $template=$this->CsdjSkins->TopandBottom($template,'user');

		        $Mark_Text=str_replace("{cscms:title}","我下载的歌曲 - 会员管理中心",$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("[listen:cid]",$cid,$Mark_Text); //CID
				$Mark_Text=str_replace("[user:op]","song",$Mark_Text);


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

                        $sqlstr="select * from ".CS_SqlPrefix."play where CS_User='".$this->session->userdata('cs_name')."'";
                        if($cid>0){
							$cids=$this->CsdjSkins->getChild($cid);
                            $sqlstr.=" and cs_cid in(".$cids.")";
                        }
                        $sqlstr.=" order by CS_AddTime desc";
                        $data_content='';
			            $Arr=$this->CsdjSkins->SpanUsersPage($sqlstr,$page_arr[2][0],$pagenum,'user/dance/listen?cid='.$cid,$page);//sql,每页显示条数
			            $result=$this->CsdjDB->db->query($Arr[2]);
			            if($result){
					            $sorti=1;
					            foreach ($result->result() as $row2) {
						            $datatmp=$this->CsdjSkins->DataListen($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);
	            $row=$this->CsdjDB->get_select ('user','CS_ID','*',''.$this->session->userdata('cs_id').'');
		        $Mark_Text=$this->CsdjUser->getuser($Mark_Text,$row);
		        $Mark_Text=$this->CsdjSkins->Common_Mark($Mark_Text,$this->session->userdata('cs_name'));
                $this->CsdjSkins->skins($Mark_Text,$data);
	}

    //删除听过舞曲
	public function listen_del()
	{
             if(!$this->CsdjUser->User_Login(1)){
                   exit('20001');
		     }
             $did  = intval($this->input->post('did', TRUE));   //did
             $dids = $this->input->post('dids', TRUE);   //dids

			 if($did==0){ //多首
 				      $len=count($dids);
				      if($len>0){
 				            for ($i=0; $i<$len; $i++) {
                                 if(intval($dids[$i])>0){
					                   $this->db->query("delete from ".CS_SqlPrefix."play where cs_user='".$this->session->userdata('cs_name')."' and cs_did='".$dids[$i]."'");
								 }
							}
					  }
			 }else{  //单首

					  $this->db->query("delete from ".CS_SqlPrefix."play where cs_user='".$this->session->userdata('cs_name')."' and cs_did='".$did."'");
			 }
			 echo 'ok';
	}
}

