<?php
if (!defined('GV32_COM')) exit('GV32.COM No direct script access allowed');
class Customer
{
	function Customer()
	{
		//$GLOBALS['WebSe'] -> isOnLine();
	}
	
	function infolist(  )
	{
		$pageSize = 20 ;		$pageNumval 	= $GLOBALS['Reque'] -> reqval["pageNum"];
		
		if( $pageNumval > 1 )
		{
			$pageNum  = $pageNumval;
			$LIMITnum = ceil( ( $pageNumval -1 ) * $pageSize );
		}else{
			$pageNum  = 1;
			$LIMITnum = 0 ;
		}

		//帐号 	真实姓名 	Email地址 	登录次数 	加入时间 	最后登录时间
		
		$sqlQuery = " SELECT customer_id, customer_name, customer_pinyin, customer_email, customer_tel,customer_fax,customer_losecount,customer_level,customer_satisfy,customer_credit,customer_status  FROM  customer  WHERE 1 GROUP BY customer_id ORDER BY `customer_id` LIMIT  $LIMITnum , $pageSize ";
		
		$info = $GLOBALS['MySql'] -> selectInfo($sqlQuery);
		
		$sqlQuery = " SELECT count(1) as CNUM  FROM  customer  WHERE 1  ORDER BY `customer_id`  ";
		
		$infocount = $GLOBALS['MySql'] -> selectOne($sqlQuery);
		
		//var_dump($info);
		
		$PageStr = $GLOBALS['Page']->buildPageStr( $url = '?load=customer&act=infolist', $pageNum  , $pageSize  , $resultCount = $infocount["CNUM"] );
		
		$GLOBALS['Templ']->assign('ADMIN_BASEUSER',ADMIN_BASEUSER);
		
		$GLOBALS['Templ']->assign('PageStr',$PageStr);
		$GLOBALS['Templ']->assign('info',$info);
		$GLOBALS['Templ']->display('customer_tpl.html');
		
	}
	
