<?php
if (!defined('HUCART_COM')) exit('HuCart.COM No direct script access allowed');
class Book
{
	function Book()
	{
		//$GLOBALS['WebSe'] -> isOnLine();
		//$this -> view -> assign('act_url',ADMIN_WEBURL."/index.php?/login/actlogin");
	}
	
	function info_list()
	{
		$page_size = 20 ;
		
		$keywordval 	= $this -> input ->  funpost("keyword");
		$prs_idval 		= $this -> input ->  funpost("prs_id");
		$page_num_val 	= $this -> input ->  get["page_num"];
		
		if( $page_num_val > 1 )
		{
			$page_num  = $page_num_val;
			$limit_num = ceil( ( $page_num_val -1 ) * $page_size );
		}else{
			$page_num  = 1;
			$limit_num = 0 ;
		}
		
		$listval  = $this -> input ->  get["listval"];
		$listtype = $this -> input ->  get["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 ";	
		}

		//序号 	广告位置 	宽度 	高度 	说明
		$sql_query = " SELECT boo_id, boo_name, boo_phone, boo_email, boo_product ,boo_addtime,boo_status ,boo_enabled FROM  ".$this -> db -> prefix."book  WHERE 1 GROUP BY boo_id ORDER BY $orderbyval  LIMIT  $limit_num , $page_size ";
		
		$info = $this -> db -> select_info($sql_query);
		
		$sql_query = " SELECT count(1) as CNUM  FROM  ".$this -> db -> prefix."book  WHERE 1  ORDER BY `boo_id`  ";
		
		$infocount = $this -> db -> select_one($sql_query);
		
		$page_str = $this -> page ->get_admin_page( $url = '?load=book&act=info_list', $page_num  , $page_size  , $result_count = $infocount["CNUM"] ,$endArray);
		
		
		$this -> view -> assign('listval',$listval);
		$this -> view -> assign('listtype',$listtype);

		
		$this -> view -> assign('page_str',$page_str);
		$this -> view -> assign('info',$info);
		$this -> view -> display('book.tpl');
		
	}
	
	function add(  )
	{
		$this -> view ->  caching = true;
		$this -> view ->  cache_lifetime = 86400 ;  //60 *  60 * 24

		$this -> view -> assign('act_url',ADMIN_WEBURL."/index.php?load=book&act=add_info");
		$this -> view -> display('bookadd.tpl');
	}
	
	function add_info()
	{

		$boo_nameval 			= $this -> input ->  funpost("boo_name");
		$boo_phoneval  			= $this -> input ->  funpost("boo_phone");
		$boo_emailval  			= $this -> input ->  funpost("boo_email");	
		$boo_productval 		= $this -> input ->  funpost("boo_product");
		$boo_descriptionval  	= $this -> input ->  funpost("boo_description");
		$boo_statusval  		= $this -> input ->  funpost("boo_status");

		//boo_status

		if($boo_nameval !='' and $boo_phoneval !='' and $boo_emailval !='' )
		{
			$sql_query = " SELECT count(1) as CNUM  FROM  ".$this -> db -> prefix."book  WHERE boo_name = '".$boo_nameval."' and  boo_product = '".$boo_productval."' ";
			
			$info = $this -> db -> select_one($sql_query);
			
			if( $info["CNUM"] < 1 )
			{				
				
				
				$boo_addtimeval 			= time();
				$insertsql ="INSERT INTO `".$this -> db -> 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')";
				
				$this -> db -> query_sql($insertsql);
				
				$this -> view ->  assign('info_title',$this->lang['add_success']);
				$this -> view ->  assign('URL_TIME',URL_TIME);
				$this -> view ->  assign('get_url',ADMIN_WEBURL."/index.php?load=book&act=info_list");
				$this -> view ->  display('suggestion.tpl');	
			}else{
				
				$this -> view ->  assign('info_title',$this->lang['err_info_exist']);
				$this -> view ->  assign('URL_TIME',URL_TIME);
				$this -> view ->  assign('get_url',ADMIN_WEBURL."/index.php?load=book&act=add");
				$this -> view ->  display('suggestion.tpl');	
			}
			
		}else{
			
			$this -> view ->  assign('info_title',$this->lang['err_info_missing']);
			$this -> view ->  assign('URL_TIME',URL_TIME);
			$this -> view ->  assign('get_url',ADMIN_WEBURL."/index.php?load=book&act=add");
			$this -> view ->  display('suggestion.tpl');		}
			//var_dump($_REQUEST);
	}
	
