<?php
if (!defined('HUCART_COM')) exit('HuCart.COM No direct script access allowed');
class Service
{
	function Service()
	{
		//$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 service_id, service_name, service_pinyin, service_email, service_tel,service_fax,service_losecount,service_level,service_satisfy,service_credit,service_status  FROM  ".$this -> db -> prefix."service  WHERE 1 GROUP BY service_id ORDER BY `service_id` LIMIT  $limit_num , $page_size ";
		
		$info = $this -> db -> select_info($sql_query);
		
		$sql_query = " SELECT count(1) as CNUM  FROM  ".$this -> db -> prefix."service  WHERE 1  ORDER BY `service_id`  ";
		
		$infocount = $this -> db -> select_one($sql_query);
		
		//var_dump($info);
		
		$page_str = $this -> page ->get_admin_page( $url = '?load=service&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('service.tpl');
		
	}
	
	function add(  )
	{
		$this -> view ->  caching = true;
		$this -> view ->  cache_lifetime = 86400 ;  //60 *  60 * 24
		$this -> view -> assign('act_url',ADMIN_WEBURL."/index.php?/service/add_info");
		$this -> view -> display('serviceadd.tpl');
	}

	
	function add_info()
	{
		$service_nameval 		= $this -> input ->  funpost("service_name");
		$service_pinyinval 		= $this -> input ->  funpost("service_pinyin");
		$service_areaval 		= $this -> input ->  funpost("service_area");
		
		$service_addressval 	= $this -> input ->  funpost("service_address");
		$service_zipval 		= $this -> input ->  funpost("service_zip");
		$service_telval 		= $this -> input ->  funpost("service_tel");
		$service_faxval 		= $this -> input ->  funpost("service_fax");
		
		$service_websiteval 	= $this -> input ->  funpost("service_website");
		$service_emailval 		= $this -> input ->  funpost("service_email");
		$service_licenceval 	= $this -> input ->  funpost("service_licence");
		$service_chieftainval 	= $this -> input ->  funpost("service_chieftain");
		$service_bankrollval 	= $this -> input ->  funpost("service_bankroll");
		$service_turnoverval 	= $this -> input ->  funpost("service_turnover");
		$service_bankval 		= $this -> input ->  funpost("service_bank");
		
		$service_bankaccountval 	= $this -> input ->  funpost("service_bankaccount");
		$service_localtaxnoval 	= $this -> input ->  funpost("service_localtaxno");
		$service_nationaltaxnoval 	= $this -> input ->  funpost("service_nationaltaxno");
		$service_manageridval 		= $this -> input ->  funpost("service_managerid");
		$service_levelval 			= $this -> input ->  funpost("service_level");
		$service_satisfyval 		= $this -> input ->  funpost("service_satisfy");
		$service_creditval 		= $this -> input ->  funpost("service_credit");
		$service_losecountval 		= $this -> input ->  funpost("service_losecount");
		$service_statusval 		= $this -> input ->  funpost("service_status");
		
		
		$service_regtimeval 	= time();
		
		if($service_nameval !='' and $service_emailval !='' and $service_telval !='' and $service_pinyinval !='' )
		{
			$sql_query = " SELECT count(1) as CNUM  FROM  ".$this -> db -> prefix."service  WHERE service_name = '".$service_nameval."' ORDER BY `service_id` ";
			
			$info = $this -> db -> select_one($sql_query);
			
			if( $info["CNUM"] < 1 )
			{
				
				$insertip ="INSERT INTO `service` (`service_name` , `service_pinyin` , `service_area` , `service_address` , `service_zip`, `service_tel` , `service_fax` , `service_website` , `service_email` , `service_licence` , `service_chieftain` , `service_bankroll` , `service_turnover`, `service_bank` , `service_bankaccount` , `service_localtaxno` , `service_nationaltaxno` , `service_managerid`, `service_level` , `service_satisfy` , `service_credit` , `service_losecount`  , `service_status` ) VALUES (  '$service_nameval', '$service_pinyinval', '$service_areaval', '$service_addressval', '$service_zipval', '$service_telval', '$service_faxval', '$service_websiteval', '$service_emailval', '$service_licenceval', '$service_chieftainval', '$service_bankrollval', '$service_turnoverval', '$service_bankval', '$service_bankaccountval', '$service_localtaxnoval', '$service_nationaltaxnoval', '$service_manageridval', '$service_levelval', '$service_satisfyval', '$service_creditval', '$service_losecountval', '$service_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?/service/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?/service/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?/service/add/");
			$this -> view ->  display('suggestion.tpl');		}
			//var_dump($_REQUEST);
	}
	
	function del( )
	{
		$indel = implode(',', $delArray);

		//$deletesql ="DELETE FROM `service` WHERE `service`.`service_id` in ( $indel ) and service_name != '".ADMIN_BASEUSER."' ";
		$deletesql ="UPDATE `service` SET  service_status = 5 WHERE `service`.`service_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?/service/info_list/");
		$this -> view ->  display('suggestion.tpl');
	}
	
