<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">

<head>
	<style>
		.tbl1 {
			border: 2px solid black;
			border-collapse: collapse;
			font-weight: 800;
			padding: 15px;
		}

		.tbl2 {
			border-collapse: collapse;
			font-weight: 800;
			padding: 15px;
		}
	</style>
</head>
<div id="medical_examination_form" style="display: none;">
	<?php

	include('includes/config/config.php');
	include_once("includes/functions.php");
	//error_reporting(0);

	function getModifiedString($var)
	{
		$var = trim($var);
		$pos = stripos($var, ":");
		$initial_str = substr($var, 0, $pos);
		$str = substr($var, $pos);
		$updated_str = "<b>" . $str . "</b>";
		return $initial_str . " " . $updated_str;
	}

	$sql_form_type_data = "select a.*,b.ticket_no,b.approve_date,b.doc_attend,b.medical_attend,b.fit_unfit_status,b.doc_findings,p.* from form_data a inner join checkup_form b on a.checkup_id=b.checkup_id left join patient_master p on p.id=b.emp_id  where a.checkup_id='" . $_REQUEST['checkup_id'] . "'";
	error_log("query " . $sql_form_type_data);
	$result_form_type_data = mysqli_query($conn, $sql_form_type_data);
	$row_form_type_data = mysqli_fetch_assoc($result_form_type_data);
	@extract($row_form_type_data);
	?>
	<div style="margin-top: 20px">
		<table width="100%">
			<tr>
				<td colspan="2" align="center" style="font-weight:900;">FORM NO- 33</td>
			</tr>

			<tr>
				<td colspan="2" align="center">[Prescribed under Rules 68-T and 102]</td>
			</tr>
			<tr>
				<td colspan="2" align="center" style="font-weight:900;">Certificate of fitness for employment in hazardous process and operations</td>
			</tr>
			<tr>
				<td colspan="2" align="center">(To be issued by Factory Medical Officer)</td>
			</tr>
		</table>
		<div style="margin-top: 20px">
			<table width="100%" class="tbl3" style="border-spacing: 10px;">
				<tr>
					<td>
						<?php
						echo getModifiedString($para_one);
						?>

					</td>
				</tr>
				<tr>
					<td>
						<?php echo getModifiedString($para_two) ?>

					</td>
				</tr>
				<tr>
					<td>
						<?php echo getModifiedString($para_three) ?>

					</td>
				</tr>
				<tr>
					<td>
						<?php echo getModifiedString($para_four) ?>

					</td>
				</tr>
				<tr>
					<td>
						<?php echo getModifiedString($para_five) ?>

					</td>
				</tr>

				<tr>
					<td>
						<?php echo getModifiedString($para_six) ?>

					</td>
				</tr>
				<tr>
					<td>
						<?php echo getModifiedString($para_seven) ?>

					</td>
				</tr>

				<tr>
					<td>
						<?php echo getModifiedString($para_eight) ?>

					</td>
				</tr>

				<tr>
					<td>
						<?php if (strcmp($para_one_1, "    a) Hazardous process:") == 0) {
							echo $row_form_type_data['hazardous_process'] == 'Y' ? "    a) Hazardous process: Yes" : "    a) Hazardous process: No";
						} else {
							echo $para_one_1;
						}
						?>

					</td>
				</tr>
				<tr>
					<td>
						<?php if (strcmp($para_one_2, "    b) Dangerous operation:") == 0) {
							echo "    b) Dangerous operation: " . $row_form_type_data['dangerous_process'];
						} else {
							echo $para_one_2;
						}
						?>
					</td>
				</tr>
				<tr>
					<td style="word-wrap:normal;">
						<?php echo $para_one_3 ?>

					</td>
				</tr>

				<tr>
					<td style="word-wrap:normal;">
						<?php echo $para_one_4 ?>

					</td>
				</tr>


				<tr>
					<td style="word-wrap:normal;">
						<?php echo $para_one_5
						?>

					</td>
				</tr>


				<tr>
					<td>
						<?php echo $para_one_6
						?>

					</td>
				</tr>
			</table>
		</div>

		<div style="margin-top: 100px">


			<table width="100%" class="tbl3" style="margin-top:20px; font-size: 16px;">
				<tr>
					<td>
						<img src="data:<?php echo $row_form_type_data['image_type'] ?>;base64,<?php echo base64_encode($row_form_type_data['emp_sign']) ?>" style="width: 120px; height: 40px;" />
						<br>
						Signature or left hand thumb
						impression of the person examined :
					</td>

					<td align="right"> <?php
										$doc_emp_id =  $row_form_type_data['doc_attend'];
										$doctor_name = getFieldfromTable('patient_name', 'patient_master', 'id', $doc_emp_id) ?>


						<span style="margin-left:170px">
							<?php
							$sql_sign = "select * from employee_signature where emp_id='" . $doc_emp_id . "'";
							$result_sign = mysqli_query($conn, $sql_sign);
							$row_sign = mysqli_fetch_assoc($result_sign);
							@extract($row_sign);
							error_log("sign query " . $sql_sign);
							?>
							<img src="data:<?php echo $row_sign['image_type'] ?>;base64,<?php echo base64_encode($row_sign['emp_sign']) ?>" style="width: 120px; height: 40px;" />

						</span>
						<br>
						Signature of the Factory Medical Officer :
					</td>
				</tr>

			</table>

			<br>
			<br>


			<table width="100%" class="tbl3">

				<tr>
					<td width="60%" align="left">
					</td>
					<td align="right">
						<span style="margin-left:170px">
							<img src="data:<?php echo $row_sign['stamp_img_type'] ?>;base64,<?php echo base64_encode($row_sign['emp_stamp']) ?>" style="width: 120px; height: 40px;" />
						</span>
						<p>Stamp of factory
							Medical Officer with

							Name of the Factory</p>
					</td>
				</tr>
			</table>

			<!-- <br> -->


			<table width="100%" class="tbl3">
				<tr>
					<td colspan="2" align="left">Date: <b><?= date_format(date_create($row_form_type_data['approval_date']), "d-m-Y") ?></b> </td>
				</tr>
			</table>
			<hr>


			<table width="100%" class="tbl3" style="page-break-after: always;">
				<tr>
					<td align="right"></td>
				</tr>

			</table>

			<br>



			<table width="100%" border="1" cellspacing="0">
				<tr>
					<th>I certify that I examined the person mentioned above on
						(date of examination)
					</th>
					<th>I examined this certificate unfit (If certificate is not extended , the period for which the worker is considered unfit for work is to be mentioned)</th>
					<th>Signs & symptoms observed during examination.</th>
					<th>Signature of the
						Factory medical
						Officer with date.</th>
				</tr>
				<tr rowspan="10">
					<td height="350"><?= $row_form_type_data['fit_unfit_status'] == 'ufit' ? date_format(date_create($row_form_type_data['approval_date']), "d-m-Y") : '' ?></td>
					<td></td>
					<td><?= $row_form_type_data['fit_unfit_status'] == 'ufit' ? $row_form_type_data['doc_findings'] : '' ?></td>
					<?php if ($row_form_type_data['fit_unfit_status'] == 'ufit') { ?>
						<td><img src="data:<?php echo $row_sign['image_type'] ?>;base64,<?php echo base64_encode($row_sign['emp_sign']) ?>" style="width: 120px; height: 40px;" /></td>
					<?php } else { ?>
						<td></td>
					<?php } ?>

				</tr>
			</table>


			<div style="margin-top: 20px; font-size: 15px; text-transform:lowercase">
				<div><b>Notes:</b></div>
				<ol>
					<li> If declared unfit, reference should be made immediately to the Certifying Surgeon.</li>
					<li>Certifying Surgeon should communicate his findings to the occupier with 30 days of the receipt of this
						reference.</li>

				</ol>
			</div>

		</div>
	</div>
	<form id="medical_examination_form_pdf" action="" method="POST">
		<input type="hidden" name="htmlText" id="htmlText" />
	</form>
</div>
<script>
	formSubmit();

	function formSubmit() {
		$("#htmlText").val($("#medical_examination_form").html());
		document.forms['medical_examination_form_pdf'].action = "pdf_dynamic.php";
		document.forms['medical_examination_form_pdf'].method = "post";
		document.forms['medical_examination_form_pdf'].submit();

	}
</script>