<?php 
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Locoy extends CI_Controller {

	function __construct(){
		parent::__construct();
        $this->load->helper('url');
		$this->load->model('CsdjDB');
		$this->load->model('CsdjSkins');

        //免登入接口密码,默认为1234，请自行修改
        $this->pass='1234';

	}

    //分类列表
	public function lists()
	{

	    $sid=intval($this->input->get_post('sid',TRUE)); //版块类型,1为歌曲，2为文章，3为视频，4为歌手
        if($sid==0) $sid=1;

        echo "<select name='list'>";
        if($sid==1){
              $sqlstr="select CS_ID,CS_Name from ".CS_SqlPrefix."class where CS_SID=1 order by CS_XID asc";
        }elseif($sid==2){
              $sqlstr="select CS_ID,CS_Name from ".CS_SqlPrefix."class where CS_SID=2 order by CS_XID asc";
        }elseif($sid==3){
              $sqlstr="select CS_ID,CS_Name from ".CS_SqlPrefix."vlist order by CS_XID asc";
        }elseif($sid==4){
              $sqlstr="select CS_ID,CS_Name from ".CS_SqlPrefix."gslist order by CS_XID asc";
        }
		$result=$this->CsdjDB->db->query($sqlstr);
		$recount=$result->num_rows();
        if($recount>0){
			foreach ($result->result() as $row) {
                 echo "<option value='".$row->CS_ID."'>".$row->CS_Name."</option>\n";
            }
        }
        echo '</select>';
	}

    //入库
	public function ruku()
	{
        //判断密码
		$pass=$this->input->get_post('pass',TRUE);
        if($this->pass=='1234' || $pass!=$this->pass){
             die('密码错误');
        }


        //--------------------以下代码非专业人员不要修改----------------------

		$sid=intval($this->input->get_post('sid',TRUE)); //版块类型,1为歌曲，2为文章，3为视频，4为歌手
        if($sid==0) $sid=1;

                //-------------------歌曲------------------------//
                if($sid==1){

		            $data['CS_Color']=$this->input->post('CS_Color',TRUE);
		            $data['CS_CID']=intval($this->input->post('CS_CID',TRUE));
		            $data['CS_Tags']=$this->input->post('CS_Tags',TRUE);
		            $data['CS_Name']=$this->input->post('CS_Name',TRUE);
		            $data['CS_TID']=intval($this->input->post('CS_TID',TRUE));
		            $data['CS_Year']=$this->input->post('CS_Year',TRUE);
		            $data['CS_Singer']=$this->input->post('CS_Singer',TRUE);
		            $data['CS_User']=$this->input->post('CS_User',TRUE);
		            $data['CS_PID']=intval($this->input->post('CS_PID',TRUE));
		            $data['CS_FID']=intval($this->input->post('CS_FID',TRUE));
		            $data['CS_YID']=intval($this->input->post('CS_YID',TRUE));
		            $data['CS_Reco']=intval($this->input->post('CS_Reco',TRUE));
		            $data['CS_Cion']=intval($this->input->post('CS_Cion',TRUE));
                    $data['CS_Scion']=intval($this->input->post('CS_Scion',TRUE));
		            $data['CS_Vip']=intval($this->input->post('CS_Vip',TRUE));
		            $data['CS_Template']=$this->input->post('CS_Template',TRUE);
		            $data['CS_PlayUrl']=$this->input->post('CS_PlayUrl',TRUE);
		            $data['CS_DownUrl1']=$this->input->post('CS_DownUrl1',TRUE);
		            $data['CS_Dx']=$this->input->post('CS_Dx',TRUE);
		            $data['CS_Yz']=$this->input->post('CS_Yz',TRUE);
		            $data['CS_Sc']=$this->input->post('CS_Sc',TRUE);
		            $data['CS_Title']=$this->input->post('CS_Title',TRUE);
                    $data['CS_Content']=$this->input->post('CS_Content',TRUE);
		            $data['CS_Keywords']=$this->input->post('CS_Keywords',TRUE);
		            $data['CS_Description']=$this->input->post('CS_Description',TRUE);
		            if(empty($data['CS_User'])) $data['CS_User']='admin';
		            if(empty($data['CS_Template'])) $data['CS_Template']='dance-play.html';

		            //开始处理数据
		            if(empty($data['CS_Name']) || empty($data['CS_PlayUrl']) || $data['CS_CID']==0){
			            echo "数据不完整";
		            }else{
		                   //判断数据是否相同
                           $row=$this->CsdjDB->db->query("select CS_ID from ".CS_SqlPrefix."dance where CS_Name='".$data['CS_Name']."'")->row();
                           if($row){ //存在同名数据则修改

		                          $data2['CS_PlayUrl']=$data['CS_PlayUrl'];
		                          $data2['CS_DownUrl1']=$data['CS_DownUrl1'];
                                  $data2['CS_AddTime']=date('Y-m-d H:i:s');
                                  $this->CsdjDB->get_update('dance',$row->CS_ID,$data2);
                                  echo("已存在,覆盖信息成功");

						   }else{ //不存在则新增

                                  $data['CS_AddTime']=date('Y-m-d H:i:s');
                                  $id=$this->CsdjDB->get_insert('dance',$data);
                                  if($id>0){
                                         echo("增加信息成功");
                                  }else{
                                         echo("增加信息失败");
								  }
						   }
					}

                //-------------------文章------------------------//
                }elseif($sid==2){

		            $data['CS_Color']=$this->input->post('CS_Color',TRUE);
		            $data['CS_CID']=intval($this->input->post('CS_CID',TRUE));
		            $data['CS_Tags']=$this->input->post('CS_Tags',TRUE);
		            $data['CS_Name']=$this->input->post('CS_Name',TRUE);
		            $data['CS_TID']=intval($this->input->post('CS_TID',TRUE));
		            $data['CS_YID']=intval($this->input->post('CS_YID',TRUE));
		            $data['CS_User']=$this->input->post('CS_User',TRUE);
		            $data['CS_Reco']=intval($this->input->post('CS_Reco',TRUE));
		            $data['CS_Vip']=intval($this->input->post('CS_Vip',TRUE));
		            $data['CS_Hits']=intval($this->input->post('CS_Hits',TRUE));
		            $data['CS_Yhits']=intval($this->input->post('CS_Yhits',TRUE));
		            $data['CS_Zhits']=intval($this->input->post('CS_Zhits',TRUE));
		            $data['CS_Template']=$this->input->post('CS_Template',TRUE);
		            $data['CS_Title']=$this->input->post('CS_Title',TRUE);
		            $data['CS_Pic']=$this->input->post('CS_Pic',TRUE);
                    $data['CS_Content']=$this->input->post('CS_Content',TRUE);
		            $data['CS_Keywords']=$this->input->post('CS_Keywords',TRUE);
		            $data['CS_Description']=$this->input->post('CS_Description',TRUE);
		            if(empty($data['CS_User'])) $data['CS_User']='admin';
		            if(empty($data['CS_Template'])) $data['CS_Template']='news-show.html';

		            //开始处理数据
		            if(empty($data['CS_Name']) || empty($data['CS_Content']) || $data['CS_CID']==0){
			            echo "数据不完整";
		            }else{
		                   //判断数据是否相同
                           $row=$this->CsdjDB->db->query("select CS_ID from ".CS_SqlPrefix."news where CS_Name='".$data['CS_Name']."'")->row();
                           if($row){ //存在同名数据则修改

		                          $data2['CS_Content']=$data['CS_Content'];
                                  $data2['CS_AddTime']=date('Y-m-d H:i:s');
                                  $this->CsdjDB->get_update('news',$row->CS_ID,$data2);
                                  echo("已存在,覆盖信息成功");

						   }else{ //不存在则新增

                                   $data['CS_AddTime']=date('Y-m-d H:i:s');
                                   $id=$this->CsdjDB->get_insert('news',$data);
                                   if($id>0){
                                         echo("增加信息成功");
                                   }else{
                                         echo("增加信息失败");
                                   }
						   }
					}


                //-------------------视频------------------------//
                }elseif($sid==3){

		            $data['CS_Color']=$this->input->post('CS_Color');
		            $data['CS_CID']=intval($this->input->post('CS_CID'));
		            $data['CS_Tags']=$this->input->post('CS_Tags',TRUE);
		            $data['CS_Name']=$this->input->post('CS_Name',TRUE);
                    $data['CS_Pic']=$this->input->post('CS_Pic',TRUE);
                    $data['CS_Yany']=$this->input->post('CS_Yany',TRUE);
                    $data['CS_Daoy']=$this->input->post('CS_Daoy',TRUE);
                    $data['CS_Yuyan']=$this->input->post('CS_Yuyan',TRUE);
                    $data['CS_Diqu']=$this->input->post('CS_Diqu',TRUE);
                    $data['CS_Remark']=$this->input->post('CS_Remark',TRUE);
		            $data['CS_TID']=intval($this->input->post('CS_TID'));
		            $data['CS_YID']=intval($this->input->post('CS_YID',TRUE));
		            $data['CS_Year']=$this->input->post('CS_Year',TRUE);
		            $data['CS_User']=$this->input->post('CS_User',TRUE);
		            $data['CS_Laiy']=$this->input->post('CS_Laiy',TRUE);
		            $data['CS_FID']=intval($this->input->post('CS_FID'));
		            $data['CS_Reco']=intval($this->input->post('CS_Reco'));
		            $data['CS_Cion']=intval($this->input->post('CS_Cion'));
		            $data['CS_Vip']=intval($this->input->post('CS_Vip'));
		            $data['CS_Hits']=intval($this->input->post('CS_Hits'));
		            $data['CS_Yhits']=intval($this->input->post('CS_Yhits'));
		            $data['CS_Zhits']=intval($this->input->post('CS_Zhits'));
		            $data['CS_Template']=$this->input->post('CS_Template',TRUE);
		            $data['CS_Title']=$this->input->post('CS_Title',TRUE);
                    $data['CS_Content']=$this->input->post('CS_Content',TRUE);
		            $data['CS_Keywords']=$this->input->post('CS_Keywords',TRUE);
		            $data['CS_Description']=$this->input->post('CS_Description',TRUE);
		            if(empty($data['CS_User'])) $data['CS_User']='admin';
		            if(empty($data['CS_Template'])) $data['CS_Template']='vod-play.html';

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

                                 $All=explode("\n",$value);
                                 for($j=0;$j<count($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",$url);
                            $data['CS_PlayUrl']=substr($playurl,0,-7);
					}else{
                            $data['CS_PlayUrl']="第".($j+1)."集$".$strs."$".$playform;
					}
                    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'])));

                    if(empty($data['CS_Name'])||empty($data['CS_Laiy'])||empty($data['CS_PlayUrl'])){
			            echo "数据不完整";
		            }else{
		                          //判断数据是否相同
                                  $row=$this->CsdjDB->db->query("select CS_ID from ".CS_SqlPrefix."vod where CS_Name='".$data['CS_Name']."'")->row();
                                  if($row){ //存在同名数据则修改

		                          $data2['CS_Laiy']=$data['CS_Laiy'];
		                          $data2['CS_PlayUrl']=$data['CS_PlayUrl'];
		                          $data2['CS_Content']=$data['CS_Content'];
                                          $data2['CS_AddTime']=date('Y-m-d H:i:s');
                                          $this->CsdjDB->get_update('vod',$row->CS_ID,$data2);
                                          echo("已存在,覆盖信息成功");

                                   }else{ //不存在则新增

                                          $data['CS_AddTime']=date('Y-m-d H:i:s');
                                          $id=$this->CsdjDB->get_insert('vod',$data);
                                          if($id>0){
                                               echo("增加信息成功");
                                          }else{
                                               echo("增加信息失败");
                                          }
                                   }
                            }

                //-------------------歌手------------------------//
                }elseif($sid==4){

		            $data['CS_Color']=$this->input->post('CS_Color',TRUE);
		            $data['CS_CID']=intval($this->input->post('CS_CID'));
		            $data['CS_Name']=$this->input->post('CS_Name',TRUE);
		            $data['CS_TID']=intval($this->input->post('CS_TID'));
		            $data['CS_Hits']=intval($this->input->post('CS_Hits'));
		            $data['CS_Yhits']=intval($this->input->post('CS_Yhits'));
		            $data['CS_Zhits']=intval($this->input->post('CS_Zhits'));
		            $data['CS_Template']=$this->input->post('CS_Template',TRUE);
		            $data['CS_Pic']=$this->input->post('CS_Pic',TRUE);
                    $data['CS_Content']=$this->input->post('CS_Content',TRUE);
		            if(empty($data['CS_Template'])) $data['CS_Template']='singer-show.html';

		            //开始处理数据
		            if(empty($data['CS_Name']) || $data['CS_CID']==0){
			            echo "数据不完整";
		            }else{
		                   //判断数据是否相同
                                  $row=$this->CsdjDB->db->query("select CS_ID from ".CS_SqlPrefix."singer where CS_Name='".$data['CS_Name']."'")->row();
                                  if($row){ //存在同名数据则修改

                                          if(!empty($data['CS_Pic'])) $data2['CS_Pic']=$data['CS_Pic'];
		                          $data2['CS_Content']=$data['CS_Content'];
                                          $data2['CS_AddTime']=date('Y-m-d H:i:s');
                                          $this->CsdjDB->get_update('singer',$row->CS_ID,$data2);
                                          echo("已存在,覆盖信息成功");

                                   }else{ //不存在则新增

                                          $data['CS_AddTime']=date('Y-m-d H:i:s');
                                          $id=$this->CsdjDB->get_insert('singer',$data);
                                          if($id>0){
                                               echo("增加信息成功");
                                          }else{
                                               echo("增加信息失败");
                                          }
                                   }
                            }

                }else{
                       echo '版块类型错误';
                }
        }
}

