<?php
/**
 * withdraw.php -- Withdraw page
 */

include '../inc/config.inc.php'; // Configuration

ob_start();
session_start();

//date_default_timezone_set('Africa/Lagos');

error_reporting(E_ALL);
ini_set('display_errors', 1);

if ( !isset($_SESSION['user']) || $_SESSION["loggedin"] !== true || trim($_SESSION['user']) == '' ){
header('Location: ' . $BASE_URL . 'signin');
exit;
}

// User Details
$stmt = $db_con->prepare("SELECT * FROM users WHERE id=:user_id");
$stmt->execute(array(":user_id"=>$_SESSION['user']));
$userRow = $stmt->fetch(PDO::FETCH_ASSOC);

// Get Total Balance
$userTB = $db_con->query("SELECT * FROM user_total_balance WHERE user_id='".$userRow['id']."'");
$tb = $userTB->fetch(PDO::FETCH_ASSOC);

?>

<!-- Smartsupp Live Chat script -->
<script type="text/javascript">
var _smartsupp = _smartsupp || {};
_smartsupp.key = '78f45a67c70f1dd991f5cda6475eb20920bf448d';
window.smartsupp||(function(d) {
  var s,c,o=smartsupp=function(){ o._.push(arguments)};o._=[];
  s=d.getElementsByTagName('script')[0];c=d.createElement('script');
  c.type='text/javascript';c.charset='utf-8';c.async=true;
  c.src='https://www.smartsuppchat.com/loader.js?';s.parentNode.insertBefore(c,s);
})(document);
</script>
<noscript>Powered by <a href="https://www.smartsupp.com" target="_blank">Smartsupp</a></noscript>

<!doctype html>
<html lang="en-uk">
<head>
<!-- Required meta tags -->
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta charset="utf-8">
<meta name="description" content="">
<meta name="keywords" content="investment, Forex, Trading, Bitcoin, Cryptocurrency, Global investment, Live Trade, Trading class, indics">
<meta name="author" content="Paul HubWeb & Tech">
<meta name="theme-color" content="#313131" />
<!-- Site Properties -->
<!-- jQuery library -->

<title>Withdrawal </title>
<link rel="shortcut icon" href="../img/Signals-Alert-3.png" type="image/x-icon" />
<link rel="apple-touch-icon-precomposed" href="../img/Signals-Alert-3.png" />
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="css/bootstrap.min.css">
<!-- Typography CSS -->
<link rel="stylesheet" href="css/typography.css">
<!-- Style CSS -->
<link rel="stylesheet" href="css/style.css">
<!-- Responsive CSS -->
<link rel="stylesheet" href="css/responsive.css">
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>

<!-- Bootstrap JS -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>


<style>
* {
box-sizing: border-box;
}

body {
margin: 0;
font-family: Arial, Helvetica, sans-serif;
}

.header {
overflow: none;
background-color: none;
padding: 20px 10px;
padding-left: 5px;
position: fixed;
}

/*.header a {
float: center;
width:30px;
color: #fff;
text-align: center;
padding: 12px;
text-decoration: none;
font-size: 18px; 
line-height: 25px;
border-radius: 4px;
background-color:rgb(196, 0, 0);
border-color: rgb(196, 0, 0);
}*/

.header a.logo {
font-size: 25px;
font-weight: bold;
}

/*.header a:hover {
background-color:  #010847;
color: #fff;
}*/

/*.header a.active {
background-color: dodgerblue;
color: white;
}*/

.header-center {
float: left;
}

@media screen and (max-width: 500px) {
.header a {
float: none;
display: block;
text-align: left;
}

.header-right {
float: none;
}
}
</style>

<script src="../plugins/sweetalerts/promise-polyfill.js"></script>
<link href="../plugins/sweetalerts/sweetalert.css" rel="stylesheet" type="text/css" />

<link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,600,700" rel="stylesheet" />
<style>
/*------ Google Font Style ------ */
body {font-family:'Roboto'!important;}
</style>

<script>
function noticePop( value, type ){
swal({
html: '<span style="font-size:18px!important;">'+ `${value}` +'</span>',
type: `${type}`,
timer: 4000,
showConfirmButton: false,
allowOutsideClick: false,
allowEscapeKey: false,
}).then(function(){
window.location.href = 'withdraw';
});
}

