<?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>Credits 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">Add Credits History</h3>
              <ol class="breadcrumb float-sm-right" style="background-color: black;">
                <li class="breadcrumb-item"><a href="#">Home</a></li>
                <!-- <li class="breadcrumb-item">Credits</li> -->
                <li class="breadcrumb-item active">Credits History</li>
              </ol>
            </div>
            <!-- /.card-header -->
            <div class="card-body">
              <table id="example1" class="table table-bordered table-striped">
                <thead>
                  <tr>
                    <th>Sr. No</th>
                    <th>Date /Time</th>
                    <th>User Type</th>
                    <th>User Id</th>
                    <th>Credits</th>
                    <th>Credit Type</th>
                    <th>Credit Note</th>
                    <th>Added by</th>

                  </tr>
                </thead>
                <tbody>
                  <?php
                  include("connection.php");
                  $i = 0;

                  $sql = "SELECT * FROM credit WHERE added_by='Admin' ORDER BY date_time";
                  $res = mysqli_query($conn, $sql);
                  while ($row = mysqli_fetch_assoc($res)) {
                    $i++;

                  ?>
                    <tr>
                      <td><?php echo $i; ?></td>
                      <td><?php echo $row['date_time'];  ?></td>
                      <td><?php echo $row['user_type'];  ?></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><?php echo $row['credit'];  ?></td>
                      <td><?php echo $row['credit_type'];  ?></td>
                      <td><?php echo $row['credit_note'];  ?></td>
                      <td><?php echo $row['added_by'];  ?></td>

                    </tr>
                  <?php
                  }
                  ?>
                  <!-- 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-color: 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 -->
                </tbody>

              </table>

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

        </div>

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

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



  </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">Remove Credits History</h3>
              <ol class="breadcrumb float-sm-right" style="background-color: black;">
                <li class="breadcrumb-item"><a href="#">Home</a></li>
                <li class="breadcrumb-item">Credits</li>
                <!-- <li class="breadcrumb-item active">Credits History</li> -->
              </ol>
            </div>
            <!-- /.card-header -->
            <div class="card-body">
              <table id="example2" class="table table-bordered table-striped">
                <thead>
                  <tr>
                    <th>Sr. No</th>
                    <th>Date /Time</th>
                    <th>User Type</th>
                    <th>User Id</th>
                    <th>Credits</th>
                    <th>Credit Type</th>
                    <th>Credit Note</th>
                    <th>Added by</th>

                  </tr>
                </thead>
                <tbody>
                  <?php
                  include("connection.php");
                  $i = 0;

                  $sql = "SELECT * FROM remove_credit WHERE added_by='Admin' ORDER BY date_time";
                  $res = mysqli_query($conn, $sql);
                  while ($row = mysqli_fetch_assoc($res)) {
                    $i++;

                  ?>
                    <tr>
                      <td><?php echo $i; ?></td>
                      <td><?php echo $row['date_time'];  ?></td>
                      <td><?php echo $row['user_type'];  ?></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><?php echo $row['credit'];  ?></td>
                      <td><?php echo $row['credit_type'];  ?></td>
                      <td><?php echo $row['credit_note'];  ?></td>
                      <td><?php echo $row['added_by'];  ?></td>

                    </tr>
                  <?php
                  }
                  ?>

                </tbody>

              </table>
              <!-- 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-color: black;" s>

                        <h6 class="modal-title float-left">
                          <span style="font-weight:600; text-transform:uppercase">Added by&nbsp;: &nbsp;</span> <span style="color:white"><?php echo $row['added_by']; ?>&nbsp;<i class="fa fa-chevron-right" aria-hidden="true" style="font-size:12px;">
                            </i>
                          </span>
                          <span style="text-transform: none;">&nbsp;<?php echo $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 class="modal-footer justify-content-between">
                          <button type="button" class="btn btn-dark" data-dismiss="modal">Close</button>
                          <!-- <input type="submit" class="btn btn-primary" value="Submit"> -->
                        </div>

                      </div>

                    </div>

                  </div>

                </div>
              <?php } ?>
              <!-- modal end -->
            </div>
          </div>
          <!-- /.card-body -->

        </div>

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

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



  </section>
</div>

<script>




</script>
<!-- searching end -->

<!-- pagination -->

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