	function add(  )
	{
		$GLOBALS['Templ'] -> caching = true;
		$GLOBALS['Templ'] -> cache_lifetime = 86400 ;  //60 *  60 * 24
		$GLOBALS['Templ']->assign('actUrl',EMPLOYEE_WEBURL."/index.php/customer/addinfo");
		$GLOBALS['Templ']->display('customeradd_tpl.html');
	}

	
	function addinfo()
	{
		$customer_nameval 		= $GLOBALS['Reque'] -> funpost("customer_name");
		$customer_pinyinval 		= $GLOBALS['Reque'] -> funpost("customer_pinyin");
		$customer_areaval 		= $GLOBALS['Reque'] -> funpost("customer_area");
		
		$customer_addressval 	= $GLOBALS['Reque'] -> funpost("customer_address");
		$customer_zipval 		= $GLOBALS['Reque'] -> funpost("customer_zip");
		$customer_telval 		= $GLOBALS['Reque'] -> funpost("customer_tel");
		$customer_faxval 		= $GLOBALS['Reque'] -> funpost("customer_fax");
		
		$customer_websiteval 	= $GLOBALS['Reque'] -> funpost("customer_website");
		$customer_emailval 		= $GLOBALS['Reque'] -> funpost("customer_email");
		$customer_licenceval 	= $GLOBALS['Reque'] -> funpost("customer_licence");
		$customer_chieftainval 	= $GLOBALS['Reque'] -> funpost("customer_chieftain");
		$customer_bankrollval 	= $GLOBALS['Reque'] -> funpost("customer_bankroll");
		$customer_turnoverval 	= $GLOBALS['Reque'] -> funpost("customer_turnover");
		$customer_bankval 		= $GLOBALS['Reque'] -> funpost("customer_bank");
		
		$customer_bankaccountval 	= $GLOBALS['Reque'] -> funpost("customer_bankaccount");
		$customer_localtaxnoval 	= $GLOBALS['Reque'] -> funpost("customer_localtaxno");
		$customer_nationaltaxnoval 	= $GLOBALS['Reque'] -> funpost("customer_nationaltaxno");
		$customer_manageridval 		= $GLOBALS['Reque'] -> funpost("customer_managerid");
		$customer_levelval 			= $GLOBALS['Reque'] -> funpost("customer_level");
		$customer_satisfyval 		= $GLOBALS['Reque'] -> funpost("customer_satisfy");
		$customer_creditval 		= $GLOBALS['Reque'] -> funpost("customer_credit");
		$customer_losecountval 		= $GLOBALS['Reque'] -> funpost("customer_losecount");
		$customer_statusval 		= $GLOBALS['Reque'] -> funpost("customer_status");
		
		
		$customer_regtimeval 	= time();
		
		if($customer_nameval !='' and $customer_emailval !='' and $customer_telval !='' and $customer_pinyinval !='' )
		{
			$sqlQuery = " SELECT count(1) as CNUM  FROM  customer  WHERE customer_name = '".$customer_nameval."' ORDER BY `customer_id` ";
			
			$info = $GLOBALS['MySql'] -> selectOne($sqlQuery);
			
			if( $info["CNUM"] < 1 )
			{
				
				$insertip ="INSERT INTO `customer` (`customer_name` , `customer_pinyin` , `customer_area` , `customer_address` , `customer_zip`, `customer_tel` , `customer_fax` , `customer_website` , `customer_email` , `customer_licence` , `customer_chieftain` , `customer_bankroll` , `customer_turnover`, `customer_bank` , `customer_bankaccount` , `customer_localtaxno` , `customer_nationaltaxno` , `customer_managerid`, `customer_level` , `customer_satisfy` , `customer_credit` , `customer_losecount`  , `customer_status` ) VALUES (  '$customer_nameval', '$customer_pinyinval', '$customer_areaval', '$customer_addressval', '$customer_zipval', '$customer_telval', '$customer_faxval', '$customer_websiteval', '$customer_emailval', '$customer_licenceval', '$customer_chieftainval', '$customer_bankrollval', '$customer_turnoverval', '$customer_bankval', '$customer_bankaccountval', '$customer_localtaxnoval', '$customer_nationaltaxnoval', '$customer_manageridval', '$customer_levelval', '$customer_satisfyval', '$customer_creditval', '$customer_losecountval', '$customer_statusval')";

				$GLOBALS['MySql'] -> querySql($insertip);
				$GLOBALS['Templ'] -> assign('infomessage',$GLOBALS['_LANG']['bd_addsusse']);
				$GLOBALS['Templ'] -> assign('URL_TIME',URL_TIME);
				$GLOBALS['Templ'] -> assign('geturl',EMPLOYEE_WEBURL."/index.php/customer/infolist");
				$GLOBALS['Templ'] -> display('suggestion_tpl.html');	
				
			}else{
				
				$GLOBALS['Templ'] -> assign('infomessage',$GLOBALS['_LANG']['bd_isrealyerror']);
				$GLOBALS['Templ'] -> assign('URL_TIME',URL_TIME);
				$GLOBALS['Templ'] -> assign('geturl',EMPLOYEE_WEBURL."/index.php/customer/add/");
				$GLOBALS['Templ'] -> display('suggestion_tpl.html');	
			}
			
			
		}else{
			
			$GLOBALS['Templ'] -> assign('infomessage',$GLOBALS['_LANG']['bd_losssusse']);
			$GLOBALS['Templ'] -> assign('URL_TIME',URL_TIME);
			$GLOBALS['Templ'] -> assign('geturl',EMPLOYEE_WEBURL."/index.php/customer/add/");
			$GLOBALS['Templ'] -> display('suggestion_tpl.html');		}
			//var_dump($_REQUEST);
	}
	
	function del( )
	{
		$indel = implode(',', $delArray);

		//$deletesql ="DELETE FROM `customer` WHERE `customer`.`customer_id` in ( $indel ) and customer_name != '".ADMIN_BASEUSER."' ";
		$deletesql ="UPDATE `customer` SET  customer_status = 5 WHERE `customer`.`customer_id` IN ( $indel )  ";
		
		$GLOBALS['MySql'] -> querySql($deletesql);
		
		$GLOBALS['Templ'] -> assign('infomessage',$GLOBALS['_LANG']['bd_delsusse']);
		$GLOBALS['Templ'] -> assign('URL_TIME',URL_TIME);
		$GLOBALS['Templ'] -> assign('geturl',EMPLOYEE_WEBURL."/index.php/customer/infolist/");
		$GLOBALS['Templ'] -> display('suggestion_tpl.html');
	}
	