function noticeUpgrade( value ){
swal({
html: '<span style="font-size:18px!important;">'+ `${value}` +'</span>',
type: "error",
confirmButtonColor: "red",
confirmButtonText: 'Okay.',
allowOutsideClick: false,
allowEscapeKey: false,
padding: '2em'
})/*.then(function(){
window.location.href = 'withdraw';
})*/;
}
</script>

</head>
<body class="sidebar-main-active right-column-fixed">
<!-- loader Start -->
<!--<div id="loading">
<div id="loading-center">
</div>
</div>-->
<!-- loader END -->
<!-- Wrapper Start -->
<div class="wrapper">
<?php include 'navbar2.php' ?>
<!-- Page Content  -->
<div id="content-page" class="content-page" style="margin-top:80px;">
<div class="container-fluid">
<div class="row">
<div class="col-sm-12 col-lg-9">
<div class="iq-card">
<div class="iq-card">
<div class="iq-card-header d-flex justify-content-between">
<div class="iq-header-title">
<h4 class="card-title" style="font-family: 'Roboto'!important;">Withdrawal</h4>
</div>
</div>
<div class="iq-card-body">
<p style="font-size:40px;"><b>Withdrawal Method</b></p>
<form action="" method="GET" autocomplete="off" id="withdrawal-form" class="was-validated">
<div class="form-group">
<select name="withdrawalmethod" id="withdrawalMethod" class="form-control" required>
<option value="" style="font-size:30px;"><b>---Select Method---</b></option>
<option value="Bitcoin">Bitcoin</option>
<option value="Ethereum">Ethereum</option>
<option value="Litecoin">USDT</option>
<option value="BitcoinCash">BitcoinCash</option>
<option value="Skrill">Skrill</option>
<!--<option value="Paypal">Paypal</option>-->
<option value="Bank Transfer">Bank Transfer</option>
</select>
</div>
<div id="field1" class="mb-3" style="display: None;">
<label for="validationTextarea">Bitcoin Wallet</label>
<input type="text" class="form-control is-invalid" name="bitcoin_address" placeholder="BTC Wallet Address">
</div>
<div id="field2" class="mb-3" style="display: None;">
<label for="validationTextarea">Ethereum Wallet</label>
<input type="text" class="form-control is-invalid" name="ethereum_address" placeholder="Ethereum Wallet Address">
</div>
<div id="field3" class="mb-3" style="display: None;">
<label for="validationTextarea">USDT Wallet</label>
<input type="text" class="form-control is-invalid" name="litecoin_address" placeholder="USDT Wallet Address">
</div>
<div id="field4" class="mb-3" style="display: None;">
<label for="validationTextarea">BitcoinCash Wallet</label>
<input type="text" class="form-control is-invalid" name="bitcoincash_address" placeholder="BitcoinCash Wallet Address">
</div>
<div id="field5" class="mb-3" style="display: None;">
<label for="validationTextarea">Skrill Email</label>
<input type="text" class="form-control is-invalid" name="skrill_email" placeholder="Skrill Email">
</div>
<div id="field6" class="mb-3" style="display: None;">
<label for="validationTextarea">PayPal Email</label>
<input type="text" class="form-control is-invalid" name="paypal_email" placeholder="PayPal Email">
</div>
<div id="field7" class="mb-3" style="display: None;">
<label for="validationTextarea">Bank Name</label>
<input type="text" class="form-control is-invalid" name="bank_name" placeholder="Bank Name">
</div>
<div id="field8" class="mb-3" style="display: None;">
<label for="validationTextarea">Account Number</label>
<input type="text" class="form-control is-invalid" name="account_number" placeholder="Account Number">
</div>
<div id="field9" class="mb-3" style="display: None;">
<label for="validationTextarea">Country</label>
<input type="text" class="form-control is-invalid" name="country" placeholder="Country">
</div>
<div id="field10" class="mb-3" style="display: None;">
<label for="validationTextarea">Swift Code</label>
<input type="text" class="form-control is-invalid" name="swift_code" placeholder="Swift Code">
</div>
<div class="mb-3">
<label for="validationTextarea">Amount (<?= $userRow['currency']; ?>)</label>
<input type="text" class="form-control is-invalid" name="amount" placeholder="Amount without (<?= $userRow['currency']; ?>)" required>
</div>
<div class="mb-3">
</div>
<div class="form-group">
<button class="btn btn-primary" name="withdraw" type="submit">Submit form</button>
</div>
</form>
<!-- Button trigger modal -->
<!-- <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#taxCodeModal">
Launch tax code modal
</button> -->

