<?php
include("functions.php");
include("connect.php");
include("userdata.php");
/*echo "
<script>
 var timerInterval;
    Swal.fire({
      title: 'Auto close alert!',
      html: 'I will close in <b></b> milliseconds.',
      timer: 2000,
      timerProgressBar: true,
      onBeforeOpen: function onBeforeOpen() {
        Swal.showLoading();
        timerInterval = setInterval(function () {
          Swal.getContent().querySelector('b').textContent = Swal.getTimerLeft();
        }, 100);
      },
      onClose: function onClose() {
        clearInterval(timerInterval);
      }
    }).then(function (result) {
      if (
    
      result.dismiss === Swal.DismissReason.timer) {
        console.log('I was closed by the timer'); // eslint-disable-line
      }
    });
    e.preventDefault();
    </script>
";*/

 if (isset($_POST)) {
	$amount = isset($_POST["amount"]) ? trim($_POST["amount"]) : "";

	if ($amount === "" || !is_numeric($amount) || (float)$amount <= 0) {
		usleep(2400000);
		echo "
             <script>
              toastr.error('Enter a valid transfer amount', 'Invalid amount', {\"progressBar\": true});
              document.getElementById('amount').style.borderColor='red';
             </script>
             
            ";
            die();
	}

	$amount = round((float)$amount, 2);

	if ($amount > $accountbalance) {
	usleep(2500000);
	 echo  "
             <script>
              toastr.error('Your balance is $money $accountbalance', 'Insufficient account balance', {\"progressBar\": true});
             </script>
             
            ";
            die();

	}
  if ($allowtransfer == 0 && $blocktransfer == 0) {
    echo "<script>
               Swal.fire('Transaction restricted', '$rest_msg', 'error');
         </script>"; 
  }
	else {
		 $transferSession = randomString(64);
		 $_SESSION['transaction_session'] = $transferSession;
		 $_SESSION['amount']= $amount;
		 ?>
         <meta http-equiv="refresh" content="3; url=transfer.php?transaction_session=<?php echo $transferSession ?>">
		 <?php
	}
}

?>