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

<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>Update Reseller Price</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">
              <h3 class="card-title">Update Reseller Price!</h3>
              <ol class="breadcrumb float-sm-right">
                <li class="breadcrumb-item"><a href="#">Home</a></li>
                <li class="breadcrumb-item">Price Update</li>
                <li class="breadcrumb-item active">Update Price</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>Added By</th>
                    <th>User Id</th>
                    <th>Credits</th>
                    <th>Virtual Credits</th>
                    <th>Price Update</th>

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

                  $sql = "SELECT c.virtual_credit, c.credit, u.* FROM credit AS c JOIN user AS u ON c.user_id = u.user_id WHERE u.user_type = 'reseller' ORDER BY u.date_time";

                  $res = mysqli_query($conn, $sql);
                  while ($row = mysqli_fetch_array($res)) {

                    $a++
                  ?>
                    <tr>
                      <td><?php echo $a; ?></td>
                      <td><?php echo $row['date_time']; ?></td>
                      <td><?php echo $row['added_by']; ?></td>
                      <td>
                        <a href="#" style="color:blue ;font-weight:600;" 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['virtual_credit']; ?></td>
                      <td>
                        <a href="#" data-toggle="modal" data-target="#modal-xl-id">
                          <i class="nav-icon fas fa-edit info" style="color:black"></i>
                        </a>
                      </td>
                    </tr>
                  <?php } ?>

                </tbody>

              </table>
              <!-- user id modal -->
              <!-- modal -->
              <?php
              $sql = "SELECT c.virtual_credit,u.* FROM credit AS c JOIN user AS u ON c.user_id = u.user_id  ORDER BY u.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">

                        <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>&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-6">
                            <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 class="col-6">

                            <span style="float:right;font-weight:600; text-transform:uppercase">Virtual
                              Credids&nbsp;:&nbsp;<span style="color:green; font-weight:400"><?php echo $row['virtual_credit']; ?></span></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 -->
              <!-- Modal Start -->
              <div class="modal fade" id="modal-xl-id">
                <div class="modal-dialog modal-xl">
                  <div class="modal-content">
                    <div class="modal-header">
                      <h4 class="modal-title">Product Details</h4>
                      <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">×</span>
                      </button>
                    </div>
                    <div class="modal-body">

                      <table id="example1" class="table table-bordered table-striped">
                        <thead>
                          <tr>
                            <th>Sr. No</th>

                            <th>Product name</th>
                            <th>Origin</th>
                            <th>Quntity</th>
                            <th>Credits</th>

                            <th style="width:20%;">Price Update</th>

                          </tr>
                        </thead>
                        <tbody>
                          <?php
                          $a = 0;
                          include('connection.php');
                          $sql = "SELECT * FROM product ORDER By date_time";
                          $res = mysqli_query($conn, $sql);
                          while ($row = mysqli_fetch_array($res)) {

                            $a++
                          ?>
                            <tr>
                              <td><?php echo $a; ?></td>

                              <td><?php echo $row['product_name']; ?></td>
                              <td><?php echo $row['origin']; ?></td>
                              <td><?php echo $row['quantity']; ?></td>

                              <td><?php echo $row['price']; ?></td>
                              <td>
                                <div class="input-group">
                                  <input type="text" class="form-control">
                                  <div class="input-group-append">
                                    <span class="input-group-text"><i class="fas fa-check"></i></span>
                                  </div>
                                </div>

                              </td>
                            </tr>

                          <?php } ?>
                        </tbody>



                      </table>

                    </div>
                    <div class="modal-footer justify-content-between">
                      <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                      <button type="button" class="btn btn-dark">Save changes</button>
                    </div>
                  </div>
                  <!-- /.modal-content -->



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

            </div>

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

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

        <!-- /.container-fluid -->
  </section>
  <!-- /.content -->
</div>
<script>
  $(document).ready(function() {
    $('.edit-link').click(function() {
      var orderID = $(this).data('orderid');
      var user_type = $(this).data('user_type');
      var user_name = $(this).data('user_name');
      var credit = $(this).data('credit');
      var virtual_credit = $(this).data('virtual_credit');

      $('#order_id').val(orderID);
      $('#user_type').val(user_type);
      $('#user_name').val(user_name);
      $('#credit').val(credit);
      $('#virtual_credit').val(virtual_credit);
    });
  });
</script>

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