<?php
	/*
		(C) DairyWindow 2017
		admin@dairywindow.nz
	*/
	
	require "inc/connect.php";
	if($_SESSION['userLevel']<= $_SESSION['admin_form_edit']) $allow_edit=1; else $allow_edit=0;
	
	switch($_SESSION['cypherorbatch']){
		case 0:
		case '0':
			$cypherorbatch = "Cypher";
			break;
		case 1:
		case '1':
			$cypherorbatch = "Batch";
			break;
		default:
			$cypherorbatch = "Cypher/Batch";
	}
	
	if(isset($_POST['Cypher']) && $_POST['Cypher']!="" && $_POST['Cypher']!=null && $_POST['Cypher']!='0' && $_POST['Cypher']!=0){
		//create new form
		
		$Cypher         = clean($_POST['Cypher'         ]);
		$Sampling       = clean($_POST['Sampling'       ]);
		$CCPCreamYesNo  = clean($_POST['CCPCreamYesNo'  ]);
		$CCPCream       = clean($_POST['CCPCream'       ]);
		$CCPVitaminYesNo = clean($_POST['CCPVitaminYesNo']);
		$CCPVitamin     = clean($_POST['CCPVitamin'     ]);
		$CCPMilkYesNo   = clean($_POST['CCPMilkYesNo'   ]);
		$CCPMilk        = clean($_POST['CCPMilk'        ]);
		$CCPMetalYesNo  = clean($_POST['CCPMetalYesNo'  ]);
		$CCPMetal       = clean($_POST['CCPMetal'       ]);
		$CCPLactoseYesNo = clean($_POST['CCPLactoseYesNo']);
		$CCPLactose     = clean($_POST['CCPLactose'     ]);
		$Interruption   = clean($_POST['Interruption'   ]);
		$MaintArea      = clean($_POST['MaintArea'      ]);
		$MaintProc      = clean($_POST['MaintProc'      ]);
		$Labelling      = clean($_POST['Labelling'      ]);
		
		$extra = array();
		$extra[0]['Nature'   ] = clean($_POST['Nature0'   ]);
		$extra[0]['Parameter'] = clean($_POST['Parameter0']);
		$extra[0]['Units'    ] = clean($_POST['Units0'    ]);
		$extra[0]['Action'   ] = clean($_POST['Action0'   ]);
		$extra[1]['Nature'   ] = clean($_POST['Nature1'   ]);
		$extra[1]['Parameter'] = clean($_POST['Parameter1']);
		$extra[1]['Units'    ] = clean($_POST['Units1'    ]);
		$extra[1]['Action'   ] = clean($_POST['Action1'   ]);
		$extra[2]['Nature'   ] = clean($_POST['Nature2'   ]);
		$extra[2]['Parameter'] = clean($_POST['Parameter2']);
		$extra[2]['Units'    ] = clean($_POST['Units2'    ]);
		$extra[2]['Action'   ] = clean($_POST['Action2'   ]);
		$extra[3]['Nature'   ] = clean($_POST['Nature3'   ]);
		$extra[3]['Parameter'] = clean($_POST['Parameter3']);
		$extra[3]['Units'    ] = clean($_POST['Units3'    ]);
		$extra[3]['Action'   ] = clean($_POST['Action3'   ]);
		$extra[4]['Nature'   ] = clean($_POST['Nature4'   ]);
		$extra[4]['Parameter'] = clean($_POST['Parameter4']);
		$extra[4]['Units'    ] = clean($_POST['Units4'    ]);
		$extra[4]['Action'   ] = clean($_POST['Action4'   ]);
		$extra[5]['Nature'   ] = clean($_POST['Nature5'   ]);
		$extra[5]['Parameter'] = clean($_POST['Parameter5']);
		$extra[5]['Units'    ] = clean($_POST['Units5'    ]);
		$extra[5]['Action'   ] = clean($_POST['Action5'   ]);
		$extra[6]['Nature'   ] = clean($_POST['Nature6'   ]);
		$extra[6]['Parameter'] = clean($_POST['Parameter6']);
		$extra[6]['Units'    ] = clean($_POST['Units6'    ]);
		$extra[6]['Action'   ] = clean($_POST['Action6'   ]);
		$extra[7]['Nature'   ] = clean($_POST['Nature7'   ]);
		$extra[7]['Parameter'] = clean($_POST['Parameter7']);
		$extra[7]['Units'    ] = clean($_POST['Units7'    ]);
		$extra[7]['Action'   ] = clean($_POST['Action7'   ]);
		$extra[8]['Nature'   ] = clean($_POST['Nature8'   ]);
		$extra[8]['Parameter'] = clean($_POST['Parameter8']);
		$extra[8]['Units'    ] = clean($_POST['Units8'    ]);
		$extra[8]['Action'   ] = clean($_POST['Action8'   ]);
		$extra[9]['Nature'   ] = clean($_POST['Nature9'   ]);
		$extra[9]['Parameter'] = clean($_POST['Parameter9']);
		$extra[9]['Units'    ] = clean($_POST['Units9'    ]);
		$extra[9]['Action'   ] = clean($_POST['Action9'   ]);
	
		$sql="
			Insert Into dw_releasemain                (rmCypher, rmSampling, rmCCPCreamYesNo, rmCCPCream, rmCCPVitaminYesNo, rmCCPVitamin, rmCCPMilkYesNo, rmCCPMilk, rmCCPMetalYesNo, rmCCPMetal, rmCCPLactoseYesNo, rmCCPLactose, rmInterruption, rmMaintArea, rmMaintProc, rmLabelling, rmModUser, rmModDate)
			Values                                    (  ?     ,   ?       ,   ?            ,   ?       ,   ?              ,   ?         ,   ?           ,   ?      ,   ?            ,   ?       ,   ?              ,   ?         ,   ?           ,   ?        ,   ?        ,   ?        ,   ?      ,   now()  )
		";
		if(!savesql($link, $sql, "isssssssssssssssi", array( $Cypher,  $Sampling,  $CCPCreamYesNo,  $CCPCream,  $CCPVitaminYesNo,  $CCPVitamin,  $CCPMilkYesNo,  $CCPMilk,  $CCPMetalYesNo,  $CCPMetal,  $CCPLactoseYesNo,  $CCPLactose,  $Interruption,  $MaintArea,  $MaintProc,  $Labelling, $_SESSION['userID'] ), __FILE__, __LINE__)) reporterror(get_error(), $sql, $_SERVER['REQUEST_URI'], __FILE__, __LINE__);
		$sql="
			Select
			  rmID
			From
			  dw_releasemain
			Where
				rmID > ?
			Order By
			  rmID Desc
			Limit 1
		";
		if(!$getid = mysqli_prepared_query($link, $sql, "i", array(0), __FILE__, __LINE__)) reporterror(get_error(), $sql, $_SERVER['REQUEST_URI'], __FILE__, __LINE__);
		$mainid = $getid[0];
		foreach($extra as $item){
			if($item['Nature']!='' && $item['Nature']!=null){
				$sql="
					Insert Into dw_releasesub     (       rsMain  ,      rsNature  ,      rsParameter  ,      rsUnits,        rsAction  )
					Values                        (         ?     ,        ?       ,        ?          ,        ?    ,          ?       )
				";
				if(!savesql($link, $sql, "issss", array($mainid['rmID'], $item['Nature'], $item['Parameter'], $item['Units'], $item['Action']), __FILE__, __LINE__)) reporterror(get_error(), $sql, $_SERVER['REQUEST_URI'], __FILE__, __LINE__);
			}
		}
	}else{
		if(isset($_GET['view']) && $_GET['view']!='' && $_GET['view']!=null){
			$rmID = clean($_GET['view']);
			$sql="
				# update this form
				Select
				  dw_cypher.cypherText,
				  dw_cypher.cypherOrderID,
				  dw_spec.specText,
				  dw_releasemain.rmSampling,
				  dw_releasemain.rmCCPCreamYesNo,
				  dw_releasemain.rmCCPCream,
				  dw_releasemain.rmCCPVitaminYesNo,
				  dw_releasemain.rmCCPVitamin,
				  dw_releasemain.rmCCPMilkYesNo,
				  dw_releasemain.rmCCPMilk,
				  dw_releasemain.rmCCPMetalYesNo,
				  dw_releasemain.rmCCPMetal,
				  dw_releasemain.rmCCPLactoseYesNo,
				  dw_releasemain.rmCCPLactose,
				  dw_releasemain.rmInterruption,
				  dw_releasemain.rmMaintArea,
				  dw_releasemain.rmMaintProc,
				  dw_releasemain.rmLabelling,
				  dw_releasemain.rmModDate,
				  dw_user.userFirst,
				  dw_user.userLast
				From
				  ((dw_releasemain Left Join
				  dw_cypher
					On dw_releasemain.rmCypher = dw_cypher.cypherID) Left Join
				  dw_spec
					On dw_cypher.cypherSpec = dw_spec.specID) Left Join
				  dw_user
					On dw_releasemain.rmModUser = dw_user.userID
				Where
				  dw_releasemain.rmID = ? And
				  dw_cypher.cypherSite = ?
			";
			if(!$select_query = mysqli_prepared_query($link, $sql, "ii", array($rmID, $_SESSION['userSite']), __FILE__, __LINE__)) reporterror(get_error(), $sql, $_SERVER['REQUEST_URI'], __FILE__, __LINE__);
			if(mysqli_prepared_num_rows($select_query)>0){
				$rmain = $select_query[0];
				require "inc/pdf/fpdf.php";
				$pdf = new FPDF();
				$pdf->AddPage();
				
				$pdf->Image('images/'.$_SESSION['userSite'].'/company_logo_pdf.jpg',10,10,0,13,'jpg', $_SESSION['website']);
				$pdf->SetFont('Arial','B',16);
				$pdf->Cell(0,15,'Production Release',0,1,'C');
				$pdf->Image('images/cow_pdf.jpg',190,10,0,13,'jpg','https://www.dairywindow.nz');
				
				$pdf->SetFont('Arial','',10);
				$pdf->Cell(0,10,'Production of '.$rmain['cypherText'].' '.$rmain['cypherOrderID'].' '.$rmain['specText'].' is hereby released with the following notes:',0,1);
				
				$pdf->MultiCell(0,5,"All process sampling and control procedures, including CCP's were followed and all production records have been completed accurately and fully:");
				$pdf->SetTextColor(0,0,128); //Navy
				$pdf->MultiCell(0,5, $rmain['rmSampling']);
				$pdf->Ln();
				
				$pdf->SetFont('Arial','U',10);
				$pdf->SetTextColor(0,0,0); //Black
				$pdf->Cell(30,5,"CCP sign off");
				$pdf->Cell(30,5,"Issues");
				$pdf->Cell(130,5,"Description",0,1);
				
				$pdf->SetFont('Arial','',10);
				$pdf->Cell(30,5,"200 micron filter");
				$pdf->SetTextColor(0,0,128); //Navy
				$pdf->Cell( 30,5, $rmain['rmCCPCreamYesNo']);
				$pdf->Cell(130,5, $rmain['rmCCPCream'],0,1);
				
				$pdf->SetFont('Arial','',10);
				$pdf->SetTextColor(0,0,0); //Black
				$pdf->Cell(30,5,"Vitamin addition");
				$pdf->SetTextColor(0,0,128); //Navy
				$pdf->Cell( 30,5, $rmain['rmCCPVitaminYesNo']);
				$pdf->Cell(130,5, $rmain['rmCCPVitamin'],0,1);
				
				$pdf->SetFont('Arial','',10);
				$pdf->SetTextColor(0,0,0); //Black
				$pdf->Cell(30,5,"Milk pasteurisation");
				$pdf->SetTextColor(0,0,128); //Navy
				$pdf->Cell( 30,5, $rmain['rmCCPMilkYesNo']);
				$pdf->Cell(130,5, $rmain['rmCCPMilk'],0,1);
				
				$pdf->SetFont('Arial','',10);
				$pdf->SetTextColor(0,0,0); //Black
				$pdf->Cell(30,5,"Metal detector");
				$pdf->SetTextColor(0,0,128); //Navy
				$pdf->Cell( 30,5, $rmain['rmCCPMetalYesNo']);
				$pdf->Cell(130,5, $rmain['rmCCPMetal'],0,1);
				
				$pdf->SetFont('Arial','',10);
				$pdf->SetTextColor(0,0,0); //Black
				$pdf->Cell(30,5,"Lactose filters");
				$pdf->SetTextColor(0,0,128); //Navy
				$pdf->Cell( 30,5, $rmain['rmCCPLactoseYesNo']);
				$pdf->Cell(130,5, $rmain['rmCCPLactose'],0,1);
				
				$pdf->Ln();
				$pdf->SetTextColor(0,0,0); //Black
				$pdf->MultiCell(0,5,"The following interruptions or significant variations to the process occurred:");
				$pdf->SetTextColor(0,0,128); //Navy
				$pdf->MultiCell(0,5, $rmain['rmInterruption']);
				
				$pdf->Ln();
				$pdf->SetTextColor(0,0,0); //Black
				$pdf->Cell(40,5,"Nature of problem");
				$pdf->Cell(60,5,"In-process parameter outside limits");
				$pdf->Cell(40,5,"Unit range affected");
				$pdf->Cell(50,5,"Action taken",0,1);
				$pdf->SetTextColor(0,0,128); //Navy
				
				//sub
				$sql="
					Select
					  rsNature,
					  rsParameter,
					  rsUnits,
					  rsAction
					From
					  dw_releasesub
					Where
					  rsMain = ?
				";
				if(!$sub_query = mysqli_prepared_query($link, $sql, "i", array($rmID), __FILE__, __LINE__)) reporterror(get_error(), $sql, $_SERVER['REQUEST_URI'], __FILE__, __LINE__);
				foreach($sub_query as $rsub){
					$pdf->Cell(40,5, $rsub['rsNature']);
					$pdf->Cell(60,5, $rsub['rsParameter']);
					$pdf->Cell(40,5, $rsub['rsUnits']);
					$pdf->Cell(50,5, $rsub['rsAction'],0,1);
				}
				
				$pdf->Ln();
				$pdf->SetTextColor(0,0,0); //Black
				$pdf->MultiCell(0,5,"Intrusive maintenance was undertaken in the following areas:");
				$pdf->SetTextColor(0,0,128); //Navy
				$pdf->MultiCell(0,5, $rmain['rmMaintArea']);
				
				$pdf->Ln();
				$pdf->SetTextColor(0,0,0); //Black
				$pdf->MultiCell(0,5,"Intrusive maintenance procedures and documentation completed:");
				$pdf->SetTextColor(0,0,128); //Navy
				$pdf->MultiCell(0,5, $rmain['rmMaintProc']);
				
				$pdf->Ln();
				$pdf->SetTextColor(0,0,0); //Black
				$pdf->MultiCell(0,5,"The packaging, labelling and identification of the product was checked and complies with the instructions provided:");
				$pdf->SetTextColor(0,0,128); //Navy
				$pdf->MultiCell(0,5, $rmain['rmLabelling']);
				
				$pdf->Ln();
				$pdf->SetTextColor(0,0,0); //Black
				$pdf->Cell(0,5,"The above information is true and correct:",0,1);
				$pdf->SetTextColor(0,0,128); //Navy
				$pdf->Cell(0,5, $rmain['userFirst']." ".$rmain['userLast']." ".date('d M y',strtotime($rmain['rmModDate'])));
				
				$pdf->Output();
				exit();
			}
		}
	}
	
	$title = "Product release";
	require "inc/head.php";
	$menu = "prodrelease";
	require "inc/menu.php";
	
	if($debug) showdebug();
