New in CWP Edge-LatestFree with every CWPpro licenceWebsites up to 300x faster

CWP now includes LSPHP, LSAPI-Cache and CWP Cage at no extra cost with all CWPpro licences. The LSAPI-Cache plugin is integrated into our WordPress and other script installers, and CWP Cage gives every user complete isolation. Available now in the CWP Edge-Latest version.

Get CWPpro ›

Real User Used Quota

Started by become, August 23, 2017, 03:43:15 PM

Previous topic - Next topic

become

I creted admin module to show real used quota for all users

https://github.com/betterapp/cwp-users-quota

darkness

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:

Hope you like it.
UNIX is a very simple OS, but you have to be a GENIUS to understand it ...

johnny09

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

darkness

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.
UNIX is a very simple OS, but you have to be a GENIUS to understand it ...

become


become