<?php

	require "inc/connect.php";

	require "inc/fade.php";
	require "inc/texttonumber.php";
	require "inc/numbertotext.php";

	if($debug) showdebug();

	//$_SESSION['inspection_comment_limit']=50;
	if(isset($_GET['btnSent']) && isset($_GET['c'])){
		$sql="
			# mark cypher as coa printed
			UPDATE dw_cypher SET
				cypherCOA   = 1
			WHERE cypherID = ?
		";
		if(!savesql($link, $sql, "i", array($_GET['c']), __FILE__, __LINE__)) reporterror(get_error(), $sql, $_SERVER['REQUEST_URI'], __FILE__, __LINE__);
	}else{
		if(isset($_GET['btnUnsent']) && isset($_GET['c'])){
			$sql="
				# mark cypher as coa UNprinted
				UPDATE dw_cypher SET
					cypherCOA   = 0
				WHERE cypherID = ?
			";
			if(!savesql($link, $sql, "i", array($_GET['c']), __FILE__, __LINE__)) reporterror(get_error(), $sql, $_SERVER['REQUEST_URI'], __FILE__, __LINE__);
		}
	}
	if(!isset($_GET['btnPDF'])){
		$title = "Inspection";
		require "inc/head.php";
		$menu = "inspection";
		require "inc/menu.php";
		echo "
			<h1 class='text-center'>Inspection</h1>
			<div role='supplementary' class='col-md-3' >
				<form method='get' name='Form1' id='Form1' class='form-horizontal'>
					<div class='form-group'>
						<select name='c' id='c' onchange=\"document.getElementById('Form1').submit();\" class='form-control'>
		";
		$sql="
			Select
				dw_cypher.cypherID,
				dw_cypher.cypherManuDate,
				dw_cypher.cypherText,
				dw_cypher.cypherOrderID,
				dw_spec.specText,
				dw_cypher.cypherNotesFP,
				dw_cypher.cypherCOA,
				dw_spec.specStyle
			From
				dw_spec Right Join
				dw_cypher
					On dw_spec.specID = dw_cypher.cypherSpec
			Where
				dw_spec.specActive        = 1 And
				dw_spec.specStyle        >= 2 And
				dw_spec.specStyle        <= 3 And
				dw_spec.specSend          = 1 And
				dw_cypher.cypherSite      = ? And
				dw_cypher.cypherManuDate >= ?
			Order By
				dw_cypher.cypherManuDate Desc,
				dw_spec.specOrder,
				dw_cypher.cypherNotesFP Desc
		";
		if(!$qrycypher = mysqli_prepared_query($link, $sql, "is", array($_SESSION['userSite'], $startDate), __FILE__, __LINE__)) reporterror(get_error(), $sql, $_SERVER['REQUEST_URI'], __FILE__, __LINE__);

		foreach($qrycypher as $cypherarray){
			echo "<option value='".$cypherarray['cypherID']."'";
			if(isset($_GET['c']) && $_GET['c']==$cypherarray['cypherID']) echo " selected='selected'";
			echo ">";
			if($debug) echo "[".$cypherarray['cypherID']."] ";
			echo date('d/m/y',strtotime($cypherarray['cypherManuDate']))." ".$cypherarray['specText']." ".substr($cypherarray['cypherNotesFP'],0,20);
			if(strlen($cypherarray['cypherNotesFP'])>20) echo "&hellip;";
			if($cypherarray['cypherCOA']==1 || $cypherarray['cypherCOA']=="1") echo "&#x2713;"; //tick
			echo "</option>";
		}
		echo "
					<option value='0'>[Edit your profile to see more]</option>
				</select>
			</div>
			<div class='form-group'>
				<input name='btnView' type='submit' value='View preview' class='btn btn-primary'>
		";
		if(isset($_GET['c']) && $_GET['c']!="" && $_GET['c']!=null){
			$sql="
				Select
					dw_cypher.cypherCOA
				From
					dw_cypher
				Where
					dw_cypher.cypherID = ?
			";
			if(!$qrysent = mysqli_prepared_query($link, $sql, "i", array($_GET['c']), __FILE__, __LINE__)) reporterror(get_error(), $sql, $_SERVER['REQUEST_URI'], __FILE__, __LINE__);
			$sentarray = $qrysent[0];
			$cyphercoa = $sentarray['cypherCOA'];

			if($cyphercoa==1 || $cyphercoa=="1") echo "<input name='btnUnsent' type='submit' value='Mark as unsent' class='btn btn-default'>";
			else echo "<input name='btnSent' type='submit' value='Mark as sent' class='btn btn-default' >";
		}
		echo "
						<input name='btnPDF' type='submit' value='View PDF' class='btn btn-default'>
					</div>
				</form>
			</div>
			<script>
				dropdown('#c');
			</script>
		";
	}
	if(isset($_GET['c']) && $_GET['c']!="" && $_GET['c']!=null){
		$sql="
			# main
			Select
				dw_cypher.cypherManuDate,
				dw_cypher.cypherText,
				dw_cypher.cypherOrderID,
				dw_cypher.cypherModUser,
				dw_cypher.cypherCOA,
				dw_spec.specText,
				dw_spec.specShortDesc,
				dw_spec.specID,
				dw_cypher.cypherNotesFP,
				dw_spec.specUnitTypeText,
				dw_user.userFirst,
				dw_user.userLast
			From
				dw_spec Right Join
				(dw_user Right Join
				dw_cypher
					On dw_user.userID = dw_cypher.cypherModUser)
					On dw_spec.specID = dw_cypher.cypherSpec
			Where
				dw_cypher.cypherID = ?
		";
		if(!$qrycypher = mysqli_prepared_query($link, $sql, "i", array($_GET['c']), __FILE__, __LINE__)) reporterror(get_error(), $sql, $_SERVER['REQUEST_URI'], __FILE__, __LINE__);
		$cypherarray = $qrycypher[0];
		$specID = $cypherarray['specID'];
		$specText = $cypherarray['specText'];
		$cypherText = $cypherarray['cypherText'];
		$cypherOrderID = $cypherarray['cypherOrderID'];
		$specUnitTypeText = $cypherarray['specUnitTypeText'];
		if($specUnitTypeText=="" || $specUnitTypeText==null) $specUnitTypeText = "Sample";
		$cypherModUser = $cypherarray['cypherModUser'];
		if($cypherModUser=="" || $cypherModUser==null) $cypherModUser = 0;
		if(isset($_GET['btnPDF'])){
			require("inc/pdf/fpdf.php");

			class PDF extends FPDF{
				function Header(){
					global $link;

					$this->Image('images/'.$_SESSION['userSite'].'/company_logo_pdf.jpg',10,5,30); //Company logo
					$this->Image('images/'.$_SESSION['userSite'].'/transport.png',130,7,70); //Transport logo
				}
				function Footer(){
					global $link;

					$this->SetFont('Arial','',10);
					$this->SetXY(10,-50);
					$this->Image('images/sigs/'.$_SESSION['userID'].'.jpg',75,230,50,20); //width='300' height='100'
					$this->Cell(60,8,"");
					$this->SetFont('Arial','B',10);
					$this->Cell(20,8,"Signatory",0,0,'L',1);
					$this->SetFont('Arial','',10);
					$this->Cell(60,8, $_SESSION['userFirst']." ".$_SESSION['userLast'],0,1,'L',1);
					$this->Cell(60,8,"");
					$this->SetFont('Arial','B',10);
					$this->Cell(20,8,"Title",0,0,'L',1);
					$this->SetFont('Arial','',10);
					$this->Cell(60,8, $_SESSION['userTitle'],0,1,'L',1);

					$this->SetFont('Arial','I',10);
					$this->Cell(190,8,"Report not valid unless signed",0,1,'C',1);

					$this->SetFont('Arial','B',10);
					$this->Cell(20,8,"");
					$this->Cell(100,8,"Follow up",1,0,'C',1);
					$this->Cell(35,8,"Date",1,0,'C',1);
					$this->Cell(20,8,"Sign",1,1,'C',1);

					$this->Cell(20,8,"");
					$this->Cell(100,8,"",1,0,'C',1);
					$this->Cell(35,8,"",1,0,'C',1);
					$this->Cell(20,8,"",1,1,'C',1);

					//$this->Ln();

					$this->SetFont('Arial','',8);
					$this->Cell(65,10,'Printed '.date('j/n/y G:i'),0,0,'L');
					$this->Cell(65,10,'DairyWindow inspection Version 1',0,0,'C');
					$this->Cell(65,10,'Page '.$this->PageNo().' of {nb}',0,0,'R'); //Page x of nb
				}

				//Cell with horizontal scaling if text is too wide
				function CellFit($w, $h=0, $txt='', $border=0, $ln=0, $align='', $fill=false, $link='', $scale=false, $force=true){
					//Get string width
					$str_width= $this->GetStringWidth($txt);

					//Calculate ratio to fit cell
					if($w==0) $w = $this->w-$this->rMargin-$this->x;
					if($str_width==0) $ratio = ($w-$this->cMargin*2);
					else $ratio = ($w-$this->cMargin*2)/$str_width;

					$fit = ($ratio < 1 || ($ratio > 1 && $force));
					if ($fit){
						if ($scale)	{
							//Calculate horizontal scaling
							$horiz_scale= $ratio*100.0;
							//Set horizontal scaling
							$this->_out(sprintf('BT %.2F Tz ET', $horiz_scale));
						}else{
							//Calculate character spacing in points
							$char_space=($w-$this->cMargin*2-$str_width)/max($this->MBGetStringLength($txt)-1, 1)*$this->k;
							//Set character spacing
							$this->_out(sprintf('BT %.2F Tc ET', $char_space));
						}
						//Override user alignment (since text will fill up cell)
						$align='';
					}

					//Pass on to Cell method
					$this->Cell($w, $h, $txt, $border, $ln, $align, $fill, $link);

					//Reset character spacing/horizontal scaling
					if($fit) $this->_out('BT '.($scale ? '100 Tz' : '0 Tc').' ET');
				}

				//Cell with horizontal scaling only if necessary
				function CellFitScale($w, $h=0, $txt='', $border=0, $ln=0, $align='', $fill=false, $link=''){
					$this->CellFit($w, $h, $txt, $border, $ln, $align, $fill, $link, true, false);
				}

				//Cell with horizontal scaling always
				function CellFitScaleForce($w, $h=0, $txt='', $border=0, $ln=0, $align='', $fill=false, $link=''){
					$this->CellFit($w, $h, $txt, $border, $ln, $align, $fill, $link, true, true);
				}

				//Cell with character spacing only if necessary
				function CellFitSpace($w, $h=0, $txt='', $border=0, $ln=0, $align='', $fill=false, $link=''){
					$this->CellFit($w, $h, $txt, $border, $ln, $align, $fill, $link, false, false);
				}

				//Cell with character spacing always
				function CellFitSpaceForce($w, $h=0, $txt='', $border=0, $ln=0, $align='', $fill=false, $link=''){
					//Same as calling CellFit directly
					$this->CellFit($w, $h, $txt, $border, $ln, $align, $fill, $link, false, true);
				}

				//Patch to also work with CJK double-byte text
				function MBGetStringLength($s){
					if($this->CurrentFont['type']=='Type0'){
						$len = 0;
						$nbbytes = strlen($s);
						for ($i = 0; $i < $nbbytes; $i++){
							if (ord($s[$i])<128)
								$len++;
							else{
								$len++;
								$i++;
							}
						}
						return $len;
					}
					else return strlen($s);
				}

			}
			$pdf=new PDF();
			$pdf->AliasNbPages(); // Total number of pages

			$pdf->SetDisplayMode('fullpage');

			$pdf->SetAuthor($_SESSION['userFirst']." ".$_SESSION['userLast'],1);
			$pdf->SetCreator('DairyWindow',1);
			$pdf->SetTitle('Inspection',1);
			$pdf->SetSubject($cypherText." - ".$specText,1);

			$pdf->AddPage('P');
			$pdf->SetFillColor(255,255,255); //Fill is white (to stop text flowover)
			$pdf->SetTextColor(0,0,0); //Black

			$pdf->SetFont('Arial','B',14);
			$pdf->Ln(10);
			$pdf->CellFitScale(190,8,strtoupper($cypherarray['specShortDesc']).' ASSESSMENT',0,1,'C');

			$pdf->SetFont('Arial','B',12);
			if($cypherarray['cypherNotesFP']!="" && $cypherarray['cypherNotesFP']!=null) $pdf->CellFitScale(190,8, $cypherarray['cypherNotesFP'],0,1,'C');

			$pdf->SetFont('Arial','',10);
			$pdf->CellFitScale(35,8,"");
			$pdf->CellFitScale(60,8,"Date of inspection:",1);
			$pdf->CellFitScale(60,8,date('l jS F, Y',strtotime($cypherarray['cypherManuDate'])),1,1);
			$pdf->CellFitScale(35,8,"");
			$pdf->CellFitScale(60,8,"Assessed by:",1);
			$pdf->CellFitScale(60,8, $cypherarray['userFirst']." ".$cypherarray['userLast'],1,1);
			$pdf->CellFitScale(35,8,"");
			$pdf->CellFitScale(60,8,"Copy to ".$_SESSION['transport_comp_name'],1);
			if($cypherarray['cypherCOA']==1 || $cypherarray['cypherCOA']=="1") $pdf->CellFitScale(60,8,"Yes",1,1,'L',1);
			else $pdf->CellFitScale(60,8,"No",1,1);
		}else{
			echo "<div role='main' class='col-md-9'>
			<h2>".strtoupper($cypherarray['specShortDesc'])." ASSESSMENT</h2>";
			if($cypherarray['cypherNotesFP']!="" && $cypherarray['cypherNotesFP']!=null) echo "<h3>".$cypherarray['cypherNotesFP']."</h3>";
			echo "
				<div class='row'>
					<div class='col-md-3'>Date of inspection:</div>
					<div class='col-md-9'>".date('l jS F, Y',strtotime($cypherarray['cypherManuDate']))."</div>
				</div>
				<div class='row'>
					<div class='col-md-3'>Assessed by:</div>
					<div class='col-md-9'>".$cypherarray['userFirst']." ".$cypherarray['userLast']."</div>
				</div>
				<div class='row'>
					<div class='col-md-3'>Copy to ".$_SESSION['transport_comp_name']."</div>
					<div class='col-md-9'>
						<form method='get' id='form1'>
							<input type='hidden' name='c' value='".$_GET['c']."'>
							<input name='"; if($cypherarray['cypherCOA']==1 || $cypherarray['cypherCOA']=="1") echo "btnUnsent"; else echo "btnSent"; echo "' type='hidden' value='1'>
							<input type='checkbox' data-toggle='toggle' data-on='Yes' data-off='No' data-onstyle='success' data-offstyle='danger' data-size='mini' id='cypherCOA' value='1' onchange=\"document.getElementById('form1').submit();\" "; if($cypherarray['cypherCOA']==1 || $cypherarray['cypherCOA']=="1") echo "checked"; echo " >
						</form>
					</div>
				</div>
			";
		}
		$sql="
			Select Distinct
				dw_test.testID,
				dw_test.testTextCOA,
				dw_group.groupOrder,
				dw_test.testOrder
			From
				dw_group Right Join
				(dw_test Right Join
				((dw_cypher Right Join
				dw_unit
					On dw_cypher.cypherID = dw_unit.unitCypher) Right Join
				dw_result
					On dw_unit.unitID = dw_result.resultUnit)
					On dw_test.testID = dw_result.resultTest Left Join
				dw_location
					On dw_unit.unitLocation = dw_location.locationID)
					On dw_group.groupID = dw_test.testGroup
			Where
				dw_cypher.cypherID = ?
			Order By
				dw_group.groupOrder,
				dw_test.testOrder
		";
		if(!$qrytest = mysqli_prepared_query($link, $sql, "i", array($_GET['c']), __FILE__, __LINE__)) reporterror(get_error(), $sql, $_SERVER['REQUEST_URI'], __FILE__, __LINE__);
		$num_tests = mysqli_prepared_num_rows($qrytest);
		if($debug) echo "num_tests: ".$num_tests."<br/>";
		foreach($qrytest as $testarray){
			$testID[]= $testarray['testID'];
			$testText[]= $testarray['testTextCOA'];
		}

		//results
		if(isset($_GET['btnPDF'])){
			$pdf->Ln(10);
			$pdf->SetFont('Arial','B',12);
			$pdf->CellFitScale(190,8,'Test results',0,1,'C');
			$pdf->SetFont('Arial','B',10);
		}else echo "<h2>Test results</h2><table name='results' class='table'>";
		$sql="
			# results
			Select Distinct
				dw_location.locationID,
				dw_location.locationText,
				dw_unit.unitText,
				dw_location.locationOrder
			From
				dw_group Right Join
				(dw_test Right Join
				((dw_cypher Right Join
				dw_unit
					On dw_cypher.cypherID = dw_unit.unitCypher) Right Join
				dw_result
					On dw_unit.unitID = dw_result.resultUnit)
					On dw_test.testID = dw_result.resultTest Left Join
				dw_location
					On dw_unit.unitLocation = dw_location.locationID)
					On dw_group.groupID = dw_test.testGroup
			Where
				dw_cypher.cypherID = ?
			Order By
				dw_location.locationOrder,
				dw_location.locationText
		";
		if(!$qrylocation = mysqli_prepared_query($link, $sql, "i", array($_GET['c']), __FILE__, __LINE__)) reporterror(get_error(), $sql, $_SERVER['REQUEST_URI'], __FILE__, __LINE__);
		$num_locations = mysqli_prepared_num_rows($qrylocation);
		if(isset($_GET['btnPDF'])){
			switch($num_tests){
				case 1:
					$margin=45;
					break;
				case 2:
					$margin=25;
					break;
				case 3:
					$margin=0.1;
					break;
				default:
					$margin=0.1;
			}
			$pdf->CellFitScale($margin,8,'');
			$pdf->CellFitScale(20,8, $specUnitTypeText,1,0,'C',1);
			$pdf->CellFitScale(40,8,'Location',1,0,'C',1);
		}else{
			if($debug) echo "num_locations: ".$num_locations."<br/>";
			echo "<tr>
				<th>".$specUnitTypeText."</th>
				<th>Location</th>";
		}
		for($i=0;$i<$num_tests;$i++){
			if(isset($_GET['btnPDF'])){
				$pdf->CellFitScale(20,8, $testText[$i],1,0,'C',1);
				$pdf->CellFitScale(20,8,'Limit',1,0,'C',1);
			}else{
				echo "<th>";
				if($debug) echo $testID[$i]." ";
				//echo substr($testText[$i],0, $_SESSION['ivp_test_length']);
				echo $testText[$i];
				echo "</th><th>Limit</th>";
			}
		}
		if(!isset($_GET['btnPDF'])){
			echo "</tr>";
		}else{
			$pdf->SetFont('Arial','',10);
			$pdf->Ln();
		}

		foreach($qrylocation as $locationarray){
			if(isset($_GET['btnPDF'])){
				$pdf->CellFitScale($margin,8,'');
				$pdf->CellFitScale(20,8, $locationarray['unitText'],1,0,'C',1);
				$pdf->CellFitScale(40,8, $locationarray['locationText'],1,0,'C',1);
			}else{
				echo "<tr><td>";
				if($debug) echo $locationarray['unitText']." ";
				echo $locationarray['unitText']."</td>";
				echo "<td>";
				if($debug) echo $locationarray['locationID']." ";
				echo $locationarray['locationText']."</td>";
			}
			for($j=0; $j<$num_tests; $j++){
				$sql="
					Select
						dw_result.resultID,
						dw_result.resultFriendly,
						dw_limit.limitLow,
						dw_limit.limitHigh,
						dw_test.testFormat,
						dw_test.testRound,
						dw_result.resultNotes,
						dw_cypher.cypherID
					From
						((dw_cypher Right Join
						dw_unit On dw_cypher.cypherID = dw_unit.unitCypher) Right Join
						(dw_test Right Join
						dw_result
							On dw_test.testID = dw_result.resultTest)
							On dw_unit.unitID = dw_result.resultUnit Left Join
						dw_location On dw_unit.unitLocation = dw_location.locationID) Left Join
						dw_limit On dw_test.testID = dw_limit.limitTest And
						dw_location.locationID = dw_limit.limitLocation
					Where
						dw_location.locationID    = ? And
						dw_test.testID            = ? And
						dw_cypher.cypherID        = ? And
						dw_limit.limitDateFrom   <= dw_cypher.cypherManuDate And
						dw_limit.limitDateTo     >= dw_cypher.cypherManuDate And
						dw_result.resultFriendly <> ''
					Order By
						dw_result.resultModDate Desc
					Limit 1
				";
				if(!$qryresult2 = mysqli_prepared_query($link, $sql, "iii", array($locationarray['locationID'], $testID[$j], $_GET['c']), __FILE__, __LINE__)) reporterror(get_error(), $sql, $_SERVER['REQUEST_URI'], __FILE__, __LINE__);
				$resultarray2 = $qryresult2[0];
				if(!isset($_GET['btnPDF'])) echo "<td name='result'><a href='results.php?r=".$resultarray2['cypherID']."'>";

				if(texttonumber($resultarray2['resultFriendly'], $resultarray2['testFormat'])<texttonumber($resultarray2['limitLow'], $resultarray2['testFormat'])){
					if(isset($_GET['btnPDF'])){
						$pdf->SetTextColor(0,0,255); //Blue
						$pdf->SetFont('Arial','BU',10);
					}
					else echo "<span class='oos-low'>";
				}else{
					if(texttonumber($resultarray2['resultFriendly'], $resultarray2['testFormat'])>texttonumber($resultarray2['limitHigh'], $resultarray2['testFormat'])){
						if(isset($_GET['btnPDF'])){
							$pdf->SetTextColor(255,0,0); //Red
							$pdf->SetFont('Arial','BU',10);
						}
						else echo "<span class='oos-high'>";
					}else{
						if(isset($_GET['btnPDF'])){
							$pdf->SetTextColor(0,0,0); //Black
							$pdf->SetFont('Arial','',10);
						}
						else echo "<span class='text'>";
					}
				}
				if(isset($_GET['btnPDF'])){
					if($resultarray2['resultID']!="" && $resultarray2['resultID']!=null) $pdf->CellFitScale(20,8,numbertotext($resultarray2['resultFriendly'], $resultarray2['testFormat'], $resultarray2['testRound']),1,0,'C',1);
					else $pdf->CellFitScale(20,8,'',1,0,'C',1);
				}else{
					if($debug) echo $resultarray2['resultID']." ";
					//SHOW RESULT
					if($resultarray2['resultID']!="" && $resultarray2['resultID']!=null) echo numbertotext($resultarray2['resultFriendly'], $resultarray2['testFormat'], $resultarray2['testRound']);
					else echo "&nbsp;";
					echo "</span></a></td>";
				}

				if(isset($_GET['btnPDF'])){
					$pdf->SetFont('Arial','',10);
					$pdf->SetTextColor(0,0,0); //Black
					if($resultarray2['limitLow']!= $resultarray2['limitHigh']) $pdf->CellFitScale(20,8,number_format($resultarray2['limitLow'], $resultarray2['testRound'])."-".number_format($resultarray2['limitHigh'], $resultarray2['testRound']),1,0,'C',1);
					else $pdf->CellFitScale(20,8,'',1,0,'C',1);
				}else{
					if($resultarray2['limitLow']!= $resultarray2['limitHigh']) echo "		<td><a href='limit.php?s=".$specID."&btnView=Refresh'>".number_format($resultarray2['limitLow'], $resultarray2['testRound'])."-".number_format($resultarray2['limitHigh'], $resultarray2['testRound'])."</a></td>";
					else echo "<td>&nbsp;</td>";
				}
			}
			if(!isset($_GET['btnPDF'])) echo "</tr>";
			else $pdf->Ln();
		}
		if(isset($_GET['btnPDF'])){
			$pdf->Ln(0.2);
			$pdf->SetFont('Arial','I',10);
			$pdf->CellFitScale(190,8,"Unacceptable results highlighted in red.",0,1,'C',1);
			$pdf->SetFont('Arial','',10);
		}else{
			echo "</table>";
		}

		if(isset($_GET['btnPDF'])){
			$pdf->Ln(0.2);
			$pdf->SetFont('Arial','I',10);
			$pdf->CellFitScale(190,8,"Any follow up to be forwarded to ".$_SESSION['comp_name']." QA dept on or before follow up date.",0,1,'C',1);
		}else{
			echo "</table>";
		}

		//signature
		$sql="
			Select
				dw_user.userCOA,
				dw_user.userID,
				dw_user.userFirst,
				dw_user.userLast,
				dw_user.userTitle
			From
				dw_user
			Where
				dw_user.userID = ?
		";
		if(!$qryUser = mysqli_prepared_query($link, $sql, "i", array($cypherModUser), __FILE__, __LINE__)) reporterror(get_error(), $sql, $_SERVER['REQUEST_URI'], __FILE__, __LINE__);
		$userarray = $qryUser[0];
		if(($userarray['userCOA']==1 || $userarray['userCOA']=="1") && (file_exists('images/sigs/'.$_SESSION['userID'].'.jpg'))){
			if(!isset($_GET['btnPDF'])){
				echo "
					<div name='signature'>
						<table name='signature'>
							<tr>
								<td>&nbsp;</td>
								<td><img src='images/sigs/".$userarray['userID'].".jpg' width='300' height='100' /></td>
							</tr>
							<tr>
								<td>Signatory:</td>
								<td>".$userarray['userFirst']." ".$userarray['userLast']."</td>
							</tr>
							<tr>
								<td>Title:</td>
								<td>".$userarray['userTitle']."</td>
							</tr>
						</table>
					</div>
				";
			}
		}
		if(isset($_GET['btnPDF'])) $pdf->Output();
	}
 require "inc/footer.php"; ?>
