<?php
/**
 *----------------------------------------------------------------------------*
 * 版权所有 2005-2010 GV32.COM，并保留所有权利。
 * 网站地址: http://www.gv32.com；
 * 作者: GV32.COM
 *----------------------------------------------------------------------------*
**/
class Vid
{
	function Vid()
	{
		//缓存
		if($GLOBALS["WebConfig"]["webtmp"]==1)
		{
			$GLOBALS['Templ'] -> caching = true;
			if($GLOBALS["WebConfig"]["webtmptime"] > 0 )
			{
				$GLOBALS['Templ'] -> cache_lifetime = $GLOBALS["WebConfig"]["webtmptime"] ;
			}else{
				$GLOBALS['Templ'] -> cache_lifetime = 3600 ;  //60 *  60 * 24
			}
			$smdirid 	= trim($_REQUEST["sid"]).trim($_REQUEST["id"]).trim($_REQUEST["pageNum"]);
			$GLOBALS['Templ'] -> cache_dir = ROOT_PATH.$GLOBALS['cache_path'].'/'.$GLOBALS['Helpe'] -> buildsmartydir( $type = 'v', $smdirid );
		}
		
		
		$getconfig = $GLOBALS['Helpe'] -> get_config();
		$GLOBALS['Templ'] -> assign('getconfig',$getconfig);

		$getmenu = $GLOBALS['Helpe'] -> get_menu();
		$GLOBALS['Templ'] -> assign('getmenu',$getmenu);
		
		$getvidsort = $GLOBALS['Helpe'] -> get_vidsort();
		$GLOBALS['Templ'] -> assign('getvidsort',$getvidsort);
		
		$getlink = $GLOBALS['Helpe'] -> get_link();
		$GLOBALS['Templ'] -> assign('getlink',$getlink);
			
		$getads = $GLOBALS['Helpe'] -> get_ads( $instr = '1,2,3,4,5,6,7,8,9,10,11' );
		$GLOBALS['Templ'] -> assign('getads',$getads);
		
		$getuserlink = $GLOBALS['WebSe']->getuserlink();
		$GLOBALS['Templ']->assign('getuserlink',$getuserlink);
		$act = trim($_REQUEST["act"]);
		if($act=='')
		{
			$this -> infolist();
		}
		
	}
	
	function infolist()
	{
	
		$sid 		= trim($_REQUEST["sid"]);
		$pageNum 	= trim($_REQUEST["pageNum"]);
		
		$pageSize = 16 ;

		if( $pageNum > 1 )
		{
			$pageNum  = $pageNum;
			$LIMITnum = ceil( ( $pageNum -1 ) * $pageSize );
		}else{
			$pageNum  = 1;
			$LIMITnum = 0 ;
		}

		$addsql = '';

		$webtitle = '视频中心';
		//处理你现在的位置
		if( $GLOBALS["WebConfig"]["webhtml"] == 1 )
		{
			$nowaddress = '您的位置：<a href="'.BASE_WEBURL.'/">首页</a> > <a href="'.BASE_WEBURL.'/vid.html">视频中心</a>';
		}else{
			$nowaddress = '您的位置：<a href="'.BASE_WEBURL.'/">首页</a> > <a href="'.BASE_WEBURL.'/?load=vid&act=infolist">视频中心</a>';
		}


		if( $sid > 0 )
		{
			$addsql = " and vis_id = ".$sid;
			$endArray["sid"] = $sid;
		}
		if( $sid != '' )
		{
			$seletsort = " SELECT vis_id,vis_name  FROM ".SQL_PREFIX."vidsort WHERE vis_id = ".$sid." or  vis_parentid = ".$sid ;
			$sortInfo  = $GLOBALS['MySql']  ->  selectInfo($seletsort);
			$sinid 	   = '';
			$addpage   = '&sid='.$sid;
			if($sortInfo!='')
			{
				foreach( $sortInfo as $skey => $sval )
				{
					if( $sval["vis_id"]== $sid )
					{
						$webtitle 	= $sortval = $sval["vis_name"];
						
						if( $GLOBALS["WebConfig"]["webhtml"] == 1 )
						{
							$nowaddress = $nowaddress. ' > <a href="'.BASE_WEBURL.'/vid-list-1-'.$sid.'.html">'.$sval["vis_name"].'</a>';
						}else{
							$nowaddress = $nowaddress. ' > <a href="'.BASE_WEBURL.'/?load=vid&act=infolist'.$addpage.'">'.$sval["vis_name"].'</a>';
						}
					}
					if($skey==0)
					{
						$sinid = $sval["vis_id"];
					}else{
						$sinid .= ','.$sval["vis_id"];
					}
				}
			}
			$addsql = " and vis_id in ( ".$sinid." ) ";
		}
		
		
		if($GLOBALS['Reque'] -> reqval["keyword"] !='')
		{   
			$keywordval 	= $GLOBALS['Reque'] -> reqval["keyword"];
			$keywordval  	= urldecode($keywordval); 
		}
		if($keywordval!='')
		{ 	
			$endArray["keyword"] =$keywordval;
			$endurl 	   .= '&keyword='.urlencode($keywordval);
			$addsql .= " AND ( vid_name LIKE  '%".$keywordval."%' )";  
		}


		$sqlQuery 	= " SELECT vid_id, vid_name ,vid_img, vid_uptime   FROM  ".SQL_PREFIX."video   WHERE vid_enabled= 1 $addsql  GROUP BY  vid_id ORDER BY  `vid_id` LIMIT  $LIMITnum , $pageSize ";
		$info 		= $GLOBALS['MySql']  ->  selectInfo( $sqlQuery );
		
		
		foreach((array)$info as $pkey => $pval )
		{
			 $info[$pkey]["vid_img"] = $GLOBALS['Helpe'] -> buildImg( $pval["vid_img"] ) ; 
			 $info[$pkey]["get_url"] = $GLOBALS['Helpe']  -> buildUrl( $valid = $pval["vid_id"],'vid');
		}


		
		$sqlQuery 	= " SELECT count(1) as CNUM  FROM  ".SQL_PREFIX."video  WHERE vid_enabled = 1 $addsql ORDER BY `vid_id`  ";
		$infocount 	= $GLOBALS['MySql']  ->  selectOne( $sqlQuery );
		
		
		if( $GLOBALS["WebConfig"]["webhtml"] == 1 )
		{
			$url = BASE_WEBURL.'/vid-list';
			$endArray["sid"] = $sid;
		}else{
			$url = './?load=vid&act=infolist'.$addpage.$addurl;
		}
		$PageStr 	= $GLOBALS['Page'] -> buildPageStr( $url , $pageNum  , $pageSize  , $resultCount = $infocount["CNUM"] ,$endArray );
		
		$GLOBALS['Templ'] -> assign('keyword',$keywordval);
		
		$GLOBALS['Templ'] -> assign('webtitle',$webtitle);
		$GLOBALS['Templ'] -> assign('nowaddress',$nowaddress);
		$GLOBALS['Templ'] -> assign('PageStr',$PageStr);
		$GLOBALS['Templ'] -> assign('info',$info);
		if($sid !='' or $pageNum!='' or  $newkeyword !='')
		{
			$cache_id = $sid.'p'.$pageNum.'k'.$keyid;
		}
		$GLOBALS['Templ'] -> display('vidlist_tpl.html',$cache_id);
	}
	
