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

	
	function addinfo()
	{
		$activity_nameval 		= $GLOBALS['Reque'] -> funpost("activity_name");
		$activity_pinyinval 		= $GLOBALS['Reque'] -> funpost("activity_pinyin");
		$activity_areaval 		= $GLOBALS['Reque'] -> funpost("activity_area");
		
		$activity_addressval 	= $GLOBALS['Reque'] -> funpost("activity_address");
		$activity_zipval 		= $GLOBALS['Reque'] -> funpost("activity_zip");
		$activity_telval 		= $GLOBALS['Reque'] -> funpost("activity_tel");
		$activity_faxval 		= $GLOBALS['Reque'] -> funpost("activity_fax");
		
		$activity_websiteval 	= $GLOBALS['Reque'] -> funpost("activity_website");
		$activity_emailval 		= $GLOBALS['Reque'] -> funpost("activity_email");
		$activity_licenceval 	= $GLOBALS['Reque'] -> funpost("activity_licence");
		$activity_chieftainval 	= $GLOBALS['Reque'] -> funpost("activity_chieftain");
		$activity_bankrollval 	= $GLOBALS['Reque'] -> funpost("activity_bankroll");
		$activity_turnoverval 	= $GLOBALS['Reque'] -> funpost("activity_turnover");
		$activity_bankval 		= $GLOBALS['Reque'] -> funpost("activity_bank");
		
		$activity_bankaccountval 	= $GLOBALS['Reque'] -> funpost("activity_bankaccount");
		$activity_localtaxnoval 	= $GLOBALS['Reque'] -> funpost("activity_localtaxno");
		$activity_nationaltaxnoval 	= $GLOBALS['Reque'] -> funpost("activity_nationaltaxno");
		$activity_manageridval 		= $GLOBALS['Reque'] -> funpost("activity_managerid");
		$activity_levelval 			= $GLOBALS['Reque'] -> funpost("activity_level");
		$activity_satisfyval 		= $GLOBALS['Reque'] -> funpost("activity_satisfy");
		$activity_creditval 		= $GLOBALS['Reque'] -> funpost("activity_credit");
		$activity_losecountval 		= $GLOBALS['Reque'] -> funpost("activity_losecount");
		$activity_statusval 		= $GLOBALS['Reque'] -> funpost("activity_status");
		
		
		$activity_regtimeval 	= time();
		
		if($activity_nameval !='' and $activity_emailval !='' and $activity_telval !='' and $activity_pinyinval !='' )
		{
			$sqlQuery = " SELECT count(1) as CNUM  FROM  ".SQL_PREFIX."activity  WHERE activity_name = '".$activity_nameval."' ORDER BY `activity_id` ";
			
			$info = $GLOBALS['MySql'] -> selectOne($sqlQuery);
			
			if( $info["CNUM"] < 1 )
			{
				
				$insertip ="INSERT INTO `".SQL_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')";

				$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/activity/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/activity/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/activity/add/");
			$GLOBALS['Templ'] -> display('suggestion_tpl.html');		}
			//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 `".SQL_PREFIX."activity` SET  activity_status = 5 WHERE `activity`.`activity_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/activity/infolist/");
		$GLOBALS['Templ'] -> display('suggestion_tpl.html');
	}
	
	function info(  )
	{
		$infoid = $infoArray[0];
		
		$sqlQuery = " SELECT *  FROM  ".SQL_PREFIX."activity  WHERE activity_id = '".$infoid."' ORDER BY `activity_id` ";
		$info = $GLOBALS['MySql'] -> selectOne($sqlQuery);
				
		$GLOBALS['Templ']->assign('actUrl',EMPLOYEE_WEBURL."/index.php/activity/editinfo");
		$GLOBALS['Templ'] -> assign('info',$info);
		$GLOBALS['Templ'] -> display('activityedit_tpl.html');
	
	}
	
	
	function editinfo( )
	{	
	
		$activity_idval 		= $GLOBALS['Reque'] -> funpost("activity_id");
		$activity_nameval 		= $GLOBALS['Reque'] -> funpost("activity_name");
		$activity_pinyinval 	= $GLOBALS['Reque'] -> funpost("activity_pinyin");
		$activity_areaval 		= $GLOBALS['Reque'] -> funpost("activity_area");
		
		$activity_addressval 	= $GLOBALS['Reque'] -> funpost("activity_address");
		$activity_zipval 		= $GLOBALS['Reque'] -> funpost("activity_zip");
		$activity_telval 		= $GLOBALS['Reque'] -> funpost("activity_tel");
		$activity_faxval 		= $GLOBALS['Reque'] -> funpost("activity_fax");
		
		$activity_websiteval 	= $GLOBALS['Reque'] -> funpost("activity_website");
		$activity_emailval 		= $GLOBALS['Reque'] -> funpost("activity_email");
		$activity_licenceval 	= $GLOBALS['Reque'] -> funpost("activity_licence");
		$activity_chieftainval 	= $GLOBALS['Reque'] -> funpost("activity_chieftain");
		$activity_bankrollval 	= $GLOBALS['Reque'] -> funpost("activity_bankroll");
		$activity_turnoverval 	= $GLOBALS['Reque'] -> funpost("activity_turnover");
		$activity_bankval 		= $GLOBALS['Reque'] -> funpost("activity_bank");
		
		$activity_bankaccountval 	= $GLOBALS['Reque'] -> funpost("activity_bankaccount");
		$activity_localtaxnoval 	= $GLOBALS['Reque'] -> funpost("activity_localtaxno");
		$activity_nationaltaxnoval 	= $GLOBALS['Reque'] -> funpost("activity_nationaltaxno");
		$activity_manageridval 		= $GLOBALS['Reque'] -> funpost("activity_managerid");
		$activity_levelval 			= $GLOBALS['Reque'] -> funpost("activity_level");
		$activity_satisfyval 		= $GLOBALS['Reque'] -> funpost("activity_satisfy");
		$activity_creditval 		= $GLOBALS['Reque'] -> funpost("activity_credit");
		$activity_losecountval 		= $GLOBALS['Reque'] -> funpost("activity_losecount");
		$activity_statusval 		= $GLOBALS['Reque'] -> funpost("activity_status");
		
		
		$addsetUp = '';
		
		if($activity_idval !='' and $activity_nameval !='' )
		{

			$updatecus = "UPDATE `".SQL_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."' ";
			
			$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/activity/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/activity/info/".$activity_idval);
			$GLOBALS['Templ'] -> display('suggestion_tpl.html');	
		}
		
	}
	
	

	
	
}

$Activity = new Activity();

?>