/**
 * Genrate statistics entry for the given user
 *
 * @param iMSCP_pTemplate $tpl Template engine instance
 * @param int $adminId User unique identifier
 * @return void
 */
function _generateUserStatistics($tpl, $adminId)
{
    list($adminName, $domainId, $web, $ftp, $smtp, $pop3, $trafficUsageBytes, $diskspaceUsageBytes) = shared_getCustomerStats($adminId);
    list($usub_current, $usub_max, $uals_current, $uals_max, $umail_current, $umail_max, $uftp_current, $uftp_max, $usql_db_current, $usql_db_max, $usql_user_current, $usql_user_max, $trafficMaxMebimytes, $diskspaceMaxMebibytes) = shared_getCustomerProps($adminId);
    $trafficLimitBytes = $trafficMaxMebimytes * 1048576;
    $diskspaceLimitBytes = $diskspaceMaxMebibytes * 1048576;
    $trafficUsagePercent = make_usage_vals($trafficUsageBytes, $trafficLimitBytes);
    $diskspaceUsagePercent = make_usage_vals($diskspaceUsageBytes, $diskspaceLimitBytes);
    $tpl->assign(array('USER_NAME' => tohtml(decode_idna($adminName)), 'USER_ID' => tohtml($adminId), 'TRAFF_PERCENT' => tohtml($trafficUsagePercent), 'TRAFF_MSG' => $trafficLimitBytes ? tohtml(tr('%s of %s', bytesHuman($trafficUsageBytes), bytesHuman($trafficLimitBytes))) : tohtml(tr('%s of unlimited', bytesHuman($trafficUsageBytes))), 'DISK_PERCENT' => tohtml($diskspaceUsagePercent), 'DISK_MSG' => $diskspaceLimitBytes ? tohtml(tr('%s of %s', bytesHuman($diskspaceUsageBytes), bytesHuman($diskspaceLimitBytes))) : tohtml(tr('%s of unlimited', bytesHuman($diskspaceUsageBytes))), 'WEB' => tohtml(bytesHuman($web)), 'FTP' => tohtml(bytesHuman($ftp)), 'SMTP' => tohtml(bytesHuman($smtp)), 'POP3' => tohtml(bytesHuman($pop3)), 'SUB_MSG' => $usub_max ? tohtml(tr('%d of %s', $usub_current, translate_limit_value($usub_max))) : tohtml(translate_limit_value($usub_max)), 'ALS_MSG' => $uals_max ? tohtml(tr('%d of %s', $uals_current, translate_limit_value($uals_max))) : tohtml(translate_limit_value($uals_max)), 'MAIL_MSG' => $umail_max ? tohtml(tr('%d of %s', $umail_current, translate_limit_value($umail_max))) : tohtml(translate_limit_value($umail_max)), 'FTP_MSG' => $uftp_max ? tohtml(tr('%d of %s', $uftp_current, translate_limit_value($uftp_max))) : tohtml(translate_limit_value($uftp_max)), 'SQL_DB_MSG' => $usql_db_max ? tohtml(tr('%d of %s', $usql_db_current, translate_limit_value($usql_db_max))) : tohtml(translate_limit_value($usql_db_max)), 'SQL_USER_MSG' => $usql_user_max ? tohtml(tr('%1$d of %2$d', $usql_user_current, translate_limit_value($usql_user_max))) : tohtml(translate_limit_value($usql_user_max))));
}
/**
 * Generates statistics for the given user
 *
 * @access private
 * @param iMSCP_pTemplate $tpl Template engine instance
 * @param int $adminId User unique identifier
 * @return void
 */
