<?php 

@session_start();


	if($_REQUEST['id'] !=''){

	}else{
		die;
	}
	
	if($_REQUEST['saveFlag'] == '1'){
		saveResult();
	}
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 <meta http-equiv="refresh" content="20">
<!--[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/ie11.css">

<style>
.three_in_one_b{
	display:inline;
}
</style>

</head>

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

        </div>
        <div class="row" align="center">
            <p>
                Date: &nbsp; <?php echo date('Y-m-d')?> &emsp; Time:&nbsp; <?php echo date('h:i')?> &nbsp;::&nbsp; Point :: 
                <b style="color:red; font-size:27px;">
                <?php
                  $sqlB1 = 'SELECT balance FROM '.$DB->pre.'balance WHERE userCode="'.$_REQUEST['id'].'" ORDER BY balanceID DESC LIMIT 0,1';
                  $B1 = $DB->dbRow($sqlB1);
                    echo ($B1['balance']==''?'0000.00':$B1['balance']);
                ?>
                 &emsp;&emsp;&emsp;&emsp;&emsp; This  Round 0 </b>
                </p> 
        </div>

        <div class="row">
            <div class="bz" style="width: 100%; background-color: rgb(255, 255, 255);">
                <div class="bz_01" style="width:70%;float: left;">
                    <div class="first-row" id="first_menu"> 
                        <table border="1" width="100%"  cellspacing="0" style="background-color: #6F0">
                            <tr class="bett_menu0">
                                <th>User </th>
                                <th>W-Play </th>
                                <th>User </th>
                                <th>W-Play </th>
                                <th>User </th>
                                <th>W-Play </th>
                                <th>User </th>
                                <th>W-Play </th>
                            </tr>
					<?php
                    	$drawTime = drawTime();
                      //  $drawTime = '12:00';
						
						$sqlP = 'SELECT sum(distinct(L.ticketTot)) as S,tranID,U.userCode,L.* FROM mx_lottary as L 
									LEFT JOIN '.$DB->pre.'users as U on L.uID = U.id
									WHERE  L.lotTime="'.$drawTime.'" AND U.userType="3" AND L.lotDate="'.date('Y-m-d').'" AND U.adminID="'.$_REQUEST['id'].'" GROUP BY L.cellID ORDER BY lotnum ';
						$P = $DB->dbRows($sqlP);
						
						$trLeft = '';
						$flag = 0;
						$actCV = 0;
						foreach($P as $P){
							if($flag < 1){
								$trLeft .= '<tr>';
							}
							
							$css = '';
							$sqlC = 'SELECT lotID FROM '.$DB->pre.'result_tran WHERE lotnum="'.$P['lotnum'].'"  AND uID="'.$_REQUEST['id'].'" AND lotTime="'.$drawTime.'" AND lotdate="'.date('Y-m-d').'"';
							$C = $DB->dbRow($sqlC);
							if($C['lotID'] != ''){
								$css = ' style="padding:3%;background-color:purple;color:#fff;"';
							}
							
							$sqlC1 = 'SELECT lotID FROM '.$DB->pre.'result_tran WHERE lotnum="'.$P['lotnum'].'" AND cellID="'.$P['cellID'].'" AND lotTime="'.$drawTime.'"  AND uID="'.$_REQUEST['id'].'" AND lotdate="'.date('Y-m-d').'"';
							$C1 = $DB->dbRow($sqlC1);
							if($C1['lotID'] != ''){
								$css = ' style="padding:3%;background-color:yellow"';
							}
							
							if($flag < 4){
								 $cell = '';
								 $trCell = '';
								if(strlen($P['cellID']) == 1){
									$trCell = $P['lotnum'].'0'.$P['cellID'];

								}else{
									$trCell = $P['lotnum'].$P['cellID'];
								}
							  
							  	$cellCV = 0;
								$actCV = 0;
								$userCellCV = explode('~',getUserCell($P['uID'],$P['cellID'],$P['lotnum'],$drawTime));
								$cellCV = ($userCellCV[1]*90);
								$actCV = ($actCV+$cellCV);
							  	
							    $sqlTC = 'SELECT count(cellID) as C FROM '.$DB->pre.'lottary WHERE uID="'.$P['uID'].'" AND cellID="'.$P['cellID'].'" AND lotnum="'.$P['lotnum'].'" AND lotTime="'.$drawTime.'" AND lotdate="'.date('Y-m-d').'" ';
								$TC = $DB->dbRow($sqlTC);
							  
							  $trLeft .= '<td width="10%" align="center"'.$css.'>'.$userCellCV[0].'</td>';
							  $trLeft .= '<td width="10%"  align="center" '.$css.'>'.$actCV.'*'.$TC['C'].'</br><a href="'.SITEURL.'/live-betting/?adminID='.$_REQUEST['id'].'&u='.$_REQUEST['u'].'&flag=1&id='.$_REQUEST['id'].'&saveFlag=1&attr='.$P['cellID'].'~'.$P['sernum'].'~'.$P['lotnum'].'~'.$P['lotdate'].'~'.$P['lotTime'].'~'.$_REQUEST['id'].'"><button type="button">'.$trCell.'</button></a></td>';
							  $flag++;
							 
							 
							 }else{
								 $trLeft .= '</tr>';
								 $flag = 0;
							}
							
							
							
							
						}//$p foreach loop end
						
						echo $trLeft;
						
					?>                        

                   </table>     

                        

                    </div>
                </div>
				<?php
                
				$sqlP2 = 'SELECT sum(distinct(L.ticketTot)) as S,tranID,L.uID,U.userCode FROM mx_lottary as L 
											LEFT JOIN '.$DB->pre.'users as U on L.uID = U.id
											WHERE  L.lotTime="'.$drawTime.'" AND U.userType="3" AND L.lotDate="'.date('Y-m-d').'" AND U.adminID="'.$_REQUEST['id'].'" GROUP BY L.uID ORDER BY lotID DESC';
				$P2 = $DB->dbRows($sqlP2);
				
				 $sum = 0;
				 $tr = '';
				 $td = '';
			     $sum1 = 0;
				
				if(count($P2) > 0){
				
				
				foreach($P2 as $P2){					
					$sqlB2 = 'SELECT balance FROM '.$DB->pre.'balance WHERE userCode="'.$P2['userCode'].'" ORDER BY balanceID DESC LIMIT 0,1';
					$B2 = $DB->dbRow($sqlB2);
					$tr .= '<tr><td>'.$P2['userCode'].'-'.$B2['balance'].'</td><td>'.getTicketTot($drawTime,$P2['uID']).'</td><td colspan="4">'.showTickets($drawTime,$P2['uID']).'</td></tr>';
					
				 
				 
				}
				
				 
				$tr .= '</tr>';
				}
				
				
				?>
                <div class="bz_02" style="width:360px; float: right; background-color: #FFFFA4;">
                    <div id="table02" style="width:360px; float:right;">    <!--  <div id="table02" style="width:360px; float:right;">  -->
                        <table border="1" cellspacing="1">
                            <tr>
                                <th>Total </th>
                                <th>
                                    <?php
                                   

                                    echo $sum;
                                    ?>


                                </th>
                                <th><?php echo drawTime();?> </th>
                            </tr>
                            <tr>
                                <th>User Id </th>
                                <th>T.Amt </th>
                                <th>T.Amt </th>
                                <th>T.Amt </th>
                                <th>T.Amt </th>
                                <th>T.Amt </th>
                            </tr>
                            
                                    <?php echo $tr;?>
                                 
                            
                            
                            
                            
                        </table>
                    </div>
                </div>
            </div>
        </div>


    </div>

</body>
</html>

<?php

	function getUserCell($uID,$cellID,$lotnum,$drawTime){
		global $DB;
	
		$sqlU = 'SELECT L.cv,L.status,L.isadvance,L.point FROM '.$DB->pre.'lottary as L 
				 WHERE L.uID="'.$uID.'" AND L.cellID="'.$cellID.'" AND lotnum="'.$lotnum.'" AND L.lotTime="'.$drawTime.'" AND lotdate="'.date('Y-m-d').'"
							';
		$U = $DB->dbRows($sqlU);
		$html = '';
		$cv = 0;
		$adv = '';
		$cancel = '';
		foreach($U as $U){
			$point = 0;
			$point = ($U['cv']*$U['point']);
			$cv = ($cv+$point);
			if($U['isadvance'] == '1'){
				$adv = 1;
			}
			if($U['status'] == '0'){
				$cancel = 1;
			}
		}

		$sql = 'SELECT userCode FROM '.$DB->pre.'users WHERE id="'.$uID.'"';
		$D = $DB->dbRow($sql);
		if($adv == '1'){
				$html = 'ADV.'.strtoupper($D['userCode']).'['.$cv.']</br>';
		}else if($cancel == '1'){
				$html = 'Cancel.'.strtoupper($D['userCode']).'['.$cv.']</br>';
		}else{
			$html = strtoupper($D['userCode']).'['.$cv.']</br>';
		}
		return $html.'~'.$cv;
	
	}
	
	function getTicketTot($lotTime,$uID){
		global $DB;
		$sql = 'SELECT sum(distinct(L.ticketTot)) as S FROM mx_lottary as L WHERE L.lotTime="'.$lotTime.'" AND L.lotDate="'.date('Y-m-d').'" AND uID="'.$uID.'" GROUP BY L.tranID ';
		$D = $DB->dbRows($sql);
		$sum = 0;
		foreach($D as $D){
			$sum += $D['S'];
		}
		return $sum;
	}
	function showTickets($lotTime,$uID){
		global $DB;
		$sql = 'SELECT sum(distinct(L.ticketTot)) as S,tranID FROM mx_lottary as L WHERE L.lotTime="'.$lotTime.'" AND L.lotDate="'.date('Y-m-d').'" AND uID="'.$uID.'" GROUP BY L.tranID ORDER BY lotID DESC';
		$D = $DB->dbRows($sql);
		$flag = 0;
		$html = '';
		//print_r($D);
		foreach($D as $D){
			if($flag < 4){
				$html .= '<a href="'.SITEURL.'/ticket/?tran='.$D['tranID'].'&userID='.$uID.'&adminID='.$_REQUEST['id'].'&u='.$_REQUEST['u'].'&flag=1&id='.$_REQUEST['id'].'">'.$D['S'].'</a>&nbsp;&nbsp;&nbsp;';
				$flag++;	 
			}else{
				$html .= '<br><a href="'.SITEURL.'/ticket/?tran='.$D['tranID'].'&userID='.$uID.'&adminID='.$_REQUEST['id'].'&u='.$_REQUEST['u'].'&flag=1&id='.$_REQUEST['id'].'">'.$D['S'].'</a>&nbsp;&nbsp;&nbsp;';
				$flag = 0;
			}

			
		}
		return $html;
	}


?>
