<?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'];
    $guranter = $_POST['guranter'];
    $p_mode_detail = $_POST['p_mode_detail'];
    $mode_number = $_POST['mode_number'];
    $j_amount    = $_POST['j_amount'];
    
    // $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'];
    
    if(!empty($_FILES['pimage']['name']) && !empty($_FILES['a_f_image']['name']) && !empty($_FILES['a_b_image']['name']) && !empty($_FILES['pan_image']['name'])
      && !empty($_FILES['sign_image']['name']) && !empty($_FILES['bill_image']['name']) && !empty($_FILES['rent_agreement']['name'])){
          
     $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'];
          
          $update = mysqli_query($conn,"UPDATE `user` SET `first_name`='$fname',`last_name`='$lname',`profile`='$pimage',`email`='$email',
                    `phone`='$phone',`address`='$address',`password`='$password',`adhar_no`='$aadhar',`adhar_front_pic`='$a_f_image',`adhar_back_pic`='$a_b_image',
                    `pan_no`='$pan',`pan_image`='$pan_image',`electricity_bill`='$bill_image',`signature_image`='$sign_image',`rent agreement_image`='$rent_agreement',
                    `guarantor_id`='$guranter',`payment_mode`='$p_mode_detail',`payment_mode_number`='$mode_number' WHERE `id`='$iddddd'");
          
      
          if($update){
             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);
           
           echo "<script>alert('Your Query Updated')</script>";
           echo "<script>window.location.href='user.php';</script>";
          }
      }elseif (!empty($_FILES['pimage']['name'])) {
           $pimage = $_FILES['pimage']['name'];
           $pimage_tmp_name = $_FILES['pimage']['tmp_name'];
           
           $update = mysqli_query($conn,"UPDATE `user` SET `first_name`='$fname',`last_name`='$lname',`profile`='$pimage',`email`='$email',
                    `phone`='$phone',`address`='$address',`password`='$password',`adhar_no`='$aadhar',
                    `pan_no`='$pan',
                    `guarantor_id`='$guranter',`payment_mode`='$p_mode_detail',`payment_mode_number`='$mode_number' WHERE `id`='$iddddd'");
                    
                     if($update){
             move_uploaded_file($pimage_tmp_name, '../img/profile_image/'.$pimage);
          
           
           echo "<script>alert('Your Query Updated')</script>";
           echo "<script>window.location.href='user.php';</script>";
          }
      }elseif (!empty($_FILES['a_f_image']['name'])) {
          
    $a_f_image = $_FILES['a_f_image']['name'];
    $a_f_image_tmp_name = $_FILES['a_f_image']['tmp_name'];
           
          $update = mysqli_query($conn,"UPDATE `user` SET `first_name`='$fname',`last_name`='$lname',`email`='$email',
                    `phone`='$phone',`address`='$address',`password`='$password',`adhar_no`='$aadhar',
                    `pan_no`='$pan',
                    `guarantor_id`='$guranter',`payment_mode`='$p_mode_detail',`payment_mode_number`='$mode_number' WHERE `id`='$iddddd'");
          
      
          if($update){
            
           move_uploaded_file($a_f_image_tmp_name, '../img/aadhar_image/'.$a_f_image);
          
           echo "<script>alert('Your Query Updated')</script>";
           echo "<script>window.location.href='user.php';</script>";
          }
      }elseif (!empty($_FILES['a_b_image']['name'])) {
          
          $a_b_image = $_FILES['a_b_image']['name'];
          $a_b_image_tmp_name = $_FILES['a_b_image']['tmp_name'];
          
           $update = mysqli_query($conn,"UPDATE `user` SET `first_name`='$fname',`last_name`='$lname',`email`='$email',
                    `phone`='$phone',`address`='$address',`password`='$password',`adhar_no`='$aadhar',`adhar_back_pic`='$a_b_image',
                    `pan_no`='$pan',
                    `guarantor_id`='$guranter',`payment_mode`='$p_mode_detail',`payment_mode_number`='$mode_number' WHERE `id`='$iddddd'");
                    
                    if($update){
             
           move_uploaded_file($a_b_image_tmp_name, '../img/aadhar_image/'.$a_b_image);
           
           
           echo "<script>alert('Your Query Updated')</script>";
           echo "<script>window.location.href='user.php';</script>";
          }
          
      }elseif (!empty($_FILES['pan_image']['name'])) {
          $pan_image = $_FILES['pan_image']['name'];
          $pan_image_tmp_name = $_FILES['pan_image']['tmp_name'];
          
          $update = mysqli_query($conn,"UPDATE `user` SET `first_name`='$fname',`last_name`='$lname',`email`='$email',
                    `phone`='$phone',`address`='$address',`password`='$password',`adhar_no`='$aadhar',
                    `pan_no`='$pan',`pan_image`='$pan_image',
                    `guarantor_id`='$guranter',`payment_mode`='$p_mode_detail',`payment_mode_number`='$mode_number' WHERE `id`='$iddddd'");
          
      
          if($update){
             
           move_uploaded_file($pan_image_tmp_name, '../img/pan_image/'.$pan_image);
           
           
           echo "<script>alert('Your Query Updated')</script>";
           echo "<script>window.location.href='user.php';</script>";
          }
      }elseif (!empty($_FILES['sign_image']['name'])) {
          $sign_image = $_FILES['sign_image']['name'];
          $sign_image_tmp_name = $_FILES['sign_image']['tmp_name'];
          
          $update = mysqli_query($conn,"UPDATE `user` SET `first_name`='$fname',`last_name`='$lname',`email`='$email',
                    `phone`='$phone',`address`='$address',`password`='$password',`adhar_no`='$aadhar',
                    `pan_no`='$pan',`signature_image`='$sign_image',
                    `guarantor_id`='$guranter',`payment_mode`='$p_mode_detail',`payment_mode_number`='$mode_number' WHERE `id`='$iddddd'");
          
      
          if($update){
            
           move_uploaded_file($sign_image_tmp_name, '../img/signature_image/'.$sign_image);
          
           
           echo "<script>alert('Your Query Updated')</script>";
           echo "<script>window.location.href='user.php';</script>";
          }
          
      }elseif (!empty($_FILES['bill_image']['name'])) {
           $bill_image = $_FILES['bill_image']['name'];
    $bill_image_tmp_name = $_FILES['bill_image']['tmp_name'];
    
    $update = mysqli_query($conn,"UPDATE `user` SET `first_name`='$fname',`last_name`='$lname',`email`='$email',
                    `phone`='$phone',`address`='$address',`password`='$password',`adhar_no`='$aadhar',
                    `pan_no`='$pan',`electricity_bill`='$bill_image',
                    `guarantor_id`='$guranter',`payment_mode`='$p_mode_detail',`payment_mode_number`='$mode_number' WHERE `id`='$iddddd'");
          
      
          if($update){
             
           move_uploaded_file($bill_image_tmp_name, '../img/electricity_bill_image/'.$bill_image);

           echo "<script>alert('Your Query Updated')</script>";
           echo "<script>window.location.href='user.php';</script>";
          }
          
      }elseif (!empty($_FILES['rent_agreement']['name'])) {
          
          $rent_agreement = $_FILES['rent_agreement']['name'];
          $rent_agreement_tmp_name = $_FILES['rent_agreement']['tmp_name'];
          
           $update = mysqli_query($conn,"UPDATE `user` SET `first_name`='$fname',`last_name`='$lname',`email`='$email',
                    `phone`='$phone',`address`='$address',`password`='$password',`adhar_no`='$aadhar',
                    `pan_no`='$pan',`rent agreement_image`='$rent_agreement',
                    `guarantor_id`='$guranter',`payment_mode`='$p_mode_detail',`payment_mode_number`='$mode_number' WHERE `id`='$iddddd'");
          
      
          if($update){
            
           move_uploaded_file($rent_agreement_tmp_name, '../img/rent_agreement/'.$rent_agreement);
           
           echo "<script>alert('Your Query Updated')</script>";
           echo "<script>window.location.href='user.php';</script>";
          }
      }else{
           $update = mysqli_query($conn,"UPDATE `user` SET `first_name`='$fname',`last_name`='$lname',`email`='$email',
                    `phone`='$phone',`address`='$address',`password`='$password',`adhar_no`='$aadhar',
                    `pan_no`='$pan',
                    `guarantor_id`='$guranter',`payment_mode`='$p_mode_detail',`payment_mode_number`='$mode_number' WHERE `id`='$iddddd'");
          
      
          if($update){
             
           echo "<script>alert('Your Query Updated')</script>";
           echo "<script>window.location.href='user.php';</script>";
          }
      }
    

}


?>