<?php
if (!defined('GV32_COM')) exit('GV32.COM No direct script access allowed');
class Chance
{
	function Chance()
	{
		//$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 chance_id, chance_source, customer_id, chance_title, chance_rate,	chance_linkman,chance_tel,	chance_mobile,chance_addtime   FROM  ".SQL_PREFIX."chance  WHERE 1 GROUP BY chance_id ORDER BY `chance_id` LIMIT  $LIMITnum , $pageSize ";
		
		$info = $GLOBALS['MySql'] -> selectInfo($sqlQuery);
		
		$sqlQuery = " SELECT count(1) as CNUM  FROM  chance  WHERE 1  ORDER BY `chance_id`  ";
		
		$infocount = $GLOBALS['MySql'] -> selectOne($sqlQuery);
		
		//var_dump($info);
		
		$PageStr = $GLOBALS['Page']->buildPageStr( $url = '?load=chance&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('chance_tpl.html');
		
	}
	
	function add(  )
	{
		$GLOBALS['Templ'] -> caching = true;
		$GLOBALS['Templ'] -> cache_lifetime = 86400 ;  //60 *  60 * 24
		$GLOBALS['Templ']->assign('actUrl',EMPLOYEE_WEBURL."/index.php/chance/addinfo");
		$GLOBALS['Templ']->display('chanceadd_tpl.html');
	}

	
	function addinfo()
	{
		$chance_nameval 		= $GLOBALS['Reque'] -> funpost("chance_name");
		$chance_pinyinval 		= $GLOBALS['Reque'] -> funpost("chance_pinyin");
		$chance_areaval 		= $GLOBALS['Reque'] -> funpost("chance_area");
		
		$chance_addressval 	= $GLOBALS['Reque'] -> funpost("chance_address");
		$chance_zipval 		= $GLOBALS['Reque'] -> funpost("chance_zip");
		$chance_telval 		= $GLOBALS['Reque'] -> funpost("chance_tel");
		$chance_faxval 		= $GLOBALS['Reque'] -> funpost("chance_fax");
		
		$chance_websiteval 	= $GLOBALS['Reque'] -> funpost("chance_website");
		$chance_emailval 		= $GLOBALS['Reque'] -> funpost("chance_email");
		$chance_licenceval 	= $GLOBALS['Reque'] -> funpost("chance_licence");
		$chance_chieftainval 	= $GLOBALS['Reque'] -> funpost("chance_chieftain");
		$chance_bankrollval 	= $GLOBALS['Reque'] -> funpost("chance_bankroll");
		$chance_turnoverval 	= $GLOBALS['Reque'] -> funpost("chance_turnover");
		$chance_bankval 		= $GLOBALS['Reque'] -> funpost("chance_bank");
		
		$chance_bankaccountval 	= $GLOBALS['Reque'] -> funpost("chance_bankaccount");
		$chance_localtaxnoval 	= $GLOBALS['Reque'] -> funpost("chance_localtaxno");
		$chance_nationaltaxnoval 	= $GLOBALS['Reque'] -> funpost("chance_nationaltaxno");
		$chance_manageridval 		= $GLOBALS['Reque'] -> funpost("chance_managerid");
		$chance_levelval 			= $GLOBALS['Reque'] -> funpost("chance_level");
		$chance_satisfyval 		= $GLOBALS['Reque'] -> funpost("chance_satisfy");
		$chance_creditval 		= $GLOBALS['Reque'] -> funpost("chance_credit");
		$chance_losecountval 		= $GLOBALS['Reque'] -> funpost("chance_losecount");
		$chance_statusval 		= $GLOBALS['Reque'] -> funpost("chance_status");
		
		
		$chance_regtimeval 	= time();
		
		if($chance_nameval !='' and $chance_emailval !='' and $chance_telval !='' and $chance_pinyinval !='' )
		{
			$sqlQuery = " SELECT count(1) as CNUM  FROM  ".SQL_PREFIX."chance  WHERE chance_name = '".$chance_nameval."' ORDER BY `chance_id` ";
			
			$info = $GLOBALS['MySql'] -> selectOne($sqlQuery);
			
			if( $info["CNUM"] < 1 )
			{
				
				$insertip ="INSERT INTO `".SQL_PREFIX."chance` (`chance_name` , `chance_pinyin` , `chance_area` , `chance_address` , `chance_zip`, `chance_tel` , `chance_fax` , `chance_website` , `chance_email` , `chance_licence` , `chance_chieftain` , `chance_bankroll` , `chance_turnover`, `chance_bank` , `chance_bankaccount` , `chance_localtaxno` , `chance_nationaltaxno` , `chance_managerid`, `chance_level` , `chance_satisfy` , `chance_credit` , `chance_losecount`  , `chance_status` ) VALUES (  '$chance_nameval', '$chance_pinyinval', '$chance_areaval', '$chance_addressval', '$chance_zipval', '$chance_telval', '$chance_faxval', '$chance_websiteval', '$chance_emailval', '$chance_licenceval', '$chance_chieftainval', '$chance_bankrollval', '$chance_turnoverval', '$chance_bankval', '$chance_bankaccountval', '$chance_localtaxnoval', '$chance_nationaltaxnoval', '$chance_manageridval', '$chance_levelval', '$chance_satisfyval', '$chance_creditval', '$chance_losecountval', '$chance_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/chance/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/chance/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/chance/add/");
			$GLOBALS['Templ'] -> display('suggestion_tpl.html');		}
			//var_dump($_REQUEST);
	}
	
	function del( )
	{
		$indel = implode(',', $delArray);

		//$deletesql ="DELETE FROM `chance` WHERE `chance`.`chance_id` in ( $indel ) and chance_name != '".ADMIN_BASEUSER."' ";
		$deletesql ="UPDATE `".SQL_PREFIX."chance` SET  chance_status = 5 WHERE `chance`.`chance_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/chance/infolist/");
		$GLOBALS['Templ'] -> display('suggestion_tpl.html');
	}
	
