500 |
500 |
501 /* |
501 /* |
502 * SELECT, produce a list of products that can be fermented. |
502 * SELECT, produce a list of products that can be fermented. |
503 */ |
503 */ |
504 if (isset($_GET['select']) && ($_GET['select'] == "ferment")) { |
504 if (isset($_GET['select']) && ($_GET['select'] == "ferment")) { |
505 $query = "SELECT code,name,uuid,stage FROM products WHERE "; |
505 $query = "SELECT code,name,uuid,stage,json_yeasts FROM products WHERE "; |
506 $query .= "stage='1' OR stage='2' OR stage='3' OR stage='4' OR stage='5' OR stage='6' ORDER BY code;"; |
506 $query .= "stage='1' OR stage='2' OR stage='3' OR stage='4' OR stage='5' OR stage='6' ORDER BY code;"; |
507 $result = mysqli_query($connect, $query) or die("SQL Error 1: " . mysqli_error($connect)); |
507 $result = mysqli_query($connect, $query) or die("SQL Error 1: " . mysqli_error($connect)); |
508 while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) { |
508 while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) { |
|
509 $yl = 0; |
|
510 $yh = 40; |
|
511 $yeasts = json_decode($row['json_yeasts'], true); |
|
512 for ($i = 0; $i < count($yeasts); $i++) { |
|
513 if ($yeasts[$i]['y_use'] == 0) { // Primary |
|
514 if (floatval($yeasts[$i]['y_min_temperature']) > $yl) |
|
515 $yl = floatval($yeasts[$i]['y_min_temperature']); |
|
516 if (floatval($yeasts[$i]['y_max_temperature']) < $yh) |
|
517 $yh = floatval($yeasts[$i]['y_max_temperature']); |
|
518 } |
|
519 } |
509 $brews[] = array( |
520 $brews[] = array( |
510 'code' => $row['code'], |
521 'code' => $row['code'], |
511 'name' => $row['name'], |
522 'name' => $row['name'], |
512 'uuid' => $row['uuid'], |
523 'uuid' => $row['uuid'], |
513 'stage' => $row['stage'] |
524 'stage' => $row['stage'], |
|
525 'yeast_lo' => $yl, |
|
526 'yeast_hi' => $yh |
514 ); |
527 ); |
515 } |
528 } |
516 header("Content-type: application/json"); |
529 header("Content-type: application/json"); |
517 echo json_encode($brews, JSON_UNESCAPED_UNICODE); |
530 echo json_encode($brews, JSON_UNESCAPED_UNICODE); |
518 return; |
531 return; |