<?php
if (!defined('GV32_COM')) exit('GV32.COM No direct script access allowed');
class Market
{
	function Market()
	{
		//$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 market_id, market_company, market_price, market_opponent, market_quotation  FROM  market  WHERE 1 GROUP BY market_id ORDER BY `market_id` LIMIT  $LIMITnum , $pageSize ";
		
		$info = $GLOBALS['MySql'] -> selectInfo($sqlQuery);
		
		$sqlQuery = " SELECT count(1) as CNUM  FROM  market  WHERE 1  ORDER BY `market_id`  ";
		
		$infocount = $GLOBALS['MySql'] -> selectOne($sqlQuery);
		
		//var_dump($info);
		
		$PageStr = $GLOBALS['Page']->buildPageStr( $url = '?load=market&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('market_tpl.html');
		
	}
	
	function add(  )
	{
		$GLOBALS['Templ'] -> caching = true;
		$GLOBALS['Templ'] -> cache_lifetime = 86400 ;  //60 *  60 * 24
		$GLOBALS['Templ']->assign('actUrl',EMPLOYEE_WEBURL."/index.php/market/addinfo");
		$GLOBALS['Templ']->display('marketadd_tpl.html');
	}

	
	function addinfo()
	{
		$market_nameval 		= $GLOBALS['Reque'] -> funpost("market_name");
		$market_pinyinval 		= $GLOBALS['Reque'] -> funpost("market_pinyin");
		$market_areaval 		= $GLOBALS['Reque'] -> funpost("market_area");
		
		$market_addressval 	= $GLOBALS['Reque'] -> funpost("market_address");
		$market_zipval 		= $GLOBALS['Reque'] -> funpost("market_zip");
		$market_telval 		= $GLOBALS['Reque'] -> funpost("market_tel");
		$market_faxval 		= $GLOBALS['Reque'] -> funpost("market_fax");
		
		$market_websiteval 	= $GLOBALS['Reque'] -> funpost("market_website");
		$market_emailval 		= $GLOBALS['Reque'] -> funpost("market_email");
		$market_licenceval 	= $GLOBALS['Reque'] -> funpost("market_licence");
		$market_chieftainval 	= $GLOBALS['Reque'] -> funpost("market_chieftain");
		$market_bankrollval 	= $GLOBALS['Reque'] -> funpost("market_bankroll");
		$market_turnoverval 	= $GLOBALS['Reque'] -> funpost("market_turnover");
		$market_bankval 		= $GLOBALS['Reque'] -> funpost("market_bank");
		
		$market_bankaccountval 	= $GLOBALS['Reque'] -> funpost("market_bankaccount");
		$market_localtaxnoval 	= $GLOBALS['Reque'] -> funpost("market_localtaxno");
		$market_nationaltaxnoval 	= $GLOBALS['Reque'] -> funpost("market_nationaltaxno");
		$market_manageridval 		= $GLOBALS['Reque'] -> funpost("market_managerid");
		$market_levelval 			= $GLOBALS['Reque'] -> funpost("market_level");
		$market_satisfyval 		= $GLOBALS['Reque'] -> funpost("market_satisfy");
		$market_creditval 		= $GLOBALS['Reque'] -> funpost("market_credit");
		$market_losecountval 		= $GLOBALS['Reque'] -> funpost("market_losecount");
		$market_statusval 		= $GLOBALS['Reque'] -> funpost("market_status");
		
		
		$market_regtimeval 	= time();
		
		if($market_nameval !='' and $market_emailval !='' and $market_telval !='' and $market_pinyinval !='' )
		{
			$sqlQuery = " SELECT count(1) as CNUM  FROM  market  WHERE market_name = '".$market_nameval."' ORDER BY `market_id` ";
			
			$info = $GLOBALS['MySql'] -> selectOne($sqlQuery);
			
			if( $info["CNUM"] < 1 )
			{
				
				$insertip ="INSERT INTO `market` (`market_name` , `market_pinyin` , `market_area` , `market_address` , `market_zip`, `market_tel` , `market_fax` , `market_website` , `market_email` , `market_licence` , `market_chieftain` , `market_bankroll` , `market_turnover`, `market_bank` , `market_bankaccount` , `market_localtaxno` , `market_nationaltaxno` , `market_managerid`, `market_level` , `market_satisfy` , `market_credit` , `market_losecount`  , `market_status` ) VALUES (  '$market_nameval', '$market_pinyinval', '$market_areaval', '$market_addressval', '$market_zipval', '$market_telval', '$market_faxval', '$market_websiteval', '$market_emailval', '$market_licenceval', '$market_chieftainval', '$market_bankrollval', '$market_turnoverval', '$market_bankval', '$market_bankaccountval', '$market_localtaxnoval', '$market_nationaltaxnoval', '$market_manageridval', '$market_levelval', '$market_satisfyval', '$market_creditval', '$market_losecountval', '$market_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/market/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/market/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/market/add/");
			$GLOBALS['Templ'] -> display('suggestion_tpl.html');		}
			//var_dump($_REQUEST);
	}
	
	function del( )
	{
		$indel = implode(',', $delArray);

		//$deletesql ="DELETE FROM `market` WHERE `market`.`market_id` in ( $indel ) and market_name != '".ADMIN_BASEUSER."' ";
		$deletesql ="UPDATE `market` SET  market_status = 5 WHERE `market`.`market_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/market/infolist/");
		$GLOBALS['Templ'] -> display('suggestion_tpl.html');
	}
	
