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

	
	function add_info()
	{
		$carrier_nameval 		= $this -> input ->  funpost("carrier_name");
		$carrier_pinyinval 		= $this -> input ->  funpost("carrier_pinyin");
		$carrier_areaval 		= $this -> input ->  funpost("carrier_area");
		
		$carrier_addressval 	= $this -> input ->  funpost("carrier_address");
		$carrier_zipval 		= $this -> input ->  funpost("carrier_zip");
		$carrier_telval 		= $this -> input ->  funpost("carrier_tel");
		$carrier_faxval 		= $this -> input ->  funpost("carrier_fax");
		
		$carrier_websiteval 	= $this -> input ->  funpost("carrier_website");
		$carrier_emailval 		= $this -> input ->  funpost("carrier_email");
		$carrier_licenceval 	= $this -> input ->  funpost("carrier_licence");
		$carrier_chieftainval 	= $this -> input ->  funpost("carrier_chieftain");
		$carrier_bankrollval 	= $this -> input ->  funpost("carrier_bankroll");
		$carrier_turnoverval 	= $this -> input ->  funpost("carrier_turnover");
		$carrier_bankval 		= $this -> input ->  funpost("carrier_bank");
		
		$carrier_bankaccountval 	= $this -> input ->  funpost("carrier_bankaccount");
		$carrier_localtaxnoval 	= $this -> input ->  funpost("carrier_localtaxno");
		$carrier_nationaltaxnoval 	= $this -> input ->  funpost("carrier_nationaltaxno");
		$carrier_manageridval 		= $this -> input ->  funpost("carrier_managerid");
		$carrier_levelval 			= $this -> input ->  funpost("carrier_level");
		$carrier_satisfyval 		= $this -> input ->  funpost("carrier_satisfy");
		$carrier_creditval 		= $this -> input ->  funpost("carrier_credit");
		$carrier_losecountval 		= $this -> input ->  funpost("carrier_losecount");
		$carrier_statusval 		= $this -> input ->  funpost("carrier_status");
		
		
		$carrier_regtimeval 	= time();
		
		if($carrier_nameval !='' and $carrier_emailval !='' and $carrier_telval !='' and $carrier_pinyinval !='' )
		{
			$sql_query = " SELECT count(1) as CNUM  FROM  ".$this -> db -> prefix."carrier  WHERE carrier_name = '".$carrier_nameval."' ORDER BY `carrier_id` ";
			
			$info = $this -> db -> select_one($sql_query);
			
			if( $info["CNUM"] < 1 )
			{
				
				$insertip ="INSERT INTO `".$this -> db -> prefix."carrier` (`carrier_name` , `carrier_pinyin` , `carrier_area` , `carrier_address` , `carrier_zip`, `carrier_tel` , `carrier_fax` , `carrier_website` , `carrier_email` , `carrier_licence` , `carrier_chieftain` , `carrier_bankroll` , `carrier_turnover`, `carrier_bank` , `carrier_bankaccount` , `carrier_localtaxno` , `carrier_nationaltaxno` , `carrier_managerid`, `carrier_level` , `carrier_satisfy` , `carrier_credit` , `carrier_losecount`  , `carrier_status` ) VALUES (  '$carrier_nameval', '$carrier_pinyinval', '$carrier_areaval', '$carrier_addressval', '$carrier_zipval', '$carrier_telval', '$carrier_faxval', '$carrier_websiteval', '$carrier_emailval', '$carrier_licenceval', '$carrier_chieftainval', '$carrier_bankrollval', '$carrier_turnoverval', '$carrier_bankval', '$carrier_bankaccountval', '$carrier_localtaxnoval', '$carrier_nationaltaxnoval', '$carrier_manageridval', '$carrier_levelval', '$carrier_satisfyval', '$carrier_creditval', '$carrier_losecountval', '$carrier_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?/carrier/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?/carrier/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?/carrier/add/");
			$this -> view ->  display('suggestion.tpl');		}
			//var_dump($_REQUEST);
	}
	
	function del( )
	{
		$indel = implode(',', $delArray);

		//$deletesql ="DELETE FROM `carrier` WHERE `carrier`.`carrier_id` in ( $indel ) and carrier_name != '".ADMIN_BASEUSER."' ";
		$deletesql ="UPDATE `".$this -> db -> prefix."carrier` SET  carrier_status = 5 WHERE `carrier`.`carrier_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?/carrier/info_list/");
		$this -> view ->  display('suggestion.tpl');
	}
	
	function info(  )
	{
		$infoid = $infoArray[0];
		
		$sql_query = " SELECT *  FROM  ".$this -> db -> prefix."carrier  WHERE carrier_id = '".$infoid."' ORDER BY `carrier_id` ";
		$info = $this -> db -> select_one($sql_query);
				
		$this -> view -> assign('act_url',ADMIN_WEBURL."/index.php?/carrier/edit_info");
		$this -> view ->  assign('info',$info);
		$this -> view ->  display('carrieredit.tpl');
	
	}
	
	
	function edit_info( )
	{	
	
		$carrier_idval 		= $this -> input ->  funpost("carrier_id");
		$carrier_nameval 		= $this -> input ->  funpost("carrier_name");
		$carrier_pinyinval 	= $this -> input ->  funpost("carrier_pinyin");
		$carrier_areaval 		= $this -> input ->  funpost("carrier_area");
		
		$carrier_addressval 	= $this -> input ->  funpost("carrier_address");
		$carrier_zipval 		= $this -> input ->  funpost("carrier_zip");
		$carrier_telval 		= $this -> input ->  funpost("carrier_tel");
		$carrier_faxval 		= $this -> input ->  funpost("carrier_fax");
		
		$carrier_websiteval 	= $this -> input ->  funpost("carrier_website");
		$carrier_emailval 		= $this -> input ->  funpost("carrier_email");
		$carrier_licenceval 	= $this -> input ->  funpost("carrier_licence");
		$carrier_chieftainval 	= $this -> input ->  funpost("carrier_chieftain");
		$carrier_bankrollval 	= $this -> input ->  funpost("carrier_bankroll");
		$carrier_turnoverval 	= $this -> input ->  funpost("carrier_turnover");
		$carrier_bankval 		= $this -> input ->  funpost("carrier_bank");
		
		$carrier_bankaccountval 	= $this -> input ->  funpost("carrier_bankaccount");
		$carrier_localtaxnoval 	= $this -> input ->  funpost("carrier_localtaxno");
		$carrier_nationaltaxnoval 	= $this -> input ->  funpost("carrier_nationaltaxno");
		$carrier_manageridval 		= $this -> input ->  funpost("carrier_managerid");
		$carrier_levelval 			= $this -> input ->  funpost("carrier_level");
		$carrier_satisfyval 		= $this -> input ->  funpost("carrier_satisfy");
		$carrier_creditval 		= $this -> input ->  funpost("carrier_credit");
		$carrier_losecountval 		= $this -> input ->  funpost("carrier_losecount");
		$carrier_statusval 		= $this -> input ->  funpost("carrier_status");
		
		
		$addsetUp = '';
		
		if($carrier_idval !='' and $carrier_nameval !='' )
		{

			$updatecus = "UPDATE `".$this -> db -> prefix."carrier` SET  carrier_name = '".$carrier_nameval."' , carrier_pinyin = '".$carrier_pinyinval."' 
			, carrier_area = '".$carrier_areaval."'
			, carrier_address = '".$carrier_addressval."'
			, carrier_zip = '".$carrier_zipval."'
			, carrier_tel = '".$carrier_telval."'
			, carrier_fax = '".$carrier_faxval."'
			, carrier_website = '".$carrier_websiteval."'
			, carrier_email = '".$carrier_emailval."'
			, carrier_licence = '".$carrier_licenceval."'
			, carrier_chieftain = '".$carrier_chieftainval."'
			, carrier_bankroll = '".$carrier_bankrollval."'
			, carrier_turnover = '".$carrier_turnoverval."'
			, carrier_bank = '".$carrier_bankval."'
			, carrier_bankaccount = '".$carrier_bankaccountval."'
			, carrier_localtaxno = '".$carrier_localtaxnoval."'
			, carrier_nationaltaxno = '".$carrier_nationaltaxnoval."'
			, carrier_managerid = '".$carrier_manageridval."'
			, carrier_level = '".$carrier_levelval."'
			, carrier_satisfy = '".$carrier_satisfyval."'
			, carrier_credit = '".$carrier_creditval."'
			, carrier_losecount = '".$carrier_losecountval."'
			, carrier_status = '".$carrier_statusval."'			
			 WHERE  carrier_id = '".$carrier_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?/carrier/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?/carrier/info/".$carrier_idval);
			$this -> view ->  display('suggestion.tpl');	
		}
		
	}
	
	

	
	
}

$Carrier = new Carrier();

?>