
<?php
// Checked for PHP5.6 / 8.x compatibility
include("../../operainfo/getq.php");
print "<h1>You are NOT allowed to QA your own WORK</h1>";
$barcode=isset($_POST['barcode']) ? $_POST['barcode'] : '';
$usestk=isset($_POST['stkref']) ? $_POST['stkref'] : '';
$usedescription=isset($_POST['description']) ? $_POST['description'] : '';
$question_type=isset($_POST['questiontype']) ? $_POST['questiontype'] : '';
$useserialno=isset($_POST['serialno']) ? $_POST['serialno'] : '';
$nowis=date("U");
if ($barcode=='')
	{
	$barcode=isset($_GET['barcode']) ? $_GET['barcode'] : '';
	$question_type=isset($_GET['qt']) ? $_GET['qt'] : '';
	}
$issrn=substr($barcode,0,3);
$srnnum=substr($barcode,3);
$sql="SELECT * FROM Serialnumbers where id = ? limit 0,1";
$stmt = pdoquery($sql, array($barcode));
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
foreach ($rows as $row) {
		$usestk=$row['Stock_ref'];
		$builtby=$row['producedby'];
		}
if ($issrn=='SRN')
	{
	$sql="SELECT * FROM viamed_customer_repairs_details where id = ?";
	print "$sql";
	$stmt = pdoquery($sql, array($srnnum));
	$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
	foreach ($rows as $row) {
		$usestk=$row['stock_ref'];
		}
	}
?>
<script type="text/javascript"> 
function getmeter(fieldid) {
document.getElementById(fieldid).value="";
 if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
 xmlhttp=new XMLHttpRequest();
}
else
 {// code for IE6, IE5
 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
 }
xmlhttp.open("GET","getmeter.php<?php  print "$x";?>",true);
xmlhttp.send();
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById(fieldid).value=xmlhttp.responseText;
	testmeter(fieldid);
    }
  } 
}
</script>
<script type="text/javascript"> 
function testmeter(fieldid) {
var link="testmeter.php<?php  print "$x";?>&stkref=<?php  print "$usestk";?>&sensorinput="+document.getElementById(fieldid).value;
//document.getElementById("RE"+fieldid).innerHTML=link;
 if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
 xmlhttp=new XMLHttpRequest();
}
else
 {// code for IE6, IE5
 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
 }
xmlhttp.open("GET",link,true);
xmlhttp.send();
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("RE"+fieldid).innerHTML=xmlhttp.responseText;
    }
  } 
}
</script>
<?php  	
$sql="SELECT * FROM ISO_employee_product_training where trainee = ? and stock_ref = ? and type = ? and trainedon >'0'";
$stmt = pdoquery($sql, array($vui, $usestk, $question_type));
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
$num=count($rows);
//print "$num $s <BR>";
if ($num >0)
	{
foreach ($rows as $row) {
	$pdate=date("d M Y",$row['trainedon']);
	$tname=getusername($row['trainedby']);
	print "$localname Trained on $question_type of $usestk on the $pdate <br>";
	}
	} else
	{
	print "$localname Needs Training Records for $question_type of $usestk NOT FOUND ";
	?>
	<a href="requesttraining.php<?php  print "$x";?>&question_type=<?php  print "$question_type";?>&trainee=<?php  print "$vui";?>&stock_ref=<?php  print "$usestk";?>"> Request Training</a><br>
	<?php 
	$havenotread=2;
	}
print "<hr>";
$sql="SELECT ISO_quality_manual_files.docid as docid,ISO_quality_manual_files.description as des  FROM ISO_quality_manual_files, ISO_quality_manual_stock_links WHERE
ISO_quality_manual_stock_links.docid = ISO_quality_manual_files.docid AND
ISO_quality_manual_files.type = 'COP' AND ISO_quality_manual_stock_links.stock_ref = ? AND
ISO_quality_manual_files.archived='' ";
$stmt = pdoquery($sql, array($usestk));
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
foreach ($rows as $row) {
		$docid=$row['docid'];
		$active[$docid]=-1;
		$description[$docid]=$row['des'];
		}
