<?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 = "Pendaftaran";
$page_id = "register";
$rand = cekpost(cleanQuery($_REQUEST["rand"]), "");
$kirim = cekpost(cleanQuery($_REQUEST["kirim"]), "");
$err = array();
if ($kirim==1) {
	$ibank = cekpost(cleanQuery($_REQUEST["ibank"]), "");
	$igame = cekpost(cleanQuery($_REQUEST["igame"]), "");
	$inorek = cekpost(cleanQuery($_REQUEST["inorek"]), "");
	$inamarek = cekpost(cleanQuery($_REQUEST["inamarek"]), "");
	$iemail = cekpost(cleanQuery($_REQUEST["iemail"]), "");
	$itelp = cekpost(cleanQuery($_REQUEST["itelp"]), "");
	$ival = cekpost(cleanQuery($_REQUEST["ival"]), "");
	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 ($iemail=="") { $err["iemail"] = 'Email harus diisi!'; }
	if ($itelp=="") { $err["itelp"] = 'Telepon 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($itelp) && $itelp!="") { $err["itelp"] = 'Telepon bukan merupakan angka!'; }
	if (!check_email_address($iemail) && $iemail!="") { $err["iemail"] = 'Email tidak valid!'; }
	if ($ival!=$_SESSION["code"] && $ival!="") { $err["ival"] = 'Kode Validasi tidak cocok!'; }
	$rsc=array();$qc="SELECT * FROM members WHERE norek='$inorek' AND kdbank='$ibank' AND kdgame='$igame' AND isdeleted=0 AND isactive=1";
	#$rsc = callRS($qc);
	callRS($rsc, $qc);
	if (count($rsc)!=0) { $err["inorek"] = 'Nomor Rekening sudah terdaftar!'; }
	if (empty($err)) {
		$isactive = 1;
		$creby = "VISITOR";
		$cretime = time();
		$kdmember = getID("members", "kdmember");
		#$tablename = "members";
		#$fieldname = "kdmember";
		#$rsGetID = callRS("SELECT MAX($fieldname) AS fieldID FROM $tablename");
		#$getID=(count($rsGetID)!=0 && $rsGetID[0]['fieldID']!=null) ?(intval($rsGetID[0]['fieldID'])+1):1;
		#$kdmember = $getID;
		#echo $kdmember;
		$tanggal_daftar = time();
		$kode_random = generateRandomString(15);
		$ip1 = get_client_ip();
		$ip2 = get_client_ip2();
		$ip3 = get_client_ip2();
		$session_id = session_id();
		do {
			$rscek = array(); $qcek = "SELECT kdmember FROM members WHERE kode_random = '$kode_random'";
			#$rscek = callRS($qcek);
			callRS($rscek, $qcek);
			if (count($rscek)!=0) {
				$flag = 0;
				$kode_random = generateRandomString(15);
			} else {
				$flag = 1;
			}
		} while($flag==0);
		$q = "INSERT INTO members (kdmember, kdgame, kdbank, norek, namarek, email, telp, isactive, tanggal_daftar, kode_random, ip1, ip2, ip3, session_id, creby, cretime) 
			VALUES ('$kdmember', '$igame', '$ibank', '$inorek', '$inamarek', '$iemail', '$itelp', '$isactive', '$tanggal_daftar', '$kode_random', '$ip1', '$ip2', '$ip3', '$session_id', '$creby', '$cretime')";
		execRS($q);
		#$q = "INSERT INTO members (kdmember, kdgame, kdbank, norek, namarek, email, telp, isactive, tanggal_daftar, kode_random, ip1, ip2, ip3, session_id, creby, cretime) 
		#	VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
		#$param = array($kdmember, $igame, $ibank, $inorek, $inamarek, $iemail, $itelp, $isactive, $tanggal_daftar, $kode_random, $ip1, $ip2, $ip3, $session_id, $creby, $cretime);
		##print_r($param);
		#$rs=callRS($q, $param);
		$kode_random = str_replace("'", "", $kode_random);
		header("Location: /daftar/thanks/$kode_random");
	}
}
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">Pendaftaran</div>');
						cout('<div class="decor decor-1"></div>');
					cout('</div>');
					cout('<div class="real-content">');
						if ($rand!="") {
							$rscm=array(); $qcm="SELECT * FROM members WHERE isactive=1 AND isdeleted=0 AND kode_random='$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 Anda Berhasil!</div>');
									cout('</div><!-- /.panel -->');
									
									cout('<div>Selamat bergabung bersama AgenVIP88 dan nikmati pelayanan yang terlatih dari kami</div>');
									cout('<div>Silahkan tunggu 1-3 menit, Anda akan menerima SMS yang berisi Username dan Password Anda</div>');
									cout('<br/>');
									cout('<div class="acenter">');
										cout('Setelah menerima UserID Anda, silahkan coba login dahulu. Pastikan Anda telah berhasil login.');
										cout('<br/>Silahkan menghubungi Customer Service kami melalui chatting untuk mendapatkan Rekening Deposit kami.');
										cout('<br/><br/>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 Anda Mengalami Kesalahan!</div>');
									cout('</div><!-- /.panel -->');
									cout('<div>Silahkan mencoba kembali pendaftaran Anda di: <a href="'.absDom.'/daftar">Daftar</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-xs-7 col-md-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-xs-7 col-md-9 -->');
									cout('</div><!-- /.row -->');
									
									cout('<div class="row am-theme-row">');
										cout('<div class="col-xs-5 col-md-3"><label for="iemail">Email</label></div><!-- /.col-sm-3 -->');
										cout('<div class="col-xs-7 col-md-9">');
											$terr = $err["iemail"]!=""?' err ':'';
											cout('<div><input class="form-control field '.$terr.'" name="iemail" id="iemail" value="'.$iemail.'" placeholder="Masukkan Email Anda" /></div>');
											if ($err["iemail"]!="") { cout('<div class="alert alert-danger"><a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>'.$err["iemail"].'</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="itelp">Nomor Telepon</label></div><!-- /.col-sm-3 -->');
										cout('<div class="col-xs-7 col-md-9">');
											$terr = $err["itelp"]!=""?' err ':'';
											cout('<div><input class="form-control field '.$terr.'" name="itelp" id="itelp" value="'.$itelp.'" placeholder="Masukkan Nomor Telepon Anda" maxlength="14" /></div>');
											if ($err["itelp"]!="") { cout('<div class="alert alert-danger"><a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>'.$err["itelp"].'</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-xs-7 col-md-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-xs-5 col-md-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="button" type="submit" value="Daftar" />');
										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 '%daftar%'";
								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><!--/.row for-footer-->');
							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");
?>