?>

<div id="topDIV" >
	<h1 class="text-center">
		<?php
			echo $title;
			if($_SESSION['userLevel']<= $_SESSION['admin_form_add']){
				?><button type="button" class="btn btn-primary" data-toggle="modal" data-target="#new_form" ><span class='glyphicon glyphicon-plus' aria-hidden='true'></span>&nbsp;Create new</button><?php
			}
		?>
	</h1>
</div>

<div id="loading" ><img src="images/loading-small.gif" alt="Please wait. Loading..." width="111" height="156" style="margin-top:150px;" class="center-block"><br><div class="text-center"><img src='images/carregando.gif' width='16' height='16'>&nbsp;Please wait while loading...</div></div>

<div id="main" class="container-fluid" style="display:none;" role="main">
	<table class="table table-hover" id="table">
		<thead>
			<tr id="table-head" style="background-color:white; color:inherit; white-space:nowrap;">
				<th class="text-center th_cypher" id="th_cypher" ><?php echo $cypherorbatch; ?></th>
				<th class="text-center th_spec"   id="th_spec"   >Product</th>
				<th class="text-center th_name"   id="th_name"   >Created by</th>
				<th class="text-center th_date"   id="th_date"   >Date</th>
			</tr>
		</thead>
		<tbody>
			<?php
				$sql="
					# sql for main table
					Select
						dw_cypher.cypherText,
						dw_cypher.cypherOrderID,
						dw_releasemain.rmID,
						dw_spec.specText,
						dw_user.userFirst,
						dw_user.userLast,
						dw_releasemain.rmModDate,
						dw_cypher.cypherID
					From
						((dw_releasemain Left Join
						dw_cypher
							On dw_releasemain.rmCypher = dw_cypher.cypherID) Left Join
						dw_spec
							On dw_cypher.cypherSpec = dw_spec.specID) Left Join
						dw_user
							On dw_releasemain.rmModUser = dw_user.userID
					Where
						dw_cypher.cypherSite = ?
					Order By
						dw_cypher.cypherManuDate Desc
				";
				if(!$form_query = mysqli_prepared_query($link, $sql, "i", array($_SESSION['userSite']), __FILE__, __LINE__)) reporterror(get_error(), $sql, $_SERVER['REQUEST_URI'], __FILE__, __LINE__);
				foreach($form_query as $form_row){
					?>
						<tr class="text-nowrap" id="form_<?php echo $form_row['rmID']; ?>">
							<td class="text-center td_cypher" id="td_cypher_<?php echo $form_row['rmID']; ?>" ><a href="?view=<?php echo $form_row['rmID']; ?>" ><?php echo $form_row['cypherText']." ".$form_row['cypherOrderID']; ?></a></td>
							<td class="text-center td_spec"   id="td_spec_<?php   echo $form_row['rmID']; ?>" ><a href="?view=<?php echo $form_row['rmID']; ?>" ><?php echo $form_row['specText'  ]; ?></a></td>
							<td class="text-center td_name"   id="td_name_<?php   echo $form_row['rmID']; ?>" ><a href="?view=<?php echo $form_row['rmID']; ?>" ><?php echo $form_row['userFirst']." ".$form_row['userLast']; ?></a></td>
							<td class="text-center td_date"   id="td_date_<?php   echo $form_row['rmID']; ?>" ><a href="?view=<?php echo $form_row['rmID']; ?>" ><?php echo date('d/m/y',strtotime($form_row['rmModDate'])); ?></a></td>
						</tr>
					<?php
				}
			?>
		</tbody>
	</table>
