<?php
if (!defined('HUCART_COM')) exit('HuCart.COM No direct script access allowed');
class Chance
{
	function Chance()
	{
		//$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 chance_id, chance_source, customer_id, chance_title, chance_rate,	chance_linkman,chance_tel,	chance_mobile,chance_addtime   FROM  ".$this -> db -> prefix."chance  WHERE 1 GROUP BY chance_id ORDER BY `chance_id` LIMIT  $limit_num , $page_size ";
		
		$info = $this -> db -> select_info($sql_query);
		
		$sql_query = " SELECT count(1) as CNUM  FROM  chance  WHERE 1  ORDER BY `chance_id`  ";
		
		$infocount = $this -> db -> select_one($sql_query);
		
		//var_dump($info);
		
		$page_str = $this -> page ->get_admin_page( $url = '?load=chance&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('chance.tpl');
		
	}
	
	function add(  )
	{
		$this -> view ->  caching = true;
		$this -> view ->  cache_lifetime = 86400 ;  //60 *  60 * 24
		$this -> view -> assign('act_url',ADMIN_WEBURL."/index.php?/chance/add_info");
		$this -> view -> display('chanceadd.tpl');
	}

	
	function add_info()
	{
		$chance_nameval 		= $this -> input ->  funpost("chance_name");
		$chance_pinyinval 		= $this -> input ->  funpost("chance_pinyin");
		$chance_areaval 		= $this -> input ->  funpost("chance_area");
		
		$chance_addressval 	= $this -> input ->  funpost("chance_address");
		$chance_zipval 		= $this -> input ->  funpost("chance_zip");
		$chance_telval 		= $this -> input ->  funpost("chance_tel");
		$chance_faxval 		= $this -> input ->  funpost("chance_fax");
		
		$chance_websiteval 	= $this -> input ->  funpost("chance_website");
		$chance_emailval 		= $this -> input ->  funpost("chance_email");
		$chance_licenceval 	= $this -> input ->  funpost("chance_licence");
		$chance_chieftainval 	= $this -> input ->  funpost("chance_chieftain");
		$chance_bankrollval 	= $this -> input ->  funpost("chance_bankroll");
		$chance_turnoverval 	= $this -> input ->  funpost("chance_turnover");
		$chance_bankval 		= $this -> input ->  funpost("chance_bank");
		
		$chance_bankaccountval 	= $this -> input ->  funpost("chance_bankaccount");
		$chance_localtaxnoval 	= $this -> input ->  funpost("chance_localtaxno");
		$chance_nationaltaxnoval 	= $this -> input ->  funpost("chance_nationaltaxno");
		$chance_manageridval 		= $this -> input ->  funpost("chance_managerid");
		$chance_levelval 			= $this -> input ->  funpost("chance_level");
		$chance_satisfyval 		= $this -> input ->  funpost("chance_satisfy");
		$chance_creditval 		= $this -> input ->  funpost("chance_credit");
		$chance_losecountval 		= $this -> input ->  funpost("chance_losecount");
		$chance_statusval 		= $this -> input ->  funpost("chance_status");
		
		
		$chance_regtimeval 	= time();
		
		if($chance_nameval !='' and $chance_emailval !='' and $chance_telval !='' and $chance_pinyinval !='' )
		{
			$sql_query = " SELECT count(1) as CNUM  FROM  ".$this -> db -> prefix."chance  WHERE chance_name = '".$chance_nameval."' ORDER BY `chance_id` ";
			
			$info = $this -> db -> select_one($sql_query);
			
			if( $info["CNUM"] < 1 )
			{
				
				$insertip ="INSERT INTO `".$this -> db -> prefix."chance` (`chance_name` , `chance_pinyin` , `chance_area` , `chance_address` , `chance_zip`, `chance_tel` , `chance_fax` , `chance_website` , `chance_email` , `chance_licence` , `chance_chieftain` , `chance_bankroll` , `chance_turnover`, `chance_bank` , `chance_bankaccount` , `chance_localtaxno` , `chance_nationaltaxno` , `chance_managerid`, `chance_level` , `chance_satisfy` , `chance_credit` , `chance_losecount`  , `chance_status` ) VALUES (  '$chance_nameval', '$chance_pinyinval', '$chance_areaval', '$chance_addressval', '$chance_zipval', '$chance_telval', '$chance_faxval', '$chance_websiteval', '$chance_emailval', '$chance_licenceval', '$chance_chieftainval', '$chance_bankrollval', '$chance_turnoverval', '$chance_bankval', '$chance_bankaccountval', '$chance_localtaxnoval', '$chance_nationaltaxnoval', '$chance_manageridval', '$chance_levelval', '$chance_satisfyval', '$chance_creditval', '$chance_losecountval', '$chance_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?/chance/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?/chance/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?/chance/add/");
			$this -> view ->  display('suggestion.tpl');		}
			//var_dump($_REQUEST);
	}
	
	function del( )
	{
		$indel = implode(',', $delArray);

		//$deletesql ="DELETE FROM `chance` WHERE `chance`.`chance_id` in ( $indel ) and chance_name != '".ADMIN_BASEUSER."' ";
		$deletesql ="UPDATE `".$this -> db -> prefix."chance` SET  chance_status = 5 WHERE `chance`.`chance_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?/chance/info_list/");
		$this -> view ->  display('suggestion.tpl');
	}
	
