<?php include("includes/header.php"); ?>
<?php include("includes/auto_out.php"); ?>
<!DOCTYPE html>
<html>
<head>
  <title>Edit Transactions | <?php echo $sitename;  ?> HQ</title>
    <link rel="stylesheet" href="bootstrap/css/bootstrap.css">
    <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="bootstrap/css/bootstrap.min.css">
  <link rel="stylesheet" href="bootstrap/css/bootstrap-theme.css">
  <link rel="stylesheet" href="bootstrap/css/bootstrap-theme.min.css">

   <!--CSS-->
  <link rel="stylesheet" href="style.css">
  <link rel="stylesheet" href="bootstrap/css/bootstrap.css">
  <link rel="stylesheet" href="bootstrap/css/bootstrap.min.css">
  <link rel="stylesheet" href="bootstrap/css/bootstrap-theme.css">
  <link rel="stylesheet" href="bootstrap/css/bootstrap-theme.min.css">

    <!-- Bootstrap Core CSS -->
      <link href="css/bootstrap.min.css" rel="stylesheet">

     <!-- Font Awesome -->
    <link rel="stylesheet" href="font-awesome/css/font-awesome.min.css">

      <!-- Custom CSS -->
      <link href="css/blog-home.css" rel="stylesheet">

      <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
      <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
      <!--[if lt IE 9]-->
          <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
          <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
          <script src="js/jquery.js"></script>
          <script src="js/bootstrap.js"></script>





          <!----MODAL-------------------->
          <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
            <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
            <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>



</head>

