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

	
	function addinfo()
	{
		$linkman_nameval 		= $GLOBALS['Reque'] -> funpost("linkman_name");
		$linkman_pinyinval 		= $GLOBALS['Reque'] -> funpost("linkman_pinyin");
		$linkman_areaval 		= $GLOBALS['Reque'] -> funpost("linkman_area");
		
		$linkman_addressval 	= $GLOBALS['Reque'] -> funpost("linkman_address");
		$linkman_zipval 		= $GLOBALS['Reque'] -> funpost("linkman_zip");
		$linkman_telval 		= $GLOBALS['Reque'] -> funpost("linkman_tel");
		$linkman_faxval 		= $GLOBALS['Reque'] -> funpost("linkman_fax");
		
		$linkman_websiteval 	= $GLOBALS['Reque'] -> funpost("linkman_website");
		$linkman_emailval 		= $GLOBALS['Reque'] -> funpost("linkman_email");
		$linkman_licenceval 	= $GLOBALS['Reque'] -> funpost("linkman_licence");
		$linkman_chieftainval 	= $GLOBALS['Reque'] -> funpost("linkman_chieftain");
		$linkman_bankrollval 	= $GLOBALS['Reque'] -> funpost("linkman_bankroll");
		$linkman_turnoverval 	= $GLOBALS['Reque'] -> funpost("linkman_turnover");
		$linkman_bankval 		= $GLOBALS['Reque'] -> funpost("linkman_bank");
		
		$linkman_bankaccountval 	= $GLOBALS['Reque'] -> funpost("linkman_bankaccount");
		$linkman_localtaxnoval 	= $GLOBALS['Reque'] -> funpost("linkman_localtaxno");
		$linkman_nationaltaxnoval 	= $GLOBALS['Reque'] -> funpost("linkman_nationaltaxno");
		$linkman_manageridval 		= $GLOBALS['Reque'] -> funpost("linkman_managerid");
		$linkman_levelval 			= $GLOBALS['Reque'] -> funpost("linkman_level");
		$linkman_satisfyval 		= $GLOBALS['Reque'] -> funpost("linkman_satisfy");
		$linkman_creditval 		= $GLOBALS['Reque'] -> funpost("linkman_credit");
		$linkman_losecountval 		= $GLOBALS['Reque'] -> funpost("linkman_losecount");
		$linkman_statusval 		= $GLOBALS['Reque'] -> funpost("linkman_status");
		
		
		$linkman_regtimeval 	= time();
		
		if($linkman_nameval !='' and $linkman_emailval !='' and $linkman_telval !='' and $linkman_pinyinval !='' )
		{
			$sqlQuery = " SELECT count(1) as CNUM  FROM  linkman  WHERE linkman_name = '".$linkman_nameval."' ORDER BY `linkman_id` ";
			
			$info = $GLOBALS['MySql'] -> selectOne($sqlQuery);
			
			if( $info["CNUM"] < 1 )
			{
				
				$insertip ="INSERT INTO `linkman` (`linkman_name` , `linkman_pinyin` , `linkman_area` , `linkman_address` , `linkman_zip`, `linkman_tel` , `linkman_fax` , `linkman_website` , `linkman_email` , `linkman_licence` , `linkman_chieftain` , `linkman_bankroll` , `linkman_turnover`, `linkman_bank` , `linkman_bankaccount` , `linkman_localtaxno` , `linkman_nationaltaxno` , `linkman_managerid`, `linkman_level` , `linkman_satisfy` , `linkman_credit` , `linkman_losecount`  , `linkman_status` ) VALUES (  '$linkman_nameval', '$linkman_pinyinval', '$linkman_areaval', '$linkman_addressval', '$linkman_zipval', '$linkman_telval', '$linkman_faxval', '$linkman_websiteval', '$linkman_emailval', '$linkman_licenceval', '$linkman_chieftainval', '$linkman_bankrollval', '$linkman_turnoverval', '$linkman_bankval', '$linkman_bankaccountval', '$linkman_localtaxnoval', '$linkman_nationaltaxnoval', '$linkman_manageridval', '$linkman_levelval', '$linkman_satisfyval', '$linkman_creditval', '$linkman_losecountval', '$linkman_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/linkman/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/linkman/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/linkman/add/");
			$GLOBALS['Templ'] -> display('suggestion_tpl.html');		}
			//var_dump($_REQUEST);
	}
	
	function del( )
	{
		$indel = implode(',', $delArray);

		//$deletesql ="DELETE FROM `linkman` WHERE `linkman`.`linkman_id` in ( $indel ) and linkman_name != '".ADMIN_BASEUSER."' ";
		$deletesql ="UPDATE `linkman` SET  linkman_status = 5 WHERE `linkman`.`linkman_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/linkman/infolist/");
		$GLOBALS['Templ'] -> display('suggestion_tpl.html');
	}
	
	function info(  )
	{
		$infoid = $infoArray[0];
		
		$sqlQuery = " SELECT *  FROM  linkman  WHERE linkman_id = '".$infoid."' ORDER BY `linkman_id` ";
		$info = $GLOBALS['MySql'] -> selectOne($sqlQuery);
				
		$GLOBALS['Templ']->assign('actUrl',EMPLOYEE_WEBURL."/index.php/linkman/editinfo");
		$GLOBALS['Templ'] -> assign('info',$info);
		$GLOBALS['Templ'] -> display('linkmanedit_tpl.html');
	
	}
	
	
	function editinfo( )
	{	
	
		$linkman_idval 		= $GLOBALS['Reque'] -> funpost("linkman_id");
		$linkman_nameval 		= $GLOBALS['Reque'] -> funpost("linkman_name");
		$linkman_pinyinval 	= $GLOBALS['Reque'] -> funpost("linkman_pinyin");
		$linkman_areaval 		= $GLOBALS['Reque'] -> funpost("linkman_area");
		
		$linkman_addressval 	= $GLOBALS['Reque'] -> funpost("linkman_address");
		$linkman_zipval 		= $GLOBALS['Reque'] -> funpost("linkman_zip");
		$linkman_telval 		= $GLOBALS['Reque'] -> funpost("linkman_tel");
		$linkman_faxval 		= $GLOBALS['Reque'] -> funpost("linkman_fax");
		
		$linkman_websiteval 	= $GLOBALS['Reque'] -> funpost("linkman_website");
		$linkman_emailval 		= $GLOBALS['Reque'] -> funpost("linkman_email");
		$linkman_licenceval 	= $GLOBALS['Reque'] -> funpost("linkman_licence");
		$linkman_chieftainval 	= $GLOBALS['Reque'] -> funpost("linkman_chieftain");
		$linkman_bankrollval 	= $GLOBALS['Reque'] -> funpost("linkman_bankroll");
		$linkman_turnoverval 	= $GLOBALS['Reque'] -> funpost("linkman_turnover");
		$linkman_bankval 		= $GLOBALS['Reque'] -> funpost("linkman_bank");
		
		$linkman_bankaccountval 	= $GLOBALS['Reque'] -> funpost("linkman_bankaccount");
		$linkman_localtaxnoval 	= $GLOBALS['Reque'] -> funpost("linkman_localtaxno");
		$linkman_nationaltaxnoval 	= $GLOBALS['Reque'] -> funpost("linkman_nationaltaxno");
		$linkman_manageridval 		= $GLOBALS['Reque'] -> funpost("linkman_managerid");
		$linkman_levelval 			= $GLOBALS['Reque'] -> funpost("linkman_level");
		$linkman_satisfyval 		= $GLOBALS['Reque'] -> funpost("linkman_satisfy");
		$linkman_creditval 		= $GLOBALS['Reque'] -> funpost("linkman_credit");
		$linkman_losecountval 		= $GLOBALS['Reque'] -> funpost("linkman_losecount");
		$linkman_statusval 		= $GLOBALS['Reque'] -> funpost("linkman_status");
		
		
		$addsetUp = '';
		
		if($linkman_idval !='' and $linkman_nameval !='' )
		{

			$updatecus = "UPDATE `linkman` SET  linkman_name = '".$linkman_nameval."' , linkman_pinyin = '".$linkman_pinyinval."' 
			, linkman_area = '".$linkman_areaval."'
			, linkman_address = '".$linkman_addressval."'
			, linkman_zip = '".$linkman_zipval."'
			, linkman_tel = '".$linkman_telval."'
			, linkman_fax = '".$linkman_faxval."'
			, linkman_website = '".$linkman_websiteval."'
			, linkman_email = '".$linkman_emailval."'
			, linkman_licence = '".$linkman_licenceval."'
			, linkman_chieftain = '".$linkman_chieftainval."'
			, linkman_bankroll = '".$linkman_bankrollval."'
			, linkman_turnover = '".$linkman_turnoverval."'
			, linkman_bank = '".$linkman_bankval."'
			, linkman_bankaccount = '".$linkman_bankaccountval."'
			, linkman_localtaxno = '".$linkman_localtaxnoval."'
			, linkman_nationaltaxno = '".$linkman_nationaltaxnoval."'
			, linkman_managerid = '".$linkman_manageridval."'
			, linkman_level = '".$linkman_levelval."'
			, linkman_satisfy = '".$linkman_satisfyval."'
			, linkman_credit = '".$linkman_creditval."'
			, linkman_losecount = '".$linkman_losecountval."'
			, linkman_status = '".$linkman_statusval."'			
			 WHERE  linkman_id = '".$linkman_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/linkman/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/linkman/info/".$linkman_idval);
			$GLOBALS['Templ'] -> display('suggestion_tpl.html');	
		}
		
	}
	
	

	
	
}

$Linkman = new Linkman();

?>