www/includes/db_profile_styles.php

Sat, 11 May 2019 23:13:40 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Sat, 11 May 2019 23:13:40 +0200
changeset 358
3be8c2278fd7
parent 296
69fadd1aded2
child 716
57118e6a4bdb
permissions
-rw-r--r--

Added flags for each ingredient group for the supplies state. On the main screen show the state of the supplies if the product stage is not yet packaged. Calculate the state of the supplies for fermentables, hops, yeasts and miscs. In the grids don't show the inventory values after they are used and reduced. On the fermentables tab show the weight of the grains to mash.

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

	$sql .= "name='" . mysqli_real_escape_string($connect, $_POST['name']);
	$sql .= "', category='" . mysqli_real_escape_string($connect, $_POST['category']);
	$sql .= "', category_number='" . $_POST['category_number'];
	$sql .= "', style_letter='" . mysqli_real_escape_string($connect, $_POST['style_letter']);
	$sql .= "', style_guide='" . mysqli_real_escape_string($connect, $_POST['style_guide']);
	$sql .= "', type='" . $_POST['type'];
	$sql .= "', og_min='" . $_POST['og_min'];
	$sql .= "', og_max='" . $_POST['og_max'];
	$sql .= "', fg_min='" . $_POST['fg_min'];
	$sql .= "', fg_max='" . $_POST['fg_max'];
	$sql .= "', ibu_min='" . $_POST['ibu_min'];
	$sql .= "', ibu_max='" . $_POST['ibu_max'];
	$sql .= "', color_min='" . $_POST['color_min'];
	$sql .= "', color_max='" . $_POST['color_max'];
	$sql .= "', carb_min='" . $_POST['carb_min'];
	$sql .= "', carb_max='" . $_POST['carb_max'];
	$sql .= "', abv_min='" . $_POST['abv_min'];
	$sql .= "', abv_max='" . $_POST['abv_max'];
	$sql .= "', notes='" . mysqli_real_escape_string($connect, $_POST['notes']);
	$sql .= "', profile='" . mysqli_real_escape_string($connect, $_POST['profile']);
	$sql .= "', ingredients='" . mysqli_real_escape_string($connect, $_POST['ingredients']);
	$sql .= "', examples='" . mysqli_real_escape_string($connect, $_POST['examples']);
	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_styles: ".$sql." result: ".mysqli_error($connect));
	} else {
		if (isset($_POST['update'])) {
			syslog(LOG_NOTICE, "db_profile_styles: updated record ".$_POST['record']);
		} else {
			$lastid = mysqli_insert_id($connect);
			syslog(LOG_NOTICE, "db_profile_styles: inserted record ".$lastid);
		}
	}
	echo $result;

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

} else {
	// SELECT COMMAND
	$query = "SELECT * FROM profile_styles ORDER BY style_guide,style_letter,name";
	$result = mysqli_query($connect, $query) or die("SQL Error 1: " . mysqli_error($connect));
	while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
		$styles[] = array(
			'record' => $row['record'],
			'name' => $row['name'],
			'category' => $row['category'],
			'category_number' => $row['category_number'],
			'style_letter' => $row['style_letter'],
			'style_guide' => $row['style_guide'],
			'type' => $row['type'],
			'og_min' => $row['og_min'],
			'og_max' => $row['og_max'],
			'fg_min' => $row['fg_min'],
			'fg_max' => $row['fg_max'],
			'ibu_min' => $row['ibu_min'],
			'ibu_max' => $row['ibu_max'],
			'color_min' => $row['color_min'],
			'color_max' => $row['color_max'],
			'carb_min' => $row['carb_min'],
			'carb_max' => $row['carb_max'],
			'abv_min' => $row['abv_min'],
			'abv_max' => $row['abv_max'],
			'notes' => $row['notes'],
			'profile' => $row['profile'],
			'ingredients' => $row['ingredients'],
			'examples' => $row['examples']
		);
	}
	header("Content-type: application/json");
	echo json_encode($styles);
}
?>

mercurial