14 die('Connect Error (' . mysqli_connect_errno() . ') ' . mysqli_connect_error()); |
14 die('Connect Error (' . mysqli_connect_errno() . ') ' . mysqli_connect_error()); |
15 } |
15 } |
16 mysqli_set_charset($db, "utf8" ); |
16 mysqli_set_charset($db, "utf8" ); |
17 |
17 |
18 $brouwhulp = '/home/mbroek/Documents/brouwhulp'; |
18 $brouwhulp = '/home/mbroek/Documents/brouwhulp'; |
|
19 |
|
20 |
|
21 function get_miscs_cost($miscname) { |
|
22 global $db; |
|
23 |
|
24 if ($result = mysqli_query($db, "SELECT cost FROM inventory_miscs WHERE name='$miscname'")) { |
|
25 if ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) { |
|
26 return floatval($row['cost']); |
|
27 } |
|
28 } |
|
29 return 0.0; |
|
30 } |
|
31 |
19 |
32 |
20 |
33 |
21 function do_fermentables() |
34 function do_fermentables() |
22 { |
35 { |
23 global $brouwhulp, $db; |
36 global $brouwhulp, $db; |
475 if ($recipe->EFFICIENCY) |
489 if ($recipe->EFFICIENCY) |
476 $efficiency = floatval($recipe->EFFICIENCY); |
490 $efficiency = floatval($recipe->EFFICIENCY); |
477 $sql .= "', efficiency='" . $efficiency; |
491 $sql .= "', efficiency='" . $efficiency; |
478 /* Don't use $recipe->EST_OG but recalculate it */ |
492 /* Don't use $recipe->EST_OG but recalculate it */ |
479 /* Don't use $recipe->EST_FG but recalculate it */ |
493 /* Don't use $recipe->EST_FG but recalculate it */ |
480 if ($recipe->EST_COLOR) { |
494 /* Don't use $recipe->EST_COLOR but recalculate it */ |
481 $srm = floatval($recipe->EST_COLOR); |
|
482 $ebc = srm_to_ebc($srm); |
|
483 $sql .= "', est_color='" . $ebc; |
|
484 } |
|
485 if ($recipe->COLOR_METHOD) |
495 if ($recipe->COLOR_METHOD) |
486 $sql .= "', color_method='" . mysqli_real_escape_string($db, $recipe->COLOR_METHOD); |
496 $sql .= "', color_method='" . mysqli_real_escape_string($db, $recipe->COLOR_METHOD); |
487 if ($recipe->IBU) |
497 if ($recipe->IBU) |
488 $sql .= "', est_ibu='" . floatval($recipe->IBU); |
498 $sql .= "', est_ibu='" . floatval($recipe->IBU); |
489 if ($recipe->IBU_METHOD) |
499 if ($recipe->IBU_METHOD) |
559 $fermentables .= ',"f_type":"' . $ftype . '"'; |
569 $fermentables .= ',"f_type":"' . $ftype . '"'; |
560 $fyield = floatval($fermentable->YIELD); |
570 $fyield = floatval($fermentable->YIELD); |
561 $fermentables .= ',"f_yield":' . $fyield; |
571 $fermentables .= ',"f_yield":' . $fyield; |
562 if ($fermentable->COLOR) { |
572 if ($fermentable->COLOR) { |
563 $srm = floatval($fermentable->COLOR); |
573 $srm = floatval($fermentable->COLOR); |
|
574 $colorw += ($famount * $srm / $batch_size) * 8.34436; /* Kleurwerking */ |
564 $ebc = srm_to_ebc($srm); |
575 $ebc = srm_to_ebc($srm); |
565 $fermentables .= ',"f_color":' . $ebc; |
576 $fermentables .= ',"f_color":' . $ebc; |
566 } |
577 } |
567 if ($fermentable->COARSE_FINE_DIFF) |
578 if ($fermentable->COARSE_FINE_DIFF) |
568 $fermentables .= ',"f_coarse_fine_diff":' . floatval($fermentable->COARSE_FINE_DIFF); |
579 $fermentables .= ',"f_coarse_fine_diff":' . floatval($fermentable->COARSE_FINE_DIFF); |
682 $comma = FALSE; |
693 $comma = FALSE; |
683 foreach ($recipe->MISCS->MISC as $misc) { |
694 foreach ($recipe->MISCS->MISC as $misc) { |
684 if ($comma) |
695 if ($comma) |
685 $miscs .= ','; |
696 $miscs .= ','; |
686 $comma = TRUE; |
697 $comma = TRUE; |
687 $miscs .= '{"m_name":"' . mysqli_real_escape_string($db, $misc->NAME) . '"'; |
698 $mname = mysqli_real_escape_string($db, $misc->NAME); |
|
699 $miscs .= '{"m_name":"' . $mname . '"'; |
688 $miscs .= ',"m_amount":' . floatval($misc->AMOUNT); |
700 $miscs .= ',"m_amount":' . floatval($misc->AMOUNT); |
689 if ($misc->COST) |
701 if ($misc->COST) { |
690 $miscs .= ',"m_cost":' . floatval($misc->COST); |
702 $miscs .= ',"m_cost":' . floatval($misc->COST); |
691 else |
703 } else { |
692 $miscs .= ',"m_cost":0'; |
704 /* Brouwhulp bug, added water agents have no cost field. */ |
|
705 if ($misc->TYPE == "Water agent") { |
|
706 $miscs .= ',"m_cost":'. get_miscs_cost($mname); |
|
707 } else { |
|
708 $miscs .= ',"m_cost":0'; |
|
709 } |
|
710 } |
693 $miscs .= ',"m_type":"' . mysqli_real_escape_string($db, $misc->TYPE) . '"'; |
711 $miscs .= ',"m_type":"' . mysqli_real_escape_string($db, $misc->TYPE) . '"'; |
694 $miscs .= ',"m_use_use":"' . mysqli_real_escape_string($db, $misc->USE) . '"'; |
712 $miscs .= ',"m_use_use":"' . mysqli_real_escape_string($db, $misc->USE) . '"'; |
695 ($misc->AMOUNT_IS_WEIGHT== "TRUE") ? $miscs .= ',"m_amount_is_weight":true' : $miscs.= ',"m_amount_is_weight":false'; |
713 ($misc->AMOUNT_IS_WEIGHT== "TRUE") ? $miscs .= ',"m_amount_is_weight":true' : $miscs.= ',"m_amount_is_weight":false'; |
696 if ($misc->TIME) |
714 if ($misc->TIME) |
697 $miscs .= ',"m_time":' . floatval($misc->TIME); |
715 $miscs .= ',"m_time":' . floatval($misc->TIME); |
837 $sql .= "', est_og='" . floatval($og); |
855 $sql .= "', est_og='" . floatval($og); |
838 $fg = estimate_fg($pSugar, $pCara, 0, 0, 0, $svg, $og); |
856 $fg = estimate_fg($pSugar, $pCara, 0, 0, 0, $svg, $og); |
839 $sql .= "', est_fg='" . floatval($fg); |
857 $sql .= "', est_fg='" . floatval($fg); |
840 $abv = abvol($og, $fg); |
858 $abv = abvol($og, $fg); |
841 $sql .= "', est_abv='" . floatval($abv); |
859 $sql .= "', est_abv='" . floatval($abv); |
842 |
860 $color = kw_to_ebc(mysqli_real_escape_string($db, $recipe->COLOR_METHOD), $colorw); |
|
861 $sql .= "', est_color='" . floatval($color); |
843 $sql .= "';"; |
862 $sql .= "';"; |
844 if (! $result = mysqli_query($db, $sql)) { |
863 if (! $result = mysqli_query($db, $sql)) { |
845 printf("Error: %s\n", mysqli_error($db)); |
864 printf("Error: %s\n", mysqli_error($db)); |
846 } |
865 } |
847 } |
866 } |