<?php 
class VideoAction extends GlobalAction 
{
	public function index()
	{
		$this->title($this->channel['title']);
		$VideoView = D('VideoView');
		$map['channels']=$this->channel['id'];
		$count = $VideoView->count($map);
		$limits = 10;
		import("ORG.Util.Page");
		$p=new page($count,$limits);
		$videoview_list = $VideoView->where($map)->order('id desc')->limit($p->firstRow.','.$p->listRows)->findall();
		$lapel = $p->show();
		//分类
		$Category=M('Category')->order("displayorder")->where($map)->findall();
		//最新推荐
		//$recommended = $VideoView->where($map)->order('ischecked,id desc')->limit(5)->findall();
		//热点新闻
		//$hot_news = $VideoView->where($map)->order('hits desc,id desc')->limit(5)->findall();
		
		//$this->assign('recommended',$recommended);
		//$this->assign('hot_news',$hot_news);
		$this->assign('cate',$Category);
		$this->assign('lapel',$lapel);
		$this->assign('list',$videoview_list);
		$this->display('Video:index');
	}
	public function sorts()
	{
		$this->title($this->channel['title']);
		$id=intval($_REQUEST['id']);
		$ArticleView = D('ArticleView');
		$map['channels']=$this->channel['id'];
		//分类
		$Category=M('Category')->order("displayorder")->where($map)->findall();
		$map['cid']=$id;
		$count = $ArticleView->count($map);
		$limits = 10;
		import("ORG.Util.Page");
		$p=new page($count,$limits);
		$article_list = $ArticleView->where($map)->order('id desc')->limit($p->firstRow.','.$p->listRows)->findall();
		$lapel = $p->show();
		
		//最新推荐
		$recommended = $ArticleView->where($map)->order('ischecked,id desc')->limit(5)->findall();
		//热点新闻
		$hot_news = $ArticleView->where($map)->order('hits desc,id desc')->limit(5)->findall();
		//热点排行
		$hot_top_week = $ArticleView->where($map)->order('hits desc,id desc')->limit(5)->findall();
		$hot_top_on = $ArticleView->where($map)->order('hits desc,id desc')->limit(5)->findall();
		$hot_top_total = $ArticleView->where($map)->order('hits desc,id desc')->limit(5)->findall();
		
		$this->assign('recommended',$recommended);
		$this->assign('hot_news',$hot_news);
		$this->assign('hot_top_week',$hot_top_week);
		$this->assign('hot_top_on',$hot_top_on);
		$this->assign('hot_top_total',$hot_top_total);
		$this->assign('cate',$Category);
		$this->assign('lapel',$lapel);
		$this->assign('list',$article_list);
		$this->display('Video:index');
	}
	public function read(){
		$this->title($this->channel['title']);
		$id=intval($_GET['id']);
		$ArticleView = D('ArticleView');
		$map['channels']=$this->channel['id'];
		//分类
		$Category=M('Category')->order("displayorder")->where($map)->findall();
		//最新推荐
		$recommended = $ArticleView->where($map)->order('id desc')->findall();
		$map['id']=$id;
		$list = $ArticleView->where($map)->find();
		if (!$list) $this->error("信息不存在");
		$ArticleView->setINC('Article.hits','Article.id='.$id);
		$this->title($list['subject']);
		$this->assign('Category',$Category);
		//上一篇
		$ma['channels']=$this->channel['id'];
		$ma['id']=array('lt',$id);
		$front = $ArticleView->where($ma)->order('Article.id desc')->find();
		$f=!$front?'没有了':'<A href="'.__APP__.'/'.$this->channel['folder'].'/read/id/'.$front['id'].'.html'.'">'.$front['subject'].'</A>';
		$this->assign('front',$f);
		//下一篇
		$ma['id']=array('gt',$id);
		$after = $ArticleView->where($ma)->find();
		$a=!$after?'没有了':'<A href="'.__APP__.'/'.$this->channel['folder'].'/read/id/'.$after['id'].'.html'.'">'.$after['subject'].'</A>';
		$this->assign('recommended',$recommended);
		$this->assign('after',$a);
		$this->assign('list',$list);
		$this->display('Video:read');

	}
	public function commentsave()
	{
		$seccode=trim($_POST['seccode']);
		if(md5($seccode)!=Session::get('verify'))$this->error('验证码错误!!!');
		$Comment=D("Comment");
        if($Comment->create()) { 
        	$Comment->ip=get_client_ip();
            if($Comment->add()){ 
            	$this->assign('jumpUrl',__URL__);
				$this->success(L('_OPERATION_SUCCESS_'));
            }else{ 
                $this->error(L(_INSERTFAIL)); 
            } 
        }else{ 
            $this->error($Comment->getError()); 
        } 
	}
}
?>