/** * 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)))); }
/** * Update resellers limit * * @throws iMSCP_Exception_Database * @param int $toReseller Reseller for which the givens customer are moved to * @param int $fromReseller Reseller for wich the givens customers are moved from * @param array $users List of user to move * @param array $errorsStack Error stack * @return bool */ function admin_updateResellerLimits($toReseller, $fromReseller, $users, &$errorsStack) { $toResellerProperties = imscp_getResellerProperties($toReseller); $fromResellerProperties = imscp_getResellerProperties($fromReseller, true); $usersList = explode(';', $users); for ($i = 0, $countUsersList = count($usersList) - 1; $i < $countUsersList; $i++) { $stmt = exec_query('SELECT domain_name FROM domain WHERE domain_admin_id = ?', $usersList[$i]); if ($stmt->rowCount()) { $domainName = $stmt->fields['domain_name']; list($subdomainsLimit, , $domainAliasesLimit, , $mailAccountsLimit, , $ftpAccountsLimit, , $sqlDatabasesLimit, , $sqlUsersLimit, , $trafficLimit, $diskspaceLimit) = shared_getCustomerProps($usersList[$i]); calculate_reseller_dvals($toResellerProperties['current_dmn_cnt'], $toResellerProperties['max_dmn_cnt'], $src_dmn_current, $fromResellerProperties['max_dmn_cnt'], 1, $errorsStack, 'Domain', $domainName); if ($errorsStack == '_off_') { calculate_reseller_dvals($toResellerProperties['current_sub_cnt'], $toResellerProperties['max_sub_cnt'], $fromResellerProperties['current_sub_cnt'], $fromResellerProperties['max_sub_cnt'], $subdomainsLimit, $errorsStack, 'Subdomain', $domainName); calculate_reseller_dvals($toResellerProperties['current_als_cnt'], $toResellerProperties['max_als_cnt'], $fromResellerProperties['current_als_cnt'], $fromResellerProperties['max_als_cnt'], $domainAliasesLimit, $errorsStack, 'Alias', $domainName); calculate_reseller_dvals($toResellerProperties['current_mail_cnt'], $toResellerProperties['max_mail_cnt'], $fromResellerProperties['current_mail_cnt'], $fromResellerProperties['max_mail_cnt'], $mailAccountsLimit, $errorsStack, 'Mail', $domainName); calculate_reseller_dvals($toResellerProperties['current_ftp_cnt'], $toResellerProperties['max_ftp_cnt'], $fromResellerProperties['current_ftp_cnt'], $fromResellerProperties['max_ftp_cnt'], $ftpAccountsLimit, $errorsStack, 'FTP', $domainName); calculate_reseller_dvals($toResellerProperties['current_sql_db_cnt'], $toResellerProperties['max_sql_db_cnt'], $fromResellerProperties['current_sql_db_cnt'], $fromResellerProperties['max_sql_db_cnt'], $sqlDatabasesLimit, $errorsStack, 'SQL Database', $domainName); calculate_reseller_dvals($toResellerProperties['current_sql_user_cnt'], $toResellerProperties['max_sql_user_cnt'], $fromResellerProperties['current_sql_user_cnt'], $fromResellerProperties['max_sql_user_cnt'], $sqlUsersLimit, $errorsStack, 'SQL User', $domainName); calculate_reseller_dvals($toResellerProperties['current_traff_amnt'], $toResellerProperties['max_traff_amnt'], $fromResellerProperties['current_traff_amnt'], $fromResellerProperties['max_traff_amnt'], $trafficLimit, $errorsStack, 'Traffic', $domainName); calculate_reseller_dvals($toResellerProperties['current_disk_amnt'], $toResellerProperties['max_disk_amnt'], $fromResellerProperties['current_disk_amnt'], $fromResellerProperties['max_disk_amnt'], $diskspaceLimit, $errorsStack, 'Disk', $domainName); } if ($errorsStack != '_off_') { return false; } } else { } } // Update reseller properties /** @var $db iMSCP_Database */ $db = iMSCP_Database::getInstance(); try { $db->beginTransaction(); $newFromResellerProperties = "{$fromResellerProperties['current_dmn_cnt']};{$fromResellerProperties['max_dmn_cnt']};"; $newFromResellerProperties .= "{$fromResellerProperties['current_sub_cnt']};{$fromResellerProperties['max_sub_cnt']};"; $newFromResellerProperties .= "{$fromResellerProperties['current_als_cnt']};{$fromResellerProperties['max_als_cnt']};"; $newFromResellerProperties .= "{$fromResellerProperties['current_mail_cnt']};{$fromResellerProperties['max_mail_cnt']};"; $newFromResellerProperties .= "{$fromResellerProperties['current_ftp_cnt']};{$fromResellerProperties['max_ftp_cnt']};"; $newFromResellerProperties .= "{$fromResellerProperties['current_sql_db_cnt']};{$fromResellerProperties['max_sql_db_cnt']};"; $newFromResellerProperties .= "{$fromResellerProperties['current_sql_user_cnt']};{$fromResellerProperties['max_sql_user_cnt']};"; $newFromResellerProperties .= "{$fromResellerProperties['current_traff_amnt']};{$fromResellerProperties['max_traff_amnt']};"; $newFromResellerProperties .= "{$fromResellerProperties['current_disk_amnt']};{$fromResellerProperties['max_disk_amnt']};"; update_reseller_props($fromReseller, $newFromResellerProperties); $newToResellerProperties = "{$toResellerProperties['current_dmn_cnt']};{$toResellerProperties['max_dmn_cnt']};"; $newToResellerProperties .= "{$toResellerProperties['current_sub_cnt']};{$toResellerProperties['max_sub_cnt']};"; $newToResellerProperties .= "{$toResellerProperties['current_als_cnt']};{$toResellerProperties['max_als_cnt']};"; $newToResellerProperties .= "{$toResellerProperties['current_mail_cnt']};{$toResellerProperties['max_mail_cnt']};"; $newToResellerProperties .= "{$toResellerProperties['current_ftp_cnt']};{$toResellerProperties['max_ftp_cnt']};"; $newToResellerProperties .= "{$toResellerProperties['current_sql_db_cnt']};{$toResellerProperties['max_sql_db_cnt']};"; $newToResellerProperties .= "{$toResellerProperties['current_sql_user_cnt']};{$toResellerProperties['max_sql_user_cnt']};"; $newToResellerProperties .= "{$toResellerProperties['current_traff_amnt']};{$toResellerProperties['max_traff_amnt']};"; $newToResellerProperties .= "{$toResellerProperties['current_disk_amnt']};{$toResellerProperties['max_disk_amnt']};"; update_reseller_props($toReseller, $newToResellerProperties); for ($i = 0, $countUsersList = count($usersList) - 1; $i < $countUsersList; $i++) { $query = 'UPDATE `admin` SET `created_by` = ? WHERE `admin_id` = ?'; exec_query($query, array($toReseller, $usersList[$i])); } $db->commit(); } catch (iMSCP_Exception_Database $e) { $db->rollBack(); throw $e; } return true; }
/** * 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); }