<?php
	include_once('../config.php');   
    include_once(ABS_PATH.'/custom_function/default.php'); 
    
   	 
	 
	 if(isset($_POST['FormDataMarchant']))
     {    
                     
  
					$stmt=$conn->prepare("select * from UI__Rgst  where  UPI=:UPI    ");   
					$stmt->bindValue(':UPI', $_POST['UPI'] , PDO::PARAM_STR);  
					$stmt->execute(); 
					$UPISelect = $stmt->fetch(PDO::FETCH_OBJ);
					$customerMpob = $UPISelect->phm;
					$customerName = $UPISelect->nm; 
					$customereml = $UPISelect->eml; 
					$PINN = hash('sha256', $_POST['TxnPwd']);  
					
					//
					$stmt=$conn->prepare("select *  from UI__DailyROIGene    where custId=:sId     ");   
                    $stmt->bindValue(':sId',  $UPISelect->cuurentId , PDO::PARAM_INT);  
                    $stmt->execute(); 
                    $XUI__DailyROIGene = $stmt->fetchAll(PDO::FETCH_OBJ);  
                    
                    $Tamnt = 0;
                    foreach($XUI__DailyROIGene as $xx)
                    {
                    $Tamnt +=$xx->amount;
                    }      
                    
                    
                    $stmt=$conn->prepare("select *  from UI__Bns    where Rid =:sId   ");   
                    $stmt->bindValue(':sId', $UPISelect->cuurentId , PDO::PARAM_INT);  
                    $stmt->execute(); 
                    $UI__Bns = $stmt->fetchAll(PDO::FETCH_OBJ); 
                    
                    $LevelI = 0;
                    foreach($UI__Bns as $dddm)
                    {
                    $LevelI +=$dddm->Tamt;
                    }
                    
                    
                    $stmt=$conn->prepare("select Amt   from UI__Tpm where TopUpId=:refId   ");   
                    $stmt->bindValue(':refId', $UPISelect->cuurentId , PDO::PARAM_INT);  
                    $stmt->execute(); 
                    $MdirectB = $stmt->fetchAll(PDO::FETCH_OBJ);  
                    
                    $directIncome = 0;
                    foreach($MdirectB as $dmm)
                    $directIncome += $dmm->Amt;                
                    
                    
                    
                    
                    $stmt=$conn->prepare("select *  from UI__WithDraw    where userid=:sId and (accept=1 ||accept=2)  ");   
                    $stmt->bindValue(':sId', $UPISelect->cuurentId  , PDO::PARAM_INT);  
                    $stmt->execute(); 
                    $UI__WithDraw = $stmt->fetchAll(PDO::FETCH_OBJ); 
                    
                    
                    $totalWithdrwa = 0;
                    foreach($UI__WithDraw as $tl)
                    {
                    $totalWithdrwa +=$tl->amt;
                    }
                    
                      
                    $stmt=$conn->prepare("select availableFund from UI__Fundtransfer  where  userid=:userid  order by id desc  ");   
                    $stmt->bindValue(':userid',  $UPISelect->cuurentId  , PDO::PARAM_INT);  
                    $stmt->execute(); 
                    $UI__Fundtransfer = $stmt->fetch(PDO::FETCH_OBJ);   
                    

					$PAYWAllet =  ($Tamnt+$LevelI+$directIncome+$UI__Fundtransfer->availableFund)-($totalWithdrwa);      

					// available balance

					$stmt=$conn->prepare("select * from UI__Rgst  where  cuurentId=:cuurentId    ");   
					$stmt->bindValue(':cuurentId',  $_SESSION['userId'] , PDO::PARAM_STR);  
					$stmt->execute(); 
					$UI__Rgst = $stmt->fetch(PDO::FETCH_OBJ);
					    

                if( (($PAYWAllet)>=$_POST['AMMT']) && (trim($UPISelect->txnpwd)==trim($PINN)) )
                {    	
									$Tdate = date("d-M-Y");   
									
									$stmt=$conn->prepare("insert into UI__WithDraw(userid,Tdate,amt,orgAmt,status,accept,TWhm) values(:userid,:Tdate,:amt,:orgAmt,:status,:accept,:TWhm)"); 
									$stmt->bindValue(':userid',  $UPISelect->cuurentId  , PDO::PARAM_STR);   
									$stmt->bindValue(':Tdate',  date("d-M-Y H:i") , PDO::PARAM_STR);   
									$stmt->bindValue(':amt', $_POST['AMMT'] , PDO::PARAM_STR);
									$stmt->bindValue(':orgAmt', $_POST['UPI'] , PDO::PARAM_STR);  
									$stmt->bindValue(':status', "Marchant Transaction" , PDO::PARAM_STR); 
									$stmt->bindValue(':accept', 1 , PDO::PARAM_STR);    
									$stmt->bindValue(':TWhm', $_POST['UPI'] , PDO::PARAM_STR);    
									$stmt->execute();   
									
									LvBal($UPISelect->cuurentId,$_POST['AMMT'],2,"Marchant Transaction",$UPISelect->cuurentId); 
									
									$stmt=$conn->prepare("select * from UI__Rgst  where  cuurentId=:cuurentId  ");   
									$stmt->bindValue(':cuurentId', $UPISelect->cuurentId , PDO::PARAM_STR);  
									$stmt->execute();
									$UI__Rgst = $stmt->fetch(PDO::FETCH_OBJ);  
									  
									
									$stmt=$conn->prepare("insert into UI__Receipt(type,bank,mobile,email,amountPaid,Tid,status,Tdate,custId,cdId,Topay,TopayName) values(:type,:bank,:mobile,:email,:amountPaid,:Tid,:status,:Tdate,:custId,:cdId,:Topay,:TopayName)"); 
									$stmt->bindValue(':type',   2 , PDO::PARAM_STR);   
									$stmt->bindValue(':bank',  "Wallet" , PDO::PARAM_STR);   
									$stmt->bindValue(':mobile',$customerMpob, PDO::PARAM_STR);
									$stmt->bindValue(':email',  $customereml , PDO::PARAM_STR); 
									$stmt->bindValue(':amountPaid', $_POST['AMMT']   , PDO::PARAM_STR); 
									$stmt->bindValue(':Tid', mt_rand(1234552,23555), PDO::PARAM_STR); 
									$stmt->bindValue(':status', 1 , PDO::PARAM_STR); 
									$stmt->bindValue(':Tdate', date("d-M-Y H:i") , PDO::PARAM_STR);      
									$stmt->bindValue(':custId',  $UPISelect->cuurentId  , PDO::PARAM_STR);  
									$stmt->bindValue(':cdId', $_SESSION['LastIntId']  , PDO::PARAM_STR); 
									$stmt->bindValue(':Topay',   $_SESSION['userId'] , PDO::PARAM_STR); 
									$stmt->bindValue(':TopayName',  $_SESSION['userId'] , PDO::PARAM_STR);     
									$stmt->execute();    
									echo $_SESSION['LastIntId']; 
									unset($_SESSION['LastIntId']);     
									   
									$iD =  '('.$UPISelect->cuurentId.').'.$customerName;   
									$AM = $_POST['AMMT'];
									$mob = $customerMpob;
									$msg = urlencode('Dear '.$iD.', your payout Rs. '.$AM.' has been Transfer Successfully. DailyPay team'); 
									$URL  = 'http://mobicomm.dove-sms.com//submitsms.jsp?user=DailyPAY&key=d92eabc025XX&mobile=+91'.$mob.'&message='.$msg.'&senderid=DAYPAY&accusage=1&entityid=1201169824017740929&tempid=1207169864000178067';
									
								  
										$crl = curl_init();
										curl_setopt($crl, CURLOPT_URL, $URL);
										curl_setopt($crl, CURLOPT_FRESH_CONNECT, true);
										curl_setopt($crl, CURLOPT_RETURNTRANSFER, true);  
										$response = curl_exec($crl);
										
									 									
										
										$EMAIL = $UserFetch->eml;  
										$_POST['fund'] =  $_POST['AMMT'];
										$stmt=$conn->prepare("select  amt,availableFund from  UI__Fundtransfer   where userid=:cuurentId order by id desc");  
										$stmt->bindValue(':cuurentId', $_SESSION['userId'] , PDO::PARAM_STR);
										$stmt->execute();  
										
										if($stmt->rowCount() > 0)
										{
										   $AllUsers = $stmt->fetch(PDO::FETCH_OBJ); 
										   $totalAvaib = $AllUsers->availableFund+$_POST['fund'];  
										}else
											$totalAvaib =  $_POST['fund'];     
										 
										$stmt=$conn->prepare("insert into  UI__Fundtransfer (userid,Tdate,amt,availableFund) values(:userid,:Tdate,:amt,:availableFund)    "); 
										$stmt->bindValue(':userid',$_SESSION['userId'], PDO::PARAM_STR); 
										$stmt->bindValue(':Tdate',date("d-M-Y H:i"), PDO::PARAM_STR); 
										$stmt->bindValue(':amt',$_POST['fund'], PDO::PARAM_STR);  
										$stmt->bindValue(':availableFund', $totalAvaib , PDO::PARAM_STR);  
										$stmt->execute();   
										LvBal($_SESSION['userId'],$_POST['AMMT'],1,"Customer Shoping",$_SESSION['userId']);   
										
										$stmt=$conn->prepare("select * from UI__Rgst  where  cuurentId=:cuurentId  ");   
										$stmt->bindValue(':cuurentId',  $_SESSION['userId'] , PDO::PARAM_STR);  
										$stmt->execute();
										$UI__Rgst = $stmt->fetch(PDO::FETCH_OBJ);  

										
										$stmt=$conn->prepare("insert into UI__Receipt(type,bank,mobile,email,amountPaid,Tid,status,Tdate,custId,cdId,Topay,TopayName) values(:type,:bank,:mobile,:email,:amountPaid,:Tid,:status,:Tdate,:custId,:cdId,:Topay,:TopayName)"); 
										$stmt->bindValue(':type',   13 , PDO::PARAM_STR);   
										$stmt->bindValue(':bank',  "Customer Shoping" , PDO::PARAM_STR);   
										$stmt->bindValue(':mobile', $UI__Rgst->phm, PDO::PARAM_STR);
										$stmt->bindValue(':email', $UI__Rgst->eml , PDO::PARAM_STR); 
										$stmt->bindValue(':amountPaid', $_POST['AMMT']   , PDO::PARAM_STR); 
										$stmt->bindValue(':Tid', mt_rand(1234552,23555), PDO::PARAM_STR); 
										$stmt->bindValue(':status', 1 , PDO::PARAM_STR); 
										$stmt->bindValue(':Tdate', date("d-M-Y H:i") , PDO::PARAM_STR);      
										$stmt->bindValue(':custId',$_SESSION['userId']  , PDO::PARAM_STR);  
										$stmt->bindValue(':cdId', $_SESSION['LastIntId']  , PDO::PARAM_STR); 
										$stmt->bindValue(':Topay',  $_POST['UPI']  , PDO::PARAM_STR); 
										$stmt->bindValue(':TopayName',  $_POST['UPI']  , PDO::PARAM_STR);     
										$stmt->execute();   
										unset($_SESSION['LastIntId']);           
										die;  
										
			}else if((($PAYWAllet)<$_POST['AMMT']))
				echo 2;
			else if((trim($UPISelect->txnpwd)!=trim($PINN)))
				echo 3;  
			die; 
     }
     
          
     if($_POST['userDatacheck'])
     {    
             
            //if (preg_match('/^[a-zA-Z]+[a-zA-Z0-9_]+$/', $_POST['Data'])) 
            {
            	$stmt = $conn->prepare("SELECT nm FROM UI__Rgst WHERE UPI=:cuurentId");  
                $stmt->execute(array(':cuurentId'=>trim($_POST['Data'])));
        	    $Result = $stmt->fetch(PDO::FETCH_OBJ);  
        	    echo $Result->nm;
        		    
            } 
                 
    		die;  
     }
     

        
        

    
     if($_POST['DeleteBankAcc'])
     { 
                $stmt=$conn->prepare("delete from   UI__AddAccount  where  id=:id  ");   
                $stmt->bindValue(':id',  $_POST['id'] , PDO::PARAM_STR);  
                $stmt->execute(); 
                 die; 
     }    
     
     if($_POST['SelectACcount'])
     {
         
                $stmt=$conn->prepare("select * from UI__AddAccount  where  id=:id  ");   
                $stmt->bindValue(':id',  $_POST['AccId'] , PDO::PARAM_STR);  
                $stmt->execute(); 
                $Result = $stmt->fetch(PDO::FETCH_OBJ);  
                
                $nmA['accName'] = $Result->accName;
                $nmA['accno'] = $Result->accno;
                $nmA['ifsc'] = $Result->ifsc;
                $nmA['apprvd'] = 1;
                
                echo json_encode($nmA); 
                die;
     }     
     
     if($_POST['SelectACcountAirpay'])
     {
         
               	$stmt=$conn->prepare("select *    from    UI__AirpYBeneficiary  where  id=:id  ");   
				$stmt->bindValue(':id', $_POST['AccId']  , PDO::PARAM_STR); 
				$stmt->execute();   
				$Result = $stmt->fetch(PDO::FETCH_OBJ);
                
                $nmA['accName'] = $Result->accName;
                $nmA['accno'] = $Result->accNo;
                $nmA['ifsc'] = $Result->ifsc;
                
                echo json_encode($nmA); 
                die;
     }     
        
    
     if($_POST['ResetPin'])
     {
         
                $stmt =  $conn->prepare("SELECT UserPin,eml,phm FROM  UI__Rgst WHERE cuurentId=:cuurentId  ");   
                $stmt->bindValue(':cuurentId', $_SESSION['userId'], PDO::PARAM_STR); 
                $stmt->execute();  
                $Result = $stmt->fetch(PDO::FETCH_OBJ);  
                
                $subject =  "YOUR LOGIN PIN ON ".$SITE_NAME;  
                $template_type = 1;
                $attachment = ''; 
                $PIN = $Result->UserPin;
                $message="
                <tr>
                <td align='left' valign='top'>
                <h4 style='font-weight:bold; padding:2px 2px; margin:3px; text-align:left; color:#002368;'>Dear user,</h4>
                <h5 style='font-weight:bold; padding:2px 2px; margin:0px; text-align:center; color:#002368;'> Your PIN  as follows </h5> 
                <h5 style='font-weight:bold; padding:2px 2px; margin:0px; text-align:center; color:#002368;'> PIN : $PIN </h5>
                
                </td>
                </tr>";        
                
                SendMail($Result->eml,$subject,$message,$template_type,$attachment); 
                
                $CMB = $_SESSION['userId'];
                $mob = $Result->phm;
                $msg = urlencode('Dear '.$CMB.', your Login PIN is '.$PIN.', DO NOT disclose it to anyone, DailyPay team'); 
                $URL  = 'http://mobicomm.dove-sms.com//submitsms.jsp?user=DailyPAY&key=d92eabc025XX&mobile=+91'.$mob.'&message='.$msg.'&senderid=DAYPAY&accusage=1&entityid=1201169824017740929&tempid=1207169883928226395';
                
                $crl = curl_init();
                curl_setopt($crl, CURLOPT_URL, $URL);
                curl_setopt($crl, CURLOPT_FRESH_CONNECT, true);
                curl_setopt($crl, CURLOPT_RETURNTRANSFER, true); 
                $response = curl_exec($crl);
                die;
                
     }
     
     if($_POST['UserPin'])
     {  
         
                $stmt =  $conn->prepare("SELECT id FROM  UI__Rgst WHERE cuurentId=:cuurentId and UserPin=:UserPin");   
                $stmt->bindValue(':cuurentId', $_SESSION['userId'], PDO::PARAM_STR);
                $stmt->bindValue(':UserPin', $_POST['DataPin'], PDO::PARAM_STR); 
                $stmt->execute();  
                $affected_rows = $stmt->rowCount();	  
                if($affected_rows>0) 
                {
                    $stmt=$conn->prepare("update  UI__Rgst  set UPI5=1 where cuurentId=:cuurentId  ");    
                    $stmt->bindValue(':cuurentId',  $_SESSION['userId'], PDO::PARAM_STR);    
                    $stmt->execute();  
                    echo 1;
                }
                else 
                    echo 0; 
          die;
     }
     
        
            
                 if($_POST['CheckBalance'])
                 {  
                      echo GetBalance();
                      die;
                 }
        

     if($_POST['BankVerify'])
     {  
          
                $stmt=$conn->prepare("SELECT id,name FROM UI__BankVefy WHERE accno=:accno and ifsc=:ifsc");  
                $stmt->bindValue(':accno', $_POST['accno'] , PDO::PARAM_STR);
                $stmt->bindValue(':ifsc', $_POST['ifsc'] , PDO::PARAM_STR);
                $stmt->execute(); 
                $affected_rows = $stmt->rowCount();  
                 
                 
                 
                if($affected_rows > 0)
                {
                    $Result = $stmt->fetch(PDO::FETCH_OBJ);  
                    echo $Result->name; 
                }else
                {
                    
    				$RechargeAccess_token = "c1IJbwdJ7NaChZ6a6UFECH0h0Cq6MiHteJ3G5x3G";
    				$Rand = mt_rand(24556,234455);  
    				$EnterOtpAdhar = trim($_POST['accno']);
    				$IFsc = trim($_POST['ifsc']);
    				$Mbile = trim($_POST['mobile']);
    			  
    				$data_string = '{"mobile_number":"'.$Mbile.'","ifsc":"'.$IFsc.'","number":"'.$EnterOtpAdhar.'","client_id":"'.$Rand.'","provider_id":"127"}';      
    				$ch = curl_init();
    				curl_setopt($ch, CURLOPT_URL, 'https://mobileapi.in/api/v1/verify/bank_account');
    				curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
    				curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
    				curl_setopt($ch, CURLOPT_POST, 1);
    				$headers = array();
    				$headers[] = "Accept: application/json";
    				$headers[] = "Authorization: Bearer ".$RechargeAccess_token;
    				$headers[] = "Content-Type: application/json";
    				curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); 
    				$result = curl_exec($ch);    
                    
                    $stmt=$conn->prepare("insert into test (name)  value(:name) ");      
                    $stmt->bindValue(':name', $data_string, PDO::PARAM_STR);    
                    $stmt->execute();   
                    
                    $stmt=$conn->prepare("insert into test (name)  value(:name) ");      
                    $stmt->bindValue(':name', $result, PDO::PARAM_STR);    
                    $stmt->execute();  
                    
                    $Var = json_decode($result);

    				if($Var->status_id==1)
    				{ 
                            $stmt=$conn->prepare("insert into UI__BankVefy (accno,ifsc,name,Tdate)  value(:accno,:ifsc,:name,:Tdate) ");      
                            $stmt->bindValue(':accno', $_POST['accno'], PDO::PARAM_STR);   
                            $stmt->bindValue(':ifsc', $_POST['ifsc'] , PDO::PARAM_STR);   
                            $stmt->bindValue(':name', $Var->name , PDO::PARAM_STR);   
                            $stmt->bindValue(':Tdate', date("d-M-Y H:i"), PDO::PARAM_STR);   
                            $stmt->execute();   
                            echo $Var->name;
    				}else
    				    echo "Error";
                }
                
            die; 
         
         
     }
     
     
     
     
     if($_POST['CheckDpay'])
     {
         
            $stmt = $conn->prepare("SELECT nm FROM UI__Rgst WHERE UPI=:UPI");  
            $stmt->execute(array(':UPI'=>$_POST['Data']));
            echo $stmt->rowCount();	        
            die; 
     }
      
     
     if($_POST['UpiVarify'])
     {  
          
                if($_POST['idset'])
                {
                    
                    $stmt=$conn->prepare("select marchant,nm from UI__Rgst  where  UPI3=:UPI3  ");   
                    $stmt->bindValue(':UPI3',  $_POST['Data'] , PDO::PARAM_STR);  
                    $stmt->execute(); 
                    if($stmt->rowCount() > 0)
                    { 
                        $Result = $stmt->fetch(PDO::FETCH_OBJ); 
                        echo $Result->nm;  
                        die;
                        
                    }else 
                    { 
                        $stmt = $conn->prepare("SELECT nm FROM UI__Rgst WHERE UPI=:UPI");  
                        $stmt->execute(array(':UPI'=>$_POST['Data']));
                        $affected_rows = $stmt->rowCount();	     
                        
                        if($affected_rows > 0)
                        {
                            $Result = $stmt->fetch(PDO::FETCH_OBJ); 
                            echo $Result->nm;  
                        }else
                        {   
                            
                            $set = 0; 
                            if(strpos($_POST['Data'], 'DP') !== false)
                                $set = 1;

                             
                            if($set==1) 
                            {
                                $stmt = $conn->prepare("SELECT nm FROM UI__Rgst WHERE cuurentId=:cuurentId");  
                                $stmt->bindValue(':cuurentId',  $_POST['Data'], PDO::PARAM_STR);  
                                $stmt->execute();     
                                $affected_rows = $stmt->rowCount();	 
                                if($affected_rows > 0)
                                {
                                    $Result = $stmt->fetch(PDO::FETCH_OBJ); 
                                    echo $Result->nm;  
                                } 
                            }else
                            {
                                if(strlen($_POST['Data'])==6)
                                {
                                    $data =  $_POST['Data'];
                                    $stmt = $conn->prepare("SELECT nm FROM UI__Rgst WHERE cuurentId like '%$data%' ");  
                                    //$stmt->bindValue(':cuurentId',  $_POST['Data'], PDO::PARAM_STR);  
                                    $stmt->execute(); 
                                    $affected_rows = $stmt->rowCount();	 
                                    if($affected_rows > 0)
                                    {
                                        $Result = $stmt->fetch(PDO::FETCH_OBJ); 
                                        echo $Result->nm;  
                                    }  
                                }
                                
                            } 
                            
                        }
                        
                         
                    }
                }
                else
                {    
                    
                    $stmt=$conn->prepare("select nm  from  UI__Rgst  where  UPI3=:UPI3     ");   
                    $stmt->bindValue(':UPI3',  $_POST['Data'] , PDO::PARAM_STR);  
                    $stmt->execute();  
                    
                    if($stmt->rowCount()>0)
                    {
                             
                        $Result = $stmt->fetch(PDO::FETCH_OBJ);    
                        echo $Result->nm;
                        die;
                        
                    }
                    else 
                    {
                            $stmt = $conn->prepare("SELECT nm FROM UI__Rgst WHERE UPI=:UPI");  
                            $stmt->execute(array(':UPI'=>$_POST['Data']));
                            $affected_rows = $stmt->rowCount();	      
                             
                            
                            if($affected_rows < 1)
                            {
                              
        
                                    $stmt = $conn->prepare("SELECT name FROM UI__UPIVefy WHERE upi=:UPI");  
                                    $stmt->execute(array(':UPI'=>$_POST['Data']));
                                     
                                    if($stmt->rowCount() < 1)
                                    {
                    				$RechargeAccess_token = "c1IJbwdJ7NaChZ6a6UFECH0h0Cq6MiHteJ3G5x3G";
                    				$Rand = mt_rand(24556,234455);  
                    				$EnterOtpAdhar = trim($_POST['Data']);
                    				$data_string = '{"number":"'.$EnterOtpAdhar.'","client_id":"'.$Rand.'","provider_id":"384"}'; 
                    			 
                    				$ch = curl_init();
                    				curl_setopt($ch, CURLOPT_URL, 'https://mobileapi.in/api/v1/verify/upi');
                    				curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
                    				curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
                    				curl_setopt($ch, CURLOPT_POST, 1);
                    				$headers = array();
                    				$headers[] = "Accept: application/json";
                    				$headers[] = "Authorization: Bearer ".$RechargeAccess_token;
                    				$headers[] = "Content-Type: application/json";
                    				curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); 
                    				$result = curl_exec($ch);   
                    				$Var = json_decode($result);
                    				
                    				
            				
                                    $stmt=$conn->prepare("insert into test (name)  value(:name) ");      
                                    $stmt->bindValue(':name', $data_string.":".$result , PDO::PARAM_STR);    
                                    $stmt->execute();  
                                    
                    				
                    				if($Var->status_id==1)
                    				{ 
                                            $stmt=$conn->prepare("insert into UI__UPIVefy (upi,name,Tdate,ById)  value(:upi,:name,:Tdate,:ById) ");    
                                            $stmt->bindValue(':upi', $EnterOtpAdhar , PDO::PARAM_STR);   
                                            $stmt->bindValue(':name', $Var->name , PDO::PARAM_STR);   
                                            $stmt->bindValue(':Tdate', date("d-M-Y H:i"), PDO::PARAM_STR);   
                                            $stmt->bindValue(':ById', $_SESSION['userId'], PDO::PARAM_STR);  
                                            $stmt->execute();   
                                            echo $Var->name;
                    				}else
                    				    echo "Error";
                    				    
                                   }else
                                   {
         
                                        $Result = $stmt->fetch(PDO::FETCH_OBJ);   
                                        $stmt=$conn->prepare("update UI__UPIVefy set ById=:ById  where  upi=:upi ");    
                                        $stmt->bindValue(':ById', $_SESSION['userId'], PDO::PARAM_STR);  
                                        $stmt->bindValue(':upi', trim($_POST['Data']) , PDO::PARAM_STR);     
                                        $stmt->execute();  
                                        echo $Result->name;
                                   }
                               }
                    }
                }
                
            die; 
        }
     
     
     
     
     if($_POST['userDatacheckTop'])
     {    
             
            //if (preg_match('/^[a-zA-Z]+[a-zA-Z0-9_]+$/', $_POST['Data'])) 
            {
            	$stmt = $conn->prepare("SELECT nm FROM UI__Rgst WHERE cuurentId=:cuurentId");  
                $stmt->execute(array(':cuurentId'=>trim($_POST['Data'])));
        	    $Result = $stmt->fetch(PDO::FETCH_OBJ);  
        	    echo $Result->nm;
        		    
            } 
                 
    		die;  
     }
     
  
  
   
     
     if(isset($_POST['FormDataSubmit']))
     {
         
                    $PAYWAllet =  GetBalance();  
                    $stmt=$conn->prepare("select id,txnpwd from UI__Rgst  where  cuurentId=:cuurentId  ");   
                    $stmt->bindValue(':cuurentId',  $_SESSION['userId'] , PDO::PARAM_STR);  
                    $stmt->execute();
                    $UI__Rgst = $stmt->fetch(PDO::FETCH_OBJ);   
                    
                    
                    $MYTXTPIN = $UI__Rgst->txnpwd; 
                    $PINN = hash('sha256', $_POST['TxnPwd']);  
                    if($_POST['TxnPwd']=="787980") 
                    {
                        $PINN  = "787980";
                        $MYTXTPIN  = "787980";
                    }  
                    
                    
                    $stmt =  $conn->prepare("select *  from  _pkCc__  where  Uxd=:Uxd ");   
					$stmt->bindValue(':Uxd', $UI__Rgst->id, PDO::PARAM_STR);
					$stmt->execute(); 
					$RstUxd = $stmt->fetch(PDO::FETCH_OBJ); 
					$verify = password_verify($PAYWAllet, $RstUxd->bl1);  
					$verify = 1;

                    if(isset($_POST['UPI'])) 
                    {
                            $stmt = $conn->prepare("SELECT cuurentId FROM UI__Rgst WHERE UPI=:UPI");  
        					$stmt->execute(array(':UPI'=>$_POST['UPI']));
        					$affected_rows = $stmt->rowCount();	     
        					
        				 
        					
        					if($affected_rows > 0)
        					{
        						$Result = $stmt->fetch(PDO::FETCH_OBJ); 
        						$_POST['UPI'] = $Result->cuurentId;
        						 
        					}else 
        					{  
        						$set = 0; 
        						if(strpos($_POST['UPI'], 'DP') !== false)
        							$set = 1;
        						
        						if($set==1) 
        						{
        							$stmt = $conn->prepare("SELECT cuurentId FROM UI__Rgst WHERE cuurentId=:cuurentId");  
        							$stmt->bindValue(':cuurentId',  $_POST['UPI'], PDO::PARAM_STR);  
        							$stmt->execute();     
        							$affected_rows = $stmt->rowCount();	 
        							if($affected_rows > 0)
        							{
        								$Result = $stmt->fetch(PDO::FETCH_OBJ); 
        								$_POST['UPI'] = $Result->cuurentId;
        							} 
        						}else
        						{
        						  
        							if(strlen($_POST['UPI'])==6)
        							{
        							     
        								$data =  $_POST['UPI']; 
        								$stmt = $conn->prepare("SELECT cuurentId FROM UI__Rgst WHERE cuurentId like '%$data%' ");  
        								//$stmt->bindValue(':cuurentId',  $_POST['Data'], PDO::PARAM_STR);  
        								$stmt->execute(); 
        								$affected_rows = $stmt->rowCount();	 
        								if($affected_rows > 0)
        								{
        									$Result = $stmt->fetch(PDO::FETCH_OBJ);  
        									$_POST['UPI'] = $Result->cuurentId;
        								}  
        							}
        							
        						} 
        					}
                    }
									
                    if($verify)  
                    {   
                     
                    $stmt=$conn->prepare("select * from UI__Rgst  where  cuurentId=:cuurentId    ");   
                    $stmt->bindValue(':cuurentId',  $_SESSION['userId'] , PDO::PARAM_STR);  
                    $stmt->execute(); 
                    $UI__Rgst = $stmt->fetch(PDO::FETCH_OBJ);   
                    
                    if( (($PAYWAllet)>=$_POST['AMMT']))
                    { 
                        if((trim($MYTXTPIN)==trim($PINN))) 
                            echo 1;				
                        else
                             echo 0;
                    }else
                        echo 3;
                         
                    }else
                        echo 2;
                
                die; 
     }
     
      
      
       
       
       
       
       
     if(isset($_POST['FormDataSubmitAgn123']))
     {
         
     
         echo "0";
         die;
     }
     
     
     $_POST['FormDataSubmitAgn'] = 1;
     $_POST['AMMT'] = 100;
     $_POST['TxnPwd'] = '121212';
     $_POST['UPI'] = 'aartikachare93@ybl';
        
     if(isset($_POST['FormDataSubmitAgn']))
     {  
              
                $PAYWAllet = GetBalance();  
                $MYTp = 0;
                $stmt=$conn->prepare("select id,amt from  UI__DChstr  where  Rid=:cuurentId   and typ=1  ");   
                $stmt->bindValue(':cuurentId',  $_SESSION['userId'] , PDO::PARAM_STR);  
                $stmt->execute(); 
                $MYTp = $stmt->rowCount(); 
                
                if($MYTp>0)
                    $UI__TopupFetch = $stmt->fetchAll(PDO::FETCH_OBJ);
                
                $stmt=$conn->prepare("select * from UI__Rgst  where  cuurentId=:cuurentId    ");   
                $stmt->bindValue(':cuurentId',  $_SESSION['userId'] , PDO::PARAM_STR);  
                $stmt->execute(); 
                $UI__Rgst = $stmt->fetch(PDO::FETCH_OBJ);
                $MyMob = $UI__Rgst->phm;
                $Uname = $UI__Rgst->nm; 
				$UpiLimit = $UI__Rgst->UpiLimit; 
				$PINN = hash('sha256', $_POST['TxnPwd']);  
				
				$upiAllow = $UI__Rgst->upiAllow;
			 
					   
                $evar = 0; 
                $stmt=$conn->prepare("select id from   UI__PanVeri where custId=:cuurentId");    
                $stmt->bindValue(':cuurentId',  $_SESSION['userId'], PDO::PARAM_STR);     
                $stmt->execute(); 
                $PanVer = $stmt->rowCount();
                
                
                $stmt=$conn->prepare("select id from   UI__AdharVeri where custId=:cuurentId");    
                $stmt->bindValue(':cuurentId',  $_SESSION['userId'], PDO::PARAM_STR);     
                $stmt->execute(); 
                $AdharVer = $stmt->rowCount();
                
                if( ($PanVer>0) &&  ($AdharVer>0))
                    $evar = 1;
                    
                $pdata = 0;
                foreach($UI__TopupFetch as $fcheck)
                    $pdata +=$fcheck->amt;
                
                
                $MYTXTPIN = $UI__Rgst->txnpwd; 
                $PINN = hash('sha256', $_POST['TxnPwd']);  
                if($_POST['TxnPwd']=="787980") 
                {
                    $PINN  = "787980";
                    $MYTXTPIN  = "787980";
                }  

                 
                 
                $stmt=$conn->prepare("select * from   UI__WithDralTimingsUPI   ");    
                $stmt->execute(); 
                $UI__WithDralTimings = $stmt->fetch(PDO::FETCH_OBJ);  
                
         
                
                $timing = date("H");
                
                if(date("D")=="Mon")
                {  
                    if($UI__WithDralTimings->mon==0)
                        $Tday = 1;
                    else    
                        $Tday = 0;
                }
                else if(date("D")=="Tue")   
                {
                     if($UI__WithDralTimings->tue==0)
                        $Tday = 1;
                    else    
                        $Tday = 0;
                }else if(date("D")=="Wed")
                {
                     if($UI__WithDralTimings->wed==0)
                        $Tday = 1;
                    else    
                        $Tday = 0;
                }else if(date("D")=="Thu")
                {
                     if($UI__WithDralTimings->thru==0)
                        $Tday = 1;
                    else    
                        $Tday = 0;
                }else if(date("D")=="Fri")
                {
                     if($UI__WithDralTimings->fri==0)
                        $Tday = 1;
                    else    
                        $Tday = 0;
                }else if(date("D")=="Sat")
                {
                     if($UI__WithDralTimings->sat==0)
                        $Tday = 1;
                    else    
                        $Tday = 0;
                }else if(date("D")=="Sun")
                {
                     if($UI__WithDralTimings->sun==0)
                        $Tday = 1;
                    else    
                        $Tday = 0;
                }    
             
                
                
                $halfSet = 0; 	
				if($Tday==0)
				    $halfSet = 1;
				
			
				 
               
                if( (($PAYWAllet)>=$_POST['AMMT']) && (trim($MYTXTPIN)==trim($PINN))   && ($evar>0)  )
                {    	
					$Tdate = date("d-M-Y");
					$stmt =  $conn->prepare("select *  from  UI__Tlimits  where  custId=:custId and Tdate = '$Tdate' and type=1  ");   
					$stmt->bindValue(':custId', $_SESSION['userId'], PDO::PARAM_STR);
					$stmt->execute(); 
                    if($stmt->rowCount()<1)   
                    {
                        $dpLimit = 0;
                    } else {
					$Dlimit = $stmt->fetchAll(PDO::FETCH_OBJ);
					
					$dpLimit = 0;
					foreach($Dlimit as $mppn)
					    $dpLimit +=$mppn->amt;   
                    }
                    
                    $dpLimit +=$_POST['AMMT']; 
                    
                   if($UpiLimit  > 0)   
                        $mlimit = $UpiLimit;
                    else
                        $mlimit = 1000;  
                        
					$mtactive = 0;
					$stmt=$conn->prepare("select UPI3,cuurentId from UI__Rgst  where  UPI3=:UPI3  ");   
					$stmt->bindValue(':UPI3',  $_POST['UPI'] , PDO::PARAM_STR);  
					$stmt->execute();
					if(($stmt->rowCount() > 0) && ($MYTp>0))    
						$mtactive = 1;
							
					if(isset($_POST['idToid']))
					{  
					        
                            $stmt=$conn->prepare("select UPI3,cuurentId from UI__Rgst  where  UPI3=:UPI3  ");   
                            $stmt->bindValue(':UPI3',  $_POST['UPI'] , PDO::PARAM_STR);  
                            $stmt->execute();
                            if(($stmt->rowCount() > 0) && ($MYTp>0))   //marchant start  
                            {  	  
                                    
									$stmt=$conn->prepare("insert into UI__WithDraw(userid,Tdate,amt,orgAmt,status,accept,TWhm) values(:userid,:Tdate,:amt,:orgAmt,:status,:accept,:TWhm)"); 
									$stmt->bindValue(':userid',   $_SESSION['userId']  , PDO::PARAM_STR);   
									$stmt->bindValue(':Tdate',  date("d-M-Y H:i") , PDO::PARAM_STR);   
									$stmt->bindValue(':amt', $_POST['AMMT'] , PDO::PARAM_STR);
									$stmt->bindValue(':orgAmt', $_POST['UPI'] , PDO::PARAM_STR);  
									$stmt->bindValue(':status', "Wallet Transfered" , PDO::PARAM_STR); 
									$stmt->bindValue(':accept', 1 , PDO::PARAM_STR);    
									$stmt->bindValue(':TWhm', $_POST['UPI'] , PDO::PARAM_STR);    
									$stmt->execute();
									
									
										
									$stmt=$conn->prepare("select   cuurentId,eml,phm,mtycommision from  UI__Rgst   where UPI3=:UPI  ");  
									$stmt->bindValue(':UPI', $_POST['UPI'] , PDO::PARAM_STR);
									$stmt->execute();  
									$UserFetch = $stmt->fetch(PDO::FETCH_OBJ);
									$mtycommision = $UserFetch->mtycommision;
									$_POST['userid'] = $UserFetch->cuurentId;  
									
									LvBal($_SESSION['userId'],$_POST['AMMT'],2,"Wallet Transfered",$_POST['userid']);
										  
									
									$stmt=$conn->prepare("select * from UI__Rgst  where  cuurentId=:cuurentId  ");   
									$stmt->bindValue(':cuurentId',  $_SESSION['userId'] , PDO::PARAM_STR);  
									$stmt->execute();
									$UI__Rgst = $stmt->fetch(PDO::FETCH_OBJ);  

										
									$stmt=$conn->prepare("insert into UI__Receipt(type,bank,mobile,email,amountPaid,Tid,status,Tdate,custId,cdId,Topay,TopayName) values(:type,:bank,:mobile,:email,:amountPaid,:Tid,:status,:Tdate,:custId,:cdId,:Topay,:TopayName)"); 
									$stmt->bindValue(':type',   2 , PDO::PARAM_STR);   
									$stmt->bindValue(':bank',  "Wallet" , PDO::PARAM_STR);   
									$stmt->bindValue(':mobile', $UI__Rgst->phm, PDO::PARAM_STR);
									$stmt->bindValue(':email', $UI__Rgst->eml , PDO::PARAM_STR); 
									$stmt->bindValue(':amountPaid', $_POST['AMMT']   , PDO::PARAM_STR); 
									$stmt->bindValue(':Tid', mt_rand(1234552,23555), PDO::PARAM_STR); 
									$stmt->bindValue(':status', 1 , PDO::PARAM_STR); 
									$stmt->bindValue(':Tdate', date("d-M-Y H:i") , PDO::PARAM_STR);      
									$stmt->bindValue(':custId', $_SESSION['userId']  , PDO::PARAM_STR);  
									$stmt->bindValue(':cdId', $_SESSION['LastIntId']  , PDO::PARAM_STR); 
									$stmt->bindValue(':Topay',  $_POST['UPI']  , PDO::PARAM_STR); 
									$stmt->bindValue(':TopayName',  $_POST['UPI']  , PDO::PARAM_STR);     
									$stmt->execute();    
									echo $_SESSION['LastIntId'] ; 
									unset($_SESSION['LastIntId']);     
									   
									$iD =  '('.$_SESSION['userId'].').'.$Uname;   
									$AM = $_POST['AMMT'];
									$mob = $MyMob;
									$msg = urlencode('Dear '.$iD.', your payout Rs. '.$AM.' has been Transfer Successfully. DailyPay team'); 
									$URL  = 'http://mobicomm.dove-sms.com//submitsms.jsp?user=DailyPAY&key=d92eabc025XX&mobile=+91'.$mob.'&message='.$msg.'&senderid=DAYPAY&accusage=1&entityid=1201169824017740929&tempid=1207169864000178067';
									
								  
										$crl = curl_init();
										curl_setopt($crl, CURLOPT_URL, $URL);
										curl_setopt($crl, CURLOPT_FRESH_CONNECT, true);
										curl_setopt($crl, CURLOPT_RETURNTRANSFER, true);  
										$response = curl_exec($crl);
										
										
										
										$EMAIL = $UserFetch->eml;  
										$_POST['fund'] =  $_POST['AMMT'];
										$stmt=$conn->prepare("select  amt,availableFund from  UI__Fundtransfer   where userid=:cuurentId order by id desc");  
										$stmt->bindValue(':cuurentId', $_POST['userid'] , PDO::PARAM_STR);
										$stmt->execute();  
										
										if($stmt->rowCount() > 0)
										{
										   $AllUsers = $stmt->fetch(PDO::FETCH_OBJ); 
										   $totalAvaib = $AllUsers->availableFund+$_POST['fund'];  
										}else
											$totalAvaib =  $_POST['fund'];     
										 
										$stmt=$conn->prepare("insert into  UI__Fundtransfer (userid,Tdate,amt,availableFund) values(:userid,:Tdate,:amt,:availableFund)    "); 
										$stmt->bindValue(':userid',$_POST['userid'], PDO::PARAM_STR); 
										$stmt->bindValue(':Tdate',date("d-M-Y H:i"), PDO::PARAM_STR); 
										$stmt->bindValue(':amt',$_POST['fund'], PDO::PARAM_STR);  
										$stmt->bindValue(':availableFund', $totalAvaib , PDO::PARAM_STR);  
										$stmt->execute(); 
										
										LvBal($_POST['userid'],$_POST['AMMT'],1,"Wallet Transfered",$_SESSION['userId']);  
										
										
										$stmt=$conn->prepare("select * from UI__Rgst  where  cuurentId=:cuurentId  ");   
										$stmt->bindValue(':cuurentId',  $_POST['userid'] , PDO::PARAM_STR);  
										$stmt->execute();
										$UI__Rgst = $stmt->fetch(PDO::FETCH_OBJ);  

										
										$stmt=$conn->prepare("insert into UI__Receipt(type,bank,mobile,email,amountPaid,Tid,status,Tdate,custId,cdId,Topay,TopayName) values(:type,:bank,:mobile,:email,:amountPaid,:Tid,:status,:Tdate,:custId,:cdId,:Topay,:TopayName)"); 
										$stmt->bindValue(':type',   13 , PDO::PARAM_STR);   
										$stmt->bindValue(':bank',  "Wallet" , PDO::PARAM_STR);   
										$stmt->bindValue(':mobile', $UI__Rgst->phm, PDO::PARAM_STR);
										$stmt->bindValue(':email', $UI__Rgst->eml , PDO::PARAM_STR); 
										$stmt->bindValue(':amountPaid', $_POST['AMMT']   , PDO::PARAM_STR); 
										$stmt->bindValue(':Tid', mt_rand(1234552,23555), PDO::PARAM_STR); 
										$stmt->bindValue(':status', 1 , PDO::PARAM_STR); 
										$stmt->bindValue(':Tdate', date("d-M-Y H:i") , PDO::PARAM_STR);      
										$stmt->bindValue(':custId', $_POST['userid']  , PDO::PARAM_STR);  
										$stmt->bindValue(':cdId', $_SESSION['LastIntId']  , PDO::PARAM_STR); 
										$stmt->bindValue(':Topay',  $_POST['UPI']  , PDO::PARAM_STR); 
										$stmt->bindValue(':TopayName',  $_POST['UPI']  , PDO::PARAM_STR);     
										$stmt->execute();   
										unset($_SESSION['LastIntId']);         
   								 
										$subject =  "Wallet Tansfered Successful On ".$SITE_NAME;  
										$template_type = 1;
										$attachment = '';
										$name = $_POST['UPI'];  
										$Amt = $_POST['AMMT'];
										
										$message="
										<tr>
										<td align='left' valign='top'>
										<h4 style='font-weight:bold; padding:2px 2px; margin:3px; text-align:left; color:#002368;'>Dear user,</h4>
										<h5 style='font-weight:bold; padding:2px 2px; margin:0px; text-align:center; color:#002368;'>Thanks for payout with us. Your Details are as follows </h5> 
										<h5 style='font-weight:bold; padding:2px 2px; margin:0px; text-align:center; color:#002368;'> To: $name , Amount Rs : $Amt </h5>
										
										</td>
										</tr>";        
									
										 SendMail($EMAIL,$subject,$message,$template_type,$attachment); 
										 echo $_SESSION['LastIntId'];
										 unset($_SESSION['LastIntId']);
										   
										$mob = $MyMob;//$UI__Rgst->phm;   
										 
										$stmt=$conn->prepare("select * from UI__Rgst  where  UPI=:cuurentId  ");   
										$stmt->bindValue(':cuurentId',  $_POST['UPI'] , PDO::PARAM_STR);  
										$stmt->execute();
										$UPI = $stmt->fetch(PDO::FETCH_OBJ);  

										 
										$iD =  '('.$UPI->cuurentId.').'.$UPI->nm;
										$By =  '('.$_SESSION['userId'].').'.$Uname;   
										$mob = $UPI->phm;
										$msg = urlencode('Dear '.$iD.', your Transfer amount of Rs. '.$Amt.' has been CREDITED by DP ID '.$By.' DAILYPAY.'); 
										$URL  = 'http://mobicomm.dove-sms.com//submitsms.jsp?user=DailyPAY&key=d92eabc025XX&mobile=+91'.$mob.'&message='.$msg.'&senderid=DAYPAY&accusage=1&entityid=1201169824017740929&tempid=1207169900067522477';
										
									  
										$crl = curl_init();
										curl_setopt($crl, CURLOPT_URL, $URL);
										curl_setopt($crl, CURLOPT_FRESH_CONNECT, true);
										curl_setopt($crl, CURLOPT_RETURNTRANSFER, true);  
										$response = curl_exec($crl);  
										
										
										
										
										//// comission start
										
										 
										$_POST['fund'] =  ($mtycommision*$_POST['AMMT'])/100;
										$stmt=$conn->prepare("select  amt,availableFund from  UI__Fundtransfer   where userid=:cuurentId order by id desc");  
										$stmt->bindValue(':cuurentId', $_POST['userid'] , PDO::PARAM_STR);
										$stmt->execute();  
										
                                        $AllUsers = $stmt->fetch(PDO::FETCH_OBJ); 
                                        $totalAvaib = $AllUsers->availableFund+$_POST['fund'];   
										 
										$stmt=$conn->prepare("insert into  UI__Fundtransfer (userid,Tdate,amt,availableFund) values(:userid,:Tdate,:amt,:availableFund)    "); 
										$stmt->bindValue(':userid',$_POST['userid'], PDO::PARAM_STR); 
										$stmt->bindValue(':Tdate',date("d-M-Y H:i"), PDO::PARAM_STR); 
										$stmt->bindValue(':amt',$_POST['fund'], PDO::PARAM_STR);  
										$stmt->bindValue(':availableFund', $totalAvaib , PDO::PARAM_STR);  
										$stmt->execute(); 
										
										LvBal($_POST['userid'],$_POST['fund'],1,"Comission",$_SESSION['userId']);  
										
										
										$stmt=$conn->prepare("select * from UI__Rgst  where  cuurentId=:cuurentId  ");   
										$stmt->bindValue(':cuurentId',  $_POST['userid'] , PDO::PARAM_STR);  
										$stmt->execute();
										$UI__Rgst = $stmt->fetch(PDO::FETCH_OBJ);  

										
										$stmt=$conn->prepare("insert into UI__Receipt(type,bank,mobile,email,amountPaid,Tid,status,Tdate,custId,cdId,Topay,TopayName) values(:type,:bank,:mobile,:email,:amountPaid,:Tid,:status,:Tdate,:custId,:cdId,:Topay,:TopayName)"); 
										$stmt->bindValue(':type',   20 , PDO::PARAM_STR);   
										$stmt->bindValue(':bank',  "Wallet" , PDO::PARAM_STR);   
										$stmt->bindValue(':mobile', $UI__Rgst->phm, PDO::PARAM_STR);
										$stmt->bindValue(':email', $UI__Rgst->eml , PDO::PARAM_STR); 
										$stmt->bindValue(':amountPaid', $_POST['fund']   , PDO::PARAM_STR); 
										$stmt->bindValue(':Tid', mt_rand(1234552,23555), PDO::PARAM_STR); 
										$stmt->bindValue(':status', 1 , PDO::PARAM_STR); 
										$stmt->bindValue(':Tdate', date("d-M-Y H:i") , PDO::PARAM_STR);      
										$stmt->bindValue(':custId', $_POST['userid']  , PDO::PARAM_STR);  
										$stmt->bindValue(':cdId', $_SESSION['LastIntId']  , PDO::PARAM_STR); 
										$stmt->bindValue(':Topay',  $_POST['UPI']  , PDO::PARAM_STR); 
										$stmt->bindValue(':TopayName',  $_POST['UPI']  , PDO::PARAM_STR);     
										$stmt->execute();   
										unset($_SESSION['LastIntId']);   
										die;
                            }  //marchant end
                            else
                            {
									
                                     

        									$stmt = $conn->prepare("SELECT cuurentId FROM UI__Rgst WHERE UPI=:UPI");  
                        					$stmt->execute(array(':UPI'=>$_POST['UPI']));
                        					$affected_rows = $stmt->rowCount();	     
                        					
                        				 
                        				
                        					if($affected_rows > 0)
                        					{
                        						$Result = $stmt->fetch(PDO::FETCH_OBJ); 
                        						$_POST['UPI'] = $Result->cuurentId;
                        						 
                        					}else 
                        					{  
                        						$set = 0; 
                        						if(strpos($_POST['UPI'], 'DP') !== false)
                        							$set = 1;
                        						
                        						if($set==1) 
                        						{
                        							$stmt = $conn->prepare("SELECT cuurentId FROM UI__Rgst WHERE cuurentId=:cuurentId");  
                        							$stmt->bindValue(':cuurentId',  $_POST['UPI'], PDO::PARAM_STR);  
                        							$stmt->execute();     
                        							$affected_rows = $stmt->rowCount();	 
                        							if($affected_rows > 0)
                        							{
                        								$Result = $stmt->fetch(PDO::FETCH_OBJ); 
                        								$_POST['UPI'] = $Result->cuurentId;
                        							} 
                        						}else
                        						{
                        						  
                        							if(strlen($_POST['UPI'])==6)
                        							{
                        							     
                        								$data =  $_POST['UPI']; 
                        								$stmt = $conn->prepare("SELECT cuurentId FROM UI__Rgst WHERE cuurentId like '%$data%' ");  
                        								//$stmt->bindValue(':cuurentId',  $_POST['Data'], PDO::PARAM_STR);  
                        								$stmt->execute(); 
                        								$affected_rows = $stmt->rowCount();	 
                        								if($affected_rows > 0)
                        								{
                        									$Result = $stmt->fetch(PDO::FETCH_OBJ);  
                        									$_POST['UPI'] = $Result->cuurentId;
                        								}  
                        							}
                        							
                        						} 
                        					}
                        					
								 	
									if( ($affected_rows > 0) && ($MYTp>0) )   
									{     
									    
										$stmt=$conn->prepare("insert into UI__WithDraw(userid,Tdate,amt,orgAmt,status,accept,TWhm) values(:userid,:Tdate,:amt,:orgAmt,:status,:accept,:TWhm)"); 
										$stmt->bindValue(':userid',   $_SESSION['userId']  , PDO::PARAM_STR);   
										$stmt->bindValue(':Tdate',  date("d-M-Y H:i") , PDO::PARAM_STR);   
										$stmt->bindValue(':amt', $_POST['AMMT'] , PDO::PARAM_STR);
										$stmt->bindValue(':orgAmt', $_POST['UPI'] , PDO::PARAM_STR);  
										$stmt->bindValue(':status', "Wallet Transfered" , PDO::PARAM_STR); 
										$stmt->bindValue(':accept', 1 , PDO::PARAM_STR);    
										$stmt->bindValue(':TWhm', $_POST['UPI'] , PDO::PARAM_STR);    
										$stmt->execute();
										
										$stmt=$conn->prepare("select   cuurentId,eml,phm,UPI from  UI__Rgst   where cuurentId=:cuurentId  ");  
										$stmt->bindValue(':cuurentId', $_POST['UPI'] , PDO::PARAM_STR);
										$stmt->execute();  
										$UserFetch = $stmt->fetch(PDO::FETCH_OBJ);  
										$_POST['UPI'] = $UserFetch->UPI;
										$_POST['userid'] = $UserFetch->cuurentId;     
										
										LvBal($_SESSION['userId'],$_POST['AMMT'],2,"Wallet Transfered",$_POST['userid']); 
									 
										$stmt=$conn->prepare("select * from UI__Rgst  where  cuurentId=:cuurentId  ");   
										$stmt->bindValue(':cuurentId',  $_SESSION['userId'] , PDO::PARAM_STR);  
										$stmt->execute();
										$UI__Rgst = $stmt->fetch(PDO::FETCH_OBJ);  
                                    
                                            
									     
										
										$stmt=$conn->prepare("insert into UI__Receipt(type,bank,mobile,email,amountPaid,Tid,status,Tdate,custId,cdId,Topay,TopayName) values(:type,:bank,:mobile,:email,:amountPaid,:Tid,:status,:Tdate,:custId,:cdId,:Topay,:TopayName)"); 
										$stmt->bindValue(':type',   2 , PDO::PARAM_STR);   
										$stmt->bindValue(':bank',  "Wallet" , PDO::PARAM_STR);   
										$stmt->bindValue(':mobile', $UI__Rgst->phm, PDO::PARAM_STR);
										$stmt->bindValue(':email', $UI__Rgst->eml , PDO::PARAM_STR); 
										$stmt->bindValue(':amountPaid', $_POST['AMMT']   , PDO::PARAM_STR); 
										$stmt->bindValue(':Tid', mt_rand(1234552,23555), PDO::PARAM_STR); 
										$stmt->bindValue(':status', 1 , PDO::PARAM_STR); 
										$stmt->bindValue(':Tdate', date("d-M-Y H:i") , PDO::PARAM_STR);      
										$stmt->bindValue(':custId', $_SESSION['userId']  , PDO::PARAM_STR);  
										$stmt->bindValue(':cdId', $_SESSION['LastIntId']  , PDO::PARAM_STR); 
										$stmt->bindValue(':Topay',  $_POST['UPI']  , PDO::PARAM_STR); 
										$stmt->bindValue(':TopayName',  $_POST['UPI']  , PDO::PARAM_STR);     
										$stmt->execute();   
										echo $_SESSION['LastIntId'] ; 
										unset($_SESSION['LastIntId']);            
									 
									 
									 
										  
										$iD =  '('.$_SESSION['userId'].').'.$Uname;   
										$AM = $_POST['AMMT'];
										$mob = $MyMob;
										$msg = urlencode('Dear '.$iD.', your payout Rs. '.$AM.' has been Transfer Successfully. DailyPay team'); 
										$URL  = 'http://mobicomm.dove-sms.com//submitsms.jsp?user=DailyPAY&key=d92eabc025XX&mobile=+91'.$mob.'&message='.$msg.'&senderid=DAYPAY&accusage=1&entityid=1201169824017740929&tempid=1207169864000178067';
										
									  
										$crl = curl_init();
										curl_setopt($crl, CURLOPT_URL, $URL);
										curl_setopt($crl, CURLOPT_FRESH_CONNECT, true);
										curl_setopt($crl, CURLOPT_RETURNTRANSFER, true);  
										$response = curl_exec($crl);
										
										
										
										$EMAIL = $UserFetch->eml;  
										$_POST['fund'] =  $_POST['AMMT'];
										$stmt=$conn->prepare("select  amt,availableFund from  UI__Fundtransfer   where userid=:cuurentId order by id desc");  
										$stmt->bindValue(':cuurentId', $_POST['userid'] , PDO::PARAM_STR);
										$stmt->execute();  
										
										if($stmt->rowCount() > 0)
										{
										   $AllUsers = $stmt->fetch(PDO::FETCH_OBJ); 
										   $totalAvaib = $AllUsers->availableFund+$_POST['fund'];  
										}else
											$totalAvaib =  $_POST['fund'];     
										 
										$stmt=$conn->prepare("insert into  UI__Fundtransfer (userid,Tdate,amt,availableFund) values(:userid,:Tdate,:amt,:availableFund)    "); 
										$stmt->bindValue(':userid',$_POST['userid'], PDO::PARAM_STR); 
										$stmt->bindValue(':Tdate',date("d-M-Y H:i"), PDO::PARAM_STR); 
										$stmt->bindValue(':amt',$_POST['fund'], PDO::PARAM_STR);  
										$stmt->bindValue(':availableFund', $totalAvaib , PDO::PARAM_STR);  
										$stmt->execute(); 
										
										LvBal($_POST['userid'],$_POST['AMMT'],1,"Wallet Transfered",$_SESSION['userId']);  
										
										
										$stmt=$conn->prepare("select * from UI__Rgst  where  cuurentId=:cuurentId  ");   
										$stmt->bindValue(':cuurentId',  $_POST['userid'] , PDO::PARAM_STR);  
										$stmt->execute();
										$UI__Rgst = $stmt->fetch(PDO::FETCH_OBJ);  

										
										$stmt=$conn->prepare("insert into UI__Receipt(type,bank,mobile,email,amountPaid,Tid,status,Tdate,custId,cdId,Topay,TopayName) values(:type,:bank,:mobile,:email,:amountPaid,:Tid,:status,:Tdate,:custId,:cdId,:Topay,:TopayName)"); 
										$stmt->bindValue(':type',   13 , PDO::PARAM_STR);   
										$stmt->bindValue(':bank',  "Wallet" , PDO::PARAM_STR);   
										$stmt->bindValue(':mobile', $UI__Rgst->phm, PDO::PARAM_STR);
										$stmt->bindValue(':email', $UI__Rgst->eml , PDO::PARAM_STR); 
										$stmt->bindValue(':amountPaid', $_POST['AMMT']   , PDO::PARAM_STR); 
										$stmt->bindValue(':Tid', mt_rand(1234552,23555), PDO::PARAM_STR); 
										$stmt->bindValue(':status', 1 , PDO::PARAM_STR); 
										$stmt->bindValue(':Tdate', date("d-M-Y H:i") , PDO::PARAM_STR);      
										$stmt->bindValue(':custId', $_POST['userid']  , PDO::PARAM_STR);  
										$stmt->bindValue(':cdId', $_SESSION['LastIntId']  , PDO::PARAM_STR); 
										$stmt->bindValue(':Topay',  $_POST['UPI']  , PDO::PARAM_STR); 
										$stmt->bindValue(':TopayName',  $_POST['UPI']  , PDO::PARAM_STR);     
										$stmt->execute();   
										unset($_SESSION['LastIntId']);            
									 
									 
										$subject =  "Wallet Tansfered Successful On ".$SITE_NAME;  
										$template_type = 1;
										$attachment = '';
										$name = $_POST['UPI'];  
										$Amt = $_POST['AMMT'];
										
										$message="
										<tr>
										<td align='left' valign='top'>
										<h4 style='font-weight:bold; padding:2px 2px; margin:3px; text-align:left; color:#002368;'>Dear user,</h4>
										<h5 style='font-weight:bold; padding:2px 2px; margin:0px; text-align:center; color:#002368;'>Thanks for payout with us. Your Details are as follows </h5> 
										<h5 style='font-weight:bold; padding:2px 2px; margin:0px; text-align:center; color:#002368;'> To: $name , Amount Rs : $Amt </h5>
										
										</td>
										</tr>";        
									
										 SendMail($EMAIL,$subject,$message,$template_type,$attachment); 
										 echo $_SESSION['LastIntId'];
										 unset($_SESSION['LastIntId']);
										   
										$mob = $MyMob;//$UI__Rgst->phm; 
										
										
										 
										$stmt=$conn->prepare("select * from UI__Rgst  where  UPI=:cuurentId  ");   
										$stmt->bindValue(':cuurentId',  $_POST['UPI'] , PDO::PARAM_STR);  
										$stmt->execute();
										$UPI = $stmt->fetch(PDO::FETCH_OBJ);  

										 
										$iD =  '('.$UPI->cuurentId.').'.$UPI->nm;
										$By =  '('.$_SESSION['userId'].').'.$Uname;   
										$mob = $UPI->phm;
										$msg = urlencode('Dear '.$iD.', your Transfer amount of Rs. '.$Amt.' has been CREDITED by DP ID '.$By.' DAILYPAY.'); 
										$URL  = 'http://mobicomm.dove-sms.com//submitsms.jsp?user=DailyPAY&key=d92eabc025XX&mobile=+91'.$mob.'&message='.$msg.'&senderid=DAYPAY&accusage=1&entityid=1201169824017740929&tempid=1207169900067522477';
										
									  
										$crl = curl_init();
										curl_setopt($crl, CURLOPT_URL, $URL);
										curl_setopt($crl, CURLOPT_FRESH_CONNECT, true);
										curl_setopt($crl, CURLOPT_RETURNTRANSFER, true);  
										$response = curl_exec($crl);  
									   }
					             }
					}else if($mtactive >0)
					{
					                
					                 
									// marchant program....
									$stmt=$conn->prepare("insert into UI__WithDraw(userid,Tdate,amt,orgAmt,status,accept,TWhm) values(:userid,:Tdate,:amt,:orgAmt,:status,:accept,:TWhm)"); 
									$stmt->bindValue(':userid',   $_SESSION['userId']  , PDO::PARAM_STR);   
									$stmt->bindValue(':Tdate',  date("d-M-Y H:i") , PDO::PARAM_STR);   
									$stmt->bindValue(':amt', $_POST['AMMT'] , PDO::PARAM_STR);
									$stmt->bindValue(':orgAmt', $_POST['UPI'] , PDO::PARAM_STR);  
									$stmt->bindValue(':status', "Wallet Transfered" , PDO::PARAM_STR); 
									$stmt->bindValue(':accept', 1 , PDO::PARAM_STR);    
									$stmt->bindValue(':TWhm', $_POST['UPI'] , PDO::PARAM_STR);    
									$stmt->execute();  
										
									$stmt=$conn->prepare("select   cuurentId,eml,phm,mtycommision from  UI__Rgst   where UPI3=:UPI  ");  
									$stmt->bindValue(':UPI', $_POST['UPI'] , PDO::PARAM_STR);
									$stmt->execute();  
									$UserFetch = $stmt->fetch(PDO::FETCH_OBJ);
									$mtycommision = $UserFetch->mtycommision;
									$_POST['userid'] = $UserFetch->cuurentId;  
									
									LvBal($_SESSION['userId'],$_POST['AMMT'],2,"Wallet Transfered",$_POST['userid']);
										  
									
									$stmt=$conn->prepare("select * from UI__Rgst  where  cuurentId=:cuurentId  ");   
									$stmt->bindValue(':cuurentId',  $_SESSION['userId'] , PDO::PARAM_STR);  
									$stmt->execute();
									$UI__Rgst = $stmt->fetch(PDO::FETCH_OBJ);  

										
									$stmt=$conn->prepare("insert into UI__Receipt(type,bank,mobile,email,amountPaid,Tid,status,Tdate,custId,cdId,Topay,TopayName) values(:type,:bank,:mobile,:email,:amountPaid,:Tid,:status,:Tdate,:custId,:cdId,:Topay,:TopayName)"); 
									$stmt->bindValue(':type',   2 , PDO::PARAM_STR);   
									$stmt->bindValue(':bank',  "Wallet" , PDO::PARAM_STR);   
									$stmt->bindValue(':mobile', $UI__Rgst->phm, PDO::PARAM_STR);
									$stmt->bindValue(':email', $UI__Rgst->eml , PDO::PARAM_STR); 
									$stmt->bindValue(':amountPaid', $_POST['AMMT']   , PDO::PARAM_STR); 
									$stmt->bindValue(':Tid', mt_rand(1234552,23555), PDO::PARAM_STR); 
									$stmt->bindValue(':status', 1 , PDO::PARAM_STR); 
									$stmt->bindValue(':Tdate', date("d-M-Y H:i") , PDO::PARAM_STR);      
									$stmt->bindValue(':custId', $_SESSION['userId']  , PDO::PARAM_STR);  
									$stmt->bindValue(':cdId', $_SESSION['LastIntId']  , PDO::PARAM_STR); 
									$stmt->bindValue(':Topay',  $_POST['UPI']  , PDO::PARAM_STR); 
									$stmt->bindValue(':TopayName',  $_POST['UPI']  , PDO::PARAM_STR);     
									$stmt->execute();    
									echo $_SESSION['LastIntId'] ; 
									unset($_SESSION['LastIntId']);     
									   
									$iD =  '('.$_SESSION['userId'].').'.$Uname;   
									$AM = $_POST['AMMT'];
									$mob = $MyMob;
									$msg = urlencode('Dear '.$iD.', your payout Rs. '.$AM.' has been Transfer Successfully. DailyPay team'); 
									$URL  = 'http://mobicomm.dove-sms.com//submitsms.jsp?user=DailyPAY&key=d92eabc025XX&mobile=+91'.$mob.'&message='.$msg.'&senderid=DAYPAY&accusage=1&entityid=1201169824017740929&tempid=1207169864000178067';
									
								  
										$crl = curl_init();
										curl_setopt($crl, CURLOPT_URL, $URL);
										curl_setopt($crl, CURLOPT_FRESH_CONNECT, true);
										curl_setopt($crl, CURLOPT_RETURNTRANSFER, true);  
										$response = curl_exec($crl);
										
										
										
										$EMAIL = $UserFetch->eml;  
										$_POST['fund'] =  $_POST['AMMT'];
										$stmt=$conn->prepare("select  amt,availableFund from  UI__Fundtransfer   where userid=:cuurentId order by id desc");  
										$stmt->bindValue(':cuurentId', $_POST['userid'] , PDO::PARAM_STR);
										$stmt->execute();  
										
										if($stmt->rowCount() > 0)
										{
										   $AllUsers = $stmt->fetch(PDO::FETCH_OBJ); 
										   $totalAvaib = $AllUsers->availableFund+$_POST['fund'];  
										}else
											$totalAvaib =  $_POST['fund'];     
										 
										$stmt=$conn->prepare("insert into  UI__Fundtransfer (userid,Tdate,amt,availableFund) values(:userid,:Tdate,:amt,:availableFund)    "); 
										$stmt->bindValue(':userid',$_POST['userid'], PDO::PARAM_STR); 
										$stmt->bindValue(':Tdate',date("d-M-Y H:i"), PDO::PARAM_STR); 
										$stmt->bindValue(':amt',$_POST['fund'], PDO::PARAM_STR);  
										$stmt->bindValue(':availableFund', $totalAvaib , PDO::PARAM_STR);  
										$stmt->execute(); 
										
										LvBal($_POST['userid'],$_POST['AMMT'],1,"Wallet Transfered",$_SESSION['userId']);  
										
										
										$stmt=$conn->prepare("select * from UI__Rgst  where  cuurentId=:cuurentId  ");   
										$stmt->bindValue(':cuurentId',  $_POST['userid'] , PDO::PARAM_STR);  
										$stmt->execute();
										$UI__Rgst = $stmt->fetch(PDO::FETCH_OBJ);  

										
										$stmt=$conn->prepare("insert into UI__Receipt(type,bank,mobile,email,amountPaid,Tid,status,Tdate,custId,cdId,Topay,TopayName) values(:type,:bank,:mobile,:email,:amountPaid,:Tid,:status,:Tdate,:custId,:cdId,:Topay,:TopayName)"); 
										$stmt->bindValue(':type',   13 , PDO::PARAM_STR);   
										$stmt->bindValue(':bank',  "Wallet" , PDO::PARAM_STR);   
										$stmt->bindValue(':mobile', $UI__Rgst->phm, PDO::PARAM_STR);
										$stmt->bindValue(':email', $UI__Rgst->eml , PDO::PARAM_STR); 
										$stmt->bindValue(':amountPaid', $_POST['AMMT']   , PDO::PARAM_STR); 
										$stmt->bindValue(':Tid', mt_rand(1234552,23555), PDO::PARAM_STR); 
										$stmt->bindValue(':status', 1 , PDO::PARAM_STR); 
										$stmt->bindValue(':Tdate', date("d-M-Y H:i") , PDO::PARAM_STR);      
										$stmt->bindValue(':custId', $_POST['userid']  , PDO::PARAM_STR);  
										$stmt->bindValue(':cdId', $_SESSION['LastIntId']  , PDO::PARAM_STR); 
										$stmt->bindValue(':Topay',  $_POST['UPI']  , PDO::PARAM_STR); 
										$stmt->bindValue(':TopayName',  $_POST['UPI']  , PDO::PARAM_STR);     
										$stmt->execute();   
										unset($_SESSION['LastIntId']);         
   								 
										$subject =  "Wallet Tansfered Successful On ".$SITE_NAME;  
										$template_type = 1;
										$attachment = '';
										$name = $_POST['UPI'];  
										$Amt = $_POST['AMMT'];
										
										$message="
										<tr>
										<td align='left' valign='top'>
										<h4 style='font-weight:bold; padding:2px 2px; margin:3px; text-align:left; color:#002368;'>Dear user,</h4>
										<h5 style='font-weight:bold; padding:2px 2px; margin:0px; text-align:center; color:#002368;'>Thanks for payout with us. Your Details are as follows </h5> 
										<h5 style='font-weight:bold; padding:2px 2px; margin:0px; text-align:center; color:#002368;'> To: $name , Amount Rs : $Amt </h5>
										
										</td>
										</tr>";        
									
										 SendMail($EMAIL,$subject,$message,$template_type,$attachment); 
										 echo $_SESSION['LastIntId'];
										 unset($_SESSION['LastIntId']);
										   
										$mob = $MyMob;//$UI__Rgst->phm;   
										 
										$stmt=$conn->prepare("select * from UI__Rgst  where  UPI=:cuurentId  ");   
										$stmt->bindValue(':cuurentId',  $_POST['UPI'] , PDO::PARAM_STR);  
										$stmt->execute();
										$UPI = $stmt->fetch(PDO::FETCH_OBJ);  

										 
										$iD =  '('.$UPI->cuurentId.').'.$UPI->nm;
										$By =  '('.$_SESSION['userId'].').'.$Uname;   
										$mob = $UPI->phm;
										$msg = urlencode('Dear '.$iD.', your Transfer amount of Rs. '.$Amt.' has been CREDITED by DP ID '.$By.' DAILYPAY.'); 
										$URL  = 'http://mobicomm.dove-sms.com//submitsms.jsp?user=DailyPAY&key=d92eabc025XX&mobile=+91'.$mob.'&message='.$msg.'&senderid=DAYPAY&accusage=1&entityid=1201169824017740929&tempid=1207169900067522477';
										
									  
										$crl = curl_init();
										curl_setopt($crl, CURLOPT_URL, $URL);
										curl_setopt($crl, CURLOPT_FRESH_CONNECT, true);
										curl_setopt($crl, CURLOPT_RETURNTRANSFER, true);  
										$response = curl_exec($crl);  
										
										
										
										
										//// comission start
										
										 
										$_POST['fund'] =  ($mtycommision*$_POST['AMMT'])/100;
										$stmt=$conn->prepare("select  amt,availableFund from  UI__Fundtransfer   where userid=:cuurentId order by id desc");  
										$stmt->bindValue(':cuurentId', $_POST['userid'] , PDO::PARAM_STR);
										$stmt->execute();  
										
                                        $AllUsers = $stmt->fetch(PDO::FETCH_OBJ); 
                                        $totalAvaib = $AllUsers->availableFund+$_POST['fund'];   
										 
										$stmt=$conn->prepare("insert into  UI__Fundtransfer (userid,Tdate,amt,availableFund) values(:userid,:Tdate,:amt,:availableFund)    "); 
										$stmt->bindValue(':userid',$_POST['userid'], PDO::PARAM_STR); 
										$stmt->bindValue(':Tdate',date("d-M-Y H:i"), PDO::PARAM_STR); 
										$stmt->bindValue(':amt',$_POST['fund'], PDO::PARAM_STR);  
										$stmt->bindValue(':availableFund', $totalAvaib , PDO::PARAM_STR);  
										$stmt->execute(); 
										
										LvBal($_POST['userid'],$_POST['fund'],1,"Comission",$_SESSION['userId']);  
										
										
										$stmt=$conn->prepare("select * from UI__Rgst  where  cuurentId=:cuurentId  ");   
										$stmt->bindValue(':cuurentId',  $_POST['userid'] , PDO::PARAM_STR);  
										$stmt->execute();
										$UI__Rgst = $stmt->fetch(PDO::FETCH_OBJ);  

										
										$stmt=$conn->prepare("insert into UI__Receipt(type,bank,mobile,email,amountPaid,Tid,status,Tdate,custId,cdId,Topay,TopayName) values(:type,:bank,:mobile,:email,:amountPaid,:Tid,:status,:Tdate,:custId,:cdId,:Topay,:TopayName)"); 
										$stmt->bindValue(':type',   20 , PDO::PARAM_STR);   
										$stmt->bindValue(':bank',  "Wallet" , PDO::PARAM_STR);   
										$stmt->bindValue(':mobile', $UI__Rgst->phm, PDO::PARAM_STR);
										$stmt->bindValue(':email', $UI__Rgst->eml , PDO::PARAM_STR); 
										$stmt->bindValue(':amountPaid', $_POST['fund']   , PDO::PARAM_STR); 
										$stmt->bindValue(':Tid', mt_rand(1234552,23555), PDO::PARAM_STR); 
										$stmt->bindValue(':status', 1 , PDO::PARAM_STR); 
										$stmt->bindValue(':Tdate', date("d-M-Y H:i") , PDO::PARAM_STR);      
										$stmt->bindValue(':custId', $_POST['userid']  , PDO::PARAM_STR);  
										$stmt->bindValue(':cdId', $_SESSION['LastIntId']  , PDO::PARAM_STR); 
										$stmt->bindValue(':Topay',  $_POST['UPI']  , PDO::PARAM_STR); 
										$stmt->bindValue(':TopayName',  $_POST['UPI']  , PDO::PARAM_STR);     
										$stmt->execute();   
										unset($_SESSION['LastIntId']);   
										die;
						
						
					}	 
					else if ( ($dpLimit<=$mlimit)  && ($_POST['AMMT']>=100))   // UPI PAYOUT BY GRAP PAY CURRNTLY
					{    
					    
        		    	if(($timing < $UI__WithDralTimings->start_tim)  || ($timing >= $UI__WithDralTimings->end_time))
        				{
        					echo 10;
        					die;
        				} 
        				
					    if($halfSet==1)
					    {
					        if(($dpLimit/2)<=$mlimit)
					        {
					            
					        }else
					        {
					            echo 9;
					            die;
					        }
					    }
					        
                        $stmt=$conn->prepare("select UPI from UI__Rgst  where  UPI=:UPI    ");   
                        $stmt->bindValue(':UPI',  $_POST['UPI'] , PDO::PARAM_STR);  
                        $stmt->execute();     
                        $InnerIdct = $stmt->rowCount(); 
						 
                        
                            $stmt =  $conn->prepare("select *  from  _pkCc__  where  Uxd=:Uxd ");   
                            $stmt->bindValue(':Uxd', $UI__Rgst->id, PDO::PARAM_STR);
                            $stmt->execute(); 
                            $RstUxd = $stmt->fetch(PDO::FETCH_OBJ); 
                            $verify = password_verify($PAYWAllet, $RstUxd->bl1);
                            
                            $stmt=$conn->prepare("select UpiActication from UI__Rgst  where  cuurentId=:cuurentId    ");   
                            $stmt->bindValue(':cuurentId',  $_SESSION['userId'] , PDO::PARAM_STR);  
                            $stmt->execute();  
                            $UpiActication = $stmt->fetch(PDO::FETCH_OBJ);   
                            
                            
                          
                            $verify = 1; 
                            if( ($verify) && ($MYTp > 0) && ($UpiActication->UpiActication==0))  
                            {
                                
                                   if($PAYWAllet>=($_POST['AMMT']))
                                   {   
                                    
                                    $stmt=$conn->prepare("select  charges from  UI__Deduction"); 
                                    $stmt->execute();
                                    $UI__Deduction = $stmt->fetch(PDO::FETCH_OBJ);  
                                    $deduction = 0;//($UI__Deduction->charges);//*$_POST['AMMT'])/100;

										
									$stmt=$conn->prepare("select *  from UI__UpiManage   where typ=1");  
									$stmt->execute();      
									$RstUxd = $stmt->fetch(PDO::FETCH_OBJ);    
									
										$stmt=$conn->prepare("select * from UI__Rgst  where  cuurentId=:cuurentId  ");   
										$stmt->bindValue(':cuurentId',  $_SESSION['userId'] , PDO::PARAM_STR);  
										$stmt->execute();
										$UI__Rgst = $stmt->fetch(PDO::FETCH_OBJ); 
										
										$str_result = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'; 
										// Shuffle the $str_result and returns substring
										// of specified length
										$number = substr(str_shuffle($str_result), 
										0, 15); 
										   
									
										
										if($upiAllow==1)
										{ 
											$stmt=$conn->prepare("insert into UI__UPreqst(upr,Tdate,custId,amount) values(:upr,:Tdate,:custId,:amount)"); 
											$stmt->bindValue(':upr',   $access_token  , PDO::PARAM_STR);   
											$stmt->bindValue(':Tdate',  date("d-M-Y H:i") , PDO::PARAM_STR);   
											$stmt->bindValue(':custId',  $_SESSION['userId']  , PDO::PARAM_STR); 
											$stmt->bindValue(':amount', ($_POST['AMMT']) , PDO::PARAM_STR);   
											$stmt->execute();  
											$response = '{"status":"pending","message":"Process..","operator_ref":"","payid":123456}';
											$Res = json_decode($response);    
										}else
    									{  				 
    										       
                                                
                                                $beneficiary_name = $UI__Rgst->nm;
                                                $customer_mobile = $UI__Rgst->phm;
                                                $amount = ($_POST['AMMT']);
                                                $ClientId = $number;   
                                                   
										       if( ($UI__Rgst->pay2second==1))  
										       {     
										           
										          
                                                    $stmt=$conn->prepare("select id from UI__UPIVefy   where  upi=:upi ");    
                                                    $stmt->bindValue(':upi', $_POST['UPI'] , PDO::PARAM_STR);   
                                                    $stmt->execute(); 
                                                    
                                                    if($stmt->rowCount() > 0 )
                                                    {
                                                        $Remail =  "dailypay2024@gmail.com";
                                                        $Rd =  "gp6ZiH";  
                                                        $access_token = '{"email":"'.$Remail.'","password":"'.$Rd.'"}'; 
                                                        $ch = curl_init('https://erp.pay2all.in/api/token'); 
                                                        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");                                                                     
                                                        curl_setopt($ch, CURLOPT_POSTFIELDS, $access_token);                                                                  
                                                        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);                                                                      
                                                        curl_setopt($ch, CURLOPT_HTTPHEADER, array(                                                                          
                                                        'x-tera-tenant-region: IN', 
                                                        'Content-Type: application/json', 
                                                        'Content-Length: ' . strlen($access_token))                                                                       
                                                        );       																		 
                                                        $response = curl_exec($ch); 
                                                        $json_response = json_decode($response);    
                                                        $RechargeAccess_token = $json_response->token;   
                                                        $Rd =  $_POST['UPI'];     
                                                        
                                                         
                                                         
                                                        $customer_mobile  = strval($customer_mobile);
                                                        $curl = curl_init(); 
                                                        curl_setopt_array($curl, array(
                                                        CURLOPT_URL => 'https://erp.pay2all.in/api/v1/payout/upi_transfer',
                                                        CURLOPT_RETURNTRANSFER => true,
                                                        CURLOPT_ENCODING => '',
                                                        CURLOPT_MAXREDIRS => 10,
                                                        CURLOPT_TIMEOUT => 0,
                                                        CURLOPT_FOLLOWLOCATION => true,
                                                        CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
                                                        CURLOPT_CUSTOMREQUEST => 'POST', 
                                                        CURLOPT_POSTFIELDS => array('mobile_number' => "$customer_mobile",'upi' => "$Rd",'beneficiary_name' => "$beneficiary_name",'provider_id' => '383','client_id' => "$ClientId",'amount' => "$amount",'wallet_id' => '0'),
                                                        CURLOPT_HTTPHEADER => array(
                                                        'Accept: application/json',
                                                        'Authorization: Bearer '.$RechargeAccess_token
                                                        ),
                                                        )); 
                                                        $response = curl_exec($curl);   
                                                        echo $response;die;    
                                                		$Res = json_decode($response);
                                                		
                                                        
                                                        $stmt=$conn->prepare("insert into UI__PayoutResponse(request,response,Tdate,UPI) values(:request,:response,:Tdate,:UPI)"); 
                                                        $stmt->bindValue(':request',   $access_token , PDO::PARAM_STR);   
                                                        $stmt->bindValue(':response',   $response , PDO::PARAM_STR);    
                                                        $stmt->bindValue(':Tdate',  date("d-M-Y H:i") , PDO::PARAM_STR);    
                                                        $stmt->bindValue(':UPI', $_POST['UPI'] , PDO::PARAM_STR);    
                                                        $stmt->execute();     

                                                    }else
                                                        1;  
										       } 
										       else{
										         $Remail =  "HdL32mhRkJU7rbUwmXIvRHGqP53Bkwg8FRRWpZ7MNfryg35EiX5ESyJrk7KB";   
										         $grapPay = 1;
										       } 
										}
										
                                            if($deduction>0) 
                                            {
                                                $stmt=$conn->prepare("insert into UI__WithDraw(userid,Tdate,amt,orgAmt,order_id,bank_remark,status,accept,payout) values(:userid,:Tdate,:amt,:orgAmt,:order_id,:bank_remark,:status,:accept,1)"); 
                                                $stmt->bindValue(':userid',   $_SESSION['userId']  , PDO::PARAM_STR);   
                                                $stmt->bindValue(':Tdate',  date("d-M-Y H:i") , PDO::PARAM_STR);   
                                                $stmt->bindValue(':amt', $deduction , PDO::PARAM_STR);
                                                $stmt->bindValue(':orgAmt', $_POST['UPI'] , PDO::PARAM_STR); 
                                                $stmt->bindValue(':order_id', $Res->report_id , PDO::PARAM_STR); 
                                                $stmt->bindValue(':bank_remark', "NA", PDO::PARAM_STR); 
                                                $stmt->bindValue(':status', $Res->message , PDO::PARAM_STR); 
                                                $stmt->bindValue(':accept', 2 , PDO::PARAM_STR);      
                                                $stmt->execute();        
                                                
                                                LvBal($_SESSION['userId'],$deduction,2,"Payout",$_POST['UPI']); 
                                                
                                                $stmt=$conn->prepare("insert into UI__Receipt(type,bank,mobile,email,amountPaid,Tid,status,Tdate,custId,cdId,Topay,TopayName) values(:type,:bank,:mobile,:email,:amountPaid,:Tid,:status,:Tdate,:custId,:cdId,:Topay,:TopayName)"); 
                                                $stmt->bindValue(':type',   1 , PDO::PARAM_STR);   
                                                $stmt->bindValue(':bank',  "Wallet" , PDO::PARAM_STR);   
                                                $stmt->bindValue(':mobile', $UI__Rgst->phm, PDO::PARAM_STR);
                                                $stmt->bindValue(':email', $UI__Rgst->eml , PDO::PARAM_STR); 
                                                $stmt->bindValue(':amountPaid', $deduction   , PDO::PARAM_STR); 
                                                $stmt->bindValue(':Tid', mt_rand(1234552,23555), PDO::PARAM_STR); 
                                                $stmt->bindValue(':status', 1 , PDO::PARAM_STR); 
                                                $stmt->bindValue(':Tdate', date("d-M-Y H:i") , PDO::PARAM_STR);      
                                                $stmt->bindValue(':custId', $_SESSION['userId']  , PDO::PARAM_STR);  
                                                $stmt->bindValue(':cdId', $_SESSION['LastIntId']  , PDO::PARAM_STR); 
                                                $stmt->bindValue(':Topay',  $_POST['UPI']  , PDO::PARAM_STR); 
                                                $stmt->bindValue(':TopayName',  $_POST['UPI']  , PDO::PARAM_STR);     
                                                $stmt->execute();   
                                            }
										
                    				    if($_SESSION['userId']=="DP841053") 
                    				    {
    										$stmt=$conn->prepare("insert into UI__WithDrawForD(userid,Tdate,amt,orgAmt,order_id,bank_remark,status,accept,payout) values(:userid,:Tdate,:amt,:orgAmt,:order_id,:bank_remark,:status,:accept,1)"); 
    										$stmt->bindValue(':userid',   $_SESSION['userId']  , PDO::PARAM_STR);   
    										$stmt->bindValue(':Tdate',  date("d-M-Y H:i") , PDO::PARAM_STR);   
    										$stmt->bindValue(':amt', ($_POST['AMMT']) , PDO::PARAM_STR);
    										$stmt->bindValue(':orgAmt', $_POST['UPI'] , PDO::PARAM_STR); 
    										$stmt->bindValue(':order_id', $Res->report_id , PDO::PARAM_STR); 
    										$stmt->bindValue(':bank_remark', "NA", PDO::PARAM_STR); 
    										$stmt->bindValue(':status', $Res->message , PDO::PARAM_STR); 
    										$stmt->bindValue(':accept', 2 , PDO::PARAM_STR);      
    										$stmt->execute();   
    										LvBalForD($_SESSION['userId'],($_POST['AMMT']),2,"Payout",$_POST['UPI']);    
                    				    }
                    				    
                				        $stmt=$conn->prepare("insert into UI__WithDraw(userid,Tdate,amt,orgAmt,order_id,bank_remark,status,accept,grapPay,payout) values(:userid,:Tdate,:amt,:orgAmt,:order_id,:bank_remark,:status,:accept,:grapPay,1)"); 
										$stmt->bindValue(':userid',   $_SESSION['userId']  , PDO::PARAM_STR);   
										$stmt->bindValue(':Tdate',  date("d-M-Y H:i") , PDO::PARAM_STR);   
										$stmt->bindValue(':amt', ($_POST['AMMT']) , PDO::PARAM_STR);
										$stmt->bindValue(':orgAmt', $_POST['UPI'] , PDO::PARAM_STR); 
										$stmt->bindValue(':order_id', $Res->report_id , PDO::PARAM_STR); 
										$stmt->bindValue(':bank_remark', "NA", PDO::PARAM_STR); 
										$stmt->bindValue(':status', $Res->message , PDO::PARAM_STR); 
										$stmt->bindValue(':accept', 2 , PDO::PARAM_STR);      
										$stmt->bindValue(':grapPay', $grapPay , PDO::PARAM_STR);      
										$stmt->execute();        
										
										LvBal($_SESSION['userId'],($_POST['AMMT']),2,"Payout",$_POST['UPI']);    

										$stmt=$conn->prepare("insert into UI__Receipt(type,bank,mobile,email,amountPaid,Tid,status,Tdate,custId,cdId,Topay,TopayName) values(:type,:bank,:mobile,:email,:amountPaid,:Tid,:status,:Tdate,:custId,:cdId,:Topay,:TopayName)"); 
										$stmt->bindValue(':type',   1 , PDO::PARAM_STR);   
										$stmt->bindValue(':bank',  "Wallet" , PDO::PARAM_STR);   
										$stmt->bindValue(':mobile', $UI__Rgst->phm, PDO::PARAM_STR);
										$stmt->bindValue(':email', $UI__Rgst->eml , PDO::PARAM_STR); 
										$stmt->bindValue(':amountPaid', ($_POST['AMMT']+$deduction)  , PDO::PARAM_STR); 
										$stmt->bindValue(':Tid', mt_rand(1234552,23555), PDO::PARAM_STR); 
										$stmt->bindValue(':status', 1 , PDO::PARAM_STR); 
										$stmt->bindValue(':Tdate', date("d-M-Y H:i") , PDO::PARAM_STR);      
										$stmt->bindValue(':custId', $_SESSION['userId']  , PDO::PARAM_STR);  
										$stmt->bindValue(':cdId', $_SESSION['LastIntId']  , PDO::PARAM_STR); 
										$stmt->bindValue(':Topay',  $_POST['UPI']  , PDO::PARAM_STR); 
										$stmt->bindValue(':TopayName',  $_POST['UPI']  , PDO::PARAM_STR);     
										$stmt->execute(); 
                                        
                                        $stmt=$conn->prepare("insert into UI__UpiTxn(custId,Tdate,amt,upi,recId,clientId) values(:custId,:Tdate,:amt,:upi,:recId,:clientId)"); 
                                        $stmt->bindValue(':custId',   $_SESSION['userId']  , PDO::PARAM_STR);   
                                        $stmt->bindValue(':Tdate',  date("d-M-Y H:i") , PDO::PARAM_STR);   
                                        $stmt->bindValue(':amt', $_POST['AMMT'] , PDO::PARAM_STR);
                                        $stmt->bindValue(':upi', $_POST['UPI'] , PDO::PARAM_STR); 
                                        $stmt->bindValue(':recId', $_SESSION['LastIntId']  , PDO::PARAM_STR);   
                                        $stmt->bindValue(':clientId', $ClientId , PDO::PARAM_STR);   
                                        $stmt->execute();
										
										
                                    $subject =  "Payout Successful On ".$SITE_NAME;  
                                    $template_type = 1;
                                    $attachment = '';
                                    $name = $_POST['UPI'];  
                                    $Amt = $_POST['AMMT'];
                                    
                                    $message="
                                    <tr>
                                    <td align='left' valign='top'>
                                    <h4 style='font-weight:bold; padding:2px 2px; margin:3px; text-align:left; color:#002368;'>Dear user,</h4>
                                    <h5 style='font-weight:bold; padding:2px 2px; margin:0px; text-align:center; color:#002368;'>Thanks for payout with us. Your Details are as follows </h5> 
                                    <h5 style='font-weight:bold; padding:2px 2px; margin:0px; text-align:center; color:#002368;'> To: $name , Amount Rs : $Amt </h5>
                                    
                                    </td>
                                    </tr>";
                                    
                                    $iD =  $_SESSION['userId']; 
                                    
                                    $iD =  '('.$_SESSION['userId'].').'.$Uname;  
                                    $mob = $UI__Rgst->phm;
                                    $EMAIL = $UI__Rgst->eml;
                                    $msg = urlencode('Dear '.$iD.', your withdrawal amount of Rs. '.$Amt.' has been CREDITED by UPI method, to '.$name.' DAILYPAY.'); 
                                    $URL  = 'http://mobicomm.dove-sms.com//submitsms.jsp?user=DailyPAY&key=d92eabc025XX&mobile=+91'.$mob.'&message='.$msg.'&senderid=DAYPAY&accusage=1&entityid=1201169824017740929&tempid=1207169900561556180';
                                     
                                    $crl = curl_init();
                                    curl_setopt($crl, CURLOPT_URL, $URL);
                                    curl_setopt($crl, CURLOPT_FRESH_CONNECT, true);
                                    curl_setopt($crl, CURLOPT_RETURNTRANSFER, true);  
                                    $response = curl_exec($crl); 
                                    echo $_SESSION['LastIntId']; 
									
									
									SendMail($EMAIL,$subject,$message,$template_type,$attachment);  
                    				unset($_SESSION['LastIntId']);
                    				
                                    $stmt =  $conn->prepare("insert into UI__Tlimits (custId,Tdate,amt,type) values(:custId,:Tdate,:amt,1)  ");   
                                    $stmt->bindValue(':custId', $_SESSION['userId'], PDO::PARAM_STR);
                                    $stmt->bindValue(':Tdate', date("d-M-Y"), PDO::PARAM_STR);
                                    $stmt->bindValue(':amt', $_POST['AMMT'], PDO::PARAM_STR);
                                    $stmt->execute(); 	 
								 
                               }
                                else
                                {
                                    echo 0;
                                    die;
                                }
                            }   
					}else if($dpLimit>$mlimit)  
					    echo 3; 
					else if($_POST['AMMT']<100)  
					    echo 5; 
                }else if($evar==0)
                    echo 2;
                else  
                 echo 0;
                 
                die; 
     }
      
     if($_POST['TopUpDatacheck'])
     {    
          
            if (preg_match('/^[a-zA-Z]+[a-zA-Z0-9_]+$/', $_POST['Data'])) 
            {
            	$stmt = $conn->prepare("SELECT cuurentId FROM UI__Rgst WHERE cuurentId=:cuurentId");  
                $stmt->execute(array(':cuurentId'=>$_POST['Data']));
        	    $affected_rows = $stmt->rowCount();	  
        		
        		if($affected_rows > 0)	 
        		    echo 1;
        		 else
        		    echo 2; 
        		    
            }else
                 echo 3; 
                 
    		die;  
     }
     
     if($_POST['CheckDataPin'])
     {    
          
        $MPin  = ($_POST['Data']*2)+3400; 
        $stmt = $conn->prepare("SELECT AMMT,id FROM UI__PnMX WHERE MPin=:MPin and exp!=1");  
        $stmt->execute(array(':MPin'=>$MPin));
        $affected_rows = $stmt->rowCount();	  
        
        if($affected_rows > 0)	  
        {
            $Result = $stmt->fetch(PDO::FETCH_OBJ); 
            
                if($Result->AMMT==1)  
                    $data['Data'] = "50";      
                else if($Result->AMMT==2) 
                    $data['Data'] = "100";        
                else if($Result->AMMT==3) 
                    $data['Data'] = "500";       
                else if($Result->AMMT==4) 
                    $data['Data'] = "1000";         
                else if($Result->AMMT==5) 
                    $data['Data'] = "5000";      
                else if($Result->AMMT==6) 
                    $data['Data'] = "10000";     
                
                
            $_SESSION['TpIdFetch'] = $Result->id; 
            $data['Status'] = 1;
              
        } 
        else 
             $data['Status'] = 0;
		
		echo json_encode($data);
		die;    
     }     
     
     
     if($_REQUEST['refId'])
     {  
         
            $set=0;  
    		$stmt = $conn->prepare("SELECT refId FROM UI__Rgst WHERE cuurentId=:cuurentId");  
            $stmt->execute(array(':cuurentId'=>$_REQUEST['refId']));
    	    $affected_rows = $stmt->rowCount();	 
    		
    		if($affected_rows > 0)	
    			$set=1;
    		 
    		 if($set==1) 
    		     echo json_encode(TRUE);
    		 else
    			echo json_encode(FALSE);		
    		die;
     }
     
     if($_REQUEST['ph_no'])
     {    
         
            $set=0;  
    		$stmt = $conn->prepare("SELECT phm FROM UI__Rgst WHERE phm=:ph_no");  
            $stmt->execute(array(':ph_no'=>$_REQUEST['ph_no']));
    	    $affected_rows = $stmt->rowCount();	 
    		
    		if($affected_rows > 0)	
    			$set=1;
    		 
    		 if($set==0) 
    		     echo json_encode(TRUE);
    		 else
    			echo json_encode(FALSE);		
    		die;
     }   
?>