<?php

@session_start();
if($_SESSION['SECEXP'] !=''){

	}else{
		echo "Go And Fuck Your Self";die;
	}

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=11" >
<!--[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">
</head>

<body>
	<div class="container">
    <input id="hideAdminID" name="hideAdminID" type="hidden" value="<?php echo $_REQUEST['id']?>">
                        <input id="hideDrawTime" name="hideDrawTime" type="hidden" value="<?php echo drawTime();?>">
		<div class="menus">
          <ul style="">
              <?php echo innerAdminMenu()?>
          </ul>
        </div>

		<div class="row">
			<div id="table02" style="width: 664px; float: left; background-color: #6F9">
            	<table>
                	<tr>
                    	<th>Time </th>
                        <th>Play </th>
                        <th>Cancel </th>
                        <th>Win </th>
                        <th>(+/-) </th>
                    </tr>
                    <?php
                    $sql = 'SELECT * FROM '.$DB->pre.'users WHERE (underHead="'.$_REQUEST['id'].'") AND userType="2" AND isActive="1"';
					$D = $DB->dbRows($sql);
					
					$retailer = '';
					foreach($D as $D){
					$sqlR = 'SELECT id FROM '.$DB->pre.'users WHERE underHead="'.$D['id'].'" AND isActive="1" AND userType="3"';
					$R = $DB->dbRows($sqlR);
					$win = '';
					
					foreach($R as $R){ 
							$retailer .= $R['id'].',';
					}
					$retailer = substr($retailer, 0, -1);
							
						
					
					}
					
					$sqlT = 'SELECT distinct(lotTime) FROM mx_lottary WHERE uID in("'.$retailer.'") AND lotDate="'.date('Y-m-d').'" order BY lotID';
					$T = $DB->dbRows($sqlT);
					$tot = 0;
					foreach($T as $T){
							$exp = explode(',',$retailer);
							$win = 0;
							foreach($exp as $exp){
								$win += winClaimeAdmin4($exp,$T['lotTime']);
							}
							
							$sqlL = 'SELECT sum(distinct(ticketTot)) as T FROM '.$DB->pre.'lottary WHERE uID in("'.$retailer.'") AND lotdate="'.date('Y-m-d').'" AND lotTime="'.$T['lotTime'].'"  GROUP BY tranID';
							$L = $DB->dbRows($sqlL);
							$tot = getSale4($L);
							
							$sqlL1 = 'SELECT sum(distinct(ticketTot)) as T FROM '.$DB->pre.'lottary WHERE uID in("'.$retailer.'") AND lotdate="'.date('Y-m-d').'" AND lotTime="'.$T['lotTime'].'" AND status="0"  GROUP BY tranID';
							$L1 = $DB->dbRows($sqlL1);
							$tot1 = getSale4($L1);
							
							?>
                            <tr>
                                <td><a href="<?php echo SITEURL?>/wining-list/?u=<?php echo $_REQUEST['u']?>&flag=<?php echo $_REQUEST['flag']?>&id=<?php echo $_REQUEST['id']?>&lotTime=<?php echo $T['lotTime']?>"><?php  echo $T['lotTime'];?></a></td>
                                <td><?php  echo $tot;?></td>
                                <td><?php  echo $tot1;?></td>
                                <td><?php echo $win;?></td>
                                <td><?php  echo ($tot-$win);?></td>
                            </tr>
                            <?php
					}
					
					
					
					?>
                    
                    
                    
                </table>
			</div>
            
            <div id="table02" style="width:670px; float:right; background-color:#FFC;">
            	<table>
                	<tr>
                    	<th>Time </th>
                        <th>Play </th>
                        <th>Cancel </th>
                        <th>Win </th>
                        <th>(+/-) </th>
                    </tr>
                    
                    
                </table>
            </div>
				
			
		</div>

	</div>
<?php

function getSale4($L){
	$tot = 0;
	foreach($L as $L){
		$tot +=$L['T'];
	}
	return $tot;
}
		
function winClaimeAdmin4($userID,$time){
	global $DB;					 
	$sql = 'SELECT * FROM '.$DB->pre.'result_win WHERE uID="'.$userID.'" AND lotTime="'.$time.'" AND lotdate="'.date('Y-m-d').'"';
	$S = $DB->dbRows($sql);
	$sqlU = 'SELECT winrate FROM '.$DB->pre.'users WHERE id="'.$userID.'"';
	$U = $DB->dbRow($sqlU);
	//print_r($S);
	$point = 0;
	$cv = 0;
	foreach($S as $S){

		$point += ($S['point']*$U['winrate'])*$S['cv'];
		//$cv += $S['cv'];
		
	}
	$str = $point;
	return ($str);

}

?>
</body>
</html>
