<?php
if (!defined('GV32_COM')) exit('GV32.COM No direct script access allowed');
class Video
{
	function Video()
	{
		//$GLOBALS['WebSe'] -> isOnLine();
		//$GLOBALS['Templ']->assign('actUrl',EMPLOYEE_WEBURL."/index.php/login/actlogin");
	}
	
	function infolist()
	{
		$pageSize = 20 ;
		
		$keywordval 	= $GLOBALS['Reque'] -> reqval["keyword"];
		$vis_idval 		= $GLOBALS['Reque'] -> funpost("vis_id");
		$pageNumval 	= $GLOBALS['Reque'] -> getval["pageNum"];
		
		if( $pageNumval > 1 )
		{
			$pageNum  = $pageNumval;
			$LIMITnum = ceil( ( $pageNumval -1 ) * $pageSize );
		}else{
			$pageNum  = 1;
			$LIMITnum = 0 ;
		}

		
		if($vis_idval !='' and $vis_idval !='A')
		{
			$vis_idval 	= $vis_idval;
		}else{
			$vis_idval = $GLOBALS['Reque'] -> getval["vis_id"];
		}
		
		if($vis_idval!='' and $vis_idval !='A' )
		{ 
			 
			 $endArray["vis_id"] = $vis_idval;
			 
			 $endurl 	  		.= '&prs='.$vis_idval;
			 
			 $sidsql  = " SELECT vis_id FROM ".SQL_PREFIX."vidsort WHERE vis_parentid = ".$vis_idval." or  vis_id = ".$vis_idval;
			 
		     $sortInfo 	  = $GLOBALS['MySql'] -> selectInfo( $sidsql );
			 
			 //var_dump( $sortInfo  );
			 $sinid  = '';
			if($sortInfo!='')
			{
				foreach( $sortInfo as $skey => $sval )
				{
					if($skey==0)
					{
						$sinid = $sval["vis_id"];
					}else{
						$sinid .= ','.$sval["vis_id"];
					}
				}
				$whereadd .= " AND ( p.vis_id IN ( ".$sinid." ) )";
			}
		 }else{ 
		 	$endurl 	   .= '&prs=A'; 	
		 }
		
		
		if($GLOBALS['Reque'] -> reqval["keyword"] !='')
		{   
			$keywordval 	= $GLOBALS['Reque'] -> reqval["keyword"];
			$keywordval  	= urldecode($keywordval); 
		}
		if($keywordval!='')
		{ 	
			$endArray["keyword"] =$keywordval;
			$endurl 	   .= '&keyword='.urlencode($keywordval);
			$whereadd .= " AND ( p.vid_name LIKE  '%".$keywordval."%' )";  
		}

		$listval  = $GLOBALS['Reque'] -> getval["listval"];
		$listtype = $GLOBALS['Reque'] -> getval["listtype"];

		$orderbyval = "";
		
		if($listval!='' and $listtype =='DESC' )
		{
			$endArray["listtype"] = 'DESC';
			$endArray["listval"]  = $listval;
			$orderbyval = $listval ."  DESC ";
			$listhtml = '';	//反向排序参数
			
		}elseif($listval!='' )
		{
			$orderbyval = $listval;
			$listhtml = 'DESC';
			
			$endArray["listtype"] = '';
			$endArray["listval"]  = $listval;

		}else{
			$endArray["listtype"] = 'DESC';
			$endArray["listval"]  = 'vid_uptime';
			$orderbyval = " p.vid_uptime DESC , `vid_id` DESC ";	
		}
		
		//序号 	商品标题 	商品分类 	数量 	销售价 	是否显示 	更新时间
		$sqlQuery = " SELECT p.vid_id, p.vid_name,p.vis_id,p.vid_count, p.vid_enabled , p.vid_uptime   FROM  ".SQL_PREFIX."video as p    WHERE vid_ismaster = 1 $whereadd  GROUP BY p.vid_id ORDER BY $orderbyval LIMIT  $LIMITnum , $pageSize ";
		
		$info 		= $GLOBALS['MySql'] -> selectInfo($sqlQuery);
		
		$sqlQuery 	= " SELECT count(1) as CNUM  FROM  ".SQL_PREFIX."video as p  WHERE 1 $whereadd  ORDER BY p.`vid_id`  ";
		
		$infocount 	= $GLOBALS['MySql'] -> selectOne($sqlQuery);
		
		//var_dump($info);
		
		$PageStr = $GLOBALS['Page']->buildPageStr( $url = '?load=video&act=infolist', $pageNum  , $pageSize  , $resultCount = $infocount["CNUM"] , $endArray );
		
		$GLOBALS['Templ']->assign('listhtml',$listhtml);
		$GLOBALS['Templ']->assign('listval',$listval);
		$GLOBALS['Templ']->assign('listtype',$listtype);

		
		
		$GLOBALS['Templ']->assign('vis_idval',$vis_idval);
		$GLOBALS['Templ']->assign('keywordval',$keywordval);
		
		$this -> getSort();
		
		
		$GLOBALS['Templ']->assign('PageStr',$PageStr);
		$GLOBALS['Templ']->assign('info',$info);
		

		$GLOBALS['Templ']->display('video_tpl.html');
		
	}
	
