<?php
session_start();                      
$username=$_SESSION['username'] ?? '';
$password=$_SESSION['password'] ?? '';
$chn="";
$xcyc="";
$chn=strtoupper($_GET['chn'] ?? '');
$xcyc=strtoupper($_GET['cyc_no'] ?? '');
$ip=$_SERVER['REMOTE_ADDR'] ?? '';
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){

//	$queryx  = "SELECT * FROM cycle_lst where pat_mrn like '%$chn%'";
//	$resultx = mysqli_query($conn, $queryx);
//	while($rowx = mysqli_fetch_array($resultx, MYSQLI_ASSOC)) {
//		$xstringx = $rowx["chn"]." : ".$rowx["part_nm"]." ".$rowx["part_sur"];	
//		$ystringy = $rowx["chn"]." : ".$rowx["pat_nm"]." ".$rowx["pat_sur"];	
//	}
$result = mysqli_query($conn, "SELECT * FROM cycle_lst where pat_mrn like '%$chn%'");
$row = mysqli_fetch_assoc($result);
$xnm=$chn." ".$row['pat_name']." ".$row['part_name'];


}else {
	session_destroy();
echo ("<SCRIPT LANGUAGE='JavaScript'> window.location.href='invalidlogin.html'; </SCRIPT>");

}
?>
<!DOCTYPE HTML>
<html>
<head>
<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>
<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>
<style>

.f-lft {
    float:left;
    border:2px solid orange;
 }

</style>

<script>
$(function() {
$( "#DPC_date1" ).DPC_date1({ dateFormat: 'dd/mm/yyyy' });
});
$(function() {
$( "#DPC_date2" ).DPC_date2({ dateFormat: 'dd/mm/yyyy' });
});
$(function() {
$( "#DPC_date3" ).DPC_date3({ dateFormat: 'dd/mm/yyyy' });
});
</script>
  <script type="text/javascript" src="datepickercontrol.js"></script>
  <script language="JavaScript">
     if (navigator.platform.toString().toLowerCase().indexOf("linux") != -1){
	 	document.write('<link type="text/css" rel="stylesheet" href="datepickercontrol_lnx.css">');
	 }
	 else{
	 	document.write('<link type="text/css" rel="stylesheet" href="datepickercontrol.css">');
	 }
    </script>
	<style type="text/css">
	INPUT { margin-right: 1em }
	</style>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script>
<script src="https://code.jquery.com/jquery-3.4.1.js"></script>
<script>
function getfrst() {
var idscan = document.getElementById("idscan").value;
	if (idscan.length > 8 ) {
		var mychn = document.getElementById("mychn").value;
		var mycycle = document.getElementById("mycycle").value;
		var myidscan = document.getElementById("idscan").value;
		window.location.href="frzmodls_genoocytstrw.php?chn="+mychn+"&cyclid="+mycycle+"&idscan="+myidscan+"&xcnt=1";
		//window.location.href="gend_cycle_select.php?chn="+mychn;
	}
}
</script>
<script>
function getfrstemb() {
var idscanemb = document.getElementById("idscanemb").value;
	if (idscanemb.length > 8 ) {
		var mychnemb = document.getElementById("mychnemb").value;
		var mycycleemb = document.getElementById("mycycleemb").value;
		var myidscanemb = document.getElementById("idscanemb").value;
		window.location.href="frzmodls_genembstrw.php?chn="+mychnemb+"&cyclid="+mycycleemb+"&idscan="+myidscanemb+"&xcnt=1";
		//window.location.href="gend_cycle_select.php?chn="+mychnemb;
	}
}
</script>

<script>
function smngetfrst() {
var smnidscan = document.getElementById("smnidscan").value;
	if (smnidscan.length > 8 ) {
		var mychn = document.getElementById("smnmychn").value;
		var mycycle = document.getElementById("smnmycycle").value;
		var myidscan = document.getElementById("smnidscan").value;
		window.location.href="frzmodls_genfrztube.php?chn="+mychn+"&cyclid="+mycycle+"&idscan="+myidscan;
		window.location.href="gend_cycle_select.php?chn="+mychn;
		//window.location.href="pat_3.php";
		//setTimeout(function() {window.open("gend_cycle_select.php?chn="+mychn, "_self")}, 100);
	}
}
</script>

