<?php

include("auth.php");
if($_GET['id']==""){
echo"invalid id";
return;
}else{
$id = $_GET['id'];
}
$sql=mysqli_query($conn,"SELECT * FROM qr_data WHERE id='".$id."'");
if(mysqli_num_rows($sql)==0){
echo"invalid id";
return;
}
//$server_data = mysqli_fetch_assoc($sql);
$api_data = mysqli_fetch_assoc($sql);


?>
<!DOCTYPE html>
<html lang="en">

<head>
  <title>Edit QR - @radiumsahil</title>
<?php include("include/head.php"); ?>  
</head>

<body id="page-top">
  <div id="wrapper">
    <!-- Sidebar -->
<?php include ("include/slidebar.php"); ?>
    <!-- Sidebar -->
    <div id="content-wrapper" class="d-flex flex-column">
      <div id="content">
        <!-- TopBar -->
<?php include ("include/topbar.php"); ?>              
        <!-- Topbar -->

  <div class="container-fluid" id="container-wrapper">
          <div class="d-sm-flex align-items-center justify-content-between mb-4">
            <h1 class="h3 mb-0 text-gray-800">Dashboard</h1>
            <ol class="breadcrumb">
              <li class="breadcrumb-item"><a href="#">Home</a></li>
              <li class="breadcrumb-item active" aria-current="page">Add Api</li>
            </ol>
          </div>

          <div class="row">
            <div class="col-lg-6">
              <!-- Form Basic -->
              <div class="card mb-4" id="loading">
                <div class="card-header py-3 d-flex flex-row align-items-center justify-content-between">
                  <h6 class="m-0 font-weight-bold text-primary">EDIT QR</h6>
                </div>
                <div class="card-body">
                     <div class="form-group">
                      <label for="exampleInputPassword1">Name</label>
                      <input type="text" class="form-control" id="api_name"  placeholder="Enter holder" value="<?php echo $api_data['name'];?>">
                    </div>
                    <div class="form-group">
                      <label for="exampleInputPassword1">Merchant Key</label>
                      <input type="text" class="form-control" id="mkey"  placeholder="Enter Merchat Key" value="<?php echo $api_data['merchant_key'];?>">
                    </div>
                    
                     <div class="form-group">
                      <label for="exampleInputPassword1">Upi ID</label>
                      <input type="text" class="form-control" id="upi_id"  placeholder="UPI_ID" value="<?php echo $api_data['upi_id'];?>">
                    </div>
                      <div class="form-group">
                      <label for="exampleInputPassword1">Minimum Amount</label>
                      <input type="text" class="form-control" id="min"  placeholder="Enter Min Amount" value="<?php echo $api_data['min'];?>">
                    </div>
                      <div class="form-group">
                      <label for="exampleInputPassword1">Maximum Amount</label>
                      <input type="text" class="form-control" id="max"  placeholder="Enter Max amount " value="<?php echo $api_data['max'];?>">
                    </div>
                      <div class="form-group">
                      <label for="exampleInputPassword1">Daily Limit</label>
                      <input type="text" class="form-control" id="limi"  placeholder="Enter Daily Limit" value="<?php echo $api_data['limi'];?>">
                    </div>
                   <button type="submit" id="update" class="btn btn-primary w-100 mb-2">Submit</button><br>
                </div>
              
        <!---Container Fluid-->
      </div>
      <!-- Footer -->
<?php // include("include/copyright.php");
 ?>
      <!-- Footer -->
    </div>
  </div>

  <!-- Scroll to top -->
  <a class="scroll-to-top rounded" href="#page-top">
    <i class="fas fa-angle-up"></i>
  </a>
<?php include("include/script.php"); ?>
<script>
$(document).ready(function() {
    // Attach a click event handler to the button

    $("#update").click(function() {
        Notiflix.Block.Dots('#loading', 'Please Wait');
    var api_name = $("#api_name").val();
    var upi_id = $("#upi_id").val();
    var mkey = $("#mkey").val();
    var min = $("#min").val();
    var max = $("#max").val();
     var limi = $("#limi").val();
   
        var params = {
        name: api_name,
        upi_id: upi_id,
        mkey: mkey,
        min:min,limi:limi,max:max,
        id:"<?php echo $_GET['id'];?>"
        };

        $.ajax({
            type: "POST",
            url: "ajax/edit_qr.php",
            data: params,
            error: function (e) {
                console.log(e);
            },
            success: function (data) {
                   Notiflix.Block.Remove('#loading');
             $('#update').html(data);
                $('#update').html("Add QR");

            }
        });
    });
});
</script>




</body>

</html>
