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

 $datetoday = date('Y-m-d'); 
$active_tab = "code";
if (!isset($_SESSION['unique_id'])) { ?>
    <script language="javascript">
      window.location.href = '../index.php';
    </script>
<?php } 

$success_messages = '';
if (isset($_POST['generate'])) {
  function generateRandomString($length = 8) {
          $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
          $charactersLength = strlen($characters);
          $randomString = '';
          for ($i = 0; $i < $length; $i++) {
              $randomString .= $characters[rand(0, $charactersLength - 1)];
          }
          return $randomString;
  }

  $count = 10;
  for($i=0;$i<$count;$i++){
    $gencodes = generateRandomString();

    $sql_generate = "INSERT INTO tbl_verification_code(verification_code, status, date_added,count) VALUES('$gencodes', '0', '$datetoday','1')";
    if (mysqli_query($conn, $sql_generate)) {
      $success_messages = '<div class="alert alert-success text-center mb-0">Successfully generate codes</div>';
    }
  }
}


if (isset($_POST['generate_multiple'])) {
  $count_codes =  $_POST['code_count'];

  function generateRandomString($length = 7) {
          $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
          $charactersLength = strlen($characters);
          $randomString = '';
          for ($i = 0; $i < $length; $i++) {
              $randomString .= $characters[rand(0, $charactersLength - 1)];
          }
          return $randomString;
  }

  $count = 3;
  for($i=0;$i<$count;$i++){
    $gencodes = generateRandomString();

    $sql_generate = "INSERT INTO tbl_verification_code(verification_code, status, date_added,count) VALUES('$gencodes', '0', '$datetoday','$count_codes')";
    if (mysqli_query($conn, $sql_generate)) {
      $success_messages = '<div class="alert alert-success text-center mb-0">Multiple account codes generated Successfully</div>';
    }
  }
}


?>  
<html>
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title>Activation Code</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 href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,400i,700" rel="stylesheet">
  <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 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;
    }
  }
  @media(max-width:991px) {
    #order_full_screen {
      display: none!important;
    }
    #order_small_screen {
      display: block!important;
    }
  }
  .page-item.active .page-link {
    background-color: #27313d!important;
    border-color: #27313d!important;
    color: #000;
  }
  .page-item .page-link {
    background-color: #151e27!important;
    border-color: grey!important;
    color: grey!important;
  }
  .transaction a {
    color: #808080!important;
  }  

  .transaction a.active {
    background-color: transparent!important;
    border-top: transparent;
    border-left: transparent;
    border-right: transparent;
    border-bottom: 2px solid #ffd700!important;
    color: #ffd700!important;
    font-weight: bold;
  }  

  .transaction a:hover{
    border-bottom: 2px solid #ffd700!important;
    border-top: 0px!important;
    border-left: 0px!important;
    border-right: 0px!important;
  }
  .alert-success {
    color: #3c763d;
    background-color: #dff0d8;
    border-color: #d6e9c6;
    border-radius: 0;
  }

  .alert-danger {
    color: #a94442;
    background-color: #f2dede;
    border-color: #ebccd1;
    border-radius: 0;
  }
  .txn-history {
    text-align: left;
  }
  .txn-list {
    background-color: #151e27;
    padding: 12px 10px; 
    color: #777;
    font-size: 14px;
    margin: 7px 0;
    box-shadow: 0 2px 5px 0 rgba(0,0,0,.16), 0 2px 10px 0 rgba(0,0,0,.12)!important;
  }
  .transaction-amount {
    float: right;
    color: #fff;
  }
  .transaction-number {
   float: right;
  }
  .form-control {
    border-radius: 10px;
  }
</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 back_arrow"><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;">Activation Code</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">
  <div class="content-header p-0">
    <div class="container-fluid p-0">
      <span id="message">
        <?php echo $success_messages; ?>
      </span>
    </div>
  </div>







  <section class="content">
 
  <div class="col-md-12">
            <div class="card card-warning collapsed-card">
              <div class="card-header">
                <h3 class="card-title">Single Account Activation Codes</h3>

                <div class="card-tools">
                  <button type="button" class="btn btn-tool" data-card-widget="collapse"><i class="fas fa-plus"></i>
                  </button>
                </div>
                <!-- /.card-tools -->
              </div>
              <!-- /.card-header -->
              <div class="card-body">
               
