Start recipes import and menus.

Thu, 30 Aug 2018 22:22:09 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Thu, 30 Aug 2018 22:22:09 +0200
changeset 48
bdd1ec9b9c06
parent 47
94cd5ac04b6a
child 49
4d27a7fb1265

Start recipes import and menus.

www/import/from_brouwhulp.php file | annotate | diff | comparison | revisions
www/includes/db_profile_styles.php file | annotate | diff | comparison | revisions
www/includes/global.inc.php file | annotate | diff | comparison | revisions
--- 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);
 
--- 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']);
--- 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 @@
        <li>Systemen
 	<ul>
 <?php
-$mysqli = new mysqli(DBASE_HOST,DBASE_USER,DBASE_PASS,DBASE_NAME);
-$result = $mysqli->query("SELECT uuid,node,online,net_address FROM mon_nodes ORDER BY node");
-while($row = $result->fetch_array(MYSQLI_ASSOC)) {
+$connect = mysqli_connect(DBASE_HOST,DBASE_USER,DBASE_PASS,DBASE_NAME);
+$result = mysqli_query($connect, "SELECT uuid,node,online,net_address FROM mon_nodes ORDER BY node");
+while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
     echo '         <li><a href="mon_node.php?uuid='.$row['uuid'].'">'.$row['node'].'</a></li>'.PHP_EOL;
 }
 mysqli_free_result($result);
@@ -105,8 +105,8 @@
        <li>Klimaatkasten
 	<ul>
 <?php
-$result = $mysqli->query("SELECT uuid,node,alias,online,mode FROM mon_fermenters ORDER BY node,alias");
-while($row = $result->fetch_array(MYSQLI_ASSOC)) {
+$result = mysqli_query($connect, "SELECT uuid,node,alias,online,mode FROM mon_fermenters ORDER BY node,alias");
+while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
     echo '         <li><a href="mon_fermenter.php?uuid='.$row['uuid'].'">'.$row['node'].'/'.$row['alias'].'</a></li>'.PHP_EOL;
 }
 mysqli_free_result($result);
@@ -118,6 +118,43 @@
      <li>Productie
      </li>
      <li>Recepten
+      <ul>
+<?php
+$result = mysqli_query($connect, "SELECT DISTINCT style_guide FROM recipes ORDER BY style_guide");
+while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
+    $guide = $row['style_guide'];
+    echo '       <li>' . $guide . PHP_EOL;
+    echo '        <ul>'.PHP_EOL;
+    $result2 = mysqli_query($connect, "SELECT DISTINCT style_letter FROM recipes WHERE style_guide='".$guide."' ORDER BY style_letter");
+    while($row2 = mysqli_fetch_array($result2, MYSQLI_ASSOC)) {
+	$letter = $row2['style_letter'];
+	echo '         <li>' . $letter . PHP_EOL;
+        echo '          <ul>'.PHP_EOL;
+	$result3 = mysqli_query($connect, "SELECT DISTINCT style_name FROM recipes WHERE style_guide='".$guide."' and style_letter='".$letter."' ORDER BY style_name");
+	while ($row3 =  mysqli_fetch_array($result3, MYSQLI_ASSOC)) {
+	    $name = $row3['style_name'];
+	    echo '           <li>' . $name . PHP_EOL;
+	    echo '            <ul>'.PHP_EOL;
+	    $result4 = mysqli_query($connect, "SELECT DISTINCT record,name FROM recipes WHERE style_guide='".$guide."' and style_letter='".$letter."' and style_name='".$name."'ORDER BY name");
+	    while ($row4 =  mysqli_fetch_array($result4, MYSQLI_ASSOC)) {
+		echo '             <li><a href="recipe.php?record='.$row4['record'].'">' . $row4['name'] . '</a></li>' . PHP_EOL;
+	    }
+	    mysqli_free_result($result4);
+	    echo '            </ul>'.PHP_EOL;
+	    echo '           </li>' . PHP_EOL;
+	}
+	mysqli_free_result($result3);
+	echo '          </ul>'.PHP_EOL;
+	echo '         </li>'.PHP_EOL;
+    }
+    mysqli_free_result($result2);
+    echo '        </ul>'.PHP_EOL;
+    echo '       </li>'.PHP_EOL;
+}
+mysqli_free_result($result);
+?>
+       <li>Nieuw</li>
+      </ul>
      </li>
      <li>Inventaris
       <ul>

mercurial