<?php
session_start();
ob_start();
include('includes/config.php');
if($_SESSION['name'] == '')
 {
     header("location:index.php");
 }
    else{

if(isset($_POST['submit'])=='Submit'){
    
	$utr_no=($_POST['utr_no']);
	$amount=($_POST['amount']);
	$status=($_POST['status']);
	$orderid=($_POST['orderid']);
	$id=($_POST['id']);
	//////////////
	if($status==1){
	   
	  $sql1="SELECT * FROM walletsummery WHERE id='$id'";
	 $select=mysqli_query($com,$sql1);
	 $row = mysqli_fetch_array($select);
	 $userid=$row['userid']; 
	 
	 
	$sql12="SELECT * FROM walletsummery WHERE userid='$userid' and actiontype='recharge' and status='1'";
	$select12=mysqli_query($com,$sql12);
    $row_count = mysqli_num_rows($select12);
//	if($row_count == 0)
// 	{ 
// 	 $chkrcode=mysqli_query($com,"select * from loginuser where id='$userid'");
// 	 $codedata=mysqli_fetch_array($chkrcode);
// 	 $reffercode=$codedata['code']; 
// 	 if($reffercode != 0)
// 	{
		
// 	 $chkrcode12=mysqli_query($com,"select * from loginuser where owncode='$reffercode'");
// 	 $codedata12=mysqli_fetch_array($chkrcode12);
// 	 $reffercode12=$codedata12['code'];
// 	 $firstuserid = $codedata12['id'];
	 
// 	 $bonus_sql=mysqli_query($com,"select * from bonus WHERE userid= '$firstuserid'"); 
//       $bonus_data=mysqli_fetch_array($bonus_sql);
//       $walletAvailablebalance=$bonus_data['amount'];
//       $level1balance=$bonus_data['level1'];
      
// 	 $value="SELECT * FROM paymentsetting WHERE id=1";
// 	 $val=mysqli_query($com,$value);
// 	 $row_val =mysqli_fetch_array($val);
// 	 $r_amount=($amount * $row_val['level1'])/100; 
	 
//       $finalbalanceCredit=$walletAvailablebalance+$r_amount;
//       $level1totalbalance=$level1balance+$r_amount;
//       $sqlwallet = mysqli_query($com,"UPDATE bonus SET amount = '$finalbalanceCredit',level1 = '$level1totalbalance' WHERE userid= '$firstuserid'");
//       $sqlwallet2 = mysqli_query($com,"insert bonussummery(userid,level1id,level1amount)values('$firstuserid','$userid','$r_amount')");
      
//       $chkrcode2=mysqli_query($com,"select * from `loginuser` where `owncode`='".$reffercode12."'");
// 	 $codeRow2=mysqli_num_rows($chkrcode2);
	 
// 	 if($codeRow2!='0'){
// 	  $codedata2=mysqli_fetch_array($chkrcode2);
// 		 $firstuserid2=$codedata2['id'];
		 
// 	  $bonus_sql2=mysqli_query($com,"select * from bonus WHERE userid= '$firstuserid2'"); 
//       $bonus_data2=mysqli_fetch_array($bonus_sql2);
//       $walletAvailablebalance2=$bonus_data2['amount'];
//       $level2balance=$bonus_data2['level2'];
      
// 	 $value2="SELECT * FROM paymentsetting WHERE id=1";
// 	 $val2=mysqli_query($com,$value2);
// 	 $row_val2 =mysqli_fetch_array($val2);
// 	 $r_amount2=($amount * $row_val2['level2'])/100; 
	 
//       $finalbalanceCredit2=$walletAvailablebalance2+$r_amount2;
//       $level2totalbalance=$level2balance+$r_amount2;
//       $sqlwallet= mysqli_query($com,"UPDATE bonus SET amount = '$finalbalanceCredit2',level2= '$level2totalbalance' WHERE userid= '$firstuserid2'");
// 	  $sqlwallet23 = mysqli_query($com,"insert bonussummery(userid,level2id,level2amount)values('$firstuserid2','$userid','$r_amount2')");
	     
// 	 }
// 	}
// 	$value12="SELECT * FROM paymentsetting WHERE id=1";
// 	 $val12=mysqli_query($com,$value12);
// 	 $row_val12 =mysqli_fetch_array($val12);
// 	 $r_amount12=$row_val12['first_bonus']; 
// 	 $amount12 = $r_amount12+$amount;
	 
// 	 $sqlwallet = mysqli_query($com,"select * from `wallet` WHERE `userid`= '$userid'");
// 	 $wallet_data  = mysqli_fetch_array($sqlwallet);
// 	$walletAvailablebalance=$wallet_data['amount'];
//     $finalbalanceCredit=$walletAvailablebalance+$amount12;
//     $sqlwallet= mysqli_query($com,"UPDATE `wallet` SET `amount` = '$finalbalanceCredit' WHERE `userid`= '$userid'");
//}else{
	 $sqlwallet = mysqli_query($com,"select * from `wallet` WHERE `userid`= '$userid'");
	 $wallet_data  = mysqli_fetch_array($sqlwallet);
	$walletAvailablebalance=$wallet_data['amount'];
$finalbalanceCredit=$walletAvailablebalance+$amount;
$sqlwallet= mysqli_query($com,"UPDATE `wallet` SET `amount` = '$finalbalanceCredit' WHERE `userid`= '$userid'");
   
//	}
	}
///////////
$sql = "UPDATE walletsummery SET utr_no='$utr_no',amount='$amount',status='$status',orderid='$orderid' WHERE id='$id'";
//print_r($sql);exit;	
$query=mysqli_query($com,$sql);
if($query){
	
	 echo "<script>
alert('Upadte sucessfully');
window.location.href='recharge.php';
</script>";
	
	}

	}
        ?>
<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
    	<meta name="viewport" content="width=device-width, initial-scale=1">
        <title>Forcecrypto Admin< </title>
        <link rel="stylesheet" href="css/bootstrap.min.css" media="screen" >
        <link rel="stylesheet" href="css/font-awesome.min.css" media="screen" >
        <link rel="stylesheet" href="css/animate-css/animate.min.css" media="screen" >
        <link rel="stylesheet" href="css/lobipanel/lobipanel.min.css" media="screen" >
        <link rel="stylesheet" href="css/prism/prism.css" media="screen" >
        <link rel="stylesheet" href="css/select2/select2.min.css" >
        <link rel="stylesheet" href="css/main.css" media="screen" >
        <script src="js/modernizr/modernizr.min.js"></script>
    </head>
    <body class="top-navbar-fixed">
        <div class="main-wrapper">

            <!-- ========== TOP NAVBAR ========== -->
  <?php include('includes/topbar.php');?> 
            <!-- ========== WRAPPER FOR BOTH SIDEBARS & MAIN CONTENT ========== -->
            <div class="content-wrapper">
                <div class="content-container">

                    <!-- ========== LEFT SIDEBAR ========== -->
                   <?php include('includes/leftbar.php');?>  
                    <!-- /.left-sidebar -->

                    <div class="main-page">

                     <div class="container-fluid">
                            <div class="row page-title-div">
                                <div class="col-md-6">
                                    <h2 class="title">Recharge Details</h2>
                                
                                </div>
                                
                                <!-- /.col-md-6 text-right -->
                            </div>
                            <!-- /.row -->
                            <div class="row breadcrumb-div">
                                <div class="col-md-6">
                                    
                                </div>
                             
                            </div>
                            <!-- /.row -->
                        </div>
                        <div class="container-fluid">
                           
                        <div class="row">
                                    <div class="col-md-12">
                                        <div class="panel">
                                            <div class="panel-heading">
                                                <div class="panel-title">
                                                    <h5></h5>
                                                </div>
                                            </div>
                                            <div class="panel-body">
<?php if($msg){?>
<div class="alert alert-success left-icon-alert" role="alert">
 <strong>Well done!</strong><?php echo htmlentities($msg); ?>
 </div><?php } 
else if($error){?>
    <div class="alert alert-danger left-icon-alert" role="alert">
                                            <strong>Oh snap!</strong> <?php echo htmlentities($error); ?>
                                        </div>
                                        <?php } ?>
                                                 <form  method="post" action="<?php echo $_SERVER['PHP_SELF'];?>" enctype="multipart/form-data">
<?php
      
      $id=$_GET['ID'];
      $sql="select* FROM `walletsummery` WHERE id='$id'";
      $query=mysqli_query($com,$sql);
      $role=mysqli_fetch_array($query); 
   ?>
   <input type="hidden" name="id" value="<?php echo $role['id'];?>">
<div class="form-group">
<label for="default" class="col-sm-6 control-label">Transaction Id</label>
<div class="col-sm-6">
<input type="text" class="form-control"  name="utr_no" id="mra" required value="<?php echo $role['utr_no'];?>" readonly>
</div>
</div>

<div class="form-group">
<label for="default" class="col-sm-6 control-label">AMOUNT</label>
<div class="col-sm-6">
<input type="text" class="form-control" name="amount" id="mwa" required value="<?php echo $role['amount_1'];?>">
</div>
</div>

<div class="form-group">
<label for="default" class="col-sm-6 control-label">STATUS </label>
<div class="col-sm-6">
<select class="form-control"  name="status">
                  <option value="0"<?php if($role['status'] == 0) { ?> selected="selected"<?php } ?>>Pending</option>
                  <option value="1"<?php if($role['status'] == 1) { ?> selected="selected"<?php } ?>>Success</option>
                  <option value="2"<?php if($role['status'] == 2) { ?> selected="selected"<?php } ?>>Fail</option>
              </select>
</div>
</div>

<br> <br>       <br>       <br>                                             <div class="form-group">
                                                        <div class="col-sm-offset-6 col-sm-6">
                                                            <input type="submit" class="btn btn-primary" value="Update"  name="submit"<?php if($role['status'] == 1) { ?> disabled <?php } ?>>
                                                        </div>
                                                    </div>
                                                </form>

                                            </div>
                                        </div>
                                    </div>
                                    <!-- /.col-md-12 -->
                                </div>
                    </div>
                </div>
                <!-- /.content-container -->
            </div>
            <!-- /.content-wrapper -->
        </div>
        <!-- /.main-wrapper -->
        <script src="js/jquery/jquery-2.2.4.min.js"></script>
        <script src="js/bootstrap/bootstrap.min.js"></script>
        <script src="js/pace/pace.min.js"></script>
        <script src="js/lobipanel/lobipanel.min.js"></script>
        <script src="js/iscroll/iscroll.js"></script>
        <script src="js/prism/prism.js"></script>
        <script src="js/select2/select2.min.js"></script>
        <script src="js/main.js"></script>
        <script>
            $(function($) {
                $(".js-states").select2();
                $(".js-states-limit").select2({
                    maximumSelectionLength: 2
                });
                $(".js-states-hide").select2({
                    minimumResultsForSearch: Infinity
                });
            });
        </script>
    </body>
</html>
<?PHP } ?>
