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

	
	function add_info()
	{
		$linkman_nameval 		= $this -> input ->  funpost("linkman_name");
		$linkman_pinyinval 		= $this -> input ->  funpost("linkman_pinyin");
		$linkman_areaval 		= $this -> input ->  funpost("linkman_area");
		
		$linkman_addressval 	= $this -> input ->  funpost("linkman_address");
		$linkman_zipval 		= $this -> input ->  funpost("linkman_zip");
		$linkman_telval 		= $this -> input ->  funpost("linkman_tel");
		$linkman_faxval 		= $this -> input ->  funpost("linkman_fax");
		
		$linkman_websiteval 	= $this -> input ->  funpost("linkman_website");
		$linkman_emailval 		= $this -> input ->  funpost("linkman_email");
		$linkman_licenceval 	= $this -> input ->  funpost("linkman_licence");
		$linkman_chieftainval 	= $this -> input ->  funpost("linkman_chieftain");
		$linkman_bankrollval 	= $this -> input ->  funpost("linkman_bankroll");
		$linkman_turnoverval 	= $this -> input ->  funpost("linkman_turnover");
		$linkman_bankval 		= $this -> input ->  funpost("linkman_bank");
		
		$linkman_bankaccountval 	= $this -> input ->  funpost("linkman_bankaccount");
		$linkman_localtaxnoval 	= $this -> input ->  funpost("linkman_localtaxno");
		$linkman_nationaltaxnoval 	= $this -> input ->  funpost("linkman_nationaltaxno");
		$linkman_manageridval 		= $this -> input ->  funpost("linkman_managerid");
		$linkman_levelval 			= $this -> input ->  funpost("linkman_level");
		$linkman_satisfyval 		= $this -> input ->  funpost("linkman_satisfy");
		$linkman_creditval 		= $this -> input ->  funpost("linkman_credit");
		$linkman_losecountval 		= $this -> input ->  funpost("linkman_losecount");
		$linkman_statusval 		= $this -> input ->  funpost("linkman_status");
		
		
		$linkman_regtimeval 	= time();
		
		if($linkman_nameval !='' and $linkman_emailval !='' and $linkman_telval !='' and $linkman_pinyinval !='' )
		{
			$sql_query = " SELECT count(1) as CNUM  FROM  linkman  WHERE linkman_name = '".$linkman_nameval."' ORDER BY `linkman_id` ";
			
			$info = $this -> db -> select_one($sql_query);
			
			if( $info["CNUM"] < 1 )
			{
				
				$insertip ="INSERT INTO `linkman` (`linkman_name` , `linkman_pinyin` , `linkman_area` , `linkman_address` , `linkman_zip`, `linkman_tel` , `linkman_fax` , `linkman_website` , `linkman_email` , `linkman_licence` , `linkman_chieftain` , `linkman_bankroll` , `linkman_turnover`, `linkman_bank` , `linkman_bankaccount` , `linkman_localtaxno` , `linkman_nationaltaxno` , `linkman_managerid`, `linkman_level` , `linkman_satisfy` , `linkman_credit` , `linkman_losecount`  , `linkman_status` ) VALUES (  '$linkman_nameval', '$linkman_pinyinval', '$linkman_areaval', '$linkman_addressval', '$linkman_zipval', '$linkman_telval', '$linkman_faxval', '$linkman_websiteval', '$linkman_emailval', '$linkman_licenceval', '$linkman_chieftainval', '$linkman_bankrollval', '$linkman_turnoverval', '$linkman_bankval', '$linkman_bankaccountval', '$linkman_localtaxnoval', '$linkman_nationaltaxnoval', '$linkman_manageridval', '$linkman_levelval', '$linkman_satisfyval', '$linkman_creditval', '$linkman_losecountval', '$linkman_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?/linkman/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?/linkman/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?/linkman/add/");
			$this -> view ->  display('suggestion.tpl');		}
			//var_dump($_REQUEST);
	}
	
	function del( )
	{
		$indel = implode(',', $delArray);

		//$deletesql ="DELETE FROM `linkman` WHERE `linkman`.`linkman_id` in ( $indel ) and linkman_name != '".ADMIN_BASEUSER."' ";
		$deletesql ="UPDATE `linkman` SET  linkman_status = 5 WHERE `linkman`.`linkman_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?/linkman/info_list/");
		$this -> view ->  display('suggestion.tpl');
	}
	
	function info(  )
	{
		$infoid = $infoArray[0];
		
		$sql_query = " SELECT *  FROM  linkman  WHERE linkman_id = '".$infoid."' ORDER BY `linkman_id` ";
		$info = $this -> db -> select_one($sql_query);
				
		$this -> view -> assign('act_url',ADMIN_WEBURL."/index.php?/linkman/edit_info");
		$this -> view ->  assign('info',$info);
		$this -> view ->  display('linkmanedit.tpl');
	
	}
	
	
	function edit_info( )
	{	
	
		$linkman_idval 		= $this -> input ->  funpost("linkman_id");
		$linkman_nameval 		= $this -> input ->  funpost("linkman_name");
		$linkman_pinyinval 	= $this -> input ->  funpost("linkman_pinyin");
		$linkman_areaval 		= $this -> input ->  funpost("linkman_area");
		
		$linkman_addressval 	= $this -> input ->  funpost("linkman_address");
		$linkman_zipval 		= $this -> input ->  funpost("linkman_zip");
		$linkman_telval 		= $this -> input ->  funpost("linkman_tel");
		$linkman_faxval 		= $this -> input ->  funpost("linkman_fax");
		
		$linkman_websiteval 	= $this -> input ->  funpost("linkman_website");
		$linkman_emailval 		= $this -> input ->  funpost("linkman_email");
		$linkman_licenceval 	= $this -> input ->  funpost("linkman_licence");
		$linkman_chieftainval 	= $this -> input ->  funpost("linkman_chieftain");
		$linkman_bankrollval 	= $this -> input ->  funpost("linkman_bankroll");
		$linkman_turnoverval 	= $this -> input ->  funpost("linkman_turnover");
		$linkman_bankval 		= $this -> input ->  funpost("linkman_bank");
		
		$linkman_bankaccountval 	= $this -> input ->  funpost("linkman_bankaccount");
		$linkman_localtaxnoval 	= $this -> input ->  funpost("linkman_localtaxno");
		$linkman_nationaltaxnoval 	= $this -> input ->  funpost("linkman_nationaltaxno");
		$linkman_manageridval 		= $this -> input ->  funpost("linkman_managerid");
		$linkman_levelval 			= $this -> input ->  funpost("linkman_level");
		$linkman_satisfyval 		= $this -> input ->  funpost("linkman_satisfy");
		$linkman_creditval 		= $this -> input ->  funpost("linkman_credit");
		$linkman_losecountval 		= $this -> input ->  funpost("linkman_losecount");
		$linkman_statusval 		= $this -> input ->  funpost("linkman_status");
		
		
		$addsetUp = '';
		
		if($linkman_idval !='' and $linkman_nameval !='' )
		{

			$updatecus = "UPDATE `linkman` SET  linkman_name = '".$linkman_nameval."' , linkman_pinyin = '".$linkman_pinyinval."' 
			, linkman_area = '".$linkman_areaval."'
			, linkman_address = '".$linkman_addressval."'
			, linkman_zip = '".$linkman_zipval."'
			, linkman_tel = '".$linkman_telval."'
			, linkman_fax = '".$linkman_faxval."'
			, linkman_website = '".$linkman_websiteval."'
			, linkman_email = '".$linkman_emailval."'
			, linkman_licence = '".$linkman_licenceval."'
			, linkman_chieftain = '".$linkman_chieftainval."'
			, linkman_bankroll = '".$linkman_bankrollval."'
			, linkman_turnover = '".$linkman_turnoverval."'
			, linkman_bank = '".$linkman_bankval."'
			, linkman_bankaccount = '".$linkman_bankaccountval."'
			, linkman_localtaxno = '".$linkman_localtaxnoval."'
			, linkman_nationaltaxno = '".$linkman_nationaltaxnoval."'
			, linkman_managerid = '".$linkman_manageridval."'
			, linkman_level = '".$linkman_levelval."'
			, linkman_satisfy = '".$linkman_satisfyval."'
			, linkman_credit = '".$linkman_creditval."'
			, linkman_losecount = '".$linkman_losecountval."'
			, linkman_status = '".$linkman_statusval."'			
			 WHERE  linkman_id = '".$linkman_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?/linkman/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?/linkman/info/".$linkman_idval);
			$this -> view ->  display('suggestion.tpl');	
		}
		
	}
	
	

	
	
}

$Linkman = new Linkman();

?>