<?php include('../includes/connection.php');
@session_start();

if(!isset($_SESSION['admin_login'])) {
  header("Location: login.php");
  }

 include('header.php'); 

$msg = 0;


 ?>
      <div id="content-wrapper">

        <div class="container-fluid">

          <!-- Breadcrumbs-->
          <ol class="breadcrumb">
            <li class="breadcrumb-item">
              <a href="#"> Dashboard </a>
            </li>
            <li class="breadcrumb-item active"> View Vault </li>
          </ol>

          <?php if ($msg=='1') {
                echo $msg_alert;
              } ?>

          <!-- DataTables Example -->
          <div class="card mb-3">
            <div class="card-header">
              <i class="fas fa-table"></i> View Vault
              <a href="add_vault.php"  style="float: right;" class="btn btn-info btn-sm" > Add New Vault </a>
          </div>

           

            <div class="card-body">
              <div class="table-responsive">
                <table class="table table-bordered" id="dataTable" width="100%" cellspacing="0">
                  <thead>
                    <tr>
                      <th> Sr# </th>
                      <th> Owner's Name </th>
                      <th> Owner's Phone </th>
                      <th> Vault Passcode </th>
                      <th> Content Remark </th>
                      <th>Actions</th>
                    </tr>
                  </thead>

                  <tbody>

<?php $i = 1;
      $sql=  mysqli_query($DB_CONN,"SELECT * from vault");
             while($rowsql = mysqli_fetch_assoc($sql)) {  ?>

                    <tr id="rowid<?php echo $rowsql['id']; ?>">
                      <td> <?php echo $i; ?> </td>
                      <td> <?php echo $rowsql['vault_ownername']; ?> </td>
                      <td> <?php echo $rowsql['vault_ownerphone']; ?></td>
                      <td> <?php echo $rowsql['vaultpasscode']; ?></td>
                      <td> <?php echo $rowsql['content_remark']; ?> </td>
                      <td> <form method="POST" action="">
                      <input type="hidden" id="hide_id<?php echo $rowsql['id']; ?>" name="hide_id" value="<?php echo $rowsql['id']; ?>" >

                       <a href="detail_vault.php?id=<?php echo $rowsql['id']; ?>" title="View" class="btn btn-sm btn-info"> View </a> &nbsp;

                       
                       <button type="button" name="delete" class="btn btn-sm btn-danger" onclick="deletevault(<?php echo $rowsql['id']; ?>)" > Delete </button>

                        </form> </td>
                    </tr>

    <?php $i++; } ?>
                    

                    
                  </tbody>
                </table>
              </div>
            </div>
          </div>
      </div>
     

    </div>
    <!-- /#wrapper -->

    <!-- Scroll to Top Button-->
    <a class="scroll-to-top rounded" href="#page-top">
      <i class="fas fa-angle-up"></i>
    </a>



<script type="text/javascript">

  function deletevault(id) {
       var hide_id = $("#hide_id"+id).val();

        bootbox.confirm(" Confirm Delete ??? ", function(result){ 
        if(result==true) {
             $.ajax({
                 url:'ajax.php?h=delete_vault',
                 method:'POST', 
                 data:{hide_id:hide_id},

                 success:function(){
                     $("#rowid"+id).html(status);

              }
         });
      }
  });
}

</script>
<?php  include('footer.php'); ?>