<?php
ob_start();
(@include ('../dt_page/lic.php')) or die("<script>alert(\"You not have a license to use this script on this domain, Please contact www.primadesain.com to purchase a license.\");"."window.location = './index.php'</script>");
$lic=$license;if(!$lic){echo "<script>alert(\"You not have a license to use this script on this domain, Please contact www.primadesain.com to purchase a license.\");"."window.location = './index.php'</script>";}$svr=$_SERVER['SERVER_NAME'];$c=curl_init();curl_setopt($c,CURLOPT_URL,"http://www.primadesain.com/verifylicenses.php");curl_setopt($c,CURLOPT_TIMEOUT,30);curl_setopt($c,CURLOPT_POST,1);curl_setopt($c,CURLOPT_RETURNTRANSFER,1);$postfields='svr='.$svr.'&lic='.$lic;curl_setopt($c,CURLOPT_POSTFIELDS,$postfields);$result=curl_exec($c);if($result=="fail"){echo "<script>alert(\"You not have a license to use this script on this domain, Please contact www.primadesain.com to purchase a license.\");"."window.location = './index.php'</script>";die();}
if (basename($_SERVER['SCRIPT_FILENAME']) == basename(__FILE__)){
echo "<p align=center><br><br><br><br><br><br><font size=\"6\" color=\"#FF0000\">ILLEGAL ACCESS !!";
echo "<meta http-equiv=\"refresh\" content=\"2; url=../index.php\">";
exit();} 
?>
<?php // Your license key 
$server = $_SERVER['SERVER_NAME'];

$c = curl_init(); 
// Set the full url path to point to your verifyLicense.php on your server 
curl_setopt($c, CURLOPT_URL, "http://www.primadesain.com/verifydomains.php"); 
curl_setopt($c, CURLOPT_TIMEOUT, 30); 
curl_setopt($c, CURLOPT_POST, 1); 
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1); 

$postfields = 'svr='.$server; 
curl_setopt($c, CURLOPT_POSTFIELDS, $postfields); 
$result = curl_exec($c); 

if ($result=="fail") { 
echo "<p style='font-family:Arial, Helvetica, sans-serif; margin-top:80px; font-size:16px; line-height:180%; letter-spacing:2px;' align='center'><img src='https://primadesain.com/images/block.png' width='90' height='90' /></br></br>You not have a license to use this script on this domain,<br>Please contact us to purchase a license.<br><strong><a href='http://www.primadesain.com'>www.primadesain.com</a></strong></p><br><p style='font-family:Arial, Helvetica, sans-serif; margin-top:30px; font-size:12px; line-height:180%; letter-spacing:2px;' align='center'>&copy; 2009 - ".date ("Y")." www.primadesain.com</p>";
die(); }
?>

