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

	require_once 'globalad.php';	
	require_once '../class/Deposit.php';	
	$deposit = new Deposit();
	
	if (empty($userid)){
		redirecting("index.php");
	}
	
	if (empty($useraccess['manage_deposit'])){
		redirecting('index.php');
	}
	
	/* sanitize post, get, request */
	$_POST['replayedit'] = ((empty($_POST['replayedit']))?"":$_POST['replayedit']);
	$_GET['getlist'] = ((empty($_GET['getlist']))?"":$_GET['getlist']);
	$_GET['keyword'] = ((empty($_GET['keyword']))?array():$_GET['keyword']);
	$_GET['field'] = ((empty($_GET['field']))?array():$_GET['field']);
	$_POST['cek'] = ((empty($_POST['cek']))?array():$_POST['cek']);
	$_POST['does'] = ((empty($_POST['does']))?"":$_POST['does']);
	$_GET['error'] = ((empty($_GET['error']))?"":$_GET['error']);		
	$_GET['actions'] = ((empty($_GET['actions']))?"":$_GET['actions']);
	/* end sanitize */
	
	if (empty($general['showperpageadmin'])){
		$general['showperpageadmin'] = 20;
	}
	
	$pagelink = '';
	$listr = '';
	$listaction = '';
	
	if ($_GET['getlist'] == 'pagenav'){
		$keywords = $_GET['keyword'];
		$fields = $_GET['field'];
		$alls = $deposit->searchDeposit($keywords,$fields,'','','pagenav',$_GET['p']);
		echo $alls;
		exit;
	}
	else if ($_GET['getlist'] == 'ajax'){
		$keywords = $_GET['keyword'];
		$fields = $_GET['field'];
		$alls = $deposit->searchDeposit($keywords,$fields,'','','data');
		$totalrows = sizeof($alls);
		$totalpgs = ceil($totalrows / $general['showperpageadmin']);
		$pgs = handlepage($_GET['p'],$totalpgs);
		$dblast = $deposit->searchDeposit($keywords,$fields,$_GET['sortf'],$_GET['sortd'],'data',$pgs);
		$listtr = '';

		if (sizeof($dblast) > 0){
			foreach ($dblast as $result){
				$cstatus = '';
				switch ($result['status']){
					case '1' : $cstatus = 'Pending'; break;
					case '2' : $cstatus = 'Success'; break;		
					case '3' : $cstatus = 'Reject'; break;
				}	

 				$listr .= '
				<tr ondblclick="window.open(\'admindepositdetail.php?deposit_id='.$result['deposit_id'].'\',\'_self\')">
					<td height="25" align="left">
					<a href="admindepositdetail.php?deposit_id='.$result['deposit_id'].'">'.htmlspecialchars($result['transaction_number']).'</a></td>
					<td height="25" align="left">
					<a href="adminuserlistdetail.php?id='.$result['userid'].'">'.htmlspecialchars($result['email']).'</a></td>
					<td height="25" align="left">
					'.htmlspecialchars($result['firstname'].' '.$result['lastname']).'</td>
					<td height="25" align="center">
					'.$deposit_type[$result['type']].'</td>
 					<td height="25" align="center">
					'.date('d-m-Y', strtotime($result['date'])).'</td>
 					<td height="25" align="right">
					'.number_format($result['amount'], 2, $decimalseparator,$thousandseparator).'</td>
 					<td height="25" align="center">
					'.htmlspecialchars($cstatus).'</td>							
				</tr>
			';
			}
 		}
		else{
			$listr = '<tr><td colspan="7" align="center">NO DATA</td></tr>';
		}
			
		echo $listr;
		exit;
	}
	
	/* $listaction = '
		<div align="right">
			With selected : 
			<select name="replayedit" style="text-align: right">
			<option value="2">Aktif di Website</option>
			<option value="3">Tidak Aktif di Website</option>
			<option value="4">Hapus Bank</option>		
			</select>&nbsp;&nbsp;<input type="submit" value="Go" class="btn btn-success btn-sm"></div><br>
		  '; */
	
	/* $menu = $_POST['replayedit'];
	if ($menu == 2){
		$alldep = $_POST['cek'];
		$sizealldep = sizeof($alldep);
		if ($sizealldep > 0){
			for ($ax = 0; $ax < $sizealldep; $ax++){
				 $db->query("UPDATE bank SET status=1 WHERE account_id ='".$alldep[$ax]."'");
			}
		}
	}
 	else if ($menu == 3){
		$alldep = $_POST['cek'];
		$sizealldep = sizeof($alldep);
		if ($sizealldep > 0){
			for ($ax = 0; $ax < $sizealldep; $ax++){
				 $db->query("UPDATE bank SET status=2 WHERE account_id='".$alldep[$ax]."'");
			}
		}
	}
	else if ($menu ==4){
		$alldep = $_POST['cek'];
		$sizealldep = sizeof($alldep);
		if ($sizealldep > 0){
			for ($ax = 0; $ax < $sizealldep; $ax++){
				$deposit->setId($alldep[$ax]);
				$deposit->deleteBank();
			}
		}
	} */
	
	$deposit_type_list = '';
	if(sizeof($deposit_type) > 0){
		foreach($deposit_type as $key => $value){
			$deposit_type_list .= '<option value="'.$key.'">'.$value.'</option>';
		}
	}
 
	require_once 'incl/global_template.php';
		
	$theme = gettemplate('admindeposit');
	eval("\$theme = \"$theme\";");
	echo $theme;
?>