<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<!--style sheets-->
<link rel="stylesheet" type="text/css" href="../css/scroll_table.css" />

<link href="../css/main.css" rel="stylesheet" type="text/css" />
<?php
include('../include/session.php');

include('../include/period_select_date.php');	
	
$table_name2 = $_SESSION['db_prefix']."_tracking_admin";
$tracking_query = "SELECT * FROM $table_name2 WHERE entry_date >= '".$start."' AND entry_date <= '".$end."' ";
$tracking_result = mySQL_query($tracking_query);
$tracking_num = mysql_num_rows($tracking_result);
?>

</head>

<body>
<?php
include ("../navigation/header.php");
$page_name = "AD-tracking";
include ("../navigation/access.php");

if ($permission_num==1) {
	include ("../navigation/admin_sidebar.php");
?>
<div class="main_frame">
  <div class="page_head_frame">
     <label class="label_page_head">Admin tracking</label></td>
  </div>
        <br />
<br />
<br />
<br />
<div class="page_middle_frame">
<?php
$page='tracking_admin.php';
$reference_name='';
$reference='';
include('../include/period_select_block.php');
?>
<div class="page_inside_frame">
<!--jscript-->
<script type="text/javascript" language="javascript" src="../jscript/jquery.dataTables.js"></script>
<script type="text/javascript" charset="utf-8">
			$(document).ready(function() {
				$('#scroll_table').dataTable( {
					"sScrollY": "500px",
					"bPaginate": false,
					"bScrollCollapse": true,
					"aaSorting": [[ 0, "desc" ]],
					"aoColumns": [
								{"iDataSort": 5},
                              	{"bSortable": true},
                             	{"bSortable": true},
								{"bSortable": true},
								{"bSortable": true},
								{"bVisible": false}
								 ]
				} );
			} );
		</script>
<table width="695" id="scroll_table" class="data_display"  >
  <thead>
  <tr>
    <th>date</th>
    <th>time</th>
    <th>user</th>
    <th>action</th>
    <th>details</th>
    <th>&nbsp;</th>
  </tr>
  </thead>
<?php 

$i=0;

while ($i<$tracking_num) {
    $b0  =  mysql_result($tracking_result, $i, "action_id");
	$b1 =  mysql_result($tracking_result, $i, "entry_date");
	$b2 =  mysql_result($tracking_result, $i, "user_name");
	$b3 =  mysql_result($tracking_result, $i, "action");
	$d1 =  mysql_result($tracking_result, $i, "details_1");
	$d2 =  mysql_result($tracking_result, $i, "details_2");
	$d3 =  mysql_result($tracking_result, $i, "details_3");
	$d4 =  mysql_result($tracking_result, $i, "details_4");
	
	$action='';
	$details='';
	switch ($b3) {
    case 1:
        $action = 'New user added';
		$details='<b>'.$d1.'</b> was added to the system.';
        break;
	
	case 2:
        $action = 'User removed';
		$details='<b>'.$d1.'</b> was removed from the system.';
        break;
	
	case 3:
        $action = 'Password reset';
		$details='Password was reset for <b>'.$d1.'</b>.';
        break;
	
	case 4:
        $action = 'Password changed';
		$details='<b>'.$d1.'</b> changed password.';;
        break;
	
	case 6:
        $action = 'Set homepage';
		$details='Home page for <b>'.$d1.'</b> was set to <b>'.$d3.'</b>(from '.$d2.')';
        break;	
		
	case 7:
        $action = 'Set permission';
		$details='Set access permission for <b>'.$d1.'</b> to <b>'.$d2.'</b>';
        break;	
		
	case 8:
        $action = 'Set permission';
		$details='Unset access permission for <b>'.$d1.'</b> to <b>'.$d2.'</b>';
        break;
		
	case 9:
        $action = 'Set pre-defined lists';
		$details='<b>'.$d1.'</b> accessed pre-defined list for: <b>'.$d2.'</b>';
        break;
		
	case 10:
        $action = 'Edit presets';
		$details='<b>'.$d4.'</b> changed from: <b>'.$d1.'</b> to <b>'.$d2.'<b>';
        break;
		
	case 11:
        $action = 'Edit presets';
		$old_hours =  floor($d1/60); 
		$old_mins =   $d1 % 60;
		$old_time = $old_hours.':'.$old_mins;
		$new_hours =  floor($d2/60); 
		$new_mins =   $d2 % 60;
		$new_time = $new_hours.':'.$new_mins;
		$details='<b>'.$d4.'</b> in <b>'.$d3.'</b> changed from: <b>'.$old_time.'</b> to <b>'.$new_time.'<b>';
        break;
	}
?>

  <tr>
    <td width="72" align="left"><?php echo date("d-m-Y", strtotime($b1 )) ?></td>
    <td width="52" align="left"><?php echo date("H:i", strtotime($b1 ))  ?></td>
    <td width="64" align="left"><?php echo $b2 ?></td>
    <td width="131" align="left"><?php echo $action ?></td>
    <td width="325" align="left"><?php echo $details ?></td>
    <td width="23" align="left"><?php echo $b1 ?></td>
    </tr>
  <?php
  $i++;
}
?>

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

<?php } else {
$_SESSION['denied_return'] = "admin_module/user_list.php";	
    include ("../navigation/admin_sidebar.php");?>
	<body onLoad="accessdenied(); return false">
<?php }
?>
<?php include ('../navigation/side_bar.php'); ?>
</body>
</html>