www/upl_miscs.php

Tue, 31 Aug 2021 20:48:37 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Tue, 31 Aug 2021 20:48:37 +0200
changeset 774
92e1e8f175a2
parent 311
f6fafccd8a6d
child 785
aa79acfdf8a9
permissions
-rw-r--r--

Split batch, adjust mash step volume. In the duplicated log_brew handle the missing values. In save product, round the mash step sg to 4 decimals. In prod_edit, ingredients are stored as strings, not arrays. This triggered a memory corruption that only happened in rare circumstances. Don't fix mash step fields in the javascript, it is already done during load from the database. Calculation of the mash volume is rounded to 6 decimals. Enter mash step Brix/Plato value, the SG result is rounded to 4 decimals.

<?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);

?>

mercurial