<?php 
  $link_status4 = "active";
  $link_status5 = "";
  $link_status6 = "";
?>
<?php 
  include("includes/top-header.php"); 

  if(isset($_POST['upd_profile'])){

    $fnm = $_POST['fn'];
    $lnm = $_POST['ln'];
    $ctr = $_POST['country'];
    $ra = $_POST['ra'];
    $tct = $_POST['tc'];
    $sct = $_POST['sc'];
    $pzip = $_POST['pz'];
    $db = $_POST['db'];
    $gend = $_POST['gen'];
    $nati = $_POST['nat'];
    $job = $_POST['occu'];
    
      
    
    if(!isset($error)) {
      $sul="update users set fn='".$fnm."', ln='".$lnm."', address='".$ra."', townCity='".$tct."', state='".$sct."', country='".$ctr."', zip='".$pzip."', dob='".$db."', gender='".$gend."', nation='".$nati."', occu='".$job."', pc_status='1' where uID='".$uid."'";
      $uRes=mysqli_query($conn,$sul);
                
      if ($uRes) {		
        echo '<script>alert("Changes Updated Successfully!")</script>';	
        echo '<script>window.location="settings-profile.php";</script>';	
      } else {
        //echo mysqli_error('$conn');
        echo '<script>alert("Something went wrong, try again later...")</script>';	
      }
    } 
  }
  
  if(isset($_POST['save_email'])){
    $ea = $_POST['ea'];

    $sul="update users set email='".$ea."' where uID='".$uid."'";
    $uRes=mysqli_query($conn,$sul);
              
    if ($uRes) {
      echo '<script>alert("Changes Updated Successfully!")</script>';	
      echo '<script>window.location="settings-profile.php";</script>';	
    } else {
      echo '<script>alert("Something went wrong, try again later...")</script>';	
    }
  }
  
  if(isset($_POST['save_phone'])){
    $ph = $_POST['ph'];

    $sul="update users set pNumber='".$ph."', pc_status='2' where uID='".$uid."'";
    $uRes=mysqli_query($conn,$sul);
              
    if ($uRes) {
      echo '<script>alert("Changes Updated Successfully!")</script>';	
      echo '<script>window.location="settings-profile.php";</script>';	
    } else {
      echo '<script>alert("Something went wrong, try again later...")</script>';	
    }
  }
?>
  
        <!-- Secondary menu
        ============================================= -->
        <!--<div class="bg-primary">-->
        <!--  <div class="container d-flex justify-content-center">-->
        <!--    <ul class="nav nav-pills alternate nav-lg border-bottom-0">-->
        <!--      <li class="nav-item"> <a class="nav-link <?php echo $link_status4; ?>" href="settings-profile.php">Account</a></li>-->
        <!--      <li class="nav-item"> <a class="nav-link <?php echo $link_status5; ?>" href="settings-security.php">Security</a></li>-->
        <!--      <li class="nav-item"> <a class="nav-link <?php echo $link_status6; ?>" href="settings-payment-methods.php">Payment Methods</a></li>-->
        <!--    </ul>-->
        <!--  </div>-->
        <!--</div>-->
        <!-- Secondary menu end --> 
        