<div class="container-fluid pt-3">
 <div class="card" style="border-radius: 10px; background-color: #1d2532; color: #fff;">
              <div class="card-body pt-2 pb-2">
                <div style="display: flex; justify-content: space-between;">
                  <h6 class="pt-2">Generate Activation Code</h6>     
                  <button type="button" data-toggle="modal" data-target="#generate" class="btn btn-success btn-sm">Generate</button> 
                </div>
          
              </div>
            </div>

            <div class="card mt-3" style="border-radius: 10px; background-color: #1d2532; color: #fff;">
              <nav>
                  <div class="nav nav-tabs transaction nav-fill" id="myTab" role="tablist">
                      <a class="nav-item nav-link active" href="#pending" data-toggle="tab" role="tab" aria-controls="nav-home" aria-selected="true">
                        Active
                      </a>
                      <a class="nav-item nav-link" href="#complete" data-toggle="tab" role="tab" aria-controls="nav-profile" aria-selected="false">
                        Used
                      </a>
                  </div>
              </nav>

            <div class="tab-content">
              <div role="tablist" class="active tab-pane" id="pending">

                  <div class="card-body table-responsive p-3" id="order_full_screen">
              <center>
                <span id="alert_show"></span>
              </center>
                    <table id="activation_code_table" class="table table-hover">
                      <thead>
                      <tr>
                        <th>Activation Code</th>
                        <th width="17%">Action</th>
                      </tr>
                      </thead>
                      <tbody id="pending_tbody">
                      <?php 
                        $sql_code = "SELECT * FROM tbl_verification_code WHERE status = '0' and count = '1'";
                        $result_code = $conn->query($sql_code);
                          while($row_code = mysqli_fetch_array($result_code)) {
                      ?>
                      <tr>
                        <td><span class="badge badge-warning" style="font-size: 15px;"><?php echo $row_code['verification_code']; ?></span></td>
                        <td>
                          <input type="hidden" id="code<?php echo $row_code['id']; ?>" value="<?php echo $row_code['verification_code']; ?>">
                          <a id="copyToClipboard<?php echo $row_code['id']; ?>" class="btn btn-sm btn-info">Copy Code</a>
                        </td>
                      </tr>
                      <script type="text/javascript">
                        $(document).ready(function () {
                          $('#copyToClipboard<?php echo $row_code['id']; ?>').click(function() {
                            var textBox = $("#code<?php echo $row_code['id']; ?>").val();
                            navigator.clipboard.writeText(textBox);
                            $('#alert_show').html('COPIED');
                          });
                        });
                      </script>
                      <?php } ?>
                      </tbody>
                    </table>
                  </div>

                  <span id="order_small_screen" style="display:none;">
             <?php
              $sql_code = "SELECT * FROM tbl_verification_code WHERE status = '0'and count = '1'";
              $result_code = $conn->query($sql_code);
              if ($result_code->num_rows > 0) { ?>
                <div class="input-group mb-3 mt-3 ml-2">
                  <div class="input-group-prepend">
                    <button class="btn bg-white" style="border-top-left-radius: 10px; border-bottom-left-radius: 10px;" type="submit" name="search"><i class="fas fa-search" ></i></button>
                  </div>
                  <input type="text" class="form-control border-left-0 mr-3" id="code_search" placeholder="Search Order number..." required/>
                </div>
              <?php } ?>
              <center>
                <span id="alert_show_small"></span>
              </center>
              <span id="search_result">
                    <?php 
                        $sql_code = "SELECT * FROM tbl_verification_code WHERE status = '0'and count = '1'";
                        $result_code = $conn->query($sql_code);
                        if ($result_code->num_rows > 0) {
                          while($row_code = mysqli_fetch_array($result_code)) {
                    ?>
                    <a id="copyToClipboardSmall<?php echo $row_code['id']; ?>">
                    <input type="hidden" id="code_small<?php echo $row_code['id']; ?>" value="<?php echo $row_code['verification_code']; ?>">
                      <div class="txn-history ml-2 mr-2">
                        <p class="txn-list">
                          <span class="text-white">Activation Code: </span><span class="transaction-amount" style="color: #ffd700;"><?php echo $row_code['verification_code']; ?></span>
                        </p>
                      </div>
                    </a>
                    <script type="text/javascript">
                        $(document).ready(function () {
                          $('#copyToClipboardSmall<?php echo $row_code['id']; ?>').click(function() {
                            var textBox = $("#code_small<?php echo $row_code['id']; ?>").val();
                            navigator.clipboard.writeText(textBox);
                            $('#alert_show_small').html('COPIED');
                          });
                        });
                      </script>
                    <?php } }else{ ?>
                      <center>
                          <div class="text-center error-content p-3">
                            <i class="fas fa-box-open text-warning" style="margin-top: 30px; margin-bottom: 10px; font-size: 80px;"></i>
                            <h6 class="font-weight-bold text-white"> No Activation Code.</h6>
                            <br><br>
                        </div>
                      </center>
                    <?php } ?>
              </span>
                    </span>


              </div>

                <div role="tablist" class="tab-pane" id="complete">

                  <div class="card-body table-responsive p-3" id="order_full_screen">
                    <table id="used_table" class="table table-hover">
                      <thead>
                      <tr>
                        <th>Activation Code</th>
                        <th width="17%">Action</th>
                      </tr>
                      </thead>
                      <tbody id="pending_tbody">
                      <?php 
                        $sql_code = "SELECT * FROM tbl_verification_code WHERE status = '1'and count = '1'";
                        $result_code = $conn->query($sql_code);
                          while($row_code = mysqli_fetch_array($result_code)) {
                      ?>
                      <tr>
                        <td><span class="badge badge-warning" style="font-size: 15px;"><?php echo $row_code['verification_code']; ?></span></td>
                        <td>
                          <a class="btn btn-sm btn-info disabled">Used</a>
                        </td>
                      </tr>
                      <?php } ?>
                      </tbody>
                    </table>
                  </div>

                  <span id="order_small_screen" style="display:none;">
                    <?php 
                        $sql_code = "SELECT * FROM tbl_verification_code WHERE status = '1'and count = '1'";
                        $result_code = $conn->query($sql_code);
                        if ($result_code->num_rows < 0) {
                          while($row_code = mysqli_fetch_array($result_code)) {
                    ?>
                    <a>
                      <div class="txn-history ml-2 mr-2">
                        <p class="txn-list">
                          <span class="text-white">Activation Code: </span><span class="transaction-amount" style="color: #ffd700;"><?php echo $row_code['verification_code']; ?></span>
                        </p>
                      </div>
                    </a>
                    <?php } }else{ ?>
                      <center>
                          <div class="text-center error-content p-3">
                            <i class="fas fa-box-open text-warning" style="margin-top: 30px; margin-bottom: 10px; font-size: 80px;"></i>
                            <h6 class="font-weight-bold text-white"> No Used Code.</h6>
                            <br><br>
                        </div>
                      </center>
                    <?php } ?>
                  </span>

                </div>
            </div>

              </div>
              <!-- /.card-body -->
            </div>
            <!-- /.card -->
     </div>
     </div>
  </div>

  

