<?php
session_start();
ob_start();
 include "../config/config.php"; 
 include "../config/function.php"; 
 
 $private_key=get_privatekey();
 $request_from_server=$_SERVER['HTTP_REFERER'];
$this_server=$_SERVER['HTTP_HOST'];
if($request_from_server!=''){
	check_access_url($request_from_server,$this_server);
}

if($_SESSION['login_status']!='YES' || $_SESSION['private_key']!=$private_key || $_SESSION['private_key']=='' || $_SESSION['admin_name']=='')
{
    echo "Blank";
	header("Location:../AppLogin");
	exit();
}

else
{
   $sys_date=date("Y-m-d H:i:s");
   // print_r($_REQUEST);
    $member_user_id=trim($_REQUEST['member_user_id']);
    $ref_no=$_REQUEST['ref_no'];
    $issuetopup_amount=$_REQUEST['issuetopup_amount'];
    
    if($issuetopup_amount<50)
    {
        $msg="Minimum 50$ Issue Fund";
    }
    else
    {
        $str="Select * from tbl_memberreg where member_user_id='$member_user_id'";
        $res=mysqli_query($connection,$str);
        while($row=mysqli_fetch_array($res))
        {
    
            $member_name=$row['member_full_name'];
            $strC="Select * from tbl_fund_issue where referrane_no='$ref_no'";
            $resC=mysqli_query($connection,$strC);
            if(mysqli_num_rows($resC)==0)
            {
                $Ins="Insert Into tbl_fund_issue(member_user_id,member_name,tr_date,tr_amount,referrane_no)values('$member_user_id','$member_name','$sys_date',$issuetopup_amount,'$ref_no')";
                mysqli_query($connection,$Ins) or die(mysqli_error($connection));
                $up="Update tbl_memberreg set topup_wallet=topup_wallet+$issuetopup_amount where member_user_id='$member_user_id'";
                mysqli_query($connection,$up) or die(mysqli_error($connection));
                $msg="Fund Issue Successfuly";
            }
            else
            {
                $msg="Fund Issue Successfuly";
            }
        }
    }
} 
header("Location:../SendTopupFund?msg=$msg");
?>