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

$chn = $_POST['chn'] ?? '';
$cyc_no = $_POST['cyc_no'] ?? '';

$cyc_no=sprintf("%06d", $_GET['cyc_no'] ?? '');
$semenid=sprintf("%06d", $_GET['semenid'] ?? '');

$deptt=$_GET['deptt'] ?? '';
$ftchreccyc=$chn.".".$cyc_no;
$ftchreccycx=$chn.".".$semenid;
$ip=$_SERVER['REMOTE_ADDR'] ?? '';
include 'dbcon.php';
$password=md5($password);
$sql = mysql_query("SELECT * FROM matcher_usermst WHERE nif_usr='$username' AND nif_pass='$password' AND act_vate='1'");

$login_check = mysql_num_rows($sql);
if($login_check > 0){
	$row = mysql_fetch_assoc($sql);
	$xadmnchk=$row['dept_x'];
    }
else {
	session_destroy();
echo ("<SCRIPT LANGUAGE='JavaScript'> window.location.href='invalidlogin.html'; </SCRIPT>");
}
$xadmnchk = $xadmnchk ?? '';
$xclr = 'blue';
?>
<!DOCTYPE HTML>
<html>
<head>
<title></title>
<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>
</head>
<body id="top">
<section id="one" class="wrapper style1">
<table><tr><td style="font-size:18px;"><strong>Witness for <?php echo $chn?></strong></td>
<td><A HREF="gend_cycle_select.php?chn=<?php echo $chn;?>" class="btn-two blue large">Back to patient page</A></td></tr></table>
<section>
<?php
include 'dbcon.php';
//$result = mysql_query("SELECT * FROM matcher_trans where chn like '%$chn%' and chn_cycle like '%$cyc_no%' order by ent_no DESC") ;
$result = mysql_query("SELECT * FROM matcher_trans where finalwitnsd like '%$ftchreccycx%'order by ent_no DESC") ;
//$result = mysql_query("SELECT * FROM matcher_trans where finalwitnsd like '%$ftchreccyc%'order by ent_no DESC") ;