	function info(  )
	{
		$infoid = $infoArray[0];
		
		$sqlQuery = " SELECT *  FROM  market  WHERE market_id = '".$infoid."' ORDER BY `market_id` ";
		$info = $GLOBALS['MySql'] -> selectOne($sqlQuery);
				
		$GLOBALS['Templ']->assign('actUrl',EMPLOYEE_WEBURL."/index.php/market/editinfo");
		$GLOBALS['Templ'] -> assign('info',$info);
		$GLOBALS['Templ'] -> display('marketedit_tpl.html');
	
	}
	
	
	function editinfo( )
	{	
	
		$market_idval 		= $GLOBALS['Reque'] -> funpost("market_id");
		$market_nameval 		= $GLOBALS['Reque'] -> funpost("market_name");
		$market_pinyinval 	= $GLOBALS['Reque'] -> funpost("market_pinyin");
		$market_areaval 		= $GLOBALS['Reque'] -> funpost("market_area");
		
		$market_addressval 	= $GLOBALS['Reque'] -> funpost("market_address");
		$market_zipval 		= $GLOBALS['Reque'] -> funpost("market_zip");
		$market_telval 		= $GLOBALS['Reque'] -> funpost("market_tel");
		$market_faxval 		= $GLOBALS['Reque'] -> funpost("market_fax");
		
		$market_websiteval 	= $GLOBALS['Reque'] -> funpost("market_website");
		$market_emailval 		= $GLOBALS['Reque'] -> funpost("market_email");
		$market_licenceval 	= $GLOBALS['Reque'] -> funpost("market_licence");
		$market_chieftainval 	= $GLOBALS['Reque'] -> funpost("market_chieftain");
		$market_bankrollval 	= $GLOBALS['Reque'] -> funpost("market_bankroll");
		$market_turnoverval 	= $GLOBALS['Reque'] -> funpost("market_turnover");
		$market_bankval 		= $GLOBALS['Reque'] -> funpost("market_bank");
		
		$market_bankaccountval 	= $GLOBALS['Reque'] -> funpost("market_bankaccount");
		$market_localtaxnoval 	= $GLOBALS['Reque'] -> funpost("market_localtaxno");
		$market_nationaltaxnoval 	= $GLOBALS['Reque'] -> funpost("market_nationaltaxno");
		$market_manageridval 		= $GLOBALS['Reque'] -> funpost("market_managerid");
		$market_levelval 			= $GLOBALS['Reque'] -> funpost("market_level");
		$market_satisfyval 		= $GLOBALS['Reque'] -> funpost("market_satisfy");
		$market_creditval 		= $GLOBALS['Reque'] -> funpost("market_credit");
		$market_losecountval 		= $GLOBALS['Reque'] -> funpost("market_losecount");
		$market_statusval 		= $GLOBALS['Reque'] -> funpost("market_status");
		
		
		$addsetUp = '';
		
		if($market_idval !='' and $market_nameval !='' )
		{

			
			$updatecus = "UPDATE `market` SET  market_name = '".$market_nameval."' , market_pinyin = '".$market_pinyinval."' 
			, market_area = '".$market_areaval."'
			, market_address = '".$market_addressval."'
			, market_zip = '".$market_zipval."'
			, market_tel = '".$market_telval."'
			, market_fax = '".$market_faxval."'
			, market_website = '".$market_websiteval."'
			, market_email = '".$market_emailval."'
			, market_licence = '".$market_licenceval."'
			, market_chieftain = '".$market_chieftainval."'
			, market_bankroll = '".$market_bankrollval."'
			, market_turnover = '".$market_turnoverval."'
			, market_bank = '".$market_bankval."'
			, market_bankaccount = '".$market_bankaccountval."'
			, market_localtaxno = '".$market_localtaxnoval."'
			, market_nationaltaxno = '".$market_nationaltaxnoval."'
			, market_managerid = '".$market_manageridval."'
			, market_level = '".$market_levelval."'
			, market_satisfy = '".$market_satisfyval."'
			, market_credit = '".$market_creditval."'
			, market_losecount = '".$market_losecountval."'
			, market_status = '".$market_statusval."'

			
			 WHERE  market_id = '".$market_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/market/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/market/info/".$market_idval);
			$GLOBALS['Templ'] -> display('suggestion_tpl.html');	
		}
		
	}
	
	

	
	
}

$Market = new Market();

?>