|
1 <?php |
|
2 require_once($_SERVER['DOCUMENT_ROOT'].'/includes/global.inc.php'); |
|
3 require_once($_SERVER['DOCUMENT_ROOT'].'/fpdf/fpdf.php'); |
|
4 |
|
5 define('EURO', chr(128) ); |
|
6 |
|
7 $link = mysqli_connect(DBASE_HOST,DBASE_USER,DBASE_PASS,DBASE_NAME); |
|
8 //mysqli_set_charset($link, "utf8" ); |
|
9 setlocale ( LC_ALL, 'nl_NL.UTF-8'); |
|
10 $record = $_GET["record"]; |
|
11 $result = mysqli_query($link, "SELECT * FROM recipes WHERE record='".$record."'"); |
|
12 $row = mysqli_fetch_array($result); |
|
13 |
|
14 |
|
15 class PDF_MySQL_Table extends FPDF |
|
16 { |
|
17 protected $ProcessingTable=false; |
|
18 protected $aCols=array(); |
|
19 protected $TableX; |
|
20 protected $HeaderColor; |
|
21 protected $RowColors; |
|
22 protected $TotalColor; |
|
23 protected $ColorIndex; |
|
24 |
|
25 function Header() { |
|
26 // Print the table header if necessary |
|
27 if ($this->ProcessingTable) |
|
28 $this->TableHeader(); |
|
29 } |
|
30 |
|
31 function TableHeader() { |
|
32 $this->SetFont('Helvetica','B',9); |
|
33 $this->SetX($this->TableX); |
|
34 $this->SetFillColor($this->HeaderColor[0],$this->HeaderColor[1],$this->HeaderColor[2]); |
|
35 foreach($this->aCols as $col) |
|
36 $this->Cell($col['w'],5,$col['c'],0,0,$col['a'],true); |
|
37 $this->Ln(); |
|
38 } |
|
39 |
|
40 function AddCol($width=-1, $caption='', $align='L') { |
|
41 $this->aCols[]=array('c'=>$caption,'w'=>$width,'a'=>$align); |
|
42 } |
|
43 |
|
44 function TableGlobal($row,$prop) { |
|
45 /* 2 Columns */ |
|
46 $vul = $this->w - $this->rMargin - $this->lMargin - 170; |
|
47 $cMargin=$this->cMargin; |
|
48 $this->cMargin=$prop['padding']; |
|
49 $this->TableX=$this->lMargin; |
|
50 $this->HeaderColor=$prop['HeaderColor']; |
|
51 $this->TotalColor=$prop['TotalColor']; |
|
52 $this->RowColors=array($prop['color1'],$prop['color2']); |
|
53 $this->SetFont('Helvetica','B',11); |
|
54 $this->SetX($this->TableX); |
|
55 $this->SetFillColor($this->HeaderColor[0],$this->HeaderColor[1],$this->HeaderColor[2]); |
|
56 $this->Cell(0, 6, 'Recept overzicht',0,0,'C',true); |
|
57 $this->Ln(); |
|
58 |
|
59 $this->SetFont('Helvetica','',9); |
|
60 $this->SetFillColor($this->RowColors[0][0],$this->RowColors[0][1],$this->RowColors[0][2]); |
|
61 |
|
62 $this->SetX($this->TableX); |
|
63 $this->Cell(35,5,'Type',0,0,'L',true); |
|
64 $this->Cell(25,5,$row['type'],0,0,'L',true); |
|
65 $this->Cell(25,5,'',0,0,'L',true); |
|
66 $this->Cell($vul,5,'',0,0,'L',false); |
|
67 $this->Cell(35,5,'Batch grootte',0,0,'L',true); |
|
68 $this->Cell(25,5,$row['batch_size'].' liter',0,0,'L',true); |
|
69 $this->Cell(25,5,'',0,0,'L',true); |
|
70 $this->Ln(); |
|
71 |
|
72 $this->SetX($this->TableX); |
|
73 $this->Cell(35,5,'Kooktijd',0,0,'L',true); |
|
74 $this->Cell(25,5,$row['boil_time'].' minuten',0,0,'L',true); |
|
75 $this->Cell(25,5,'',0,0,'L',true); |
|
76 $this->Cell($vul,5,'',0,0,'L',false); |
|
77 $this->Cell(35,5,'Brouwzaal rendement',0,0,'L',true); |
|
78 $this->Cell(25,5,$row['efficiency'].' %',0,0,'L',true); |
|
79 $this->Cell(25,5,'',0,0,'L',true); |
|
80 $this->Ln(); |
|
81 |
|
82 $this->SetX($this->TableX); |
|
83 $this->Cell(35,5,'Start SG',0,0,'L',true); |
|
84 $this->Cell(25,5,sprintf("%.3f",$row['est_og']),0,0,'L',true); |
|
85 $this->Cell(25,5,'('.sprintf("%.3f",$row['st_og_min']).' - '.sprintf("%.3f",$row['st_og_max']).')',0,0,'L',true); |
|
86 $this->Cell($vul,5,'',0,0,'L',false); |
|
87 $this->Cell(35,5,'Eind SG',0,0,'L',true); |
|
88 $this->Cell(25,5,sprintf("%.3f",$row['est_fg']),0,0,'L',true); |
|
89 $this->Cell(25,5,'('.sprintf("%.3f",$row['st_fg_min']).' - '.sprintf("%.3f",$row['st_fg_max']).')',0,0,'L',true); |
|
90 $this->Ln(); |
|
91 |
|
92 $this->SetX($this->TableX); |
|
93 $this->Cell(35,5,'Geschat alcohol',0,0,'L',true); |
|
94 $this->Cell(25,5,sprintf("%.1f",$row['est_abv']).'%',0,0,'L',true); |
|
95 $this->Cell(25,5,'('.sprintf("%.1f",$row['st_abv_min']).' - '.sprintf("%.1f",$row['st_abv_max']).'%)',0,0,'L',true); |
|
96 $this->Cell($vul,5,'',0,0,'L',false); |
|
97 $this->Cell(35,5,'CO2',0,0,'L',true); |
|
98 $this->Cell(25,5,sprintf("%.1f",$row['est_carb']).'%',0,0,'L',true); |
|
99 $this->Cell(25,5,'('.sprintf("%.1f",$row['st_carb_min']).' - '.sprintf("%.1f",$row['st_carb_max']).'%)',0,0,'L',true); |
|
100 $this->Ln(); |
|
101 |
|
102 $this->SetX($this->TableX); |
|
103 $this->Cell(35,5,'Kleur ('.$row['color_method'].')',0,0,'L',true); |
|
104 $this->Cell(25,5,$row['est_color'].' EBC',0,0,'L',true); |
|
105 $this->Cell(25,5,'('.$row['st_color_min'].' - '.$row['st_color_max'].' EBC)',0,0,'L',true); |
|
106 $this->Cell($vul,5,'',0,0,'L',false); |
|
107 $this->Cell(35,5,'Bitterheid ('.$row['ibu_method'].')',0,0,'L',true); |
|
108 $this->Cell(25,5,sprintf("%.0f",$row['est_ibu']).' IBU',0,0,'L',true); |
|
109 $this->Cell(25,5,'('.$row['st_ibu_min'].' - '.$row['st_ibu_max'].' IBU)',0,0,'L',true); |
|
110 $this->Ln(); |
|
111 |
|
112 $this->cMargin=$cMargin; |
|
113 } |
|
114 |
|
115 function TableFermentables($row,$prop) { |
|
116 $vul = $this->w - $this->rMargin - $this->lMargin - 130; |
|
117 $this->AddCol($vul,'Grondstof','L'); |
|
118 $this->AddCol( 30,'Leverancier','L'); |
|
119 $this->AddCol( 15,'EBC','R'); |
|
120 $this->AddCol( 15,'Moment','L'); |
|
121 $this->AddCol( 20,'Kg','R'); |
|
122 $this->AddCol( 15,'Procent','R'); |
|
123 $this->AddCol( 15,'Opbr.','R'); |
|
124 $this->AddCol( 20,'Prijs','R'); |
|
125 |
|
126 $cMargin=$this->cMargin; |
|
127 $this->cMargin=$prop['padding']; |
|
128 $this->TableX=$this->lMargin; |
|
129 $this->TableHeader(); |
|
130 $this->ColorIndex=0; |
|
131 $this->ProcessingTable=true; |
|
132 |
|
133 $this->SetFont('Helvetica','',9); |
|
134 $this->SetFillColor($this->RowColors[0][0],$this->RowColors[0][1],$this->RowColors[0][2]); |
|
135 |
|
136 $arr = json_decode($row['json_fermentables'], true); |
|
137 foreach($arr as $item) { //foreach element in $arr |
|
138 $name = $item['f_name']; |
|
139 $supplier = $item['f_supplier']; |
|
140 $amount = floatval($item['f_amount']); |
|
141 $costkg = floatval($item['f_cost']); |
|
142 $yield = floatval($item['f_yield']); |
|
143 $color = floatval($item['f_color']); |
|
144 $percent = floatval($item['f_percentage']); |
|
145 if ($item['f_added'] == "Boil") |
|
146 $add = "Koken"; |
|
147 else if ($item['f_added'] == "Mash") |
|
148 $add = "Maisch"; |
|
149 else |
|
150 $add = $item['f_added']; |
|
151 $cost = $amount * $costkg; |
|
152 $this->Cell($vul,5,$name,0,0,'L',true); |
|
153 $this->Cell(30,5,$supplier,0,0,'L',true); |
|
154 $this->Cell(15,5,sprintf("%.0f",$color),0,0,'R',true); |
|
155 $this->Cell(15,5,$add,0,0,'L',true); |
|
156 $this->Cell(20,5,sprintf("%8.3f",$amount),0,0,'R',true); |
|
157 $this->Cell(15,5,sprintf("%.1f%%",$percent),0,0,'R',true); |
|
158 $this->Cell(15,5,sprintf("%.1f%%",$yield),0,0,'R',true); |
|
159 $this->Cell(20,5,sprintf("%8.3f",$cost).EURO,0,0,'R',true); |
|
160 $this->Ln(); |
|
161 } |
|
162 |
|
163 $this->ProcessingTable=false; |
|
164 $this->cMargin=$cMargin; |
|
165 $this->aCols=array(); |
|
166 } |
|
167 } |
|
168 |
|
169 |
|
170 |
|
171 class PDF extends PDF_MySQL_Table { |
|
172 function Header() { |
|
173 global $row; |
|
174 $this->Image('images/logo.png',10,6,30); |
|
175 // Title |
|
176 $this->SetFont('Helvetica','B',18); |
|
177 $this->SetX(45); |
|
178 $this->Cell(0,8,$row['name'],1,1,'L'); |
|
179 $this->Ln(20); |
|
180 // Ensure table header is printed |
|
181 parent::Header(); |
|
182 } |
|
183 } |
|
184 |
|
185 |
|
186 /* |
|
187 * Generate PDF from recipe data |
|
188 */ |
|
189 $pdf = new PDF(); |
|
190 $pdf->AddPage(); |
|
191 $prop = array('HeaderColor'=>array(255,150,100), 'color1'=>array(210,245,255), |
|
192 'color2'=>array(255,255,210), 'TotalColor'=>array(255,150,100), 'padding'=>2); |
|
193 $pdf->TableGlobal($row,$prop); |
|
194 $pdf->Ln(10); |
|
195 $pdf->TableFermentables($row,$prop); |
|
196 |
|
197 //$pdf->SetFont('Helvetica','',10); |
|
198 //$pdf->Cell(0,10,'Receptje '.$record,0,1,'C'); |
|
199 |
|
200 $pdf->Output(); |