<?php include("includes/header.php"); ?>
        <!-- Left Panel End --> 
        
        <!-- Middle Panel
        ============================================= -->
      <div class="col-lg-9">
  
  <!-- PERSONAL DETAILS -->
  <div class="bg-white rounded shadow-sm p-4 mb-4">
    <h3 class="text-5 fw-bold d-flex align-items-center mb-3">
      <i class="fas fa-user me-2 text-primary"></i> Personal Details
      <a href="#edit-personal-details" data-bs-toggle="modal" class="ms-auto btn btn-outline-primary btn-sm rounded-pill">
        <i class="fas fa-edit me-1"></i> Edit
      </a>
    </h3>
    <hr>
    <div class="row gx-4">
      <div class="col-sm-3 text-muted text-sm-end">Name:</div>
      <div class="col-sm-9"><?php echo $fname . " " . $lname; ?></div>
    </div>
    <div class="row gx-4 mt-2">
      <div class="col-sm-3 text-muted text-sm-end">Date of Birth:</div>
      <div class="col-sm-9"><?php echo $dob; ?></div>
    </div>
    <div class="row gx-4 mt-2">
      <div class="col-sm-3 text-muted text-sm-end">Address:</div>
      <div class="col-sm-9">
        <?php echo $add; ?>,<br>
        <?php echo $ct; ?>, <?php echo $state; ?>,<br>
        <?php echo $country__; ?>.
      </div>
    </div>
  </div>

 <!-- KYC SECTION -->
  <div class="bg-white rounded shadow-sm p-4 mb-4">
    <h3 class="text-5 fw-bold d-flex align-items-center mb-3">
      <i class="fas fa-id-card me-2 text-primary"></i> KYC Documents
      <a href="#edit-kyc" data-bs-toggle="modal" class="ms-auto btn btn-outline-primary btn-sm rounded-pill">
        <i class="fas fa-edit me-1"></i> Edit
      </a>
    </h3>
    <hr>
    <div class="row gx-4">
      <div class="col-sm-3 text-muted text-sm-end">ID Front:</div>
      <div class="col-sm-9">
        <?php if ($id_front) : ?>
          <a href="<?php echo $id_front; ?>" target="_blank">View Front ID</a>
        <?php else: ?>
          <span class="text-muted">No ID front uploaded</span>
        <?php endif; ?>
      </div>
    </div>
    <div class="row gx-4 mt-2">
      <div class="col-sm-3 text-muted text-sm-end">ID Back:</div>
      <div class="col-sm-9">
        <?php if ($id_back) : ?>
          <a href="<?php echo $id_back; ?>" target="_blank">View Back ID</a>
        <?php else: ?>
          <span class="text-muted">No ID back uploaded</span>
        <?php endif; ?>
      </div>
    </div>
  </div>

  <!-- MODALS -->
  <!-- KYC Modal -->
  <div id="edit-kyc" class="modal fade" role="dialog" aria-hidden="true">
    <div class="modal-dialog modal-dialog-centered" role="document">
      <div class="modal-content">
        <div class="modal-header">
          <h5 class="modal-title fw-bold">Upload KYC Documents</h5>
          <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
        </div>
        <div class="modal-body">
          <form method="post" action="settings-profile.php" enctype="multipart/form-data">
            <div class="mb-3">
              <label for="idFront" class="form-label">ID Front</label>
              <input type="file" class="form-control" name="id_front" id="idFront" accept="image/*" required>
            </div>
            <div class="mb-3">
              <label for="idBack" class="form-label">ID Back</label>
              <input type="file" class="form-control" name="id_back" id="idBack" accept="image/*" required>
            </div>
            <div class="d-grid">
              <button type="submit" name="save_kyc" class="btn btn-primary">Upload KYC</button>
            </div>
          </form>
        </div>
      </div>
    </div>
  </div>