</div>

<div id="new_form" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="new_formLabel" aria-hidden="true">
	<div class="modal-dialog modal-lg">
		<div class="modal-content">
			<form class="container-fluid panel-info form-horizontal" method="post">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
					<h2 class="modal-title" id="new_formLabel">Production release</h2>
				</div>
				<div class="modal-body">
					<div class="form-group">
						<label for="Cypher" class="col-sm-2 control-label">Cypher:</label>
						<div class="col-sm-10">
							<?php
								$sql="
									Select
										dw_cypher.cypherID,
										dw_cypher.cypherText,
										dw_cypher.cypherOrderID,
										dw_spec.specText
									From
										dw_cypher Left Join
										dw_spec
										On dw_cypher.cypherSpec = dw_spec.specID
									Where
										dw_cypher.cypherSite = ? And
										dw_spec.specStyle = 1 And
										dw_spec.specActive = 1 And
										dw_cypher.cypherID Not In (
											Select
											rmCypher
										From
											dw_releasemain
										)
									Order By
										dw_cypher.cypherManuDate Desc,
										dw_spec.specOrder
								";
								if(!$cypher_query = mysqli_prepared_query($link, $sql, "i", array($_SESSION['userSite']), __FILE__, __LINE__)) reporterror(get_error(), $sql, $_SERVER['REQUEST_URI'], __FILE__, __LINE__);
							?>
							<select name='Cypher' id='Cypher' class='form-control' >
								<?php
									if(mysqli_prepared_num_rows($cypher_query)==0){
										echo "<option value='0'>All ".$cypherorbatch."s have been completed</option>";
									}else{
										foreach($cypher_query as $cypher){
											echo "<option value='".$cypher['cypherID']."'>".$cypher['cypherText']." ".$cypher['cypherOrderID'];
											if($debug) echo " [".$cypher['cypherID']."]";
											echo " ".$cypher['specText']."</option>";
										}
									}
								?>
							</select>
						</div>
					</div>
					<div class="form-group">
						<label for="Sampling" class="col-sm-2 control-label">All process sampling and control procedures including CCP's were followed and all production records have been completed accurately and fully:</label>
						<div class="col-sm-10">
							<textarea class='form-control' id="Sampling" name="Sampling" style="height:140px;resize:none;" rows="7" required ></textarea>
						</div>
					</div>
					<div class="form-group">
						<label for="CCPCreamYesNo" class="col-sm-2 control-label">200 micron filter</label>
						<div class="col-sm-2">
							<input type="text" class="form-control" id="CCPCreamYesNo" name="CCPCreamYesNo" placeholder="Issues?" required >
						</div>
						<div class="col-sm-8">
							<input type="text" class="form-control" id="CCPCream" name="CCPCream" placeholder="Description of issue(s)" >
						</div>
					</div>
					<div class="form-group">
						<label for="CCPVitaminYesNo" class="col-sm-2 control-label">Vitamin addition</label>
						<div class="col-sm-2">
							<input type="text" class="form-control" id="CCPVitaminYesNo" name="CCPVitaminYesNo" placeholder="Issues?" required >
						</div>
						<div class="col-sm-8">
							<input type="text" class="form-control" id="CCPVitamin" name="CCPVitamin" placeholder="Description of issue(s)" >
						</div>
					</div>
					<div class="form-group">
						<label for="CCPMilkYesNo" class="col-sm-2 control-label">Milk pasteurisation</label>
						<div class="col-sm-2">
							<input type="text" class="form-control" id="CCPMilkYesNo" name="CCPMilkYesNo" placeholder="Issues?" required >
						</div>
						<div class="col-sm-8">
							<input type="text" class="form-control" id="CCPMilk" name="CCPMilk" placeholder="Description of issue(s)" >
						</div>
					</div>
					<div class="form-group">
						<label for="CCPMetalYesNo" class="col-sm-2 control-label">Metal detector</label>
						<div class="col-sm-2">
							<input type="text" class="form-control" id="CCPMetalYesNo" name="CCPMetalYesNo" placeholder="Issues?" required >
						</div>
						<div class="col-sm-8">
							<input type="text" class="form-control" id="CCPMetal" name="CCPMetal" placeholder="Description of issue(s)" >
						</div>
					</div>
					<div class="form-group">
						<label for="CCPLactoseYesNo" class="col-sm-2 control-label">Lactose filters</label>
						<div class="col-sm-2">
							<input type="text" class="form-control" id="CCPLactoseYesNo" name="CCPLactoseYesNo" placeholder="Issues?" required >
						</div>
						<div class="col-sm-8">
							<input type="text" class="form-control" id="CCPLactose" name="CCPLactose" placeholder="Description of issue(s)" >
						</div>
					</div>
					<div class="form-group">
						<label for="Interruption" class="col-sm-2 control-label">The following interruptions or significant variations to the process occurred:</label>
						<div class="col-sm-10">
							<textarea class='form-control' id="Interruption" name="Interruption" style="height:80px;resize:none;" rows="4" required ></textarea>
						</div>
					</div>
					<div class="form-group" id="sub0" >
						<div class="col-sm-4">
							<input type="text" class="form-control" id="Nature0" name="Nature0" placeholder="Nature of problem" onchange="showdiv('sub1');" >
						</div>
						<div class="col-sm-2">
							<input type="text" class="form-control" id="Parameter0" name="Parameter0" placeholder="Parameter" onchange="showdiv('sub1');" >
						</div>
						<div class="col-sm-2">
							<input type="text" class="form-control" id="Units0" name="Units0" placeholder="Units affected" onchange="showdiv('sub1');" >
						</div>
						<div class="col-sm-4">
							<input type="text" class="form-control" id="Action0" name="Action0" placeholder="Action taken" onchange="showdiv('sub1');" >
						</div>
					</div>
					<div class="form-group" id="sub1" style="display:none;" >
						<div class="col-sm-4">
							<input type="text" class="form-control" id="Nature1" name="Nature1" placeholder="Nature of problem" onchange="showdiv('sub2');" >
						</div>
						<div class="col-sm-2">
							<input type="text" class="form-control" id="Parameter1" name="Parameter1" placeholder="Parameter" onchange="showdiv('sub2');" >
						</div>
						<div class="col-sm-2">
							<input type="text" class="form-control" id="Units1" name="Units1" placeholder="Units affected" onchange="showdiv('sub2');" >
						</div>
						<div class="col-sm-4">
							<input type="text" class="form-control" id="Action1" name="Action1" placeholder="Action taken" onchange="showdiv('sub2');" >
						</div>
					</div>
					<div class="form-group" id="sub2" style="display:none;" >
						<div class="col-sm-4">
							<input type="text" class="form-control" id="Nature2" name="Nature2" placeholder="Nature of problem" onchange="showdiv('sub3');" >
						</div>
						<div class="col-sm-2">
							<input type="text" class="form-control" id="Parameter2" name="Parameter2" placeholder="Parameter" onchange="showdiv('sub3');" >
						</div>
						<div class="col-sm-2">
							<input type="text" class="form-control" id="Units2" name="Units2" placeholder="Units affected" onchange="showdiv('sub3');" >
						</div>
						<div class="col-sm-4">
							<input type="text" class="form-control" id="Action2" name="Action2" placeholder="Action taken" onchange="showdiv('sub3');" >
						</div>
					</div>
					<div class="form-group" id="sub3" style="display:none;" >
						<div class="col-sm-4">
							<input type="text" class="form-control" id="Nature3" name="Nature3" placeholder="Nature of problem" onchange="showdiv('sub4');" >
						</div>
						<div class="col-sm-2">
							<input type="text" class="form-control" id="Parameter3" name="Parameter3" placeholder="Parameter" onchange="showdiv('sub4');" >
						</div>
						<div class="col-sm-2">
							<input type="text" class="form-control" id="Units3" name="Units3" placeholder="Units affected" onchange="showdiv('sub4');" >
						</div>
						<div class="col-sm-4">
							<input type="text" class="form-control" id="Action3" name="Action3" placeholder="Action taken" onchange="showdiv('sub4');" >
						</div>
					</div>
					<div class="form-group" id="sub4" style="display:none;" >
						<div class="col-sm-4">
							<input type="text" class="form-control" id="Nature4" name="Nature4" placeholder="Nature of problem" onchange="showdiv('sub5');" >
						</div>
						<div class="col-sm-2">
							<input type="text" class="form-control" id="Parameter4" name="Parameter4" placeholder="Parameter" onchange="showdiv('sub5');" >
						</div>
						<div class="col-sm-2">
							<input type="text" class="form-control" id="Units4" name="Units4" placeholder="Units affected" onchange="showdiv('sub5');" >
						</div>
						<div class="col-sm-4">
							<input type="text" class="form-control" id="Action4" name="Action4" placeholder="Action taken" onchange="showdiv('sub5');" >
						</div>
					</div>
					<div class="form-group" id="sub5" style="display:none;" >
						<div class="col-sm-4">
							<input type="text" class="form-control" id="Nature5" name="Nature5" placeholder="Nature of problem" onchange="showdiv('sub6');" >
						</div>
						<div class="col-sm-2">
							<input type="text" class="form-control" id="Parameter5" name="Parameter5" placeholder="Parameter" onchange="showdiv('sub6');" >
						</div>
						<div class="col-sm-2">
							<input type="text" class="form-control" id="Units5" name="Units5" placeholder="Units affected" onchange="showdiv('sub6');" >
						</div>
						<div class="col-sm-4">
							<input type="text" class="form-control" id="Action5" name="Action5" placeholder="Action taken" onchange="showdiv('sub6');" >
						</div>
					</div>
					<div class="form-group" id="sub6" style="display:none;" >
						<div class="col-sm-4">
							<input type="text" class="form-control" id="Nature6" name="Nature6" placeholder="Nature of problem" onchange="showdiv('sub7');" >
						</div>
						<div class="col-sm-2">
							<input type="text" class="form-control" id="Parameter6" name="Parameter6" placeholder="Parameter" onchange="showdiv('sub7');" >
						</div>
						<div class="col-sm-2">
							<input type="text" class="form-control" id="Units6" name="Units6" placeholder="Units affected" onchange="showdiv('sub7');" >
						</div>
						<div class="col-sm-4">
							<input type="text" class="form-control" id="Action6" name="Action6" placeholder="Action taken" onchange="showdiv('sub7');" >
						</div>
					</div>
					<div class="form-group" id="sub7" style="display:none;" >
						<div class="col-sm-4">
							<input type="text" class="form-control" id="Nature7" name="Nature7" placeholder="Nature of problem" onchange="showdiv('sub8');" >
						</div>
						<div class="col-sm-2">
							<input type="text" class="form-control" id="Parameter7" name="Parameter7" placeholder="Parameter" onchange="showdiv('sub8');" >
						</div>
						<div class="col-sm-2">
							<input type="text" class="form-control" id="Units7" name="Units7" placeholder="Units affected" onchange="showdiv('sub8');" >
						</div>
						<div class="col-sm-4">
							<input type="text" class="form-control" id="Action7" name="Action7" placeholder="Action taken" onchange="showdiv('sub8');" >
						</div>
					</div>
					<div class="form-group" id="sub8" style="display:none;" >
						<div class="col-sm-4">
							<input type="text" class="form-control" id="Nature8" name="Nature8" placeholder="Nature of problem" onchange="showdiv('sub9');" >
						</div>
						<div class="col-sm-2">
							<input type="text" class="form-control" id="Parameter8" name="Parameter8" placeholder="Parameter" onchange="showdiv('sub9');" >
						</div>
						<div class="col-sm-2">
							<input type="text" class="form-control" id="Units8" name="Units8" placeholder="Units affected" onchange="showdiv('sub9');" >
						</div>
						<div class="col-sm-4">
							<input type="text" class="form-control" id="Action8" name="Action8" placeholder="Action taken" onchange="showdiv('sub9');" >
						</div>
					</div>
					<div class="form-group" id="sub9" style="display:none;" >
						<div class="col-sm-4">
							<input type="text" class="form-control" id="Nature9" name="Nature9" placeholder="Nature of problem" >
						</div>
						<div class="col-sm-2">
							<input type="text" class="form-control" id="Parameter9" name="Parameter9" placeholder="Parameter" >
						</div>
						<div class="col-sm-2">
							<input type="text" class="form-control" id="Units9" name="Units9" placeholder="Units affected" >
						</div>
						<div class="col-sm-4">
							<input type="text" class="form-control" id="Action9" name="Action9" placeholder="Action taken" >
						</div>
					</div>
					
					<div class="form-group">
						<label for="MaintArea" class="col-sm-2 control-label">Intrusive Maintenance was undertaken in the following areas:</label>
						<div class="col-sm-10">
							<textarea class='form-control' id="MaintArea" name="MaintArea" style="height:60px;resize:none;" rows="3" required ></textarea>
						</div>
					</div>
					<div class="form-group">
						<label for="MaintProc" class="col-sm-2 control-label">All Intrusive Maintenance procedures and documentation completed:</label>
						<div class="col-sm-10">
							<textarea class='form-control' id="MaintProc" name="MaintProc" style="height:100px;resize:none;" rows="5" required ></textarea>
						</div>
					</div>
					<div class="form-group">
						<label for="Labelling" class="col-sm-2 control-label">The packaging, labelling and identification of the product was checked and complies with the instructions provided:</label>
						<div class="col-sm-10">
							<textarea class='form-control' id="Labelling" name="Labelling" style="height:100px;resize:none;" rows="5" required ></textarea>
						</div>
					</div>
					
				</div>
				<div class="modal-footer">
					<button type="button" class="btn btn-default" data-dismiss="modal"><span class='glyphicon glyphicon-remove' aria-hidden='true'></span>&nbsp;Cancel</button>
					<button type="submit" class="btn btn-primary" id="new_form_button" onclick="please_wait('new_form_button');"><span class='glyphicon glyphicon-ok' aria-hidden='true'></span>&nbsp;Create</button>
				</div>
			</form>
		</div>
	</div>
</div>

<?php require "inc/footer.php"; ?>