--- a/www/includes/db_recipes.php Sun Jan 27 23:35:19 2019 +0100 +++ b/www/includes/db_recipes.php Tue Jan 29 21:52:08 2019 +0100 @@ -36,7 +36,7 @@ $sql .= "', st_name='" . mysqli_real_escape_string($connect, $_POST['st_name']); $sql .= "', st_letter='" . mysqli_real_escape_string($connect, $_POST['st_letter']); $sql .= "', st_guide='" . mysqli_real_escape_string($connect, $_POST['st_guide']); - $sql .= "', st_type='" . mysqli_real_escape_string($connect, $_POST['st_type']); + $sql .= "', st_type='" . $_POST['st_type']; $sql .= "', st_category='" . mysqli_real_escape_string($connect, $_POST['st_category']); $sql .= "', st_category_number='" . $_POST['st_category_number']; $sql .= "', st_og_min='" . $_POST['st_og_min']; @@ -100,29 +100,82 @@ $sql .= "', w2_ph='" . $_POST['w2_ph']; $sql .= "', w2_cost='" . $_POST['w2_cost']; } + $sql .= "', wa_acid_name='" . $_POST['wa_acid_name']; + $sql .= "', wa_acid_perc='" . $_POST['wa_acid_perc']; + $sql .= "', wa_base_name='" . $_POST['wa_base_name']; syslog(LOG_NOTICE, $sql); + $fermentables = '['; + $comma = FALSE; if (isset($_POST['fermentables'])) { $array = $_POST['fermentables']; foreach($array as $key => $item){ - foreach ($disallowed as $disallowed_key) { - unset($array[$key]["$disallowed_key"]); - } + /* + * Manual encode to json. + */ + if ($comma) + $fermentables .= ','; + $comma = TRUE; + $fermentable = '{"f_name":"' . str_replace($rescapers,$rreplacements,$item['f_name']); + $fermentable .= '","f_origin":"' . str_replace($rescapers,$rreplacements,$item['f_origin']); + $fermentable .= '","f_supplier":"' . str_replace($rescapers,$rreplacements,$item['f_supplier']); + $fermentable .= '","f_amount":' . $item['f_amount']; + $fermentable .= ',"f_cost":' . $item['f_cost']; + $fermentable .= ',"f_type":' . $item['f_type']; + $fermentable .= ',"f_yield":' . $item['f_yield']; + $fermentable .= ',"f_color":' . $item['f_color']; + $fermentable .= ',"f_coarse_fine_diff":' . $item['f_coarse_fine_diff']; + $fermentable .= ',"f_moisture":' . $item['f_moisture']; + $fermentable .= ',"f_diastatic_power":' . $item['f_diastatic_power']; + $fermentable .= ',"f_protein":' . $item['f_protein']; + $fermentable .= ',"f_dissolved_protein":' . $item['f_dissolved_protein']; + $fermentable .= ',"f_max_in_batch":' . $item['f_max_in_batch']; + $fermentable .= ',"f_graintype":' . $item['f_graintype']; + $fermentable .= ',"f_added":' . $item['f_added']; + $fermentable .= ',"f_recommend_mash":' . $item['f_recommend_mash']; + $fermentable .= ',"f_add_after_boil":' . $item['f_add_after_boil']; + $fermentable .= ',"f_adjust_to_total_100":' . $item['f_adjust_to_total_100']; + $fermentable .= ',"f_percentage":' . $item['f_percentage']; + $fermentable .= ',"f_di_ph":' . $item['f_di_ph']; + $fermentable .= ',"f_acid_to_ph_57":' . $item['f_acid_to_ph_57'] . '}'; + syslog(LOG_NOTICE, $fermentable); + $fermentables .= $fermentable; } - syslog(LOG_NOTICE, "json_fermentables=: ".str_replace($rescapers,$rreplacements,json_encode($array))); - $sql .= "', json_fermentables='" . str_replace($rescapers,$rreplacements,json_encode($array)); } + $fermentables .= ']'; + $sql .= "', json_fermentables='" . $fermentables; + $hops = '['; + $comma = FALSE; if (isset($_POST['hops'])) { $array = $_POST['hops']; foreach($array as $key => $item){ - foreach ($disallowed as $disallowed_key) { - unset($array[$key]["$disallowed_key"]); - } + if ($comma) + $hops .= ','; + $comma = TRUE; + $hop = '{"h_name":"' . str_replace($rescapers,$rreplacements,$item['h_name']); + $hop .= '","h_origin":"' . str_replace($rescapers,$rreplacements,$item['h_origin']); + $hop .= '","h_amount":' . $item['h_amount']; + $hop .= ',"h_cost":' . $item['h_cost']; + $hop .= ',"h_type":' . $item['h_type']; + $hop .= ',"h_form":' . $item['h_form']; + $hop .= ',"h_useat":' . $item['h_useat']; + $hop .= ',"h_time":' . $item['h_time']; + $hop .= ',"h_alpha":' . $item['h_alpha']; + $hop .= ',"h_beta":' . $item['h_beta']; + $hop .= ',"h_hsi":' . $item['h_hsi']; + $hop .= ',"h_humulene":' . $item['h_humulene']; + $hop .= ',"h_carophyllene":' . $item['h_carophyllene']; + $hop .= ',"h_cohumulone":' . $item['h_cohumulone']; + $hop .= ',"h_myrcene":' . $item['h_myrcene']; + $hop .= ',"h_total_oil":' . $item['h_total_oil']; + $hop .= ',"h_weight":' . $item['h_weight'] . '}'; + syslog(LOG_NOTICE, $hop); + $hops .= $hop; } - syslog(LOG_NOTICE, "json_hops: ".str_replace($rescapers,$rreplacements,json_encode($array))); - $sql .= "', json_hops='" . str_replace($rescapers,$rreplacements,json_encode($array)); } + $hops .= ']'; + $sql .= "', json_hops='" . $hops; if (isset($_POST['miscs'])) { $array = $_POST['miscs']; @@ -212,8 +265,8 @@ $recipes .= ',"st_guide":"' . str_replace($escapers, $replacements, $row['st_guide']); $recipes .= '","st_letter":"' . str_replace($escapers, $replacements, $row['st_letter']); $recipes .= '","st_name":"' . str_replace($escapers, $replacements, $row['st_name']); - $recipes .= '","st_type":"' . str_replace($escapers, $replacements, $row['st_type']); - $recipes .= '","st_category":"' . str_replace($escapers, $replacements, $row['st_category']); + $recipes .= '","st_type":' . $row['st_type']; + $recipes .= ',"st_category":"' . str_replace($escapers, $replacements, $row['st_category']); $recipes .= '","st_category_number":' . floatval($row['st_category_number']); $recipes .= ',"st_og_min":' . floatval($row['st_og_min']); $recipes .= ',"st_og_max":' . floatval($row['st_og_max']); @@ -229,8 +282,8 @@ $recipes .= ',"st_abv_max":' . floatval($row['st_abv_max']); $recipes .= ',"name":"' . str_replace($escapers, $replacements, $row['name']); $recipes .= '","notes":"' . str_replace($escapers, $replacements, $row['notes']); - $recipes .= '","type":"' . $row['type']; - $recipes .= '","batch_size":' . floatval($row['batch_size']); + $recipes .= '","type":' . $row['type']; + $recipes .= ',"batch_size":' . floatval($row['batch_size']); $recipes .= ',"boil_size":' . floatval($row['boil_size']); $recipes .= ',"boil_time":' . floatval($row['boil_time']); $recipes .= ',"efficiency":' . floatval($row['efficiency']); @@ -239,15 +292,15 @@ $recipes .= ',"est_abv":' . floatval($row['est_abv']); $recipes .= ',"est_carb":' . floatval($row['est_carb']); $recipes .= ',"est_color":' . floatval($row['est_color']); - $recipes .= ',"color_method":"' . $row['color_method']; - $recipes .= '","est_ibu":' . floatval($row['est_ibu']); - $recipes .= ',"ibu_method":"' . $row['ibu_method']; - $recipes .= '","sparge_temp":' . $row['sparge_temp']; + $recipes .= ',"color_method":' . $row['color_method']; + $recipes .= ',"est_ibu":' . floatval($row['est_ibu']); + $recipes .= ',"ibu_method":' . $row['ibu_method']; + $recipes .= ',"sparge_temp":' . $row['sparge_temp']; $recipes .= ',"sparge_ph":' . $row['sparge_ph']; $recipes .= ',"sparge_volume":' . $row['sparge_volume']; $recipes .= ',"sparge_source":"' . $row['sparge_source']; - $recipes .= '","sparge_acid_type":"' . $row['sparge_acid_type']; - $recipes .= '","sparge_acid_perc":' . $row['sparge_acid_perc']; + $recipes .= '","sparge_acid_type":' . $row['sparge_acid_type']; + $recipes .= ',"sparge_acid_perc":' . $row['sparge_acid_perc']; $recipes .= ',"sparge_acid_amount":' . $row['sparge_acid_amount']; $recipes .= ',"mash_ph":' . $row['mash_ph']; $recipes .= ',"mash_name":"' . $row['mash_name']; @@ -272,6 +325,9 @@ $recipes .= ',"w2_total_alkalinity":' . $row['w2_total_alkalinity']; $recipes .= ',"w2_ph":' . $row['w2_ph']; $recipes .= ',"w2_cost":' . $row['w2_cost']; + $recipes .= ',"wa_acid_name":' . $row['wa_acid_name']; + $recipes .= ',"wa_acid_perc":' . $row['wa_acid_perc']; + $recipes .= ',"wa_base_name":' . $row['wa_base_name']; $recipes .= ',"fermentables":' . $row['json_fermentables']; $recipes .= ',"hops":' . $row['json_hops']; $recipes .= ',"miscs":' . $row['json_miscs'];