www/includes/db_inventory_equipments.php

Tue, 10 Dec 2019 20:11:37 +0100

author
Michiel Broek <mbroek@mbse.eu>
date
Tue, 10 Dec 2019 20:11:37 +0100
changeset 565
dfc850e6ee1f
parent 296
69fadd1aded2
child 715
8fb922c00a2d
permissions
-rw-r--r--

Fix upgrade of the yeast data in products and recipes if the original yeast is not found. Export product or recipe for forum is now coded in forum format and copied to the clipboard ready to paste on a forum.

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

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

} else if (isset($_POST['delete'])) {
	// DELETE COMMAND
	// FIXME: need to check if the record is in use
	$sql = "DELETE FROM `inventory_equipments` WHERE record='".$_POST['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 ".$_POST['record']);
	}
	echo $result;

} else {
	// SELECT COMMAND
	$query = "SELECT * FROM inventory_equipments ORDER BY name";
	$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' => floatval($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' => floatval($row['lauter_height']) * 100.0,
			'lauter_deadspace' => $row['lauter_deadspace'],
			'kettle_volume' => $row['kettle_volume'],
			'kettle_height' => floatval($row['kettle_height']) * 100.0,
			'mash_volume' => $row['mash_volume'],
			'mash_max' => $row['mash_max'],
			'efficiency' => $row['efficiency']
		);
	}
	header("Content-type: application/json");
	echo json_encode($equipments);
}
?>

mercurial