<!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");
include('../include/period_select_date.php');	

if ($permission_num==1) {
	include ("../navigation/admin_sidebar.php");
?>
<?php
	
$table_name2 = $_SESSION['db_prefix']."_tracking_quality";
$tracking_query = "SELECT * FROM $table_name2 WHERE entry_date >= '".$start."' AND entry_date <= ('".$end."'+ INTERVAL 1 DAY) ORDER BY action_id DESC ";
$tracking_result = mySQL_query($tracking_query);
$tracking_num = mysql_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": [[ 0, "desc" ]],
					"aoColumns": [
								{"iDataSort": 5},
                              	{"bSortable": true},
                             	{"bSortable": true},
								{"bSortable": true},
								{"bSortable": true},
								{"bVisible": false}
								 ]
				} );
			} );
		</script>
</head>

<body>


<div class="main_frame">
<div class="page_head_frame">
        
        <table width="825" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td width="523"><label class="label_page_head">Quality control tracking</label></td>
            <td width="287">&nbsp;</td>
          </tr>
        </table>
  </div>
        <br />
<br />

<div class="page_middle_frame">	
<?php
$page='tracking_quality.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="371" >details</th>
    <th width="55" >&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 90: 
		$action = 'Wet tile inspection';
		
		$table_name = $_SESSION['db_prefix']."_wet_tile_spec";
		$production_query = "SELECT mix_design_name FROM $table_name WHERE wet_report_no='".$d2."'  ";
		$production_result = mySQL_query($production_query);
		$mix_design_name = mysql_result($production_result, 0, "mix_design_name");
		
     	$details = 'Wet tile inspection for <a href=../quality/wet_tile_report.php?report_no='.$d2.'&approve=><b>'.$d2.'</b></a>, '.$mix_design_name.'updated. First testing date '.date("d-m-Y", strtotime($d1)).'.';
        break;
	case 91:
		$action = 'Dry tile inspection';
		$products = '';
		$table_name = $_SESSION['db_prefix']."_production_plan";
		$production_query = "SELECT mix_design_name FROM $table_name WHERE dry_report_no ='".$d2."'  ";
		$production_result = mySQL_query($production_query);
		$production_num = mysql_num_rows($production_result);
		$k=0;
		while ($k<$production_num) {
		   $mix_design_name = mysql_result($production_result, 0, "mix_design_name");
		   $products = $products.', '.$mix_design_name;
		   $k++;
		}
		
     	$details = 'Dry tile inspection for <a href=../quality/dry_tile_report.php?report_no='.$d2.'&approve=><b>'.$d2.'</b></a>, '.$products.'updated. First testing date '.date("d-m-Y", strtotime($d1)).'.';
        break;
	case 92:
		$action = 'Wet tile inspection approve';
		$table_name = $_SESSION['db_prefix']."_production_plan";
		$production_query = "SELECT mix_design_name FROM $table_name WHERE wet_report_no='".$d2."'  ";
		
		$production_result = mySQL_query($production_query);
		$mix_design_name = mysql_result($production_result, 0, "mix_design_name");
		
     	$details = 'Wet tile inspection for <a href=../quality/wet_tile_report.php?report_no='.$d2.'&approve=><b>'.$d2.'</b></a>, '.$mix_design_name.' approved on '.date("d-m-Y", strtotime($d4)).' by '.$d3.'.';
        break;
	case 93:
		$action = 'Dry tile inspection approve';
		$products = '';
		$table_name = $_SESSION['db_prefix']."_production_plan";
		$production_query = "SELECT mix_design_name FROM $table_name WHERE dry_report_no ='".$d2."'  ";
		$production_result = mySQL_query($production_query);
		$production_num = mysql_num_rows($production_result);
		$k=0;
		while ($k<$production_num) {
		   $mix_design_name = mysql_result($production_result, 0, "mix_design_name");
		   $products = $products.', '.$mix_design_name;
		   $k++;
		}
		
     	$details = 'Dry tile inspection for <a href=../quality/dry_tile_report.php?report_no='.$d2.'&approve=><b>'.$d2.'</b></a>, '.$products.' approved on '.date("d-m-Y", strtotime($d4)).' by '.$d3.'.';
        break;
	case 94: 
		$action = 'Edit wet tile inspection';
		
		$table_name = $_SESSION['db_prefix']."_production_plan";
		$production_query = "SELECT mix_design_name FROM $table_name WHERE wet_report_no='".$d1."'  ";
		$production_result = mySQL_query($production_query);
		$mix_design_name = mysql_result($production_result, 0, "mix_design_name");
		
     	$details = '"'.$d4.'" on wet tile inspection for <a href=../quality/wet_tile_report.php?report_no='.$d1.'&approve=><b>'.$d1.'</b></a>, '.$mix_design_name.' was changed from '.$d2.' to '.$d3.'.';
        break;
	case 95: 
		$action = 'Edit wet tile inspection';
		
		$table_name = $_SESSION['db_prefix']."_production_plan";
		$production_query = "SELECT mix_design_name FROM $table_name WHERE wet_report_no='".$d1."'  ";
		$production_result = mySQL_query($production_query);
		$mix_design_name = mysql_result($production_result, 0, "mix_design_name");
		
     	$details = 'Test data on wet tile inspection for <a href=../quality/wet_tile_report.php?report_no='.$d1.'&approve=><b>'.$d1.'</b></a>, '.$mix_design_name.' was edited.';
        break;
	case 96:
		$action = 'Dry tile inspection';
		$products = '';
		$table_name = $_SESSION['db_prefix']."_production_plan";
		$production_query = "SELECT mix_design_name FROM $table_name WHERE dry_report_no ='".$d1."'  ";
		$production_result = mySQL_query($production_query);
		$production_num = mysql_num_rows($production_result);
		$k=0;
		while ($k<$production_num) {
		   $mix_design_name = mysql_result($production_result, 0, "mix_design_name");
		   $products = $products.', '.$mix_design_name;
		   $k++;
		}
		
     	$details = '"'.$d4.'" on dry tile inspection for <a href=../quality/dry_tile_report.php?report_no='.$d1.'&approve=><b>'.$d1.'</b></a>, '.$products.'was changed from '.$d2.' to '.$d3.'.';
        break;
	case 97:
		$action = 'Dry tile inspection';
		$products = '';
		$table_name = $_SESSION['db_prefix']."_production_plan";
		$production_query = "SELECT mix_design_name FROM $table_name WHERE dry_report_no ='".$d1."'  ";
		$production_result = mySQL_query($production_query);
		$production_num = mysql_num_rows($production_result);
		$k=0;
		while ($k<$production_num) {
		   $mix_design_name = mysql_result($production_result, 0, "mix_design_name");
		   $products = $products.', '.$mix_design_name;
		   $k++;
		}
		
		if ($d3==0) {
			$status = 'unchecked';
		}
		else {
			$status = 'checked';
		}
		
     	$details = '"'.$d4.'" on dry tile inspection for <a href=../quality/dry_tile_report.php?report_no='.$d1.'&approve=><b>'.$d1.'</b></a>, '.$products.'was '.$status.'.';
        break;
	case 98: 
		$action = 'Edit dry tile inspection';
		
		$products = '';
		$table_name = $_SESSION['db_prefix']."_production_plan";
		$production_query = "SELECT mix_design_name FROM $table_name WHERE dry_report_no ='".$d1."'  ";
		$production_result = mySQL_query($production_query);
		$production_num = mysql_num_rows($production_result);
		$k=0;
		while ($k<$production_num) {
		   $mix_design_name = mysql_result($production_result, 0, "mix_design_name");
		   $products = $products.', '.$mix_design_name;
		   $k++;
		}
		
     	$details = 'Test data on dry tile inspection for <a href=../quality/dry_tile_report.php?report_no='.$d1.'&approve=><b>'.$d1.'</b></a>, '.$products.' was edited.';
        break;				
		
	
 }
	
	?>
  
  
  <tr>
    <td width="54" align="left"><?php echo date("d-m-Y", strtotime($b1 )) ?></td>
    <td width="38" align="left"><?php echo date("H:i", strtotime($b1 ))  ?></td>
    <td width="50" align="left"><?php echo $b2 ?></td>
    <td width="87" align="left"><?php echo $action ?></td>
    <td align="left"><?php echo $details ?></td>
    <td align="left"><?php echo $b1 ?></td>
    </tr>
  <?php
  $i++;
}
?>

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