	function getSort()
	{
		$sqlQuery = " SELECT vis_id, vis_name,vis_parentid  FROM  ".SQL_PREFIX."vidsort  WHERE 1 and vis_enabled = 1 GROUP BY vis_id ORDER BY `vis_list` limit 1000 ";
		
		$infosm = $GLOBALS['MySql'] -> selectInfo($sqlQuery);
		
		$vsInfo = array();
		foreach ($infosm as $rowkey => $rowval)
		{
				if($rowval["vis_parentid"] == 0)
				{
					$vsInfo[$rowval["vis_id"]]['vis_id'] = $rowval["vis_id"] ;
					$vsInfo[$rowval["vis_id"]]['vis_name'] = $rowval["vis_name"] ;
					$vsInfo[$rowval["vis_id"]]['vis_parentid'] = $rowval["vis_parentid"] ;
				}else{
					$vsInfo[$rowval["vis_parentid"]]['array'][] = $rowval;	
				}
				$vsInfoval[$rowval["vis_id"]] = $rowval["vis_name"] ;
		}
		
		$GLOBALS['Templ']->assign('vsInfoval',$vsInfoval);		//列排表显示使用
		
		$GLOBALS['Templ']->assign('vsInfo',$vsInfo);		
		//return $vsInfo;
	}
	
	
	function add()
	{
		///$GLOBALS['Templ'] -> caching = true;
		//$GLOBALS['Templ'] -> cache_lifetime = 86400 ;  //60 *  60 * 24

		$this -> getSort();
		
		
		$GLOBALS['Helpe'] -> load_ckeditor( $textName = 'vid_content','','Basic'  );	//加载文本编辑器

		
		$GLOBALS['Templ']->assign('actUrl',EMPLOYEE_WEBURL."/index.php?load=video&act=addinfo");
		$GLOBALS['Templ']->display('videoadd_tpl.html');
		
	}
	