<!-- Modal -->
<div class="modal fade" id="taxCodeModal" tabindex="-1" role="dialog" aria-labelledby="taxCodeModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="taxCodeModalLabel">Pay network fees</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<form id="RegisterForm" method="post">
<div id="result"></div>
<div class="form-group">
<label for="taxCodeInput"></label>
<input type="text" name="taxCodeInput" class="form-control" id="taxCodeInput" placeholder="contact system admin">
<input type="hidden" name="amount" value="<?php  echo $_GET["amount"] ?>">

</div>
</f>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary" t>i</button>
</div>
</div>
</div>
</div>

<?php
if ( isset($_GET['withdraw']) ){
error_reporting(E_ALL);

$withdrawalmethod = $_GET['withdrawalmethod'];
$amount = $_GET['amount'];
$fees = $_GET['fees'];
$narration = $_GET['narration'];
$time = date('H:i:s');
$date = date('Y/m/d');
$created = date('Y-m-d H:i:s');
?>

<?php
$checkPlanStatus = 'No';
$checkPlans = $db_con->query(
"SELECT up.up_id, up.plan_name, upfr.upfr_id, upfr.up_id, upfr.user_id, upfr.allow_withdraw
FROM user_upgrade_plans up 
INNER JOIN user_upgrade_plans_feerequest upfr
ON up.up_id=upfr.up_id
WHERE upfr.user_id='".$userRow['id']."' AND up.publish='Yes'"
);
$checkPlan = $checkPlans->fetchAll();
if ( $checkPlans->rowCount() > 0 ){ // user has at least one plan
foreach ( $checkPlan as $chkPlan ){
if ( ($chkPlan['plan_name'] == $userRow['current_plan']) AND ($chkPlan['allow_withdraw'] == 'No') ){ // plan in "fee requests" table matches plan in "users" table. also user is allowed to withdraw
$checkPlanStatus = 'Yes';
}
}
}

if ( $checkPlanStatus == 'Yes' ){
?>
<script>
setTimeout(function(){
noticeUpgrade('Please upgrade account. Funds on your account has exceeded your current plan. Contact system admin');
}, 1000);
</script>
<?php
}
else {
//if ( $userRow['status'] != 'Active' ){ // account has not been verified
if ( $userRow['allow_withdraw'] == 'No' ){ // user cannot withdraw
?>
<script>
setTimeout(function(){
//noticePop('commission fees not paid, contact system admin.', 'error');
noticePop('Commission fees not paid, contact system admin', 'error');
}, 2000);
</script>
<?php
}
elseif ( $amount > $tb['current_balance'] ){ // insufficient funds
?>
<script>
setTimeout(function(){
noticePop('Insufficient Funds', 'error');
}, 2000);
</script>
<?php
}
else {

if ( $withdrawalmethod == 'Bitcoin' ){
$bitcoin_address = $_GET['bitcoin_address'];
if ( empty($bitcoin_address) ){
?>
<script>
setTimeout(function(){
noticePop('Bitcoin Address Cannot Be Left Empty', 'error');
}, 2000);
</script>
<?php
} else {
$narration = $narration .'\n<br>-----\n<br>Bitcoin Address: '. $bitcoin_address .'\n<br>Fee: '. $fees;
}
}
elseif ( $withdrawalmethod == 'Ethereum' ){
$ethereum_address = $_GET['ethereum_address'];
if ( empty($ethereum_address) ){
?>
<script>
setTimeout(function(){
noticePop('Ethereum Address Cannot Be Left Empty', 'error');
}, 2000);
</script>
<?php
} else {
$narration = $narration .'\n<br>-----\n<br>Ethereum Address: '. $ethereum_address .'\n<br>Fee: '. $fees;
}
}
elseif ( $withdrawalmethod == 'Litecoin' ){
$litecoin_address = $_GET['litecoin_address'];
if ( empty($litecoin_address) ){
?>
<script>
setTimeout(function(){
noticePop('LiteCoin Address Cannot Be Left Empty', 'error');
}, 2000);
</script>
<?php
} else {
$narration = $narration .'\n<br>-----\n<br>LiteCoin Address: '. $litecoin_address .'\n<br>Fee: '. $fees;
}
}
elseif ( $withdrawalmethod == 'BitcoinCash' ){
$bitcoincash_address = $_GET['bitcoincash_address'];
if ( empty($bitcoincash_address) ){
?>
<script>
setTimeout(function(){
noticePop('BitcoinCash Address Cannot Be Left Empty', 'error');
}, 2000);
</script>
<?php
} else {
$narration = $narration .'\n<br>-----\n<br>BitcoinCash Address: '. $bitcoincash_address .'\n<br>Fee: '. $fees;
}
}
elseif ( $withdrawalmethod == 'Skrill' ){
$skrill_email = $_GET['skrill_email'];
if ( empty($skrill_email) ){
?>
<script>
setTimeout(function(){
noticePop('Skrill Email Cannot Be Left Empty', 'error');
}, 2000);
</script>
<?php
} else {
$narration = $narration .'\n<br>-----\n<br>Skrill Email: '. $skrill_email .'\n<br>Fee: '. $fees;
}
}
elseif ( $withdrawalmethod == 'Paypal' ){
$paypal_email = $_GET['paypal_email'];
if ( empty($skrill_email) ){
?>
<script>
setTimeout(function(){
noticePop('PayPal Email Cannot Be Left Empty', 'error');
}, 2000);
</script>
<?php
} else {
$narration = $narration .'\n<br>-----\n<br>PayPal Email: '. $paypal_email .'\n<br>Fee: '. $fees;
}
}
elseif ( $withdrawalmethod == 'Bank Transfer' ){
$bank_name = $_GET['bank_name'];
$account_number = $_GET['account_number'];
$country = $_GET['country'];
$swift_code = $_GET['swift_code'];
if ( empty($bank_name) || empty($account_number) || empty($country) || empty($swift_code) ){
?>
<script>
setTimeout(function(){
noticePop('All Bank Details Must Be Filled', 'error');
}, 2000);
</script>
<?php
} else {
$narration = $narration .'\n<br>-----\n<br>Bank Name: '. $bank_name .'\n<br>Account Number: '. $account_number .'\n<br>Country: '. $country .'\n<br>Swift Code: '. $swift_code .'\n<br>Fee: '. $fees;
}
}
$insert = "INSERT INTO user_transactions(user_id, fullname, type, method, amount, narration, time, date, created) VALUES ('".$userRow['id']."', '".$userRow['fullname']."', 'Withdrawal', '$withdrawalmethod', '$amount', '$narration', '$time', '$date', '$created')";

if ( $db_con->exec($insert) ){
?>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>

<!-- Bootstrap JS -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>

<script>
$('#taxCodeModal').modal('show');
</script>
<?php
  } else {
    ?>
    <script>
    setTimeout(function(){
    noticePop('Something Went Wrong. Try again.', 'error');
    }, 2000);
    </script>
    <?php
    }
}

}
}
 
