<?php
if (!defined('HUCART_COM')) exit('HuCart.COM No direct script access allowed');
class Ad_position
{
	function Adposition()
	{
		//$GLOBALS['WebSe'] -> isOnLine();

		//$this -> view -> assign('act_url',ADMIN_WEBURL."/index.php?/login/actlogin");
		//var $styleArray = array( 'default'=>'默认模式','heartleft'=>'左对联模式','heartright'=>'右对联模式');
		//$this -> view -> assign('styleArray',$styleArray);
	}
	
	function info_list(  )
	{
		$page_size = 20 ;		$page_num_val 	= $this -> input ->  req["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 ;
		}
		//序号 	广告位置 	宽度 	高度 	说明
		$sql_query = " SELECT adp_id, adp_name, adp_width, 	adp_height, adp_desc   FROM  ".$this -> db -> prefix."adposition  WHERE 1 GROUP BY adp_id ORDER BY `adp_id` LIMIT  $limit_num , $page_size ";
		
		$info = $this -> db -> select_info($sql_query);
		
		$sql_query = " SELECT count(1) as CNUM  FROM  ".$this -> db -> prefix."adposition  WHERE 1  ORDER BY `adp_id`  ";
		
		$infocount = $this -> db -> select_one($sql_query);
		
		$page_str = $this -> page ->get_admin_page( $url = '?load=adposition&act=info_list', $page_num  , $page_size  , $result_count = $infocount["CNUM"] );
		

		$this -> view -> assign('page_str',$page_str);
		$this -> view -> assign('info',$info);
		$this -> view -> display('adposition.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=adposition&act=add_info");
		$this -> view -> display('adpositionadd.tpl');
	}
	
	function add_info()
	{
		$adp_nameval 		= $this -> input ->  funpost("adp_name");
		$adp_widthval 		= $this -> input ->  funpost("adp_width");
		$adp_heightval		= $this -> input ->  funpost("adp_height");
		$adp_descval 		= $this -> input ->  funpost("adp_desc");
		$adp_styleval	 	= $this -> input ->  funpost("adp_style");

		if($adp_nameval !='' and $adp_widthval !='' and $adp_heightval !='' )
		{
			$sql_query = " SELECT count(1) as CNUM  FROM  ".$this -> db -> prefix."adposition  WHERE adp_name = '".$adp_nameval."' ";
			
			$info = $this -> db -> select_one($sql_query);
			
			if( $info["CNUM"] < 1 )
			{				
				$insertip ="INSERT INTO `".$this -> db -> prefix."adposition` (`adp_name` , `adp_width` , `adp_height` , `adp_desc` , `adp_style` ) VALUES (  '$adp_nameval', '$adp_widthval', '$adp_heightval', '$adp_descval', '$adp_styleval')";
				
				$this -> db -> query_sql($insertip);
				$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=adposition&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=adposition&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=adposition&act=add");
			$this -> view ->  display('suggestion.tpl');		}
			//var_dump($_REQUEST);
	}
	
	function del( )
	{
		$infoid = $this -> input ->  get["id"];
		$deletesql ="DELETE FROM `".$this -> db -> prefix."adposition` WHERE `adp_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=adposition&act=info_list");
		$this -> view ->  display('suggestion.tpl');
	}
	
	function info( )
	{
		$infoid = $this -> input ->  get["id"];
		$sql_query = " SELECT *  FROM  ".$this -> db -> prefix."adposition  WHERE adp_id = '".$infoid."' ORDER BY `adp_id` ";
		$info = $this -> db -> select_one($sql_query);
		$this -> view -> assign('act_url',ADMIN_WEBURL."/index.php?load=adposition&act=edit_info");
		$this -> view ->  assign('info',$info);
		$this -> view ->  display('adpositionedit.tpl');
	
	}
	
	
	function edit_info( )
	{	
		$adp_idval 		= $this -> input ->  funpost("adp_id");
		$adp_nameval 	= $this -> input ->  funpost("adp_name");
		$adp_widthval 	= $this -> input ->  funpost("adp_width");
		$adp_heightval	= $this -> input ->  funpost("adp_height");
		$adp_descval 	= $this -> input ->  funpost("adp_desc");
		$adp_styleval	= $this -> input ->  funpost("adp_style");
		
		if($adp_idval !='' and $adp_nameval !='' )
		{

			$updatesql = "UPDATE `".$this -> db -> prefix."adposition` SET  adp_name = '".$adp_nameval."' , adp_width = '".$adp_widthval."'  , adp_height = '".$adp_heightval."' , adp_desc = '".$adp_descval."' , adp_style = '".$adp_styleval."'   WHERE  adp_id = '".$adp_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=adposition&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=adposition&act=info&id=".$admin_idval);
			$this -> view ->  display('suggestion.tpl');	
		}
		
	}
		
}

//


$Adposition = new Adposition();

?>