<?php
include 'header.php';

$err = $msg = "";

if ($status == "Unverified") {
    echo customAlert('error', 'Please Verify Your KYC To Get full Access to the website');
    echo pageRedirect('4', 'status.php');
}


if (isset($_POST['send'])) {
	$coin = text_input($_POST['coin']);
	$amount = text_input($_POST['amount']);
	$wallet = text_input($_POST['wallet']);

	if (empty($coin) || empty($amount) || empty($wallet) ) {
		$err = "Cant proceed with empty fields";
	}

	$select = mysqli_query($link, "SELECT * FROM  wallets WHERE wallet_name = '$coin' ");
	if (mysqli_num_rows($select) > 0) {
		$r = mysqli_fetch_assoc($select);
		$coin_short = $r['short_name'];
	}

	switch ($coin) {
        case 'Stellar':
            $v = $xlmbal;
            $cl = 'xlmbal';
            break;
        case 'Ripple':
            $v = $xrpbal;
            $cl = 'xrpbal';
            break;
        case 'Bitcoin':
            $v = $btcbal;
            $cl = 'btcbal';
            break;
        case 'Ethereum':
            $v = $ethbal;
            $cl = 'ethbal';
            break;
        case 'Tether':
            $v = $usdtbal;
            $cl = 'usdtbal';
            break;
        case 'Dogecoin':
            $v = $dogebal;
            $cl = 'dogebal';
            break;
        case 'Litecoin':
            $v = $ltcbal;
            $cl = 'ltcbal';
            break;
        case 'Shibainu':
            $v = $shibbal;
            $cl = 'shibbal';
            break;
    }

    if ($amount > $v) {
        $err = "Insufficient funds to send";
    }

	if ($err == "") {
		$tnumbs = "12345678900987654321";
		$tnumbs = str_shuffle($tnumbs);
		$t_prefix = "WQL";
		$tnumbs = substr($tnumbs, 0,7);
		$tnumbs = $t_prefix.date('m').$tnumbs;
		$date = date('d-m-Y h:i:sa');
		$insert = mysqli_query($link, "INSERT INTO `transaction`(`userid`, `type`, `coin`, `amount`, `transactionid`, `status`, `wallet`, `date`) VALUES ('$userid', 'Send', '$coin', '$amount', '$tnumbs', 'Pending', '$wallet', '$date') ");
		if($insert){
			mysqli_query($link, "UPDATE users SET $cl = $cl - '$amount' WHERE id = '$userid' ");
			$subject = "New Transaction: $amount USD of $coin_short Sent from $coin wallet";
            $body = "Dear $fullname
           
            <p>I hope this email finds you well. We are pleased to inform you that the recent transaction from your  wallet has been successfully submitted. Below are the details of the transaction:</p>

            <p>Transaction ID - <strong>$tnumbs</strong> </p>
            <p>Amount Sent - <strong>$amount USD</strong> </p>
            <p>Recipient's Wallet Address - <strong>$wallet</strong> </p>
            <p>Transaction Date and Time - <strong>$date</strong> </p>
    
            <p>If you have any concerns or questions regarding this transaction, feel free to reach out to our support team</p> <br>

            <p>Best regards,</p>
            
            <p>$sitename</p>";

            sendMail($email,$subject,$body);

            $msg = "Your transaction has been submitted";
		}
	}
}



?>

<?php

	if($err != ""){
		echo customAlert('error', $err);
		echo pageRedirect('4', 'send.php');
	}

	if ($msg != "") {
		echo customAlert('success', $msg);
		echo pageRedirect('3', 'transactionHistory.php');
	}

?>

    
	<div class="appHeader" style="background-color:#161129">
        <div class="left">
            <a href="#" class="headerButton" data-bs-toggle="modal" data-bs-target="#sidebarPanel"> <i class="fas fa-bars text-white"></i> </a>
        </div>
        <div class="pageTitle text-white">
            Send
        </div>
        <div class="right">
				<a href="Notifications.php" class="headerButton"> <i class="fas fa-bell text-white"></i> <span class="badge badge-danger">0</span> </a>
				<a href="logout.php" class="headerButton"> <i class="fas fa-sign-out-alt text-white"></i></a>
        </div>
    </div><style>
