Skip to content

Commit

Permalink
Fix for Issue #635
Browse files Browse the repository at this point in the history
  • Loading branch information
geoffhumphrey committed Jun 28, 2016
1 parent ac0bf92 commit 2f52d90
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 29 deletions.
103 changes: 77 additions & 26 deletions includes/process/process_brewing.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -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."<br>";
echo "Sweet: ".$brewMead2."<br>";
echo "Strength: ".$brewMead3;
exit;
*/

// The following are only enabled when preferences dictate that the recipe fields be shown.
if ($_SESSION['prefsHideRecipe'] == "N") {
Expand Down Expand Up @@ -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"));
Expand Down Expand Up @@ -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";
}

Expand All @@ -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";
}
}

Expand All @@ -714,7 +764,8 @@
echo $style[0]."<br>";
echo $styleTrim."<br>";
if (check_mead_strength($styleBreak,$_SESSION['prefsStyleSet'])) echo "YES strength<br>"; else echo "No strength<br>";
if (check_carb_sweetness($styleBreak,$_SESSION['prefsStyleSet'])) echo "YES carb/sweetness<br>"; else echo "No carb/sweeness<br>";
if (check_carb($styleBreak,$_SESSION['prefsStyleSet'])) echo "YES carb<br>"; else echo "No carb/sweeness<br>";
if (check_sweetness($styleBreak,$_SESSION['prefsStyleSet'])) echo "YES sweetness<br>"; else echo "No carb/sweeness<br>";
echo $brewMead1."<br>";
echo $brewMead2."<br>";
echo $brewMead3."<br>";
Expand Down
25 changes: 22 additions & 3 deletions lib/process.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
}

Expand Down

0 comments on commit 2f52d90

Please sign in to comment.