Wed, 28 Nov 2018 21:57:06 +0100
Small fixes for prject import from Brouwhulp. Fixes for poduct database read/write. New menu entries. Equipment select in product editor. Started brewday editor. Added conditions on some buttons and edit fields. Screen layout changes.
<?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 `prod_main` SET "; } if (isset($_POST['update'])) { $sql = "UPDATE `prod_main` SET "; } // Basic settings $sql .= "uuid='" . $_POST['uuid']; $sql .= "', name='" . mysqli_real_escape_string($connect, $_POST['name']); $sql .= "', birth='" . $_POST['birth']; $sql .= "', stage='" . $_POST['stage']; $sql .= "', notes='" . mysqli_real_escape_string($connect, $_POST['notes']); ($_POST['log_brew'] == 'true') ? $sql .= "', log_brew='1" : $sql .= "', log_brew='0"; ($_POST['log_fermentation'] == 'true') ? $sql .= "', log_fermentation='1" : $sql .= "', log_fermentation='0"; ($_POST['inventory_reduced'] == 'true') ? $sql .= "', inventory_reduced='1" : $sql .= "', inventory_reduced='0"; ($_POST['locked'] == 'true') ? $sql .= "', locked='1" : $sql .= "', locked='0"; // Equipment $sql .= "', eq_name='" . mysqli_real_escape_string($connect, $_POST['eq_name']); $sql .= "', eq_boil_size='" . $_POST['eq_boil_size']; $sql .= "', eq_batch_size='" . $_POST['eq_batch_size']; $sql .= "', eq_tun_volume='" . $_POST['eq_tun_volume']; $sql .= "', eq_tun_weight='" . $_POST['eq_tun_weight']; $material = mysqli_real_escape_string($connect, $_GET['tun_material']); $sql .= "', eq_tun_material='" . $material; if ($material == "RVS") { $sql .= "', eq_tun_specific_heat='0.11"; } else if ($material == "Aluminium") { $sql .= "', eq_tun_specific_heat='0.22"; } else if ($material == "Kunststof") { $sql .= "', eq_tun_specific_heat='0.46"; } else if ($material == "Koper") { $sql .= "', eq_tun_specific_heat='0.092"; } $sql .= "', eq_tun_height='" . $_POST['eq_tun_height']; $sql .= "', eq_top_up_water='" . $_POST['eq_top_up_water']; $sql .= "', eq_trub_chiller_loss='" . $_POST['eq_trub_chiller_loss']; $sql .= "', eq_evap_rate='" . $_POST['eq_evap_rate']; $sql .= "', eq_boil_time='" . $_POST['eq_boil_time']; $sql .= "', eq_calc_boil_volume='" . $_POST['eq_calc_boil_volume']; $sql .= "', eq_top_up_kettle='" . $_POST['eq_top_up_kettle']; $sql .= "', eq_hop_utilization='" . $_POST['eq_hop_utilization']; $sql .= "', eq_lauter_volume='" . $_POST['eq_lauter_volume']; $sql .= "', eq_lauter_height='" . $_POST['eq_lauter_height']; $sql .= "', eq_lauter_deadspace='" . $_POST['eq_lauter_deadspace']; $sql .= "', eq_kettle_volume='" . $_POST['eq_kettle_volume']; $sql .= "', eq_kettle_height='" . $_POST['eq_kettle_height']; $sql .= "', eq_mash_volume='" . $_POST['eq_mash_volume']; $sql .= "', eq_efficiency='" . $_POST['eq_efficiency']; syslog(LOG_NOTICE, $sql); 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_product: result: ".mysqli_error($connect)); } else { if (isset($_POST['update'])) { syslog(LOG_NOTICE, "db_product: updated record ".$_POST['record']); } else { $lastid = mysqli_insert_id($connect); syslog(LOG_NOTICE, "db_product: inserted record ".$lastid); } } echo $result; } else if (isset($_POST['delete'])) { // DELETE COMMAND $sql = "DELETE FROM `prod_main` WHERE record='".$_POST['record']."';"; syslog(LOG_NOTICE, $sql); // $result = mysqli_query($connect, $sql); // if (! $result) { // syslog(LOG_NOTICE, "db_product: result: ".mysqli_error($connect)); // } else { // syslog(LOG_NOTICE, "db_product: deleted record ".$_POST['record']); // } // echo $result; } else { // syslog(LOG_NOTICE, "db_product: select"); // if (isset($_GET['select'])) { // syslog(LOG_NOTICE, "db_product: select isset ".$_GET['select']); // } // SELECT COMMAND if (isset($_GET['select']) && ($_GET['select'] == "inprod")) { $query = "SELECT record,name,code,birth,stage FROM prod_main WHERE stage != 'Closed' ORDER BY birth,code;"; $result = mysqli_query($connect, $query) or die("SQL Error 1: " . mysqli_error($connect)); while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) { $brews[] = array( 'record' => $row['record'], 'name' => $row['name'], 'code' => $row['code'], 'birth' => $row['birth'], 'stage' => $row['stage'] ); } echo json_encode($brews); return; } /* * Default, select all */ $query = "SELECT * FROM prod_main ORDER BY birth,code;"; $result = mysqli_query($connect, $query) or die("SQL Error 1: " . mysqli_error($connect)); while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) { $brews[] = array( 'record' => $row['record'], 'uuid' => $row['uuid'], 'name' => $row['name'], 'code' => $row['code'], 'birth' => $row['birth'], 'stage' => $row['stage'], 'notes' => $row['notes'], 'log_brew' => $row['log_brew'], 'log_fermentation' => $row['log_fermentation'], 'inventory_reduced' => $row['inventory_reduced'], 'locked' => $row['locked'], 'eq_name' => $row['eq_name'], 'eq_notes' => $row['eq_notes'], 'eq_boil_size' => $row['eq_boil_size'], 'eq_batch_size' => $row['eq_batch_size'], 'eq_tun_volume' => $row['eq_tun_volume'], 'eq_tun_weight' => $row['eq_tun_weight'], 'eq_tun_specific_heat' => $row['eq_tun_specific_heat'], 'eq_tun_material' => $row['eq_tun_material'], 'eq_tun_height' => $row['eq_tun_height'], 'eq_top_up_water' => $row['eq_top_up_water'], 'eq_trub_chiller_loss' => $row['eq_trub_chiller_loss'], 'eq_evap_rate' => $row['eq_evap_rate'], 'eq_boil_time' => $row['eq_boil_time'], 'eq_calc_boil_volume' => $row['eq_calc_boil_volume'], 'eq_top_up_kettle' => $row['eq_top_up_kettle'], 'eq_hop_utilization' => $row['eq_hop_utilization'], 'eq_lauter_volume' => $row['eq_lauter_volume'], 'eq_lauter_height' => $row['eq_lauter_height'], 'eq_lauter_deadspace' => $row['eq_lauter_deadspace'], 'eq_kettle_volume' => $row['eq_kettle_volume'], 'eq_kettle_height' => $row['eq_kettle_height'], 'eq_mash_volume' => $row['eq_mash_volume'], 'eq_efficiency' => $row['eq_efficiency'], 'brew_date_start' => $row['brew_date_start'], 'brew_mash_ph' => $row['brew_mash_ph'], 'brew_mash_sg' => $row['brew_mash_sg'], 'brew_sparge_temperature' => $row['brew_sparge_temperature'], 'brew_sparge_volume' => $row['brew_sparge_volume'], 'brew_preboil_volume' => $row['brew_preboil_volume'], 'brew_preboil_sg' => $row['brew_preboil_sg'], 'brew_preboil_ph' => $row['brew_preboil_ph'], 'brew_aboil_volume' => $row['brew_aboil_volume'], 'brew_aboil_sg' => $row['brew_aboil_sg'], 'brew_aboil_ph' => $row['brew_aboil_ph'], 'brew_aboil_efficiency' => $row['brew_aboil_efficiency'], 'brew_cooling_method' => $row['brew_cooling_method'], 'brew_cooling_time' => $row['brew_cooling_time'], 'brew_cooling_to' => $row['brew_cooling_to'], 'brew_whirlpool9' => $row['brew_whirlpool9'], 'brew_whirlpool7' => $row['brew_whirlpool7'], 'brew_whirlpool6' => $row['brew_whirlpool6'], 'brew_whirlpool2' => $row['brew_whirlpool2'], 'brew_fermenter_volume' => $row['brew_fermenter_volume'], 'brew_fermenter_extrawater' => $row['brew_fermenter_extrawater'], 'brew_aeration_time' => $row['brew_aeration_time'], 'brew_aeration_speed' => $row['brew_aeration_speed'], 'brew_aeration_type' => $row['brew_aeration_type'], 'brew_fermenter_sg' => $row['brew_fermenter_sg'], 'brew_fermenter_ibu' => $row['brew_fermenter_ibu'], 'brew_date_end' => $row['brew_date_end'], 'brew_log_available' => $row['brew_log_available'], 'primary_start_temp' => $row['primary_start_temp'], 'primary_max_temp' => $row['primary_max_temp'], 'primary_end_temp' => $row['primary_end_temp'], 'primary_end_sg' => $row['primary_end_sg'], 'primary_end_date' => $row['primary_end_date'], 'secondary_temp' => $row['secondary_temp'], 'secondary_end_date' => $row['secondary_end_date'], 'tertiary_temp' => $row['tertiary_temp'], 'package_date' => $row['package_date'], 'bottle_amount' => $row['bottle_amount'], 'bottle_carbonation' => $row['bottle_carbonation'], 'bottle_priming_sugar' => $row['bottle_priming_sugar'], 'bottle_priming_amount' => $row['bottle_priming_amount'], 'bottle_carbonation_temp' => $row['bottle_carbonation_temp'], 'keg_amount' => $row['keg_amount'], 'keg_carbonation' => $row['keg_carbonation'], 'keg_priming_sugar' => $row['keg_priming_sugar'], 'keg_priming_amount' => $row['keg_priming_amount'], 'keg_carbonation_temp' => $row['keg_carbonation_temp'], 'keg_forced_carb' => $row['keg_forced_carb'], 'keg_pressure' => $row['keg_pressure'], 'keg_priming_factor' => $row['keg_priming_factor'], 'taste_notes' => $row['taste_notes'], 'taste_rate' => $row['taste_rate'], 'taste_date' => $row['taste_date'], 'taste_color' => $row['taste_color'], 'taste_transparency' => $row['taste_transparency'], 'taste_head' => $row['taste_head'], 'taste_aroma' => $row['taste_aroma'], 'taste_taste' => $row['taste_taste'], 'taste_mouthfeel' => $row['taste_mouthfeel'], 'taste_aftertaste' => $row['taste_aftertaste'] ); } // syslog(LOG_NOTICE, json_encode($brews)); echo json_encode($brews); } ?>