www/import/from_brouwhulp.php

changeset 151
2c9cfe2f0860
parent 150
159d7a89fcef
child 152
2e4249add363
equal deleted inserted replaced
150:159d7a89fcef 151:2c9cfe2f0860
972 $len_miscs = 0; 972 $len_miscs = 0;
973 $len_yeasts = 0; 973 $len_yeasts = 0;
974 $len_mash = 0; 974 $len_mash = 0;
975 975
976 echo " Start adding brews to the database\n"; 976 echo " Start adding brews to the database\n";
977 $psql = "TRUNCATE TABLE prod_main;"; 977 $sql = "TRUNCATE TABLE products;";
978 if (! $presult = mysqli_query($db, $psql)) { 978 if (! $presult = mysqli_query($db, $sql)) {
979 printf("Error: %s\n", mysqli_error($db)); 979 printf("Error: %s\n", mysqli_error($db));
980 }
981 $rsql = "TRUNCATE TABLE prod_recipes;";
982 if (! $rresult = mysqli_query($db, $rsql)) {
983 printf("Error: %s\n", mysqli_error($db));
984 } 980 }
985 981
986 date_default_timezone_set('Europe/Amsterdam'); 982 date_default_timezone_set('Europe/Amsterdam');
987 $recipes = simplexml_load_file($brouwhulp . '/brews.xml'); 983 $recipes = simplexml_load_file($brouwhulp . '/brews.xml');
988 984
997 $colorw = 0; 993 $colorw = 0;
998 $stageno = 0; 994 $stageno = 0;
999 $stage = "Plan"; // Default value. 995 $stage = "Plan"; // Default value.
1000 $uuid = str_replace("\n", "", file_get_contents('/proc/sys/kernel/random/uuid')); 996 $uuid = str_replace("\n", "", file_get_contents('/proc/sys/kernel/random/uuid'));
1001 997
1002 $psql = "INSERT INTO prod_main SET puuid='" . $uuid; // So we can link the records. 998 $sql = "INSERT INTO products SET uuid='" . $uuid;
1003 $rsql = "INSERT INTO prod_recipes SET uuid='" . $uuid; 999 $sql .= "', name='" . mysqli_real_escape_string($db, $recipe->NAME);
1004
1005 $psql .= "', pname='" . mysqli_real_escape_string($db, $recipe->NAME);
1006 $rsql .= "', name='" . mysqli_real_escape_string($db, $recipe->NAME);
1007 1000
1008 if ($recipe->NOTES) { 1001 if ($recipe->NOTES) {
1009 $rsql .= "', notes='" . mysqli_real_escape_string($db, $recipe->NOTES); // Duplicate the notes 1002 $sql .= "', notes='" . mysqli_real_escape_string($db, $recipe->NOTES);
1010 $psql .= "', pnotes='" . mysqli_real_escape_string($db, $recipe->NOTES);
1011 } else { 1003 } else {
1012 $rsql .= "', notes='"; 1004 $sql .= "', notes='";
1013 $psql .= "', pnotes='";
1014 } 1005 }
1015 if ($recipe->TYPE) 1006 if ($recipe->TYPE)
1016 $rsql .= "', type='" . mysqli_real_escape_string($db, $recipe->TYPE); 1007 $sql .= "', type='" . mysqli_real_escape_string($db, $recipe->TYPE);
1017 else 1008 else
1018 $rsql .= "', type='"; 1009 $sql .= "', type='";
1019 if ($recipe->BATCH_SIZE) 1010 if ($recipe->BATCH_SIZE)
1020 $batch_size = floatval($recipe->BATCH_SIZE); 1011 $batch_size = floatval($recipe->BATCH_SIZE);
1021 $rsql .= "', batch_size='" . $batch_size; 1012 $sql .= "', batch_size='" . $batch_size;
1022 if ($recipe->BOIL_SIZE) 1013 if ($recipe->BOIL_SIZE)
1023 $boil_size = floatval($recipe->BOIL_SIZE); 1014 $boil_size = floatval($recipe->BOIL_SIZE);
1024 $rsql .= "', boil_size='" . $boil_size; 1015 $sql .= "', boil_size='" . $boil_size;
1025 if ($recipe->BOIL_TIME) 1016 if ($recipe->BOIL_TIME)
1026 $rsql .= "', boil_time='" . floatval($recipe->BOIL_TIME); 1017 $sql .= "', boil_time='" . floatval($recipe->BOIL_TIME);
1027 else 1018 else
1028 $rsql .= "', boil_time='90"; 1019 $sql .= "', boil_time='90";
1029 if ($recipe->EFFICIENCY) 1020 if ($recipe->EFFICIENCY)
1030 $efficiency = floatval($recipe->EFFICIENCY); 1021 $efficiency = floatval($recipe->EFFICIENCY);
1031 $rsql .= "', efficiency='" . $efficiency; 1022 $sql .= "', efficiency='" . $efficiency;
1032 /* Don't use $recipe->EST_OG but recalculate it */ 1023 /* Don't use $recipe->EST_OG but recalculate it */
1033 /* Don't use $recipe->EST_FG but recalculate it */ 1024 /* Don't use $recipe->EST_FG but recalculate it */
1034 /* Don't use $recipe->EST_COLOR but recalculate it */ 1025 /* Don't use $recipe->EST_COLOR but recalculate it */
1035 if ($recipe->COLOR_METHOD) 1026 if ($recipe->COLOR_METHOD)
1036 $rsql .= "', color_method='" . mysqli_real_escape_string($db, $recipe->COLOR_METHOD); 1027 $sql .= "', color_method='" . mysqli_real_escape_string($db, $recipe->COLOR_METHOD);
1037 if ($recipe->IBU) 1028 if ($recipe->IBU)
1038 $rsql .= "', est_ibu='" . floatval($recipe->IBU); 1029 $sql .= "', est_ibu='" . floatval($recipe->IBU);
1039 if ($recipe->IBU_METHOD) 1030 if ($recipe->IBU_METHOD)
1040 $rsql .= "', ibu_method='" . mysqli_real_escape_string($db, $recipe->IBU_METHOD); 1031 $sql .= "', ibu_method='" . mysqli_real_escape_string($db, $recipe->IBU_METHOD);
1041 if ($recipe->CARBONATION) 1032 if ($recipe->CARBONATION)
1042 $rsql .= "', est_carb='" . floatval($recipe->CARBONATION); 1033 $sql .= "', est_carb='" . floatval($recipe->CARBONATION);
1043 1034
1044 if ($recipe->STYLE) { 1035 if ($recipe->STYLE) {
1045 $rsql .= recipe_style($recipe); 1036 $sql .= recipe_style($recipe);
1046 } 1037 }
1047 1038
1048 if ($recipe->CALC_ACID) { 1039 if ($recipe->CALC_ACID) {
1049 ($recipe->CALC_ACID == "TRUE") ? $rsql .= "', calc_acid='1" : $rsql .= "', calc_acid='0"; 1040 ($recipe->CALC_ACID == "TRUE") ? $sql .= "', calc_acid='1" : $sql .= "', calc_acid='0";
1050 } 1041 }
1051 if ($recipe->TARGET_PH) { 1042 if ($recipe->TARGET_PH) {
1052 $rsql .= "', mash_ph='" . floatval($recipe->TARGET_PH); 1043 $sql .= "', mash_ph='" . floatval($recipe->TARGET_PH);
1053 } 1044 }
1054 if ($recipe->SPARGE_ACID_TYPE && ($recipe->SPARGE_ACID_TYPE == "Lactic")) { 1045 if ($recipe->SPARGE_ACID_TYPE && ($recipe->SPARGE_ACID_TYPE == "Lactic")) {
1055 $rsql .= "', sparge_acid_type='Melkzuur"; 1046 $sql .= "', sparge_acid_type='Melkzuur";
1056 } else if ($recipe->SPARGE_ACID_TYPE && ($recipe->SPARGE_ACID_TYPE == "Hydrochloric")) { 1047 } else if ($recipe->SPARGE_ACID_TYPE && ($recipe->SPARGE_ACID_TYPE == "Hydrochloric")) {
1057 $rsql .= "', sparge_acid_type='Zoutzuur"; 1048 $sql .= "', sparge_acid_type='Zoutzuur";
1058 } else if ($recipe->SPARGE_ACID_TYPE && ($recipe->SPARGE_ACID_TYPE == "Phosphoric")) { 1049 } else if ($recipe->SPARGE_ACID_TYPE && ($recipe->SPARGE_ACID_TYPE == "Phosphoric")) {
1059 $rsql .= "', sparge_acid_type='Fosforzuur"; 1050 $sql .= "', sparge_acid_type='Fosforzuur";
1060 } else if ($recipe->SPARGE_ACID_TYPE && ($recipe->SPARGE_ACID_TYPE == "Sulfuric")) { 1051 } else if ($recipe->SPARGE_ACID_TYPE && ($recipe->SPARGE_ACID_TYPE == "Sulfuric")) {
1061 $rsql .= "', sparge_acid_type='Zwavelzuur"; 1052 $sql .= "', sparge_acid_type='Zwavelzuur";
1062 } 1053 }
1063 if ($recipe->ACID_SPARGE_PERC) { 1054 if ($recipe->ACID_SPARGE_PERC) {
1064 $rsql .= "', sparge_acid_perc='" . floatval($recipe->ACID_SPARGE_PERC); 1055 $sql .= "', sparge_acid_perc='" . floatval($recipe->ACID_SPARGE_PERC);
1065 } 1056 }
1066 if ($recipe->LACTIC_SPARGE) { 1057 if ($recipe->LACTIC_SPARGE) {
1067 $rsql .= "', sparge_acid_amount='" . floatval($recipe->LACTIC_SPARGE); 1058 $sql .= "', sparge_acid_amount='" . floatval($recipe->LACTIC_SPARGE);
1068 } 1059 }
1069 if ($recipe->VOLUME_HLT) { 1060 if ($recipe->VOLUME_HLT) {
1070 $rsql .= "', sparge_volume='" . floatval($recipe->VOLUME_HLT); 1061 $sql .= "', sparge_volume='" . floatval($recipe->VOLUME_HLT);
1071 } 1062 }
1072 1063
1073 /* 1064 /*
1074 * Put the fermentables in a json array 1065 * Put the fermentables in a json array
1075 */ 1066 */
1076 if ($recipe->FERMENTABLES) { 1067 if ($recipe->FERMENTABLES) {
1077 $fermentables = recipe_fermentables($recipe); 1068 $fermentables = recipe_fermentables($recipe);
1078 $rsql .= "', json_fermentables='" . $fermentables; 1069 $sql .= "', json_fermentables='" . $fermentables;
1079 if (strlen($fermentables) > $len_fermentables) 1070 if (strlen($fermentables) > $len_fermentables)
1080 $len_fermentables = strlen($fermentables); 1071 $len_fermentables = strlen($fermentables);
1081 } 1072 }
1082 1073
1083 /* 1074 /*
1084 * Put the hops in a json array 1075 * Put the hops in a json array
1085 */ 1076 */
1086 if ($recipe->HOPS) { 1077 if ($recipe->HOPS) {
1087 $hops = recipe_hops($recipe); 1078 $hops = recipe_hops($recipe);
1088 $rsql .= "', json_hops='" . $hops; 1079 $sql .= "', json_hops='" . $hops;
1089 if (strlen($hops) > $len_hops) 1080 if (strlen($hops) > $len_hops)
1090 $len_hops = strlen($hops); 1081 $len_hops = strlen($hops);
1091 } 1082 }
1092 1083
1093 /* 1084 /*
1094 * Put the miscs in a json array 1085 * Put the miscs in a json array
1095 */ 1086 */
1096 if ($recipe->MISCS) { 1087 if ($recipe->MISCS) {
1097 $miscs = recipe_miscs($recipe); 1088 $miscs = recipe_miscs($recipe);
1098 $rsql .= "', json_miscs='" . $miscs; 1089 $sql .= "', json_miscs='" . $miscs;
1099 if (strlen($miscs) > $len_miscs) 1090 if (strlen($miscs) > $len_miscs)
1100 $len_miscs = strlen($miscs); 1091 $len_miscs = strlen($miscs);
1101 } 1092 }
1102 1093
1103 /* 1094 /*
1104 * Put the yeasts in a json array 1095 * Put the yeasts in a json array
1105 */ 1096 */
1106 if ($recipe->YEASTS) { 1097 if ($recipe->YEASTS) {
1107 $yeasts = recipe_yeasts($recipe); 1098 $yeasts = recipe_yeasts($recipe);
1108 $rsql .= "', json_yeasts='" . $yeasts; 1099 $sql .= "', json_yeasts='" . $yeasts;
1109 if (strlen($yeasts) > $len_yeasts) 1100 if (strlen($yeasts) > $len_yeasts)
1110 $len_yeasts = strlen($yeasts); 1101 $len_yeasts = strlen($yeasts);
1111 } 1102 }
1112 1103
1113 /* 1104 /*
1114 * Get the waters 1105 * Get the waters
1115 */ 1106 */
1116 if ($recipe->WATERS) { 1107 if ($recipe->WATERS) {
1117 $rsql .= recipe_waters($recipe, $db); 1108 $sql .= recipe_waters($recipe, $db);
1118 } 1109 }
1119 1110
1120 /* 1111 /*
1121 * Put the mash in a json array 1112 * Put the mash in a json array
1122 */ 1113 */
1123 if ($recipe->MASH) { 1114 if ($recipe->MASH) {
1124 $rsql .= "',sparge_temp='" . floatval($recipe->MASH->SPARGE_TEMP); 1115 $sql .= "',sparge_temp='" . floatval($recipe->MASH->SPARGE_TEMP);
1125 $rsql .= "',sparge_ph='" . floatval($recipe->MASH->PH); 1116 $sql .= "',sparge_ph='" . floatval($recipe->MASH->PH);
1126 if ($recipe->MASH->NAME) 1117 if ($recipe->MASH->NAME)
1127 $rsql .= "',mash_name='" . mysqli_real_escape_string($db, $recipe->MASH->NAME); 1118 $sql .= "',mash_name='" . mysqli_real_escape_string($db, $recipe->MASH->NAME);
1128 1119
1129 if ($recipe->MASH->MASH_STEPS) { 1120 if ($recipe->MASH->MASH_STEPS) {
1130 $steps = recipe_mash_steps($recipe); 1121 $steps = recipe_mash_steps($recipe);
1131 $rsql .= "', json_mashs='" . $steps; 1122 $sql .= "', json_mashs='" . $steps;
1132 if (strlen($steps) > $len_mash) 1123 if (strlen($steps) > $len_mash)
1133 $len_mash = strlen($steps); 1124 $len_mash = strlen($steps);
1134 } 1125 }
1135 } 1126 }
1136 1127
1137 /* 1128 /*
1138 * Added the calculated values 1129 * Added the calculated values
1139 * OG, FG, color, IBU 1130 * OG, FG, color, IBU
1140 */ 1131 */
1141 $og = estimate_sg($f_sugars, $batch_size); 1132 $og = estimate_sg($f_sugars, $batch_size);
1142 $rsql .= "', est_og='" . floatval($og); 1133 $sql .= "', est_og='" . floatval($og);
1143 $fg = estimate_fg($pSugar, $pCara, 0, 0, 0, $svg, $og); 1134 $fg = estimate_fg($pSugar, $pCara, 0, 0, 0, $svg, $og);
1144 $rsql .= "', est_fg='" . floatval($fg); 1135 $sql .= "', est_fg='" . floatval($fg);
1145 $abv = abvol($og, $fg); 1136 $abv = abvol($og, $fg);
1146 $rsql .= "', est_abv='" . floatval($abv); 1137 $sql .= "', est_abv='" . floatval($abv);
1147 $color = kw_to_ebc(mysqli_real_escape_string($db, $recipe->COLOR_METHOD), $colorw); 1138 $color = kw_to_ebc(mysqli_real_escape_string($db, $recipe->COLOR_METHOD), $colorw);
1148 $rsql .= "', est_color='" . floatval($color); 1139 $sql .= "', est_color='" . floatval($color);
1149 $psql .= "', code='" . mysqli_real_escape_string($db, $recipe->NR_RECIPE); 1140 $sql .= "', code='" . mysqli_real_escape_string($db, $recipe->NR_RECIPE);
1150 1141
1151 /* 1142 /*
1152 * Update external logfiles 1143 * Update external logfiles
1153 */ 1144 */
1154 $sql = "UPDATE log_brews SET product_uuid='".$uuid."', product_name='".mysqli_real_escape_string($db, $recipe->NAME); 1145 $lsql = "UPDATE log_brews SET product_uuid='".$uuid."', product_name='".mysqli_real_escape_string($db, $recipe->NAME);
1155 $sql .= "' WHERE product_code='".mysqli_real_escape_string($db, $recipe->NR_RECIPE)."';"; 1146 $lsql .= "' WHERE product_code='".mysqli_real_escape_string($db, $recipe->NR_RECIPE)."';";
1156 if (! $result = mysqli_query($db, $sql)) { 1147 if (! $result = mysqli_query($db, $lsql)) {
1157 printf("Error: %s\n", mysqli_error($db)); 1148 printf("Error: %s\n", mysqli_error($db));
1158 } 1149 }
1159 $count = mysqli_affected_rows($db); 1150 $count = mysqli_affected_rows($db);
1160 if ($count > 0) { 1151 if ($count > 0) {
1161 $psql .= "', log_brew='1"; 1152 $sql .= "', log_brew='1";
1162 } 1153 }
1163 $sql = "UPDATE log_fermentation SET product_uuid='".$uuid."', product_name='".mysqli_real_escape_string($db, $recipe->NAME); 1154 $lsql = "UPDATE log_fermentation SET product_uuid='".$uuid."', product_name='".mysqli_real_escape_string($db, $recipe->NAME);
1164 $sql .= "' WHERE product_code='".mysqli_real_escape_string($db, $recipe->NR_RECIPE)."';"; 1155 $lsql .= "' WHERE product_code='".mysqli_real_escape_string($db, $recipe->NR_RECIPE)."';";
1165 if (! $result = mysqli_query($db, $sql)) { 1156 if (! $result = mysqli_query($db, $lsql)) {
1166 printf("Error: %s\n", mysqli_error($db)); 1157 printf("Error: %s\n", mysqli_error($db));
1167 } 1158 }
1168 $count = mysqli_affected_rows($db); 1159 $count = mysqli_affected_rows($db);
1169 if ($count > 0) { 1160 if ($count > 0) {
1170 $psql .= "', log_fermentation='1"; 1161 $sql .= "', log_fermentation='1";
1171 } else { 1162 } else {
1172 // See if there really are no records 1163 // See if there really are no records
1173 $sql = "SELECT product_code FROM log_fermentation WHERE product_code='".$recipe->NR_RECIPE."';"; 1164 $lsql = "SELECT product_code FROM log_fermentation WHERE product_code='".$recipe->NR_RECIPE."';";
1174 $count = mysqli_affected_rows($db); 1165 $count = mysqli_affected_rows($db);
1175 if ($count > 0) { 1166 if ($count > 0) {
1176 $psql .= "', log_fermentation='1"; 1167 $sql .= "', log_fermentation='1";
1177 } 1168 }
1178 } 1169 }
1179 1170
1180 /* 1171 /*
1181 * If no external fermentation log is found, check for an internal one. 1172 * If no external fermentation log is found, check for an internal one.
1197 $lsql .= "';"; 1188 $lsql .= "';";
1198 if (! $lresult = mysqli_query($db, $lsql)) { 1189 if (! $lresult = mysqli_query($db, $lsql)) {
1199 printf("Error: %s\n", mysqli_error($db)); 1190 printf("Error: %s\n", mysqli_error($db));
1200 } 1191 }
1201 } 1192 }
1202 $psql .= "', log_fermentation='1"; 1193 $sql .= "', log_fermentation='1";
1203 } 1194 }
1204 1195
1205 if ($recipe->EQUIPMENT) { 1196 if ($recipe->EQUIPMENT) {
1206 $psql .= "', eq_name='" . mysqli_real_escape_string($db, $recipe->EQUIPMENT->NAME); 1197 $sql .= "', eq_name='" . mysqli_real_escape_string($db, $recipe->EQUIPMENT->NAME);
1207 $psql .= "', eq_notes='" . mysqli_real_escape_string($db, $recipe->EQUIPMENT->NOTES); 1198 $sql .= "', eq_notes='" . mysqli_real_escape_string($db, $recipe->EQUIPMENT->NOTES);
1208 $psql .= "', eq_boil_size='" . floatval($recipe->EQUIPMENT->BOIL_SIZE); 1199 $sql .= "', eq_boil_size='" . floatval($recipe->EQUIPMENT->BOIL_SIZE);
1209 $psql .= "', eq_batch_size='" . floatval($recipe->EQUIPMENT->BATCH_SIZE); 1200 $sql .= "', eq_batch_size='" . floatval($recipe->EQUIPMENT->BATCH_SIZE);
1210 $psql .= "', eq_tun_volume='" . floatval($recipe->EQUIPMENT->TUN_VOLUME); 1201 $sql .= "', eq_tun_volume='" . floatval($recipe->EQUIPMENT->TUN_VOLUME);
1211 $psql .= "', eq_tun_weight='" . floatval($recipe->EQUIPMENT->TUN_WEIGHT); 1202 $sql .= "', eq_tun_weight='" . floatval($recipe->EQUIPMENT->TUN_WEIGHT);
1212 $psql .= "', eq_tun_specific_heat='" . floatval($recipe->EQUIPMENT->TUN_SPECIFIC_HEAT); 1203 $sql .= "', eq_tun_specific_heat='" . floatval($recipe->EQUIPMENT->TUN_SPECIFIC_HEAT);
1213 $psql .= "', eq_tun_material='" . mysqli_real_escape_string($db, $recipe->EQUIPMENT->TUN_MATERIAL); 1204 $sql .= "', eq_tun_material='" . mysqli_real_escape_string($db, $recipe->EQUIPMENT->TUN_MATERIAL);
1214 $psql .= "', eq_tun_height='" . floatval($recipe->EQUIPMENT->TUN_HEIGHT); 1205 $sql .= "', eq_tun_height='" . floatval($recipe->EQUIPMENT->TUN_HEIGHT);
1215 if ($recipe->EQUIPMENT->TOP_UP_WATER) 1206 if ($recipe->EQUIPMENT->TOP_UP_WATER)
1216 $psql .= "', eq_top_up_water='" . floatval($recipe->EQUIPMENT->TOP_UP_WATER); 1207 $sql .= "', eq_top_up_water='" . floatval($recipe->EQUIPMENT->TOP_UP_WATER);
1217 $psql .= "', eq_trub_chiller_loss='" . floatval($recipe->EQUIPMENT->TRUB_CHILLER_LOSS); 1208 $sql .= "', eq_trub_chiller_loss='" . floatval($recipe->EQUIPMENT->TRUB_CHILLER_LOSS);
1218 /* 1209 /*
1219 * Brouwhulp uses a percentage for the evaporation rate. This is wrong 1210 * Brouwhulp uses a percentage for the evaporation rate. This is wrong
1220 * but was made so because the beerxml standard requires this. What we 1211 * but was made so because the beerxml standard requires this. What we
1221 * do is calculate the actual evaporation and store that. 1212 * do is calculate the actual evaporation and store that.
1222 * This is what we use. Brouwhulp calculates this on the fly. 1213 * This is what we use. Brouwhulp calculates this on the fly.
1223 */ 1214 */
1224 $psql .= "', eq_evap_rate='" . (floatval($recipe->EQUIPMENT->EVAP_RATE) * floatval($recipe->EQUIPMENT->BOIL_SIZE)) / 100; 1215 $sql .= "', eq_evap_rate='" . (floatval($recipe->EQUIPMENT->EVAP_RATE) * floatval($recipe->EQUIPMENT->BOIL_SIZE)) / 100;
1225 $psql .= "', eq_boil_time='" . floatval($recipe->EQUIPMENT->BOIL_TIME); 1216 $sql .= "', eq_boil_time='" . floatval($recipe->EQUIPMENT->BOIL_TIME);
1226 ($recipe->EQUIPMENT->CALC_BOIL_VOLUME == 'TRUE') ? $psql .= "', eq_calc_boil_volume='1" : $psql .= "', eq_calc_boil_volume='0"; 1217 ($recipe->EQUIPMENT->CALC_BOIL_VOLUME == 'TRUE') ? $sql .= "', eq_calc_boil_volume='1" : $sql .= "', eq_calc_boil_volume='0";
1227 if ($recipe->EQUIPMENT->TOP_UP_KETTLE) 1218 if ($recipe->EQUIPMENT->TOP_UP_KETTLE)
1228 $psql .= "', eq_top_up_kettle='" . floatval($recipe->EQUIPMENT->TOP_UP_KETTLE); 1219 $sql .= "', eq_top_up_kettle='" . floatval($recipe->EQUIPMENT->TOP_UP_KETTLE);
1229 $psql .= "', eq_hop_utilization='" . floatval($recipe->EQUIPMENT->HOP_UTILIZATION); 1220 $sql .= "', eq_hop_utilization='" . floatval($recipe->EQUIPMENT->HOP_UTILIZATION);
1230 $psql .= "', eq_lauter_volume='" . floatval($recipe->EQUIPMENT->LAUTER_VOLUME); 1221 $sql .= "', eq_lauter_volume='" . floatval($recipe->EQUIPMENT->LAUTER_VOLUME);
1231 $psql .= "', eq_lauter_height='" . floatval($recipe->EQUIPMENT->LAUTER_HEIGHT); 1222 $sql .= "', eq_lauter_height='" . floatval($recipe->EQUIPMENT->LAUTER_HEIGHT);
1232 $psql .= "', eq_lauter_deadspace='" . floatval($recipe->EQUIPMENT->LAUTER_DEADSPACE); 1223 $sql .= "', eq_lauter_deadspace='" . floatval($recipe->EQUIPMENT->LAUTER_DEADSPACE);
1233 $psql .= "', eq_kettle_volume='" . floatval($recipe->EQUIPMENT->KETTLE_VOLUME); 1224 $sql .= "', eq_kettle_volume='" . floatval($recipe->EQUIPMENT->KETTLE_VOLUME);
1234 $psql .= "', eq_kettle_height='" . floatval($recipe->EQUIPMENT->KETTLE_HEIGHT); 1225 $sql .= "', eq_kettle_height='" . floatval($recipe->EQUIPMENT->KETTLE_HEIGHT);
1235 $psql .= "', eq_mash_volume='" . floatval($recipe->EQUIPMENT->MASH_VOLUME); 1226 $sql .= "', eq_mash_volume='" . floatval($recipe->EQUIPMENT->MASH_VOLUME);
1236 $psql .= "', eq_mash_max='" . round((floatval($recipe->EQUIPMENT->MASH_VOLUME) / 3) * 10) / 10; // Not in beerxml/brouwhulp. For RIMS systems. 1227 $sql .= "', eq_mash_max='" . round((floatval($recipe->EQUIPMENT->MASH_VOLUME) / 3) * 10) / 10; // Not in beerxml/brouwhulp. For RIMS systems.
1237 $psql .= "', eq_efficiency='" . floatval($recipe->EQUIPMENT->EFFICIENCY); 1228 $sql .= "', eq_efficiency='" . floatval($recipe->EQUIPMENT->EFFICIENCY);
1238 } 1229 }
1239 1230
1240 if (($recipe->DATE) && (! $recipe->TIME_STARTED) && (! $recipe->TIME_ENDED)) { 1231 if (($recipe->DATE) && (! $recipe->TIME_STARTED) && (! $recipe->TIME_ENDED)) {
1241 /* We have a plan date but haven't brewed yet, use current date */ 1232 /* We have a plan date but haven't brewed yet, use current date */
1242 $psql .= "', birth='" . date("Y-m-d"); 1233 $sql .= "', birth='" . date("Y-m-d");
1243 $stageno= 1; 1234 $stageno= 1;
1244 $stage = "Wait"; 1235 $stage = "Wait";
1245 } 1236 }
1246 1237
1247 if (($recipe->DATE) && ($recipe->TIME_STARTED) && ($recipe->TIME_ENDED)) { 1238 if (($recipe->DATE) && ($recipe->TIME_STARTED) && ($recipe->TIME_ENDED)) {
1248 /* We have brew data */ 1239 /* We have brew data */
1249 $stageno = 3; 1240 $stageno = 3;
1250 $stage = "Primary"; // Need to think about during a brew... 1241 $stage = "Primary"; // Need to think about during a brew...
1251 $brewdate = substr($recipe->DATE, 6, 4).substr($recipe->DATE,2,4).substr($recipe->DATE,0,2); 1242 $brewdate = substr($recipe->DATE, 6, 4).substr($recipe->DATE,2,4).substr($recipe->DATE,0,2);
1252 $psql .= "', birth='" . $brewdate; 1243 $sql .= "', birth='" . $brewdate;
1253 $date_start = $brewdate.' '.$recipe->TIME_STARTED; 1244 $date_start = $brewdate.' '.$recipe->TIME_STARTED;
1254 $date_end = $brewdate.' '.$recipe->TIME_ENDED; 1245 $date_end = $brewdate.' '.$recipe->TIME_ENDED;
1255 $psql .= "', brew_date_start='" . $date_start; 1246 $sql .= "', brew_date_start='" . $date_start;
1256 1247
1257 if ($recipe->PH_ADJUSTED) 1248 if ($recipe->PH_ADJUSTED)
1258 $psql .= "', brew_mash_ph='" . floatval($recipe->PH_ADJUSTED); 1249 $sql .= "', brew_mash_ph='" . floatval($recipe->PH_ADJUSTED);
1259 if (floatval($recipe->SG_END_MASH) != 1.0) 1250 if (floatval($recipe->SG_END_MASH) != 1.0)
1260 $psql .= "', brew_mash_sg='" . floatval($recipe->SG_END_MASH); 1251 $sql .= "', brew_mash_sg='" . floatval($recipe->SG_END_MASH);
1261 if ($recipe->MASH->SPARGE_TEMP) 1252 if ($recipe->MASH->SPARGE_TEMP)
1262 $psql .= "', brew_sparge_temperature='" . floatval($recipe->MASH->SPARGE_TEMP); 1253 $sql .= "', brew_sparge_temperature='" . floatval($recipe->MASH->SPARGE_TEMP);
1263 if ($recipe->MASH->PH) 1254 if ($recipe->MASH->PH)
1264 $psql .= "', brew_sparge_ph='" . floatval($recipe->MASH->PH); 1255 $sql .= "', brew_sparge_ph='" . floatval($recipe->MASH->PH);
1265 if ($recipe->VOLUME_HLT) 1256 if ($recipe->VOLUME_HLT)
1266 $psql .= "', brew_sparge_volume='" . floatval($recipe->VOLUME_HLT); 1257 $sql .= "', brew_sparge_volume='" . floatval($recipe->VOLUME_HLT);
1267 if ($recipe->VOLUME_BEFORE_BOIL) 1258 if ($recipe->VOLUME_BEFORE_BOIL)
1268 $psql .= "', brew_preboil_volume='" . floatval($recipe->VOLUME_BEFORE_BOIL); 1259 $sql .= "', brew_preboil_volume='" . floatval($recipe->VOLUME_BEFORE_BOIL);
1269 if (floatval($recipe->OG_BEFORE_BOIL) != 1.0) 1260 if (floatval($recipe->OG_BEFORE_BOIL) != 1.0)
1270 $psql .= "', brew_preboil_sg='" . floatval($recipe->OG_BEFORE_BOIL); 1261 $sql .= "', brew_preboil_sg='" . floatval($recipe->OG_BEFORE_BOIL);
1271 if ($recipe->PH_BEFORE_BOIL) 1262 if ($recipe->PH_BEFORE_BOIL)
1272 $psql .= "', brew_preboil_ph='" . floatval($recipe->PH_BEFORE_BOIL); 1263 $sql .= "', brew_preboil_ph='" . floatval($recipe->PH_BEFORE_BOIL);
1273 if ($recipe->VOLUME_AFTER_BOIL) 1264 if ($recipe->VOLUME_AFTER_BOIL)
1274 $psql .= "', brew_aboil_volume='" . floatval($recipe->VOLUME_AFTER_BOIL); 1265 $sql .= "', brew_aboil_volume='" . floatval($recipe->VOLUME_AFTER_BOIL);
1275 $psql .= "', brew_aboil_sg='" . floatval($recipe->OG); 1266 $sql .= "', brew_aboil_sg='" . floatval($recipe->OG);
1276 if ($recipe->PH_AFTER_BOIL) 1267 if ($recipe->PH_AFTER_BOIL)
1277 $psql .= "', brew_aboil_ph='" . floatval($recipe->PH_AFTER_BOIL); 1268 $sql .= "', brew_aboil_ph='" . floatval($recipe->PH_AFTER_BOIL);
1278 if ($recipe->ACTUAL_EFFICIENCY) 1269 if ($recipe->ACTUAL_EFFICIENCY)
1279 $psql .= "', brew_aboil_efficiency='" . floatval($recipe->ACTUAL_EFFICIENCY); 1270 $sql .= "', brew_aboil_efficiency='" . floatval($recipe->ACTUAL_EFFICIENCY);
1280 $psql .= "', brew_whirlpool2='" . floatval($recipe->WHIRLPOOL_TIME); 1271 $sql .= "', brew_whirlpool2='" . floatval($recipe->WHIRLPOOL_TIME);
1281 $psql .= "', brew_cooling_method='" . mysqli_real_escape_string($db, $recipe->COOLING_METHOD); 1272 $sql .= "', brew_cooling_method='" . mysqli_real_escape_string($db, $recipe->COOLING_METHOD);
1282 $psql .= "', brew_cooling_time='" . floatval($recipe->COOLING_TIME); 1273 $sql .= "', brew_cooling_time='" . floatval($recipe->COOLING_TIME);
1283 $psql .= "', brew_cooling_to='" . floatval($recipe->COOLING_TO); 1274 $sql .= "', brew_cooling_to='" . floatval($recipe->COOLING_TO);
1284 if ($recipe->VOLUME_FERMENTER) 1275 if ($recipe->VOLUME_FERMENTER)
1285 $psql .= "', brew_fermenter_volume='" . floatval($recipe->VOLUME_FERMENTER); 1276 $sql .= "', brew_fermenter_volume='" . floatval($recipe->VOLUME_FERMENTER);
1286 if ($recipe->EQUIPMENT->TOP_UP_WATER_BREWDAY) 1277 if ($recipe->EQUIPMENT->TOP_UP_WATER_BREWDAY)
1287 $psql .= "', brew_fermenter_extrawater='" . floatval($recipe->EQUIPMENT->TOP_UP_WATER_BREWDAY); 1278 $sql .= "', brew_fermenter_extrawater='" . floatval($recipe->EQUIPMENT->TOP_UP_WATER_BREWDAY);
1288 $psql .= "', brew_fermenter_sg='" . floatval($recipe->OG_FERMENTER); 1279 $sql .= "', brew_fermenter_sg='" . floatval($recipe->OG_FERMENTER);
1289 $psql .= "', brew_fermenter_ibu='" . floatval($recipe->IBU); 1280 $sql .= "', brew_fermenter_ibu='" . floatval($recipe->IBU);
1290 $psql .= "', brew_aeration_type='" . mysqli_real_escape_string($db, $recipe->AERATION_TYPE); 1281 $sql .= "', brew_aeration_type='" . mysqli_real_escape_string($db, $recipe->AERATION_TYPE);
1291 if ($recipe->AERATION_TYPE != "None") { 1282 if ($recipe->AERATION_TYPE != "None") {
1292 $psql .= "', brew_aeration_speed='" . floatval($recipe->AERATION_SPEED); 1283 $sql .= "', brew_aeration_speed='" . floatval($recipe->AERATION_SPEED);
1293 $psql .= "', brew_aeration_time='" . floatval($recipe->AERATION_TIME); 1284 $sql .= "', brew_aeration_time='" . floatval($recipe->AERATION_TIME);
1294 } 1285 }
1295 $psql .= "', brew_date_end='" . $date_end; 1286 $sql .= "', brew_date_end='" . $date_end;
1296 } 1287 }
1297 1288
1298 if ($recipe->PRIMARY_AGE && ($stageno >= 3)) { 1289 if ($recipe->PRIMARY_AGE && ($stageno >= 3)) {
1299 /* PRIMARY_TEMP is the average of START_TEMP_PRIMARY MAX_TEMP_PRIMARY END_TEMP_PRIMARY */ 1290 /* PRIMARY_TEMP is the average of START_TEMP_PRIMARY MAX_TEMP_PRIMARY END_TEMP_PRIMARY */
1300 $pdate = new DateTime($brewdate); 1291 $pdate = new DateTime($brewdate);
1301 $pdate->modify("+".floatval($recipe->PRIMARY_AGE)." days"); 1292 $pdate->modify("+".floatval($recipe->PRIMARY_AGE)." days");
1302 $psql .= "', primary_start_temp='" . floatval($recipe->START_TEMP_PRIMARY); 1293 $sql .= "', primary_start_temp='" . floatval($recipe->START_TEMP_PRIMARY);
1303 $psql .= "', primary_max_temp='" . floatval($recipe->MAX_TEMP_PRIMARY); 1294 $sql .= "', primary_max_temp='" . floatval($recipe->MAX_TEMP_PRIMARY);
1304 $psql .= "', primary_end_temp='" . floatval($recipe->END_TEMP_PRIMARY); 1295 $sql .= "', primary_end_temp='" . floatval($recipe->END_TEMP_PRIMARY);
1305 $psql .= "', primary_end_sg='" . floatval($recipe->SG_END_PRIMARY); 1296 $sql .= "', primary_end_sg='" . floatval($recipe->SG_END_PRIMARY);
1306 $psql .= "', primary_end_date='" . $pdate->format("Y-m-d"); 1297 $sql .= "', primary_end_date='" . $pdate->format("Y-m-d");
1307 $stageno = 4; 1298 $stageno = 4;
1308 $stage = "Secondary"; 1299 $stage = "Secondary";
1309 1300
1310 if ($recipe->SECONDARY_AGE && ($stageno >= 4)) { 1301 if ($recipe->SECONDARY_AGE && ($stageno >= 4)) {
1311 $sdate = new DateTime($brewdate); 1302 $sdate = new DateTime($brewdate);
1312 $sdate->modify("+".floatval($recipe->SECONDARY_AGE)." days"); 1303 $sdate->modify("+".floatval($recipe->SECONDARY_AGE)." days");
1313 $psql .= "', secondary_temp='" . floatval($recipe->SECONDARY_TEMP); 1304 $sql .= "', secondary_temp='" . floatval($recipe->SECONDARY_TEMP);
1314 $psql .= "', secondary_end_date='" . $sdate->format("Y-m-d"); 1305 $sql .= "', secondary_end_date='" . $sdate->format("Y-m-d");
1315 $stageno = 5; 1306 $stageno = 5;
1316 $stage = "Tertiary"; 1307 $stage = "Tertiary";
1317 1308
1318 if ($recipe->TERTIARY_TEMP && ($stageno >= 5)) { 1309 if ($recipe->TERTIARY_TEMP && ($stageno >= 5)) {
1319 $psql .= "', tertiary_temp='" . floatval($recipe->TERTIARY_TEMP); 1310 $sql .= "', tertiary_temp='" . floatval($recipe->TERTIARY_TEMP);
1320 } 1311 }
1321 } 1312 }
1322 } 1313 }
1323 1314
1324 if ($recipe->DATE_BOTTLING && ($recipe->AMOUNT_BOTTLING || $recipe->AMOUNT_KEGGED) && 1315 if ($recipe->DATE_BOTTLING && ($recipe->AMOUNT_BOTTLING || $recipe->AMOUNT_KEGGED) &&
1325 ($recipe->AMOUNT_PRIMING || $recipe->AMOUNT_PRIMING_KEGS) && ($stageno >= 5)) { 1316 ($recipe->AMOUNT_PRIMING || $recipe->AMOUNT_PRIMING_KEGS) && ($stageno >= 5)) {
1326 $bdate = substr($recipe->DATE_BOTTLING, 6, 4).substr($recipe->DATE_BOTTLING,2,4).substr($recipe->DATE_BOTTLING,0,2); 1317 $bdate = substr($recipe->DATE_BOTTLING, 6, 4).substr($recipe->DATE_BOTTLING,2,4).substr($recipe->DATE_BOTTLING,0,2);
1327 $psql .= "', package_date='" . $bdate; 1318 $sql .= "', package_date='" . $bdate;
1328 $stage = "Package"; 1319 $stage = "Package";
1329 $stageno = 6; 1320 $stageno = 6;
1330 $dStart = new DateTime($bdate); 1321 $dStart = new DateTime($bdate);
1331 $dEnd = new DateTime(''); 1322 $dEnd = new DateTime('');
1332 $dDiff = $dStart->diff($dEnd); 1323 $dDiff = $dStart->diff($dEnd);
1344 $stage = "Taste"; 1335 $stage = "Taste";
1345 $stageno = 9; 1336 $stageno = 9;
1346 } 1337 }
1347 1338
1348 if ($recipe->AMOUNT_BOTTLING && $recipe->AMOUNT_PRIMING) { 1339 if ($recipe->AMOUNT_BOTTLING && $recipe->AMOUNT_PRIMING) {
1349 $psql .= "', bottle_amount='" . floatval($recipe->AMOUNT_BOTTLING); 1340 $sql .= "', bottle_amount='" . floatval($recipe->AMOUNT_BOTTLING);
1350 $psql .= "', bottle_carbonation='" . floatval($recipe->CARBONATION); 1341 $sql .= "', bottle_carbonation='" . floatval($recipe->CARBONATION);
1351 $psql .= "', bottle_priming_sugar='" . mysqli_real_escape_string($db, $recipe->PRIMING_SUGAR_BOTTLES); 1342 $sql .= "', bottle_priming_sugar='" . mysqli_real_escape_string($db, $recipe->PRIMING_SUGAR_BOTTLES);
1352 $psql .= "', bottle_priming_amount='" . floatval($recipe->AMOUNT_PRIMING); 1343 $sql .= "', bottle_priming_amount='" . floatval($recipe->AMOUNT_PRIMING);
1353 $psql .= "', bottle_carbonation_temp='" . floatval($recipe->CARBONATION_TEMP); 1344 $sql .= "', bottle_carbonation_temp='" . floatval($recipe->CARBONATION_TEMP);
1354 } 1345 }
1355 if ($recipe->AMOUNT_KEGGED && $recipe->AMOUNT_PRIMING_KEGS) { 1346 if ($recipe->AMOUNT_KEGGED && $recipe->AMOUNT_PRIMING_KEGS) {
1356 $psql .= "', keg_amount='" . floatval($recipe->AMOUNT_KEGGED); 1347 $sql .= "', keg_amount='" . floatval($recipe->AMOUNT_KEGGED);
1357 $psql .= "', keg_carbonation='" . floatval($recipe->CARBONATION); // Lijkt wel hetzelfde als bottles 1348 $sql .= "', keg_carbonation='" . floatval($recipe->CARBONATION); // Lijkt wel hetzelfde als bottles
1358 $psql .= "', keg_priming_sugar='" . mysqli_real_escape_string($db, $recipe->PRIMING_SUGAR_KEGS); 1349 $sql .= "', keg_priming_sugar='" . mysqli_real_escape_string($db, $recipe->PRIMING_SUGAR_KEGS);
1359 $psql .= "', keg_priming_amount='" . floatval($recipe->AMOUNT_PRIMING_KEGS); 1350 $sql .= "', keg_priming_amount='" . floatval($recipe->AMOUNT_PRIMING_KEGS);
1360 $psql .= "', keg_carbonation_temp='" . floatval($recipe->KEG_CARB_TEMP); 1351 $sql .= "', keg_carbonation_temp='" . floatval($recipe->KEG_CARB_TEMP);
1361 ($recipe->FORCED_CARB_KEGS == 'TRUE') ? $psql .= "', keg_forced_carb='1" : $psql .= "', keg_forced_carb='0"; 1352 ($recipe->FORCED_CARB_KEGS == 'TRUE') ? $sql .= "', keg_forced_carb='1" : $sql .= "', keg_forced_carb='0";
1362 $psql .= "', keg_pressure='" . floatval($recipe->KEG_PRESSURE); 1353 $sql .= "', keg_pressure='" . floatval($recipe->KEG_PRESSURE);
1363 $psql .= "', keg_priming_factor='" . floatval($recipe->KEG_PRIMING_FACTOR); 1354 $sql .= "', keg_priming_factor='" . floatval($recipe->KEG_PRIMING_FACTOR);
1364 } 1355 }
1365 } 1356 }
1366 1357
1367 if ($recipe->TASTE_NOTES && $recipe->TASTING_RATE && $recipe->TASTE_DATE && ($stageno >= 9)) { 1358 if ($recipe->TASTE_NOTES && $recipe->TASTING_RATE && $recipe->TASTE_DATE && ($stageno >= 9)) {
1368 $stage = "Ready"; // Ready if tasted. 1359 $stage = "Ready"; // Ready if tasted.
1369 $stageno = 10; 1360 $stageno = 10;
1370 $psql .= "', taste_notes='" . mysqli_real_escape_string($db, $recipe->TASTE_NOTES); 1361 $sql .= "', taste_notes='" . mysqli_real_escape_string($db, $recipe->TASTE_NOTES);
1371 $psql .= "', taste_rate='" . floatval($recipe->TASTING_RATE); 1362 $sql .= "', taste_rate='" . floatval($recipe->TASTING_RATE);
1372 $tdate = substr($recipe->TASTE_DATE, 6, 4).substr($recipe->TASTE_DATE,2,4).substr($recipe->TASTE_DATE,0,2); 1363 $tdate = substr($recipe->TASTE_DATE, 6, 4).substr($recipe->TASTE_DATE,2,4).substr($recipe->TASTE_DATE,0,2);
1373 $psql .= "', taste_date='" . $tdate; 1364 $sql .= "', taste_date='" . $tdate;
1374 $psql .= "', taste_color='" . mysqli_real_escape_string($db, $recipe->TASTE_COLOR); 1365 $sql .= "', taste_color='" . mysqli_real_escape_string($db, $recipe->TASTE_COLOR);
1375 $psql .= "', taste_transparency='" . mysqli_real_escape_string($db, $recipe->TASTE_TRANSPARENCY); 1366 $sql .= "', taste_transparency='" . mysqli_real_escape_string($db, $recipe->TASTE_TRANSPARENCY);
1376 $psql .= "', taste_head='" . mysqli_real_escape_string($db, $recipe->TASTE_HEAD); 1367 $sql .= "', taste_head='" . mysqli_real_escape_string($db, $recipe->TASTE_HEAD);
1377 $psql .= "', taste_aroma='" . mysqli_real_escape_string($db, $recipe->TASTE_AROMA); 1368 $sql .= "', taste_aroma='" . mysqli_real_escape_string($db, $recipe->TASTE_AROMA);
1378 $psql .= "', taste_taste='" . mysqli_real_escape_string($db, $recipe->TASTE_TASTE); 1369 $sql .= "', taste_taste='" . mysqli_real_escape_string($db, $recipe->TASTE_TASTE);
1379 $psql .= "', taste_mouthfeel='" . mysqli_real_escape_string($db, $recipe->TASTE_MOUTHFEEL); 1370 $sql .= "', taste_mouthfeel='" . mysqli_real_escape_string($db, $recipe->TASTE_MOUTHFEEL);
1380 $psql .= "', taste_aftertaste='" . mysqli_real_escape_string($db, $recipe->TASTE_AFTERTASTE); 1371 $sql .= "', taste_aftertaste='" . mysqli_real_escape_string($db, $recipe->TASTE_AFTERTASTE);
1381 } 1372 }
1382 1373
1383 ($recipe->INVENTORY_REDUCED == 'TRUE') ? $psql .= "', inventory_reduced='1" : $psql .= "', inventory_reduced='0"; 1374 ($recipe->INVENTORY_REDUCED == 'TRUE') ? $sql .= "', inventory_reduced='1" : $sql .= "', inventory_reduced='0";
1384 if (($recipe->LOCKED == 'TRUE') && ($stage == 'Ready')) { 1375 if (($recipe->LOCKED == 'TRUE') && ($stage == 'Ready')) {
1385 $psql .= "', plocked='1"; 1376 $sql .= "', locked='1";
1386 $rsql .= "', locked='1";
1387 $stage = "Closed"; 1377 $stage = "Closed";
1388 $stageno = 11; 1378 $stageno = 11;
1389 } else { 1379 } else {
1390 $psql .= "', plocked='0"; 1380 $sql .= "', locked='0";
1391 $rsql .= "', locked='0"; 1381 }
1392 } 1382
1393 1383 $sql .= "', stage='" . $stage;
1394 $psql .= "', stage='" . $stage;
1395 // echo ' '.$brewdate.' '.$recipe->NR_RECIPE.' '.$stage . PHP_EOL; 1384 // echo ' '.$brewdate.' '.$recipe->NR_RECIPE.' '.$stage . PHP_EOL;
1396 1385
1397 $rsql .= "';"; 1386 $sql .= "';";
1398 if (! $rresult = mysqli_query($db, $rsql)) { 1387 if (! $rresult = mysqli_query($db, $sql)) {
1399 printf("Error: %s\n", mysqli_error($db));
1400 }
1401
1402 $psql .= "';";
1403 if (! $presult = mysqli_query($db, $psql)) {
1404 printf("Error: %s\n", mysqli_error($db)); 1388 printf("Error: %s\n", mysqli_error($db));
1405 } 1389 }
1406 } 1390 }
1407 } 1391 }
1408 1392

mercurial