<?php
if (!defined("root")) {
	define("root", $_SERVER['DOCUMENT_ROOT']);
}
session_start();
require(root."/_common.php");
require(root."/_lib/db.php");
require(root."/_lib/main.php");
require(root."/mobileDetect/Mobile_Detect.php");
require(root."/_lib/bootstraps.php");
$page_title = "Deposit";
$page_id = "deposit";
$rand = cekpost(cleanQuery($_REQUEST["rand"]), "");
$kirim = cekpost(cleanQuery($_REQUEST["kirim"]), "");
$err = array();
if ($kirim==1) {
	$igame = cekpost(cleanQuery($_REQUEST["igame"]), "");
	$ibank = cekpost(cleanQuery($_REQUEST["ibank"]), "");
	$inorek = cekpost(cleanQuery($_REQUEST["inorek"]), "");
	$inamarek = cekpost(cleanQuery($_REQUEST["inamarek"]), "");
	$iusername = cekpost(cleanQuery($_REQUEST["iusername"]), "");
	$inilai = cekpost(cleanQuery($_REQUEST["inilai"]), "");
	$ival = cekpost(cleanQuery($_REQUEST["ival"]), "");
	$inilai = str_replace(",", "", $inilai);
	if ($ibank=="") { $err["ibank"] = 'Bank harus dipilih!'; }
	if ($igame=="") { $err["igame"] = 'Permainan harus dipilih!'; }
	if ($inorek=="") { $err["inorek"] = 'Nomor Rekening harus diisi!'; }
	if ($inamarek=="") { $err["inamarek"] = 'Nama Pemilik Rekening harus diisi!'; }
	if ($iusername=="") { $err["iusername"] = 'Username harus diisi!'; }
	if ($inilai=="") { $err["inilai"] = 'Nominal harus diisi!'; }
	if ($ival=="") { $err["ival"] = 'Kode Validasi harus diisi!'; }
	if (!is_numeric($inorek) && $inorek!="") { $err["inorek"] = 'Nomor Rekening bukan merupakan angka!'; }
	if (!is_numeric($inilai) && $inilai!="") { $err["inilai"] = 'Nominal bukan merupakan angka!'; }
	if ($inilai < 50000 && $inilai!="") { $err["inilai"] = 'Nominal minimal bernilai Rp. 50,000,- (Lima Puluh Ribu Rupiah)!'; }
	
	$rsc=array();
	$qc="SELECT a.*, username FROM members a 
		LEFT JOIN accounts b ON b.kdaccount=a.kdaccount 
		WHERE a.isactive=1 AND username='$iusername' AND a.kdgame='$igame' AND a.kdbank='$ibank' AND a.norek='$inorek'";
	#$rsc = callRS($qc);
	callRS($rsc, $qc);
	if (count($rsc)<=0 && $iusername!="") { $err["iusername"] = 'Username tidak ditemukan! Pastikan Username sudah sesuai dengan nomor rekening terdaftar.'; }
	
	$rsc2 = array();
	$qc2 = "SELECT * FROM deposits WHERE kdgame='$igame' AND username='$iusername' AND kdbank='$ibank' AND norek='$inorek' AND ispending=1 AND isclear=0";
	#$rsc2 = callRS($qc2);
	callRS($rsc2, $qc2);
	if (count($rsc2)!=0) { $err["ibank"] = 'Tidak dapat melakukan deposit, Anda masih memiliki 1 deposit yang sedang diproses'; }
	if ($ival!=$_SESSION["code"] && $ival!="") { $err["ival"] = 'Kode Validasi tidak cocok!'; }
	
	if (empty($err)) {
		$isactive = 1;
		$creby = "VISITOR";
		$cretime = time();
		$kddeposit = getID("deposits", "kddeposit");
		$rsu=array();$qu="SELECT a.*, username FROM members a 
			LEFT JOIN accounts b ON b.kdaccount=a.kdaccount
			WHERE a.isactive=1 AND username='$iusername' AND a.kdbank='$ibank' AND a.kdgame='$igame' AND a.norek='$inorek'";
		#$rsu = callRS($qu);
		callRS($rsu, $qu);
		$username = $rsu[0]["username"];
		$kdmember = $rsu[0]["kdmember"];
		$ispending = 1;
		$dari = "WEBSITE";
		$dari_ip1 = get_client_ip();
		$dari_ip2 = get_client_ip2();
		$tanggal = time();
		$kodetransaksi = generateRandomString(15);
		do {
			$rscek = array(); $qcek = "SELECT kddeposit FROM deposits WHERE kodetransaksi = '$kodetransaksi'";
			#$rscek = callRS($qcek);
			callRS($rscek, $qcek);
			if (count($rscek)!=0) {
				$flag = 0;
				$kodetransaksi = generateRandomString(15);
			} else {
				$flag = 1;
			}
		} while($flag==0);
		$kdbank = $ibank;
		$norek = $inorek;
		$namarek = $inamarek;
		$jumlah = $inilai;
		$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);
		#$q = "INSERT INTO deposits (kddeposit, kdgame, username, kdmember, kdbank, norek, namarek, jumlah, tanggal, kodetransaksi, dari, dari_ip1, dari_ip2, ispending, isactive, creby, cretime) 
		#	VALUES ('?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?')";
		#$q = "INSERT INTO deposits (kddeposit, kdgame, username, kdmember, kdbank, norek, namarek, jumlah, tanggal, kodetransaksi, dari, dari_ip1, dari_ip2, ispending, isactive, creby, cretime) 
		#	VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
		#$param = array($kddeposit, $igame, $username, $kdmember, $kdbank, $norek, $namarek, $jumlah, $tanggal, $kodetransaksi, $dari, $dari_ip1, $dari_ip2, $ispending, $isactive, $creby, $cretime);
		#$rs = callRS($q, $param);
		header("Location: /deposit/thanks/$kodetransaksi");
	}
}
require(root."/_tpl/html_begin.php");
require(root."/_tpl/tag_head.php");
require(root."/_tpl/ie_style_exception.php");
/*
 * begin
 * additional style
 * */