	function info(  )
	{
		$infoid = $infoArray[0];
		
		$sql_query = " SELECT *  FROM  ".$this -> db -> prefix."chance  WHERE chance_id = '".$infoid."' ORDER BY `chance_id` ";
		$info = $this -> db -> select_one($sql_query);
				
		$this -> view -> assign('act_url',ADMIN_WEBURL."/index.php?/chance/edit_info");
		$this -> view ->  assign('info',$info);
		$this -> view ->  display('chanceedit.tpl');
	
	}
	
	
	function edit_info( )
	{	
	
		$chance_idval 		= $this -> input ->  funpost("chance_id");
		$chance_nameval 		= $this -> input ->  funpost("chance_name");
		$chance_pinyinval 	= $this -> input ->  funpost("chance_pinyin");
		$chance_areaval 		= $this -> input ->  funpost("chance_area");
		
		$chance_addressval 	= $this -> input ->  funpost("chance_address");
		$chance_zipval 		= $this -> input ->  funpost("chance_zip");
		$chance_telval 		= $this -> input ->  funpost("chance_tel");
		$chance_faxval 		= $this -> input ->  funpost("chance_fax");
		
		$chance_websiteval 	= $this -> input ->  funpost("chance_website");
		$chance_emailval 		= $this -> input ->  funpost("chance_email");
		$chance_licenceval 	= $this -> input ->  funpost("chance_licence");
		$chance_chieftainval 	= $this -> input ->  funpost("chance_chieftain");
		$chance_bankrollval 	= $this -> input ->  funpost("chance_bankroll");
		$chance_turnoverval 	= $this -> input ->  funpost("chance_turnover");
		$chance_bankval 		= $this -> input ->  funpost("chance_bank");
		
		$chance_bankaccountval 	= $this -> input ->  funpost("chance_bankaccount");
		$chance_localtaxnoval 	= $this -> input ->  funpost("chance_localtaxno");
		$chance_nationaltaxnoval 	= $this -> input ->  funpost("chance_nationaltaxno");
		$chance_manageridval 		= $this -> input ->  funpost("chance_managerid");
		$chance_levelval 			= $this -> input ->  funpost("chance_level");
		$chance_satisfyval 		= $this -> input ->  funpost("chance_satisfy");
		$chance_creditval 		= $this -> input ->  funpost("chance_credit");
		$chance_losecountval 		= $this -> input ->  funpost("chance_losecount");
		$chance_statusval 		= $this -> input ->  funpost("chance_status");
		
		
		$addsetUp = '';
		
		if($chance_idval !='' and $chance_nameval !='' )
		{

			
			$updatecus = "UPDATE `".$this -> db -> prefix."chance` SET  chance_name = '".$chance_nameval."' , chance_pinyin = '".$chance_pinyinval."' 
			, chance_area = '".$chance_areaval."'
			, chance_address = '".$chance_addressval."'
			, chance_zip = '".$chance_zipval."'
			, chance_tel = '".$chance_telval."'
			, chance_fax = '".$chance_faxval."'
			, chance_website = '".$chance_websiteval."'
			, chance_email = '".$chance_emailval."'
			, chance_licence = '".$chance_licenceval."'
			, chance_chieftain = '".$chance_chieftainval."'
			, chance_bankroll = '".$chance_bankrollval."'
			, chance_turnover = '".$chance_turnoverval."'
			, chance_bank = '".$chance_bankval."'
			, chance_bankaccount = '".$chance_bankaccountval."'
			, chance_localtaxno = '".$chance_localtaxnoval."'
			, chance_nationaltaxno = '".$chance_nationaltaxnoval."'
			, chance_managerid = '".$chance_manageridval."'
			, chance_level = '".$chance_levelval."'
			, chance_satisfy = '".$chance_satisfyval."'
			, chance_credit = '".$chance_creditval."'
			, chance_losecount = '".$chance_losecountval."'
			, chance_status = '".$chance_statusval."'

			
			 WHERE  chance_id = '".$chance_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?/chance/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?/chance/info/".$chance_idval);
			$this -> view ->  display('suggestion.tpl');	
		}
		
	}
	
	

	
	
}

$Chance = new Chance();

?>