	function info(  )
	{
		$infoid = $infoArray[0];
		
		$sqlQuery = " SELECT *  FROM  ".SQL_PREFIX."chance  WHERE chance_id = '".$infoid."' ORDER BY `chance_id` ";
		$info = $GLOBALS['MySql'] -> selectOne($sqlQuery);
				
		$GLOBALS['Templ']->assign('actUrl',EMPLOYEE_WEBURL."/index.php/chance/editinfo");
		$GLOBALS['Templ'] -> assign('info',$info);
		$GLOBALS['Templ'] -> display('chanceedit_tpl.html');
	
	}
	
	
	function editinfo( )
	{	
	
		$chance_idval 		= $GLOBALS['Reque'] -> funpost("chance_id");
		$chance_nameval 		= $GLOBALS['Reque'] -> funpost("chance_name");
		$chance_pinyinval 	= $GLOBALS['Reque'] -> funpost("chance_pinyin");
		$chance_areaval 		= $GLOBALS['Reque'] -> funpost("chance_area");
		
		$chance_addressval 	= $GLOBALS['Reque'] -> funpost("chance_address");
		$chance_zipval 		= $GLOBALS['Reque'] -> funpost("chance_zip");
		$chance_telval 		= $GLOBALS['Reque'] -> funpost("chance_tel");
		$chance_faxval 		= $GLOBALS['Reque'] -> funpost("chance_fax");
		
		$chance_websiteval 	= $GLOBALS['Reque'] -> funpost("chance_website");
		$chance_emailval 		= $GLOBALS['Reque'] -> funpost("chance_email");
		$chance_licenceval 	= $GLOBALS['Reque'] -> funpost("chance_licence");
		$chance_chieftainval 	= $GLOBALS['Reque'] -> funpost("chance_chieftain");
		$chance_bankrollval 	= $GLOBALS['Reque'] -> funpost("chance_bankroll");
		$chance_turnoverval 	= $GLOBALS['Reque'] -> funpost("chance_turnover");
		$chance_bankval 		= $GLOBALS['Reque'] -> funpost("chance_bank");
		
		$chance_bankaccountval 	= $GLOBALS['Reque'] -> funpost("chance_bankaccount");
		$chance_localtaxnoval 	= $GLOBALS['Reque'] -> funpost("chance_localtaxno");
		$chance_nationaltaxnoval 	= $GLOBALS['Reque'] -> funpost("chance_nationaltaxno");
		$chance_manageridval 		= $GLOBALS['Reque'] -> funpost("chance_managerid");
		$chance_levelval 			= $GLOBALS['Reque'] -> funpost("chance_level");
		$chance_satisfyval 		= $GLOBALS['Reque'] -> funpost("chance_satisfy");
		$chance_creditval 		= $GLOBALS['Reque'] -> funpost("chance_credit");
		$chance_losecountval 		= $GLOBALS['Reque'] -> funpost("chance_losecount");
		$chance_statusval 		= $GLOBALS['Reque'] -> funpost("chance_status");
		
		
		$addsetUp = '';
		
		if($chance_idval !='' and $chance_nameval !='' )
		{

			
			$updatecus = "UPDATE `".SQL_PREFIX."chance` SET  chance_name = '".$chance_nameval."' , chance_pinyin = '".$chance_pinyinval."' 
			, chance_area = '".$chance_areaval."'
			, chance_address = '".$chance_addressval."'
			, chance_zip = '".$chance_zipval."'
			, chance_tel = '".$chance_telval."'
			, chance_fax = '".$chance_faxval."'
			, chance_website = '".$chance_websiteval."'
			, chance_email = '".$chance_emailval."'
			, chance_licence = '".$chance_licenceval."'
			, chance_chieftain = '".$chance_chieftainval."'
			, chance_bankroll = '".$chance_bankrollval."'
			, chance_turnover = '".$chance_turnoverval."'
			, chance_bank = '".$chance_bankval."'
			, chance_bankaccount = '".$chance_bankaccountval."'
			, chance_localtaxno = '".$chance_localtaxnoval."'
			, chance_nationaltaxno = '".$chance_nationaltaxnoval."'
			, chance_managerid = '".$chance_manageridval."'
			, chance_level = '".$chance_levelval."'
			, chance_satisfy = '".$chance_satisfyval."'
			, chance_credit = '".$chance_creditval."'
			, chance_losecount = '".$chance_losecountval."'
			, chance_status = '".$chance_statusval."'

			
			 WHERE  chance_id = '".$chance_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/chance/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/chance/info/".$chance_idval);
			$GLOBALS['Templ'] -> display('suggestion_tpl.html');	
		}
		
	}
	
	

	
	
}

$Chance = new Chance();

?>