<?php
 session_start();
 require_once('../connect.php');
 require_once('sql_required.php');

 $datetoday = date('Y-m-d'); 

 $unique_id = $_GET['id'];

$sql_user_details = "SELECT * FROM tbl_user_account WHERE unique_id = '$unique_id'";
$result_user_details = mysqli_query($conn, $sql_user_details);
$row_user_details = mysqli_fetch_assoc($result_user_details);
$username = $row_user_details['username'];
$firstname = $row_user_details['firstname'];
$homeadd = $row_user_details['home_address'];
 
$mi = $row_user_details['mi'];
 
$lastname = $row_user_details['lastname'];
 
$mobilenumber = $row_user_details['mobilenumber'];
$mobilenumber2 = $row_user_details['other_number'];
 

$message = '';
if (isset($_POST['save_changes'])) {
  $firstname = mysqli_real_escape_string($conn, $_POST['firstname']);
  $lastname = mysqli_real_escape_string($conn, $_POST['lastname']);
  $mobilenumber = mysqli_real_escape_string($conn, $_POST['mobilenumber']);
  $homeadd = mysqli_real_escape_string($conn, $_POST['homeadd']);
  $contact_persons = mysqli_real_escape_string($conn, $_POST['contact_persons']);
  $mobilenumber2 = mysqli_real_escape_string($conn, $_POST['mobilenumber2']);

  $sql_update = "UPDATE tbl_user_account SET firstname = '$firstname', lastname = '$lastname', 
  mobilenumber = '$mobilenumber', home_address= '$homeadd', other_number= '$mobilenumber2',username= '$contact_persons' WHERE unique_id = '$unique_id'";
  if (mysqli_query($conn, $sql_update)) {
    $message = '<div class="pb-4">
                  <span class="alert alert-success">Your profile details is successfully update</span>
                </div>';

  }
  
  
   
  $number_placement = $mobilenumber;
  $message_placement = urlencode("Hi ".$firstname."! Maari mo ng i-activate ang iyong AMWDS account");
   include_once ("sms_function.php");
  
  
}

?>  
<html>
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title>Edit Profile</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
  <link rel="icon" href="images/logo.png" type="image/png" sizes="16x16">
  <link rel="stylesheet" href="plugins/fontawesome-free/css/all.min.css">
  <link rel="stylesheet" href="https://code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css">
  <link rel="stylesheet" href="dist/css/adminlte.min.css">
  <link rel="stylesheet" href="plugins/overlayScrollbars/css/OverlayScrollbars.min.css">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/OwlCarousel2/2.3.4/assets/owl.carousel.min.css">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/OwlCarousel2/2.3.4/assets/owl.theme.default.css">
  <link href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,400i,700" rel="stylesheet">
  <link rel="stylesheet" href="plugins/overlayScrollbars/css/OverlayScrollbars.min.css">
  <link rel="stylesheet" href="plugins/datatables-bs4/css/dataTables.bootstrap4.min.css">
  <link rel="stylesheet" href="plugins/datatables-responsive/css/responsive.bootstrap4.min.css">
  <link href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,400i,700" rel="stylesheet">
  <link rel="stylesheet" type="text/css" href="css/style1.css">
  <link rel="stylesheet" type="text/css" href="css/skeleton_loading.css">
<style type="text/css">
  .content-wrapper {
    background: #151e27!important;
  }
  @media(max-width:800px) {
    .modal-content {
      position: fixed; bottom: 40%; width: 96%; left: 7;
    }
    .modal-dialog {
      margin: 0!important; padding: 0!important;
    }
  }
  .btn {
    border-radius: 10px;
  }
  .form-control {
    border-radius: 10px;
  }
  .form-control:focus {
    border: 1px solid #ffd700!important;
  }
  .label {
    display: inline-block;
    margin-bottom: 0px !important;
    color: #fff!important;
    font-size: 80%!important;
    font-weight: 400!important;
  }
  .img-circle {
    border-color: grey;
  }
  .alert-success {
    color: #155724;
    background-color: #d4edda;
    border-color: #c3e6cb;
  }
  .list-group-item {
    background: #1d2532!important;
    color: #fff!important;
  }
  .account-href {
    cursor: pointer; 
    display: block;
    color: #fff;
  }
  .account-href:hover {
    color: #fff;
  }
  .transaction-amount {
    float: right;
    color: #fff;
    font-weight: 800;
  }
  .transaction-number {
   float: right;
  }
  .form-control {
    border-radius: 10px;
  }
  .form-control:focus {
    border: 1px solid #ffd700!important;
  }
  @media(max-width:991px) {
    #order_full_screen {
      display: none!important;
    }
    #order_small_screen {
      display: block!important;
    }
  } 
