<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

<?php
include('../include/session.php');
include('../include/period_select_date.php');	

$date = $_GET['date'];

$table_name2 = $_SESSION['db_prefix']."_maintenance_jobs";
$maintenance_query = "SELECT maintenance_no, maintenance_card_no, cust_id, date, start_date, end_date, team, project, project_no, project_area, project_place, card_opened, card_closed, completed FROM $table_name2  ORDER BY maintenance_card_no DESC ";
$maintenance_result = mySQL_query($maintenance_query);
$maintenance_num = mysql_num_rows($maintenance_result);	

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

<!--jscript-->
<script language="JavaScript" src="../jscript/tooltip.js"  type="text/javascript"></script> 

</head>
<body>
<?php
include ("../navigation/header.php");
$page_name = "Maintenance-main";
include ("../navigation/access.php");

if ($permission_num==1) {
	include ("../navigation/maintenance_sidebar.php");
?>
<div class="main_frame">
  <div class="page_head_frame">
  <table width="809" border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td width="385"><label class="label_page_head">Maintenance cards</label></td>
              <td width="253">&nbsp;</td>
              <td width="171" align="right">&nbsp;</td>
            </tr>
          </table>
        </div>
       
        <div class="page_middle_frame">
        

<?php
$page='maintenance_cards_list.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": "485px",
					"bPaginate": false,
					"bScrollCollapse": true,
					"aaSorting": [[ 0, "desc" ]],
					"aoColumns": [
								{"bSortable": true},
								{"bSortable": true},
								{"iDataSort": 8},
								{"bSortable": true},
								{"bSortable": true},
								{"bSortable": true},
								{"bSortable": true},
								{"bSortable": true},
								{"bVisible": false}
								 ]
				} );
			} );
		</script>
 
        <table width="667"  id="scroll_table" class="data_display" >
           
           <thead>
            <tr>
              <th width="53" align="center" >Card no</th>
              <th align="center" >Date</th>
              <th align="center" >Start<br>
              date</th>
              <th align="center" >Complete<br>
              date</th>
              <th align="center" >Project</th>
              <th align="center" >Team</th>
              <th align="center" >Customer</th>
              <th align="center" >Survey</th>
              <th align="center" >&nbsp;</th>
             </tr>
            </thead>
            <?php 
