<?php
session_start();                      
$username = $_SESSION['username'] ?? null;
$password = $_SESSION['password'] ?? null;

$chn = $_GET['chn'] ?? null;

$ip=$_SERVER['REMOTE_ADDR'] ?? null;
include 'dbcon.php';
$password=md5($password);
$sql = mysqli_query($conn, "SELECT * FROM matcher_usermst WHERE nif_usr='$username' AND nif_pass='$password' AND act_vate='1'");
$login_check = mysqli_num_rows($sql);
if($login_check > 0){
	$row = mysqli_fetch_assoc($sql);
	$xadmnchk=$row['dept_x'];
		//$xadmnchk="3";
		$xbacknav="<a href='pat_3.php' class='btn-two blue medium'>Back</a>";
		$sql = mysqli_query($conn, "INSERT INTO matcher_trans_ptcrd (reslt_dt, ent_by, chn)
		VALUES(now(), '$username', '$chn')") or die (mysqli_error($conn));

} else {
session_destroy();
echo "Invalid login";
}
?>
<!DOCTYPE HTML>
<html>
<head>
<style>
  #tagdetct {
    position: fixed;
    top: -100000000px;
  }
</style>

<style type="text/css">
INPUT { margin-right: 1em }
</style>
<link href="../style.css" rel="stylesheet" type="text/css" />
<link href="style_btn.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="js_button.js"></script>
<link href="../style_btn.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="../js_button.js"></script>
<style>
#Image {
    margin: 5px;
    border:2px solid #FF3399;
    border-radius: 5px;
    background-size: 210px;
    background-position:center;
}
#Imagex {
    margin: 5px;
    border:2px solid #FF3399;
	width:200px;
	height:200px;
    border-radius: 10px;
    background-size: 210px;
    background-position:center;
}
</style>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script>
<script>
    window.onkeydown = function (event) {
      if (event.which == 8) { 
         event.preventDefault();   // turn off browser transition to the previous page 
       } };      
     </script>

<script>
window.onload = function() {
  document.getElementById("frst_contnr").focus();
}
</script>
<script>
function getfrst() {
var frst_contnr_chr = document.getElementById("frst_contnr").value;
var resultfrst = frst_contnr_chr.split(".");
var resulta = resultfrst[2];
var resulta_frst = resulta.split(":");
var resultb = resulta_frst[0];

	if (frst_contnr_chr.length > 23 ) {
	//alert(resultb);
		if ( resultb == 'a1' ){
			document.getElementById('contnr_a').innerHTML = '<img src="oocyt.gif" />';
		} else if ( resultb == 'a2' ){
			document.getElementById('contnr_a').innerHTML = '<img src="sperm.gif" />';
		}else {
		}
	
	document.getElementById("secnd_contnr").focus();
	}
}
</script>
<script>
function getscnd() {
var scnd_contnr_chr = document.getElementById("secnd_contnr").value;
var resultscnd = scnd_contnr_chr.split(".");
var resultascnd = resultscnd[2];
var resulta_scnd = resultascnd.split(":");
var resultbscnd = resulta_scnd[0];

	if (scnd_contnr_chr.length > 23 ) {
	//alert(resultbscnd);
			var sumatone = document.getElementById("frst_contnr").value.length;
			var sumattwo = document.getElementById("secnd_contnr").value.length;
			var totsumlenonetwo = sumatone + sumattwo;
			document.getElementById("fcusextra").value = totsumlenonetwo;
		var result1 = document.getElementById("chn_new").value;
		var result2 = document.getElementById("cyc_no_new").value;
		var result3 = document.getElementById("don_no_new").value;
		var result4 = document.getElementById("semen_no_new").value;
		var result5 = document.getElementById("xnm_new").value;

	document.getElementById("fcusextra").focus();

		if ( resultbscnd == 'a1' ){
			document.getElementById('contnr_b').innerHTML = '<img src="oocyt.gif" />';
		} else if ( resultbscnd == 'a2' ){
			document.getElementById('contnr_b').innerHTML = '<img src="sperm.gif" />';
		}else {
		}
setTimeout(function() {window.open("process_sele_test2.php?chn="+result1+"&cyc_no="+result2+"&don_no="+result3+"&semen_no="+result4+"&xnm="+result5, "_self")}, 200);

	}
}
</script>
<style>
	body, input, select, textarea {
		font-size: 16pt;
	}
