<?php
if (!defined('HUCART_COM')) exit('HuCart.COM No direct script access allowed');
class Plan
{
	function Plan()
	{
		//$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 plan_id, chance_id, plan_date, plan_item, plan_result  FROM  ".$this -> db -> prefix."plan  WHERE 1 GROUP BY plan_id ORDER BY `plan_id` LIMIT  $limit_num , $page_size ";
		
		$info = $this -> db -> select_info($sql_query);
		
		$sql_query = " SELECT count(1) as CNUM  FROM  ".$this -> db -> prefix."plan  WHERE 1  ORDER BY `plan_id`  ";
		
		$infocount = $this -> db -> select_one($sql_query);
		
		//var_dump($info);
		
		$page_str = $this -> page ->get_admin_page( $url = '?load=plan&act=info_list', $page_num  , $page_size  , $result_count = $infocount["CNUM"] );
		
		
		$this -> view -> assign('page_str',$page_str);
		$this -> view -> assign('info',$info);
		$this -> view -> display('plan.tpl');
		
	}
	
	function add(  )
	{
		$this -> view ->  caching = true;
		$this -> view ->  cache_lifetime = 86400 ;  //60 *  60 * 24
		$this -> view -> assign('act_url',ADMIN_WEBURL."/index.php?/plan/add_info");
		$this -> view -> display('planadd.tpl');
	}

	
	function add_info()
	{
		$plan_nameval 		= $this -> input ->  funpost("plan_name");
		$plan_pinyinval 		= $this -> input ->  funpost("plan_pinyin");
		$plan_areaval 		= $this -> input ->  funpost("plan_area");
		
		$plan_addressval 	= $this -> input ->  funpost("plan_address");
		$plan_zipval 		= $this -> input ->  funpost("plan_zip");
		$plan_telval 		= $this -> input ->  funpost("plan_tel");
		$plan_faxval 		= $this -> input ->  funpost("plan_fax");
		
		$plan_websiteval 	= $this -> input ->  funpost("plan_website");
		$plan_emailval 		= $this -> input ->  funpost("plan_email");
		$plan_licenceval 	= $this -> input ->  funpost("plan_licence");
		$plan_chieftainval 	= $this -> input ->  funpost("plan_chieftain");
		$plan_bankrollval 	= $this -> input ->  funpost("plan_bankroll");
		$plan_turnoverval 	= $this -> input ->  funpost("plan_turnover");
		$plan_bankval 		= $this -> input ->  funpost("plan_bank");
		
		$plan_bankaccountval 	= $this -> input ->  funpost("plan_bankaccount");
		$plan_localtaxnoval 	= $this -> input ->  funpost("plan_localtaxno");
		$plan_nationaltaxnoval 	= $this -> input ->  funpost("plan_nationaltaxno");
		$plan_manageridval 		= $this -> input ->  funpost("plan_managerid");
		$plan_levelval 			= $this -> input ->  funpost("plan_level");
		$plan_satisfyval 		= $this -> input ->  funpost("plan_satisfy");
		$plan_creditval 		= $this -> input ->  funpost("plan_credit");
		$plan_losecountval 		= $this -> input ->  funpost("plan_losecount");
		$plan_statusval 		= $this -> input ->  funpost("plan_status");
		
		
		$plan_regtimeval 	= time();
		
		if($plan_nameval !='' and $plan_emailval !='' and $plan_telval !='' and $plan_pinyinval !='' )
		{
			$sql_query = " SELECT count(1) as CNUM  FROM  ".$this -> db -> prefix."plan  WHERE plan_name = '".$plan_nameval."' ORDER BY `plan_id` ";
			
			$info = $this -> db -> select_one($sql_query);
			
			if( $info["CNUM"] < 1 )
			{
				
				$insertip ="INSERT INTO `".$this -> db -> 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')";

				$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?/plan/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?/plan/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?/plan/add/");
			$this -> view ->  display('suggestion.tpl');		}
			//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 `".$this -> db -> prefix."plan` SET  plan_status = 5 WHERE `plan`.`plan_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?/plan/info_list/");
		$this -> view ->  display('suggestion.tpl');
	}
	
	function info(  )
	{
		$infoid = $infoArray[0];
		
		$sql_query = " SELECT *  FROM  ".$this -> db -> prefix."plan  WHERE plan_id = '".$infoid."' ORDER BY `plan_id` ";
		$info = $this -> db -> select_one($sql_query);
				
		$this -> view -> assign('act_url',ADMIN_WEBURL."/index.php?/plan/edit_info");
		$this -> view ->  assign('info',$info);
		$this -> view ->  display('planedit.tpl');
	
	}
	
	
	function edit_info( )
	{	
	
		$plan_idval 		= $this -> input ->  funpost("plan_id");
		$plan_nameval 		= $this -> input ->  funpost("plan_name");
		$plan_pinyinval 	= $this -> input ->  funpost("plan_pinyin");
		$plan_areaval 		= $this -> input ->  funpost("plan_area");
		
		$plan_addressval 	= $this -> input ->  funpost("plan_address");
		$plan_zipval 		= $this -> input ->  funpost("plan_zip");
		$plan_telval 		= $this -> input ->  funpost("plan_tel");
		$plan_faxval 		= $this -> input ->  funpost("plan_fax");
		
		$plan_websiteval 	= $this -> input ->  funpost("plan_website");
		$plan_emailval 		= $this -> input ->  funpost("plan_email");
		$plan_licenceval 	= $this -> input ->  funpost("plan_licence");
		$plan_chieftainval 	= $this -> input ->  funpost("plan_chieftain");
		$plan_bankrollval 	= $this -> input ->  funpost("plan_bankroll");
		$plan_turnoverval 	= $this -> input ->  funpost("plan_turnover");
		$plan_bankval 		= $this -> input ->  funpost("plan_bank");
		
		$plan_bankaccountval 	= $this -> input ->  funpost("plan_bankaccount");
		$plan_localtaxnoval 	= $this -> input ->  funpost("plan_localtaxno");
		$plan_nationaltaxnoval 	= $this -> input ->  funpost("plan_nationaltaxno");
		$plan_manageridval 		= $this -> input ->  funpost("plan_managerid");
		$plan_levelval 			= $this -> input ->  funpost("plan_level");
		$plan_satisfyval 		= $this -> input ->  funpost("plan_satisfy");
		$plan_creditval 		= $this -> input ->  funpost("plan_credit");
		$plan_losecountval 		= $this -> input ->  funpost("plan_losecount");
		$plan_statusval 		= $this -> input ->  funpost("plan_status");
		
		
		$addsetUp = '';
		
		if($plan_idval !='' and $plan_nameval !='' )
		{

			$updatecus = "UPDATE `".$this -> db -> 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."' ";
			
			$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?/plan/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?/plan/info/".$plan_idval);
			$this -> view ->  display('suggestion.tpl');	
		}
		
	}
	
	

	
	
}

$Plan = new Plan();

?>