<?php
define('THIS_SCRIPT', 'pay_boardlimited');
require_once 'global.php';
$lang = load_lang($lang, 'pay_boardlimited' );
$stats = $lang['title_num'];
$gettitle = $stats;
head();
PageLoad();
footer();
function PageLoad(){
	global $action,$lang,$dv,$db,$userid,$board_settings,$forum_setting,$vipgroupuser,$boardid,$fsetting;
	global $GetUserMoney,$GetUserTicket,$ChkPoint,$userinfo,$UseMondy,$UseTicket,$board_type,$membername,$paytimeout;
	$action=$_GET['action'];
	if($userid<=0){
		head();
		showmsg($lang['pay_limit.info1']);
		exit;
	}else{
		if($master==true){
			header("location:index.php?boardid={$boardid}");
		}
	}
	//head(1,0,0,$lang['title_num']);
	if($action=="subinfo"){
		subinfo();
	}
	else{
		main_sub();
	}
	require_once printout('pay_boardlimited');
}
function main_sub(){
	global $lang,$board_settings,$fsetting,$UseMondy,$UseTicket,$vipgroupuser,$userinfo;
	$UseMondy = $board_settings[39];
	$UseTicket = $board_settings[40];
	if($vipgroupuser===true){
		$UseMondy*=$board_settings[41];
		$UseTicket*=$board_settings[41];
	}
	$usermoney = $userinfo['usermoney'];
	$userticket = $userinfo['userticket'];
	eval("\$lang['pay_limit.info12']=\"{$lang['pay_limit.info12']}\";");
	eval("\$lang['pay_limit.info16']=\"{$lang['pay_limit.info16']}\";");
}
function subinfo(){
	global $lang,$GetUserMoney,$GetUserTicket,$vipgroupuser,$userinfo,$userid,$boardinfo,$board_type,$paytimeout,$membername,$board_settings,$db,$dv;
	$GetUserMoney =abs(floatval($board_settings[39]));
	$GetUserTicket =abs(floatval($board_settings[40]));
	$chkpoint = false;
	if($vipgroupuser===true){
		$GetUserMoney*=floatval($board_settings[41]);
		$GetUserTicket*=floatval($board_settings[41]);
	}
	if ( $GetUserTicket > 0 ){
		if ( $userinfo['userticket'] >= $GetUserTicket ){
			$chkpoint = true;
			$GetUserMoney = 0;
		}
	}
	if ( $GetUserMoney > 0 ){
		if ( $userinfo['usermoney'] >= $GetUserMoney ){
			$chkpoint = true;
			$GetUserTicket = 0;
		}
	}
	if( $chkpoint === false ){
		showmsg($lang['pay_limit.info3']);
	}else{
		$board_type = $boardinfo['boardtype'];
		$paytimeout = dateAdd('N',$board_settings[42], TIME_NOW+getUserTimeZoneOffset());
		add_super_boarduser($membername);
		$db->query("UPDATE {$dv}user SET usermoney=usermoney-".$GetUserMoney.",userticket=userticket-".$GetUserTicket." WHERE userid=".intval($userid)."");
	}
}
function add_super_boarduser($username){
	global $lang,$boardid,$_DCACHE,$db,$dv;
	$username=str_replace(",","",$username);
	$boardmaster = $db->scalar("Select boarduser From {$dv}board Where boardid=$boardid");
	if($boardmaster==''){
		$SuperBoardUser=$username."=".TIME_NOW;
	}
	else{
		$boardmaster=explode(",",$boardmaster);
		$num=count($boardmaster);
		for($i=0;$i<$num;$i++){
			$SuperBoardUser_List_A=explode("=",$boardmaster[$i]);
			if(trim(strtolower($SuperBoardUser_List_A[0]))<>trim(strtolower($username))){
				$SuperBoardUser.=$boardmaster[$i].",";
			}
		}
		if($SuperBoardUser<>""){
			$SuperBoardUser=substr($SuperBoardUser,0,-1);
			$SuperBoardUser.=",".$username."=".TIME_NOW;
		}else{
			$SuperBoardUser=$username."=".TIME_NOW;
		}
	}
	$db->query("UPDATE {$dv}board SET boarduser='".str_replace("'","",$SuperBoardUser)."' WHERE boardid=".intval($boardid)."");
}
?>