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

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

$table_name2 = $_SESSION['db_prefix']."_maintenance_contracts";
$contract_query = "SELECT contract_card_no, cust_id, start_date, project, project_no, project_area, project_place FROM $table_name2 WHERE start_date IS NOT NULL ORDER BY contract_card_no ASC ";

$contract_result = mySQL_query($contract_query);
$contract_num = mysql_num_rows($contract_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/calendar.js"></script>
<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">
  <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},
								{"iDataSort": 6},
								{"bSortable": true},
								{"bSortable": true},
								{"bSortable": true},
								{"bSortable": true},
								{"bVisible": false}
								 ]
				} );
			} );
		</script>

    <table width="809" border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td width="385"><label class="label_page_head">Maintenance  contracts</label></td>
              <td width="253">&nbsp;</td>
              <td width="171" align="right">&nbsp;</td>
            </tr>
          </table>
        </div>
       
        <div class="page_middle_frame">
        <div align="left">
<img src="../images/info_green.png" width="16" height="16"><label class="label_info">Click contract no to open the contract.</label>          
</div>     
        
        <table width="678"  id="scroll_table" class="data_display" >
           
           <thead>
            <tr>
              <th width="69" >Contract no</th>
              <th >Start Date</th>
              <th >Project </th>
              <th >Name</th>
              <th >Place</th>
              <th >&nbsp;</th>
              <th >&nbsp;</th>
            </tr>
            </thead>
            <?php 
$i=0;
$a7tot=0;
while ($i<$contract_num) {
	$a1 = mysql_result($contract_result, $i, "contract_card_no");
	
	
	     $a2 = mysql_result($contract_result, $i, "cust_id");
		 
		 if ($a2!='0') {
	     $table_name3 = $_SESSION['db_prefix']."_customer";
         $customer_query = "SELECT comp_name, name_2, title, account_type, status, bag_box, box_no, postal_place, phone, contact_1 FROM $table_name3 WHERE cust_id = '".$a2."' ";
		 $customer_result = mySQL_query($customer_query);
		 
		 $at = mysql_result($customer_result, 0, "account_type");
			if ($at=="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='';
		 }
		 
		 
		 
		 
	
	
	$a5 = mysql_result($contract_result, $i, "start_date");
	//$a8 = mysql_result($contract_result, $i, "seller");
	//$a9 = mysql_result($quotation_result, $i, "company_contact");
	//$a10 = mysql_result($quotation_result, $i, "contact_phone");
	$a11 = mysql_result($contract_result, $i, "project");
	$a12 = mysql_result($contract_result, $i, "project_no");
	$a13 = mysql_result($contract_result, $i, "project_place");
	$a14 = mysql_result($contract_result, $i, "project_area");
	
	$contractTT = "Click for contract details";
	
	//$quoteTT ="<img src=../images/view.png  width=20 height=16><table id=table_tool_tip width=250 ><tr><td  width=75>Quote no:</td><td width=175>".$a1."</td></tr><tr><td>Company:</td><td>".$a2a."</td></tr><tr><td>Items quoted:</td><td>".$line_text."</td></tr></table><br><b>Click to invoice</b>";
	
	//$productsTT ="<img src=../images/view.png  width=20 height=16><table id=table_tool_tip width=250 ><tr><td  width=75>Products quoted:</td><td width=175>".$line_text."</td></tr></table><br><b>Click for details</b>";
	$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_contract.php?contract_card_no=<?php echo $a1 ?> " onmouseover="ddrivetip('<?php echo $contractTT?>', 140)"; onmouseout="hideddrivetip()"><?php echo $a1 ?></a></td>
              <td width="82" align="left"><?php if ($a5!='') {echo date("d-m-Y", strtotime($a5)); }?></td>
              <td width="109" align="left"><?php echo $a11 ?></td>
              <td width="146" 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="146" align="left"><?php echo $a12.' '.$a14.' '.$a13 ?></td>
              <td width="53" align="left">&nbsp;</td>
              <td width="41" align="left"><?php echo $a5?></td>
            </tr>
            <?php
  $i++;
}
?>
            <tfoot>
            </tfoot>
          </table>
     
</div>  
</div>
<?php include ('../navigation/side_bar.php'); ?>
</body>
<?php } else {
$_SESSION['denied_return'] = "maintenance/mantenance_main.php";	
include ("../navigation/maintenance_sidebar.php");?>
<body onload="accessdenied(); return false">
</body>
<?php }
?>
</html>