<div class="modal" id="generate">
  <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;">Generate Code</h5>
      </div>
      <div class="modal-body pt-0 pb-0">
        <p class="text-muted">Are you sure you want to generate?</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">
            <form method="POST" style="margin: 0px;">
              <button type="submit" name="generate" class="btn btn-warning btn-lg btn-block withanimation_submit" style="background: #FFD700; border-color: #ffd700;">Yes, Generate</button>
            </form>
          </div>
        </div>
        
      </div>
    </div>
  </div>
</div>


<!-- FOR MULTIPLE ACCOUNTS-->

<div class="col-md-12">
            <div class="card card-danger collapsed-card">
              <div class="card-header">
                <h3 class="card-title">Multiple Account Activation Codes</h3>

                <div class="card-tools">
                  <button type="button" class="btn btn-tool" data-card-widget="collapse"><i class="fas fa-plus"></i>
                  </button>
                </div>
                <!-- /.card-tools -->
              </div>
              <!-- /.card-header -->
              <div class="card-body">
            
<div class="container-fluid pt-3">
 <div class="card" style="border-radius: 10px; background-color: #1d2532; color: #fff;">
              <div class="card-body pt-2 pb-2">
                <div style="display: flex; justify-content: space-between;">
                
                
             
                
                <h6 class="pt-2">Generate Activation Code</h6>  
               
                  <button type="button" data-toggle="modal" data-target="#generate_multiple" class="btn btn-success btn-sm">Generate</button> 
                </div>
          
              </div>
            </div>

            <div class="card mt-3" style="border-radius: 10px; background-color: #1d2532; color: #fff;">
              <nav>
                  <div class="nav nav-tabs transaction nav-fill" id="myTab" role="tablist">
                      <a class="nav-item nav-link active" href="#pending" data-toggle="tab" role="tab" aria-controls="nav-home" aria-selected="true">
                        Active
                      </a>
                      <a class="nav-item nav-link" href="#complete" data-toggle="tab" role="tab" aria-controls="nav-profile" aria-selected="false">
                        Used
                      </a>
                  </div>
              </nav>

            <div class="tab-content">
              <div role="tablist" class="active tab-pane" id="pending">

                  <div class="card-body table-responsive p-3" id="order_full_screen">
              <center>
                <span id="alert_show"></span>
              </center>
                    <table id="activation_code_table" class="table table-hover">
                      <thead>
                      <tr>
                        <th>Activation Code</th>
                        <th width="17%">Activation Count</th>
                        
                        <th width="17%">Action</th>
                      </tr>
                      </thead>
                      <tbody id="pending_tbody">
                      <?php 
                        $sql_code = "SELECT * FROM tbl_verification_code WHERE status = '0' and count > 1";
                        $result_code = $conn->query($sql_code);
                          while($row_code = mysqli_fetch_array($result_code)) {
                      ?>
                      <tr>
                        <td><span class="badge badge-warning" style="font-size: 15px;"><?php echo $row_code['verification_code']; ?></span></td>
                        <td><span class="badge badge-warning" style="font-size: 15px;"><?php echo $row_code['count']; ?></span></td>

                        <td>
                          <input type="hidden" id="code<?php echo $row_code['id']; ?>" value="<?php echo $row_code['verification_code']; ?>">
                          <a id="copyToClipboard<?php echo $row_code['id']; ?>" class="btn btn-sm btn-info">Copy Code</a>
                        </td>
                      </tr>
                      <script type="text/javascript">
                        $(document).ready(function () {
                          $('#copyToClipboard<?php echo $row_code['id']; ?>').click(function() {
                            var textBox = $("#code<?php echo $row_code['id']; ?>").val();
                            navigator.clipboard.writeText(textBox);
                            $('#alert_show').html('COPIED');
                          });
                        });
                      </script>
                      <?php } ?>
                      </tbody>
                    </table>
                  </div>

                  <span id="order_small_screen" style="display:none;">
             <?php
              $sql_code = "SELECT * FROM tbl_verification_code WHERE status = '0' and count > 1";
              $result_code = $conn->query($sql_code);
              if ($result_code->num_rows > 0) { ?>
                <div class="input-group mb-3 mt-3 ml-2">
                  <div class="input-group-prepend">
                    <button class="btn bg-white" style="border-top-left-radius: 10px; border-bottom-left-radius: 10px;" type="submit" name="search"><i class="fas fa-search" ></i></button>
                  </div>
                  <input type="text" class="form-control border-left-0 mr-3" id="code_search" placeholder="Search Order number..." required/>
                </div>
              <?php } ?>
              <center>
                <span id="alert_show_small"></span>
              </center>
              <span id="search_result">
                    <?php 
                        $sql_code = "SELECT * FROM tbl_verification_code WHERE status = '0'and count > 1";
                        $result_code = $conn->query($sql_code);
                        if ($result_code->num_rows > 0) {
                          while($row_code = mysqli_fetch_array($result_code)) {
                    ?>
                    <a id="copyToClipboardSmall<?php echo $row_code['id']; ?>">
                    <input type="hidden" id="code_small<?php echo $row_code['id']; ?>" value="<?php echo $row_code['verification_code']; ?>">
                      <div class="txn-history ml-2 mr-2">
                        <p class="txn-list">
                          <span class="text-white">Count:&nbsp; <span class="badge badge-warning" style="font-size: 14px;"><?php echo $row_code['count']; ?></span> &nbsp;Activation Code: </span><span class="transaction-amount" style="color: #ffd700;"><?php echo $row_code['verification_code']; ?> </span>
             
                        </p>
                      </div>
                    </a>
                    <script type="text/javascript">
                        $(document).ready(function () {
                          $('#copyToClipboardSmall<?php echo $row_code['id']; ?>').click(function() {
                            var textBox = $("#code_small<?php echo $row_code['id']; ?>").val();
                            navigator.clipboard.writeText(textBox);
                            $('#alert_show_small').html('COPIED');
                          });
                        });
                      </script>
                    <?php } }else{ ?>
                      <center>
                          <div class="text-center error-content p-3">
                            <i class="fas fa-box-open text-warning" style="margin-top: 30px; margin-bottom: 10px; font-size: 80px;"></i>
                            <h6 class="font-weight-bold text-white"> No Activation Code.</h6>
                            <br><br>
                        </div>
                      </center>
                    <?php } ?>
              </span>
                    </span>


              </div>

                <div role="tablist" class="tab-pane" id="complete">

                  <div class="card-body table-responsive p-3" id="order_full_screen">
                    <table id="used_table" class="table table-hover">
                      <thead>
                      <tr>
                        <th>Activation Code</th>
                        <th width="17%">Action</th>
                      </tr>
                      </thead>
                      <tbody id="pending_tbody">
                      <?php 
                        $sql_code = "SELECT * FROM tbl_verification_code WHERE status = '1'and count > 1";
                        $result_code = $conn->query($sql_code);
                          while($row_code = mysqli_fetch_array($result_code)) {
                      ?>
                      <tr>
                        <td><span class="badge badge-warning" style="font-size: 15px;"><?php echo $row_code['verification_code']; ?></span></td>
                        <td>
                          <a class="btn btn-sm btn-info disabled">Used</a>
                        </td>
                      </tr>
                      <?php } ?>
                      </tbody>
                    </table>
                  </div>

                  <span id="order_small_screen" style="display:none;">
                    <?php 
                        $sql_code = "SELECT * FROM tbl_verification_code WHERE status = '1'and count > 1";
                        $result_code = $conn->query($sql_code);
                        if ($result_code->num_rows < 0) {
                          while($row_code = mysqli_fetch_array($result_code)) {
                    ?>
                    <a>
                      <div class="txn-history ml-2 mr-2">
                        <p class="txn-list">
                          <span class="text-white">Activation Code: </span><span class="transaction-amount" style="color: #ffd700;"><?php echo $row_code['verification_code']; ?></span>
                        </p>
                      </div>
                    </a>
                    <?php } }else{ ?>
                      <center>
                          <div class="text-center error-content p-3">
                            <i class="fas fa-box-open text-warning" style="margin-top: 30px; margin-bottom: 10px; font-size: 80px;"></i>
                            <h6 class="font-weight-bold text-white"> No Used Code.</h6>
                            <br><br>
                        </div>
                      </center>
                    <?php } ?>
                  </span>

                </div>
            </div>

              </div>
              <!-- /.card-body -->
            </div>
            <!-- /.card -->
     </div>

     </div>
