<?php
if(isset($_POST['btn-invest']))
{
 $amount = trim($_POST['amount']);
 $orderID = USER::Numeric(5);
 $date = date("d/m/Y");
 $start = strtotime("now");
 $end = strtotime("+3 day");
 $plan = trim($_POST['plan']);
 $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($plan == 'basic'){
    if($amount < 500|| $amount > 999){
        header("Location: invest?basic-error");
   exit; 
    }
    
 }elseif($plan == 'standard'){
    if($amount < 1000 || $amount > 9999){
        header("Location: invest?standard-error");
   exit; 
    }

}elseif($plan == 'silver'){
    if($amount < 10000 || $amount > 49999){
        header("Location: invest?silver-error");
   exit; 
    }
}elseif($plan == 'gold'){
    if($amount < 50000 || $amount > 1000000 ){
        header("Location: invest?gold-error");
   exit; 
    }
}

 if($amount < 500)
 {
    header("Location: invest?invalid");
    exit; 
 }
    
 if($userRow['balance'] >= 500)
 {
   if($amount > $userRow['balance'])
   {
	   header("Location: invest?insufficient-balance");
       exit;
   }
   else
   {
	   if($actionParam->invest_funds($uemail,$amount,$orderID,$date,$start,$end,$plan))
       {
	        $message = "
	        <img src=  http://bitxprofits.com/pip.png alt= BitXprofits><br><br>
                     Hello $fullname,
                     <br /><br />
                     You successfully scheduled an investment of $".number_format($amount)." worth of bitcoin. You keep earning daily untill your investment plan expires. <br>
                     Date placed: $date<br><br>
                     Best Regards;<br>
                     BitXprofits Team.
                     ";

                     $subject = "Investment started";
                     $email = $uemail;
                     $actionParam->send_mail_cron3($email,$message,$subject);//send mail to user
					 
					 header("Location: invest?success");
                     exit;
       }
   }
 }
 else
 {
	 header("Location: invest?low-funds");
     exit;
 }
	
}
?>