From 2f52d90a431b47c8871141b511faa82336e145ca Mon Sep 17 00:00:00 2001
From: geoffhumphrey <507357@den-e88543m.la.frd.directv.com>
Date: Tue, 28 Jun 2016 09:45:59 -0600
Subject: [PATCH] Fix for Issue #635
---
includes/process/process_brewing.inc.php | 103 +++++++++++++++++------
lib/process.lib.php | 25 +++++-
2 files changed, 99 insertions(+), 29 deletions(-)
diff --git a/includes/process/process_brewing.inc.php b/includes/process/process_brewing.inc.php
index d6c8d2d0..9de9de2e 100644
--- a/includes/process/process_brewing.inc.php
+++ b/includes/process/process_brewing.inc.php
@@ -85,9 +85,16 @@
$brewMead2 = "";
$brewMead3 = "";
- if (isset($_POST['brewMead1'])) $brewMead1 .= $_POST['brewMead1'];
- if (isset($_POST['brewMead2'])) $brewMead2 .= $_POST['brewMead2'];
- if (isset($_POST['brewMead3'])) $brewMead3 .= $_POST['brewMead3'];
+ if (isset($_POST['brewMead1'])) $brewMead1 .= $_POST['brewMead1']; // Carbonation
+ if (isset($_POST['brewMead2'])) $brewMead2 .= $_POST['brewMead2']; // Sweetness
+ if (isset($_POST['brewMead3'])) $brewMead3 .= $_POST['brewMead3']; // Strength
+
+ /*
+ echo "Carb: ".$brewMead1."
";
+ echo "Sweet: ".$brewMead2."
";
+ echo "Strength: ".$brewMead3;
+ exit;
+ */
// The following are only enabled when preferences dictate that the recipe fields be shown.
if ($_SESSION['prefsHideRecipe'] == "N") {
@@ -445,48 +452,71 @@
}
- // Check if mead/cider entry has carbonation and sweetness
-
- if (check_mead_strength($styleBreak,$_SESSION['prefsStyleSet'])) {
-
- if (empty($brewMead3)) {
+
+ // $brewMead1 - Check if entry style requires carbonation
+ if (check_carb($styleBreak,$_SESSION['prefsStyleSet'])) {
+
+ if (empty($brewMead1)) {
$updateSQL = sprintf("UPDATE $brewing_db_table SET brewConfirmed='0' WHERE id=%s", GetSQLValueString($id, "int"));
mysqli_real_escape_string($connection,$updateSQL);
$result = mysqli_query($connection,$updateSQL) or die (mysqli_error($connection));
}
if ($section == "admin") {
- if (empty($brewMead3)) $insertGoTo = $base_url."index.php?section=brew&go=entries&filter=$filter&action=edit&id=$id&msg=1-".$styleReturn;
+ if ((empty($brewMead1)) || (empty($brewMead2))) $insertGoTo = $base_url."index.php?section=brew&go=entries&filter=$filter&action=edit&id=$id&msg=1-".$styleReturn;
else $insertGoTo = $base_url."index.php?section=admin&go=entries&msg=2";
}
else {
- if (empty($brewMead3)) $insertGoTo = $base_url."index.php?section=brew&action=edit&id=$id&msg=1-".$styleReturn;
+ if (empty($brewMead1)) $insertGoTo = $base_url."index.php?section=brew&action=edit&id=$id&msg=1-".$styleReturn;
else $insertGoTo = $base_url."index.php?section=list&msg=2";
}
- }
-
- if (check_carb_sweetness($styleBreak,$_SESSION['prefsStyleSet'])) {
+
+ }
+
+ // $brewMead2 - Check if entry style requires sweetness
+ if (check_sweetness($styleBreak,$_SESSION['prefsStyleSet'])) {
- if ((empty($brewMead1)) || (empty($brewMead2))) {
+ if (empty($brewMead2)) {
$updateSQL = sprintf("UPDATE $brewing_db_table SET brewConfirmed='0' WHERE id=%s", GetSQLValueString($id, "int"));
mysqli_real_escape_string($connection,$updateSQL);
$result = mysqli_query($connection,$updateSQL) or die (mysqli_error($connection));
}
if ($section == "admin") {
- if ((empty($brewMead1)) || (empty($brewMead2))) $insertGoTo = $base_url."index.php?section=brew&go=entries&filter=$filter&action=edit&id=$id&msg=1-".$styleReturn;
+ if (empty($brewMead2)) $insertGoTo = $base_url."index.php?section=brew&go=entries&filter=$filter&action=edit&id=$id&msg=1-".$styleReturn;
else $insertGoTo = $base_url."index.php?section=admin&go=entries&msg=2";
}
else {
- if ((empty($brewMead1)) || (empty($brewMead2))) $insertGoTo = $base_url."index.php?section=brew&action=edit&id=$id&msg=1-".$styleReturn;
+ if (empty($brewMead2)) $insertGoTo = $base_url."index.php?section=brew&action=edit&id=$id&msg=1-".$styleReturn;
else $insertGoTo = $base_url."index.php?section=list&msg=2";
}
}
+
+ // $brewMead3 - Check if entry style requires strength
+
+ if (check_mead_strength($styleBreak,$_SESSION['prefsStyleSet'])) {
+
+ if (empty($brewMead3)) {
+ $updateSQL = sprintf("UPDATE $brewing_db_table SET brewConfirmed='0' WHERE id=%s", GetSQLValueString($id, "int"));
+ mysqli_real_escape_string($connection,$updateSQL);
+ $result = mysqli_query($connection,$updateSQL) or die (mysqli_error($connection));
+ }
+
+ if ($section == "admin") {
+ if (empty($brewMead3)) $insertGoTo = $base_url."index.php?section=brew&go=entries&filter=$filter&action=edit&id=$id&msg=1-".$styleReturn;
+ else $insertGoTo = $base_url."index.php?section=admin&go=entries&msg=2";
+ }
+
+ else {
+ if (empty($brewMead3)) $insertGoTo = $base_url."index.php?section=brew&action=edit&id=$id&msg=1-".$styleReturn;
+ else $insertGoTo = $base_url."index.php?section=list&msg=2";
+ }
+ }
- if ((check_carb_sweetness($styleBreak,$_SESSION['prefsStyleSet'])) && (check_mead_strength($styleBreak,$_SESSION['prefsStyleSet']))) {
+ if ((check_carb($styleBreak,$_SESSION['prefsStyleSet'])) && (check_sweetness($styleBreak,$_SESSION['prefsStyleSet'])) && (check_mead_strength($styleBreak,$_SESSION['prefsStyleSet']))) {
if ((empty($brewMead1)) || (empty($brewMead2)) || (empty($brewMead3))) {
$updateSQL = sprintf("UPDATE $brewing_db_table SET brewConfirmed='0' WHERE id=%s", GetSQLValueString($id, "int"));
@@ -665,21 +695,41 @@
// Check if mead/cider entry has carbonation and sweetness, if so, override the $updateGoTo variable with another and redirect
- if (check_carb_sweetness($styleBreak,$_SESSION['prefsStyleSet'])) {
+ if (check_carb($styleBreak,$_SESSION['prefsStyleSet'])) {
+
+ if (empty($brewMead1)) {
+ $updateSQL = sprintf("UPDATE $brewing_db_table SET brewConfirmed='0' WHERE id=%s", GetSQLValueString($id, "text"));
+ mysqli_real_escape_string($connection,$updateSQL);
+ $result = mysqli_query($connection,$updateSQL) or die (mysqli_error($connection));
+ }
+
+ if ($section == "admin") {
+ if (empty($brewMead1)) $updateGoTo = $base_url."index.php?section=brew&go=entries&filter=$filter&action=edit&id=$id&msg=1-".$styleReturn;
+ else $updateGoTo = $base_url."index.php?section=admin&go=entries&msg=2";
+ }
+
+ else {
+ if (empty($brewMead1)) $updateGoTo = $base_url."index.php?section=brew&action=edit&id=$id&msg=1-".$styleReturn;
+ else $updateGoTo = $base_url."index.php?section=list&msg=2";
+ }
+
+ }
+
+ if (check_sweetness($styleBreak,$_SESSION['prefsStyleSet'])) {
- if ((empty($brewMead1)) || (empty($brewMead2))) {
+ if (empty($brewMead2)) {
$updateSQL = sprintf("UPDATE $brewing_db_table SET brewConfirmed='0' WHERE id=%s", GetSQLValueString($id, "text"));
mysqli_real_escape_string($connection,$updateSQL);
$result = mysqli_query($connection,$updateSQL) or die (mysqli_error($connection));
}
if ($section == "admin") {
- if ((empty($brewMead1)) || (empty($brewMead2))) $updateGoTo = $base_url."index.php?section=brew&go=entries&filter=$filter&action=edit&id=$id&msg=1-".$styleReturn;
+ if (empty($brewMead2)) $updateGoTo = $base_url."index.php?section=brew&go=entries&filter=$filter&action=edit&id=$id&msg=1-".$styleReturn;
else $updateGoTo = $base_url."index.php?section=admin&go=entries&msg=2";
}
else {
- if ((empty($brewMead1)) || (empty($brewMead2)))$updateGoTo = $base_url."index.php?section=brew&action=edit&id=$id&msg=1-".$styleReturn;
+ if (empty($brewMead2)) $updateGoTo = $base_url."index.php?section=brew&action=edit&id=$id&msg=1-".$styleReturn;
else $updateGoTo = $base_url."index.php?section=list&msg=2";
}
@@ -696,13 +746,13 @@
}
if ($section == "admin") {
- if (empty($brewMead3)) $updateGoTo = $base_url."index.php?section=admin&go=entries&msg=2";
- else $updateGoTo = $base_url."index.php?section=brew&go=entries&filter=$filter&action=edit&id=$id&msg=1-".$styleReturn;
+ if (empty($brewMead3)) $updateGoTo = $base_url."index.php?section=brew&go=entries&filter=$filter&action=edit&id=$id&msg=1-".$styleReturn;
+ else $updateGoTo = $base_url."index.php?section=admin&go=entries&msg=2";
}
else {
- if (empty($brewMead3)) $updateGoTo = $base_url."index.php?section=list&msg=2";
- else $updateGoTo = $base_url."index.php?section=brew&action=edit&id=$id&msg=1-".$styleReturn;
+ if (empty($brewMead3)) $updateGoTo = $base_url."index.php?section=brew&action=edit&id=$id&msg=1-".$styleReturn;
+ else $updateGoTo = $base_url."index.php?section=list&msg=2";
}
}
@@ -714,7 +764,8 @@
echo $style[0]."
";
echo $styleTrim."
";
if (check_mead_strength($styleBreak,$_SESSION['prefsStyleSet'])) echo "YES strength
"; else echo "No strength
";
- if (check_carb_sweetness($styleBreak,$_SESSION['prefsStyleSet'])) echo "YES carb/sweetness
"; else echo "No carb/sweeness
";
+ if (check_carb($styleBreak,$_SESSION['prefsStyleSet'])) echo "YES carb
"; else echo "No carb/sweeness
";
+ if (check_sweetness($styleBreak,$_SESSION['prefsStyleSet'])) echo "YES sweetness
"; else echo "No carb/sweeness
";
echo $brewMead1."
";
echo $brewMead2."
";
echo $brewMead3."
";
diff --git a/lib/process.lib.php b/lib/process.lib.php
index e7650291..9415e50a 100644
--- a/lib/process.lib.php
+++ b/lib/process.lib.php
@@ -206,7 +206,7 @@ function check_special_ingredients($style,$styleSet) {
}
*/
-function check_carb_sweetness($style,$styleSet) {
+function check_sweetness($style,$styleSet) {
include(CONFIG.'config.php');
mysqli_select_db($connection,$database);
@@ -216,11 +216,30 @@ function check_carb_sweetness($style,$styleSet) {
if (preg_match("/^[[:digit:]]+$/",$style[0])) $style_0 = sprintf('%02d',$style[0]);
else $style_0 = $style[0];
- $query_brews = sprintf("SELECT brewStyleCarb,brewStyleSweet FROM %s WHERE brewStyleGroup='%s' AND brewStyleNum='%s' AND (brewStyleVersion='%s' OR brewStyleOwn='custom')", $prefix."styles", $style_0, $style[1], $_SESSION['prefsStyleSet']);
+ $query_brews = sprintf("SELECT brewStyleSweet FROM %s WHERE brewStyleGroup='%s' AND brewStyleNum='%s' AND (brewStyleVersion='%s' OR brewStyleOwn='custom')", $prefix."styles", $style_0, $style[1], $_SESSION['prefsStyleSet']);
$brews = mysqli_query($connection,$query_brews) or die (mysqli_error($connection));
$row_brews = mysqli_fetch_assoc($brews);
- if (($row_brews['brewStyleCarb'] == 1) || ($row_brews['brewStyleSweet'] == 1)) return TRUE;
+ if ($row_brews['brewStyleSweet'] == 1) return TRUE;
+ else return FALSE;
+}
+
+
+function check_carb($style,$styleSet) {
+
+ include(CONFIG.'config.php');
+ mysqli_select_db($connection,$database);
+
+ $style = explode("-",$style);
+
+ if (preg_match("/^[[:digit:]]+$/",$style[0])) $style_0 = sprintf('%02d',$style[0]);
+ else $style_0 = $style[0];
+
+ $query_brews = sprintf("SELECT brewStyleCarb FROM %s WHERE brewStyleGroup='%s' AND brewStyleNum='%s' AND (brewStyleVersion='%s' OR brewStyleOwn='custom')", $prefix."styles", $style_0, $style[1], $_SESSION['prefsStyleSet']);
+ $brews = mysqli_query($connection,$query_brews) or die (mysqli_error($connection));
+ $row_brews = mysqli_fetch_assoc($brews);
+
+ if ($row_brews['brewStyleCarb'] == 1) return TRUE;
else return FALSE;
}