<?php
	include_once('../config.php');    
	include_once(ABS_PATH.'/custom_function/default.php');  
	       
 
    
            if( (date("D")=="Sat") || (date("D")=="Sun"))
            {
                die;
            }
              
            $set = 0;
            if(date("H:i")=="01:30")
            $set = 1;     
 							
           function sendMl($eml,$amount)
           {
               /* 
			     $subject = "Level income generated on ".$SITE_NAME;  
                $template_type = 1;
                $attachment = '';  
                $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 daily income generated. Details are as follows </h5> 
                <h5 style='font-weight:bold; padding:2px 2px; margin:0px; text-align:center; color:#002368;'>Amount: $amount   </h5>
                
                </td>
                </tr>";   
                SendMail($Str->eml,$subject,$message,$template_type,$attachment);  
			*/
           }            
                
  
	           if(($_REQUEST['Ffnvwvbv']=='NEUIEUBNDDOUIOEIONKLV6897634fnfvBVKV34') && ($set==1)) 
	           {
	               
                    $stmt=$conn->prepare("select  cuurentId from  UI__Rgst  order by id");   
                    $stmt->execute(); 
                    $Repoints = $stmt->fetchAll(PDO::FETCH_OBJ); 
                    $sr = 1;
                    foreach($Repoints as $usersFetch)
                    { 
                         
                    }
			        
								       
                    $stmt=$conn->prepare("select  *   from  UI__DChstr where typ=1  and Rid!='DP112233' and specialUser=0 ");   
                    $stmt->execute();  
                    $UI__DailyROIGeneCt = $stmt->fetchAll(PDO::FETCH_OBJ);  
                    //echo '<pre>'; print_r($UI__DailyROIGeneCt); die; 
                    
                    
                    foreach($UI__DailyROIGeneCt as $dmt)
                    {      
						
						$stmt=$conn->prepare("select   is_active,id  from  UI__Rgst where  cuurentId=:cuurentId   ");
						$stmt->bindValue(':cuurentId', $dmt->Rid , PDO::PARAM_STR);   								
						$stmt->execute();  
						$is_active = $stmt->fetch(PDO::FETCH_OBJ); 
						$MyctId = $is_active->id; 
							
                        
								$stmt=$conn->prepare(" select phm  from  UI__Rgst where  cuurentId=:cuurentId   ");
								$stmt->bindValue(':cuurentId', $dmt->Rid , PDO::PARAM_STR);   								
								$stmt->execute();  
								$phm = $stmt->fetch(PDO::FETCH_OBJ);     

                                    
                                $abb[] = $dmt->Rid;  
                                 
                                       
                                
                        if($dmt->id > 5256)        
                        {
                            $levelDays = 120;      
                            $leftdays = 118;      
                        }else
                        {
                            $levelDays = 60;      
                            $leftdays = 58; 
                        }
						
						$NewLevel = 0; 		
						
						if($MyctId>932)
						 $NewLevel = 1; 		
                        
                        if($dmt->bnsStatus==0) // level cond staRT
                        {
                
                				$_POST['cuurentId'] = $dmt->Rid;    
                				$MrefId= $dmt->id;
                				$stmt=$conn->prepare("select refId,custId   from UI__Rgst where cuurentId =:cuurentId ");   
                				$stmt->bindValue(':cuurentId',  $_POST['cuurentId'] , PDO::PARAM_INT);  
                				$stmt->execute();  
                                if($stmt->rowCount() > 0)
                                {     
                                    $ard = null;
                                    $ard = [];
                                    $Result = $stmt->fetch(PDO::FETCH_OBJ);   
                                    $CC = $Result->refId;
                                    $MyCust =  $Result->custId;
                                    $ard[] = $CC;
                                    for($i=0;$i<=9;$i++)
                                    {
                                        $stmt=$conn->prepare("select refId from UI__Rgst where cuurentId =:cuurentId ");   
                                        $stmt->bindValue(':cuurentId',$CC, PDO::PARAM_INT);  
                                        $stmt->execute();  
                                        if($stmt->rowCount() > 0)
                                        { 
                                            $Result = $stmt->fetch(PDO::FETCH_OBJ);   
                                            $CC = $Result->refId;
                                            $ard[] = $CC;
                                        }
                                    }  
                                }
				
				
				     
				                
				 $data['Data'] = $dmt->amt;   
				 if(end($ard)==0)
                 {
 
 
                    $myDirectBussiness = 0; 
                    for($j1=0;$j1<(count($ard)-1);$j1++)
                    {
                      
						 $GetLevel = 0; 
						 
					     if( (($_POST['cuurentId']=='DP213439') || ($_POST['cuurentId']=='DP360639') || ($_POST['cuurentId']=='DP244196')) && (($ard[$j1]=='DP647792') ||  ($ard[$j1]=='DP609575')  ||  ($ard[$j1]=='DP889773')) )
							$GetLevel = 1;
						
						if($GetLevel==0)
						{
						$mylevelAmt = 100000;
						/*if($NewLevel==1)
						{
    						if( ($ard[$j1]!='DP112233') && ($ard[$j1]!='DP212871')) 
    						{
    						
        						$stmt=$conn->prepare("select amt from UI__Rgst where refId=:refId  ");   
        						$stmt->bindValue(':refId', $ard[$j1] , PDO::PARAM_STR);   
        						$stmt->execute();  
        						$MYtotalCt = $stmt->rowCount();
        
        						if($MYtotalCt>0) 
        						{
        						    $ICtm = $stmt->fetchAll(PDO::FETCH_OBJ);    
                                    foreach($ICtm as $amp)
                                        $mylevelAmt +=$amp->amt;
        						}
    						
    						}
						}*/

                      
                        $Ssprcl100 = 1; 
                        if (strpos($ard[$j1], 'SP') !== false)   
                            $Ssprcl100=0;     
						
						$stmt=$conn->prepare("select cuurentId   from UI__Rgst where refId=:refId  ");   
						$stmt->bindValue(':refId', $ard[$j1] , PDO::PARAM_STR);   
						$stmt->execute();
						
						if($stmt->rowCount() > 0)
						{  
							$fetchAll = $stmt->fetchAll(PDO::FETCH_OBJ); 
							$myDirectBussiness = 0;
							foreach($fetchAll as $dpp)
							{
									$stmt=$conn->prepare("select amt  from UI__DChstr where Rid=:Rid  ");   
									$stmt->bindValue(':Rid', $dpp->cuurentId , PDO::PARAM_STR);   
									$stmt->execute();
									$UI__DChstr2 = $stmt->fetchAll(PDO::FETCH_OBJ); 
									
									foreach($UI__DChstr2 as $dpp1)
    								    $myDirectBussiness +=$dpp1->amt;
							}
						} 						

                        
                        if( ($j1==0) && ($Ssprcl100==1))
                        {       
                                
								$MYtotalCt=1;
								if($NewLevel==1)
								{
										$stmt=$conn->prepare("select cuurentId from UI__Rgst where refId=:refId  ");   
										$stmt->bindValue(':refId', $ard[$j1] , PDO::PARAM_STR);   
										$stmt->execute();  
										$MYtotalCt = $stmt->rowCount();
								}
									
								$CoinVal = ($data['Data']*0.1)/100;    
                                $stmt=$conn->prepare("select id from UI__DChstr where Rid=:Rid and typ=1 and status=0 ");   
                                $stmt->bindValue(':Rid', $ard[$j1] , PDO::PARAM_STR);   
                                $stmt->execute();  
                                if( ($stmt->rowCount() > 0) && ($MYtotalCt>0)  &&($myDirectBussiness>=10000) ) 
                                {     
                                    
                                    $stmt=$conn->prepare("select  cct  from UI__LevlCt where tblId=:tblId and custId=:custId  ");   
                                    $stmt->bindValue(':tblId', $MrefId , PDO::PARAM_STR);   
                                    $stmt->bindValue(':custId', $ard[$j1] , PDO::PARAM_STR);   
                                    $stmt->execute(); 
                                    $IeerCt = $stmt->fetch(PDO::FETCH_OBJ); 
                                    if($IeerCt->cct <= $levelDays) 
                                    {    
                                        $stmt=$conn->prepare("insert into  UI__Bns (Rid,Brid,Tdate,Tamt,BAmt,level,DaysLeft) values(:Rid,:Brid,:Tdate,:Tamt,:BAmt,:level,:DaysLeft) ");   
                                        $stmt->bindValue(':Rid', $ard[$j1] , PDO::PARAM_STR); 
                                        $stmt->bindValue(':Brid', $_POST['cuurentId'], PDO::PARAM_STR); 
                                        $stmt->bindValue(':Tdate', date("d-M-Y") , PDO::PARAM_STR); 
                                        $stmt->bindValue(':Tamt', $CoinVal , PDO::PARAM_STR);   
                                        $stmt->bindValue(':BAmt', $data['Data'] , PDO::PARAM_STR);      
                                        $stmt->bindValue(':level', 1  , PDO::PARAM_STR); 
                                        $stmt->bindValue(':DaysLeft', ($leftdays-$IeerCt->cct) , PDO::PARAM_STR);    
                                        $stmt->execute();   
                                        
                                        $stmt=$conn->prepare("select eml from UI__Rgst where cuurentId =:cuurentId ");   
                                        $stmt->bindValue(':cuurentId', $ard[$j1], PDO::PARAM_STR);  
                                        $stmt->execute();  
                                        $Str = $stmt->fetch(PDO::FETCH_OBJ); 
                                        
                                        sendMl($Str->eml,$CoinVal);
                                        
                                        $stmt=$conn->prepare("select  * from  UI__Rgst where cuurentId=:cuurentId  ");   
                                        $stmt->bindValue(':cuurentId',  $ard[$j1] , PDO::PARAM_STR);   
                                        $stmt->execute();  
                                        $custId = $stmt->fetch(PDO::FETCH_OBJ); 
                                        
                                        if( ($ard[$j1]!='DP112233') && ($ard[$j1]!='DP212871')) 
										{
                                            LvBal_new($ard[$j1],$CoinVal,1,"Level Balance",$_POST['cuurentId']);  
                                            unset($_SESSION['LastIntId']);
                                        } 
										
                                        $stmt=$conn->prepare("update   UI__LevlCt set cct=cct+1 where tblId=:tblId and custId=:custId  ");   
                                        $stmt->bindValue(':tblId', $MrefId , PDO::PARAM_STR);   
                                        $stmt->bindValue(':custId', $ard[$j1] , PDO::PARAM_STR);   
                                        $stmt->execute();  
                                    }else
                                    {
                                        $stmt=$conn->prepare("update   UI__DChstr set  bnsStatus=1  where id=:id ");   
                                        $stmt->bindValue(':id', $MrefId , PDO::PARAM_STR);    
                                        $stmt->execute();   
                                    }
                                    
                                }
                        }
                        else if( ($j1==1) && ($Ssprcl100==1))
                        { 
                            
							$MYtotalCt=2;
							if($NewLevel==1)
							{
									$stmt=$conn->prepare("select cuurentId from UI__Rgst where refId=:refId  ");   
									$stmt->bindValue(':refId', $ard[$j1] , PDO::PARAM_STR);   
									$stmt->execute();  
									$MYtotalCt = $stmt->rowCount();
							}
								
							$CoinVal = ($data['Data']*0.08)/100;    
                            $stmt=$conn->prepare("select id from UI__DChstr where Rid=:Rid and typ=1  and status=0 ");   
                            $stmt->bindValue(':Rid', $ard[$j1] , PDO::PARAM_STR);   
                            $stmt->execute();  
                            if( ($stmt->rowCount() > 0) && ($MYtotalCt>0) &&($myDirectBussiness>=20000) ) 
                            {
                                
                                $stmt=$conn->prepare("select  cct  from UI__LevlCt where tblId=:tblId and custId=:custId  ");   
                                $stmt->bindValue(':tblId', $MrefId , PDO::PARAM_STR);   
                                $stmt->bindValue(':custId', $ard[$j1] , PDO::PARAM_STR);   
                                $stmt->execute(); 
                                $IeerCt = $stmt->fetch(PDO::FETCH_OBJ); 
                                if($IeerCt->cct <= $levelDays) 
                                {
                                $stmt=$conn->prepare("insert into  UI__Bns (Rid,Brid,Tdate,Tamt,BAmt,level,DaysLeft) values(:Rid,:Brid,:Tdate,:Tamt,:BAmt,:level,:DaysLeft) ");   
                                $stmt->bindValue(':Rid', $ard[$j1] , PDO::PARAM_STR); 
                                $stmt->bindValue(':Brid', $_POST['cuurentId'], PDO::PARAM_STR); 
                                $stmt->bindValue(':Tdate', date("d-M-Y") , PDO::PARAM_STR); 
                                $stmt->bindValue(':Tamt', $CoinVal , PDO::PARAM_STR);   
                                $stmt->bindValue(':BAmt', $data['Data'] , PDO::PARAM_STR);      
                                $stmt->bindValue(':level', 2  , PDO::PARAM_STR);      
                                $stmt->bindValue(':DaysLeft', ($leftdays-$IeerCt->cct) , PDO::PARAM_STR);    
                                $stmt->execute();   
                                
                                
                                $stmt=$conn->prepare("select eml from UI__Rgst where cuurentId =:cuurentId ");   
                                $stmt->bindValue(':cuurentId', $ard[$j1], PDO::PARAM_STR);  
                                $stmt->execute();  
                                $Str = $stmt->fetch(PDO::FETCH_OBJ); 
                                
                                sendMl($Str->eml,$CoinVal);
                                
                                $stmt=$conn->prepare("select  * from  UI__Rgst where cuurentId=:cuurentId  ");   
                                $stmt->bindValue(':cuurentId',  $ard[$j1] , PDO::PARAM_STR);   
                                $stmt->execute();  
                                $custId = $stmt->fetch(PDO::FETCH_OBJ);
                                
                               if( ($ard[$j1]!='DP112233') && ($ard[$j1]!='DP212871')) 
                               {
                                            LvBal_new($ard[$j1],$CoinVal,1,"Level Balance",$_POST['cuurentId']);  
                                            unset($_SESSION['LastIntId']);
                                        }
                                         
                                                                 
                                $stmt=$conn->prepare("update   UI__LevlCt set cct=cct+1 where tblId=:tblId and custId=:custId  ");   
                                $stmt->bindValue(':tblId', $MrefId , PDO::PARAM_STR);   
                                $stmt->bindValue(':custId', $ard[$j1] , PDO::PARAM_STR);   
                                $stmt->execute();  
                                
                                }else
                                    {
                                        $stmt=$conn->prepare("update   UI__DChstr set  bnsStatus=1  where id=:id ");   
                                        $stmt->bindValue(':id', $MrefId , PDO::PARAM_STR);    
                                        $stmt->execute();   
                                    }
                            }
                             
 					    }else if( ($j1==2) && ($Ssprcl100==1))
                        { 
                            $MYtotalCt=3;
							if($NewLevel==1)
							{
									$stmt=$conn->prepare("select cuurentId from UI__Rgst where refId=:refId  ");   
									$stmt->bindValue(':refId', $ard[$j1] , PDO::PARAM_STR);   
									$stmt->execute();  
									$MYtotalCt = $stmt->rowCount();
							}
							
							
							$CoinVal = ($data['Data']*(0.07))/100;   
                            $stmt=$conn->prepare("select id from UI__DChstr where Rid=:Rid and typ=1  and status=0 ");   
                            $stmt->bindValue(':Rid', $ard[$j1] , PDO::PARAM_STR);   
                            $stmt->execute();  
                            if( ($stmt->rowCount() > 0) && ($MYtotalCt>0)  &&($myDirectBussiness>=30000)) 
                            {
                               
                                $stmt=$conn->prepare("select  cct  from UI__LevlCt where tblId=:tblId and custId=:custId  ");   
                                $stmt->bindValue(':tblId', $MrefId , PDO::PARAM_STR);   
                                $stmt->bindValue(':custId', $ard[$j1] , PDO::PARAM_STR);   
                                $stmt->execute(); 
                                $IeerCt = $stmt->fetch(PDO::FETCH_OBJ); 
                                if($IeerCt->cct <= $levelDays) 
                                {
                                
                                $stmt=$conn->prepare("insert into  UI__Bns (Rid,Brid,Tdate,Tamt,BAmt,level,DaysLeft) values(:Rid,:Brid,:Tdate,:Tamt,:BAmt,:level,:DaysLeft) ");   
                                $stmt->bindValue(':Rid', $ard[$j1] , PDO::PARAM_STR); 
                                $stmt->bindValue(':Brid', $_POST['cuurentId'], PDO::PARAM_STR); 
                                $stmt->bindValue(':Tdate', date("d-M-Y") , PDO::PARAM_STR); 
                                $stmt->bindValue(':Tamt', $CoinVal , PDO::PARAM_STR);   
                                $stmt->bindValue(':BAmt', $data['Data'] , PDO::PARAM_STR);      
                                $stmt->bindValue(':level', 3  , PDO::PARAM_STR);
                                $stmt->bindValue(':DaysLeft', ($leftdays-$IeerCt->cct) , PDO::PARAM_STR);    
                                $stmt->execute();   
                                
                                
                                $stmt=$conn->prepare("select eml from UI__Rgst where cuurentId =:cuurentId ");   
                                $stmt->bindValue(':cuurentId', $ard[$j1], PDO::PARAM_STR);  
                                $stmt->execute();  
                                $Str = $stmt->fetch(PDO::FETCH_OBJ); 
                                
                                sendMl($Str->eml,$CoinVal);
                                
                                $stmt=$conn->prepare("select  * from  UI__Rgst where cuurentId=:cuurentId  ");   
                                $stmt->bindValue(':cuurentId',  $ard[$j1] , PDO::PARAM_STR);   
                                $stmt->execute();  
                                $custId = $stmt->fetch(PDO::FETCH_OBJ);
                                
                                if( ($ard[$j1]!='DP112233') && ($ard[$j1]!='DP212871')) 
                                {
                                            LvBal_new($ard[$j1],$CoinVal,1,"Level Balance",$_POST['cuurentId']);  
                                            unset($_SESSION['LastIntId']);
                                        }
                                         
                                                                        
                                $stmt=$conn->prepare("update   UI__LevlCt set cct=cct+1 where tblId=:tblId and custId=:custId  ");   
                                $stmt->bindValue(':tblId', $MrefId , PDO::PARAM_STR);   
                                $stmt->bindValue(':custId', $ard[$j1] , PDO::PARAM_STR);   
                                $stmt->execute();  
                                }else
                                    {
                                        $stmt=$conn->prepare("update   UI__DChstr set  bnsStatus=1  where id=:id ");   
                                        $stmt->bindValue(':id', $MrefId , PDO::PARAM_STR);    
                                        $stmt->execute();   
                                    }
                            }
                             
 					    }else if( ($j1==3) && ($Ssprcl100==1))
                        { 
                            $MYtotalCt=4;
							if($NewLevel==1)
							{
									$stmt=$conn->prepare("select cuurentId from UI__Rgst where refId=:refId  ");   
									$stmt->bindValue(':refId', $ard[$j1] , PDO::PARAM_STR);   
									$stmt->execute();  
									$MYtotalCt = $stmt->rowCount();
							}
							
							$CoinVal = ($data['Data']*(0.06))/100;       
                            $stmt=$conn->prepare("select id from UI__DChstr where Rid=:Rid and typ=1  and status=0 ");   
                            $stmt->bindValue(':Rid', $ard[$j1] , PDO::PARAM_STR);   
                            $stmt->execute();  
                            if( ($stmt->rowCount() > 0) && ($MYtotalCt>0)   &&($myDirectBussiness>=40000) ) 
                            {
                                
                                $stmt=$conn->prepare("select  cct  from UI__LevlCt where tblId=:tblId and custId=:custId  ");   
                                $stmt->bindValue(':tblId', $MrefId , PDO::PARAM_STR);   
                                $stmt->bindValue(':custId', $ard[$j1] , PDO::PARAM_STR);   
                                $stmt->execute(); 
                                $IeerCt = $stmt->fetch(PDO::FETCH_OBJ); 
                                if($IeerCt->cct <= $levelDays) 
                                {
                                $stmt=$conn->prepare("insert into  UI__Bns (Rid,Brid,Tdate,Tamt,BAmt,level,DaysLeft) values(:Rid,:Brid,:Tdate,:Tamt,:BAmt,:level,:DaysLeft) ");   
                                $stmt->bindValue(':Rid', $ard[$j1] , PDO::PARAM_STR); 
                                $stmt->bindValue(':Brid', $_POST['cuurentId'], PDO::PARAM_STR); 
                                $stmt->bindValue(':Tdate', date("d-M-Y") , PDO::PARAM_STR); 
                                $stmt->bindValue(':Tamt', $CoinVal , PDO::PARAM_STR);   
                                $stmt->bindValue(':BAmt', $data['Data'] , PDO::PARAM_STR);      
                                $stmt->bindValue(':level', 4  , PDO::PARAM_STR);   
                                $stmt->bindValue(':DaysLeft', ($leftdays-$IeerCt->cct) , PDO::PARAM_STR);    
                                $stmt->execute();   
                                
                                
                            
                                $stmt=$conn->prepare("select eml from UI__Rgst where cuurentId =:cuurentId ");   
                                $stmt->bindValue(':cuurentId', $ard[$j1], PDO::PARAM_STR);  
                                $stmt->execute();  
                                $Str = $stmt->fetch(PDO::FETCH_OBJ); 
                                
                                sendMl($Str->eml,$CoinVal);
                                    
                                $stmt=$conn->prepare("select  * from  UI__Rgst where cuurentId=:cuurentId  ");   
                                $stmt->bindValue(':cuurentId',  $ard[$j1] , PDO::PARAM_STR);   
                                $stmt->execute();  
                                $custId = $stmt->fetch(PDO::FETCH_OBJ);
                                
                                if( ($ard[$j1]!='DP112233') && ($ard[$j1]!='DP212871')) 
                                {
                                            LvBal_new($ard[$j1],$CoinVal,1,"Level Balance",$_POST['cuurentId']);  
                                            unset($_SESSION['LastIntId']);
                                        }
                                        
                                        
                                
                                $stmt=$conn->prepare("update   UI__LevlCt set cct=cct+1 where tblId=:tblId and custId=:custId  ");   
                                $stmt->bindValue(':tblId', $MrefId , PDO::PARAM_STR);   
                                $stmt->bindValue(':custId', $ard[$j1] , PDO::PARAM_STR);   
                                $stmt->execute();  
                                }else
                                    {
                                        $stmt=$conn->prepare("update   UI__DChstr set  bnsStatus=1  where id=:id ");   
                                        $stmt->bindValue(':id', $MrefId , PDO::PARAM_STR);    
                                        $stmt->execute();   
                                    }
                            }
                             
 					    }else if( ($j1==4) && ($Ssprcl100==1))
                        { 
                            $MYtotalCt=5;
							if($NewLevel==1)
							{
									$stmt=$conn->prepare("select cuurentId from UI__Rgst where refId=:refId  ");   
									$stmt->bindValue(':refId', $ard[$j1] , PDO::PARAM_STR);   
									$stmt->execute();  
									$MYtotalCt = $stmt->rowCount();
							}
							
							$CoinVal = ($data['Data']*(0.05))/100;     
                            $stmt=$conn->prepare("select id from UI__DChstr where Rid=:Rid and typ=1 and status=0 ");   
                            $stmt->bindValue(':Rid', $ard[$j1] , PDO::PARAM_STR);   
                            $stmt->execute();  
                            if( ($stmt->rowCount() > 0) && ($MYtotalCt>0)   &&($myDirectBussiness>=50000) ) 
                            {
                                
                                $stmt=$conn->prepare("select  cct  from UI__LevlCt where tblId=:tblId and custId=:custId  ");   
                                $stmt->bindValue(':tblId', $MrefId , PDO::PARAM_STR);   
                                $stmt->bindValue(':custId', $ard[$j1] , PDO::PARAM_STR);   
                                $stmt->execute(); 
                                $IeerCt = $stmt->fetch(PDO::FETCH_OBJ); 
                                if($IeerCt->cct <= $levelDays) 
                                {
                                $stmt=$conn->prepare("insert into  UI__Bns (Rid,Brid,Tdate,Tamt,BAmt,level,DaysLeft) values(:Rid,:Brid,:Tdate,:Tamt,:BAmt,:level,:DaysLeft) ");   
                                $stmt->bindValue(':Rid', $ard[$j1] , PDO::PARAM_STR); 
                                $stmt->bindValue(':Brid', $_POST['cuurentId'], PDO::PARAM_STR); 
                                $stmt->bindValue(':Tdate', date("d-M-Y") , PDO::PARAM_STR); 
                                $stmt->bindValue(':Tamt', $CoinVal , PDO::PARAM_STR);   
                                $stmt->bindValue(':BAmt', $data['Data'] , PDO::PARAM_STR);      
                                $stmt->bindValue(':level', 5 , PDO::PARAM_STR);  
                                $stmt->bindValue(':DaysLeft', ($leftdays-$IeerCt->cct) , PDO::PARAM_STR);    
                                $stmt->execute();   
                                
                                
                                $stmt=$conn->prepare("select eml from UI__Rgst where cuurentId =:cuurentId ");   
                                $stmt->bindValue(':cuurentId', $ard[$j1], PDO::PARAM_STR);  
                                $stmt->execute();  
                                $Str = $stmt->fetch(PDO::FETCH_OBJ); 
                                
                                sendMl($Str->eml,$CoinVal);
                                
                                $stmt=$conn->prepare("select  * from  UI__Rgst where cuurentId=:cuurentId  ");   
                                $stmt->bindValue(':cuurentId',  $ard[$j1] , PDO::PARAM_STR);   
                                $stmt->execute();  
                                $custId = $stmt->fetch(PDO::FETCH_OBJ);
                                
                               if( ($ard[$j1]!='DP112233') && ($ard[$j1]!='DP212871')) 
                               {
                                            LvBal_new($ard[$j1],$CoinVal,1,"Level Balance",$_POST['cuurentId']);  
                                            unset($_SESSION['LastIntId']);
                                        }
                                        
                                         
                                $stmt=$conn->prepare("update   UI__LevlCt set cct=cct+1 where tblId=:tblId and custId=:custId  ");   
                                $stmt->bindValue(':tblId', $MrefId , PDO::PARAM_STR);   
                                $stmt->bindValue(':custId', $ard[$j1] , PDO::PARAM_STR);   
                                $stmt->execute();  
                                }else
                                    {
                                        $stmt=$conn->prepare("update   UI__DChstr set  bnsStatus=1  where id=:id ");   
                                        $stmt->bindValue(':id', $MrefId , PDO::PARAM_STR);    
                                        $stmt->execute();   
                                    }
                            } 
 					      }else if( ($j1==5) && ($Ssprcl100==1))
                        { 
                            $MYtotalCt=6;
							if($NewLevel==1)
							{
									$stmt=$conn->prepare("select cuurentId from UI__Rgst where refId=:refId  ");   
									$stmt->bindValue(':refId', $ard[$j1] , PDO::PARAM_STR);   
									$stmt->execute();  
									$MYtotalCt = $stmt->rowCount();
							}
							
							$CoinVal = ($data['Data']*(0.04))/100;     
                            $stmt=$conn->prepare("select id from UI__DChstr where Rid=:Rid and typ=1 and status=0 ");   
                            $stmt->bindValue(':Rid', $ard[$j1] , PDO::PARAM_STR);   
                            $stmt->execute();  
                            if( ($stmt->rowCount() > 0) && ($MYtotalCt>0)  &&($myDirectBussiness>=60000)  ) 
                            {
                                $stmt=$conn->prepare("select  cct  from UI__LevlCt where tblId=:tblId and custId=:custId  ");   
                                $stmt->bindValue(':tblId', $MrefId , PDO::PARAM_STR);   
                                $stmt->bindValue(':custId', $ard[$j1] , PDO::PARAM_STR);   
                                $stmt->execute(); 
                                $IeerCt = $stmt->fetch(PDO::FETCH_OBJ); 
                                if($IeerCt->cct <= $levelDays) 
                                {
                                $stmt=$conn->prepare("insert into  UI__Bns (Rid,Brid,Tdate,Tamt,BAmt,level,DaysLeft) values(:Rid,:Brid,:Tdate,:Tamt,:BAmt,:level,:DaysLeft) ");   
                                $stmt->bindValue(':Rid', $ard[$j1] , PDO::PARAM_STR); 
                                $stmt->bindValue(':Brid', $_POST['cuurentId'], PDO::PARAM_STR); 
                                $stmt->bindValue(':Tdate', date("d-M-Y") , PDO::PARAM_STR); 
                                $stmt->bindValue(':Tamt', $CoinVal , PDO::PARAM_STR);   
                                $stmt->bindValue(':BAmt', $data['Data'] , PDO::PARAM_STR);      
                                $stmt->bindValue(':level', 6 , PDO::PARAM_STR);    
                                $stmt->bindValue(':DaysLeft', ($leftdays-$IeerCt->cct) , PDO::PARAM_STR);    
                                $stmt->execute();   
                                
                            
                                $stmt=$conn->prepare("select eml from UI__Rgst where cuurentId =:cuurentId ");   
                                $stmt->bindValue(':cuurentId', $ard[$j1], PDO::PARAM_STR);  
                                $stmt->execute();  
                                $Str = $stmt->fetch(PDO::FETCH_OBJ); 
                                
                                sendMl($Str->eml,$CoinVal);
                                
                                $stmt=$conn->prepare("select  * from  UI__Rgst where cuurentId=:cuurentId  ");   
                                $stmt->bindValue(':cuurentId',  $ard[$j1] , PDO::PARAM_STR);   
                                $stmt->execute();  
                                $custId = $stmt->fetch(PDO::FETCH_OBJ);
                                
                                if( ($ard[$j1]!='DP112233') && ($ard[$j1]!='DP212871')) 
                                {
                                            LvBal_new($ard[$j1],$CoinVal,1,"Level Balance",$_POST['cuurentId']);  
                                            unset($_SESSION['LastIntId']);
                                        }
                                        
                                        
                                $stmt=$conn->prepare("update   UI__LevlCt set cct=cct+1 where tblId=:tblId and custId=:custId  ");   
                                $stmt->bindValue(':tblId', $MrefId , PDO::PARAM_STR);   
                                $stmt->bindValue(':custId', $ard[$j1] , PDO::PARAM_STR);   
                                $stmt->execute();  
                                }else
                                    {
                                        $stmt=$conn->prepare("update   UI__DChstr set  bnsStatus=1  where id=:id ");   
                                        $stmt->bindValue(':id', $MrefId , PDO::PARAM_STR);    
                                        $stmt->execute();   
                                    }
                            }
                             
 					      }else if( ($j1==6) && ($Ssprcl100==1))
                        { 
                           
							$MYtotalCt=7;
							if($NewLevel==1)
							{
									$stmt=$conn->prepare("select cuurentId from UI__Rgst where refId=:refId  ");   
									$stmt->bindValue(':refId', $ard[$j1] , PDO::PARAM_STR);   
									$stmt->execute();  
									$MYtotalCt = $stmt->rowCount();
							}

							$CoinVal = ($data['Data']*(0.03))/100;     
                            $stmt=$conn->prepare("select id from UI__DChstr where Rid=:Rid and typ=1 and status=0 ");   
                            $stmt->bindValue(':Rid', $ard[$j1] , PDO::PARAM_STR);   
                            $stmt->execute();  
                            if( ($stmt->rowCount() > 0) && ($MYtotalCt>0) &&($myDirectBussiness>=70000) ) 
                            {
                                $stmt=$conn->prepare("select  cct  from UI__LevlCt where tblId=:tblId and custId=:custId  ");   
                                $stmt->bindValue(':tblId', $MrefId , PDO::PARAM_STR);   
                                $stmt->bindValue(':custId', $ard[$j1] , PDO::PARAM_STR);   
                                $stmt->execute(); 
                                $IeerCt = $stmt->fetch(PDO::FETCH_OBJ); 
                                if($IeerCt->cct <= $levelDays) 
                                {
                                $stmt=$conn->prepare("insert into  UI__Bns (Rid,Brid,Tdate,Tamt,BAmt,level,DaysLeft) values(:Rid,:Brid,:Tdate,:Tamt,:BAmt,:level,:DaysLeft) ");   
                                $stmt->bindValue(':Rid', $ard[$j1] , PDO::PARAM_STR); 
                                $stmt->bindValue(':Brid', $_POST['cuurentId'], PDO::PARAM_STR); 
                                $stmt->bindValue(':Tdate', date("d-M-Y") , PDO::PARAM_STR); 
                                $stmt->bindValue(':Tamt', $CoinVal , PDO::PARAM_STR);   
                                $stmt->bindValue(':BAmt', $data['Data'] , PDO::PARAM_STR);      
                                $stmt->bindValue(':level', 7 , PDO::PARAM_STR); 
                                $stmt->bindValue(':DaysLeft', ($leftdays-$IeerCt->cct) , PDO::PARAM_STR);    
                                $stmt->execute();   
                                
                            
                                $stmt=$conn->prepare("select eml from UI__Rgst where cuurentId =:cuurentId ");   
                                $stmt->bindValue(':cuurentId', $ard[$j1], PDO::PARAM_STR);  
                                $stmt->execute();  
                                $Str = $stmt->fetch(PDO::FETCH_OBJ); 
                                
                                sendMl($Str->eml,$CoinVal);
                                
                                $stmt=$conn->prepare("select  * from  UI__Rgst where cuurentId=:cuurentId  ");   
                                $stmt->bindValue(':cuurentId',  $ard[$j1] , PDO::PARAM_STR);   
                                $stmt->execute();  
                                $custId = $stmt->fetch(PDO::FETCH_OBJ);
                                
                                if( ($ard[$j1]!='DP112233') && ($ard[$j1]!='DP212871')) 
                                {
                                            LvBal_new($ard[$j1],$CoinVal,1,"Level Balance",$_POST['cuurentId']);  
                                            unset($_SESSION['LastIntId']);
                                        }
                                        
                                        
                                $stmt=$conn->prepare("update   UI__LevlCt set cct=cct+1 where tblId=:tblId and custId=:custId  ");   
                                $stmt->bindValue(':tblId', $MrefId , PDO::PARAM_STR);   
                                $stmt->bindValue(':custId', $ard[$j1] , PDO::PARAM_STR);   
                                $stmt->execute();  
                                }else
                                    {
                                        $stmt=$conn->prepare("update   UI__DChstr set  bnsStatus=1  where id=:id ");   
                                        $stmt->bindValue(':id', $MrefId , PDO::PARAM_STR);    
                                        $stmt->execute();   
                                    }
                            }
                             
 					      }else if( ($j1==7) && ($Ssprcl100==1))
                        { 
                            
							$MYtotalCt=8;
							if($NewLevel==1)
							{
									$stmt=$conn->prepare("select cuurentId from UI__Rgst where refId=:refId  ");   
									$stmt->bindValue(':refId', $ard[$j1] , PDO::PARAM_STR);   
									$stmt->execute();  
									$MYtotalCt = $stmt->rowCount();
							}
							
							$CoinVal = ($data['Data']*(0.02))/100;     
                            $stmt=$conn->prepare("select id from UI__DChstr where Rid=:Rid and typ=1 and status=0 ");   
                            $stmt->bindValue(':Rid', $ard[$j1] , PDO::PARAM_STR);   
                            $stmt->execute();  
                            if( ($stmt->rowCount() > 0) && ($MYtotalCt>0) &&($myDirectBussiness>=80000)  ) 
                            {
                                $stmt=$conn->prepare("select  cct  from UI__LevlCt where tblId=:tblId and custId=:custId  ");   
                                $stmt->bindValue(':tblId', $MrefId , PDO::PARAM_STR);   
                                $stmt->bindValue(':custId', $ard[$j1] , PDO::PARAM_STR);   
                                $stmt->execute(); 
                                $IeerCt = $stmt->fetch(PDO::FETCH_OBJ); 
                                if($IeerCt->cct <= $levelDays) 
                                {
                                $stmt=$conn->prepare("insert into  UI__Bns (Rid,Brid,Tdate,Tamt,BAmt,level,DaysLeft) values(:Rid,:Brid,:Tdate,:Tamt,:BAmt,:level,:DaysLeft) ");   
                                $stmt->bindValue(':Rid', $ard[$j1] , PDO::PARAM_STR); 
                                $stmt->bindValue(':Brid', $_POST['cuurentId'], PDO::PARAM_STR); 
                                $stmt->bindValue(':Tdate', date("d-M-Y") , PDO::PARAM_STR); 
                                $stmt->bindValue(':Tamt', $CoinVal , PDO::PARAM_STR);   
                                $stmt->bindValue(':BAmt', $data['Data'] , PDO::PARAM_STR);      
                                $stmt->bindValue(':level', 8 , PDO::PARAM_STR);
                                $stmt->bindValue(':DaysLeft', ($leftdays-$IeerCt->cct) , PDO::PARAM_STR);    
                                $stmt->execute();   
                                
                                
                                $stmt=$conn->prepare("select eml from UI__Rgst where cuurentId =:cuurentId ");   
                                $stmt->bindValue(':cuurentId', $ard[$j1], PDO::PARAM_STR);  
                                $stmt->execute();  
                                $Str = $stmt->fetch(PDO::FETCH_OBJ); 
                                
                                sendMl($Str->eml,$CoinVal);
                            
                                $stmt=$conn->prepare("select  * from  UI__Rgst where cuurentId=:cuurentId  ");   
                                $stmt->bindValue(':cuurentId',  $ard[$j1] , PDO::PARAM_STR);   
                                $stmt->execute();  
                                $custId = $stmt->fetch(PDO::FETCH_OBJ);
                                
                               if( ($ard[$j1]!='DP112233') && ($ard[$j1]!='DP212871')) 
                               {
                                            LvBal_new($ard[$j1],$CoinVal,1,"Level Balance",$_POST['cuurentId']);  
                                            unset($_SESSION['LastIntId']);
                                        }
                                        
                                                 
                                $stmt=$conn->prepare("update   UI__LevlCt set cct=cct+1 where tblId=:tblId and custId=:custId  ");   
                                $stmt->bindValue(':tblId', $MrefId , PDO::PARAM_STR);   
                                $stmt->bindValue(':custId', $ard[$j1] , PDO::PARAM_STR);   
                                $stmt->execute();  
                                }else
                                    {
                                        $stmt=$conn->prepare("update   UI__DChstr set  bnsStatus=1  where id=:id ");   
                                        $stmt->bindValue(':id', $MrefId , PDO::PARAM_STR);    
                                        $stmt->execute();   
                                    }
                            }
                             
 					      }else if( ($j1==8) && ($Ssprcl100==1))
                        { 
                            
							$MYtotalCt=9;
							if($NewLevel==1)
							{
									$stmt=$conn->prepare("select cuurentId from UI__Rgst where refId=:refId  ");   
									$stmt->bindValue(':refId', $ard[$j1] , PDO::PARAM_STR);   
									$stmt->execute();  
									$MYtotalCt = $stmt->rowCount();
							}
							
							$CoinVal = ($data['Data']*(0.01))/100;     
                            $stmt=$conn->prepare("select id from UI__DChstr where Rid=:Rid and typ=1 and status=0 ");   
                            $stmt->bindValue(':Rid', $ard[$j1] , PDO::PARAM_STR);   
                            $stmt->execute();  
                            if( ($stmt->rowCount() > 0) && ($MYtotalCt>0) &&($myDirectBussiness>=90000)  ) 
                            {
                                $stmt=$conn->prepare("select  cct  from UI__LevlCt where tblId=:tblId and custId=:custId  ");   
                                $stmt->bindValue(':tblId', $MrefId , PDO::PARAM_STR);   
                                $stmt->bindValue(':custId', $ard[$j1] , PDO::PARAM_STR);   
                                $stmt->execute(); 
                                $IeerCt = $stmt->fetch(PDO::FETCH_OBJ); 
                                if($IeerCt->cct <= $levelDays) 
                                {
                                $stmt=$conn->prepare("insert into  UI__Bns (Rid,Brid,Tdate,Tamt,BAmt,level,DaysLeft) values(:Rid,:Brid,:Tdate,:Tamt,:BAmt,:level,:DaysLeft) ");   
                                $stmt->bindValue(':Rid', $ard[$j1] , PDO::PARAM_STR); 
                                $stmt->bindValue(':Brid', $_POST['cuurentId'], PDO::PARAM_STR); 
                                $stmt->bindValue(':Tdate', date("d-M-Y") , PDO::PARAM_STR); 
                                $stmt->bindValue(':Tamt', $CoinVal , PDO::PARAM_STR);   
                                $stmt->bindValue(':BAmt', $data['Data'] , PDO::PARAM_STR);      
                                $stmt->bindValue(':level', 9 , PDO::PARAM_STR);  
                                $stmt->bindValue(':DaysLeft', ($leftdays-$IeerCt->cct) , PDO::PARAM_STR);    
                                $stmt->execute();   
                                
                                
                            
                                $stmt=$conn->prepare("select eml from UI__Rgst where cuurentId =:cuurentId ");   
                                $stmt->bindValue(':cuurentId', $ard[$j1], PDO::PARAM_STR);  
                                $stmt->execute();  
                                $Str = $stmt->fetch(PDO::FETCH_OBJ); 
                                
                                sendMl($Str->eml,$CoinVal);
                                
                                $stmt=$conn->prepare("select  * from  UI__Rgst where cuurentId=:cuurentId  ");   
                                $stmt->bindValue(':cuurentId',  $ard[$j1] , PDO::PARAM_STR);   
                                $stmt->execute();  
                                $custId = $stmt->fetch(PDO::FETCH_OBJ);
                                
                               if( ($ard[$j1]!='DP112233') && ($ard[$j1]!='DP212871')) 
                               {
                                            LvBal_new($ard[$j1],$CoinVal,1,"Level Balance",$_POST['cuurentId']);  
                                            unset($_SESSION['LastIntId']);
                                        }
                                        
                                                 
                                $stmt=$conn->prepare("update   UI__LevlCt set cct=cct+1 where tblId=:tblId and custId=:custId  ");   
                                $stmt->bindValue(':tblId', $MrefId , PDO::PARAM_STR);   
                                $stmt->bindValue(':custId', $ard[$j1] , PDO::PARAM_STR);   
                                $stmt->execute();  
                                }else
                                    {
                                        $stmt=$conn->prepare("update   UI__DChstr set  bnsStatus=1  where id=:id ");   
                                        $stmt->bindValue(':id', $MrefId , PDO::PARAM_STR);    
                                        $stmt->execute();   
                                    }
                            }
                             
 					      }else if( ($j1==9) && ($Ssprcl100==1))
                        { 
                            $MYtotalCt=10;
							if($NewLevel==1)
							{
									$stmt=$conn->prepare("select cuurentId from UI__Rgst where refId=:refId  ");   
									$stmt->bindValue(':refId', $ard[$j1] , PDO::PARAM_STR);   
									$stmt->execute();  
									$MYtotalCt = $stmt->rowCount();
							}
							
							$CoinVal = ($data['Data']*(0.01))/100;     
                            $stmt=$conn->prepare("select id from UI__DChstr where Rid=:Rid and typ=1 and status=0 ");   
                            $stmt->bindValue(':Rid', $ard[$j1] , PDO::PARAM_STR);   
                            $stmt->execute();  
                            if( ($stmt->rowCount() > 0) && ($MYtotalCt>0)   &&($myDirectBussiness>=100000) ) 
                            {
                                $stmt=$conn->prepare("select  cct  from UI__LevlCt where tblId=:tblId and custId=:custId  ");   
                                $stmt->bindValue(':tblId', $MrefId , PDO::PARAM_STR);   
                                $stmt->bindValue(':custId', $ard[$j1] , PDO::PARAM_STR);   
                                $stmt->execute(); 
                                $IeerCt = $stmt->fetch(PDO::FETCH_OBJ); 
                                if($IeerCt->cct <= $levelDays) 
                                {
                                $stmt=$conn->prepare("insert into  UI__Bns (Rid,Brid,Tdate,Tamt,BAmt,level,DaysLeft) values(:Rid,:Brid,:Tdate,:Tamt,:BAmt,:level,:DaysLeft) ");   
                                $stmt->bindValue(':Rid', $ard[$j1] , PDO::PARAM_STR); 
                                $stmt->bindValue(':Brid', $_POST['cuurentId'], PDO::PARAM_STR); 
                                $stmt->bindValue(':Tdate', date("d-M-Y") , PDO::PARAM_STR); 
                                $stmt->bindValue(':Tamt', $CoinVal , PDO::PARAM_STR);   
                                $stmt->bindValue(':BAmt', $data['Data'] , PDO::PARAM_STR);      
                                $stmt->bindValue(':level', 10 , PDO::PARAM_STR);        
                                $stmt->bindValue(':DaysLeft', ($leftdays-$IeerCt->cct) , PDO::PARAM_STR);    
                                $stmt->execute();   
                                
                                
                                
                                $stmt=$conn->prepare("select eml from UI__Rgst where cuurentId =:cuurentId ");   
                                $stmt->bindValue(':cuurentId', $ard[$j1], PDO::PARAM_STR);  
                                $stmt->execute();  
                                $Str = $stmt->fetch(PDO::FETCH_OBJ); 
                                
                                sendMl($Str->eml,$CoinVal);
                                
                                $stmt=$conn->prepare("select  * from  UI__Rgst where cuurentId=:cuurentId  ");   
                                $stmt->bindValue(':cuurentId',  $ard[$j1] , PDO::PARAM_STR);   
                                $stmt->execute();  
                                $custId = $stmt->fetch(PDO::FETCH_OBJ);
                                
                               if( ($ard[$j1]!='DP112233') && ($ard[$j1]!='DP212871')) 
                               {
                                            LvBal_new($ard[$j1],$CoinVal,1,"Level Balance",$_POST['cuurentId']);  
                                            unset($_SESSION['LastIntId']);
                                        }
                                        
                                                 
                                $stmt=$conn->prepare("update   UI__LevlCt set cct=cct+1 where tblId=:tblId and custId=:custId  ");   
                                $stmt->bindValue(':tblId', $MrefId , PDO::PARAM_STR);   
                                $stmt->bindValue(':custId', $ard[$j1] , PDO::PARAM_STR);   
                                $stmt->execute();  
                                }else
                                    {
                                        $stmt=$conn->prepare("update   UI__DChstr set  bnsStatus=1  where id=:id ");   
                                        $stmt->bindValue(':id', $MrefId , PDO::PARAM_STR);    
                                        $stmt->execute();   
                                    }
                                
                               } 
 					        }
 					        
                                $stmt=$conn->prepare("insert test   (name) values(:Rname) ");   
                                $stmt->bindValue(':Rname', $_POST['cuurentId']."::".$ard[$j1] , PDO::PARAM_STR);  
                                $stmt->execute();  

					           }								
                         }  
                      
					  }
					  
					 }	//level condotion end 
                     
                       
					}// for end     
					      
        			$stmt=$conn->prepare("insert test   (name) values(:Rname) ");   
        			$stmt->bindValue(':Rname', "Completed..".date("d-M-Y H:i") , PDO::PARAM_STR);  
        			$stmt->execute();  
	            }
	            
	                   
                               