<?php
session_start();
include 'include/config.php';
if(isset($_POST['submit'])){
    $fname = $_POST['fname'];
    $lname = $_POST['lname'];
    $email = $_POST['email'];
    $ac_number = $_POST['ac_number'];
    $phone   = $_POST['phone'];
    $address = $_POST['address'];
    $password = $_POST['password'];
    $aadhar  = $_POST['aadhar'];
    $pan    = $_POST['pan'];
     $bank_account_number    = $_POST['bank_account_number'];
    
    $pimage = $_FILES['pimage']['name'];
    $pimage_tmp_name = $_FILES['pimage']['tmp_name'];
    
    $a_f_image = $_FILES['a_f_image']['name'];
    $a_f_image_tmp_name = $_FILES['a_f_image']['tmp_name'];
    
    $a_b_image = $_FILES['a_b_image']['name'];
    $a_b_image_tmp_name = $_FILES['a_b_image']['tmp_name'];
    
    $pan_image = $_FILES['pan_image']['name'];
    $pan_image_tmp_name = $_FILES['pan_image']['tmp_name'];
    
    $sign_image = $_FILES['sign_image']['name'];
    $sign_image_tmp_name = $_FILES['sign_image']['tmp_name'];
    
    $bill_image = $_FILES['bill_image']['name'];
    $bill_image_tmp_name = $_FILES['bill_image']['tmp_name'];
    
    $rent_agreement = $_FILES['rent_agreement']['name'];
    $rent_agreement_tmp_name = $_FILES['rent_agreement']['tmp_name'];
    
    $bank_statement = $_FILES['bank_statement']['name'];
    $bank_statement_tmp_name = $_FILES['bank_statement']['tmp_name'];
    
    $pass_book = $_FILES['pass_book']['name'];
    $pass_book_tmp_name = $_FILES['pass_book']['tmp_name'];
    
   $date =  $date = date("Y/m/d");
   
   $next_date = date("Y/m/d", strtotime("+1 month"));

   
   $currentMonthName = date('F');
   $nextMonthName = date('F', strtotime('+1 month'));
  // $result = mysqli_query($conn, "SELECT * FROM user WHERE a_c_number = '$ac_number'");
   
//   if(mysqli_num_rows($result) > 0) {
//       echo "<script>alert('Error: This account number already exists.');</script>";
//   //echo "<script>window.location.href='add_user.php';</script>";
//      header('Location:add_user.php');
//     }else{ 
   
    
    
                 
       
    //   $insertt = mysqli_query($conn,"INSERT INTO `user`(`first_name`, `last_name`, `profile`, `email`, `a_c_number`, `phone`, `address`, `password`, `adhar_no`, `adhar_front_pic`, 
    //               `adhar_back_pic`, `pan_no`, `pan_image`, `electricity_bill`, `signature_image`, `rent agreement_image`, `guarantor_id`, `payment_mode`, 
    //               `payment_mode_number`, `joining_amount`, `created_at`, `moth_name`,`bank_statement`,`pass_book`,`bank_account`) VALUES ('$fname','$lname','$pimage','$email','$ac_number',
    //               '$phone','$address','$password','$aadhar','$a_f_image','$a_b_image','$pan','$pan_image','$bill_image','$sign_image','$rent_agreement',
    //               '$guranter','$p_mode_detail','$mode_number','$j_amount','$date','$currentMonthName','$bank_statement','$pass_book','$bank_account_number')");
        
        
         $insertt = mysqli_query($conn,"INSERT INTO `subadmin`(`first_name`, `last_name`, `profile`, 
                                        `email`, `a_c_number`, `phone`, `address`, `password`, `adhar_no`, 
                                        `adhar_front_pic`, `adhar_back_pic`, `pan_no`, `pan_image`, `electricity_bill`, 
                                        `signature_image`, `rent agreement_image`, `created_at`, `moth_name`, `bank_statement`,
                                        `pass_book`, `bank_account`) VALUES ('$fname','$lname','$pimage','$email','$ac_number','$phone','$address',
                                        '$password','$aadhar','$a_f_image','$a_b_image','$pan',
                                        '$pan_image','$bill_image','$sign_image','$rent_agreement','$date','$currentMonthName','$bank_statement','$pass_book','$bank_account_number')");
        if($insertt)
        {
           move_uploaded_file($pimage_tmp_name, '../img/profile_image/'.$pimage);
           move_uploaded_file($a_f_image_tmp_name, '../img/aadhar_image/'.$a_f_image);
           move_uploaded_file($a_b_image_tmp_name, '../img/aadhar_image/'.$a_b_image);
           move_uploaded_file($pan_image_tmp_name, '../img/pan_image/'.$pan_image);
           move_uploaded_file($sign_image_tmp_name, '../img/signature_image/'.$sign_image);
           move_uploaded_file($bill_image_tmp_name, '../img/electricity_bill_image/'.$bill_image);
           move_uploaded_file($rent_agreement_tmp_name, '../img/rent_agreement/'.$rent_agreement);
            move_uploaded_file($bank_statement_tmp_name, '../img/rent_agreement/'.$bank_statement);
             move_uploaded_file($pass_book_tmp_name, '../img/rent_agreement/'.$pass_book);
           
           echo "<script>alert('Your Query Submeted')</script>";
        
        echo "<script>window.location.href='subadmin.php'</script>";
    
                                                        
        }
    //}
}


?>