<script>
function xflush() {
//document.getElementById("mychn").value=="";
//document.getElementById("mycycle").value=="";
}
</script>

</head>
<body onLoad="xflush()">
<?php
echo $xnm;
$query2 = mysqli_query($conn, "SELECT * FROM actvty_trans_frzng_sperm where pat_id='$chn' and cycle_id='$xcyc' and actvty='' order by due_date_act ASC");
$rw_check = mysqli_num_rows($query2);
if($rw_check == 0){
echo "<table align='center' style='width:96%;' border='0'>";
echo"<tr bgcolor='#CCF2FF' style='font-size:16px;'><td align='left' colspan='11'><strong>SEMEN FREEZING</strong></td></tr>";
}else {
echo "<table align='center' style='width:98%;' border='0'>";
echo"<tr bgcolor='#CCF2FF' style='font-size:16px;'><td align='left' colspan='11'><strong>SEMEN FREEZING</strong></td></tr>";
	echo"<tr bgcolor='#ECFBFF'>
	<td align='left'>Freezing Date</td>
	<td align='left'>Due Date</td>
	<td align='left'>Enter by</td>
	<td align='left'>Vial No.</td>
	<td align='left'>Container No.</td>
	<td align='left'>Canister No.</td>
	<td align='left'>Lift No.</td>
	<td align='left'>Vial position</td>
	<td align='left' colspan='3' bgcolor='#FFFFCC'>Navigation</td>
	</tr>";
		while ($row2=mysqli_fetch_array($query2)) {
		if($row2["outwrdresn"]==="1"){
		$xreasn="Used for procedure";
		}else if ($row2["outwrdresn"]==="2"){
		$xreasn="Non Viable";
		}else if ($row2["outwrdresn"]==="3"){
		$xreasn="Non-renewal";
		}else if ($row2["outwrdresn"]==="4"){
		$xreasn="Patient consent to discard";
		}else if ($row2["outwrdresn"]==="5"){
		$xreasn="Tube added by mistake";
		}else{
		$xreasn="";
		}
		
		if($row2["term_date"]=="0000-00-00"){
		$trmdt="";
		}else{
			$today = date("Y-m-d H:i:s");
			$startdate = $row2['term_date'];
			$offset = strtotime("+1 day");
			$enddate = date($startdate, $offset);
			$today_date = new DateTime($today);
			$expiry_date = new DateTime($enddate);
			//if( date("d-m-Y", strtotime($row2["term_date"])) < date("d-m-Y") ){
			if( $expiry_date < $today_date ){
				$trmdt="<span style='color:red;'>".date("d-m-Y", strtotime($row2["term_date"]))."</span>";
			}else{
				$trmdt="<span style='color:green;'>".date("d-m-Y", strtotime($row2["term_date"]))."</span>";
			}
		}
				echo "<tr>";
				echo "<td align='left'>" . date("d-m-Y", strtotime($row2["due_date_act"])). "</td>";
				echo "<td align='left'>" . $trmdt. "</td>";
				echo "<td align='center'>" . $row2["user_id"]."</td>";
				echo "<td align='center'>" . $row2["strow_no"]."</td>";
				echo "<td align='center'>" . $row2["contnrno"]. "</td>";
				echo "<td align='center'>" . $row2["canistrno"]. "</td>";
				echo "<td align='center'>" . $row2["liftno"]. "</td>";
				echo "<td align='center'>" . $row2["vialposno"]. "</td>";
				if($row2['actvty_mrk']=='e'){
				echo "<td align='left' colspan='2'>" . "Biological material storage validity extended"."</td>";
				}elseif($row2['actvty_mrk']=='c'){
				echo "<td align='left' colspan='2'>" ."O/W Reason : ".$xreasn."</td>";
				}else{
				echo "<td align='left'>" . "<a href='actyvty_load_sprmfrz.php?chn=$row2[pat_id]&cyc_no=$row2[cycle_id]&actvty_id=$row2[log_no]' class='button33'>Edit Record</a>"."</td>";
				echo "<td align='left'>" . "<a href='actyvty_extnd_sprmfrz.php?chn=$row2[pat_id]&cyc_no=$row2[cycle_id]&actvty_id=$row2[log_no]' class='button33'>Extend Storage</a>"."</td>";
				echo "<td align='left'>" . "<a href='actvcty_clsngupdt_sprmfrz.php?chn=$row2[pat_id]&cyc_no=$row2[cycle_id]&actvty_id=$row2[log_no]' class='button33'>Use or discard</a>"."</td>";
				}
				echo "</tr>";
		}
}
echo"<tr><td align='left' colspan='9'>
<form id='smnmyfrm' name='smnmyfrm' enctype='multipart/form-data' action='frzmodls_genfrztube.php'>
<input type='hidden' id='smnmychn' name='smnmychn' value='$chn'>
<input type='hidden' id='smnmycycle' name='smnmycycle' value='$xcyc'>
<div><input class='f-lft' type='text' id='smnidscan' name='snmidscan' style='width:10%'>
<input class='f-lft' name='semenfrm' type='submit' value='Add new vial'></div>
</form>";
echo "</table>";

