<?php
if (!defined('GV32_COM')) exit('GV32.COM No direct script access allowed');
class Book
{
	function Book()
	{
		//$GLOBALS['WebSe'] -> isOnLine();
		//$GLOBALS['Templ']->assign('actUrl',EMPLOYEE_WEBURL."/index.php/login/actlogin");
	}
	
	function infolist()
	{
		$pageSize = 20 ;
		
		$keywordval 	= $GLOBALS['Reque'] -> funpost("keyword");
		$prs_idval 		= $GLOBALS['Reque'] -> funpost("prs_id");
		$pageNumval 	= $GLOBALS['Reque'] -> getval["pageNum"];
		
		if( $pageNumval > 1 )
		{
			$pageNum  = $pageNumval;
			$LIMITnum = ceil( ( $pageNumval -1 ) * $pageSize );
		}else{
			$pageNum  = 1;
			$LIMITnum = 0 ;
		}
		
		$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"]  = 'art_uptime';
			$orderbyval = " boo_addtime DESC ";	
		}

		//序号 	广告位置 	宽度 	高度 	说明
		$sqlQuery = " SELECT boo_id, boo_name, boo_phone, boo_email, boo_product ,boo_addtime,boo_status ,boo_enabled FROM  ".SQL_PREFIX."book  WHERE 1 GROUP BY boo_id ORDER BY $orderbyval  LIMIT  $LIMITnum , $pageSize ";
		
		$info = $GLOBALS['MySql'] -> selectInfo($sqlQuery);
		
		$sqlQuery = " SELECT count(1) as CNUM  FROM  ".SQL_PREFIX."book  WHERE 1  ORDER BY `boo_id`  ";
		
		$infocount = $GLOBALS['MySql'] -> selectOne($sqlQuery);
		
		$PageStr = $GLOBALS['Page']->buildPageStr( $url = '?load=book&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('PageStr',$PageStr);
		$GLOBALS['Templ']->assign('info',$info);
		$GLOBALS['Templ']->display('book_tpl.html');
		
	}
	
	function add(  )
	{
		$GLOBALS['Templ'] -> caching = true;
		$GLOBALS['Templ'] -> cache_lifetime = 86400 ;  //60 *  60 * 24

		$GLOBALS['Templ']->assign('actUrl',EMPLOYEE_WEBURL."/index.php?load=book&act=addinfo");
		$GLOBALS['Templ']->display('bookadd_tpl.html');
	}
	
	function addinfo()
	{

		$boo_nameval 			= $GLOBALS['Reque'] -> funpost("boo_name");
		$boo_phoneval  			= $GLOBALS['Reque'] -> funpost("boo_phone");
		$boo_emailval  			= $GLOBALS['Reque'] -> funpost("boo_email");	
		$boo_productval 		= $GLOBALS['Reque'] -> funpost("boo_product");
		$boo_descriptionval  	= $GLOBALS['Reque'] -> funpost("boo_description");
		$boo_statusval  		= $GLOBALS['Reque'] -> funpost("boo_status");

		//boo_status

		if($boo_nameval !='' and $boo_phoneval !='' and $boo_emailval !='' )
		{
			$sqlQuery = " SELECT count(1) as CNUM  FROM  ".SQL_PREFIX."book  WHERE boo_name = '".$boo_nameval."' and  boo_product = '".$boo_productval."' ";
			
			$info = $GLOBALS['MySql'] -> selectOne($sqlQuery);
			
			if( $info["CNUM"] < 1 )
			{				
				
				
				$boo_addtimeval 			= time();
				$insertsql ="INSERT INTO `".SQL_PREFIX."book` (`boo_name` , `boo_phone` , `boo_email` , `boo_product` , `boo_description`,`boo_addtime` ,`boo_status`) 
		VALUES (  '$boo_nameval', '$boo_phoneval', '$boo_emailval', '$boo_productval', '$boo_descriptionval', '$boo_addtimeval','$boo_statusval')";
				
				$GLOBALS['MySql'] -> querySql($insertsql);
				
				$GLOBALS['Templ'] -> assign('infomessage',$GLOBALS['_LANG']['bd_addsusse']);
				$GLOBALS['Templ'] -> assign('URL_TIME',URL_TIME);
				$GLOBALS['Templ'] -> assign('geturl',EMPLOYEE_WEBURL."/index.php?load=book&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=book&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=book&act=add");
			$GLOBALS['Templ'] -> display('suggestion_tpl.html');		}
			//var_dump($_REQUEST);
	}
	
	function del( )
	{
		$infoid = $GLOBALS['Reque'] -> getval["id"];
		
		$deletesql ="UPDATE `".SQL_PREFIX."book` SET boo_status = 6 WHERE  `boo_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=book&act=infolist");
		$GLOBALS['Templ'] -> display('suggestion_tpl.html');
	}
 
	
	
