<!doctype html>
<html lang="en">
<head>
  <?php
    include_once("element/connection.php");
    $db = mysqli_connect("localhost", "root", "", "sp");
   ?>
    <?php
  // Create database connection
  $db = mysqli_connect("localhost", "root", "", "sp");

  // Initialize message variable
  $msg = "";

  // If upload button is clicked ...
  if (isset($_POST['upload'])) {
  	// Get image name
  	$image = $_FILES['image']['name'];
  	// Get user_id
  	$user_id = mysqli_real_escape_string($db, $_POST['user_id']);
      // Get name
  	$name = mysqli_real_escape_string($db, $_POST['name']);
      // Get messa
  	$messa = mysqli_real_escape_string($db, $_POST['messa']);
      // Get pin
  	$pin = mysqli_real_escape_string($db, $_POST['pin']);
  	// image file directory
  	$target = "images/".basename($image);

  	$sql = "INSERT INTO `pin_request` (`user_id`, `name`, `messa`, `pin`, `image`) VALUES ('$user_id', '$name', '$messa', '$pin', '$image')";
  	// execute query
  	mysqli_query($db, $sql);

  	if (move_uploaded_file($_FILES['image']['tmp_name'], $target)) {
  		$msg = "Image uploaded successfully";
  	}else{
  		$msg = "Failed to upload image";
  	}
  }
  $result = mysqli_query($db, "SELECT * FROM `pin_request`");
?>
    
   
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <title>Data Tables</title>
    <!-- Bootstrap CSS -->
    <link rel="stylesheet" href="assets/vendor/bootstrap/css/bootstrap.min.css">
    <link href="assets/vendor/fonts/circular-std/style.css" rel="stylesheet">
    <link rel="stylesheet" href="assets/libs/css/style.css">
    <link rel="stylesheet" href="assets/vendor/fonts/fontawesome/css/fontawesome-all.css">
    <link rel="stylesheet" type="text/css" href="assets/vendor/datatables/css/dataTables.bootstrap4.css">
    <link rel="stylesheet" type="text/css" href="assets/vendor/datatables/css/buttons.bootstrap4.css">
    <link rel="stylesheet" type="text/css" href="assets/vendor/datatables/css/select.bootstrap4.css">
    <link rel="stylesheet" type="text/css" href="assets/vendor/datatables/css/fixedHeader.bootstrap4.css">
    <link rel="stylesheet" href="/path/to/dist/css/image-zoom.css" />
<script src="js/zooming.min.js"></script>
</head>

<body>

    <div class="dashboard-main-wrapper">

        <?php
        include_once("element/sidebar.php");
         ?>
         <div class="dashboard-wrapper">
             <div class="container-fluid  dashboard-content">

                 <div class="row">

<?php
                          $details=mysqli_fetch_array(mysqli_query($conn,"SELECT * FROM `pin_request` WHERE `user_id`"));
                          ?>

                   <div class="col-12">
                         <div class="card">
                             <h5 class="card-header">Pin Requests</h5>
                             <div class="card-body">
                                 <div class="table-responsive">
                                     <table class="table table-striped table-bordered first">
                                         
                                         <thead>
                                             
          
                                            
                                             <tr>
                                                 <th>Sr no</th>
                                                 <th>Payment Reciept</th>
                                                 <th>User ID</th>
                                                 <th>Name</th>
                                                 <th>Message</th>
                                                 <th>Pin Amount</th>
                                                 <th>Request Date</th>
                                                 <th>Action</th>
                                             </tr>
                                         </thead>
                                          
                                         <tbody>
                                             <?php
                                           $a=0;
                                               $data=mysqli_query($conn,"SELECT * FROM `pin_request` WHERE `status`='0'");
                                               while ($d=mysqli_fetch_array($data)) {
                                                 ?>
                                            
                                             
                                <style>
                                    .php-image img{
                                        width:90px
                                    }
                                             </style>
                                             <script>
  new Zooming().listen('img')
</script>
                                                 <tr>
                                                    
                                                   <th><?php   echo "<p>". ++$a ."</p>"; ?></th>
                                                   <th><div class="php-image"><?php  echo "<img <img id='img' data-action='zoom' style='width:90px' src='../images/".$d['image']."' >"; ?></div></th>
                                                     <th><?php echo $d['user_id'] ?></th>
                                                   <th><?php echo $d['name'] ?></th>
                                                   <th><?php echo $d['messa'] ?></th>
                                                   <th><?php echo $d['pin'] ?></th>
                                                   <th><?php echo $d['timestamp'] ?></th>                                        
                                                   <th>
                                                       <form class="" action="element/redirect.php" method="post">
                                                           
                                                       <div class="form-group">
                                              <label for="inputPassword">ID</label>
                                              <input id="inputPassword" type="tel" required="" class="form-control" value="<?php echo $d['user_id'] ?>" name="id">
                                          </div>
                                          <div class="form-group">
                                              <label for="inputRepeatPassword">Pin count</label>
                                              <input id="inputRepeatPassword" data-parsley-equalto="#inputPassword" name="pin_count" type="text" placeholder="Enter Pin" class="form-control" oninput="this.value = this.value.toUpperCase()" value="<?php echo $d['pin'] ?>" required >
                                             
                                          </div>
                                                     
                                                       <input type="text" name="res_id" value="<?php echo $d['id'] ?>" hidden>
                                                       <button type="submit" class="btn btn-sm btn-secondary" name="send_epin">Approve</button>
                                                     </form>
                                                   </th>
                                                 </tr>
                                                 <?php
                                               }
                                                                                        
                                            ?>

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

                 </div>

             </div>


         </div>

    </div>
    <!-- ============================================================== -->
    <!-- end main wrapper -->
    <!-- ============================================================== -->
    <!-- Optional JavaScript -->
    <script src="assets/vendor/jquery/jquery-3.3.1.min.js"></script>
    <script src="medium-zoom.min.js"></script>
    <script src="main.js"></script>
    <script src="assets/vendor/bootstrap/js/bootstrap.bundle.js"></script>
    <script src="assets/vendor/slimscroll/jquery.slimscroll.js"></script>
    <script src="assets/vendor/multi-select/js/jquery.multi-select.js"></script>
    <script src="assets/libs/js/main-js.js"></script>
    <script src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js"></script>
    <script src="assets/vendor/datatables/js/dataTables.bootstrap4.min.js"></script>
    <script src="https://cdn.datatables.net/buttons/1.5.2/js/dataTables.buttons.min.js"></script>
    <script src="assets/vendor/datatables/js/buttons.bootstrap4.min.js"></script>
    <script src="assets/vendor/datatables/js/data-table.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.1.3/jszip.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.36/pdfmake.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.36/vfs_fonts.js"></script>
    <script src="https://cdn.datatables.net/buttons/1.5.2/js/buttons.html5.min.js"></script>
    <script src="https://cdn.datatables.net/buttons/1.5.2/js/buttons.print.min.js"></script>
    <script src="https://cdn.datatables.net/buttons/1.5.2/js/buttons.colVis.min.js"></script>
    <script src="https://cdn.datatables.net/rowgroup/1.0.4/js/dataTables.rowGroup.min.js"></script>
    <script src="https://cdn.datatables.net/select/1.2.7/js/dataTables.select.min.js"></script>
    <script src="https://cdn.datatables.net/fixedheader/3.1.5/js/dataTables.fixedHeader.min.js"></script>

</body>

</html>
