<?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";

          $data_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($data_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
	           if (isset($_POST['withdraw_a_transfer_confirmation'])) 
               {
                    $tac_no = randomRefferalNumber();

                    $type_wallet = $_POST['type_wallet'];
                    $type_Of_wallet = $_POST['type_Of_wallet'];
                    $amount_1 = $_POST['amount'];

                    $amount = $amount_1 ; 

                    $ref_code1 = $_POST['ref_code'];
                    $ref_code  = htmlspecialchars($ref_code1, ENT_QUOTES);

                    $friend_ref_code1 = $_POST['friend_ref_code'];
                    $friend_ref_code  = htmlspecialchars($friend_ref_code1, ENT_QUOTES);

                    $password1 = $_POST['password'];
                    $password  = htmlspecialchars($password1, ENT_QUOTES);

                    /*
                    if ($level == "2")
                    {
			            $email_user = $email;
			            $name_user = $name;

			            $to_user      = $email_user;
			            $subject_user = "TAC No. $tac_no for A-Wallet Transfer USD $amount";
        
			            $message_user = "
			            <html>
			            <head>
			            <title>TAC No. $tac_no for A-Wallet Transfer USD $amount</title>
			            </head>
			            <body>
			            <p>

			            TAC No. $tac_no for A-Wallet Transfer USD $amount

			            </p>

			            </body>
			            </html>
			            ";       
			            // Always set content-type when sending HTML email
			            $headers_user = "MIME-Version: 1.0" . "\r\n";
			            $headers_user .= 'Content-type:text/html;charset=UTF-8' . "\r\n";        
			            // More headers
			            $headers_user .= 'From: <finance@mygoldsdnbhd.com >' . "\r\n";
			            $headers_user .= "Reply-To: finance@mygoldsdnbhd.com \r\n";
			            $headers_user .= "Return-Path: finance@mygoldsdnbhd.com \r\n";
			            mail($to_user, $subject_user, $message_user, $headers_user);
			            /********************** Email To user *************************************************/
            
                        /********************** SMS To User Start*************************************************/
                        /*
		                $message = "RM0 UMRAH HAJI MABRUR SDN BHD: TAC No. $tac_no for A-Wallet Transfer USD $amount";

		                $curl = curl_init();
		                $endpoint = 'http://www.sms.bulksms2u.com/websmsapi/ISendSMS.aspx';
		                $params = array(
		                'username' => 'mygoldplt_websystemmabrur',
		                'password' => 'mygoldplt_websystemmabrur123',
		                'message' => $message,
		                'mobile' => $phone_number,
		                'Sender' => 'Test',
		                'type' => '1'
		                );
		                $url = $endpoint . '?' . http_build_query($params);
		                curl_setopt($curl, CURLOPT_URL, $url);

		                $result = curl_exec($curl);
		                $info = curl_getinfo($curl);  
		                curl_close($curl);
		                $obj = json_decode($result);
		                /********************** SMS To User End*************************************************/
                        /*
					}
                    */
                    
                    $sql_password = "SELECT * FROM user 
                    WHERE ref_code='$ref_code' 
                    And status='1'
                    LIMIT 1";
                    $result_password = $mysqli-> query($sql_password);
                    if ($result_password -> num_rows > 0)
                    {
                        $row_password = $result_password ->fetch_assoc();
                        $password_user = $row_password['password'];
                    }

                    if ( $password != $password_user)
                    {
                        echo "<script type='text/javascript'>alert('Wrong Password. Please enter the right password');</script>";
                        echo "<script type='text/javascript'> document.location='wallet_transfer.php?type_wallet=$type_wallet'; </script>";
                        exit();
                    }

                    //Check user info
                    $sql_user = "SELECT *
                    FROM user
                    Where ref_code = '$friend_ref_code'
                    And status='1'";
                    $result_user = $mysqli-> query($sql_user);
                    if ($result_user -> num_rows > 0)
                    {
                        $row_user = $result_user ->fetch_assoc();
                        $friend_name = $row_user['name'];
                    }
               }
               ?>

               <div class="row">
                    <div class="col-lg-12">
                        <div class="card">
                            <div class="card-body">
                                <form method="post" action="../Controller/Database_sql.php" enctype="multipart/form-data">
                                    <div class="form-body"> 
                                    <h3 class="card-title">Please Confirm Your A-wallet Transfer Info</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" value="<?php echo $amount_1; ?>" readonly>
                                                </div>
                                            </div>
     
                                            <div class="col-md-6">
                                                <div class="form-group">
                                                    <label class="control-label">Member Refferal Code</label>
                                                    <input type="text" class="form-control" name="friend_ref_code" value="<?php echo $friend_ref_code; ?>" readonly>
                                                </div>
                                            </div>
                                            <div class="col-md-6">
                                                <div class="form-group">
                                                    <label class="control-label">Member Detail</label>
                                                    <input type="text" class="form-control"  value="<?php echo $friend_name; ?>" readonly>
                                                </div>
                                            </div>

                                            <!--?php if ($level == "2")
                                            {
                                            ?-->
                                                <!--div class="col-md-6">
                                                    <div class="form-group">
                                                        <label class="control-label">TAC No</label>
                                                        <input type="number" class="form-control" name="tac_no" required>
                                                    </div>
                                                </div-->
                                            <!--?php
											}
                                            ?-->
                                            
                                        </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="password" value="<?php echo $password; ?>">
                                        <input type="hidden" class="form-control"  name="type_wallet" value="<?php echo $type_wallet; ?>">
                                        <input type="hidden" class="form-control"  name="type_Of_wallet" value="<?php echo $type_Of_wallet; ?>">
                                        <input type="hidden" class="form-control"  name="ori_tac_no" value="<?php echo $tac_no; ?>">
                                        <input type="hidden" class="form-control"  name="level" value="<?php echo $level; ?>">

                                    </div>
                                    <div class="form-actions">
                                        <a href="wallet_transfer.php?type_wallet=<?php echo $type_wallet; ?>" class="btn btn-danger">Cancel</a>
                                        <button name="withdraw_transfer" class="btn btn-success"><i class="fa fa-check"></i> Confirm And Proceed</button>
                                    </div>
                                </form>
                            </div>
                        </div>	
                    </div>
               </div>
	              				
                <!-- ============================================================== -->
                <!-- 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 -->
    
     <!-- All Jquery Start-->
    <?php include ("../Header/all_jquery.php"); ?>
    <!-- All Jquery End-->

    

</body>

</html>