<?php
if (!defined('GV32_COM')) exit('GV32.COM No direct script access allowed');
class Plan
{
	function Plan()
	{
		//$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 plan_id, chance_id, plan_date, plan_item, plan_result  FROM  ".SQL_PREFIX."plan  WHERE 1 GROUP BY plan_id ORDER BY `plan_id` LIMIT  $LIMITnum , $pageSize ";
		
		$info = $GLOBALS['MySql'] -> selectInfo($sqlQuery);
		
		$sqlQuery = " SELECT count(1) as CNUM  FROM  ".SQL_PREFIX."plan  WHERE 1  ORDER BY `plan_id`  ";
		
		$infocount = $GLOBALS['MySql'] -> selectOne($sqlQuery);
		
		//var_dump($info);
		
		$PageStr = $GLOBALS['Page']->buildPageStr( $url = '?load=plan&act=infolist', $pageNum  , $pageSize  , $resultCount = $infocount["CNUM"] );
		
		
		$GLOBALS['Templ']->assign('PageStr',$PageStr);
		$GLOBALS['Templ']->assign('info',$info);
		$GLOBALS['Templ']->display('plan_tpl.html');
		
	}
	
	function add(  )
	{
		$GLOBALS['Templ'] -> caching = true;
		$GLOBALS['Templ'] -> cache_lifetime = 86400 ;  //60 *  60 * 24
		$GLOBALS['Templ']->assign('actUrl',EMPLOYEE_WEBURL."/index.php/plan/addinfo");
		$GLOBALS['Templ']->display('planadd_tpl.html');
	}

	
	function addinfo()
	{
		$plan_nameval 		= $GLOBALS['Reque'] -> funpost("plan_name");
		$plan_pinyinval 		= $GLOBALS['Reque'] -> funpost("plan_pinyin");
		$plan_areaval 		= $GLOBALS['Reque'] -> funpost("plan_area");
		
		$plan_addressval 	= $GLOBALS['Reque'] -> funpost("plan_address");
		$plan_zipval 		= $GLOBALS['Reque'] -> funpost("plan_zip");
		$plan_telval 		= $GLOBALS['Reque'] -> funpost("plan_tel");
		$plan_faxval 		= $GLOBALS['Reque'] -> funpost("plan_fax");
		
		$plan_websiteval 	= $GLOBALS['Reque'] -> funpost("plan_website");
		$plan_emailval 		= $GLOBALS['Reque'] -> funpost("plan_email");
		$plan_licenceval 	= $GLOBALS['Reque'] -> funpost("plan_licence");
		$plan_chieftainval 	= $GLOBALS['Reque'] -> funpost("plan_chieftain");
		$plan_bankrollval 	= $GLOBALS['Reque'] -> funpost("plan_bankroll");
		$plan_turnoverval 	= $GLOBALS['Reque'] -> funpost("plan_turnover");
		$plan_bankval 		= $GLOBALS['Reque'] -> funpost("plan_bank");
		
		$plan_bankaccountval 	= $GLOBALS['Reque'] -> funpost("plan_bankaccount");
		$plan_localtaxnoval 	= $GLOBALS['Reque'] -> funpost("plan_localtaxno");
		$plan_nationaltaxnoval 	= $GLOBALS['Reque'] -> funpost("plan_nationaltaxno");
		$plan_manageridval 		= $GLOBALS['Reque'] -> funpost("plan_managerid");
		$plan_levelval 			= $GLOBALS['Reque'] -> funpost("plan_level");
		$plan_satisfyval 		= $GLOBALS['Reque'] -> funpost("plan_satisfy");
		$plan_creditval 		= $GLOBALS['Reque'] -> funpost("plan_credit");
		$plan_losecountval 		= $GLOBALS['Reque'] -> funpost("plan_losecount");
		$plan_statusval 		= $GLOBALS['Reque'] -> funpost("plan_status");
		
		
		$plan_regtimeval 	= time();
		
		if($plan_nameval !='' and $plan_emailval !='' and $plan_telval !='' and $plan_pinyinval !='' )
		{
			$sqlQuery = " SELECT count(1) as CNUM  FROM  ".SQL_PREFIX."plan  WHERE plan_name = '".$plan_nameval."' ORDER BY `plan_id` ";
			
			$info = $GLOBALS['MySql'] -> selectOne($sqlQuery);
			
			if( $info["CNUM"] < 1 )
			{
				
				$insertip ="INSERT INTO `".SQL_PREFIX."plan` (`plan_name` , `plan_pinyin` , `plan_area` , `plan_address` , `plan_zip`, `plan_tel` , `plan_fax` , `plan_website` , `plan_email` , `plan_licence` , `plan_chieftain` , `plan_bankroll` , `plan_turnover`, `plan_bank` , `plan_bankaccount` , `plan_localtaxno` , `plan_nationaltaxno` , `plan_managerid`, `plan_level` , `plan_satisfy` , `plan_credit` , `plan_losecount`  , `plan_status` ) VALUES (  '$plan_nameval', '$plan_pinyinval', '$plan_areaval', '$plan_addressval', '$plan_zipval', '$plan_telval', '$plan_faxval', '$plan_websiteval', '$plan_emailval', '$plan_licenceval', '$plan_chieftainval', '$plan_bankrollval', '$plan_turnoverval', '$plan_bankval', '$plan_bankaccountval', '$plan_localtaxnoval', '$plan_nationaltaxnoval', '$plan_manageridval', '$plan_levelval', '$plan_satisfyval', '$plan_creditval', '$plan_losecountval', '$plan_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/plan/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/plan/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/plan/add/");
			$GLOBALS['Templ'] -> display('suggestion_tpl.html');		}
			//var_dump($_REQUEST);
	}
	
