<?php @session_start();?>
<?php


	//header( 'Content-type: text/html; charset=utf-8');
	if(isset($_REQUEST['bntSubmit'])){
		saveResultNew();
		
		header('Location:'.SITEURL.'/ticket/?u='.$_REQUEST['u'].'&flag=1&id='.$_REQUEST['id'].'&tran='.$_REQUEST['tran'].'&userID='.$_REQUEST['userID'].'&adminID='.$_REQUEST['adminID'],true,307);
		//echo "in";
	}
	
	
	
	
	
	
?>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<!--[if IE 7]>
<link rel="stylesheet" type="text/css" href="<?php echo SITEURL?>/css/ie7.css">
<![endif]-->
<!--[if IE 8]>
<link rel="stylesheet" type="text/css" href="<?php echo SITEURL?>/css/ie7.css">
<![endif]-->
<link rel="stylesheet" type="text/css" href="<?php echo SITEURL?>/css/ie7.css">
<style>
.tick01{
	display:inline;
}
</style>


</head>

<body style="background:#FFF;" id="tblData">
	<div class="container">
		<div class="row inline">
			
			<div class="menus">
      <ul style="">
          <?php echo innerAdminMenu()?>
      </ul>
    </div>
    </div>

		</div>

		<div class="row" style=" background:#fff;">
			<div class="a-form" style="width: 100%;">
				<div style=" background-color:#fff;">
                <?php
                	$sql1 = 'SELECT * FROM '.$DB->pre.'lottary WHERE tranID="'.$_REQUEST['tran'].'"';
						$D1 = $DB->dbRow($sql1);
						//echo $datetime_from = date("h:i", strtotime("-15 minutes", strtotime(drawTime())));
				?>
					<b>SHREE ONLINE </b></br>
					<b>For Amusement Only</b></br>
					<b>Dr. <?php echo $D1['lotdate']?> <?php echo $D1['lotTime']?> </b></br>
                    <b>Print Time <?php echo $D1['printTime']?> </b></br>
					<b>Per Ticket Point <?php echo $D1['point']?>.00 Total Point <?php echo $D1['ticketTot']?><b></br>
					<b><?php echo date('d-M-Y');?><b></br>
					<b style="background-color:#2FFDFD">Retailer Code 
					<?php
                    	$sqlN = 'SELECT userCode FROM '.$DB->pre.'users WHERE id="'.$D1['uID'].'"';
						$N = $DB->dbRow($sqlN);
						echo $N['userCode'];
					
					?> </b></br></br>
                    <b>Code: <?php echo $D1['tranID']?></b>
				</div>
				<div class="ticket_1" style="background-color: rgb(255, 255, 255);">
					<table border="1" width="58%" cellspacing="1">
					<tr>
						<th>Number </th>
						<th>Qty</th>
						<th>Number </th>
						<th>Qty</th>
						<th>Number </th>
						<th>Qty</th>
                        <th>Number </th>
						<th>Qty</th>
					</tr>
				


				
					<?php

						$start = microtime(true);
						$drawTime = drawTime();
						//$drawTime = '4:15';
						
					  	 $sql = '
							  select lotnum, cellID,barcode, sernum, lotDate, lotTime, GROUP_CONCAT(lotID) as lotID, count(cellID) as tc, isadvance, status,(sumcv) as sumcv, GROUP_CONCAT(userCode) as userCode, GROUP_CONCAT(LT) as LT, lotteryID,cv From ( SELECT distinct L.cv,L.lotnum,L.cellID,L.uID,L.sernum,L.lotdate,L.lottime,L.lotID as lotteryID, max(R.lotID) as lotID,R.lotnum as LT, L.isadvance,L.status, ((L.cv)*L.point) as sumcv ,concat(U.userCode,"[", (sum(L.cv)*L.point),"]") as userCode,L.barcode FROM mx_lottary as L 
                              Inner JOIN mx_users as U on U.id = L.uID AND U.userType="3" AND U.adminID="1"
                              left join mx_result_tran R on L.lotID = R.lID 
                              WHERE  L.lotdate="'.date('Y-m-d').'" AND L.lotTime="'.$drawTime.'"    AND L.cellID IN (Select L1.cellID from mx_lottary L1 where L1.tranID="'.$_REQUEST['tran'].'") group by L.uID, L.cellID ORDER BY L.cellID ) P group by P.cellID order by cellID
						
						';
                      $sqlCV = 'SELECT cv FROM '.$DB->pre.'lottary WHERE barcode="'.$_REQUEST['tran'].'" ORDER BY cellID';
						$CV = $DB->dbRows($sqlCV);
					/*	$sql = '
							 select lotnum,cellID,barcode,sernum, lotDate, lotTime,(lotID) as lotID, count(cellID) as tc, isadvance, status,(sumcv) as sumcv, GROUP_CONCAT(userCode) as userCode, GROUP_CONCAT(LT) as LT, lotteryID,cv 
From ( 
SELECT distinct L.cv,L.lotnum,L.cellID,L.uID,L.sernum,L.lotdate,L.lottime,L.lotID as lotteryID, 
(select (R1.lotID) from mx_result_tran R1 where R1.cellID=L.cellID and R1.lotdate=L.lotdate and R1.lotTime=L.lotTime)
 as lotID,(select (R2.lotnum) from mx_result_tran R2 where R2.cellID=L.cellID and R2.lotdate=L.lotdate and R2.lotTime=L.lotTime) as LT , L.isadvance,L.status, ((L.cv)*L.point) as sumcv ,concat(U.userCode,"[", (sum(L.cv)*L.point),"]") as userCode,L.barcode 
FROM mx_lottary as L Inner JOIN mx_users as U on U.id = L.uID AND U.userType="3" AND U.adminID="'.$_REQUEST['adminID'].'" left join mx_result_tran R on L.lotID = R.lID 
WHERE L.lotdate="'.date('Y-m-d').'" AND L.lotTime="'.$drawTime.'" AND (L.cellID,L.tranID) IN 
(
Select L1.cellID,L1.tranID from mx_lottary L1 where L1.tranID="'.$_REQUEST['tran'].'") group by L.uID, L.cellID ORDER BY L.cellID ) P group by P.cellID order by cellID
							
						';*/
						$D = $DB->dbRows($sql);
						$end = microtime(true);
						echo ($end-$start);
						$trLeft = '';
						$flag = 0;
						$barcode = '';
                      	
                      	$resultLot = array();
                        $sqlLT = 'SELECT lotnum FROM '.$DB->pre.'result_tran WHERE uID="1" AND lotTime="'.$drawTime.'" AND lotdate="'.date('Y-m-d').'" AND lID IS NOT NULL';
						$LT = $DB->dbRows($sqlLT);
                      	foreach($LT as $k=>$LT){
							$resultLot[$k] = $LT['lotnum'];
						}
                     // print_r($resultLot);
						foreach($D as $k=>$D){
							$barcode = $D['barcode'];
							if($flag < 1){
								$trLeft .= '<tr>';
							}
							$css = '';
							$msg = '';
							if(in_array($D['lotnum'],$resultLot)){
								$css = ' style="padding:3%;background-color:purple;color:#fff;"';
							}
							
							//echo $C1['lotID'].'--'.$D['cellID'].'<br>';
							if($D['lotID'] != ''){
								$css = ' style="background-color:yellow"';

							}
                         
							if($D['isadvance'] == '1'){
								$msg = 'ADV';

							}
							if($D['status'] == '0'){
								$msg = 'Cancel';

							}
							
							
							if($flag < 3){
								$trCell = '';
								$trCell = $D['cellID'];
								//$str = getUserCell($D['cellID'],$D['lotnum'],$D1['lotTime']);
								
								$trLeft .= '<td align="center" '.$css.' id="t'.($k+1).'">'.$msg.'
								<form id="" name="" action="" method="GET">
								<input id="tran" name="tran" type="hidden" value="'.$_REQUEST['tran'].'">
								<input id="userID" name="userID" type="hidden" value="'.$_REQUEST['userID'].'">
								<input id="adminID" name="adminID" type="hidden" value="1">
							  	<input id="id" name="id" value="1" type="hidden">
								<input id="u" name="u" value="'.$_REQUEST['u'].'" type="hidden">
								<input id="rLotID" name="rLotID" type="hidden" value="'.$D['lotteryID'].'">
								<input id="flag" name="flag" type="hidden" value="1">
								<input id="attr" type="hidden" name="attr" value="'.$D['cellID'].'~'.$D['sernum'].'~'.$D['lotnum'].'~'.date('Y-m-d').'~'.$D['lotTime'].'~1">
							  	<button id="bntSubmit" value="1" name="bntSubmit" type="submit">'.$trCell.'</button>
							  </form>
								</br>'.(($CV[$k]['cv']*$D1['point'])*90).'<br>'.$D['userCode'].'</td>';
								$trLeft .= '<td align="center"  id="t'.($k+1).'">'.$CV[$k]['cv'].'</br>'.$str.'</td>';
								$flag++;
							}else{
								$trCell = '';
								$trCell = $D['cellID'];
								//$str = getUserCell($D['cellID'],$D['lotnum'],$D1['lotTime']);
								
								$trLeft .= '<td align="center" '.$css.' id="t'.($k+1).'">
								<form id="" name="" action="" method="GET">
								<input id="tran" name="tran" type="hidden" value="'.$_REQUEST['tran'].'">
								<input id="userID" name="userID" type="hidden" value="'.$_REQUEST['userID'].'">
								<input id="adminID" name="adminID" type="hidden" value="1">
							  	<input id="id" name="id" value="'.$_REQUEST['id'].'" type="hidden">
								<input id="rLotID" name="rLotID" type="hidden" value="'.$D['lotteryID'].'">
								<input id="u" name="u" value="'.$_REQUEST['u'].'" type="hidden">
								<input id="flag" name="flag" type="hidden" value="1">
								<input id="attr" type="hidden" name="attr" value="'.$D['cellID'].'~'.$D['sernum'].'~'.$D['lotnum'].'~'.date('Y-m-d').'~'.$D['lotTime'].'~1">
							  	<button id="bntSubmit" value="1" name="bntSubmit" type="submit">'.$trCell.'</button>
							  </form>
								
								</br>'.(($CV[$k]['cv']*$D1['point'])*90).'<br>'.$D['userCode'].'</td>';
								$trLeft .= '<td align="center" id="t'.($k+1).'">'.$CV[$k]['cv'].'</br>'.$str.'</td>';
								$trLeft .= '</tr>';
								$flag = 0;
							}
							?>
							
								

							
							<?php

						}
						
						echo $trLeft;
					?>
                    
				<tr>
                	<td colspan="6" valign="middle" style="border:0px;"></br><center><img class="barcode" src="<?php echo SITEURL?>/inc/barcode.php?text=<?php echo trim($D1['barcode'])?>&print=true"></center></td>
                </tr>	
			
						
