Control Web Panel
Developers => New Modules => Topic started by: become on August 23, 2017, 03:43:15 PM
-
I creted admin module to show real used quota for all users
https://github.com/betterapp/cwp-users-quota
-
Hello,
First of all - Great job.
Sorry but I never used github for something different than "git clone ..." and I have no idea how to make a "Pull request" so I will put it here. As I have my own users on the shell and for them I have created an Unlimited (Quota) package I noticed a small error. If the package is Unlimited the quota is 0 (zero) and I saw "Division by zero ... bla bla bla". I made a small fix which you might like:
<?php
$usedQuotaPercent = null; <- Added for no warnings
$usedQuotaProgress = null; <- Added for no warnings
$packageMaxQuotaBytes = $result[$i]['disk_quota'] * 1024 * 1024;
if ($packageMaxQuotaBytes == "0") { <- Added for "Division by zero" error
echo "Unlimited";
} else {
$usedQuotaPercent = round($allQuota * 100 / $packageMaxQuotaBytes, 2);
$usedQuotaProgress = round($allQuota * 100 / $packageMaxQuotaBytes, 0);
}
echo "[$usedQuotaPercent %]";
$progressBarClass = 'progressBarGreen';
if ($usedQuotaProgress > 50) {
$progressBarClass = 'progressBarOrange';
}
if ($usedQuotaProgress > 90) {
$progressBarClass = 'progressBarRed';
}
?>
Like this for users with package "Unlimited" you see "Unlimited [%]" and always a full green bar. For the other users with different packages you see "[3.01%]" and green bar (for example). Something like this:
(http://i.imgur.com/map932S.png)
Hope you like it.
-
Something is wrong
Parse error: syntax error, unexpected '<' in /usr/local/cwpsrv/htdocs/resources/admin/modules/users_used_quota.php on line 268
Can you please add the full code here?
Thanks
-
Just replace:
<?php
$packageMaxQuotaBytes = $result[$i]['disk_quota'] * 1024 * 1024;
$usedQuotaPercent = round($allQuota * 100 / $packageMaxQuotaBytes, 2);
$usedQuotaProgress = round($allQuota * 100 / $packageMaxQuotaBytes, 0);
echo "[$usedQuotaPercent %]";
$progressBarClass = 'progressBarGreen';
if ($usedQuotaProgress > 50) {
$progressBarClass = 'progressBarOrange';
}
if ($usedQuotaProgress > 90) {
$progressBarClass = 'progressBarRed';
}
?>
With:
<?php
$usedQuotaPercent = null;
$usedQuotaProgress = null;
$packageMaxQuotaBytes = $result[$i]['disk_quota'] * 1024 * 1024;
if ($packageMaxQuotaBytes == "0") {
echo "Unlimited";
} else {
$usedQuotaPercent = round($allQuota * 100 / $packageMaxQuotaBytes, 2);
$usedQuotaProgress = round($allQuota * 100 / $packageMaxQuotaBytes, 0);
}
echo "[$usedQuotaPercent %]";
$progressBarClass = 'progressBarGreen';
if ($usedQuotaProgress > 50) {
$progressBarClass = 'progressBarOrange';
}
if ($usedQuotaProgress > 90) {
$progressBarClass = 'progressBarRed';
}
?>
Your error was coming from the comments I put here:
<- Added for no warnings
<- Added for no warnings
<- Added for "Division by zero" error
It was my bad assuming that people know that they need to remove that comments. Anyway, replace the code like I put it now and it will be ok.
-
I updated module today.
-
Updated today:
* add sum for all accounts
https://github.com/betterapp/cwp-users-quota (https://github.com/betterapp/cwp-users-quota)