<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Html 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('CsdjAdmin');
		    $this->load->model('CsdjSkins');
	        $this->CsdjAdmin->Admin_Login();
            $this->load->helper('file');
	}

	public function index()
	{
            $this->CsdjAdmin->Admin_Qx('17');
            $this->load->get_templates();
		    $template=$this->load->view('cs-index.html','',true);
            $data=$this->CsdjSkins->skins($template,'',true);

            if(empty($data)) die('Error,<a href="javascript:location.reload()">点我刷新重试!</a>');

            $html="./".Html_Index;
            if ( ! write_file($html, $data)){
                 echo '<a href="'.str_replace('//','/',Web_Path.Html_Index).'" target="_blank">'.$html.'文件没有写入权限！</a>';
            }else{
                 echo '<a href="'.str_replace('//','/',Web_Path.Html_Index).'" target="_blank">网站首页生成成功！</a>';
            }
    }

	public function dance()
	{
		    $this->load->model('CsdjDance');
            $this->CsdjAdmin->Admin_Qx('11');
            $data['title']='歌曲';
	        $op = $this->input->get('op');
	        $t = $this->input->get('t');
	        $id = $this->input->get('id');
	        $page = $this->input->get('page');
            if(empty($page)) $page=1;

            if($op=='index'){ //主页

                      $data=$this->CsdjDance->index();
                      if(empty($data)) die('Error,<a href="javascript:location.reload()">点我刷新重试!</a>');

                      $html=".".Html_Dindex;
                      $html=$this->CsdjAdmin->gethtmls($html); //补全HTML地址
                      if ( ! write_file($html, $data)){
                           echo '<a href="'.str_replace('//','/',Web_Path.substr($html,1)).'" target="_blank">'.$html.'文件没有写入权限！</a>';
                      }else{
                           echo '<a href="'.str_replace('//','/',Web_Path.substr($html,1)).'" target="_blank">歌曲首页生成成功！</a>';
                      }

            }elseif($op=='play'){ //播放页
                  if($t=='id'){
	                  $ksid = $this->input->get_post('ksid');
	                  $jsid = $this->input->get_post('jsid');
                      $sqlstr="select * from ".CS_SqlPrefix."dance where CS_ID>".($ksid-1)." and CS_ID<".($jsid+1)." and CS_YID=0 and CS_HID=0";
		              $result=$this->CsdjDB->db->query($sqlstr);
		              $recount=$result->num_rows();

                         if($recount==0 || $page>$jsid || $id==-1){
                              echo '发布完成！ID从'.$ksid.'到'.$jsid.'的共发布'.$recount.'个歌曲记录。<p><a href="'.site_url('admin/dance/html').'">继续发布</a></p><script type="text/javascript">parent.TokeymakeMsg(\'msg_content\',\'发布完成！ID从'.$ksid.'到'.$jsid.'的共发布'.$recount.'个歌曲记录。\');parent.Dialog.close();</script>';
                         }else{

                              if(empty($id)){
		                            $rows=$this->CsdjDB->get_all($sqlstr);
                                    $id=$rows[0]->CS_ID;
                              }

                              $row=$this->CsdjDB->get_select ('dance','CS_ID','*',''.$id.'');
                              $neir=$this->CsdjDance->play('id',$id,$row);
                              if(empty($neir)) die('Error,<a href="javascript:location.reload()">点我刷新重试!</a>');

                              $html=".".$this->CsdjSkins->LinkUrl('play','dance','id',1,$id,1,2);
                              $html=$this->CsdjAdmin->gethtmls($html); //补全HTML地址

                              if ( ! write_file($html, $neir)){
                                    die(''.$html.'文件没有写入权限！');
                              }

                              //下一个ID
                              $sql="Select CS_ID from ".CS_SqlPrefix."dance where CS_ID>".$id." and CS_YID=0 and CS_HID=0 order by CS_ID asc";
		                      $row=$this->CsdjDB->get_all($sql);
                              if(!$row){
                                  $data['xid']=-1; //下ID
                              }else{
                                  $data['xid']=$row[0]->CS_ID; //下ID
                              }

                              $xpage=$page+1;

                              $data['jind']=intval($page/$recount*100); //进度条

                              $data['xlink']=site_url('admin/html/dance/')."?op=play&t=id&ksid=".$ksid."&jsid=".$jsid."&page=".$xpage."&id=".$data['xid'];


                              $data['nums']=$recount;
                              $data['link']=$html;
                              $data['id']=$id;
                              $data['page']=$page;
                              $this->load->get_admin_templates();
                              $this->load->view('admin/html',$data);
                         }

                  }elseif($t=='news'){ //最新多少个

	                     $topn = $this->input->get_post('topn');
                         if(empty($topn)) $topn=10;

                         $sqlstr="select * from ".CS_SqlPrefix."dance where CS_YID=0 and CS_HID=0 order by CS_AddTime desc limit ".$topn."";
		                 $result=$this->CsdjDB->db->query($sqlstr);
		                 $recount=$result->num_rows();

                         if($recount==0 || $page>$recount){
                              echo '成功发布最新'.$topn.'首歌曲，实际完成'.$recount.'个歌曲记录。<p><a href="'.site_url('admin/dance/html').'">继续发布</a></p>';
                         }else{

                               if(empty($id)){
		                            $rows=$this->CsdjDB->get_all($sqlstr);
                                    $id=$rows[0]->CS_ID;
                               }
 
                               $row=$this->CsdjDB->get_select ('dance','CS_ID','*',''.$id.'');
                               $neir=$this->CsdjDance->play('id',$id,$row);
                               if(empty($neir)) die('Error,<a href="javascript:location.reload()">点我刷新重试!</a>');

                               $html=".".$this->CsdjSkins->LinkUrl('play','dance','id',1,$id,1,2);
                               $html=$this->CsdjAdmin->gethtmls($html); //补全HTML地址

                               if ( ! write_file($html, $neir)){
                                 die(''.$html.'文件没有写入权限！');
                               }

                              //下一个ID
                              $sql="Select CS_ID from ".CS_SqlPrefix."dance where CS_ID<".$id." and CS_YID=0 and CS_HID=0 order by CS_ID desc";
		                      $row=$this->CsdjDB->get_all($sql);
                              if($row){
                                 $data['xid']=$row[0]->CS_ID; //下ID
                              }else{
                                 $data['xid']=-1; //下ID
                              }

                              $xpage=$page+1;

                              $data['xid']=$row[0]->CS_ID; //下ID
                              $data['jind']=intval($page/$recount*100); //进度条

                              $data['xlink']=site_url('admin/html/dance/')."?op=play&t=news&topn=".$topn."&page=".$xpage."&id=".$data['xid'];

                              $data['nums']=$recount;
                              $data['link']=$html;
                              $data['id']=$id;
                              $data['page']=$page;
                              $this->load->get_admin_templates();
                              $this->load->view('admin/html',$data);
                         }

                  }elseif($t=='date'){ //按时间生成
	                     $ksdate = $this->input->get_post('ksdate');
	                     $jsdate = $this->input->get_post('jsdate');
                         $ksdates = date("Y-m-d",mktime(00,00,01,date("m",strtotime($ksdate)),date("d",strtotime($ksdate))-1,date("Y",strtotime($ksdate))));
                         $jsdates = date("Y-m-d",mktime(00,00,01,date("m",strtotime($jsdate)),date("d",strtotime($jsdate))+1,date("Y",strtotime($jsdate))));

                         $sqlstr="select * from ".CS_SqlPrefix."dance where CS_AddTime > '{$ksdates}' and CS_AddTime < '{$jsdates}' and CS_YID=0 and CS_HID=0 order by CS_AddTime desc";
		                 $result=$this->CsdjDB->db->query($sqlstr);
		                 $recount=$result->num_rows();

                         if($recount==0 || $page>$recount || $id==-1){
                              echo '发布完成！日期从:'.$ksdate.'到'.$jsdate.'的共发布'.$recount.'首歌曲记录。<p><a href="'.site_url('admin/dance/html').'">继续发布</a></p>';
                         }else{

                               if(empty($id)){
		                            $rows=$this->CsdjDB->get_all($sqlstr);
                                    $id=$rows[0]->CS_ID;
                               }

                               $row=$this->CsdjDB->get_select ('dance','CS_ID','*',''.$id.'');
                               $neir=$this->CsdjDance->play('id',$id,$row);
                               if(empty($neir)) die('Error,<a href="javascript:location.reload()">点我刷新重试!</a>');

                               $html=".".$this->CsdjSkins->LinkUrl('play','dance','id',1,$id,1,2);
                               $html=$this->CsdjAdmin->gethtmls($html); //补全HTML地址

                               if ( ! write_file($html, $neir)){
                                 die(''.$html.'文件没有写入权限！');
                               }

                              //下一个ID
                              $sql="Select CS_ID from ".CS_SqlPrefix."dance where CS_ID<".$id." and CS_AddTime>='{$ksdates}' and CS_AddTime<='{$jsdates}' and CS_YID=0 and CS_HID=0 order by CS_ID desc";
		                      $row=$this->CsdjDB->get_all($sql);
                              if($row){
                                     $data['xid']=$row[0]->CS_ID; //下ID
                              }else{
                                     $data['xid']=-1; //下ID
                              }

                              $xpage=$page+1;
                              $data['jind']=intval($page/$recount*100); //进度条

                              $data['xlink']=site_url('admin/html/dance/')."?op=play&t=date&ksdate=".$ksdate."&jsdate=".$jsdate."&page=".$xpage."&id=".$data['xid'];


                              $data['nums']=$recount;
                              $data['link']=$html;
                              $data['id']=$id;
                              $data['page']=$page;
                              $this->load->get_admin_templates();
                              $this->load->view('admin/html',$data);
                         }

                  }elseif($t=='lists'){ //按分类生成
	                     $cid = $this->input->get_post('cid');
	                     $topn = $this->input->get_post('topn');
                         if(empty($topn)) $topn=10;
                         if(empty($cid)) $this->CsdjAdmin->Admin_Url('<font color=red>请选择分类！</font>',site_url('admin/dance/html/'));

                         if (is_array($cid)){
                              $cids=implode(',', $cid);
                         }else{
                              $cids=$cid;
                         }
                         $classname='';
                         $Arr=explode(',',$cids);
                         for($i=0;$i<count($Arr);$i++){
                                $classname.=$this->CsdjSkins->getclass($Arr[$i])."、";
                         }
                         $sqlstr="select * from ".CS_SqlPrefix."dance where CS_CID in (".$cids.") and CS_YID=0 and CS_HID=0 order by CS_AddTime desc limit ".$topn."";
		                 $result=$this->CsdjDB->db->query($sqlstr);
		                 $recount=$result->num_rows();

                         if($recount==0 || $page>$recount || $id==-1){
                              echo '成功发布['.$classname.']分类最新'.$recount.'首歌曲记录。<p><a href="'.site_url('admin/dance/html').'">继续发布</a></p>';
                         }else{

                               if(empty($id)){
		                            $rows=$this->CsdjDB->get_all($sqlstr);
                                    $id=$rows[0]->CS_ID;
                               }

                               $row=$this->CsdjDB->get_select ('dance','CS_ID','*',''.$id.'');
                               $neir=$this->CsdjDance->play('id',$id,$row);
                               if(empty($neir)) die('Error,<a href="javascript:location.reload()">点我刷新重试!</a>');

                               $html=".".$this->CsdjSkins->LinkUrl('play','dance','id',1,$id,1,2);
                               $html=$this->CsdjAdmin->gethtmls($html); //补全HTML地址

                               if ( ! write_file($html, $neir)){
                                    die(''.$html.'文件没有写入权限！');
                               }

                              //下一个ID
                              $sql="Select CS_ID from ".CS_SqlPrefix."dance where CS_ID<".$id." and  CS_CID in (".$cids.") and CS_YID=0 and CS_HID=0 order by CS_ID desc";
		                      $row=$this->CsdjDB->get_all($sql);
                              if($row){
                                     $data['xid']=$row[0]->CS_ID; //下ID
                              }else{
                                     $data['xid']=-1; //下ID
                              }

                              $xpage=$page+1;

                              $data['jind']=intval($page/$recount*100); //进度条

                              $data['xlink']=site_url('admin/html/dance/')."?op=play&t=lists&cid=".$cids."&topn=".$topn."&page=".$xpage."&id=".$data['xid'];


                              $data['nums']=$recount;
                              $data['link']=$html;
                              $data['id']=$id;
                              $data['page']=$page;
                              $this->load->get_admin_templates();
                              $this->load->view('admin/html',$data);
                         }


                  }elseif($t=='all'){ //生成全部播放

                         $sqlstr="select * from ".CS_SqlPrefix."dance where CS_YID=0 and CS_HID=0 order by CS_AddTime desc";
		                 $result=$this->CsdjDB->db->query($sqlstr);
		                 $recount=$result->num_rows();

                         if($recount==0 || $page>$recount){
                              echo '发布完成！全部共发布'.$recount.'首歌曲记录。<script type="text/javascript">parent.TokeymakeMsg(\'msg_play\',\'发布完成！全部共发布'.$recount.'首歌曲记录。\');parent.Dialog.close();parent.Dialog.close();</script><p><a href="'.site_url('admin/dance/html').'">继续发布</a></p>';
                         }else{

                               if(empty($id)){
		                            $rows=$this->CsdjDB->get_all($sqlstr);
                                    $id=$rows[0]->CS_ID;
                               }

                               $row=$this->CsdjDB->get_select ('dance','CS_ID','*',''.$id.'');
                               $neir=$this->CsdjDance->play('id',$id,$row);
                               if(empty($neir)) die('Error,<a href="javascript:location.reload()">点我刷新重试!</a>');

                               $html=".".$this->CsdjSkins->LinkUrl('play','dance','id',1,$id,1,2);
                               $html=$this->CsdjAdmin->gethtmls($html); //补全HTML地址

                               if ( ! write_file($html, $neir)){
                                 die(''.$html.'文件没有写入权限！');
                               }

                              //下一个ID
                              $sql="Select CS_ID from ".CS_SqlPrefix."dance where CS_ID<".$id." and CS_YID=0 and CS_HID=0 order by CS_ID desc";
		                      $row=$this->CsdjDB->get_all($sql);
                              $xpage=$page+1;

                              $data['xid']=$row[0]->CS_ID; //下ID
                              $data['jind']=intval($page/$recount*100); //进度条

                              $data['xlink']=site_url('admin/html/dance/')."?op=play&t=all&page=".$xpage."&id=".$row[0]->CS_ID;

                              $data['nums']=$recount;
                              $data['link']=$html;
                              $data['id']=$id;
                              $data['page']=$page;
                              $this->load->get_admin_templates();
                              $this->load->view('admin/html',$data);
                         }
                  }

            }elseif($op=='list'){ //分类页  
   
	              $nums = $this->input->get('nums');
	              $cgid = $this->input->get('cgid');
	              $xid = $this->input->get('xid');
                  if(empty($cgid)) $cgid=1; 
                  if(empty($xid)) $xid=0; 

                  $Title=array("按ID","按总人气","按每月人气","按每周人气","按每日人气","按被顶人气","按下载人气","按收藏人气","按推荐星际","按正在播放","按更新时间");
                  $Type=array("id","hits","yue","zhou","ri","ding","down","fav","reco","play","new");


                  if($t=='all'){  //所有分类

                        if(empty($id)){
                            $sqlstr="select * from ".CS_SqlPrefix."class where CS_SID=1 and CS_YID=0 order by CS_ID desc";
		                    $result=$this->CsdjDB->db->query($sqlstr);
		                    $recount=$result->num_rows();
                            if($recount==0){
                                   echo "暂时没有分类记录！<script type=\"text/javascript\">parent.TokeymakeMsg('msg_list','暂时没有分类记录！');parent.Dialog.close();</script>";
                                   exit();
                            }
                         }else{
                            $recount=$nums;
                            $sqlstr="select * from ".CS_SqlPrefix."class where cs_id=".$id."";
                         }
		                 $row=$this->CsdjDB->get_all($sqlstr);
                         if($row){
                                   $id=$row[0]->CS_ID;
                                   if(empty($row[0]->CS_Template)){
                                         $CS_Template='dance-list.html';
                                   }else{
                                         $CS_Template=$row[0]->CS_Template;
                                   }
                                    //获取分页标签
                                    $CS_Template="./skins/".Skins_dir.$CS_Template;
		                            $template=read_file($CS_Template);
		                            preg_match_all('/{cscms:dance(.*?pagesize=([\S]+).*?)}([\s\S]+?){\/cscms:dance}/',$template,$page_arr);//判断是否有分页标识
		                            if(!empty($page_arr) && !empty($page_arr[2])){
                                           $per_page=$page_arr[2][0];
                                    }else{
                                           echo "模板里没有使用歌曲分页标签！<script type=\"text/javascript\">parent.TokeymakeMsg('msg_list','模板里没有使用歌曲分页标签！');parent.Dialog.close();</script>";
                                           exit();
                                    }
                                    if(empty($per_page)) $per_page=10; 

                                     //下一个ID
                                     $sql="Select CS_ID from ".CS_SqlPrefix."class where CS_ID<".$id." and CS_YID=0  order by CS_ID desc";
		                             $rows=$this->CsdjDB->get_all($sql);
                                     if($rows){
                                          $data['xid']=$rows[0]->CS_ID; //下ID
                                     }else{
                                          $data['xid']=0; //下ID
                                     }

                                    $cid=$this->CsdjSkins->getChild($id);
                                    $sql="select * from ".CS_SqlPrefix."dance where CS_CID in(".$cid.") and CS_YID=0 and CS_HID=0";
		                            $query=$this->db->query($sql);
		                            $nums=$query->num_rows();
                                    if($nums==0) $nums=1; 
                                    $pagejs=ceil($nums / $per_page); // 总页数

                                    $data['cname']=$row[0]->CS_Name."->".$Title[$xid]."排序";
                                    $data['nums']=$recount;
                                    $data['pagejs']=$pagejs;
                                    $data['ok']='no';
                                    $data['cgid']=$cgid;
                                    $data['page']=$page;
                                    $data['jind']=intval($page/$pagejs*100); //进度条

                                     //------------------------------生成-----------------------------

                                     $neir=$this->CsdjDance->lists($Type[$xid],$id,$page,$row);
                                     if(empty($neir)) die('Error,<a href="javascript:location.reload()">点我刷新重试!</a>');

                                     $html=".".$this->CsdjSkins->LinkUrl('lists','dance',$Type[$xid],$id,1,$page,2);
                                     $html=$this->CsdjAdmin->gethtmls($html); //补全HTML地址

                                     if ( ! write_file($html, $neir)){
                                       die("文件没有写入权限！<script type=\"text/javascript\">parent.TokeymakeMsg('msg_list','文件没有写入权限！');parent.Dialog.close();</script>");
                                     }


                                    if($pagejs>$page){
                                               $data['xlink']=site_url('admin/html/dance/')."?op=list&t=all&id=".$id."&cgid=".($cgid+1)."&xid=".$xid."&nums=".$recount."&page=".($page+1)."";
                                    }else{
                                         if($data['xid']==0){
                                               $data['ok']='yes';
                                               $data['type']='msg_list';
                                               $data['neir']="共发布[歌曲分类]模块".$recount."个分类列表页，".$cgid."个页面。";
                                          }else{
                                               $data['xlink']=site_url('admin/html/dance/')."?op=list&t=all&id=".$data['xid']."&cgid=".($cgid+1)."&xid=".$xid."&nums=".$recount."";
                                          }
                                    }
                             }else{
                                    $data['ok']='yes';
                                    $data['neir']="共发布[歌曲分类]模块".$recount."个分类列表页，".$cgid."个页面。";
                             }
                             $this->load->get_admin_templates();
                             $this->load->view('admin/html_list',$data);

                  }elseif($t=='id'){
	               $cid = $this->input->get_post('cid');
	               $xid = $this->input->get('xid');
	               $sort = $this->input->get_post('sort');
                       if(empty($xid)) $xid=0; 
                       if(empty($cid)) $this->CsdjAdmin->Admin_Url('<font color=red>请选择分类！</font>',site_url('admin/dance/html/'));

                       if($sort=='hits'){
                                   $title='总人气';
                       }elseif($sort=='ri'){
                                   $title='日人气';
                       }elseif($sort=='zhou'){
                                   $title='周人气';
                       }elseif($sort=='yue'){
                                   $title='月人气';
                       }elseif($sort=='fav'){
                                   $title='收藏人气';
                       }elseif($sort=='down'){
                                   $title='下载人气';
                       }elseif($sort=='ding'){
                                   $title='被顶人气';
                       }elseif($sort=='play'){
                                   $title='正在播放';
                       }elseif($sort=='reco'){
                                   $title='推荐星际';
                       }elseif($sort=='id'){
                                   $title='ID';
                       }else{
                                   $title='最新更新';
                       }

                         if (is_array($cid)){
                              $cids=implode(',', $cid);
                              $cid=$cids;
                              $Arr=explode(',',$cids);
                              $id=$Arr[0];
                              $count=count($Arr);
                         }else{
                              $cid=$cid;
                              $Arr=explode(',',$cid);
                              $id=$id;
                              $count=$nums;
                         }
                            $sqlstr="select * from ".CS_SqlPrefix."class where cs_id=".$id."";
		                    $row=$this->CsdjDB->get_all($sqlstr);
                            if($row){
                                   $id=$row[0]->CS_ID;
                                   if(empty($row[0]->CS_Template)){
                                         $CS_Template='dance-list.html';
                                   }else{
                                         $CS_Template=$row[0]->CS_Template;
                                   }
                                    //获取分页标签
                                    $CS_Template="./skins/".Skins_dir.$CS_Template;
		                    $template=read_file($CS_Template);
		                    preg_match_all('/{cscms:dance(.*?pagesize=([\S]+).*?)}([\s\S]+?){\/cscms:dance}/',$template,$page_arr);//判断是否有分页标识
		                    if(!empty($page_arr) && !empty($page_arr[2])){
                                           $per_page=$page_arr[2][0];
                                    }else{
                                           echo "模板里没有使用专题分页标签！<script type=\"text/javascript\">parent.TokeymakeMsg('msg_list','模板里没有使用歌曲分页标签！');parent.Dialog.close();</script>";
                                           exit();
                                    }
                                    if(empty($per_page)) $per_page=10; 

                                    $cidc=$this->CsdjSkins->getChild($id);
                                    $sql="select * from ".CS_SqlPrefix."dance where CS_CID in(".$cidc.") and CS_YID=0 and CS_HID=0";
		                    $query=$this->db->query($sql);
		                    $nums=$query->num_rows();
                                    if($nums==0) $nums=1; 
                                    $pagejs=ceil($nums / $per_page); // 总页数

                                    $data['cname']=$row[0]->CS_Name."->".$title."排序";
                                    $data['nums']=$count;
                                    $data['pagejs']=$pagejs;
                                    $data['ok']='no';
                                    $data['cgid']=$cgid;
                                    $data['page']=$page;
                                    $data['jind']=intval($page/$pagejs*100); //进度条

                                     //------------------------------生成-----------------------------

                                     $neir=$this->CsdjDance->lists($sort,$id,$page,$row);
                                     if(empty($neir)) die('Error,<a href="javascript:location.reload()">点我刷新重试!</a>');

                                     $html=".".$this->CsdjSkins->LinkUrl('lists','dance',$sort,$id,1,$page,2);
                                     $html=$this->CsdjAdmin->gethtmls($html); //补全HTML地址

                                     if ( ! write_file($html, $neir)){
                                       die("文件没有写入权限！<script type=\"text/javascript\">parent.TokeymakeMsg('msg_list','文件没有写入权限！');parent.Dialog.close();</script>");
                                     }

                                    if($data['pagejs']>$page){
                                               $data['xlink']=site_url('admin/html/dance/')."?op=list&t=id&id=".$id."&cgid=".($cgid+1)."&cid=".$cid."&xid=".$xid."&nums=".$count."&page=".($page+1)."&sort=".$sort."";
                                    }else{
                                         if($xid==($count-1)){
                                              $data['ok']='yes';
                                              $data['type']='msg_list';
                                              $data['neir']="共发布[歌曲分类]模块".$count."个分类列表页，".$cgid."个页面。";
                                         }else{
                                               $data['xlink']=site_url('admin/html/dance/')."?op=list&t=id&id=".$Arr[($xid+1)]."&cgid=".($cgid+1)."&cid=".$cid."&xid=".$xid."&nums=".$count."&xid=".($xid+1)."&sort=".$sort."";
                                         }
                                    }
                             }
                             $this->load->get_admin_templates();
                             $this->load->view('admin/html_list',$data);

                  }

            }
	}

	public function news()
	{
		    $this->load->model('CsdjNews');
            $this->CsdjAdmin->Admin_Qx('16');
            $data['title']='文章';
	        $op = $this->input->get('op');
	        $t = $this->input->get('t');
	        $id = $this->input->get('id');
	        $page = $this->input->get('page');
            if(empty($page)) $page=1;

            if($op=='index'){ //主页

                      $data=$this->CsdjNews->index();
                      if(empty($data)) die('Error,<a href="javascript:location.reload()">点我刷新重试!</a>');

                      $html=".".Html_Nindex;
                      $html=$this->CsdjAdmin->gethtmls($html); //补全HTML地址
                      if ( ! write_file($html, $data)){
                           echo '<a href="'.str_replace('//','/',Web_Path.substr($html,1)).'" target="_blank">'.$html.'文件没有写入权限！</a>';
                      }else{
                           echo '<a href="'.str_replace('//','/',Web_Path.substr($html,1)).'" target="_blank">文章首页生成成功！</a>';
                      }

            }elseif($op=='show'){ //内容页
                  if($t=='id'){
	                 $ksid = $this->input->get_post('ksid');
	                 $jsid = $this->input->get_post('jsid');

                         $sqlstr="select * from ".CS_SqlPrefix."news where CS_ID>".($ksid-1)." and CS_ID<".($jsid+1)." and CS_YID=0 and CS_HID=0";
		         $result=$this->CsdjDB->db->query($sqlstr);
		         $recount=$result->num_rows();

                         if($recount==0 || $page>$jsid || $id==-1){
                              echo '发布完成！ID从'.$ksid.'到'.$jsid.'的共发布'.$recount.'个文章记录。<p><a href="'.site_url('admin/news/html').'">继续发布</a></p><script type="text/javascript">parent.TokeymakeMsg(\'msg_content\',\'发布完成！ID从'.$ksid.'到'.$jsid.'的共发布'.$recount.'个文章记录。\');parent.Dialog.close();</script>';
                         }else{

                               if(empty($id)){
		                    $rows=$this->CsdjDB->get_all($sqlstr);
                                    $id=$rows[0]->CS_ID;
                               }

                               $row=$this->CsdjDB->get_select ('news','CS_ID','*',''.$id.'');
                               $neir=$this->CsdjNews->show('id',$id,$row);

                               if(empty($neir)) die('Error,<a href="javascript:location.reload()">点我刷新重试!</a>');

                               $html=".".$this->CsdjSkins->LinkUrl('show','news','id',1,$id,1,2);
                               $html=$this->CsdjAdmin->gethtmls($html); //补全HTML地址

                               if ( ! write_file($html, $neir)){
                                 die(''.$html.'文件没有写入权限！');
                               }


                              //下一个ID
                              $sql="Select CS_ID from ".CS_SqlPrefix."news where CS_ID>".$id." and CS_YID=0 and CS_HID=0 order by CS_ID asc";
		                      $row=$this->CsdjDB->get_all($sql);
                              if(!$row){
                                  $data['xid']=-1; //下ID
                              }else{
                                  $data['xid']=$row[0]->CS_ID; //下ID
                              }

                              $xpage=$page+1;

                              $data['jind']=intval($page/$recount*100); //进度条

                              $data['xlink']=site_url('admin/html/news/')."?op=show&t=id&ksid=".$ksid."&jsid=".$jsid."&page=".$xpage."&id=".$data['xid'];


                              $data['nums']=$recount;
                              $data['link']=$html;
                              $data['id']=$id;
                              $data['page']=$page;
                              $this->load->get_admin_templates();
                              $this->load->view('admin/html',$data);
                         }

                  }elseif($t=='news'){ //最新多少个

	                 $topn = $this->input->get_post('topn');
                         if(empty($topn)) $topn=10;

                         $sqlstr="select * from ".CS_SqlPrefix."news where CS_YID=0 and CS_HID=0 order by CS_AddTime desc limit ".$topn."";
		         $result=$this->CsdjDB->db->query($sqlstr);
		         $recount=$result->num_rows();

                         if($recount==0 || $page>$recount){
                              echo '成功发布最新'.$topn.'首文章，实际完成'.$recount.'个文章记录。<p><a href="'.site_url('admin/news/html').'">继续发布</a></p>';
                         }else{

                               if(empty($id)){
		                    $rows=$this->CsdjDB->get_all($sqlstr);
                                    $id=$rows[0]->CS_ID;
                               }

                               $row=$this->CsdjDB->get_select ('news','CS_ID','*',''.$id.'');
                               $neir=$this->CsdjNews->show('id',$id,$row);

                               if(empty($neir)) die('Error,<a href="javascript:location.reload()">点我刷新重试!</a>');

                               $html=".".$this->CsdjSkins->LinkUrl('show','news','id',1,$id,1,2);
                               $html=$this->CsdjAdmin->gethtmls($html); //补全HTML地址

                               if ( ! write_file($html, $neir)){
                                 die(''.$html.'文件没有写入权限！');
                               }

                              //下一个ID
                              $sql="Select CS_ID from ".CS_SqlPrefix."news where CS_ID<".$id." and CS_YID=0 and CS_HID=0 order by CS_ID desc";
		              $row=$this->CsdjDB->get_all($sql);
                              if($row){
                                 $data['xid']=$row[0]->CS_ID; //下ID
                              }else{
                                 $data['xid']=-1; //下ID
                              }

                              $xpage=$page+1;

                              $data['jind']=intval($page/$recount*100); //进度条

                              $data['xlink']=site_url('admin/html/news/')."?op=show&t=news&topn=".$topn."&page=".$xpage."&id=".$data['xid'];


                              $data['nums']=$recount;
                              $data['link']=$html;
                              $data['id']=$id;
                              $data['page']=$page;
                              $this->load->get_admin_templates();
                              $this->load->view('admin/html',$data);
                         }

                  }elseif($t=='date'){ //按时间生成
	                 $ksdate = $this->input->get_post('ksdate');
	                 $jsdate = $this->input->get_post('jsdate');
                         $ksdates = date("Y-m-d",mktime(00,00,01,date("m",strtotime($ksdate)),date("d",strtotime($ksdate))-1,date("Y",strtotime($ksdate))));
                         $jsdates = date("Y-m-d",mktime(00,00,01,date("m",strtotime($jsdate)),date("d",strtotime($jsdate))+1,date("Y",strtotime($jsdate))));


                         $sqlstr="select * from ".CS_SqlPrefix."news where CS_AddTime>='{$ksdates}' and CS_AddTime<='{$jsdates}' and CS_YID=0 and CS_HID=0 order by CS_AddTime desc";
		         $result=$this->CsdjDB->db->query($sqlstr);
		         $recount=$result->num_rows();

                         if($recount==0 || $page>$recount || $id==-1){
                              echo '发布完成！日期从:'.$ksdate.'到'.$ksdate.'的共发布'.$recount.'首文章记录。<p><a href="'.site_url('admin/news/html').'">继续发布</a></p>';
                         }else{

                               if(empty($id)){
		                    $rows=$this->CsdjDB->get_all($sqlstr);
                                    $id=$rows[0]->CS_ID;
                               }

                               $row=$this->CsdjDB->get_select ('news','CS_ID','*',''.$id.'');
                               $neir=$this->CsdjNews->show('id',$id,$row);

                               if(empty($neir)) die('Error,<a href="javascript:location.reload()">点我刷新重试!</a>');

                               $html=".".$this->CsdjSkins->LinkUrl('show','news','id',1,$id,1,2);
                               $html=$this->CsdjAdmin->gethtmls($html); //补全HTML地址

                               if ( ! write_file($html, $neir)){
                                 die(''.$html.'文件没有写入权限！');
                               }

                              //下一个ID
                              $sql="Select CS_ID from ".CS_SqlPrefix."news where CS_ID<".$id." and CS_AddTime>='{$ksdates}' and CS_AddTime<='{$jsdates}' and CS_YID=0 and CS_HID=0 order by CS_ID desc";
		              $row=$this->CsdjDB->get_all($sql);
                              if($row){
                                     $data['xid']=$row[0]->CS_ID; //下ID
                              }else{
                                     $data['xid']=-1; //下ID
                              }

                              $xpage=$page+1;
                              $data['jind']=intval($page/$recount*100); //进度条

                              $data['xlink']=site_url('admin/html/news/')."?op=show&t=date&ksdate=".$ksdate."&jsdate=".$jsdate."&page=".$xpage."&id=".$data['xid'];


                              $data['nums']=$recount;
                              $data['link']=$html;
                              $data['id']=$id;
                              $data['page']=$page;
                              $this->load->get_admin_templates();
                              $this->load->view('admin/html',$data);
                         }

                  }elseif($t=='lists'){ //按分类生成
	                 $cid = $this->input->get_post('cid');
	                 $topn = $this->input->get_post('topn');
                         if(empty($topn)) $topn=10;
                         if(empty($cid)) $this->CsdjAdmin->Admin_Url('<font color=red>请选择分类！</font>',site_url('admin/news/html/'));

                         if (is_array($cid)){
                              $cids=implode(',', $cid);
                         }else{
                              $cids=$cid;
                         }
                         $classname='';
                         $Arr=explode(',',$cids);
                         for($i=0;$i<count($Arr);$i++){
                                $classname.=$this->CsdjSkins->getclass($Arr[$i])."、";
                         }
                         $sqlstr="select * from ".CS_SqlPrefix."news where CS_CID in (".$cids.") and CS_YID=0 and CS_HID=0 order by CS_AddTime desc limit ".$topn."";
		         $result=$this->CsdjDB->db->query($sqlstr);
		         $recount=$result->num_rows();

                         if($recount==0 || $page>$recount || $id==-1){
                              echo '成功发布['.$classname.']分类最新'.$recount.'首文章记录。<p><a href="'.site_url('admin/news/html').'">继续发布</a></p>';
                         }else{

                               if(empty($id)){
		                    $rows=$this->CsdjDB->get_all($sqlstr);
                                    $id=$rows[0]->CS_ID;
                               }

                               $row=$this->CsdjDB->get_select ('news','CS_ID','*',''.$id.'');
                               $neir=$this->CsdjNews->show('id',$id,$row);
                               if(empty($neir)) die('Error,<a href="javascript:location.reload()">点我刷新重试!</a>');

                               $html=".".$this->CsdjSkins->LinkUrl('show','news','id',1,$id,1,2);
                               $html=$this->CsdjAdmin->gethtmls($html); //补全HTML地址

                               if ( ! write_file($html, $neir)){
                                 die(''.$html.'文件没有写入权限！');
                               }

                              //下一个ID
                              $sql="Select CS_ID from ".CS_SqlPrefix."news where CS_ID<".$id." and  CS_CID in (".$cids.") and CS_YID=0 and CS_HID=0 order by CS_ID desc";
		              $row=$this->CsdjDB->get_all($sql);
                              if($row){
                                     $data['xid']=$row[0]->CS_ID; //下ID
                              }else{
                                     $data['xid']=-1; //下ID
                              }

                              $xpage=$page+1;
                              $data['jind']=intval($page/$recount*100); //进度条

                              $data['xlink']=site_url('admin/html/news/')."?op=show&t=lists&cid=".$cids."&topn=".$topn."&page=".$xpage."&id=".$data['xid'];


                              $data['nums']=$recount;
                              $data['link']=$html;
                              $data['id']=$id;
                              $data['page']=$page;
                              $this->load->get_admin_templates();
                              $this->load->view('admin/html',$data);
                         }


                  }elseif($t=='all'){ //生成全部播放

                         $sqlstr="select * from ".CS_SqlPrefix."news where CS_YID=0 and CS_HID=0 order by CS_AddTime desc";
		         $result=$this->CsdjDB->db->query($sqlstr);
		         $recount=$result->num_rows();

                         if($recount==0 || $page>$recount){
                              echo '发布完成！全部共发布'.$recount.'首文章记录。<script type="text/javascript">parent.TokeymakeMsg(\'msg_show\',\'发布完成！全部共发布'.$recount.'首文章记录。\');parent.Dialog.close();parent.Dialog.close();</script><p><a href="'.site_url('admin/news/html').'">继续发布</a></p>';
                         }else{

                               if(empty($id)){
		                    $rows=$this->CsdjDB->get_all($sqlstr);
                                    $id=$rows[0]->CS_ID;
                               }

                               $row=$this->CsdjDB->get_select ('news','CS_ID','*',''.$id.'');
                               $neir=$this->CsdjNews->show('id',$id,$row);
                               if(empty($neir)) die('Error,<a href="javascript:location.reload()">点我刷新重试!</a>');

                               $html=".".$this->CsdjSkins->LinkUrl('show','news','id',1,$id,1,2);
                               $html=$this->CsdjAdmin->gethtmls($html); //补全HTML地址

                               if ( ! write_file($html, $neir)){
                                 die(''.$html.'文件没有写入权限！');
                               }

                              //下一个ID
                              $sql="Select CS_ID from ".CS_SqlPrefix."news where CS_ID<".$id." and CS_YID=0 and CS_HID=0 order by CS_ID desc";
		              $row=$this->CsdjDB->get_all($sql);

                              $xpage=$page+1;

                              $data['xid']=$row[0]->CS_ID; //下ID
                              $data['jind']=intval($page/$recount*100); //进度条

                              $data['xlink']=site_url('admin/html/news/')."?op=show&t=all&page=".$xpage."&id=".$row[0]->CS_ID;


                              $data['nums']=$recount;
                              $data['link']=$html;
                              $data['id']=$id;
                              $data['page']=$page;
                              $this->load->get_admin_templates();
                              $this->load->view('admin/html',$data);
                         }
                  }


            }elseif($op=='list'){ //分类页  
   
	          $nums = $this->input->get('nums');
	          $cgid = $this->input->get('cgid');
	          $xid = $this->input->get('xid');
                  if(empty($cgid)) $cgid=1; 
                  if(empty($xid)) $xid=0; 

                  $Title=array("按ID","按总人气","按每月人气","按每周人气","按每日人气","按推荐星际","按更新时间");
                  $Type=array("id","hits","yue","zhou","ri","reco","new");


                  if($t=='all'){  //所有分类

                        if(empty($id)){
                            $sqlstr="select * from ".CS_SqlPrefix."class where CS_SID=2 and CS_YID=0 order by CS_ID desc";
		            $result=$this->CsdjDB->db->query($sqlstr);
		            $recount=$result->num_rows();
                            if($recount==0){
                                   echo "暂时没有分类记录！<script type=\"text/javascript\">parent.TokeymakeMsg('msg_list','暂时没有分类记录！');parent.Dialog.close();</script>";
                                   exit();
                            }
                         }else{
                            $recount=$nums;
                            $sqlstr="select * from ".CS_SqlPrefix."class where cs_id=".$id."";
                         }
		            $row=$this->CsdjDB->get_all($sqlstr);
                            if($row || $id==0){
                                   $id=$row[0]->CS_ID;
                                   if(empty($row[0]->CS_Template)){
                                         $CS_Template='news-list.html';
                                   }else{
                                         $CS_Template=$row[0]->CS_Template;
                                   }
                                    //获取分页标签
                                    $CS_Template="./skins/".Skins_dir.$CS_Template;
		                    $template=read_file($CS_Template);
		                    preg_match_all('/{cscms:news(.*?pagesize=([\S]+).*?)}([\s\S]+?){\/cscms:news}/',$template,$page_arr);//判断是否有分页标识
		                    if(!empty($page_arr) && !empty($page_arr[2])){
                                           $per_page=$page_arr[2][0];
                                    }else{
                                           $per_page=50;
                                    }
                                    if(empty($per_page)) $per_page=10; 

                                     //下一个ID
                                     $sql="Select CS_ID from ".CS_SqlPrefix."class where CS_ID<".$id." and CS_SID=2 and CS_YID=0  order by CS_ID desc";
		                     $rows=$this->CsdjDB->get_all($sql);
                                     if($rows){
                                          $data['xid']=$rows[0]->CS_ID; //下ID
                                     }else{
                                          $data['xid']=0; //下ID
                                     }

                                    $cid=$this->CsdjSkins->getChild($id);
                                    $sql="select * from ".CS_SqlPrefix."news where CS_CID in(".$cid.") and CS_YID=0 and CS_HID=0";
		                    $query=$this->db->query($sql);
		                    $nums=$query->num_rows();
                                    if($nums==0) $nums=1; 
                                    $pagejs=ceil($nums / $per_page); // 总页数

                                    $data['cname']=$row[0]->CS_Name."->".$Title[$xid]."排序";
                                    $data['nums']=$recount;
                                    $data['pagejs']=$pagejs;
                                    $data['ok']='no';
                                    $data['cgid']=$cgid;
                                    $data['page']=$page;
                                    $data['jind']=intval($page/$pagejs*100); //进度条

                                     //------------------------------生成-----------------------------

                                     $neir=$this->CsdjNews->lists($Type[$xid],$id,$page,$row);

                                     if(empty($neir)) die('Error,<a href="javascript:location.reload()">点我刷新重试!</a>');

                                     $html=".".$this->CsdjSkins->LinkUrl('lists','news',$Type[$xid],$id,1,$page,2);
                                     $html=$this->CsdjAdmin->gethtmls($html); //补全HTML地址

                                     if ( ! write_file($html, $neir)){
                                       die("文件没有写入权限！<script type=\"text/javascript\">parent.TokeymakeMsg('msg_list','文件没有写入权限！');parent.Dialog.close();</script>");
                                     }

                                    if($pagejs>$page){
                                               $data['xlink']=site_url('admin/html/news/')."?op=list&t=all&id=".$id."&cgid=".($cgid+1)."&xid=".$xid."&nums=".$recount."&page=".($page+1)."";
                                    }else{
                                         if($data['xid']==0){
                                               $data['ok']='yes';
                                               $data['neir']="共发布[文章分类]模块".$recount."个分类列表页，".$cgid."个页面。";
                                         }else{
                                               $data['xlink']=site_url('admin/html/news/')."?op=list&t=all&id=".$data['xid']."&cgid=".($cgid+1)."&xid=".$xid."&nums=".$recount."";
                                         }
                                    }
                             }else{
                                    $data['ok']='yes';
                                    $data['neir']="共发布[文章分类]模块".$recount."个分类列表页，".$cgid."个页面。";
                             }
                             $this->load->get_admin_templates();
                             $this->load->view('admin/html_list',$data);

                  }elseif($t=='id'){
	               $cid = $this->input->get_post('cid');
	               $xid = $this->input->get('xid');
	               $sort = $this->input->get_post('sort');
                       if(empty($xid)) $xid=0; 
                       if(empty($cid)) $this->CsdjAdmin->Admin_Url('<font color=red>请选择分类！</font>',site_url('admin/news/html/'));

                       if($sort=='hits'){
                                   $title='总人气';
                       }elseif($sort=='ri'){
                                   $title='日人气';
                       }elseif($sort=='zhou'){
                                   $title='周人气';
                       }elseif($sort=='yue'){
                                   $title='月人气';
                       }elseif($sort=='reco'){
                                   $title='推荐星际';
                       }elseif($sort=='id'){
                                   $title='ID';
                       }else{
                                   $title='最新更新';
                       }

                         if (is_array($cid)){
                              $cids=implode(',', $cid);
                              $cid=$cids;
                              $Arr=explode(',',$cids);
                              $id=$Arr[0];
                              $count=count($Arr);
                         }else{
                              $cid=$cid;
                              $Arr=explode(',',$cid);
                              $id=$id;
                              $count=$nums;
                         }
                            $sqlstr="select * from ".CS_SqlPrefix."class where cs_id=".$id."";
		            $row=$this->CsdjDB->get_all($sqlstr);
                            if($row){
                                   $id=$row[0]->CS_ID;
                                   if(empty($row[0]->CS_Template)){
                                         $CS_Template='news-list.html';
                                   }else{
                                         $CS_Template=$row[0]->CS_Template;
                                   }
                                    //获取分页标签
                                    $CS_Template="./skins/".Skins_dir.$CS_Template;
		                    $template=read_file($CS_Template);
		                    preg_match_all('/{cscms:news(.*?pagesize=([\S]+).*?)}([\s\S]+?){\/cscms:news}/',$template,$page_arr);//判断是否有分页标识
		                    if(!empty($page_arr) && !empty($page_arr[2])){
                                           $per_page=$page_arr[2][0];
                                    }else{
                                           $per_page=50;
                                    }
                                    if(empty($per_page)) $per_page=10; 

                                    $cidc=$this->CsdjSkins->getChild($id);
                                    $sql="select * from ".CS_SqlPrefix."news where CS_CID in(".$cidc.") and CS_YID=0 and CS_HID=0";
		                    $query=$this->db->query($sql);
		                    $nums=$query->num_rows();
                                    if($nums==0) $nums=1; 
                                    $pagejs=ceil($nums / $per_page); // 总页数

                                    $data['cname']=$row[0]->CS_Name."->".$title."排序";
                                    $data['nums']=$count;
                                    $data['pagejs']=$pagejs;
                                    $data['ok']='no';
                                    $data['cgid']=$cgid;
                                    $data['page']=$page;
                                    $data['jind']=intval($page/$pagejs*100); //进度条

                                     //------------------------------生成-----------------------------

                                     $neir=$this->CsdjDance->lists($sort,$id,$page,$row);

                                     if(empty($neir)) die('Error,<a href="javascript:location.reload()">点我刷新重试!</a>');

                                     $html=".".$this->CsdjSkins->LinkUrl('lists','news',$sort,$id,1,$page,2);
                                     $html=$this->CsdjAdmin->gethtmls($html); //补全HTML地址

                                     if ( ! write_file($html, $neir)){
                                       die("文件没有写入权限！<script type=\"text/javascript\">parent.TokeymakeMsg('msg_list','文件没有写入权限！');parent.Dialog.close();</script>");
                                     }

                                    if($data['pagejs']>$page){
                                               $data['xlink']=site_url('admin/html/news/')."?op=list&t=id&id=".$id."&cgid=".($cgid+1)."&cid=".$cid."&xid=".$xid."&nums=".$count."&page=".($page+1)."&sort=".$sort."";
                                    }else{
                                         if($xid==($count-1)){
                                              $data['ok']='yes';
                                              $data['type']='msg_list';
                                              $data['neir']="共发布[文章分类]模块".$count."个分类列表页，".$cgid."个页面。";
                                         }else{
                                               $data['xlink']=site_url('admin/html/news/')."?op=list&t=id&id=".$Arr[($xid+1)]."&cgid=".($cgid+1)."&cid=".$cid."&xid=".$xid."&nums=".$count."&xid=".($xid+1)."&sort=".$sort."";
                                         }
                                    }
                             }
							 $this->load->get_admin_templates();
                             $this->load->view('admin/html_list',$data);

                  }

            }
	}


	public function vod()
	{
		    $this->load->model('CsdjVod');
            $this->CsdjAdmin->Admin_Qx('21');
            $data['title']='视频';
	    $op = $this->input->get('op');
	    $t = $this->input->get('t');
	    $id = $this->input->get('id');
	    $page = $this->input->get('page');
            if(empty($page)) $page=1;

            if($op=='index'){ //主页

                      $data=$this->CsdjVod->index();
                      if(empty($data)) die('Error,<a href="javascript:location.reload()">点我刷新重试!</a>');

                      $html=".".Html_Vindex;
                      $html=$this->CsdjAdmin->gethtmls($html); //补全HTML地址
                      if ( ! write_file($html, $data)){
                           echo '<a href="'.str_replace('//','/',Web_Path.substr($html,1)).'" target="_blank">'.$html.'文件没有写入权限！</a>';
                      }else{
                           echo '<a href="'.str_replace('//','/',Web_Path.substr($html,1)).'" target="_blank">视频首页生成成功！</a>';
                      }

            }elseif($op=='show'){ //内容页
                  if($t=='id'){
	                 $ksid = $this->input->get_post('ksid');
	                 $jsid = $this->input->get_post('jsid');

                         $sqlstr="select * from ".CS_SqlPrefix."vod where CS_ID>".($ksid-1)." and CS_ID<".($jsid+1)." and CS_YID=0 and CS_HID=0";
		         $result=$this->CsdjDB->db->query($sqlstr);
		         $recount=$result->num_rows();

                         if($recount==0 || $page>$jsid || $id==-1){
                              echo '发布完成！ID从'.$ksid.'到'.$jsid.'的共发布'.$recount.'个视频记录。<p><a href="'.site_url('admin/vod/html').'">继续发布</a></p><script type="text/javascript">parent.TokeymakeMsg(\'msg_content\',\'发布完成！ID从'.$ksid.'到'.$jsid.'的共发布'.$recount.'个视频记录。\');parent.Dialog.close();</script>';
                         }else{

                               if(empty($id)){
		                    $rows=$this->CsdjDB->get_all($sqlstr);
                                    $id=$rows[0]->CS_ID;
                               }

                               $row=$this->CsdjDB->get_select ('vod','CS_ID','*',''.$id.'');
                               $neir=$this->CsdjVod->show('id',$id,$row);

                               if(empty($neir)) die('Error,<a href="javascript:location.reload()">点我刷新重试!</a>');

                               $html=".".$this->CsdjSkins->LinkUrl('show','vod','id',1,$id,1,2);
                               $html=$this->CsdjAdmin->gethtmls($html); //补全HTML地址

                               if ( ! write_file($html, $neir)){
                                 die(''.$html.'文件没有写入权限！');
                               }


                              //下一个ID
                              $sql="Select CS_ID from ".CS_SqlPrefix."vod where CS_ID>".$id." and CS_YID=0 and CS_HID=0 order by CS_ID asc";
		              $row=$this->CsdjDB->get_all($sql);

                              if(!$row){
                                  $data['xid']=-1; //下ID
                              }else{
                                  $data['xid']=$row[0]->CS_ID; //下ID
                              }

                              $xpage=$page+1;
                              $data['jind']=intval($page/$recount*100); //进度条

                              $data['xlink']=site_url('admin/html/vod/')."?op=show&t=id&ksid=".$ksid."&jsid=".$jsid."&page=".$xpage."&id=".$data['xid'];


                              $data['nums']=$recount;
                              $data['link']=$html;
                              $data['id']=$id;
                              $data['page']=$page;
							 $this->load->get_admin_templates();
                              $this->load->view('admin/html',$data);
                         }

                  }elseif($t=='news'){ //最新多少个

	                 $topn = $this->input->get_post('topn');
                         if(empty($topn)) $topn=10;

                         $sqlstr="select * from ".CS_SqlPrefix."vod where CS_YID=0 and CS_HID=0 order by CS_ID desc limit ".$topn."";
		         $result=$this->CsdjDB->db->query($sqlstr);
		         $recount=$result->num_rows();

                         if($recount==0 || $page>$recount){
                              echo '成功发布最新'.$topn.'首视频，实际完成'.$recount.'个视频记录。<p><a href="'.site_url('admin/vod/html').'">继续发布</a></p>';
                         }else{

                               if(empty($id)){
		                    $rows=$this->CsdjDB->get_all($sqlstr);
                                    $id=$rows[0]->CS_ID;
                               }

                               $row=$this->CsdjDB->get_select ('vod','CS_ID','*',''.$id.'');
                               $neir=$this->CsdjVod->show('id',$id,$row);
                               if(empty($neir)) die('Error,<a href="javascript:location.reload()">点我刷新重试!</a>');

                               $html=".".$this->CsdjSkins->LinkUrl('show','vod','id',1,$id,1,2);
                               $html=$this->CsdjAdmin->gethtmls($html); //补全HTML地址

                               if ( ! write_file($html, $neir)){
                                 die(''.$html.'文件没有写入权限！');
                               }

                              //下一个ID
                              $sql="Select CS_ID from ".CS_SqlPrefix."vod where CS_ID<".$id." and CS_YID=0 and CS_HID=0 order by CS_ID desc";

		              $row=$this->CsdjDB->get_all($sql);
                              if($row){
                                 $data['xid']=$row[0]->CS_ID; //下ID
                              }else{
                                 $data['xid']=-1; //下ID
                              }

                              $xpage=$page+1;
                              $data['jind']=intval($page/$recount*100); //进度条

                              $data['xlink']=site_url('admin/html/vod/')."?op=show&t=news&topn=".$topn."&page=".$xpage."&id=".$data['xid'];


                              $data['nums']=$recount;
                              $data['link']=$html;
                              $data['id']=$id;
                              $data['page']=$page;
							 $this->load->get_admin_templates();
                              $this->load->view('admin/html',$data);
                         }

                  }elseif($t=='date'){ //按时间生成
	                 $ksdate = $this->input->get_post('ksdate');
	                 $jsdate = $this->input->get_post('jsdate');
                         $ksdates = date("Y-m-d",mktime(00,00,01,date("m",strtotime($ksdate)),date("d",strtotime($ksdate))-1,date("Y",strtotime($ksdate))));
                         $jsdates = date("Y-m-d",mktime(00,00,01,date("m",strtotime($jsdate)),date("d",strtotime($jsdate))+1,date("Y",strtotime($jsdate))));

                         $sqlstr="select * from ".CS_SqlPrefix."vod where CS_AddTime>='{$ksdates}' and CS_AddTime<='{$jsdates}' and CS_YID=0 and CS_HID=0 order by CS_AddTime desc";
		         $result=$this->CsdjDB->db->query($sqlstr);
		         $recount=$result->num_rows();

                         if($recount==0 || $page>$recount || $id==-1){
                              echo '发布完成！日期从:'.$ksdate.'到'.$ksdate.'的共发布'.$recount.'首视频记录。<p><a href="'.site_url('admin/vod/html').'">继续发布</a></p>';
                         }else{

                               if(empty($id)){
		                    $rows=$this->CsdjDB->get_all($sqlstr);
                                    $id=$rows[0]->CS_ID;
                               }

                               $row=$this->CsdjDB->get_select ('vod','CS_ID','*',''.$id.'');
                               $neir=$this->CsdjVod->show('id',$id,$row);

                               if(empty($neir)) die('Error,<a href="javascript:location.reload()">点我刷新重试!</a>');

                               $html=".".$this->CsdjSkins->LinkUrl('show','vod','id',1,$id,1,2);
                               $html=$this->CsdjAdmin->gethtmls($html); //补全HTML地址

                               if ( ! write_file($html, $neir)){
                                 die(''.$html.'文件没有写入权限！');
                               }

                              //下一个ID
                              $sql="Select CS_ID from ".CS_SqlPrefix."vod where CS_ID<".$id." and CS_AddTime>='{$ksdates}' and CS_AddTime<='{$jsdates}' and CS_YID=0 and CS_HID=0 order by CS_ID desc";
		              $row=$this->CsdjDB->get_all($sql);
                              if($row){
                                   $data['xid']=$row[0]->CS_ID; //下ID
                              }else{
                                   $data['xid']=-1; //下ID
                              }

                              $xpage=$page+1;

                              $data['jind']=intval($page/$recount*100); //进度条

                              $data['xlink']=site_url('admin/html/vod/')."?op=show&t=date&ksdate=".$ksdate."&jsdate=".$jsdate."&page=".$xpage."&id=".$data['xid'];


                              $data['nums']=$recount;
                              $data['link']=$html;
                              $data['id']=$id;
                              $data['page']=$page;
							 $this->load->get_admin_templates();
                              $this->load->view('admin/html',$data);
                         }

                  }elseif($t=='lists'){ //按分类生成
	                 $cid = $this->input->get_post('cid');
	                 $topn = $this->input->get_post('topn');
                         if(empty($topn)) $topn=10;
                         if(empty($cid)) $this->CsdjAdmin->Admin_Url('<font color=red>请选择分类！</font>',site_url('admin/vod/html/'));

                         if (is_array($cid)){
                              $cids=implode(',', $cid);
                         }else{
                              $cids=$cid;
                         }
                         $classname='';
                         $Arr=explode(',',$cids);
                         for($i=0;$i<count($Arr);$i++){
                                $classname.=$this->CsdjSkins->getclass($Arr[$i])."、";
                         }
                         $sqlstr="select * from ".CS_SqlPrefix."vod where CS_CID in (".$cids.") and CS_YID=0 and CS_HID=0 order by CS_AddTime desc limit ".$topn."";
		         $result=$this->CsdjDB->db->query($sqlstr);
		         $recount=$result->num_rows();

                         if($recount==0 || $page>$recount || $id==-1){
                              echo '成功发布['.$classname.']分类最新'.$recount.'首视频记录。<p><a href="'.site_url('admin/vod/html').'">继续发布</a></p>';
                         }else{

                               if(empty($id)){
		                    $rows=$this->CsdjDB->get_all($sqlstr);
                                    $id=$rows[0]->CS_ID;
                               }

                               $row=$this->CsdjDB->get_select ('vod','CS_ID','*',''.$id.'');
                               $neir=$this->CsdjVod->show('id',$id,$row);
                               if(empty($neir)) die('Error,<a href="javascript:location.reload()">点我刷新重试!</a>');

                               $html=".".$this->CsdjSkins->LinkUrl('show','vod','id',1,$id,1,2);
                               $html=$this->CsdjAdmin->gethtmls($html); //补全HTML地址

                               if ( ! write_file($html, $neir)){
                                 die(''.$html.'文件没有写入权限！');
                               }

                              //下一个ID
                              $sql="Select CS_ID from ".CS_SqlPrefix."vod where CS_ID<".$id." and  CS_CID in (".$cids.") and CS_YID=0 and CS_HID=0 order by CS_ID desc";
		              $row=$this->CsdjDB->get_all($sql);
                              if($row){
                                   $data['xid']=$row[0]->CS_ID; //下ID
                              }else{
                                   $data['xid']=-1; //下ID
                              }

                              $xpage=$page+1;

                              $data['jind']=intval($page/$recount*100); //进度条

                              $data['xlink']=site_url('admin/html/vod/')."?op=show&t=lists&cid=".$cids."&topn=".$topn."&page=".$xpage."&id=".$data['xid'];


                              $data['nums']=$recount;
                              $data['link']=$html;
                              $data['id']=$id;
                              $data['page']=$page;
							 $this->load->get_admin_templates();
                              $this->load->view('admin/html',$data);
                         }


                  }elseif($t=='all'){ //生成全部播放

                         $sqlstr="select * from ".CS_SqlPrefix."vod where CS_YID=0 and CS_HID=0 order by CS_AddTime desc";
		         $result=$this->CsdjDB->db->query($sqlstr);
		         $recount=$result->num_rows();

                         if($recount==0 || $page>$recount){
                              echo '发布完成！全部共发布'.$recount.'首视频记录。<script type="text/javascript">parent.TokeymakeMsg(\'msg_show\',\'发布完成！全部共发布'.$recount.'首视频记录。\');parent.Dialog.close();parent.Dialog.close();</script><p><a href="'.site_url('admin/vod/html').'">继续发布</a></p>';
                         }else{

                               if(empty($id)){
		                    $rows=$this->CsdjDB->get_all($sqlstr);
                                    $id=$rows[0]->CS_ID;
                               }

                               $row=$this->CsdjDB->get_select ('vod','CS_ID','*',''.$id.'');
                               $neir=$this->CsdjVod->show('id',$id,$row);
                               if(empty($neir)) die('Error,<a href="javascript:location.reload()">点我刷新重试!</a>');

                               $html=".".$this->CsdjSkins->LinkUrl('show','vod','id',1,$id,1,2);
                               $html=$this->CsdjAdmin->gethtmls($html); //补全HTML地址

                               if ( ! write_file($html, $neir)){
                                 die(''.$html.'文件没有写入权限！');
                               }

                              //下一个ID
                              $sql="Select CS_ID from ".CS_SqlPrefix."vod where CS_ID<".$id." and CS_YID=0 and CS_HID=0 order by CS_ID desc";
		              $row=$this->CsdjDB->get_all($sql);

                              $xpage=$page+1;

                              $data['xid']=$row[0]->CS_ID; //下ID
                              $data['jind']=intval($page/$recount*100); //进度条

                              $data['xlink']=site_url('admin/html/vod/')."?op=show&t=all&page=".$xpage."&id=".$row[0]->CS_ID;


                              $data['nums']=$recount;
                              $data['link']=$html;
                              $data['id']=$id;
                              $data['page']=$page;
							 $this->load->get_admin_templates();
                              $this->load->view('admin/html',$data);
                         }
                  }


            }elseif($op=='list'){ //分类页  
   
	          $nums = $this->input->get('nums');
	          $cgid = $this->input->get('cgid');
	          $xid = $this->input->get('xid');
                  if(empty($cgid)) $cgid=1; 
                  if(empty($xid)) $xid=0; 

                  $Title=array("按ID","按总人气","按每月人气","按每周人气","按每日人气","按推荐星际","按更新时间");
                  $Type=array("id","hits","yue","zhou","ri","reco","new");


                  if($t=='all'){  //所有分类

                        if(empty($id)){
                            $sqlstr="select * from ".CS_SqlPrefix."vlist where CS_YID=0 order by CS_ID desc";
		            $result=$this->CsdjDB->db->query($sqlstr);
		            $recount=$result->num_rows();
                            if($recount==0){
                                   echo "暂时没有分类记录！<script type=\"text/javascript\">parent.TokeymakeMsg('msg_list','暂时没有分类记录！');parent.Dialog.close();</script>";
                                   exit();
                            }
                         }else{
                            $recount=$nums;
                            $sqlstr="select * from ".CS_SqlPrefix."vlist where cs_id=".$id."";
                         }
		            $row=$this->CsdjDB->get_all($sqlstr);
                            if($row || $id==0){
                                   $id=$row[0]->CS_ID;
                                   if(empty($row[0]->CS_Template)){
                                         $CS_Template='vod-list.html';
                                   }else{
                                         $CS_Template=$row[0]->CS_Template;
                                   }
                                    //获取分页标签
                                    $CS_Template="./skins/".Skins_dir.$CS_Template;
		                    $template=read_file($CS_Template);
		                    preg_match_all('/{cscms:vod(.*?pagesize=([\S]+).*?)}([\s\S]+?){\/cscms:vod}/',$template,$page_arr);//判断是否有分页标识
		                    if(!empty($page_arr) && !empty($page_arr[2])){
                                           $per_page=$page_arr[2][0];
                                    }else{
                                           $per_page=50;
                                    }
                                    if(empty($per_page)) $per_page=10; 

                                     //下一个ID
                                     $sql="Select CS_ID from ".CS_SqlPrefix."vlist where CS_ID<".$id." and CS_YID=0  order by CS_ID desc";
		                     $rows=$this->CsdjDB->get_all($sql);
                                     if($rows){
                                          $data['xid']=$rows[0]->CS_ID; //下ID
                                     }else{
                                          $data['xid']=0; //下ID
                                     }

                                    $cid=$this->CsdjSkins->getChild($id,'vlist');
                                    $sql="select * from ".CS_SqlPrefix."vod where CS_CID in(".$cid.") and CS_YID=0 and CS_HID=0";
		                    $query=$this->db->query($sql);
		                    $nums=$query->num_rows();
                                    if($nums==0) $nums=1; 
                                    $pagejs=ceil($nums / $per_page); // 总页数

                                    $data['cname']=$row[0]->CS_Name."->".$Title[$xid]."排序";
                                    $data['nums']=$recount;
                                    $data['pagejs']=$pagejs;
                                    $data['ok']='no';
                                    $data['cgid']=$cgid;
                                    $data['page']=$page;
                                    $data['jind']=intval($page/$pagejs*100); //进度条

                                     //------------------------------生成-----------------------------

                                     $neir=$this->CsdjVod->lists($Type[$xid],$id,$page,$row);
                                     if(empty($neir)) die('Error,<a href="javascript:location.reload()">点我刷新重试!</a>');

                                     $html=".".$this->CsdjSkins->LinkUrl('lists','vod',$Type[$xid],$id,1,$page,2);
                                     $html=$this->CsdjAdmin->gethtmls($html); //补全HTML地址

                                     if ( ! write_file($html, $neir)){
                                       die("文件没有写入权限！<script type=\"text/javascript\">parent.TokeymakeMsg('msg_list','文件没有写入权限！');parent.Dialog.close();</script>");
                                     }

                                    if($data['pagejs']>$page){
                                               $data['xlink']=site_url('admin/html/vod/')."?op=list&t=all&id=".$id."&cgid=".($cgid+1)."&xid=".$xid."&nums=".$recount."&page=".($page+1)."";
                                    }else{
                                          if($data['xid']==0){
                                               $data['ok']='yes';
                                               $data['type']='msg_list';
                                               $data['neir']="共发布[视频分类]模块".$recount."个分类列表页，".$cgid."个页面。";
                                          }else{
                                               $data['xlink']=site_url('admin/html/vod/')."?op=list&t=all&id=".$data['xid']."&cgid=".($cgid+1)."&xid=".$xid."&nums=".$recount."";
                                          }
                                    }
                             }else{
                                    $data['ok']='yes';
                                    $data['neir']="共发布[视频分类]模块".$recount."个分类列表页，".$cgid."个页面。";
                             }
							 $this->load->get_admin_templates();
                             $this->load->view('admin/html_list',$data);

                  }elseif($t=='id'){
	               $cid = $this->input->get_post('cid');
	               $xid = $this->input->get('xid');
	               $sort = $this->input->get_post('sort');
                       if(empty($xid)) $xid=0; 
                       if(empty($cid)) $this->CsdjAdmin->Admin_Url('<font color=red>请选择分类！</font>',site_url('admin/vod/html/'));

                       if($sort=='hits'){
                                   $title='总人气';
                       }elseif($sort=='ri'){
                                   $title='日人气';
                       }elseif($sort=='zhou'){
                                   $title='周人气';
                       }elseif($sort=='yue'){
                                   $title='月人气';
                       }elseif($sort=='reco'){
                                   $title='推荐星际';
                       }elseif($sort=='id'){
                                   $title='ID';
                       }else{
                                   $title='最新更新';
                       }

                         if (is_array($cid)){
                              $cids=implode(',', $cid);
                              $cid=$cids;
                              $Arr=explode(',',$cids);
                              $id=$Arr[0];
                              $count=count($Arr);
                         }else{
                              $cid=$cid;
                              $Arr=explode(',',$cid);
                              $id=$id;
                              $count=$nums;
                         }
                            $sqlstr="select * from ".CS_SqlPrefix."vlist where cs_id=".$id."";
		            $row=$this->CsdjDB->get_all($sqlstr);
                            if($row){
                                   $id=$row[0]->CS_ID;
                                   if(empty($row[0]->CS_Template)){
                                         $CS_Template='vod-list.html';
                                   }else{
                                         $CS_Template=$row[0]->CS_Template;
                                   }
                                    //获取分页标签
                                    $CS_Template="./skins/".Skins_dir.$CS_Template;
		                    $template=read_file($CS_Template);
		                    preg_match_all('/{cscms:vod(.*?pagesize=([\S]+).*?)}([\s\S]+?){\/cscms:vod}/',$template,$page_arr);//判断是否有分页标识
		                    if(!empty($page_arr) && !empty($page_arr[2])){
                                           $per_page=$page_arr[2][0];
                                    }else{
                                           $per_page=50;
                                    }
                                    if(empty($per_page)) $per_page=10; 

                                    $cidc=$this->CsdjSkins->getChild($id,'vlist');
                                    $sql="select * from ".CS_SqlPrefix."vod where CS_CID in(".$cidc.") and CS_YID=0 and CS_HID=0";
		                    $query=$this->db->query($sql);
		                    $nums=$query->num_rows();
                                    if($nums==0) $nums=1; 
                                    $pagejs=ceil($nums / $per_page); // 总页数

                                    $data['cname']=$row[0]->CS_Name."->".$title."排序";
                                    $data['nums']=$count;
                                    $data['pagejs']=$pagejs;
                                    $data['ok']='no';
                                    $data['cgid']=$cgid;
                                    $data['page']=$page;
                                    $data['jind']=intval($page/$pagejs*100); //进度条

                                     //------------------------------生成-----------------------------

                                     $neir=$this->CsdjVod->lists($sort,$id,$page,$row);
                                     if(empty($neir)) die('Error,<a href="javascript:location.reload()">点我刷新重试!</a>');

                                     $html=".".$this->CsdjSkins->LinkUrl('lists','vod',$sort,$id,1,$page,2);
                                     $html=$this->CsdjAdmin->gethtmls($html); //补全HTML地址

                                     if ( ! write_file($html, $neir)){
                                       die("文件没有写入权限！<script type=\"text/javascript\">parent.TokeymakeMsg('msg_list','文件没有写入权限！');parent.Dialog.close();</script>");
                                     }

                                    if($data['pagejs']>$page){
                                               $data['xlink']=site_url('admin/html/vod/')."?op=list&t=id&id=".$id."&cgid=".($cgid+1)."&cid=".$cid."&xid=".$xid."&nums=".$count."&page=".($page+1)."&sort=".$sort."";
                                    }else{
                                         if($xid==($count-1)){
                                              $data['ok']='yes';
                                              $data['type']='msg_list';
                                              $data['neir']="共发布[视频分类]模块".$count."个分类列表页，".$cgid."个页面。";
                                         }else{
                                               $data['xlink']=site_url('admin/html/vod/')."?op=list&t=id&id=".$Arr[($xid+1)]."&cgid=".($cgid+1)."&cid=".$cid."&xid=".$xid."&nums=".$count."&xid=".($xid+1)."&sort=".$sort."";
                                         }
                                    }
                             }
							 $this->load->get_admin_templates();
                             $this->load->view('admin/html_list',$data);

                  }

            }
        }


	public function singer()
	{
		    $this->load->model('CsdjSinger');
            $this->CsdjAdmin->Admin_Qx('21');
            $data['title']='歌手';
	    $op = $this->input->get('op');
	    $t = $this->input->get('t');
	    $id = $this->input->get('id');
	    $page = $this->input->get('page');
            if(empty($page)) $page=1;

            if($op=='index'){ //主页

                      $data=$this->CsdjSinger->index();
                      if(empty($data)) die('Error,<a href="javascript:location.reload()">点我刷新重试!</a>');

                      $html=".".Html_Sindex;
                      $html=$this->CsdjAdmin->gethtmls($html); //补全HTML地址
                      if ( ! write_file($html, $data)){
                           echo '<a href="'.str_replace('//','/',Web_Path.substr($html,1)).'" target="_blank">'.$html.'文件没有写入权限！</a>';
                      }else{
                           echo '<a href="'.str_replace('//','/',Web_Path.substr($html,1)).'" target="_blank">歌手首页生成成功！</a>';
                      }

            }elseif($op=='show'){ //歌手页


                  if($t=='id'){

	                 $ksid = $this->input->get_post('ksid');
	                 $jsid = $this->input->get_post('jsid');

                         $strs='';
		         $singer=$this->db->query("select CS_ID,CS_Name,CS_Template from ".CS_SqlPrefix."singer where CS_ID>".($ksid-1)." and CS_ID<".($jsid+1)." and CS_YID=0");
		         $recount=$singer->num_rows();
                                  foreach ($singer->result() as $row2) {

                                         if(empty($row2->CS_Template)){
                                               $CS_Template='singer-show.html';
                                         }else{
                                               $CS_Template=$row2->CS_Template;
                                         }
                                          //获取分页标签
                                          $CS_Template="./skins/".Skins_dir.$CS_Template;
		                          $template=read_file($CS_Template);
		                          preg_match_all('/{cscms:dance(.*?pagesize=([\S]+).*?)}([\s\S]+?){\/cscms:dance}/',$template,$page_arr);//判断是否有分页标识
		                          if(!empty($page_arr) && !empty($page_arr[2])){
                                                 $per_page=$page_arr[2][0];
                                          }else{
                                                 $per_page=50; 
                                          }
                                          if(empty($per_page)) $per_page=10; 

                                          $sql="select * from ".CS_SqlPrefix."dance where CS_SingerID=".$row2->CS_ID." and CS_YID=0 and CS_HID=0";
		                          $query=$this->db->query($sql);
		                          $nums=$query->num_rows();
                                          if($nums==0) $nums=1; 
                                          $pagejs=ceil($nums / $per_page); // 总页数

                                          for($k=1;$k<=$pagejs;$k++){
                                                   //------------------------------生成-----------------------------

                                                   $row=$this->CsdjDB->get_select ('singer','CS_ID','*',''.$row2->CS_ID.'');
                                                   $neir=$this->CsdjSinger->show('id',$row2->CS_ID,$k,$row);

                                                   if(empty($neir)) die('Error,<a href="javascript:location.reload()">点我刷新重试!</a>');
                                                   $html=".".$this->CsdjSkins->LinkUrl('show','singer','id',$row2->CS_ID,$row2->CS_ID,$k,2);
                                                   $html=$this->CsdjAdmin->gethtmls($html); //补全HTML地址
                                                   if ( ! write_file($html, $neir)){
                                                        die("<script type=\"text/javascript\">parent.TokeymakeMsg('msg_topicshow','文件没有写入权限！');parent.Dialog.close();</script>");
                                                   }else{
                                                        $strs.="".$row2->CS_Name."第".$k."页,发布完毕!<br>";
                                                   }
                                          }
                                  }
                         $data['ok']='yes';
                         $data['type']='msg_topicshow';
                         $data['neir']=$strs."<b style='color:red'>所有歌手发布完成，共发布[歌手内容]模块".$recount."个歌手</b>";
							 $this->load->get_admin_templates();
                         $this->load->view('admin/html_list',$data);

                  }elseif($t=='news'){ //最新多少个

	                 $topn = $this->input->get_post('topn');
                         if(empty($topn)) $topn=10;

                         $strs='';
		         $singer=$this->db->query("select CS_ID,CS_Name,CS_Template from ".CS_SqlPrefix."singer where CS_YID=0 order by CS_AddTime desc limit ".$topn."");
		         $recount=$singer->num_rows();
                                  foreach ($singer->result() as $row2) {

                                         if(empty($row2->CS_Template)){
                                               $CS_Template='singer-show.html';
                                         }else{
                                               $CS_Template=$row2->CS_Template;
                                         }
                                          //获取分页标签
                                          $CS_Template="./skins/".Skins_dir.$CS_Template;
		                          $template=read_file($CS_Template);
		                          preg_match_all('/{cscms:dance(.*?pagesize=([\S]+).*?)}([\s\S]+?){\/cscms:dance}/',$template,$page_arr);//判断是否有分页标识
		                          if(!empty($page_arr) && !empty($page_arr[2])){
                                                 $per_page=$page_arr[2][0];
                                          }else{
                                                 $per_page=50; 
                                          }
                                          if(empty($per_page)) $per_page=10; 

                                          $sql="select * from ".CS_SqlPrefix."dance where CS_SingerID=".$row2->CS_ID." and CS_YID=0 and CS_HID=0";
		                          $query=$this->db->query($sql);
		                          $nums=$query->num_rows();
                                          if($nums==0) $nums=1; 
                                          $pagejs=ceil($nums / $per_page); // 总页数

                                          for($k=1;$k<=$pagejs;$k++){
                                                   //------------------------------生成-----------------------------

                                                   $row=$this->CsdjDB->get_select ('singer','CS_ID','*',''.$row2->CS_ID.'');
                                                   $neir=$this->CsdjSinger->show('id',$row2->CS_ID,$k,$row);
                                                   if(empty($neir)) die('Error,<a href="javascript:location.reload()">点我刷新重试!</a>');
                                                   $html=".".$this->CsdjSkins->LinkUrl('show','singer','id',$row2->CS_ID,$row2->CS_ID,$k,2);
                                                   $html=$this->CsdjAdmin->gethtmls($html); //补全HTML地址
                                                   if ( ! write_file($html, $neir)){
                                                        die("<script type=\"text/javascript\">parent.TokeymakeMsg('msg_topicshow','文件没有写入权限！');parent.Dialog.close();</script>");
                                                   }else{
                                                        $strs.="".$row2->CS_Name."第".$k."页,发布完毕!<br>";
                                                   }
                                          }
                                  }
                         $data['ok']='yes';
                         $data['type']='msg_topicshow';
                         $data['neir']=$strs."<b style='color:red'>所有歌手发布完成，共发布[歌手内容]模块".$recount."个歌手</b>";
							 $this->load->get_admin_templates();
                         $this->load->view('admin/html_list',$data);

                  }elseif($t=='date'){ //按时间生成
	                 $ksdate = $this->input->get_post('ksdate');
	                 $jsdate = $this->input->get_post('jsdate');
                         $ksdates = date("Y-m-d",mktime(00,00,01,date("m",strtotime($ksdate)),date("d",strtotime($ksdate))-1,date("Y",strtotime($ksdate))));
                         $jsdates = date("Y-m-d",mktime(00,00,01,date("m",strtotime($jsdate)),date("d",strtotime($jsdate))+1,date("Y",strtotime($jsdate))));

                         $strs='';
		         $singer=$this->db->query("select CS_ID,CS_Name,CS_Template from ".CS_SqlPrefix."singer where CS_AddTime>='{$ksdates}' and CS_AddTime<='{$jsdates}' and CS_YID=0 order by CS_AddTime desc");
		         $recount=$singer->num_rows();
                                  foreach ($singer->result() as $row2) {

                                         if(empty($row2->CS_Template)){
                                               $CS_Template='singer-show.html';
                                         }else{
                                               $CS_Template=$row2->CS_Template;
                                         }
                                          //获取分页标签
                                          $CS_Template="./skins/".Skins_dir.$CS_Template;
		                          $template=read_file($CS_Template);
		                          preg_match_all('/{cscms:dance(.*?pagesize=([\S]+).*?)}([\s\S]+?){\/cscms:dance}/',$template,$page_arr);//判断是否有分页标识
		                          if(!empty($page_arr) && !empty($page_arr[2])){
                                                 $per_page=$page_arr[2][0];
                                          }else{
                                                 $per_page=50; 
                                          }
                                          if(empty($per_page)) $per_page=10; 

                                          $sql="select * from ".CS_SqlPrefix."dance where CS_SingerID=".$row2->CS_ID." and CS_YID=0 and CS_HID=0";
		                          $query=$this->db->query($sql);
		                          $nums=$query->num_rows();
                                          if($nums==0) $nums=1; 
                                          $pagejs=ceil($nums / $per_page); // 总页数

                                          for($k=1;$k<=$pagejs;$k++){
                                                   //------------------------------生成-----------------------------

                                                   $row=$this->CsdjDB->get_select ('singer','CS_ID','*',''.$row2->CS_ID.'');
                                                   $neir=$this->CsdjSinger->show('id',$row2->CS_ID,$k,$row);
                                                   if(empty($neir)) die('Error,<a href="javascript:location.reload()">点我刷新重试!</a>');
                                                   $html=".".$this->CsdjSkins->LinkUrl('show','singer','id',$row2->CS_ID,$row2->CS_ID,$k,2);
                                                   $html=$this->CsdjAdmin->gethtmls($html); //补全HTML地址
                                                   if ( ! write_file($html, $neir)){
                                                        die("<script type=\"text/javascript\">parent.TokeymakeMsg('msg_topicshow','文件没有写入权限！');parent.Dialog.close();</script>");
                                                   }else{
                                                        $strs.="".$row2->CS_Name."第".$k."页,发布完毕!<br>";
                                                   }
                                          }
                                  }
                         $data['ok']='yes';
                         $data['type']='msg_topicshow';
                         $data['neir']=$strs."<b style='color:red'>所有歌手发布完成，共发布[歌手内容]模块".$recount."个歌手</b>";
							 $this->load->get_admin_templates();
                         $this->load->view('admin/html_list',$data);

                  }elseif($t=='lists'){ //按分类生成

	                 $cid = $this->input->get_post('cid');
	                 $topn = $this->input->get_post('topn');
                         if(empty($topn)) $topn=10;
                         if(empty($cid)) $this->CsdjAdmin->Admin_Url('<font color=red>请选择分类！</font>',site_url('admin/singer/html/'));
                         $strs='';

                         $cids=implode(',', $cid);

                         $sqlstr="select * from ".CS_SqlPrefix."gslist where CS_ID in(".$cids.") and CS_YID=0 order by CS_ID desc";

		         $result=$this->db->query($sqlstr);
		         $recount=$result->num_rows();
                         foreach ($result->result() as $row) {
		                  $singer=$this->db->query("select CS_ID,CS_Name,CS_Template from ".CS_SqlPrefix."singer where CS_CID=".$row->CS_ID." and CS_YID=0 order by CS_ID desc limit ".$topn."");
		                  $recount=$singer->num_rows();
                                  foreach ($singer->result() as $row2) {

                                         if(empty($row2->CS_Template)){
                                               $CS_Template='singer-show.html';
                                         }else{
                                               $CS_Template=$row2->CS_Template;
                                         }
                                          //获取分页标签
                                          $CS_Template="./skins/".Skins_dir.$CS_Template;
		                          $template=read_file($CS_Template);
		                          preg_match_all('/{cscms:dance(.*?pagesize=([\S]+).*?)}([\s\S]+?){\/cscms:dance}/',$template,$page_arr);//判断是否有分页标识
		                          if(!empty($page_arr) && !empty($page_arr[2])){
                                                 $per_page=$page_arr[2][0];
                                          }else{
                                                 $per_page=50; 
                                          }
                                          if(empty($per_page)) $per_page=10; 

                                          $sql="select * from ".CS_SqlPrefix."dance where CS_SingerID=".$row2->CS_ID." and CS_YID=0 and CS_HID=0";
		                          $query=$this->db->query($sql);
		                          $nums=$query->num_rows();
                                          if($nums==0) $nums=1; 
                                          $pagejs=ceil($nums / $per_page); // 总页数

                                          for($k=1;$k<=$pagejs;$k++){
                                                   //------------------------------生成-----------------------------

                                                   $row=$this->CsdjDB->get_select ('singer','CS_ID','*',''.$row2->CS_ID.'');
                                                   $neir=$this->CsdjSinger->show('id',$row2->CS_ID,$k,$row);
                                                   if(empty($neir)) die('Error,<a href="javascript:location.reload()">点我刷新重试!</a>');
                                                   $html=".".$this->CsdjSkins->LinkUrl('show','singer','id',$row2->CS_ID,$row2->CS_ID,$k,2);
                                                   $html=$this->CsdjAdmin->gethtmls($html); //补全HTML地址
                                                   if ( ! write_file($html, $neir)){
                                                        die("<script type=\"text/javascript\">parent.TokeymakeMsg('msg_topicshow','文件没有写入权限！');parent.Dialog.close();</script>");
                                                   }else{
                                                        $strs.="".$row2->CS_Name."第".$k."页,发布完毕!<br>";
                                                   }
                                          }
                                  }
			 }
                         $data['ok']='yes';
                         $data['type']='msg_topicshow';
                         $data['neir']=$strs."<b style='color:red'>所有歌手发布完成，共发布[歌手内容]模块".$recount."个分类的歌手</b>";
							 $this->load->get_admin_templates();
                         $this->load->view('admin/html_list',$data);

                  }elseif($t=='all'){ //生成全部歌手

	               $cgid = $this->input->get('cgid');
	               $nums = $this->input->get('nums');
                       if(empty($cgid)) $cgid=1; 

                       if(empty($id)){
                            $sqlstr="select * from ".CS_SqlPrefix."singer where CS_YID=0 order by CS_ID desc";
		            $result=$this->db->query($sqlstr);
		            $recount=$result->num_rows();
                            if($recount==0){
                                   echo "暂时没有歌手记录！<script type=\"text/javascript\">parent.TokeymakeMsg('msg_show','暂时没有歌手记录！');parent.Dialog.close();</script>";
                                   exit();
                            }
                            $count=$recount;
		            $rows=$this->CsdjDB->get_all($sqlstr);
                            $id=$rows[0]->CS_ID;
                       }else{
                            $count=$nums;
                       }


                            $sqlstr="select * from ".CS_SqlPrefix."singer where cs_id=".$id."";
		            $row=$this->CsdjDB->get_all($sqlstr);
                            if($row){
                                   if(empty($row[0]->CS_Template)){
                                         $CS_Template='singer-show.html';
                                   }else{
                                         $CS_Template=$row[0]->CS_Template;
                                   }
                                    //获取分页标签
                                    $CS_Template="./skins/".Skins_dir.$CS_Template;
		                    $template=read_file($CS_Template);
		                    preg_match_all('/{cscms:dance(.*?pagesize=([\S]+).*?)}([\s\S]+?){\/cscms:dance}/',$template,$page_arr);//判断是否有分页标识
		                    if(!empty($page_arr) && !empty($page_arr[2])){
                                           $per_page=$page_arr[2][0];
                                    }else{
                                           $per_page=50; 
                                    }
                                    if(empty($per_page)) $per_page=10; 

                                    $sql="select * from ".CS_SqlPrefix."dance where CS_SingerID=".$id." and CS_YID=0 and CS_HID=0";
		                    $query=$this->db->query($sql);
		                    $nums=$query->num_rows();
                                    if($nums==0) $nums=1; 
                                    $pagejs=ceil($nums / $per_page); // 总页数

                                    $data['cname']=$row[0]->CS_Name;
                                    $data['nums']=$count;
                                    $data['pagejs']=$pagejs;
                                    $data['ok']='no';
                                    $data['cgid']=$cgid;
                                    $data['page']=$page;
                                    $data['jind']=intval($page/$pagejs*100); //进度条

                                     //------------------------------生成-----------------------------

                                     $row=$this->CsdjDB->get_select ('singer','CS_ID','*',''.$id.'');
                                     $neir=$this->CsdjSinger->show('id',$id,$page,$row);
                                     if(empty($neir)) die('Error,<a href="javascript:location.reload()">点我刷新重试!</a>');

                                     $html=".".$this->CsdjSkins->LinkUrl('show','singer','id',$id,$id,$page,2);

                                     $html=$this->CsdjAdmin->gethtmls($html); //补全HTML地址

                                     if ( ! write_file($html, $neir)){
                                       die("<script type=\"text/javascript\">parent.TokeymakeMsg('msg_topicshow','文件没有写入权限！');parent.Dialog.close();</script>");
                                     }

                                      //下一个ID
                                      $sql="Select CS_ID from ".CS_SqlPrefix."singer where CS_ID<".$id." and CS_YID=0  order by CS_ID desc";
		                      $rows=$this->CsdjDB->get_all($sql);
                                      if($rows){
                                           $xid=$rows[0]->CS_ID; //下ID
                                      }else{
                                           $xid=0; //下ID
                                      }


                                    if($pagejs>$page){
                                               $data['xlink']=site_url('admin/html/singer')."?op=show&t=all&cgid=".($cgid+1)."&id=".$id."&nums=".$count."&page=".($page+1)."";
                                    }else{
                                         if($xid==0){
                                              $data['ok']='yes';
                                              $data['type']='msg_topicshow';
                                              $data['neir']="共发布[歌手内容]模块".$count."个歌手，".$cgid."个页面。";
                                         }else{
                                               $data['xlink']=site_url('admin/html/singer')."?op=show&t=all&id=".$xid."&cgid=".($cgid+1)."&nums=".$count."";
                                         }
                                    }
                             }else{

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


            }elseif($op=='list'){ //分类页  
   
	          $nums = $this->input->get('nums');
	          $cgid = $this->input->get('cgid');
	          $xid = $this->input->get('xid');
                  if(empty($cgid)) $cgid=1; 
                  if(empty($xid)) $xid=0; 

                  $Title=array("按ID","按总人气","按每月人气","按每周人气","按每日人气","按更新时间");
                  $Type=array("id","hits","yue","zhou","ri","new");


                  if($t=='all'){  //所有分类
                        if(empty($id)){
                            $sqlstr="select * from ".CS_SqlPrefix."gslist where CS_YID=0 order by CS_ID desc";
		            $result=$this->CsdjDB->db->query($sqlstr);
		            $recount=$result->num_rows();
                            if($recount==0){
                                   echo "暂时没有分类记录！<script type=\"text/javascript\">parent.TokeymakeMsg('msg_list','暂时没有分类记录！');parent.Dialog.close();</script>";
                                   exit();
                            }
                         }else{
                            $recount=$nums;
                            $sqlstr="select * from ".CS_SqlPrefix."gslist where cs_id=".$id."";
                         }
		            $row=$this->CsdjDB->get_all($sqlstr);

                            if($row || $id==0){
                                   $id=$row[0]->CS_ID;
                                   if(empty($row[0]->CS_Template)){
                                         $CS_Template='singer-list.html';
                                   }else{
                                         $CS_Template=$row[0]->CS_Template;
                                   }
                                    //获取分页标签
                                    $CS_Template="./skins/".Skins_dir.$CS_Template;
		                    $template=read_file($CS_Template);
		                    preg_match_all('/{cscms:singer(.*?pagesize=([\S]+).*?)}([\s\S]+?){\/cscms:singer}/',$template,$page_arr);//判断是否有分页标识
		                    if(!empty($page_arr) && !empty($page_arr[2])){
                                           $per_page=$page_arr[2][0];
                                    }else{
                                           echo "模板里没有使用歌手分页标签！<script type=\"text/javascript\">parent.TokeymakeMsg('msg_list','模板里没有使用歌手分页标签！');parent.Dialog.close();</script>";
                                           exit();
                                    }
                                    if(empty($per_page)) $per_page=10; 

                                     //下一个ID
                                     $sql="Select CS_ID from ".CS_SqlPrefix."gslist where CS_ID<".$id." and CS_YID=0  order by CS_ID desc";
		                     $rows=$this->CsdjDB->get_all($sql);
                                     if($rows){
                                          $data['xid']=$rows[0]->CS_ID; //下ID
                                     }else{
                                          $data['xid']=0; //下ID
                                     }


                                    $sql="select cs_id from ".CS_SqlPrefix."singer where CS_CID=".$id." and CS_YID=0";
		                    $query=$this->db->query($sql);
		                    $nums=$query->num_rows();
                                    if($nums==0) $nums=1; 
                                    $pagejs=ceil($nums / $per_page); // 总页数

                                    $data['cname']=$row[0]->CS_Name."->".$Title[$xid]."排序";
                                    $data['nums']=$recount;
                                    $data['pagejs']=$pagejs;
                                    $data['ok']='no';
                                    $data['cgid']=$cgid;
                                    $data['page']=$page;
                                    $data['jind']=intval($page/$pagejs*100); //进度条

                                     //------------------------------生成-----------------------------

                                     $neir=$this->CsdjSinger->lists($Type[$xid],$id,$page,$row);
                                     if(empty($neir)) die('Error,<a href="javascript:location.reload()">点我刷新重试!</a>');

                                     $html=".".$this->CsdjSkins->LinkUrl('lists','singer',$Type[$xid],$id,1,$page,2);
                                     $html=$this->CsdjAdmin->gethtmls($html); //补全HTML地址

                                     if ( ! write_file($html, $neir)){
                                       die("文件没有写入权限！<script type=\"text/javascript\">parent.TokeymakeMsg('msg_list','文件没有写入权限！');parent.Dialog.close();</script>");
                                     }

                                    if($data['pagejs']>$page){
                                               $data['xlink']=site_url('admin/html/singer/')."?op=list&t=all&id=".$id."&cgid=".($cgid+1)."&xid=".$xid."&nums=".$recount."&page=".($page+1)."";
                                    }else{
                                          if($data['xid']==0){
                                               $data['ok']='yes';
                                               $data['type']='msg_list';
                                               $data['neir']="共发布[歌手分类]模块".$recount."个分类列表页，".$cgid."个页面。";
                                          }else{
                                               $data['xlink']=site_url('admin/html/singer/')."?op=list&t=all&id=".$data['xid']."&cgid=".($cgid+1)."&xid=".$xid."&nums=".$recount."";
                                          }
                                    }
                             }else{
                                    $data['ok']='yes';
                                    $data['neir']="共发布[歌手分类]模块".$recount."个分类列表页，".$cgid."个页面。";
                             }
							 $this->load->get_admin_templates();
                             $this->load->view('admin/html_list',$data);

                  }elseif($t=='id'){
	               $cid = $this->input->get_post('cid');
	               $xid = $this->input->get('xid');
	               $sort = $this->input->get_post('sort');
                       if(empty($xid)) $xid=0; 
                       if(empty($cid)) $this->CsdjAdmin->Admin_Url('<font color=red>请选择分类！</font>',site_url('admin/singer/html/'));

                       if($sort=='hits'){
                                   $title='总人气';
                       }elseif($sort=='ri'){
                                   $title='日人气';
                       }elseif($sort=='zhou'){
                                   $title='周人气';
                       }elseif($sort=='yue'){
                                   $title='月人气';
                       }elseif($sort=='id'){
                                   $title='ID';
                       }else{
                                   $title='最新更新';
                       }

                         if (is_array($cid)){
                              $cids=implode(',', $cid);
                              $cid=$cids;
                              $Arr=explode(',',$cids);
                              $id=$Arr[0];
                              $count=count($Arr);
                         }else{
                              $cid=$cid;
                              $Arr=explode(',',$cid);
                              $id=$id;
                              $count=$nums;
                         }
                            $sqlstr="select * from ".CS_SqlPrefix."gslist where cs_id=".$id."";
		            $row=$this->CsdjDB->get_all($sqlstr);
                            if($row){
                                   $id=$row[0]->CS_ID;
                                   if(empty($row[0]->CS_Template)){
                                         $CS_Template='singer-list.html';
                                   }else{
                                         $CS_Template=$row[0]->CS_Template;
                                   }
                                    //获取分页标签
                                    $CS_Template="./skins/".Skins_dir.$CS_Template;
		                    $template=read_file($CS_Template);
		                    preg_match_all('/{cscms:singer(.*?pagesize=([\S]+).*?)}([\s\S]+?){\/cscms:singer}/',$template,$page_arr);//判断是否有分页标识
		                    if(!empty($page_arr) && !empty($page_arr[2])){
                                           $per_page=$page_arr[2][0];
                                    }else{
                                           echo "模板里没有使用专题分页标签！<script type=\"text/javascript\">parent.TokeymakeMsg('msg_list','模板里没有使用歌手分页标签！');parent.Dialog.close();</script>";
                                           exit();
                                    }
                                    if(empty($per_page)) $per_page=10; 

                                    $sql="select * from ".CS_SqlPrefix."singer where CS_CID=".$id." and CS_YID=0";
		                    $query=$this->db->query($sql);
		                    $nums=$query->num_rows();
                                    if($nums==0) $nums=1; 
                                    $pagejs=ceil($nums / $per_page); // 总页数

                                    $data['cname']=$row[0]->CS_Name."->".$title."排序";
                                    $data['nums']=$count;
                                    $data['pagejs']=$pagejs;
                                    $data['ok']='no';
                                    $data['cgid']=$cgid;
                                    $data['page']=$page;
                                    $data['jind']=intval($page/$pagejs*100); //进度条

                                     //------------------------------生成-----------------------------

                                     $neir=$this->CsdjSinger->lists($sort,$id,$page,$row);
                                     if(empty($neir)) die('Error,<a href="javascript:location.reload()">点我刷新重试!</a>');

                                     $html=".".$this->CsdjSkins->LinkUrl('lists','singer',$sort,$id,1,$page,2);
                                     $html=$this->CsdjAdmin->gethtmls($html); //补全HTML地址

                                     if ( ! write_file($html, $neir)){
                                       die("文件没有写入权限！<script type=\"text/javascript\">parent.TokeymakeMsg('msg_list','文件没有写入权限！');parent.Dialog.close();</script>");
                                     }

                                    if($data['pagejs']>$page){
                                               $data['xlink']=site_url('admin/html/singer/')."?op=list&t=id&id=".$id."&cgid=".($cgid+1)."&cid=".$cid."&xid=".$xid."&nums=".$count."&page=".($page+1)."&sort=".$sort."";
                                    }else{
                                         if($xid==($count-1)){
                                              $data['ok']='yes';
                                              $data['type']='msg_list';
                                              $data['neir']="共发布[歌手分类]模块".$count."个分类列表页，".$cgid."个页面。";
                                         }else{
                                               $data['xlink']=site_url('admin/html/singer/')."?op=list&t=id&id=".$Arr[($xid+1)]."&cgid=".($cgid+1)."&cid=".$cid."&xid=".$xid."&nums=".$count."&xid=".($xid+1)."&sort=".$sort."";
                                         }
                                    }
                             }
							 $this->load->get_admin_templates();
                             $this->load->view('admin/html_list',$data);

                  }

            }
        }

	public function topic() //专集
	{
		    $this->load->model('CsdjTopic');
	    $op = $this->input->get('op');
	    $id = $this->input->get('id');
	    $sid = $this->input->get('sid');
	    $xid = $this->input->get('xid');
	    $page = $this->input->get('page');
            if(empty($page)) $page=1;
            if(empty($xid)) $xid=0;
            if(empty($sid)) $sid=1;

                  $data['title']='歌曲专集';
                  if($op=='list'){  //所有分类
                            $Title=array("按ID","按总人气","按月人气","按周人气","按日人气","按推荐","按时间");
                            $Type=array("id","hits","yue","zhou","ri","reco","new");

                            $sqlstr="select * from ".CS_SqlPrefix."topic where CS_SID=".$sid." and CS_YID=0 order by CS_ID desc";
		            $result=$this->CsdjDB->db->query($sqlstr);
		            $recount=$result->num_rows();
                            if($recount==0){
                                   echo "暂时没有专集记录！<script type=\"text/javascript\">parent.TokeymakeMsg('msg_topiclist','暂时没有专集记录！');parent.Dialog.close();parent.Dialog.close();</script>";
                                   exit();
                            }
		            $row=$this->CsdjDB->get_all($sqlstr);
                            if($row){
                                   if($sid==3){
                                       $CS_Template='topic-vod.html';
                                   }else if($sid==2){
                                       $CS_Template='topic-news.html';
                                   }else{
                                       $CS_Template='topic-dance.html';
                                   }
                                    //获取分页标签
                                    $CS_Template="./skins/".Skins_dir.$CS_Template;

                                    //判断模板是否存在
                                    if(!file_exists($CS_Template)){
                                        echo "专题模板《".$CS_Template."》不存在！<script type=\"text/javascript\">parent.TokeymakeMsg('msg_topiclist','专题模板《".$CS_Template."》不存在！');parent.Dialog.close();parent.Dialog.close();</script>";
                                        exit();
                                    }

		                    $template=read_file($CS_Template);
		                    preg_match_all('/{cscms:topic(.*?pagesize=([\S]+).*?)}([\s\S]+?){\/cscms:topic}/',$template,$page_arr);//判断是否有分页标识
		                    if(!empty($page_arr) && !empty($page_arr[2])){
                                           $per_page=$page_arr[2][0];
                                    }else{
                                           $per_page=10;
                                    }
                                    if(empty($per_page)) $per_page=10; 

                                    $pagejs=ceil($recount / $per_page); // 总页数

                                    $data['cname']=$Title[$xid];
                                    $data['nums']=$recount;
                                    $data['pagejs']=$pagejs;
                                    $data['ok']='no';
                                    $data['page']=$page;
                                    $data['jind']=intval($page/$pagejs*100); //进度条

                                     //------------------------------生成-----------------------------

                                     $neir=$this->CsdjTopic->lists($Type[$xid],$sid,$page);
                                     if(empty($neir)) die('Error,<a href="javascript:location.reload()">点我刷新重试!</a>');

                                     $html=".".$this->CsdjSkins->LinkUrl('lists','zj',$Type[$xid],$sid,1,$page,2);
                                     $html=$this->CsdjAdmin->gethtmls($html); //补全HTML地址

                                     if ( ! write_file($html, $neir)){
                                       die("文件没有写入权限！<script type=\"text/javascript\">parent.TokeymakeMsg('msg_topiclist','文件没有写入权限！');parent.Dialog.close();</script>");
                                     }


                                    if($data['pagejs']>$page){
                                               $data['xlink']=site_url('admin/html/topic/')."?op=list&xid=".$xid."&sid=".$sid."&page=".($page+1)."";
                                    }else{
                                         if($xid==6){
                                              $data['ok']='yes';
                                              $data['type']='msg_topiclist';
                                              $data['neir']="共发布[歌曲专集]模块".$pagejs."个列表页，".($page*7)."个页面。";
                                         }else{
                                               $data['xlink']=site_url('admin/html/topic/')."?op=list&xid=".($xid+1)."&sid=".$sid."";
                                         }
                                    }
                             }else{
                                    $data['ok']='yes';
                                    $data['cgid']=$cgid;
                                    $data['nums']=$recount;
                             }
							 $this->load->get_admin_templates();
                             $this->load->view('admin/html_list',$data);

                  }elseif($op=='show'){

	               $tid = $this->input->get_post('tid');
	               $cgid = $this->input->get('cgid');
	               $nums = $this->input->get('nums');
	               $sort = $this->input->get_post('sort');
                       if(empty($cgid)) $cgid=1; 

                       if($sort=='hits'){
                                   $title='总人气';
                       }elseif($sort=='ri'){
                                   $title='日人气';
                       }elseif($sort=='zhou'){
                                   $title='周人气';
                       }elseif($sort=='yue'){
                                   $title='月人气';
                       }elseif($sort=='reco'){
                                   $title='推荐星际';
                       }elseif($sort=='id'){
                                   $title='ID';
                       }else{
                                   $title='最新更新';
                       }

                         if(empty($tid)&&empty($id)) $this->CsdjAdmin->Admin_Url('<font color=red>请选择专集！</font>',site_url('admin/dance/html/'));

                         if (is_array($tid)){
                              $tids=implode(',', $tid);
                              $tid=$tids;
                         }else{
                              $tid=$id;
                         }
                              $Arr=explode(',',$tid);
                              $id=$Arr[$xid];
                              $count=count($Arr);
                            $sqlstr="select * from ".CS_SqlPrefix."topic where cs_id=".$id."";
		            $row=$this->CsdjDB->get_all($sqlstr);
                            if($row){
                                   if(empty($row[0]->CS_Template)){
                                         if($sid==3){
                                             $CS_Template='topic-vod-show.html';
                                         }else if($sid==2){
                                             $CS_Template='topic-news-show.html';
                                         }else{
                                             $CS_Template='topic-dance-show.html';
                                         }
                                   }else{
                                         $CS_Template=$row[0]->CS_Template;
                                   }
                                    //获取分页标签
                                    $CS_Template="./skins/".Skins_dir.$CS_Template;
		                    $template=read_file($CS_Template);
		                    preg_match_all('/{cscms:dance(.*?pagesize=([\S]+).*?)}([\s\S]+?){\/cscms:dance}/',$template,$page_arr);//判断是否有分页标识
		                    if(!empty($page_arr) && !empty($page_arr[2])){
                                           $per_page=$page_arr[2][0];
                                    }else{
                                           echo "模板里没有使用专题分页标签！<script type=\"text/javascript\">parent.TokeymakeMsg('msg_topicshow','模板里没有使用专题分页标签！');parent.Dialog.close();</script>";
                                           exit();
                                    }
                                    if(empty($per_page)) $per_page=10; 

                                    $sql="select * from ".CS_SqlPrefix."dance where CS_TID=".$id." and CS_YID=0 and CS_HID=0";
		                    $query=$this->db->query($sql);
		                    $nums=$query->num_rows();
                                    if($nums==0) $nums=1; 
                                    $pagejs=ceil($nums / $per_page); // 总页数

                                    $data['cname']=$row[0]->CS_Name."->按".$title."排序";
                                    $data['nums']=$count;
                                    $data['pagejs']=$pagejs;
                                    $data['ok']='no';
                                    $data['cgid']=$cgid;
                                    $data['page']=$page;
                                    $data['jind']=intval($page/$pagejs*100); //进度条

                                     //------------------------------生成-----------------------------

                                     $neir=$this->CsdjTopic->show($sort,$id,$page,$row);
                                     if(empty($neir)) die('Error,<a href="javascript:location.reload()">点我刷新重试!</a>');

                                     $html=".".$this->CsdjSkins->LinkUrl('show','zj',$sort,$id,$id,$page,2);
                                     $html=$this->CsdjAdmin->gethtmls($html); //补全HTML地址

                                     if ( ! write_file($html, $neir)){
                                       die("<script type=\"text/javascript\">parent.TokeymakeMsg('msg_topicshow','文件没有写入权限！');parent.Dialog.close();</script>");
                                     }

                                    if($pagejs>$page){
                                               $data['xlink']=site_url('admin/html/topic/')."?op=show&cgid=".($cgid+1)."&id=".$tid."&xid=".$xid."&sort=".$sort."&nums=".$count."&page=".($page+1)."";
                                    }else{
                                         if($xid==($count-1)){
                                              $data['ok']='yes';
                                              $data['type']='msg_topicshow';
                                              $data['neir']="共发布[歌曲专集]模块".$count."个专集，".$cgid."个页面。";
                                         }else{
                                               $data['xlink']=site_url('admin/html/topic/')."?op=show&id=".$tid."&cgid=".($cgid+1)."&sort=".$sort."&nums=".$count."&xid=".($xid+1)."";
                                         }
                                    }
                             }

							 $this->load->get_admin_templates();
                             $this->load->view('admin/html_list',$data);

                  }elseif($op=='showall'){

	               $cgid = $this->input->get('cgid');
	               $sid = $this->input->get('sid');
	               $nums = $this->input->get('nums');
	               $sort = $this->input->get_post('sort');
                       if(empty($cgid)) $cgid=1; 
                       if(empty($sort)) $sort='id'; 
                       if(empty($sid)) $sid=1; 

                       if(empty($id)){
                            $sqlstr="select * from ".CS_SqlPrefix."topic where CS_SID=".$sid." and CS_YID=0 order by CS_ID desc";
		            $result=$this->CsdjDB->db->query($sqlstr);
		            $recount=$result->num_rows();
                            if($recount==0){
                                   echo "暂时没有专集记录！<script type=\"text/javascript\">parent.TokeymakeMsg('msg_topicshow','暂时没有专集记录！');parent.Dialog.close();</script>";
                                   exit();
                            }
                            $count=$recount;
		            $rows=$this->CsdjDB->get_all($sqlstr);
                            $id=$rows[0]->CS_ID;
                       }else{
                            $count=$nums;
                       }

                            $sqlstr="select * from ".CS_SqlPrefix."topic where cs_id=".$id."";
		            $row=$this->CsdjDB->get_all($sqlstr);
                            if($row){
                                   if(empty($row[0]->CS_Template)){
                                         $CS_Template='topic-dance-show.html';
                                   }else{
                                         $CS_Template=$row[0]->CS_Template;
                                   }
                                    //获取分页标签
                                    $CS_Template="./skins/".Skins_dir.$CS_Template;
		                    $template=read_file($CS_Template);
                                    if($sid==3){
                                          $table="vod";
		                          preg_match_all('/{cscms:vod(.*?pagesize=([\S]+).*?)}([\s\S]+?){\/cscms:vod}/',$template,$page_arr);//判断是否有分页标识
                                    }elseif($sid==2){
                                          $table="news";
		                          preg_match_all('/{cscms:news(.*?pagesize=([\S]+).*?)}([\s\S]+?){\/cscms:news}/',$template,$page_arr);//判断是否有分页标识
                                    }else{
                                          $table="dance";
		                          preg_match_all('/{cscms:dance(.*?pagesize=([\S]+).*?)}([\s\S]+?){\/cscms:dance}/',$template,$page_arr);//判断是否有分页标识
                                    }
		                    if(!empty($page_arr) && !empty($page_arr[2])){
                                           $per_page=$page_arr[2][0];
                                    }else{
                                           $per_page=50;
                                    }
                                    if(empty($per_page)) $per_page=10; 

                                    $sql="select * from ".CS_SqlPrefix.$table." where CS_TID=".$id." and CS_YID=0 and CS_HID=0";
		                    $query=$this->db->query($sql);
		                    $nums=$query->num_rows();
                                    if($nums==0) $nums=1; 
                                    $pagejs=ceil($nums / $per_page); // 总页数

                                    $data['cname']=$row[0]->CS_Name."->按".$sort."排序";
                                    $data['nums']=$count;
                                    $data['pagejs']=$pagejs;
                                    $data['ok']='no';
                                    $data['cgid']=$cgid;
                                    $data['page']=$page;
                                    $data['jind']=intval($page/$pagejs*100); //进度条

                                     //------------------------------生成-----------------------------

                                     $neir=$this->CsdjTopic->show($sort,$id,$page,$row);
                                     if(empty($neir)) die('Error,<a href="javascript:location.reload()">点我刷新重试!</a>');

                                     $html=".".$this->CsdjSkins->LinkUrl('show','zj','id',$id,$id,$page,2);
                                     $html=$this->CsdjAdmin->gethtmls($html); //补全HTML地址

                                     if ( ! write_file($html, $neir)){
                                       die("<script type=\"text/javascript\">parent.TokeymakeMsg('msg_topicshow','文件没有写入权限！');parent.Dialog.close();</script>");
                                     }

                                     //下一个ID
                                     $sql="Select CS_ID from ".CS_SqlPrefix."topic where CS_ID<".$id." and CS_SID=".$sid." and CS_YID=0  order by CS_ID desc";
		                     $rows=$this->CsdjDB->get_all($sql);
                                     if($rows){
                                          $xid=$rows[0]->CS_ID; //下ID
                                     }else{
                                          $xid=0; //下ID
                                     }
                                    if($pagejs>$page){
                                               $data['xlink']=site_url('admin/html/topic/')."?op=showall&cgid=".($cgid+1)."&id=".$id."&sid=".$sid."&nums=".$count."&page=".($page+1)."&sort=".$sort."";
                                    }else{
                                         if($xid==0){
                                              $data['ok']='yes';
                                              $data['type']='msg_topicshow';
                                              $data['neir']="共发布[歌曲专集]模块".$count."个专集，".$cgid."个页面。";
                                         }else{
                                               $data['xlink']=site_url('admin/html/topic/')."?op=showall&id=".$xid."&cgid=".($cgid+1)."&sid=".$sid."&nums=".$count."&sort=".$sort."";
                                         }
                                    }
                             }

							 $this->load->get_admin_templates();
                             $this->load->view('admin/html_list',$data);

                  }
        }
}

