<?php
	define('thisscript','wallet');

	require_once "global.php";
	
	if (empty($userid)){
		redirecting('home');
	}
	
	require_once "class/User.php";
	$user = new User();
	
	$bonus = empty($userdetail['bonus_sharing']) ? 0 : number_format($userdetail['bonus_sharing'], 2, $decimalseparator, $thousandseparator);
	
 	/* sanitize post, get, request */
	$_POST['do'] = ((empty($_POST['do']))?"":$_POST['do']);
	$_POST['regpassword'] = ((empty($_POST['regpassword']))?"":$_POST['regpassword']);
	$_GET['page'] = ((empty($_GET['page']))?'':$_GET['page']);
	/* end sanitize */
  	 
	 	
 	$alls = $db->fetch_one("SELECT COUNT(history_id) as total FROM transaction_history WHERE transaction_type LIKE '%bonus%' AND userid = ".$db->clean($userid));
	$totalrows = $alls['total'];
	$totalpgs = ceil($totalrows / $general['showperpage']);
	
	$pgs = handlepage($_GET['page'],$totalpgs);
	
	$addlimit = '';
	if ($pgs > 0){
		$addlimit = ' LIMIT '.($pgs-1)*$general['showperpage'].','.$general['showperpage'];
	}
	
	$dblast = $db->fetch_all("SELECT * FROM transaction_history WHERE transaction_type LIKE '%bonus%' AND userid = ".$db->clean($userid)." ORDER BY transactiondate DESC".$addlimit);
	
	$pagenavs = generatepagelinkgeneral($pgs,$totalrows,$general['showperpage'],'wallet','','');
	
	$list = '';
	if (sizeof($dblast) > 0){
		foreach ($dblast as $result){
			$list .= '<tr>
						<td>'.$result['notes'].(stristr($result['transaction_type'], 'withdraw')?' ('.$result['transactionnumber'].' - '.date("d M Y", strtotime($result['transactiondate'])).')':'').'</td>
						<td align="right">'.(stristr($result['transaction_type'], 'withdraw')?'-':'$'.number_format($result['nominal'], 2, $decimalseparator, $thousandseparator)).'</td>
						<td align="right">'.(stristr($result['transaction_type'], 'withdraw')?'$'.number_format($result['nominal'], 2, $decimalseparator, $thousandseparator):'-').'</td>
					</tr>';
		}
	}
	else{
		$list = '<tr><td colspan="3" align="center">NO DATA</td></tr>';
	}
	
	require_once "incl/global_template.php";
	
	$tmpl = gettemplate('history');
	eval("\$template = \"$tmpl\";");
	echo $template;
?>