<?php
session_start();
include 'include/config.php';

if(!isset($_SESSION['id'])){
    // echo "<script> window.location.href = 'index.php' </script>";
  }
  
  
 $iddddd = $_GET['id'];
 
 $select_data = mysqli_fetch_assoc(mysqli_query($conn,"select * from `subadmin` where `id`='$iddddd'"));
 //print_r($select_data);

?>

<?php  include 'include/head.php'; ?>
                    
    <!-- Start Content-->
    <div class="container-fluid">
                        
                        <!-- start page title -->
                        <div class="row">
                            <div class="col-12">
                                <div class="page-title-box">
                                    <div class="page-title-right">
                                        <ol class="breadcrumb m-0">
                                            <li class="breadcrumb-item"><a href="dashboard.php">Home</a></li>
                                            <li class="breadcrumb-item active">Update User</li>
                                        </ol>
                                    </div>
                                    <h4 class="page-title">Update User</h4>
                                </div>
                            </div>
                        </div>
                        <!-- end page title --> 

                        <div class="row">
                        <div class="col-12">
                            <div class="card">
                                <div class="card-body">

                   <?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 `subadmin` 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' 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 `subadmin` SET `first_name`='$fname',`last_name`='$lname',`profile`='$pimage',`email`='$email',
                    `phone`='$phone',`address`='$address',`password`='$password',`adhar_no`='$aadhar',
                    `pan_no`='$pan' 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 `subadmin` SET `first_name`='$fname',`last_name`='$lname',`email`='$email',
                    `phone`='$phone',`address`='$address',`password`='$password',`adhar_no`='$aadhar',
                    `pan_no`='$pan' 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 `subadmin` 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' 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 `subadmin` 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' 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 `subadmin` 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' 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 `subadmin` 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' 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 `subadmin` 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' 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 `subadmin` SET `first_name`='$fname',`last_name`='$lname',`email`='$email',
                    `phone`='$phone',`address`='$address',`password`='$password',`adhar_no`='$aadhar',
                    `pan_no`='$pan' WHERE `id`='$iddddd'");
          
      
          if($update){
             
           echo "<script>alert('Your Query Updated')</script>";
           echo "<script>window.location.href='subadmin_list.php';</script>";
          }
      }
    

}


