<?php 
include ('database.php');
session_start();

if(isset($_POST['submit']));
{
    
    $id = mysqli_real_escape_string($connection, $_POST['id']);
	$occupation = mysqli_real_escape_string($connection, $_POST['occupation']);
	$company = mysqli_real_escape_string($connection, $_POST['company']);
    $companylocation = mysqli_real_escape_string($connection, $_POST['companylocation']);
	$loantype = mysqli_real_escape_string($connection, $_POST['loantype']);
	 $loanamount = mysqli_real_escape_string($connection, $_POST['loanamount']);
	$loanlength = mysqli_real_escape_string($connection, $_POST['loanlength']);
	$marital = mysqli_real_escape_string($connection, $_POST['marital']);
	$downpayment = mysqli_real_escape_string($connection, $_POST['downpayment']);
    $ncosigner = mysqli_real_escape_string($connection, $_POST['ncosigner']);
	$coccupation = mysqli_real_escape_string($connection, $_POST['coccupation']);
	$comment = mysqli_real_escape_string($connection, $_POST['comment']);
    $place = mysqli_real_escape_string($connection, $_POST['place']);
    $notification = "Loan Application";
	$icon= "cash-outline";
	$icolor= "bg-secondary";
	$status="Under Going Review";
	$scolor="text-warning";
	$amount= $_POST['loanamount'];
	$acolor= "text-warning";
	$avalue= "+$";
	
   $verify_query = "SELECT identification, id FROM users WHERE id='$id' LIMIT 1";
   $verify_query_run = mysqli_query($connection, $verify_query);

   if(mysqli_num_rows($verify_query_run) > 0)
   {
      $row = mysqli_fetch_array($verify_query_run);
      if($row['identification'] == "1")
      {
  
     $query = "INSERT INTO `loan` (`id`, `occupation`, `company`, `companylocation`, `loantype`, `loanamount`, `loanlength`, `marital`, `downpayment`, `ncosigner`, `coccupation`, `comment`, `place`) VALUES ('$id', '$occupation', '$company', '$companylocation', '$loantype', '$loanamount', '$loanlength', '$marital', '$downpayment', '$ncosigner', '$coccupation', '$comment', '$place')";
     $query_run = mysqli_query($connection, $query);
    if($query_run)
    {
	$notification_query = "INSERT INTO `notifications` (id, notification, icon, icolor, status, scolor, amount, acolor, avalue) VALUES ('$id', '$notification', '$icon', '$icolor', '$status', '$scolor', '$amount', '$acolor', '$avalue')";
     $notification_query_run = mysqli_query($connection, $notification_query);	
	 $_SESSION['id'] = $id;
	 $_SESSION['status'] = "<h5 style='padding:8px; background: #1a1849; border-radius: 10px; color: #fff; text-align: center;'>Loan Application Successfully submitted. On review you will receive an email</h5>";
      
	 header("location:../loan.php"); 
 }
 else
 {
	  $_SESSION['status'] = "<h5 style='padding:8px; background: #fe8b8e; border-radius: 10px; color: #fff; text-align: center;'>Failed Upgrade account</h5>";
       
	header("location: ../loan.php");  
 }
}else{
	 $_SESSION['status'] = "<h5 style='padding:8px; background: #fe8b8e; border-radius: 10px; color: #fff; text-align: center;'>Failed Upgrade account</h5>";
       
	header("location: ../loan.php");  
}
   }
   else{
	 $_SESSION['status'] = "<h5 style='padding:8px; background: #fe8b8e; border-radius: 10px; color: #fff; text-align: center;'>Failed Upgrade account</h5>";
       
	header("location: ../loan.php");  
}
}
?>