	function del( )
	{
		$indel = implode(',', $delArray);

		//$deletesql ="DELETE FROM `plan` WHERE `plan`.`plan_id` in ( $indel ) and plan_name != '".ADMIN_BASEUSER."' ";
		$deletesql ="UPDATE `".SQL_PREFIX."plan` SET  plan_status = 5 WHERE `plan`.`plan_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/plan/infolist/");
		$GLOBALS['Templ'] -> display('suggestion_tpl.html');
	}
	
	function info(  )
	{
		$infoid = $infoArray[0];
		
		$sqlQuery = " SELECT *  FROM  ".SQL_PREFIX."plan  WHERE plan_id = '".$infoid."' ORDER BY `plan_id` ";
		$info = $GLOBALS['MySql'] -> selectOne($sqlQuery);
				
		$GLOBALS['Templ']->assign('actUrl',EMPLOYEE_WEBURL."/index.php/plan/editinfo");
		$GLOBALS['Templ'] -> assign('info',$info);
		$GLOBALS['Templ'] -> display('planedit_tpl.html');
	
	}
	
	
	function editinfo( )
	{	
	
		$plan_idval 		= $GLOBALS['Reque'] -> funpost("plan_id");
		$plan_nameval 		= $GLOBALS['Reque'] -> funpost("plan_name");
		$plan_pinyinval 	= $GLOBALS['Reque'] -> funpost("plan_pinyin");
		$plan_areaval 		= $GLOBALS['Reque'] -> funpost("plan_area");
		
		$plan_addressval 	= $GLOBALS['Reque'] -> funpost("plan_address");
		$plan_zipval 		= $GLOBALS['Reque'] -> funpost("plan_zip");
		$plan_telval 		= $GLOBALS['Reque'] -> funpost("plan_tel");
		$plan_faxval 		= $GLOBALS['Reque'] -> funpost("plan_fax");
		
		$plan_websiteval 	= $GLOBALS['Reque'] -> funpost("plan_website");
		$plan_emailval 		= $GLOBALS['Reque'] -> funpost("plan_email");
		$plan_licenceval 	= $GLOBALS['Reque'] -> funpost("plan_licence");
		$plan_chieftainval 	= $GLOBALS['Reque'] -> funpost("plan_chieftain");
		$plan_bankrollval 	= $GLOBALS['Reque'] -> funpost("plan_bankroll");
		$plan_turnoverval 	= $GLOBALS['Reque'] -> funpost("plan_turnover");
		$plan_bankval 		= $GLOBALS['Reque'] -> funpost("plan_bank");
		
		$plan_bankaccountval 	= $GLOBALS['Reque'] -> funpost("plan_bankaccount");
		$plan_localtaxnoval 	= $GLOBALS['Reque'] -> funpost("plan_localtaxno");
		$plan_nationaltaxnoval 	= $GLOBALS['Reque'] -> funpost("plan_nationaltaxno");
		$plan_manageridval 		= $GLOBALS['Reque'] -> funpost("plan_managerid");
		$plan_levelval 			= $GLOBALS['Reque'] -> funpost("plan_level");
		$plan_satisfyval 		= $GLOBALS['Reque'] -> funpost("plan_satisfy");
		$plan_creditval 		= $GLOBALS['Reque'] -> funpost("plan_credit");
		$plan_losecountval 		= $GLOBALS['Reque'] -> funpost("plan_losecount");
		$plan_statusval 		= $GLOBALS['Reque'] -> funpost("plan_status");
		
		
		$addsetUp = '';
		
		if($plan_idval !='' and $plan_nameval !='' )
		{

			$updatecus = "UPDATE `".SQL_PREFIX."plan` SET  plan_name = '".$plan_nameval."' , plan_pinyin = '".$plan_pinyinval."' 
			, plan_area = '".$plan_areaval."'
			, plan_address = '".$plan_addressval."'
			, plan_zip = '".$plan_zipval."'
			, plan_tel = '".$plan_telval."'
			, plan_fax = '".$plan_faxval."'
			, plan_website = '".$plan_websiteval."'
			, plan_email = '".$plan_emailval."'
			, plan_licence = '".$plan_licenceval."'
			, plan_chieftain = '".$plan_chieftainval."'
			, plan_bankroll = '".$plan_bankrollval."'
			, plan_turnover = '".$plan_turnoverval."'
			, plan_bank = '".$plan_bankval."'
			, plan_bankaccount = '".$plan_bankaccountval."'
			, plan_localtaxno = '".$plan_localtaxnoval."'
			, plan_nationaltaxno = '".$plan_nationaltaxnoval."'
			, plan_managerid = '".$plan_manageridval."'
			, plan_level = '".$plan_levelval."'
			, plan_satisfy = '".$plan_satisfyval."'
			, plan_credit = '".$plan_creditval."'
			, plan_losecount = '".$plan_losecountval."'
			, plan_status = '".$plan_statusval."'			
			 WHERE  plan_id = '".$plan_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/plan/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/plan/info/".$plan_idval);
			$GLOBALS['Templ'] -> display('suggestion_tpl.html');	
		}
		
	}
	
	

	
	
}

$Plan = new Plan();

?>