?>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- Wrapper END -->
<?php include 'footer.php' ?>
<!-- Optional JavaScript -->
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="../plugins/jquery-3.1.1.min.js"></script>
<script src="../plugins/sweetalerts/sweetalert2.min.js"></script>
<script src="https://unpkg.com/@popperjs/core@2/dist/umd/popper.js"></script>

<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<!--<script src="js/jquery.min.js"></script>
<script src="js/popper.min.js"></script>-->
<script src="js/bootstrap.min.js"></script>
<!-- Appear JavaScript -->
<script src="js/jquery.appear.js"></script>
<!-- Countdown JavaScript -->
<script src="js/countdown.min.js"></script>
<!-- Counterup JavaScript -->
<script src="js/waypoints.min.js"></script>
<script src="js/jquery.counterup.min.js"></script>
<!-- Wow JavaScript -->
<script src="js/wow.min.js"></script>
<!-- Apexcharts JavaScript -->
<script src="js/apexcharts.js"></script>
<!-- Slick JavaScript -->
<script src="js/slick.min.js"></script>
<!-- Select2 JavaScript -->
<script src="js/select2.min.js"></script>
<!-- Owl Carousel JavaScript -->
<script src="js/owl.carousel.min.js"></script>
<!-- Magnific Popup JavaScript -->
<script src="js/jquery.magnific-popup.min.js"></script>
<!-- Smooth Scrollbar JavaScript -->
<script src="js/smooth-scrollbar.js"></script>
<!-- lottie JavaScript -->
<script src="js/lottie.js"></script>
<!-- am core JavaScript -->
<script src="js/core.js"></script>
<!-- am charts JavaScript -->
<script src="js/charts.js"></script>
<!-- am animated JavaScript -->
<script src="js/animated.js"></script>
<!-- am kelly JavaScript -->
<script src="js/kelly.js"></script>
<!-- am maps JavaScript -->
<script src="js/maps.js"></script>
<!-- am worldLow JavaScript -->
<script src="js/worldLow.js"></script>
<!-- Style Customizer -->
<script src="js/style-customizer.js"></script>
<!-- Chart Custom JavaScript -->
<script src="js/chart-custom.js"></script>
<!-- Custom JavaScript -->
<script src="js/custom.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$("#withdrawalMethod").change(function() {
if ($(this).val() == "Bitcoin") {
$("#field1").fadeIn();
$("#field2").hide();
$("#field3").hide();
$("#field4").hide();
$("#field5").hide();
$("#field6").hide();
$("#field7").hide();
$("#field8").hide();
$("#field9").hide();
$("#field10").hide();
$("#field11").hide();
$('#wallet-number').attr("placeholder", "Bitcoin");
$('#amount-fees').val('2%')

} else if ($(this).val() == "Ethereum") {
$("#field2").fadeIn();
$("#field1").hide();
$("#field3").hide();
$("#field4").hide();
$("#field5").hide();
$("#field6").hide();
$("#field7").hide();
$("#field8").hide();
$("#field9").hide();
$("#field10").hide();
$("#field11").hide();
$('#wallet-number').attr("placeholder", "Ethereum");
$('#amount-fees').val('4%')
} else if ($(this).val() == "Litecoin") {
$("#field3").fadeIn();
$("#field1").hide();
$("#field2").hide();
$("#field4").hide();
$("#field5").hide();
$("#field6").hide();
$("#field7").hide();
$("#field8").hide();
$("#field9").hide();
$("#field10").hide();
$("#field11").hide();
$('#wallet-number').attr("placeholder", "Litecoin");
$('#amount-fees').val('4%')
} else if ($(this).val() == "BitcoinCash") {
$("#field4").fadeIn();
$("#field1").hide();
$("#field2").hide();
$("#field3").hide();
$("#field5").hide();
$("#field6").hide();
$("#field7").hide();
$("#field8").hide();
$("#field9").hide();
$("#field10").hide();
$("#field11").hide();
$('#wallet-number').attr("placeholder", "BitcoinCash");
$('#amount-fees').val('4%')
} else if ($(this).val() == "Skrill") {
$("#field5").fadeIn();
$("#field1").hide();
$("#field2").hide();
$("#field3").hide();
$("#field4").hide();
$("#field6").hide();
$("#field7").hide();
$("#field8").hide();
$("#field9").hide();
$("#field10").hide();
$("#field11").hide();
$('#wallet-number').attr("placeholder", "Skrill");
$('#amount-fees').val('3%')
} else if ($(this).val() == "Paypal") {
$("#field6").fadeIn();
$("#field1").hide();
$("#field2").hide();
$("#field3").hide();
$("#field4").hide();
$("#field5").hide();
$("#field7").hide();
$("#field8").hide();
$("#field9").hide();
$("#field10").hide();
$("#field11").hide();
$('#wallet-number').attr("placeholder", "Paypal");
$('#amount-fees').val('2%')
} else if ($(this).val() == "Bank Transfer") {
$("#field7").fadeIn();
$("#field8").fadeIn();
$("#field9").fadeIn();
$("#field10").fadeIn();
$("#field11").fadeIn();
$("#field1").hide();
$("#field2").hide();
$("#field3").hide();
$("#field4").hide();
$("#field5").hide();
$("#field6").hide();
$('#wallet-number').attr("placeholder", "Bank Transfer");
$('#amount-fees').val('5%')
} else {
$("#field1").hide();
$("#field2").hide();
$("#field3").hide();
$("#field4").hide();
$("#field5").hide();
$("#field6").hide();
$("#field7").hide();
$("#field8").hide();
$("#field9").hide();
$("#field10").hide();
$("#field11").hide();
}
});

$("#amount-gram").keyup(function() {
//var usd = this.val();
var usd = $("#amount-gram").val();
//var course = '2.0682345991368067';
var course = '0.00011';
$("#amount-usd").val(usd * course);
});


});


</script>
<script src="change.js"></script>
</body>
</html>