www/includes/db_inventory_yeasts.php

Sat, 26 Jan 2019 15:03:09 +0100

author
Michiel Broek <mbroek@mbse.eu>
date
Sat, 26 Jan 2019 15:03:09 +0100
changeset 209
dc30801e6961
parent 201
f9b7e3f6be7c
child 296
69fadd1aded2
permissions
-rw-r--r--

Import set tun_material from the specifix heat value. Equipment database uses POST instead of GET. Equipment editor screen in style with other inventory screens. In stock print now uses the type indexes to translate to text. Also show the correct unit and values of the yeast.

<?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 .= "', 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
		);
	}
	echo json_encode($yeasts);
}
?>

mercurial