www/includes/db_recipes.php

changeset 394
ccd85f0ed96c
parent 392
544d7d0183b2
child 559
10cc2400b5d5
--- a/www/includes/db_recipes.php	Sun Jun 02 19:56:44 2019 +0200
+++ b/www/includes/db_recipes.php	Tue Jun 04 16:37:58 2019 +0200
@@ -124,6 +124,17 @@
 	$comma = FALSE;
 	if (isset($_POST['fermentables'])) {
 		$array = $_POST['fermentables'];
+		// Sort the array
+                $added = array();
+                $amount = array();
+                for ($i = 0; $i < count($array); $i++) {
+                        $added[] = $array[$i]['f_added'];
+                        $amount[] = $array[$i]['f_amount'];
+                }
+                array_multisort($added, SORT_ASC, SORT_NUMERIC,
+                        $amount, SORT_DESC, SORT_NUMERIC,
+                        $array);
+                // Write the sorted array.
 		foreach($array as $key => $item){
 			/*
 			 * Manual encode to json.
@@ -164,6 +175,20 @@
 	$comma = FALSE;
 	if (isset($_POST['hops'])) {
 		$array = $_POST['hops'];
+		// Sort the array
+                $useat = array();
+                $time = array();
+                $amount = array();
+                for ($i = 0; $i < count($array); $i++) {
+                        $useat[] = $array[$i]['h_useat'];
+                        $time[] = $array[$i]['h_time'];
+                        $amount[] = $array[$i]['h_amount'];
+                }
+                array_multisort($useat, SORT_ASC, SORT_NUMERIC,
+                                $time, SORT_DESC, SORT_NUMERIC,
+                                $amount, SORT_DESC, SORT_NUMERIC,
+                                $array);
+                // Write the sorted array.
 		foreach($array as $key => $item){
 			if ($comma)
 				$hops .= ',';
@@ -195,6 +220,20 @@
 	$comma = FALSE;
 	if (isset($_POST['miscs'])) {
 		$array = $_POST['miscs'];
+		// Sort the array
+                $use = array();
+                $type = array();
+                $amount = array();
+                for ($i = 0; $i < count($array); $i++) {
+                        $use[] = $array[$i]['m_use_use'];
+                        $type[] = $array[$i]['m_type'];
+                        $amount[] = $array[$i]['m_amount'];
+                }
+                array_multisort($use, SORT_ASC, SORT_NUMERIC,
+                        $type, SORT_ASC, SORT_NUMERIC,
+                        $amount, SORT_DESC, SORT_NUMERIC,
+                        $array);
+                // Write the sorted array.
 		foreach($array as $key => $item) {
 			if ($comma)
 				$miscs .= ',';
@@ -217,7 +256,17 @@
 	$comma = FALSE;
 	if (isset($_POST['yeasts'])) {
 		$array = $_POST['yeasts'];
-syslog(LOG_NOTICE, $_POST['yeasts']);
+		// Sort the array
+                $use = array();
+                $amount = array();
+                for ($i = 0; $i < count($array); $i++) {
+                        $use[] = $array[$i]['y_use'];
+                        $amount[] = $array[$i]['y_amount'];
+                }
+                array_multisort($use, SORT_ASC, SORT_NUMERIC,
+                        $amount, SORT_DESC, SORT_NUMERIC,
+                        $array);
+                // Write the sorted array.
 		foreach($array as $key => $item) {
 			if ($comma)
 				$yeasts .= ',';
@@ -248,6 +297,13 @@
 	$comma = FALSE;
 	if (isset($_POST['mashs'])) {
 		$array = $_POST['mashs'];
+		// Sort the array
+                $temp = array();
+                for ($i = 0; $i < count($array); $i++) {
+                        $temp[] = $array[$i]['step_temp'];
+                }
+                array_multisort($temp, SORT_ASC, SORT_NUMERIC, $array);
+                // Write the sorted array.
 		foreach($array as $key => $item) {
 			if ($comma)
 				$mashs .= ',';

mercurial