<?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>Order History</h1> -->
        </div>
        <div class="col-sm-6">

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

  <!-- Main content -->
  <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">Order History </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 active">Order History</li>
              </ol>
            </div>
            <!-- /.card-header -->
            <div class="card-body">
              <table id="example1" class="table table-bordered table-striped">
                <thead>
                  <tr>
                    <th>Date</th>
                    <th>User Id</th>
                    <th>Order ID</th>

                    <th>Vendor</th>
                    <th>Tracking</th>
                    <th>Status</th>

                  </tr>
                </thead>
                <tbody>
                  <?php
                  include('connection.php');

                  $sql = "SELECT * FROM new_order WHERE status='Delivered' ORDER BY date_time";
                  $res = mysqli_query($conn, $sql);
                  while ($row = mysqli_fetch_assoc($res)) {
                  ?>
                    <tr>
                      <td><?php echo $row['date_time']; ?></td>
                      <td>
                        <a href="#" class="user-id-linking" style="color:blue ;font-weight:600;" class="btn btn-default" data-toggle="modal" data-target="#modal-lg-id<?php echo $row['user_id']; ?>">

                          <?php echo $row['user_id']; ?>
                        </a>
                      </td>

                      <td>
                        <a href="#" class="user-id-link" style="color:blue ;font-weight:600;" class="btn btn-default" data-toggle="modal" data-target="#myModal<?php echo $row['order_id']; ?>">

                          <?php echo $row['order_id']; ?>
                        </a>
                      </td>

                      <td><?php echo $row['vendor']; ?></td>
                      <td style="display: flex;">
                        &nbsp;&nbsp;<?php echo $row['traking']; ?>&nbsp;&nbsp;
                        <a href="https://tools.usps.com/go/TrackConfirmAction?tRef=fullpage&tLc=2&text28777=&tLabels=<?php echo $row['traking']; ?>" target="_blank">
                          <small class="badge badge-warning">Status</small>
                          <a>

                      </td>
                      <td><button type="submit" id="approve_button" class="btn btn-info" style="font-weight: 600;font-size: 12px;height: 30px;"><?php echo $row['status']; ?></button></td>
                    </tr>

                    <!-- order id demo modal -->

                    <div class="modal fade" id="myModal<?php echo $row['order_id']; ?>" role="dialog">
                      <div class="modal-dialog modal-lg">
                        <div class="modal-content">
                          <div class="modal-header" style="background:black;">
                            <h6 class="modal-title float-left" style="font-weight:600; text-transform:uppercase">Order Id:<?php echo $row['order_id']; ?> </h6>
                            <button type="button" class="close" data-dismiss="modal">&times;</button>

                          </div>
                          <div class="modal-body">
                            <div class="row">
                              <div class="col-6">
                                <span style="font-weight:600; text-transform:uppercase">User name: </span> <span style="color:green">
                                  <?php echo $row['user_id']; ?>
                                </span>
                              </div>
                              <div class="col-6">
                                <span style="font-weight:600; text-transform:uppercase;float:right;">Added by: <span style="color:green;text-transform: none;font-weight:400;">
                                    Sadmin
                                  </span></span>
                              </div>
                            </div>
                           
                            <div class="row">

                              <div class="col-6">
                                <ul style="list-style-type: none">
                                  <li style="font-weight:600; text-transform:uppercase"> <i class="fa fa-chevron-right" aria-hidden="true" style="margin-right: 2%;font-size: 11px;"></i>Name: <span style="color:blueviolet;margin-left:1%;text-transform: none;font-weight:400;"><?php echo $row['name']; ?></span></li>
                                  <li style="font-weight:600; text-transform:uppercase"> <i class="fa fa-chevron-right" aria-hidden="true" style="margin-right: 2%;font-size: 11px;"></i>Address: <span style="color:blueviolet;margin-left:1%;text-transform: none;font-weight:400;"><?php echo $row['address']; ?></span></li>
                                  <li style="font-weight:600; text-transform:uppercase"> <i class="fa fa-chevron-right" aria-hidden="true" style="margin-right: 2%;font-size: 11px;"></i>City: <span style="color:blueviolet;margin-left:1%;text-transform: none;font-weight:400;"><?php echo $row['city']; ?></span></li>
                                  <li style="font-weight:600; text-transform:uppercase"> <i class="fa fa-chevron-right" aria-hidden="true" style="margin-right: 2%;font-size: 11px;"></i>Zip Code: <span style="color:blueviolet;margin-left:1%;text-transform: none;font-weight:400;"><?php echo $row['zipcode']; ?></span></li>
                                  <li style="font-weight:600; text-transform:uppercase"> <i class="fa fa-chevron-right" aria-hidden="true" style="margin-right: 2%;font-size: 11px;"></i>Product Name: <span style="color:blueviolet;margin-left:1%;text-transform: none;font-weight:400;"><?php echo $row['product_name']; ?></span></li>
                                </ul>
                              </div>
                              <div class="col-6">
                                <ul style="list-style-type: none">
                                  <li style="font-weight:600; text-transform:uppercase"> <i class="fa fa-chevron-right" aria-hidden="true" style="margin-right: 2%;font-size: 11px;"></i>Origin: <span style="color:blueviolet;margin-left:1%;text-transform: none;font-weight:400;"><?php echo $row['origin']; ?></span></li>
                                  <li style="font-weight:600; text-transform:uppercase"> <i class="fa fa-chevron-right" aria-hidden="true" style="margin-right: 2%;font-size: 11px;"></i>State: <span style="color:blueviolet;margin-left:1%;text-transform: none;font-weight:400;"><?php echo $row['state']; ?></span></li>
                                  <li style="font-weight:600; text-transform:uppercase"> <i class="fa fa-chevron-right" aria-hidden="true" style="margin-right: 2%;font-size: 11px;"></i>Country: <span style="color:blueviolet;margin-left:1%;text-transform: none;font-weight:400;"><?php echo $row['country']; ?></span></li>
                                  <li style="font-weight:600; text-transform:uppercase"> <i class="fa fa-chevron-right" aria-hidden="true" style="margin-right: 2%;font-size: 11px;"></i>Quantity: <span style="color:blueviolet;margin-left:1%;text-transform: none;font-weight:400;"><?php echo $row['quantity']; ?></span></li>
                                </ul>
                              </div>

                            </div>

                          </div>

                        </div>
                      </div>
                      <!-- order id demo modal -->
                    <?php } ?>
                </tbody>
                <!-- User ID Modal -->
                <?php
                $sql = "SELECT * FROM user ORDER BY date_time";
                $res = mysqli_query($conn, $sql);

                while ($row = mysqli_fetch_array($res)) {
                ?>
                  <div class="modal fade" id="modal-lg-id<?php echo $row['user_id']; ?>" style="display: none;" aria-hidden="true">
                    <div class="modal-dialog modal-lg">
                      <div class="modal-content">
                        <div class="modal-header" style="background:black;">
                          <h6 class="modal-title float-left">
                            <?php
                            echo '<span style="font-weight: 600; text-transform: uppercase">Added by : &nbsp;</span>';
                            $addedByChain = [];
                            $currentUser = $row;
                            while (!empty($currentUser['added_by'])) {
                              $addedByChain[] = $currentUser['added_by'];
                              $sql = "SELECT * FROM user WHERE user_id = '{$currentUser['added_by']}'";
                              $result = mysqli_query($conn, $sql);
                              $currentUser = mysqli_fetch_assoc($result);
                            }
                            $addedByChain = array_reverse($addedByChain);
                            foreach ($addedByChain as $addedByUser) {
                              echo '<span style="color: white;text-transform: none;">' . $addedByUser . '</span>';
                              echo '&nbsp;<i class="fa fa-chevron-right" aria-hidden="true" style="font-size: 12px;"></i>&nbsp;';
                            }
                            echo '<span style="text-transform: none;">' . $row['user_id'] . '</span>';
                            ?>
                          </h6>
                          <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                            <span aria-hidden="true">×</span>
                          </button>
                        </div>
                        <div class="modal-body">
                          <div class="row">

                            <div class="col-12">
                              <span style="float:center;font-weight:600; text-transform:uppercase">Created On&nbsp;:
                                &nbsp;</span> <span style="color:green">
                                <?php echo $row['date_time']; ?>
                              </span>
                            </div>

                          </div>
                          <br>

                          <div class="row">

                            <div class="col-6">
                              <ul style="list-style-type: none">
                                <li style="font-weight:600; text-transform:uppercase"> <i class="fa fa-chevron-right" aria-hidden="true" style="margin-right: 2%;font-size: 11px;"></i>Name: <span style="color:blueviolet;text-transform: none;margin-left:1%;font-weight:400;">
                                    <?php echo $row['user_name']; ?>
                                  </span></li>
                                <li style="font-weight:600; text-transform:uppercase"> <i class="fa fa-chevron-right" aria-hidden="true" style="margin-right: 2%;font-size: 11px;"></i>City: <span style="color:blueviolet;text-transform: none;margin-left:1%;font-weight:400;">
                                    <?php echo $row['city']; ?>
                                  </span></li>
                                <li style="font-weight:600; text-transform:uppercase"> <i class="fa fa-chevron-right" aria-hidden="true" style="margin-right: 2%;font-size: 11px;"></i>Password: <span style="color:blueviolet;text-transform: none;margin-left:1%;font-weight:400;">
                                    <?php echo $row['password']; ?>
                                  </span></li>
                              </ul>
                            </div>
                            <div class="col-6">
                              <ul style="list-style-type: none">
                                <li style="font-weight:600; text-transform:uppercase"> <i class="fa fa-chevron-right" aria-hidden="true" style="margin-right: 2%;font-size: 11px;"></i>Email: <span style="color:blueviolet;text-transform: none;margin-left:1%;font-weight:400;">
                                    <?php echo $row['user_email']; ?>
                                  </span></li>
                                <li style="font-weight:600; text-transform:uppercase"> <i class="fa fa-chevron-right" aria-hidden="true" style="margin-right: 2%;font-size: 11px;"></i>Country: <span style="color:blueviolet;text-transform: none;margin-left:1%;font-weight:400;">
                                    <?php echo $row['country']; ?>
                                  </span></li>
                                <li style="font-weight:600; text-transform:uppercase"> <i class="fa fa-chevron-right" aria-hidden="true" style="margin-right: 2%;font-size: 11px;"></i>Security Answer: <span style="color:blueviolet;text-transform: none;margin-left:1%;font-weight:400;">
                                    <?php echo $row['answer']; ?>
                                  </span></li>
                              </ul>
                            </div>

                          </div>


                        </div>

                      </div>

                    </div>

                  </div>
                <?php } ?>
                <!-- modal end -->

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

        </div>

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

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

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


<?php
require("footer.php")
?>