<?php
@session_start();
include "control/activity.php";

 $dd = new activity();
 $loginStatus = $_SESSION['loginDetails'];


  if($loginStatus == null){
    echo "<script>window.open('login.php','_self')</script>";
  }



  $table = "admin_calculation";
  $condition = null;
  $getAdminDetails = $dd->single($table,$condition);
  
?>

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.0.0/dist/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<title><?= $getAdminDetails['title']; ?></title>
</head>
<body>

    <div class="main" id="main">
		  <?php include "menu.php"; ?>
    <div class="right"> 
  <div class="tab-content">


   <?php include "headermenu.php"; ?>


        <!-- Overview -->
         <div id="overview" class="tab-pane active"  >
                <div class="content" >
                  
               <div class="content-wrapper">
                 <div class="container-fluid">

                      <!--======================================================  Content  ====================================================-->                                            
                          <ol class="breadcrumb">
                            <li class="breadcrumb-item">
                              <a href="dashboard.php">Gift Card</a>
                            </li>
                          </ol>

                          <div class="row">
                              <div class="col-xl-12 col-sm-12 mb-12">
                                 <table class="table table-bordered data-table">
                                    <tr>
                                        <td colspan="7px"><button onclick="createGiftCraed()" style="float:right;" class="fa fa-plus"> Create Gift</button></td>
                                    </tr>
                                    <tr id="craeteInputSection" style="display:none;"><form method="post">
                                       <td><input required class="form-control" id="giftcardnumber" onkeyup="getEntry()" name="giftNumber" placeholder="Gift Number"/></td>
                                       <td><input required class="form-control" name="amount" placeholder="Amount"/></td>
                                       <td><input required class="form-control" name="nooffgift" placeholder="No Of Gift"/></td>
                                       <td><button name="submit" id="buttonData" disabled>Submit</button></td></form>
                                       <td colspan="3px"></td>
                                    </tr>
                                    <table>
<script>
    function getEntry()
    {
         var ttttt = document.getElementById('giftcardnumber').value; 
         if(ttttt.length >= 6){
                const xhttp = new XMLHttpRequest();
                xhttp.onload = function() {
                    var demo_show = this.responseText;
                    const exData = JSON.parse(demo_show);
                    if(exData.status == 'success'){
                         document.getElementById("buttonData").disabled = false;
                    }
                    else{
                       alert('Sorry Already exist..!!');
                    }
                    
                }
                xhttp.open("GET", "chekGiftCradDetails.php?cardNumber="+ttttt);
                xhttp.send(); 
            


         }
    }
</script>





                                    <table class="table table-bordered data-table">
                                    <tr>
                                        <th>Sr</th>
                                        <th>Gift Card</th>
                                        <th>Total Used</th>
                                        <th>Available</th>
                                        <th>Created Date</th>
                                        <th>Amount</th>
                                        <th>status</th>
                                    </tr>
                                    <?php
                                      $table = "gift_card";
                                      $condition = null;
                                      $result = $dd->fetch_multi($table,$condition);
                                      foreach($result as $key){
                                        @$i++;
                                    ?>
                                    <tr>
                                        <td><?= $i; ?></td>
                                        <td><?= $key->giftNumber; ?></td>
                                        <td><?= $key->total_used; ?></td>
                                        <td><?= $key->number_of_people-$key->total_used; ?></td>
                                        <td><?= $key->create_date; ?></td>
                                        <td><?= $key->amount; ?></td>
                                        <td><?= $key->status; ?></td>
                                    </tr>
                                    <?php } ?>
                                 </table>
                              </div>
                          </div>
  
                           
      <!--============  FIN DE L'AJOUT  ===============-->
      
<script>
 function createGiftCraed()
 {
     document.getElementById("craeteInputSection").style.display = "block";
 }



</script>
      
     
      </div>
      <!-- /.container-fluid-->
       </div>  <!-- /content-wrapper-->


                </div>
                </div>
             </div><!--Right panel-->
</div><!--Main-->


</body>
</html>

<?php
  if(isset($_REQUEST['submit']))
  {
     $giftNumber = $_REQUEST['giftNumber'];
     $amount = $_REQUEST['amount'];
     $nooffgift = $_REQUEST['nooffgift'];
     $date = date("h:i d/m/Y");
     $table = " gift_card";
     $value = "(`giftNumber`, `number_of_people`, `amount`, `create_date`, `status`) 
     VALUES ('$giftNumber','$nooffgift ','$amount','$date','success')";
     $result = $dd->insertData($table,$value);
     if($result){
         echo "<script>alert('Created Successfully..!!'),window.open('?','_self')</script>";
     }

  }

?>




<script>
    function getAction(a)
    {
       var tttt = confirm('Are you sure to get ACTION..!!');
       if(tttt == true){
          window.open('getWithdraw.php?payIId='+a,'_self');
       }
    }
</script>



<?php include "style.php" ?>