$numrows=mysql_num_rows($result);
if($numrows > 0){
	echo "<table width=100% border='0' class='imagetable'><tr><th width =auto align='left' bgcolor='#E0EFFC' style='text-align:left;font-size:18px;'>Procedure witness log</th></tr>";
	while($row=mysql_fetch_array($result)) 
	{
	$xdelnav = '';
	if($xadmnchk=="1"){
	$xdelnav="<a href='delrecx.php?cntr=$row[ent_no];'> [ Remove ]</a>";
	}

	echo "<tr>"; 
						$xproc_mainid_parts = explode('.',$row['finalwitnsd']);
						$xproc_mainid_first=$xproc_mainid_parts[2] ?? '';
                           if($xproc_mainid_first=="a1:b01"){
						   $xprocedure_a="Pool dish (35mm Dish)";
						   }elseif($xproc_mainid_first=="a1:b02"){
						   $xprocedure_a="Post Denudation dish (60 mm Dish)";
						   }elseif($xproc_mainid_first=="a1:b03"){
						   $xprocedure_a="ICSI Dish";
						   }elseif($xproc_mainid_first=="a1:b04"){
						   $xprocedure_a="Fert dish (D0)";
						   }elseif($xproc_mainid_first=="a1:b05"){
						   $xprocedure_a="Cleave dish (D1)";
						   }elseif($xproc_mainid_first=="a1:b06"){
						   $xprocedure_a="Blast Dish (D3)";

						   }elseif($xproc_mainid_first=="a1:b10"){
						   $xprocedure_a="Freezing dish (d3)";
						   }elseif($xproc_mainid_first=="a1:b11"){
						   $xprocedure_a="Thaw Dish";
						   }elseif($xproc_mainid_first=="a1:b12"){
						   $xprocedure_a="ET Dish";
						   }elseif($xproc_mainid_first=="a1:b07"){
						   $xprocedure_a="Blast Dish (D5/6)";
						   }elseif($xproc_mainid_first=="a1:b13"){
						   $xprocedure_a="Biopsy dish (d5)";
						   }elseif($xproc_mainid_first=="a1:b21"){
						   $xprocedure_a="Freezing dish (d5)";
						   }elseif($xproc_mainid_first=="a1:b14"){
						   $xprocedure_a="Biopsy dish (d6)";
						   }elseif($xproc_mainid_first=="a1:b22"){
						   $xprocedure_a="Freezing dish (d6)";

						   }elseif($xproc_mainid_first=="a1:b08"){
						   $xprocedure_a="ET Dish";
						   }elseif($xproc_mainid_first=="a1:b09"){
						   $xprocedure_a="PGT Biopsy Dish";
						   }elseif($xproc_mainid_first=="a1:b10"){
						   $xprocedure_a="Freezing dish";
						   }elseif($xproc_mainid_first=="a2:b01"){
						   $xprocedure_a="Semen Collection container";
						   }elseif($xproc_mainid_first=="a2:b02"){
						   $xprocedure_a="DG Tube/ Swim up Tube";
						   }elseif($xproc_mainid_first=="a2:b03"){
						   $xprocedure_a="Post wash tube";
						   }else{
						   $xprocedure_a="Screen label not defined";
						   }
						$xproc_mainid_second=$xproc_mainid_parts[5] ?? '';
                           if($xproc_mainid_second=="a1:b01"){
						   $xprocedure_b="Pool dish (35mm Dish)";
						   }elseif($xproc_mainid_second=="a1:b02"){
						   $xprocedure_b="Post Denudation dish (60 mm Dish)";
						   }elseif($xproc_mainid_second=="a1:b03"){
						   $xprocedure_b="ICSI Dish";
						   }elseif($xproc_mainid_second=="a1:b04"){
						   $xprocedure_b="Fert dish (D0)";
						   }elseif($xproc_mainid_second=="a1:b05"){
						   $xprocedure_b="Cleave dish (D1)";
						   }elseif($xproc_mainid_second=="a1:b06"){
						   $xprocedure_b="Blast Dish (D3)";

						   }elseif($xproc_mainid_second=="a1:b10"){
						   $xprocedure_b="Freezing dish (d3)";
						   }elseif($xproc_mainid_first=="a1:b11"){
						   $xprocedure_a="Thaw Dish";
						   }elseif($xproc_mainid_first=="a1:b12"){
						   $xprocedure_a="ET Dish";
						   }elseif($xproc_mainid_second=="a1:b07"){
						   $xprocedure_b="Blast Dish (D5/6)";
						   }elseif($xproc_mainid_second=="a1:b13"){
						   $xprocedure_b="Biopsy dish (d5)";
						   }elseif($xproc_mainid_second=="a1:b21"){
						   $xprocedure_b="Freezing dish (d5)";
						   }elseif($xproc_mainid_second=="a1:b14"){
						   $xprocedure_b="Biopsy dish (d6)";
						   }elseif($xproc_mainid_second=="a1:b22"){
						   $xprocedure_b="Freezing dish (d6)";

						   }elseif($xproc_mainid_second=="a1:b08"){
						   $xprocedure_b="ET Dish";
						   }elseif($xproc_mainid_second=="a1:b09"){
						   $xprocedure_b="PGT Biopsy Dish";
						   }elseif($xproc_mainid_second=="a1:b10"){
						   $xprocedure_b="Freezing dish";
						   }elseif($xproc_mainid_second=="a2:b01"){
						   $xprocedure_b="Semen Collection container";
						   }elseif($xproc_mainid_second=="a2:b02"){
						   $xprocedure_b="DG Tube/ Swim up Tube";
						   }elseif($xproc_mainid_second=="a2:b03"){
						   $xprocedure_b="Post wash tube";
						   }else{
						   $xprocedure_b="Screen label not defined";
						   }
					$xentby=$row['ent_by'];
					if($row['p_mark']=="1"){
					$xclr="blue";
					}else{
					$xclr="red";
					}
					$xmxup=$row['witns1pnt'];
					if($xmxup==2){
					$xmxup="Gametes Addition";
					}else{
					$xmxup="";
					}
	echo "<td width=100% style='text-align:left;font-size:18px;'>"."<font color='#009900'>".date('d/m/Y',strtotime($row['reslt_dt']))." ".substr($row['reslt_dt'],-8)." by user "."</font><font color='#FF0000'>".$xentby."</font>"." - "."<font color='$xclr'>".$xprocedure_a." V/s ".$xprocedure_b."</font>".$xdelnav." ".$xmxup."</td>";
	} // while end
}else{ // if end
echo "No procedure witnessing performed yet<br>";
}
//****** sperm freezing
$result1 = mysql_query("SELECT * FROM matcher_trans_sprmfrz where chn like '%$chn%' and chn_cycle='$cyc_nox' order by ent_no DESC") ;
$numrows1=mysql_num_rows($result1);
if($numrows1 > 0){
	echo "<table width=100% border='0' class='imagetable'><tr><th width =auto align='left' bgcolor='#E0EFFC' style='text-align:left;'>Sperm freezing witness log</th></tr>";
	while($row1=mysql_fetch_array($result1)) 
	{
		if($row1['retndt']=="0000-00-00 00:00:00"){
		$outwrddta="Stock";
		}else{
		$outwrddta=" Outward dated ".date('d/m/Y  H:m:s',strtotime($row1['retndt']))." by user ".$row1['outwrdusr'];
		}
	echo "<td width=100% style='text-align:left;font-size:18px;'>"."<font color='#009900'>"."Inward ".date('d/m/Y H:m:s',strtotime($row1['reslt_dt']))." by user ".$row1['ent_by']."</font>"." - "."<font color='$xclr'>".$outwrddta."</font></td>";
	}

}else{
//echo "No semen freezing performed yet<br>";
}
////
//****** egg freezing
$result2 = mysql_query("SELECT * FROM matcher_trans_eggfrz where chn like '%$chn%' and chn_cycle='$cyc_nox' order by ent_no DESC") ;
$numrows2=mysql_num_rows($result2);
if($numrows2 > 0){
	echo "<table width=100% border='0' class='imagetable'><tr><th width =auto align='left' bgcolor='#E0EFFC' style='text-align:left;'>Egg/Oocyte freezing witness log</th></tr>";
	while($row2=mysql_fetch_array($result2)) 
	{
	echo "<tr>";
		if($row2['retndt']=="0000-00-00 00:00:00"){
		$outwrddtb="Stock";
		}else{
		$outwrddtb=" Outward dated ".date('d/m/Y H:m:s',strtotime($row2['retndt']))." by user ".$row2['outwrdusr'];
		}
	echo "<td width=100% style='text-align:left;font-size:18px;'>"."<font color='#009900'>"."Inward ".date('d/m/Y H:m:s',strtotime($row2['reslt_dt']))." by user ".$row2['ent_by']."</font>"." - "."<font color='$xclr'>".$outwrddtb."</font></td></tr>";
	}

}else{
//echo "No egg / oocyte freezing performed yet";
}
////


?>
</section>
</body>
</html>
