<?php
$table_name = $_SESSION['db_prefix']."_maintenance_schedule_temp";
$schedule_query = "SELECT  * FROM $table_name WHERE checked = 'yes' AND user_name = '".$_SESSION['username']."' ORDER BY contract_card_no ASC ";
$schedule_result = mySQL_query($schedule_query);
$schedule_num = mysql_num_rows($schedule_result);


?>
<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="maintenance_scheduleWiz5.php" method="get" name="form1" id="form1" >

<div class="wizard_frame">
Maintenance job in cluster: <?php echo $_SESSION['cluster']?>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for team: <?php echo $_SESSION['team']?><br>
<br>
Maintenance scheduled for: <?php echo date("d-m-Y", strtotime($_SESSION['schedule_date'])) ?> 
</div>

    <div class="wizard_frame">
       <table width="600" id="table_details_display">
         <tr>
    <td width="76">Contract no</td>
    <td width="56">Cycle</td>
    <td width="176">Customer</td>
    <td width="272">Address</td>
         </tr>
  <?php 
  $i = 0;
  while ($i<$schedule_num) {
	  $contract_card_no = mysql_result($schedule_result, $i, "contract_card_no");
	  		$table_name = $_SESSION['db_prefix']."_maintenance_contracts";
			$contract_query = "SELECT cust_id, project_no, project_area, project_place  FROM $table_name WHERE contract_card_no = '".$contract_card_no."'  ";
			$contract_result = mySQL_query($contract_query);
			$contract_num = mysql_num_rows($contract_result);
			$cust_id = mysql_result($contract_result, 0, "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($contract_result, 0, "project_no");
			$project_area = mysql_result($contract_result, 0, "project_area");
			$project_place = mysql_result($contract_result, 0, "project_place");
	  
	  
	  $cycle_no = mysql_result($schedule_result, $i, "cycle_num");
	  ?>
  <tr>
    <td><?php echo $contract_card_no ?>
      <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><?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 ?> "></td>
    <td><?php echo $cust_name ?></td>
    <td><?php echo $project_no.' '.$project_area.' '.$project_place ?></td>
  </tr>
  <?php
  $i++;
  }
  ?>
      </table>
       <input name="line_num"  id="line_num" type="hidden" value="<?php echo $schedule_num ?>">
        </div>
        <div class="wizard_frame">
        On clicking 'Finish', maintenance cards for the above contracts wil be generated and placed in the process scheme.
        </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=2');return document.MM_returnValue" /></td>
          <td width="115">&nbsp;</td>
          <td width="99"><input name="p" type="hidden" id="p" value="3" />
            <input name="s" type="hidden" id="s" value="3" />
            </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  name="finish_button" type="submit" class="imagebutton" id="finish_button" value="Finish" onClick="needToConfirm = false; MM_showHideLayers('wait','','show');"  /></td>
        </tr>
      </table>
      </div>
</form>
</div>

</body>      