	function addinfo()
	{
		
		$vid_nameval 	= $GLOBALS['Reque'] -> funpost("vid_name");
		$vis_idval 		= $GLOBALS['Reque'] -> funpost("vis_id");
		$vid_pinyinval	= $GLOBALS['Reque'] -> funpost("vid_pinyin");
		
		$vid_imgval 	= $GLOBALS['Reque'] -> funpost("vid_img");
		$vid_urlval 	= $GLOBALS['Reque'] -> funpost("vid_url");
		$vid_contentval = $_POST["vid_content"];
		$vid_enabledval 	= $GLOBALS['Reque'] -> funpost("vid_enabled");	

		
		if( $vid_nameval !='' and $vis_idval !='' and  $vid_urlval != '' )
		{
			$sqlQuery = " SELECT count(1) as CNUM  FROM  ".SQL_PREFIX."video  WHERE vid_name = '".$vid_nameval."' ORDER BY `vid_id` ";
			
			$info = $GLOBALS['MySql'] -> selectOne($sqlQuery);
			
			if( $info["CNUM"] < 1 )
			{
				$vid_uptimeval = $vid_addtimeval 	= time();
				
				///$use_idval			= $_SESSION["emplyeeUser"]["use_id"];

				$insertpro =" INSERT INTO `".SQL_PREFIX."video` (`vid_name` , `vid_pinyin` , `vis_id` , `vid_img`,`vid_url` , `vid_content` , `vid_enabled` ,`vid_ismaster`,vid_uptime, vid_addtime) VALUES (  '$vid_nameval', '$vid_pinyinval',  '$vis_idval','$vid_imgval', '$vid_urlval', '$vid_contentval', '$vid_enabledval',1 ,'$vid_uptimeval', '$vid_addtimeval')";

				$proinsertId = $GLOBALS['MySql'] -> insertSql($insertpro);

				$GLOBALS['Templ'] -> assign('infomessage',$GLOBALS['_LANG']['bd_addsusse']);
				$GLOBALS['Templ'] -> assign('URL_TIME',URL_TIME);
				$GLOBALS['Templ'] -> assign('geturl',EMPLOYEE_WEBURL."/index.php?load=video&act=infolist");
				$GLOBALS['Templ'] -> display('suggestion_tpl.html');	
			}else{
				
				$GLOBALS['Templ'] -> assign('infomessage',$GLOBALS['_LANG']['bd_isrealyerror']);
				$GLOBALS['Templ'] -> assign('URL_TIME',URL_TIME);
				$GLOBALS['Templ'] -> assign('geturl',EMPLOYEE_WEBURL."/index.php?load=video&act=add");
				$GLOBALS['Templ'] -> display('suggestion_tpl.html');	
			}
			
		}else{
			
			$GLOBALS['Templ'] -> assign('infomessage',$GLOBALS['_LANG']['bd_losssusse']);
			$GLOBALS['Templ'] -> assign('URL_TIME',URL_TIME);
			$GLOBALS['Templ'] -> assign('geturl',EMPLOYEE_WEBURL."/index.php?load=video&act=add");
			$GLOBALS['Templ'] -> display('suggestion_tpl.html');		}
			//var_dump($_REQUEST);
	}
	
	function del()
	{
		
		$infoid = $GLOBALS['Reque'] -> getval["id"];
		
		$deletesql ="DELETE FROM `".SQL_PREFIX."video` WHERE `".SQL_PREFIX."video`.`vid_id` in ( $infoid ) ";
		
		$GLOBALS['MySql'] -> querySql($deletesql);
		$GLOBALS['Templ'] -> assign('infomessage',$GLOBALS['_LANG']['bd_delsusse']);
		$GLOBALS['Templ'] -> assign('URL_TIME',URL_TIME);
		$GLOBALS['Templ'] -> assign('geturl',EMPLOYEE_WEBURL."/index.php?load=video&act=infolist");
		$GLOBALS['Templ'] -> display('suggestion_tpl.html');
		
		
	}
	
	
	
