
<?php
include('header.php');
if($_SESSION['userid'] != "ADMIN"){
    ?>
    <script>
        window.location.href='index.php';
    </script>
    <?php
    die;

}
if(isset($_GET['apid']) && $_GET['approve'] == 1 ){
     $apid = base64_decode(mysqli_real_escape_string($conn,$_GET['apid']));
    $select = mysqli_query($conn,"SELECT * FROM qrtxn WHERE txnid='$apid' AND status='pending'");
    if(mysqli_num_rows($select)==1){
    $data = mysqli_fetch_assoc($select);
    $amt = $data['amount'];
    $pupdate =  mysqli_query($conn,"UPDATE payments SET status='success' WHERE order_id='$apid' ");
    $update = mysqli_query($conn,"UPDATE users SET balance=balance+$amt WHERE username='".$data['username']."'");
    if($update && $pupdate){
        ?>
         <script>
            $(function(){
                Swal.fire(
                    'Balance Added Successfully', 
                    '',
                    'success'
                )
            })
            setTimeout(() => {
                window.location='BalanceTransfer.php';
            }, 1000);
            </script>
        <?php
    }else{
        ?>
                <script>
                    $(function(){
                        Swal.fire(
                            'Not Added', 
                            '',
                            'error'
                        )
                    })
                  
                </script>
                <?php
    }
    }
}else if(isset($_GET['rejid']) && $_GET['reject'] == 1 ){
    $apid = base64_decode(mysqli_real_escape_string($conn,$_GET['rejid']));
   $select = mysqli_query($conn,"SELECT * FROM payments WHERE order_id='$apid' ");
   if(mysqli_num_rows($select)==1){
   $data = mysqli_fetch_assoc($select);
   $update = mysqli_query($conn,"UPDATE payments SET status='rejected' WHERE order_id='$apid'");
   if($update){
       ?>
        <script>
           $(function(){
               Swal.fire(
                   'Reject Successfully', 
                   '',
                   'success'
               )
           })
           setTimeout(() => {
               window.location='BalanceTransfer.php';
           }, 1000);
           </script>
       <?php
   }else{
       ?>
               <script>
                   $(function(){
                       Swal.fire(
                           'Something Wrong', 
                           '',
                           'error'
                       )
                   })
                 
               </script>
               <?php
   }
   }
}
if(isset($_POST['ahkweb_add_user']) && $_POST['ahkweb_add_user'] =="ahkwebsolutions_adduser"){
        $email = mysqli_real_escape_string($conn,$_POST['emailid']);
        $amount = mysqli_real_escape_string($conn,$_POST['amount']);
      
      $res = mysqli_query($conn,"UPDATE usertable SET walletamount=walletamount+'$amount' WHERE emailid='$email' ");
      
      if($res){
      ?>
                <script>
                    $(function(){
                        Swal.fire(
                            'Balance Added Successfully', 
                            '',
                            'success'
                        )
                    })
                  
                </script>
                <?php
      }else{
      ?>
                <script>
                    $(function(){
                        Swal.fire(
                            'Opps',
                            'Balance Not Added',
                            'error'
                        )
                    })
                </script>
                <?php
        
      }
        
    }
if(isset($_POST['mobile']) && $_POST['transfer'] == 'true'){
    $mobile = mysqli_real_escape_string($conn,$_POST['mobile']);
    $sl = mysqli_query($conn,"SELECT * FROM usertable WHERE  phone='$mobile'");
    if(mysqli_num_rows($sl)==1){
        $ud = mysqli_fetch_assoc($sl);
        ?>
       	

																																															

            
                
                             
                          <div class="payment-form">
                           <h4 >Conform User Details</h4>
                          
                              <form action="" method="POST">
                                  <div class="row">
                                      <div class="col-md-6">
                                          <div class="row">
                                              <div class="col-md-6">
                                                  <div class="form-group">
                                                      <label>Full name of User:</label>
                                                      <input type="text" class="form-control" value="<?php echo $ud['name']; ?>" readonly>
                                                  </div>
                                              </div>
                                              <div class="col-md-6">
                                                  <div class="form-group">
                                                      <label>Old Wallet balance:</label>
                                                      <input type="text" class="form-control" value="<?php echo $ud['walletamount']; ?>" readonly >
                                                  </div>
                                              </div>
                                              <input type="hidden" name="ahkweb_add_user" value="ahkwebsolutions_adduser">
                                              <input type="hidden" name="emailid" value="<?php echo $ud['emailid']; ?>">
                                              <div class="col-md-6">
                                                  <div class="form-group">
                                                      <label>Add Wallet Amount:</label>
                                                      <input required name="amount" value="" type="number" placeholder="Enter Amount" class="form-control">
                                                  </div>
                                              </div>
                                          </div>
                                          
                                          <div class="text-end">
                                              <button type="submit" class="btn btn-primary">Transfer</button>
                                          </div>
                                      </div>
                                  </div>
                              </form>
                        
                            </div>
  <?php
    }else{
        ?>
        <div class="payment-form">
                                  <h4 class="card-title">Balance Transfer ENTER USER MOBILE NO ONLY</h4>
                              
                             
                                  <form action="" method="POST">
                                      <div class="row">
                                          <div class="col-md-6">
                                              <div class="row">
                                                  <div class="col-md-6">
                                                    <p class="text-danger">No Data Found try Again by User Mobile No!!</p>
                                                      <div class="form-group">
                                                          <label>ENTER USER MOBILE NO ONLY</label>
                                                          <input type="number" class="form-control" maxlength="10" name="mobile"  placeholder="Enter beneficiary Mobile no" required >
                                                      </div>
                                                  </div>
                                                  <input type="hidden" name="transfer" value="true">
                                                  
                                              </div>
                                              
                                              <div class="text-end">
                                                  <button type="submit" class="btn btn-danger">Fetch Balance</button>
                                              </div>
                                          </div>
                                      </div>
                                  </form>
                              </div>
                          
      <?php
    }
    
    
    

}else{
    ?>
    <div class="payment-form">
                                <h4 class="card-title">Balance Transfer </h4>
                           
                                <form action="" method="POST">
                                    <div class="row">
                                        <div class="col-md-6">
                                            <div class="row">
                                                <div class="col-md-6">
                                                    <div class="form-group">
                                                        <label>ENTER USER MOBILE NO ONLY:</label>
                                                        <input type="number" class="form-control" maxlength="10" name="mobile"  placeholder="Enter beneficiary Mobile no" required>
                                                    </div>
                                                </div>
                                                <input type="hidden" name="transfer" value="true">
                                                
                                            </div>
                                            
                                            <div class="text-end">
                                                <button type="submit" class="btn btn-success">Fetch Balance</button>
                                            </div>
                                        </div>
                                    </div>
                                </form>
                            </div>
                        
    <?php
}
?>
              
        
             