function _generateUserStatistics($tpl, $adminId)
{
    list($adminName, , $webTraffic, $ftpTraffic, $smtpTraffic, $popImapTraffic, $trafficUsageBytes, $diskspaceUsageBytes) = shared_getCustomerStats($adminId);
    list($subCount, $subMax, $alsCount, $alsMax, $mailCount, $mailMax, $ftpUserCount, $FtpUserMax, $sqlDbCount, $sqlDbMax, $sqlUserCount, $sqlUserMax, $trafficLimit, $diskspaceLimit) = shared_getCustomerProps($adminId);
    $trafficLimitBytes = $trafficLimit * 1048576;
    $diskspaceLimitBytes = $diskspaceLimit * 1048576;
    $trafficPercent = make_usage_vals($trafficUsageBytes, $trafficLimitBytes);
    $diskPercent = make_usage_vals($diskspaceUsageBytes, $diskspaceLimitBytes);
    $tpl->assign(array('USER_ID' => tohtml($adminId), 'USERNAME' => tohtml(decode_idna($adminName)), 'TRAFF_PERCENT' => tohtml($trafficPercent), 'TRAFF_MSG' => $trafficLimitBytes ? tohtml(tr('%1$s / %2$s', bytesHuman($trafficUsageBytes), bytesHuman($trafficLimitBytes))) : tohtml(tr('%s / unlimited', bytesHuman($trafficUsageBytes))), 'DISK_PERCENT' => tohtml($diskPercent), 'DISK_MSG' => $diskspaceLimitBytes ? tohtml(tr('%1$s / %2$s', bytesHuman($diskspaceUsageBytes), bytesHuman($diskspaceLimitBytes))) : tohtml(tr('%s / unlimited', bytesHuman($diskspaceUsageBytes))), 'WEB' => tohtml(bytesHuman($webTraffic)), 'FTP' => tohtml(bytesHuman($ftpTraffic)), 'SMTP' => tohtml(bytesHuman($smtpTraffic)), 'POP3' => tohtml(bytesHuman($popImapTraffic)), 'SUB_MSG' => $subMax ? $subMax > 0 ? tohtml(tr('%1$d / %2$d', $subCount, $subMax)) : tohtml(tr('disabled')) : tohtml(tr('%d / unlimited', $subCount)), 'ALS_MSG' => $alsMax ? $alsMax > 0 ? tohtml(tr('%1$d / %2$d', $alsCount, $alsMax)) : tohtml(tr('disabled')) : tohtml(tr('%d / unlimited', $alsCount)), 'MAIL_MSG' => $mailMax ? $mailMax > 0 ? tohtml(tr('%1$d / %2$d', $mailCount, $mailMax)) : tohtml(tr('disabled')) : tohtml(tr('%d / unlimited', $mailCount)), 'FTP_MSG' => $FtpUserMax ? $FtpUserMax > 0 ? tohtml(tr('%1$d / %2$d', $ftpUserCount, $FtpUserMax)) : tohtml(tr('disabled')) : tohtml(tr('%d / unlimited', $ftpUserCount)), 'SQL_DB_MSG' => $sqlDbMax ? $sqlDbMax > 0 ? tohtml(tr('%1$d / %2$d', $sqlDbCount, $sqlDbMax)) : tohtml(tr('disabled')) : tohtml(tr('%d / unlimited', $sqlDbCount)), 'SQL_USER_MSG' => $sqlUserMax ? $sqlUserMax > 0 ? tohtml(tr('%1$d / %2$d', $sqlUserCount, $sqlUserMax)) : tohtml(tr('disabled')) : tohtml(tr('%d / unlimited', $sqlUserCount))));
}
Exemple #3
0
/**
 * Generates user's properties
 *
 * @param int $resellerId Reseller unique identifier
 * @return array An array that contains user's properties
 */
