Added xml import for fermentables, hops, miscs, yeasts and styles. Fixed update IBU calculation in the editor hop popups.

Sun, 03 Mar 2019 13:26:28 +0100

author
Michiel Broek <mbroek@mbse.eu>
date
Sun, 03 Mar 2019 13:26:28 +0100
changeset 311
f6fafccd8a6d
parent 310
b316b88ebe12
child 312
ec26ad6ff509

Added xml import for fermentables, hops, miscs, yeasts and styles. Fixed update IBU calculation in the editor hop popups.

www/Makefile file | annotate | diff | comparison | revisions
www/import_ingredients.php file | annotate | diff | comparison | revisions
www/js/import_ingredients.js file | annotate | diff | comparison | revisions
www/js/inv_fermentables.js file | annotate | diff | comparison | revisions
www/js/inv_hops.js file | annotate | diff | comparison | revisions
www/js/inv_miscs.js file | annotate | diff | comparison | revisions
www/js/inv_yeasts.js file | annotate | diff | comparison | revisions
www/js/prod_edit.js file | annotate | diff | comparison | revisions
www/js/profile_styles.js file | annotate | diff | comparison | revisions
www/js/rec_edit.js file | annotate | diff | comparison | revisions
www/upl_fermentables.php file | annotate | diff | comparison | revisions
www/upl_hops.php file | annotate | diff | comparison | revisions
www/upl_miscs.php file | annotate | diff | comparison | revisions
www/upl_styles.php file | annotate | diff | comparison | revisions
www/upl_yeasts.php file | annotate | diff | comparison | revisions
--- a/www/Makefile	Sat Mar 02 19:21:50 2019 +0100
+++ b/www/Makefile	Sun Mar 03 13:26:28 2019 +0100
@@ -6,7 +6,7 @@
 SRC		= cmd_fermenter.php config.php.dist crontasks.php favicon.ico gen_about.php \
 		  getbrewlog.php getfermentablesources.php getfermenter.php getfermentlog.php \
 		  gethopsources.php getmiscsources.php getnode.php getwatersources.php \
-		  getyeastsources.php index.php \
+		  getyeastsources.php import_ingredients.php index.php \
 		  inv_equipments.php inv_fermentables.php inv_hops.php inv_instock.php \
 		  inv_miscs.php inv_suppliers.php inv_waters.php inv_yeasts.php \
 		  log_brew.php log_fermentation.php \
@@ -18,7 +18,8 @@
 		  profile_water.php \
 		  rec_beerxml.php rec_duplicate.php rec_edit.php rec_export.php rec_import.php \
 		  rec_main.php rec_new.php rec_print.php rec_toproduct.php \
