<!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" />

<link href="../css/main.css" rel="stylesheet" type="text/css" />
<?php
include ("../navigation/header.php");
$page_name = "AD-tracking";
include ("../navigation/access.php");

if ($permission_num==1) {
	include ("../navigation/admin_sidebar.php");
?>
<?php

require_once('../include/tc_calendar.php');
	$date = $_GET['date'];
	
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."' ORDER BY action_id DESC ";
$tracking_result = $con->query($tracking_query);
$tracking_num = mysqli_num_rows($tracking_result);


?>
<!--style sheets-->
<link rel="stylesheet" type="text/css" href="../css/scroll_table.css" />

<!--jscript-->
<script language="javascript" src="../jscript/calendar.js"></script>
<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": [[ 5, "desc" ]],
					"aoColumns": [
								{"iDataSort": 5},
                              	{"bSortable": true},
                             	{"bSortable": true},
								{"bSortable": true},
								{"bSortable": true},
								{"bVisible": false}
								 ]
				} );
			} );
		</script>
</head>

<body>
<div class="main_frame" style="height:auto;">
<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='';
$reference_name_2='';
$reference_2='';
$reference_name_3='';
$reference_3='';
include('../include/period_select_block_small.php');
?>
</div>
<div  class="page_middle_frame">
<table width="683" id="scroll_table" class="data_display">
  <thead>
  <tr>
    <th>date</th>
    <th >time</th>
    <th>user</th>
    <th>action</th>
    <th width="322">details</th>
    <th width="51">&nbsp;</th>
    </tr>
   </thead>
<?php 

while($row = $tracking_result->fetch_assoc()) {
	$b0 = $row["action_id"];
	$b1 = $row["entry_date"];
	$b2 = $row["user_name"];
	$b3 = $row["action"];
	$d1 = $row["details_1"];
	$d2 = $row["details_2"];
	$d3 = $row["details_3"];
	$d4 = $row["details_4"];
	
	
	$action='';
	$details='';
	switch ($b3) {
    case 120:
        $action = 'Edit preset';
		$details = '<b>'.$d4.'</b> was changed from <b>'.$d1.'</b> to <b>'.$d2.'</b>';
        break;
	case 121:
        $action = 'New user';
		$details = '<b>'.$d1.'</b> was added as new user';
        break;
	case 122:
        $action = 'Remove user';
		$details = '<b>'.$d1.'</b> was removed as user';
        break;
	case 123:
        $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="67" align="left"><?php echo date("d-m-Y", strtotime($b1 )) ?></td>
    <td width="57" align="left"><?php echo date("H:i", strtotime($b1 ))  ?></td>
    <td width="64" align="left"><?php echo $b2 ?></td>
    <td width="94" align="left"><?php echo $action ?></td>
    <td align="left"><?php echo $details ?></td>
    <td align="left"><?php echo $b1?></td>
    </tr>
  <?php
  
}
?>

</table>
</div>

</div>
</body>
<?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'); ?>
</html>