<?php
if(isset($_POST['btn-withdraw']))
{
 $amount = trim($_POST['amount']);
 $desc = trim($_POST['description']);
 $desc_name = trim($_POST['description_name']);
 $orderID = USER::Numeric(5);
 $date = date("d/m/Y");
 $stmt = $actionParam->runQuery("SELECT * FROM tbl_user WHERE userID=:id");
 $stmt->execute(array(":id"=>$uid));
 $userRow = $stmt->fetch(PDO::FETCH_ASSOC);
 $fullname = $userRow['fullname'];
 if($amount < 50)
 {
    header("Location: withdraw?withdrawal-limit");
    exit;
 }
 if($userRow['balance'] >= 50)
 {
   if($amount > $userRow['balance'])
   {
	   header("Location: withdraw?insufficient-balance");
       exit;
   }
   else
   {
	   if($actionParam->withdraw_funds($uemail,$amount,$desc,$desc_name,$orderID,$date))
       {
	        $message = "
	         <img src=  http://sescentigate.com/pip.png alt= Sescentigate><br><br>
   
                     Hello $fullname,
                     <br /><br />
                     You have successfully placed a withdrawal request of $".number_format($amount)." worth of  bitcoin. Please kindly wait for your Withdrawal to be approved and confirmed.<br>
                     Receiver: $desc<br>
                     Date sent: $date<br><br>
					           Awaiting Approval.
                     ";

                     $subject = "Withdrawal Request";
                     $email = $uemail;
                     $actionParam->send_mail_cron3($email,$message,$subject);//send mail to user
           
            $message = "
                     Hello admin,
                     <br /><br />
                     $fullname just sent $".number_format($amount)." bitcoin.<br>
                     Receiver: $desc<br>
                     Date sent: $date<br><br>
					 Please complete the transaction.
                     ";

                     $subject = "Bitcoin sent";
                     $email = 'support@sescentigate.com';
                     $actionParam->send_mail_cron3($email,$message,$subject);//send mail to user
					 
					 header("Location: withdraw?success");
                     exit;
       }
   }
 }
 else
 {
	 header("Location: withdraw?low-funds");
     exit;
 }
	
}
?>