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

	
	function add_info()
	{
		$activity_nameval 		= $this -> input ->  funpost("activity_name");
		$activity_pinyinval 		= $this -> input ->  funpost("activity_pinyin");
		$activity_areaval 		= $this -> input ->  funpost("activity_area");
		
		$activity_addressval 	= $this -> input ->  funpost("activity_address");
		$activity_zipval 		= $this -> input ->  funpost("activity_zip");
		$activity_telval 		= $this -> input ->  funpost("activity_tel");
		$activity_faxval 		= $this -> input ->  funpost("activity_fax");
		
		$activity_websiteval 	= $this -> input ->  funpost("activity_website");
		$activity_emailval 		= $this -> input ->  funpost("activity_email");
		$activity_licenceval 	= $this -> input ->  funpost("activity_licence");
		$activity_chieftainval 	= $this -> input ->  funpost("activity_chieftain");
		$activity_bankrollval 	= $this -> input ->  funpost("activity_bankroll");
		$activity_turnoverval 	= $this -> input ->  funpost("activity_turnover");
		$activity_bankval 		= $this -> input ->  funpost("activity_bank");
		
		$activity_bankaccountval 	= $this -> input ->  funpost("activity_bankaccount");
		$activity_localtaxnoval 	= $this -> input ->  funpost("activity_localtaxno");
		$activity_nationaltaxnoval 	= $this -> input ->  funpost("activity_nationaltaxno");
		$activity_manageridval 		= $this -> input ->  funpost("activity_managerid");
		$activity_levelval 			= $this -> input ->  funpost("activity_level");
		$activity_satisfyval 		= $this -> input ->  funpost("activity_satisfy");
		$activity_creditval 		= $this -> input ->  funpost("activity_credit");
		$activity_losecountval 		= $this -> input ->  funpost("activity_losecount");
		$activity_statusval 		= $this -> input ->  funpost("activity_status");
		
		
		$activity_regtimeval 	= time();
		
		if($activity_nameval !='' and $activity_emailval !='' and $activity_telval !='' and $activity_pinyinval !='' )
		{
			$sql_query = " SELECT count(1) as CNUM  FROM  ".$this -> db -> prefix."activity  WHERE activity_name = '".$activity_nameval."' ORDER BY `activity_id` ";
			
			$info = $this -> db -> select_one($sql_query);
			
			if( $info["CNUM"] < 1 )
			{
				
				$insertip ="INSERT INTO `".$this -> db -> prefix."activity` (`activity_name` , `activity_pinyin` , `activity_area` , `activity_address` , `activity_zip`, `activity_tel` , `activity_fax` , `activity_website` , `activity_email` , `activity_licence` , `activity_chieftain` , `activity_bankroll` , `activity_turnover`, `activity_bank` , `activity_bankaccount` , `activity_localtaxno` , `activity_nationaltaxno` , `activity_managerid`, `activity_level` , `activity_satisfy` , `activity_credit` , `activity_losecount`  , `activity_status` ) VALUES (  '$activity_nameval', '$activity_pinyinval', '$activity_areaval', '$activity_addressval', '$activity_zipval', '$activity_telval', '$activity_faxval', '$activity_websiteval', '$activity_emailval', '$activity_licenceval', '$activity_chieftainval', '$activity_bankrollval', '$activity_turnoverval', '$activity_bankval', '$activity_bankaccountval', '$activity_localtaxnoval', '$activity_nationaltaxnoval', '$activity_manageridval', '$activity_levelval', '$activity_satisfyval', '$activity_creditval', '$activity_losecountval', '$activity_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?/activity/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?/activity/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?/activity/add/");
			$this -> view ->  display('suggestion.tpl');		}
			//var_dump($_REQUEST);
	}
	
	function del( )
	{
		$indel = implode(',', $delArray);

		//$deletesql ="DELETE FROM `activity` WHERE `activity`.`activity_id` in ( $indel ) and activity_name != '".ADMIN_BASEUSER."' ";
		$deletesql ="UPDATE `".$this -> db -> prefix."activity` SET  activity_status = 5 WHERE `activity`.`activity_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?/activity/info_list/");
		$this -> view ->  display('suggestion.tpl');
	}
	
	function info(  )
	{
		$infoid = $infoArray[0];
		
		$sql_query = " SELECT *  FROM  ".$this -> db -> prefix."activity  WHERE activity_id = '".$infoid."' ORDER BY `activity_id` ";
		$info = $this -> db -> select_one($sql_query);
				
		$this -> view -> assign('act_url',ADMIN_WEBURL."/index.php?/activity/edit_info");
		$this -> view ->  assign('info',$info);
		$this -> view ->  display('activityedit.tpl');
	
	}
	
	
	function edit_info( )
	{	
	
		$activity_idval 		= $this -> input ->  funpost("activity_id");
		$activity_nameval 		= $this -> input ->  funpost("activity_name");
		$activity_pinyinval 	= $this -> input ->  funpost("activity_pinyin");
		$activity_areaval 		= $this -> input ->  funpost("activity_area");
		
		$activity_addressval 	= $this -> input ->  funpost("activity_address");
		$activity_zipval 		= $this -> input ->  funpost("activity_zip");
		$activity_telval 		= $this -> input ->  funpost("activity_tel");
		$activity_faxval 		= $this -> input ->  funpost("activity_fax");
		
		$activity_websiteval 	= $this -> input ->  funpost("activity_website");
		$activity_emailval 		= $this -> input ->  funpost("activity_email");
		$activity_licenceval 	= $this -> input ->  funpost("activity_licence");
		$activity_chieftainval 	= $this -> input ->  funpost("activity_chieftain");
		$activity_bankrollval 	= $this -> input ->  funpost("activity_bankroll");
		$activity_turnoverval 	= $this -> input ->  funpost("activity_turnover");
		$activity_bankval 		= $this -> input ->  funpost("activity_bank");
		
		$activity_bankaccountval 	= $this -> input ->  funpost("activity_bankaccount");
		$activity_localtaxnoval 	= $this -> input ->  funpost("activity_localtaxno");
		$activity_nationaltaxnoval 	= $this -> input ->  funpost("activity_nationaltaxno");
		$activity_manageridval 		= $this -> input ->  funpost("activity_managerid");
		$activity_levelval 			= $this -> input ->  funpost("activity_level");
		$activity_satisfyval 		= $this -> input ->  funpost("activity_satisfy");
		$activity_creditval 		= $this -> input ->  funpost("activity_credit");
		$activity_losecountval 		= $this -> input ->  funpost("activity_losecount");
		$activity_statusval 		= $this -> input ->  funpost("activity_status");
		
		
		$addsetUp = '';
		
		if($activity_idval !='' and $activity_nameval !='' )
		{

			$updatecus = "UPDATE `".$this -> db -> prefix."activity` SET  activity_name = '".$activity_nameval."' , activity_pinyin = '".$activity_pinyinval."' 
			, activity_area = '".$activity_areaval."'
			, activity_address = '".$activity_addressval."'
			, activity_zip = '".$activity_zipval."'
			, activity_tel = '".$activity_telval."'
			, activity_fax = '".$activity_faxval."'
			, activity_website = '".$activity_websiteval."'
			, activity_email = '".$activity_emailval."'
			, activity_licence = '".$activity_licenceval."'
			, activity_chieftain = '".$activity_chieftainval."'
			, activity_bankroll = '".$activity_bankrollval."'
			, activity_turnover = '".$activity_turnoverval."'
			, activity_bank = '".$activity_bankval."'
			, activity_bankaccount = '".$activity_bankaccountval."'
			, activity_localtaxno = '".$activity_localtaxnoval."'
			, activity_nationaltaxno = '".$activity_nationaltaxnoval."'
			, activity_managerid = '".$activity_manageridval."'
			, activity_level = '".$activity_levelval."'
			, activity_satisfy = '".$activity_satisfyval."'
			, activity_credit = '".$activity_creditval."'
			, activity_losecount = '".$activity_losecountval."'
			, activity_status = '".$activity_statusval."'			
			 WHERE  activity_id = '".$activity_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?/activity/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?/activity/info/".$activity_idval);
			$this -> view ->  display('suggestion.tpl');	
		}
		
	}
	
	

	
	
}

$Activity = new Activity();

?>