$i=0;
while ($i<$maintenance_num) {
	$a1a = mysql_result($maintenance_result, $i, "maintenance_no");
	$a1 = mysql_result($maintenance_result, $i, "maintenance_card_no");
		
	     $a2 = mysql_result($maintenance_result, $i, "cust_id");
		 if ($a2!='0') {
	     $table_name3 = $_SESSION['db_prefix']."_customer";
         $customer_query = "SELECT comp_name, account_type, name_2, title, status, bag_box, box_no, postal_place, phone, contact_1 FROM $table_name3 WHERE cust_id = '".$a2."' ";
		 $customer_result = mySQL_query($customer_query);
		 
		 $status = mysql_result($customer_result, 0, "account_type");
			if ($status=="corporate") { 
				$a2a = mysql_result($customer_result, 0, "comp_name"); 
			} 
			else {
				$a2a = mysql_result($customer_result, 0, "title")." ".mysql_result($customer_result, 0, "name_2")." ".mysql_result($customer_result, 0, "comp_name");
 			}
		 	 
         
		 $a2b = mysql_result($customer_result, 0, "bag_box");
		 $a2c = mysql_result($customer_result, 0, "box_no");
		 $a2d = mysql_result($customer_result, 0, "postal_place");
		 $a2e = mysql_result($customer_result, 0, "phone");
		 $a2f = mysql_result($customer_result, 0, "contact_1");
		 $a3 = mysql_result($customer_result, 0, "status");
		 } 
		 else {
			 $a2a='';
		 }
	$a4 = mysql_result($maintenance_result, $i, "date");
	$a5 = mysql_result($maintenance_result, $i, "start_date");
	$a6 = mysql_result($maintenance_result, $i, "end_date");
	$a7 = mysql_result($maintenance_result, $i, "team");
	$a8 = mysql_result($maintenance_result, $i, "project");
	
	$a12 = mysql_result($maintenance_result, 0, "project_no");
	$a13 = mysql_result($maintenance_result, 0, "project_place");
	$a14 = mysql_result($maintenance_result, 0, "project_area");
	
	$a15= mysql_result($maintenance_result, $i, "card_opened");
	$a16= mysql_result($maintenance_result, $i, "card_closed");
	$a17= mysql_result($maintenance_result, $i, "completed");
	
	$table_name4 = $_SESSION['db_prefix']."_survey_maintenance";
	$survey_query = "SELECT * FROM $table_name4 WHERE maintenance_card_no = '".$a1."' ";
	$survey_result = mySQL_query($survey_query);
	$survey_num = mysql_num_rows($survey_result);
	if ($survey_num>0) {
	$result_1 = mysql_result($survey_result, 0, "result_1");
	$result_2 = mysql_result($survey_result, 0, "result_2");
	$result_3 = mysql_result($survey_result, 0, "result_3");
	$result_4 = mysql_result($survey_result, 0, "result_4");
	$survey_perc = (($result_1+$result_2+$result_3+$result_4)/8)*100;
	}
	else {
	$survey_perc = '';
	}
	

	$jobTT ="<table id=table_tool_tip width=250 ><tr><td  width=75>Job card:</td><td width=175>".$a1." (".$a1a.")</td></tr><tr><td  width=75>Project:</td><td width=175>".$a8."</td></tr><tr><td>Project place:</td><td>".$a12."</td></tr><tr><td>&nbsp;</td><td>".$a14."</td></tr><tr><td>&nbsp;</td><td>".$a13."</td></tr></table><br><b>Click for details</b>";
	
	
	$projectTT ="<table id=table_tool_tip width=250 ><tr><td  width=75>Project:</td><td width=175>".$a8."</td></tr><tr><td>Project place:</td><td>".$a12."</td></tr><tr><td>&nbsp;</td><td>".$a14."</td></tr><tr><td>&nbsp;</td><td>".$a13."</td></tr></table>";
	
		
	$customerTT ="<table id=table_tool_tip width=250 ><tr><td  width=75>Company:</td><td width=175>".$a2a."</td></tr><tr><td>Address:</td><td>".$a2b."&nbsp;".$a2c."<br>".$a2d."</td></tr><tr><td>Phone:</td><td>".$a2e."</td></tr><tr><td>Contact:</td><td>".$a2f."</td></tr></table><br><b>Click for details</b>";
	?>
            <tr>
              <td  style="padding-left:0px;" align="center"><a href="maintenance_card.php?maintenance_card_no=<?php echo $a1 ?> " onmouseover="ddrivetip('<?php echo $jobTT?>', 250)"; onmouseout="hideddrivetip()"><?php echo $a1 ?></a></td>
              <td width="56" align="left"><?php echo date("d-m-Y", strtotime($a4))?></td>
              <td width="56" align="center"><?php if ($a5!='') {echo date("d-m-Y", strtotime($a5));}?></td>
              <td width="70" align="center"><?php if ($a6!='') {echo date("d-m-Y", strtotime($a6));} ?></td>
              <td width="118" align="left"><a href="maintenance_card.php?maintenance_card_no=<?php echo $a1 ?>" onMouseOver="ddrivetip('<?php echo $projectTT?>', 250)"; onMouseOut="hideddrivetip()"><?php echo $a8 ?></a></td>
              <td width="45" align="center"><?php echo $a7 ?></td>
              <td width="154" align="left"><a href="../sales/customer_details.php?cust_id=<?php echo $a2 ?>" onMouseOver="ddrivetip('<?php echo $customerTT?>', 250)"; onMouseOut="hideddrivetip()"><?php echo $a2a ?></a></td>
              <td width="52" align="center"><?php  if ($survey_perc>='0') { ?> <a href="survey_maintenance_report.php?maintenance_card_no=<?php echo $a1 ?>" onMouseover="ddrivetip('Click to view report', 150)"; onMouseout="hideddrivetip()"><?php echo number_format($survey_perc, 0, '.', ',').'%'; ?> </a><?php } else { echo '--';} ?></td>
              <td width="23" align="center"><?php echo $a5 ?></td>
            </tr>
            <?php
  $i++;
}
?>
            <tfoot>
            </tfoot>
          </table>
          
        </div>
  
 </div> 
</div>
<?php include ('../navigation/side_bar.php'); ?>
</body>
<?php } else {
$_SESSION['denied_return'] = "maintenance/maintenance_main.php";	
include ("../navigation/maintenance_sidebar.php");?>
<body onload="accessdenied(); return false">
</body>
<?php }
?>
</html>