<?php 
 require('./fpdf/fpdf.php');
 require('./config.php');
if(!empty($_SESSION['user_connect_id']))
{ if(isset($_GET['id_ord'])){
//call the FPDF library


//if(!empty($_SESSION['user_connect_id'])){ 


$id_ord=$_GET['id_ord'];
$req_sql_ord= "SELECT *,o.id_ord FROM ordonnances as o,consultations as c, consultation_ordonnance as co  
     WHERE o.id_ord=co.id_ord and  c.id=co.id_consult and o.id_ord='$id_ord'"; 
      $result_ord= mysqli_query($con,$req_sql_ord);
      $row_ord= mysqli_fetch_array($result_ord); 
     $id_consult= $row_ord['id_consult'];


                 
              $req_get_p="SELECT *  FROM patients as p, consultations as c where c.id_patient=p.id and c.id='$id_consult'";
              $query_get_p=mysqli_query($con,$req_get_p);

              $row_p= mysqli_fetch_array($query_get_p); 
              $nom_patient=$row_p['nom'];
              $prenom_patient=$row_p['prenom'];
              $date_naissance=$row_p['date_naissance'];


  
                       $total = mysqli_num_rows($result_ord);

// //A4 width : 219mm
// //default margin : 10mm each side
// //writable horizontal : 219-(10*2)=189mm

//create pdf object
$pdf = new FPDF('P','mm','A5');


//add new page
$pdf->AddPage();
//Image(string file [, float x [, float y [, float w [, float h [, string type [, mixed link]]]]]])

$pdf->Image('assets/img/logo.png', 20, 10, 40,25);

$X=80;
$Y=10;
$pdf->SetXY($X,$Y);
$pdf->SetFont('Arial','B','18');
$pdf->SetTextColor(27,74,209);
$pdf->Cell('0','10','ALGERMED','0','c');

$pdf->SetFont('Arial','','13');
$pdf->SetTextColor(27,74,209);
$X=90;
$Y=25;
$pdf->SetXY($X,$Y);
$pdf->Cell('0','10','DR.BENNABES','0','c');

$X=90;
$Y=30;
$pdf->SetXY($X,$Y);
$pdf->Cell('0','10','Cabinet de pediatrie','0','c');
$X=90;
$Y=35;
$pdf->SetXY($X,$Y);
$pdf->Cell('0','10','C.R.O 8241 / TZO','0','c');
$pdf->SetFont('Arial','','12');
$X=80;
$Y=40;
$pdf->SetXY($X,$Y);
$pdf->Cell('0','10','Cite 1406 logement batiment 25','0','c');
$X=80;
$Y=45;
$pdf->SetXY($X,$Y);
$pdf->Cell('0','10','35000 Boumerdes, Algerie','0','c');
$X=90;
$Y=50;
$pdf->SetXY($X,$Y);
$pdf->Cell('0','10','+213 555 199 879','0','c');
$X=90;
$Y=55;
$pdf->SetXY($X,$Y);
$pdf->Cell('0','10','info@algermed.com','0','c');
$X=90;
$Y=60;
$pdf->SetXY($X,$Y);
$pdf->Cell('0','10','www.algermed.com','0','c');

$pdf->SetFont('Arial','','12');
$X=10;
$Y=40;
$pdf->SetXY($X,$Y);
$pdf->Cell('0','10','Boumerdes,le:','0');
$X=40;
$Y=40;
$pdf->SetXY($X,$Y);
$pdf->Cell('0','10','date','0');
$pdf->Ln(3);
$X=10;
$Y=47;
$pdf->SetXY($X,$Y);
$pdf->Cell('0','10','Nom:','0','C');
$X=25;
$Y=47;
$pdf->SetXY($X,$Y);
$pdf->Cell('0','10',$nom_patient,'0','C');
$pdf->Ln(1);

$X=10;
$Y=54;
$pdf->SetXY($X,$Y);
$pdf->Cell('0','10','Prenom:','0','C');
$X=30;
$Y=54;
$pdf->SetXY($X,$Y);
$pdf->Cell('0','10',$prenom_patient,'0','C');
$pdf->Ln(5);
$X=10;
$Y=61;
$pdf->SetXY($X,$Y);
$pdf->Cell('0','10','Date de naissance:','0','C');
$X=47;
$Y=61;
$pdf->SetXY($X,$Y);
$pdf->Cell('0','10',$date_naissance,'0','C');
$pdf->Ln(50);
$X=47;
$Y=80;
$pdf->SetXY($X,$Y);
$pdf->SetFont('Arial','B','25');
$pdf->Cell('0','10','Ordonnance','0','C');

$pdf->Ln(50);

$X=0;
$Y=150;
                         if($total) {

while($row = mysqli_fetch_array($res_med))
{
	 $nom_med = $row["nom_med"];
 $quantite = $row["quantite"];
 $posologie = $row["posologie"];  


$pdf->SetFont('Arial','',14);
$pdf->SetTextColor(0,0,0);

$pdf->SetXY($X,$Y);
$pdf->Cell(50,4,$nom_med,0,1,'C');
$X=$X+40;
$pdf->SetXY($X,$Y);
$pdf->SetFont('Arial','I',12);
$pdf->Cell(50,4,$quantite,0,1,'C');
$X=$X+80;
$pdf->SetFont('Arial','I',12);
$pdf->SetXY($X,$Y);
$pdf->Cell(50,4,$posologie,0,1,'C');

$pdf->Ln(20);
$X=0;
$Y=$Y+20;

$pdf->SetXY($X,$Y);
}

}                  
$pdf->Output();










// }
// }



// //output the result
// $pdf->Output();
}}?>