<?php
if (!defined('HUCART_COM')) exit('HuCart.COM No direct script access allowed');
class Market
{
	function Market()
	{
		//$GLOBALS['WebSe'] -> isOnLine();
	}
	
	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 ;
		}

		//帐号 	真实姓名 	Email地址 	登录次数 	加入时间 	最后登录时间
		
		$sql_query = " SELECT market_id, market_company, market_price, market_opponent, market_quotation  FROM  market  WHERE 1 GROUP BY market_id ORDER BY `market_id` LIMIT  $limit_num , $page_size ";
		
		$info = $this -> db -> select_info($sql_query);
		
		$sql_query = " SELECT count(1) as CNUM  FROM  market  WHERE 1  ORDER BY `market_id`  ";
		
		$infocount = $this -> db -> select_one($sql_query);
		
		//var_dump($info);
		
		$page_str = $this -> page ->get_admin_page( $url = '?load=market&act=info_list', $page_num  , $page_size  , $result_count = $infocount["CNUM"] );
		
		$this -> view -> assign('ADMIN_BASEUSER',ADMIN_BASEUSER);
		
		$this -> view -> assign('page_str',$page_str);
		$this -> view -> assign('info',$info);
		$this -> view -> display('market.tpl');
		
	}
	
	function add(  )
	{
		$this -> view ->  caching = true;
		$this -> view ->  cache_lifetime = 86400 ;  //60 *  60 * 24
		$this -> view -> assign('act_url',ADMIN_WEBURL."/index.php?/market/add_info");
		$this -> view -> display('marketadd.tpl');
	}

	
	function add_info()
	{
		$market_nameval 		= $this -> input ->  funpost("market_name");
		$market_pinyinval 		= $this -> input ->  funpost("market_pinyin");
		$market_areaval 		= $this -> input ->  funpost("market_area");
		
		$market_addressval 	= $this -> input ->  funpost("market_address");
		$market_zipval 		= $this -> input ->  funpost("market_zip");
		$market_telval 		= $this -> input ->  funpost("market_tel");
		$market_faxval 		= $this -> input ->  funpost("market_fax");
		
		$market_websiteval 	= $this -> input ->  funpost("market_website");
		$market_emailval 		= $this -> input ->  funpost("market_email");
		$market_licenceval 	= $this -> input ->  funpost("market_licence");
		$market_chieftainval 	= $this -> input ->  funpost("market_chieftain");
		$market_bankrollval 	= $this -> input ->  funpost("market_bankroll");
		$market_turnoverval 	= $this -> input ->  funpost("market_turnover");
		$market_bankval 		= $this -> input ->  funpost("market_bank");
		
		$market_bankaccountval 	= $this -> input ->  funpost("market_bankaccount");
		$market_localtaxnoval 	= $this -> input ->  funpost("market_localtaxno");
		$market_nationaltaxnoval 	= $this -> input ->  funpost("market_nationaltaxno");
		$market_manageridval 		= $this -> input ->  funpost("market_managerid");
		$market_levelval 			= $this -> input ->  funpost("market_level");
		$market_satisfyval 		= $this -> input ->  funpost("market_satisfy");
		$market_creditval 		= $this -> input ->  funpost("market_credit");
		$market_losecountval 		= $this -> input ->  funpost("market_losecount");
		$market_statusval 		= $this -> input ->  funpost("market_status");
		
		
		$market_regtimeval 	= time();
		
		if($market_nameval !='' and $market_emailval !='' and $market_telval !='' and $market_pinyinval !='' )
		{
			$sql_query = " SELECT count(1) as CNUM  FROM  market  WHERE market_name = '".$market_nameval."' ORDER BY `market_id` ";
			
			$info = $this -> db -> select_one($sql_query);
			
			if( $info["CNUM"] < 1 )
			{
				
				$insertip ="INSERT INTO `market` (`market_name` , `market_pinyin` , `market_area` , `market_address` , `market_zip`, `market_tel` , `market_fax` , `market_website` , `market_email` , `market_licence` , `market_chieftain` , `market_bankroll` , `market_turnover`, `market_bank` , `market_bankaccount` , `market_localtaxno` , `market_nationaltaxno` , `market_managerid`, `market_level` , `market_satisfy` , `market_credit` , `market_losecount`  , `market_status` ) VALUES (  '$market_nameval', '$market_pinyinval', '$market_areaval', '$market_addressval', '$market_zipval', '$market_telval', '$market_faxval', '$market_websiteval', '$market_emailval', '$market_licenceval', '$market_chieftainval', '$market_bankrollval', '$market_turnoverval', '$market_bankval', '$market_bankaccountval', '$market_localtaxnoval', '$market_nationaltaxnoval', '$market_manageridval', '$market_levelval', '$market_satisfyval', '$market_creditval', '$market_losecountval', '$market_statusval')";

				$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?/market/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?/market/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?/market/add/");
			$this -> view ->  display('suggestion.tpl');		}
			//var_dump($_REQUEST);
	}
	
	function del( )
	{
		$indel = implode(',', $delArray);

		//$deletesql ="DELETE FROM `market` WHERE `market`.`market_id` in ( $indel ) and market_name != '".ADMIN_BASEUSER."' ";
		$deletesql ="UPDATE `market` SET  market_status = 5 WHERE `market`.`market_id` IN ( $indel )  ";
		
		$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?/market/info_list/");
		$this -> view ->  display('suggestion.tpl');
	}
	
	function info(  )
	{
		$infoid = $infoArray[0];
		
		$sql_query = " SELECT *  FROM  market  WHERE market_id = '".$infoid."' ORDER BY `market_id` ";
		$info = $this -> db -> select_one($sql_query);
				
		$this -> view -> assign('act_url',ADMIN_WEBURL."/index.php?/market/edit_info");
		$this -> view ->  assign('info',$info);
		$this -> view ->  display('marketedit.tpl');
	
	}
	
	
	function edit_info( )
	{	
	
		$market_idval 		= $this -> input ->  funpost("market_id");
		$market_nameval 		= $this -> input ->  funpost("market_name");
		$market_pinyinval 	= $this -> input ->  funpost("market_pinyin");
		$market_areaval 		= $this -> input ->  funpost("market_area");
		
		$market_addressval 	= $this -> input ->  funpost("market_address");
		$market_zipval 		= $this -> input ->  funpost("market_zip");
		$market_telval 		= $this -> input ->  funpost("market_tel");
		$market_faxval 		= $this -> input ->  funpost("market_fax");
		
		$market_websiteval 	= $this -> input ->  funpost("market_website");
		$market_emailval 		= $this -> input ->  funpost("market_email");
		$market_licenceval 	= $this -> input ->  funpost("market_licence");
		$market_chieftainval 	= $this -> input ->  funpost("market_chieftain");
		$market_bankrollval 	= $this -> input ->  funpost("market_bankroll");
		$market_turnoverval 	= $this -> input ->  funpost("market_turnover");
		$market_bankval 		= $this -> input ->  funpost("market_bank");
		
		$market_bankaccountval 	= $this -> input ->  funpost("market_bankaccount");
		$market_localtaxnoval 	= $this -> input ->  funpost("market_localtaxno");
		$market_nationaltaxnoval 	= $this -> input ->  funpost("market_nationaltaxno");
		$market_manageridval 		= $this -> input ->  funpost("market_managerid");
		$market_levelval 			= $this -> input ->  funpost("market_level");
		$market_satisfyval 		= $this -> input ->  funpost("market_satisfy");
		$market_creditval 		= $this -> input ->  funpost("market_credit");
		$market_losecountval 		= $this -> input ->  funpost("market_losecount");
		$market_statusval 		= $this -> input ->  funpost("market_status");
		
		
		$addsetUp = '';
		
		if($market_idval !='' and $market_nameval !='' )
		{

			
			$updatecus = "UPDATE `market` SET  market_name = '".$market_nameval."' , market_pinyin = '".$market_pinyinval."' 
			, market_area = '".$market_areaval."'
			, market_address = '".$market_addressval."'
			, market_zip = '".$market_zipval."'
			, market_tel = '".$market_telval."'
			, market_fax = '".$market_faxval."'
			, market_website = '".$market_websiteval."'
			, market_email = '".$market_emailval."'
			, market_licence = '".$market_licenceval."'
			, market_chieftain = '".$market_chieftainval."'
			, market_bankroll = '".$market_bankrollval."'
			, market_turnover = '".$market_turnoverval."'
			, market_bank = '".$market_bankval."'
			, market_bankaccount = '".$market_bankaccountval."'
			, market_localtaxno = '".$market_localtaxnoval."'
			, market_nationaltaxno = '".$market_nationaltaxnoval."'
			, market_managerid = '".$market_manageridval."'
			, market_level = '".$market_levelval."'
			, market_satisfy = '".$market_satisfyval."'
			, market_credit = '".$market_creditval."'
			, market_losecount = '".$market_losecountval."'
			, market_status = '".$market_statusval."'

			
			 WHERE  market_id = '".$market_idval."' ";
			
			$this -> db -> query_sql( $updatecus );
			
			$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?/market/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?/market/info/".$market_idval);
			$this -> view ->  display('suggestion.tpl');	
		}
		
	}
	
	

	
	
}

$Market = new Market();

?>