<?php 	include_once('../../config.php');
		 
?>  
<?php  include ABS_PATH.'/admin/header.php';	?>   
<style> 
    td
    {
        font-size:18px;
         
    }  
    th
    {
        font-size:20px;
        font-weight:bold;
        color:orange;
    } 
</style>
<script>
function del_record(val)
{

	var r = confirm("Do you really want to delete record !");
	if (r == true) {    
	$.ajax({
	type: 'POST',
	url: "../ajax/default.php",
	//async: false,			 
	data: {delLive:1,val:val},	  
	success: function(ajaxresult){	     
		location.reload();	 	
	},
	error: function(XMLHttpRequest, textStatus, errorThrown) { 
	alert('Error');
	}
	});
	
	}	
	
	
	
}

function delD(val)
{

	var r = confirm("Do you really want to delete record !");
	if (r == true) {    
	$.ajax({
	type: 'POST',
	url: "../ajax/default.php",
	//async: false,			 
	data: {delLiveDigit:1,val:val},	  
	success: function(ajaxresult){	     
		location.reload();	 	
	},
	error: function(XMLHttpRequest, textStatus, errorThrown) { 
	alert('Error');
	}
	});
	
	}	
	
	 
	
}


 
</script> 
		 
<?php 

    $Rs1t = mysql_query("select * from    splitCalE   "); 
    $key = 1;
    while($rw1 = mysql_fetch_object($Rs1t))
    {
         $SplitFor[$key] = $rw1->cal1;
         $key++;
    } 
     
     
    function functionCheck($id,$cal)
    {    
      $RowsCt = mysql_num_rows(mysql_query("select * from   splitCalc  where calcId = $id and col = $cal "));   
      
      if($RowsCt > 0)
      {
          $Rst = mysql_fetch_object(mysql_query("select splitAmt from   splitCalc  where calcId = $id and col = $cal "));  
          return $Rst->splitAmt;
      }else  
        return "";
    }