<style>
/* ===================== PAGE BACKGROUND ===================== */
body{
    background:linear-gradient(135deg,#0f2027,#203a43,#2c5364);
    font-family:"Poppins",sans-serif;
    min-height:100vh;
}

/* ===================== PAYMENT CARD ===================== */
.payment-form{
     max-width:1400px;
    margin:40px auto;
    background:linear-gradient(135deg,#ffffff,#f4f7ff);
    padding:25px 30px;
    border-radius:18px;
    box-shadow:0 20px 50px rgba(0,0,0,.35);
    position:relative;
}

/* TOP BORDER GLOW */
.payment-form::before{
    content:'';
    position:absolute;
    top:0;
    left:0;
    right:0;
    height:6px;
    background:linear-gradient(135deg,#11998e,#38ef7d);
    border-radius:18px 18px 0 0;
}

/* ===================== HEADING ===================== */
.payment-form h1{
    text-align:center;
    font-weight:800;
    color:#1e3c72;
    margin-bottom:25px;
    letter-spacing:1px;
}

/* ===================== LABEL ===================== */
.payment-form label{
    font-weight:600;
    color:#2c3e50;
    margin-bottom:6px;
}

/* ===================== INPUTS (ALL TYPES) ===================== */
.payment-form input[type="text"],
.payment-form input[type="password"],
.payment-form input[type="email"],
.payment-form input[type="number"],
.payment-form select,
.payment-form textarea{
    width:100%;
    padding:14px 16px;
    margin-bottom:15px;
    border-radius:30px;
    border:1px solid #d0d7ff;
    font-size:15px;
    transition:all .3s ease;
    box-shadow:inset 0 2px 6px rgba(0,0,0,.08);
    background:#fff;
}

/* PLACEHOLDER */
.payment-form input::placeholder,
.payment-form textarea::placeholder{
    color:#999;
    font-weight:500;
}

/* ===================== FOCUS EFFECT ===================== */
.payment-form input[type="text"]:focus,
.payment-form input[type="password"]:focus,
.payment-form input[type="email"]:focus,
.payment-form input[type="number"]:focus,
.payment-form select:focus,
.payment-form textarea:focus{
    outline:none;
    border-color:#396afc;
    box-shadow:0 0 0 3px rgba(57,106,252,.25);
}

/* ===================== BUTTON ===================== */
.payment-form button,
.payment-form input[type="submit"]{
    width:100%;
    padding:14px;
    margin-top:10px;
    border-radius:30px;
    font-weight:700;
    font-size:16px;
    border:none;
    cursor:pointer;
    background:linear-gradient(135deg,#11998e,#38ef7d);
    color:#fff;
    box-shadow:0 6px 18px rgba(0,0,0,.35);
    transition:all .25s ease;
}

/* BUTTON HOVER */
.payment-form button:hover,
.payment-form input[type="submit"]:hover{
    transform:translateY(-2px);
    box-shadow:0 10px 28px rgba(0,0,0,.45);
}

/* ===================== CARD BODY / FOOTER ===================== */
.payment-form .card-body{
    padding:0;
}

.payment-form .card-footer{
    background:none;
    border:none;
    padding-top:10px;
}

/* ===================== INFO & ALERT ===================== */
.bg-info{
    background:linear-gradient(135deg,#396afc,#2948ff)!important;
    color:#fff;
    font-weight:700;
    padding:10px;
    border-radius:10px 0 0 10px;
}

.bg-danger{
    background:linear-gradient(135deg,#ff416c,#ff4b2b)!important;
    color:#fff;
    padding:10px;
    border-radius:0 10px 10px 0;
}

/* ===================== MARQUEE ===================== */
.marquee{
    font-weight:600;
    letter-spacing:.5px;
}

/* ===================== TEXT ===================== */
.payment-form p{
    color:#2c3e50;
    font-size:14px;
}

/* ===================== QR POPUP ===================== */
.qr-popup{
    display:none;
    position:fixed;
    top:80px;
    left:50%;
    transform:translateX(-50%);
    width:320px;
    background:#ffffff;
    padding:20px;
    border-radius:18px;
    text-align:center;
    border:4px solid #38ef7d;
    box-shadow:0 15px 40px rgba(0,0,0,.45);
    z-index:9999;
}

.qr-popup img{
    max-width:220px;
    margin:15px auto;
}

.qr-popup button{
    background:linear-gradient(135deg,#ff416c,#ff4b2b);
    border-radius:25px;
}

/* ===================== MOBILE ===================== */
@media(max-width:768px){
    .payment-form{
        margin:20px;
        padding:20px;
    }
}
</style>

<?php 
include('userfooter.php');
?>
