From a64c9c806330edfb0785a193fd2e0cea70d1bbdf Mon Sep 17 00:00:00 2001
From: Xaver Maierhofer <xwissen@xwissen.info>
Date: Fri, 24 Jan 2020 10:19:52 +0100
Subject: [PATCH] Sort list quota correct

---
 interface/lib/classes/listform_actions.inc.php | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/interface/lib/classes/listform_actions.inc.php b/interface/lib/classes/listform_actions.inc.php
index 4a463fe015..097b41fc0d 100644
--- a/interface/lib/classes/listform_actions.inc.php
+++ b/interface/lib/classes/listform_actions.inc.php
@@ -39,6 +39,7 @@ class listform_actions {
 	private $sortKeys;
 
 	private function _sort($aOne, $aTwo) {
+		$suffixes=array('k' => 1, 'M' => 1024, 'G' => 1048576, 'T' => 1099511627776);
 		if(!is_array($aOne) || !is_array($aTwo)) return 0;
 
 		if(!is_array($this->sortKeys)) $this->sortKeys = array($this->sortKeys);
@@ -49,6 +50,15 @@ class listform_actions {
 			}
 			$a = $aOne[$sKey];
 			$b = $aTwo[$sKey];
+
+			if(preg_match('/(\d+\.?\d*) ([kMGT])B/', $a, $match)) {
+				$a = $match[1] * $suffixes[$match[2]];
+			}
+
+			if(preg_match('/(\d+\.?\d*) ([kMGT])B/', $b, $match)) {
+				$b = $match[1]  * $suffixes[$match[2]];
+			}
+
 			if(is_string($a)) $a = strtolower($a);
 			if(is_string($b)) $b = strtolower($b);
 			if($a < $b) return $sDir == 'DESC' ? 1 : -1;
@@ -129,7 +139,7 @@ class listform_actions {
 
 		// Getting Datasets from DB
 		$records = $app->db->queryAllRecords($this->getQueryString($php_sort));
-		
+
 		$csrf_token = $app->auth->csrf_token_get($app->listform->listDef['name']);
 		$_csrf_id = $csrf_token['csrf_id'];
 		$_csrf_key = $csrf_token['csrf_key'];
-- 
GitLab