<?php
if (!defined('GV32_COM')) exit('GV32.COM No direct script access allowed');
class Service
{
	function Service()
	{
		//$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 service_id, service_name, service_pinyin, service_email, service_tel,service_fax,service_losecount,service_level,service_satisfy,service_credit,service_status  FROM  ".SQL_PREFIX."service  WHERE 1 GROUP BY service_id ORDER BY `service_id` LIMIT  $LIMITnum , $pageSize ";
		
		$info = $GLOBALS['MySql'] -> selectInfo($sqlQuery);
		
		$sqlQuery = " SELECT count(1) as CNUM  FROM  ".SQL_PREFIX."service  WHERE 1  ORDER BY `service_id`  ";
		
		$infocount = $GLOBALS['MySql'] -> selectOne($sqlQuery);
		
		//var_dump($info);
		
		$PageStr = $GLOBALS['Page']->buildPageStr( $url = '?load=service&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('service_tpl.html');
		
	}
	
	function add(  )
	{
		$GLOBALS['Templ'] -> caching = true;
		$GLOBALS['Templ'] -> cache_lifetime = 86400 ;  //60 *  60 * 24
		$GLOBALS['Templ']->assign('actUrl',EMPLOYEE_WEBURL."/index.php/service/addinfo");
		$GLOBALS['Templ']->display('serviceadd_tpl.html');
	}

	
	function addinfo()
	{
		$service_nameval 		= $GLOBALS['Reque'] -> funpost("service_name");
		$service_pinyinval 		= $GLOBALS['Reque'] -> funpost("service_pinyin");
		$service_areaval 		= $GLOBALS['Reque'] -> funpost("service_area");
		
		$service_addressval 	= $GLOBALS['Reque'] -> funpost("service_address");
		$service_zipval 		= $GLOBALS['Reque'] -> funpost("service_zip");
		$service_telval 		= $GLOBALS['Reque'] -> funpost("service_tel");
		$service_faxval 		= $GLOBALS['Reque'] -> funpost("service_fax");
		
		$service_websiteval 	= $GLOBALS['Reque'] -> funpost("service_website");
		$service_emailval 		= $GLOBALS['Reque'] -> funpost("service_email");
		$service_licenceval 	= $GLOBALS['Reque'] -> funpost("service_licence");
		$service_chieftainval 	= $GLOBALS['Reque'] -> funpost("service_chieftain");
		$service_bankrollval 	= $GLOBALS['Reque'] -> funpost("service_bankroll");
		$service_turnoverval 	= $GLOBALS['Reque'] -> funpost("service_turnover");
		$service_bankval 		= $GLOBALS['Reque'] -> funpost("service_bank");
		
		$service_bankaccountval 	= $GLOBALS['Reque'] -> funpost("service_bankaccount");
		$service_localtaxnoval 	= $GLOBALS['Reque'] -> funpost("service_localtaxno");
		$service_nationaltaxnoval 	= $GLOBALS['Reque'] -> funpost("service_nationaltaxno");
		$service_manageridval 		= $GLOBALS['Reque'] -> funpost("service_managerid");
		$service_levelval 			= $GLOBALS['Reque'] -> funpost("service_level");
		$service_satisfyval 		= $GLOBALS['Reque'] -> funpost("service_satisfy");
		$service_creditval 		= $GLOBALS['Reque'] -> funpost("service_credit");
		$service_losecountval 		= $GLOBALS['Reque'] -> funpost("service_losecount");
		$service_statusval 		= $GLOBALS['Reque'] -> funpost("service_status");
		
		
		$service_regtimeval 	= time();
		
		if($service_nameval !='' and $service_emailval !='' and $service_telval !='' and $service_pinyinval !='' )
		{
			$sqlQuery = " SELECT count(1) as CNUM  FROM  ".SQL_PREFIX."service  WHERE service_name = '".$service_nameval."' ORDER BY `service_id` ";
			
			$info = $GLOBALS['MySql'] -> selectOne($sqlQuery);
			
			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')";

				$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/service/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/service/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/service/add/");
			$GLOBALS['Templ'] -> display('suggestion_tpl.html');		}
			//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 )  ";
		
		$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/service/infolist/");
		$GLOBALS['Templ'] -> display('suggestion_tpl.html');
	}
	
	function info(  )
	{
		$infoid = $infoArray[0];
		
		$sqlQuery = " SELECT *  FROM  ".SQL_PREFIX."service  WHERE service_id = '".$infoid."' ORDER BY `service_id` ";
		$info = $GLOBALS['MySql'] -> selectOne($sqlQuery);
				
		$GLOBALS['Templ']->assign('actUrl',EMPLOYEE_WEBURL."/index.php/service/editinfo");
		$GLOBALS['Templ'] -> assign('info',$info);
		$GLOBALS['Templ'] -> display('serviceedit_tpl.html');
	
	}
	
	
	function editinfo( )
	{	
	
		$service_idval 		= $GLOBALS['Reque'] -> funpost("service_id");
		$service_nameval 		= $GLOBALS['Reque'] -> funpost("service_name");
		$service_pinyinval 	= $GLOBALS['Reque'] -> funpost("service_pinyin");
		$service_areaval 		= $GLOBALS['Reque'] -> funpost("service_area");
		
		$service_addressval 	= $GLOBALS['Reque'] -> funpost("service_address");
		$service_zipval 		= $GLOBALS['Reque'] -> funpost("service_zip");
		$service_telval 		= $GLOBALS['Reque'] -> funpost("service_tel");
		$service_faxval 		= $GLOBALS['Reque'] -> funpost("service_fax");
		
		$service_websiteval 	= $GLOBALS['Reque'] -> funpost("service_website");
		$service_emailval 		= $GLOBALS['Reque'] -> funpost("service_email");
		$service_licenceval 	= $GLOBALS['Reque'] -> funpost("service_licence");
		$service_chieftainval 	= $GLOBALS['Reque'] -> funpost("service_chieftain");
		$service_bankrollval 	= $GLOBALS['Reque'] -> funpost("service_bankroll");
		$service_turnoverval 	= $GLOBALS['Reque'] -> funpost("service_turnover");
		$service_bankval 		= $GLOBALS['Reque'] -> funpost("service_bank");
		
		$service_bankaccountval 	= $GLOBALS['Reque'] -> funpost("service_bankaccount");
		$service_localtaxnoval 	= $GLOBALS['Reque'] -> funpost("service_localtaxno");
		$service_nationaltaxnoval 	= $GLOBALS['Reque'] -> funpost("service_nationaltaxno");
		$service_manageridval 		= $GLOBALS['Reque'] -> funpost("service_managerid");
		$service_levelval 			= $GLOBALS['Reque'] -> funpost("service_level");
		$service_satisfyval 		= $GLOBALS['Reque'] -> funpost("service_satisfy");
		$service_creditval 		= $GLOBALS['Reque'] -> funpost("service_credit");
		$service_losecountval 		= $GLOBALS['Reque'] -> funpost("service_losecount");
		$service_statusval 		= $GLOBALS['Reque'] -> funpost("service_status");
		
		
		$addsetUp = '';
		
		if($service_idval !='' and $service_nameval !='' )
		{

			
			$updatecus = "UPDATE `".SQL_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."' ";
			
			$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/service/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/service/info/".$service_idval);
			$GLOBALS['Templ'] -> display('suggestion_tpl.html');	
		}
		
	}
	
	

	
	
}

$Service = new Service();

?>