# reaches the notification limit an email will be sent out. This should be set up as a
# cron job.
include "../../include/db.php";
include "../../include/general.php";
if (!isset($disk_quota_limit_size_warning_noupload) && !isset($disk_quota_notification_limit_percent_warning)) {
    die("Please set the disk quota limits in your configuration before running this script!");
} else {
    echo "Checking disk usage...<br/>";
    # Work out free space / usage
    if (!file_exists($storagedir)) {
        mkdir($storagedir, 0777);
    }
    if (isset($disksize)) {
        # Use disk quota rather than real disk size
        $avail = $disksize * (1024 * 1024 * 1024);
        $used = get_total_disk_usage();
        $free = $avail - $used;
    } else {
        $avail = disk_total_space($storagedir);
        $free = disk_free_space($storagedir);
        $used = $avail - $free;
    }
    if ($free < 0) {
        $free = 0;
    }
    $avail_format = str_replace("&nbsp;", " ", formatfilesize($avail));
    $used_format = str_replace("&nbsp;", " ", formatfilesize($used));
    $free_format = str_replace("&nbsp;", " ", formatfilesize($free));
    $used_percent = round(($avail ? $used / $avail : 0) * 100, 0);
    echo $lang["diskusage"] . ": " . $used_percent . "%\n" . $lang["available"] . ": " . $avail_format . "\n" . $lang["used"] . ": " . $used_format . "\n" . $lang["free"] . ": " . $free_format . "<br/><br/>";
    if (isset($disk_quota_notification_limit_percent_warning)) {
function overquota()
	{
	# Return true if the system is over quota
	global $disksize;
	if (isset($disksize))
		{
		# Disk quota functionality. Calculate the usage by the $storagedir folder only rather than the whole disk.
		# Unix only due to reliance on 'du' command
		$avail=$disksize*(1024*1024*1024);
		$used=get_total_disk_usage();
		
		$free=$avail-$used;
		if ($free<=0) {return true;}
		}
	return false;
	}