/////// ******************  egg freezing strts ******************  /////
echo "<br>";

$query2 = mysqli_query($conn, "SELECT * FROM actvty_trans_frzng_oocyt where pat_id='$chn' and cycle_id='$xcyc' and actvty='' order by due_date_act ASC");
$rw_check = mysqli_num_rows($query2);
if($rw_check == 0){
echo "<table align='center' style='width:98%;' border='0'>";
echo"<tr bgcolor='#FFE1FF' style='font-size:16px;'><td align='left' colspan='12'><strong>OOCYTE FREEZING</strong></td></tr>";
	echo"<tr><td align='left' colspan='10'><a href='#frzmodls_genfrztube.php?chn=$chn&cyclid=$xcyc'></a></td></tr>";
}else {
echo "<table align='center' style='width:98%;' border='0'>";
echo"<tr bgcolor='#FFE1FF' style='font-size:16px;'><td align='left' colspan='12'><strong>OOCYTE FREEZING</strong></td></tr>";
	echo"<tr bgcolor='#FFF2FF'>
	<td align='left'>Date</td>
	<td align='left'>Due Date</td>
	<td align='left'>Enter by</td>
	<td align='left'>Straw No.</td>
	<td align='left'>Ext. Straw</td>
	<td align='left'>Oocytes</td>
	<td align='left'>Container No.</td>
	<td align='left'>Canister No.</td>
	<td align='left'>Goblet</td>
	<td align='left'>Viscotube</td>
	<td align='left'>Cryo color</td>
	<td align='left' colspan='3' bgcolor='#FFFFCC'>Navigation</td>
	</tr>";
		while ($row2=mysqli_fetch_array($query2)) {
		if($row2["outwrdresn"]==="1"){
		$xreasn="Used for procedure";
		}else if ($row2["outwrdresn"]==="2"){
		$xreasn="Non Viable";
		}else if ($row2["outwrdresn"]==="3"){
		$xreasn="Non-renewal";
		}else if ($row2["outwrdresn"]==="4"){
		$xreasn="Patient consent to discard";
		}else if ($row2["outwrdresn"]==="5"){
		$xreasn="Tube added by mistake";
		}else{
		$xreasn="";
		}
		if($row2["term_date"]=="0000-00-00"){
		$trmdtx="";
		}else{
			$today_x = date("Y-m-d H:i:s");
			$startdate_x = $row2['term_date'];
			$offset_x = strtotime("+1 day");
			$enddate_x = date($startdate_x, $offset);
			$today_date_x = new DateTime($today_x);
			$expiry_date_x = new DateTime($enddate_x);
			//if( date("d-m-Y", strtotime($row2["term_date"])) < date("d-m-Y") ){
			if( $expiry_date_x < $today_date_x ){
				$trmdtx="<span style='color:red;'>".date("d-m-Y", strtotime($row2["term_date"]))."</span>";
			}else{
				$trmdtx="<span style='color:green;'>".date("d-m-Y", strtotime($row2["term_date"]))."</span>";
			}
		}
			if($row2["goblet"]=="1"){
			$goblet="Orange";
			}elseif($row2["goblet"]=="2"){
			$goblet="Blue";
			}elseif($row2["goblet"]=="3"){
			$goblet="White";
			}elseif($row2["goblet"]=="4"){
			$goblet="Yellow";
			}else{
			$goblet="";
			}
			if($row2["viscotube"]=="1"){
			$viscosty="Orange";
			}elseif($row2["viscotube"]=="2"){
			$viscosty="Blue";
			}elseif($row2["viscotube"]=="3"){
			$viscosty="Red";
			}elseif($row2["viscotube"]=="4"){
			$viscosty="Yellow";
			}elseif($row2["viscotube"]=="5"){
			$viscosty="Black";
			}elseif($row2["viscotube"]=="6"){
			$viscosty="Light blue";
			}elseif($row2["viscotube"]=="7"){
			$viscosty="Grey";
			}elseif($row2["viscotube"]=="8"){
			$viscosty="Green";
			}else{
			$viscosty="";
			}
			if($row2["cryocolor"]=="1"){
			$cryoclr="Green";
			}elseif($row2["cryocolor"]=="2"){
			$cryoclr="Blue";
			}elseif($row2["cryocolor"]=="3"){
			$cryoclr="White";
			}elseif($row2["cryocolor"]=="4"){
			$cryoclr="Orange";
			}elseif($row2["cryocolor"]=="5"){
			$cryoclr="Yellow";
			}else{
			$cryoclr="";
			}
				echo "<tr>";
				echo "<td align='left'>" . date("d-m-Y", strtotime($row2["due_date_act"])). "</td>";
				echo "<td align='left'>" . $trmdtx. "</td>";
				echo "<td align='center'>" . $row2["user_id"]."</td>";
				echo "<td align='center'>" . $row2["strow_no"]."</td>";
				echo "<td align='center'>" . $row2["exchngstrw"]."</td>";
				echo "<td align='center'>" . $row2["nosoocyt"]."</td>";
				echo "<td align='center'>" . $row2["contnrno"]. "</td>";
				echo "<td align='center'>" . $row2["canistrno"]. "</td>";
				echo "<td align='center'>" . $goblet. "</td>";
				echo "<td align='center'>" . $viscosty. "</td>";
				echo "<td align='center'>" . $cryoclr. "</td>";
				if($row2['actvty_mrk']=='e'){
				echo "<td align='left' colspan='2'>" . "Biological material storage validity extended"."</td>";
				}elseif($row2['actvty_mrk']=='c'){
				echo "<td align='left' colspan='2'>" ."O/W Reason : ".$xreasn."</td>";
				}else{
				echo "<td align='left'>" . "<a href='actyvty_load_oocyt.php?chn=$row2[pat_id]&cyc_no=$row2[cycle_id]&actvty_id=$row2[log_no]' class='button33'>Edit Record</a>"."</td>";
				echo "<td align='left'>" . "<a href='actyvty_extnd_oocyt.php?chn=$row2[pat_id]&cyc_no=$row2[cycle_id]&actvty_id=$row2[log_no]' class='button33'>Extend Storage</a>"."</td>";
				echo "<td align='left'>" . "<a href='actvcty_clsngupdt_oocyt.php?chn=$row2[pat_id]&cyc_no=$row2[cycle_id]&actvty_id=$row2[log_no]' class='button33'>Use or discard</a>"."</td>";
				}
				echo "</tr>";
		}
}
echo"<tr><td align='left' colspan='9'>
<form id='myfrm' name='myfrm' enctype='multipart/form-data' action='frzmodls_genoocytstrw.php'>
<input type='hidden' id='mychn' name='mychn' value='$chn'>
<input type='hidden' id='mycycle' name='mycycle' value='$xcyc'>
<div><input class='f-lft' type='text' id='idscan' name='idscan' style='width:10%'>
<input class='f-lft' name='xyzfrms' type='submit' value='Add new straw'></div>
</form></td></tr>";
echo "</table>";

