<?php include("../Header/Session.php"); ?>
<?php include("../Header/Connection.php"); ?>


<!DOCTYPE html>
<html lang="en">
<?php include ("../Header/head.php"); ?>
<body class="skin-default fixed-layout">

    <!-- Main wrapper - style you can find in pages.scss -->
    <div id="main-wrapper">    
        <?php include ("../Header/header.php"); ?>
        <?php include ("../Header/left_menu.php"); ?>
        <?php include ("../Header/right_sidebar.php"); ?>

        <?php
	      $type_wallet = $_GET['type_wallet'];
          
          $hq_ref_code="MGP10000";

          $q_rules = "SELECT *
                     FROM system_setting
                     Where status='1'";
          $result_rules = $mysqli->query($q_rules);
	      if ($result_rules ->num_rows > 0)
	      {
		    $row_q_rules = $result_rules ->fetch_assoc();
		    $e_wallet_transfer = $row_q_rules['e_wallet_transfer'];
            $a_wallet_transfer = $row_q_rules['a_wallet_transfer'];
	      }

          $sql_total_hq_wallet =
          "select SUM(out_transactions) As num 
          from transactions
          Where user_ref_code = '$hq_ref_code'
          And type_of_transaction In ('PW')  
          And type_of_process In ('HQ Transfer Activation Wallet')";
          $result_total_hq_wallet = $mysqli->query($sql_total_hq_wallet);
	      if ($result_total_hq_wallet->num_rows > 0)
	      {
		    $row_total_hq_wallet = $result_total_hq_wallet ->fetch_assoc();
		    $full_total_hq_wallet = number_format($row_total_hq_wallet['num'],2);
	      }

          $sql_wallet = "SELECT * FROM wallet 
          WHERE ref_code='$ref_code' LIMIT 1";
          $result_wallet = $mysqli->query($sql_wallet);
	      if ($result_wallet->num_rows > 0)
	      {
		    $row_wallet = $result_wallet ->fetch_assoc();
		    $e_wallet = number_format($row_wallet['cash_wallet'],2);
	        $gold_wallet = number_format($row_wallet['product_wallet'],2);
	      }

          if ( $type_wallet == "e_wallet")
          {
               if ($level == '1')
               {
                  $wallet = $full_total_hq_wallet;
			   }
               else
               {
                  $wallet = $e_wallet;
			   }
               
               $walletname = "E-Wallet";
               $type_of_transaction = "CW";
		  }
          else  
          if ( $type_wallet == "a_wallet")
          {
               
               if ($level == '1')
               {
                  $wallet = $full_total_hq_wallet;
			   }
               else
               {
                  $wallet = $gold_wallet;
			   }

               $walletname = "Activation Wallet";
               $type_of_transaction = "PW";
		  }

	    ?>
        
        <!-- Page wrapper  -->
        <div class="page-wrapper">
            <!-- Container fluid  -->
            <div class="container-fluid">

                <!-- Bread crumb and right sidebar toggle -->
                <!--?php include ("../Header/breadcumb.php"); ?-->
                <br><br>
                <!-- End Bread crumb and right sidebar toggle -->
    
                <!-- Start Page Content -->
                <!-- ============================================================== -->

               <?php

               $ref_code = $_GET['ref_code'];
               if ( $ref_code == '')
               {
                    $ref_code=$_SESSION['ref_code'];
			   }

               $q = "SELECT *
               FROM user
               WHERE ref_code='$ref_code'";
               $result = $mysqli->query($q);
               if ($result->num_rows > 0)
               {
                   while($record = $result -> fetch_assoc())
                   {  
                       $id = $record['id'] ;
			           $sponsor_code = $record['sponsor_code'] ;
                       $ref_code = $record['ref_code'] ;
                       $name = $record['name'];
			           $email = $record['email'];
			           $password = $record['password'];
			           $phone_number = $record['phone_number'];
                       $paid = $record['paid'];
                       $address = $record['address'];
                       $bank_type = $record['bank_type'];
                       $acc_no = $record['acc_no'];
                       $acc_holder = $record['acc_holder'];
                       $verification_status = $record['verification_status'];
               ?> 

               <?php
               if ( $type_wallet == "a_wallet")
               {
               ?>
               
               <div class="row">
                    <div class="col-lg-12">
                        <div class="card">
                            <div class="card-body">
                                <form method="post" action="wallet_transfer_confirmation_a_wallet.php" enctype="multipart/form-data">
                                    <div class="form-body"> 
                                    <h3 class="card-title"><?php echo $walletname; ?> : $ <?php echo $wallet; ?></h3>
                                        <hr>
                                        <div class="row p-t-20">
                                            <div class="col-md-6">
                                                <div class="form-group">
                                                    <label class="control-label">Amount To Transfer($)</label>
                                                    <input type="number" step="0.01" class="form-control"  name="amount" required>
                                                </div>
                                            </div>
                                            <div class="col-md-6">
                                                <div class="form-group">
                                                    <label class="control-label">Your MyUHM Acc Password</label>
                                                    <input type="password" class="form-control"  name="password" required>
                                                </div>
                                            </div>

                                            <div class="col-md-6">
                                                <div class="form-group">
                                                    <label class="control-label">Member/Your Refferal Code</label>
                                                    <input type="text" class="form-control"  name="friend_ref_code" required>
                                                </div>
                                            </div>
                                        </div>

                                        <input type="hidden" class="form-control"  name="id" value="<?php echo $id; ?>">
                                        <input type="hidden" class="form-control"  name="ref_code" value="<?php echo $ref_code; ?>">
                                        <input type="hidden" class="form-control"  name="type_wallet" value="<?php echo $type_wallet; ?>">

                                    </div>
                                    <div class="form-actions">
                                        <?php if ($verification_status == '1')
                                        {
                                        ?>
                                          <!-- withdraw_transfer -->
                                          <?php if ($a_wallet_transfer == '1')
                                          {
                                          ?>
                                              <button name="withdraw_a_transfer_confirmation" class="btn btn-success"><i class="fa fa-check"></i> Transfer</button>
                                          <?php
                                          }
                                          else
                                          {
                                          ?>
                                              <button name="withdraw_a_transfer_confirmation" class="btn btn-success" disabled><i class="fa fa-check"></i> Transfer</button>
                                          <?php
                                          }
                                          ?>
                                        <?php
										}
                                        else
                                        {
                                        ?>
                                          <button name="withdraw_a_transfer_confirmation" class="btn btn-success" disabled><i class="fa fa-check"></i> Transfer</button><br>
                                          Unverified user cannot transfer A-wallet/E-wallet
                                        <?php
										}
                                        ?>
                                    </div>
                                </form>
                            </div>
                        </div>
                    </div>
               </div>

               <?php
               }
               else
               if ( $type_wallet == "e_wallet")
               {
               ?>

               <div class="row">
                    <div class="col-lg-12">
                        <div class="card">
                            <div class="card-body">
                                <form method="post" action="wallet_transfer_confirmation.php" enctype="multipart/form-data">
                                    <div class="form-body"> 
                                    <h3 class="card-title"><?php echo $walletname; ?> : $ <?php echo $wallet; ?></h3>
                                        <hr>
                                        <div class="row p-t-20">
                                            <div class="col-md-6">
                                                <div class="form-group">
                                                    <label class="control-label">Transfer To Wallet</label>
                                                    <select name="type_Of_wallet" id="select" class="form-control" required>
								                        <option value="">Select Type Of Wallet</option>
                                                        <!--option value="e_wallet">E-Wallet (0% Fee Charge Pertransaction)</option-->
                                                        <option value="a_wallet">A-Wallet ($0.00 Fee Charge Pertransaction)</option>
                                                    </select>
                                                </div>
                                            </div>
                                            <div class="col-md-6">
                                                <div class="form-group">
                                                    <label class="control-label">Amount To Transfer($)</label>
                                                    <input type="number" step="0.01" class="form-control" id="amount" name="amount" required>
                                                </div>
                                            </div>
                                            <div class="col-md-6">
                                                <div class="form-group">
                                                    <label class="control-label">Your MyUHM Acc Password</label>
                                                    <input type="password" class="form-control" name="password" required>
                                                </div>
                                            </div>

                                            <div class="col-md-6">
                                                <div class="form-group">
                                                    <label class="control-label">User ID Code</label>
                                                    <input type="text" class="form-control"  id="friend_ref_code" name="friend_ref_code" value="<?php echo $ref_code; ?>" readonly>
                                                </div>
                                            </div>
                                        </div>

                                        <input type="hidden" class="form-control"  name="id" value="<?php echo $id; ?>">
                                        <input type="hidden" class="form-control"  name="ref_code" value="<?php echo $ref_code; ?>">
                                        <input type="hidden" class="form-control"  name="type_wallet" value="<?php echo $type_wallet; ?>">

                                    </div>
                                    <div class="form-actions">
                                        <?php if ($verification_status == '1')
                                        {
                                        ?>
                                            <?php if ($e_wallet_transfer == '1')
                                            {
                                            ?>
                                                <button name="withdraw_e_transfer_confirmation" class="btn btn-success"><i class="fa fa-check"></i> Transfer</button>
                                            <?php
                                            }
                                            else
                                            {
                                            ?>
                                                <button name="withdraw_e_transfer_confirmation" class="btn btn-success" disabled><i class="fa fa-check"></i> Transfer</button>
                                            <?php
                                            }
                                            ?>
                                        <?php
										}
                                        else
                                        {
                                        ?>
                                          <button name="withdraw_e_transfer_confirmation" class="btn btn-success" disabled><i class="fa fa-check"></i> Transfer</button><br>
                                          Unverified user cannot transfer A-wallet/E-wallet
                                        <?php
										}
                                        ?>
                                    </div>
                                </form>
                            </div>
                        </div>	
                    </div>
               </div>
               <?php
			   }
               ?>

                <?php
                }
                }
                ?>		
               
                				
                <!-- ============================================================== -->
                <!-- End PAge Content -->

            </div>
            <!-- End Container fluid  -->
        </div>
        <!-- End Page wrapper  -->


        <!-- Footer Start-->
        <?php include ("../Footer/footer.php"); ?>
        <!-- Footer End-->

    </div>
    <!-- End Wrapper -->
    <!-- All Jquery -->
    
    <script>
    document.getElementById("myForm").onsubmit = function() 
    {
        amount = document.getElementById("amount").value;
        friend_ref_code = document.getElementById("friend_ref_code").value;

        fee_charge = 0.1 * Number(amount);

        return confirm('Do you want to proceed transfer $'+amount+' To Member:'+friend_ref_code+' with 10% fee charge $'+fee_charge.toFixed(2)+' ?');
    }
    </script>

     <!-- All Jquery Start-->
    <?php include ("../Header/all_jquery.php"); ?>
    <!-- All Jquery End-->

    

</body>

</html>