www/includes/db_profile_water.php

Tue, 31 Aug 2021 20:48:37 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Tue, 31 Aug 2021 20:48:37 +0200
changeset 774
92e1e8f175a2
parent 768
ae1195153fa2
child 785
aa79acfdf8a9
permissions
-rw-r--r--

Split batch, adjust mash step volume. In the duplicated log_brew handle the missing values. In save product, round the mash step sg to 4 decimals. In prod_edit, ingredients are stored as strings, not arrays. This triggered a memory corruption that only happened in rare circumstances. Don't fix mash step fields in the javascript, it is already done during load from the database. Calculation of the mash volume is rounded to 6 decimals. Enter mash step Brix/Plato value, the SG result is rounded to 4 decimals.

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

$response = array(
   'error' => false,
   'msg' => 'Ok',
);

if (isset($_POST['insert']) || isset($_POST['update'])) {
	if (isset($_POST['insert'])) {
		$sql  = "INSERT INTO `profile_water` SET ";
	}
	if (isset($_POST['update'])) {
		$sql  = "UPDATE `profile_water` SET ";
	}

	$sql .= "name='" . mysqli_real_escape_string($connect, $_POST['name']);
	$sql .= "', calcium='" . $_POST['calcium'];
	$sql .= "', bicarbonate='" . $_POST['bicarbonate'];
	$sql .= "', sulfate='" . $_POST['sulfate'];
	$sql .= "', chloride='" . $_POST['chloride'];
	$sql .= "', sodium='" . $_POST['sodium'];
	$sql .= "', magnesium='" . $_POST['magnesium'];
	$sql .= "', ph='" . $_POST['ph'];
	$sql .= "', notes='" . mysqli_real_escape_string($connect, $_POST['notes']);
	$sql .= "', total_alkalinity='" . $_POST['total_alkalinity'];
	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_profile_water: ".$sql." result: ".mysqli_error($connect));
                $response['error'] = true;
                $response['msg'] = "SQL fout: ".mysqli_error($connect);
        }
        exit(json_encode($response));

} else if (isset($_POST['delete'])) {
	// DELETE COMMAND
	$sql = "DELETE FROM `profile_water` WHERE record='".$_POST['record']."';";
	$result = mysqli_query($connect, $sql);
	if (! $result) {
		syslog(LOG_NOTICE, "db_profile_water: ".$sql." result: ".mysqli_error($connect));
                $response['error'] = true;
                $response['msg'] = "SQL fout: ".mysqli_error($connect);
        }
        exit(json_encode($response));

} else {
	// SELECT COMMAND
	$query = "SELECT * FROM profile_water ORDER BY name";
	$result = mysqli_query($connect, $query) or die("SQL Error 1: " . mysqli_error($connect));
	while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
		$waters[] = array(
			'record' => $row['record'],
			'name' => $row['name'],
			'calcium' => $row['calcium'],
			'bicarbonate' => $row['bicarbonate'],
			'sulfate' => $row['sulfate'],
			'chloride' => $row['chloride'],
			'sodium' => $row['sodium'],
			'magnesium' => $row['magnesium'],
			'ph' => $row['ph'],
			'notes' => $row['notes'],
			'total_alkalinity' => $row['total_alkalinity']
		);
	}
	header("Content-type: application/json");
	exit(json_encode($waters));
}

syslog(LOG_NOTICE, "db_profile_water: missing arguments");
$response['error'] = true;
$response['msg'] = "missing arguments";
echo json_encode($response);

?>

mercurial