</table>

						

						

						


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

	</div>

</body>
</html>
<?php
//flush();               // - Make sure all buffers are flushed
//ob_flush();
//exit();

	
	

?>
<script type="text/javascript">
/*function setUserWin(attr,lotteryID,id){
	//alert(attr+"----"+lotteryID);return false;
	var SITEURL = 'http://www.vidyacf.com/mr-admin';
	//var SITEURL = 'http://localhost/mr-admin'
	var xmlhttp = new XMLHttpRequest();
	var url = SITEURL+"/mod/page/x-page.inc.php?xAction=saveResult&attr="+attr+"&rLotID="+lotteryID;
 // alert(url);
	document.getElementById(id).style.backgroundColor='#fff';
	xmlhttp.open("POST",url,false);
	xmlhttp.send();
	var str = xmlhttp.responseText;
  //alert(str);
	//var data = JSON.parse(str);
	//
	if(str == 'OK'){
		document.getElementById(id).style.backgroundColor='yellow';
	}
  location.reload();

}*/
</script>
<script>
  document.getElementById('tblData').focus();
document.onkeydown = getBackBtn;
function getBackBtn(){

	var key = event.which || event.keyCode || event.charCode; 
	//alert(key+"-----"+'<?php echo SITEURL?>/live-betting/?u=<?php echo $_REQUEST['u']?>&flag=1&id=<?php echo $_REQUEST['id']?>');
	
	if(key == 8){
		location.href = '<?php echo SITEURL?>/live-betting/?u=<?php echo $_REQUEST['u']?>&flag=1&id=<?php echo $_REQUEST['id']?>'
      //window.history.go(-1);
	}
}
</script>
