Fri, 28 Dec 2018 23:18:42 +0100
Some pH calculations cane use twice as much loops, probably because we have better float precision then the original pascal code. More variables to prevent html reads. Use predicted mash pH (the grist in demi water) to calculate the pH shift from the tapwater to the target pH. It's better but not right yet. Or it is right and brouwhulp is far off.
<?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 $query = "SELECT * FROM inventory_equipments ORDER BY name"; if (isset($_GET['insert']) || isset($_GET['update'])) { if (isset($_GET['insert'])) { // INSERT COMMAND $sql = "INSERT INTO `inventory_equipments` SET "; } if (isset($_GET['update'])) { // UPDATE COMMAND $sql = "UPDATE `inventory_equipments` SET "; } $sql .= "name='" . mysqli_real_escape_string($connect, $_GET['name']); $sql .= "', boil_size='" . $_GET['boil_size']; $sql .= "', batch_size='" . $_GET['batch_size']; $sql .= "', tun_volume='" . $_GET['tun_volume']; $sql .= "', tun_weight='" . $_GET['tun_weight']; $sql .= "', tun_specific_heat='" . $_GET['tun_specific_heat']; $sql .= "', tun_material='" . mysqli_real_escape_string($connect, $_GET['tun_material']); $sql .= "', tun_height='" . $_GET['tun_height'] / 100.0; $sql .= "', top_up_water='" . $_GET['top_up_water']; $sql .= "', trub_chiller_loss='" . $_GET['trub_chiller_loss']; $sql .= "', evap_rate='" . $_GET['evap_rate']; $sql .= "', boil_time='" . $_GET['boil_time']; ($_GET['calc_boil_volume'] == 'true') ? $sql .= "', calc_boil_volume='1" : $sql .= "', calc_boil_volume='0"; $sql .= "', top_up_kettle='" . $_GET['top_up_kettle']; $sql .= "', hop_utilization='" . $_GET['hop_utilization']; $sql .= "', notes='" . mysqli_real_escape_string($connect, $_GET['notes']); $sql .= "', lauter_volume='" . $_GET['lauter_volume']; $sql .= "', lauter_height='" . $_GET['lauter_height'] / 100.0; $sql .= "', lauter_deadspace='" . $_GET['lauter_deadspace']; $sql .= "', kettle_volume='" . $_GET['kettle_volume']; $sql .= "', kettle_height='" . $_GET['kettle_height'] / 100.0; $sql .= "', mash_volume='" . $_GET['mash_volume']; $sql .= "', mash_max='" . $_GET['mash_max']; $sql .= "', efficiency='" . $_GET['efficiency']; if (isset($_GET['insert'])) { $sql .= "';"; } if (isset($_GET['update'])) { $sql .= "' WHERE record='" . $_GET['record'] . "';"; } $result = mysqli_query($connect, $sql); if (! $result) { syslog(LOG_NOTICE, "db_inventory_equipment: ".$sql." result: ".mysqli_error($connect)); } else { if (isset($_GET['update'])) { syslog(LOG_NOTICE, "db_inventory_equipment: updated record ".$_GET['record']); } else { $lastid = mysqli_insert_id($connect); syslog(LOG_NOTICE, "db_inventory_equipment: inserted record ".$lastid); } } echo $result; } else if (isset($_GET['delete'])) { // DELETE COMMAND // FIXME: need to check if the record is in use $sql = "DELETE FROM `inventory_equipments` WHERE record='".$_GET['record']."';"; $result = mysqli_query($connect, $sql); if (! $result) { syslog(LOG_NOTICE, "db_inventory_equipment: ".$sql." result: ".mysqli_error($connect)); } else { syslog(LOG_NOTICE, "db_inventory_equipment: deleted record ".$_GET['record']); } 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)) { $equipments[] = array( 'record' => $row['record'], 'name' => $row['name'], 'boil_size' => $row['boil_size'], 'batch_size' => $row['batch_size'], 'tun_volume' => $row['tun_volume'], 'tun_weight' => $row['tun_weight'], 'tun_specific_heat' => $row['tun_specific_heat'], 'tun_material' => $row['tun_material'], 'tun_height' => $row['tun_height'] * 100.0, 'top_up_water' => $row['top_up_water'], 'trub_chiller_loss' => $row['trub_chiller_loss'], 'evap_rate' => $row['evap_rate'], 'boil_time' => $row['boil_time'], 'calc_boil_volume' => $row['calc_boil_volume'], 'top_up_kettle' => $row['top_up_kettle'], 'hop_utilization' => $row['hop_utilization'], 'notes' => $row['notes'], 'lauter_volume' => $row['lauter_volume'], 'lauter_height' => $row['lauter_height'] * 100.0, 'lauter_deadspace' => $row['lauter_deadspace'], 'kettle_volume' => $row['kettle_volume'], 'kettle_height' => $row['kettle_height'] * 100.0, 'mash_volume' => $row['mash_volume'], 'mash_max' => $row['mash_max'], 'efficiency' => $row['efficiency'] ); } echo json_encode($equipments); } ?>