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


mysqli_query($conn, "SET NAMES 'utf8'");
mysqli_query($conn, 'SET CHARACTER SET utf8');

header('Content-Type: text/html;charset=UTF-8');
ini_set('default_charset', 'utf-8');

$maindb = 'visamain';
$trandb = 'visatran';

$file = 'visaapp_pdf.php';
$formname = "Visaform";
$keyfld = "vouchno";

$zdb = $_SESSION["zdbyear_" . $dbname];
$zroot = $_SESSION["zdir"];
mysqli_select_db($conn, $zdb);
$mht = 'height:20px;';

$admin = $_SESSION["admin_" . $dbname];
$myvouch = $_REQUEST["myvouch"];
$ppno = $_REQUEST["passport"];
$passport = trim($ppno);

// browse($passport);
$pname = $getacc['name'];
$add1 = $getacc['add1'];
$add2 = $getacc['add2'];
$mainqry = mysqli_query($conn, "SELECT a.*, b.ladd1, b.sector, b.sponsor, b.sponsor2, b.visano, b.hijridate, b.purpvisit,
                                       DATE_FORMAT(a.vouchdt,  '%d-%m-%Y') AS mydt, 
                                       DATE_FORMAT(a.dob,  '%d-%m-%Y') AS mydob, 
                                       DATE_FORMAT(a.issdate,  '%d-%m-%Y') AS mydoi,  
                                       DATE_FORMAT(a.doe,  '%d-%m-%Y') AS mydoe  
                                       FROM `$trandb` a, `$maindb` b 
                                       WHERE a.myvouch = '$myvouch' and a.passport = '$passport'
                                       and a.`myvouch` = b.`myvouch` ") or die(mysqli_error($conn));
//print table($mainqry);
//die();
$fetdata = mysqli_fetch_array($mainqry);
// $sponsor  = $fetdata['sponsor'];
// $mofano   = $fetdata['mofano'];
$mofano2   = $fetdata['mofano2'];
$imagepath   = $fetdata['imagepath'];
//browse($pname);
// browse($sponsor);

$getcomp = mysqli_query($conn, "SELECT * FROM $zroot.`company` WHERE `code`= '1'")or die(mysqli_error($conn));
$comp = mysqli_fetch_array($getcomp);

//$gettran = mysqli_query($conn, 
//require("library/fpdf/fpdf.php");
require_once("library/TCPDF/tcpdf.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);
//        //to add custom font from unicode folder
////Page number
////        $this->Cell(0, 10, 'Page ' . $this->PageNo() . '/{nb}', 0, 0, 'C');
//    }
//}
//browse('udar');
//$pdf = new tFPDF();
//$pdf->AddPage();
// Add a Unicode font (uses UTF-8)
//$pdf = new pdf('P', 'mm', 'A4');
$pdf = new TCPDF('P', 'mm', 'A4', true, 'UTF-8' ,false);

//remove default header and footer
$pdf->setPrintHeader(false);
$pdf->setPrintFooter(false);

//$pdf->AliasNbPages();
$pdf->AddPage();


$fs = 11;
$ht = 5;
$hln = 8;
$pdf->SetFont('freeserif', '', 14);
$pdf->SetTextColor(0, 0, 0);
$pdf->Image( "$imagepath", 10, 7, +30);
$pdf->Cell(10, 6, "", 0, 0, 'C');
$pdf->Image('images/visaform/saudiarabialogo.jpg', 77, 7, +40);
$pdf->SetFont('freeserif', '', 14);
$pdf->Cell(180, 6, "CONSULATE GENERAL", 0, 0, 'R');
$pdf->Ln(6);
$pdf->SetFont('freeserif', '', 13);
$pdf->Cell(182, 5, "OF SAUDI ARABIA", 0, 0, 'R');
$pdf->Ln(6);
$pdf->Cell(172, 5, "MUMBAI", 0, 0, 'R');

$pdf->Ln(9);
$pdf->SetFont('freeserif', '', 14);
$pdf->Cell(80, 6, "", 0, 0, 'C');

$pdf->SetFont('aefurat', 'B', 12);
$pdf->Cell(45, 6, "مومباي", 0, 0, 'L');
$pdf->Cell(0.1, 6, "", 0, 0, 'L');
if ($mofano2 != ''){
    $pdf->Cell(70, 9, "MOFA NO.:"."$mofano2", 1, 0, 'L');
}else {
    $pdf->Cell(70, 9, "MOFA NO.:"."$mofano", 1, 0, 'L');
}
$pdf->SetFont('aefurat', '', 12);
// $pdf->Cell(10, 9, "$mofano", 0, 0, 'L');

$pdf->Ln(8);
$pdf->Cell(70, 6, "" ,'L');
$pdf->Cell(55, 6, "استمارة طلب تأشيرة", 0, 0, 'L');
// $pdf->Cell(55, 6,"0 ,0,"استمارة طلب تأشيرة ,'L');
$pdf->SetFont('freeserif', '', $fs);
// $pdf->Cell(70, 9, "رقم التسلسل________________/ ٢٣٢", 1, 0, 'L');
$pdf->Image('images/visaform/mofa.jpg', 135, 42, +71);

$pdf->Ln(11);
$pdf->SetFont('freeserif', 'B', $fs);
$pdf->Cell(50, 6, "", 0, 0, 'L');

mysqli_query($conn, "SET NAMES 'utf8'");
mysqli_query($conn, 'SET CHARACTER SET utf8');

$category = $fetdata['category'];                                       
$sponsor  = $fetdata['sponsor'];
$mofano   = $fetdata['mofano'];



$sponsor2 = $fetdata['sponsor2'];

$relcast =  $fetdata['religion'];
$paxname = $fetdata['paxname'];
$residential = $fetdata['ladd1'];
$nationality = 'INDIAN';
$plbirth = $fetdata['plbirth'] ;
$place = $fetdata['sector'] ;
$dob = $fetdata['mydob'] ;
$doi = $fetdata['mydoi'] ;
$poi = $fetdata['issplace'] ;
$doe = $fetdata['mydoe'];
$sex = $fetdata['sex'];
$visatype = $fetdata['visatype'];

if ($sex == 'M') {
    $gender = 'Male' ;
} else {
    $gender = 'Female' ;
}

$purofvis = $fetdata['purpvisit'];
$perofstay = $fetdata['periodstay'] ;
$dep = 'SOON';
$visano = $fetdata['visano'] ;
$dateissue = $fetdata['hijridate'];

$pdf->Cell(75, 6, "VISA APPLICATION FORM", 0, 0, 'C');

$pdf->SetFont('freeserif', '', $fs);
//$pdf->Cell(70, 9, "/___________________", 1, 0, 'L');
// $pdf->Image('images/visaform/visa.jpg', 75, 37, +42);
// browse($paxname);

$pdf->Ln(7);
$pdf->SetFont('freeserif', 'B', $fs);
$pdf->Cell(16, 6, "Job title:", 0, 0, 'R'); 
$pdf->SetFont('aefurat', 'B', $fs);
$pdf->Cell(80, 6, $category, 'B', 0, 'L');
$pdf->Cell(15, 6, "المهنة :", '', 0, 'L ');
$pdf->Cell(25, 6, "GCC Code No.", 0, 0, 'L');
$pdf->Cell(42, 5, '', 'B', 0, 'L');
$pdf->SetFont('freeserif', 'BU', $fs);
$pdf->Cell(0.5, 7, 'رمزالطبيب:', '', 'B', 'L');
$pdf->SetFont('freeserif', 'B', $fs);

$pdf->Ln($hln);
$pdf->Cell(40, $ht, "Agent's name (optional)", 0, 0, 'L');
$pdf->Cell(25, $ht, "", 'B', 0, 'L');
$pdf->SetFont('freeserif', 'B', 11);
$pdf->Cell(81, $ht, "AL  HAMD  TOURS  AND  TRAVELS", 'B', 0, 'R');
$pdf->SetFont('freeserif', 'B', $fs);
$pdf->Cell(25, $ht, "", 'B', 0, 'L');
$pdf->Cell(25, $ht, "اسم الوكيل (اذا وجد)", '', 0, 'R');

$pdf->Ln(3);
$pdf->SetFont('freeserif', 'BU', $fs);
$pdf->Cell(195, 6, "", 'B', 0, 'L');
$pdf->SetFont('freeserif', '', $fs);
$pdf->Ln(2);
$pdf->Cell(195, 6, "", 'B', 0, 'L');
$pdf->SetFont('freeserif', '', $fs);

$pdf->Ln($hln);
$pdf->SetFont('aefurat', '', $fs);
$pdf->Cell(38, 6, "P.P. holder's first name : ", 0, 0, 'L');
$pdf->Cell(45, 6, "الاسم الاول لحامل الجواز", 0, 0, 'L');
$pdf->Cell(22, 6, "Middle name : ", 0, 0, 'L');
$pdf->SetFont('aefurat', 'B', $fs);
$pdf->Cell(33, 6, "الاسم الثاني", 0, 0, 'L');
$pdf->Cell(40, 6, "Family Name (optional):", 0, 0, 'L');
$pdf->Cell(5, 6, "اسم العائلة", 0, 0, 'L');
$pdf->SetFont('aefurat', '', $fs);

$pdf->Ln(6);
$pdf->SetFont('freeserif', '', $fs);
$pdf->Cell(195, $ht, $paxname, 'B', 0, 'C');

$pdf->Ln($hln);
$pdf->SetFont('freeserif', '', $fs);
$pdf->Cell(35, $ht, "Place & date of birth:", 0, 0, 'L');
$pdf->SetFont('freeserif', 'B', $fs);
$pdf->Cell(65, $ht, $plbirth, 'B', 0, 'C');
$pdf->Cell(66, $ht, $dob, 'B', 0, 'C');
$pdf->Cell(27, 5.5, "محل وتاريخ الولادة:", 'B', 0, 'L');
$pdf->SetFont('freeserif', '', $fs);

$pdf->Ln($hln);
$pdf->Cell(20, $ht, "Nationality:", 0, 0, 'L');
$pdf->SetFont('freeserif', 'B', $fs);
$pdf->Cell(70, $ht, "", 'B', 0, 'R');
$pdf->Cell(91, $ht, $nationality , 'B', 0, 'L');
$pdf->Cell(33, $ht, "الجنسية :", '', 0, 'L');
$pdf->SetFont('freeserif', '', $fs);

$pdf->Ln($hln);
$pdf->Cell(28, $ht, "Religion & caste:", 0, 0, 'L');
$pdf->SetFont('freeserif', 'B', $fs);
$pdf->Cell(70, $ht, "", 'B', 0, 'R');
$pdf->Cell(84.5, $ht, $relcast,  'B', 0, 'L');
$pdf->Cell(95, $ht, 'الديانة : ',  0, 0, 'L');
$pdf->SetFont('freeserif', '', $fs);

$pdf->Ln($hln);
$pdf->Cell(32, $ht, "Residential address:", 0, 0, 'L');
$pdf->SetFont('freeserif', 'B', $fs);
$pdf->Cell(55, $ht, "", 'B', 0, 'R');
$pdf->Cell(87, $ht, $plbirth,  'B', 0, 'L');
$pdf->Cell(72, $ht, 'عنوان المنزل :',  0, 0, 'L');
$pdf->SetFont('freeserif', '', $fs);

$pdf->Ln($hln);
$pdf->Cell(50, $ht, "Passport No: & Place of Issue:", 0, 0, 'L');
$pdf->SetFont('freeserif', 'B', $fs);
$pdf->Cell(60, $ht, $ppno,  'B', 0, 'C');
$pdf->Cell(57, $ht, $poi,  'B', 0, 'C');
$pdf->Cell(72, $ht, 'رقم الجواز و مصدره:',  0, 0, 'L');
$pdf->SetFont('freeserif', '', $fs);

$pdf->Ln($hln);
$pdf->Cell(37, $ht, "Date of issue & expiry:", 0, 0, 'L');
$pdf->SetFont('freeserif', 'B', $fs);
$pdf->Cell(45, $ht, $doi,  'B', 0, 'C');
$pdf->Cell(45, $ht, $doe,  'B', 0, 'R');
$pdf->Cell(36, $ht, '',  'B', 0, 'L');
$pdf->Cell(33, 5.5, 'تاريخ الإصدار والإنتهاء :',  'B', 0, 'L');
$pdf->SetFont('freeserif', '', $fs);

$pdf->Ln($hln);
$pdf->Cell(33, $ht, "Sex (Male/Female):", 0, 0, 'L');
$pdf->SetFont('freeserif', 'B', $fs);
$pdf->Cell(50, $ht, '','B', 0, 'C');
$pdf->Cell(40, $ht, $gender,  'B', 0, 'C');
$pdf->Cell(49.5, $ht, ':',  'B', 0, 'R');
$pdf->Cell(24, 5.5, 'الجنس:ذكر/ أنثي',  '', 0, 'L');
$pdf->SetFont('freeserif', '', $fs);

$pdf->Ln($hln);
$pdf->Cell(50, $ht, "Accompanied in passport by:(1)", 0, 0, 'L');
$pdf->SetFont('freeserif', 'B', $fs);
$pdf->Cell(40, $ht, '','B', 0, 'C');
$pdf->Cell(30, $ht, '',  'B', 0, 'C');
$pdf->Cell(44, $ht, ':',  'B', 0, 'R');
$pdf->Cell(50, $ht, 'المرا�?قون بن�?س الجواز ',  '', 0, 'L');
$pdf->SetFont('freeserif', '', $fs);

$pdf->Ln($hln);
$pdf->Cell(6, $ht, "(2)", 0, 0, 'L');
$pdf->Cell(70, $ht, '','B', 0, 'C');
$pdf->Cell(40, $ht, '(3)',  'B', 0, 'C');
$pdf->Cell(79, $ht, '',  'B', 0, 'R');

if ($visatype == 'W'){
    $purofvis = 'WORK';
}

if ($visatype == 'F'){
    $purofvis = 'FAMILY';
}

if ($visatype == 'R'){
    $purofvis = 'RESIDENCE';
}

if ($visatype == 'V'){
    $purofvis = 'VISIT';
}
$pdf->Ln($hln);
$pdf->Cell(52, $ht, "Purpose of visit & period of stay:", '', 0, 'L');
$pdf->SetFont('freeserif', 'B', $fs);
$pdf->Cell(75, $ht, $purofvis,'B', 0, 'C');
$pdf->Cell(15, $ht, $perofstay,  'B', 0, 'R');
$pdf->Cell(13.5, $ht, ':',  'B', 0, 'R');
$pdf->Cell(20, $ht, 'الغاية من الس�?رو مدة الاقامة  ',  '', 0, 'L');
$pdf->SetFont('freeserif', '', $fs);

$pdf->Ln($hln);
$pdf->Cell(55, $ht, "Date of departure & port of arrival:", 0, 0, 'L');
$pdf->SetFont('freeserif', 'B', $fs);
$pdf->Cell(50, $ht, $dep,'B', 0, 'R');
$pdf->Cell(20, $ht, '',  'B', 0, 'C');
$pdf->Cell(31, $ht, ':',  'B', 0, 'R');
$pdf->Cell(45, $ht, 'تاريخ المغادرة وجهة الوصول',  '', 0, 'L');
$pdf->SetFont('freeserif', '', $fs);

$pdf->Ln($hln);
$pdf->Cell(46, $ht, "Visa number & date of issue:", 0, 0, 'L');
$pdf->SetFont('freeserif', 'B', $fs);
$pdf->Cell(65, $ht, $visano,'B', 0, 'C');
$pdf->Cell(20, $ht, $dateissue, 'B', 0, 'C');
$pdf->Cell(17, $ht, ':',  'B', 0, 'R');
$pdf->Cell(20, $ht, 'رقم أمرالاستقدام التأشيرة و تاريخها',  '', 0, 'L');
$pdf->SetFont('freeserif', '', $fs);

$pdf->Ln($hln);
$pdf->Cell(26, $ht, "Sponsor's name:", 0, 0, 'L');
$pdf->SetFont('freeserif', 'B', $fs);
$pdf->Cell(153, $ht, $sponsor, 'B', 0, 'C');
$pdf->Cell(1.1, $ht,':' , 'B', 0, 'R');
$pdf->Cell(3, $ht,'اسم الك�?يل' , '', 0, 'L');
$pdf->SetFont('freeserif', '', $fs);

$pdf->Ln($hln);
$pdf->Cell(30, $ht, "Address & Tel no.:", 0, 0, 'L');
$pdf->SetFont('freeserif', 'B', $fs);
$pdf->Cell(45, $ht, '','B', 0, 'C');
$pdf->Cell(20, $ht, '',  'B', 0, 'C');
$pdf->Cell(40, $ht, "KINGDOM  OF  SAUDI ARABIA", 'B', 0, 'R');
$pdf->Cell(32, $ht, ':',  'B', 0, 'R');
$pdf->Cell(35, $ht, 'العنوان ورقم الهات�?',  '', 0, 'L');
$pdf->SetFont('freeserif', '', $fs);

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

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

$pdf->Ln();
$pdf->SetFont('freeserif', '', 10.3);
$pdf->Cell(109, $ht, "1.  THE  UNDERSIGNED  HEREBY  CERTIFY  THAT  ALL THE", 0, 0, 'L');
$pdf->SetFont('freeserif', 'B', 10.3);
$pdf->Cell(90, $ht, "أنا الموقع أدناه أقر بأن كل المعلومات التي دونتها صحيحة وسأكون", 0, 0, 'L');
$pdf->SetFont('freeserif', '', 10.3);

$pdf->Ln(4);
$pdf->SetFont('freeserif', '', 10.3);
$pdf->Cell(142.5, $ht, "INFORMATION I HAVE PROVIDED IS CORRECT.I WILL ABIDE BY", 0, 0, 'L');
$pdf->SetFont('freeserif', 'B', 10.3);
$pdf->Cell(90, $ht, "ملتزماً بقوانين المملكة أثناء وجودي بها .", 0, 0, 'L');
$pdf->SetFont('freeserif', '', 10.3);

$pdf->Ln(4);
$pdf->SetFont('freeserif', '', 10.3);
$pdf->Cell(90, $ht, "THE LAWS OF THE KINGDOM DURING HER PERIOD OF STAY.", 0, 0, 'L');

$pdf->Ln($hln);
$pdf->SetFont('freeserif', '', $fs);
$pdf->Cell(90, $ht, "I the undersigned hereby agree that I am ready to undergo through all the emigration / residential rules applied in", 0, 0, 'L');

$pdf->Ln();
$pdf->SetFont('freeserif', '', $fs);
$pdf->Cell(90, $ht, "the kingdom of Saudi Arabia even the investigation about my identify through the new identification process finger", 0, 0, 'L');

$pdf->Ln();
$pdf->SetFont('freeserif', '', $fs);
$pdf->Cell(90, $ht, "prints / iris of the eyes.", 0, 0, 'L');

$pdf->Ln(10);
$pdf->Cell(69, $ht, "         SIGNATURE OF THE APPLICANT", 0, 0, 'L');
$pdf->Cell(45, $ht, '','B', 0, 'C');
$pdf->Cell(10, $ht, '',  'B', 0, 'C');
$pdf->Cell(30, $ht, '',  'B', 0, 'R');
$pdf->SetFont('freeserif', 'B', $fs);
$pdf->Cell(30, $ht, 'توقيع طالب التأشيرة',  '', 0, 'R');
$pdf->SetFont('freeserif', '', $fs);

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

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

$pdf->Ln(5);
$pdf->Cell(190, $ht, "(FOR OFFICIAL USE ONLY)", 0, 0, 'C');
$pdf->Ln();
ob_end_clean();
$pdf->Output("Annexure I Normal-" . $getmdata[vouchno] . ".pdf", "I");
?>
         