	function info()
	{
		//$infoid = $infoArray[0];
		$idval = $GLOBALS['Reque'] -> getval["id"];

		$sqlQuery = " SELECT *  FROM  ".SQL_PREFIX."video  WHERE vid_id = '".$idval."' ORDER BY `vid_id` ";
		$info = $GLOBALS['MySql'] -> selectOne($sqlQuery);
		$GLOBALS['Templ']->assign('actUrl',EMPLOYEE_WEBURL."/index.php?load=video&act=editinfo");
		$GLOBALS['Templ'] -> assign('info',$info);
		
		$this -> getSort();
		
		$GLOBALS['Helpe'] -> load_ckeditor( $textName = 'vid_content' ,$textValue = $info["vid_content"] ,'Basic' );	 //加载文本编辑器
		
		
		$GLOBALS['Templ'] -> display('videoedit_tpl.html');
	
	}
	
	
	function editinfo()
	{	
	
		$vid_idval 		= $GLOBALS['Reque'] -> funpost("vid_id");	
		$vid_nameval 	= $GLOBALS['Reque'] -> funpost("vid_name");
		$vis_idval 		= $GLOBALS['Reque'] -> funpost("vis_id");
		$vid_pinyinval	= $GLOBALS['Reque'] -> funpost("vid_pinyin");
		$vid_urlval 	= $GLOBALS['Reque'] -> funpost("vid_url");
		$vid_imgval 	= $GLOBALS['Reque'] -> funpost("vid_img");
		$vid_contentval = $_POST["vid_content"];
		$vid_enabledval 	= $GLOBALS['Reque'] -> funpost("vid_enabled");
		
		
		if($vid_idval !='' and  $vid_nameval !='' and $vis_idval !=''  and $vid_contentval != '' )
		{
			$vid_uptimeval =  time();
			$updatesql = " UPDATE `".SQL_PREFIX."video` SET  vid_name = '".$vid_nameval."' , vid_pinyin = '".$vid_pinyinval."' , vis_id = '".$vis_idval."', vid_img = '".$vid_imgval."',vid_url = '".$vid_urlval."', vid_content = '".$vid_contentval."', vid_enabled = '".$vid_enabledval."' WHERE  vid_id = '".$vid_idval."' ";
			
			$GLOBALS['MySql'] -> querySql( $updatesql );
			
			$GLOBALS['Templ'] -> assign('infomessage',$GLOBALS['_LANG']['bd_editsusse']);
			$GLOBALS['Templ'] -> assign('URL_TIME',URL_TIME);
			$GLOBALS['Templ'] -> assign('geturl',EMPLOYEE_WEBURL."/index.php?load=video&act=infolist");
			$GLOBALS['Templ'] -> display('suggestion_tpl.html');
				
		}else{
		
			$GLOBALS['Templ'] -> assign('infomessage',$GLOBALS['_LANG']['bd_losssusse'] );
			$GLOBALS['Templ'] -> assign('URL_TIME',URL_TIME);
			$GLOBALS['Templ'] -> assign('geturl',EMPLOYEE_WEBURL."/index.php?load=video&act=info&id=".$vid_idval);
			$GLOBALS['Templ'] -> display('suggestion_tpl.html');	
		}
		
	}
	
	function show()
	{
		//$indel = implode(',', $delArray);

		$infoid = $GLOBALS['Reque'] -> getval["id"];
		
		$upshow = " UPDATE `".SQL_PREFIX."video` SET vid_enabled = 1  WHERE  `vid_id` in ( $infoid ) ";

		$GLOBALS['MySql'] -> querySql($upshow);
		$GLOBALS['Templ'] -> assign('infomessage',$GLOBALS['_LANG']['bd_showsusse']);
		$GLOBALS['Templ'] -> assign('URL_TIME',URL_TIME);
		$GLOBALS['Templ'] -> assign('geturl',EMPLOYEE_WEBURL."/index.php?load=video&act=infolist");
		$GLOBALS['Templ'] -> display('suggestion_tpl.html');
	}
	
	function hide()
	{
		//$indel = implode(',', $delArray);
		
		$infoid = $GLOBALS['Reque'] -> getval["id"];
		/*
		if($idval)
		{
			$infoid = implode(',', $idval);
		}*/

		$uphide = " UPDATE `".SQL_PREFIX."video` SET vid_enabled = 0  WHERE `vid_id` in ( $infoid ) ";

		$GLOBALS['MySql'] -> querySql($uphide);
		$GLOBALS['Templ'] -> assign('infomessage',$GLOBALS['_LANG']['bd_hidesusse']);
		$GLOBALS['Templ'] -> assign('URL_TIME',URL_TIME);
		$GLOBALS['Templ'] -> assign('geturl',EMPLOYEE_WEBURL."/index.php?load=video&act=infolist");
		$GLOBALS['Templ'] -> display('suggestion_tpl.html');
	}
	

}

//nmon_x86_rhel4

$Video = new Video();

?>