-		  upl_brew.php upl_recipe.php version.php
+		  upl_brew.php upl_fermentables.php upl_hops.php upl_miscs.php upl_recipe.php \
+		  upl_styles.php upl_yeasts.php version.php
 SUB		= version.php.in images/* css/* jqwidgets/* jqwidgets/styles/* \
 		  jqwidgets/styles/images/* jqwidgets/globalization/* js/* \
 		  includes/* fpdf/* import/*
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/www/import_ingredients.php	Sun Mar 03 13:26:28 2019 +0100
@@ -0,0 +1,38 @@
+<?php
+require_once($_SERVER['DOCUMENT_ROOT'].'/includes/global.inc.php');
+if ($my_select == "fermentables" )
+	page_header('Vergistbare ingredi&euml;nten import', 'import_ingredients');
+else if ($my_select == "hops" )
+	page_header('Hoppen import', 'import_ingredients');
+else if ($my_select == "miscs" )
+	page_header('Diverse ingredi&euml;nten import', 'import_ingredients');
+else if ($my_select == "yeasts")
+	page_header('Gisten import', 'import_ingredients');
+else if ($my_select == "styles")
+	page_header('Bierstijlen import', 'import_ingredients');
+else
+	page_header('Bummer', '');
+?>
+
+   <div id="MainPanel">
+    <div style="float: left; margin-left: 240px; margin-top: 50px;">
+<?php
+     if ($my_select == "fermentables")
+	echo '<div align="center">Vergistbare ingredi&euml;nten xml bestand upload.</div><br>' . PHP_EOL;
+     else if ($my_select == "hops")
+	echo '<div align="center">Hoppen xml bestand upload.</div><br>' . PHP_EOL;
+     else if ($my_select == "miscs")
+	echo '<div align="center">Diverse ingredi&euml;nten xml bestand upload.</div><br>' . PHP_EOL;
+     else if ($my_select == "yeasts")
+	echo '<div align="center">Gisten xml bestand upload.</div><br>' . PHP_EOL;
+     else if ($my_select == "styles")
+	echo '<div align="center">Bierstijlen xml bestand upload.</div><br>' . PHP_EOL;
+?>
+     <div id="eventsPanel"> </div>
+     <div style="float: left; margin-top: 10px;" id="jqxFileUpload"> </div>
+    </div>
+   </div>
+
+<?php
+page_footer();
+?>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/www/js/import_ingredients.js	Sun Mar 03 13:26:28 2019 +0100
@@ -0,0 +1,69 @@
+/*****************************************************************************
+ * Copyright (C) 2019
+ *
+ * Michiel Broek <mbroek at mbse dot eu>
+ *
+ * This file is part of BMS
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2, or (at your option) any
+ * later version.
+ *
+ * BrewCloud is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with ThermFerm; see the file COPYING.  If not, write to the Free
+ * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ *****************************************************************************/
+
+
+$(document).ready(function () {
+
+	var	url = '';
+
+	if (my_select == 'fermentables')
+		url = 'upl_fermentables.php';
+	else if (my_select == 'hops')
+		url = 'upl_hops.php';
+	else if (my_select == 'miscs')
+		url = 'upl_miscs.php';
+	else if (my_select == 'yeasts')
+		url = 'upl_yeasts.php';
+	else if (my_select == "styles")
+		url = 'upl_styles.php';
+
+	$('#jqxFileUpload').jqxFileUpload({
+		width: 300,
+		browseTemplate: 'success',
+		cancelTemplate: 'inverse',
+		uploadTemplate: 'primary',
+		theme: theme,
+		multipleFilesUpload: false,
+		accept: 'application/xml',
+		uploadUrl: url,
+		fileInputName: 'fileToUpload'
+	});
+	$('#eventsPanel').jqxPanel({
+		width: 800,
+		height: 200,
+		theme: theme
+	});
+	$('#jqxFileUpload').on('select', function (event) {
+		var args = event.args;
+		var fileName = args.file;
+		var fileSize = args.size;
+		$('#eventsPanel').jqxPanel('clearcontent');
+		$('#eventsPanel').jqxPanel('append', '<strong>' + event.type + ':</strong> ' + fileName + '  size: ' + fileSize + '<br />');
+	});
+	$('#jqxFileUpload').on('uploadEnd', function (event) {
+		var args = event.args;
+		var fileName = args.file;
+		var serverResponce = args.response;
+		$('#eventsPanel').jqxPanel('append', '<strong>' + event.type + ':</strong> ontvangen ' + fileName + '<br />' + serverResponce + '<br />');
+	});
+
+});
--- a/www/js/inv_fermentables.js	Sat Mar 02 19:21:50 2019 +0100
+++ b/www/js/inv_fermentables.js	Sun Mar 03 13:26:28 2019 +0100
@@ -200,9 +200,12 @@
 		renderstatusbar: function (statusbar) {
 			var container = $("<div style='overflow: hidden; position: relative; margin: 5px;'></div>");
 			var addButton = $("<div style='float: right; margin-right: 15px;'><img style='position: relative; margin-top: 2px;' src='images/add.png'/><span style='margin-left: 4px; position: relative; top: -3px;'>Nieuw</span></div>");
+			var impButton = $("<div style='float: right; margin-right: 50px;'><img style='position: relative; margin-top: 2px;' src='images/add.png'/><span style='margin-left: 4px; position: relative; top: -3px;'>Import</span></div>");
 			container.append(addButton);
+			container.append(impButton);
 			statusbar.append(container);
 			addButton.jqxButton({ theme: theme, width: 90, height: 20 });
+			impButton.jqxButton({ theme: theme, width: 90, height: 20 });
 			// add new row.
 			addButton.click(function (event) {
 				editrow = -1;
@@ -233,6 +236,10 @@
 				$("#tht_date").val('');
 				$("#popupWindow").jqxWindow('open');
 			});
+			impButton.click(function (event) {
+				var url="import_ingredients.php?select=fermentables";
+				window.location.href = url;
+			});
 		},
 		filterable: true,
 		filtermode: 'excel',
--- a/www/js/inv_hops.js	Sat Mar 02 19:21:50 2019 +0100
+++ b/www/js/inv_hops.js	Sun Mar 03 13:26:28 2019 +0100
@@ -183,9 +183,12 @@
 		renderstatusbar: function (statusbar) {
 			var container = $("<div style='overflow: hidden; position: relative; margin: 5px;'></div>");
 			var addButton = $("<div style='float: right; margin-right: 15px;'><img style='position: relative; margin-top: 2px;' src='images/add.png'/><span style='margin-left: 4px; position: relative; top: -3px;'>Nieuw</span></div>");
+			var impButton = $("<div style='float: right; margin-right: 50px;'><img style='position: relative; margin-top: 2px;' src='images/add.png'/><span style='margin-left: 4px; position: relative; top: -3px;'>Import</span></div>");
 			container.append(addButton);
+			container.append(impButton);
 			statusbar.append(container);
 			addButton.jqxButton({ theme: theme, width: 90, height: 20 });
+			impButton.jqxButton({ theme: theme, width: 90, height: 20 });
 			// add new row.
 			addButton.click(function (event) {
 				editrow = -1;
@@ -211,6 +214,10 @@
 				$("#total_oil").val(0);
 				$("#popupWindow").jqxWindow('open');
 			});
+			impButton.click(function (event) {
+				var url="import_ingredients.php?select=hops";
+				window.location.href = url;
+			});
 		},
 		filterable: true,
 		filtermode: 'excel',
--- a/www/js/inv_miscs.js	Sat Mar 02 19:21:50 2019 +0100
+++ b/www/js/inv_miscs.js	Sun Mar 03 13:26:28 2019 +0100
@@ -178,9 +178,12 @@
 		renderstatusbar: function (statusbar) {
 			var container = $("<div style='overflow: hidden; position: relative; margin: 5px;'></div>");
 			var addButton = $("<div style='float: right; margin-right: 15px;'><img style='position: relative; margin-top: 2px;' src='images/add.png'/><span style='margin-left: 4px; position: relative; top: -3px;'>Nieuw</span></div>");
+			var impButton = $("<div style='float: right; margin-right: 50px;'><img style='position: relative; margin-top: 2px;' src='images/add.png'/><span style='margin-left: 4px; position: relative; top: -3px;'>Import</span></div>");
 			container.append(addButton);
+			container.append(impButton);
 			statusbar.append(container);
 			addButton.jqxButton({ theme: theme, width: 90, height: 20 });
+			impButton.jqxButton({ theme: theme, width: 90, height: 20 });
 			// add new row.
 			addButton.click(function (event) {
 				editrow = -1;
@@ -199,6 +202,10 @@
 				$("#tht_date").val('');
 				$("#popupWindow").jqxWindow('open');
 			});
+			impButton.click(function (event) {
+				var url="import_ingredients.php?select=miscs";
+				window.location.href = url;
+			});
 		},
 		filterable: true,
 		filtermode: 'excel',