	function info(  )
	{
		$infoid = $infoArray[0];
		
		$sql_query = " SELECT *  FROM  ".$this -> db -> prefix."service  WHERE service_id = '".$infoid."' ORDER BY `service_id` ";
		$info = $this -> db -> select_one($sql_query);
				
		$this -> view -> assign('act_url',ADMIN_WEBURL."/index.php?/service/edit_info");
		$this -> view ->  assign('info',$info);
		$this -> view ->  display('serviceedit.tpl');
	
	}
	
	
	function edit_info( )
	{	
	
		$service_idval 		= $this -> input ->  funpost("service_id");
		$service_nameval 		= $this -> input ->  funpost("service_name");
		$service_pinyinval 	= $this -> input ->  funpost("service_pinyin");
		$service_areaval 		= $this -> input ->  funpost("service_area");
		
		$service_addressval 	= $this -> input ->  funpost("service_address");
		$service_zipval 		= $this -> input ->  funpost("service_zip");
		$service_telval 		= $this -> input ->  funpost("service_tel");
		$service_faxval 		= $this -> input ->  funpost("service_fax");
		
		$service_websiteval 	= $this -> input ->  funpost("service_website");
		$service_emailval 		= $this -> input ->  funpost("service_email");
		$service_licenceval 	= $this -> input ->  funpost("service_licence");
		$service_chieftainval 	= $this -> input ->  funpost("service_chieftain");
		$service_bankrollval 	= $this -> input ->  funpost("service_bankroll");
		$service_turnoverval 	= $this -> input ->  funpost("service_turnover");
		$service_bankval 		= $this -> input ->  funpost("service_bank");
		
		$service_bankaccountval 	= $this -> input ->  funpost("service_bankaccount");
		$service_localtaxnoval 	= $this -> input ->  funpost("service_localtaxno");
		$service_nationaltaxnoval 	= $this -> input ->  funpost("service_nationaltaxno");
		$service_manageridval 		= $this -> input ->  funpost("service_managerid");
		$service_levelval 			= $this -> input ->  funpost("service_level");
		$service_satisfyval 		= $this -> input ->  funpost("service_satisfy");
		$service_creditval 		= $this -> input ->  funpost("service_credit");
		$service_losecountval 		= $this -> input ->  funpost("service_losecount");
		$service_statusval 		= $this -> input ->  funpost("service_status");
		
		
		$addsetUp = '';
		
		if($service_idval !='' and $service_nameval !='' )
		{

			
			$updatecus = "UPDATE `".$this -> db -> prefix."service` SET  service_name = '".$service_nameval."' , service_pinyin = '".$service_pinyinval."' 
			, service_area = '".$service_areaval."'
			, service_address = '".$service_addressval."'
			, service_zip = '".$service_zipval."'
			, service_tel = '".$service_telval."'
			, service_fax = '".$service_faxval."'
			, service_website = '".$service_websiteval."'
			, service_email = '".$service_emailval."'
			, service_licence = '".$service_licenceval."'
			, service_chieftain = '".$service_chieftainval."'
			, service_bankroll = '".$service_bankrollval."'
			, service_turnover = '".$service_turnoverval."'
			, service_bank = '".$service_bankval."'
			, service_bankaccount = '".$service_bankaccountval."'
			, service_localtaxno = '".$service_localtaxnoval."'
			, service_nationaltaxno = '".$service_nationaltaxnoval."'
			, service_managerid = '".$service_manageridval."'
			, service_level = '".$service_levelval."'
			, service_satisfy = '".$service_satisfyval."'
			, service_credit = '".$service_creditval."'
			, service_losecount = '".$service_losecountval."'
			, service_status = '".$service_statusval."'

			
			 WHERE  service_id = '".$service_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?/service/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?/service/info/".$service_idval);
			$this -> view ->  display('suggestion.tpl');	
		}
		
	}
	
	

	
	
}

$Service = new Service();

?>