<?php
if($db->dataku("status", $user_session) == 0 || $db->dataku("blokir", $user_session) == 1) {
echo "<div class='alert alert-danger alert-dismissable'><button type='button' class='close' data-dismiss='alert' aria-hidden='true'></button>".$LANG["status0"]."</div>";
}else{
?>


 <?php
if (isset($_GET['page']) && $_GET['page'] == "goconvert") {

?>
<?
$kode = anti_injection($_POST['kode']);
$username = anti_injection($_POST['user']);
$amount = anti_injection($_POST['amount']);

$fee = anti_injection($_POST['fee']);
$jml_fee=($fee/100)*$amount;


$saldocwallete = $db->mybwalet($username);
$pendingcwallete = $db->mybwaletpending($username);
$jmlsaldone_c = $saldocwallete-$pendingcwallete;

if ($amount > $jmlsaldone_c) {
        header("location: ?go=wallet&result=errbalance");
		exit;
      } else {
		  
$query35 = "SELECT * FROM dataewalet2d WHERE kode='".$kode."'"; 
$result35 = mysql_query($query35);
$ceks1 = mysql_num_rows($result35);
if($ceks1){ 
header("location: ?go=convert&result=errproccess");
	exit;
} else {		  
		  

$jml_byr=$amount-$jml_fee;
$jmlfeex = rupiah($jml_fee);
$jmlrecx = rupiah($jml_byr);



$jmlconvert=$jml_byr*$nilaiconvertbalance;



		  
if (!$amount || $amount < $minconvertbalance) {
        header("location: ?go=convert&result=min");
	
      } else {



$tgl_skr = (date("Y-m-d"));
			$dtfromnya = "$tgl_skr 00:00:00";
			$dttonya = "$tgl_skr 23:59:59";
  $cekjmlah=mysql_query("select SUM(jumlah) from dataewalet2d where username='$username' and (tgl between '$dtfromnya' and '$dttonya')");
	
	                 while($rowcekjumlah=mysql_fetch_row($cekjmlah)) {
		             $totconv = $rowcekjumlah[0];
		             $tothariini = $rowcekjumlah[0]+$amount;
		             }
if ($tothariini > $maxconvertbalance) {
        header("location: index.php?go=convert&result=max&td=$totconv");
	
      } else {	  


		  

$db->insert("dataewalet2d", "", "'', '$kode', '$user_session', '$amount', '', '$user_session', '$clientdate', '1', '', '$jml_fee', '$jml_byr', '$jmlconvert'"); 

$cekadane = mysql_query("select kode from databwalet where kode='$kode'");
$ada_adane = mysql_num_rows($cekadane); 
if(!$ada_adane) {
if($fee > 0){
$db->insert("databwalet", "", "'', '$kode', '$username', '$jml_fee', 'Fee exchange to R-POINT $feeconvertbalance%', 'administrator', '$clientdate', 1, '$clientdate'"); 
}
$db->insert("databwalet", "", "'', '$kode', '$username', '$jml_byr', 'Exchange to R-POINT', 'administrator', '$clientdate', 1, '$clientdate'"); 
}
$cekadane2 = mysql_query("select kode from datacwalet where kode='$kode'");
$ada_adane2 = mysql_num_rows($cekadane2); 
if(!$ada_adane2) {
$db->insert("datacwalet", "", "'', '$kode', 'administrator', '$jmlconvert', 'Exchange from Cash Balance ".rupiah($jml_byr)."', '$username', '$clientdate', 1, '$clientdate'"); 
}

			$nama_ku = $db->dataku("nama",$username);
			$hp_ku = $db->dataku("hp",$username);
			$email_ku = $db->dataku("email",$username);
			$jumlahdepone = rupiah($amount);
			





$isimail="<a href='http://".$domain."'><img src='".$logoinvoice."' style='display:inline;outline-style:none;text-decoration:none;' /></a><br><br><br>
<p>Hello ".$nama_ku." (".$username."),</p>
<p>You have to convert Cash Balance to R-POINT Balance,</p>
<p>No: ".$kode."<br>
Amount: ".$jumlahdepone."<br>
Fee ".$fee."%: ".$jmlfeex."<br>
Convert: ".$jmlrecx."<br>
Sent To R-POINT: ".rupiah($jmlconvert)."<br>
Date: ".$tgl."<br>
Status: success<br>
</p>
<p><br><br><br>
Regards,<br>
<b>".$bisnisname."</b><br>
".$domain."<br>".$emailadmin."<br>".$hpadmin."</p>";
	   
	    $mail3 = new PHPMailer;
        $mail3->setFrom($emailadmin, $bisnisname);
        $mail3->addAddress($email_ku, $nama_ku);
	    $mail3->IsHTML(true);       
        $mail3->Subject = ''.$nama_ku.', your convert balance';
        $mail3->msgHTML($isimail);
	   // $mail3->AddAttachment("../invoice/".$invc.".pdf");      // attachment
        $mail3->send();		
	
	

 header("location: index.php?go=convert&result=success");
	exit;


}
}
	}
	  }
 
?>	












<?php } else { ?>







 <?php
 if(isset($_GET['result'])&&$_GET['result']=="success"){
echo "<div class='alert alert-success alert-dismissable'><button type='button' class='close' data-dismiss='alert' aria-hidden='true'></button>Convert balance has been successfully.</div>";
}
?>

<?php
 if(isset($_GET['result'])&&$_GET['result']=="no_pin"){
echo "<div class='alert alert-danger alert-dismissable'><button type='button' class='close' data-dismiss='alert' aria-hidden='true'></button>".LANG_FORGOT_NO_PIN."</div>";
}
?>  
 <?php
 if(isset($_GET['result'])&&$_GET['result']=="wrong_pin"){
echo "<div class='alert alert-danger alert-dismissable'><button type='button' class='close' data-dismiss='alert' aria-hidden='true'></button>".LANG_FORGOT_WRONG_PIN."</div>";
}
?>  
 <?php
 if(isset($_GET['result'])&&$_GET['result']=="pin_lock"){
echo "<div class='alert alert-danger alert-dismissable'><button type='button' class='close' data-dismiss='alert' aria-hidden='true'></button>".LANG_FORGOT_BLOCK_PIN."</div>";
}
?>  

 <?php
 if(isset($_GET['result'])&&$_GET['result']=="pin_off"){
echo "<div class='alert alert-danger alert-dismissable'><button type='button' class='close' data-dismiss='alert' aria-hidden='true'></button>".LANG_FORGOT_OFF_PIN."</div>";
}
?>
 <?php
 if(isset($_GET['result'])&&$_GET['result']=="min"){
echo "<div class='alert alert-danger alert-dismissable'><button type='button' class='close' data-dismiss='alert' aria-hidden='true'></button>Min Convert balance is ".rupiah($minconvertbalance).".</div>";
}
?>
 <?php
 if(isset($_GET['result'])&&$_GET['result']=="max"){
echo "<div class='alert alert-danger alert-dismissable'><button type='button' class='close' data-dismiss='alert' aria-hidden='true'></button>Max Convert balance is ".rupiah($maxconvertbalance).", you already exchange ".rupiah($_GET['td'])." today.</div>";
}
?>
 <?php
 if(isset($_GET['result'])&&$_GET['result']=="pending"){
echo "<div class='alert alert-danger alert-dismissable'><button type='button' class='close' data-dismiss='alert' aria-hidden='true'></button>You still have a balance Convert transaction previously pending status. Wait until the transaction is processed in order to be able to Convert balances back.</div>";
}
?>


<?php
 if(isset($_GET['result'])&&$_GET['result']=="errproccess"){
echo "<div class='alert alert-danger alert-dismissable'><button type='button' class='close' data-dismiss='alert' aria-hidden='true'></button>This transaction already proccessed before!</div>";
}
?>
 <?php
 if(isset($_GET['result'])&&$_GET['result']=="errbalance"){
$mx = $_GET['mx'];
echo "<div class='alert alert-danger alert-dismissable'><button type='button' class='close' data-dismiss='alert' aria-hidden='true'></button>Your balance is insufficient, min Convert is ".rupiah($minconvertbalance).".</div>";
}
?>
<div class="row">
                <div class="col-md-4">
                
                
				<div class="panel panel-primary ">
                        <!-- Start .panel -->
                        <div class="panel-heading">
                            <h4 class="panel-title"> Convert To R-POINT</h4>
                        </div>
                        <div class="panel-body">
               
               
               
                 <?php  if($transbalance_st == 0){ 
				 echo "<div class='alert alert-danger alert-dismissable'><button type='button' class='close' data-dismiss='alert' aria-hidden='true'></button>You still have a pending convert. Wait until your convert transaction is processed in order to be able to convert balance again.</div>";
				 $diss3=" disabled='disabled'";
}else{
	$diss3="";
}
				 
				  ?>
                                	
      <?php    
$initialex = substr(str_shuffle(str_repeat("ABEF123456789GHIJKLMNPR123456789KLEFGHILMNP123456789RRSTUVWXYZ", 46)), 22, 12);
?>           

   <?php
$sql_sp3 = mysql_query("select * from dataewalet2d where username='".$user_session."' and status='0'");
                        $ada_sp3 = mysql_num_rows($sql_sp3);
                        if($ada_sp3){	
		$stss="<div class='alert alert-danger alert-dismissable'><button type='button' class='close' data-dismiss='alert' aria-hidden='true'></button>You still have a pending convert. Wait until your convert transaction is processed in order to be able to convert balance again.</div>";
$diss=" disabled='disabled'";
		
} else {
				
$stss="";
$diss="";
}
$saldocwallete = $db->mybwalet($user_session);
$pendingcwallete = $db->mybwaletpending($user_session);
$jmlsaldone_c = $saldocwallete-$pendingcwallete;
if($jmlsaldone_c > 0){
	$stylec="";
	$rprec=rupiah($jmlsaldone_c);
	$stssc="";
$dissc="";
}else{
	$stylec="style='background-color:#B50404; color:#FFF;' disabled='disabled'";
	$rprec="No Balance";
	$stssc="<div class='alert alert-danger'><button type='button' class='close' data-dismiss='alert'><i class='icon-remove'></i></button><h4> Error!</h4><p>You not have any activation balance to transfer.</p></div>";
$dissc=" disabled='disabled'";
}
						
?>	            
      <script type="text/javascript">
 
        function isNumberKey(evt, obj) {
 
            var charCode = (evt.which) ? evt.which : event.keyCode
            var value = obj.value;
            var dotcontains = value.indexOf(".") != -1;
            if (dotcontains)
                if (charCode == 46) return false;
            if (charCode == 46) return true;
            if (charCode > 31 && (charCode < 48 || charCode > 57))
                return false;
            return true;
        }
 </script>        
	<script>
		function confirmexchange(){
      var session_valuex=document.getElementById('amount').value;
      var confirmed = confirm("Are you sure you want to convert balance " + "" + "€"+session_valuex+" to R-POINT balance?");
      return confirmed;
}
</script>  

<form method="post" id="tab2" name="transfer" action="index.php?go=convert&page=goconvert">
<input type="hidden" id="kode" name="kode" value="<?php echo $initialex; ?>"/>
<input type="hidden" id="user" name="user" value="<?php echo $user_session; ?>"/>
<input type="hidden" id="fee" name="fee" value="<?php echo $feeconvertbalance; ?>"/>
                 
	<input type='hidden' id='price' name='price' value="<?php echo $nilaiconvertbalance; ?>" readonly="true">



          <div class="controls-row">

            <label>Cash Balance</label>

            
             <?php  if($jmlsaldone_c > 0){ ?>
			<input type="text" class="form-control" style='background-color:#009F50; color:#FFF;' disabled='disabled' value="<?php echo $rprec;?>"> 
            
               <?php }else{ ?>
			<input type="text" class="form-control" style='background-color:#B50404; color:#FFF;' disabled='disabled' value="<?php echo $rprec;?>"> 
             <?php } ?>
		     
          </div>
<div class="controls-row">

            <label>Amount Convert</label>
<input type="number" class="form-control" placeholder="Enter amount convert" autocomplete="off" name="amount" id="amount" required='required' onKeyUp='cekQ();'; onkeypress="return isNumberKey(event,this)" <?php echo $diss; ?> <?php echo $dissc; ?>>
          </div>
         

          <div class="controls-row">


            <label>Total R-POINT</label>

          <input type="text" class="form-control" name="total" id="total" style='color:#333;' disabled='disabled'>

          </div>

         <?php if ($feeconvertbalance > 0){ ?> <div class="controls-row">

            <label>Fee Convert</label>
<input type="text" class="form-control" readonly="readonly" style='color:#333;' value="<?php echo $feeconvertbalance;?>%">
          </div><?php } ?>

         
 <div>

           &nbsp;

          </div>
          <div>
        
            <input type="submit" value="Submit"class="btn btn-primary" name="addbalance"<?php echo $diss3; ?><?php echo $diss4; ?>>

          </div>

        </form>
       <script language="JavaScript">
	<!--
	function roundNumber(number,decimals) {
	var newString;// The new rounded number
	decimals = Number(decimals);
	if (decimals < 1) {
		newString = (Math.round(number)).toString();
	} else {
		var numString = number.toString();
		if (numString.lastIndexOf(".") == -1) {
			numString += ".";
		}
		var cutoff = numString.lastIndexOf(".") + decimals;
		var d1 = Number(numString.substring(cutoff,cutoff+1));
		var d2 = Number(numString.substring(cutoff+1,cutoff+2));
		if (d2 >= 5) {
			if (d1 == 9 && cutoff > 0) {
				while (cutoff > 0 && (d1 == 9 || isNaN(d1))) {
					if (d1 != ".") {
						cutoff -= 1;
						d1 = Number(numString.substring(cutoff,cutoff+1));
					} else {
						cutoff -= 1;
					}
				}
			}
			d1 += 1;
		} 
		newString = numString.substring(0,cutoff) + d1.toString();
	}
	if (newString.lastIndexOf(".") == -1) {
		newString += ".";
	}
	var decs = (newString.substring(newString.lastIndexOf(".")+1)).length;
	for(var i=0;i<decimals-decs;i++) newString += "0";
	var newNumber = Number(newString);
	return newNumber;
}

function format_num(num){
		
		var res = "";
		num = num.toString();
		counter = 0;
		var c = num.indexOf('.');
		var end = num.length-1;
		if(c>-1) {
			res = ","+num.substring(c+1,c+3);
			end = c-1;
			if(res.length==2) res = res + "0";
		}
		
		
		for(var i=end;i>=0;i--){
			res = num.substring(i,i+1) + res;
			counter ++;
			if(counter%3 == 0 && i > 0)
				res = "." + res;
		}
		return res;
	}


function numbersonly(e){
		var unicode=e.charCode? e.charCode : e.keyCode
		
		if (unicode!=8 && unicode!=46){ //if the key isn't the backspace key (which we should allow)
			if (unicode<48||unicode>57) {
				var temp = document.getElementById('amount').value;
				var totalfound = 0;
				var titik = temp.indexOf('.');
				if(titik>-1){
					totalfound=1;
					var temp2 = temp.substring(temp.indexOf('.')+1,temp.length);
					if(temp2.indexOf('.')>-1) totalfound=2;
				}
				if(unicode!=46 && unicode!=37 && unicode!=39) return false; //disable key press
				if(unicode==46 && totalfound>0) return false;
			}
		}
	}

	function cekQ(){
		var temp = document.getElementById('amount').value;
		var totalfound = 0;
		var titik = temp.indexOf('.');
		if(titik>-1){
			totalfound=1;
			var temp2 = temp.substring(temp.indexOf('.')+1,temp.length);
			if(temp2.indexOf('.')>-1) totalfound=2;
		}
if(totalfound>1) temp = temp.substring(0,temp.length-1);
else if(totalfound==1 && titik==temp.length-1) temp = document.getElementById('amount').value;
		//if(totalfound>1) temp = parseFloat(document.getElementById('quant').value);
		//else if(totalfound==0) temp = parseFloat(document.getElementById('quant').value);
		//else if(totalfound==1 && titik==temp.length-1) temp = document.getElementById('quant').value;
		//else temp = parseFloat(document.getElementById('quant').value);
		//var q = parseFloat(document.getElementById('quant').value);
		var q = parseFloat(temp);
		
	var p = document.getElementById('price').value;
		if(isNaN(q)) {q = 0;temp=0;}
		if(q<0) {q = 0;temp=0;}
		document.getElementById('amount').value = temp;
		document.getElementById('total').value = '' + format_num(roundNumber(q*p,2));
	}

	
	//-->
	</script>	  
		  
        
        
                </div></div>
                   <div class="row">
                   
                   
                   	
                   </div>
                </div><!--end .col-->
                
                <div class="col-md-8">
                    <div class="panel panel-primary ">
                        <!-- Start .panel -->
                        <div class="panel-heading">
                            <h4 class="panel-title"> Convert Balance </h4>
                            <div class="panel-actions">
                                <a href="#" class="panel-action panel-action-toggle" data-panel-toggle></a>
                                <a href="#" class="panel-action panel-action-dismiss" data-panel-dismiss></a>
                            </div>
                        </div>
                        <div class="panel-body">
                                                            <div class="panel-body">
                                    <div class="table-responsive">
                                    <table id="basic-datatables" class="table table-bordered" cellspacing="0" width="100%">
                                        <thead>
                                            <tr>
					<th width="20%"><?php echo $LANG["wltransno"]?></th>
                            <th width="15%"><?php echo $LANG["date"]?></th>
							<th width="15%">Amount</th>
                            <?php if($feeconvertbalance > 0){ ?>
							<th width="15%">Fee</th>
							<th width="15%">Exchange</th>
                            <?php } ?>
							<th width="15%">Sent</th>
							<th width="7%">Status</th>
							</tr>
                                        </thead>
                                       
                                        <tbody>
                                           
<?

	
	$db->select("kode, username, jumlah, tgl, status, fee, jumlahnet, exchg", "dataewalet2d", "username='$user_session'", "tgl desc");
	
		while($row=$db->fetch_row()) {
			
			
			if(is_odd($nom) == 0) {
				$class = "tblrow_ganjil";
			} else {
				$class = "tblrow_genap";
			} 	
			if($row[4] > 0) {
				$st = "<span class='label label-success'>Done</span>";
				$style = "<font>";
			} else {
				$st = "<span class='label label-danger'>Pending</span>";
			
	   $style = "<font color='#F00000'>";
			}	
				$tt = formatgl($row[3]);
				
			
?>
     	<tr>
							<td align="center"><?php echo $style; ?><?= $row[0]; ?></font></td>
							<td align="center"><?php echo $style; ?><?= $tt; ?></font></td>
							<td align="center"><?php echo $style; ?><?= rupiah($row[2]); ?></font></td>
                            <?php if($feeconvertbalance > 0){ ?>
							<td align="center"><?php echo $style; ?><?= rupiah($row[5]); ?></font></td>
							<td align="center"><?php echo $style; ?><?= rupiah($row[6]); ?></font></td>
                            <?php } ?>
							<td align="center"><?php echo $style; ?><?= rupiah($row[7]); ?></font></td>
                          
            
							<td align="center"><?php echo $style; ?><?= $st; ?></font></td>
						  </tr> 
	 
 

	<?
	
		}
	?>

                                                                                </tbody>
                                    </table>
                                    </div>
                                </div>
<input type=hidden id='clr' value='yellow'>
                            <div class="clearfix"></div>
                        </div>
                    </div><!-- End .panel -->                       
                </div><!--end .col-->

            </div><!--end .row-->
   

   <?
   }
}
   ?>
</div>
<?php ob_flush(); ?>