</style>
</head>
<body class="hold-transition sidebar-mini layout-footer-fixed layout-fixed" style="background: #151e27;">
<div id="preloader" class="loading" style="display: none"></div>
<div class="wrapper">
  <nav class="main-header navbar navbar-expand navbar-white" style="background: #151e27; border-bottom: 0; box-shadow: none!important;">
    <ul class="navbar-nav">
      <li class="nav-item">
        <a href="index.php?<?php echo generate_string($permitted_chars, 100); ?>" class="withanimation"><i class="fas fa-angle-left pr-2" style="font-size: 20px; color: #ffd700;"></i></a><span class="brand-text" style="font-size: 20px;"><span style="font-size: 20px; font-weight: bolder; line-height: 20px; color: #fff;">Edit Profile</span></a>
      </li>
    </ul>
    <ul class="navbar-nav ml-auto">
      <a class="nav-link" data-widget="pushmenu" href="#" role="button"><i class="fas fa-bars"></i></a>
    </ul>
  </nav>

<?php include ("navbar.php")?>
<div class="content-wrapper">
  <section class="content menu-main">
    <div class="container-fluid">
      <div class="pt-2"></div>
      <div style="display: flex; justify-content: space-between;">
        <legend style="font-size: 20px; font-weight: 400; color: #fff;">Update Details
          <br><span style="font-size: 14px" class="text-muted">Please make sure your info is correct.</span>
        </legend>
        <a class="information" data-toggle="tooltip" data-placement="left" title="Please tap the image to choose new profile."><i class="fas fa-info-circle pt-1" style="font-size: 20px; color: grey;"></i></a>
      </div>
      <div class="text-center pt-2">
            <img id="logo_merchant"  class="profile-user-img img-fluid img-circle" src="dist/img/avatar5.png" alt="User profile picture">
            <p class="pt-1 text-white"><b><?php echo $username; ?></b><br>
            <span><small class="text-muted"><?php echo 'Account #: 000'.$unique_id; ?></small></span>
            </p>

            <span id="message">
              <?php echo $message; ?>
            </span>
      </div>
    </div><!-- /.container-fluid -->
  </section>

  <section class="content">
    <div class="container-fluid pt-0 pb-0 pl-3 pr-3">
      <form method="POST" id="userDetails">

      <label class="label"><b>Account Holder Detail</b></label>


        <input type="hidden" name="unique_id" value="<?php echo $unique_id; ?>">
        <div class="form-group">
          <label class="label">First Name</label>
          <input type="text" name="firstname" class="form-control" value="<?php echo $firstname; ?>" placeholder="Enter First Name" required/>
        </div>

        <div class="form-group">
          <label class="label">Last Name</label>
          <input type="text" name="lastname" class="form-control" value="<?php echo $lastname; ?>" placeholder="Enter Last Name" required/>
        </div>

        <div class="form-group">
          <label class="label">Mobile Number</label>
          <input type="number" name="mobilenumber" maxlength="11" class="form-control" value="<?php echo $mobilenumber; ?>" required/>
        </div>
        <div class="form-group">
          <label class="label">Other Contact Number</label>
          <input type="number" name="mobilenumber2" maxlength="11" class="form-control" value="<?php echo $mobilenumber2; ?>" required/>
        </div>

        <div class="form-group">
          <label class="label">Home Address</label>
          <input type="text" name="homeadd" class="form-control" value="<?php echo $homeadd; ?>" required/>
        </div>


        <input type="hidden" name="unique_id" value="<?php echo $unique_id; ?>">
        <div class="form-group">
          <label class="label">Contact Person/s</label>
          <input type="text" name="contact_persons" class="form-control" value="<?php echo $username; ?>" placeholder="Enter Contact Person Names" required/>
        </div>

        <button type="button" data-toggle="modal" data-target="#update_info" class="btn btn-warning btn-block btn-lg" style="background: #FFD700; border-color: #ffd700;">Save Changes</button>

        <div class="modal" id="update_info">
          <div class="modal-dialog">
            <div class="modal-content" style="background-color: #151e27!important;">
              <div class="modal-header pb-0" style="border: 0px;">
                <h5 class="modal-title text-white" style="font-weight: bold;">Update</h5>
              </div>
              <div class="modal-body pt-0 pb-0">
                <p class="text-muted">Are you sure you want to update your info?</p>
              </div>
              <div class="modal-footer pr-0 pl-0 pb-2 pt-0" style="display: block; border: 0px">
                <div class="row">
                  <div class="col-6">
                    <button type="button" class="btn btn-default btn-lg btn-block" style="background: transparent; color: #fff;" data-dismiss="modal">Cancel</button>
                  </div>
                  <div class="col-6">
                    <button type="submit" name="save_changes" class="btn btn-warning btn-lg btn-block withanimation_submit" style="background: #FFD700; border-color: #ffd700;">Yes, Submit</button>
                  </div>
                </div>
                
              </div>
            </div>
          </div>
        </div> <!-- logout -->

      </form>
    </div>

    <br>
  </section>
  [
  <?php include('cut_off_list.php')?>
 

</div>
</div>


<script src="dist/js/adminlte.min.js"></script>
<script src="plugins/jquery/jquery.min.js"></script>
<!-- Bootstrap 4 -->
<script src="plugins/bootstrap/js/bootstrap.bundle.min.js"></script>
<script src="plugins/jquery-validation/jquery.validate.min.js"></script>
<script src="plugins/jquery-validation/additional-methods.min.js"></script>
<script src="dist/js/pages/dashboard.js"></script>
<script src="plugins/overlayScrollbars/js/jquery.overlayScrollbars.min.js"></script>
<script src="plugins/datatables/jquery.dataTables.min.js"></script>
<script src="plugins/datatables-bs4/js/dataTables.bootstrap4.min.js"></script>
<script src="plugins/datatables-responsive/js/dataTables.responsive.min.js"></script>
<script src="plugins/datatables-responsive/js/responsive.bootstrap4.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
  var form = $('#userDetails');
    form.validate({
    rules: {
      firstname: {
        required: true,
      },
      lastname:{
        required: true,
      },
      mobilenumber: {
        required: true,
      }
    },
    errorElement: 'span',
    errorPlacement: function (error, element) {
      error.addClass('invalid-feedback');
      element.closest('.form-group').append(error);
    },
    highlight: function (element, errorClass, validClass) {
      $(element).addClass('is-invalid');
    },
    unhighlight: function (element, errorClass, validClass) {
      $(element).removeClass('is-invalid');
    }
  });


  setInterval(function() {
    $('#message').hide();
  }, 3000);
});

