www/includes/db_inventory_yeasts.php

Sun, 02 Jun 2019 12:48:54 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Sun, 02 Jun 2019 12:48:54 +0200
changeset 392
544d7d0183b2
parent 313
9f45d09c2071
child 512
4451af8b6295
permissions
-rw-r--r--

Added 15 fields to the recipes table. Added 18 fields to the products table. These are calculated values that are now stored in the database so export programs can use these values without calculating them again. Product and recipe print have water and mash schedule added. Product print has brewday results added if the brewday is over. The ingredients layout changed in the product and recipe prints.

<?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
if (isset($_POST['insert']) || isset($_POST['update'])) {
	if (isset($_POST['insert'])) {
		$sql  = "INSERT INTO `inventory_yeasts` SET ";
	}
	if (isset($_POST['update'])) {
		$sql  = "UPDATE `inventory_yeasts` SET ";
	}

	$sql .= "name='" . mysqli_real_escape_string($connect, $_POST['name']);
	$sql .= "', type='" . $_POST['type'];
	$sql .= "', form='" . $_POST['form'];
	$sql .= "', laboratory='" . mysqli_real_escape_string($connect, $_POST['laboratory']);
	$sql .= "', product_id='" . mysqli_real_escape_string($connect, $_POST['product_id']);
	$sql .= "', min_temperature='" . $_POST['min_temperature'];
	$sql .= "', max_temperature='" . $_POST['max_temperature'];
	$sql .= "', flocculation='" . $_POST['flocculation'];
	$sql .= "', attenuation='" . $_POST['attenuation'];
	$sql .= "', notes='" . mysqli_real_escape_string($connect, $_POST['notes']);
	$sql .= "', best_for='" . mysqli_real_escape_string($connect, $_POST['best_for']);
	$sql .= "', max_reuse='" . $_POST['max_reuse'];
	$sql .= "', cells='" . floatval($_POST['cells']) * 1000000000.0;
	$sql .= "', tolerance='" . $_POST['tolerance'];
	$sql .= "', inventory='" . $_POST['inventory'];
	$sql .= "', cost='" . $_POST['cost'] . "'";
	if ($_POST['production_date'] == '')
		$sql .= ", production_date=NULL";
	else
		$sql .= ", production_date='" . $_POST['production_date'] . "'";
	if ($_POST['tht_date'] == '')
		$sql .= ", tht_date=NULL";
	else
		$sql .= ", tht_date='" . $_POST['tht_date'] . "'";
	if (isset($_POST['insert'])) {
		$sql .= ";";
	}
	if (isset($_POST['update'])) {
		$sql .= " WHERE record='" . $_POST['record'] . "';";
	}
	syslog(LOG_NOTICE, $sql);

	$result = mysqli_query($connect, $sql);
	if (! $result) {
		syslog(LOG_NOTICE, "db_inventory_yeasts: ".$sql." result: ".mysqli_error($connect));
	} else {
		if (isset($_POST['update'])) {
			syslog(LOG_NOTICE, "db_inventory_yeasts: updated record ".$_POST['record']);
		} else {
			$lastid = mysqli_insert_id($connect);
			syslog(LOG_NOTICE, "db_inventory_yeasts: inserted record ".$lastid);
		}
	}
	echo $result;

} else if (isset($_POST['delete'])) {
	// DELETE COMMAND
	$sql = "DELETE FROM `inventory_yeasts` WHERE record='".$_POST['record']."';";
	$result = mysqli_query($connect, $sql);
	if (! $result) {
		syslog(LOG_NOTICE, "db_inventory_yeasts: ".$sql." result: ".mysqli_error($connect));
	} else {
		syslog(LOG_NOTICE, "db_inventory_yeasts: deleted record ".$_POST['record']);
	}
	echo $result;

} else {
	// SELECT COMMAND
	$query = "SELECT * FROM inventory_yeasts ORDER BY laboratory,product_id,name";
	$result = mysqli_query($connect, $query) or die("SQL Error 1: " . mysqli_error($connect));
	while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
		$yeasts[] = array(
			'record' => $row['record'],
			'name' => $row['name'],
			'type' => $row['type'],
			'form' => $row['form'],
			'laboratory' => $row['laboratory'],
			'product_id' => $row['product_id'],
			'min_temperature' => $row['min_temperature'],
			'max_temperature' => $row['max_temperature'],
			'flocculation' => $row['flocculation'],
			'attenuation' => $row['attenuation'],
			'notes' => $row['notes'],
			'best_for' => $row['best_for'],
			'max_reuse' => $row['max_reuse'],
			'inventory' => $row['inventory'],
			'cost' => $row['cost'],
			'production_date' => $row['production_date'],
			'tht_date' => $row['tht_date'],
			'cells' => floatval($row['cells']) / 1000000000.0,
			'tolerance' => $row['tolerance']
		);
	}
	header("Content-type: application/json");
	echo json_encode($yeasts);
}
?>

mercurial