--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/www/includes/db_inventory_fermentables.php Sun Aug 12 21:24:33 2018 +0200 @@ -0,0 +1,121 @@ +<?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()); +} + +// get data and store in a json array +$query = "SELECT * FROM inventory_fermentables"; +if (isset($_GET['insert'])) { + // INSERT COMMAND + $sql = "INSERT INTO `inventory_fermentables` SET name='" . mysqli_real_escape_string($connect, $_GET['name']); + $sql .= "', type='" . $_GET['type']; + $sql .= "', yield='" . $_GET['yield']; + $sql .= "', color='" . ebc_to_srm($_GET['color']); + ($_GET['add_after_boil'] == 'true') ? $sql .= "', add_after_boil='1" : $sql .= "', add_after_boil='0"; + $sql .= "', origin='" . mysqli_real_escape_string($connect, $_GET['origin']); + $sql .= "', supplier='" . mysqli_real_escape_string($connect, $_GET['supplier']); + $sql .= "', notes='" . mysqli_real_escape_string($connect, $_GET['notes']); + $sql .= "', coarse_fine_diff='" . $_GET['coarse_fine_diff']; + $sql .= "', moisture='" . $_GET['moisture']; + $sql .= "', diastatic_power='" . $_GET['diastatic_power']; + $sql .= "', protein='" . $_GET['protein']; + $sql .= "', max_in_batch='" . $_GET['max_in_batch']; + ($_GET['recommend_mash'] == 'true') ? $sql .= "', recommend_mash='1" : $sql .= "', recommend_mash='0"; + $sql .= "', ibu_gal_per_lb='" . $_GET['ibu_gal_per_lb']; + ($_GET['always_on_stock'] == 'true') ? $sql .= "', always_on_stock='1" : $sql .= "', always_on_stock='0"; + $sql .= "', di_ph='" . $_GET['di_ph']; + $sql .= "', acid_to_ph_57='" . $_GET['acid_to_ph_57']; + $sql .= "', graintype='" . mysqli_real_escape_string($connect, $_GET['graintype']); + $sql .= "', inventory='" . $_GET['inventory']; + $sql .= "', cost='" . $_GET['cost']; + $sql .= "', production_date='" . $_GET['production_date']; + $sql .= "', tht_date='" . $_GET['tht_date']; + $sql .= "', supplier_rec='" . $_GET['supplier_rec']; + $sql .= "';"; + error_log("\"$sql\""); + $result = mysqli_query($connect, $sql) or die("SQL Error 1: " . mysqli_error($connect)); + error_log("result " . $result); + echo $result; + +} else if (isset($_GET['update'])) { + // UPDATE COMMAND + $sql = "UPDATE `inventory_fermentables` SET name='" . mysqli_real_escape_string($connect, $_GET['name']); + $sql .= "', type='" . $_GET['type']; + $sql .= "', yield='" . $_GET['yield']; + $sql .= "', color='" . ebc_to_srm($_GET['color']); + ($_GET['add_after_boil'] == 'true') ? $sql .= "', add_after_boil='1" : $sql .= "', add_after_boil='0"; + $sql .= "', origin='" . mysqli_real_escape_string($connect, $_GET['origin']); + $sql .= "', supplier='" . mysqli_real_escape_string($connect, $_GET['supplier']); + $sql .= "', notes='" . mysqli_real_escape_string($connect, $_GET['notes']); + $sql .= "', coarse_fine_diff='" . $_GET['coarse_fine_diff']; + $sql .= "', moisture='" . $_GET['moisture']; + $sql .= "', diastatic_power='" . $_GET['diastatic_power']; + $sql .= "', protein='" . $_GET['protein']; + $sql .= "', max_in_batch='" . $_GET['max_in_batch']; + ($_GET['recommend_mash'] == 'true') ? $sql .= "', recommend_mash='1" : $sql .= "', recommend_mash='0"; + $sql .= "', ibu_gal_per_lb='" . $_GET['ibu_gal_per_lb']; + ($_GET['always_on_stock'] == 'true') ? $sql .= "', always_on_stock='1" : $sql .= "', always_on_stock='0"; + $sql .= "', di_ph='" . $_GET['di_ph']; + $sql .= "', acid_to_ph_57='" . $_GET['acid_to_ph_57']; + $sql .= "', graintype='" . mysqli_real_escape_string($connect, $_GET['graintype']); + $sql .= "', inventory='" . $_GET['inventory']; + $sql .= "', cost='" . $_GET['cost']; + $sql .= "', production_date='" . $_GET['production_date']; + $sql .= "', tht_date='" . $_GET['tht_date']; + $sql .= "', supplier_rec='" . $_GET['supplier_rec']; + $sql .= "' WHERE record='" . $_GET['record'] . "';"; + error_log("\"$sql\""); + $result = mysqli_query($connect, $sql) or die("SQL Error 1: " . mysqli_error($connect)); + error_log("result " . $result); + echo $result; + +} else if (isset($_GET['delete'])) { + // DELETE COMMAND + $sql = "DELETE FROM `inventory_fermentables` WHERE record='".$_GET['record']."';"; + error_log("\"$sql\""); + $result = mysqli_query($connect, $sql) or die("SQL Error 1: " . mysqli_error($connect)); + error_log("result " . $result); + echo $result; + +} else { + // SELECT COMMAND + $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' => $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'], + 'max_in_batch' => $row['max_in_batch'], + 'recommend_mash' => $row['recommend_mash'], + 'ibu_gal_per_lb' => $row['ibu_gal_per_lb'], + 'always_on_stock' => $row['always_on_stock'], + 'di_ph' => $row['di_ph'], + 'acid_to_ph_57' => $row['acid_to_ph_57'], + 'graintype' => $row['graintype'], + 'inventory' => $row['inventory'], + 'cost' => $row['cost'], + 'production_date' => $row['production_date'], + 'tht_date' => $row['tht_date'], + 'supplier_rec' => $row['supplier_rec'] + ); + } + echo json_encode($fermentables); +} +?>