.style1 {
	color: #FF0000;
	font-weight: bold;
}
</style>
</head>
<body>
<?php
$result = mysqli_query($conn, "SELECT * FROM cycle_lst where pat_mrn like '%$chn%'");
$row = mysqli_fetch_assoc($result);
$xnm=$row['pat_name']." ".$row['part_name'];
?>
<table border="0" width="98%">
<tr>
<td colspan="5"><div align="left"><img src="logo-inner.jpg"/>
<?php
echo "<a href='#pat_2.php?user_id=$row[pat_mrn]' class='btn-two cyan medium'>$row[pat_mrn]</a>";
echo $xbacknav;
?></td>
<td width="10%" rowspan="5" style="text-align:center">
<div id="contnr_a"></div></td>
<td width="10%" rowspan="5" style="text-align:left">
<div id="contnr_b"></div></td>
  </tr>
  <tr>
    <td colspan="3"><span class="style1">Patient</span></td>
    <td colspan="2"><span class="style1">Partner</span></td>
  </tr>
  <tr>
    <td width="9%">Patient Name</td>
    <td width="17%"><?php echo $row['pat_name'] ?></td>
    <td width="4%">&nbsp;</td>
    <td width="12%">Partner Name</td>
    <td width="20%"><?php echo $row['part_name'] ?></td>
  </tr>
  <tr>
    <td>Date of Birth</td>
    <td><?php echo $row['pat_dob'] ?></td>
    <td>&nbsp;</td>
    <td>Date of Birth</td>
    <td><?php echo $row['part_dob'] ?></td>
  </tr>
  <tr>
    <td>Sex</td>
    <td>Female</td>
    <td>&nbsp;</td>
    <td>Sex</td>
    <td>Male</td>
	<td></td>
  </tr>
</table>
 <table width="100%" border="0">
  <tr>
    <td colspan="5" style="background-color:#FFCC99"><div align="left"><strong>Procedures</strong> </div></td>
  </tr>
   <tr>
     <td colspan="2"><?php
if($xadmnchk=="2"){
	echo "No clinical list display here - FrontDesk"; 
}else{
//	$result = mysqli_query($conn, "SELECT * FROM cycle_lst where pat_mrn like '%$chn%' order by pat_mrn DESC") ;
	$result = mysqli_query($conn, "SELECT * FROM cycle_lst where pat_mrn='$chn' order by chn_id DESC limit 1") ;
		echo "<table width=100% border='0' class='imagetable'>"; 
		while($row=mysqli_fetch_array($result)) 
		{
		echo "<tr>";
		$xxchn=$chn.".".$row['chn_id'];
		echo "<td width=100% colspan='2' style='font-size:18px;'>" . date('d/m/Y',strtotime($row['cycle_strtd'])) ." - ". $row['cycle_type']."<br>";
		echo "<a href='frzmodls.php?chn=$chn&cyc_no=$row[chn_id]' class='btn-two green large'>Freezing module</a>";
			if($row['cycle_activt']==="1"){
			echo "<a href='#' class='btn-two gray large'>USED CONSUMABLE DISCARDED AND THIS CYCLE IS CLOSED</a>";
			}else{
			echo "<a href='cycl_clsng.php?chn=$row[pat_mrn]&cyc_no=$row[chn_id]' class='btn-two red large'>I hereby state that USED CONSUMABLE FOR THIS CYCLE is discarded and close the RFID EWS</a>";
			}

		//echo "<a href='process_sele_test2.php?chn=$row[pat_mrn]&cyc_no=$row[chn_id]&don_no=$row[cycle_donorid]&semen_no=$row[cycle_semenid]&xnm=$xnm' class='btn-two red large'> Start Witnessing</a><td>";
		echo "</tr>";
?>
<div id="tagdetct"><form id="contnrloader" name="contnrloader">
<input type="text" id="frst_contnr" name="frst_contnr" onKeyUp="getfrst_x()">
<input type="text" id="secnd_contnr" name="secnd_contnr" onKeyUp="getscnd_x()">


<input name="chn_new" id = "chn_new" type="text" value="<?php echo $row['pat_mrn'];?>"><br>
<input name="cyc_no_new" id = "cyc_no_new" type="text" value="<?php echo $row['chn_id'];?>"><br>
<input name="don_no_new" id = "don_no_new" type="text" value="<?php echo $row['cycle_donorid'];?>"><br>
<input name="semen_no_new" id = "semen_no_new" type="text" value="<?php echo $row['cycle_semenid'];?>"><br>
<input name="xnm_new" id = "xnm_new" type="text" value="<?php echo $xnm;?>">

</form>
<form>
<input type="text" id="fcusextra" name="fcusextra">
</form></div>
<?php
		}
}
?></td>
   </tr>
 </table>
</body>
</html>