	function info(  )
	{
		$infoid = $infoArray[0];
		
		$sqlQuery = " SELECT *  FROM  customer  WHERE customer_id = '".$infoid."' ORDER BY `customer_id` ";
		$info = $GLOBALS['MySql'] -> selectOne($sqlQuery);
				
		$GLOBALS['Templ']->assign('actUrl',EMPLOYEE_WEBURL."/index.php/customer/editinfo");
		$GLOBALS['Templ'] -> assign('info',$info);
		$GLOBALS['Templ'] -> display('customeredit_tpl.html');
	
	}
	
	
	function editinfo( )
	{	
	
		$customer_idval 		= $GLOBALS['Reque'] -> funpost("customer_id");
		$customer_nameval 		= $GLOBALS['Reque'] -> funpost("customer_name");
		$customer_pinyinval 	= $GLOBALS['Reque'] -> funpost("customer_pinyin");
		$customer_areaval 		= $GLOBALS['Reque'] -> funpost("customer_area");
		
		$customer_addressval 	= $GLOBALS['Reque'] -> funpost("customer_address");
		$customer_zipval 		= $GLOBALS['Reque'] -> funpost("customer_zip");
		$customer_telval 		= $GLOBALS['Reque'] -> funpost("customer_tel");
		$customer_faxval 		= $GLOBALS['Reque'] -> funpost("customer_fax");
		
		$customer_websiteval 	= $GLOBALS['Reque'] -> funpost("customer_website");
		$customer_emailval 		= $GLOBALS['Reque'] -> funpost("customer_email");
		$customer_licenceval 	= $GLOBALS['Reque'] -> funpost("customer_licence");
		$customer_chieftainval 	= $GLOBALS['Reque'] -> funpost("customer_chieftain");
		$customer_bankrollval 	= $GLOBALS['Reque'] -> funpost("customer_bankroll");
		$customer_turnoverval 	= $GLOBALS['Reque'] -> funpost("customer_turnover");
		$customer_bankval 		= $GLOBALS['Reque'] -> funpost("customer_bank");
		
		$customer_bankaccountval 	= $GLOBALS['Reque'] -> funpost("customer_bankaccount");
		$customer_localtaxnoval 	= $GLOBALS['Reque'] -> funpost("customer_localtaxno");
		$customer_nationaltaxnoval 	= $GLOBALS['Reque'] -> funpost("customer_nationaltaxno");
		$customer_manageridval 		= $GLOBALS['Reque'] -> funpost("customer_managerid");
		$customer_levelval 			= $GLOBALS['Reque'] -> funpost("customer_level");
		$customer_satisfyval 		= $GLOBALS['Reque'] -> funpost("customer_satisfy");
		$customer_creditval 		= $GLOBALS['Reque'] -> funpost("customer_credit");
		$customer_losecountval 		= $GLOBALS['Reque'] -> funpost("customer_losecount");
		$customer_statusval 		= $GLOBALS['Reque'] -> funpost("customer_status");
		
		
		$addsetUp = '';
		
		if($customer_idval !='' and $customer_nameval !='' )
		{

			
			$updatecus = "UPDATE `customer` SET  customer_name = '".$customer_nameval."' , customer_pinyin = '".$customer_pinyinval."' 
			, customer_area = '".$customer_areaval."'
			, customer_address = '".$customer_addressval."'
			, customer_zip = '".$customer_zipval."'
			, customer_tel = '".$customer_telval."'
			, customer_fax = '".$customer_faxval."'
			, customer_website = '".$customer_websiteval."'
			, customer_email = '".$customer_emailval."'
			, customer_licence = '".$customer_licenceval."'
			, customer_chieftain = '".$customer_chieftainval."'
			, customer_bankroll = '".$customer_bankrollval."'
			, customer_turnover = '".$customer_turnoverval."'
			, customer_bank = '".$customer_bankval."'
			, customer_bankaccount = '".$customer_bankaccountval."'
			, customer_localtaxno = '".$customer_localtaxnoval."'
			, customer_nationaltaxno = '".$customer_nationaltaxnoval."'
			, customer_managerid = '".$customer_manageridval."'
			, customer_level = '".$customer_levelval."'
			, customer_satisfy = '".$customer_satisfyval."'
			, customer_credit = '".$customer_creditval."'
			, customer_losecount = '".$customer_losecountval."'
			, customer_status = '".$customer_statusval."'

			
			 WHERE  customer_id = '".$customer_idval."' ";
			
			$GLOBALS['MySql'] -> querySql( $updatecus );
			
			$GLOBALS['Templ'] -> assign('infomessage',$GLOBALS['_LANG']['bd_editsusse']);
			$GLOBALS['Templ'] -> assign('URL_TIME',URL_TIME);
			$GLOBALS['Templ'] -> assign('geturl',EMPLOYEE_WEBURL."/index.php/customer/infolist/");
			$GLOBALS['Templ'] -> display('suggestion_tpl.html');
				
		}else{
		
			$GLOBALS['Templ'] -> assign('infomessage',$GLOBALS['_LANG']['bd_losssusse']);
			$GLOBALS['Templ'] -> assign('URL_TIME',URL_TIME);
			$GLOBALS['Templ'] -> assign('geturl',EMPLOYEE_WEBURL."/index.php/customer/info/".$customer_idval);
			$GLOBALS['Templ'] -> display('suggestion_tpl.html');	
		}
		
	}
	
	

	
	
}

$Customer = new Customer();

?>