</div>
  <!-- EMAIL ADDRESS -->
  <div class="bg-white rounded shadow-sm p-4 mb-4">
    <h3 class="text-5 fw-bold d-flex align-items-center mb-3">
      <i class="fas fa-envelope me-2 text-primary"></i> Email Address
      <a href="#edit-email" data-bs-toggle="modal" class="ms-auto btn btn-outline-primary btn-sm rounded-pill">
        <i class="fas fa-edit me-1"></i> Edit
      </a>
    </h3>
    <hr>
    <div class="row gx-4">
      <div class="col-sm-3 text-muted text-sm-end">Email:</div>
      <div class="col-sm-9"><?php echo $em; ?></div>
    </div>
  </div>

  <!-- PHONE -->
  <div class="bg-white rounded shadow-sm p-4 mb-4">
    <h3 class="text-5 fw-bold d-flex align-items-center mb-3">
      <i class="fas fa-phone-alt me-2 text-primary"></i> Phone Number
      <a href="#edit-phone" data-bs-toggle="modal" class="ms-auto btn btn-outline-primary btn-sm rounded-pill">
        <i class="fas fa-edit me-1"></i> Edit
      </a>
    </h3>
    <hr>
    <div class="row gx-4">
      <div class="col-sm-3 text-muted text-sm-end">Phone:</div>
      <div class="col-sm-9"><?php echo $ph; ?></div>
    </div>
  </div>

  <!-- BANKING INFO -->
  <div class="bg-white rounded shadow-sm p-4 mb-4">
    <h3 class="text-5 fw-bold d-flex align-items-center mb-3">
      <i class="fas fa-university me-2 text-primary"></i> Banking Information
      <a href="#edit-bank-details" data-bs-toggle="modal" class="ms-auto btn btn-outline-primary btn-sm rounded-pill">
        <i class="fas fa-edit me-1"></i> Edit
      </a>
    </h3>
    <hr>
    <div class="row gx-4">
      <div class="col-sm-3 text-muted text-sm-end">Bank Name:</div>
      <div class="col-sm-9"><?php echo $bank_name; ?></div>
    </div>
    <div class="row gx-4 mt-2">
      <div class="col-sm-3 text-muted text-sm-end">Account Number:</div>
      <div class="col-sm-9"><?php echo $account_number; ?></div>
    </div>
    <div class="row gx-4 mt-2">
      <div class="col-sm-3 text-muted text-sm-end">IFSC Code:</div>
      <div class="col-sm-9"><?php echo $ifsc_code; ?></div>
    </div>
  </div>

  <!-- MODALS -->
  <!-- Personal Details Modal -->
  <div id="edit-personal-details" class="modal fade" role="dialog" aria-hidden="true">
    <div class="modal-dialog modal-dialog-centered" role="document">
      <div class="modal-content">
        <div class="modal-header">
          <h5 class="modal-title fw-bold">Edit Personal Details</h5>
          <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
        </div>
        <div class="modal-body">
          <form method="post" action="settings-profile.php">
            <div class="mb-3">
              <label for="firstName" class="form-label">First Name</label>
              <input type="text" class="form-control" name="fn" value="<?php echo $fname; ?>" id="firstName" required>
            </div>
            <div class="mb-3">
              <label for="lastName" class="form-label">Last Name</label>
              <input type="text" class="form-control" name="ln" value="<?php echo $lname; ?>" id="lastName" required>
            </div>
            <div class="mb-3">
              <label for="dob" class="form-label">Date of Birth</label>
              <input type="date" class="form-control" name="db" value="<?php echo $dob; ?>" id="dob" required>
            </div>
            <div class="mb-3">
              <label for="address" class="form-label">Address</label>
              <input type="text" class="form-control" name="ra" value="<?php echo $add; ?>" id="address" required>
            </div>
            <div class="mb-3">
              <label for="city" class="form-label">City</label>
              <input type="text" class="form-control" name="tc" value="<?php echo $ct; ?>" id="city" required>
            </div>
            <div class="mb-3">
              <label for="state" class="form-label">State</label>
              <input type="text" class="form-control" name="sc" value="<?php echo $state; ?>" id="state" required>
            </div>
            <div class="mb-3">
              <label for="country" class="form-label">Country</label>
              <select class="form-select" id="country" name="country" required>
                <option value="<?php echo $country__; ?>"><?php echo $country__; ?></option>
                <!-- Add more countries as necessary -->
              </select>
            </div>
            <div class="d-grid">
              <button type="submit" name="upd_profile" class="btn btn-primary">Save Changes</button>
            </div>
          </form>
        </div>
      </div>
    </div>
  </div>

  <!-- Email Modal -->
  <div id="edit-email" class="modal fade" role="dialog" aria-hidden="true">
    <div class="modal-dialog modal-dialog-centered" role="document">
      <div class="modal-content">
        <div class="modal-header">
          <h5 class="modal-title fw-bold">Edit Email Address</h5>
          <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
        </div>
        <div class="modal-body">
          <form method="post" action="settings-profile.php">
            <div class="mb-3">
              <label for="emailID" class="form-label">Email Address</label>
              <input type="email" class="form-control" name="ea" value="<?php echo $em; ?>" id="emailID" required>
            </div>
            <div class="d-grid">
              <button type="submit" name="save_email" class="btn btn-primary">Save Changes</button>
            </div>
          </form>
        </div>
      </div>
    </div>
  </div>

  <!-- Phone Modal -->
  <div id="edit-phone" class="modal fade" role="dialog" aria-hidden="true">
    <div class="modal-dialog modal-dialog-centered" role="document">
      <div class="modal-content">
        <div class="modal-header">
          <h5 class="modal-title fw-bold">Edit Phone Number</h5>
          <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
        </div>
        <div class="modal-body">
          <form method="post" action="settings-profile.php">
            <div class="mb-3">
              <label for="mobileNumber" class="form-label">Phone Number</label>
              <input type="text" class="form-control" name="ph" value="<?php echo $ph; ?>" id="mobileNumber" required>
            </div>
            <div class="d-grid">
              <button type="submit" name="save_phone" class="btn btn-primary">Save Changes</button>
            </div>
          </form>
        </div>
      </div>
    </div>
  </div>

  <!-- Banking Modal -->
  <div id="edit-bank-details" class="modal fade" role="dialog" aria-hidden="true">
    <div class="modal-dialog modal-dialog-centered" role="document">
      <div class="modal-content">
        <div class="modal-header">
          <h5 class="modal-title fw-bold">Edit Banking Information</h5>
          <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
        </div>
        <div class="modal-body">
          <form method="post" action="settings-profile.php">
            <div class="mb-3">
              <label for="bankName" class="form-label">Bank Name</label>
              <input type="text" class="form-control" name="bn" value="<?php echo $bank_name; ?>" id="bankName" required>
            </div>
            <div class="mb-3">
              <label for="accountNumber" class="form-label">Account Number</label>
              <input type="text" class="form-control" name="acn" value="<?php echo $account_number; ?>" id="accountNumber" required>
            </div>
            <div class="mb-3">
              <label for="ifscCode" class="form-label">IFSC Code</label>
              <input type="text" class="form-control" name="ifsc" value="<?php echo $ifsc_code; ?>" id="ifscCode" required>
            </div>
            <div class="d-grid">
              <button type="submit" name="save_bank" class="btn btn-primary">Save Changes</button>
            </div>
          </form>
        </div>
      </div>
    </div>
  </div>