/////// ******************  embryo freezing strts ******************  /////
echo "<br>";

$query2 = mysqli_query($conn, "SELECT * FROM actvty_trans_frzng_embryo where pat_id='$chn' and cycle_id='$xcyc' and actvty='' order by due_date_act ASC");
$rw_check = mysqli_num_rows($query2);
if($rw_check == 0){
echo "<table align='center' style='width:98%;' border='0'>";
echo"<tr bgcolor='#FFE1FF' style='font-size:16px;'><td align='left' colspan='12'><strong>EMBRYO FREEZING</strong></td></tr>";
	echo"<tr><td align='left' colspan='10'><a href='#frzmodls_genfrztube.php?chn=$chn&cyclid=$xcyc'></a></td></tr>";
}else {
echo "<table align='center' style='width:98%;' border='0'>";
echo"<tr bgcolor='#FFE1FF' style='font-size:16px;'><td align='left' colspan='12'><strong>EMBRYO FREEZING</strong></td></tr>";
	echo"<tr bgcolor='#FFF2FF'>
	<td align='left'>Date</td>
	<td align='left'>Due Date</td>
	<td align='left'>Enter by</td>
	<td align='left'>Straw No.</td>
	<td align='left'>Ext. Straw</td>
	<td align='left'>Embryos</td>
	<td align='left'>Container No.</td>
	<td align='left'>Canister No.</td>
	<td align='left'>Goblet</td>
	<td align='left'>Viscotube</td>
	<td align='left'>Cryo color</td>
	<td align='left' colspan='3' bgcolor='#FFFFCC'>Navigation</td>
	</tr>";
		while ($row2=mysqli_fetch_array($query2)) {
		if($row2["outwrdresn"]=="1"){
		$xreasn1="Used for procedure";
		}else if ($row2["outwrdresn"]=="2"){
		$xreasn1="Non-Viable";
		}else if ($row2["outwrdresn"]=="3"){
		$xreasn1="Non-renewal";
		}else if ($row2["outwrdresn"]=="4"){
		$xreasn1="Patient consent to discard";
		}else if ($row2["outwrdresn"]=="5"){
		$xreasn1="Tube added by mistake";
		}else{
		$xreasn1="";
		}
		if($row2["term_date"]=="0000-00-00"){
		$trmdtx="";
		}else{
			$today_x = date("Y-m-d H:i:s");
			$startdate_x = $row2['term_date'];
			$offset_x = strtotime("+1 day");
			$enddate_x = date($startdate_x, $offset);
			$today_date_x = new DateTime($today_x);
			$expiry_date_x = new DateTime($enddate_x);
			//if( date("d-m-Y", strtotime($row2["term_date"])) < date("d-m-Y") ){
			if( $expiry_date_x < $today_date_x ){
				$trmdtx="<span style='color:red;'>".date("d-m-Y", strtotime($row2["term_date"]))."</span>";
			}else{
				$trmdtx="<span style='color:green;'>".date("d-m-Y", strtotime($row2["term_date"]))."</span>";
			}
		}
			if($row2["goblet"]=="1"){
			$goblet="Orange";
			}elseif($row2["goblet"]=="2"){
			$goblet="Blue";
			}elseif($row2["goblet"]=="3"){
			$goblet="White";
			}elseif($row2["goblet"]=="4"){
			$goblet="Yellow";
			}else{
			$goblet="";
			}
			if($row2["viscotube"]=="1"){
			$viscosty="Orange";
			}elseif($row2["viscotube"]=="2"){
			$viscosty="Blue";
			}elseif($row2["viscotube"]=="3"){
			$viscosty="Red";
			}elseif($row2["viscotube"]=="4"){
			$viscosty="Yellow";
			}elseif($row2["viscotube"]=="5"){
			$viscosty="Black";
			}elseif($row2["viscotube"]=="6"){
			$viscosty="Light blue";
			}elseif($row2["viscotube"]=="7"){
			$viscosty="Grey";
			}elseif($row2["viscotube"]=="8"){
			$viscosty="Green";
			}else{
			$viscosty="";
			}
			if($row2["cryocolor"]=="1"){
			$cryoclr="Green";
			}elseif($row2["cryocolor"]=="2"){
			$cryoclr="Blue";
			}elseif($row2["cryocolor"]=="3"){
			$cryoclr="White";
			}elseif($row2["cryocolor"]=="4"){
			$cryoclr="Orange";
			}elseif($row2["cryocolor"]=="5"){
			$cryoclr="Yellow";
			}else{
			$cryoclr="";
			}
				echo "<tr>";
				echo "<td align='left'>" . date("d-m-Y", strtotime($row2["due_date_act"])). "</td>";
				echo "<td align='left'>" . $trmdtx. "</td>";
				echo "<td align='center'>" . $row2["user_id"]."</td>";
				echo "<td align='center'>" . $row2["strow_no"]."</td>";
				echo "<td align='center'>" . $row2["exchngstrw"]."</td>";
				echo "<td align='center'>" . $row2["nosoocyt"]."</td>";
				echo "<td align='center'>" . $row2["contnrno"]. "</td>";
				echo "<td align='center'>" . $row2["canistrno"]. "</td>";
				echo "<td align='center'>" . $goblet. "</td>";
				echo "<td align='center'>" . $viscosty. "</td>";
				echo "<td align='center'>" . $cryoclr. "</td>";
				if($row2['actvty_mrk']=='e'){
				echo "<td align='left' colspan='2'>" . "Biological material storage validity extended"."</td>";
				}elseif($row2['actvty_mrk']=='c'){
				echo "<td align='left' colspan='2'>" ."O/W Reason : ".$xreasn1."</td>";
				}else{
				echo "<td align='left'>" . "<a href='actyvty_load_embryo.php?chn=$row2[pat_id]&cyc_no=$row2[cycle_id]&actvty_id=$row2[log_no]' class='button33'>Edit Record</a>"."</td>";
				echo "<td align='left'>" . "<a href='actyvty_extnd_embryo.php?chn=$row2[pat_id]&cyc_no=$row2[cycle_id]&actvty_id=$row2[log_no]' class='button33'>Extend Storage</a>"."</td>";
				echo "<td align='left'>" . "<a href='actvcty_clsngupdt_embryo.php?chn=$row2[pat_id]&cyc_no=$row2[cycle_id]&actvty_id=$row2[log_no]' class='button33'>Use or discard</a>"."</td>";
				}
				echo "</tr>";
		}
}
echo"<tr><td align='left' colspan='9'>
<form id='myfrmembryo' name='myfrmembryo' enctype='multipart/form-data'  action='frzmodls_genembstrw.php'>
<input type='hidden' id='mychnemb' name='mychnemb' value='$chn'>
<input type='hidden' id='mycycleemb' name='mycycleemb' value='$xcyc'>
<div><input class='f-lft' type='text' id='idscanemb' name='idscanemb' style='width:10%'>
<input name='embsubfrm' type='submit' value='Add new straw'></div>
</form>
<a href='gend_cycle_select.php?chn=$chn' class='btn-two blue small'>Back to main screen</a></td></tr>";
echo "</table>";

?>
</body>
</html>
