<?php

// require('FPDF/fpdf.php');
ob_start();
require("includes/check_auth_user.php");
require("includes/dbconnect.php");
include('includes/function.php');
require("library/fpdf/dash.php");

ini_set("display_errors", 1);
error_reporting(E_ERROR);

$maindb = 'visaform';
$formname = "Medical ";
$zdb = $_SESSION["zdbyear_" . $dbname];

$zroot = $_SESSION["zdir"];
$compcd = $_SESSION["comp_" . $dbname];
$myyear = $_SESSION[$myyear];
$tourcode = $_SESSION['tourcode'];
$tourname = $_SESSION['tourname'];

mysqli_select_db($conn, $zdb);

$class = $_POST["class"];
$frmregnno = $_POST["frmregnno"];
$toregnno = $_POST["toregnno"];
$frmpaxno = $_POST["frmpaxno"];
$topaxno = $_POST["topaxno"];

//$ccond = "";
//if (!empty($_POST["class"])) {
//    $ccond = " AND b.`batchno`='$class' ";
//}


$regnnocond = "";
if (!empty($_POST["frmregnno"]) && !empty($_POST["toregnno"])) {
    $regnnocond = " AND b.`vregnno` BETWEEN '$frmregnno' AND '$toregnno'";
}

$paxcond = "";
if (!empty($_POST["frmpaxno"]) && !empty($_POST["topaxno"])) {
    $paxcond = " AND b.`vouchno` BETWEEN '$frmpaxno' AND '$topaxno'";
}




$pdf = new PDF_Dash('P', 'mm', 'A4');
$getpmain = mysqli_query($conn, "SELECT a.add1,a.add2,a.city,a.tel,b.redypass,date_format(b.dob,'%d-%m-%Y') as dob,
                                 b.image, b.name as paxname, b.cmbgender, b.fhname FROM bookform a, `$maindb` b WHERE a.regnno = b.vregnno
                                 AND a.tourno = b.tour and b.tour = '$tourcode' $regnnocond $paxcond  ") or die(mysqli_error($conn));
//print table($getpmain);
//die();
while ($pmain = mysqli_fetch_array($getpmain)) {
// $pdf = new FPDF('P','mm','A4');
    $pdf->AddPage();

    /* ---------- HEADER IMAGE ---------- */
//    $pdf->Image("images/mini_head.jpg", 3, 3, 200, 25);
    $pdf->Ln(22);
    if (file_exists($pmain['image'])) {
        $pt = $pmain['image'];
        $pdf->Image("$pt", 167, 38, 35, 35);
    }

    $pdf->Rect(165, 32, 38, 43);

    /* ---------- TITLE ---------- */
    $pdf->SetFont('Arial', 'BU', 11);
    $pdf->Cell(160, 6, "MEDICAL SCREENING & FITNESS CERTIFICATE- 1447(H)-2026(C.E)", 0, 0, 'C');
    $pdf->SetFont('Arial', 'B', 10);
    $pdf->Cell(28, 6, "PHOTOGRAPH", 0, 0, 'C');
    $pdf->Ln(5);

    $pdf->SetFont('Arial', 'UB', 10);
    $pdf->Cell(165, 5, "(Must obtain the following certificate from a Government Medical Officer", 0, 0, 'C');
    $pdf->Ln(5);

    $pdf->SetFont('Arial', 'UB', 10);
    $pdf->Cell(165, 5, "(Allopathic) authorized by the State/UT Government/Central Govt./Defence", 0, 0, 'C');
    $pdf->Ln(5);

    $pdf->SetFont('Arial', 'UB', 10);
    $pdf->Cell(160, 5, "Authorities / PSU / Autonomous Bodies)", 0, 0, 'C');
    $pdf->Ln();
    $pdf->Ln(5);

    $pdf->SetFont('Arial', 'B', 9);
    $pdf->Cell(18, 6, "", 0, 0, 'L');
    $pdf->Cell(70, 6, "Personal Particulars:", 0, 1, 'L');
    $pdf->Ln();

    $pdf->SetFont('Arial', '', 9);
    $pdf->Cell(18, 6, "", 0, 0, 'L');
    $pdf->Cell(13, 6, "Name :", 0, 0, 'L');
    $pdf->Cell(55, 6, "$pmain[paxname]", 0, 0, 'L');
    $pdf->Ln(5);

    $pdf->SetFont('Arial', '', 9);
    $pdf->Cell(18, 6, "", 0, 0, 'L');
    $pdf->Cell(25, 6, "Date Of Birth :", 0, 0, 'L');
    $pdf->Cell(35, 6, "$pmain[dob]", 0, 0, 'L');
    $pdf->Ln(5);

    $pdf->SetFont('Arial', '', 9);
    $pdf->Cell(18, 6, "", 0, 0, 'L');
    $pdf->Cell(16, 6, "Gender :", 0, 0, 'L');
    $pdf->Cell(70, 6, "$pmain[cmbgender]", 0, 0, 'L');
    $pdf->Cell(22, 6, "Contact No :", 0, 0, 'L');
    $pdf->Cell(90, 6, "$pmain[tel]", 0, 0, 'L');
    $pdf->Ln(5);

    $pdf->SetFont('Arial', '', 9);
    $pdf->Cell(18, 6, "", 0, 0, 'L');
    $pdf->Cell(12, 6, "ID No. ", 0, 0, 'L');
    $pdf->Cell(74, 6, "(Passport/Voter Id/Aadhar etc.) - $pmain[redypass]", 0, 0, 'L');
    $pdf->Cell(27, 6, "Blood Group :", 0, 0, 'L');
    $pdf->Cell(90, 6, "", 0, 0, 'L');
    $pdf->Ln(5);
    $address = $pmain['add1'] . " " . $pmain['add2'] . " " . $pmain['city'];
    $pdf->Cell(18, 6, "", 0, 0, 'L');
    $pdf->Cell(29, 6, "Complete Address :", 0, 0, 'L');
    $pdf->SetFont('Arial', '', 6);
    $pdf->Cell(147, 6, "$address", 0, 0, 'L');
    $pdf->Ln(5);

    $pdf->Image("images/content01.jpg", 28, 95, 175, 150);
    $pdf->Ln(153);

    $pdf->SetLineWidth(0);
    $pdf->SetDash(0.9, 0.5);
    $pdf->Line(33, 252, 105, 252);

    $pdf->SetTextColor(39, 39, 39);
    $pdf->SetFont('times', 'B', 9);
    $pdf->Cell(19, 6, "", 0, 0, 'L');
    $pdf->Cell(2, 6, "I", 0, 0, 'L');
    $pdf->SetFont('times', 'B', 8);
    $pdf->Cell(73, 6, "$pmain[paxname]", 0, 0, 'L');

// Reset dash (IMPORTANT)
    $pdf->SetDash(); // <-- this breaks the connection
// Second dashed line
    $pdf->SetDash(0.9, 0.5);
    $pdf->Line(119, 252, 169, 252); // left → right

    $pdf->SetFont('times', 'B', 9);
    $pdf->Cell(15, 6, "S/D/W OF", 0, 0, 'L');
    $pdf->SetFont('times', 'B', 7);
    $pdf->Cell(50, 6, "$pmain[fhname]", 0, 0, 'L');
    $pdf->SetFont('times', 'B', 10);
    $pdf->Cell(10, 6, "here by declare that the", 0, 0, 'L');
    $pdf->Ln(5);

    $pdf->Image("images/content02.jpg", 29, 253, 175, 18);
    $pdf->Ln(22);
    /* ---------- OUTPUT ---------- */
}
$pdf->Output();
