# HG changeset patch # User Michiel Broek # Date 1535660529 -7200 # Node ID bdd1ec9b9c06ff68143079d24ed13617b694e3a1 # Parent 94cd5ac04b6a59e1ce3eb03d3fd7dffa39c8b4a7 Start recipes import and menus. diff -r 94cd5ac04b6a -r bdd1ec9b9c06 www/import/from_brouwhulp.php --- a/www/import/from_brouwhulp.php Wed Aug 29 23:13:13 2018 +0200 +++ b/www/import/from_brouwhulp.php Thu Aug 30 22:22:09 2018 +0200 @@ -343,18 +343,18 @@ if ($style->STYLE_GUIDE) $sql .= "', style_guide='" . mysqli_real_escape_string($db, $style->STYLE_GUIDE); $sql .= "', type='" . $style->TYPE; - $sql .= "', og_min='" . $style->OG_MIN; - $sql .= "', og_max='" . $style->OG_MAX; - $sql .= "', fg_min='" . $style->FG_MIN; - $sql .= "', fg_max='" . $style->FG_MAX; - $sql .= "', ibu_min='" . $style->IBU_MIN; - $sql .= "', ibu_max='" . $style->IBU_MAX; - $sql .= "', color_min='" . $style->COLOR_MIN; - $sql .= "', color_max='" . $style->COLOR_MAX; - $sql .= "', carb_min='" . $style->CARB_MIN; - $sql .= "', carb_max='" . $style->CARB_MAX; - $sql .= "', abv_min='" . $style->ABV_MIN; - $sql .= "', abv_max='" . $style->ABV_MAX; + $sql .= "', og_min='" . floatval($style->OG_MIN); + $sql .= "', og_max='" . floatval($style->OG_MAX); + $sql .= "', fg_min='" . floatval($style->FG_MIN); + $sql .= "', fg_max='" . floatval($style->FG_MAX); + $sql .= "', ibu_min='" . floatval($style->IBU_MIN); + $sql .= "', ibu_max='" . floatval($style->IBU_MAX); + $sql .= "', color_min='" . floatval($style->COLOR_MIN); + $sql .= "', color_max='" . floatval($style->COLOR_MAX); + $sql .= "', carb_min='" . floatval($style->CARB_MIN); + $sql .= "', carb_max='" . floatval($style->CARB_MAX); + $sql .= "', abv_min='" . floatval($style->ABV_MIN); + $sql .= "', abv_max='" . floatval($style->ABV_MAX); if ($style->PROFILE) $sql .= "', profile='" . mysqli_real_escape_string($db, $style->PROFILE); if ($style->INGREDIENTS) @@ -429,14 +429,206 @@ -do_fermentables(); -do_hops(); -do_yeasts(); -do_miscs(); -do_waters(); -do_equipments(); -do_styles(); -do_mash(); + +function do_recipes() +{ + global $brouwhulp, $db; + $len_fermentables = 0; + $len_hops = 0; + $len_miscs = 0; + $len_waters = 0; + $len_mash = 0; + + echo " Start adding recipes to the database\n"; + $sql = "TRUNCATE TABLE recipes;"; + if (! $result = mysqli_query($db, $sql)) { + printf("Error: %s\n", mysqli_error($db)); + } + + $recipes= simplexml_load_file($brouwhulp . '/recipes.xml'); + + foreach ($recipes->RECIPE as $recipe) { + $sql = "INSERT INTO recipes SET name='" . mysqli_real_escape_string($db, $recipe->NAME); + if ($recipe->NOTES) + $sql .= "', notes='" . mysqli_real_escape_string($db, $recipe->NOTES); + if ($recipe->TYPE) + $sql .= "', type='" . mysqli_real_escape_string($db, $recipe->TYPE); + if ($recipe->BATCH_SIZE) + $sql .= "', batch_size='" . floatval($recipe->BATCH_SIZE); + if ($recipe->BOIL_TIME) + $sql .= "', boil_time='" . floatval($recipe->BOIL_TIME); + if ($recipe->EFFICIENCY) + $sql .= "', efficiency='" . floatval($recipe->EFFICIENCY); + if ($recipe->EST_OG) + $sql .= "', est_og='" . floatval($recipe->EST_OG); + if ($recipe->EST_FG) + $sql .= "', est_fg='" . floatval($recipe->EST_FG); + if ($recipe->EST_COLOR) + $sql .= "', est_color='" . floatval($recipe->EST_COLOR); + if ($recipe->COLOR_METHOD) + $sql .= "', color_method='" . mysqli_real_escape_string($db, $recipe->COLOR_METHOD); + if ($recipe->IBU) + $sql .= "', est_ibu='" . floatval($recipe->IBU); + if ($recipe->IBU_METHOD) + $sql .= "', ibu_method='" . mysqli_real_escape_string($db, $recipe->IBU_METHOD); + + if ($recipe->STYLE) { + if ($recipe->STYLE->NAME) + $sql .= "', style_name='" . mysqli_real_escape_string($db, $recipe->STYLE->NAME); + if ($recipe->STYLE->STYLE_LETTER) + $sql .= "', style_letter='" . mysqli_real_escape_string($db, $recipe->STYLE->STYLE_LETTER); + if ($recipe->STYLE->STYLE_GUIDE) + $sql .= "', style_guide='" . mysqli_real_escape_string($db, $recipe->STYLE->STYLE_GUIDE); + } + + /* + * Put the fermentables in a json array + */ + if ($recipe->FERMENTABLES) { + $fermentables = "["; + $comma = FALSE; + foreach ($recipe->FERMENTABLES->FERMENTABLE as $fermentable) { + if ($comma) + $fermentables .= ','; + $comma = TRUE; + $fermentables .= '{"name":"' . mysqli_real_escape_string($db, $fermentable->NAME) . '"'; + $fermentables .= ',"amount":' . floatval($fermentable->AMOUNT); + $fermentables .= ',"cost":' . floatval($fermentable->COST); + $fermentables .= ',"type":"' . mysqli_real_escape_string($db, $fermentable->TYPE) . '"'; + $fermentables .= ',"yield":' . floatval($fermentable->YIELD); + if ($fermentable->COLOR) { + $srm = floatval($fermentable->COLOR); + $ebc = srm_to_ebc($srm); + $fermentables .= ',"color":' . $ebc; + } + if ($fermentable->COARSE_FINE_DIFF) { + $fermentables .= ',"coarse_fine_diff":' . floatval($fermentable->COARSE_FINE_DIFF); + } + if ($fermentable->MOISTURE) { + $fermentables .= ',"moisture":' . floatval($fermentable->MOISTURE); + } + if ($fermentable->DIASTATIC_POWER) { + $fermentables .= ',"diastatic_power":' . floatval($fermentable->DIASTATIC_POWER); + } + if ($fermentable->PROTEIN) { + $fermentables .= ',"protein":' . floatval($fermentable->PROTEIN); + } + if ($fermentable->MAX_IN_BATCH) { + $fermentables .= ',"max_in_batch":' . floatval($fermentable->MAX_IN_BATCH); + } + if ($fermentable->GRAINTYPE) { + $fermentables .= ',"graintype":"' . mysqli_real_escape_string($db, $fermentable->GRAINTYPE) . '"'; + } + if ($fermentable->ADDED) { + $fermentables .= ',"added":"' . mysqli_real_escape_string($db, $fermentable->ADDED) . '"'; + } + if ($fermentable->DISSOLVED_PROTEIN) { + $fermentables .= ',"dissolved_protein":' . floatval($fermentable->DISSOLVED_PROTEIN); + } + ($fermentable->ADJUST_TO_TOTAL_100 == "TRUE") ? $fermentables .= ',"adjust_to_total_100":true' : $fermentables .= ',"adjust_to_total_100":false'; + if ($fermentable->DI_pH) { + $fermentables .= ',"di_ph":' . floatval($fermentable->DI_pH); + } + $fermentables .= "}"; + } + + $fermentables .= ']'; +// echo $fermentables . PHP_EOL; + $sql .= "', json_fermentables='" . $fermentables; + if (strlen($fermentables) > $len_fermentables) + $len_fermentables = strlen($fermentables); + } + + /* + * Put the hops in a json array + */ + if ($recipe->HOPS) { + $hops = "["; + $comma = FALSE; + foreach ($recipe->HOPS->HOP as $hop) { + if ($comma) + $hops .= ','; + $comma = TRUE; + $hops .= '{"name":"' . mysqli_real_escape_string($db, $hop->NAME) . '"'; + $hops .= ',"amount":' . floatval($hop->AMOUNT); + $hops .= ',"cost":' . floatval($hop->COST); + $hops .= ',"type":"' . mysqli_real_escape_string($db, $hop->TYPE) . '"'; + $hops .= ',"form":"' . mysqli_real_escape_string($db, $hop->FORM) . '"'; + $hops .= ',"use":"' . mysqli_real_escape_string($db, $hop->USE) . '"'; + if ($hop->TIME) + $hops .= ',"time":' . floatval($hop->TIME); + $hops .= ',"alpha":' . floatval($hop->ALPHA); + $hops .= ',"beta":' . floatval($hop->BETA); + $hops .= ',"hsi":' . floatval($hop->HSI); + $hops .= ',"humulene":' . floatval($hop->HUMULENE); + $hops .= ',"carophyllene":' . floatval($hop->CAROPHYLLENE); + $hops .= ',"cohumulone":' . floatval($hop->COHUMULONE); + $hops .= ',"myrcene":' . floatval($hop->MYRCENE); + if ($hop->TOTAL_OIL) + $hops .= ',"total_oil":' . floatval($hop->TOTAL_OIL); + $hops .= "}"; + } + + $hops .= ']'; +// echo $hops . PHP_EOL; + $sql .= "', json_hops='" . $hops; + if (strlen($hops) > $len_hops) + $len_hops = strlen($hops); + } + + /* + * Put the miscs in a json array + */ + if ($recipe->MISCS) { + $miscs = "["; + $comma = FALSE; + foreach ($recipe->MISCS->MISC as $misc) { + if ($comma) + $miscs .= ','; + $comma = TRUE; + $miscs .= '{"name":"' . mysqli_real_escape_string($db, $misc->NAME) . '"'; + $miscs .= ',"amount":' . floatval($misc->AMOUNT); + if ($misc->COST) + $miscs .= ',"cost":' . floatval($misc->COST); + $miscs .= ',"type":"' . mysqli_real_escape_string($db, $misc->TYPE) . '"'; + $miscs .= ',"use":"' . mysqli_real_escape_string($db, $misc->USE) . '"'; + ($misc->AMOUNT_IS_WEIGHT== "TRUE") ? $miscs .= ',"amount_is_weight":true' : $miscs.= ',"amount_is_weight":false'; + if ($misc->TIME) + $miscs .= ',"time":' . floatval($misc->TIME); + $miscs .= "}"; + } + + $miscs .= ']'; + echo $miscs . PHP_EOL; + $sql .= "', json_miscs='" . $miscs; + if (strlen($miscs) > $len_miscs) + $len_miscs = strlen($miscs); + } + + $sql .= "';"; + if (! $result = mysqli_query($db, $sql)) { + printf("Error: %s\n", mysqli_error($db)); + } + } + echo "Fermentables: " . $len_fermentables . PHP_EOL; + echo "Hops: " . $len_hops . PHP_EOL; + echo "Miscs: " . $len_miscs . PHP_EOL; + echo "Waters: " . $len_waters . PHP_EOL; + echo "Mash: " . $len_mash . PHP_EOL; +} + + + +//do_fermentables(); +//do_hops(); +//do_yeasts(); +//do_miscs(); +//do_waters(); +//do_equipments(); +//do_styles(); +//do_mash(); +do_recipes(); + mysqli_close($db); diff -r 94cd5ac04b6a -r bdd1ec9b9c06 www/includes/db_profile_styles.php --- a/www/includes/db_profile_styles.php Wed Aug 29 23:13:13 2018 +0200 +++ b/www/includes/db_profile_styles.php Thu Aug 30 22:22:09 2018 +0200 @@ -10,7 +10,7 @@ } // get data and store in a json array -$query = "SELECT * FROM profile_styles ORDER BY name"; +$query = "SELECT * FROM profile_styles ORDER BY style_guide,style_letter,name"; if (isset($_GET['insert'])) { // INSERT COMMAND $sql = "INSERT INTO `profile_styles` SET name='" . mysqli_real_escape_string($connect, $_GET['name']); diff -r 94cd5ac04b6a -r bdd1ec9b9c06 www/includes/global.inc.php --- a/www/includes/global.inc.php Wed Aug 29 23:13:13 2018 +0200 +++ b/www/includes/global.inc.php Thu Aug 30 22:22:09 2018 +0200 @@ -93,9 +93,9 @@
  • Systemen