<?php
 require('./fpdf/fpdf.php');
 include('./config.php');

if(!empty($_SESSION['user_connect_id']))
{ if(isset($_GET['id_ord'])){

$id_ord=$_GET['id_ord'];
$id_patient=$_GET['id_patient'];
$req_sql_ord= "SELECT o.id_ord,nom_med,quantite,posologie FROM ordonnances as o,medicaments as m, ordonnance_medicament as om  
     WHERE o.id_ord=om.id_ord and  m.id_medicament=om.id_med and o.id_ord='$id_ord'"; 
      $result_ord= mysqli_query($con,$req_sql_ord);
      $row_ord= mysqli_fetch_array($result_ord); 

              $req_get_p="SELECT *  FROM patients as p where  p.id='$id_patient'";
              $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);




//Initialize the 3 columns and the total
$column_nom_med = "";
$column_quantite = "";
$column_posologie = "";


//For each row, add the field to the corresponding column
while($row = mysql_fetch_array($result_ord))
{
	$nom_med = $row["nom_med"];
$quantite = $row["quantite"];
$posologie = $row["posologie"];
	
	$column_code = $column_nom_med.$nom_med."\n";
	$column_name = $column_quantite.$quantite."\n";
	$column_price = $column_posologie.$posologie."\n";
}


//Create a new PDF file
$pdf=new FPDF();
$pdf->AddPage();

//Fields Name position
$Y_Fields_Name_position = 20;
//Table position, under Fields Name
$Y_Table_Position = 26;

//First create each Field Name
//Gray color filling each Field Name box
$pdf->SetFillColor(232,232,232);
//Bold Font for Field Name
$pdf->SetFont('Arial','B',12);
$pdf->SetY($Y_Fields_Name_position);
$pdf->SetX(45);
$pdf->Cell(20,6,'CODE',1,0,'L',1);
$pdf->SetX(65);
$pdf->Cell(100,6,'NAME',1,0,'L',1);
$pdf->SetX(135);
$pdf->Cell(30,6,'PRICE',1,0,'R',1);
$pdf->Ln();

//Now show the 3 columns
$pdf->SetFont('Arial','',12);
$pdf->SetY($Y_Table_Position);
$pdf->SetX(45);
$pdf->MultiCell(20,6,$column_code,1);
$pdf->SetY($Y_Table_Position);
$pdf->SetX(65);
$pdf->MultiCell(100,6,$column_name,1);
$pdf->SetY($Y_Table_Position);
$pdf->SetX(135);
$pdf->MultiCell(30,6,$columna_price,1,'R');
$pdf->SetX(135);
$pdf->MultiCell(30,6,'$ '.$total,1,'R');

//Create lines (boxes) for each ROW (Product)
//If you don't use the following code, you don't create the lines separating each row
$i = 0;
$pdf->SetY($Y_Table_Position);
while ($i < $number_of_products)
{
	$pdf->SetX(45);
	$pdf->MultiCell(120,6,'',1);
	$i = $i +1;
}

$pdf->Output();



}}
?>