</div>

        <!-- Middle Panel End --> 
      </div>
    </div>
  </div>
  <!-- Content end --> 
  
  <!-- Footer
  ============================================= -->
  <?php include("includes/footer.php"); ?>
  <!-- Footer end --> 
  
</div>
<!-- Document Wrapper end --> 

<!-- Back to Top
============================================= --> 
<a id="back-to-top" data-bs-toggle="tooltip" title="Back to Top" href="javascript:void(0)"><i class="fa fa-chevron-up"></i></a> 

<!-- Styles Switcher -->

<!-- Styles Switcher End --> 

<!-- Script --> 
<script src="vendor/jquery/jquery.min.js"></script> 
<script src="vendor/bootstrap/js/bootstrap.bundle.min.js"></script> 
<script src="vendor/daterangepicker/moment.min.js"></script> 
<script src="vendor/daterangepicker/daterangepicker.js"></script> 
<script>
$(function() {
 'use strict';
  // Birth Date
  $('#birthDate').daterangepicker({
	singleDatePicker: true,
	showDropdowns: true,
	autoUpdateInput: false,
	maxDate: moment().add(0, 'days'),
	}, function(chosen_date) {
  $('#birthDate').val(chosen_date.format('MM-DD-YYYY'));
  });
  });
</script> 
<!-- Style Switcher --> 
<script src="js/switcher.min.js"></script> 
<script src="js/theme.js"></script>
</body>
</html>