?>
                    <form action=""  method="POST" enctype="multipart/form-data">
                                
                                    <!-- end nav-->
                                    <div class="tab-content">
                                        <div class="tab-pane show active">
                                            <div class="row">
                                                
                                                <div class="col-lg-12">
                                                    <!-- Date Range Picker With Times -->
                                                    <div class="mb-3">
                                                        <label for="example-select" class="form-label">First Name</label>
                                                        <input type="text" value="<?php echo $select_data['first_name'];?>" name="fname" class="form-control" placeholder="User First Name" >
                                                    </div>
                                                </div>
                                                
                                                <div class="col-lg-12">
                                                    <!-- Date Range Picker With Times -->
                                                    <div class="mb-3">
                                                        <label for="example-select" class="form-label">Last Name</label>
                                                        <input type="text" value="<?php echo $select_data['last_name'];?>" name="lname" class="form-control" placeholder="User Last Name" >
                                                    </div>
                                                </div>
                                                
                                                <div class="col-lg-12">
                                                    <!-- Date Range Picker With Times -->
                                                    <div class="mb-3">
                                                        <label for="example-select" class="form-label">Email</label>
                                                        <input type="email" value="<?php echo $select_data['email'];?>" name="email" class="form-control" placeholder="User Email" >
                                                    </div>
                                                </div>
                                                
                                                <div class="col-lg-12">
                                                    <!-- Date Range Picker With Times -->
                                                    <div class="mb-3">
                                                        <label for="example-select" class="form-label">Account Number</label>
                                                        <input type="text" value="<?php echo $select_data['a_c_number'];?>" name="ac_number" id="ac_number"  class="form-control" placeholder="User Acount Number"  readonly>
                                                           <span id="check-mobile"></span>
                                                    </div>
                                                </div>
                                                
                                                <div class="col-lg-12">
                                                    <!-- Date Range Picker With Times -->
                                                    <div class="mb-3">
                                                        <label for="example-select" class="form-label">Phone Number</label>
                                                        <input type="text" value="<?php echo $select_data['phone'];?>" name="phone" class="form-control" placeholder="User Phone Number" >
                                                    </div>
                                                </div>
                                                
                                                <div class="col-lg-12">
                                                    <!-- Date Range Picker With Times -->
                                                    <div class="mb-3">
                                                        <label for="example-select" class="form-label">Address</label>
                                                        <input type="text" value="<?php echo $select_data['address'];?>" name="address" class="form-control" placeholder="User Address" >
                                                    </div>
                                                </div>
                                                
                                                <div class="col-lg-12">
                                                    <!-- Date Range Picker With Times -->
                                                    <div class="mb-3">
                                                        <label for="example-select" class="form-label">Password</label>
                                                        <input type="text" value="<?php echo $select_data['password'];?>" name="password" class="form-control" placeholder="User Password" >
                                                    </div>
                                                </div>
                                                
                                                <div class="col-lg-12">
                                                    <!-- Date Range Picker With Times -->
                                                    <div class="mb-3">
                                                        <label for="example-select" class="form-label">Aadhar Number</label>
                                                        <input type="text" value="<?php echo $select_data['adhar_no'];?>" name="aadhar" class="form-control" placeholder="User Aadhar Number" >
                                                    </div>
                                                </div>
                                                
                                                <div class="col-lg-12">
                                                    <!-- Date Range Picker With Times -->
                                                    <div class="mb-3">
                                                        <label for="example-select" class="form-label">Pan Number</label>
                                                        <input type="text" value="<?php echo $select_data['pan_no'];?>" name="pan" class="form-control" placeholder="Pan Number" >
                                                    </div>
                                                </div>
                                                
                                                <!--<div class="col-lg-12">-->
                                                    <!-- Date Range Picker With Times -->
                                                <!--    <div class="mb-3">-->
                                                <!--        <label for="example-select" class="form-label">Guarantor ID</label>-->
                                                <!--        <input type="text" value="<?php echo $select_data['guarantor_id'];?>" name="guranter" class="form-control" placeholder="Guarantor ID" >-->
                                                <!--    </div>-->
                                                <!--</div>-->
                                                
                                                
                                               <!-- <div class="col-lg-12">-->
                                                   <!-- Date Range Picker With Times -->
                                               <!--    <div class="mb-3">-->
                                               <!--        <label for="payment-mode" class="form-label">Payment Mode</label>-->
                                               <!--        <select name="p_mode_detail" id="payment-mode" class="form-control" required>-->
                                               <!--            <option value="">Select Payment Mode</option>-->
                                               <!--            <option <?php if($select_data['payment_mode']=='phone_pay') echo 'selected';?> value="phone_pay">Phone Pay</option>-->
                                               <!--            <option <?php if($select_data['payment_mode']=='cash') echo 'selected';?> value="cash">Cash</option>-->
                                               <!--            <option <?php if($select_data['payment_mode']=='upi') echo 'selected';?> value="upi">UPI</option>-->
                                               <!--            <option <?php if($select_data['payment_mode']=='account_transfer') echo 'selected';?> value="account_transfer">Account Transfer</option>-->
                                               <!--        </select>-->
                                               <!--    </div>-->
                                               <!--</div>-->
                                                
                                                <!--<div class="col-lg-12">-->
                                                    <!-- Date Range Picker With Times -->
                                                <!--    <div class="mb-3">-->
                                                <!--        <label for="example-select" class="form-label">Payment Mode Number(example:cheque no,upi no,account no)</label>-->
                                                <!--        <input type="text" value="<?php echo $select_data['payment_mode_number'];?>" name="mode_number" class="form-control" placeholder="Cheque no,Upi No,Account No" >-->
                                                <!--    </div>-->
                                                <!--</div>-->
                                                
                                                
                                                
                                                <div class="col-lg-12">
                                                    <!-- Date Range Picker With Times -->
                                                    <div class="mb-3">
                                                        <label for="example-select" class="form-label">Profile Image</label>
                                                        <input type="file" value="" name="pimage" class="form-control" placeholder="Give image" >
                                                        <img src="<?= '../img/profile_image/'.$select_data['profile'];?>" style="width:100px; height:60px;">
                                                    </div>
                                                </div>
                                                
                                                <div class="col-lg-12">
                                                    <!-- Date Range Picker With Times -->
                                                    <div class="mb-3">
                                                        <label for="example-select" class="form-label">Aadhar Front Image</label>
                                                        <input type="file" value="" name="a_f_image" class="form-control" placeholder="Give image" >
                                                        <img src="<?= '../img/aadhar_image/'.$select_data['adhar_front_pic'];?>" style="width:100px; height:60px;">
                                                    </div>
                                                </div>
                                                
                                                 <div class="col-lg-12">
                                                    <!-- Date Range Picker With Times -->
                                                    <div class="mb-3">
                                                        <label for="example-select" class="form-label">Aadhar Back Image</label>
                                                        <input type="file" value="" name="a_b_image" class="form-control" placeholder="Give image" >
                                                        <img src="<?= '../img/aadhar_image/'.$select_data['adhar_back_pic'];?>" style="width:100px; height:60px;">
                                                    </div>
                                                </div>
                                                
                                                 <div class="col-lg-12">
                                                    <!-- Date Range Picker With Times -->
                                                    <div class="mb-3">
                                                        <label for="example-select" class="form-label">Pan Card Image</label>
                                                        <input type="file" value="" name="pan_image" class="form-control" placeholder="Give image" >
                                                        <img src="<?= '../img/pan_image/'.$select_data['pan_image'];?>" style="width:100px; height:60px;"></td>
                                                    </div>
                                                </div>
                                                
                                                <div class="col-lg-12">
                                                    <!-- Date Range Picker With Times -->
                                                    <div class="mb-3">
                                                        <label for="example-select" class="form-label">Signature Image</label>
                                                        <input type="file" value="" name="sign_image" class="form-control" placeholder="Give Signatureimage" >
                                                        <img src="<?= '../img/signature_image/'.$select_data['signature_image'];?>" style="width:100px; height:60px;"></td>
                                                        
                                                    </div>
                                                </div>
                                                
                                                <div class="col-lg-12">
                                                    <!-- Date Range Picker With Times -->
                                                    <div class="mb-3">
                                                        <label for="example-select" class="form-label">Electricity Bill Image</label>
                                                        <input type="file" value="" name="bill_image" class="form-control" placeholder="Give ">
                                                        <img src="<?= '../img/electricity_bill_image/'.$select_data['electricity_bill'];?>" style="width:100px; height:60px;"></td>
                                                    </div>
                                                </div>
                                                
                                                <div class="col-lg-12">
                                                    <!-- Date Range Picker With Times -->
                                                    <div class="mb-3">
                                                        <label for="example-select" class="form-label">Rent agreement Image	</label>
                                                        <input type="file" value="" name="rent_agreement" class="form-control" placeholder="Give ">
                                                        <img src="<?= '../img/rent_agreement/'.$select_data['rent agreement_image'];?>" style="width:100px; height:60px;"></td>
                                                    </div>
                                                </div>
                                                
                                                
                                                
                                                <!--<div class="col-lg-12">-->
                                                    <!-- Date Range Picker With Times -->
                                                <!--    <div class="mb-3">-->
                                                <!--        <label for="example-select" class="form-label">Offer Value</label>-->
                                                <!--        <input type="text" value="" name="value" class="form-control" placeholder="offer value">-->
                                                <!--    </div>-->
                                                <!--</div>-->


                                            </div>

                                            <div class="row">
                                                <div class="clearfix"></div>
                                                <div class="col-lg-6">
                                                    <!-- Predefined Date Ranges -->
                                                    <div class="mb-3">
                                                        <input type="submit" id="submit" class="btn btn-success" value="Update" name="submit">
                                                        
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                        <!-- end preview-->

                                        
                                        <!-- end preview code-->
                                    </div>
                                    <!-- end tab-content-->
                    </form>
                                </div>
                                <!-- end card-body -->
                            </div>
                            <!-- end card-->
                        </div>
                            <!-- end col -->
            </div> <!-- end row-->


                    
    </div> <!-- container -->


<?php  
include 'include/footer.php'; 
?>
<!-- editor -->
        <script src='https://cdn.ckeditor.com/4.13.0/standard/ckeditor.js'></script>
        <script src='https://code.jquery.com/jquery-3.4.1.min.js'></script>
        <script id="rendered-js" >
            CKEDITOR.replace('editor1');
            CKEDITOR.on('instanceReady', function (evt)
            {
            var editor = evt.editor;

            editor.on('change', function (e) {
                var contentSpace = editor.ui.space('contents');
                var ckeditorFrameCollection = contentSpace.$.getElementsByTagName('iframe');
                var ckeditorFrame = ckeditorFrameCollection[0];
                var innerDoc = ckeditorFrame.contentDocument;
                var innerDocTextAreaHeight = $(innerDoc.body).height();
                console.log(innerDocTextAreaHeight);
            });
            });
            //# sourceURL=pen.js
            
            function checkmobile() {
    jQuery.ajax({
    url: "check_availability.php",
    data:'checkmobilel='+$("#ac_number").val(),
    type: "POST",
    success:function(data){
        $("#check-mobile").html(data);
    },
    error:function (){}
    });
}
        </script>
        
        