<?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('CsdjAdmin');
                $this->load->helper('file');
                $this->CsdjAdmin->Admin_Login();
	}

	public function index()
	{
 	    $page = $this->input->get('page');
            if(empty($page)) $page=1;

	    $sql_string = "SELECT * FROM ".CS_SqlPrefix."dance where cs_hid=0 order by CS_AddTime desc";
	    $query = $this->db->query($sql_string); 
	    $total = $query->num_rows();

            $base_url = site_url('admin/dance/index/')."?";
	    $per_page = 20; 
            $totalPages = ceil($total / $per_page); // 总页数
	    $data['nums'] = $total;
            if($total<$per_page){
               $per_page=$total;
            }
            $sql_string.=' limit '. $per_page*($page-1) .','. $per_page;
	    $query = $this->db->query($sql_string);

	    $data['dance'] = $query->result();
	    $data['pages'] = $this->CsdjAdmin->get_page($base_url,$totalPages,$page,10); //获取分页类

            $this->load->view('admin/dance',$data);
        }

	public function huis()
	{
 	    $page = $this->input->get('page');
            if(empty($page)) $page=1;

	    $sql_string = "SELECT * FROM ".CS_SqlPrefix."dance where cs_hid=1 order by CS_AddTime desc";
	    $query = $this->db->query($sql_string); 
	    $total = $query->num_rows();

            $base_url = site_url('admin/dance/huis/')."?";
	    $per_page = 20; 
            $totalPages = ceil($total / $per_page); // 总页数
	    $data['nums'] = $total;
            if($total<$per_page){
               $per_page=$total;
            }
            $sql_string.=' limit '. $per_page*($page-1) .','. $per_page;
	    $query = $this->db->query($sql_string);

	    $data['dance'] = $query->result();
	    $data['pages'] = $this->CsdjAdmin->get_page($base_url,$totalPages,$page,10); //获取分页类

            $this->load->view('admin/dance',$data);
        }

	public function so()
	{
	    $key = $this->input->get('key');
	    $user = $this->input->get('user');
	    $cid = $this->input->get('cid');
	    $page = $this->input->get('page');
            if(empty($page)) $page=1;
	    $sql_string = "SELECT * FROM ".CS_SqlPrefix."dance where 1=1";
            if($key){
	       $sql_string.= " and CS_Name like '%".$key."%'";
            }
            if($user){
	       $sql_string.= " and CS_User like '%".$user."%'";
            }
            if($cid){
                  if($cid=="-1"){
	               $sql_string.= " and cs_hid=1";
                  }elseif($cid=="-2"){
	               $sql_string.= " and cs_yid=1";
                  }elseif($cid=="-3"){
	               $sql_string.= " and cs_reco=5";
                  }else{
	               $sql_string.= " and CS_CID=".$cid."";
                  }
            }
	    $sql_string.= " order by CS_AddTime desc";
	    $query = $this->db->query($sql_string); 
	    $total = $query->num_rows();

            $base_url = site_url('admin/dance/so/')."?key=".$key."&user=".$user."&cid=".$cid."";
	    $per_page = 20; 
            $totalPages = ceil($total / $per_page); // 总页数
	    $data['nums'] = $total;
            if($total<$per_page){
               $per_page=$total;
            }
	    $query = $this->db->query($sql_string .' limit '. $per_page*($page-1) .','. $per_page);
	    $data['dance'] = $query->result();
	    $data['pages'] = $this->CsdjAdmin->get_page($base_url,$totalPages,$page,10); //获取分页类

            $this->load->view('admin/dance',$data);
        }

	public function lists()
	{
            $this->load->view('admin/dlist');
        }

	public function fwqip()
	{
 	    $page = $this->input->get('page');
            if(empty($page)) $page=1;

	    $sql_string = "SELECT * FROM ".CS_SqlPrefix."fwqip where cs_sid=1 order by CS_ID desc";
	    $query = $this->db->query($sql_string); 
	    $total = $query->num_rows();

            $base_url = site_url('admin/dance/fwqip/')."?";
	    $per_page = 20; 
            $totalPages = ceil($total / $per_page); // 总页数
	    $data['nums'] = $total;
            if($total<$per_page){
               $per_page=$total;
            }
            $sql_string.=' limit '. $per_page*($page-1) .','. $per_page;
	    $query = $this->db->query($sql_string);

	    $data['server'] = $query->result();
	    $data['pages'] = $this->CsdjAdmin->get_page($base_url,$totalPages,$page,10); //获取分页类

            $this->load->view('admin/dance_server',$data);
        }

	public function fwqadd()
	{
            $data['title']="新增";
            $data['CS_ID']=0;
            $data['CS_Name']="";
            $data['CS_Playip']="";
            $data['CS_Downip']="";
            $this->load->view('admin/dance_server_edit',$data);
        }

	public function fwqedit()
	{
	    $id = $this->uri->segment(4);
            if(empty($id)) $this->CsdjAdmin->Admin_Url('<font color=red>参数错误，ID为空！</font>',site_url('admin/dance/fwqip/'));
            $data['title']="修改";
            $sql="SELECT * FROM ".CS_SqlPrefix."fwqip where cs_id=".$id."";
	    $row=$this->CsdjDB->get_all($sql);
	    if($row){
                 $data['CS_ID']=$row[0]->CS_ID;
                 $data['CS_Name']=$row[0]->CS_Name;
                 $data['CS_Playip']=$row[0]->CS_Playip;
                 $data['CS_Downip']=$row[0]->CS_Downip;
            }
            $this->load->view('admin/dance_server_edit',$data);
        }

	public function fwqsave()
	{
            $this->CsdjAdmin->Admin_Qx('9');
            $ids=$this->input->post('CS_ID', TRUE);
            $data['CS_Name']=$this->input->post('CS_Name', TRUE);
            $data['CS_Playip']=$this->input->post('CS_Playip', TRUE);
            $data['CS_Downip']=$this->input->post('CS_Downip', TRUE);
            $data['CS_SID']=1;

            if(empty($data['CS_Name']) || empty($data['CS_Playip']) || empty($data['CS_Downip'])) $this->CsdjAdmin->Admin_Url('<font color=red>名称、视听地址、下载地址、不能为空！</font>','javascript:history.back();');

            if($ids==0 || empty($ids)){
                 $this->CsdjDB->get_insert('fwqip',$data);
            }else{
                 $this->CsdjDB->get_update('fwqip',$ids,$data);
            }
            $this->CsdjAdmin->Admin_Url('<font color=#0000ff>恭喜您，操作成功！</font>',site_url('admin/dance/fwqip/'),'ok');
        }

	public function fwqdel()
	{
            $this->CsdjAdmin->Admin_Qx('9');
	    $id = $this->uri->segment(4);
            if(empty($id)) $this->CsdjAdmin->Admin_Url('<font color=red>参数错误，ID为空！</font>',site_url('admin/dance/fwqip/'));

	    $sql_string = "SELECT * FROM ".CS_SqlPrefix."dance where cs_fid=".$id."";
	    $query = $this->db->query($sql_string); 
	    $total = $query->num_rows();
            IF($total>0){
                 $this->CsdjAdmin->Admin_Url('<font color=red>该服务器组下有歌曲数据，请先移除歌曲！</font>',site_url('admin/dance/fwqip/'));
            }

            $this->CsdjDB->get_del('fwqip',$id);
            $this->CsdjAdmin->Admin_Url('<font color=#0000ff>恭喜您，删除成功！</font>',site_url('admin/dance/fwqip/'),'ok');
        }

	public function topic()
	{
 	    $page = $this->input->get('page');
            if(empty($page)) $page=1;

	    $sql_string = "SELECT * FROM ".CS_SqlPrefix."topic where cs_sid=1 order by CS_AddTime desc";
	    $query = $this->db->query($sql_string); 
	    $total = $query->num_rows();

            $base_url = site_url('admin/dance/topic/')."?";
	    $per_page = 20; 
            $totalPages = ceil($total / $per_page); // 总页数
	    $data['nums'] = $total;
            if($total<$per_page){
               $per_page=$total;
            }
            $sql_string.=' limit '. $per_page*($page-1) .','. $per_page;
	    $query = $this->db->query($sql_string);

	    $data['topic'] = $query->result();
	    $data['pages'] = $this->CsdjAdmin->get_page($base_url,$totalPages,$page,10); //获取分页类

            $this->load->view('admin/dance_zj',$data);
        }

	public function topicadd()
	{
            $data['title']="新增";
            $data['CS_ID']=0;
            $data['CS_Name']="";
            $data['CS_Pic']="";
            $data['CS_CID']=0;
            $data['CS_SingerID']=0;
            $data['CS_Singer']='';
            $data['CS_AliasName']="";
            $data['CS_Template']="topic-dance-show.html";
            $data['CS_Content']="";
            $data['CS_Fxgs']="";
            $data['CS_Tags']="";
            $data['CS_Yuyan']="国语";
            $data['CS_Year']=date('Y');
            $data['CS_User']="admin";
            $data['CS_Title']="";
            $data['CS_Keywords']="";
            $data['CS_Description']="";
            $this->load->view('admin/dance_zj_edit',$data);
        }

	public function topicedit()
	{
	    $id = $this->uri->segment(4);
            if(empty($id)) $this->CsdjAdmin->Admin_Url('<font color=red>参数错误，ID为空！</font>',site_url('admin/dance/lists/'));
            $data['title']="修改";
            $sql="SELECT * FROM ".CS_SqlPrefix."topic where cs_id=".$id."";
	    $row=$this->CsdjDB->get_all($sql);
	    if($row){
                 $data['CS_ID']=$row[0]->CS_ID;
                 $data['CS_Name']=$row[0]->CS_Name;
                 $data['CS_SingerID']=$row[0]->CS_SingerID;
                 $data['CS_Singer']=$row[0]->CS_Singer;
                 $data['CS_CID']=$row[0]->CS_CID;
                 $data['CS_Tags']=$row[0]->CS_Tags;
                 $data['CS_AliasName']=$row[0]->CS_AliasName;
                 $data['CS_Template']=$row[0]->CS_Template;
                 $data['CS_Title']=$row[0]->CS_Title;
                 $data['CS_Pic']=$row[0]->CS_Pic;
                 $data['CS_Fxgs']=$row[0]->CS_Fxgs;
                 $data['CS_Yuyan']=$row[0]->CS_Yuyan;
                 $data['CS_Year']=$row[0]->CS_Year;
                 $data['CS_User']=$row[0]->CS_User;
                 $data['CS_Content']=$row[0]->CS_Content;
                 $data['CS_Keywords']=$row[0]->CS_Keywords;
                 $data['CS_Description']=$row[0]->CS_Description;
            }
            $this->load->view('admin/dance_zj_edit',$data);
        }

	public function topicsave()
	{
            $this->CsdjAdmin->Admin_Qx('10');
            $ids=$this->input->post('CS_ID', TRUE);
            $data['CS_Singer']=$this->input->post('CS_Singer', TRUE);
            $data['CS_Name']=$this->input->post('CS_Name', TRUE);
            $data['CS_CID']=$this->input->post('CS_CID', TRUE);
            $data['CS_Pic']=$this->input->post('CS_Pic', TRUE);
            $data['CS_AliasName']=$this->input->post('CS_AliasName', TRUE);
            $data['CS_Year']=$this->input->post('CS_Year', TRUE);
            $data['CS_Tags']=$this->input->post('CS_Tags', TRUE);
            $data['CS_Fxgs']=$this->input->post('CS_Fxgs', TRUE);
            $data['CS_Yuyan']=$this->input->post('CS_Yuyan', TRUE);
            $data['CS_User']=$this->input->post('CS_User', TRUE);
            $data['CS_Content']=$this->input->post('CS_Content');
            $data['CS_Template']=$this->input->post('CS_Template', TRUE);
            $data['CS_Title']=$this->input->post('CS_Title', TRUE);
            $data['CS_Keywords']=$this->input->post('CS_Keywords', TRUE);
            $data['CS_Description']=$this->input->post('CS_Description', TRUE);
            $data['CS_SID']=1;

            if(empty($data['CS_Template'])) $data['CS_Template']="topic-dance-show.html";
            if(empty($data['CS_Name']) || empty($data['CS_AliasName']) || empty($data['CS_User'])) $this->CsdjAdmin->Admin_Url('<font color=red>分类名称、英文别名、会员、不能为空！</font>','javascript:history.back();');
            if(!ctype_alpha($data['CS_AliasName'])) $this->CsdjAdmin->Admin_Url('<font color=red>英文别名只能是字母！</font>','javascript:history.back();');


            $sql="SELECT * FROM ".CS_SqlPrefix."user where cs_name='".$data['CS_User']."'";
	    $row=$this->CsdjDB->get_all($sql); 
	    if(!$row){
                $this->CsdjAdmin->Admin_Url('<font color=red>抱歉，该会员不存在！</font>','javascript:history.back();');
            }

            if(!empty($data['CS_Singer'])){
                    $sql="SELECT CS_ID FROM ".CS_SqlPrefix."singer where cs_name='".$data['CS_Singer']."'";
	            $row=$this->CsdjDB->get_all($sql); 
	            if(!$row){
                       $singer['CS_Name']=$data['CS_Singer'];
                       $this->CsdjDB->get_insert('singer',$singer);

                       $sqls="SELECT * FROM ".CS_SqlPrefix."singer where cs_name='".$data['CS_Singer']."'";
	               $rows=$this->CsdjDB->get_all($sqls); 
                       $data['CS_SingerID']=$rows[0]->CS_ID;
                    }else{
                       $data['CS_SingerID']=$row[0]->CS_ID;
                    }
            }

            if($ids==0 || empty($ids)){
                 $data['CS_AddTime']=date('Y-m-d H:i:s');
                 $this->CsdjDB->get_insert('topic',$data);
            }else{
                 if($this->input->post('CS_Addtime')==1) $data['CS_AddTime']=date('Y-m-d H:i:s');
                 $this->CsdjDB->get_update('topic',$ids,$data);
            }
            $this->CsdjAdmin->Admin_Url('<font color=#0000ff>恭喜您，操作成功！</font>',site_url('admin/dance/topic/'),'ok');
        }

	public function topicdel()
	{
            $this->CsdjAdmin->Admin_Qx('10');
	    $id = $this->uri->segment(4);
            if(empty($id)) $this->CsdjAdmin->Admin_Url('<font color=red>参数错误，ID为空！</font>',site_url('admin/dance/topic/'));

            IF($this->CsdjSkins->gettopiccount($id,1)>0){
                 $this->CsdjAdmin->Admin_Url('<font color=red>该专集下有歌曲数据，请先移除歌曲！</font>',site_url('admin/dance/topic/'));
            }

            //-------------------------------删除文件---------------------------------------//
            if(Web_Mode==3){
                 $fileurl=$this->CsdjSkins->LinkUrl('show','zj','id',1,$id);
                 $fileurl=$this->CsdjAdmin->gethtmls($fileurl); //补全HTML地址
	         $fileurl=".".substr($fileurl,strlen(Web_Path));
	         if(file_exists($fileurl)){
		     @unlink($fileurl);
	         }
            }

            //--------------------------------删除图片----------------------------------------//
	    $row=$this->CsdjDB->get_select ('topic','CS_ID','*',''.$id.'');
	    if($row){
		     $pic="./attachment/topic/".$row[0]->CS_Pic;
                     if(FTP_Fun==1){ //远程附件
                            $this->load->library('ftp');
                            $FTPUP['hostname'] = FTP_Server;
                            $FTPUP['port']     = FTP_Port;
                            $FTPUP['username'] = FTP_Name;
                            $FTPUP['password'] = FTP_Pass;
                            //$FTPUP['debug']    = TRUE;
                            $FTPUP['passive']  = FTP_Ive;

                            $Dirs=FTP_Dir;
                            if(substr($Dirs,0,1)=='/') $Dirs=substr($Dirs,1);
                            if(substr($Dirs,-1)=='/') $Dirs=substr($Dirs,0,-1);
                            if(!empty($Dirs)) $Dirs.='/';
		            $pic="./".$Dirs."attachment/topic/".$row[0]->CS_Pic;

                            $this->ftp->connect($FTPUP);
                            $this->ftp->delete_file($pic);
                            $this->ftp->close();
                     }else{
	                 if(file_exists($pic)){
		            @unlink($pic);
	                 }
                     }
	    }

            $this->db->query("delete from ".CS_SqlPrefix."pl where CS_SID=1 and CS_DID in (".$id.")");  //评论
            $this->db->query("delete from ".CS_SqlPrefix."dt where CS_CID=4 and CS_DID in (".$id.")");  //动态
            $this->CsdjDB->get_del('topic',$id);
            $this->CsdjAdmin->Admin_Url('<font color=#0000ff>恭喜您，删除成功！</font>',site_url('admin/dance/topic/'),'ok');
        }

	public function topicdelall()
	{
            $this->CsdjAdmin->Admin_Qx('10');
	    $ids=$this->input->post('CS_ID');
            $id=implode(',', $ids);
            if(empty($id)) $this->CsdjAdmin->Admin_Url('<font color=red>参数错误，ID为空！</font>','javascript:history.back();');

	    $Arr=explode(',',$id);
            for($i=0;$i<count($Arr);$i++){

                  //-------------------------------删除文件---------------------------------------//
                  if(Web_Mode==3){
                       $fileurl=$this->CsdjSkins->LinkUrl('show','zj','id',1,$Arr[$i]);
                       $fileurl=$this->CsdjAdmin->gethtmls($fileurl); //补全HTML地址
	               $fileurl=".".substr($fileurl,strlen(Web_Path));
	               if(file_exists($fileurl)){
		           @unlink($fileurl);
	               }
                  }

                 //--------------------------------删除图片----------------------------------------//
	         $row=$this->CsdjDB->get_select ('topic','CS_ID','*',''.$Arr[$i].'');
	         if($row){
		     $pic="./attachment/topic/".$row[0]->CS_Pic;
                     if(FTP_Fun==1){ //远程附件
                            $this->load->library('ftp');
                            $FTPUP['hostname'] = FTP_Server;
                            $FTPUP['port']     = FTP_Port;
                            $FTPUP['username'] = FTP_Name;
                            $FTPUP['password'] = FTP_Pass;
                            //$FTPUP['debug']    = TRUE;
                            $FTPUP['passive']  = FTP_Ive;

                            $Dirs=FTP_Dir;
                            if(substr($Dirs,0,1)=='/') $Dirs=substr($Dirs,1);
                            if(substr($Dirs,-1)=='/') $Dirs=substr($Dirs,0,-1);
                            if(!empty($Dirs)) $Dirs.='/';
		            $pic="./".$Dirs."attachment/topic/".$row[0]->CS_Pic;

                            $this->ftp->connect($FTPUP);
                            $this->ftp->delete_file($pic);
                     }else{
	                 if(file_exists($pic)){
		            @unlink($pic);
	                 }
                     }
	         }
                  $this->db->query("delete from ".CS_SqlPrefix."dt where CS_CID=4 and CS_DID in (".$Arr[$i].")");  //动态
            }

            $this->db->query("delete from ".CS_SqlPrefix."pl where CS_SID=1 and CS_DID in (".$id.")");  //评论
            $this->db->query("delete from ".CS_SqlPrefix."topic where CS_ID in (".$id.")");  //动态
            $this->CsdjAdmin->Admin_Url('<font color=#0000ff>恭喜您，删除成功！</font>',site_url('admin/dance/topic/'),'ok');
        }

	public function listsadd()
	{
            $data['title']="新增";
            $data['CS_ID']=0;
            $data['CS_Name']="";
            $data['CS_FID']=0;
            $data['CS_XID']=50;
            $data['CS_AliasName']="";
            $data['CS_Template']="dance-list.html";
            $data['CS_Title']="";
            $data['CS_Keywords']="";
            $data['CS_Description']="";
            $this->load->view('admin/dlist_edit',$data);
        }

	public function listsedit()
	{
	    $id = $this->uri->segment(4);
            if(empty($id)) $this->CsdjAdmin->Admin_Url('<font color=red>参数错误，ID为空！</font>',site_url('admin/dance/lists/'));
            $data['title']="修改";
            $sql="SELECT * FROM ".CS_SqlPrefix."class where cs_id=".$id."";
	    $row=$this->CsdjDB->get_all($sql);
	    if($row){
                 $data['CS_ID']=$row[0]->CS_ID;
                 $data['CS_Name']=$row[0]->CS_Name;
                 $data['CS_FID']=$row[0]->CS_FID;
                 $data['CS_XID']=$row[0]->CS_XID;
                 $data['CS_AliasName']=$row[0]->CS_AliasName;
                 $data['CS_Template']=$row[0]->CS_Template;
                 $data['CS_Title']=$row[0]->CS_Title;
                 $data['CS_Keywords']=$row[0]->CS_Keywords;
                 $data['CS_Description']=$row[0]->CS_Description;
            }
            $this->load->view('admin/dlist_edit',$data);
        }

	public function listssave()
	{
            $this->CsdjAdmin->Admin_Qx('8');
            $ids=$this->input->post('ids', TRUE);
            $CS_Name=$this->input->post('CS_Name', TRUE);
            $CS_FID=$this->input->post('CS_FID', TRUE);
            $CS_XID=$this->input->post('CS_XID', TRUE);
            $CS_AliasName=$this->input->post('CS_AliasName', TRUE);
            $CS_Template=$this->input->post('CS_Template', TRUE);
            $CS_Title=$this->input->post('CS_Title', TRUE);
            $CS_Keywords=$this->input->post('CS_Keywords', TRUE);
            $CS_Description=$this->input->post('CS_Description', TRUE);

            if(empty($CS_XID)) $CS_XID=50;
            if(empty($CS_Template)) $CS_Template="dance-list.html";

            if(empty($CS_Name) || empty($CS_AliasName)) $this->CsdjAdmin->Admin_Url('<font color=red>分类名称、英文别名、不能为空！</font>','javascript:history.back();');
            if(!ctype_alpha($CS_AliasName)) $this->CsdjAdmin->Admin_Url('<font color=red>英文别名只能是字母！</font>','javascript:history.back();');

            $data['CS_Name']=$CS_Name;
            $data['CS_SID']=1;
            $data['CS_FID']=$CS_FID;
            $data['CS_XID']=$CS_XID;
            $data['CS_AliasName']=$CS_AliasName;
            $data['CS_Template']=$CS_Template;
            $data['CS_Title']=$CS_Title;
            $data['CS_Keywords']=$CS_Keywords;
            $data['CS_Description']=$CS_Description;

            if($ids==0 || empty($ids)){
                 $this->CsdjDB->get_insert('class',$data);
            }else{
                 $this->CsdjDB->get_update('class',$ids,$data);
            }
            $this->CsdjAdmin->Admin_Url('<font color=#0000ff>恭喜您，操作成功！</font>',site_url('admin/dance/lists/'),'ok');
        }

	public function listspledit()
	{
            $this->CsdjAdmin->Admin_Qx('8');
            $ids=$this->input->post('CS_ID', TRUE);
            $id = implode(',', $ids);

            $arr=explode(",",$id);

            for($j=0;$j<count($arr);$j++){
                  $data['CS_Name']=$this->input->post('CS_Name'.$arr[$j].'', TRUE);
                  $data['CS_YID']=$this->input->post('CS_YID'.$arr[$j].'', TRUE);
                  $data['CS_XID']=$this->input->post('CS_XID'.$arr[$j].'', TRUE);
                  $data['CS_AliasName']=$this->input->post('CS_AliasName'.$arr[$j].'', TRUE);
                  if(empty($data['CS_XID'])) $data['CS_XID']=50;

                  if(!empty($data['CS_Name']) && !empty($data['CS_AliasName'])){
                         $this->CsdjDB->get_update('class',$arr[$j],$data);
                  }
            }
            $this->CsdjAdmin->Admin_Url('<font color=#0000ff>恭喜您，操作成功！</font>',site_url('admin/dance/lists/'),'ok');
        }

	public function listsdel()
	{
            $this->CsdjAdmin->Admin_Qx('8');
	    $id = $this->uri->segment(4);
            if(empty($id)) $this->CsdjAdmin->Admin_Url('<font color=red>参数错误，ID为空！</font>',site_url('admin/dance/lists/'));

            $sql="SELECT * FROM ".CS_SqlPrefix."class where cs_fid=".$id."";
	    $row=$this->CsdjDB->get_all($sql);
	    if($row){
                 $this->CsdjAdmin->Admin_Url('<font color=red>该分类下二级分类，请先移除二级分类！</font>',site_url('admin/dance/lists/'));
            }

            IF($this->CsdjSkins->getclasscount($id,1)>0){
                 $this->CsdjAdmin->Admin_Url('<font color=red>该分类下有歌曲数据，请先移除歌曲！</font>',site_url('admin/dance/lists/'));
            }

            $this->CsdjDB->get_del('class',$id);
            $this->CsdjAdmin->Admin_Url('<font color=#0000ff>恭喜您，删除成功！</font>',site_url('admin/dance/lists/'),'ok');
        }


	public function add()
	{
            $data['title']="新增歌曲";
            $data['CS_ID']=0;
            $data['CS_CID']=0;
            $data['CS_Color']="";
            $data['CS_TID']=0;
            $data['CS_Reco']=0;
            $data['CS_Name']="";
            $data['CS_Tags']="";
            $data['CS_Singer']="";
            $data['CS_Year']=date('Y');
            $data['CS_User']="admin";
            $data['CS_Cion']=1;
            $data['CS_Scion']=0;
            $data['CS_Vip']=0;
            $data['CS_FID']=0;
            $data['CS_PID']=1;
            $data['CS_Pic']='';
            $data['CS_PlayUrl']="";
            $data['CS_DownUrl1']="";
			$data['CS_Content']="";
			$data['CS_Lrc']="";
            $data['CS_Dx']="";
            $data['CS_Yz']="";
            $data['CS_Sc']="";
			$data['CS_Zc']="";
			$data['CS_Zq']="";
			$data['CS_Bq']="";
			$data['CS_Hy']="";
			$data['CS_Tuig']="";
			$data['CS_Js']="";
			$data['CS_Wpfx']="";
			$data['CS_Wpfxmm']="";
            $data['CS_Hits']=0;
            $data['CS_Xhits']=0;
            $data['CS_Shits']=0;
			$data['CS_Dhits']=0;
            $data['CS_Template']="dance-play.html";
            $data['CS_Title']="";
            $data['CS_Keywords']="";
            $data['CS_Description']="";
            $this->load->view('admin/dance_edit',$data);
        }

	public function edit()
	{
            $id = $this->security->xss_clean($this->uri->segment(4));   //ID
            if(empty($id)) $this->CsdjAdmin->Admin_Url('<font color=red>参数错误，ID为空！</font>','javascript:history.back();');

	    $row=$this->CsdjDB->get_select ('dance','CS_ID','*',''.$id.'');
	    if(!$row){
		 $this->CsdjAdmin->Admin_Url('<font color=red>抱歉，改ID不存在！</font>','javascript:history.back();');
	    }

            $data['title']="修改歌曲";
            $data['CS_ID']=$id;
            $data['CS_CID']=$row[0]->CS_CID;
            $data['CS_Color']=$row[0]->CS_Color;
            $data['CS_TID']=$row[0]->CS_TID;
            $data['CS_Reco']=$row[0]->CS_Reco;
            $data['CS_Name']=$row[0]->CS_Name;
            $data['CS_Tags']=$row[0]->CS_Tags;
            $data['CS_Singer']=$row[0]->CS_Singer;
            $data['CS_Year']=$row[0]->CS_Year;
            $data['CS_User']=$row[0]->CS_User;
            $data['CS_Cion']=$row[0]->CS_Cion;
            $data['CS_Scion']=$row[0]->CS_Scion;
            $data['CS_Vip']=$row[0]->CS_Vip;
            $data['CS_FID']=$row[0]->CS_FID;
            $data['CS_PID']=$row[0]->CS_PID;
            $data['CS_Pic']=$row[0]->CS_Pic;
            $data['CS_PlayUrl']=$row[0]->CS_PlayUrl;
            $data['CS_DownUrl1']=$row[0]->CS_DownUrl1;
            $data['CS_Content']=$row[0]->CS_Content;
			$data['CS_Lrc']=$row[0]->CS_Lrc;
            $data['CS_Dx']=$row[0]->CS_Dx;
            $data['CS_Yz']=$row[0]->CS_Yz;
            $data['CS_Sc']=$row[0]->CS_Sc;
			$data['CS_Zc']=$row[0]->CS_Zc;
			$data['CS_Zq']=$row[0]->CS_Zq;
            $data['CS_Bq']=$row[0]->CS_Bq;
			$data['CS_Hy']=$row[0]->CS_Hy;
			$data['CS_Tuig']=$row[0]->CS_Tuig;
			$data['CS_Js']=$row[0]->CS_Js;
			$data['CS_Wpfx']=$row[0]->CS_Wpfx;
			$data['CS_Wpfxmm']=$row[0]->CS_Wpfxmm;
            $data['CS_Hits']=$row[0]->CS_Hits;
            $data['CS_Xhits']=$row[0]->CS_Xhits;
            $data['CS_Shits']=$row[0]->CS_Shits;
			$data['CS_Dhits']=$row[0]->CS_Dhits;
            $data['CS_Template']=$row[0]->CS_Template;
            $data['CS_Title']=$row[0]->CS_Title;
            $data['CS_Keywords']=$row[0]->CS_Keywords;
            $data['CS_Description']=$row[0]->CS_Description;
            $this->load->view('admin/dance_edit',$data);
        }


	public function save()
	{
            $this->CsdjAdmin->Admin_Qx('8');
            $CS_ID=$this->input->post('CS_ID');

		$data['CS_Color']=$this->input->post('CS_Color');
		$data['CS_CID']=$this->input->post('CS_CID');
		$data['CS_Tags']=$this->input->post('CS_Tags');
		$data['CS_Name']=$this->input->post('CS_Name');
		$data['CS_TID']=$this->input->post('CS_TID');
		$data['CS_Year']=$this->input->post('CS_Year');
		$data['CS_Singer']=$this->input->post('CS_Singer');
		$data['CS_User']=$this->input->post('CS_User');
		$data['CS_PID']=$this->input->post('CS_PID');
		$data['CS_Pic']=$this->input->post('CS_Pic');
		$data['CS_FID']=$this->input->post('CS_FID');
		$data['CS_Reco']=$this->input->post('CS_Reco');
		$data['CS_Cion']=$this->input->post('CS_Cion');
         $data['CS_Scion']=$this->input->post('CS_Scion');
		$data['CS_Vip']=$this->input->post('CS_Vip');
		$data['CS_Hits']=$this->input->post('CS_Hits');
		$data['CS_Xhits']=$this->input->post('CS_Xhits');
		$data['CS_Shits']=$this->input->post('CS_Shits');
		$data['CS_Dhits']=$this->input->post('CS_Dhits');
		$data['CS_Template']=$this->input->post('CS_Template');
		$data['CS_PlayUrl']=$this->input->post('CS_PlayUrl');
		$data['CS_DownUrl1']=$this->input->post('CS_DownUrl1');
		$data['CS_Dx']=$this->input->post('CS_Dx');
		$data['CS_Yz']=$this->input->post('CS_Yz');
		$data['CS_Sc']=$this->input->post('CS_Sc');
		$data['CS_Zc']=$this->input->post('CS_Zc');
		$data['CS_Zq']=$this->input->post('CS_Zq');
		$data['CS_Bq']=$this->input->post('CS_Bq');
		$data['CS_Hy']=$this->input->post('CS_Hy');
		$data['CS_Tuig']=$this->input->post('CS_Tuig');
		$data['CS_Js']=$this->input->post('CS_Js');
		$data['CS_Wpfx']=$this->input->post('CS_Wpfx');
		$data['CS_Wpfxmm']=$this->input->post('CS_Wpfxmm');
		$data['CS_Title']=$this->input->post('CS_Title');
        $data['CS_Content']=$this->input->post('CS_Content');
		$data['CS_Lrc']=$this->input->post('CS_Lrc');
		$data['CS_Keywords']=$this->input->post('CS_Keywords');
		$data['CS_Description']=$this->input->post('CS_Description');

                if(empty($data['CS_Name'])||empty($data['CS_User'])||empty($data['CS_DownUrl1'])){
                        $this->CsdjAdmin->Admin_Url('<font color=red>名称、会员、视听地址、不能为空！</font>','javascript:history.back();');
                }

                $sql="SELECT * FROM ".CS_SqlPrefix."user where cs_name='".$data['CS_User']."'";
	        $row=$this->CsdjDB->get_all($sql); 
	        if(!$row){
                     $this->CsdjAdmin->Admin_Url('<font color=red>抱歉，该会员不存在！</font>','javascript:history.back();');
                }

                if(!empty($data['CS_Singer'])){
                    $sql="SELECT * FROM ".CS_SqlPrefix."singer where cs_name='".$data['CS_Singer']."'";
	            $row=$this->CsdjDB->get_all($sql); 
	            if(!$row){
                       $singer['CS_Name']=$data['CS_Singer'];
                       $this->CsdjDB->get_insert('singer',$singer);

                       $sqls="SELECT * FROM ".CS_SqlPrefix."singer where cs_name='".$data['CS_Singer']."'";
	               $rows=$this->CsdjDB->get_all($sqls); 
                       $data['CS_SingerID']=$rows[0]->CS_ID;
                    }else{
                       $data['CS_SingerID']=$row[0]->CS_ID;
                    }
                }

                if(empty($data['CS_Cion'])) $data['CS_Cion']=0;
                if(empty($data['CS_Scion'])) $data['CS_Scion']=0;
                if(empty($data['CS_Hits'])) $data['CS_Hits']=0;
                if(empty($data['CS_Shits'])) $data['CS_Shits']=0;
                if(empty($data['CS_Xhits'])) $data['CS_Xhits']=0;
                if(empty($data['CS_Template'])) $data['CS_Template']='dance-play.html';

                if($CS_ID==0 || empty($CS_ID)){
                     $data['CS_AddTime']=date('Y-m-d H:i:s');
                     $this->CsdjDB->get_insert('dance',$data);
                }else{
                     if($this->input->post('CS_AddTime')==1) $data['CS_AddTime']=date('Y-m-d H:i:s');
                     $this->CsdjDB->get_update('dance',$CS_ID,$data);
                }
                $this->CsdjAdmin->Admin_Url('<font color=#0000ff>恭喜您，操作成功！</font>',site_url('admin/dance/index'),'ok');
        }

	public function pledit()
	{
            $id=$this->input->get('id');
            $data['id']=$id;
            $data['sid']=1;
            $data['name']="歌曲";
            $data['link']=site_url('admin/dance/plsave/');
            $this->load->view('admin/pl_edit',$data);
        }

	public function plsave()
	{
            $this->CsdjAdmin->Admin_Qx('8');
            $xid=$this->input->post('xid');
            $CS_CSID=$this->input->post('CS_CSID');
            $CS_ID=$this->input->post('CS_ID');

		$CS_Color=$this->input->post('CS_Color');
		$CS_CID=$this->input->post('CS_CID');
		$CS_HID=$this->input->post('CS_HID');
		$CS_CIDS=$this->input->post('CS_CIDS');
		$CS_TID=$this->input->post('CS_TID');
		$CS_YID=$this->input->post('CS_YID');
		$CS_Singer=$this->input->post('CS_Singer');
		$CS_User=$this->input->post('CS_User');
		$CS_PID=$this->input->post('CS_PID');
		$CS_FID=$this->input->post('CS_FID');
		$CS_FIDS=$this->input->post('CS_FIDS');
		$CS_Reco=$this->input->post('CS_Reco');
		$CS_Cion=$this->input->post('CS_Cion');
		$CS_Vip=$this->input->post('CS_Vip');
		$CS_Hits=$this->input->post('CS_Hits');
		$CS_Yhits=$this->input->post('CS_Yhits');
		$CS_Zhits=$this->input->post('CS_Zhits');
		$CS_Rhits=$this->input->post('CS_Rhits');
		$CS_Xhits=$this->input->post('CS_Xhits');
		$CS_Shits=$this->input->post('CS_Shits');
		$CS_Template=$this->input->post('CS_Template');

                if(!empty($CS_CSID)){
                    $CS_CSID=implode(',', $CS_CSID);
                }

 		$Arr=explode(',',$CS_CSID);
                switch($xid){
	                 case '1':
		              if($CS_ID==""){
			         $this->CsdjAdmin->Admin_Url('<font color=red>抱歉,请填写要修改的歌曲ID!</font>','javascript:history.back();');
		              }

                              for($i=0;$i<count($Arr);$i++){
                                     if($Arr[$i]=="CS_Color"){
                                         $this->db->query("update ".CS_SqlPrefix."dance set CS_Color='".$CS_Color."' where CS_ID in (".$CS_ID.")");
                                     }elseif($Arr[$i]=="CS_CID"){
                                         $this->db->query("update ".CS_SqlPrefix."dance set CS_CID=".$CS_CID." where CS_ID in (".$CS_ID.")");
                                     }elseif($Arr[$i]=="CS_YID"){
                                         $this->db->query("update ".CS_SqlPrefix."dance set CS_YID=".$CS_YID." where CS_ID in (".$CS_ID.")");
                                     }elseif($Arr[$i]=="CS_TID"){
                                         $this->db->query("update ".CS_SqlPrefix."dance set CS_TID=".$CS_TID." where CS_ID in (".$CS_ID.")");
                                     }elseif($Arr[$i]=="CS_FID"){
                                         $this->db->query("update ".CS_SqlPrefix."dance set CS_FID=".$CS_FID." where CS_ID in (".$CS_ID.")");
                                     }elseif($Arr[$i]=="CS_Singer"){
                                         $singerid=$this->CsdjSkins->getziduan('singer','cs_id',$CS_Singer,'cs_name');
                                         if($singerid){
                                              $this->db->query("update ".CS_SqlPrefix."dance set CS_Singer='".$CS_Singer."',CS_SingerID=".$singerid." where CS_ID in (".$CS_ID.")");
                                         }
                                     }elseif($Arr[$i]=="CS_Reco"){
                                         $this->db->query("update ".CS_SqlPrefix."dance set CS_Reco=".$CS_Reco." where CS_ID in (".$CS_ID.")");
                                     }elseif($Arr[$i]=="CS_Cion"){
                                         $this->db->query("update ".CS_SqlPrefix."dance set CS_Cion=".$CS_Cion." where CS_ID in (".$CS_ID.")");
                                     }elseif($Arr[$i]=="CS_User"){
                                         $this->db->query("update ".CS_SqlPrefix."dance set CS_User='".$CS_User."' where CS_ID in (".$CS_ID.")");
                                     }elseif($Arr[$i]=="CS_Vip"){
                                         $this->db->query("update ".CS_SqlPrefix."dance set CS_Vip=".$CS_Vip." where CS_ID in (".$CS_ID.")");
                                     }elseif($Arr[$i]=="CS_Hits"){
                                         $this->db->query("update ".CS_SqlPrefix."dance set CS_Hits=".$CS_Hits." where CS_ID in (".$CS_ID.")");
                                     }elseif($Arr[$i]=="CS_Yhits"){
                                         $this->db->query("update ".CS_SqlPrefix."dance set CS_Yhits=".$CS_Yhits." where CS_ID in (".$CS_ID.")");
                                     }elseif($Arr[$i]=="CS_Zhits"){
                                         $this->db->query("update ".CS_SqlPrefix."dance set CS_Zhits=".$CS_Zhits." where CS_ID in (".$CS_ID.")");
                                     }elseif($Arr[$i]=="CS_Rhits"){
                                         $this->db->query("update ".CS_SqlPrefix."dance set CS_Rhits=".$CS_Rhits." where CS_ID in (".$CS_ID.")");
                                     }elseif($Arr[$i]=="CS_Xhits"){
                                         $this->db->query("update ".CS_SqlPrefix."dance set CS_Xhits=".$CS_Xhits." where CS_ID in (".$CS_ID.")");
                                     }elseif($Arr[$i]=="CS_Shits"){
                                         $this->db->query("update ".CS_SqlPrefix."dance set CS_Shits=".$CS_Shits." where CS_ID in (".$CS_ID.")");
                                     }elseif($Arr[$i]=="CS_Template"){
                                         $this->db->query("update ".CS_SqlPrefix."dance set CS_Template='".$CS_Template."' where CS_ID in (".$CS_ID.")");
                                     }elseif($Arr[$i]=="CS_PID"){
                                         $this->db->query("update ".CS_SqlPrefix."dance set CS_PID='".$CS_PID."' where CS_ID in (".$CS_ID.")");
                                     }elseif($Arr[$i]=="CS_HID"){
                                           if($CS_HID==2){
                                                  $this->db->query("delete from ".CS_SqlPrefix."dance where CS_ID in (".$CS_ID.")");
                                           }else{
                                                  $this->db->query("update ".CS_SqlPrefix."dance set CS_HID=".$CS_HID." where CS_ID in (".$CS_ID.")");
                                           }
                                     }
                              }
                         break;
	                 case '2':
		              if($CS_CIDS=="0"){
			         $this->CsdjAdmin->Admin_Url('<font color=red>抱歉,选择要操作的分类!</font>','javascript:history.back();');
		              }
                              for($i=0;$i<count($Arr);$i++){
                                     if($Arr[$i]=="CS_Color"){
                                         $this->db->query("update ".CS_SqlPrefix."dance set CS_Color='".$CS_Color."' where CS_CID in (".$CS_CIDS.")");
                                     }elseif($Arr[$i]=="CS_CID"){
                                         $this->db->query("update ".CS_SqlPrefix."dance set CS_CID=".$CS_CID." where CS_CID in (".$CS_CIDS.")");
                                     }elseif($Arr[$i]=="CS_YID"){
                                         $this->db->query("update ".CS_SqlPrefix."dance set CS_YID=".$CS_YID." where CS_CID in (".$CS_CIDS.")");
                                     }elseif($Arr[$i]=="CS_TID"){
                                         $this->db->query("update ".CS_SqlPrefix."dance set CS_TID=".$CS_TID." where CS_CID in (".$CS_CIDS.")");
                                     }elseif($Arr[$i]=="CS_FID"){
                                         $this->db->query("update ".CS_SqlPrefix."dance set CS_FID=".$CS_FID." where CS_CID in (".$CS_CIDS.")");
                                     }elseif($Arr[$i]=="CS_Singer"){
                                         $singerid=$this->CsdjSkins->getziduan('singer','cs_id',$CS_Singer,'cs_name');
                                         if($singerid){
                                              $this->db->query("update ".CS_SqlPrefix."dance set CS_Singer='".$CS_Singer."',CS_SingerID=".$singerid." where CS_CID in (".$CS_CIDS.")");
                                         }
                                     }elseif($Arr[$i]=="CS_Reco"){
                                         $this->db->query("update ".CS_SqlPrefix."dance set CS_Reco=".$CS_Reco." where CS_CID in (".$CS_CIDS.")");
                                     }elseif($Arr[$i]=="CS_Cion"){
                                         $this->db->query("update ".CS_SqlPrefix."dance set CS_Cion=".$CS_Cion." where CS_CID in (".$CS_CIDS.")");
                                     }elseif($Arr[$i]=="CS_User"){
                                         $this->db->query("update ".CS_SqlPrefix."dance set CS_User='".$CS_User."' where CS_CID in (".$CS_CIDS.")");
                                     }elseif($Arr[$i]=="CS_Vip"){
                                         $this->db->query("update ".CS_SqlPrefix."dance set CS_Vip=".$CS_Vip." where CS_CID in (".$CS_CIDS.")");
                                     }elseif($Arr[$i]=="CS_Hits"){
                                         $this->db->query("update ".CS_SqlPrefix."dance set CS_Hits=".$CS_Hits." where CS_CID in (".$CS_CIDS.")");
                                     }elseif($Arr[$i]=="CS_Yhits"){
                                         $this->db->query("update ".CS_SqlPrefix."dance set CS_Yhits=".$CS_Yhits." where CS_CID in (".$CS_CIDS.")");
                                     }elseif($Arr[$i]=="CS_Zhits"){
                                         $this->db->query("update ".CS_SqlPrefix."dance set CS_Zhits=".$CS_Zhits." where CS_CID in (".$CS_CIDS.")");
                                     }elseif($Arr[$i]=="CS_Rhits"){
                                         $this->db->query("update ".CS_SqlPrefix."dance set CS_Rhits=".$CS_Rhits." where CS_CID in (".$CS_CIDS.")");
                                     }elseif($Arr[$i]=="CS_Xhits"){
                                         $this->db->query("update ".CS_SqlPrefix."dance set CS_Xhits=".$CS_Xhits." where CS_CID in (".$CS_CIDS.")");
                                     }elseif($Arr[$i]=="CS_Shits"){
                                         $this->db->query("update ".CS_SqlPrefix."dance set CS_Shits=".$CS_Shits." where CS_CID in (".$CS_CIDS.")");
                                     }elseif($Arr[$i]=="CS_Template"){
                                         $this->db->query("update ".CS_SqlPrefix."dance set CS_Template='".$CS_Template."' where CS_CID in (".$CS_CIDS.")");
                                     }elseif($Arr[$i]=="CS_PID"){
                                         $this->db->query("update ".CS_SqlPrefix."dance set CS_PID='".$CS_PID."' where CS_CID in (".$CS_CIDS.")");
                                     }elseif($Arr[$i]=="CS_HID"){
                                           if($CS_HID==2){
                                                  $this->db->query("delete from ".CS_SqlPrefix."dance where CS_CID in (".$CS_CIDS.")");
                                           }else{
                                                  $this->db->query("update ".CS_SqlPrefix."dance set CS_HID=".$CS_HID." where CS_CID in (".$CS_CIDS.")");
                                           }
                                     }
                              }
                         break;
	                 case '3':
		              if($CS_FIDS=="0"){
			         $this->CsdjAdmin->Admin_Url('<font color=red>抱歉,请填写要操作的服务器组!</font>','javascript:history.back();');
		              }
                              for($i=0;$i<count($Arr);$i++){
                                     if($Arr[$i]=="CS_Color"){
                                         $this->db->query("update ".CS_SqlPrefix."dance set CS_Color='".$CS_Color."' where CS_FID in (".$CS_FIDS.")");
                                     }elseif($Arr[$i]=="CS_CID"){
                                         $this->db->query("update ".CS_SqlPrefix."dance set CS_CID=".$CS_CID." where CS_FID in (".$CS_FIDS.")");
                                     }elseif($Arr[$i]=="CS_YID"){
                                         $this->db->query("update ".CS_SqlPrefix."dance set CS_YID=".$CS_YID." where CS_FID in (".$CS_FIDS.")");
                                     }elseif($Arr[$i]=="CS_TID"){
                                         $this->db->query("update ".CS_SqlPrefix."dance set CS_TID=".$CS_TID." where CS_FID in (".$CS_FIDS.")");
                                     }elseif($Arr[$i]=="CS_FID"){
                                         $this->db->query("update ".CS_SqlPrefix."dance set CS_FID=".$CS_FID." where CS_FID in (".$CS_FIDS.")");
                                     }elseif($Arr[$i]=="CS_Singer"){
                                         $singerid=$this->CsdjSkins->getziduan('singer','cs_id',$CS_Singer,'cs_name');
                                         if($singerid){
                                              $this->db->query("update ".CS_SqlPrefix."dance set CS_Singer='".$CS_Singer."',CS_SingerID=".$singerid." where CS_FID in (".$CS_FIDS.")");
                                         }
                                     }elseif($Arr[$i]=="CS_Reco"){
                                         $this->db->query("update ".CS_SqlPrefix."dance set CS_Reco=".$CS_Reco." where CS_FID in (".$CS_FIDS.")");
                                     }elseif($Arr[$i]=="CS_Cion"){
                                         $this->db->query("update ".CS_SqlPrefix."dance set CS_Cion=".$CS_Cion." where CS_FID in (".$CS_FIDS.")");
                                     }elseif($Arr[$i]=="CS_User"){
                                         $this->db->query("update ".CS_SqlPrefix."dance set CS_User='".$CS_User."' where CS_FID in (".$CS_FIDS.")");
                                     }elseif($Arr[$i]=="CS_Vip"){
                                         $this->db->query("update ".CS_SqlPrefix."dance set CS_Vip=".$CS_Vip." where CS_FID in (".$CS_FIDS.")");
                                     }elseif($Arr[$i]=="CS_Hits"){
                                         $this->db->query("update ".CS_SqlPrefix."dance set CS_Hits=".$CS_Hits." where CS_FID in (".$CS_FIDS.")");
                                     }elseif($Arr[$i]=="CS_Yhits"){
                                         $this->db->query("update ".CS_SqlPrefix."dance set CS_Yhits=".$CS_Yhits." where CS_FID in (".$CS_FIDS.")");
                                     }elseif($Arr[$i]=="CS_Zhits"){
                                         $this->db->query("update ".CS_SqlPrefix."dance set CS_Zhits=".$CS_Zhits." where CS_FID in (".$CS_FIDS.")");
                                     }elseif($Arr[$i]=="CS_Rhits"){
                                         $this->db->query("update ".CS_SqlPrefix."dance set CS_Rhits=".$CS_Rhits." where CS_FID in (".$CS_FIDS.")");
                                     }elseif($Arr[$i]=="CS_Xhits"){
                                         $this->db->query("update ".CS_SqlPrefix."dance set CS_Xhits=".$CS_Xhits." where CS_FID in (".$CS_FIDS.")");
                                     }elseif($Arr[$i]=="CS_Shits"){
                                         $this->db->query("update ".CS_SqlPrefix."dance set CS_Shits=".$CS_Shits." where CS_FID in (".$CS_FIDS.")");
                                     }elseif($Arr[$i]=="CS_Template"){
                                         $this->db->query("update ".CS_SqlPrefix."dance set CS_Template='".$CS_Template."' where CS_FID in (".$CS_FIDS.")");
                                     }elseif($Arr[$i]=="CS_PID"){
                                         $this->db->query("update ".CS_SqlPrefix."dance set CS_PID='".$CS_PID."' where CS_FID in (".$CS_FIDS.")");
                                     }elseif($Arr[$i]=="CS_HID"){
                                           if($CS_HID==2){
                                                  $this->db->query("delete from ".CS_SqlPrefix."dance where CS_FID in (".$CS_FIDS.")");
                                           }else{
                                                  $this->db->query("update ".CS_SqlPrefix."dance set CS_HID=".$CS_HID." where CS_FID in (".$CS_FIDS.")");
                                           }
                                     }
                              }
                         break;
                }
                 echo '<script>
                        alert("恭喜您，操作成功！");
                        parent.document.location.reload();
                 </script>';
        }

	public function del()
	{
            $this->CsdjAdmin->Admin_Qx('8');
            $id = $this->security->xss_clean($this->uri->segment(4));   //ID
            if(empty($id)) $this->CsdjAdmin->Admin_Url('<font color=red>参数错误，ID为空！</font>','javascript:history.back();');

            //-------------------------------删除歌曲文件---------------------------------------//
            if(Web_Mode==3){
                 $fileurl=$this->CsdjSkins->LinkUrl('play','dance','id',1,$id);
                 $fileurl=$this->CsdjAdmin->gethtmls($fileurl); //补全HTML地址
	         $fileurl=".".substr($fileurl,strlen(Web_Path));
		 @unlink($fileurl);
            }

	         $row=$this->CsdjDB->get_select ('dance','CS_ID','CS_FID,CS_YID,CS_PlayUrl,CS_Pic,CS_User,CS_Name',''.$id.'');
	         if($row){
		     $purl=$row[0]->CS_PlayUrl;
		     $pic="/attachment/music/".$row[0]->CS_Pic;

                     if(FTP_Fun==1 && $row[0]->CS_FID){ //远程附件
                            $this->load->library('ftp');
                            $FTPUP['hostname'] = FTP_Server;
                            $FTPUP['port']     = FTP_Port;
                            $FTPUP['username'] = FTP_Name;
                            $FTPUP['password'] = FTP_Pass;
                            //$FTPUP['debug']    = TRUE;

                            $Dirs=FTP_Dir;
                            if(substr($Dirs,0,1)=='/') $Dirs=substr($Dirs,1);
                            if(substr($Dirs,-1)=='/') $Dirs=substr($Dirs,0,-1);
                            if(!empty($Dirs)) $Dirs.='/';
		            $purl="/".$Dirs.$row[0]->CS_PlayUrl;
		            $pic="/".$Dirs."attachment/music/".$row[0]->CS_Pic;

                            $FTPUP['passive']  = FTP_Ive;
                            $this->ftp->connect($FTPUP);
                            $this->ftp->delete_file(".".$purl);  //删除歌曲远程数据
                            $this->ftp->delete_file(".".$pic);
                            $this->ftp->close();
                     }else{
	                 //删除歌曲本地数据
		            @unlink(".".$purl);
		            @unlink(".".$pic);
                     } 
	         }

            $this->db->query("delete from ".CS_SqlPrefix."pl where CS_SID=1 and CS_DID in (".$id.")");  //评论
            $this->db->query("delete from ".CS_SqlPrefix."down where CS_DID in (".$id.")"); //下载
            $this->db->query("delete from ".CS_SqlPrefix."fav where CS_DID in (".$id.")");  //收藏
            $this->db->query("delete from ".CS_SqlPrefix."dt where cs_cid=1 and CS_DID in (".$id.")");  //动态
            $this->db->query("delete from ".CS_SqlPrefix."dance where CS_ID in (".$id.")");

            if(Cion_DelMusic>0 && $row[0]->CS_YID==0){
                //减去金币
                $this->db->query("update ".CS_SqlPrefix."user set CS_Cion=CS_Cion-".Cion_DelMusic." where cs_name='".$row[0]->CS_User."' and CS_Cion>0");
                //发送消息
                $msg['CS_Name']='歌曲删除消息';
                $msg['CS_Neir']=$row[0]->CS_User.'，您好，您的歌曲《'.$row[0]->CS_Name.'》被管理员删除，同时扣除您'.Cion_DelMusic.'个金币，如有问题，请联系管理员。';
                $msg['CS_Usera']=$row[0]->CS_User;
                $msg['CS_Userb']='管理员';
                $msg['CS_AddTime']=date('Y-m-d h:i:s');
                $this->CsdjDB->get_insert('xiaoxi',$msg);
            }
           
            $this->CsdjAdmin->Admin_Url('<font color=#0000ff>恭喜您，删除成功！</font>',$_SERVER['HTTP_REFERER'],'ok');
        }

	public function pldel()
	{
            $this->CsdjAdmin->Admin_Qx('8');
	    $ids=$this->input->post('CS_ID');
            if(empty($ids)) $this->CsdjAdmin->Admin_Url('<font color=red>参数错误，ID为空！</font>','javascript:history.back();');
            $id=implode(',', $ids);

	    $Arr=explode(',',$id);
            for($i=0;$i<count($Arr);$i++){
                 //-------------------------------删除歌曲文件---------------------------------------//
            if(Web_Mode==3){
                      $fileurl=$this->CsdjSkins->LinkUrl('play','dance','id',1,$Arr[$i]);
                      $fileurl=$this->CsdjAdmin->gethtmls($fileurl); //补全HTML地址
	              $fileurl=".".substr($fileurl,strlen(Web_Path));
		      @unlink($fileurl);
                 }

	         $row=$this->CsdjDB->get_select ('dance','CS_ID','CS_FID,CS_YID,CS_PlayUrl,CS_User,CS_Name',''.$Arr[$i].'');
	         if($row){
		     $purl=$row[0]->CS_PlayUrl;
                     if(FTP_Fun==1 && $row[0]->CS_FID){ //远程附件
                            $this->load->library('ftp');
                            $FTPUP['hostname'] = FTP_Server;
                            $FTPUP['port']     = FTP_Port;
                            $FTPUP['username'] = FTP_Name;
                            $FTPUP['password'] = FTP_Pass;
                            //$FTPUP['debug']    = TRUE;
                            $FTPUP['passive']  = FTP_Ive;

                            $Dirs=FTP_Dir;
                            if(substr($Dirs,0,1)=='/') $Dirs=substr($Dirs,1);
                            if(substr($Dirs,-1)=='/') $Dirs=substr($Dirs,0,-1);
                            if(!empty($Dirs)) $Dirs.='/';
		            $purl="/".$Dirs.$row[0]->CS_PlayUrl;

                            $this->ftp->connect($FTPUP);
                            $this->ftp->delete_file(".".$purl);  //删除歌曲远程数据
                            $this->ftp->close();
                     }else{
		            @unlink(".".$purl);
                     } 
	         }
                 if(Cion_DelMusic>0 && $row[0]->CS_YID==0){
                     //减去金币
                     $this->db->query("update ".CS_SqlPrefix."user set CS_Cion=CS_Cion-".Cion_DelMusic." where cs_name='".$row[0]->CS_User."' and CS_Cion>0");
                     //发送消息
                     $msg['CS_Name']='歌曲删除消息';
                     $msg['CS_Neir']=$row[0]->CS_User.'，您好，您的歌曲《'.$row[0]->CS_Name.'》被管理员删除，同时扣除您'.Cion_DelMusic.'个金币，如有问题，请联系管理员。';
                     $msg['CS_Usera']=$row[0]->CS_User;
                     $msg['CS_Userb']='管理员';
                     $msg['CS_AddTime']=date('Y-m-d h:i:s');
                     $this->CsdjDB->get_insert('xiaoxi',$msg);
                 }
            }

            $this->db->query("delete from ".CS_SqlPrefix."pl where CS_SID=1 and CS_DID in (".$id.")");  //评论
            $this->db->query("delete from ".CS_SqlPrefix."down where CS_DID in (".$id.")"); //下载
            $this->db->query("delete from ".CS_SqlPrefix."fav where CS_DID in (".$id.")");  //收藏
            $this->db->query("delete from ".CS_SqlPrefix."dt where cs_cid=1 and CS_DID in (".$id.")");  //动态
            $this->db->query("delete from ".CS_SqlPrefix."dance where CS_ID in (".$id.")");
            $this->CsdjAdmin->Admin_Url('<font color=#0000ff>恭喜您，删除成功！</font>',$_SERVER['HTTP_REFERER'],'ok');
        }


	public function html()
	{
            if(Web_Mode!=3) $this->CsdjAdmin->Admin_Url('<font color=red>网站为动态模式，不用生成！</font>','javascript:history.back();'); 
            $this->load->view('admin/dance_html');
        }

        //获取舞曲属性
	public function info()
	{
            $xtpath=$_SERVER['DOCUMENT_ROOT'];
	    $url=$this->input->get('url');
            $File=$xtpath.$url;
            if(!file_exists($File)) exit('no');
   	    if(substr(php_uname('s'),0,7)=="Windows"){ //LINUX系统暂时不支持
       		$player= new COM("WMPlayer.OCX");
       		$media = $player->newMedia($File);
       		$time = $media->duration; //获取持续时间
       		@$s_bitrate = $media->getItemInfo(Bitrate); //获取位速
       		@$size=$media->getItemInfo(FileSize);//大小 
       		$time = sprintf("%01.0f", $time);
       		$s_duration = strftime("%H:%M:%S",$time-28800);
       		$s_bitrate = str_replace(substr($s_bitrate,-3),"",$s_bitrate)." Kbps";
       		$s_size=$this->CsdjSkins->formatsize($size);
      		    echo $s_size.'|'.$s_bitrate.'|'.$s_duration;
   	    }else{
      		echo 'linux';
   	    }
        }
}