?>		 
		<div class="col-md-10">  
  			<div class="content-box-large">
  				<div class="panel-heading">
					<div class="panel-title"><h3> Live Results</h3></div>
					
					<!--div align="right"> 
					
					<input type="button"    class="btn btn-warning" name="btnback" id="btnback" value=" Add New Result " onClick="javascript:location.href='add.php';" />
					</div--> 
					
				    <div align="right"> 
				           <SPAN  class="btn btn-warning" >YES</SPAN> 
				    </div>
					
				</div>
				
					<?php              
                            $aryX[] = 10; 
                            $aryY[] = 10;
                            $BlockR = mysql_query("select * from   replaceDigit    ");
                            while($Brst = mysql_fetch_object($BlockR))  
                            {
                                $aryX[] = $Brst->repalceFor;
                                $aryY[] = $Brst->digit;
                            }
                ?>
			
				
  				<div class="panel-body">
  				    
  				    	<Br>	<Br>	<Br>	<Br>
  					<table cellpadding="0" cellspacing="0" border="0" class="table table-striped table-bordered" id="example">
						<thead>
							<tr>
								<th>Sr</th>  
								<th>Market</th>  
								<th><?php if(array_search(0,$aryX)) { ?> <strike>0</strike> <?php echo "=".$aryY[array_search(0,$aryX)]; ?> <a href="javascript:void(0);" onclick="delD(0)" style="font-size:14px;">Del</a><?php } else echo 0; ?></th> 
								<th><?php if(array_search(1,$aryX)) { ?> <strike>1</strike> <?php echo "=".$aryY[array_search(1,$aryX)]; ?> <a href="javascript:void(0);" onclick="delD(1)" style="font-size:14px;">Del</a><?php } else echo 1; ?></th> 
							    <th><?php if(array_search(2,$aryX)) { ?> <strike>2</strike> <?php echo "=".$aryY[array_search(2,$aryX)]; ?> <a href="javascript:void(0);" onclick="delD(2)" style="font-size:14px;">Del</a><?php } else echo 2; ?></th> 
								<th><?php if(array_search(3,$aryX)) { ?> <strike>3</strike> <?php echo "=".$aryY[array_search(3,$aryX)]; ?> <a href="javascript:void(0);" onclick="delD(3)" style="font-size:14px;">Del</a><?php } else echo 3; ?></th> 
							    <th><?php if(array_search(4,$aryX)) { ?> <strike>4</strike> <?php echo "=".$aryY[array_search(4,$aryX)]; ?> <a href="javascript:void(0);" onclick="delD(4)" style="font-size:14px;">Del</a><?php } else echo 4; ?></th> 
								<th><?php if(array_search(5,$aryX)) { ?> <strike>5</strike> <?php echo "=".$aryY[array_search(5,$aryX)]; ?> <a href="javascript:void(0);" onclick="delD(5)" style="font-size:14px;">Del</a><?php } else echo 5; ?></th> 
							    <th><?php if(array_search(6,$aryX)) { ?> <strike>6</strike> <?php echo "=".$aryY[array_search(6,$aryX)]; ?> <a href="javascript:void(0);" onclick="delD(6)" style="font-size:14px;">Del</a><?php } else echo 6; ?></th> 
								<th><?php if(array_search(7,$aryX)) { ?> <strike>7</strike> <?php echo "=".$aryY[array_search(7,$aryX)]; ?> <a href="javascript:void(0);" onclick="delD(7)" style="font-size:14px;">Del</a><?php } else echo 7; ?></th> 
							    <th><?php if(array_search(8,$aryX)) { ?> <strike>8</strike> <?php echo "=".$aryY[array_search(8,$aryX)]; ?> <a href="javascript:void(0);" onclick="delD(8)" style="font-size:14px;">Del</a><?php } else echo 8; ?></th> 
								<th><?php if(array_search(9,$aryX)) { ?> <strike>9</strike> <?php echo "=".$aryY[array_search(9,$aryX)]; ?> <a href="javascript:void(0);" onclick="delD(9)" style="font-size:14px;">Del</a><?php } else echo 9; ?></th> 
						         <th>Action/<a href="replace.php">Replace</a></th> 
								 
							</tr>
						</thead>
						<tbody>
							<?php
							 
                            
                                    $Tdate= date("Y-m-d"); 
                                    $aryD[] = 10;
                                    
                                    $BlockR = mysql_query("select * from  blockedD where Tdate = '$Tdate' ");
                                    while($Brst = mysql_fetch_object($BlockR)) 
                                     $aryD[] =$Brst->digit;
                                     
                                     
								  $sr = mysql_num_rows(mysql_query("select * from  calc     order by id desc")); 
								  $CT = $sr;
								  
								  $result = mysql_query("select * from  calc     order by id desc"); 
								  while($row = mysql_fetch_object($result))
								  { 
    							        $TT = 0; 
    							        $rws = mysql_fetch_object(mysql_query("select * from  calcWin where rowid =  $row->id ")); 
    							        
    							        
    							         
    							     
                                        $old_date = $row->tDate;
                                        $old_date_timestamp = strtotime($old_date);
                                        $check_in =  date('Y-m-d', $old_date_timestamp); 
                                          
                                        $today = date("Y-m-d");
								        //if($today ==$check_in)
								        {      
							?>
							<tr class="odd gradeX">
								<td><b><?php echo $sr--;?></b> </td>  
								<td style="font-size:10px;" <?php if($rws->digit==0) { ?>  style="background:green;color:#fff" <?php  } ?>    <?php  if(array_search(0,$aryD)) {   ?>  style="background:red;color:#fff" <?php  } ?>  ><?php echo substr($row->market,0,15);?></td>
								<td <?php if(array_search(0,$SplitFor)) {  if( ($sr == ($CT-1)) ) { ?> style="color:red;" <?php }  }  ?> >
								    <?php echo $row->zero;?>  
								     <?php 
								        $returnAmt = functionCheck($row->id,0);   
							        ?>
							        <span style="font-size:12px;">
							        <?php
								        if($returnAmt!='')
								        echo "(split ".$returnAmt.") = ".($row->zero+$returnAmt); 
								         $TT += $returnAmt+$row->zero;  
								    ?>  
								    </span>
								</td>  
								<td <?php if(array_search(1,$SplitFor)) {  if( ($sr == ($CT-1)) ) { ?> style="color:red;" <?php }  }  ?> <?php if($rws->digit==1) { ?>  style="background:green;color:#fff" <?php  } ?>   <?php if(array_search(1,$aryD)) {?>  style="background:red;color:#fff" <?php  } ?> >
							        <?php echo $row->one;?>
								        
							        <?php 
								        $returnAmt = functionCheck($row->id,1);  
							        ?>
							        <span style="font-size:12px;">
							        <?php
								        if($returnAmt!='')
								        echo "(split ".$returnAmt.") = ".($row->one+$returnAmt); 
								        $TT += $returnAmt+$row->one;  
								    ?>
								    </span>
								
								</td>  
								<td <?php if(array_search(2,$SplitFor)) {  if( ($sr == ($CT-1)) ) { ?> style="color:red;" <?php }  }  ?>  <?php if($rws->digit==2) { ?>  style="background:green;color:#fff" <?php  } ?>   <?php if(array_search(2,$aryD)) { ?>  style="background:red;color:#fff" <?php  } ?>>
								    <?php echo $row->two;?> 
							        <?php 
								        $returnAmt = functionCheck($row->id,2);  
							        ?>
							        <span style="font-size:12px;">
							        <?php
								        if($returnAmt!='')
								        echo "(split ".$returnAmt.") = ".($row->two+$returnAmt);
								        
								        $TT += $returnAmt+$row->two;  
								    ?>
								    </span>
								    
								</td>  
								<td <?php if(array_search(3,$SplitFor)) {  if( ($sr == ($CT-1)) ) { ?> style="color:red;" <?php }  }  ?> <?php if($rws->digit==3) { ?>  style="background:green;color:#fff" <?php  } ?>  <?php if(array_search(3,$aryD)) { ?>  style="background:red;color:#fff" <?php  } ?> >
								    <?php echo $row->three;?> 
								    <?php 
								        $returnAmt = functionCheck($row->id,3);  
							        ?>
							        <span style="font-size:12px;">
							        <?php
								        if($returnAmt!='')
								        echo "(split ".$returnAmt.") = ".($row->three+$returnAmt);
								        
								        $TT += $returnAmt+$row->three;  
								    ?>
								    </span>
								</td>  
								<td <?php if(array_search(4,$SplitFor)) {  if( ($sr == ($CT-1)) ) { ?> style="color:red;" <?php }  }  ?> <?php if($rws->digit==4) { ?>  style="background:green;color:#fff" <?php  } ?>   <?php  if(array_search(4,$aryD)) { ?>  style="background:red;color:#fff" <?php  } ?>>
								    <?php echo $row->four;?>
								        
							         <?php 
								        $returnAmt = functionCheck($row->id,4);  
							        ?>
							        <span style="font-size:12px;">
							        <?php
								        if($returnAmt!='')
								        echo "(split ".$returnAmt.") = ".($row->four+$returnAmt);
								        
								        $TT += $returnAmt+$row->four;  
								    ?>
								    </span>
								
								</td>  
								<td <?php if(array_search(5,$SplitFor)) {  if( ($sr == ($CT-1)) ) { ?> style="color:red;" <?php }  }  ?> <?php if($rws->digit==5) { ?>  style="background:green;color:#fff" <?php  } ?>  <?php  if(array_search(5,$aryD)) {  ?>  style="background:red;color:#fff" <?php  } ?> >
								    <?php echo $row->five;?>   
							         <?php 
								        $returnAmt = functionCheck($row->id,5);  
							        ?>
							        <span style="font-size:12px;">
							        <?php
								        if($returnAmt!='')
								        echo "(split ".$returnAmt.") = ".($row->five+$returnAmt);
								        
								        $TT += $returnAmt+$row->five; 
								    ?>
								    </span>
							    </td>  
								<td <?php if(array_search(6,$SplitFor)) {  if( ($sr == ($CT-1)) ) { ?> style="color:red;" <?php }  }  ?> <?php if($rws->digit==6) { ?>  style="background:green;color:#fff" <?php  } ?>   <?php if(array_search(6,$aryD)) { ?>  style="background:red;color:#fff" <?php  } ?>>
								    <?php echo $row->six;?>
								  <?php 
								        $returnAmt = functionCheck($row->id,6);  
							        ?>
							        <span style="font-size:12px;">
							        <?php
								        if($returnAmt!='')
								        echo "(split ".$returnAmt.") = ".($row->six+$returnAmt);
								        
								        $TT += $returnAmt+$row->six; 
								    ?>
								    </span>
								    
								</td>  
								<td <?php if(array_search(7,$SplitFor)) {  if( ($sr == ($CT-1)) ) { ?> style="color:red;" <?php }  }  ?> <?php if($rws->digit==7) { ?>  style="background:green;color:#fff" <?php  } ?>   <?php if(array_search(7,$aryD)) { ?>  style="background:red;color:#fff" <?php  } ?>>
								    <?php echo $row->seven;?>
								    <?php 
								        $returnAmt = functionCheck($row->id,7);  
							        ?>
							        <span style="font-size:12px;">
							        <?php
								        if($returnAmt!='')
								        echo "(split ".$returnAmt.") = ".($row->seven+$returnAmt);
								        
								        $TT += $returnAmt+$row->seven; 
								    ?>
								    </span>
								</td>  
								<td <?php if(array_search(8,$SplitFor)) {  if( ($sr == ($CT-1)) ) { ?> style="color:red;" <?php }  }  ?> <?php if($rws->digit==8) { ?>  style="background:green;color:#fff" <?php  } ?>  <?php if(array_search(8,$aryD)) { ?>  style="background:red;color:#fff" <?php  } ?>  >
								    <?php echo $row->eight;?>
								    <?php 
								        $returnAmt = functionCheck($row->id,8);  
							        ?>
							        <span style="font-size:12px;">
							        <?php
								        if($returnAmt!='')
								        echo "(split ".$returnAmt.") = ".($row->eight+$returnAmt);
								        
								        $TT += $returnAmt+$row->eight; 
								    ?>
								    </span>
								</td>  
								<td <?php if(array_search(9,$SplitFor)) {  if( ($sr == ($CT-1)) ) { ?> style="color:red;" <?php }  }  ?> <?php if($rws->digit==9) { ?>  style="background:green;color:#fff" <?php  } ?>  <?php if(array_search(9,$aryD)) { ?>  style="background:red;color:#fff" <?php  } ?>>
								    <?php echo $row->nine;?>
								
								 <?php 
								        $returnAmt = functionCheck($row->id,9);  
							        ?>
							        <span style="font-size:12px;">
							        <?php
								        if($returnAmt!='')
								        echo "(split ".$returnAmt.") = ".($row->nine+$returnAmt);
								        
								        $TT += $returnAmt+$row->nine; 
								    ?>
								    </span>
								</td>  
								   
								<td class="center" >
								    <?php 
								    
								    $Shw = ($CT-2);
								    if($sr >= $Shw ) 
								    { 
								    ?>
								    <a  style="font-size:12px;" href="editcalc.php?id=<?php echo $row->id;?>"> Add </a> / 
								    <a  style="font-size:12px;" href="editcalcU.php?id=<?php echo $row->id;?>"> Update</a>
									<?php   
								    }  
									    echo   "<span style='color:blue;font-size:12px;font-weight:bold'>".($TT)."</span>";
									    $Ftotal += $TT;	
									?> 
						    </td> 
							</tr>  
							<?php }
							
							}
							?>
						</tbody>
					</table>
					
					Final Total : <?php echo $Ftotal;?>
  				</div>
  			</div>
		  </div>
		</div>
    </div>  
<?php  include ABS_PATH.'/admin/footer.php';	?>    