<?php
	
$table_name = $_SESSION['db_prefix']."_maintenance_contracts";
$cluster_query = "SELECT contract_card_no, cust_id, start_date, end_date, cluster, project_no, project_area, project_place FROM $table_name WHERE cluster = '".$_SESSION['cluster']."' ";
$cluster_result = mySQL_query($cluster_query);
$cluster_num = mysql_num_rows($cluster_result);

$cur_month = date('m');
		

?>
<script type="text/javascript" src="../jscript/jquery.1.4.2.js"></script>
<script language="JavaScript" src="../jscript/gen_validatorv4.js"  type="text/javascript" xml:space="preserve"></script>
<script language="javascript" src="../jscript/calendar.js"></script>
</head>

<?php include('../include/wait.php') ?>
<link href="../css/wait.css" rel="stylesheet" type="text/css">
<body onLoad="MM_showHideLayers('wait','','hide')" onFocus="MM_showHideLayers('wait','','hide');"  onBlur="MM_showHideLayers('wait','','hide');">



<div class="wizard_page_middle_frame">
<form action="" method="get" name="form1" id="form1" >
<div class="wizard_frame">
Cluster: <?php echo $_SESSION['cluster']?>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Team: <?php echo $_SESSION['team']?>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Date:&nbsp;<?php echo date("l, d-m-Y", strtotime($_SESSION['schedule_date'])) ?></div>

    <div class="wizard_frame">
        <table width="630" id="table_details_display">
        <thead>
        <tr>
    	<td align="left" valign="middle">&nbsp;</td>
    	<td align="left" valign="middle">Cycle</td>
    	<td align="left" valign="middle">Contract no</td>
    	<td align="left" valign="middle">Customer</td>
    	<td align="left" valign="middle">Address</td>
  		</tr>
        </thead>
  <?php
  $i=0;
  while ($i<$cluster_num) {
	$contract_card_no =   mysql_result($cluster_result, $i, "contract_card_no"); 
	$cust_id = mysql_result($cluster_result, $i, "cust_id");
	  		$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");
 			}
			
	$project_no = mysql_result($cluster_result, $i, "project_no");
	$project_area = mysql_result($cluster_result, $i, "project_area");
	$project_place = mysql_result($cluster_result, $i, "project_place");
	
	$start_date = mysql_result($cluster_result, $i, "start_date");
	$start_month = date('m', strtotime($start_date));
	
	
	if ($cur_month > $start_month) {
	        $cycle_no = $cur_month - $start_month +1;
	}
	
	if ($cur_month < $start_month) {
	        $cycle_no = 12 - ABS($start_month - $cur_month -1);
	}
	
	if ($cur_month == $start_month) {
	        $cycle_no = 1;
	}
	
	$table_name = $_SESSION['db_prefix']."_maintenance_schedule_temp";
	$check_query = "SELECT contract_card_no  FROM $table_name WHERE contract_card_no = '".$contract_card_no."' AND checked = 'yes' ";
	$check_result = mySQL_query($check_query);
	$check_num = mysql_num_rows($check_result);
	if ($check_num == 1) {
		   $check='yes';
	}
	else {
		$check='';
	}
	
?>	  
  <tr>
    <td width="34" align="left" valign="middle"><input type="checkbox" name="contract_checkbox<?php echo $i ?>" id="contract_checkbox<?php echo $i ?>" <?php if ($check=='yes') { ?> checked <?php } ?> ></td>
    <td width="48" align="center" valign="middle"><?php echo $cycle_no ?><input type="hidden" name="cycle_no_text<?php echo $i ?>" id="cycle_no_text<?php echo $i ?>" value="<?php echo $cycle_no ?> "><?php if ($cycle_no==12) { ?><a href="" onMouseover="ddrivetip('This is the last visit in the cycle, contract needs to be renewed.', 150)"; onMouseout="hideddrivetip()"> <img src="../images/exclamation_mark_red_small.png" width="10" height="16"><?php } ?>  </a><?php if ($cycle_no==11) { ?><a href="" onMouseover="ddrivetip('Next month will be the last visit in the cycle, contract needs to be renewed.', 190)"; onMouseout="hideddrivetip()"> <img src="../images/exclamation_mark_orange_small.png" width="10" height="16"><?php } ?>  </a> </td>
    <td width="86" align="center" valign="middle"><?php echo $contract_card_no?>&nbsp;<input name="contract_card_no_text<?php echo $i ?>" id="contract_card_no_text<?php echo $i ?>" type="hidden" value="<?php echo $contract_card_no ?>"></td>
    <td width="166" align="left" valign="middle"><?php echo $cust_name ?></td>
    <td width="272" align="left" valign="middle"><?php echo $project_no.' '.$project_area.' '.$project_place ?></td>
  </tr>
<?php
$i++;
  }
  ?>
  <input name="line_num"  id="line_num" type="hidden" value="<?php echo $cluster_num ?>">
        </table>
    </div>
    
    <div class="wizard_frame">
    <table width="600" id="table_details_display">
  <tr>
    <td width="166" valign="top">&nbsp;</td>
    <td width="422">&nbsp;</td>
  </tr>
</table>

    </div>
      
        <div class="wizard_frame">
      <table width="590" height="50" align="center" id="table_button_bar">
        <tr>
          <td width="117"><input type="button" name="lastprev_button" class="imagebutton" value="Prev"  onclick="needToConfirm = false;MM_showHideLayers('wait','','show');MM_goToURL('parent','maintenance_scheduleWizbase.php?s=&amp;p=1');return document.MM_returnValue" /></td>
          <td width="115">&nbsp;</td>
          <td width="99"><input name="p" type="hidden" id="p" value="2" />
            <input name="s" type="hidden" id="s" value="2" />
            </span></td>
          <td width="125" align="right"><input name="cancelbutton" type="button" class="imagebutton" id="cancelbutton"  onClick="needToConfirm = false; cancel_confirmation(1, '../maintenance/maintenance_main.php');" value="Cancel" /></td>
          <td width="110" align="right"><input type="submit" name="next_button" id="next_button" class="imagebutton" value="Next"  onClick="needToConfirm = false; MM_showHideLayers('wait','','show'); " /></td>
        </tr>
      </table>
      </div>
</form>
</div>
<script language="JavaScript" type="text/javascript" xml:space="preserve">
  var frmvalidator  = new Validator("form1");
  frmvalidator.EnableMsgsTogether();
  frmvalidator.addValidation("invoice_amount_text","req","- invoice amount.");
  frmvalidator.addValidation("invoice_no_text","req","- invoice no.");
  frmvalidator.addValidation("invoiced_by_select","req","- invoiced by.");
</script>
</body>      