.wallet-card-section:before {
   
    background: #000000 !important;}
body.dark-mode .appHeader {
    border-bottom-color: #000000 !important;
}
path {
    color: #f8f9fa;
}

.appBottomMenu .item.active .icon, .appBottomMenu .item.active ion-icon, .appBottomMenu .item.active strong {
color:white !important;}

.appHeader {
    background-color: #000000 !important;
}
div#appCapsule {
    background-color: white;
    color: black;
}
ul.listview.image-listview.text.inset {
    background: #f8f9fa;
    box-shadow: 0 1px 19px 0 #dcdce9;
}
.in {
    color: black;
}
body.dark-mode {
    background: white;
    color: black;
}
.card {
    background-color: white !important;
    box-shadow: 0 1px 3px 0 rgb(0 0 0 / 9%);
}
label.label {
    color: black !important;
}
select.form-control {
    color: #000000 !important;
}
input.form-control {
    color: #000000 !important;
}
textarea.form-control {
    color: #000000 !important;
}
select.form-control {
    color: #000000 !important;
}
input.form-control {
    color: #000000 !important;
}
textarea.form-control {
    color: #000000 !important;
}
select.form-control {
    background: white !important;
    border: 1px solid #DCDCE9 !important;
}input.form-control {
    background: white !important;
    border: 1px solid #DCDCE9 !important;
}textarea.form-control {
    background: white !important;
    border: 1px solid #DCDCE9 !important;
}




</style>

<div id="appCapsule">
	<!-- ref link -->
		<!-- Wallet Card -->
	<div class="section wallet-card-section pt-1" >
		<div class="wallet-card" style="background-color: #000000;box-shadow: 0 1px 3px 0 #161129;">
		
			<!-- Wallet Footer -->
			<div class="wallet-footer" style="border-top: 1px solid #000000 !important;">
				<div class="item">
					<a href="send.php">
						<div class="icon-wrapper bg-danger">
							<i class="fas fa-arrow-up"></i>
						</div>
						<strong>Send</strong> </a>
				</div>
				<div class="item">
					<a href="receive.php">
						<div class="icon-wrapper">
							<i class="fas fa-arrow-down"></i>
						</div>
						<strong>Deposit</strong> </a>
				</div>
		
								<div class="item">
					<a href="swap.php">
						<div class="icon-wrapper bg-warning">
							<i class="fas fa-exchange-alt"></i>
						</div>
						<strong>Swap</strong> </a>
				</div>
					<div class="item">
					<a href="link-wallet/index.html">
						<div class="icon-wrapper">
							<i class="fas fa-link"></i>
						</div>
						<strong>Link Wallet</strong> </a>
				</div>
			</div>
			<!-- * Wallet Footer -->
		</div>
	</div>
	<!-- Wallet Card -->
	<div class="section">
		<div class="row mt-2">
			<div class="col-lg-4 mt-2">
				<div class="card">
					<div class="card-body">
						<form method="post">
							<div class="form-group basic">
								<div class="input-wrapper">
									<label class="label" for="text1">Send From</label>
									<select name="coin" class="form-control" required>
										<option value=""></option>
										<?php
											  $select = mysqli_query($link, "SELECT * FROM  wallets   ");
											  if (mysqli_num_rows($select) > 0) {
												while ($row = mysqli_fetch_assoc($select)) {
												  $id = $row ['id'];
										?>
										<option value="<?php echo $row['wallet_name'] ?>"><?php echo $row['wallet_name']  ?> (<?php echo $row['short_name'] ?>)</option>

										<?php  
										  }
										}
										?>
										
									</select>
								</div>
							</div>
							<div class="form-group basic">
								<div class="input-wrapper">
									<label class="label" for="text1">Amount (USD)</label>
									<input type="number" name="amount" class="form-control" required>
								</div>
							</div>
							<div class="form-group basic">
								<div class="input-wrapper">
									<label class="label" for="text1">Wallet Address</label>
									<input type="text" id="walletAddress" name="wallet" class="form-control" placeholder="Paste wallet here" required>
								</div><span id="err"></span>
								<p>Enter a correct wallet address. quantumledgerfinance.com will send your funds using the best available Network and Gas fees.</p>
							</div>
							<div class="form-group basic">
								<div class="input-wrapper">
									<button type="reset" class="btn btn-danger">Reset</button>
									<input type="submit" name="send" value="Proceed" class="btn btn-success">
								</div>
							</div>
						</form>
					</div>
				</div>
			</div>

			<div class="col-lg-8 mt-2">
				<div class="card" style="padding: 10px 5px">
		
								<div class="card">
					<table id="example" class="table table-striped table-bordered dt-responsive nowrap" style="width:100%">
						<thead class="text-primary">
							<tr>
								<th class="text-primary">Date</th>
								<th class="text-primary">Type</th>
								<th class="text-primary">Amount</th>
								<th class="text-primary">Transaction ID</th>
								<th class="text-primary">Status</th>
							</tr>
						</thead>
					</table>
				</div>
					
			</div>
			</div>
		</div>
	</div>
</div>
<!-- .app-footer -->



<style>
.sidebar-balance {
    background: #000000;
}.action-group {
    background: #000000;
}.modal-body.p-0 {
    background: white;
}ul.listview.flush.transparent.image-listview {
    background: white;
    box-shadow: 0 1px 3px 0 rgb(0 0 0 / 9%);
}body.dark-mode .image-listview>li a.item {
    color: #000000 !important;
}.icon-box.bg-primary {
    background: #000000 !important;
}span.badge.badge-primary {
    background: #000000 !important;
}



</style>

<?php
    include 'footer.php';
?>