www/upl_recipe.php

changeset 307
75f8b569043c
child 308
a59413ba4057
equal deleted inserted replaced
306:3435646b230e 307:75f8b569043c
1 <?php
2 require_once('config.php');
3 require("version.php");
4 require("includes/formulas.php");
5
6
7 $target_dir = "tmp/";
8 $target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
9 $uploadOk = 1;
10 $imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
11
12 // Check if file already exists
13 if (file_exists($target_file)) {
14 echo "Fout 1: bestand bestaat al. ";
15 $uploadOk = 0;
16 }
17 // Check file size
18 if ($_FILES["fileToUpload"]["size"] > 500000 && $uploadOk) {
19 echo "Fout 2: het bestand is te groot. ";
20 $uploadOk = 0;
21 }
22 // Allow certain file formats
23 if ($imageFileType != "xml" && $uploadOk) {
24 echo "Fout 3: alleen XML bestanden toegestaan. ";
25 $uploadOk = 0;
26 }
27 // Check if $uploadOk is set to 0 by an error
28 if ($uploadOk == 0) {
29 exit;
30 }
31
32 if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
33 echo "Verwerken bestand ". basename( $_FILES["fileToUpload"]["name"]). "<br />";
34 } else {
35 echo "Fout 4: er ging iets fout met de upload.";
36 exit;
37 }
38
39
40 $db = mysqli_connect(DBASE_HOST, DBASE_USER, DBASE_PASS, DBASE_NAME);
41 if (! $db) {
42 echo "Fout 5: ".mysqli_connect_errno()." ".mysqli_connect_error();
43 exit;
44 }
45 mysqli_set_charset($db, "utf8" );
46 date_default_timezone_set('Europe/Amsterdam');
47
48
49 $pCara = 0;
50 $pSugar = 0;
51 $svg = 77;
52 $efficiency = 75;
53 $batch_size = 20;
54 $colorw = 0;
55 $f_sugars = 0;
56
57
58
59 function get_miscs_cost($miscname) {
60 global $db;
61
62 if ($result = mysqli_query($db, "SELECT cost FROM inventory_miscs WHERE name='$miscname'")) {
63 if ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
64 return floatval($row['cost']);
65 }
66 }
67 return 0.0;
68 }
69
70
71
72 function recipe_style($recipe)
73 {
74 global $db;
75
76 if ($recipe->STYLE->NAME)
77 $sql = "', st_name='" . mysqli_real_escape_string($db, $recipe->STYLE->NAME);
78 if ($recipe->STYLE->STYLE_LETTER)
79 $sql .= "', st_letter='" . mysqli_real_escape_string($db, $recipe->STYLE->STYLE_LETTER);
80 if ($recipe->STYLE->STYLE_GUIDE) {
81 if ($recipe->STYLE->STYLE_GUIDE == "Biertypengids Derek Walsh") {
82 $sql .= "', st_guide='BKG 2015";
83 } else if ($recipe->STYLE->STYLE_GUIDE == "BKG Biertypen") {
84 $sql .= "', st_guide='BKG 2015";
85 } else {
86 $sql .= "', st_guide='" . mysqli_real_escape_string($db, $recipe->STYLE->STYLE_GUIDE);
87 }
88 }
89 if ($recipe->STYLE->CATEGORY)
90 $sql .= "', st_category='" . mysqli_real_escape_string($db, $recipe->STYLE->CATEGORY);
91 if ($recipe->STYLE->CATEGORY_NUMBER)
92 $sql .= "', st_category_number='" . floatval($recipe->STYLE->CATEGORY_NUMBER);
93 if ($recipe->STYLE->TYPE == 'Lager')
94 $sql .= "', st_type='0";
95 else if (($recipe->STYLE->TYPE == 'Ale') || ($recipe->STYLE->TYPE == 'Strong Ale'))
96 $sql .= "', st_type='1";
97 else if ($recipe->STYLE->TYPE == 'Mead')
98 $sql .= "', st_type='2";
99 else if ($recipe->STYLE->TYPE == 'Wheat')
100 $sql .= "', st_type='3";
101 else if ($recipe->STYLE->TYPE == 'Mixed')
102 $sql .= "', st_type='4";
103 else if ($recipe->STYLE->TYPE == 'Cider')
104 $sql .= "', st_type='5";
105 else
106 echo "Unknown TYPE " . $recipe->STYLE->TYPE . "<br />";
107
108 if ($recipe->STYLE->OG_MIN)
109 $sql .= "', st_og_min='" . floatval($recipe->STYLE->OG_MIN);
110 if ($recipe->STYLE->OG_MAX)
111 $sql .= "', st_og_max='" . floatval($recipe->STYLE->OG_MAX);
112 if ($recipe->STYLE->FG_MIN)
113 $sql .= "', st_fg_min='" . floatval($recipe->STYLE->FG_MIN);
114 if ($recipe->STYLE->FG_MAX)
115 $sql .= "', st_fg_max='" . floatval($recipe->STYLE->FG_MAX);
116 if ($recipe->STYLE->IBU_MIN)
117 $sql .= "', st_ibu_min='" . floatval($recipe->STYLE->IBU_MIN);
118 if ($recipe->STYLE->IBU_MAX)
119 $sql .= "', st_ibu_max='" . floatval($recipe->STYLE->IBU_MAX);
120 if ($recipe->STYLE->COLOR_MIN) {
121 $srm = floatval($recipe->STYLE->COLOR_MIN);
122 $sql .= "', st_color_min='" . srm_to_ebc($srm);
123 }
124 if ($recipe->STYLE->COLOR_MAX) {
125 $srm = floatval($recipe->STYLE->COLOR_MAX);
126 $sql .= "', st_color_max='" . srm_to_ebc($srm);
127 }
128 if ($recipe->STYLE->CARB_MIN)
129 $sql .= "', st_carb_min='" . floatval($recipe->STYLE->CARB_MIN);
130 if ($recipe->STYLE->CARB_MAX)
131 $sql .= "', st_carb_max='" . floatval($recipe->STYLE->CARB_MAX);
132 if ($recipe->STYLE->ABV_MIN)
133 $sql .= "', st_abv_min='" . floatval($recipe->STYLE->ABV_MIN);
134 if ($recipe->STYLE->ABV_MAX)
135 $sql .= "', st_abv_max='" . floatval($recipe->STYLE->ABV_MAX);
136 return $sql;
137 }
138
139
140
141 function recipe_fermentables($recipe)
142 {
143 global $db;
144 global $pCara;
145 global $pSugar;
146 global $batch_size;
147 global $efficiency;
148 global $colorw;
149 global $f_sugars;
150
151 $fermentables = "[";
152 $comma = FALSE;
153 foreach ($recipe->FERMENTABLES->FERMENTABLE as $fermentable) {
154 if ($comma)
155 $fermentables .= ',';
156 $comma = TRUE;
157 $fermentables .= '{"f_name":"' . mysqli_real_escape_string($db, $fermentable->NAME) . '"';
158 $fermentables .= ',"f_origin":"' . mysqli_real_escape_string($db, $fermentable->ORIGIN) . '"';
159 $fermentables .= ',"f_supplier":"' . mysqli_real_escape_string($db, $fermentable->SUPPLIER) . '"';
160 $famount = floatval($fermentable->AMOUNT);
161 $fermentables .= ',"f_amount":' . $famount;
162 $fermentables .= ',"f_cost":' . floatval($fermentable->COST);
163
164 if ($fermentable->TYPE == 'Grain')
165 $fermentables .= ',"f_type":0';
166 else if ($fermentable->TYPE == 'Sugar')
167 $fermentables .= ',"f_type":1';
168 else if ($fermentable->TYPE == 'Extract')
169 $fermentables .= ',"f_type":2';
170 else if ($fermentable->TYPE == 'Dry extract')
171 $fermentables .= ',"f_type":3';
172 else if ($fermentable->TYPE == 'Adjunct')
173 $fermentables .= ',"f_type":4';
174 else
175 echo "Unknown TYPE " . $fermentable->TYPE . "<br / >";
176
177 $fyield = floatval($fermentable->YIELD);
178 $fermentables .= ',"f_yield":' . $fyield;
179 if ($fermentable->COLOR) {
180 $srm = floatval($fermentable->COLOR);
181 $ebc = srm_to_ebc($srm);
182 } else {
183 $srm = 0;
184 $ebc = 0;
185 }
186 $colorw += ($famount * $srm / $batch_size) * 8.34436; /* Kleurwerking */
187 $fermentables .= ',"f_color":' . $ebc;
188 if ($fermentable->COARSE_FINE_DIFF)
189 $fermentables .= ',"f_coarse_fine_diff":' . floatval($fermentable->COARSE_FINE_DIFF);
190 else
191 $fermentables .= ',"f_coarse_fine_diff":0';
192 if ($fermentable->MOISTURE)
193 $fmoisture = floatval($fermentable->MOISTURE);
194 else
195 $fmoisture = 0;
196 $fermentables .= ',"f_moisture":' . $fmoisture;
197 if ($fermentable->DIASTATIC_POWER)
198 $fermentables .= ',"f_diastatic_power":' . floatval($fermentable->DIASTATIC_POWER);
199 else
200 $fermentables .= ',"f_diastatic_power":0';
201 if ($fermentable->PROTEIN)
202 $fermentables .= ',"f_protein":' . floatval($fermentable->PROTEIN);
203 else
204 $fermentables .= ',"f_protein":0';
205 if ($fermentable->MAX_IN_BATCH)
206 $fermentables .= ',"f_max_in_batch":' . floatval($fermentable->MAX_IN_BATCH);
207 else
208 $fermentables .= ',"f_max_in_batch":100.0';
209
210 if ($fermentable->GRAINTYPE == 'Roast')
211 $fermentables .= ',"f_graintype":1';
212 else if ($fermentable->GRAINTYPE == 'Crystal')
213 $fermentables .= ',"f_graintype":2';
214 else if ($fermentable->GRAINTYPE == 'Kilned')
215 $fermentables .= ',"f_graintype":3';
216 else if ($fermentable->GRAINTYPE == 'Sour malt')
217 $fermentables .= ',"f_graintype":4';
218 else if ($fermentable->GRAINTYPE == 'Special')
219 $fermentables .= ',"f_graintype":5';
220 else if ($fermentable->GRAINTYPE == 'No malt')
221 $fermentables .= ',"f_graintype":6';
222 else
223 $fermentables .= ',"f_graintype":0'; // Base, default
224
225 if ($fermentable->ADDED == 'Boil')
226 $fermentables .= ',"f_added":1';
227 else if ($fermentable->ADDED == 'Fermentation')
228 $fermentables .= ',"f_added":2';
229 else if ($fermentable->ADDED == 'Lagering')
230 $fermentables .= ',"f_added":3';
231 else if ($fermentable->ADDED == 'Bottle')
232 $fermentables .= ',"f_added":4';
233 else
234 $fermentables .= ',"f_added":0'; // Mash, default.
235
236 ($fermentable->ADD_AFTER_BOIL== "TRUE") ? $fermentables .= ',"f_add_after_boil":1' : $fermentables .= ',"f_add_after_boil":0';
237 ($fermentable->RECOMMEND_MASH== "TRUE") ? $fermentables .= ',"f_recommend_mash":1' : $fermentables .= ',"f_recommend_mash":0';
238 if ($fermentable->DISSOLVED_PROTEIN)
239 $fermentables .= ',"f_dissolved_protein":' . floatval($fermentable->DISSOLVED_PROTEIN);
240 else
241 $fermentables .= ',"f_dissolved_protein":0';
242 ($fermentable->ADJUST_TO_TOTAL_100 == "TRUE") ? $fermentables .= ',"f_adjust_to_total_100":1' : $fermentables .= ',"f_adjust_to_total_100":0';
243 $percent = floatval($fermentable->PERCENTAGE);
244 $fermentables .= ',"f_percentage":' . round($percent * 10) / 10.0;
245 if ($fermentable->DI_pH)
246 $fermentables .= ',"f_di_ph":' . floatval($fermentable->DI_pH);
247 else
248 $fermentables .= ',"f_di_ph":0.0';
249 if ($fermentable->{'ACID_TO_pH_5.7'})
250 $fermentables .= ',"f_acid_to_ph_57":' . floatval($fermentable->{'ACID_TO_pH_5.7'});
251 else
252 $fermentables .= ',"f_acid_to_ph_57":0.0';
253 $fermentables .= "}";
254
255 /* Sugars */
256 $d = $famount * ($fyield / 100) * (1 - $fmoisture / 100);
257 if ($fermentable->ADDED == 'Mash')
258 $d = floatval($efficiency) / 100 * $d;
259 $f_sugars += $d;
260 if ($fermentable->GRAINTYPE == 'Crystal')
261 $pCara += $percent;
262 if ($fermentable->TYPE == 'Sugar')
263 $pSugar += $percent;
264 }
265 $fermentables .= ']';
266 return $fermentables;
267 }
268
269
270
271 function recipe_hops($recipe)
272 {
273 global $db;
274
275 $hops = "[";
276 $comma = FALSE;
277 foreach ($recipe->HOPS->HOP as $hop) {
278 if ($comma)
279 $hops .= ',';
280 $comma = TRUE;
281 $hops .= '{"h_name":"' . mysqli_real_escape_string($db, $hop->NAME) . '"';
282 $hops .= ',"h_amount":' . floatval($hop->AMOUNT);
283 $hops .= ',"h_cost":' . floatval($hop->COST);
284
285 if ($hop->TYPE == 'Aroma')
286 $hops .= ',"h_type":1';
287 else if ($hop->TYPE == 'Both')
288 $hops .= ',"h_type":2';
289 else
290 $hops .= ',"h_type":0'; // Default bittering
291
292 if ($hop->FORM == 'Pellet')
293 $hops .= ',"h_form":0';
294 else if ($hop->FORM == 'Plug')
295 $hops .= ',"h_form":1';
296 else
297 $hops .= ',"h_form":2'; // Default.
298
299 if ($hop->USE == 'Mash')
300 $hops .= ',"h_useat":0';
301 else if (($hop->USE == 'First wort') || ($hop->USE == 'First Wort'))
302 $hops .= ',"h_useat":1';
303 else if ($hop->USE == 'Aroma')
304 $hops .= ',"h_useat":3';
305 else if ($hop->USE == 'Whirlpool')
306 $hops .= ',"h_useat":4';
307 else if (($hop->USE == 'Dry hop') || ($hop->USE == 'Dry Hop'))
308 $hops .= ',"h_useat":5';
309 else
310 $hops .= ',"h_useat":2'; // Default boil.
311
312 if ($hop->TIME)
313 $hops .= ',"h_time":' . floatval($hop->TIME);
314 else
315 $hops .= ',"h_time":0';
316 $hops .= ',"h_alpha":' . floatval($hop->ALPHA);
317 $hops .= ',"h_beta":' . floatval($hop->BETA);
318 $hops .= ',"h_hsi":' . floatval($hop->HSI);
319 $hops .= ',"h_humulene":' . floatval($hop->HUMULENE);
320 $hops .= ',"h_caryophyllene":' . floatval($hop->CAROPHYLLENE);
321 $hops .= ',"h_cohumulone":' . floatval($hop->COHUMULONE);
322 $hops .= ',"h_myrcene":' . floatval($hop->MYRCENE);
323 if ($hop->TOTAL_OIL)
324 $hops .= ',"h_total_oil":' . floatval($hop->TOTAL_OIL);
325 else
326 $hops .= ',"h_total_oil":0';
327 if ($hop->ORIGIN)
328 $hops .= ',"h_origin":"' . mysqli_real_escape_string($db, $hop->ORIGIN) . '"';
329 else
330 $hops .= ',"h_origin":""';
331 $hops .= "}";
332 }
333 $hops .= ']';
334 return $hops;
335 }
336
337
338
339 function recipe_miscs($recipe)
340 {
341 global $db;
342
343 $miscs = "[";
344 $comma = FALSE;
345 foreach ($recipe->MISCS->MISC as $misc) {
346 if ($comma)
347 $miscs .= ',';
348 $comma = TRUE;
349 $mname = mysqli_real_escape_string($db, $misc->NAME);
350 $miscs .= '{"m_name":"' . $mname . '"';
351 $miscs .= ',"m_amount":' . floatval($misc->AMOUNT);
352 if ($misc->COST) {
353 $miscs .= ',"m_cost":' . floatval($misc->COST);
354 } else {
355 /* Brouwhulp bug, added water agents have no cost field. */
356 if ($misc->TYPE == "Water agent") {
357 $miscs .= ',"m_cost":'. get_miscs_cost($mname);
358 } else {
359 $miscs .= ',"m_cost":0';
360 }
361 }
362
363 if ($misc->TYPE == 'Spice')
364 $miscs .= ',"m_type":0';
365 else if ($misc->TYPE == 'Herb')
366 $miscs .= ',"m_type":1';
367 else if ($misc->TYPE == 'Flavor')
368 $miscs .= ',"m_type":2';
369 else if ($misc->TYPE == 'Fining')
370 $miscs .= ',"m_type":3';
371 else if (($misc->TYPE == 'Water agent') || ($misc->TYPE == 'Water Agent'))
372 $miscs .= ',"m_type":4';
373 else if ($misc->TYPE == 'Yeast nutrient')
374 $miscs .= ',"m_type":5';
375 else if ($misc->TYPE == 'Other')
376 $miscs .= ',"m_type":6';
377 else
378 echo "Unknown TYPE " . $misc->TYPE . "<br />";
379
380 if ($misc->USE == 'Starter')
381 $miscs .= ',"m_use_use":0';
382 else if ($misc->USE == 'Mash')
383 $miscs .= ',"m_use_use":1';
384 else if ($misc->USE == 'Primary')
385 $miscs .= ',"m_use_use":3';
386 else if ($misc->USE == 'Secondary')
387 $miscs .= ',"m_use_use":4';
388 else if ($misc->USE == 'Bottling')
389 $miscs .= ',"m_use_use":5';
390 else
391 $miscs .= ',"m_use_use":2'; // Default boil. BrewFather defines 'Sparge', we don't support this even if it's a nice idea.
392
393 ($misc->AMOUNT_IS_WEIGHT== "TRUE") ? $miscs .= ',"m_amount_is_weight":1' : $miscs.= ',"m_amount_is_weight":0';
394 if ($misc->TIME) {
395 $miscs .= ',"m_time":' . floatval($misc->TIME);
396 } else
397 $miscs .= ',"m_time":0';
398 $miscs .= "}";
399 }
400 $miscs .= ']';
401 return $miscs;
402 }
403
404
405
406 function recipe_yeasts($recipe)
407 {
408 global $db;
409 global $svg;
410
411 $yeasts = "[";
412 $comma = FALSE;
413 foreach ($recipe->YEASTS->YEAST as $yeast) {
414 if ($comma)
415 $yeasts .= ',';
416 $comma = TRUE;
417 $yeasts .= '{"y_name":"' . mysqli_real_escape_string($db, $yeast->NAME) . '"';
418 if ($yeast->FORM == "Liquid") {
419 $paks = floatval($yeast->AMOUNT) / 0.0588;
420 $yeasts .= ',"y_amount":' . $paks;
421 $yeasts .= ',"y_cost":' . floatval($yeast->COST);
422 } else {
423 $yeasts .= ',"y_amount":' . floatval($yeast->AMOUNT);
424 $yeasts .= ',"y_cost":' . floatval($yeast->COST) * 1000;
425 }
426
427 $yeasts .= ',"y_laboratory":"' . mysqli_real_escape_string($db, $yeast->LABORATORY) . '"';
428 $yeasts .= ',"y_product_id":"' . mysqli_real_escape_string($db, $yeast->PRODUCT_ID) . '"';
429
430 if ($yeast->TYPE == 'Lager')
431 $yeasts .= ',"y_type":0';
432 else if ($yeast->TYPE == 'Ale')
433 $yeasts .= ',"y_type":1';
434 else if ($yeast->TYPE == 'Wheat')
435 $yeasts .= ',"y_type":2';
436 else if ($yeast->TYPE == 'Wine')
437 $yeasts .= ',"y_type":3';
438 else if ($yeast->TYPE == 'Champagne')
439 $yeasts .= ',"y_type":4';
440 else
441 echo "Unknown TYPE " . $yeast->TYPE . "<br />";
442
443 if ($yeast->FORM == 'Liquid') {
444 if ($yeast->LABORATORY == 'Imperial Yeast')
445 $yeasts .= ',"y_form":0,"y_cells":200000000000';
446 else
447 $yeasts .= ',"y_form":0,"y_cells":100000000000';
448 } else if ($yeast->FORM == 'Dry')
449 $yeasts .= ',"y_form":1,"y_cells":15000000000';
450 else if ($yeast->FORM == 'Slant')
451 $yeasts .= ',"y_form":2,"y_cells":1700000000';
452 else if ($yeast->FORM == 'Culture')
453 $yeasts .= ',"y_form":3,"y_cells":1700000000';
454 else if ($yeast->FORM == 'Frozen')
455 $yeasts .= ',"y_form":4,"y_cells":1700000000';
456 else if ($yeast->FORM == 'Bottle')
457 $yeasts .= ',"y_form":5,"y_cells":1700000000';
458 else
459 echo "Unknown FORM " . $yeast->FORM . "<br />";
460
461 if ($yeast->FLOCCULATION == 'Medium')
462 $yeasts .= ',"y_flocculation":1';
463 else if ($yeast->FLOCCULATION == 'High')
464 $yeasts .= ',"y_flocculation":2';
465 else if ($yeast->FLOCCULATION == 'Very high')
466 $yeasts .= ',"y_flocculation":3';
467 else
468 $yeasts .= ',"y_flocculation":0'; // Low, default.
469
470 if ($yeast->PRODUCT_ID=="F2" || $yeast->PRODUCT_ID=="CBC-1") {
471 $yeasts .= ',"y_use":3'; // Bottle
472 } else if ($yeast->ADD_TO_SECONDARY=="TRUE") {
473 $yeasts .= ',"y_use":1'; // Secondary
474 } else {
475 $yeasts .= ',"y_use":0'; // Primary
476 $svg = floatval($yeast->ATTENUATION);
477 }
478 $yeasts .= ',"y_min_temperature":' . floatval($yeast->MIN_TEMPERATURE);
479 $yeasts .= ',"y_max_temperature":' . floatval($yeast->MAX_TEMPERATURE);
480 $yeasts .= ',"y_attenuation":' . floatval($yeast->ATTENUATION);
481 $yeasts .= "}";
482 }
483 $yeasts .= ']';
484 return $yeasts;
485 }
486
487
488
489 function recipe_waters($recipe, $db)
490 {
491 $waters = "";
492 $index = 0;
493 foreach ($recipe->WATERS->WATER as $water) {
494 $index++;
495 $waters .= "', w" . $index . "_name='" . mysqli_real_escape_string($db, $water->NAME);
496 $waters .= "', w" . $index . "_amount='" . floatval($water->AMOUNT);
497 if ($water->CALCIUM)
498 $waters .= "', w" . $index . "_calcium='" . floatval($water->CALCIUM);
499 if ($water->SULFATE)
500 $waters .= "', w" . $index . "_sulfate='" . floatval($water->SULFATE);
501 if ($water->CHLORIDE)
502 $waters .= "', w" . $index . "_chloride='" . floatval($water->CHLORIDE);
503 if ($water->SODIUM)
504 $waters .= "', w" . $index . "_sodium='" . floatval($water->SODIUM);
505 if ($water->MAGNESIUM)
506 $waters .= "', w" . $index . "_magnesium='" . floatval($water->MAGNESIUM);
507 if ($water->PH)
508 $waters .= "', w" . $index . "_ph='" . floatval($water->PH);
509 if ($water->TOTAL_ALKALINITY)
510 $waters .= "', w" . $index . "_total_alkalinity='" . floatval($water->TOTAL_ALKALINITY);
511 if ($water->COST)
512 $waters .= "', w" . $index . "_cost='" . floatval($water->COST);
513 else
514 $waters .= "', w" . $index . "_cost='0";
515 }
516 return $waters;
517 }
518
519
520
521 function recipe_mash_steps($recipe)
522 {
523 global $db;
524
525 $steps = '[';
526 $comma = FALSE;
527 foreach ($recipe->MASH->MASH_STEPS->MASH_STEP as $step) {
528 if ($comma)
529 $steps .= ',';
530 $comma = TRUE;
531 $steps .= '{"step_name":"' . mysqli_real_escape_string($db, $step->NAME) . '"';
532
533 if ($step->TYPE == 'Infusion')
534 $steps .= ',"step_type":0';
535 else if ($step->TYPE == 'Temperature')
536 $steps .= ',"step_type":1';
537 else if ($step->TYPE == 'Decoction')
538 $steps .= ',"step_type":2';
539 else
540 echo "Unknown step TYPE " . $step->TYPE . "<br />";
541
542 if ($step->INFUSE_AMOUNT)
543 $steps .= ',"step_infuse_amount":' . floatval($step->INFUSE_AMOUNT);
544 else
545 $steps .= ',"step_infuse_amount":0';
546 if ($step->STEP_TEMP)
547 $steps .= ',"step_temp":' . floatval($step->STEP_TEMP);
548 if ($step->STEP_TIME)
549 $steps .= ',"step_time":' . floatval($step->STEP_TIME);
550 if ($step->RAMP_TIME)
551 $steps .= ',"ramp_time":' . floatval($step->RAMP_TIME);
552 if ($step->END_TEMP)
553 $steps .= ',"end_temp":' . floatval($step->END_TEMP);
554 $steps .= "}";
555 }
556 $steps .= ']';
557 return $steps;
558 }
559
560
561 $imported = 0;
562 $recipes = simplexml_load_file($target_file);
563 foreach ($recipes->RECIPE as $recipe) {
564 $f_sugars = 0;
565 $efficiency = 75;
566 $batch_size = 20;
567 $boil_size = 22;
568 $pCara = 0;
569 $pSugar = 0;
570 $svg = 77;
571 $colorw = 0;
572 $uuid = str_replace("\n", "", file_get_contents('/proc/sys/kernel/random/uuid'));
573
574 $sql = "INSERT INTO recipes SET uuid='" . $uuid;
575 $sql .= "', name='" . mysqli_real_escape_string($db, $recipe->NAME);
576 $sql .= "', locked='0";
577 if ($recipe->NOTES)
578 $sql .= "', notes='" . mysqli_real_escape_string($db, $recipe->NOTES);
579 else
580 $sql .= "', notes='";
581
582 if ($recipe->TYPE == 'Extract')
583 $sql .= "', type='0";
584 else if ($recipe->TYPE == 'Partial Mash')
585 $sql .= "', type='1";
586 else if ($recipe->TYPE == 'All Grain')
587 $sql .= "', type='2";
588 else
589 echo "Unknown TYPE " . $recipe->TYPE . "<br />";
590
591 if ($recipe->BATCH_SIZE)
592 $batch_size = floatval($recipe->BATCH_SIZE);
593 $sql .= "', batch_size='" . $batch_size;
594 if ($recipe->BOIL_SIZE)
595 $boil_size = floatval($recipe->BOIL_SIZE);
596 $sql .= "', boil_size='" . $boil_size;
597 if ($recipe->BOIL_TIME)
598 $sql .= "', boil_time='" . floatval($recipe->BOIL_TIME);
599 else
600 $sql .= "', boil_time='90";
601 if ($recipe->EFFICIENCY)
602 $efficiency = floatval($recipe->EFFICIENCY);
603 $sql .= "', efficiency='" . $efficiency;
604
605 $color_method = 0; // Morey
606 if ($recipe->COLOR_METHOD == 'Mosher') {
607 $color_method = 1;
608 } else if ($recipe->COLOR_METHOD == 'Daniels') {
609 $color_method = 2;
610 }
611 $sql .= "', color_method='" . $color_method;;
612
613
614 if ($recipe->IBU)
615 $sql .= "', est_ibu='" . floatval($recipe->IBU);
616 if ($recipe->IBU_METHOD == 'Rager')
617 $sql .= "', ibu_method='1";
618 else if ($recipe->IBU_METHOD == 'Daniels')
619 $sql .= "', ibu_method='2";
620 else
621 $sql .= "', ibu_method='0"; // Tinseth, default
622
623 if ($recipe->CARBONATION)
624 $sql .= "', est_carb='" . floatval($recipe->CARBONATION);
625
626 if ($recipe->STYLE) {
627 $sql .= recipe_style($recipe);
628 }
629 if ($recipe->CALC_ACID) {
630 ($recipe->CALC_ACID == "TRUE") ? $sql .= "', calc_acid='1" : $sql .= "', calc_acid='0";
631 }
632 if ($recipe->TARGET_PH) {
633 $sql .= "', mash_ph='" . floatval($recipe->TARGET_PH);
634 }
635 if ($recipe->SPARGE_ACID_TYPE && ($recipe->SPARGE_ACID_TYPE == "Lactic")) {
636 $sql .= "', sparge_acid_type='0";
637 } else if ($recipe->SPARGE_ACID_TYPE && ($recipe->SPARGE_ACID_TYPE == "Hydrochloric")) {
638 $sql .= "', sparge_acid_type='1";
639 } else if ($recipe->SPARGE_ACID_TYPE && ($recipe->SPARGE_ACID_TYPE == "Phosphoric")) {
640 $sql .= "', sparge_acid_type='2";
641 } else if ($recipe->SPARGE_ACID_TYPE && ($recipe->SPARGE_ACID_TYPE == "Sulfuric")) {
642 $sql .= "', sparge_acid_type='3";
643 }
644 if ($recipe->ACID_SPARGE_PERC) {
645 $sql .= "', sparge_acid_perc='" . floatval($recipe->ACID_SPARGE_PERC);
646 }
647 if ($recipe->LACTIC_SPARGE) {
648 $sql .= "', sparge_acid_amount='" . floatval($recipe->LACTIC_SPARGE);
649 }
650 if ($recipe->VOLUME_HLT) {
651 $sql .= "', sparge_volume='" . floatval($recipe->VOLUME_HLT);
652 }
653 $sql .= "', sparge_source='0";
654
655 /*
656 * Put all ingredients in json arrays
657 */
658 if ($recipe->FERMENTABLES)
659 $sql .= "', json_fermentables='" . recipe_fermentables($recipe);
660 if ($recipe->HOPS)
661 $sql .= "', json_hops='" . recipe_hops($recipe);
662 if ($recipe->MISCS)
663 $sql .= "', json_miscs='" . recipe_miscs($recipe);
664 if ($recipe->YEASTS)
665 $sql .= "', json_yeasts='" . recipe_yeasts($recipe);
666 if ($recipe->WATERS)
667 $sql .= recipe_waters($recipe, $db);
668 if ($recipe->MASH) {
669 $sql .= "',sparge_temp='" . floatval($recipe->MASH->SPARGE_TEMP);
670 $sql .= "',sparge_ph='" . floatval($recipe->MASH->PH);
671 if ($recipe->MASH->NAME)
672 $sql .= "',mash_name='" . mysqli_real_escape_string($db, $recipe->MASH->NAME);
673 if ($recipe->MASH->MASH_STEPS)
674 $sql .= "', json_mashs='" . recipe_mash_steps($recipe);
675 }
676
677 /*
678 * Added the calculated values
679 * OG, FG, color, IBU
680 */
681 $og = estimate_sg($f_sugars, $batch_size);
682 $sql .= "', est_og='" . floatval($og);
683 $fg = estimate_fg($pSugar, $pCara, 0, 0, 0, $svg, $og);
684 $sql .= "', est_fg='" . floatval($fg);
685 $abv = abvol($og, $fg);
686 $sql .= "', est_abv='" . floatval($abv);
687 $color = kw_to_ebc($color_method, $colorw);
688 $sql .= "', est_color='" . floatval($color);
689 $sql .= "';";
690 if (! $result = mysqli_query($db, $sql)) {
691 echo "Fout 6: " . mysqli_error($db) . "<br />";
692 syslog(LOG_NOTICE, "upl_recipe: result: ".mysqli_error($db));
693 } else {
694 echo "Recept `" . $recipe->NAME . "' toegevoegd<br />";
695 $lastid = mysqli_insert_id($db);
696 syslog(LOG_NOTICE, "upl_recipe: inserted record ".$lastid);
697 }
698 $imported++;
699 }
700 if ($imported == 0) {
701 echo "Fout 7: geen recepten in dit bestand.<br />";
702 }
703
704
705 // Don't clutter the upload directory.
706 unlink($target_file);
707
708 ?>

mercurial