<body>
  <?php  include("includes/dashboard_navbar.php"); ?>
  <!-- DESTOP Side bar starts here--><!-- DESTOP Side bar starts here--><!-- DESTOP Side bar starts here-->
  <style>
    body{
      background-color: #f5f5f5;
    }
    .destop-siderbar{
      background-color: #131e2a;
      height: 100%;
      width:240px;
      box-shadow: 0 0 4px 0 rgba(0,0,0,.50), 0 2px 4px 0 rgba(0,0,0,.50);
      position: fixed;
      margin-left:-20px;
      padding:50px 25px;
    }
    .destop-siderbar li{
       padding: 30px 20px;
       list-style: none;
    }
    .destop-siderbar li a{
      color: #fff;
      font-size: 17px;
      padding:10px 0px;
    }
    .destop-siderbar li a i{
      color:rgb(45, 156, 219);
      font-weight: lighter;
    }
    .destop-siderbar .active {
      background-color:#123962;
      box-shadow: 0 0 4px 0 rgba(0,0,0,.50), 0 2px 4px 0 rgba(0,0,0,.50);
      
    }
    .destop-siderbar .active a{
      color:#fff;
    }
    .destop-siderbar .active a:hover{
      color:#fff;
    }
    .destop-siderbar li a:hover{
      color: #a5bdd9;
      text-decoration: none;
    }
    .panel{
      border-radius: 0px;
      border-color: transparent;
    }
    .input-danger{
       border:1px solid darkred;
       color:darkred;
     }
     .input-danger::placeholder{
       opacity: 0.6;
       color:darkred;
     }
  </style>

  <div class="container-fluid">
    <div class="row">
      <!-- DESTOP Side bar starts here--><!-- DESTOP Side bar starts here--><!-- DESTOP Side bar starts here-->
      <div class="col-sm-2 hidden-xs" style="height: 100%;">
             <ul class="destop-siderbar">
                <br><br>
                 <li><a href="dashboard.php"><i class="fa fa-th-large"></i>&nbsp;&nbsp;Dashboard</a></li><br><br>

                 <li><a href="all-users.php"><i class="fa fa-users"></i>&nbsp;&nbsp;All Users</a></li><br><br>
                 <li><a href="all-transactions.php"><i class="fa fa-exchange"></i>&nbsp;&nbsp;All Transactions</a></li><br><br>
                 <li><a href="airtime-bonus.php"><i class="fa fa-gift"></i>&nbsp;&nbsp;Airtime Bonus</a></li><br><br>
                 <li><a href="naira-requests.php"><i class="fa fa-google-wallet"></i>&nbsp;&nbsp;Naira Requests <sup><span style="font-size: 12px; color: #00d67d;"> ₦</span></sup></a></li><br><br>
                 <li><a href="deposit-proofs.php"><i class="fa fa-money"></i>&nbsp;&nbsp;Deposit Proofs <sup><span style="font-size:12px; color: #00d67d;"> ₦</span></sup></a></li><br><br>
                 <li><a href="selling-receipts.php"><i class="fa fa-btc"></i>&nbsp;&nbsp;Selling Receipts <sup><span style="font-size: 10px; color: #00d67d;"> <i class="fa fa-btc"></i></span></sup></a></li><br><br>
                 <li><a href="buying-request.php"><i class="fa fa-shopping-cart"></i>&nbsp;&nbsp;Buying Request <sup><span style="font-size: 10px; color: #00d67d;"> <i class="fa fa-btc"></i></span></sup></a></li><br><br>
                 <li><a href="settings.php"><i class="fa fa-cog"></i>&nbsp;&nbsp;Settings</a></li><br><br>
                 <!--<li><a href="security.php"><i class="fa fa-shield"></i>&nbsp;&nbsp;Security</a></li><br><br>
                 <li><a href="live-chat.php"><i class="fa fa-comments-o"></i>&nbsp;&nbsp;Live Chat</a></li><br><br>-->
                 <li><a href="logout.php"><i class="fa fa-power-off"></i>&nbsp;&nbsp;Logout</a></li>
                 <br><br><br><br><br><br><br>
               </ul>
      </div>
      <!--/////////////////////// DESTOP Side bar starts here--><!-- DESTOP Side bar starts here--><!-- DESTOP Side bar starts here-->
      <div class="col-sm-10">
        <br><br><br><br>

        <!----------------------------------------------------------------------------------->

        <div class="row">
          <div class="col-sm-12">
            <div class="row">


              <div class="col-sm-9">
                 <div class="panel panel-default">
                  <div class="panel-body">
                       <span style="font-size: 16px; font-weight: bold;"><i class="fa fa-caret-left" style="font-size: 18px;"></i> <i class="fa fa-caret-right" style="font-size: 18px;"></i> EDIT TRANSACTIONS</span>
                       <br><br>

                       <?php
                         if(isset($_GET["trans_id"])){
                          $trans_id = $_GET["trans_id"];
                          $zux_username = $_GET["zux_username"];

                          //USER TRANS ID TO TRACK TRANSACTION
                          $query = mysqli_query($conn, "SELECT * FROM transactions WHERE id = '$trans_id'");
                          $row = mysqli_fetch_assoc($query);
                          $trans_type = $row["trans_type"];
                          $trans_order_id = $row["trans_order_id"];
                          $trans_amount = $row["trans_amount"];
                          $trans_status = $row["trans_status"];
                          $trans_action = $row["trans_action"];
                          $trans_date = $row["trans_date"];
                          $trans_desc = $row["trans_desc"];
                         }
                       ?>

                       <?php
                         if(isset($_POST["confirmnairabtn"])){

                          $amount = $_POST["amount"];
                          $status = $_POST["status"];


                          if($trans_type == "SELL BTC"){

                             if($status == "SUCCESS"){
                               $action = "F";
                             }else{
                               $action = "T";
                             }

                             //UPDATE AMOUNT,STATUS ON TRANSACTIONS
                             $query = mysqli_query($conn, "UPDATE transactions SET trans_amount = '$amount', trans_status = '$status', trans_action = '$action' WHERE id = '$trans_id'");

                             //Fetch Naira Balance
                             $query = mysqli_query($conn, "SELECT * FROM users WHERE zux_username = '$zux_username'");
                             $row = mysqli_fetch_assoc($query);
                             $naira_wallet_b = $row["naira_wallet_b"];
                             $new_naira_wallet_b = (($naira_wallet_b*1) + ($amount));
                             //Update Naira Balance
                             $query = mysqli_query($conn, "UPDATE users SET naira_wallet_b = '$new_naira_wallet_b' WHERE zux_username = '$zux_username'");
                             echo "<div class='alert alert-success'>Updated</div>";
                             echo "<script>window.location.assign('all-transactions.php');</script>";


                          }elseif($trans_type == "BUY BTC"){
                            if($status == "SUCCESS"){
                              $action = "F";
                            }else{
                              $action = "T";
                            }

                            //UPDATE ONLY STATUS AND ACTION
                             $query = mysqli_query($conn, "UPDATE transactions SET trans_status = '$status', trans_action = '$action' WHERE id = '$trans_id'");
                             echo "<div class='alert alert-success'>Updated</div>";
                             echo "<script>window.location.assign('all-transactions.php');</script>";
                         
                          }elseif($trans_type == "WITHDRAW NAIRA"){
                            if($status == "SUCCESS"){
                              $action = "F";
                            }else{
                              $action = "T";
                            }

                            //UPDATE ONLY STATUS AND ACTION
                             $query = mysqli_query($conn, "UPDATE transactions SET trans_status = '$status', trans_action = '$action' WHERE id = '$trans_id'");
                             echo "<div class='alert alert-success'>Updated</div>";
                             echo "<script>window.location.assign('all-transactions.php');</script>";
                          }elseif($trans_type == "DEPOSIT NAIRA"){
                            if($status == "SUCCESS"){
                              $action = "F";
                            }else{
                              $action = "T";
                            }

                            //UPDATE ONLY STATUS, AMOUNT AND ACTION
                             $query = mysqli_query($conn, "UPDATE transactions SET trans_amount = '$amount', trans_status = '$status', trans_action = '$action' WHERE id = '$trans_id'");

                             //Fetch Naira Balance
                             $query = mysqli_query($conn, "SELECT * FROM users WHERE zux_username = '$zux_username'");
                             $row = mysqli_fetch_assoc($query);
                             $naira_wallet_b = $row["naira_wallet_b"];
                             $new_naira_wallet_b = (($naira_wallet_b*1) + ($amount));
                             //Update Naira Balance
                             $query = mysqli_query($conn, "UPDATE users SET naira_wallet_b = '$new_naira_wallet_b' WHERE zux_username = '$zux_username'");


                             echo "<div class='alert alert-success'>Updated</div>";
                             echo "<script>window.location.assign('all-transactions.php');</script>";
                          
                          }elseif($trans_type == "AIRTIME"){
                             if($status == "SUCCESS"){
                               $action = "F";
                             }else{
                               $action = "T";
                             }

                             //UPDATE ONLY STATUS AND ACTION
                              $query = mysqli_query($conn, "UPDATE transactions SET trans_status = '$status', trans_action = '$action' WHERE id = '$trans_id'");
                              echo "<div class='alert alert-success'>Updated</div>";
                              echo "<script>window.location.assign('all-transactions.php');</script>";
                          }
                          
                          
                         }
                       ?>


                       <form action="" method="POST">

                         <div class="form-group">
                          <label>Amount</label>
                           <input type="number" class="form-control input-lg" name="amount" style="border-radius: 0px; width: 50%;">

                           <label>Status</label>
                            <select type="text" class="form-control input-lg" name="status" style="border-radius: 0px; width: 50%;" value="<?php echo $zux_username; ?>">
                              <option>Select Status</option>
                              <option>SUCCESS</option>
                              <option>PENDING</option>
                              <option>DECLINED</option>
                            </select>

                            <br>

                            <button type="submit" name="confirmnairabtn" class="btn btn-lg btn-primary" style="border-radius: 0px;">CONFIRM</button>

                          
                         </div>
                       </form>
 
                   
                    <br>
                  </div>
                </div>
              </div>
              

              <div class="col-sm-3">
                 <div class="panel panel-default">
                  <div class="panel-body">
                    <img src="images/transactions.png" width="50px">&nbsp;&nbsp;<b><?php echo $_GET["zux_username"]; ?> | <?php echo $trans_order_id; ?></b>
                    <hr>
                    <table class="table table-bordered">
                        <tbody>
                          <tr>
                            <td><b>USERNAME</b></td>
                            <td><span style="color:#ff9800; font-size: 14px;"><?php echo $zux_username; ?></span></td>
                          </tr>
                          <tr>
                            <td><b>TYPE</b></td>
                            <td><span style="color:#ff9800; font-size: 14px;"><?php echo $trans_type; ?></span></td>
                          </tr>
                          <tr>
                            <td><b>AMOUNT</b></td>
                            <td><span style="color:#ff9800; font-size: 14px;"><?php echo $trans_amount; ?></span></td>
                          </tr>
                          <tr>
                            <td><b>STATUS</b></td>
                            <td><span style="color:#ff9800; font-size: 14px;"><?php echo $trans_status; ?></span></td>
                          </tr>
                          <tr>
                            <td><b>DATE</b></td>
                            <td><span style="color:#ff9800; font-size: 14px;"><?php echo $trans_date; ?></span></td>
                          </tr>
                        </tbody>
                      </table>
                    <div align="right">
                    </div>
                  </div>
                </div>
              </div>

            </div>

            

            <!--------------------------->

            






          </div>








          </div>
        </div>
        
        
        
        
        
        
      </div>
    </div>
  </div>
</body>
</html>