<?php
@session_start();
	if($_SESSION['id'] != ''){
		
	}else{
		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" >

<link rel="stylesheet" type="text/css" href="<?php echo SITEURL?>/css/style.css">

</head>

<body style="background-color: rgb(204, 238, 150);">
	<div class="container">
		<div class="row inline">
			<div class="navstyle">
				

				
            </div>
        </div>
        <div class="row inline" style="float: left; width: 100%; background-color: white; min-height: 500px;">
        <?php
			$sql = 'SELECT userCode FROM '.$DB->pre.'users WHERE id="'.intval($_SESSION['id']).'"';
			$D = $DB->dbrow($sql);
        	
			$sqlB = 'SELECT balance FROM '.$DB->pre.'balance WHERE userCode="'.strtoupper($D['userCode']).'" ORDER BY balanceID DESC limit 0,1';
			$B = $DB->dbRow($sqlB);
			
		?>
            <h4 style="text-align: center;">Ajent Balance : <?php echo $B['balance']?> </h4>
			<div class="menus">
                <ul>
                   <?php echo innerAdminMenu();?>
                </ul>
		    </div>

		

		<div class="row">
			<div id="ajent_table02" >
            	

                <div id="ajent_table02" style="width: 70%;  ">
                    <table border="1px">
                      <tr>
                        <th>User ID </th>
                        <th>Log Time </th>
                        <th>IP Address</th>
                        
                      </tr>
                      <?php
                      	$sql = 'SELECT U.name,L.ipAddress,L.logTime,U.userType,U.id,max(L.id) as logid,U.userCode FROM '.$DB->pre.'users as U
							LEFT JOIN '.$DB->pre.'user_logs as L on U.id = L.userID 
							WHERE   L.logDate="'.date('Y-m-d').'" AND L.logStatus="1"  AND underHead="'.$_SESSION['id'].'"  group by U.name';
						$D = $DB->dbRows($sql);
					foreach($D as $D){
						
						?>
                        <tr>
                        	<td><?php echo $D['userCode']; ?></td>
                            <td><?php echo $D['logTime']; ?></td>
                            <td><?php echo $D['ipAddress']; ?></td>
                        </tr>
                        <?php
						if($D['userType'] == '2'){
							echo getAgentUserLive($D['id']);
						}
					}
					  ?>
                    </table>
    
                </div>


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

        
	</div>
<?php

function getAgentUserLive($ID){
	global $DB;
	$sql = 'SELECT U.name,L.ipAddress,L.logTime,U.userType,U.id,max(L.id) as logid FROM '.$DB->pre.'users as U
							LEFT JOIN '.$DB->pre.'user_logs as L on U.id = L.userID 
							WHERE   L.logDate="'.date('Y-m-d').'" AND L.logStatus="1"  AND underHead="'.$ID.'"  group by U.name';
						$D = $DB->dbRows($sql);
	$tot = 0;
	foreach($D as $D){
		
		$str .= '
			<tr>
				<td>'.$D['userCode'].'</td>
				<td>'.$D['logTime'].'</td>                    
				<td>'.$D['ipAddress'].'</td>
			  </tr>
		
		';
			
		if($D['userType'] == '2'){
			getAgentUserLive($D['id']);
		}
	}
}

?>
</body>
</html>
