<?php
require("header.php")
?>
<style>
  .btn-group>.btn:not(:last-child):not(.dropdown-toggle) {
    background: black;
  }

  .btn-group>.btn-group:not(:first-child)>.btn {
    background: black;
  }

  .page-item.active .page-link {
    background: black;
  }

  .dt-button-collection .dropdown-menu .buttons-columnVisibility {
    background-color: black;
  }
</style>
<div class="content-wrapper">
  <!-- Content Header (Page header) -->
  <section class="content-header">
    <div class="container-fluid">
      <div class="row mb-2">
        <div class="col-sm-6">
          <!-- <h1>Add Notice for user!!</h1> -->
        </div>
        <div class="col-sm-6">

        </div>
      </div>
    </div><!-- /.container-fluid -->
  </section>

  <section class="content">
    <div class="container-fluid">
      <div class="row">
        <div class="col-12">
          <!-- /.card -->

          <div class="card card-secondary">
            <div class="card-header"  style="background-color: black;">
              <h3 class="card-title">Add Track</h3>
              <!--<ol class="breadcrumb float-sm-right">-->
              <!--    <li class="breadcrumb-item"><a href="#"></a></li>-->
              <!--    <li class="breadcrumb-item"><a href="#"></a></li>-->

              <!--</ol>-->
            </div>
            <!-- /.card-header -->
            <div class="card-body">
              <form action="add_track_code.php" method="post">
                <div class="row">
                  <div class="col-sm-12">

                    <div class="form-group">
                      <label for="exampleInputEmail1">Track Number<span style="color:red; font-size:25px;">*<span></label>
                      <textarea class="form-control" rows="5" name="track_number" placeholder="Enter ..." required></textarea>

                    </div>
                  </div>
                  <div class="col-sm-2">

                    <button type="submit" style="margin-top: 45px;width:95%; margin-left:5%; background:black;" name="add" class="btn btn-dark">Create</button>

                  </div>
                </div>

              </form>


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

          </div>

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

        <!-- /.col -->
      </div>
      <!-- /.row -->

      <!-- /.container-fluid -->
  </section>
  <!-- Main content -->
  <section class="content">
    <div class="container-fluid">
      <div class="row">

        <div class="col-md-12">
          <!-- general form elements -->
          <div class="card card-secondary">
            <div class="card-header" style="background-color: black;">
              <!-- <h3 class="card-title">Whatsapp Filter</h3> -->
              <ol class="breadcrumb float-sm-right"  style="background-color: black;">
                <li class="breadcrumb-item"><a href="dashboad.php">Home</a></li>
                <li class="breadcrumb-item">Track</li>

              </ol>
            </div>

            <!-- /.card-header -->
            <!-- form start -->
            <section class="content">
              <div class="container-fluid">
                <div class="row">
                  <!-- left column -->
                  <div class="col-md-12">
                    <!-- general form elements -->

                  </div>

                </div>
                <!-- /.row -->
              </div><!-- /.container-fluid -->
            </section>

            <section class="content">
              <div class="container-fluid">
                <div class="row">
                  <div class="col-12">
                    <div class="card shadow">

                      <!-- /.card-header -->
                      <div class="card-body">
                        <div id="example2_wrapper" class="dataTables_wrapper dt-bootstrap4">
                          <div class="row">
                            <div class="col-sm-12 col-md-6"></div>
                            <div class="col-sm-12 col-md-6"></div>
                          </div>
                          <div class="row">
                            <div class="col-sm-12">
                              <table class="table-responsive text-center">
                                <table id="example2" class="table table-bordered table-hover dataTable dtr-inline display text-center" aria-describedby="example2_info">
                                  <thead>
                                    <tr>
                                      <th>Sr No.</th>
                                      <th>Date &amp; time</th>

                                      <th>Track Number</th>
                                      <th>Status</th>

                                    </tr>
                                  </thead>
                                  <tbody>
                                    <?php


                                    include('connection.php');


                                    $a = 0;
                                    $sql = "SELECT * FROM track  ORDER BY date_time";
                                    $res = mysqli_query($conn, $sql);

                                    while ($row = mysqli_fetch_assoc($res)) {
                                      $trackNumbers = nl2br($row['track_file']); // Convert newline characters to <br>
                                      $a++;
                                    ?>

                                      <tr>
                                        <td><?php echo $a; ?></td>
                                        <td><?php echo $row['date_time']; ?></td>
                                        <td><?php echo $trackNumbers; ?></td>

                                        <td class="mailbox-attachment" style="color:red;font-weight:600"><a href="track_delete.php?id=<?php echo $row['id']; ?>" class="btn btn-danger btn-xs"><i class="fas fa-trash"></i></a></td>

                                        <td>

                                        </td>

                                      </tr>

                                    <?php
                                    }
                                    ?>

                                    <!-- Add more rows as needed -->
                                  </tbody>

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

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

                  </div>
                  <!-- /.col -->
                </div>

              </div>

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




        </div>

      </div>

      <!-- /.col -->
    </div>
    <!-- /.row -->

    <!-- /.container-fluid -->
  </section>
  <!-- /.content -->
</div>

<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
<!-- Sweet Alert  start-->
<?php if (isset($_REQUEST['msg']) && $_REQUEST['msg'] == 1) { ?>
  <script>
    Swal.fire(
      'Good job!',
      'Track Added Successfully!!',
      'success'
    ).then(() => {
      window.location.href = "add_track.php";
    });
  </script>
<?php } ?>

<?php if (isset($_REQUEST['msg']) && $_REQUEST['msg'] == 2) { ?>
  <script>
    Swal.fire(
      'Oops...',
      'Something went wrong!!',
      'error'
    ).then(() => {
      window.location.href = "add_track.php";
    });
  </script>
<?php } ?>
<?php
require("footer.php")
?>