$sql="SELECT ISO_quality_manual_files.docid as docid,ISO_quality_manual_user_read.last_read as lastread FROM ISO_quality_manual_files, ISO_quality_manual_stock_links,ISO_quality_manual_user_read WHERE
ISO_quality_manual_stock_links.docid = ISO_quality_manual_files.docid AND
ISO_quality_manual_files.type = 'COP' AND ISO_quality_manual_stock_links.stock_ref = ? AND
ISO_quality_manual_files.archived='' AND
ISO_quality_manual_user_read.docid=ISO_quality_manual_files.docid AND
ISO_quality_manual_user_read.userid = ?
ORDER BY ISO_quality_manual_user_read.last_read
";
$stmt = pdoquery($sql, array($usestk, $vui));
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
foreach ($rows as $row) {
		$docid=$row['docid'];
		$prndate=date("d M y",$row['lastread']);
		$active[$docid]=$prndate;
		}
if ($active != '')
	{
foreach ($active as $key => $value){

	if ($value==-1)
		{

		$havenotread=2;
		?>
		<a href="/intranet/databases/iso_documents/showdoc2.php<?php echo $x; ?>&docid=<?php  print "$key";?>">Please Read the Following Document<br><?php  print "$description[$key]";?><?php  print "Last Read $value";?> </a><br>
		<?php 
		}
		else {
		?>
		<a href="/intranet/databases/iso_documents/showdoc2.php<?php echo $x; ?>&docid=<?php  print "$key";?>"><?php  print "$description[$key]";?> </a><?php  print "Last Read $value";?><br>
		<?php 		
		}
}
}
$havenotread = isset ( $havenotread ) ? $havenotread : 0 ;
if ($havenotread<>2) {
if ($issrn=='SRN' or $issrn=='srn') {
print "<h1>$issrn$srnnum </h1>";
	$sql="SELECT * FROM viamed_customer_repairs_details where id = ?";
	$stmt = pdoquery($sql, array($srnnum));
	$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
	foreach ($rows as $row) {
					  if ($row['equipment_type']=="Pulse Oximetery Finger Sensor" OR $row['equipment_type']=="Pulse Oximetery Ear Clip Sensor" OR $row['equipment_type']=="Pulse Oximetery Extension Cable" OR $row['equipment_type']=="Pulse Oximetery Y Sensor") {
							$usestk="SRNERPROBE";
							$usedescription=$row['equipment_type'];
							$useserialno=$row['serialnumber'];
							print "->>$useserialno";
								}
					  else {
							$usestk=$row['stock_ref'];
							if ($barcode=='')
									{
									$barcode=$row['barcode'];
									}
							if ($barcode=='')
									{
									$usedescription=$row['equipment_type'];
									$useserialno=$row['serialnumber'];
									}
					  }
					  }
	}
	ELSE
	{
$sql= "SELECT * FROM Serialnumbers WHERE id = ?";
$stmt = pdoquery($sql, array($barcode));
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
$numcon=count($rows);
foreach ($rows as $row) {
	$usestk=$row['Stock_ref'];
	$usedescription=$row['usedescription'];
	$useserialno=$row['Serialnumber'];
	$builtby=$row['producedby'];
	$hasbeeninvoiced=$row['Invoicenumber'];
	$invoiceon=$row['Dateout'];
	}
if ($barcode=='')
	{
$barcode=isset($_GET['barcode']) ? $_GET['barcode'] : '';
$usestk=isset($_GET['stkref']) ? $_GET['stkref'] : '';
$usedescription=isset($_GET['description']) ? $_GET['description'] : '';
$question_type=isset($_GET['questiontype']) ? $_GET['questiontype'] : '';
$useserialno=isset($_GET['serialno']) ? $_GET['serialno'] : '';
	}
if ($question_type=='Global Information')
	{
	$barcode='1';
	$useserialno='All Units';
	}
	}
$sql= "SELECT * FROM serialnumber_questions WHERE question_text <>'Pass' and special_function<>'hide' AND stock_ref = ? AND question_type = ? order by question_order limit 0,1";
$stmt = pdoquery($sql, array($usestk, $question_type));
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
foreach ($rows as $row) {
	$firstQ="Q".$row['id'];
	//print "$firstQ";
	}
//print "$barcode";

$hasmerge=0;
$sql="SELECT * FROM serialnumber_questions  WHERE stock_ref = ? AND question_type = ?";
$stmt = pdoquery($sql, array($usestk, $question_type));
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
$numq=count($rows);
foreach ($rows as $row) {
		if ($row['special_function']=='merge')
		{
		$hasmerge=1;
		}

	}

// do we have a merge function if so disable the enter Key
if ($hasmerge==1)
	{
	?>
<head>
<i>Enter Key Disabled</i>
<script language=javascript type=text/javascript>
<!-- Script courtesy of http://www.web-source.net - Your Guide to Professional Web Site Design and Development 
function stopRKey(evt) {
   var evt = (evt) ? evt : ((event) ? event : null);
   var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
   if ((evt.keyCode == 13) && (node.type=="text")) {return false;}
}
document.onkeypress = stopRKey; 
-->
</script>
</head>	
	<?php
	}
?>
<body onLoad="self.focus();document.input.<?php print "$firstQ";?>.focus()">
<?php  
#$r= "SELECT * FROM serialnumber_answers  WHERE stock_ref='$usestk' AND question_type='$question_type' AND barcode='$barcode'  group by date_created order by date_created DESC";
#$result = getquery($r);
#$numr=mysql_num_rows($result);
//$hasbeeninvoiced 
if ($builtby >0)
	{
print "Built by ".getusername($builtby);
	}
if (($builtby==$vui  and $question_type=="QA")  )
	{
	Print "<h3>You cannot QA your own Builds Please get this Item QA by someone Else</h3>";
	} else
	{

if ($numq>0)
	{
$cc=0;
foreach ($rows as $row) {
	//$shwdate=date("d/M/Y ",$row['date_created']);
	$shwdate='';
	if ($cc=='0')
	{
	Print "Previous Form Submission(s) on<BR>";
	}
	?>
	<a href="showoldrec.php<?php echo $x; ?>&anid=<?php  print "$row[id]";?>">
	<?php
	print "$shwdate - $row[question_type]</a><br>";
	$cc=$cc+1;
	}
print "<h3>$usestk $usedescription (";
?>
<a href="../../operainfo/stockbook/edititem.php<?php echo $x; ?>&bid=<?php  print "$barcode";?>" target="_blank">
<?php
print "$useserialno</a>)<br>$question_type</h3>";
print "ALL Values in the Form Below are Suggested Values from Previous QA Session, Change as Required!!!";
print "<table border=1>";
//print"<td>Question ID</td><td>Questions</td><td>Answers</td></tr>";
?>
<form enctype="multipart/form-data" name="input" method="POST" action="qa4.php">
<input type=hidden name=barcode value="<?php  print "$barcode";?>">
<input type=hidden name=stkref value="<?php  print "$usestk";?>">
<input type=hidden name=description value="<?php  print "$usedescription";?>">
<input type=hidden name=questiontype value="<?php  print "$question_type";?>">
<input type=hidden name=serialno value="<?php  print "$useserialno";?>">
<form method="POST" action="qa4.php<?php echo $x; ?>">
<?php  
$sql= "SELECT * FROM serialnumber_questions WHERE stock_ref = ? AND question_type = ? order by question_order, id ";
$stmt = pdoquery($sql, array($usestk, $question_type));
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
foreach ($rows as $row) {
	$useq="Q$row[id]";
	$useo="O$row[id]";
	$bclastans='98989898989';
	$bclastans2='98989898989';
	if ($row['accesskey']<>'') {
		$access="accesskey=\"$row[accesskey]\"";
	} else {
		$access='';
	}
	if ($row['repeatans']==0)
		{
	$sql2= "SELECT * FROM serialnumber_answers WHERE questionid = ? AND barcode = ? ORDER BY id desc limit 0,1";
		$stmt2 = pdoquery($sql2, array($row['id'], $barcode));
		$rows2 = $stmt2->fetchAll(PDO::FETCH_ASSOC);
		foreach ($rows2 as $row2) {
			$bclastans=$row2['answer'];
			}
	$sql9= "SELECT * FROM serialnumber_answers WHERE questionid = ? ORDER BY id desc limit 0,1";
		$stmt9 = pdoquery($sql9, array($row['id']));
		$rows9 = $stmt9->fetchAll(PDO::FETCH_ASSOC);
		foreach ($rows9 as $row9) {
			$bclastans2=$row9['answer'];
			}
		}
if ($row['special_function']<>'hide')
	{
	// print "<tr><td>$row[id] ($row[special_function])</td>";
	print "<td>$row[id] ($row[accesskey]) $row[special_function]</td><td>$row[question_text]</td>";
	print "<td>";
	// find special functions
	// LOCATION FUNCTION!
	// CAN AUTOMATICALLY move product to a shelf during QA
	// Get one shot at entering a location it should then stay as a hidden field
	if ($row['special_function']=='location')
		{
		$lastans="";
		// ok so we need to move the Item IF it passes QA!
		// for the input form we Only need to put in the Destination ID
		$sql2= "SELECT * FROM serialnumber_answers WHERE questionid = ? and answer<>'' ORDER BY id desc limit 0,1";
		$stmt2 = pdoquery($sql2, array($row['id']));
		$rows2 = $stmt2->fetchAll(PDO::FETCH_ASSOC);
		foreach ($rows2 as $row2) {
			$lastans=$row2['answer'];
			}
		if ($bclastans<>'98989898989')
		{
		$lastans=$bclastans;
		}
		if ($lastans=="")
			{
		?>
		<input type=text name=<?php  print "$useq";?> value='<?php  print "$lastans";?>' autocomplete='off'>
		<?php
			}
			else
			{
		?>
		<input type=hidden name=<?php  print "$useq";?> value='<?php  print "$lastans";?>' autocomplete='off'>
		<?php
			print "$lastans";
			}
		}
	if ($row['special_function']=='viameduser')
		{
		?>
		<select name=<?php  print "$useq";?> value='1' size='1'>
		<?php
		if ($bclastans2<>'98989898989')
		{
		?>
		<option value="<?php  print "$bclastans2";?>"><?php  print "$bclastans2";?></option>
		<?php
		}
		$sql3= "SELECT * FROM pw where active='1' ORDER BY username";
		$stmt3 = pdoquery($sql3);
		$rows3 = $stmt3->fetchAll(PDO::FETCH_ASSOC);
		foreach ($rows3 as $row3) {
		print "<option value=\"$row3[username]\">$row3[username]</option>";
		}
		print "</select>";
		}
	if ($row['special_function']=='Yesno')
		{
			?>
			<select name=<?php  print "$useq";?> value='1' size='1'>
			<?php
		if ($row['question_text']=='Pass') {
			?>
			<option value="Yes">Yes</option>
			<?php
		} else {
		if ($bclastans2<>'98989898989')
		{
		?>
		<option value="<?php  print "$bclastans2";?>"><?php  print "$bclastans2";?></option>
		<?php
		}
		}
		?>
		<option value=""></option>
		<option value="Yes">Yes</option>
		<option value="No">No</option>
		</select>
		<?php
		}
	if ($row['special_function']=='testequ')
		{
		$sql2= "SELECT * FROM serialnumber_answers WHERE questionid = ? ORDER BY id desc limit 0,1";
		$stmt2 = pdoquery($sql2, array($row['id']));
		$rows2 = $stmt2->fetchAll(PDO::FETCH_ASSOC);
		foreach ($rows2 as $row2) {
			$lastans=$row2['answer'];
			}
		$duetext="Valid";
		$sql3= "SELECT * FROM serialnumber_answers WHERE barcode = ? and (questionid='68' OR questionid='75') ORDER BY id desc limit 0,2";
		$stmt3 = pdoquery($sql3, array($lastans));
		$rows3 = $stmt3->fetchAll(PDO::FETCH_ASSOC);
		foreach ($rows3 as $row3) {
			if ($row3['questionid']=='68')
			{
			$calon=$row3['answer'];
			}
			if ($row3['questionid']=='75')
			{
			$caltime=$row3['answer'];
			}
			}
			$seccaltime=($calon+(30*$caltime*24*60*60));
			if ($seccaltime < $nowis)
				{
				$duetext="OUT OF CALIBRATION<br>";
				}
				ELSE
				{
				$dispdate=date("M/Y",$seccaltime);
				$duetext="Cal due:$dispdate<br>";
				}
			if ($caltime<'1')
				{
				$duetext="<br>";
				}
		print "$duetext";
		?>
		<input type=text name=<?php  print "$useq";?> value='<?php  print "$lastans";?>' autocomplete='off'>
		<?php
		}
	if ($row['special_function']=='lastanswer')
		{
		$sql2= "SELECT * FROM serialnumber_answers WHERE questionid = ? ORDER BY id desc limit 0,1";
		$stmt2 = pdoquery($sql2, array($row['id']));
		$rows2 = $stmt2->fetchAll(PDO::FETCH_ASSOC);
		foreach ($rows2 as $row2) {
			$lastans=$row2['answer'];
			}
		if ($bclastans<>'98989898989')
		{
		$lastans=$bclastans;
		}
		?>
		<input type=text name=<?php  print "$useq";?> value='<?php  print "$lastans";?>' autocomplete='off'>
		<?php
		}
	if ($row['special_function']=='pulldown')
		{
		?>
		<select name=<?php  print "$useq";?> value='1' size='1'>
		<?php
		if ($bclastans<>'98989898989')
		{
		?>
		<option value="<?php  print "$bclastans";?>"> <?php  print "$bclastans";?> </option>
		<?php
		}
		?>
		<option value='Other'>Other>></option>
		<?php
		$sql2= "SELECT * FROM serialnumber_answers WHERE questionid = ? GROUP BY answer";
		$stmt2 = pdoquery($sql2, array($row['id']));
		$rows2 = $stmt2->fetchAll(PDO::FETCH_ASSOC);
		foreach ($rows2 as $row2) {
			?>
			<option value='<?php  print "$row2[answer]";?>'><?php  print "$row2[answer]";?></option>
			<?php
			}
		?>
		</select>
		<input type=text name='<?php  print "$useo";?>'>
		<?php
		}
	if ($row['special_function']=='Text' )
		{
		if ($bclastans<>'98989898989')
		{
		?>
		<input type=text name='<?php  print "$useq";?>' value="<?php  print "$bclastans"; ?> <?php  print "$access";?> " autocomplete='off'>
		<?php
		}
		ELSE
		{
		?>
		<input type=text name='<?php  print "$useq";?>' autocomplete='off' <?php  print "$access";?> >
		<?php
		}
		}
	if ($row['special_function']=='IPQA' )
		{
		if ($bclastans<>'98989898989')
		{
		?>
		<input type=text id='ipqa' name='<?php  print "$useq";?>' value="<?php  print "$bclastans"; ?> <?php  print "$access";?> " autocomplete='off'>
		<?php
		}
		ELSE
		{
		?>
		<input type=text id='ipqa' name='<?php  print "$useq";?>' autocomplete='off' <?php  print "$access";?> >
		<?php
		}
		print "<div id='ipqatester'><a href=\"../qatester/ipqatester.php$x&barcode=$barcode\">Start Test</a></div>";
		}
	if ($row['special_function']=='SensorTester')
		{
		if ($bclastans<>'98989898989')
		{
		print "(Last QA $bclastans)<br>";
		?>
		<input type=text id='<?php  print "$row[id]";?>' name='<?php  print "$useq";?>' value="<?php  print "$bclastans"; ?>" autocomplete='off' <?php  print "$access";?> onfocus="this.value=''" >
		<?php
		}
		ELSE
		{
		?>
		<input type=text id='<?php  print "$row[id]";?>' name='<?php  print "$row[id]";?>' autocomplete='off' <?php  print "$access";?> onfocus="this.value=''" >
		<?php
		}
		print "<a onclick=\"getmeter('$row[id]')\">Update</a><div id='RE$row[id]'>---</div>";
		?>
		<script>
		getmeter('<?php  print "$row[id]";?>');
		</script>
		<?php
		}
	if ($row['special_function']=='file' )
		{
		?>
		<input type="hidden" name="MAX_FILE_SIZE" value="200000000" />
		<input name="<?php  print "$useq";?>" type="file" />
		<?php 
		}
	if ($row['special_function']=='merge')
		{
		if ($bclastans<>'98989898989')
		{
		?>
		<input type=text name='<?php  print "$useq";?>' value="<?php  print "$bclastans"; ?>" autocomplete='off'>
		<?php
		}
		ELSE
		{
		?>
		<input type=text name='<?php  print "$useq";?>' autocomplete='off'>
		<?php
		}
		}
	if ($row['special_function']=='DateAuto')
		{
		?>
		<a href="../../operainfo/datefinder.php" target="_blank">Find Date Code</a><br>
		<input type=text name='<?php  print "$useq";?>' value='<?php  print "$nowis"; ?>' autocomplete='off'>
		<?php
		}
	if ($row['special_function']=='Date')
		{
		?>
		<a href="../../operainfo/datefinder.php" target="_blank">Find Date Code</a><br>
		<?php
		if ($bclastans<>'98989898989')
		{
		?>
		<input type=text name='<?php  print "$useq";?>' value="<?php  print "$bclastans"; ?>" autocomplete='off'>
		<?php
		}
		ELSE
		{
		?>
		<input type=text name='<?php  print "$useq";?>' autocomplete='off'>
		<?php
		}
		}
	if ($row['special_function']=='area')
		{
		if ($bclastans<>'98989898989')
		{
		$sqlblb="Select * from serialnumber_answers_blob where answerid = ?";
		$stmtblb = pdoquery($sqlblb, array($bclastans));
		$rowsblb = $stmtblb->fetchAll(PDO::FETCH_ASSOC);
		foreach ($rowsblb as $brow) {
			$bclastans=$brow['blb'];
			}
		?>
		<textarea name='<?php  print "$useq";?>' cols=40 rows=6 value="<?php  print "$bclastans"; ?>"></textarea>
		<?php
		}
		ELSE
		{
		?>
		<textarea name='<?php  print "$useq";?>' cols=40 rows=6 ></textarea>
		<?php
		}
		}
	if ($row['special_function']=='autopressure')
		{
		$sql2="SELECT * FROM archive order by dateTime desc limit 0,1";
		$stmt2 = getweatherquery($sql2);
		$rows2 = $stmt2->fetchAll(PDO::FETCH_ASSOC);
		foreach ($rows2 as $row2) {
				$condate=date("d-m-y h:i:s A",$row2['dateTime']);
				$conpressure=((int)(($row2['barometer']*33.8637526)*100)/100);
				$contempin=((int)(((($row2['inTemp']-32)*5)/9)*100)/100);
				$conhumid=$row2['inHumidity'];
			}
		?>
		<input type=hidden name='<?php  print "$useq";?>' value='<?php  print "$conpressure,mBar,$condate";?>' autocomplete='off'>
		<?php
		print "<b>$conpressure,mBar,$condate</b>";
		}
	if ($row['special_function']=='autotemperature')
		{
			if ($condate=='')
					{
					$sql2="SELECT * FROM archive order by dateTime desc limit 0,1";
					$stmt2 = getweatherquery($sql2);
					$rows2 = $stmt2->fetchAll(PDO::FETCH_ASSOC);
					foreach ($rows2 as $row2) {
							$condate=date("d-m-y h:i:s A",$row2['dateTime']);
							$conpressure=((int)(($row2['barometer']*33.8637526)*100)/100);
							$contempin=((int)(((($row2['inTemp']-32)*5)/9)*100)/100);
							$conhumid=$row2['inHumidity'];
						}
					}
		?>
		<input type=hidden name='<?php  print "$useq";?>' value='<?php  print "$contempin,C,$condate";?>' autocomplete='off'>
		<?php
		print "<b>$contempin,C,$condate</b>";
		}
	if ($row['special_function']=='autohumidity')
		{
			if ($condate=='')
					{
					$sql2="SELECT * FROM archive order by dateTime desc limit 0,1";
					$stmt2 = getweatherquery($sql2);
					$rows2 = $stmt2->fetchAll(PDO::FETCH_ASSOC);
					foreach ($rows2 as $row2) {
							$condate=date("d-m-y h:i:s A",$row2['dateTime']);
							$conpressure=((int)(($row2['barometer']*33.8637526)*100)/100);
							$contempin=((int)(((($row2['inTemp']-32)*5)/9)*100)/100);
							$conhumid=$row2['inHumidity'];
						}
					}
		?>
		<input type=hidden name='<?php  print "$useq";?>' value='<?php  print "$conhumid,%,$condate";?>' autocomplete='off'>
		<?php
		print "<b>$conhumid,%,$condate</b>";
		}
	print "</td>";
	print "</tr>";
	}
	}
?>
<input type=submit value=Submit>
<?php  
$usetoday=mktime ( 0,0,0,date('m'),date('d'),date('y'));
$usetoday_text=date("d/m/y",$usetoday);
print "</table><br>Information about $usestk Processed Today $usetoday_text:<br>";
// JUNK CODE TO WORK OUT HOW MANY PROCESSED
$useq=substr($useq , 1);
print "<table border=1><td>Stock Reference</td><td>Quantity Processed Today</td></tr>";
$sql="SELECT count(*),question_type,stock_ref FROM serialnumber_answers where
date_created > ? and stock_ref = ? and questionid = ? group by stock_ref,question_type";
//print "$sql<br>";
$stmt = pdoquery($sql, array($usetoday, $usestk, $useq));
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
foreach ($rows as $row) {
	$usestk2=$row['stock_ref'];
	print "<tr><td>";
	?>
	<a href="qa_report.php<?php echo $x; ?>&findstock=<?php  print "$usestk2";?>">
	<?php
	print "$usestk2</a></td><Td>$row[0]</td><td>$row[1]</td></tr>";
	}
print "</table>";
}
ELSE
{
Print "No $question_type Forms Found for $usestk";
$lengthbarcode=strlen($barcode);
$halflenth=$lengthbarcode/2;
$firstcode=substr($barcode,0,$halflenth);
$secondcode=substr($barcode,$halflenth);
//print "&nbsp &nbsp ($firstcode - $secondcode) Barcode Bits n Pieces";
if ($firstcode==$secondcode)
	{
	?>
	<script>
	window.location='qa3.php<?php echo $x; ?>&barcode=<?php print "$firstcode"; ?>&qt=<?php print "$question_type";?>'
	</script>
	<?php	
	}
}
} 
}
?>
</form>
</body>
</html>