	function del( )
	{
		$infoid = $this -> input ->  get["id"];
		
		$deletesql ="UPDATE `".$this -> db -> prefix."book` SET boo_status = 6 WHERE  `boo_id` in ( $infoid ) ";
		
		$this -> db -> query_sql($deletesql);
		$this -> view ->  assign('info_title',$this->lang['del_success']);
		$this -> view ->  assign('URL_TIME',URL_TIME);
		$this -> view ->  assign('get_url',ADMIN_WEBURL."/index.php?load=book&act=info_list");
		$this -> view ->  display('suggestion.tpl');
	}
 
	
	
	function info(  )
	{
		$idval = $this -> input ->  get["id"];

		$sql_query = " SELECT *  FROM  ".$this -> db -> prefix."book  WHERE boo_id = '".$idval."' ORDER BY `boo_id` ";
		$info = $this -> db -> select_one($sql_query);
		$this -> view -> assign('act_url',ADMIN_WEBURL."/index.php?load=book&act=edit_info");
		$this -> view ->  assign('info',$info);
		$this -> view ->  display('bookedit.tpl');
	
	}
	
	
	function edit_info( )
	{	
		$boo_idval 				= $this -> input ->  funpost("boo_id");
		$boo_nameval 			= $this -> input ->  funpost("boo_name");
		$boo_phoneval  			= $this -> input ->  funpost("boo_phone");
		$boo_emailval  			= $this -> input ->  funpost("boo_email");	
		$boo_productval 		= $this -> input ->  funpost("boo_product");
		$boo_descriptionval  	= $this -> input ->  funpost("boo_description");
		$boo_statusval  		= $this -> input ->  funpost("boo_status");
		$boo_enabledval  		= $this -> input ->  funpost("boo_enabled");
		$boo_remarkval  		= $this -> input ->  funpost("boo_remark");
		
		if($boo_idval !='' and $boo_nameval !='' )
		{

			$updatesql = "UPDATE `".$this -> db -> 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."' ";
			
			$this -> db -> query_sql( $updatesql );
			
			$this -> view ->  assign('info_title',$this->lang['edit_success']);
			$this -> view ->  assign('URL_TIME',URL_TIME);
			$this -> view ->  assign('get_url',ADMIN_WEBURL."/index.php?load=book&act=info_list");
			$this -> view ->  display('suggestion.tpl');
			
		}else{
		
			$this -> view ->  assign('info_title',$this->lang['err_info_missing']);
			$this -> view ->  assign('URL_TIME',URL_TIME);
			$this -> view ->  assign('get_url',ADMIN_WEBURL."/index.php?load=book&act=info&id=".$boo_idval);
			$this -> view ->  display('suggestion.tpl');
			
		}
		
	}
	
	function show()
	{
		$infoid = $this -> input ->  get["id"];
		
		$upshow = " UPDATE `".$this -> db -> prefix."book` SET boo_enabled = 1  WHERE  `boo_id` in ( $infoid ) ";

		$this -> db -> query_sql($upshow);
		$this -> view ->  assign('info_title',$_LANG['bd_showsusse']);
		$this -> view ->  assign('URL_TIME',URL_TIME);
		$this -> view ->  assign('get_url',ADMIN_WEBURL."/index.php?load=book&act=info_list");
		$this -> view ->  display('suggestion.tpl');
	}
	
	function hide()
	{		
		$infoid = $this -> input ->  get["id"];
		
		$uphide = " UPDATE `".$this -> db -> prefix."book` SET boo_enabled = 0  WHERE `boo_id` in ( $infoid ) ";

		$this -> db -> query_sql($uphide);
		$this -> view ->  assign('info_title',$_LANG['bd_hidesusse']);
		$this -> view ->  assign('URL_TIME',URL_TIME);
		$this -> view ->  assign('get_url',ADMIN_WEBURL."/index.php?load=book&act=info_list");
		$this -> view ->  display('suggestion.tpl');
	}
	
		
}

//

$Book = new Book();

?>