<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Vod 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."vod where cs_hid=0 order by CS_AddTime desc";
	    $query = $this->db->query($sql_string); 
	    $total = $query->num_rows();

            $base_url = site_url('admin/vod/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['vod'] = $query->result();
	    $data['pages'] = $this->CsdjAdmin->get_page($base_url,$totalPages,$page,10); //获取分页类

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

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

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

            $base_url = site_url('admin/vod/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['vod'] = $query->result();
	    $data['pages'] = $this->CsdjAdmin->get_page($base_url,$totalPages,$page,10); //获取分页类

            $this->load->view('admin/vod',$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."vod 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";
                  }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/vod/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['vod'] = $query->result();
	    $data['pages'] = $this->CsdjAdmin->get_page($base_url,$totalPages,$page,10); //获取分页类

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

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

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

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

            $base_url = site_url('admin/vod/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/vod_server',$data);
        }

	public function fwqadd()
	{
            $data['title']="新增";
            $data['CS_ID']=0;
            $data['CS_Name']="";
            $data['CS_Playip']="";
            $data['CS_Downip']="";
            $this->load->view('admin/vod_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/vod/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/vod_server_edit',$data);
        }

	public function fwqsave()
	{
            $this->CsdjAdmin->Admin_Qx('19');
            $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']=2;

            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/vod/fwqip/'),'ok');
        }

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

	    $sql_string = "SELECT * FROM ".CS_SqlPrefix."vod 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/vod/fwqip/'));
            }

            $this->CsdjDB->get_del('fwqip',$id);
            $this->CsdjAdmin->Admin_Url('<font color=#0000ff>恭喜您，删除成功！</font>',site_url('admin/vod/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=3 order by CS_AddTime desc";
	    $query = $this->db->query($sql_string); 
	    $total = $query->num_rows();

            $base_url = site_url('admin/vod/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/vod_zj',$data);
        }

	public function topicadd()
	{
            $data['title']="新增";
            $data['CS_ID']=0;
            $data['CS_Name']="";
            $data['CS_Pic']="";
            $data['CS_CID']=0;
            $data['CS_AliasName']="";
            $data['CS_Template']="topic-vod-show.html";
            $data['CS_Content']="";
            $data['CS_Fxgs']="";
            $data['CS_Yuyan']="国语";
            $data['CS_Year']=date('Y');
            $data['CS_User']="admin";
            $data['CS_Title']="";
            $data['CS_Keywords']="";
            $data['CS_Tags']="";
            $data['CS_Description']="";
            $this->load->view('admin/vod_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/vod/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_CID']=$row[0]->CS_CID;
                 $data['CS_AliasName']=$row[0]->CS_AliasName;
                 $data['CS_Template']=$row[0]->CS_Template;
                 $data['CS_Title']=$row[0]->CS_Title;
                 $data['CS_Tags']=$row[0]->CS_Tags;
                 $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/vod_zj_edit',$data);
        }

	public function topicsave()
	{
            $this->CsdjAdmin->Admin_Qx('20');
            $ids=$this->input->post('CS_ID', 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_Fxgs']=$this->input->post('CS_Fxgs', TRUE);
            $data['CS_Tags']=$this->input->post('CS_Tags', 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']=3;

            if(empty($data['CS_Template'])) $data['CS_Template']="topic-vod-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($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/vod/topic/'),'ok');
        }

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

            IF($this->CsdjSkins->gettopiccount($id,1)>0){
                 $this->CsdjAdmin->Admin_Url('<font color=red>该专集下有视频数据，请先移除视频！</font>',site_url('admin/vod/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=4 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/vod/topic/'),'ok');
        }

	public function topicdelall()
	{
            $this->CsdjAdmin->Admin_Qx('20');
	    $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;

                            $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;

                            $FTPUP['passive']  = FTP_Ive;
                            $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=4 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/vod/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']="vod-list.html";
            $data['CS_Template2']="vod-show.html";
            $data['CS_Title']="";
            $data['CS_Keywords']="";
            $data['CS_Description']="";
            $this->load->view('admin/vlist_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/vod/lists/'));
            $data['title']="修改";
            $sql="SELECT * FROM ".CS_SqlPrefix."vlist 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_Template2']=$row[0]->CS_Template2;
                 $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/vlist_edit',$data);
        }

	public function listssave()
	{
            $this->CsdjAdmin->Admin_Qx('18');
            $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_Template2=$this->input->post('CS_Template2', 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="vod-list.html";
            if(empty($CS_Template2)) $CS_Template2="vod-show.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_FID']=$CS_FID;
            $data['CS_XID']=$CS_XID;
            $data['CS_AliasName']=$CS_AliasName;
            $data['CS_Template']=$CS_Template;
            $data['CS_Template2']=$CS_Template2;
            $data['CS_Title']=$CS_Title;
            $data['CS_Keywords']=$CS_Keywords;
            $data['CS_Description']=$CS_Description;

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

	public function listspledit()
	{
            $this->CsdjAdmin->Admin_Qx('18');
            $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('vlist',$arr[$j],$data);
                  }
            }
            $this->CsdjAdmin->Admin_Url('<font color=#0000ff>恭喜您，操作成功！</font>',site_url('admin/vod/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/vod/lists/'));

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

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

            $this->CsdjDB->get_del('vlist',$id);
            $this->CsdjAdmin->Admin_Url('<font color=#0000ff>恭喜您，删除成功！</font>',site_url('admin/vod/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_Pic']="";
            $data['CS_Yany']="";
            $data['CS_Daoy']="";
			$data['CS_Vodurl']="";
			$data['CS_Wpfx']="";
			$data['CS_Wpfxmm']="";
            $data['CS_Yuyan']="";
            $data['CS_Diqu']="";
            $data['CS_Remark']="";
            $data['CS_Year']=date('Y');
            $data['CS_User']="admin";
            $data['CS_Cion']=0;
            $data['CS_Vip']=0;
            $data['CS_FID']=0;
            $data['CS_Laiy']="";
            $data['CS_PlayUrl']="";
            $data['CS_DownUrl']="";
            $data['CS_Content']="";
            $data['CS_Hits']=0;
            $data['CS_Yhits']=0;
            $data['CS_Zhits']=0;
            $data['CS_Intro']="";
            $data['CS_Template']="vod-play.html";
            $data['CS_Title']="";
            $data['CS_Keywords']="";
            $data['CS_Description']="";
            $this->load->view('admin/vod_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 ('vod','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_Pic']=$row[0]->CS_Pic;
            $data['CS_Yany']=$row[0]->CS_Yany;
            $data['CS_Daoy']=$row[0]->CS_Daoy;
			$data['CS_Vodurl']=$row[0]->CS_Vodurl;
			$data['CS_Wpfx']=$row[0]->CS_Wpfx;
			$data['CS_Wpfxmm']=$row[0]->CS_Wpfxmm;
            $data['CS_Yuyan']=$row[0]->CS_Yuyan;
            $data['CS_Diqu']=$row[0]->CS_Diqu;
            $data['CS_Remark']=$row[0]->CS_Remark;
            $data['CS_Year']=$row[0]->CS_Year;
            $data['CS_User']=$row[0]->CS_User;
            $data['CS_Cion']=$row[0]->CS_Cion;
            $data['CS_Vip']=$row[0]->CS_Vip;
            $data['CS_FID']=$row[0]->CS_FID;
            $data['CS_Laiy']=$row[0]->CS_Laiy;
            $data['CS_PlayUrl']=$row[0]->CS_PlayUrl;
            $data['CS_DownUrl']=$row[0]->CS_DownUrl;
            $data['CS_Intro']=$row[0]->CS_Intro;
            $data['CS_Content']=$row[0]->CS_Content;
            $data['CS_Hits']=$row[0]->CS_Hits;
            $data['CS_Yhits']=$row[0]->CS_Yhits;
            $data['CS_Zhits']=$row[0]->CS_Zhits;
            $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/vod_edit',$data);
	}

	public function save()
	{
                $this->CsdjAdmin->Admin_Qx('18');
                $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_Pic']=$this->input->post('CS_Pic');
                $data['CS_Yany']=$this->input->post('CS_Yany');
                $data['CS_Daoy']=$this->input->post('CS_Daoy');
				$data['CS_Vodurl']=$this->input->post('CS_Vodurl');
				$data['CS_Wpfx']=$this->input->post('CS_Wpfx');
				$data['CS_Wpfxmm']=$this->input->post('CS_Wpfxmm');
                $data['CS_Yuyan']=$this->input->post('CS_Yuyan');
                $data['CS_Diqu']=$this->input->post('CS_Diqu');
                $data['CS_Remark']=$this->input->post('CS_Remark');
		        $data['CS_TID']=$this->input->post('CS_TID');
		        $data['CS_Year']=$this->input->post('CS_Year');
		        $data['CS_User']=$this->input->post('CS_User');
		        $data['CS_Laiy']=$this->input->post('CS_Laiy');
		        $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_Vip']=$this->input->post('CS_Vip');
		        $data['CS_Hits']=$this->input->post('CS_Hits');
		        $data['CS_Yhits']=$this->input->post('CS_Yhits');
		        $data['CS_Zhits']=$this->input->post('CS_Zhits');
		        $data['CS_Template']=$this->input->post('CS_Template');
		        $data['CS_Intro']=$this->input->post('CS_Intro');
		        $data['CS_Title']=$this->input->post('CS_Title');
                $data['CS_Content']=$this->input->post('CS_Content');
		        $data['CS_Keywords']=$this->input->post('CS_Keywords');
		        $data['CS_Description']=$this->input->post('CS_Description');

                $url=$playurl="";
		        $playform=$this->input->post('cs_playfrom');
		        $strs=$this->input->post('CS_PlayUrl');
                $k=0;
                foreach ($strs as $value) {

                     $All=explode("\n",$value);
                     for($j=0;$j<count($All);$j++){	
						 if(!empty($All[$j])){
                             if(strpos($All[$j],'$') === FALSE){
                                 if(($j+1)==count($All)){
                                      $url.="第".($j+1)."集$".$All[$j]."$".$playform[$k];
                                 }else{
                                      $url.="第".($j+1)."集$".$All[$j]."$".$playform[$k]."\r\n";
                                 }
                             }else{
                                 if(($j+1)==count($All)){
                                      $url.=$All[$j];
                                 }else{
                                      $url.=$All[$j]."\r\n";
                                 }
							 }
						 }
					 }
					 $url.="#cscms#";
				}
                $k=$k+1;
                $playurl=str_replace("\r\r","\r",str_replace("\n\n","\n",$url));
                $data['CS_PlayUrl']=trim(substr($playurl,0,-7));

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

                if(empty($data['CS_Intro'])){
                    $data['CS_Intro']=$this->CsdjSkins->str_encode(sub_str($data['CS_Content'],250));
                }
                $data['CS_Intro']=trim($this->CsdjSkins->str_checkhtml($this->CsdjSkins->str_decode($data['CS_Intro'])));

                $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_Cion'])) $data['CS_Cion']=0;
                if(empty($data['CS_Hits'])) $data['CS_Hits']=0;
                if(empty($data['CS_Yhits'])) $data['CS_Yhits']=0;
                if(empty($data['CS_Zhits'])) $data['CS_Zhits']=0;
                if(empty($data['CS_Template'])) $data['CS_Template']='vod-play.html';

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

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

	public function plsave()
	{
            $this->CsdjAdmin->Admin_Qx('18');
            $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."vod set CS_Color='".$CS_Color."' where CS_ID in (".$CS_ID.")");
                                     }elseif($Arr[$i]=="CS_CID"){
                                         $this->db->query("update ".CS_SqlPrefix."vod set CS_CID=".$CS_CID." where CS_ID in (".$CS_ID.")");
                                     }elseif($Arr[$i]=="CS_YID"){
                                         $this->db->query("update ".CS_SqlPrefix."vod set CS_YID=".$CS_YID." where CS_ID in (".$CS_ID.")");
                                     }elseif($Arr[$i]=="CS_TID"){
                                         $this->db->query("update ".CS_SqlPrefix."vod set CS_TID=".$CS_TID." where CS_ID in (".$CS_ID.")");
                                     }elseif($Arr[$i]=="CS_FID"){
                                         $this->db->query("update ".CS_SqlPrefix."vod set CS_FID=".$CS_FID." where CS_ID in (".$CS_ID.")");
                                     }elseif($Arr[$i]=="CS_Reco"){
                                         $this->db->query("update ".CS_SqlPrefix."vod set CS_Reco=".$CS_Reco." where CS_ID in (".$CS_ID.")");
                                     }elseif($Arr[$i]=="CS_Cion"){
                                         $this->db->query("update ".CS_SqlPrefix."vod set CS_Cion=".$CS_Cion." where CS_ID in (".$CS_ID.")");
                                     }elseif($Arr[$i]=="CS_User"){
                                         $this->db->query("update ".CS_SqlPrefix."vod set CS_User='".$CS_User."' where CS_ID in (".$CS_ID.")");
                                     }elseif($Arr[$i]=="CS_Vip"){
                                         $this->db->query("update ".CS_SqlPrefix."vod set CS_Vip=".$CS_Vip." where CS_ID in (".$CS_ID.")");
                                     }elseif($Arr[$i]=="CS_Hits"){
                                         $this->db->query("update ".CS_SqlPrefix."vod set CS_Hits=".$CS_Hits." where CS_ID in (".$CS_ID.")");
                                     }elseif($Arr[$i]=="CS_Yhits"){
                                         $this->db->query("update ".CS_SqlPrefix."vod set CS_Yhits=".$CS_Yhits." where CS_ID in (".$CS_ID.")");
                                     }elseif($Arr[$i]=="CS_Zhits"){
                                         $this->db->query("update ".CS_SqlPrefix."vod set CS_Zhits=".$CS_Zhits." where CS_ID in (".$CS_ID.")");
                                     }elseif($Arr[$i]=="CS_Rhits"){
                                         $this->db->query("update ".CS_SqlPrefix."vod set CS_Rhits=".$CS_Rhits." where CS_ID in (".$CS_ID.")");
                                     }elseif($Arr[$i]=="CS_Xhits"){
                                         $this->db->query("update ".CS_SqlPrefix."vod set CS_Xhits=".$CS_Xhits." where CS_ID in (".$CS_ID.")");
                                     }elseif($Arr[$i]=="CS_Shits"){
                                         $this->db->query("update ".CS_SqlPrefix."vod set CS_Shits=".$CS_Shits." where CS_ID in (".$CS_ID.")");
                                     }elseif($Arr[$i]=="CS_Template"){
                                         $this->db->query("update ".CS_SqlPrefix."vod set CS_Template='".$CS_Template."' where CS_ID in (".$CS_ID.")");
                                     }elseif($Arr[$i]=="CS_HID"){
                                           if($CS_HID==2){
                                                  $this->db->query("delete from ".CS_SqlPrefix."vod where CS_ID in (".$CS_ID.")");
                                           }else{
                                                  $this->db->query("update ".CS_SqlPrefix."vod 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."vod set CS_Color='".$CS_Color."' where CS_CID in (".$CS_CIDS.")");
                                     }elseif($Arr[$i]=="CS_CID"){
                                         $this->db->query("update ".CS_SqlPrefix."vod set CS_CID=".$CS_CID." where CS_CID in (".$CS_CIDS.")");
                                     }elseif($Arr[$i]=="CS_YID"){
                                         $this->db->query("update ".CS_SqlPrefix."vod set CS_YID=".$CS_YID." where CS_CID in (".$CS_CIDS.")");
                                     }elseif($Arr[$i]=="CS_TID"){
                                         $this->db->query("update ".CS_SqlPrefix."vod set CS_TID=".$CS_TID." where CS_CID in (".$CS_CIDS.")");
                                     }elseif($Arr[$i]=="CS_FID"){
                                         $this->db->query("update ".CS_SqlPrefix."vod set CS_FID=".$CS_FID." where CS_CID in (".$CS_CIDS.")");
                                     }elseif($Arr[$i]=="CS_Reco"){
                                         $this->db->query("update ".CS_SqlPrefix."vod set CS_Reco=".$CS_Reco." where CS_CID in (".$CS_CIDS.")");
                                     }elseif($Arr[$i]=="CS_Cion"){
                                         $this->db->query("update ".CS_SqlPrefix."vod set CS_Cion=".$CS_Cion." where CS_CID in (".$CS_CIDS.")");
                                     }elseif($Arr[$i]=="CS_User"){
                                         $this->db->query("update ".CS_SqlPrefix."vod set CS_User='".$CS_User."' where CS_CID in (".$CS_CIDS.")");
                                     }elseif($Arr[$i]=="CS_Vip"){
                                         $this->db->query("update ".CS_SqlPrefix."vod set CS_Vip=".$CS_Vip." where CS_CID in (".$CS_CIDS.")");
                                     }elseif($Arr[$i]=="CS_Hits"){
                                         $this->db->query("update ".CS_SqlPrefix."vod set CS_Hits=".$CS_Hits." where CS_CID in (".$CS_CIDS.")");
                                     }elseif($Arr[$i]=="CS_Yhits"){
                                         $this->db->query("update ".CS_SqlPrefix."vod set CS_Yhits=".$CS_Yhits." where CS_CID in (".$CS_CIDS.")");
                                     }elseif($Arr[$i]=="CS_Zhits"){
                                         $this->db->query("update ".CS_SqlPrefix."vod set CS_Zhits=".$CS_Zhits." where CS_CID in (".$CS_CIDS.")");
                                     }elseif($Arr[$i]=="CS_Rhits"){
                                         $this->db->query("update ".CS_SqlPrefix."vod set CS_Rhits=".$CS_Rhits." where CS_CID in (".$CS_CIDS.")");
                                     }elseif($Arr[$i]=="CS_Xhits"){
                                         $this->db->query("update ".CS_SqlPrefix."vod set CS_Xhits=".$CS_Xhits." where CS_CID in (".$CS_CIDS.")");
                                     }elseif($Arr[$i]=="CS_Shits"){
                                         $this->db->query("update ".CS_SqlPrefix."vod set CS_Shits=".$CS_Shits." where CS_CID in (".$CS_CIDS.")");
                                     }elseif($Arr[$i]=="CS_Template"){
                                         $this->db->query("update ".CS_SqlPrefix."vod set CS_Template='".$CS_Template."' where CS_CID in (".$CS_CIDS.")");
                                     }elseif($Arr[$i]=="CS_HID"){
                                           if($CS_HID==2){
                                                  $this->db->query("delete from ".CS_SqlPrefix."vod where CS_CID in (".$CS_CIDS.")");
                                           }else{
                                                  $this->db->query("update ".CS_SqlPrefix."vod 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."vod set CS_Color='".$CS_Color."' where CS_FID in (".$CS_FIDS.")");
                                     }elseif($Arr[$i]=="CS_CID"){
                                         $this->db->query("update ".CS_SqlPrefix."vod set CS_CID=".$CS_CID." where CS_FID in (".$CS_FIDS.")");
                                     }elseif($Arr[$i]=="CS_YID"){
                                         $this->db->query("update ".CS_SqlPrefix."vod set CS_YID=".$CS_YID." where CS_FID in (".$CS_FIDS.")");
                                     }elseif($Arr[$i]=="CS_TID"){
                                         $this->db->query("update ".CS_SqlPrefix."vod set CS_TID=".$CS_TID." where CS_FID in (".$CS_FIDS.")");
                                     }elseif($Arr[$i]=="CS_FID"){
                                         $this->db->query("update ".CS_SqlPrefix."vod set CS_FID=".$CS_FID." where CS_FID in (".$CS_FIDS.")");
                                     }elseif($Arr[$i]=="CS_Reco"){
                                         $this->db->query("update ".CS_SqlPrefix."vod set CS_Reco=".$CS_Reco." where CS_FID in (".$CS_FIDS.")");
                                     }elseif($Arr[$i]=="CS_Cion"){
                                         $this->db->query("update ".CS_SqlPrefix."vod set CS_Cion=".$CS_Cion." where CS_FID in (".$CS_FIDS.")");
                                     }elseif($Arr[$i]=="CS_User"){
                                         $this->db->query("update ".CS_SqlPrefix."vod set CS_User='".$CS_User."' where CS_FID in (".$CS_FIDS.")");
                                     }elseif($Arr[$i]=="CS_Vip"){
                                         $this->db->query("update ".CS_SqlPrefix."vod set CS_Vip=".$CS_Vip." where CS_FID in (".$CS_FIDS.")");
                                     }elseif($Arr[$i]=="CS_Hits"){
                                         $this->db->query("update ".CS_SqlPrefix."vod set CS_Hits=".$CS_Hits." where CS_FID in (".$CS_FIDS.")");
                                     }elseif($Arr[$i]=="CS_Yhits"){
                                         $this->db->query("update ".CS_SqlPrefix."vod set CS_Yhits=".$CS_Yhits." where CS_FID in (".$CS_FIDS.")");
                                     }elseif($Arr[$i]=="CS_Zhits"){
                                         $this->db->query("update ".CS_SqlPrefix."vod set CS_Zhits=".$CS_Zhits." where CS_FID in (".$CS_FIDS.")");
                                     }elseif($Arr[$i]=="CS_Rhits"){
                                         $this->db->query("update ".CS_SqlPrefix."vod set CS_Rhits=".$CS_Rhits." where CS_FID in (".$CS_FIDS.")");
                                     }elseif($Arr[$i]=="CS_Xhits"){
                                         $this->db->query("update ".CS_SqlPrefix."vod set CS_Xhits=".$CS_Xhits." where CS_FID in (".$CS_FIDS.")");
                                     }elseif($Arr[$i]=="CS_Shits"){
                                         $this->db->query("update ".CS_SqlPrefix."vod set CS_Shits=".$CS_Shits." where CS_FID in (".$CS_FIDS.")");
                                     }elseif($Arr[$i]=="CS_Template"){
                                         $this->db->query("update ".CS_SqlPrefix."vod set CS_Template='".$CS_Template."' where CS_FID in (".$CS_FIDS.")");
                                     }elseif($Arr[$i]=="CS_HID"){
                                           if($CS_HID==2){
                                                  $this->db->query("delete from ".CS_SqlPrefix."vod where CS_FID in (".$CS_FIDS.")");
                                           }else{
                                                  $this->db->query("update ".CS_SqlPrefix."vod 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('18');
            $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('show','vod','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('vod','CS_ID','CS_YID,CS_Pic,CS_PlayUrl,CS_User,CS_Name',''.$id.'');
	         if($row){
		     $purl=$row[0]->CS_PlayUrl;
		     $pic="/attachment/vod/".$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;
                            $this->ftp->connect($FTPUP);

                            $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/vod/".$row[0]->CS_Pic;

                            $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=3 and CS_DID in (".$id.")");  //评论
            $this->db->query("delete from ".CS_SqlPrefix."dt where cs_cid=2 and CS_DID in (".$id.")");  //动态
            $this->db->query("delete from ".CS_SqlPrefix."vod where CS_ID in (".$id.")");

                 if(Cion_DelVod>0 && $row[0]->CS_YID==0){
                     //减去金币
                     $this->db->query("update ".CS_SqlPrefix."user set CS_Cion=CS_Cion-".Cion_DelVod." 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_DelVod.'个金币，如有问题，请联系管理员。';
                     $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('18');
	        $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('show','vod','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 ('vod','CS_ID','CS_YID,CS_Pic,CS_PlayUrl,CS_User,CS_Name',''.$Arr[$i].'');
	         if($row){
		     $purl=$row[0]->CS_PlayUrl;
		     $pic="/attachment/vod/".$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.='/';
		            $purl="/".$Dirs.$row[0]->CS_PlayUrl;
		            $pic="/".$Dirs."attachment/vod/".$row[0]->CS_Pic;

                            $this->ftp->connect($FTPUP);
                            $this->ftp->delete_file(".".$purl);  //删除歌曲远程数据
                            $this->ftp->delete_file(".".$pic);
                            $this->ftp->close();
                     }else{

		            @unlink(".".$purl);
		            @unlink(".".$pic);

                     }
	         }
                 if(Cion_DelVod>0 && $row[0]->CS_YID==0){
                     //减去金币
                     $this->db->query("update ".CS_SqlPrefix."user set CS_Cion=CS_Cion-".Cion_DelVod." 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_DelVod.'个金币，如有问题，请联系管理员。';
                     $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=3 and CS_DID in (".$id.")");  //评论
            $this->db->query("delete from ".CS_SqlPrefix."dt where cs_cid=2 and CS_DID in (".$id.")");  //动态
            $this->db->query("delete from ".CS_SqlPrefix."vod 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/vod_html');
	}

    //批量下载远程图片
	public function downpic()
	{
 	        $page = $this->input->get('page');
            if(empty($page)) $page=1;
            echo '<LINK href="'.base_url().'csdj/admin/images/admin.css" type="text/css" rel="stylesheet"><br>';

	        $sql_string = "SELECT CS_ID,CS_Pic FROM ".CS_SqlPrefix."vod where cs_hid=0 and  Lower(Left(CS_Pic,7))='http://' order by CS_AddTime desc";
	        $query = $this->db->query($sql_string); 
	        $total = $query->num_rows();

	        $per_page = 20; 
            $totalPages = ceil($total / $per_page); // 总页数
	        $data['nums'] = $total;
            if($total<$per_page){
               $per_page=$total;
            }

            if($page>$totalPages){
                 exit("&nbsp;&nbsp;&nbsp;&nbsp;<font style='font-size:12px;color:red'><b>恭喜您，所有远程图片同步完毕．．．．．．</b></font><script language='javascript'>setTimeout('ReadGo();',".(3000).");function ReadGo(){location.href='".site_url('admin/vod')."';}</script>");
            }

            $sql_string.=' limit '. $per_page*($page-1) .','. $per_page;
	        $query = $this->db->query($sql_string);
	        echo("&nbsp;<b>正在开始同步第<font style='color:red; font-size:12px; font-style:italic'>".$page."</font>页，剩<font style='color:red; font-size:12px; font-style:italic'>".$totalPages."</font>页</b><br>");
 	        foreach ($query->result() as $row) { 
                  if(!empty($row->CS_Pic)){
                       $picdata = @file_get_contents($row->CS_Pic); // 读文件内容
                       $picfolder ="./attachment/vod/".date('Ymd')."/";
                       $picname=date('Ymd').time().mt_rand(1,100).".jpg";
                       if(!empty($picdata)){

                            write_file($picfolder.$picname, $picdata);

                            //判断水印
                            if(CS_WaterMark==1){
		                           $this->load->model('CsdjPic');
                                   $this->CsdjPic->imageWaterMark($picfolder.$picname);
                            }

                            if(FTP_Fun==1){  //开启远程附件

                                  $FTPUP['hostname'] = FTP_Server;
                                  $FTPUP['port']     = FTP_Port;
                                  $FTPUP['username'] = FTP_Name;
                                  $FTPUP['password'] = FTP_Pass;
                                  $FTPUP['passive']  = FTP_Ive;
                                  $this->ftp->connect($FTPUP);


                                  //----------创建目录------------------------
                                  $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.='/';
                                  $All=explode("/",$picfolder);
                                  $Dir1='./'.$Dirs.$All[1].'/';
                                  $this->ftp->mkdir($Dir1, DIR_WRITE_MODE); 
                                  $Dir2=$Dir1.$All[2].'/';
                                  $this->ftp->mkdir($Dir2, DIR_WRITE_MODE); 
                                  $Dir3=$Dir2.$All[3].'/';
                                  $this->ftp->mkdir($Dir3, DIR_WRITE_MODE); 

                                  //----------上传文件------------------------
                                  $this->ftp->upload($picfolder.$picname, $Dir3.$picname);
                                  $this->ftp->close();
                                  //删除本地附件
                                  @unlink($picfolder.$picname);

                             }

                             //修改数据库
                             $this->db->query("update ".CS_SqlPrefix."vod set CS_Pic='".date('Ymd')."/".$picname."' where CS_ID=".$row->CS_ID."");
                             echo "&nbsp;&nbsp;&nbsp;&nbsp;<font style=font-size:12px;>同步<font color=red>".$row->CS_Pic."</font>图片成功!<a href=\"".Web_Path."attachment/vod/".date('Ymd')."/".$picname."\" target=_blank>".$picname."</a></font></br>";						
                       }else{
                             //修改数据库
                             $this->db->query("update ".CS_SqlPrefix."vod set CS_Pic='' where CS_ID=".$row->CS_ID."");
                             echo "&nbsp;&nbsp;&nbsp;&nbsp;<font color=red style=font-size:12px;>".$row->CS_Pic."</font>远程图片不存在!</br>";
                       }
                  }
				  ob_flush();flush();
 	        }
	        echo "&nbsp;&nbsp;&nbsp;&nbsp;<font style=font-size:12px;>第".$page."页图片同步完毕,暂停3秒后继续同步．．．．．．</font><script language='javascript'>setTimeout('ReadGo();',".(3000).");function ReadGo(){location.href='".site_url('admin/vod/downpic/')."?page=".($page+1)."';}</script>";	
	}
}