cout('<style type="text/css">');
cout('');
cout('</style>');
/*
 * end
 * additional style
 * 
 * v
 * v
 * closing tag head
 * 
 * */
require(root."/_tpl/body_open.php");
cout('<div class="container-fluid main-body">');
	cout('<div class="decor-1"></div>');
	
	cout('<div class="container-fluid">');
		cout('<div class="container for-footer">');
			cout('<div class="decor decor-1"></div>');
			cout('<div class="decor decor-2"></div>');
			cout('<div class="decor decor-3"></div>');
			cout('<div class="special-box">');
				cout('<div class="decor decor-1"></div>');
				cout('<div class="decor decor-2"></div>');
				cout('<div class="content">');
					cout('<div class="decor decor-1"></div>');
					cout('<div class="decor decor-2"></div>');
					cout('<div class="title">');
						cout('<div class="page-title">Deposit</div>');
						cout('<div class="decor decor-1"></div>');
					cout('</div>');
					cout('<div class="real-content">');
						if ($rand!="") {
							$rscm=array(); $qcm="SELECT * FROM deposits WHERE isactive=1 AND kodetransaksi='$rand'";
							#$rscm = callRS($qcm);
							callRS($rscm, $qcm);
							if (count($rscm)!=0) {
								cout('<div class="special-box">');
									cout('<div class="panel panel-success text-center greet" style="margin:10px 0;">');
										cout('<div class="panel-heading">Pendaftaran Deposit Anda berhasil!</div>');
									cout('</div><!-- /.panel -->');
									
									cout('<div>Silahkan tunggu 3-5 menit, sementara deposit Anda kami proses. Anda akan menerima SMS begitu Deposit Anda telah kami proses.</div>');
									cout('<div>Pastikan Anda telah mentransfer-kan deposit Anda kepada kami.</div>');
									cout('<br/>');
									cout('<div class="acenter">');
										cout('Setelah Anda men-transfer deposit, silahkan isi form deposit (<a href="'.absDom.'/deposit" target="_blank">'.absDom.'/deposit</a>) dan tunggu 1-3 menit,');
										cout('<br/>maka kredit akan otomatis ditambahkan ke Username dan Anda sudah bisa mulai bermain.');
									cout('</div>');
								cout('</div>');
							} else {
								cout('<div class="special-box">');
									cout('<div class="panel panel-danger text-center greet" style="margin:10px 0;">');
										cout('<div class="panel-heading">Pendaftaran Deposit Anda Mengalami Kesalahan!</div>');
									cout('</div><!-- /.panel -->');
									
									cout('<div>Silahkan mencoba kembali pendaftaran deposit Anda di: <a href="'.absDom.'/deposit">Deposit</a></div>');
									cout('<div>Apabila mengalami kendala atau kesulitan, Anda dapat menghubungi Customer Service Online kami.</div>');
									
									cout('<div>Silahkan menghubungi Customer Service kami untuk informasi lebih lanjut.</div>');
									cout('<div>Anda juga akan kami bantu sepenuhnya apabila Anda mengalami kesulitan lainnya.</div>');
								cout('</div>');
							}
						} else {
							cout('<div class="multi-3">');
								cout('<form method="post" action="" role="form">');
									cout('<input type="hidden" name="kirim" id="kirim" value="1" />');
									
									cout('<div class="row am-theme-row">');
										cout('<div class="col-xs-5 col-md-3"><label for="igame">Games</label></div><!-- /.col-xs-5 col-md-3 -->');
										cout('<div class="col-xs-7 col-md-9">');
											$terr = $err["igame"]!=""?' err ':'';
											cout('<div><select class="form-control field '.$terr.'" name="igame" id="igame">');
												cout('<option value="">- Pilih Permainan Anda -</option>');
												$rsx=array(); $qx="SELECT * FROM games WHERE isactive=1";
												#$rsx = callRS($qx);
												callRS($rsx, $qx);
												for ($x=0;$x<count($rsx);$x++) {
													$sel = intval($rsx[$x]["kdgame"])==intval($igame)?'selected="selected"':'';
													cout('<option value="'.$rsx[$x]["kdgame"].'" '.$sel.'>'.strtoupper($rsx[$x]["nama"]).'</option>');
												}
											cout('</select></div>');
											if ($err["igame"]!="") { cout('<div class="alert alert-danger"><a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>'.$err["igame"].'</div>'); }
										cout('</div><!-- /.col-sm-9 -->');
									cout('</div><!-- /.row -->');
									
									cout('<div class="row am-theme-row">');
										cout('<div class="col-xs-5 col-md-3"><label for="iusername">UserID</label></div><!-- /.col-sm-3 -->');
										cout('<div class="col-xs-7 col-md-9">');
											$terr = $err["iusername"]!=""?' err ':'';
											cout('<div><input class="form-control field '.$terr.'" name="iusername" id="iusername" value="'.$iusername.'" placeholder="Masukkan Username Anda" /></div>');
											if ($err["iusername"]!="") { cout('<div class="alert alert-danger"><a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>'.$err["iusername"].'</div>'); }
										cout('</div><!-- /.col-sm-9 -->');
									cout('</div><!-- /.row -->');
									
									cout('<div class="row am-theme-row">');
										cout('<div class="col-xs-5 col-md-3"><label for="ibank">Bank</label></div><!-- /.col-sm-3 -->');
										cout('<div class="col-xs-7 col-md-9">');
											$terr = $err["ibank"]!=""?' err ':'';
											cout('<div><select class="form-control field '.$terr.'" name="ibank" id="ibank">');
												cout('<option value="">- Pilih Rekening Anda -</option>');
												$rsx=array(); $qx="SELECT * FROM banks WHERE isactive=1";
												#$rsx = callRS($qx);
												callRS($rsx, $qx);
												for ($x=0;$x<count($rsx);$x++) {
													$sel = intval($rsx[$x]["kdbank"])==intval($ibank)?'selected="selected"':'';
													cout('<option value="'.$rsx[$x]["kdbank"].'" '.$sel.'>'.$rsx[$x]["inisial"].' - '.$rsx[$x]["namabank"].'</option>');
												}
											cout('</select></div>');
											if ($err["ibank"]!="") { cout('<div class="alert alert-danger"><a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>'.$err["ibank"].'</div>'); }
										cout('</div><!-- /.col-sm-9 -->');
									cout('</div><!-- /.row -->');
									
									cout('<div class="row am-theme-row">');
										cout('<div class="col-xs-5 col-md-3"><label for="inorek">Nomor Rekening</label></div><!-- /.col-sm-3 -->');
										cout('<div class="col-xs-7 col-md-9">');
											$terr = $err["inorek"]!=""?' err ':'';
											cout('<div><input class="form-control field '.$terr.'" name="inorek" id="inorek" value="'.$inorek.'" placeholder="Masukkan Nomor Rekening Anda" maxlength="15" /></div>');
											if ($err["inorek"]!="") { cout('<div class="alert alert-danger"><a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>'.$err["inorek"].'</div>'); }
										cout('</div><!-- /.col-sm-9 -->');
									cout('</div><!-- /.row -->');
									
									cout('<div class="row am-theme-row">');
										cout('<div class="col-xs-5 col-md-3"><label for="inamarek">Nama Pemilik Rekening</label></div><!-- /.col-sm-3 -->');
										cout('<div class="col-xs-7 col-md-9">');
											$terr = $err["inamarek"]!=""?' err ':'';
											cout('<div><input class="form-control field '.$terr.'" name="inamarek" id="inamarek" value="'.$inamarek.'" placeholder="Masukkan Nama Pemilik Rekening Anda" /></div>');
											if ($err["inamarek"]!="") { cout('<div class="alert alert-danger"><a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>'.$err["inamarek"].'</div>'); }
										cout('</div><!-- /.col-sm-9 -->');
									cout('</div><!-- /.row -->');
									
									cout('<div class="row am-theme-row">');
										cout('<div class="col-xs-5 col-md-3"><label for="inilai">Nominal</label></div><!-- /.col-sm-3 -->');
										cout('<div class="col-xs-7 col-md-9">');
											$terr = $err["inilai"]!=""?' err ':'';
											cout('<div><input class="form-control field '.$terr.'" name="inilai" id="inilai" value="'.$inilai.'" placeholder="Masukkan Nominal Deposit Anda" /></div>');
											if ($err["inilai"]!="") { cout('<div class="alert alert-danger"><a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>'.$err["inilai"].'</div>'); }
										cout('</div><!-- /.col-sm-9 -->');
									cout('</div><!-- /.row -->');
									
									cout('<div class="row am-theme-row">');
										cout('<div class="col-xs-5 col-md-3"><label for="ival">Validasi</label></div><!-- /.col-sm-3 -->');
										cout('<div class="col-xs-7 col-md-9">');
											cout('<div class="row">');
												cout('<div class="col-xs-7 col-md-2">');
													cout('<img class="captcha-main-image" src="/gfx/captcha/'.rand(1000000000,9999999999).'.gif/captcha_order" alt="Security Code" />');
												cout('</div><!-- /.col-sm-2 -->');
												cout('<div class="col-xs-5 col-md-10">');
													$terr = $err["ival"]!=""?' err ':'';
													cout('<div><input class="form-control field '.$terr.'" name="ival" id="ival" value="'.$ival.'" size="6" maxlength="6" placeholder="Masukkan Kode Validasi" /></div>');
													if ($err["ival"]!="") { cout('<div class="alert alert-danger"><a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>'.$err["ival"].'</div>'); }
												cout('</div><!-- /.col-sm-10 -->');
											cout('</div><!-- /.row -->');
										cout('</div><!-- /.col-sm-9 -->');
									cout('</div><!-- /.row -->');
									cout('<div class="row">');
										cout('<div class="col-sm-12 text-center">');
											cout('<input class="fbutt button" type="submit" value="Deposit" />');
										cout('</div><!-- /.col-sm-12 -->');
									cout('</div><!-- /.row -->');
									cout('<br/><br/>');
								cout('</form>');
							cout('</div><!-- /.multi-3 -->');
							
							cout('<div class="row for-footer">');
								$rsr=array(); $qr="SELECT * FROM cara_main WHERE LOWER(judul) LIKE '%deposit%'";
								callRS($rsr, $qr);
								$isi = str_replace("\n", "<br/>", $rsr[0]["isi"]);
								$isi = str_replace("[h5]", '<h5 class="small text-warning">', $isi);
								$isi = str_replace("[/h5]", '</h5>', $isi);
								$isi = str_replace("[p]", '<p>', $isi);
								$isi = str_replace("[/p]", '</p>', $isi);
								$isi = str_replace('style="font-size:x-small;"', '', $isi);
								$isi = str_replace('style="font-size: x-small;"', '', $isi);
								cout('<div class="special-box">');
									cout($isi);
								cout('</div><!--/.special-box-->');
							cout('</div><!--/.row for-footer-->');
						}
						
					cout('</div><!--/.real-content-->');
				cout('</div><!--/.content-->');
			cout('</div><!--/.special-box-->');
			
		cout('</div><!--/.container for-footer-->');
	cout('</div><!--/.container-fluid-->');
	
require(root."/_tpl/body_close.php");
?>