www/includes/db_inventory_equipments.php

Mon, 10 Dec 2018 22:20:19 +0100

author
Michiel Broek <mbroek@mbse.eu>
date
Mon, 10 Dec 2018 22:20:19 +0100
changeset 136
bcc4583fd013
parent 116
ac993ef43b13
child 149
ff45488d480e
permissions
-rw-r--r--

Fixed estimate FG calculation during recipes import. Added estimate FG calculation in the recipe editor but do not yet update the recipe. Added SVG calculation to the recipes editor. Added calculations for hop aroma and flavour contribution.

<?php
require($_SERVER['DOCUMENT_ROOT']."/config.php");
require($_SERVER['DOCUMENT_ROOT']."/version.php");

#Connect to the database
$connect = mysqli_connect(DBASE_HOST, DBASE_USER, DBASE_PASS, DBASE_NAME);
if (! $connect) {
	die('Connect Error (' . mysqli_connect_errno() . ') ' . mysqli_connect_error());
}
mysqli_set_charset($connect, "utf8" );

// get data and store in a json array
$query = "SELECT * FROM inventory_equipments ORDER BY name";
if (isset($_GET['insert']) || isset($_GET['update'])) {
	if (isset($_GET['insert'])) {
		// INSERT COMMAND
		$sql  = "INSERT INTO `inventory_equipments` SET ";
	}
	if (isset($_GET['update'])) {
		// UPDATE COMMAND
		$sql  = "UPDATE `inventory_equipments` SET ";
	}
	$sql .=    "name='" . mysqli_real_escape_string($connect, $_GET['name']);
	$sql .= "', boil_size='" . $_GET['boil_size'];
	$sql .= "', batch_size='" . $_GET['batch_size'];
	$sql .= "', tun_volume='" . $_GET['tun_volume'];
	$sql .= "', tun_weight='" . $_GET['tun_weight'];
	$sql .= "', tun_specific_heat='" .  $_GET['tun_specific_heat'];
	$sql .= "', tun_material='" . mysqli_real_escape_string($connect, $_GET['tun_material']);
	$sql .= "', tun_height='" . $_GET['tun_height'] / 100.0;
	$sql .= "', top_up_water='" . $_GET['top_up_water'];
	$sql .= "', trub_chiller_loss='" . $_GET['trub_chiller_loss'];
	$sql .= "', evap_rate='" . $_GET['evap_rate'];
	$sql .= "', boil_time='" . $_GET['boil_time'];
	($_GET['calc_boil_volume'] == 'true') ? $sql .= "', calc_boil_volume='1" : $sql .= "', calc_boil_volume='0";
	$sql .= "', top_up_kettle='" . $_GET['top_up_kettle'];
	$sql .= "', hop_utilization='" . $_GET['hop_utilization'];
	$sql .= "', notes='" . mysqli_real_escape_string($connect, $_GET['notes']);
	$sql .= "', lauter_volume='" . $_GET['lauter_volume'];
	$sql .= "', lauter_height='" . $_GET['lauter_height'] / 100.0;
	$sql .= "', lauter_deadspace='" . $_GET['lauter_deadspace'];
	$sql .= "', kettle_volume='" . $_GET['kettle_volume'];
	$sql .= "', kettle_height='" . $_GET['kettle_height'] / 100.0;
	$sql .= "', mash_volume='" . $_GET['mash_volume'];
	$sql .= "', efficiency='" . $_GET['efficiency'];
	if (isset($_GET['insert'])) {
		$sql .= "';";
	}
	if (isset($_GET['update'])) {
		$sql .= "' WHERE record='" . $_GET['record'] . "';";
	}
	$result = mysqli_query($connect, $sql);
	if (! $result) {
		syslog(LOG_NOTICE, "db_inventory_equipment: ".$sql." result: ".mysqli_error($connect));
	} else {
		if (isset($_GET['update'])) {
			syslog(LOG_NOTICE, "db_inventory_equipment: updated record ".$_GET['record']);
		} else {
			$lastid = mysqli_insert_id($connect);
			syslog(LOG_NOTICE, "db_inventory_equipment: inserted record ".$lastid);
		}
	}
	echo $result;

} else if (isset($_GET['delete'])) {
	// DELETE COMMAND
	// FIXME: need to check if the record is in use
	$sql = "DELETE FROM `inventory_equipments` WHERE record='".$_GET['record']."';";
	$result = mysqli_query($connect, $sql);
	if (! $result) {
		syslog(LOG_NOTICE, "db_inventory_equipment: ".$sql." result: ".mysqli_error($connect));
	} else {
		syslog(LOG_NOTICE, "db_inventory_equipment: deleted record ".$_GET['record']);
	}
	echo $result;

} else {
	// SELECT COMMAND
	$result = mysqli_query($connect, $query) or die("SQL Error 1: " . mysqli_error($connect));
	while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
		$equipments[] = array(
			'record' => $row['record'],
			'name' => $row['name'],
			'boil_size' => $row['boil_size'],
			'batch_size' => $row['batch_size'],
			'tun_volume' => $row['tun_volume'],
			'tun_weight' => $row['tun_weight'],
			'tun_specific_heat' => $row['tun_specific_heat'],
			'tun_material' => $row['tun_material'],
			'tun_height' => $row['tun_height'] * 100.0,
			'top_up_water' => $row['top_up_water'],
			'trub_chiller_loss' => $row['trub_chiller_loss'],
			'evap_rate' => $row['evap_rate'],
			'boil_time' => $row['boil_time'],
			'calc_boil_volume' => $row['calc_boil_volume'],
			'top_up_kettle' => $row['top_up_kettle'],
			'hop_utilization' => $row['hop_utilization'],
			'notes' => $row['notes'],
			'lauter_volume' => $row['lauter_volume'],
			'lauter_height' => $row['lauter_height'] * 100.0,
			'lauter_deadspace' => $row['lauter_deadspace'],
			'kettle_volume' => $row['kettle_volume'],
			'kettle_height' => $row['kettle_height'] * 100.0,
			'mash_volume' => $row['mash_volume'],
			'efficiency' => $row['efficiency']
		);
	}
	echo json_encode($equipments);
}
?>

mercurial