<?php

require("includes/check_auth_user.php");
require("includes/dbconnect.php");
include('includes/function.php');

$formname = 'Pax Form';
$maindb = 'visaform';
$trandb = 'mehram';
$file = 'paxform_pdf.php';
$source = "";
$zcomp = $_SESSION["comp_" . $dbname];
$fseries = $_SESSION["series_" . $dbname];

$zdb = $_SESSION["zdbyear_" . $dbname];
$zroot = $_SESSION["zdir"];
mysqli_select_db($conn, $zdb);

$mht = 'height:20px;';
$admin = $_SESSION["admin_" . $dbname];
$vouchno = $_REQUEST["vouchno"];

$mainqry = mysqli_query($conn, "SELECT *, DATE_FORMAT(`vouchdt`, '%d-%m-%Y') AS vouchdt,DATE_FORMAT(`dob`, '%d-%m-%Y') AS dob,
                                          DATE_FORMAT(`issdate`, '%d-%m-%Y') AS doi, DATE_FORMAT(`expdate`, '%d-%m-%Y') AS doe
                                          FROM `$maindb` WHERE `vouchno`='$vouchno' ORDER BY `vouchno` ") or die(mysqli_error($conn));
$getmdata = mysqli_fetch_array($mainqry);

$cmpname = mysqli_query($conn, "SELECT * From $zroot.`company` where code ='$zcomp'") or die(mysqli_error($conn));
$getcmpname = mysqli_fetch_array($cmpname);


require("library/fpdf/fpdf.php");

class pdf extends fpdf {

    function Footer() {

        //Position at 1.5 cm from bottom
        $this->SetY(-15);

        //Arial italic 8
        $this->SetFont('Arial', 'I', 8);
        //Page number
        $this->Cell(0, 10, 'Page ' . $this->PageNo() . '/{nb}', 0, 0, 'C');
    }

}

$ht = 7;

$pdf = new pdf('P', 'mm', 'A4');

$pdf->AliasNbPages();
$pdf->AddPage();
$pdf->SetFont('Arial', 'B', 18);
$pdf->SetTextColor(0, 0, 0);
$headerimg = $getcmpname['headerimg'];

// if ($headerimg != "images/Khadim_logo.png") {
// }else{
//     $image1 = "images/Khadim_logo.jpg";
// }

$image1 = $headerimg;
//if ($getmdata['image'] != "") {
//    $image2 = $getmdata['image'];
//    if (file_exists($image2)) {
//        $image2 = $getmdata['image'];
//    } else {
//        $image2 = 'images/blank.jpg';
//    }
//} else {
//    $image2 = 'images/blank.jpg';
//}


// $pdf->Image($image1, 25, 5, 120, 40);
$pdf->ln(35);
$pdf->SetFont('Arial', 'B', 12);
$pdf->Cell(60, $ht, "BOOKING FORM FOR HAJ :", 0, 0, 'L');
$pdf->Cell(80, $ht, "", 'B', 0, 'L');
//$pdf->Image($image2, 155, 15, 50, 50);
$pdf->Rect(155, 15, 50, 50, 'D');
$pdf->Ln(10);

$pdf->SetTextColor(0, 0, 0);
$pdf->Cell(35, $ht, "BOOKING No.  :", 0, 0);
$pdf->SetFont('Arial', 'B', 10);
$pdf->SetTextColor(0, 0, 0);
$pdf->Cell(60, $ht, "$getmdata[vouchno]", 'B', 0, 'L');
$pdf->Cell(30, $ht, "(FOR OFFICE USE ONLY)", 0, 0, 'L');
$pdf->ln(20);
$pdf->Rect(10, 70, 90, 15, 'D');
$pdf->Rect(100, 70, 90, 15, 'D');
$pdf->SetFont('Arial', 'B', 12);
$pdf->Cell(90, $ht, "STANDARD CLASS", 0, 0);
$pdf->Rect(52, 72, 25, 12, 'D');
$pdf->Cell(30, $ht, "BUSY CLASS", 0, 0);
$pdf->Rect(130, 72, 25, 12, 'D');
$pdf->ln(15);

$pdf->SetFont('Arial', '', 10);
$pdf->Cell(20, $ht, "1. Name :", 0, 0);
$pdf->Cell(175, $ht, "$getmdata[surname] $getmdata[lastname] $getmdata[midname]", 'B', 0);
$pdf->Ln($ht);

$pdf->Cell(40, $ht, "2A. Passport Number :", 0, 0);
$pdf->Cell(45, $ht, "$getmdata[redypass]", 'B', 0);
$pdf->Cell(30, $ht, "B. Date of Birth :", 0, 0, 'R');

$pdf->Cell(80, $ht, "$getmdata[dob]", 'B', 0);
$pdf->Ln($ht);

$pdf->Cell(36, $ht, "3A. Place of Issue :", 0, 0);
$pdf->Cell(49, $ht, "$getmdata[issplace]", 'B', 0);
$pdf->Cell(30, $ht, "B. Nationality :", 0, 0, 'R');
$pdf->Cell(80, $ht, "$getmdata[nation]", 'B', 0);
$pdf->Ln($ht);

$pdf->Cell(36, $ht, "4A. Date of Issue :", 0, 0);
$pdf->Cell(49, $ht, "$getmdata[doi]", 'B', 0);
$pdf->Cell(36, $ht, "B. Date of Expiry :", 0, 0, 'R');
$pdf->Cell(74, $ht, "$getmdata[doe]", 'B', 0);
$pdf->Ln($ht);

$pdf->SetFont('Arial', '', 10);
$pdf->Cell(32, $ht, "5. Father's Name :", 0, 0);
$pdf->Cell(163, $ht, "$getmdata[fhname]", 'B', 0);
$pdf->Ln($ht);

$pdf->Cell(36, $ht, "6A. Mother's Name :", 0, 0);
$pdf->Cell(49, $ht, "", 'B', 0);
$pdf->Cell(36, $ht, "B. Spouse Name :", 0, 0, 'R');
$pdf->Cell(74, $ht, "", 'B', 0);
$pdf->Ln($ht);

$gettran = mysqli_query($conn, "SELECT * FROM $trandb where vouchno = '$getmdata[vouchno]' ") or die(mysqli_error($conn));
$fettran = mysqli_fetch_array($gettran);

$getrelate = mysqli_query($conn, "SELECT code,name FROM relation where code='$fettran[trelate]'") or die(mysqli_error($conn));
$fetrelate = mysqli_fetch_array($getrelate);

$pdf->Cell(38, $ht, "7A. Name of Mehram :", 0, 0);
$pdf->Cell(47, $ht, "$fettran[paxname]", 'B', 0);
$pdf->Cell(36, $ht, "B. Relationship :", 0, 0, 'R');
$pdf->Cell(74, $ht, "$fetrelate[name]", 'B', 0);
$pdf->Ln($ht);

$pdf->SetFont('Arial', '', 10);
$pdf->Cell(75, $ht, "8. Present Residential Address with Pin Code :", 0, 0);
$pdf->Cell(120, $ht, "", 'B', 0);
$pdf->Ln($ht);

$pdf->Cell(195, $ht, "", 'B', 0);
$pdf->Ln($ht);
$pdf->SetTextColor(0, 0, 0);

$pdf->Cell(38, $ht, "9A. Mobile Number :", 0, 0);
$pdf->Cell(47, $ht, "", 'B', 0);
$pdf->Cell(36, $ht, "B. Phone Number :", 0, 0, 'R');
$pdf->Cell(74, $ht, "", 'B', 0);
$pdf->Ln($ht);

$pdf->SetFont('Arial', '', 10);
$pdf->Cell(20, $ht, "10. Email :", 0, 0);
$pdf->Cell(175, $ht, "", 'B', 0);
$pdf->Ln($ht);

$pdf->Cell(38, $ht, "11A. Maritial Status :", 0, 0);
$pdf->Cell(35, $ht, "", 'B', 0);
$pdf->Cell(15, $ht, "B. Sex :", 0, 0, 'R');
$pdf->Cell(35, $ht, "", 'B', 0);
$pdf->Cell(30, $ht, "C. Blood Group :", 0, 0, 'R');
$pdf->Cell(42, $ht, "", 'B', 0);
$pdf->Ln($ht);

$pdf->Cell(25, $ht, "12A. Religion :", 0, 0);
$pdf->Cell(70, $ht, "", 'B', 0);
$pdf->Cell(20, $ht, "B. Sect :", 0, 0, 'R');
$pdf->Cell(80, $ht, "", 'B', 0);
$pdf->Ln($ht);

$pdf->Cell(32, $ht, "13A. Qualification :", 0, 0);
$pdf->Cell(60, $ht, "", 'B', 0);
$pdf->Cell(30, $ht, "B. Profession :", 0, 0, 'R');
$pdf->Cell(73, $ht, "", 'B', 0);
$pdf->Ln($ht);

$pdf->Cell(42, $ht, "14A. Passport Enclosed :", 0, 0);
$pdf->Cell(45, $ht, "", 'B', 0);
$pdf->Cell(55, $ht, "B. Special Requirement if any :", 0, 0, 'R');
$pdf->Cell(53, $ht, "", 'B', 0);
$pdf->Ln($ht);

$pdf->Cell(42, $ht, "15A. Name of Nominee :", 0, 0);
$pdf->Cell(45, $ht, "", 'B', 0);
$pdf->Cell(30, $ht, "B. Relationship :", 0, 0, 'R');
$pdf->Cell(78, $ht, "", 'B', 0);
$pdf->Ln($ht);

$pdf->SetFont('Arial', '', 10);
$pdf->Cell(25, $ht, "C. Address :", 0, 0);
$pdf->Cell(170, $ht, "", 'B', 0);
$pdf->Ln($ht);

$pdf->Cell(115, $ht, "", 'B', 0);
$pdf->Cell(30, $ht, "D. Contact No :", 0, 0, 'R');
$pdf->Cell(50, $ht, "", 'B', 0);
$pdf->Ln(10);

$pdf->SetFont('Arial', 'B', 12);
$pdf->Cell(195, $ht, "Declaration by the Applicant :", 0, 0, 'L');
$pdf->Ln($ht);

$pdf->SetFont('Arial', '', 10);
$pdf->Cell(4, $ht, "I,", 0, 0, 'L');
$pdf->Cell(68, $ht, "", 'B', 0, 'L');
$pdf->Cell(140, $ht, "hereby authorise M/s Global Atlas Tours & Forex to arrange the Flight Ticket /", 0, 0, 'L');
$pdf->Ln($ht);

$pdf->Cell(195, $ht, "Accomodation  in Makkah Al - Mukarrama, Madina Al - Munawwara, Maulim Draft and other Haj Expenses as the need be in ", 0, 0, 'L');
$pdf->Ln($ht);

$pdf->Cell(195, $ht, "Saudi Arabia. Further, If I die, bury my body in the same Country, according to the laws of that country,  ", 0, 0, 'L');
$pdf->Ln($ht);

$pdf->Cell(195, $ht, "I do hereby accept and abide all the terms and Conditions of your company.", 0, 0, 'L');
$pdf->Ln(2);

$pdf->SetFont('Arial', 'B', 12);
$pdf->Cell(140, $ht, "", 0, 0, 'L');
$pdf->Cell(35, $ht, "Your's Sincerely", 0, 0, 'L');
$pdf->Ln(20);

$pdf->SetFont('Arial', '', 10);
$pdf->Cell(100, $ht, "Please See Overleaf", 0, 0, 'L');
$pdf->SetFont('Arial', 'B', 12);
$pdf->Cell(35, $ht, "Sign or Thumb Impression of the Applicant", 0, 0, 'L');
$pdf->Ln($ht);

ob_end_clean();
$pdf->Output("$formname - $lparty[name]-" . $getmdata['vouchno'] . ".pdf", "I");