function generate_reseller_user_props($resellerId)
{
    $rdmnCurrent = $rdmnMax = $rsubCurrent = $rsubMax = $ralsCurrent = $ralsMax = $rmailCurrent = $rmailMax = $rftpCurrent = $rftpMax = $rsqlDbCurrent = $rsqlDbMax = $rsqlUserCurrent = $rsqlUserMax = $rtraffCurrent = $rtraffMax = $rdiskCurrent = $rdiskMax = 0;
    $rdmnUf = $rsubUf = $ralsUf = $rmailUf = $rftpUf = $rsqlDbUf = $rsqlUserUf = $rtraffUf = $rdiskUf = '_off_';
    $stmt = exec_query('
			SELECT
				admin_id, domain_id
			FROM
				admin
			INNER JOIN
				domain ON(domain_admin_id = admin_id)
			WHERE
				created_by = ?
		', $resellerId);
    if (!$stmt->rowCount()) {
        return array_fill(0, 27, 0);
    }
    while ($data = $stmt->fetchRow()) {
        $adminId = $data['admin_id'];
        list($subCurrent, $subMax, $alsCurrent, $alsMax, $mailCurrent, $mailMax, $ftpCurrent, $ftpMax, $sqlDbCurrent, $sqlDbMax, $sqlUserCurrent, $sqlUserMax, $traffMax, $diskMax) = get_user_props($adminId);
        list(, , , , , , $traffCurrent, $diskCurrent) = shared_getCustomerStats($adminId);
        $rdmnCurrent += 1;
        if ($subMax != -1) {
            if ($subMax == 0) {
                $rsubUf = '_on_';
            }
            $rsubCurrent += $subCurrent;
            $rsubMax += $subMax;
        }
        if ($alsMax == 0) {
            $ralsUf = '_on_';
        }
        $ralsCurrent += $alsCurrent;
        $ralsMax += $alsMax;
        if ($mailMax != -1) {
            if ($mailMax == 0) {
                $rmailUf = '_on_';
            }
            $rmailCurrent += $mailCurrent;
            $rmailMax += $mailMax;
        }
        if ($ftpMax != -1) {
            if ($ftpMax == 0) {
                $rftpUf = '_on_';
            }
            $rftpCurrent += $ftpCurrent;
            $rftpMax += $ftpMax;
        }
        if ($sqlDbMax != -1) {
            if ($sqlDbMax == 0) {
                $rsqlDbUf = '_on_';
            }
            $rsqlDbCurrent += $sqlDbCurrent;
            $rsqlDbMax += $sqlDbMax;
        }
        if ($sqlUserMax != -1) {
            if ($sqlUserMax == 0) {
                $rsqlUserUf = '_on_';
            }
            $rsqlUserCurrent += $sqlUserCurrent;
            $rsqlUserMax += $sqlUserMax;
        }
        if ($traffMax == 0) {
            $rtraffUf = '_on_';
        }
        $rtraffCurrent += $traffCurrent;
        $rtraffMax += $traffMax;
        if ($diskMax == 0) {
            $rdiskUf = '_on_';
        }
        $rdiskCurrent += $diskCurrent;
        $rdiskMax += $diskMax;
    }
    return array($rdmnCurrent, $rdmnMax, $rdmnUf, $rsubCurrent, $rsubMax, $rsubUf, $ralsCurrent, $ralsMax, $ralsUf, $rmailCurrent, $rmailMax, $rmailUf, $rftpCurrent, $rftpMax, $rftpUf, $rsqlDbCurrent, $rsqlDbMax, $rsqlDbUf, $rsqlUserCurrent, $rsqlUserMax, $rsqlUserUf, $rtraffCurrent, $rtraffMax, $rtraffUf, $rdiskCurrent, $rdiskMax, $rdiskUf);
}
Exemple #4
0
/**
 * Returns the total number of consumed and assigned items for the given reseller
 *
 * @param  int $resellerId Reseller unique indentifier
 * @return array
 */
function generate_reseller_users_props($resellerId)
{
    $rdmnConsumed = $rdmnAssigned = $rsubConsumed = $rsubAssigned = $ralsConsumed = $ralsAssigned = $rmailConsumed = $rmailAssigned = $rftpConsumed = $rftpAssigned = $rsqlDbConsumed = $rsqlDbAssigned = $rsqlUserConsumed = $rsqlUserAssigned = $rtraffConsumed = $rtraffAssigned = $rdiskConsumed = $rdiskAssigned = 0;
    $stmt = exec_query('SELECT admin_id FROM admin WHERE created_by = ?', $resellerId);
    $rdmnUnlimited = $rsubUnlimited = $ralsUnlimited = $rmailUnlimited = $rftpUnlimited = $rsqlDbUnlimited = $rsqlUserUnlimited = $rtraffUnlimited = $rdiskUnlimited = false;
    if (!$stmt->rowCount()) {
        // Case in reseller has not customer yet
        return array($rdmnConsumed, $rdmnAssigned, $rdmnUnlimited, $rsubConsumed, $rsubAssigned, $rsubUnlimited, $ralsConsumed, $ralsAssigned, $ralsUnlimited, $rmailConsumed, $rmailAssigned, $rmailUnlimited, $rftpConsumed, $rftpAssigned, $rftpUnlimited, $rsqlDbConsumed, $rsqlDbAssigned, $rsqlDbUnlimited, $rsqlUserConsumed, $rsqlUserAssigned, $rsqlUserUnlimited, $rtraffConsumed, $rtraffAssigned, $rtraffUnlimited, $rdiskConsumed, $rdiskAssigned, $rdiskUnlimited);
    }
    while ($row = $stmt->fetchRow(PDO::FETCH_ASSOC)) {
        list($subConsumed, $subAssigned, $alsConsumed, $alsAssigned, $mailConsumed, $mailAssigned, $ftpConsumed, $ftpAssigned, $sqlDbConsumed, $sqlDbAssigned, $sqlUserConsumed, $sqlUserAssigned, $traffAssigned, $diskAssigned) = shared_getCustomerProps($row['admin_id']);
        list(, , , , , , $traffConsumed, $diskConsumed) = shared_getCustomerStats($row['admin_id']);
        $rdmnConsumed += 1;
        // Compute subdomains
        if ($subAssigned != -1) {
            $rsubConsumed += $subConsumed;
            $rsubAssigned += $subAssigned;
            if (!$subAssigned) {
                $rsubUnlimited = true;
            }
        }
        // Compute domain aliases
        if ($alsAssigned != -1) {
            $ralsConsumed += $alsConsumed;
            $ralsAssigned += $alsAssigned;
            if (!$alsAssigned) {
                $ralsUnlimited = true;
            }
        }
        // Compute mail accounts
        if ($sqlDbAssigned != -1) {
            $rmailConsumed += $mailConsumed;
            $rmailAssigned += $mailAssigned;
            if (!$mailAssigned) {
                $rmailUnlimited = true;
            }
        }
        // Compute Ftp account
        if ($ftpAssigned != -1) {
            $rftpConsumed += $ftpConsumed;
            $rftpAssigned += $ftpAssigned;
            if (!$ftpAssigned) {
                $rftpUnlimited = true;
            }
        }
        // Compute Sql databases
        if ($sqlDbAssigned != -1) {
            $rsqlDbConsumed += $sqlDbConsumed;
            $rsqlDbAssigned += $sqlDbAssigned;
            if (!$sqlDbAssigned) {
                $rsqlDbUnlimited = true;
            }
        }
        // Compute Sql users
        if ($sqlUserAssigned != -1) {
            $rsqlUserConsumed += $sqlUserConsumed;
            $rsqlUserAssigned += $sqlUserAssigned;
            if (!$sqlUserAssigned) {
                $rsqlUserUnlimited = true;
            }
        }
        // Compute Monthly traffic volume
        $rtraffConsumed += $traffConsumed;
        $rtraffAssigned += $traffAssigned;
        if (!$rtraffAssigned) {
            $rtraffUnlimited = true;
        }
        // Compute diskspace
        $rdiskConsumed += $diskConsumed;
        $rdiskAssigned += $diskAssigned;
        if (!$rdiskAssigned) {
            $rdiskUnlimited = true;
        }
    }
    return array($rdmnConsumed, $rdmnAssigned, $rdmnUnlimited, $rsubConsumed, $rsubAssigned, $rsubUnlimited, $ralsConsumed, $ralsAssigned, $ralsUnlimited, $rmailConsumed, $rmailAssigned, $rmailUnlimited, $rftpConsumed, $rftpAssigned, $rftpUnlimited, $rsqlDbConsumed, $rsqlDbAssigned, $rsqlDbUnlimited, $rsqlUserConsumed, $rsqlUserAssigned, $rsqlUserUnlimited, $rtraffConsumed, $rtraffAssigned, $rtraffUnlimited, $rdiskConsumed, $rdiskAssigned, $rdiskUnlimited);
}