<?php 	include_once('../../config.php');   	
		include_once(ABS_PATH.'/admin/login_check.php');    
?>  
<?php  include ABS_PATH.'/admin/header.php';	?>  

<script>
function ConfirmOpen(name,rst,id)
{

	var r = confirm(name+" OPEN : "+rst+" === Do you want to update ?");
	  
	if (r == true) {    
	$.ajax({
	type: 'POST',
	url: "../ajax/default.php",
	//async: false,			 
	data: {OpenConf:1,name:name,rst:rst,id:id},	  
	success: function(ajaxresult){	     
		location.reload();	 	
	},
	error: function(XMLHttpRequest, textStatus, errorThrown) { 
	alert('Error');
	}
	});
	
	} 
}

function ConfirmClose(name,rst,id)
{
 
 var r = confirm(name+" CLOSE : "+rst+" === Do you want to update ?");
	  
	if (r == true) {    
	$.ajax({
	type: 'POST',
	url: "../ajax/default.php",
	//async: false,			 
	data: {CloseConf:1,name:name,rst:rst,id:id},	
	success: function(ajaxresult){	     
		location.reload();	 	
	},
	error: function(XMLHttpRequest, textStatus, errorThrown) { 
	alert('Error');
	}
	});
	
	}    
} 
</script>

 
		<div class="col-md-10">  
  			<div class="content-box-large">
  				<div class="panel-heading">
					<div class="panel-title"><h3 style="color:red">Today <?php echo date("d-M-y");?>  </h3></div>
					
					<!--div align="right">  <input type="button"    class="btn btn-warning" name="btnback" id="btnback" value=" Add New User " onClick="javascript:location.href='add_new.php';" />
					</div-->
					
				</div>
				
  				<div class="panel-body">
  					<table cellpadding="0" cellspacing="0" border="0" class="table table-striped table-bordered" id="example">
						<thead>
							<tr>
								<th>Sr</th>
								<th>Name</th>  	  
								<th>Result</th>   
								<th>Action</th> 
							</tr>
						</thead>
						<tbody>
							<?php
								  $result = mysql_query("select * from  Bazzar where is_active=1 and AppActive = 1  order by priority ");
								  $sr=1; 
								  $datepicker = date("d-M-Y");
								  while($row = mysql_fetch_object($result))
								  { 
                            			$RESULT = '***-**-***';					      
                                        $datepicker = date("Y-m-d");
                            			$todayRes=""; 
										$bazzarIdData = mysql_fetch_object(mysql_query("select * from live_result where bazzarId = $row->id"));
										
										$OPNE1 = '';
									    $CLOSE1 = '';
									    //
									    if($row->id!=23)
									    {
    										if($bazzarIdData->loadingDate==date("Y-m-d"))
    										{
    										    $RESULT = $bazzarIdData->value;  
    										    $BZOpen = null;
    										    $BZOpen = explode("-",$bazzarIdData->value);
    										    
    										    
    										    if(count($BZOpen) > 0)
    										        $OPNE1 = $BZOpen[0].'-'.$BZOpen[1][0];
    										      
    										    if( (count($BZOpen) > 1)  && ($BZOpen[2]!='') )      
    										        $CLOSE1 = $BZOpen[2].'-'.$BZOpen[1][1];
    										}
									    }else
									    {
									        $Tdate = date("Y-m-d");//2022-06-23
									        $CtN =mysql_num_rows(mysql_query("SELECT * FROM `expandBazzar` WHERE `fdate` = '$Tdate' and `bazzarId` = 23"));
									        if($CtN > 0)
									        {
    								            if($bazzarIdData->loadingDate==date("Y-m-d"))
        										{
        										    $RESULT = $bazzarIdData->value;  
        										    $BZOpen = null;
        										    $BZOpen = explode("-",$bazzarIdData->value);
        										    
        										    
        										    if(count($BZOpen) > 0)
        										        $OPNE1 = $BZOpen[0].'-'.$BZOpen[1][0];
        										      
        										    if( (count($BZOpen) > 1)  && ($BZOpen[2]!='') )      
        										        $CLOSE1 = $BZOpen[2].'-'.$BZOpen[1][1];
        										}
									        }
									    }
										
										 
										$confirmResults = mysql_fetch_object(mysql_query("select * from confirmResults where bazarId = $row->id and Tdate = '$datepicker' "));
										if($confirmResults->Bopen!='')
										    $Bopen =  1;
										 else
										    $Bopen =  0;
										    
										    
									 	if($confirmResults->Bclose!='')
										    $Bclose =  1;
										 else
										    $Bclose =  0;
										    
										       
							?>
							<tr class="odd gradeX">
								<td><?php echo $sr++;?> </td>
								<td><?php echo $row->name;?>  </td> 
								<td><?php echo $RESULT;?>  </td>  
								<td><?php if(($OPNE1!='')) {   ?>
								            <a href="javascript:void(0);" <?php if($Bopen==0) { ?> onclick="ConfirmOpen('<?php echo $row->name;?>','<?php echo $OPNE1;?>',<?php echo $row->id;?>)" <?php } ?> > <?php if($Bopen==0) { ?>  OPEN <?php } else { ?> <span style="color:green">UPDATED</span><?php } ?> </a> <?php } ?>
								            <?php if($CLOSE1!='') { ?> / 
								            <a href="javascript:void(0);" <?php if($Bclose==0) { ?> onclick="ConfirmClose('<?php echo $row->name;?>','<?php echo $CLOSE1;?>',<?php echo $row->id;?>)" <?php } ?>>   <?php if($Bclose==0) { ?> CLOSE <?php } else { ?> <span style="color:green">UPDATED</span><?php } ?></a>
								            <?php } ?> 
					            </td> 
							</tr>  
							<?php } ?>
						</tbody>
					</table>
  				</div>
  			</div>



		  </div>
		</div>
    </div>

<?php  include ABS_PATH.'/admin/footer.php';	?>    