<?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 == 'starter'){
     if($amount < 50 || $amount > 9999){
         header("Location: invest?starter-error");
    exit; 
     }
 }elseif($plan == 'premium'){
     if($amount < 10000 || $amount > 99999){
         header("Location: invest?premium-error");
    exit; 
     }
 }elseif($plan == 'hedgefund'){
     if($amount < 500000 || $amount > 3000000){
         header("Location: invest?hedgefund-error");
    exit; 
     }
     
 }elseif($plan == 'trial'){
     if($amount < 999 || $amount > 300000){
         header("Location: invest?trial-error");
    exit; 
     }
     
 }elseif($plan == 'nfp'){
     if($amount < 50000 || $amount > 1000000){
         header("Location: invest?nfp-error");
    exit; 
     }
     
 }elseif($plan == 'nfpp'){
     if($amount < 250000 || $amount > 1000000){
         header("Location: invest?nfpp-error");
    exit; 
     }
     
 }elseif($plan == 'fomc'){
     if($amount < 25000){
         header("Location: invest?fomc-error");
    exit; 
     }
 } elseif($plan == 'spot'){
     if($amount < 100000){
         header("Location: invest?spot-error");
    exit; 
     }
 }
    

 if($amount < 50)
 {
    header("Location: invest?invalid");
    exit; 
 }
    
 if($userRow['balance'] >= 50)
 {
   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://sescentigate.com/pip.png alt= Sescentigate><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>
                     Sescentigate 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;
 }
	
}
?>