<?php
	include_once('../config.php');   
    
  
          
    if(!isset($_SESSION['userId']))
    { 
         header("Location: ../");
         die;
    }
    
             
             
                    if(isset($_REQUEST['cancelSloat']))
                    {
                        
                        $stmt=$conn->prepare("select id   from 	UI__AtwReserse  where custId=:custId  and Tdate=:Tdate ");   
                        $stmt->bindValue(':custId',  $_SESSION['userId'] , PDO::PARAM_STR);  
                        $stmt->bindValue(':Tdate',  date("d-M-Y"), PDO::PARAM_STR);  
                        $stmt->execute(); 
                        
                        $mtc = $stmt->rowCount();
                        $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);   
                        $userPWd = hash('sha256',trim($_POST['pinno'])); 
                             
                       

                        if( ($mtc < 1) && (trim($UI__Rgst->txnpwd)==$userPWd))
                        {  
                             
                            $stmt=$conn->prepare("select  id  from 	UI__Atw  where custId=:custId   and status=1 order by id desc ");   
                            $stmt->bindValue(':custId',  $_SESSION['userId'] , PDO::PARAM_STR);   
                            $stmt->execute(); 
                            $AllUsers = $stmt->fetch(PDO::FETCH_OBJ); 

                                                         
                            $stmt=$conn->prepare("update 	UI__Atw   set status=0 where id=:id ");   
                            $stmt->bindValue(':id',  $AllUsers->id, PDO::PARAM_STR);   
                            $stmt->execute();    
                            
                            
                            $stmt=$conn->prepare("insert into  UI__AtwReserse (custId,Tdate,Amt,sloaTid) values(:custId,:Tdate,:Amt,:sloaTid) ");   
                            $stmt->bindValue(':custId',  $_SESSION['userId'] , PDO::PARAM_STR);  
                            $stmt->bindValue(':Tdate',  date("d-M-Y"), PDO::PARAM_STR);  
                            $stmt->bindValue(':Amt',  10000 , PDO::PARAM_STR);  
                            $stmt->bindValue(':sloaTid',   $AllUsers->id , PDO::PARAM_STR); 
                            $stmt->execute();   
                            
                            
                        	 
                        	$_POST['fund'] =  10000;
							$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'],10000,1,"ATW Sloat Removed",$_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',   19 , 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', 10000   , 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',  $_SESSION['userId'] , PDO::PARAM_STR); 
								$stmt->bindValue(':TopayName',   $_SESSION['userId']  , PDO::PARAM_STR);     
								$stmt->execute();   
								unset($_SESSION['LastIntId']);            
							 
							 
                                $mob = $UI__Rgst->phm; 
                                $iD = $_SESSION['userId'];
                                $am = 10000;  
                                $msg = urlencode('Dear '.$iD.', Congratulations, Rs. '.$am.' has been credited in your DAILYPAY account, 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=1207169907278194379';

                                
                                $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);

							  
    					
							
                            $_SESSION['topSuc']  = 1;
                            $_SESSION['Regis']  = "Slot Cancelled Successfully";
                        }else
                             $_SESSION['Regis']  = "Sorry Sloat Could Not Cancel Now ";
                             
                        header("Location: atwsloats.php");   
                        die;
                    }
                
            $stmt=$conn->prepare("select *   from 	UI__Atw  where custId =:userid  and status=1   order by id desc  ");   
            $stmt->bindValue(':userid',  $_SESSION['userId'] , PDO::PARAM_STR);  
            $stmt->execute(); 
            $NofSloats = $stmt->rowCount();    
        
        
            /*$stmt=$conn->prepare("select id   from 	UI__AtwReserse  where custId=:custId  and Tdate=:Tdate ");   
            $stmt->bindValue(':custId',  $_SESSION['userId'] , PDO::PARAM_STR);  
            $stmt->bindValue(':Tdate',  date("d-M-Y"), PDO::PARAM_STR);  
            $stmt->execute(); 
            
            if($stmt->rowCount() > 0)
                 $_SESSION['Regis']  = "You Have Already Cancelled One Sloat Today!";
            
            */
            
            
                
include_once("../view/dashboard/atwsloats.php");
?>