fix zero division error when userquota is 0 but prevent setting quota=0 anyway
Bernd Wurst

Bernd Wurst commited on 2024-09-29 05:21:48
Zeige 3 geänderte Dateien mit 7 Einfügungen und 4 Löschungen.

... ...
@@ -36,7 +36,7 @@ if (!customer_may_have_useraccounts()) {
36 36
         foreach ($usedquota as $q) {
37 37
             $mailbar = '';
38 38
             $mailstring = '';
39
-            $mailpercent = round(($q['mailquota'] / $q["systemquota"]) * 100);
39
+            $mailpercent = round(($q['mailquota'] / max($q["systemquota"],1)) * 100);
40 40
             $mailwidth = 2 * min($mailpercent, 100);
41 41
 
42 42
             if ($q["mailquota"] > 0) {
... ...
@@ -44,7 +44,7 @@ if (!customer_may_have_useraccounts()) {
44 44
                 $mailbar = "<div style=\"font-size: 1px; background-color: blue; height: 10px; width: {$mailwidth}px; margin: 0; padding: 0; float: left;\">&#160;</div>";
45 45
             }
46 46
 
47
-            $percent = round((($q["systemquota_used"] + $q["mailquota"]) / $q["systemquota"]) * 100);
47
+            $percent = round((($q["systemquota_used"] + $q["mailquota"]) / max($q["systemquota"],1)) * 100);
48 48
             $color = ($percent > 99 ? 'red' : ($percent > 80 ? "yellow" : "green"));
49 49
             $width = 2 * min($percent, 100) - $mailwidth;
50 50
 
... ...
@@ -28,7 +28,7 @@ $need_more_storage = false;
28 28
 foreach ($usedquota as $q) {
29 29
     $mailbar = '';
30 30
     $mailstring = '';
31
-    $mailpercent = round(($q['mailquota'] / $q["systemquota"]) * 100);
31
+    $mailpercent = round(($q['mailquota'] / max($q["systemquota"],1)) * 100);
32 32
     $mailwidth = 2 * min($mailpercent, 100);
33 33
 
34 34
     if ($q["mailquota"] > 0) {
... ...
@@ -36,7 +36,7 @@ foreach ($usedquota as $q) {
36 36
         $mailbar = "<div style=\"font-size: 1px; background-color: blue; height: 10px; width: {$mailwidth}px; margin: 0; padding: 0; float: left;\">&#160;</div>";
37 37
     }
38 38
 
39
-    $percent = round((($q["systemquota_used"] + $q["mailquota"]) / $q["systemquota"]) * 100);
39
+    $percent = round((($q["systemquota_used"] + $q["mailquota"]) / max($q["systemquota"],1)) * 100);
40 40
     if ($percent > 90) {
41 41
         $need_more_storage = true;
42 42
     }
... ...
@@ -66,6 +66,9 @@ if ($_GET['action'] == 'new') {
66 66
         $maxquota = $customerquota['max'] - $customerquota['assigned'] + $account['quota'];
67 67
 
68 68
         $quota = (int) $_POST['quota'];
69
+        if ($quota < 1) {
70
+            system_failure("Sie müssen dem Account mindestens 1 MB Speicherplatz zuweisen.");
71
+        }
69 72
         if ($quota > $maxquota) {
70 73
             system_failure("Sie können diesem Account maximal {$maxquota} MB Speicherplatz zuweisen.");
71 74
         }
72 75