Inventory PDF now properly handles UTF8 encoding.

Thu, 08 Nov 2018 20:30:32 +0100

author
Michiel Broek <mbroek@mbse.eu>
date
Thu, 08 Nov 2018 20:30:32 +0100
changeset 82
7af1d472475a
parent 81
aad866b2bcea
child 83
85521c6e0022

Inventory PDF now properly handles UTF8 encoding.

www/inv_instock.php file | annotate | diff | comparison | revisions
--- a/www/inv_instock.php	Thu Nov 08 19:57:32 2018 +0100
+++ b/www/inv_instock.php	Thu Nov 08 20:30:32 2018 +0100
@@ -5,6 +5,14 @@
 define('EURO', chr(128) );
 
 $link = mysqli_connect(DBASE_HOST,DBASE_USER,DBASE_PASS,DBASE_NAME);
+if (! $link) {
+	die('Connect Error (' . mysqli_connect_errno() . ') ' . mysqli_connect_error());
+}
+if (! mysqli_set_charset($link, "utf8" )) {
+	echo "error";
+	return 1;
+}
+
 setlocale ( LC_ALL, 'nl_NL.UTF-8');
 
 class PDF_MySQL_Table extends FPDF
@@ -86,8 +94,8 @@
 			$this->SetX($this->TableX);
 			$ci=$this->ColorIndex;
 			$this->SetFillColor($this->RowColors[$ci][0],$this->RowColors[$ci][1],$this->RowColors[$ci][2]);
-			$this->Cell(30,5,$row['supplier'],0,0,'L',true);
-			$this->Cell(90,5,$row['name'],0,0,'L',true);
+			$this->Cell(30,5,iconv('UTF-8','windows-1252',$row['supplier']),0,0,'L',true);
+			$this->Cell(90,5,iconv('UTF-8','windows-1252',$row['name']),0,0,'L',true);
 			$this->Cell(30,5,sprintf("%10.3f kg",$row['inventory']),0,0,'R',true);
 			$this->Cell(20,5,sprintf("%8.2f ",$row['cost']).EURO,0,0,'R',true);
 			$this->Cell(20,5,sprintf("%8.2f ",$value).EURO,0,0,'R',true);
@@ -134,9 +142,9 @@
 			$this->SetX($this->TableX);
 			$ci=$this->ColorIndex;
 			$this->SetFillColor($this->RowColors[$ci][0],$this->RowColors[$ci][1],$this->RowColors[$ci][2]);
-			$this->Cell(30,5,$row['origin'],0,0,'L',true);
-			$this->Cell(75,5,$row['name'],0,0,'L',true);
-			$this->Cell(15,5,$row['form'],0,0,'L',true);
+			$this->Cell(30,5,iconv('UTF-8','windows-1252',$row['origin']),0,0,'L',true);
+			$this->Cell(75,5,iconv('UTF-8','windows-1252',$row['name']),0,0,'L',true);
+			$this->Cell(15,5,iconv('UTF-8','windows-1252',$row['form']),0,0,'L',true);
 			$this->Cell(30,5,sprintf("%10.1f gr",$stock),0,0,'R',true);
 			$this->Cell(20,5,sprintf("%8.2f ",$row['cost']).EURO,0,0,'R',true);
 			$this->Cell(20,5,sprintf("%8.2f ",$value).EURO,0,0,'R',true);
@@ -184,9 +192,9 @@
 			$this->SetX($this->TableX);
 			$ci=$this->ColorIndex;
 			$this->SetFillColor($this->RowColors[$ci][0],$this->RowColors[$ci][1],$this->RowColors[$ci][2]);
-			$this->Cell(30,5,$row['laboratory'],0,0,'L',true);
-			$this->Cell(20,5,$row['product_id'],0,0,'L',true);
-			$this->Cell(70,5,$row['name'],0,0,'L',true);
+			$this->Cell(30,5,iconv('UTF-8','windows-1252',$row['laboratory']),0,0,'L',true);
+			$this->Cell(20,5,iconv('UTF-8','windows-1252',$row['product_id']),0,0,'L',true);
+			$this->Cell(70,5,iconv('UTF-8','windows-1252',$row['name']),0,0,'L',true);
 			$this->Cell(30,5,sprintf("%10.1f ",$stock).$amount,0,0,'R',true);
 			$this->Cell(20,5,sprintf("%8.2f ",$row['cost']).EURO,0,0,'R',true);
 			$this->Cell(20,5,sprintf("%8.2f ",$value).EURO,0,0,'R',true);
@@ -233,8 +241,8 @@
 			$this->SetX($this->TableX);
 			$ci=$this->ColorIndex;
 			$this->SetFillColor($this->RowColors[$ci][0],$this->RowColors[$ci][1],$this->RowColors[$ci][2]);
-			$this->Cell(30,5,$row['type'],0,0,'L',true);
-			$this->Cell(90,5,$row['name'],0,0,'L',true);
+			$this->Cell(30,5,iconv('UTF-8','windows-1252',$row['type']),0,0,'L',true);
+			$this->Cell(90,5,iconv('UTF-8','windows-1252',$row['name']),0,0,'L',true);
 			$this->Cell(30,5,sprintf("%10.1f ",$stock).$amount,0,0,'R',true);
 			$this->Cell(20,5,sprintf("%8.2f ",$row['cost']).EURO,0,0,'R',true);
 			$this->Cell(20,5,sprintf("%8.2f ",$value).EURO,0,0,'R',true);

mercurial