--- a/www/js/inv_yeasts.js	Sat Mar 02 19:21:50 2019 +0100
+++ b/www/js/inv_yeasts.js	Sun Mar 03 13:26:28 2019 +0100
@@ -204,9 +204,12 @@
 		renderstatusbar: function (statusbar) {
 			var container = $("<div style='overflow: hidden; position: relative; margin: 5px;'></div>");
 			var addButton = $("<div style='float: right; margin-right: 15px;'><img style='position: relative; margin-top: 2px;' src='images/add.png'/><span style='margin-left: 4px; position: relative; top: -3px;'>Nieuw</span></div>");
+			var impButton = $("<div style='float: right; margin-right: 50px;'><img style='position: relative; margin-top: 2px;' src='images/add.png'/><span style='margin-left: 4px; position: relative; top: -3px;'>Import</span></div>");
 			container.append(addButton);
+			container.append(impButton);
 			statusbar.append(container);
 			addButton.jqxButton({ theme: theme, width: 90, height: 20 });
+			impButton.jqxButton({ theme: theme, width: 90, height: 20 });
 			// add new row.
 			addButton.click(function (event) {
 				editrow = -1;
@@ -230,6 +233,10 @@
 				$("#cells").val(1);
 				$("#popupWindow").jqxWindow('open');
 			});
+			impButton.click(function (event) {
+				var url="import_ingredients.php?select=yeasts";
+				window.location.href = url;
+			});
 		},
 		filterable: true,
 		filtermode: 'excel',
--- a/www/js/prod_edit.js	Sat Mar 02 19:21:50 2019 +0100
+++ b/www/js/prod_edit.js	Sun Mar 03 13:26:28 2019 +0100
@@ -4449,6 +4449,9 @@
 			parseFloat(rowdata.h_alpha), $("#ibu_method").val()
 		);
 		rowdata.h_amount = amount;
+		var ibu = toIBU(rowdata.h_useat, rowdata.h_form, preboil_sg, parseFloat($("#batch_size").jqxNumberInput('decimal')),
+				parseFloat(rowdata.h_amount), parseFloat(rowdata.h_time), parseFloat(rowdata.h_alpha), $("#ibu_method").val());
+		$("#wh_ibu").val(ibu);
 		calcIBUs();
 	});
 	$("#wh_ibu").jqxNumberInput( Show1dec );
--- a/www/js/profile_styles.js	Sat Mar 02 19:21:50 2019 +0100
+++ b/www/js/profile_styles.js	Sun Mar 03 13:26:28 2019 +0100
@@ -182,9 +182,12 @@
 		renderstatusbar: function (statusbar) {
 			var container = $("<div style='overflow: hidden; position: relative; margin: 5px;'></div>");
 			var addButton = $("<div style='float: right; margin-right: 15px;'><img style='position: relative; margin-top: 2px;' src='images/add.png'/><span style='margin-left: 4px; position: relative; top: -3px;'>Nieuw</span></div>");
+			var impButton = $("<div style='float: right; margin-right: 50px;'><img style='position: relative; margin-top: 2px;' src='images/add.png'/><span style='margin-left: 4px; position: relative; top: -3px;'>Import</span></div>");
 			container.append(addButton);
+			container.append(impButton);
 			statusbar.append(container);
 			addButton.jqxButton({ theme: theme, width: 90, height: 20 });
+			impButton.jqxButton({ theme: theme, width: 90, height: 20 });
 			// add new row.
 			addButton.click(function (event) {
 				editrow = -1;
@@ -212,6 +215,10 @@
 				$("#examples").val('');
 				$("#popupWindow").jqxWindow('open');
 			});
+			impButton.click(function (event) {
+				var url="import_ingredients.php?select=styles";
+				window.location.href = url;
+			});
 		},
 		filterable: true,
 		filtermode: 'excel',
--- a/www/js/rec_edit.js	Sat Mar 02 19:21:50 2019 +0100
+++ b/www/js/rec_edit.js	Sun Mar 03 13:26:28 2019 +0100
@@ -3047,6 +3047,9 @@
 			parseFloat(rowdata.h_alpha), $("#ibu_method").val()
 		);
 		rowdata.h_amount = amount;
