<?php
!function_exists('readover') && exit('Forbidden');

/*
*
* ÐüÉÍ
*
*/
list($rw_valid,$rw_b_val,$rw_a_val,$rw_credit) = explode("\t",$forumset['rewarddb']);

empty($rw_valid) && $rw_valid = 10;
$rw_credit = explode(',',$rw_credit);

InitGP(array('bonus','ctype'),'P');
$bonus['best']   = (int)$bonus['best'];
$bonus['active'] = (int)$bonus['active'];
$bonus['best']   < $rw_b_val && Showmsg('credit_limit');
$bonus['active'] < $rw_a_val && Showmsg('credit_limit');

if (!in_array($ctype['best'],$rw_credit) || !in_array($ctype['active'],$rw_credit)) {
	Showmsg('reward_credit_error');
}
require_once(R_P.'require/credit.php');

$logdata = array(
	'uid'		=> $winduid,
	'username'	=> $windid,
	'ip'		=> $onlineip,
	'fname'		=> $forum[$fid]['name'],
	'cbtype'	=> $credit->cType[$ctype['best']],
	'cbval'		=> $bonus['best'],
	'catype'	=> $credit->cType[$ctype['active']],
	'caval'		=> $bonus['active']
);
if ($ctype['best'] == $ctype['active']) {
	$reduce = $bonus['best'] * 2 + $bonus['active'];
	$credit->get($winduid,$ctype['best']) < $reduce && Showmsg('reward_credit_limit');
	$credit->addLog('reward_'.$action,array($ctype['best'] => -$reduce),$logdata);
	$credit->set($winduid,$ctype['best'],-$reduce,false);
} else {
	foreach ($ctype as $key => $val) {
		$reduce = $bonus[$key] * ($key == 'best' ? 2 : 1);
		$credit->get($winduid,$val) < $reduce && Showmsg('reward_credit_limit');
		$credit->addLog('reward_'.$action,array($val => -$reduce),$logdata);
		$credit->set($winduid,$val,-$reduce,false);
	}
}
if ($action == 'new') {
	array_sum($bonus) < 1 && $special = 0;
	$timelimit = $timestamp + $rw_valid * 86400;
} else {
	$timelimit = ($rewdb['timelimit']>$timestamp ? $rewdb['timelimit'] : $timestamp) + $rw_valid*86400;
}
?>