	function detail()
	{
		$id 		= trim($_REQUEST["id"]);

		if( $GLOBALS["WebConfig"]["webhtml"] == 1 )
		{
			$nowaddress = '您的位置：<a href="'.BASE_WEBURL.'/">首页</a> > <a href="'.BASE_WEBURL.'/vid.html">视频中心</a>';
		}else{
			$nowaddress = '您的位置：<a href="'.BASE_WEBURL.'/">首页</a> > <a href="'.BASE_WEBURL.'/?load=vid&act=infolist">视频中心</a>';
		}
		
		if($id > 0 )
		{
			$sqlQuery 	= " SELECT p.* ,s.vis_name  FROM  ".SQL_PREFIX."video as p , ".SQL_PREFIX."vidsort  as s   WHERE p.vis_id = s.vis_id and p.vid_enabled = 1  and p.vid_id = ".$id." ORDER BY p.`vid_id`  ";
			
			$infodetail 	= $GLOBALS['MySql']  ->  selectOne($sqlQuery);
			
			$infoItemval = array();
			
			$infoItemval[0]["pii_url"] = $GLOBALS['Helpe'] -> buildImg( $infodetail["vid_url"] ) ;
			$infoItemval[0]["pii_id"]  = 0 ;
			$infoItemval[0]["vid_id"]  = $infodetail["vid_id"] ;  

			//var_dump( $infoItem );

			$nowaddress = $nowaddress. " > 详细内容";
			$webtitle = $infodetail["vid_name"];
			
			$sqlup = " UPDATE ".SQL_PREFIX."video set vid_count = vid_count +1 WHERE vid_id = ".$id ; 
			
			$GLOBALS['MySql'] -> querySql($sqlup);
			
			//查询上一组及下一组
			//查询上一组
			$prosql = " SELECT vid_id, vid_name  FROM ".SQL_PREFIX."video WHERE  vid_id < ".$infodetail["vid_id"]." GROUP BY vid_id   ORDER BY vid_id  DESC ";
			$Prodetail 	= $GLOBALS['MySql']  ->  selectOne($prosql);
			$Prodetail["vid_url"]= $GLOBALS['Helpe']  -> buildUrl( $valid = $Prodetail["vid_id"],'vid');
			
			//查询下一组
			$nextsql = " SELECT vid_id, vid_name  FROM ".SQL_PREFIX."video WHERE  vid_id > ".$infodetail["vid_id"]." GROUP BY vid_id  ORDER BY vid_id  ";
			$Nextdetail 	= $GLOBALS['MySql']  ->  selectOne($nextsql);
			$Nextdetail["vid_url"]= $GLOBALS['Helpe']  -> buildUrl( $valid = $Nextdetail["vid_id"],'vid');
			
			$GLOBALS['Templ'] -> assign('Prodetail',$Prodetail);
			$GLOBALS['Templ'] -> assign('Nextdetail',$Nextdetail);

			
			
			
			$GLOBALS['Templ'] -> assign('infoItemval',$infoItemval);

			$GLOBALS['Templ'] -> assign('nowaddress',$nowaddress);
			$GLOBALS['Templ'] -> assign('webtitle',$webtitle);
			$GLOBALS['Templ'] -> assign('infodetail',$infodetail);
			$cache_id = $id.'d'.$pageNum;
			$GLOBALS['Templ'] -> display('vid_tpl.html',$cache_id);
			
			
		}else{
			$GLOBALS['Helpe'] -> error404();

		}
	
	}



	function play()
	{
		$id = trim($_REQUEST["id"]);
		
		if($id > 0 )
		{
			$sqlQuery 	= " SELECT vid_name,vid_url   FROM  ".SQL_PREFIX."video   WHERE vid_enabled = 1  and vid_id = ".$id." ORDER BY `vid_id`  ";
			$info 	= $GLOBALS['MySql']  ->  selectOne($sqlQuery);
		}
		
		$GLOBALS['Templ'] -> assign('info',$info);
		$GLOBALS['Templ'] -> display('vidplay_tpl.html');
	
	}
	

}

$Vid = new Vid();

?>