<!-- END FOR MULTIPLE ACCOUNTS-->

 

<div class="modal" id="generate_multiple">
  <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;">Generate Code</h5>
      </div>
      <form method="POST" style="margin: 0px;">
      <div class="modal-body pt-0 pb-0">
   
             
        <p class="text-muted">For how many counts per multiple account you want to create?</p>
        <input type="number" min="3" value="3" name="code_count" class="btn-sm" style="font-size:18px;width:100%"/>
      </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="generate_multiple" class="btn btn-warning btn-lg btn-block withanimation_submit" style="background: #FFD700; border-color: #ffd700;">Yes, Generate</button>
            </form>
          </div>
        </div>
        
      </div>
    </div>
  </div>
</div>

    </div>
  </section>
</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 () {
  $('a[data-toggle="tab"]').on('show.bs.tab', function(e) {
      localStorage.setItem('activeTab', $(e.target).attr('href'));
  });
  var activeTab = localStorage.getItem('activeTab');
  if(activeTab){
      $('#myTab a[href="' + activeTab + '"]').tab('show');
  }

  $('#code_search').keyup(function() {
    var code = $(this).val();
    var btn_action = "code_search";
     $.ajax({
      url:'search_order.php',
      method:"POST",
      dataType:"html",
      data:{code:code, btn_action:btn_action},
      success:function(data){
        $('#search_result').html(data);
      }
    });
  });

});
$(function () {
  $(".withanimation").click(function(e) {
      e.preventDefault();
      $(".loading").show();
      var url=$(this).attr("href");
      setTimeout(function() {
          window.location=url;
      }, 500);
  });
});
$(function () {
  $("#activation_code_table").DataTable({
    "responsive": true,
    "autoWidth": false,
  });
  $('#example2').DataTable({
    "paging": true,
    "lengthChange": false,
    "searching": false,
    "ordering": true,
    "info": true,
    "autoWidth": false,
    "responsive": true,
  });

  $("#used_table").DataTable({
    "responsive": true,
    "autoWidth": false,
  });
  $('#example2').DataTable({
    "paging": true,
    "lengthChange": false,
    "searching": false,
    "ordering": true,
    "info": true,
    "autoWidth": false,
    "responsive": true,
  });

  $(".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);
  });
});
setTimeout(function(){
  $('#message').html('');
}, 5000);

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

if ( window.history.replaceState ) {
  window.history.replaceState( null, null, window.location.href );
}
</script>
</body>
</html>
