<?php
session_start();                      
$username=$_SESSION['username'] ?? '';
$password=$_SESSION['password'] ?? '';
include 'config.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){
		$code = $_GET['chn'] ?? '';
		$query  = "SELECT * FROM cycle_lst where pat_mrn LIKE '%$code%'";
		$result = mysqli_query($conn, $query);
				while($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
$xid_f = $row['pat_mrn'];
$xnm_f = $row['pat_name'];
$dob_f = $row['pat_dob'];
$xid_m = $row['part_mrn'];
$xnm_m = $row['part_name'];
$dob_m = $row['part_dob'];
				}

  include('php-barcode.php');
  require('../fpdff/fpdf.php');
  
  // -------------------------------------------------- //
  //                      USEFUL
  // -------------------------------------------------- //
  
  class eFPDF extends FPDF{
    function TextWithRotation($x, $y, $txt, $txt_angle, $font_angle=0)
    {
        $font_angle+=90+$txt_angle;
        $txt_angle*=M_PI/180;
        $font_angle*=M_PI/180;
    
        $txt_dx=cos($txt_angle);
        $txt_dy=sin($txt_angle);
        $font_dx=cos($font_angle);
        $font_dy=sin($font_angle);
    
        $s=sprintf('BT %.2F %.2F %.2F %.2F %.2F %.2F Tm (%s) Tj ET',$txt_dx,$txt_dy,$font_dx,$font_dy,$x*$this->k,($this->h-$y)*$this->k,$this->_escape($txt));
        if ($this->ColorFlag)
            $s='q '.$this->TextColor.' '.$s.' Q';
        $this->_out($s);
    }
  }

  // -------------------------------------------------- //
  //                  PROPERTIES
  // -------------------------------------------------- //
  
  $fontSize = 7;
  $marge    = 4;   // between barcode and hri in pixel
  //$x        = 50;  // barcode center
  //$y        = 20;  // barcode center
  $y1        = 120;  // barcode center
  $y2        = 190;  // barcode center
  $y3        = 260;  // barcode center
  $height   = 10;   // barcode height in 1D ; module size in 2D
  $height_x   = 10;   // barcode height in 1D ; module size in 2D
  $width    = 0.5;    // barcode height in 1D ; not use in 2D
  $width_x    = 0.4;    // barcode height in 1D ; not use in 2D
  $angle    = 0;   // rotation in degrees
  $angle_x    = 90;   // rotation in degrees
  $pos1 = 0;
  $pos2 = 85;
  
//  $code     = 'PAT038071'; // barcode, of course ;)
//  $type     = 'ean13';
  $type     = 'code128';
  $black    = '000000'; // color in hexa
  
  
  // -------------------------------------------------- //
  //            ALLOCATE FPDF RESSOURCE
  // -------------------------------------------------- //
    
  $pdf = new eFPDF('P', 'pt');
  $pdf->AddPage();
  
  // -------------------------------------------------- //
  //                      BARCODE
  // -------------------------------------------------- //
  
  
  $pdf->SetFont('Arial','B',$fontSize);
  $pdf->SetTextColor(0, 0, 0);

$i = 1;
$i = 1;
do{
    $i++;

//$pdf->SetX(12);
//$pdf->Cell(30,0,$code);
//$pdf->SetX(87);
//$pdf->Cell(30,0,$code);
//$pdf->SetX(157);
//$pdf->Cell(30,0,$code);

//$pdf->Ln(10);
$pdf->Ln(6);
$pdf->SetX(14);
$pdf->Cell(30,0,$xid_f);
$pdf->SetX(87);
$pdf->Cell(30,0,$xid_f);
$pdf->SetX(157);
$pdf->Cell(30,0,$xid_f);
$pdf->Ln(7);
$pdf->SetX(14);
$pdf->Cell(50,0,$xnm_f);
$pdf->SetX(87);
$pdf->Cell(50,0,$xnm_f);
$pdf->SetX(157);
$pdf->Cell(50,0,$xnm_f);
$pdf->Ln(7);
$pdf->SetX(14);
$pdf->Cell(30,0,$dob_f);
$pdf->SetX(87);
$pdf->Cell(30,0,$dob_f);
$pdf->SetX(157);
$pdf->Cell(30,0,$dob_f);

$pdf->Ln(10);

$pdf->SetX(14);
$pdf->Cell(30,0,$xid_m);
$pdf->SetX(87);
$pdf->Cell(30,0,$xid_m);
$pdf->SetX(157);
$pdf->Cell(30,0,$xid_m);
$pdf->Ln(7);
$pdf->SetX(14);
$pdf->Cell(50,0,$xnm_m);
$pdf->SetX(87);
$pdf->Cell(50,0,$xnm_m);
$pdf->SetX(157);
$pdf->Cell(50,0,$xnm_m);
$pdf->Ln(7);
$pdf->SetX(14);
$pdf->Cell(30,0,$dob_m);
$pdf->SetX(87);
$pdf->Cell(30,0,$dob_m);
$pdf->SetX(157);
$pdf->Cell(30,0,$dob_m);

//$pdf->Ln(10);

$pos2 = $pos2+10;

}
while($i <= 1);

//$pdf->Output();
$content = $pdf->Output('Test.pdf','F');
echo "<div><iframe src=\"Test.pdf\" width=\"100%\" style=\"height:100%\"></iframe></div>";
echo "<meta http-equiv=Refresh content=3;url=pat_3.php>";
}else{
echo "You are not authorised to view this page";

}
?>
