<?php
if (!defined("root")) {
	define("root", $_SERVER['DOCUMENT_ROOT']);
}
ob_start();
require(root."/___simple_config.php");
session_start();
require(root."/".adminFolder."/_common.php");
require(root."/".adminFolder."/_lib/db.php");
require(root."/".adminFolder."/_lib/main.php");
require(root."/".adminFolder."/PHPMailer/PHPMailerAutoload.php");
require(root."/".adminFolder."/_lib/bacasbo.php");
require(root."/".adminFolder."/_lib/mail.php");
require(root."/".adminFolder."/_lib/auth.php");
require(root."/".adminFolder."/_lib/bootstraps.php");
$pageSubOf = "pages";
$pageName = "members";
$pageTitle = "Members";
$thisUrl = "members";
$ajax_page = "ajax_members.php";
$pageUrl = "/".adminFolder."/$thisUrl";
$a = cekpost(cleanQuery($_GET["a"]), "");
$err = "";
if ($a=="section_main") {
	if (!authorizedModule("members_main", $ses_kduser)) {
		unAuthorizedAccess("members_main");
	} else {
		$fil_username = trim(cekpost(cleanQuery($_REQUEST["fil_username"]), ""));
		$fil_kdbank = trim(cekpost(cleanQuery($_REQUEST["fil_kdbank"]), ""));
		$fil_kdgame = trim(cekpost(cleanQuery($_REQUEST["fil_kdgame"]), ""));
		$fil_norek = trim(cekpost(cleanQuery($_REQUEST["fil_norek"]), ""));
		$fil_namarek = trim(cekpost(cleanQuery($_REQUEST["fil_namarek"]), ""));
		$fil_email = trim(cekpost(cleanQuery($_REQUEST["fil_email"]), ""));
		$fil_telp = trim(cekpost(cleanQuery($_REQUEST["fil_telp"]), ""));
		$fil_isactive = trim(cekpost(cleanQuery($_REQUEST["fil_isactive"]), ""));
		$fil_assign = trim(cekpost(cleanQuery($_REQUEST["fil_assign"]), ""));
		$fil_sort = trim(cekpost(cleanQuery($_REQUEST["fil_sort"]), ""));
		$swhere = '';
		$sorder = '';
		if ($fil_kdbank!="") { $swhere .= " AND a.kdbank='$fil_kdbank' "; }
		if ($fil_kdgame!="") { $swhere .= " AND a.kdgame='$fil_kdgame' "; }
		if ($fil_username!="") { $swhere .= " AND c.username LIKE '%$fil_username%' "; }
		if ($fil_norek!="") { $swhere .= " AND a.norek LIKE '%$fil_norek%' "; }
		if ($fil_namarek!="") { $swhere .= " AND a.namarek LIKE '%$fil_namarek%' "; }
		if ($fil_email!="") { $swhere .= " AND a.email LIKE '%$fil_email%' "; }
		if ($fil_assign!="0") {
			if ($fil_assign==1) { $swhere .= " AND a.kdaccount='0'"; }
			if ($fil_assign==2) { $swhere .= " AND a.kdaccount!='0'"; }
		}
		if ($fil_isactive!="0") {
			if ($fil_isactive==1) { $swhere .= " AND a.isactive='1'"; }
			if ($fil_isactive==2) { $swhere .= " AND a.isactive='0'"; }
		}
		if ($fil_telp!="") { $swhere .= " AND a.telp LIKE '%$fil_telp%' "; }
		if ($fil_sort!="0") {
			if ($fil_sort==1) { $sorder .= " ORDER BY tdp.totaldp DESC"; }
			if ($fil_sort==2) { $sorder .= " ORDER BY twd.totalwd DESC"; }
			if ($fil_sort==3) { $sorder .= " ORDER BY tdp.totaldp"; }
			if ($fil_sort==4) { $sorder .= " ORDER BY twd.totalwd"; }
		} else {
			$sorder .= " ORDER BY tanggal_daftar DESC";
		}
		$rs=array();
		$q="SELECT a.*,namabank, b.inisial, username, d.nama AS nama_game, COALESCE(depo.jdepo,0) AS jdepox, COALESCE(wd.jwd,0) AS jwdx, COALESCE(tdp.totaldp,0) AS tdpx, COALESCE(twd.totalwd,0) AS twdx
			FROM members a 
			LEFT JOIN banks b ON b.kdbank=a.kdbank
			LEFT JOIN accounts c ON c.kdaccount=a.kdaccount
			LEFT JOIN games d ON d.kdgame=a.kdgame
			LEFT JOIN (
				SELECT COUNT(kddeposit) AS jdepo, kdmember FROM deposits WHERE isclear=1
				GROUP BY kdmember
			) AS depo ON depo.kdmember = a.kdmember
			LEFT JOIN (
				SELECT COUNT(kdwithdraw) AS jwd, kdmember FROM withdraws WHERE isclear=1
				GROUP BY kdmember
			) AS wd ON wd.kdmember = a.kdmember
			LEFT JOIN (
				SELECT SUM(jumlah) AS totaldp, kdmember FROM deposits WHERE isclear=1
				GROUP BY kdmember
			) AS tdp ON tdp.kdmember = a.kdmember
			LEFT JOIN (
				SELECT SUM(jumlah) AS totalwd, kdmember FROM withdraws WHERE isclear=1
				GROUP BY kdmember
			) AS twd ON twd.kdmember = a.kdmember
			WHERE 1=1 AND isdeleted=0
			$swhere
			$sorder
			";
		callRS($rs, $q);
		if (count($rs)!=0) {
			$ld = 15;
			$cp = cekpost(cleanQuery($_GET["cp"]), "1");
			$tp = intval(count($rs) / $ld) + (count($rs)%$ld==0?0:1);
			$sr = ($cp-1) * $ld;
			$pagination = '';
			if ($tp!=1) {
				$pagination .= ('<ul class="pagination pagination-sm">');
					$disabled = '';
					$purl = '#';
					$onclick = '';
					if ($cp<=1) {
						$disabled = 'disabled';
						$onclick = ' onclick="return false;" ';
					}
					$pagination .= ('<li class="'.$disabled.'"><a href="'.$purl.'" '.($onclick!=""?$onclick:'onclick="filterReload(\''.$pageName.'\', 1);return false;"').'>&lt;&lt;</a></li>');
					$pagination .= ('<li class="'.$disabled.'"><a href="'.$purl.'" '.($onclick!=""?$onclick:'onclick="filterReload(\''.$pageName.'\', '.($cp-1).');return false;"').'>&lt;</a></li>');
					for ($c=1;$c<=$tp;$c++) {
						$active = '';
						$purl = '#';
						$disabled = '';
						$onclick = '';
						if ($c==$cp) {
							$active = 'active';
						} else {
							$purl = '#';
							$onclick = ' onclick="filterReload(\''.$pageName.'\', '.$c.');return false;" ';
						}
						$pagination .= ('<li class="'.$active.' '.$disabled.'"><a href="'.$purl.'" '.$onclick.'>'.$c.'</a></li>');
					}
					$disabled = '';
					$onclick = '';
					if ($cp>=$tp) {
						$disabled = 'disabled';
						$onclick = ' onclick="return false;" ';
					}
					$pagination .= ('<li class="'.$disabled.'"><a href="#" '.($onclick!=""?$onclick:'onclick="filterReload(\''.$pageName.'\', '.($cp+1).');return false;"').'>&gt;</a></li>');
					$pagination .= ('<li class="'.$disabled.'"><a href="#" '.($onclick!=""?$onclick:'onclick="filterReload(\''.$pageName.'\', '.$tp.');return false;"').'>&gt;&gt;</a></li>');
				$pagination .= ('</ul>');
			}
			cout('<div class="alert alert-info" role="alert"><strong>Total whole data</strong> <span class="badge">'.count($rs).'</span></div>');
			
			if ($tp!=1) {
				cout($pagination);
			}
			cout('<table class="table table-striped table-bordered">');
				cout('<thead>');
					cout('<tr>');
						cout('<th class="text-center">#</th>');
						if (authorizedModule("members_element_games", $ses_kduser)) {
							cout('<th class="text-center">Games</th>');
						}
						if (authorizedModule("members_element_username", $ses_kduser)) {
							cout('<th class="text-center">Username</th>');
						}
						if (authorizedModule("members_element_banks", $ses_kduser)) {
							cout('<th class="text-center">Bank</th>');
						}
						if (authorizedModule("members_element_bank_account_number", $ses_kduser)) {
							cout('<th class="text-center">No. Rek.</th>');
						}
						if (authorizedModule("members_element_bank_account_holder", $ses_kduser)) {
							cout('<th class="text-center">Nama Rek.</th>');
						}
						if (authorizedModule("members_element_email", $ses_kduser)) {
							cout('<th class="text-center">Email</th>');
						}
						if (authorizedModule("members_element_phone", $ses_kduser)) {
							cout('<th class="text-center">Telp</th>');
						}
						if (authorizedModule("members_element_registration_time", $ses_kduser)) {
							cout('<th class="text-center">Reg Date</th>');
						}
						if (authorizedModule("members_element_active", $ses_kduser)) {
							cout('<th class="text-center">Active?</th>');
						}
						cout('<th class="text-center"><input type="button" value="Refresh" onclick="filterReload(\''.$pageName.'\', '.$cp.');" /></th>');
					cout('</tr>');
				cout('</thead>');
				cout('<tbody>');
				$cnt = 0;
				for ($i=$sr;$i<count($rs) && $cnt<$ld;$i++) {
					$cnt++;
					$kdmember = $rs[$i]["kdmember"];
					if (intval($rs[$i]["isactive"])==0) {
						$isactive = '<a href="#" title="Activate" onclick="chActive(\''.$pageName.'\', '.$kdmember.', '.$rs[$i]["isactive"].');return false;">Non-Active</a>';
					} else {
						$isactive = '<a href="#" title="Deactivate" onclick="chActive(\''.$pageName.'\', '.$kdmember.', '.$rs[$i]["isactive"].');return false;">Active</a>';
					}
					#$isactive = (intval($rs[$i]["isactive"])==1)?'<span class="label label-success">Active</span>':'<span class="label label-danger">Non-Active</span>';
					$isassigned=intval($rs[$i]["kdmember"])==0?'<span class="label label-success">Available</span>':'<span class="label label-danger">Assigned&nbsp;<span class="badge">&nbsp;&nbsp;'.$rs[$i]["kdmember"].'&nbsp;&nbsp;</span></span>';
					$isi = str_replace("\n", "<br/>", $rs[$i]["isi"]);
					cout('<tr class="tr-data'.$kdmember.'">');
						cout('<td class="text-center">'.$rs[$i]["kdmember"].'</td>');
						if (authorizedModule("members_element_games", $ses_kduser)) {
							cout('<td class="text-center"><div class="nfkdgame'.$kdmember.'">'.$rs[$i]["nama_game"].'</div></td>');
						}
						if (authorizedModule("members_element_username", $ses_kduser)) {
							cout('<td class="text-center"><div class="nfkdaccount'.$kdmember.'">'.$rs[$i]["username"].'</div></td>');
						}
						if (authorizedModule("members_element_banks", $ses_kduser)) {
							cout('<td class="text-center"><div class="nfkdbank'.$kdmember.'">'.$rs[$i]["inisial"].'</div></td>');
						}
						if (authorizedModule("members_element_bank_account_number", $ses_kduser)) {
							cout('<td class="text-center"><div class="nfnorek'.$kdmember.'"><a href="#" onclick="prepareAct(\'tryview\', '.$kdmember.');return false;" data-toggle="tooltip" title="View Detail">'.$rs[$i]["norek"].'</a></div></td>');
						}
						if (authorizedModule("members_element_bank_account_holder", $ses_kduser)) {
							cout('<td class="text-center"><div class="nfnamarek'.$kdmember.'">'.$rs[$i]["namarek"].'</div></td>');
						}
						if (authorizedModule("members_element_email", $ses_kduser)) {
							cout('<td class="text-center"><div class="nfemail'.$kdmember.'">'.$rs[$i]["email"].'</div></td>');
						}
						if (authorizedModule("members_element_phone", $ses_kduser)) {
							cout('<td class="text-center"><div class="nftelp'.$kdmember.'">'.$rs[$i]["telp"].'</div></td>');
						}
						if (authorizedModule("members_element_registration_time", $ses_kduser)) {
							cout('<td class="text-center"><span data-toggle="tooltip" title="'.date('l', $rs[$i]["tanggal_daftar"]).'">'.date('d-M-Y', $rs[$i]["tanggal_daftar"]).'</span></td>');
						}
						if (authorizedModule("members_element_active", $ses_kduser)) {
							cout('<td class="text-center isactive'.$kdmember.'">'.$isactive.'</td>');
						}
						$creby = (trim($rs[$i]["creby"])!=""?'<strong>'.$rs[$i]["creby"].'</strong>':'&lt;<em>no data</em>&gt;').(trim($rs[$i]["cretime"])?' ('.date('d M Y, H:i:s A', $rs[$i]["cretime"]).')':' &lt;<em>no data</em>&gt;');
						$modby = (trim($rs[$i]["modby"])!=""?'<strong>'.$rs[$i]["modby"].'</strong>':'&lt;<em>no data</em>&gt;').(trim($rs[$i]["modtime"])?' ('.date('d M Y, H:i:s A', $rs[$i]["modtime"]).')':' &lt;<em>no data</em>&gt;');
						cout('<td class="text-center">');
							cout('<span class="option'.$kdmember.'">');
								if ($rs[$i]["kdaccount"]=="0") {
									if (authorizedModule("members_assign", $ses_kduser)) {
										cout('<a href="#" onclick="prepareAct(\'assign\', '.$kdmember.');return false;" data-toggle="tooltip" title="Assign"><span class="glyphicon glyphicon-user"></span><span class="hidden-xs hidden-sm"> Assign</span></a>');
									}
								} else {
									if (authorizedModule("members_reassign", $ses_kduser)) {
										cout('<a href="#" onclick="prepareAct(\'reassign\', '.	$kdmember.');return false;" data-toggle="tooltip" title="Re-Assign"><span class="glyphicon glyphicon-user"></span><span class="hidden-xs hidden-sm"> Re-Assign</span></a>');
									}
								}
								if (authorizedModule("members_edit", $ses_kduser)) {
									cout('<a href="#" onclick="prepareAct(\'edit\', '.$kdmember.');return false;" data-toggle="tooltip" title="Edit"><span class="glyphicon glyphicon-pencil"></span><span class="hidden-xs hidden-sm"> Edit</span></a>');
								}
								if (authorizedModule("members_delete", $ses_kduser)) {
									cout('<a href="#" onclick="prepareAct(\'delete\', '.$kdmember.');return false;" data-toggle="tooltip" title="Delete"><span class="glyphicon glyphicon-trash"></span><span class="hidden-xs hidden-sm"> Delete</span></a>');
								}
							cout('</span>');
						cout('</td>');
					cout('</tr>');
					$session_id = $rs[$i]["session_id"];
					$sess_id = substr($session_id, 0, strlen($session_id)/2).'-'.substr($rs[$i]["session_id"], (strlen($session_id)/2)+1, strlen($session_id));
					cout('<tr class="tr-data'.$kdmember.'">');
						cout('<td class="text-center row" colspan="11">');
							if (authorizedModule("members_element_ips", $ses_kduser)) {
								#cout('<div class="col-xs-2">IP 1: '.$rs[$i]["ip1"].'</div>');
								#cout('<div class="col-xs-2">IP 2: '.$rs[$i]["ip2"].'</div>');
								cout('<div class="col-xs-2">IP: <a href="#" onclick="checkIP(\''.$rs[$i]["ip1"].'\');return false;">'.$rs[$i]["ip1"].'</a></div>');
							}
							if (authorizedModule("members_element_bank_account_holder", $ses_kduser)) {
								#cout('<div class="col-xs-2"><input type="text" size="15" class="form-control input-sm" value="'.substr($rs[$i]["namarek"], 0, 15).'" /></div>');
								
							}
							cout('<div class="col-xs-6">');
								if (authorizedModule("members_quick_deposit", $ses_kduser)) {
									$cekUser = ($_SESSION["user"]["kduser"]=="0")?1:0;
									$cekUser = 1;
									if ($cekUser) {
										cout('<a class="btn btn-sm btn-primary" href="#" onclick="prepareAct(\'trydepo\', '.$kdmember.');return false;">'.number_format($rs[$i]["tdpx"],0).' ('.$rs[$i]["jdepox"].') DP</a>');
									} else {
										cout('<a href="#" onclick="prepareAct(\'trydepo\', '.$kdmember.');return false;">'.$rs[$i]["jdepox"].' DP</a>');
									}
								}
								cout("&nbsp;|&nbsp;");
								if (authorizedModule("members_quick_withdraw", $ses_kduser)) {
									$cekUser = ($_SESSION["user"]["kduser"]=="0")?1:0;
									$cekUser = 1;
									if ($cekUser) {
										cout('<a class="btn btn-sm btn-warning" href="#" onclick="prepareAct(\'trywd\', '.$kdmember.');return false;">'.number_format($rs[$i]["twdx"],0).' ('.$rs[$i]["jwdx"].') WD</a>');
									} else {
										cout('<a href="#" onclick="prepareAct(\'trywd\', '.$kdmember.');return false;">'.$rs[$i]["jwdx"].' WD</a>');
									}
								}
								$cekUser = ($_SESSION["user"]["kduser"]=="0")?1:0;
								$cekUser = 1;
								if ($cekUser) {
									cout("&nbsp;=&nbsp;");
									$ttdpwd = $rs[$i]["tdpx"]-$rs[$i]["twdx"];
									cout('<span class="btn btn-sm '.($ttdpwd<0?'btn-danger':'btn-info').'">'.(number_format($ttdpwd,0)).'</span>');
								}
							cout('</div>');
							if (authorizedModule("members_element_session", $ses_kduser)) {
								#cout('<div class="col-xs-4">s: '.$sess_id.'</div>');
								##$credit_member = getCreditMember($rs[$i]["username"]);
								##$sisa_credit = floatval($credit_member["cre"]) - floatval($credit_member["cre_bal"]);
								##cout('<div class="col-xs-4">Credit: '.$sisa_credit.'</div>');
								#if ($rs[$i]["kdgame"]==1) {
								#	cout('<div class="col-xs-3"><a href="#" onclick="prepareAct(\'trycredit\', '.$kdmember.');return false;" data-toggle="tooltip" title="View Credit">Click to View Credit</a></div>');
								#} else {
									cout('<div class="col-xs-3">s: '.$sess_id.'</div>');
								#}
							}
							if (authorizedModule("members_element_registration_time", $ses_kduser)) {
								cout('<div class="col-xs-1">Reg. Time: <strong>'.date('H:i:s', $rs[$i]["tanggal_daftar"]).'</strong></div>');
							}
						cout('</td>');
					cout('</tr>');
					cout('<tr class="tr-data'.$kdmember.'">');
						cout('<td class="text-center row" colspan="11"></td>');
					cout('</tr>');
				}
				cout('</tbody>');
			cout('</table>');
			cout('<!-- Modal -->
			<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
				<div class="modal-dialog">
					<div class="modal-content">
						<div class="modal-header">
							<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
							<h4 class="modal-title">Modal title</h4>
						</div>
						<div class="modal-body row"><div class="te"></div></div>
						<div class="modal-footer">
							<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
							<button type="button" class="btn btn-primary">Save changes</button>
						</div>
					</div><!-- /.modal-content -->
				</div><!-- /.modal-dialog -->
			</div><!-- /.modal -->');
			if ($tp!=1) {
				cout($pagination);
			}
			cout('<div class="alert alert-info" role="alert"><strong>Total whole data</strong> <span class="badge">'.count($rs).'</span></div>');
			$act_ket = "Members: Main List";
			if ($swhere!="") { $act_ket .= ": ".cleanQuery($swhere).""; }
			updateUserActivities($act_ket);
		} else {
			cout('<div class="alert alert-info" role="alert">');
				cout('<strong>No data available.</strong> Please add new data for display.');
			cout('</div>');
		}
	}
}
if ($a=="do") {
	$type = cekpost(cleanQuery($_GET["type"]), "");
	$kd = cekpost(cleanQuery($_GET["kd"]), "");
	
	if ($type=="cancel") {
		$rs=array();$q="SELECT a.*, namabank, inisial, c.nama AS nama_game 
			FROM members a 
			LEFT JOIN banks b ON b.kdbank=a.kdbank 
			LEFT JOIN games c ON c.kdgame=a.kdgame 
			WHERE kdmember='$kd'";
		callRS($rs, $q);
		#$isactive=intval($rs[0]["isactive"])==0?'Non-Active':'Active';
		if (intval($rs[0]["isactive"])==0) {
			$isactive = '<a href="#" title="Activate" onclick="chActive(\''.$pageName.'\', '.$kd.', '.$rs[0]["isactive"].');return false;">Non-Active</a>';
		} else {
			$isactive = '<a href="#" title="Deactivate" onclick="chActive(\''.$pageName.'\', '.$kd.', '.$rs[0]["isactive"].');return false;">Active</a>';
		}
		$target .= 'nfkdbank'.$kd.'$$'.$rs[0]["inisial"].'$$$';
		$target .= 'nfkdgame'.$kd.'$$'.$rs[0]["nama_game"].'$$$';
		$target .= 'nfnorek'.$kd.'$$'.$rs[0]["norek"].'$$$';
		$target .= 'nfnamarek'.$kd.'$$'.$rs[0]["namarek"].'$$$';
		$target .= 'nfemail'.$kd.'$$'.$rs[0]["email"].'$$$';
		$target .= 'nftelp'.$kd.'$$'.$rs[0]["telp"].'$$$';
		#$target .= 'isactive'.$kd.'$$'.$isactive.'$$$';
		$target .= 'option'.$kd.'$$';
			if ($rs[$i]["kdaccount"]=="0") {
				$target .= ' <a href="#" onclick="prepareAct(\'assign\', '.$kd.');return false;" data-toggle="tooltip" title="Assign"><span class="glyphicon glyphicon-user"></span><span class="hidden-xs hidden-sm"> Assign</span></a>';
			} else {
				$target .= ' <a href="#" onclick="prepareAct(\'reassign\', '.$kd.');return false;" data-toggle="tooltip" title="Re-Assign"><span class="glyphicon glyphicon-user"></span><span class="hidden-xs hidden-sm"> Re-Assign</span></a>';
			}
			$target .= ' <a href="#" onclick="prepareAct(\'edit\', '.$kd.');return false;" data-toggle="tooltip" title="Edit"><span class="glyphicon glyphicon-pencil"></span><span class="hidden-xs hidden-sm"> Edit</span></a>';
			$target .= ' <a href="#" onclick="prepareAct(\'delete\', '.$kd.');return false;" data-toggle="tooltip" title="Delete"><span class="glyphicon glyphicon-trash"></span><span class="hidden-xs hidden-sm"> Delete</span></a>';
		echo $target;
		$act_ket = "Members: Cancelling previous action";
		updateUserActivities($act_ket);
	}
	if ($type=="delete") {
		$modby = $_SESSION["user"]["inisial"];
		$modtime = time();
		$qu = "UPDATE accounts SET kdmember=0, modby='$modby', modtime='$modtime' WHERE kdmember='$kd'";
		execRS($qu);
		#$qd = "DELETE FROM members WHERE kdmember='$kd'";
		$qd = "UPDATE members SET isdeleted=1 WHERE kdmember='$kd'";
		execRS($qd);
		$target .= 'deleterow$$$'.$kd.'';
		echo $target;
		$act_ket = "Members: Delete: Deleted: [kdmember: $kd]";
		updateUserActivities($act_ket);
	}
	if ($type=="edit") {
		$nfkdbank = cekpost(cleanQuery($_GET["nfkdbank$kd"]), "");
		$nfkdgame = cekpost(cleanQuery($_GET["nfkdgame$kd"]), "");
		$nfnorek = cekpost(cleanQuery($_GET["nfnorek$kd"]), "");
		$nfnamarek = cekpost(cleanQuery($_GET["nfnamarek$kd"]), "");
		$nfemail = cekpost(cleanQuery($_GET["nfemail$kd"]), "");
		$nftelp = cekpost(cleanQuery($_GET["nftelp$kd"]), "");
		$nfisactive = cekpost(cleanQuery($_GET["nfisactive$kd"]), "");
		if ($nfkdbank=="" || $nfkdgame=="" || $nfnorek=="" || $nfnamarek=="" || $nfemail=="" || $nftelp=="") {
			
		} else {
			$modby = $_SESSION["user"]["inisial"];
			$modtime = time();
			$qu = "UPDATE members SET kdgame='$nfkdgame', kdbank='$nfkdbank', norek='$nfnorek', namarek='$nfnamarek', email='$nfemail', telp='$nftelp', 
				modby='$modby', modtime='$modtime' WHERE kdmember='$kd'";
			execRS($qu);
			$rs=array();
			$q = "SELECT a.*,namabank, b.inisial, c.nama AS nama_game FROM members a 
				LEFT JOIN banks b ON b.kdbank=a.kdbank 
				LEFT JOIN games c ON c.kdgame=a.kdgame
				WHERE kdmember='$kd'";
			callRS($rs, $q);
			$isactive=intval($rs[0]["isactive"])==0?'Non-Active':'Active';
			$target .= 'nfkdbank'.$kd.'$$'.$rs[0]["inisial"].'$$$';
			$target .= 'nfkdgame'.$kd.'$$'.$rs[0]["nama_game"].'$$$';
			$target .= 'nfnorek'.$kd.'$$'.$rs[0]["norek"].'$$$';
			$target .= 'nfnamarek'.$kd.'$$'.$rs[0]["namarek"].'$$$';
			$target .= 'nfemail'.$kd.'$$'.$rs[0]["email"].'$$$';
			$target .= 'nftelp'.$kd.'$$'.$rs[0]["telp"].'$$$';
			#$target .= 'nfisactive'.$kd.'$$'.$isactive.'$$$';
			$target .= 'option'.$kd.'$$';
				if ($rs[0]["kdaccount"]=="0") {
					$target .= ' <a href="#" onclick="prepareAct(\'assign\', '.$kd.');return false;" data-toggle="tooltip" title="Assign"><span class="glyphicon glyphicon-user"></span> Assign</a>';
				} else {
					$target .= ' <a href="#" onclick="prepareAct(\'reassign\', '.$kd.');return false;" data-toggle="tooltip" title="Re-Assign"><span class="glyphicon glyphicon-user"></span> Re-Assign</a>';
				}
				$target .= ' <a href="#" onclick="prepareAct(\'edit\', '.$kd.');return false;" data-toggle="tooltip" title="Edit"><span class="glyphicon glyphicon-pencil"></span> Edit</a>';
				$target .= ' <a href="#" onclick="prepareAct(\'delete\', '.$kd.');return false;" data-toggle="tooltip" title="Delete"><span class="glyphicon glyphicon-trash"></span> Delete</a>';
		}
		echo $target;
		$act_ket = "Members: Edit: Edited: [".cleanQuery($qu)."]";
		updateUserActivities($act_ket);
	}
	if ($type=="assignr") {
		$rsl=array();$ql="SELECT * FROM accounts WHERE kdmember='0'";
		callRS($rsl, $ql);
		if (count($rsl)!=0) {
			$targ_acc = $rsl[rand(0, count($rsl))]["kdaccount"];
			$modby = $_SESSION["user"]["inisial"];
			$modtime = time();
			$rsc=array();$qc="SELECT * FROM accounts WHERE kdmember='$kd'";
			callRS($rsc, $qc);
			if (count($rsc)!=0) {
				$target .= 'modal-title$$Assign Randomly New UserID';
				$target .= '$$$';
				$target .= 'modal-body$$<div class="alert alert-warning" role="alert"><strong>Warning!</strong> This member username already assigned by other admin: <strong>'.$rsc[0]["modby"].'</strong> as <strong>'.$rsc[0]["username"].'</strong></div>';
				$target .= '$$$';
				$target .= 'modal-footer$$<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>';
			} else {
				$qu1 = "UPDATE accounts SET kdmember='$kd', modby='$modby', modtime='$modtime' WHERE kdaccount='$targ_acc'";
				execRS($qu1);
				$qu2 = "UPDATE members SET kdaccount='$targ_acc', modby='$modby', modtime='$modtime' WHERE kdmember='$kd'";
				execRS($qu2);
				$rs=array();$q="SELECT * FROM accounts WHERE kdmember='$kd'";
				callRS($rs, $q);
				$target .= 'nfkdaccount'.$kd.'$$'.$rs[0]["username"].'$$$';
				$target .= 'option'.$kd.'$$
					<a href="#" onclick="prepareAct(\'reassign\', '.$kd.');return false;" data-toggle="tooltip" title="Re-Assign"><span class="glyphicon glyphicon-user"></span> Re-Assign</a>
					<a href="#" onclick="prepareAct(\'edit\', '.$kd.');return false;" data-toggle="tooltip" title="Edit"><span class="glyphicon glyphicon-pencil"></span> Edit</a>
					<a href="#" onclick="prepareAct(\'delete\', '.$kd.');return false;" data-toggle="tooltip" title="Delete"><span class="glyphicon glyphicon-trash"></span> Delete</a>$$$';
				$target .= 'modal-title$$Assign New UserID';
				$target .= '$$$';
				$target .= 'modal-body$$<div class="alert alert-success" role="alert"><strong>Success!</strong> This member username successfully assigned by admin: <strong>'.$rs[0]["modby"].'</strong> as <strong>'.$rs[0]["username"].'</strong></div>';
				$target .= '$$$';
				$target .= 'modal-footer$$<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>';
				## do email ##### ##### ##### ##### ##### ##### ##### ##### ##### ##### ##### ##### 
					#sendMail($kd);
					newSendMail($type, $kd);
					#sendSMS($type, $kd);
					sendSMSCP($type, $kd);
				##### ##### ##### ##### ##### ##### ##### ##### ##### ##### ##### ##### ##### #####
				$act_ket = "Members: Assign: Assign Random: [".cleanQuery($qu1)."][".cleanQuery($qu2)."]";
				updateUserActivities($act_ket);
			}
		} else {
			$act_ket = "Members: Assign: Assign Random: Failed: No Accounts";
			updateUserActivities($act_ket);
		}
		echo $target;
	}
	if ($type=="assign" || $type=="reassign") {
		$nfkdaccount = cekpost(cleanQuery($_GET["nfkdaccount$kd"]), "");
		$modby = $_SESSION["user"]["inisial"];
		$modtime = time();
		if ($type=="assign") {
			$qc="SELECT * FROM accounts WHERE kdmember='$kd'";
		} else if ($type=="reassign") {
			$qc="SELECT a.*, username FROM unused_accs a LEFT JOIN accounts b ON b.kdaccount=a.kdaccount WHERE a.kdmember='$kd' AND a.kdaccount='$nfkdaccount'";
		}
		$rsc=array();
		callRS($rsc, $qc);
		if (count($rsc)!=0) {
			if ($type=="reassign") {
				$target .= 'modal-title$$Re-Assign New UserID';
			} else {
				$target .= 'modal-title$$Assign New UserID';
			}
			$target .= '$$$';
			$target .= 'modal-body$$<div class="alert alert-warning" role="alert"><strong>Warning!</strong> This member username already assigned by other admin: <strong>'.$rsc[0]["modby"].'</strong> as <strong>'.$rsc[0]["username"].'</strong></div>';
			$target .= '$$$';
			$target .= 'modal-footer$$<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>';
		} else {
			if ($type=="reassign") {
				$rsx=array(); $qx = "SELECT * FROM members WHERE kdmember='$kd'";
				callRS($rsx, $qx);
				$kdmember = $rsx[0]["kdmember"];
				$kdaccount = $rsx[0]["kdaccount"];
				$kdunused = getID("unused_accs", "kdunused");
				$qi="INSERT INTO unused_accs (kdunused, kdmember, kdaccount, modby, modtime)
					VALUES ('$kdunused', '$kdmember', '$kdaccount', '$modby', '$modtime')";
				execRS($qi);
			}
			$qu1 = "UPDATE accounts SET kdmember='$kd', modby='$modby', modtime='$modtime' WHERE kdaccount='$nfkdaccount'";
			execRS($qu1);
			$qu2 = "UPDATE members SET kdaccount='$nfkdaccount', modby='$modby', modtime='$modtime' WHERE kdmember='$kd'";
			execRS($qu2);
			$rs=array();$q="SELECT * FROM accounts WHERE kdmember='$kd' AND kdaccount NOT IN (SELECT kdaccount FROM unused_accs)";
			callRS($rs, $q);
			$target .= 'nfkdaccount'.$kd.'$$'.$rs[0]["username"].'';
			$target .= '$$$';
			$target .= 'option'.$kd.'$$
				<a href="#" onclick="prepareAct(\'reassign\', '.$kd.');return false;" data-toggle="tooltip" title="Re-Assign"><span class="glyphicon glyphicon-user"></span><span class="hidden-xs hidden-sm"> Re-Assign</span></a>
				<a href="#" onclick="prepareAct(\'edit\', '.$kd.');return false;" data-toggle="tooltip" title="Edit"><span class="glyphicon glyphicon-pencil"></span><span class="hidden-xs hidden-sm"> Edit</span></a>
				<a href="#" onclick="prepareAct(\'delete\', '.$kd.');return false;" data-toggle="tooltip" title="Delete"><span class="glyphicon glyphicon-trash"></span><span class="hidden-xs hidden-sm"> Delete</span></a>';
			$target .= '$$$';
			if ($type=="reassign") {
				$target .= 'modal-title$$Re-Assign New UserID';
			} else {
				$target .= 'modal-title$$Assign New UserID';
			}
			$target .= '$$$';
			$target .= 'modal-body$$<div class="alert alert-success" role="alert"><strong>Success!</strong> This member username successfully assigned by admin: <strong>'.$rs[0]["modby"].'</strong> as <strong>'.$rs[0]["username"].'</strong></div>';
			$target .= '$$$';
			$target .= 'modal-footer$$<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>';
			## do email ##### ##### ##### ##### ##### ##### ##### ##### ##### ##### ##### ##### 
				#sendMail($kd);
				newSendMail($type, $kd);
				#sendSMS($type, $kd);
				sendSMSCP($type, $kd);
			##### ##### ##### ##### ##### ##### ##### ##### ##### ##### ##### ##### ##### #####
			$act_ket = "Members: Assign/Re-Assign: [Type: $type][".cleanQuery($qu1)."][".cleanQuery($qu2)."]";
			updateUserActivities($act_ket);
		}
		echo $target;
	}
	
	if ($type=="trydepo" || $type=="trywd") {
		$rst=array(); $qt="SELECT a.*, b.nama AS nama_game, c.namabank AS nama_bank, c.inisial AS inisial_bank, d.username
			FROM members a 
			LEFT JOIN games b ON b.kdgame=a.kdgame 
			LEFT JOIN banks c ON c.kdbank=a.kdbank 
			LEFT JOIN accounts d ON d.kdaccount=a.kdaccount 
			WHERE a.kdmember='$kd'";
		callRS($rst, $qt);
		$igame = $rst[0]["kdgame"];
		$ibank = $rst[0]["kdbank"];
		$inorek = $rst[0]["norek"];
		$inamarek = $rst[0]["namarek"];
		$iusername = $rst[0]["username"];
		$inilai = cekpost(cleanQuery($_REQUEST["jumlah"]), "0");
		$super_error = 0;
		if ($type=="trydepo") {
			$target .= 'modal-title$$<span class="text-success">Quick Deposit Form</span>';
		}
		if ($type=="trywd") {
			$target .= 'modal-title$$<span class="text-danger">Quick Withdraw Form</span>';
		}
		$target .= '$$$';
		if ($inilai<50000) {
			$super_error = 1;
			$target .= 'modal-body$$<div class="alert alert-warning" role="alert"><strong>Warning!</strong> Amount must be equal or more than 50,000</div>';
		}
		$rsc2 = array();
		$qc2 = "SELECT * FROM deposits WHERE kdgame='$igame' AND username='$iusername' AND kdbank='$ibank' AND norek='$inorek' AND ispending=1 AND isclear=0";
		callRS($rsc2, $qc2);
		if (count($rsc2)!=0) { $err["ibank"] = '';
			$super_error = 1;
			if ($type=="trydepo") {
				$target .= 'modal-body$$<div class="alert alert-warning" role="alert"><strong>Warning!</strong> Tidak dapat melakukan deposit, Anda masih memiliki 1 deposit yang sedang diproses</div>';
			}
			if ($type=="trywd") {
				$target .= 'modal-body$$<div class="alert alert-warning" role="alert"><strong>Warning!</strong> Tidak dapat melakukan withdraw, Anda masih memiliki 1 withdraw yang sedang diproses</div>';
			}
			
		}
		if ($super_error == 0) {
			$kdmember = $kd;
			$isactive = 1;
			$ispending = 1;
			$dari = "ADMIN";
			$dari_ip1 = get_client_ip();
			$dari_ip2 = get_client_ip2();
			$tanggalx = cekpost(cleanQuery($_REQUEST["tanggalx"]), date('d-m-y', time()));
			$ijam = cekpost(cleanQuery($_REQUEST["ijam"]), date('H:i:s', time()));
			$tanggal = strtotime($tanggalx.' '.$ijam);
			$kodetransaksi = generateRandomString(15);
			$jumlah = $inilai;
			$creby = $_SESSION["user"]["inisial"];
			$cretime = time();
			$kdgame = $igame;
			$kdbank = $ibank;
			$norek = $inorek;
			$namarek = $inamarek;
			$username = $iusername;
			if ($type=="trydepo") {
				$kddeposit = getID("deposits", "kddeposit");
				$q = "INSERT INTO deposits (kddeposit, kdgame, username, kdmember, kdbank, norek, namarek, jumlah, tanggal, kodetransaksi, dari, dari_ip1, dari_ip2, ispending, isactive, creby, cretime) 
					VALUES ('$kddeposit', '$igame', '$username', '$kdmember', '$kdbank', '$norek', '$namarek', '$jumlah', '$tanggal', '$kodetransaksi', '$dari', '$dari_ip1', '$dari_ip2', '$ispending', '$isactive', '$creby', '$cretime')";
				execRS($q);
				$target .= 'modal-body$$<div class="alert alert-success" role="alert"><strong>Success!</strong> Deposit has been made.</div>';
			}
			if ($type=="trywd") {
				$kdwithdraw = getID("withdraws", "kdwithdraw");
				$q = "INSERT INTO withdraws (kdwithdraw, kdgame, username, kdmember, kdbank, norek, namarek, jumlah, tanggal, kodetransaksi, dari, dari_ip1, dari_ip2, ispending, isactive, creby, cretime) 
					VALUES ('$kdwithdraw', '$igame', '$username', '$kdmember', '$kdbank', '$norek', '$namarek', '$jumlah', '$tanggal', '$kodetransaksi', '$dari', '$dari_ip1', '$dari_ip2', '$ispending', '$isactive', '$creby', '$cretime')";
				execRS($q);
				$target .= 'modal-body$$<div class="alert alert-success" role="alert"><strong>Success!</strong> Withdraw has been made.</div>';
			}
		}
		$target .= '$$$';
		$target .= 'modal-footer$$<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>';
		echo $target;
	}
}
if ($a=="checkcredit") {
	$kd = cekpost(cleanQuery($_GET["kd"]), "");
	$rs=array();$q="SELECT * FROM members WHERE kdmember='$kd'";
	callRS($rs, $q);
	$rsaa=array();$qaa="SELECT * FROM accounts WHERE kdaccount='".$rs[0]["kdaccount"]."'";
	callRS($rsaa, $qaa);
	$theUsername = strtolower($rsaa[0]["username"]);
	$all = getCreditMemberAll();
	$given_credit = 0;
	$balance_credit = 0;
	$last_scrape = time();
	$flag = 1;
	#printR($all);
	$flag = 0;
	for ($i=0;$i<count($all) && $flag==0;$i++) {
		$thisUsername = trim(strtolower($all[$i]["user"]));
		#echo $thisUsername;
		if ($thisUsername==$theUsername) {
			$given_credit = str_replace(",", "", $all[$i]["cre"]);
			$balance_credit = str_replace(",", "", $all[$i]["cre_bal"]);
			$flag = 1;
		}
	}
	#$ss_str = 'INSERT INTO sbo_credit (userid, given_credit, balance_credit, last_scrape) VALUES ';
	#$s_str = '';
	#for ($i=0;$i<count($all);$i++) {
	#	#$tuserid = $i + 1;
	#	$thisUsername = trim(strtolower($all[$i]["user"]));
	#	$given_credit = str_replace(",", "", $all[$i]["cre"]);
	#	$balance_credit = str_replace(",", "", $all[$i]["cre_bal"]);
	#	if (trim($thisUsername)!="") {
	#		$s_str .= ($s_str!=""?", ":"")."('$thisUsername', $given_credit, $balance_credit, '$last_scrape')";
	#	}
	#}
	#$s_str .= ';';
	#execRS($ss_str.$s_str);
	
	$rscek=array();$qcek="SELECT * FROM sbo_credit WHERE userid='$theUsername'";
	callRS($rscek, $qcek);
	if (count($rscek)!=0) {
		$qu = "UPDATE sbo_credit SET given_credit=$given_credit, balance_credit=$balance_credit, last_scrape='$last_scrape' WHERE userid='$theUsername'";
		#echo $qu;
		execRS($qu);
	} else {
		$qi = "INSERT INTO sbo_credit (userid, given_credit, balance_credit, last_scrape) VALUES ('$theUsername', $given_credit, $balance_credit, '$last_scrape');";
		#echo $qi;
		execRS($qi);
	}
	$rscall=array();$qcall="SELECT * FROM sbo_credit WHERE userid='$theUsername'";
	callRS($rscall, $qcall);
	$given_credit = $rscall[0]["given_credit"];
	$balance_credit = $rscall[0]["balance_credit"];
	$sisa_credit = floatval($given_credit) + floatval($balance_credit);
	$target .= '<div class="container-fluid table-responsive" style="color:#fff;">';
		$target .= '<table class="table table-striped table-bordered table-hover">';
			$target .= '<thead>';
				$target .= '<tr>';
					$target .= '<th>USERNAME</th>';
					$target .= '<th>Given Credit</th>';
					$target .= '<th>Balance Credit</th>';
					$target .= '<th>Sisa Credit</th>';
					$target .= '<th colspan="2">Last Check</th>';
				$target .= '</tr>';
			$target .= '</thead>';
			$target .= '<thead>';
				$target .= '<tr>';
					$target .= '<td>'.strtolower($theUsername).'</td>';
					$target .= '<td style="color:#99f;">'.number_format($given_credit,2).'</td>';
					$target .= '<td style="'.($balance_credit>0?'color:#99f;':'color:#f99;').'">'.number_format($balance_credit,2).'</td>';
					$target .= '<td style="color:#9f9;">'.number_format($sisa_credit,2).'</td>';
					$target .= '<td>'.($rscall[0]["last_scrape"]!=""?date('d-M-Y H:i:s', $rscall[0]["last_scrape"]):"").'</td>';
					$target .= '<td>'.($rscall[0]["last_scrape"]!=""?convertSecToStr(time() - $rscall[0]["last_scrape"])." ago":"").'</td>';
				$target .= '</tr>';
			$target .= '</thead>';
		$target .= '</table>';
	$target .= '</div>';
	$target .= '<div class="container">';
		#$target .= $ss_str.$s_str;
		$target .= '<a href="#" class="btn btn-default" onclick="checkSBOCredit('.$kd.');return false;">Check Now</a>';
	$target .= '</div>';
	echo $target;
}
if ($a=="prepare") {
	$type = cekpost(cleanQuery($_GET["type"]), "");
	$kd = cekpost(cleanQuery($_GET["kd"]), "");
	$rs=array();$q="SELECT * FROM members WHERE kdmember='$kd'";
	callRS($rs, $q);
	$kdgame = $rs[0]["kdgame"];
	$rsa=array();$qa="SELECT * FROM accounts WHERE isactive=1 AND kdmember=0 AND kdgame='$kdgame'";
	callRS($rsa, $qa);
	$target='';
	if ($type=="trycredit") {
		############################################################################################################################################################
		############################################################################################################################################################
		$rscek=array();$qcek="SELECT * FROM sbo_credit ORDER BY last_scrape DESC LIMIT 0,1";
		callRS($rscek, $qcek);
		if ((time() - $rscek[0]["last_scrape"]) > (60 * 30)) {
			execRS("DELETE FROM sbo_credit");
			$all = getCreditMemberAll();
			$given_credit = 0;
			$balance_credit = 0;
			$last_scrape = time();
			$flag = 1;
			#printR($all);
			$flag = 0;
			#for ($i=0;$i<count($all) && $flag==0;$i++) {
			#	$thisUsername = trim(strtolower($all[$i]["user"]));
			#	#echo $thisUsername;
			#	if ($thisUsername==$theUsername) {
			#		$given_credit = str_replace(",", "", $all[$i]["cre"]);
			#		$balance_credit = str_replace(",", "", $all[$i]["cre_bal"]);
			#		$flag = 1;
			#	}
			#}
			$ss_str = 'INSERT INTO sbo_credit (userid, given_credit, balance_credit, last_scrape) VALUES ';
			$s_str = '';
			for ($i=0;$i<count($all);$i++) {
				#$tuserid = $i + 1;
				$thisUsername = trim(strtolower($all[$i]["user"]));
				$given_credit = str_replace(",", "", $all[$i]["cre"]);
				$balance_credit = str_replace(",", "", $all[$i]["cre_bal"]);
				if (trim($thisUsername)!="") {
					$s_str .= ($s_str!=""?", ":"")."('$thisUsername', $given_credit, $balance_credit, '$last_scrape')";
				}
			}
			$s_str .= ';';
			execRS($ss_str.$s_str);
		}
		############################################################################################################################################################
		############################################################################################################################################################
		$rsaa=array();$qaa="SELECT * FROM accounts WHERE kdaccount='".$rs[0]["kdaccount"]."'";
		callRS($rsaa, $qaa);
		$target .= 'tryview';
		$target .= '$$$';
		$target .= 'Member Detail';
		$target .= '$$$';
		$theUsername = $rsaa[0]["username"];
		$rscre=array();$qcre="SELECT * FROM sbo_credit WHERE userid='$theUsername'";
		callRS($rscre, $qcre);
		$given_credit = $rscre[0]["given_credit"];
		$balance_credit = $rscre[0]["balance_credit"];
		#$credit_member = getCreditMember(strtolower($theUsername));
		#$given_credit = str_replace(",", "", $credit_member["cre"]);
		#$balance_credit = str_replace(",", "", $credit_member["cre_bal"]);
		$sisa_credit = floatval($given_credit) + floatval($balance_credit);
		$target .= '<div class="container-fluid table-responsive" style="color:#fff;">';
			$target .= '<table class="table table-striped table-bordered table-hover">';
				$target .= '<thead>';
					$target .= '<tr>';
						$target .= '<th>USERNAME</th>';
						$target .= '<th>Given Credit</th>';
						$target .= '<th>Balance Credit</th>';
						$target .= '<th>Sisa Credit</th>';
						$target .= '<th colspan="2">Last Check</th>';
					$target .= '</tr>';
				$target .= '</thead>';
				$target .= '<thead>';
					$target .= '<tr>';
						$target .= '<td>'.strtolower($theUsername).'</td>';
						$target .= '<td style="color:#99f;">'.number_format($given_credit,2).'</td>';
						$target .= '<td style="'.($balance_credit>0?'color:#99f;':'color:#f99;').'">'.number_format($balance_credit,2).'</td>';
						$target .= '<td style="color:#9f9;">'.number_format($sisa_credit,2).'</td>';
						$target .= '<td>'.($rscre[0]["last_scrape"]!=""?date('d-M-Y H:i:s', $rscre[0]["last_scrape"]):"").'</td>';
						$target .= '<td>'.($rscre[0]["last_scrape"]!=""?convertSecToStr(time() - $rscre[0]["last_scrape"])." ago":"").'</td>';
					$target .= '</tr>';
				$target .= '</thead>';
			$target .= '</table>';
		$target .= '</div>';
		$target .= '<div class="container">';
			#$target .= $ss_str.$s_str;
			$target .= '<a href="#" class="btn btn-default" onclick="checkSBOCredit('.$kd.');return false;">Check Now</a>';
		$target .= '</div>';
		$target .= '$$$';
		#$target .= '<button type="button" class="btn btn-primary" onclick="doAct(\''.$type.'\', '.$kd.');return false;">Re-Assign</button>';
		$target .= '<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>';
		echo $target;
		$act_ket = "Members: Prepare: [Type: $type]";
		updateUserActivities($act_ket);
	}
	if ($type=="tryview") {
		$target .= 'tryview';
		$target .= '$$$';
		$target .= 'Member Detail';
		$target .= '$$$';
		$target .= '<div class="container-fluid">';
			#$target .= '<div class="row">';
			#	$target .= '<div class="col-sm-12">';
			#		$target .= '<dl class="dl-horizontal dldata">';
			#			$target .= '<dt></dt>';
			#			$target .= '<dd></dd>';
			#		$target .= '</dl>';
			#	$target .= '</div>';
			#$target .= '</div>';
			$target .= '<div class="row">';
				$target .= '<div class="col-sm-6">
					
				</div>';
				$target .= '<div class="col-sm-6"></div>';
			$target .= '</div>';
		$target .= '</div>';
		$rsv=array();$qv="SELECT a.*, b.username, c.inisial, c.namabank, d.nama AS namagame FROM members a LEFT JOIN accounts b ON b.kdaccount=a.kdaccount LEFT JOIN banks c ON c.kdbank=a.kdbank LEFT JOIN games d ON d.kdgame=a.kdgame WHERE a.kdmember='$kd'";
		callRS($rsv, $qv);
		
		$target .= '<div style="border:0px red solid;">';
			$target .= '<dl class="dl-horizontal dldata">';
				$target .= '<dt>Game</dt>';
				$target .= '<dd>'.$rsv[0]["namagame"].'</dd>';
				$target .= '<dt>Username</dt>';
				$target .= '<dd>'.$rsv[0]["username"].'</dd>';
				$target .= '<dt>Bank</dt>';
				$target .= '<dd>'.$rsv[0]["inisial"].' / '.$rsv[0]["namabank"].'</dd>';
				$target .= '<dt>Bank Account</dt>';
				$target .= '<dd>'.$rsv[0]["norek"].' / '.$rsv[0]["namarek"].'</dd>';
				$target .= '<dt>Email</dt>';
				$target .= '<dd>'.$rsv[0]["email"].'</dd>';
				$target .= '<dt>Phone</dt>';
				$target .= '<dd>'.$rsv[0]["telp"].'</dd>';
				$target .= '<dt>Created by</dt>';
				$target .= '<dd>'.$rsv[0]["creby"].' ('.date('d-M-Y H:i:sA', $rsv[0]["cretime"]).')</dd>';
				$target .= '<dt>Modified by</dt>';
				$target .= '<dd>'.$rsv[0]["modby"].' ('.date('d-M-Y H:i:sA', $rsv[0]["modtime"]).')</dd>';
			$target .= '</dl>';
		$target .= '</div>';
		$rsdp=array(); $qdp="SELECT * FROM deposits WHERE kdmember='$kd' ORDER BY tanggal DESC";
		callRS($rsdp, $qdp);
		$totaldp = 0;
		for ($j=0;$j<count($rsdp);$j++) { if ($rsdp[$j]["isclear"]) { $totaldp += $rsdp[$j]["jumlah"]; } }
		
		$rswd=array(); $qwd="SELECT * FROM withdraws WHERE kdmember='$kd' ORDER BY tanggal DESC";
		callRS($rswd, $qwd);
		$totalwd = 0;
		for ($k=0;$k<count($rswd);$k++) { if ($rswd[$k]["isclear"]) { $totalwd += $rswd[$k]["jumlah"]; } }
		$totalDPWD = $totaldp - $totalwd;
		$target .= '<div class="row" style="padding:0;margin:0;">';
			$target .= '<div class="col-sm-3" style="padding:0;"><strong>Total DP/WD</strong></div>';
			$target .= '<div class="col-sm-9 text-left" style="background:#fff;padding:0 10px;'.($totalDPWD<0?'color:#f20000;':'color:#0000f2;').'"><strong>'.($totalDPWD<0?'-':'+').' '.number_format($totalDPWD).'</strong></div>';
		$target .= '</div>';
		$target .= '<div class="row" style="margin:0;">';
			$target .= '<div class="col-sm-6" style="padding:0;">';
				$target .= '<div class="panel panel-success" style="margin:0;">';
					$target .= '<div class="panel-heading text-center" style="margin:0;padding:0;">All Deposits</div>';
					$target .= '<div class="panel-body" style="margin:0;padding:0;height:200px;overflow-y:scroll;">';
						$target .= '<div class="row" style="padding:0;margin:0;border-bottom:1px #999 solid;">';
							$target .= '<div class="col-sm-6" style="padding:0;"><strong>Total Clear</strong></div>';
							$target .= '<div class="col-sm-6 text-right" style="padding:0;"><strong>'.number_format($totaldp).'</strong></div>';
						$target .= '</div>';
							for ($j=0;$j<count($rsdp);$j++) {
								$target .= '<div class="row" style="padding:0;margin:0;border-bottom:1px #999 solid;">';
									$target .= '<div class="col-sm-6" style="padding:0;">'.date('d-M-y | H:i:s', $rsdp[$j]["tanggal"]).'</div>';
									$target .= '<div class="col-sm-4 text-right" style="padding:0;">'.number_format($rsdp[$j]["jumlah"]).'</div>';
									$target .= '<div class="col-sm-2 text-center" style="font-size:70%;padding:0;">'.($rsdp[$j]["isclear"]==1?'Clear':'').' '.($rsdp[$j]["ispending"]==1?'Pend.':'').' '.($rsdp[$j]["isrejected"]==1?'Rejected':'').'</div>';
								$target .= '</div>';
							}
						$target .= '<div class="row" style="padding:0;margin:0;border-bottom:1px #999 solid;">';
							$target .= '<div class="col-sm-6" style="padding:0;"><strong>Total Clear</strong></div>';
							$target .= '<div class="col-sm-6 text-right" style="padding:0;"><strong>'.number_format($totaldp).'</strong></div>';
						$target .= '</div>';
					$target .= '</div>';
				$target .= '</div>';
			$target .= '</div>';
			$target .= '<div class="col-sm-6" style="padding:0;">';
				$target .= '<div class="panel panel-danger" style="margin:0;">';
					$target .= '<div class="panel-heading text-center" style="margin:0;padding:0;">All Withdraws</div>';
					$target .= '<div class="panel-body" style="margin:0;padding:0;height:200px;overflow-y:scroll;">';
						$target .= '<div class="row" style="padding:0;margin:0;border-bottom:1px #999 solid;">';
							$target .= '<div class="col-sm-6" style="padding:0;"><strong>Total Clear</strong></div>';
							$target .= '<div class="col-sm-6 text-right" style="padding:0;"><strong>'.number_format($totalwd).'</strong></div>';
						$target .= '</div>';
							for ($k=0;$k<count($rswd);$k++) {
								$target .= '<div class="row" style="padding:0;margin:0;border-bottom:1px #999 solid;">';
									$target .= '<div class="col-sm-6" style="padding:0;">'.date('d-M-y | H:i:s', $rswd[$k]["tanggal"]).'</div>';
									$target .= '<div class="col-sm-4 text-right" style="padding:0;">'.number_format($rswd[$k]["jumlah"]).'</div>';
									$target .= '<div class="col-sm-2 text-center" style="font-size:70%;padding:0;">'.($rswd[$k]["isclear"]==1?'Clear':'').' '.($rswd[$k]["ispending"]==1?'Pend.':'').' '.($rswd[$k]["isrejected"]==1?'Rejected':'').'</div>';
								$target .= '</div>';
							}
						$target .= '<div class="row" style="padding:0;margin:0;border-bottom:1px #999 solid;">';
							$target .= '<div class="col-sm-6" style="padding:0;"><strong>Total Clear</strong></div>';
							$target .= '<div class="col-sm-6 text-right" style="padding:0;"><strong>'.number_format($totalwd).'</strong></div>';
						$target .= '</div>';
					$target .= '</div>';
				$target .= '</div>';
			$target .= '</div>';
		$target .= '</div>';
		
		#$target .= '<form id="'.$type.'-form" method="post" target="quick_'.$type.'_iframe" action="/'.adminFolder.'/_ajax/'.$ajax_page.'?a=do&type='.$type.'&kd='.$kd.'" role="form">';
		#	$target .= '<dl class="dl-horizontal dldata">';
		#		$target .= '<dt><label for="nfkdaccount'.$kd.'">Available UserID</label></dt>';
		#		$target .= '<dd><select name="nfkdaccount'.$kd.'" id="nfkdaccount'.$kd.'" size="10" class="form-control">';
		#			for ($i=0;$i<count($rsa);$i++) {
		#				$sel = $i==0?' selected="selected" ':'';
		#				$target .= '<option value="'.$rsa[$i]["kdaccount"].'" '.$sel.'>'.$rsa[$i]["username"].' / '.$rsa[$i]["pass"].'</option>';
		#			}
		#		$target .= '</select></dd>';
		#	$target .= '</dl>';
		#$target .= '</form>';
		$target .= '$$$';
		#$target .= '<button type="button" class="btn btn-primary" onclick="doAct(\''.$type.'\', '.$kd.');return false;">Re-Assign</button>';
		$target .= '<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>';
		echo $target;
		$act_ket = "Members: Prepare: [Type: $type]";
		updateUserActivities($act_ket);
	}
	if ($type=="reassign") {
		$target .= 'reassign';
		$target .= '$$$';
		$target .= 'Re-Assign New UserID';
		$target .= '$$$';
		$target .= '<form id="'.$type.'-form" method="post" target="quick_'.$type.'_iframe" action="/'.adminFolder.'/_ajax/'.$ajax_page.'?a=do&type='.$type.'&kd='.$kd.'" role="form">';
			$target .= '<dl class="dl-horizontal dldata">';
				$target .= '<dt><label for="nfkdaccount'.$kd.'">Available UserID</label></dt>';
				$target .= '<dd><select name="nfkdaccount'.$kd.'" id="nfkdaccount'.$kd.'" size="10" class="form-control">';
					for ($i=0;$i<count($rsa);$i++) {
						$sel = $i==0?' selected="selected" ':'';
						$target .= '<option value="'.$rsa[$i]["kdaccount"].'" '.$sel.'>'.$rsa[$i]["username"].' / '.$rsa[$i]["pass"].'</option>';
					}
				$target .= '</select></dd>';
			$target .= '</dl>';
		$target .= '</form>';
		$target .= '$$$';
		$target .= '<button type="button" class="btn btn-primary" onclick="doAct(\''.$type.'\', '.$kd.');return false;">Re-Assign</button>';
		$target .= '<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>';
		echo $target;
		$act_ket = "Members: Prepare: [Type: $type]";
		updateUserActivities($act_ket);
	}
	if ($type=="assign") {
		$target .= 'assign';
		$target .= '$$$';
		$target .= 'Assign New UserID';
		$target .= '$$$';
		$target .= '<div class="col-xs-4">';
			$target .= 'Available <strong>'.count($rsa).' Account'.(count($rsa)>1?'s':'').'';
			$target .= '<br/><br/>';
			$target .= '<input class="btn btn-warning" type="button" value="Assign Randomly" onclick="doAct(\'assignr\', '.$kd.');" />';
		$target .= '</div>';
		$target .= '<div class="col-xs-8">';
			$target .= '<form id="'.$type.'-form" method="post" target="quick_'.$type.'_iframe" action="/'.adminFolder.'/_ajax/'.$ajax_page.'?a=do&type='.$type.'&kd='.$kd.'" role="form">';
				$target .= '<dl class="dl-vertical dldata">';
					$target .= '<dt><label for="nfkdaccount'.$kd.'">Available UserID</label></dt>';
					$target .= '<dd><select name="nfkdaccount'.$kd.'" id="nfkdaccount'.$kd.'" size="5" class="form-control">';
						for ($i=0;$i<count($rsa);$i++) {
							$sel = $i==0?' selected="selected" ':'';
							$target .= '<option value="'.$rsa[$i]["kdaccount"].'" '.$sel.'>'.$rsa[$i]["username"].' / '.$rsa[$i]["pass"].'</option>';
						}
					$target .= '</select></dd>';
					$target .= '<dt></dt><dd>';
						$target .= '<input class="btn btn-primary" type="button" value="Assign Manually" onclick="doAct(\''.$type.'\', '.$kd.');" />';
					$target .= '</dd>';
				$target .= '</dl>';
			$target .= '</form>';
		$target .= '</div>';
		$target .= '$$$';
		$target .= '<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>';
		echo $target;
		$act_ket = "Members: Prepare: [Type: $type]";
		updateUserActivities($act_ket);
	}
	if ($type=="edit") {
		$target .= 'nfkdgame'.$kd.'$$<select name="nfkdgame'.$kd.'" id="nfkdgame'.$kd.'" class="form-control input-sm">';
			$rsb=array();$qb="SELECT * FROM games WHERE isactive=1";
			callRS($rsb, $qb);
			for ($i=0;$i<count($rsb);$i++) {
				$sel = intval($rsb[$i]["kdgame"])==intval($rs[0]["kdgame"])?'selected="selected"':'';
				$target .= '<option value="'.$rsb[$i]["kdgame"].'" '.$sel.'>'.$rsb[$i]["nama"].'</option>';
			}
		$target .= '</select>$$$';
		$target .= 'nfkdbank'.$kd.'$$<select name="nfkdbank'.$kd.'" id="nfkdbank'.$kd.'" class="form-control input-sm">';
			$rsb=array();$qb="SELECT * FROM banks WHERE isactive=1";
			callRS($rsb, $qb);
			for ($i=0;$i<count($rsb);$i++) {
				$sel = intval($rsb[$i]["kdbank"])==intval($rs[0]["kdbank"])?'selected="selected"':'';
				$target .= '<option value="'.$rsb[$i]["kdbank"].'" '.$sel.'>'.$rsb[$i]["inisial"].'</option>';
			}
		$target .= '</select>$$$';
		$target .= 'nfnorek'.$kd.'$$<input type="text" name="nfnorek'.$kd.'" id="nfnorek'.$kd.'" value="'.$rs[0]["norek"].'" class="form-control input-sm" />$$$';
		$target .= 'nfnamarek'.$kd.'$$<input type="text" name="nfnamarek'.$kd.'" id="nfnamarek'.$kd.'" value="'.$rs[0]["namarek"].'" class="form-control input-sm" />$$$';
		$target .= 'nfemail'.$kd.'$$<input type="text" name="nfemail'.$kd.'" id="nfemail'.$kd.'" value="'.$rs[0]["email"].'" class="form-control input-sm" />$$$';
		$target .= 'nftelp'.$kd.'$$<input type="text" name="nftelp'.$kd.'" id="nftelp'.$kd.'" value="'.$rs[0]["telp"].'" class="form-control input-sm" />$$$';
		$isactive0 = intval($rs[0]["isactive"])==0?'selected="selected"':'';
		$isactive1 = intval($rs[0]["isactive"])==1?'selected="selected"':'';
		$target .= 'nfisactive'.$kd.'$$<select name="nfisactive'.$kd.'" id="nfisactive'.$kd.'" class="form-control input-sm">
			<option value="0" '.$isactive0.'>Non-Active</option>
			<option value="1" '.$isactive1.'>Active</option>
		</select>$$$';
		$target .= 'option'.$kd.'$$<input type="button" value="Update" onclick="doAct(\''.$type.'\', '.$kd.');" />&nbsp;
			<input type="button" value="Cancel" onclick="doAct(\'cancel\', '.$kd.');" />';
		echo $target;
		$act_ket = "Members: Prepare: [Type: $type]";
		updateUserActivities($act_ket);
	}
	if ($type=="delete") {
		$target .= 'option'.$kd.'$$Sure?&nbsp;<input type="button" value="Yes" onclick="doAct(\''.$type.'\', '.$kd.');" />&nbsp;
			<input type="button" value="Cancel" onclick="doAct(\'cancel\', '.$kd.');" />';
		echo $target;
	}
	if ($type=="trydepo" || $type=="trywd") {
		$rst=array(); $qt="SELECT a.*, b.nama AS nama_game, c.namabank AS nama_bank, c.inisial AS inisial_bank, d.username
			FROM members a 
			LEFT JOIN games b ON b.kdgame=a.kdgame 
			LEFT JOIN banks c ON c.kdbank=a.kdbank 
			LEFT JOIN accounts d ON d.kdaccount=a.kdaccount 
			WHERE a.kdmember='$kd'";
		callRS($rst, $qt);
		$target .= 'trydepo';
		$target .= '$$$';
		if ($type=="trydepo") {
			$target .= '<span class="text-success">Quick Deposit Form</a>';
		}
		if ($type=="trywd") {
			$target .= '<span class="text-danger">Quick Withdraw Form</a>';
		}
		$target .= '$$$';
		$target .= '<form id="'.$type.'-form" method="post" target="quick_'.$type.'_iframe" action="/'.adminFolder.'/_ajax/'.$ajax_page.'?a=do&type='.$type.'&kd='.$kd.'" role="form">';
			$target .= '<dl class="dl-horizontal dldata">';
				$target .= '<dt>Game/Product</dt>';
				$target .= '<dd>'.$rst[0]["nama_game"].'</dt>';
				
				$target .= '<dt>Username</dt>';
				$target .= '<dd>'.$rst[0]["username"].'</dt>';
				
				$target .= '<dt>Bank</dt>';
				$target .= '<dd>'.$rst[0]["inisial_bank"].' | '.$rst[0]["nama_bank"].'</dt>';
				
				$target .= '<dt>Bank Account</dt>';
				$target .= '<dd>';
					if (authorizedModule("members_element_bank_account_number", $ses_kduser)) {
						$target .= $rst[0]["norek"];
					}
					if (authorizedModule("members_element_bank_account_holder", $ses_kduser)) {
						$target .= ' a/n '.$rst[0]["namarek"].'';
					}
				$target .= '</dt>';
				
				$target .= '<dt><label for="tanggal">Date</label></dt>';
				$target .= '<dd>';
					$target .= '<div class="input-group">';
						$target .= '<input id="tanggalx" name="tanggalx" type="text" class="tanggalx form-control" placeholder="Date" value="'.date('d-m-Y', time()).'" />';
						$target .= '<label for="tanggalx" class="input-group-addon btn">';
							$target .= '<span class="glyphicon glyphicon-calendar"></span>';
						$target .= '</label>';
						$target .= '<input class="form-control" name="ijam" id="ijam" type="text" value="'.date('H:i:s', time()).'" size="10" />';
					$target .= '</div>';
				$target .= '</dd>';
				
				$target .= '<dt><label for="jumlah">Amount</label></dt>';
				$target .= '<dd><input type="text" name="jumlah" id="jumlah" class="form-control" placeholder="Amount" value="0" /></dd>';
			$target .= '</dl>';
		$target .= '</form>';
		$target .= '$$$';
		if ($type=="trydepo") {
			$target .= '<button type="button" class="btn btn-success" onclick="doAct(\''.$type.'\', '.$kd.');return false;">DEPOSIT!</button>';
		}
		if ($type=="trywd") {
			$target .= '<button type="button" class="btn btn-danger" onclick="doAct(\''.$type.'\', '.$kd.');return false;">WITHDRAW!</button>';
		}
		$target .= '<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>';
		echo $target;
		$act_ket = "Members: Prepare: [Type: $type]";
		updateUserActivities($act_ket);
	}
}
if ($a=="quick_add") {
	$ikdbank = cekpost(cleanQuery($_POST["ikdbank"]), "");
	$ikdgame = cekpost(cleanQuery($_POST["ikdgame"]), "");
	$inorek = cekpost(cleanQuery($_POST["inorek"]), "");
	$inamarek = cekpost(cleanQuery($_POST["inamarek"]), "");
	$iemail = cekpost(cleanQuery($_POST["iemail"]), "");
	$itelp = cekpost(cleanQuery($_POST["itelp"]), "");
	if ($ikdbank=="") { $err.= BSErrorMessage('Bank must be chosen'); }
	if ($ikdgame=="") { $err.= BSErrorMessage('Game must be chosen'); }
	if ($inorek=="") { $err.= BSErrorMessage('Bank Account Number must be filled'); }
	if ($inamarek=="") { $err.= BSErrorMessage('Bank Account Holder must be filled'); }
	if ($iemail=="") { $err.= BSErrorMessage('Email must be filled'); }
	if ($itelp=="") { $err.= BSErrorMessage('Phone must be filled'); }
	if (!is_numeric($inorek)) { $err.= BSErrorMessage('Account Number must be number formatted!'); }
	if (!is_numeric($itelp)) { $err.= BSErrorMessage('Phone must be number formatted!'); }
	if (!check_email_address($iemail)) { $err.= BSErrorMessage('Invalid Email Format'); }
	
	$rs=array();$q="SELECT * FROM members WHERE norek='$inorek' AND kdbank='$ikdbank' AND kdgame='$ikdgame' AND isdeleted=0 AND isactive=1";
	callRS($rs, $q);
	
	if (count($rs)!=0) { $err.= ($err!=''?'<br/>':'').'<span>This Bank Account Number already exist!</span>'; }
	if ($err=="") {
		$isactive = 1;
		$creby = $_SESSION["user"]["inisial"];
		$cretime = time();
		$kdmember = getID("members", "kdmember");
		$tanggal_daftar = time();
		$kode_random = generateRandomString(15);
		do {
			$rscek = array(); $qcek = "SELECT kdmember FROM members WHERE kode_random = '$kode_random'";
			callRS($rscek, $qcek);
			if (count($rscek)!=0) {
				$flag = 0;
				$kode_random = generateRandomString(15);
			} else {
				$flag = 1;
			}
		} while($flag==0);
		$q = "INSERT INTO members (kdmember, kdbank, kdgame, norek, namarek, email, telp, isactive, tanggal_daftar, kode_random, creby, cretime) 
			VALUES ('$kdmember', '$ikdbank', '$ikdgame', '$inorek', '$inamarek', '$iemail', '$itelp', '$isactive', '$tanggal_daftar', '$kode_random', '$creby', '$cretime')";
		execRS($q);
		$act_ket = "Members: Quick Add: [Query: ".cleanQuery($q)."]";
		updateUserActivities($act_ket);
		cout('<script>parent.clearQuickAdd();parent.filterReload(\''.$pageName.'\', 1);parent.showError(\'\');</script>');
	} else {
		cout('<script>parent.showError(\''.$err.'\');</script>');
		$act_ket = "Members: Quick Add: Error [$err]";
		updateUserActivities($act_ket);
	}
	
}
if ($a=="chactive") {
	$kd = cekpost(cleanQuery($_REQUEST["kd"]), "");
	$ca = cekpost(cleanQuery($_REQUEST["ca"]), "");
	$kd = (trim($kd)=="undefined")?'':$kd;
	$ca = (trim($ca)=="undefined")?'':$ca;
	if ($kd!="" && $kd!=0 && $ca!="") {
		$na = $ca==0?1:0;
		$modby = $_SESSION["user"]["inisial"];
		$modtime = time();
		$qu = "UPDATE members SET isactive='$na', modby='$modby', modtime='$modtime' WHERE kdmember='$kd'";
		execRS($qu);
		$act_ket = "Members: Ch. Active [kd: $kd][from Act: $ca][to Act: $na]";
		updateUserActivities($act_ket);
		if (intval($na)==0) {
			$isactive = '<a href="#" title="Activate" onclick="chActive(\''.$pageName.'\', '.$kd.', '.$na.');return false;">Non-Active</a>';
		} else {
			$isactive = '<a href="#" title="Deactivate" onclick="chActive(\''.$pageName.'\', '.$kd.', '.$na.');return false;">Active</a>';
		}
		echo $isactive;
	}
}
$len1 = ob_get_length();
header('Content-length:'.$len1.'');
ob_end_flush();
?>