+		var ibu = toIBU(rowdata.h_useat, rowdata.h_form, preboil_sg, parseFloat($("#batch_size").jqxNumberInput('decimal')),
+				parseFloat(rowdata.h_amount), parseFloat(rowdata.h_time), parseFloat(rowdata.h_alpha), $("#ibu_method").val());
+		$("#wh_ibu").val(ibu);
 		calcIBUs();
 	});
 	$("#wh_ibu").jqxNumberInput( Show1dec );
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/www/upl_fermentables.php	Sun Mar 03 13:26:28 2019 +0100
@@ -0,0 +1,152 @@
+<?php
+require_once('config.php');
+require("version.php");
+require("includes/formulas.php");
+
+
+$target_dir = "tmp/";
+$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
+$uploadOk = 1;
+$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
+
+// Check if file already exists
+if (file_exists($target_file)) {
+	echo "Fout 1: bestand bestaat al. ";
+	$uploadOk = 0;
+}
+// Check file size
+if ($_FILES["fileToUpload"]["size"] > 500000 && $uploadOk) {
+	echo "Fout 2: het bestand is te groot. ";
+	$uploadOk = 0;
+}
+// Allow certain file formats
+if ($imageFileType != "xml" && $uploadOk) {
+	echo "Fout 3: alleen XML bestanden toegestaan. ";
+	$uploadOk = 0;
+}
+// Check if $uploadOk is set to 0 by an error
+if ($uploadOk == 0) {
+	exit;
+}
+
+if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
+	echo "Verwerken bestand ". basename( $_FILES["fileToUpload"]["name"]). "<br />";
+} else {
+	echo "Fout 4: er ging iets fout met de upload.";
+	exit;
+}
+
+
+$db = mysqli_connect(DBASE_HOST, DBASE_USER, DBASE_PASS, DBASE_NAME);
+if (! $db) {
+	echo "Fout 5: ".mysqli_connect_errno()." ".mysqli_connect_error();
+	exit;
+}
+mysqli_set_charset($db, "utf8" );
+date_default_timezone_set('Europe/Amsterdam');
+
+
+$imported = 0;
+$myfermentables= simplexml_load_file($target_file);
+
+
+foreach ($myfermentables->FERMENTABLE as $fermentable) {
+
+	$sql  = "INSERT INTO inventory_fermentables SET name='" . mysqli_real_escape_string($db, $fermentable->NAME);
+	if ($fermentable->TYPE == 'Grain')
+		$sql .= "', type='0";
+	else if ($fermentable->TYPE == 'Sugar')
+		$sql .= "', type='1";
+	else if ($fermentable->TYPE == 'Extract')
+		$sql .= "', type='2";
+	else if ($fermentable->TYPE == 'Dry extract')
+		$sql .= "', type='3";
+	else if ($fermentable->TYPE == 'Adjunct')
+		$sql .= "', type='4";
+	else
+		echo "Unknown TYPE " . $fermentable->TYPE . "<br />";
+	if ($fermentable->YIELD)
+		$sql .= "', yield='" . floatval($fermentable->YIELD);
+	if ($fermentable->COLOR) {
+		$sql .= "', color='" . srm_to_ebc(floatval($fermentable->COLOR));
+	}
+	($fermentable->ADD_AFTER_BOIL == "TRUE") ? $sql .= "', add_after_boil='1" : $sql .= "', add_after_boil='0";
+	if ($fermentable->ADDED == 'Mash')
+		$sql .= "', added='0";
+	else if ($fermentable->ADDED == 'Boil')
+		$sql .= "', added='1";
+	else if ($fermentable->ADDED == 'Fermentation')
+		$sql .= "', added='2";
+	else if ($fermentable->ADDED == 'Lagering')
+		$sql .= "', added='3";
+	else if ($fermentable->ADDED == 'Bottle')
+		$sql .= "', added='4";
+	else
+		echo "Unknown ADDED " . $fermentable->ADDED . "<br />";
+
+	$sql .= "', origin='" . mysqli_real_escape_string($db, $fermentable->ORIGIN);
+	$sql .= "', supplier='" . mysqli_real_escape_string($db, $fermentable->SUPPLIER);
+	$sql .= "', notes='" . mysqli_real_escape_string($db, $fermentable->NOTES);
+	if ($fermentable->COARSE_FINE_DIFF)
+		$sql .= "', coarse_fine_diff='" . floatval($fermentable->COARSE_FINE_DIFF);
+	if ($fermentable->MOISTURE)
+		$sql .= "', moisture='" . floatval($fermentable->MOISTURE);
+	if ($fermentable->DIASTATIC_POWER)
+		$sql .= "', diastatic_power='" . floatval($fermentable->DIASTATIC_POWER);
+	if ($fermentable->PROTEIN)
+		$sql .= "', protein='" . floatval($fermentable->PROTEIN);
+	if ($fermentable->DISSOLVED_PROTEIN)
+		$sql .= "', dissolved_protein='" . floatval($fermentable->DISSOLVED_PROTEIN);
+	if ($fermentable->MAX_IN_BATCH)
+		$sql .= "', max_in_batch='" . floatval($fermentable->MAX_IN_BATCH);
+	($fermentable->RECOMMEND_MASH == "TRUE") ? $sql .= "', recommend_mash='1" : $sql .= "', recommend_mash='0";
+	($fermentable->ALWAYS_ON_STOCK == "TRUE") ? $sql .= "', always_on_stock='1" : $sql .= "', always_on_stock='0";
+	if ($fermentable->INVENTORY)
+		$sql .= "', inventory='" . floatval($fermentable->INVENTORY);
+	if ($fermentable->COST)
+		$sql .= "', cost='" . floatval($fermentable->COST);
+
+	/*
+	 * These are not beerxml standard:
+	 */
+	if ($fermentable->DI_pH)
+		$sql .= "', di_ph='" . floatval($fermentable->DI_pH);
+	if ($fermentable->{'ACID_TO_pH_5.7'})
+		$sql .= "', acid_to_ph_57='" . floatval($fermentable->{'ACID_TO_pH_5.7'});
+	if ($fermentable->GRAINTYPE == 'Base')
+		$sql .= "', graintype='0";
+	else if ($fermentable->GRAINTYPE == 'Roast')
+		$sql .= "', graintype='1";
+	else if ($fermentable->GRAINTYPE == 'Crystal')
+		$sql .= "', graintype='2";
+	else if ($fermentable->GRAINTYPE == 'Kilned')
+		$sql .= "', graintype='3";
+	else if ($fermentable->GRAINTYPE == 'Sour malt')
+		$sql .= "', graintype='4";
+	else if ($fermentable->GRAINTYPE == 'Special')
+		$sql .= "', graintype='5";
+	else if ($fermentable->GRAINTYPE == 'No malt')
+		$sql .= "', graintype='6";
+	else
+		echo "Unknown GRAINTYPE " . $fermentable->GRAINTYPE . "<br />";
+	$sql .= "';";
+	if (! $result = mysqli_query($db, $sql)) {
+		echo "Fout 8: " . mysqli_error($db) . "<br />";
+	} else {
+		echo "+ " . $fermentable->NAME . "<br />";
+		$imported++;
+	}
+}
+
+if ($imported == 0) {
+	echo "Fout 7: geen vergistbare ingredienten in dit bestand.<br />";
+} else {
+	echo $imported . " ingredienten toegevoegd.<br />";
+}
+
+
+
+// Don't clutter the upload directory.
+unlink($target_file);
+
+?>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/www/upl_hops.php	Sun Mar 03 13:26:28 2019 +0100
@@ -0,0 +1,123 @@
+<?php
+require_once('config.php');
+require("version.php");
+require("includes/formulas.php");
+
+
+$target_dir = "tmp/";
+$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
+$uploadOk = 1;
+$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
+
+// Check if file already exists
+if (file_exists($target_file)) {
+	echo "Fout 1: bestand bestaat al. ";
+	$uploadOk = 0;
+}
+// Check file size
+if ($_FILES["fileToUpload"]["size"] > 500000 && $uploadOk) {
+	echo "Fout 2: het bestand is te groot. ";
+	$uploadOk = 0;
+}
+// Allow certain file formats
+if ($imageFileType != "xml" && $uploadOk) {
+	echo "Fout 3: alleen XML bestanden toegestaan. ";
+	$uploadOk = 0;
+}
+// Check if $uploadOk is set to 0 by an error
+if ($uploadOk == 0) {
+	exit;
+}
+
+if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
+	echo "Verwerken bestand ". basename( $_FILES["fileToUpload"]["name"]). "<br />";
+} else {
+	echo "Fout 4: er ging iets fout met de upload.";
+	exit;
+}
+
+
+$db = mysqli_connect(DBASE_HOST, DBASE_USER, DBASE_PASS, DBASE_NAME);
+if (! $db) {
+	echo "Fout 5: ".mysqli_connect_errno()." ".mysqli_connect_error();
+	exit;
+}
+mysqli_set_charset($db, "utf8" );
+date_default_timezone_set('Europe/Amsterdam');
+
+
+$imported = 0;
+$hops = simplexml_load_file($target_file);
+
+
+foreach ($hops->HOP as $hop) {
+
+	$sql  = "INSERT INTO inventory_hops SET name='" . mysqli_real_escape_string($db, $hop->NAME);
+	if ($hop->ALPHA)
+		$sql .= "', alpha='" . floatval($hop->ALPHA);
+	if ($hop->BETA)
+		$sql .= "', beta='" . floatval($hop->BETA);
+	if ($hop->HUMULENE)
+		$sql .= "', humulene='" . floatval($hop->HUMULENE);
+	if ($hop->CAROPHYLLENE)
+		$sql .= "', caryophyllene='" . floatval($hop->CAROPHYLLENE);
+	if ($hop->COHUMULONE)
+		$sql .= "', cohumulone='" . floatval($hop->COHUMULONE);
+	if ($hop->MYRCENE)
+		$sql .= "', myrcene='" . floatval($hop->MYRCENE);
+	if ($hop->HSI)
+		$sql .= "', hsi='" . floatval($hop->HSI);
+
+	if ($hop->TYPE == 'Bittering')
+		$sql .= "', type='0";
+	else if ($hop->TYPE == 'Aroma')
+		$sql .= "', type='1";
+	else if ($hop->TYPE == 'Both')
+		$sql .= "', type='2";
+	else
+		echo "Unknown TYPE " . $hop->TYPE . "<br />";
+
+	if ($hop->FORM == 'Pellet')
+		$sql .= "', form='0";
+	else if ($hop->FORM == 'Plug')
+		$sql .= "', form='1";
+	else if ($hop->FORM == 'Leaf')
+		$sql .= "', form='2";
+	else
+		echo "Unknown FORM " . $hop->FORM . "<br />";
+
+	$sql .= "', notes='" . mysqli_real_escape_string($db, $hop->NOTES);
+	$sql .= "', origin='" . mysqli_real_escape_string($db, $hop->ORIGIN);
+	$sql .= "', substitutes='" . mysqli_real_escape_string($db, $hop->SUBSTITUTES);
+	($hop->ALWAYS_ON_STOCK == 'TRUE') ? $sql .= "', always_on_stock='1" : $sql .= "', always_on_stock='0";
+	if ($hop->INVENTORY)
+		$sql .= "', inventory='" . floatval($hop->INVENTORY) / 1000.0;
+	if ($hop->COST)
+		$sql .= "', cost='" . floatval($hop->COST);
+	if ($hop->TOTAL_OIL)
+		$sql .= "', total_oil='" . floatval($hop->TOTAL_OIL);
+	if ($hop->HARVEST_DATE) {
+		$date = substr($hop->HARVEST_DATE, 6, 4).'-'.substr($hop->HARVEST_DATE, 3, 2).'-'.substr($hop->HARVEST_DATE, 0, 2);
+		$sql .= "', production_date='" . $date;
+	}
+	$sql .= "';";
+	if (! $result = mysqli_query($db, $sql)) {
+		echo "Fout 8: " . mysqli_error($db) . "<br />";
+	} else {
+		echo "+ " . $hop->NAME . "<br />";
+		$imported++;
+	}
+}
+
+if ($imported == 0) {
+	echo "Fout 7: geen hoppen in dit bestand.<br />";
+} else {
+	echo $imported . " hoppen toegevoegd.<br />";
+}
+
+
+
+// Don't clutter the upload directory.
+unlink($target_file);
+
+?>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/www/upl_miscs.php	Sun Mar 03 13:26:28 2019 +0100
@@ -0,0 +1,120 @@
+<?php
+require_once('config.php');
+require("version.php");
+require("includes/formulas.php");
+
+
+$target_dir = "tmp/";
+$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
+$uploadOk = 1;
+$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
+
+// Check if file already exists
+if (file_exists($target_file)) {
+	echo "Fout 1: bestand bestaat al. ";
+	$uploadOk = 0;
+}
+// Check file size
+if ($_FILES["fileToUpload"]["size"] > 500000 && $uploadOk) {
+	echo "Fout 2: het bestand is te groot. ";
+	$uploadOk = 0;
+}
+// Allow certain file formats
+if ($imageFileType != "xml" && $uploadOk) {
+	echo "Fout 3: alleen XML bestanden toegestaan. ";
+	$uploadOk = 0;
+}
+// Check if $uploadOk is set to 0 by an error
+if ($uploadOk == 0) {
+	exit;
+}
+
+if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
+	echo "Verwerken bestand ". basename( $_FILES["fileToUpload"]["name"]). "<br />";
+} else {
+	echo "Fout 4: er ging iets fout met de upload.";
+	exit;
+}
+
+
+$db = mysqli_connect(DBASE_HOST, DBASE_USER, DBASE_PASS, DBASE_NAME);
+if (! $db) {
+	echo "Fout 5: ".mysqli_connect_errno()." ".mysqli_connect_error();
+	exit;
+}
+mysqli_set_charset($db, "utf8" );
+date_default_timezone_set('Europe/Amsterdam');
+
+
+$imported = 0;
+$miscs = simplexml_load_file($target_file);
+
+foreach ($miscs->MISC as $misc) {
+
+	$sql  = "INSERT INTO inventory_miscs SET name='" . mysqli_real_escape_string($db, $misc->NAME);
+	if ($misc->NOTES)
+		$sql .= "', notes='" . mysqli_real_escape_string($db, $misc->NOTES);
+
+	if ($misc->TYPE == 'Spice')
+		$sql .= "', type='0";
+	else if ($misc->TYPE == 'Herb')
+		$sql .= "', type='1";
+	else if ($misc->TYPE == 'Flavor')
+		$sql .= "', type='2";
+	else if ($misc->TYPE == 'Fining')
+		$sql .= "', type='3";
+	else if ($misc->TYPE == 'Water agent')
+		$sql .= "', type='4";
+	else if ($misc->TYPE == 'Yeast nutrient')
+		$sql .= "', type='5";
+	else if ($misc->TYPE == 'Other')
+		$sql .= "', type='6";
+	else
+		echo "Unknown TYPE " . $misc->TYPE . "<br />";
+
+	if ($misc->USE == 'Starter')
+		$sql .= "', use_use='0";
+	else if ($misc->USE == 'Mash')
+		$sql .= "', use_use='1";
+	else if ($misc->USE == 'Boil')
+		$sql .= "', use_use='2";
+	else if ($misc->USE == 'Primary')
+		$sql .= "', use_use='3";
+	else if ($misc->USE == 'Secondary')
+		$sql .= "', use_use='4";
+	else if ($misc->USE == 'Bottling')
+		$sql .= "', use_use='5";
+	else
+		echo "Unknown USE " . $misc->USE . "<br />";
+
+	$sql .= "', time='" . $misc->TIME;
+	($misc->AMOUNT_IS_WEIGHT == 'TRUE') ? $sql .= "', amount_is_weight='1" : $sql .= "', amount_is_weight='0";
+	if ($misc->USE_FOR)
+		$sql .= "', use_for='" . mysqli_real_escape_string($db, $misc->USE_FOR);
+	if ($misc->ALWAYS_ON_STOCK)
+		($misc->ALWAYS_ON_STOCK == 'TRUE') ? $sql .= "', always_on_stock='1" : $sql .= "', always_on_stock='0";
+	if ($misc->INVENTORY)
+		$sql .= "', inventory='" . floatval($misc->INVENTORY) / 1000.0;
+	if ($misc->COST)
+		$sql .= "', cost='" . floatval($misc->COST);
+	$sql .= "';";
+	if (! $result = mysqli_query($db, $sql)) {
+		echo "Fout 8: " . mysqli_error($db) . "<br />";
+	} else {
+		echo "+ " . $misc->NAME . "<br />";
+		$imported++;
+	}
+}
+
+if ($imported == 0) {
+	echo "Fout 7: geen diverse ingredienten in dit bestand.<br />";
+} else {
+	echo $imported . " diverse ingredienten toegevoegd.<br />";
+}
+
+
+
+// Don't clutter the upload directory.
+unlink($target_file);
+
+?>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/www/upl_styles.php	Sun Mar 03 13:26:28 2019 +0100
@@ -0,0 +1,120 @@
+<?php
+require_once('config.php');
+require("version.php");
+require("includes/formulas.php");
+
+
+$target_dir = "tmp/";
+$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
+$uploadOk = 1;
+$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
+
+// Check if file already exists
+if (file_exists($target_file)) {
+	echo "Fout 1: bestand bestaat al. ";
+	$uploadOk = 0;
+}
+// Check file size
+if ($_FILES["fileToUpload"]["size"] > 500000 && $uploadOk) {
+	echo "Fout 2: het bestand is te groot. ";
+	$uploadOk = 0;
+}
+// Allow certain file formats
+if ($imageFileType != "xml" && $uploadOk) {
+	echo "Fout 3: alleen XML bestanden toegestaan. ";
+	$uploadOk = 0;
+}
+// Check if $uploadOk is set to 0 by an error
+if ($uploadOk == 0) {
+	exit;
+}
+
+if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
+	echo "Verwerken bestand ". basename( $_FILES["fileToUpload"]["name"]). "<br />";
+} else {
+	echo "Fout 4: er ging iets fout met de upload.";
+	exit;
+}
+
+
+$db = mysqli_connect(DBASE_HOST, DBASE_USER, DBASE_PASS, DBASE_NAME);
+if (! $db) {
+	echo "Fout 5: ".mysqli_connect_errno()." ".mysqli_connect_error();
+	exit;
+}
+mysqli_set_charset($db, "utf8" );
+date_default_timezone_set('Europe/Amsterdam');
+
+
+$imported = 0;
+$styles = simplexml_load_file($target_file);
+
+foreach ($styles->STYLE as $style) {
+
+	$sql  = "INSERT INTO profile_styles SET name='" . mysqli_real_escape_string($db, $style->NAME);
+	if ($style->NOTES)
+		$sql .= "', notes='" . mysqli_real_escape_string($db, $style->NOTES);
+	if ($style->CATEGORY)
+		$sql .= "', category='" . mysqli_real_escape_string($db, $style->CATEGORY);
+	if ($style->CATEGORY_NUMBER)
+		$sql .= "', category_number='" . $style->CATEGORY_NUMBER;
+	if ($style->STYLE_LETTER)
+		$sql .= "', style_letter='" . mysqli_real_escape_string($db, $style->STYLE_LETTER);
+	if ($style->STYLE_GUIDE)
+		$sql .= "', style_guide='" . mysqli_real_escape_string($db, $style->STYLE_GUIDE);
+
+	if ($style->TYPE == 'Lager')
+		$sql .= "', type='0";
+	else if ($style->TYPE == 'Ale')
+		$sql .= "', type='1";
+	else if ($style->TYPE == 'Mead')
+		$sql .= "', type='2";
+	else if ($style->TYPE == 'Wheat')
+		$sql .= "', type='3";
+	else if ($style->TYPE == 'Mixed')
+		$sql .= "', type='4";
+	else if ($style->TYPE == 'Cider')
+		$sql .= "', type='5";
+	else
+		echo "Unknown TYPE " . $style->TYPE . "<br />";
+
+	$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='" . srm_to_ebc(floatval($style->COLOR_MIN));
+	$sql .= "', color_max='" . srm_to_ebc(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)
+		$sql .= "', ingredients='" . mysqli_real_escape_string($db, $style->INGREDIENTS);
+	if ($style->EXAMPLES)
+		$sql .= "', examples='" . mysqli_real_escape_string($db, $style->EXAMPLES);
+
+	$sql .= "';";
+	if (! $result = mysqli_query($db, $sql)) {
+		echo "Fout 8: " . mysqli_error($db) . "<br />";
+	} else {
+		echo "+ " . $style->NAME . "<br />";
+		$imported++;
+	}
+}
+
+if ($imported == 0) {
+	echo "Fout 7: geen stylen in dit bestand.<br />";
+} else {
+	echo $imported . " stylen toegevoegd.<br />";
+}
+
+
+
+// Don't clutter the upload directory.
+unlink($target_file);
+
+?>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/www/upl_yeasts.php	Sun Mar 03 13:26:28 2019 +0100
@@ -0,0 +1,155 @@
+<?php
+require_once('config.php');
+require("version.php");
+require("includes/formulas.php");
+
+
+$target_dir = "tmp/";
+$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
+$uploadOk = 1;
+$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
+
+// Check if file already exists
+if (file_exists($target_file)) {
+	echo "Fout 1: bestand bestaat al. ";
+	$uploadOk = 0;
+}
+// Check file size
+if ($_FILES["fileToUpload"]["size"] > 500000 && $uploadOk) {
+	echo "Fout 2: het bestand is te groot. ";
+	$uploadOk = 0;
+}
+// Allow certain file formats
+if ($imageFileType != "xml" && $uploadOk) {
+	echo "Fout 3: alleen XML bestanden toegestaan. ";
+	$uploadOk = 0;
+}
+// Check if $uploadOk is set to 0 by an error
+if ($uploadOk == 0) {
+	exit;
+}
+
+if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
+	echo "Verwerken bestand ". basename( $_FILES["fileToUpload"]["name"]). "<br />";
+} else {
+	echo "Fout 4: er ging iets fout met de upload.";
+	exit;
+}
+
+
+$db = mysqli_connect(DBASE_HOST, DBASE_USER, DBASE_PASS, DBASE_NAME);
+if (! $db) {
+	echo "Fout 5: ".mysqli_connect_errno()." ".mysqli_connect_error();
+	exit;
+}
+mysqli_set_charset($db, "utf8" );
+date_default_timezone_set('Europe/Amsterdam');
+
+
+$imported = 0;
+$yeasts = simplexml_load_file($target_file);
+
+foreach ($yeasts->YEAST as $yeast) {
+
+	$sql  = "INSERT INTO inventory_yeasts SET name='" . mysqli_real_escape_string($db, $yeast->NAME);
+
+	if ($yeast->TYPE == 'Lager')
+		$sql .= "', type='0";
+	else if ($yeast->TYPE == 'Ale')
+		$sql .= "', type='1";
+	else if ($yeast->TYPE == 'Wheat')
+		$sql .= "', type='2";
+	else if ($yeast->TYPE == 'Wine')
+		$sql .= "', type='3";
+	else if ($yeast->TYPE == 'Champagne')
+		$sql .= "', type='4";
+	else
+		echo "Unknown TYPE " . $yeast->TYPE . "<br />";
+
+	if ($yeast->FORM == 'Liquid')
+		$sql .= "', form='0";
+	else if ($yeast->FORM == 'Dry')
+		$sql .= "', form='1";
+	else if ($yeast->FORM == 'Slant')
+		$sql .= "', form='2";
+	else if ($yeast->FORM == 'Culture')
+		$sql .= "', form='3";
+	else if ($yeast->FORM == 'Frozen')
+		$sql .= "', form='4";
+	else if ($yeast->FORM == 'Bottle')
+		$sql .= "', form='5";
+	else
+		echo "Unknown FORM " . $yeast->FORM . "<br />";
+
+	$sql .= "', laboratory='" . mysqli_real_escape_string($db, $yeast->LABORATORY);
+	$sql .= "', product_id='" . mysqli_real_escape_string($db, $yeast->PRODUCT_ID);
+	if ($yeast->MIN_TEMPERATURE)
+		$sql .= "', min_temperature='" . floatval($yeast->MIN_TEMPERATURE);
+	if ($yeast->MAX_TEMPERATURE)
+		$sql .= "', max_temperature='" . floatval($yeast->MAX_TEMPERATURE);
+
+	if ($yeast->FLOCCULATION == 'Low')
+		$sql .= "', flocculation='0";
+	else if ($yeast->FLOCCULATION == 'Medium')
+		$sql .= "', flocculation='1";
+	else if ($yeast->FLOCCULATION == 'High')
+		$sql .= "', flocculation='2";
+	else if ($yeast->FLOCCULATION == 'Very high')
+		$sql .= "', flocculation='3";
+	else
+		echo "Unknown FLOCCULATION " . $yeast->FLOCCULATION . PHP_EOL;
+
+	if ($yeast->ATTENUATION)
+		$sql .= "', attenuation='" . floatval($yeast->ATTENUATION);
+	$sql .= "', notes='" . mysqli_real_escape_string($db, $yeast->NOTES);
+	$sql .= "', best_for='" . mysqli_real_escape_string($db, $yeast->BEST_FOR);
+	if ($yeast->MAX_REUSE)
+		$sql .= "', max_reuse='" . $yeast->MAX_REUSE;
+
+	if ($yeast->FORM == 'Liquid') {
+		if ($yeast->LABORATORY == 'Imperial Yeast')
+			$sql .= "', cells='200000000000";       // 200 billion cells per pack
+		else
+			$sql .= "', cells='100000000000";       // 100 billion cells per pack
+		if ($yeast->COST)
+			$sql .= "', cost='" . floatval($yeast->COST);
+		if ($yeast->INVENTORY)
+			$sql .= "', inventory='" . floatval($yeast->INVENTORY);
+	} else if ($yeast->FORM == 'Dry') {
+		$sql .= "', cells='15000000000";        // 6..15 billion per gram
+		if ($yeast->INVENTORY)
+			$sql .= "', inventory='" . floatval($yeast->INVENTORY) / 1000.0; // To kg
+		if ($yeast->COST)
+			$sql .= "', cost='" . floatval($yeast->COST) * 1000.0;  // to Euro/kg
+	} else {
+		$sql .= "', cells='1700000000";         // 1.7 billion cells per ml.
+		if ($yeast->INVENTORY)
+			$sql .= "', inventory='" . floatval($yeast->INVENTORY) / 1000.0; // To liter
+		if ($yeast->COST)
+			$sql .= "', cost='" . floatval($yeast->COST) * 1000.0;  // to Euro/liter
+	}
+	if ($yeast->CULTURE_DATE) {
+		$date = substr($yeast->CULTURE_DATE, 6, 4) . '-' . substr($yeast->CULTURE_DATE, 3, 2) . '-' . substr($yeast->CULTURE_DATE, 0, 2);
+		$sql .= "', production_date='" . $date;
+	}
+	$sql .= "';";
+	if (! $result = mysqli_query($db, $sql)) {
+		echo "Fout 8: " . mysqli_error($db) . "<br />";
+	} else {
+		echo "+ " . $yeast->NAME . "<br />";
+		$imported++;
+	}
+}
+
+if ($imported == 0) {
+	echo "Fout 7: geen gisten in dit bestand.<br />";
+} else {
+	echo $imported . " gisten toegevoegd.<br />";
+}
+
+
+
+// Don't clutter the upload directory.
+unlink($target_file);
+
+?>

mercurial