www/includes/db_inventory_fermentables.php

Wed, 16 Oct 2019 21:05:03 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Wed, 16 Oct 2019 21:05:03 +0200
changeset 514
3c680d1dea35
parent 296
69fadd1aded2
child 712
65da479b5542
permissions
-rw-r--r--

Added dutch array strings to a global php script. Changed fermentables, hops, yeast and misc inventory scripts to use these strings between the database scripts and javascript scripts. This makes filtering on types strings useable. Added these changes to the product/recipe forum and print exports too.

<?php

require($_SERVER['DOCUMENT_ROOT']."/config.php");
require($_SERVER['DOCUMENT_ROOT']."/version.php");
require($_SERVER['DOCUMENT_ROOT']."/includes/constants.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_fermentables` SET ";
	}
	if (isset($_POST['update'])) {
		$sql  = "UPDATE `inventory_fermentables` SET ";
	}

	$sql .= "name='" . mysqli_real_escape_string($connect, $_POST['name']);
	$sql .= "', type='" . array_search($_POST['type'], $fermentabletype);
	$sql .= "', yield='" . $_POST['yield'];
	$sql .= "', color='" . $_POST['color'];
	($_POST['add_after_boil'] == 'true') ? $sql .= "', add_after_boil='1" : $sql .= "', add_after_boil='0";
	$sql .= "', origin='" . mysqli_real_escape_string($connect, $_POST['origin']);
	$sql .= "', supplier='" . mysqli_real_escape_string($connect, $_POST['supplier']);
	$sql .= "', notes='" . mysqli_real_escape_string($connect, $_POST['notes']);
	$sql .= "', coarse_fine_diff='" . $_POST['coarse_fine_diff'];
	$sql .= "', moisture='" . $_POST['moisture'];
	$sql .= "', diastatic_power='" . $_POST['diastatic_power'];
	$sql .= "', protein='" . $_POST['protein'];
	$sql .= "', dissolved_protein='" . $_POST['dissolved_protein'];
	$sql .= "', max_in_batch='" . $_POST['max_in_batch'];
	($_POST['recommend_mash'] == 'true') ? $sql .= "', recommend_mash='1" : $sql .= "', recommend_mash='0";
	$sql .= "', added='" . array_search($_POST['added'], $added);
	($_POST['always_on_stock'] == 'true') ? $sql .= "', always_on_stock='1" : $sql .= "', always_on_stock='0";
	$sql .= "', di_ph='" . $_POST['di_ph'];
	$sql .= "', acid_to_ph_57='" . $_POST['acid_to_ph_57'];
	$sql .= "', graintype='" . array_search($_POST['graintype'], $graintype);
	$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_fermentables: ".$sql." result: ".mysqli_error($connect));
	} else {
		if (isset($_POST['update'])) {
			syslog(LOG_NOTICE, "db_inventory_fermentables: updated record ".$_POST['record']);
		} else {
			$lastid = mysqli_insert_id($connect);
			syslog(LOG_NOTICE, "db_inventory_fermentables: inserted record ".$lastid);
		}
	}
	echo $result;

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

} else {
	// SELECT COMMAND
	$query = "SELECT * FROM inventory_fermentables ORDER BY supplier,name";
	$result = mysqli_query($connect, $query) or die("SQL Error 1: " . mysqli_error($connect));
	while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
		$fermentables[] = array(
			'record' => $row['record'],
			'name' => $row['name'],
			'type' => $fermentabletype[$row['type']],
			'yield' => $row['yield'],
			'color' => $row['color'],
			'add_after_boil' => $row['add_after_boil'],
			'origin' => $row['origin'],
			'supplier' => $row['supplier'],
			'notes' => $row['notes'],
			'coarse_fine_diff' => $row['coarse_fine_diff'],
			'moisture' => $row['moisture'],
			'diastatic_power' => $row['diastatic_power'],
			'protein' => $row['protein'],
			'dissolved_protein' => $row['dissolved_protein'],
			'max_in_batch' => $row['max_in_batch'],
			'recommend_mash' => $row['recommend_mash'],
			'added' => $added[$row['added']],
			'always_on_stock' => $row['always_on_stock'],
			'di_ph' => $row['di_ph'],
			'acid_to_ph_57' => $row['acid_to_ph_57'],
			'graintype' => $graintype[$row['graintype']],
			'inventory' => $row['inventory'],
			'cost' => $row['cost'],
			'production_date' => $row['production_date'],
			'tht_date' => $row['tht_date']
		);
	}
	header("Content-type: application/json");
	echo json_encode($fermentables);
}
?>

mercurial