	function info(  )
	{
		$idval = $GLOBALS['Reque'] -> getval["id"];

		$sqlQuery = " SELECT *  FROM  ".SQL_PREFIX."book  WHERE boo_id = '".$idval."' ORDER BY `boo_id` ";
		$info = $GLOBALS['MySql'] -> selectOne($sqlQuery);
		$GLOBALS['Templ']->assign('actUrl',EMPLOYEE_WEBURL."/index.php?load=book&act=editinfo");
		$GLOBALS['Templ'] -> assign('info',$info);
		$GLOBALS['Templ'] -> display('bookedit_tpl.html');
	
	}
	
	
	function editinfo( )
	{	
		$boo_idval 				= $GLOBALS['Reque'] -> funpost("boo_id");
		$boo_nameval 			= $GLOBALS['Reque'] -> funpost("boo_name");
		$boo_phoneval  			= $GLOBALS['Reque'] -> funpost("boo_phone");
		$boo_emailval  			= $GLOBALS['Reque'] -> funpost("boo_email");	
		$boo_productval 		= $GLOBALS['Reque'] -> funpost("boo_product");
		$boo_descriptionval  	= $GLOBALS['Reque'] -> funpost("boo_description");
		$boo_statusval  		= $GLOBALS['Reque'] -> funpost("boo_status");
		$boo_enabledval  		= $GLOBALS['Reque'] -> funpost("boo_enabled");
		$boo_remarkval  		= $GLOBALS['Reque'] -> funpost("boo_remark");
		
		if($boo_idval !='' and $boo_nameval !='' )
		{

			$updatesql = "UPDATE `".SQL_PREFIX."book` SET  boo_name = '".$boo_nameval."' , boo_phone = '".$boo_phoneval."'  , boo_email = '".$boo_emailval."' , boo_product = '".$boo_productval."' , boo_description = '".$boo_descriptionval."' , boo_enabled = '".$boo_enabledval."', boo_status = '".$boo_statusval."',boo_remark =  '".$boo_remarkval."'  WHERE  boo_id = '".$boo_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=book&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=book&act=info&id=".$boo_idval);
			$GLOBALS['Templ'] -> display('suggestion_tpl.html');
			
		}
		
	}
	
	function show()
	{
		$infoid = $GLOBALS['Reque'] -> getval["id"];
		
		$upshow = " UPDATE `".SQL_PREFIX."book` SET boo_enabled = 1  WHERE  `boo_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=book&act=infolist");
		$GLOBALS['Templ'] -> display('suggestion_tpl.html');
	}
	
	function hide()
	{		
		$infoid = $GLOBALS['Reque'] -> getval["id"];
		
		$uphide = " UPDATE `".SQL_PREFIX."book` SET boo_enabled = 0  WHERE `boo_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=book&act=infolist");
		$GLOBALS['Templ'] -> display('suggestion_tpl.html');
	}
	
		
}

//nmon_x86_rhel4

$Book = new Book();

?>