720 return $yeasts; |
720 return $yeasts; |
721 } |
721 } |
722 |
722 |
723 function recipe_waters($recipe, $db) |
723 function recipe_waters($recipe, $db) |
724 { |
724 { |
725 $waters = "["; |
725 $waters = ""; |
726 $comma = FALSE; |
726 $index = 0; |
727 foreach ($recipe->WATERS->WATER as $water) { |
727 foreach ($recipe->WATERS->WATER as $water) { |
728 if ($comma) |
728 $index++; |
729 $waters .= ','; |
729 $waters .= "', w" . $index . "_name='" . mysqli_real_escape_string($db, $water->NAME); |
730 $comma = TRUE; |
730 $waters .= "', w" . $index . "_amount='" . floatval($water->AMOUNT); |
731 $waters .= '{"w_name":"' . mysqli_real_escape_string($db, $water->NAME) . '"'; |
|
732 $waters .= ',"w_amount":' . floatval($water->AMOUNT); |
|
733 if ($water->CALCIUM) |
731 if ($water->CALCIUM) |
734 $waters .= ',"w_calcium":' . floatval($water->CALCIUM); |
732 $waters .= "', w" . $index . "_calcium='" . floatval($water->CALCIUM); |
735 if ($water->SULFATE) |
733 if ($water->SULFATE) |
736 $waters .= ',"w_sulfate":' . floatval($water->SULFATE); |
734 $waters .= "', w" . $index . "_sulfate='" . floatval($water->SULFATE); |
737 if ($water->CHLORIDE) |
735 if ($water->CHLORIDE) |
738 $waters .= ',"w_chloride":' . floatval($water->CHLORIDE); |
736 $waters .= "', w" . $index . "_chloride='" . floatval($water->CHLORIDE); |
739 if ($water->SODIUM) |
737 if ($water->SODIUM) |
740 $waters .= ',"w_sodium":' . floatval($water->SODIUM); |
738 $waters .= "', w" . $index . "_sodium='" . floatval($water->SODIUM); |
741 if ($water->MAGNESIUM) |
739 if ($water->MAGNESIUM) |
742 $waters .= ',"w_magnesium":' . floatval($water->MAGNESIUM); |
740 $waters .= "', w" . $index . "_magnesium='" . floatval($water->MAGNESIUM); |
743 if ($water->PH) |
741 if ($water->PH) |
744 $waters .= ',"w_ph":' . floatval($water->PH); |
742 $waters .= "', w" . $index . "_ph='" . floatval($water->PH); |
745 if ($water->TOTAL_ALKALINITY) |
743 if ($water->TOTAL_ALKALINITY) |
746 $waters .= ',"w_total_alkalinity":' . floatval($water->TOTAL_ALKALINITY); |
744 $waters .= "', w" . $index . "_total_alkalinity='" . floatval($water->TOTAL_ALKALINITY); |
747 if ($water->COST) |
745 if ($water->COST) |
748 $waters .= ',"w_cost":' . floatval($water->COST); |
746 $waters .= "', w" . $index . "_cost='" . floatval($water->COST); |
749 else |
747 else |
750 $waters .= ',"w_cost":0.00'; |
748 $waters .= "', w" . $index . "_cost='0"; |
751 $waters .= "}"; |
749 } |
752 } |
|
753 $waters .= ']'; |
|
754 return $waters; |
750 return $waters; |
755 } |
751 } |
756 |
752 |
757 function recipe_mash_steps($recipe) |
753 function recipe_mash_steps($recipe) |
758 { |
754 { |
790 global $brouwhulp, $db, $efficiency, $batch_size, $pCara, $pSugar, $svg, $colorw, $f_sugars; |
786 global $brouwhulp, $db, $efficiency, $batch_size, $pCara, $pSugar, $svg, $colorw, $f_sugars; |
791 $len_fermentables = 0; |
787 $len_fermentables = 0; |
792 $len_hops = 0; |
788 $len_hops = 0; |
793 $len_miscs = 0; |
789 $len_miscs = 0; |
794 $len_yeasts = 0; |
790 $len_yeasts = 0; |
795 $len_waters = 0; |
|
796 $len_mash = 0; |
791 $len_mash = 0; |
797 |
792 |
798 echo " Start adding recipes to the database\n"; |
793 echo " Start adding recipes to the database\n"; |
799 $sql = "TRUNCATE TABLE recipes;"; |
794 $sql = "TRUNCATE TABLE recipes;"; |
800 if (! $result = mysqli_query($db, $sql)) { |
795 if (! $result = mysqli_query($db, $sql)) { |
911 if (strlen($yeasts) > $len_yeasts) |
906 if (strlen($yeasts) > $len_yeasts) |
912 $len_yeasts = strlen($yeasts); |
907 $len_yeasts = strlen($yeasts); |
913 } |
908 } |
914 |
909 |
915 /* |
910 /* |
916 * Put the waters in a json array |
911 * Get the waters |
917 */ |
912 */ |
918 if ($recipe->WATERS) { |
913 if ($recipe->WATERS) { |
919 $waters = recipe_waters($recipe, $db); |
914 $sql .= recipe_waters($recipe, $db); |
920 $sql .= "', json_waters='" . $waters; |
|
921 if (strlen($waters) > $len_waters) |
|
922 $len_waters = strlen($waters); |
|
923 } |
915 } |
924 |
916 |
925 /* |
917 /* |
926 * Put the mash in a json array |
918 * Put the mash in a json array |
927 */ |
919 */ |
958 } |
950 } |
959 // echo "Fermentables: " . $len_fermentables . PHP_EOL; |
951 // echo "Fermentables: " . $len_fermentables . PHP_EOL; |
960 // echo "Hops: " . $len_hops . PHP_EOL; |
952 // echo "Hops: " . $len_hops . PHP_EOL; |
961 // echo "Miscs: " . $len_miscs . PHP_EOL; |
953 // echo "Miscs: " . $len_miscs . PHP_EOL; |
962 // echo "Yeasts: " . $len_yeasts . PHP_EOL; |
954 // echo "Yeasts: " . $len_yeasts . PHP_EOL; |
963 // echo "Waters: " . $len_waters . PHP_EOL; |
|
964 // echo "Mash: " . $len_mash . PHP_EOL; |
955 // echo "Mash: " . $len_mash . PHP_EOL; |
965 } |
956 } |
966 |
957 |
967 |
958 |
968 |
959 |
971 global $brouwhulp, $db, $efficiency, $batch_size, $pCara, $pSugar, $colorw, $f_sugars; |
962 global $brouwhulp, $db, $efficiency, $batch_size, $pCara, $pSugar, $colorw, $f_sugars; |
972 $len_fermentables = 0; |
963 $len_fermentables = 0; |
973 $len_hops = 0; |
964 $len_hops = 0; |
974 $len_miscs = 0; |
965 $len_miscs = 0; |
975 $len_yeasts = 0; |
966 $len_yeasts = 0; |
976 $len_waters = 0; |
|
977 $len_mash = 0; |
967 $len_mash = 0; |
978 |
968 |
979 echo " Start adding brews to the database\n"; |
969 echo " Start adding brews to the database\n"; |
980 $psql = "TRUNCATE TABLE prod_main;"; |
970 $psql = "TRUNCATE TABLE prod_main;"; |
981 if (! $presult = mysqli_query($db, $psql)) { |
971 if (! $presult = mysqli_query($db, $psql)) { |
1105 if (strlen($yeasts) > $len_yeasts) |
1095 if (strlen($yeasts) > $len_yeasts) |
1106 $len_yeasts = strlen($yeasts); |
1096 $len_yeasts = strlen($yeasts); |
1107 } |
1097 } |
1108 |
1098 |
1109 /* |
1099 /* |
1110 * Put the waters in a json array |
1100 * Get the waters |
1111 */ |
1101 */ |
1112 if ($recipe->WATERS) { |
1102 if ($recipe->WATERS) { |
1113 $waters = recipe_waters($recipe, $db); |
1103 $rsql .= recipe_waters($recipe, $db); |
1114 $rsql .= "', json_waters='" . $waters; |
|
1115 if (strlen($waters) > $len_waters) |
|
1116 $len_waters = strlen($waters); |
|
1117 } |
1104 } |
1118 |
1105 |
1119 /* |
1106 /* |
1120 * Put the mash in a json array |
1107 * Put the mash in a json array |
1121 */ |
1108 */ |