$(function () {
  $(".withanimation_submit").click(function() {
    $(".loading").show();
  });
  $(".withanimation").click(function(e) {
      e.preventDefault();
      $(".loading").show();
      var url=$(this).attr("href");
      setTimeout(function() {
          window.location=url;
      }, 500);
  });
});

if ( window.history.replaceState ) {
  window.history.replaceState( null, null, window.location.href );
}


</script>




<script type="text/javascript">
$(document).ready(function () {
  $('#search').keyup(function() {
    var members = $(this).val();
    var btn_action = "member_search";
     $.ajax({
      url:'fetch_data.php',
      method:"POST",
      dataType:"html",
      data:{members:members, btn_action:btn_action},
      success:function(data){
        $('#members_result').html(data);
      }
    });
  });
});
$(function () {
  $("#members_table").DataTable({
    "responsive": true,
    "autoWidth": false,
  });
  $('#example2').DataTable({
    "paging": true,
    "lengthChange": false,
    "searching": false,
    "ordering": true,
    "info": true,
    "autoWidth": false,
    "responsive": true,
  });
  $(".withanimation").click(function(e) {
      e.preventDefault();
      $(".loading").show();
      var url=$(this).attr("href");
      setTimeout(function() {
          window.location=url;
      }, 500);
  });
});
</script>
</body>
</html>
