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

include('../include/period_select_date.php');	
	
	
$table_name2 = $_SESSION['db_prefix']."_tracking_maintenance";
$tracking_query = "SELECT * FROM $table_name2 WHERE entry_date >= '".$start."' AND entry_date <= '".$end."' 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" />

</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" style="height:auto;">
<div  class="page_head_frame"> <label class="label_page_head">Maintenance tracking</label></td>
</div>
       

<div class="page_middle_frame" >	
  <?php
$page='tracking_maintenance.php';
$reference_name='';
$reference='';
include('../include/period_select_block.php');
?>
  
<div  class="page_inside_frame">
	<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>
<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 

$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 120:
        $action = 'Request maintenance';
		
		$table_name = $_SESSION['db_prefix']."_customer";
		$cust_name_query = "SELECT comp_name FROM $table_name WHERE cust_id= '".$d2."' ";
		$cust_name_result = mySQL_query($cust_name_query);
		$cust_name_num = mysql_num_rows($cust_name_result);
		if ($cust_name_num!=0) {
		$cust_name = mysql_result($cust_name_result, 0, "comp_name");
		}
		else {
			$cust_name='';
		}
		
		$details = 'Request for maintenance <a href=../maintenance/maintenance_quotation_request.php?quote_no='.$d1.'><b>'.$d1.'</b></a> for <a href=../sales/customer_details.php?cust_id='.$d2.'><b>'.$cust_name.'</b></a> for <b>'.$d3.'</b>';
        break;
		
	case 121:
        $action = 'Quotation maintenance';
		
		$table_name = $_SESSION['db_prefix']."_customer";
		$cust_name_query = "SELECT comp_name FROM $table_name WHERE cust_id= '".$d2."' ";
		$cust_name_result = mySQL_query($cust_name_query);
		$cust_name_num = mysql_num_rows($cust_name_result);
		if ($cust_name_num!=0) {
		$cust_name = mysql_result($cust_name_result, 0, "comp_name");
		}
		else {
			$cust_name='';
		}
		
		$details = 'Maintenance quote <a href=../maintenance/maintenance_quotation.php?quote_no='.$d1.'><b>'.$d1.'</b></a> for <a href=../sales/customer_details.php?cust_id='.$d2.'><b>'.$cust_name.'</b></a> for <b>'.$d3.'</b>';
        break;	
		
	case 122:
        $action = 'Quotation maintenance invoiced';
		
		$table_name = $_SESSION['db_prefix']."_customer";
		$cust_name_query = "SELECT comp_name FROM $table_name WHERE cust_id= '".$d2."' ";
		$cust_name_result = mySQL_query($cust_name_query);
		$cust_name_num = mysql_num_rows($cust_name_result);
		if ($cust_name_num!=0) {
		$cust_name = mysql_result($cust_name_result, 0, "comp_name");
		}
		else {
			$cust_name='';
		}
		
		$details = 'Maintenance quote <a href=../maintenance/maintenance_quotation.php?quote_no='.$d1.'><b>'.$d1.'</b></a> for <a href=../sales/customer_details.php?cust_id='.$d2.'><b>'.$cust_name.'</b></a> invoiced by: <b>'.$d3.'</b> Invoice no: <a href=../maintenance/maintenance_invoice_report.php?invoice_no='.$d4.'&maintenance_no='.$d1.'><b>'.$d4.'</b>';
        break;		
		
	
	case 123:
	    $action = 'Maintenance planning edited';
        $table_name = $_SESSION['db_prefix']."_maintenance_jobs";
		$job_query = "SELECT cust_id, project FROM $table_name WHERE maintenance_card_no = '".$d1."' ";
		$job_result = mySQL_query($job_query);
		$cust_id = mysql_result($job_result, 0, "cust_id");
		$project = mysql_result($job_result, 0, "project");
		
		
		$table_name2 = $_SESSION['db_prefix']."_customer";
		$customer_query = "SELECT * FROM $table_name2 WHERE cust_id ='".$cust_id."' ";
		$customer_result = mySQL_query($customer_query);
		$customer_num = mysql_num_rows($customer_result);	
		$a1 = mysql_result($customer_result, 0, "account_type");
			if ($a1=="corporate") { 
				$cust_name = mysql_result($customer_result, 0, "comp_name"); 
			} 
			else {
				$cust_name = mysql_result($customer_result, 0, "title")." ".mysql_result($customer_result, 0, "name_2")." ".mysql_result($customer_result, 0, "comp_name");
 			}
			
			
		$details=$d4.' on maintenance card no <a href="../maintenance/maintenance_card.php?maintenance_card_no='.$d1.'"> <b>'.$d1.'</b></a> for '.$project.' for <a href="../sales/customer_details.php?cust_id='.$cust_id.'" ><b> '.$cust_name.'</b></a> changed from <b>'.date("d-m-Y", strtotime($d2)).'</b> to <b>'.date("d-m-Y", strtotime($d3)).'</b>.';
		
		break;	
		
		case 124:
        $action = 'Maintenance card opened';
		
		$table_name = $_SESSION['db_prefix']."_customer";
		$cust_name_query = "SELECT comp_name FROM $table_name WHERE cust_id= '".$d3."' ";
		$cust_name_result = mySQL_query($cust_name_query);
		$cust_name_num = mysql_num_rows($cust_name_result);
		if ($cust_name_num!=0) {
		$cust_name = mysql_result($cust_name_result, 0, "comp_name");
		}
		else {
			$cust_name='';
		}

		$details = 'Maintenance card <a href=../maintenance/maintenance_card.php?maintenance_card_no='.$d1.'><b>'.$d1.'</b></a> for <b>'.$d2.'</b> for <a href=../sales/customer_details.php?cust_id='.$d3.'><b>'.$cust_name.'</b></a> opened. Start date: <b>'.date("d-m-Y", strtotime($d4)).'</b>';
        break;
		
		case 125:
        $action = 'Maintenance card closed';
		
		$table_name = $_SESSION['db_prefix']."_customer";
		$cust_name_query = "SELECT comp_name FROM $table_name WHERE cust_id= '".$d3."' ";
		$cust_name_result = mySQL_query($cust_name_query);
		$cust_name_num = mysql_num_rows($cust_name_result);
		if ($cust_name_num!=0) {
		$cust_name = mysql_result($cust_name_result, 0, "comp_name");
		}
		else {
			$cust_name='';
		}

		$details = 'Maintenance card <a href=../maintenance/closed_maintenance_card.php?maintenance_card_no='.$d1.'><b>'.$d1.'</b></a> for <b>'.$d2.'</b> for <a href=../sales/customer_details.php?cust_id='.$d3.'><b>'.$cust_name.'</b></a> closed. Date: <b>'.date("d-m-Y", strtotime($d4)).'</b>';
        break;
		
		case 126:
        $action = 'Maintenance card completed';
		
		$table_name = $_SESSION['db_prefix']."_customer";
		$cust_name_query = "SELECT comp_name FROM $table_name WHERE cust_id= '".$d3."' ";
		$cust_name_result = mySQL_query($cust_name_query);
		$cust_name_num = mysql_num_rows($cust_name_result);
		if ($cust_name_num!=0) {
		$cust_name = mysql_result($cust_name_result, 0, "comp_name");
		}
		else {
			$cust_name='';
		}

		$details = 'Maintenance card <a href=../maintenance/maintenance_costing_job_card.php?maintenance_card_no='.$d1.'><b>'.$d1.'</b></a> for <b>'.$d2.'</b> for <a href=../sales/customer_details.php?cust_id='.$d3.'><b>'.$cust_name.'</b></a> completed. Date: <b>'.date("d-m-Y", strtotime($d4)).'</b>';
        break;
		
		case 129:
        $action = 'Maintenance contract edit';
		
		$table_name = $_SESSION['db_prefix']."_maintenance_contracts";
		$contract_query = "SELECT cust_id FROM $table_name WHERE contract_card_no = '".$d1."' ";
		$contract_result = mySQL_query($contract_query);
		$cust_id = mysql_result($contract_result, 0, "cust_id");
		
		$table_name = $_SESSION['db_prefix']."_customer";
		$cust_name_query = "SELECT comp_name FROM $table_name WHERE cust_id= '".$cust_id."' ";
		$cust_name_result = mySQL_query($cust_name_query);
		$cust_name_num = mysql_num_rows($cust_name_result);
		if ($cust_name_num!=0) {
		$cust_name = mysql_result($cust_name_result, 0, "comp_name");
		}
		else {
			$cust_name='';
		}

		$details = $d4.' on maintenance card <a href=../maintenance/maintenance_contract.php?maintenance_card_no='.$d1.'><b>'.$d1.'</b></a> for <a href=../sales/customer_details.php?cust_id='.$cust_id.'><b>'.$cust_name.'</b></a> changed from <b>'.$d2.'</b> to <b>'.$d3.'</b>';
        break;	
		
		case 130:
        $action = 'Maintenance quotation edit';
		
		$table_name = $_SESSION['db_prefix']."_maintenance_quotations";
		$quote_query = "SELECT cust_id FROM $table_name WHERE quote_no = '".$d1."' ";
		$quote_result = mySQL_query($quote_query);
		$cust_id = mysql_result($quote_result, 0, "cust_id");
		
		$table_name = $_SESSION['db_prefix']."_customer";
		$cust_name_query = "SELECT comp_name FROM $table_name WHERE cust_id= '".$cust_id."' ";
		$cust_name_result = mySQL_query($cust_name_query);
		$cust_name_num = mysql_num_rows($cust_name_result);
		if ($cust_name_num!=0) {
		$cust_name = mysql_result($cust_name_result, 0, "comp_name");
		}
		else {
			$cust_name='';
		}
		$details = $d4.'</b> on maintenance quotation <a href=../maintenance/maintenance_quotation.php?quote_no='.$d1.'><b>'.$d1.'</b></a> for <a href=../sales/customer_details.php?cust_id='.$cust_id.'><b>'.$cust_name.'</b></a> changed from <b>'.$d2.'</b> to <b>'.$d3.'</b>';
        break;
		
		case 131:
        $action = 'Maintenance quotation edit';
		
		$table_name = $_SESSION['db_prefix']."_maintenance_quotations";
		$quote_query = "SELECT cust_id FROM $table_name WHERE quote_no = '".$d1."' ";
		$quote_result = mySQL_query($quote_query);
		$cust_id = mysql_result($quote_result, 0, "cust_id");
		
		$table_name = $_SESSION['db_prefix']."_customer";
		$cust_name_query = "SELECT comp_name FROM $table_name WHERE cust_id= '".$cust_id."' ";
		$cust_name_result = mySQL_query($cust_name_query);
		$cust_name_num = mysql_num_rows($cust_name_result);
		if ($cust_name_num!=0) {
		$cust_name = mysql_result($cust_name_result, 0, "comp_name");
		}
		else {
			$cust_name='';
		}
		
		$details = 'Item <b>'.$d2.'</b> on maintenance quotation <a href=../maintenance/maintenance_quotation.php?quote_no='.$d1.'><b>'.$d1.'</b></a> for <a href=../sales/customer_details.php?cust_id='.$cust_id.'><b>'.$cust_name.'</b></a> deleted';
        break;	
		
		case 132:
        $action = 'Maintenance quotation edit';
		
		$table_name = $_SESSION['db_prefix']."_maintenance_quotations";
		$quote_query = "SELECT cust_id FROM $table_name WHERE quote_no = '".$d1."' ";
		$quote_result = mySQL_query($quote_query);
		$cust_id = mysql_result($quote_result, 0, "cust_id");
		
		$table_name = $_SESSION['db_prefix']."_customer";
		$cust_name_query = "SELECT comp_name FROM $table_name WHERE cust_id= '".$cust_id."' ";
		$cust_name_result = mySQL_query($cust_name_query);
		$cust_name_num = mysql_num_rows($cust_name_result);
		if ($cust_name_num!=0) {
		$cust_name = mysql_result($cust_name_result, 0, "comp_name");
		}
		else {
			$cust_name='';
		}

		$details = 'Item <b>'.$d3.'</b> on maintenance quotation <a href=../maintenance/maintenance_quotation.php?quote_no='.$d1.'><b>'.$d1.'</b></a> for <a href=../sales/customer_details.php?cust_id='.$cust_id.'><b>'.$cust_name.'</b></a> added';
        break;
		
		case 133:
	    $action = 'Survey report';
        $table_name = $_SESSION['db_prefix']."_maintenance_jobs";
		$job_query = "SELECT cust_id, project FROM $table_name WHERE maintenance_card_no = '".$d1."' ";
		$job_result = mySQL_query($job_query);
		$cust_id = mysql_result($job_result, 0, "cust_id");
		$project = mysql_result($job_result, 0, "project");
		
		$table_name2 = $_SESSION['db_prefix']."_customer";
		$customer_query = "SELECT * FROM $table_name2 WHERE cust_id ='".$cust_id."' ";
		$customer_result = mySQL_query($customer_query);
		$customer_num = mysql_num_rows($customer_result);	
		$a1 = mysql_result($customer_result, 0, "account_type");
			if ($a1=="corporate") { 
				$cust_name = mysql_result($customer_result, 0, "comp_name"); 
			} 
			else {
				$cust_name = mysql_result($customer_result, 0, "title")." ".mysql_result($customer_result, 0, "name_2")." ".mysql_result($customer_result, 0, "comp_name");
 			}
		$details='Survey completed for maintenance card no<a href="../maintenance/maintenance_card.php?maintenance_card_no='.$d1.'"> <b>'.$d1.'</a></b> for <b>'.$project.'</b> for <a href="../sales/customer_details.php?cust_id='.$cust_id.'" ><b> '.$cust_name.'</b></a>. Survey score: <a href="../maintenance/survey_maintenance_report.php?maintenance_card_no='.$d1.'"> <b>'.$d2.'</a>%</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
  $i++;
}
?>

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